mirror of
https://github.com/encounter/rust-ffmpeg.git
synced 2026-07-10 21:18:39 -07:00
Expose packet methods
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
use std::ops::{Deref, DerefMut};
|
||||
use std::{
|
||||
ops::{Deref, DerefMut},
|
||||
ptr,
|
||||
};
|
||||
|
||||
use super::{Audio, Decoder, Subtitle, Video};
|
||||
use crate::{
|
||||
codec::{Context, Profile},
|
||||
ffi::*,
|
||||
media, Error, Rational,
|
||||
media, packet, Error, Frame, Rational,
|
||||
};
|
||||
|
||||
pub struct Opened(pub Decoder);
|
||||
@@ -37,6 +40,35 @@ impl Opened {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn send_packet<P: packet::Ref>(&mut self, packet: &P) -> Result<(), Error> {
|
||||
unsafe {
|
||||
match avcodec_send_packet(self.as_mut_ptr(), packet.as_ptr()) {
|
||||
e if e < 0 => Err(Error::from(e)),
|
||||
_ => Ok(()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Sends a NULL packet to the decoder to signal end of stream and enter
|
||||
/// draining mode.
|
||||
pub fn send_eof(&mut self) -> Result<(), Error> {
|
||||
unsafe {
|
||||
match avcodec_send_packet(self.as_mut_ptr(), ptr::null()) {
|
||||
e if e < 0 => Err(Error::from(e)),
|
||||
_ => Ok(()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn receive_frame(&mut self, frame: &mut Frame) -> Result<(), Error> {
|
||||
unsafe {
|
||||
match avcodec_receive_frame(self.as_mut_ptr(), frame.as_mut_ptr()) {
|
||||
e if e < 0 => Err(Error::from(e)),
|
||||
_ => Ok(()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn bit_rate(&self) -> usize {
|
||||
unsafe { (*self.as_ptr()).bit_rate as usize }
|
||||
}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
use std::ops::{Deref, DerefMut};
|
||||
|
||||
use libc::c_int;
|
||||
use std::{
|
||||
ops::{Deref, DerefMut},
|
||||
os::raw::c_int,
|
||||
ptr,
|
||||
};
|
||||
|
||||
use super::{audio, subtitle, video};
|
||||
use crate::{codec::Context, media, Error, Rational};
|
||||
use crate::{codec::Context, ffi::*, media, packet, Error, Frame, Rational};
|
||||
|
||||
pub struct Encoder(pub Context);
|
||||
|
||||
@@ -56,6 +58,30 @@ impl Encoder {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn send_frame(&mut self, frame: &Frame) -> Result<(), Error> {
|
||||
unsafe {
|
||||
match avcodec_send_frame(self.as_mut_ptr(), frame.as_ptr()) {
|
||||
e if e < 0 => Err(Error::from(e)),
|
||||
_ => Ok(()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Sends a NULL packet to the encoder to signal end of stream and enter
|
||||
/// draining mode.
|
||||
pub fn send_eof(&mut self) -> Result<(), Error> {
|
||||
unsafe { self.send_frame(&Frame::wrap(ptr::null_mut())) }
|
||||
}
|
||||
|
||||
pub fn receive_packet<P: packet::Mut>(&mut self, packet: &mut P) -> Result<(), Error> {
|
||||
unsafe {
|
||||
match avcodec_receive_packet(self.as_mut_ptr(), packet.as_mut_ptr()) {
|
||||
e if e < 0 => Err(Error::from(e)),
|
||||
_ => Ok(()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_strict_std_compliance(&mut self, value: i32) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).strict_std_compliance = value as c_int;
|
||||
|
||||
@@ -71,7 +71,7 @@ impl Context {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn nb_streams(&self) -> u32 {
|
||||
pub fn nb_streams(&self) -> u32 {
|
||||
unsafe { (*self.as_ptr()).nb_streams }
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user