From e6c157b556561301ca0f22bed75a7ce025c6f6f4 Mon Sep 17 00:00:00 2001 From: _ <_@_> Date: Sat, 13 Nov 2021 10:31:58 -0600 Subject: [PATCH] :shirt: refactor: took apart the decoder and put it back together as an iterator popping is still there --- .gitignore | 1 + src/decoder.rs | 125 +++++++++++++++++++++++++++++-------------------- src/main.rs | 58 +++++++++++++---------- 3 files changed, 110 insertions(+), 74 deletions(-) diff --git a/.gitignore b/.gitignore index 9ab26b4..ba3e3ea 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ /target +*.data *.m4a *.ogg *.opus diff --git a/src/decoder.rs b/src/decoder.rs index 64825b6..1776ce8 100644 --- a/src/decoder.rs +++ b/src/decoder.rs @@ -24,6 +24,7 @@ use ffmpeg_next::{ self, Sample, }, + frame::Audio as AudioFrame, }, }; @@ -86,7 +87,6 @@ pub struct Decoder { best_stream_idx: usize, pub decoder: DecodeContext, pub resampler: ResamplingContext, - resampler_flushed: bool, } impl Decoder { @@ -110,46 +110,92 @@ impl Decoder { best_stream_idx, decoder, resampler, - resampler_flushed: false, }) } - pub fn fill_buffer (&mut self, pcm_buffers: &mut PcmBuffers) -> Result { - if ! self.resampler_flushed && self.resampler.delay ().is_some () { - let mut frame_resampled = ffmpeg_next::util::frame::Audio::empty (); - frame_resampled.set_channel_layout (ChannelLayout::STEREO); - frame_resampled.set_format (Sample::F32 (sample::Type::Packed)); - frame_resampled.set_rate (48000); - - let rc = self.resampler.flush (&mut frame_resampled)?; - if rc.is_none () { - self.resampler_flushed = true; + fn new_frame () -> AudioFrame { + let mut x = AudioFrame::empty (); + x.set_channel_layout (ChannelLayout::STEREO); + x.set_format (Sample::F32 (sample::Type::Packed)); + x + } + + pub fn next (&mut self) -> Result