Skip to content

Commit 420503f

Browse files
committed
Add Bitrate tracking and display to Track Info
1 parent 49b8be6 commit 420503f

4 files changed

Lines changed: 16 additions & 0 deletions

File tree

src/audio.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ pub trait AudioSource: Send {
246246
fn get_video_info(&mut self) -> Option<String> { None }
247247
fn attach_video_queue(&mut self, _tx: crossbeam_channel::Sender<(u64, ffmpeg_next::Packet)>) {}
248248
fn take_video_parameters(&mut self) -> Option<(ffmpeg_next::codec::Parameters, ffmpeg_next::Rational)> { None }
249+
fn get_bitrate(&mut self) -> Option<u32> { None }
249250
}
250251

251252
// ---------------------------------------------------------
@@ -1111,6 +1112,15 @@ impl AudioSource for VideoOnlySource {
11111112
fn get_current_order(&mut self) -> i32 { 0 }
11121113
fn get_current_row(&mut self) -> i32 { 0 }
11131114
fn get_video_info(&mut self) -> Option<String> { self.video_info.clone() }
1115+
1116+
fn get_bitrate(&mut self) -> Option<u32> {
1117+
let br = self.ictx.bit_rate();
1118+
if br > 0 {
1119+
Some((br / 1000) as u32)
1120+
} else {
1121+
None
1122+
}
1123+
}
11141124

11151125
fn attach_video_queue(&mut self, tx: crossbeam_channel::Sender<(u64, ffmpeg_next::Packet)>) {
11161126
self.video_tx = Some(tx);
@@ -1561,6 +1571,7 @@ pub fn start_audio_thread(file_path: &str, mic: bool, shared_state: Arc<Mutex<Ap
15611571
state.num_samples = audio_source.get_num_samples();
15621572
state.num_instruments = audio_source.get_num_instruments();
15631573
state.num_patterns = audio_source.get_num_patterns();
1574+
state.bitrate = audio_source.get_bitrate();
15641575

15651576
if !mic {
15661577
state.tracker_channels = tracker_channels;

src/engine.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2980,6 +2980,7 @@ impl<'a> VulkanEngine<'a> {
29802980
if state.num_instruments > 0 { columns[2].horizontal(|ui| { ui.label("Instruments"); ui.label(format!("{}", state.num_instruments)); }); }
29812981
if state.num_samples > 0 { columns[2].horizontal(|ui| { ui.label("Samples"); ui.label(format!("{}", state.num_samples)); }); }
29822982
columns[2].horizontal(|ui| { ui.label("Sample Rate"); ui.label(format!("{} Hz", state.current_sample_rate as u32)); });
2983+
columns[2].horizontal(|ui| { ui.label("Bitrate"); ui.label(state.bitrate.map(|b| format!("{} kbps", b)).unwrap_or_else(|| "Unknown".to_string())); });
29832984
columns[2].horizontal(|ui| {
29842985
if let Some(tc) = state.tracker_channels {
29852986
ui.label("Tracker Channels");

src/state.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ pub struct AppState {
116116
pub artist: String,
117117
pub module_type: String,
118118
pub duration_seconds: f64,
119+
pub bitrate: Option<u32>,
119120
pub current_seconds: f64,
120121
pub seek_request: Option<f64>,
121122
pub seek_epoch: u64,
@@ -245,6 +246,7 @@ impl AppState {
245246
artist: "Unknown".to_string(),
246247
module_type: "Unknown".to_string(),
247248
duration_seconds: 0.0,
249+
bitrate: None,
248250
current_seconds: 0.0,
249251
seek_request: None,
250252
seek_epoch: 0,
@@ -325,6 +327,7 @@ impl AppState {
325327
artist: self.artist.clone(),
326328
module_type: self.module_type.clone(),
327329
duration_seconds: self.duration_seconds,
330+
bitrate: self.bitrate,
328331
current_seconds: self.current_seconds,
329332
seek_request: None,
330333
seek_epoch: self.seek_epoch,

src/ui.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ pub fn draw(f: &mut Frame, state: &AppState) {
166166
Row::new(vec!["Speed".to_string(), state.speed.to_string()]),
167167
Row::new(vec!["Channels".to_string(), state.num_channels.to_string()]),
168168
Row::new(vec!["Sample Rate".to_string(), format!("{} Hz", state.current_sample_rate as u32)]),
169+
Row::new(vec!["Bitrate".to_string(), state.bitrate.map(|b| format!("{} kbps", b)).unwrap_or_else(|| "Unknown".to_string())]),
169170
Row::new(vec!["Length".to_string(), if state.duration_seconds <= 0.0 { "LIVE".to_string() } else { format!("{:.1}s", state.duration_seconds) }]),
170171
],
171172
[Constraint::Percentage(40), Constraint::Percentage(60)].as_ref()

0 commit comments

Comments
 (0)