chore(codec): remove legacy encode/decode API, use send/receive alternatives

This commit is contained in:
tilpner
2023-05-24 17:22:59 +02:00
committed by Till Höppner
parent 757bc42c85
commit 6e80476017
4 changed files with 2 additions and 91 deletions
+1 -14
View File
@@ -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<P: packet::Ref>(&mut self, packet: &P, out: &mut frame::Audio) -> Result<bool, Error> {
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 }
}
+1 -19
View File
@@ -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<P: packet::Ref>(&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 }
}
-27
View File
@@ -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<Context> for Audio {
pub struct Encoder(pub Audio);
impl Encoder {
pub fn encode<P: packet::Mut>(&mut self, frame: &frame::Audio, out: &mut P) -> Result<bool, Error> {
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<P: packet::Mut>(&mut self, out: &mut P) -> Result<bool, Error> {
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 }
}
-31
View File
@@ -419,37 +419,6 @@ impl AsMut<Context> for Video {
pub struct Encoder(pub Video);
impl Encoder {
#[inline]
pub fn encode<P: packet::Mut>(&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<P: packet::Mut>(&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 }