xref: /aosp_15_r20/external/webrtc/modules/video_coding/codecs/vp9/include/vp9_globals.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1 /*
2  *  Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 // This file contains codec dependent definitions that are needed in
12 // order to compile the WebRTC codebase, even if this codec is not used.
13 
14 #ifndef MODULES_VIDEO_CODING_CODECS_VP9_INCLUDE_VP9_GLOBALS_H_
15 #define MODULES_VIDEO_CODING_CODECS_VP9_INCLUDE_VP9_GLOBALS_H_
16 
17 #include <stdint.h>
18 
19 #include "modules/video_coding/codecs/interface/common_constants.h"
20 #include "rtc_base/checks.h"
21 
22 namespace webrtc {
23 
24 const int16_t kMaxOneBytePictureId = 0x7F;    // 7 bits
25 const int16_t kMaxTwoBytePictureId = 0x7FFF;  // 15 bits
26 const uint8_t kNoSpatialIdx = 0xFF;
27 const uint8_t kNoGofIdx = 0xFF;
28 const uint8_t kNumVp9Buffers = 8;
29 const size_t kMaxVp9RefPics = 3;
30 const size_t kMaxVp9FramesInGof = 0xFF;  // 8 bits
31 const size_t kMaxVp9NumberOfSpatialLayers = 8;
32 
33 const size_t kMinVp9SpatialLayerLongSideLength = 240;
34 const size_t kMinVp9SpatialLayerShortSideLength = 135;
35 
36 enum TemporalStructureMode {
37   kTemporalStructureMode1,  // 1 temporal layer structure - i.e., IPPP...
38   kTemporalStructureMode2,  // 2 temporal layers 01...
39   kTemporalStructureMode3,  // 3 temporal layers 0212...
40 };
41 
42 struct GofInfoVP9 {
SetGofInfoVP9GofInfoVP943   void SetGofInfoVP9(TemporalStructureMode tm) {
44     switch (tm) {
45       case kTemporalStructureMode1:
46         num_frames_in_gof = 1;
47         temporal_idx[0] = 0;
48         temporal_up_switch[0] = true;
49         num_ref_pics[0] = 1;
50         pid_diff[0][0] = 1;
51         break;
52       case kTemporalStructureMode2:
53         num_frames_in_gof = 2;
54         temporal_idx[0] = 0;
55         temporal_up_switch[0] = true;
56         num_ref_pics[0] = 1;
57         pid_diff[0][0] = 2;
58 
59         temporal_idx[1] = 1;
60         temporal_up_switch[1] = true;
61         num_ref_pics[1] = 1;
62         pid_diff[1][0] = 1;
63         break;
64       case kTemporalStructureMode3:
65         num_frames_in_gof = 4;
66         temporal_idx[0] = 0;
67         temporal_up_switch[0] = true;
68         num_ref_pics[0] = 1;
69         pid_diff[0][0] = 4;
70 
71         temporal_idx[1] = 2;
72         temporal_up_switch[1] = true;
73         num_ref_pics[1] = 1;
74         pid_diff[1][0] = 1;
75 
76         temporal_idx[2] = 1;
77         temporal_up_switch[2] = true;
78         num_ref_pics[2] = 1;
79         pid_diff[2][0] = 2;
80 
81         temporal_idx[3] = 2;
82         temporal_up_switch[3] = true;
83         num_ref_pics[3] = 1;
84         pid_diff[3][0] = 1;
85         break;
86       default:
87         RTC_DCHECK_NOTREACHED();
88     }
89   }
90 
CopyGofInfoVP9GofInfoVP991   void CopyGofInfoVP9(const GofInfoVP9& src) {
92     num_frames_in_gof = src.num_frames_in_gof;
93     for (size_t i = 0; i < num_frames_in_gof; ++i) {
94       temporal_idx[i] = src.temporal_idx[i];
95       temporal_up_switch[i] = src.temporal_up_switch[i];
96       num_ref_pics[i] = src.num_ref_pics[i];
97       for (uint8_t r = 0; r < num_ref_pics[i]; ++r) {
98         pid_diff[i][r] = src.pid_diff[i][r];
99       }
100     }
101   }
102 
103   size_t num_frames_in_gof;
104   uint8_t temporal_idx[kMaxVp9FramesInGof];
105   bool temporal_up_switch[kMaxVp9FramesInGof];
106   uint8_t num_ref_pics[kMaxVp9FramesInGof];
107   uint8_t pid_diff[kMaxVp9FramesInGof][kMaxVp9RefPics];
108   uint16_t pid_start;
109 };
110 
111 struct RTPVideoHeaderVP9 {
InitRTPVideoHeaderVP9RTPVideoHeaderVP9112   void InitRTPVideoHeaderVP9() {
113     inter_pic_predicted = false;
114     flexible_mode = false;
115     beginning_of_frame = false;
116     end_of_frame = false;
117     ss_data_available = false;
118     non_ref_for_inter_layer_pred = false;
119     picture_id = kNoPictureId;
120     max_picture_id = kMaxTwoBytePictureId;
121     tl0_pic_idx = kNoTl0PicIdx;
122     temporal_idx = kNoTemporalIdx;
123     spatial_idx = kNoSpatialIdx;
124     temporal_up_switch = false;
125     inter_layer_predicted = false;
126     gof_idx = kNoGofIdx;
127     num_ref_pics = 0;
128     num_spatial_layers = 1;
129     first_active_layer = 0;
130     end_of_picture = true;
131   }
132 
133   bool inter_pic_predicted;  // This layer frame is dependent on previously
134                              // coded frame(s).
135   bool flexible_mode;        // This frame is in flexible mode.
136   bool beginning_of_frame;   // True if this packet is the first in a VP9 layer
137                              // frame.
138   bool end_of_frame;  // True if this packet is the last in a VP9 layer frame.
139   bool ss_data_available;  // True if SS data is available in this payload
140                            // descriptor.
141   bool non_ref_for_inter_layer_pred;  // True for frame which is not used as
142                                       // reference for inter-layer prediction.
143   int16_t picture_id;                 // PictureID index, 15 bits;
144                        // kNoPictureId if PictureID does not exist.
145   int16_t max_picture_id;   // Maximum picture ID index; either 0x7F or 0x7FFF;
146   int16_t tl0_pic_idx;      // TL0PIC_IDX, 8 bits;
147                             // kNoTl0PicIdx means no value provided.
148   uint8_t temporal_idx;     // Temporal layer index, or kNoTemporalIdx.
149   uint8_t spatial_idx;      // Spatial layer index, or kNoSpatialIdx.
150   bool temporal_up_switch;  // True if upswitch to higher frame rate is possible
151                             // meaning subsequent higher temporal layer pictures
152                             // will not depend on any picture before the current
153                             // picture (in coding order) with temporal layer ID
154                             // greater than `temporal_idx` of this frame.
155   bool inter_layer_predicted;  // Frame is dependent on directly lower spatial
156                                // layer frame.
157 
158   uint8_t gof_idx;  // Index to predefined temporal frame info in SS data.
159 
160   uint8_t num_ref_pics;  // Number of reference pictures used by this layer
161                          // frame.
162   uint8_t pid_diff[kMaxVp9RefPics];  // P_DIFF signaled to derive the PictureID
163                                      // of the reference pictures.
164   int16_t ref_picture_id[kMaxVp9RefPics];  // PictureID of reference pictures.
165 
166   // SS data.
167   size_t num_spatial_layers;  // Always populated.
168   size_t first_active_layer;  // Not sent on wire, used to adjust ss data.
169   bool spatial_layer_resolution_present;
170   uint16_t width[kMaxVp9NumberOfSpatialLayers];
171   uint16_t height[kMaxVp9NumberOfSpatialLayers];
172   GofInfoVP9 gof;
173 
174   bool end_of_picture;  // This frame is the last frame in picture.
175 };
176 
177 }  // namespace webrtc
178 
179 #endif  // MODULES_VIDEO_CODING_CODECS_VP9_INCLUDE_VP9_GLOBALS_H_
180