@@ -5,8 +5,8 @@ use std::mem;
55
66use crate :: ffi:: * ;
77use crate :: util:: format;
8- use crate :: { Error , Rational } ;
9- use libc:: { c_int, c_void } ;
8+ use crate :: { AsMutPtr , AsPtr , Error , Rational } ;
9+ use libc:: c_int;
1010
1111#[ cfg( not( feature = "ffmpeg_7_0" ) ) ]
1212use crate :: ChannelLayoutMask ;
@@ -20,21 +20,16 @@ macro_rules! check {
2020 } ;
2121}
2222
23- pub unsafe trait Target {
24- fn as_ptr ( & self ) -> * const c_void ;
25- fn as_mut_ptr ( & mut self ) -> * mut c_void ;
26- }
27-
28- pub trait Settable : Target {
29- fn set < T : ' static > ( & mut self , name : & str , value : & T ) -> Result < ( ) , Error > {
23+ pub trait Settable < T > : AsPtr < T > + AsMutPtr < T > {
24+ fn set < V : ' static > ( & mut self , name : & str , value : & V ) -> Result < ( ) , Error > {
3025 unsafe {
3126 let name = CString :: new ( name) . unwrap ( ) ;
3227
3328 check ! ( av_opt_set_bin(
34- self . as_mut_ptr( ) ,
29+ self . as_mut_ptr( ) as * mut _ ,
3530 name. as_ptr( ) ,
3631 value as * const _ as * const _,
37- mem:: size_of:: <T >( ) as c_int,
32+ mem:: size_of:: <V >( ) as c_int,
3833 AV_OPT_SEARCH_CHILDREN
3934 ) )
4035 }
@@ -46,7 +41,7 @@ pub trait Settable: Target {
4641 let value = CString :: new ( value) . unwrap ( ) ;
4742
4843 check ! ( av_opt_set(
49- self . as_mut_ptr( ) ,
44+ self . as_mut_ptr( ) as * mut _ ,
5045 name. as_ptr( ) ,
5146 value. as_ptr( ) ,
5247 AV_OPT_SEARCH_CHILDREN
@@ -59,7 +54,7 @@ pub trait Settable: Target {
5954 let name = CString :: new ( name) . unwrap ( ) ;
6055
6156 check ! ( av_opt_set_int(
62- self . as_mut_ptr( ) ,
57+ self . as_mut_ptr( ) as * mut _ ,
6358 name. as_ptr( ) ,
6459 value,
6560 AV_OPT_SEARCH_CHILDREN
@@ -72,20 +67,20 @@ pub trait Settable: Target {
7267 let name = CString :: new ( name) . unwrap ( ) ;
7368
7469 check ! ( av_opt_set_double(
75- self . as_mut_ptr( ) ,
70+ self . as_mut_ptr( ) as * mut _ ,
7671 name. as_ptr( ) ,
7772 value,
7873 AV_OPT_SEARCH_CHILDREN
7974 ) )
8075 }
8176 }
8277
83- fn set_rational < T : Into < Rational > > ( & mut self , name : & str , value : T ) -> Result < ( ) , Error > {
78+ fn set_rational < V : Into < Rational > > ( & mut self , name : & str , value : V ) -> Result < ( ) , Error > {
8479 unsafe {
8580 let name = CString :: new ( name) . unwrap ( ) ;
8681
8782 check ! ( av_opt_set_q(
88- self . as_mut_ptr( ) ,
83+ self . as_mut_ptr( ) as * mut _ ,
8984 name. as_ptr( ) ,
9085 value. into( ) . into( ) ,
9186 AV_OPT_SEARCH_CHILDREN
@@ -98,7 +93,7 @@ pub trait Settable: Target {
9893 let name = CString :: new ( name) . unwrap ( ) ;
9994
10095 check ! ( av_opt_set_image_size(
101- self . as_mut_ptr( ) ,
96+ self . as_mut_ptr( ) as * mut _ ,
10297 name. as_ptr( ) ,
10398 w as c_int,
10499 h as c_int,
@@ -112,7 +107,7 @@ pub trait Settable: Target {
112107 let name = CString :: new ( name) . unwrap ( ) ;
113108
114109 check ! ( av_opt_set_pixel_fmt(
115- self . as_mut_ptr( ) ,
110+ self . as_mut_ptr( ) as * mut _ ,
116111 name. as_ptr( ) ,
117112 format. into( ) ,
118113 AV_OPT_SEARCH_CHILDREN
@@ -125,7 +120,7 @@ pub trait Settable: Target {
125120 let name = CString :: new ( name) . unwrap ( ) ;
126121
127122 check ! ( av_opt_set_sample_fmt(
128- self . as_mut_ptr( ) ,
123+ self . as_mut_ptr( ) as * mut _ ,
129124 name. as_ptr( ) ,
130125 format. into( ) ,
131126 AV_OPT_SEARCH_CHILDREN
@@ -139,7 +134,7 @@ pub trait Settable: Target {
139134 let name = CString :: new ( name) . unwrap ( ) ;
140135
141136 check ! ( av_opt_set_channel_layout(
142- self . as_mut_ptr( ) ,
137+ self . as_mut_ptr( ) as * mut _ ,
143138 name. as_ptr( ) ,
144139 layout. bits( ) as i64 ,
145140 AV_OPT_SEARCH_CHILDREN
@@ -148,6 +143,6 @@ pub trait Settable: Target {
148143 }
149144}
150145
151- pub trait Gettable : Target { }
146+ pub trait Gettable < T > : AsPtr < T > + AsMutPtr < T > { }
152147
153- pub trait Iterable : Target { }
148+ pub trait Iterable < T > : AsPtr < T > + AsMutPtr < T > { }
0 commit comments