codec/threading: add threading configuration
This commit is contained in:
parent
e2039ac550
commit
a0dae25b94
@ -1,10 +1,11 @@
|
||||
use std::ops::Deref;
|
||||
use std::ptr;
|
||||
|
||||
use libc::c_int;
|
||||
use ffi::*;
|
||||
use ::media;
|
||||
use ::{Error, Codec, Dictionary};
|
||||
use super::{Id, Debug, Compliance};
|
||||
use super::{Id, Debug, Compliance, threading};
|
||||
use super::decoder::Decoder;
|
||||
use super::encoder::Encoder;
|
||||
|
||||
@ -107,6 +108,24 @@ impl Context {
|
||||
(*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 {
|
||||
|
@ -26,6 +26,8 @@ pub use self::debug::*;
|
||||
pub mod profile;
|
||||
pub use self::profile::Profile;
|
||||
|
||||
pub mod threading;
|
||||
|
||||
pub mod encoder;
|
||||
pub mod decoder;
|
||||
|
||||
|
61
src/codec/threading.rs
Normal file
61
src/codec/threading.rs
Normal 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
|
||||
}
|
||||
}
|
||||
}
|
@ -40,6 +40,8 @@ pub use codec::{decoder, encoder};
|
||||
pub use codec::field_order::FieldOrder;
|
||||
#[cfg(feature = "codec")]
|
||||
pub use codec::audio_service::AudioService;
|
||||
#[cfg(feature = "codec")]
|
||||
pub use codec::threading;
|
||||
|
||||
#[cfg(feature = "device")]
|
||||
pub mod device;
|
||||
|
Loading…
x
Reference in New Issue
Block a user