mirror of
https://github.com/encounter/rust-ffmpeg.git
synced 2026-07-10 21:18:39 -07:00
feat: impl Debug for Stream and Context
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
use std::mem;
|
||||
use std::ptr;
|
||||
use std::rc::Rc;
|
||||
|
||||
use std::fmt;
|
||||
use super::destructor::{self, Destructor};
|
||||
use ffi::*;
|
||||
use libc::{c_int, c_uint};
|
||||
@@ -41,7 +41,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(Stream::wrap(self, index))
|
||||
@@ -54,7 +54,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))
|
||||
@@ -70,10 +70,20 @@ impl Context {
|
||||
StreamIterMut::new(self)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn nb_streams(&self) -> u32 {
|
||||
unsafe { (*self.as_ptr()).nb_streams }
|
||||
}
|
||||
|
||||
pub fn bit_rate(&self) -> i64 {
|
||||
unsafe { (*self.as_ptr()).bit_rate }
|
||||
}
|
||||
|
||||
pub fn duration(&self) -> i64 {
|
||||
unsafe { (*self.as_ptr()).duration }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn nb_chapters(&self) -> u32 {
|
||||
unsafe { (*self.as_ptr()).nb_chapters }
|
||||
}
|
||||
@@ -83,7 +93,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))
|
||||
@@ -96,7 +106,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))
|
||||
@@ -218,7 +228,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;
|
||||
}
|
||||
|
||||
@@ -229,15 +239,13 @@ 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),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> ExactSizeIterator for StreamIter<'a> {}
|
||||
@@ -260,13 +268,12 @@ impl<'a> Iterator for StreamIterMut<'a> {
|
||||
type Item = StreamMut<'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;
|
||||
}
|
||||
|
||||
self.current += 1;
|
||||
|
||||
unsafe {
|
||||
Some(StreamMut::wrap(
|
||||
mem::transmute_copy(&self.context),
|
||||
(self.current - 1) as usize,
|
||||
@@ -275,15 +282,13 @@ 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),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> ExactSizeIterator for StreamIterMut<'a> {}
|
||||
@@ -376,3 +381,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()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user