From a373d9bf3f552e0afbe115822925836094d49127 Mon Sep 17 00:00:00 2001 From: meh Date: Fri, 28 Aug 2015 21:25:23 +0200 Subject: [PATCH] codec: add profiles getter --- src/codec/codec.rs | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/src/codec/codec.rs b/src/codec/codec.rs index 859317b..2e28f1a 100644 --- a/src/codec/codec.rs +++ b/src/codec/codec.rs @@ -3,7 +3,7 @@ use std::ffi::CStr; use std::str::from_utf8_unchecked; use ffi::*; -use super::{Id, Context, Video, Audio, Capabilities}; +use super::{Id, Context, Video, Audio, Capabilities, Profile}; use ::{Error, media}; use ::codec::context::Opened; @@ -101,4 +101,46 @@ impl<'a> Codec<'a> { Capabilities::from_bits_truncate((*self.as_ptr()).capabilities as u32) } } + + pub fn profiles(&self) -> Option { + unsafe { + if (*self.as_ptr()).profiles.is_null() { + return None; + } + else { + Some(ProfileIter::new(self.id(), (*self.as_ptr()).profiles)) + } + } + } +} + +pub struct ProfileIter<'a> { + id: Id, + ptr: *const AVProfile, + + _marker: PhantomData<&'a ()>, +} + +impl<'a> ProfileIter<'a> { + pub fn new(id: Id, ptr: *const AVProfile) -> Self { + ProfileIter { id: id, ptr: ptr, _marker: PhantomData } + } +} + +impl<'a> Iterator for ProfileIter<'a> { + type Item = Profile; + + fn next(&mut self) -> Option<::Item> { + unsafe { + if (*self.ptr).profile != FF_PROFILE_UNKNOWN && !(*self.ptr).name.is_null() { + let profile = Profile::from((self.id, (*self.ptr).profile)); + self.ptr = self.ptr.offset(1); + + Some(profile) + } + else { + None + } + } + } }