Skip to content

Commit c6db135

Browse files
committed
Make codec::Context Settable.
1 parent a7b50dd commit c6db135

File tree

3 files changed

+38
-25
lines changed

3 files changed

+38
-25
lines changed

src/codec/context.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ use std::any::Any;
22
use std::ptr;
33
use std::rc::Rc;
44

5+
use crate::option;
6+
57
use super::decoder::Decoder;
68
use super::encoder::Encoder;
79
use super::{threading, Compliance, Debug, Flags, Id, Parameters};
@@ -197,3 +199,15 @@ impl Clone for Context {
197199
}
198200
}
199201
}
202+
203+
unsafe impl option::Target<AVCodecContext> for Context {
204+
fn as_ptr(&self) -> *const AVCodecContext {
205+
self.ptr as *const _
206+
}
207+
208+
fn as_mut_ptr(&mut self) -> *mut AVCodecContext {
209+
self.ptr as *mut _
210+
}
211+
}
212+
213+
impl option::Settable<AVCodecContext> for Context {}

src/filter/context/context.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use super::{Sink, Source};
22
use ffi::*;
3-
use libc::c_void;
43
use {format, option, ChannelLayout};
54

65
pub struct Context {
@@ -58,14 +57,14 @@ impl Context {
5857
}
5958
}
6059

61-
unsafe impl option::Target for Context {
62-
fn as_ptr(&self) -> *const c_void {
60+
unsafe impl option::Target<AVFilterContext> for Context {
61+
fn as_ptr(&self) -> *const AVFilterContext {
6362
self.ptr as *const _
6463
}
6564

66-
fn as_mut_ptr(&mut self) -> *mut c_void {
65+
fn as_mut_ptr(&mut self) -> *mut AVFilterContext {
6766
self.ptr as *mut _
6867
}
6968
}
7069

71-
impl option::Settable for Context {}
70+
impl option::Settable<AVFilterContext> for Context {}

src/util/option/traits.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::ffi::CString;
44
use std::mem;
55

66
use ffi::*;
7-
use libc::{c_int, c_void};
7+
use libc::c_int;
88
use util::format;
99
use {ChannelLayout, Error, Rational};
1010

@@ -17,21 +17,21 @@ macro_rules! check {
1717
};
1818
}
1919

20-
pub unsafe trait Target {
21-
fn as_ptr(&self) -> *const c_void;
22-
fn as_mut_ptr(&mut self) -> *mut c_void;
20+
pub unsafe trait Target<T> {
21+
fn as_ptr(&self) -> *const T;
22+
fn as_mut_ptr(&mut self) -> *mut T;
2323
}
2424

25-
pub trait Settable: Target {
26-
fn set<T: 'static>(&mut self, name: &str, value: &T) -> Result<(), Error> {
25+
pub trait Settable<T>: Target<T> {
26+
fn set<V: 'static>(&mut self, name: &str, value: &V) -> Result<(), Error> {
2727
unsafe {
2828
let name = CString::new(name).unwrap();
2929

3030
check!(av_opt_set_bin(
31-
self.as_mut_ptr(),
31+
self.as_mut_ptr() as *mut _,
3232
name.as_ptr(),
3333
value as *const _ as *const _,
34-
mem::size_of::<T>() as c_int,
34+
mem::size_of::<V>() as c_int,
3535
AV_OPT_SEARCH_CHILDREN
3636
))
3737
}
@@ -43,7 +43,7 @@ pub trait Settable: Target {
4343
let value = CString::new(value).unwrap();
4444

4545
check!(av_opt_set(
46-
self.as_mut_ptr(),
46+
self.as_mut_ptr() as *mut _,
4747
name.as_ptr(),
4848
value.as_ptr(),
4949
AV_OPT_SEARCH_CHILDREN
@@ -56,7 +56,7 @@ pub trait Settable: Target {
5656
let name = CString::new(name).unwrap();
5757

5858
check!(av_opt_set_int(
59-
self.as_mut_ptr(),
59+
self.as_mut_ptr() as *mut _,
6060
name.as_ptr(),
6161
value,
6262
AV_OPT_SEARCH_CHILDREN
@@ -69,20 +69,20 @@ pub trait Settable: Target {
6969
let name = CString::new(name).unwrap();
7070

7171
check!(av_opt_set_double(
72-
self.as_mut_ptr(),
72+
self.as_mut_ptr() as *mut _,
7373
name.as_ptr(),
7474
value,
7575
AV_OPT_SEARCH_CHILDREN
7676
))
7777
}
7878
}
7979

80-
fn set_rational<T: Into<Rational>>(&mut self, name: &str, value: T) -> Result<(), Error> {
80+
fn set_rational<V: Into<Rational>>(&mut self, name: &str, value: V) -> Result<(), Error> {
8181
unsafe {
8282
let name = CString::new(name).unwrap();
8383

8484
check!(av_opt_set_q(
85-
self.as_mut_ptr(),
85+
self.as_mut_ptr() as *mut _,
8686
name.as_ptr(),
8787
value.into().into(),
8888
AV_OPT_SEARCH_CHILDREN
@@ -95,7 +95,7 @@ pub trait Settable: Target {
9595
let name = CString::new(name).unwrap();
9696

9797
check!(av_opt_set_image_size(
98-
self.as_mut_ptr(),
98+
self.as_mut_ptr() as *mut _,
9999
name.as_ptr(),
100100
w as c_int,
101101
h as c_int,
@@ -109,7 +109,7 @@ pub trait Settable: Target {
109109
let name = CString::new(name).unwrap();
110110

111111
check!(av_opt_set_pixel_fmt(
112-
self.as_mut_ptr(),
112+
self.as_mut_ptr() as *mut _,
113113
name.as_ptr(),
114114
format.into(),
115115
AV_OPT_SEARCH_CHILDREN
@@ -122,7 +122,7 @@ pub trait Settable: Target {
122122
let name = CString::new(name).unwrap();
123123

124124
check!(av_opt_set_sample_fmt(
125-
self.as_mut_ptr(),
125+
self.as_mut_ptr() as *mut _,
126126
name.as_ptr(),
127127
format.into(),
128128
AV_OPT_SEARCH_CHILDREN
@@ -137,7 +137,7 @@ pub trait Settable: Target {
137137
#[cfg(not(feature = "ffmpeg_7_0"))]
138138
{
139139
check!(av_opt_set_channel_layout(
140-
self.as_mut_ptr(),
140+
self.as_mut_ptr() as *mut _,
141141
name.as_ptr(),
142142
layout.bits() as i64,
143143
AV_OPT_SEARCH_CHILDREN
@@ -147,7 +147,7 @@ pub trait Settable: Target {
147147
#[cfg(feature = "ffmpeg_7_0")]
148148
{
149149
check!(av_opt_set_chlayout(
150-
self.as_mut_ptr(),
150+
self.as_mut_ptr() as *mut _,
151151
name.as_ptr(),
152152
&layout.into(),
153153
AV_OPT_SEARCH_CHILDREN
@@ -157,6 +157,6 @@ pub trait Settable: Target {
157157
}
158158
}
159159

160-
pub trait Gettable: Target {}
160+
pub trait Gettable<T>: Target<T> {}
161161

162-
pub trait Iterable: Target {}
162+
pub trait Iterable<T>: Target<T> {}

0 commit comments

Comments
 (0)