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