xref: /aosp_15_r20/external/libgav1/src/gav1/decoder_settings.h (revision 095378508e87ed692bf8dfeb34008b65b3735891)
1*09537850SAkhilesh Sanikop /*
2*09537850SAkhilesh Sanikop  * Copyright 2019 The libgav1 Authors
3*09537850SAkhilesh Sanikop  *
4*09537850SAkhilesh Sanikop  * Licensed under the Apache License, Version 2.0 (the "License");
5*09537850SAkhilesh Sanikop  * you may not use this file except in compliance with the License.
6*09537850SAkhilesh Sanikop  * You may obtain a copy of the License at
7*09537850SAkhilesh Sanikop  *
8*09537850SAkhilesh Sanikop  *      http://www.apache.org/licenses/LICENSE-2.0
9*09537850SAkhilesh Sanikop  *
10*09537850SAkhilesh Sanikop  * Unless required by applicable law or agreed to in writing, software
11*09537850SAkhilesh Sanikop  * distributed under the License is distributed on an "AS IS" BASIS,
12*09537850SAkhilesh Sanikop  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*09537850SAkhilesh Sanikop  * See the License for the specific language governing permissions and
14*09537850SAkhilesh Sanikop  * limitations under the License.
15*09537850SAkhilesh Sanikop  */
16*09537850SAkhilesh Sanikop 
17*09537850SAkhilesh Sanikop #ifndef LIBGAV1_SRC_GAV1_DECODER_SETTINGS_H_
18*09537850SAkhilesh Sanikop #define LIBGAV1_SRC_GAV1_DECODER_SETTINGS_H_
19*09537850SAkhilesh Sanikop 
20*09537850SAkhilesh Sanikop #if defined(__cplusplus)
21*09537850SAkhilesh Sanikop #include <cstdint>
22*09537850SAkhilesh Sanikop #else
23*09537850SAkhilesh Sanikop #include <stdint.h>
24*09537850SAkhilesh Sanikop #endif  // defined(__cplusplus)
25*09537850SAkhilesh Sanikop 
26*09537850SAkhilesh Sanikop #include "gav1/frame_buffer.h"
27*09537850SAkhilesh Sanikop #include "gav1/symbol_visibility.h"
28*09537850SAkhilesh Sanikop 
29*09537850SAkhilesh Sanikop // All the declarations in this file are part of the public ABI.
30*09537850SAkhilesh Sanikop 
31*09537850SAkhilesh Sanikop #if defined(__cplusplus)
32*09537850SAkhilesh Sanikop extern "C" {
33*09537850SAkhilesh Sanikop #endif
34*09537850SAkhilesh Sanikop 
35*09537850SAkhilesh Sanikop // This callback is invoked by the decoder when it is done using an input frame
36*09537850SAkhilesh Sanikop // buffer. When frame_parallel is set to true, this callback must not be
37*09537850SAkhilesh Sanikop // nullptr. Otherwise, this callback is optional.
38*09537850SAkhilesh Sanikop //
39*09537850SAkhilesh Sanikop // |buffer_private_data| is the value passed in the EnqueueFrame() call.
40*09537850SAkhilesh Sanikop typedef void (*Libgav1ReleaseInputBufferCallback)(void* callback_private_data,
41*09537850SAkhilesh Sanikop                                                   void* buffer_private_data);
42*09537850SAkhilesh Sanikop 
43*09537850SAkhilesh Sanikop typedef struct Libgav1DecoderSettings {
44*09537850SAkhilesh Sanikop   // Number of threads to use when decoding. Must be greater than 0. The library
45*09537850SAkhilesh Sanikop   // will create at most |threads| new threads. Defaults to 1 (no new threads
46*09537850SAkhilesh Sanikop   // will be created).
47*09537850SAkhilesh Sanikop   int threads;
48*09537850SAkhilesh Sanikop   // A boolean. Indicate to the decoder that frame parallel decoding is allowed.
49*09537850SAkhilesh Sanikop   // Note that this is just a request and the decoder will decide the number of
50*09537850SAkhilesh Sanikop   // frames to be decoded in parallel based on the video stream being decoded.
51*09537850SAkhilesh Sanikop   int frame_parallel;
52*09537850SAkhilesh Sanikop   // A boolean. In frame parallel mode, should Libgav1DecoderDequeueFrame wait
53*09537850SAkhilesh Sanikop   // until a enqueued frame is available for dequeueing.
54*09537850SAkhilesh Sanikop   //
55*09537850SAkhilesh Sanikop   // If frame_parallel is 0, this setting is ignored.
56*09537850SAkhilesh Sanikop   int blocking_dequeue;
57*09537850SAkhilesh Sanikop   // Called when the first sequence header or a sequence header with a
58*09537850SAkhilesh Sanikop   // different frame size (which includes bitdepth, monochrome, subsampling_x,
59*09537850SAkhilesh Sanikop   // subsampling_y, maximum frame width, or maximum frame height) is received.
60*09537850SAkhilesh Sanikop   Libgav1FrameBufferSizeChangedCallback on_frame_buffer_size_changed;
61*09537850SAkhilesh Sanikop   // Get frame buffer callback.
62*09537850SAkhilesh Sanikop   Libgav1GetFrameBufferCallback get_frame_buffer;
63*09537850SAkhilesh Sanikop   // Release frame buffer callback.
64*09537850SAkhilesh Sanikop   Libgav1ReleaseFrameBufferCallback release_frame_buffer;
65*09537850SAkhilesh Sanikop   // Release input frame buffer callback. This callback must be set when
66*09537850SAkhilesh Sanikop   // |frame_parallel| is true.
67*09537850SAkhilesh Sanikop   Libgav1ReleaseInputBufferCallback release_input_buffer;
68*09537850SAkhilesh Sanikop   // Passed as the private_data argument to the callbacks.
69*09537850SAkhilesh Sanikop   void* callback_private_data;
70*09537850SAkhilesh Sanikop   // A boolean. If set to 1, the decoder will output all the spatial and
71*09537850SAkhilesh Sanikop   // temporal layers.
72*09537850SAkhilesh Sanikop   int output_all_layers;
73*09537850SAkhilesh Sanikop   // Index of the operating point to decode.
74*09537850SAkhilesh Sanikop   int operating_point;
75*09537850SAkhilesh Sanikop   // Mask indicating the post processing filters that need to be applied to the
76*09537850SAkhilesh Sanikop   // reconstructed frame. Note this is an advanced setting and does not
77*09537850SAkhilesh Sanikop   // typically need to be changed.
78*09537850SAkhilesh Sanikop   // From LSB:
79*09537850SAkhilesh Sanikop   //   Bit 0: Loop filter (deblocking filter).
80*09537850SAkhilesh Sanikop   //   Bit 1: Cdef.
81*09537850SAkhilesh Sanikop   //   Bit 2: SuperRes.
82*09537850SAkhilesh Sanikop   //   Bit 3: Loop restoration.
83*09537850SAkhilesh Sanikop   //   Bit 4: Film grain synthesis.
84*09537850SAkhilesh Sanikop   //   All the bits other than the last 5 are ignored.
85*09537850SAkhilesh Sanikop   uint8_t post_filter_mask;
86*09537850SAkhilesh Sanikop } Libgav1DecoderSettings;
87*09537850SAkhilesh Sanikop 
88*09537850SAkhilesh Sanikop LIBGAV1_PUBLIC void Libgav1DecoderSettingsInitDefault(
89*09537850SAkhilesh Sanikop     Libgav1DecoderSettings* settings);
90*09537850SAkhilesh Sanikop 
91*09537850SAkhilesh Sanikop #if defined(__cplusplus)
92*09537850SAkhilesh Sanikop }  // extern "C"
93*09537850SAkhilesh Sanikop 
94*09537850SAkhilesh Sanikop namespace libgav1 {
95*09537850SAkhilesh Sanikop 
96*09537850SAkhilesh Sanikop using ReleaseInputBufferCallback = Libgav1ReleaseInputBufferCallback;
97*09537850SAkhilesh Sanikop 
98*09537850SAkhilesh Sanikop // Applications must populate this structure before creating a decoder instance.
99*09537850SAkhilesh Sanikop struct DecoderSettings {
100*09537850SAkhilesh Sanikop   // Number of threads to use when decoding. Must be greater than 0. The library
101*09537850SAkhilesh Sanikop   // will create at most |threads| new threads. Defaults to 1 (no new threads
102*09537850SAkhilesh Sanikop   // will be created).
103*09537850SAkhilesh Sanikop   int threads = 1;
104*09537850SAkhilesh Sanikop   // Indicate to the decoder that frame parallel decoding is allowed. Note that
105*09537850SAkhilesh Sanikop   // this is just a request and the decoder will decide the number of frames to
106*09537850SAkhilesh Sanikop   // be decoded in parallel based on the video stream being decoded.
107*09537850SAkhilesh Sanikop   bool frame_parallel = false;
108*09537850SAkhilesh Sanikop   // In frame parallel mode, should DequeueFrame wait until a enqueued frame is
109*09537850SAkhilesh Sanikop   // available for dequeueing.
110*09537850SAkhilesh Sanikop   //
111*09537850SAkhilesh Sanikop   // If frame_parallel is false, this setting is ignored.
112*09537850SAkhilesh Sanikop   bool blocking_dequeue = false;
113*09537850SAkhilesh Sanikop   // Called when the first sequence header or a sequence header with a
114*09537850SAkhilesh Sanikop   // different frame size (which includes bitdepth, monochrome, subsampling_x,
115*09537850SAkhilesh Sanikop   // subsampling_y, maximum frame width, or maximum frame height) is received.
116*09537850SAkhilesh Sanikop   FrameBufferSizeChangedCallback on_frame_buffer_size_changed = nullptr;
117*09537850SAkhilesh Sanikop   // Get frame buffer callback.
118*09537850SAkhilesh Sanikop   GetFrameBufferCallback get_frame_buffer = nullptr;
119*09537850SAkhilesh Sanikop   // Release frame buffer callback.
120*09537850SAkhilesh Sanikop   ReleaseFrameBufferCallback release_frame_buffer = nullptr;
121*09537850SAkhilesh Sanikop   // Release input frame buffer callback. This callback must be set when
122*09537850SAkhilesh Sanikop   // |frame_parallel| is true.
123*09537850SAkhilesh Sanikop   ReleaseInputBufferCallback release_input_buffer = nullptr;
124*09537850SAkhilesh Sanikop   // Passed as the private_data argument to the callbacks.
125*09537850SAkhilesh Sanikop   void* callback_private_data = nullptr;
126*09537850SAkhilesh Sanikop   // If set to true, the decoder will output all the spatial and temporal
127*09537850SAkhilesh Sanikop   // layers.
128*09537850SAkhilesh Sanikop   bool output_all_layers = false;
129*09537850SAkhilesh Sanikop   // Index of the operating point to decode.
130*09537850SAkhilesh Sanikop   int operating_point = 0;
131*09537850SAkhilesh Sanikop   // Mask indicating the post processing filters that need to be applied to the
132*09537850SAkhilesh Sanikop   // reconstructed frame. Note this is an advanced setting and does not
133*09537850SAkhilesh Sanikop   // typically need to be changed.
134*09537850SAkhilesh Sanikop   // From LSB:
135*09537850SAkhilesh Sanikop   //   Bit 0: Loop filter (deblocking filter).
136*09537850SAkhilesh Sanikop   //   Bit 1: Cdef.
137*09537850SAkhilesh Sanikop   //   Bit 2: SuperRes.
138*09537850SAkhilesh Sanikop   //   Bit 3: Loop restoration.
139*09537850SAkhilesh Sanikop   //   Bit 4: Film grain synthesis.
140*09537850SAkhilesh Sanikop   //   All the bits other than the last 5 are ignored.
141*09537850SAkhilesh Sanikop   uint8_t post_filter_mask = 0x1f;
142*09537850SAkhilesh Sanikop };
143*09537850SAkhilesh Sanikop 
144*09537850SAkhilesh Sanikop }  // namespace libgav1
145*09537850SAkhilesh Sanikop #endif  // defined(__cplusplus)
146*09537850SAkhilesh Sanikop #endif  // LIBGAV1_SRC_GAV1_DECODER_SETTINGS_H_
147