codec/threading: add threading configuration

This commit is contained in:
meh 2015-05-16 19:18:26 +02:00
parent e2039ac550
commit a0dae25b94
4 changed files with 85 additions and 1 deletions

View File

@ -1,10 +1,11 @@
use std::ops::Deref; use std::ops::Deref;
use std::ptr; use std::ptr;
use libc::c_int;
use ffi::*; use ffi::*;
use ::media; use ::media;
use ::{Error, Codec, Dictionary}; use ::{Error, Codec, Dictionary};
use super::{Id, Debug, Compliance}; use super::{Id, Debug, Compliance, threading};
use super::decoder::Decoder; use super::decoder::Decoder;
use super::encoder::Encoder; use super::encoder::Encoder;
@ -107,6 +108,24 @@ impl Context {
(*self.ptr).debug = value.bits(); (*self.ptr).debug = value.bits();
} }
} }
pub fn set_threading(&mut self, config: threading::Config) {
unsafe {
(*self.ptr).thread_type = config.kind.into();
(*self.ptr).thread_count = config.count as c_int;
(*self.ptr).thread_safe_callbacks = if config.safe { 1 } else { 0 };
}
}
pub fn threading(&self) -> threading::Config {
unsafe {
threading::Config {
kind: threading::Type::from((*self.ptr).active_thread_type),
count: (*self.ptr).thread_count as usize,
safe: (*self.ptr).thread_safe_callbacks != 0,
}
}
}
} }
impl Drop for Context { impl Drop for Context {

View File

@ -26,6 +26,8 @@ pub use self::debug::*;
pub mod profile; pub mod profile;
pub use self::profile::Profile; pub use self::profile::Profile;
pub mod threading;
pub mod encoder; pub mod encoder;
pub mod decoder; pub mod decoder;

61
src/codec/threading.rs Normal file
View File

@ -0,0 +1,61 @@
use libc::c_int;
use ffi::*;
#[derive(Eq, PartialEq, Clone, Copy, Debug)]
pub struct Config {
pub kind: Type,
pub count: usize,
pub safe: bool,
}
impl Config {
pub fn kind(value: Type) -> Self {
Config { kind: value, .. Default::default() }
}
pub fn count(value: usize) -> Self {
Config { count: value, .. Default::default() }
}
pub fn safe(value: bool) -> Self {
Config { safe: value, .. Default::default() }
}
}
impl Default for Config {
fn default() -> Self {
Config {
kind: Type::None,
count: 0,
safe: false,
}
}
}
#[derive(Eq, PartialEq, Clone, Copy, Debug)]
pub enum Type {
None,
Frame,
Slice,
}
impl From<c_int> for Type {
fn from(value: c_int) -> Type {
match value {
FF_THREAD_FRAME => Type::Frame,
FF_THREAD_SLICE => Type::Slice,
_ => Type::None,
}
}
}
impl Into<c_int> for Type {
fn into(self) -> c_int {
match self {
Type::None => 0,
Type::Frame => FF_THREAD_FRAME,
Type::Slice => FF_THREAD_SLICE
}
}
}

View File

@ -40,6 +40,8 @@ pub use codec::{decoder, encoder};
pub use codec::field_order::FieldOrder; pub use codec::field_order::FieldOrder;
#[cfg(feature = "codec")] #[cfg(feature = "codec")]
pub use codec::audio_service::AudioService; pub use codec::audio_service::AudioService;
#[cfg(feature = "codec")]
pub use codec::threading;
#[cfg(feature = "device")] #[cfg(feature = "device")]
pub mod device; pub mod device;