commit
f88f1a981c
@ -127,9 +127,7 @@ impl Packet {
|
||||
|
||||
#[inline]
|
||||
pub fn set_pts(&mut self, value: Option<i64>) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).pts = value.unwrap_or(AV_NOPTS_VALUE);
|
||||
}
|
||||
self.0.pts = value.unwrap_or(AV_NOPTS_VALUE);
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@ -142,9 +140,7 @@ impl Packet {
|
||||
|
||||
#[inline]
|
||||
pub fn set_dts(&mut self, value: Option<i64>) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).dts = value.unwrap_or(AV_NOPTS_VALUE);
|
||||
}
|
||||
self.0.dts = value.unwrap_or(AV_NOPTS_VALUE);
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@ -157,11 +153,21 @@ impl Packet {
|
||||
self.0.duration as i64
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_duration(&mut self, value: i64) {
|
||||
self.0.duration = value;
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn position(&self) -> isize {
|
||||
self.0.pos as isize
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_position(&mut self, value: isize) {
|
||||
self.0.pos = value as i64
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn convergence(&self) -> isize {
|
||||
self.0.convergence_duration as isize
|
||||
|
@ -1,3 +1,4 @@
|
||||
use std::fmt;
|
||||
use std::mem;
|
||||
use std::ptr;
|
||||
use std::rc::Rc;
|
||||
@ -36,12 +37,17 @@ impl Context {
|
||||
}
|
||||
|
||||
impl Context {
|
||||
#[inline]
|
||||
fn nb_streams(&self) -> u32 {
|
||||
unsafe { (*self.as_ptr()).nb_streams }
|
||||
}
|
||||
|
||||
pub fn stream<'a, 'b>(&'a self, index: usize) -> Option<Stream<'b>>
|
||||
where
|
||||
'a: 'b,
|
||||
{
|
||||
unsafe {
|
||||
if index >= (*self.as_ptr()).nb_streams as usize {
|
||||
if index >= self.nb_streams() as usize {
|
||||
None
|
||||
} else {
|
||||
Some(Stream::wrap(self, index))
|
||||
@ -54,7 +60,7 @@ impl Context {
|
||||
'a: 'b,
|
||||
{
|
||||
unsafe {
|
||||
if index >= (*self.as_ptr()).nb_streams as usize {
|
||||
if index >= self.nb_streams() as usize {
|
||||
None
|
||||
} else {
|
||||
Some(StreamMut::wrap(self, index))
|
||||
@ -78,6 +84,7 @@ impl Context {
|
||||
unsafe { (*self.as_ptr()).duration }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn nb_chapters(&self) -> u32 {
|
||||
unsafe { (*self.as_ptr()).nb_chapters }
|
||||
}
|
||||
@ -87,7 +94,7 @@ impl Context {
|
||||
'a: 'b,
|
||||
{
|
||||
unsafe {
|
||||
if index >= (*self.as_ptr()).nb_chapters as usize {
|
||||
if index >= self.nb_chapters() as usize {
|
||||
None
|
||||
} else {
|
||||
Some(Chapter::wrap(self, index))
|
||||
@ -100,7 +107,7 @@ impl Context {
|
||||
'a: 'b,
|
||||
{
|
||||
unsafe {
|
||||
if index >= (*self.as_ptr()).nb_chapters as usize {
|
||||
if index >= self.nb_chapters() as usize {
|
||||
None
|
||||
} else {
|
||||
Some(ChapterMut::wrap(self, index))
|
||||
@ -222,7 +229,7 @@ impl<'a> Iterator for StreamIter<'a> {
|
||||
|
||||
fn next(&mut self) -> Option<<Self as Iterator>::Item> {
|
||||
unsafe {
|
||||
if self.current >= (*self.context.as_ptr()).nb_streams {
|
||||
if self.current >= self.context.nb_streams() {
|
||||
return None;
|
||||
}
|
||||
|
||||
@ -233,14 +240,12 @@ impl<'a> Iterator for StreamIter<'a> {
|
||||
}
|
||||
|
||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||
unsafe {
|
||||
let length = (*self.context.as_ptr()).nb_streams as usize;
|
||||
let length = self.context.nb_streams() as usize;
|
||||
|
||||
(
|
||||
length - self.current as usize,
|
||||
Some(length - self.current as usize),
|
||||
)
|
||||
}
|
||||
(
|
||||
length - self.current as usize,
|
||||
Some(length - self.current as usize),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@ -264,13 +269,12 @@ impl<'a> Iterator for StreamIterMut<'a> {
|
||||
type Item = StreamMut<'a>;
|
||||
|
||||
fn next(&mut self) -> Option<<Self as Iterator>::Item> {
|
||||
if self.current >= self.context.nb_streams() {
|
||||
return None;
|
||||
}
|
||||
self.current += 1;
|
||||
|
||||
unsafe {
|
||||
if self.current >= (*self.context.as_ptr()).nb_streams {
|
||||
return None;
|
||||
}
|
||||
|
||||
self.current += 1;
|
||||
|
||||
Some(StreamMut::wrap(
|
||||
mem::transmute_copy(&self.context),
|
||||
(self.current - 1) as usize,
|
||||
@ -279,14 +283,12 @@ impl<'a> Iterator for StreamIterMut<'a> {
|
||||
}
|
||||
|
||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||
unsafe {
|
||||
let length = (*self.context.as_ptr()).nb_streams as usize;
|
||||
let length = self.context.nb_streams() as usize;
|
||||
|
||||
(
|
||||
length - self.current as usize,
|
||||
Some(length - self.current as usize),
|
||||
)
|
||||
}
|
||||
(
|
||||
length - self.current as usize,
|
||||
Some(length - self.current as usize),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@ -380,3 +382,14 @@ impl<'a> Iterator for ChapterIterMut<'a> {
|
||||
}
|
||||
|
||||
impl<'a> ExactSizeIterator for ChapterIterMut<'a> {}
|
||||
|
||||
impl fmt::Debug for Context {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
let mut s = fmt.debug_struct("AVFormatContext");
|
||||
s.field("bit_rate", &self.bit_rate());
|
||||
s.field("duration", &self.duration());
|
||||
s.field("nb_chapters", &self.nb_chapters());
|
||||
s.field("nb_streams", &self.nb_streams());
|
||||
s.finish()
|
||||
}
|
||||
}
|
||||
|
@ -72,11 +72,12 @@ impl Output {
|
||||
|
||||
pub fn add_stream<E: traits::Encoder>(&mut self, codec: E) -> Result<StreamMut, Error> {
|
||||
unsafe {
|
||||
let codec = codec.encoder().ok_or(Error::EncoderNotFound)?;
|
||||
let ptr = avformat_new_stream(self.as_mut_ptr(), codec.as_ptr());
|
||||
let codec = codec.encoder();
|
||||
let codec = codec.map_or(ptr::null(), |c| c.as_ptr());
|
||||
let ptr = avformat_new_stream(self.as_mut_ptr(), codec);
|
||||
|
||||
if ptr.is_null() {
|
||||
panic!("out of memory");
|
||||
return Err(Error::Unknown);
|
||||
}
|
||||
|
||||
let index = (*self.ctx.as_ptr()).nb_streams - 1;
|
||||
|
@ -5,6 +5,7 @@ use format::context::common::Context;
|
||||
use libc::c_int;
|
||||
use {DictionaryRef, Discard, Rational};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Stream<'a> {
|
||||
context: &'a Context,
|
||||
index: usize,
|
||||
|
@ -20,6 +20,8 @@ pub struct Context {
|
||||
output: Definition,
|
||||
}
|
||||
|
||||
unsafe impl Send for Context {}
|
||||
|
||||
impl Context {
|
||||
#[doc(hidden)]
|
||||
pub unsafe fn as_ptr(&self) -> *const SwrContext {
|
||||
|
@ -1,4 +1,5 @@
|
||||
use std::ffi::{CStr, CString};
|
||||
use std::fmt;
|
||||
use std::marker::PhantomData;
|
||||
use std::ptr;
|
||||
use std::str::from_utf8_unchecked;
|
||||
@ -58,3 +59,9 @@ impl<'a> IntoIterator for &'a Ref<'a> {
|
||||
self.iter()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> fmt::Debug for Ref<'a> {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
fmt.debug_map().entries(self.iter()).finish()
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
use std::ffi::CString;
|
||||
use std::fmt;
|
||||
use std::marker::PhantomData;
|
||||
use std::ops::Deref;
|
||||
|
||||
@ -50,3 +51,9 @@ impl<'a> Deref for Ref<'a> {
|
||||
&self.imm
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> fmt::Debug for Ref<'a> {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
self.imm.fmt(fmt)
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
use std::fmt;
|
||||
use std::iter::FromIterator;
|
||||
use std::ops::{Deref, DerefMut};
|
||||
use std::ptr;
|
||||
@ -126,3 +127,9 @@ impl<'a> Drop for Owned<'a> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> fmt::Debug for Owned<'a> {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
self.inner.fmt(fmt)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user