Line data Source code
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 WEBRTC_MODULES_VIDEO_CODING_CODECS_VP9_INCLUDE_VP9_GLOBALS_H_
15 : #define WEBRTC_MODULES_VIDEO_CODING_CODECS_VP9_INCLUDE_VP9_GLOBALS_H_
16 :
17 : #include "webrtc/modules/video_coding/codecs/interface/common_constants.h"
18 :
19 : namespace webrtc {
20 :
21 : const int16_t kMaxOneBytePictureId = 0x7F; // 7 bits
22 : const int16_t kMaxTwoBytePictureId = 0x7FFF; // 15 bits
23 : const uint8_t kNoSpatialIdx = 0xFF;
24 : const uint8_t kNoGofIdx = 0xFF;
25 : const uint8_t kNumVp9Buffers = 8;
26 : const size_t kMaxVp9RefPics = 3;
27 : const size_t kMaxVp9FramesInGof = 0xFF; // 8 bits
28 : const size_t kMaxVp9NumberOfSpatialLayers = 8;
29 :
30 : enum TemporalStructureMode {
31 : kTemporalStructureMode1, // 1 temporal layer structure - i.e., IPPP...
32 : kTemporalStructureMode2, // 2 temporal layers 01...
33 : kTemporalStructureMode3, // 3 temporal layers 0212...
34 : kTemporalStructureMode4 // 3 temporal layers 02120212...
35 : };
36 :
37 : struct GofInfoVP9 {
38 0 : void SetGofInfoVP9(TemporalStructureMode tm) {
39 0 : switch (tm) {
40 : case kTemporalStructureMode1:
41 0 : num_frames_in_gof = 1;
42 0 : temporal_idx[0] = 0;
43 0 : temporal_up_switch[0] = false;
44 0 : num_ref_pics[0] = 1;
45 0 : pid_diff[0][0] = 1;
46 0 : break;
47 : case kTemporalStructureMode2:
48 0 : num_frames_in_gof = 2;
49 0 : temporal_idx[0] = 0;
50 0 : temporal_up_switch[0] = false;
51 0 : num_ref_pics[0] = 1;
52 0 : pid_diff[0][0] = 2;
53 :
54 0 : temporal_idx[1] = 1;
55 0 : temporal_up_switch[1] = true;
56 0 : num_ref_pics[1] = 1;
57 0 : pid_diff[1][0] = 1;
58 0 : break;
59 : case kTemporalStructureMode3:
60 0 : num_frames_in_gof = 4;
61 0 : temporal_idx[0] = 0;
62 0 : temporal_up_switch[0] = false;
63 0 : num_ref_pics[0] = 1;
64 0 : pid_diff[0][0] = 4;
65 :
66 0 : temporal_idx[1] = 2;
67 0 : temporal_up_switch[1] = true;
68 0 : num_ref_pics[1] = 1;
69 0 : pid_diff[1][0] = 1;
70 :
71 0 : temporal_idx[2] = 1;
72 0 : temporal_up_switch[2] = true;
73 0 : num_ref_pics[2] = 1;
74 0 : pid_diff[2][0] = 2;
75 :
76 0 : temporal_idx[3] = 2;
77 0 : temporal_up_switch[3] = false;
78 0 : num_ref_pics[3] = 2;
79 0 : pid_diff[3][0] = 1;
80 0 : pid_diff[3][1] = 2;
81 0 : break;
82 : case kTemporalStructureMode4:
83 0 : num_frames_in_gof = 8;
84 0 : temporal_idx[0] = 0;
85 0 : temporal_up_switch[0] = false;
86 0 : num_ref_pics[0] = 1;
87 0 : pid_diff[0][0] = 4;
88 :
89 0 : temporal_idx[1] = 2;
90 0 : temporal_up_switch[1] = true;
91 0 : num_ref_pics[1] = 1;
92 0 : pid_diff[1][0] = 1;
93 :
94 0 : temporal_idx[2] = 1;
95 0 : temporal_up_switch[2] = true;
96 0 : num_ref_pics[2] = 1;
97 0 : pid_diff[2][0] = 2;
98 :
99 0 : temporal_idx[3] = 2;
100 0 : temporal_up_switch[3] = false;
101 0 : num_ref_pics[3] = 2;
102 0 : pid_diff[3][0] = 1;
103 0 : pid_diff[3][1] = 2;
104 :
105 0 : temporal_idx[4] = 0;
106 0 : temporal_up_switch[0] = false;
107 0 : num_ref_pics[4] = 1;
108 0 : pid_diff[4][0] = 4;
109 :
110 0 : temporal_idx[5] = 2;
111 0 : temporal_up_switch[1] = false;
112 0 : num_ref_pics[5] = 2;
113 0 : pid_diff[5][0] = 1;
114 0 : pid_diff[5][1] = 2;
115 :
116 0 : temporal_idx[6] = 1;
117 0 : temporal_up_switch[2] = false;
118 0 : num_ref_pics[6] = 2;
119 0 : pid_diff[6][0] = 2;
120 0 : pid_diff[6][1] = 4;
121 :
122 0 : temporal_idx[7] = 2;
123 0 : temporal_up_switch[3] = false;
124 0 : num_ref_pics[7] = 2;
125 0 : pid_diff[7][0] = 1;
126 0 : pid_diff[7][1] = 2;
127 0 : break;
128 : default:
129 0 : assert(false);
130 : }
131 0 : }
132 :
133 0 : void CopyGofInfoVP9(const GofInfoVP9& src) {
134 0 : num_frames_in_gof = src.num_frames_in_gof;
135 0 : for (size_t i = 0; i < num_frames_in_gof; ++i) {
136 0 : temporal_idx[i] = src.temporal_idx[i];
137 0 : temporal_up_switch[i] = src.temporal_up_switch[i];
138 0 : num_ref_pics[i] = src.num_ref_pics[i];
139 0 : for (uint8_t r = 0; r < num_ref_pics[i]; ++r) {
140 0 : pid_diff[i][r] = src.pid_diff[i][r];
141 : }
142 : }
143 0 : }
144 :
145 : size_t num_frames_in_gof;
146 : uint8_t temporal_idx[kMaxVp9FramesInGof];
147 : bool temporal_up_switch[kMaxVp9FramesInGof];
148 : uint8_t num_ref_pics[kMaxVp9FramesInGof];
149 : uint8_t pid_diff[kMaxVp9FramesInGof][kMaxVp9RefPics];
150 : uint16_t pid_start;
151 : };
152 :
153 : struct RTPVideoHeaderVP9 {
154 0 : void InitRTPVideoHeaderVP9() {
155 0 : inter_pic_predicted = false;
156 0 : flexible_mode = false;
157 0 : beginning_of_frame = false;
158 0 : end_of_frame = false;
159 0 : ss_data_available = false;
160 0 : picture_id = kNoPictureId;
161 0 : max_picture_id = kMaxTwoBytePictureId;
162 0 : tl0_pic_idx = kNoTl0PicIdx;
163 0 : temporal_idx = kNoTemporalIdx;
164 0 : spatial_idx = kNoSpatialIdx;
165 0 : temporal_up_switch = false;
166 0 : inter_layer_predicted = false;
167 0 : gof_idx = kNoGofIdx;
168 0 : num_ref_pics = 0;
169 0 : num_spatial_layers = 1;
170 0 : }
171 :
172 : bool inter_pic_predicted; // This layer frame is dependent on previously
173 : // coded frame(s).
174 : bool flexible_mode; // This frame is in flexible mode.
175 : bool beginning_of_frame; // True if this packet is the first in a VP9 layer
176 : // frame.
177 : bool end_of_frame; // True if this packet is the last in a VP9 layer frame.
178 : bool ss_data_available; // True if SS data is available in this payload
179 : // descriptor.
180 : int16_t picture_id; // PictureID index, 15 bits;
181 : // kNoPictureId if PictureID does not exist.
182 : int16_t max_picture_id; // Maximum picture ID index; either 0x7F or 0x7FFF;
183 : int16_t tl0_pic_idx; // TL0PIC_IDX, 8 bits;
184 : // kNoTl0PicIdx means no value provided.
185 : uint8_t temporal_idx; // Temporal layer index, or kNoTemporalIdx.
186 : uint8_t spatial_idx; // Spatial layer index, or kNoSpatialIdx.
187 : bool temporal_up_switch; // True if upswitch to higher frame rate is possible
188 : // starting from this frame.
189 : bool inter_layer_predicted; // Frame is dependent on directly lower spatial
190 : // layer frame.
191 :
192 : uint8_t gof_idx; // Index to predefined temporal frame info in SS data.
193 :
194 : uint8_t num_ref_pics; // Number of reference pictures used by this layer
195 : // frame.
196 : uint8_t pid_diff[kMaxVp9RefPics]; // P_DIFF signaled to derive the PictureID
197 : // of the reference pictures.
198 : int16_t ref_picture_id[kMaxVp9RefPics]; // PictureID of reference pictures.
199 :
200 : // SS data.
201 : size_t num_spatial_layers; // Always populated.
202 : bool spatial_layer_resolution_present;
203 : uint16_t width[kMaxVp9NumberOfSpatialLayers];
204 : uint16_t height[kMaxVp9NumberOfSpatialLayers];
205 : GofInfoVP9 gof;
206 : };
207 :
208 : } // namespace webrtc
209 :
210 : #endif // WEBRTC_MODULES_VIDEO_CODING_CODECS_VP9_INCLUDE_VP9_GLOBALS_H_
|