refactor: buffer frame without returning sampled frame
This commit is contained in:
@ -27,12 +27,8 @@ impl AudioFifo {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Buffer a resampled frame, and get a frame from the buffer with the desired size
|
/// Buffer a frame
|
||||||
pub unsafe fn buffer_frame(
|
pub unsafe fn buffer_frame(&mut self, frame: *mut AVFrame) -> Result<()> {
|
||||||
&mut self,
|
|
||||||
frame: *mut AVFrame,
|
|
||||||
samples_out: usize,
|
|
||||||
) -> Result<Option<*mut AVFrame>> {
|
|
||||||
let mut ret =
|
let mut ret =
|
||||||
av_audio_fifo_realloc(self.ctx, av_audio_fifo_size(self.ctx) + (*frame).nb_samples);
|
av_audio_fifo_realloc(self.ctx, av_audio_fifo_size(self.ctx) + (*frame).nb_samples);
|
||||||
bail_ffmpeg!(ret);
|
bail_ffmpeg!(ret);
|
||||||
@ -44,8 +40,7 @@ impl AudioFifo {
|
|||||||
|
|
||||||
ret = av_audio_fifo_write(self.ctx, buf_ptr, (*frame).nb_samples);
|
ret = av_audio_fifo_write(self.ctx, buf_ptr, (*frame).nb_samples);
|
||||||
bail_ffmpeg!(ret);
|
bail_ffmpeg!(ret);
|
||||||
|
Ok(())
|
||||||
self.get_frame(samples_out)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get a frame from the buffer if there is enough data
|
/// Get a frame from the buffer if there is enough data
|
||||||
@ -105,9 +100,8 @@ mod tests {
|
|||||||
av_frame_get_buffer(demo_frame, 0);
|
av_frame_get_buffer(demo_frame, 0);
|
||||||
|
|
||||||
let dst_nb_samples = (*enc.codec_context()).frame_size;
|
let dst_nb_samples = (*enc.codec_context()).frame_size;
|
||||||
let mut out_frame = buf
|
buf.buffer_frame(demo_frame)?;
|
||||||
.buffer_frame(demo_frame, dst_nb_samples as usize)?
|
let mut out_frame = buf.get_frame(dst_nb_samples as usize)?.unwrap();
|
||||||
.unwrap();
|
|
||||||
for mut pkt in enc.encode_frame(out_frame)? {
|
for mut pkt in enc.encode_frame(out_frame)? {
|
||||||
av_packet_free(&mut pkt);
|
av_packet_free(&mut pkt);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user