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