@@ -12,11 +12,12 @@ use ffmpeg_the_third::ffi::{
1212use ffmpeg_the_third:: packet:: { Borrow , Ref } ;
1313use ffmpeg_the_third:: { Frame , decoder, packet:: Packet } ;
1414use nokhwa_core:: codec:: Codec ;
15- use nokhwa_core:: decoder:: { Decoder , ImageBuffer , Pixel , Primitive } ;
15+ use nokhwa_core:: decoder:: { ConfigHasResolution , Decoder , Pixel } ;
1616use nokhwa_core:: error:: NokhwaError ;
1717use nokhwa_core:: frame_buffer:: FrameBuffer ;
1818use nokhwa_core:: frame_format:: { CustomFrameFormat , FrameFormat } ;
19- use nokhwa_core:: image:: { DecodedImage , NonFloatScalarWidth } ;
19+ use nokhwa_core:: image:: { NonFloatScalarWidth } ;
20+ use nokhwa_core:: pixel_destination:: PixelDestination ;
2021use nokhwa_core:: types:: { CameraFormat , FrameRate , Resolution } ;
2122
2223pub struct FfmpegDecoder {
@@ -56,7 +57,8 @@ impl FfmpegDecoder {
5657impl Decoder for FfmpegDecoder {
5758 type Config = <FfmpegCodec as Codec >:: Config ;
5859 type OutputMeta = <FfmpegCodec as Codec >:: WrittenMeta ;
59- type DestinationFormatHint = AVPixelFormat ;
60+ const SUPPORTED_DESTINATIONS : & ' static [ PixelDestination ] = & [ ] ;
61+
6062
6163 fn config ( & self ) -> & Self :: Config {
6264 self . codec . config ( )
@@ -71,7 +73,7 @@ impl Decoder for FfmpegDecoder {
7173 & mut self ,
7274 to_decode : FrameBuffer ,
7375 mut buffer : impl AsMut < [ u8 ] > ,
74- _destination_format : Option < Self :: DestinationFormatHint > ,
76+ _destination_format : PixelDestination ,
7577 ) -> Result < Self :: OutputMeta , NokhwaError > {
7678 // TODO: add an extra zippy happy path for rgb/bgr/luma
7779 let ( frame, metadata) = self . receive_decoded_frame ( to_decode) ?;
@@ -188,54 +190,6 @@ impl Decoder for FfmpegDecoder {
188190 Ok ( decoded_meta)
189191 }
190192 }
191-
192- fn decode < P : Pixel > (
193- & mut self ,
194- to_decode : FrameBuffer ,
195- ) -> Result < DecodedImage < P , Self :: OutputMeta > , NokhwaError >
196- where
197- <P as Pixel >:: Subpixel : NonFloatScalarWidth ,
198- {
199- let min_size = self . output_decoder_min_size_pixel :: < P > ( self . config ( ) . resolution ) ;
200- let mut buffer: Vec < P :: Subpixel > = vec ! [ <P :: Subpixel >:: DEFAULT_MIN_VALUE ; min_size] ;
201- let meta = self . decode_to_buffer (
202- to_decode,
203- try_cast_slice_mut ( & mut buffer)
204- . map_err ( |why| NokhwaError :: DecoderInvalidBuffer ( why. to_string ( ) ) ) ?,
205- None ,
206- ) ?;
207- Ok ( DecodedImage :: new (
208- ImageBuffer :: from_vec (
209- self . codec . config . resolution . width ( ) ,
210- self . codec . config . resolution . height ( ) ,
211- buffer,
212- )
213- . ok_or ( NokhwaError :: Decoder (
214- "Failed to create Image Buffer" . to_string ( ) ,
215- ) ) ?,
216- meta,
217- ) )
218- }
219-
220- fn output_decoder_min_size (
221- & self ,
222- resolution : Resolution ,
223- destination_format : Self :: DestinationFormatHint ,
224- ) -> usize {
225- let size = unsafe {
226- av_image_get_buffer_size (
227- destination_format,
228- resolution. width ( ) as i32 ,
229- resolution. height ( ) as i32 ,
230- 1 ,
231- )
232- } ;
233- size as usize
234- }
235-
236- fn buffer_takes_destination_hint ( & self ) -> bool {
237- false
238- }
239193}
240194
241195fn create_sws_context (
@@ -261,53 +215,6 @@ fn create_sws_context(
261215 Ok ( new_sws)
262216}
263217
264- fn pixel_to_destination_px_fmt < P : Pixel > ( ) -> Option < AVPixelFormat >
265- where
266- <P as Pixel >:: Subpixel : NonFloatScalarWidth ,
267- {
268- match P :: COLOR_MODEL {
269- "RGB" => match <<P as Pixel >:: Subpixel >:: WIDTH_BYTES {
270- 1 => Some ( AVPixelFormat :: AV_PIX_FMT_RGB24 ) ,
271- _ => None ,
272- } ,
273-
274- "RGBA" => match <<P as Pixel >:: Subpixel >:: WIDTH_BYTES {
275- 1 => Some ( AVPixelFormat :: AV_PIX_FMT_RGBA ) ,
276- 2 => Some ( switch_endian (
277- AVPixelFormat :: AV_PIX_FMT_RGBA64LE ,
278- AVPixelFormat :: AV_PIX_FMT_RGBA64BE ,
279- ) ) ,
280- _ => None ,
281- } ,
282- "BGR" => match <<P as Pixel >:: Subpixel >:: WIDTH_BYTES {
283- 1 => Some ( AVPixelFormat :: AV_PIX_FMT_BGR24 ) ,
284- _ => None ,
285- } ,
286-
287- "BGRA" => match <<P as Pixel >:: Subpixel >:: WIDTH_BYTES {
288- 1 => Some ( AVPixelFormat :: AV_PIX_FMT_BGRA ) ,
289- 2 => Some ( switch_endian (
290- AVPixelFormat :: AV_PIX_FMT_BGRA64LE ,
291- AVPixelFormat :: AV_PIX_FMT_BGRA64BE ,
292- ) ) ,
293- _ => None ,
294- } ,
295- "Y" => match <<P as Pixel >:: Subpixel >:: WIDTH_BYTES {
296- 1 => Some ( AVPixelFormat :: AV_PIX_FMT_GRAY8 ) ,
297- 2 => Some ( switch_endian (
298- AVPixelFormat :: AV_PIX_FMT_GRAY16LE ,
299- AVPixelFormat :: AV_PIX_FMT_GRAY16BE ,
300- ) ) ,
301- _ => None ,
302- } ,
303- "YA" => match <<P as Pixel >:: Subpixel >:: WIDTH_BYTES {
304- 1 => Some ( AVPixelFormat :: AV_PIX_FMT_GRAY8A ) ,
305- _ => None ,
306- } ,
307- _ => None ,
308- }
309- }
310-
311218pub struct Sws {
312219 pub sws : * mut SwsContext ,
313220 pub source_pixel_format : AVPixelFormat ,
@@ -686,6 +593,12 @@ pub struct FfmpegDecoderConfig {
686593 pub video_delay : i32 ,
687594}
688595
596+ impl ConfigHasResolution for FfmpegDecoderConfig {
597+ fn resolution ( & self ) -> Resolution {
598+ self . resolution
599+ }
600+ }
601+
689602impl FfmpegDecoderConfig {
690603 pub fn with_camera_format ( camera_format : & CameraFormat ) -> Self {
691604 FfmpegDecoderConfig :: from ( * camera_format)
0 commit comments