1 // Copyright 2024 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #[cfg(feature = "dav1d")]
16 pub mod dav1d;
17 
18 #[cfg(feature = "libgav1")]
19 pub mod libgav1;
20 
21 #[cfg(feature = "android_mediacodec")]
22 pub mod android_mediacodec;
23 
24 use crate::decoder::Category;
25 use crate::image::Image;
26 use crate::parser::mp4box::CodecConfiguration;
27 use crate::AndroidMediaCodecOutputColorFormat;
28 use crate::AvifResult;
29 
30 #[derive(Clone, Default)]
31 pub struct DecoderConfig {
32     pub operating_point: u8,
33     pub all_layers: bool,
34     pub width: u32,
35     pub height: u32,
36     pub depth: u8,
37     pub max_threads: u32,
38     pub max_input_size: usize,
39     pub codec_config: CodecConfiguration,
40     pub category: Category,
41     pub android_mediacodec_output_color_format: AndroidMediaCodecOutputColorFormat,
42 }
43 
44 pub trait Decoder {
initialize(&mut self, config: &DecoderConfig) -> AvifResult<()>45     fn initialize(&mut self, config: &DecoderConfig) -> AvifResult<()>;
get_next_image( &mut self, av1_payload: &[u8], spatial_id: u8, image: &mut Image, category: Category, ) -> AvifResult<()>46     fn get_next_image(
47         &mut self,
48         av1_payload: &[u8],
49         spatial_id: u8,
50         image: &mut Image,
51         category: Category,
52     ) -> AvifResult<()>;
53     // Destruction must be implemented using Drop.
54 }
55