@@ -100,6 +100,21 @@ pub enum EncoderStatus {
100
100
NotReady = -2 ,
101
101
}
102
102
103
+ impl EncoderStatus {
104
+ fn to_c ( & self ) -> * const u8 {
105
+ use self :: EncoderStatus :: * ;
106
+ match self {
107
+ Success => "Normal operation\0 " . as_ptr ( ) ,
108
+ NeedMoreData => "The encoder needs more data to produce an output packet\0 " . as_ptr ( ) ,
109
+ EnoughData => "There are enough frames in the queue\0 " . as_ptr ( ) ,
110
+ LimitReached => "The encoder has already produced the number of frames requested\0 " . as_ptr ( ) ,
111
+ Encoded => "A Frame had been encoded but not emitted yet\0 " . as_ptr ( ) ,
112
+ Failure => "Generic fatal error\0 " . as_ptr ( ) ,
113
+ NotReady => "First-pass stats data not retrieved or not enough second-pass data provided\0 " . as_ptr ( ) ,
114
+ }
115
+ }
116
+ }
117
+
103
118
impl From < Option < rav1e:: EncoderStatus > > for EncoderStatus {
104
119
fn from ( status : Option < rav1e:: EncoderStatus > ) -> Self {
105
120
match status {
@@ -701,28 +716,17 @@ pub unsafe extern fn rav1e_last_status(ctx: *const Context) -> EncoderStatus {
701
716
( * ctx) . last_err . into ( )
702
717
}
703
718
704
- /// Return a string matching the EncoderStatus variant.
719
+ /// Return a static string matching the EncoderStatus variant.
705
720
///
706
- /// Must be freed with free().
707
721
#[ no_mangle]
708
722
pub unsafe extern fn rav1e_status_to_str (
709
723
status : EncoderStatus ,
710
- ) -> * mut c_char {
724
+ ) -> * const c_char {
711
725
if EncoderStatus :: from_i32 ( std:: mem:: transmute ( status) ) . is_none ( ) {
712
- return std:: ptr:: null_mut ( ) ;
713
- }
714
-
715
- let status = format ! ( "{:?}" , status) ;
716
- let cbuf = CString :: new ( status) . unwrap ( ) ;
717
- let len = cbuf. as_bytes_with_nul ( ) . len ( ) ;
718
- let ret = libc:: malloc ( len) ;
719
-
720
- if !ret. is_null ( ) {
721
- let cptr = cbuf. as_ptr ( ) as * const libc:: c_void ;
722
- libc:: memcpy ( ret, cptr, len) ;
726
+ return std:: ptr:: null ( ) ;
723
727
}
724
728
725
- ret as * mut c_char
729
+ status . to_c ( ) as * const c_char
726
730
}
727
731
728
732
/// Receive encoded data
0 commit comments