Skip to content

Commit 7a57b73

Browse files
committed
Fix bitstream codec fallback and video stream detection
1 parent 942bf8a commit 7a57b73

2 files changed

Lines changed: 22 additions & 8 deletions

File tree

src/audio.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,12 +1329,22 @@ pub fn start_audio_thread(file_path: &str, mic: bool, shared_state: Arc<Mutex<Ap
13291329
if passthrough {
13301330
let (tx, rx) = bounded::<DspMessage>(32);
13311331
let stop_token = Arc::new(std::sync::atomic::AtomicBool::new(false));
1332-
if let Ok((handle, decoder_rate)) = crate::bitstream::start_bitstream_thread(file_path, shared_state.clone(), tx.clone(), stop_token.clone()) {
1332+
if let Ok((handle, decoder_rate, codec_name, has_video)) = crate::bitstream::start_bitstream_thread(file_path, shared_state.clone(), tx.clone(), stop_token.clone()) {
13331333
let max_frequency = shared_state.lock().unwrap().max_frequency;
13341334
let sample_rate = decoder_rate;
13351335
let window_size = (((sample_rate as f32 * 0.185).round() as usize) / 2) * 2;
13361336
let window_size = window_size.max(2048).min(65536);
13371337

1338+
let display_name = match codec_name.as_str() {
1339+
"truehd" => "TrueHD / Dolby Atmos",
1340+
"eac3" => "E-AC3 / Dolby Digital Plus",
1341+
"dts" => "DTS",
1342+
"ac3" => "AC3 / Dolby Digital",
1343+
_ => &codec_name,
1344+
}.to_string();
1345+
1346+
let video_suffix = if has_video { " (Video stream available)" } else { "" };
1347+
13381348
{
13391349
let mut state = shared_state.lock().unwrap();
13401350
state.artist = "Bitstream Active".to_string();
@@ -1346,7 +1356,7 @@ pub fn start_audio_thread(file_path: &str, mic: bool, shared_state: Arc<Mutex<Ap
13461356
state.hardware_channels = 8;
13471357
state.channel_vus = vec![0.0; 8];
13481358
state.peak_vus = vec![0.0; 8];
1349-
state.video_info = Some("TrueHD/Atmos".to_string());
1359+
state.video_info = Some(format!("{}{}", display_name, video_suffix));
13501360
}
13511361

13521362
spawn_dsp_thread(rx, shared_state.clone(), sample_rate, max_frequency, window_size);

src/bitstream.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ pub fn start_bitstream_thread(
44
_shared_state: std::sync::Arc<std::sync::Mutex<crate::state::AppState>>,
55
tx: crossbeam_channel::Sender<crate::audio::DspMessage>,
66
stop_token: std::sync::Arc<std::sync::atomic::AtomicBool>,
7-
) -> anyhow::Result<(std::thread::JoinHandle<()>, u32)> {
7+
) -> anyhow::Result<(std::thread::JoinHandle<()>, u32, String, bool)> {
88
use anyhow::Context;
99

1010
println!("[bitstream] Probing codec via ffmpeg-next on Linux...");
@@ -29,6 +29,8 @@ pub fn start_bitstream_thread(
2929
_ => return Err(anyhow::anyhow!("Unsupported codec for bitstreaming: {:?}", codec_id)),
3030
}.to_string();
3131

32+
let has_video = ictx.streams().best(ffmpeg_next::media::Type::Video).is_some();
33+
3234
let parameters = best_audio.parameters();
3335
let best_audio_index = best_audio.index();
3436

@@ -193,7 +195,7 @@ pub fn start_bitstream_thread(
193195
println!("[bitstream] FFmpeg thread finished on Linux.");
194196
});
195197

196-
Ok((ffmpeg_thread, decoder_sample_rate as u32))
198+
Ok((ffmpeg_thread, decoder_sample_rate as u32, codec_name, has_video))
197199
}
198200

199201
#[cfg(not(any(target_os = "windows", target_os = "linux")))]
@@ -202,7 +204,7 @@ pub fn start_bitstream_thread(
202204
_shared_state: std::sync::Arc<std::sync::Mutex<crate::state::AppState>>,
203205
_tx: crossbeam_channel::Sender<crate::audio::DspMessage>,
204206
_stop_token: std::sync::Arc<std::sync::atomic::AtomicBool>,
205-
) -> anyhow::Result<(std::thread::JoinHandle<()>, u32)> {
207+
) -> anyhow::Result<(std::thread::JoinHandle<()>, u32, String, bool)> {
206208
Err(anyhow::anyhow!("Bitstream passthrough is not supported on this platform."))
207209
}
208210
#[cfg(windows)]
@@ -397,7 +399,7 @@ mod wasapi_bitstream {
397399

398400
// ─── Main bitstream pump ─────────────────────────────────────────
399401

400-
pub fn start_bitstream_thread(file_path: &str, _shared_state: Arc<Mutex<AppState>>, tx: Sender<DspMessage>, stop_token: Arc<AtomicBool>) -> Result<(std::thread::JoinHandle<()>, u32)> {
402+
pub fn start_bitstream_thread(file_path: &str, _shared_state: Arc<Mutex<AppState>>, tx: Sender<DspMessage>, stop_token: Arc<AtomicBool>) -> Result<(std::thread::JoinHandle<()>, u32, String, bool)> {
401403
unsafe { let _ = CoInitializeEx(None, COINIT_MULTITHREADED); }
402404

403405
// ── Probe codec via ffmpeg-next ─────────────────────────────
@@ -420,9 +422,11 @@ mod wasapi_bitstream {
420422
ffmpeg_next::codec::Id::EAC3 => "eac3",
421423
ffmpeg_next::codec::Id::DTS => "dts",
422424
ffmpeg_next::codec::Id::AC3 => "ac3",
423-
_ => "unknown",
425+
_ => return Err(anyhow::anyhow!("Unsupported codec for bitstreaming: {:?}", codec_id)),
424426
}.to_string();
425427

428+
let has_video = ictx.streams().best(ffmpeg_next::media::Type::Video).is_some();
429+
426430
let profiles = detect_codec_profile(&codec_name);
427431
println!("Detected codec: {}", codec_name);
428432
for p in &profiles {
@@ -779,7 +783,7 @@ mod wasapi_bitstream {
779783
println!("Bitstream thread finished.");
780784
});
781785

782-
Ok((handle, decoder_sample_rate))
786+
Ok((handle, decoder_sample_rate, profile.name.to_string(), has_video))
783787
}
784788
}
785789

0 commit comments

Comments
 (0)