@@ -29,12 +29,9 @@ use core::fmt;
2929#[ derive( Clone ) ]
3030#[ non_exhaustive]
3131pub struct DecodedFrame {
32- /// RGBA pixel data (4 bytes per pixel)
33- pub data : Vec < u8 > ,
34- /// Frame width in pixels
35- pub width : u32 ,
36- /// Frame height in pixels
37- pub height : u32 ,
32+ data : Vec < u8 > ,
33+ width : u32 ,
34+ height : u32 ,
3835}
3936
4037impl DecodedFrame {
@@ -50,6 +47,26 @@ impl DecodedFrame {
5047 ) ;
5148 Self { data, width, height }
5249 }
50+
51+ /// RGBA pixel data (4 bytes per pixel).
52+ pub fn data ( & self ) -> & [ u8 ] {
53+ & self . data
54+ }
55+
56+ /// Frame width in pixels.
57+ pub fn width ( & self ) -> u32 {
58+ self . width
59+ }
60+
61+ /// Frame height in pixels.
62+ pub fn height ( & self ) -> u32 {
63+ self . height
64+ }
65+
66+ /// Consume the frame and return the owned RGBA buffer.
67+ pub fn into_data ( self ) -> Vec < u8 > {
68+ self . data
69+ }
5370}
5471
5572impl fmt:: Debug for DecodedFrame {
@@ -286,11 +303,7 @@ mod openh264_impl {
286303 let mut rgba = vec ! [ 0u8 ; rgba_size] ;
287304 yuv. write_rgba8 ( & mut rgba) ;
288305
289- Ok ( DecodedFrame {
290- data : rgba,
291- width : w32,
292- height : h32,
293- } )
306+ Ok ( DecodedFrame :: new ( rgba, w32, h32) )
294307 }
295308
296309 fn reset ( & mut self ) {
@@ -309,3 +322,24 @@ mod openh264_impl {
309322
310323#[ cfg( feature = "openh264" ) ]
311324pub use openh264_impl:: OpenH264Decoder ;
325+
326+ #[ cfg( test) ]
327+ mod tests {
328+ use super :: DecodedFrame ;
329+
330+ #[ test]
331+ fn getters_return_constructor_inputs ( ) {
332+ let data = vec ! [ 0u8 ; 2 * 3 * 4 ] ;
333+ let frame = DecodedFrame :: new ( data. clone ( ) , 2 , 3 ) ;
334+ assert_eq ! ( frame. data( ) , data. as_slice( ) ) ;
335+ assert_eq ! ( frame. width( ) , 2 ) ;
336+ assert_eq ! ( frame. height( ) , 3 ) ;
337+ }
338+
339+ #[ test]
340+ fn into_data_yields_owned_buffer ( ) {
341+ let data = vec ! [ 0xAAu8 ; 4 * 4 * 4 ] ;
342+ let frame = DecodedFrame :: new ( data. clone ( ) , 4 , 4 ) ;
343+ assert_eq ! ( frame. into_data( ) , data) ;
344+ }
345+ }
0 commit comments