From 6e804760173824a833332e7d079fe97d43ec896c Mon Sep 17 00:00:00 2001 From: tilpner Date: Fri, 21 Apr 2023 13:54:15 +0200 Subject: [PATCH] chore(codec): remove legacy encode/decode API, use send/receive alternatives --- src/codec/decoder/audio.rs | 15 +-------------- src/codec/decoder/video.rs | 20 +------------------- src/codec/encoder/audio.rs | 27 --------------------------- src/codec/encoder/video.rs | 31 ------------------------------- 4 files changed, 2 insertions(+), 91 deletions(-) diff --git a/src/codec/decoder/audio.rs b/src/codec/decoder/audio.rs index 07f0aa4..2eb9fd1 100644 --- a/src/codec/decoder/audio.rs +++ b/src/codec/decoder/audio.rs @@ -1,24 +1,11 @@ use std::ops::{Deref, DerefMut}; -use libc::c_int; - use super::Opened; -use crate::{codec::Context, ffi::*, frame, packet, util::format, AudioService, ChannelLayout, Error}; +use crate::{codec::Context, util::format, AudioService, ChannelLayout}; pub struct Audio(pub Opened); impl Audio { - pub fn decode(&mut self, packet: &P, out: &mut frame::Audio) -> Result { - unsafe { - let mut got: c_int = 0; - - match avcodec_decode_audio4(self.as_mut_ptr(), out.as_mut_ptr(), &mut got, packet.as_ptr()) { - e if e < 0 => Err(Error::from(e)), - _ => Ok(got != 0), - } - } - } - pub fn sample_rate(&self) -> u32 { unsafe { (*self.as_ptr()).sample_rate as u32 } } diff --git a/src/codec/decoder/video.rs b/src/codec/decoder/video.rs index b4f988d..473e98b 100644 --- a/src/codec/decoder/video.rs +++ b/src/codec/decoder/video.rs @@ -6,31 +6,13 @@ use super::{slice, Opened}; use crate::{ codec::Context, color, - ffi::*, - frame, packet, util::{chroma, format}, - Error, FieldOrder, Rational, + FieldOrder, Rational, }; pub struct Video(pub Opened); impl Video { - pub fn decode(&mut self, packet: &P, out: &mut frame::Video) -> Result<(), Error> { - unsafe { - match avcodec_send_packet(self.as_mut_ptr(), packet.as_ptr()) { - e if e < 0 => Err(Error::from(e))?, - _ => (), - } - - match avcodec_receive_frame(self.as_mut_ptr(), out.as_mut_ptr()) { - e if e < 0 => Err(Error::from(e))?, - _ => (), - } - - Ok(()) - } - } - pub fn width(&self) -> u32 { unsafe { (*self.as_ptr()).width as u32 } } diff --git a/src/codec/encoder/audio.rs b/src/codec/encoder/audio.rs index 00c020b..bca30c4 100644 --- a/src/codec/encoder/audio.rs +++ b/src/codec/encoder/audio.rs @@ -9,7 +9,6 @@ use super::Encoder as Super; use crate::{ codec::{traits, Context}, ffi::*, - frame, packet, util::format, ChannelLayout, Dictionary, Error, }; @@ -143,32 +142,6 @@ impl AsMut for Audio { pub struct Encoder(pub Audio); impl Encoder { - pub fn encode(&mut self, frame: &frame::Audio, out: &mut P) -> Result { - unsafe { - if self.format() != frame.format() { - return Err(Error::InvalidData); - } - - let mut got: c_int = 0; - - match avcodec_encode_audio2(self.0.as_mut_ptr(), out.as_mut_ptr(), frame.as_ptr(), &mut got) { - e if e < 0 => Err(Error::from(e)), - _ => Ok(got != 0), - } - } - } - - pub fn flush(&mut self, out: &mut P) -> Result { - unsafe { - let mut got: c_int = 0; - - match avcodec_encode_audio2(self.0.as_mut_ptr(), out.as_mut_ptr(), ptr::null(), &mut got) { - e if e < 0 => Err(Error::from(e)), - _ => Ok(got != 0), - } - } - } - pub fn frame_size(&self) -> u32 { unsafe { (*self.as_ptr()).frame_size as u32 } } diff --git a/src/codec/encoder/video.rs b/src/codec/encoder/video.rs index a109c66..462333f 100644 --- a/src/codec/encoder/video.rs +++ b/src/codec/encoder/video.rs @@ -419,37 +419,6 @@ impl AsMut for Video { pub struct Encoder(pub Video); impl Encoder { - #[inline] - pub fn encode(&mut self, frame: &frame::Video, out: &mut P) -> Result<(), Error> { - unsafe { - if self.format() != frame.format() || self.width() != frame.width() || self.height() != frame.height() { - return Err(Error::InvalidData); - } - - match avcodec_send_frame(self.as_mut_ptr(), frame.as_ptr()) { - e if e < 0 => Err(Error::from(e))?, - _ => (), - } - - match avcodec_receive_packet(self.as_mut_ptr(), out.as_mut_ptr()) { - e if e < 0 => Err(Error::from(e))?, - _ => (), - } - - Ok(()) - } - } - - #[inline] - pub fn flush(&mut self, out: &mut P) -> Result<(), Error> { - unsafe { - match avcodec_receive_packet(self.0.as_mut_ptr(), out.as_mut_ptr()) { - e if e < 0 => Err(Error::from(e)), - _ => Ok(()), - } - } - } - #[inline] pub fn frame_size(&self) -> u32 { unsafe { (*self.as_ptr()).frame_size as u32 }