From 68461866d806d9ceee03d70049b75ca6e492aa8a Mon Sep 17 00:00:00 2001 From: _ <_@_> Date: Sat, 13 Nov 2021 11:23:10 -0600 Subject: [PATCH] :bug: bug: popping is gone It was a combination of two bugs: 1. For some reason, libswresample sometimes returns more data than you need. Like, it'll return X samples but _more than_ 8X bytes, for f32 stereo. 2. I wasn't supposed to be calling `flush`. I should have been calling `run` with a dummy frame. This isn't intuitive to me, and it required me to construct a dummy frame and keep it around in my code. I think this is pretty inelegant. And looking at the ffmpeg code, I think it's a flaw in the API design of the `ffmpeg_next` crate. I may ask them about it in the future. --- src/decoder.rs | 67 +++++++++++++++++++++++++------------------------- todo.md | 2 -- 2 files changed, 33 insertions(+), 36 deletions(-) diff --git a/src/decoder.rs b/src/decoder.rs index 3b77d8c..1acb702 100644 --- a/src/decoder.rs +++ b/src/decoder.rs @@ -84,9 +84,11 @@ pub struct SharedState { pub struct Decoder { pub input_ctx: DemuxContext, - best_stream_idx: usize, pub decoder: DecodeContext, pub resampler: ResamplingContext, + + best_stream_idx: usize, + dummy_frame: Option , } impl Decoder { @@ -107,9 +109,11 @@ impl Decoder { Ok (Self { input_ctx, - best_stream_idx, decoder, resampler, + + best_stream_idx, + dummy_frame: None, }) } @@ -133,8 +137,8 @@ impl Decoder { if actual_bytes > expected_bytes { let extra_bytes = actual_bytes - expected_bytes; let extra_samples = extra_bytes / 4 / 2; - tracing::debug! ("Extra bytes: {}", extra_bytes); - tracing::debug! ("Extra samples: {}", extra_samples); + // tracing::debug! ("Extra bytes: {}", extra_bytes); + // tracing::debug! ("Extra samples: {}", extra_samples); } Some (frame) @@ -175,26 +179,18 @@ impl Decoder { } pub fn pump_resampler (&mut self) -> Result