vp9_globals.h (9255B)
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 <cstddef> 20 21 #include "modules/video_coding/codecs/interface/common_constants.h" 22 #include "rtc_base/checks.h" 23 24 namespace webrtc { 25 26 const int16_t kMaxOneBytePictureId = 0x7F; // 7 bits 27 const int16_t kMaxTwoBytePictureId = 0x7FFF; // 15 bits 28 const uint8_t kNoSpatialIdx = 0xFF; 29 const uint8_t kNoGofIdx = 0xFF; 30 const uint8_t kNumVp9Buffers = 8; 31 const size_t kMaxVp9RefPics = 3; 32 const size_t kMaxVp9FramesInGof = 0xFF; // 8 bits 33 const size_t kMaxVp9NumberOfSpatialLayers = 8; 34 35 const int kMinVp9SpatialLayerLongSideLength = 240; 36 const int kMinVp9SpatialLayerShortSideLength = 135; 37 38 enum TemporalStructureMode { 39 kTemporalStructureMode1, // 1 temporal layer structure - i.e., IPPP... 40 kTemporalStructureMode2, // 2 temporal layers 01... 41 kTemporalStructureMode3, // 3 temporal layers 0212... 42 }; 43 44 struct GofInfoVP9 { 45 void SetGofInfoVP9(TemporalStructureMode tm) { 46 switch (tm) { 47 case kTemporalStructureMode1: 48 num_frames_in_gof = 1; 49 temporal_idx[0] = 0; 50 temporal_up_switch[0] = true; 51 num_ref_pics[0] = 1; 52 pid_diff[0][0] = 1; 53 break; 54 case kTemporalStructureMode2: 55 num_frames_in_gof = 2; 56 temporal_idx[0] = 0; 57 temporal_up_switch[0] = true; 58 num_ref_pics[0] = 1; 59 pid_diff[0][0] = 2; 60 61 temporal_idx[1] = 1; 62 temporal_up_switch[1] = true; 63 num_ref_pics[1] = 1; 64 pid_diff[1][0] = 1; 65 break; 66 case kTemporalStructureMode3: 67 num_frames_in_gof = 4; 68 temporal_idx[0] = 0; 69 temporal_up_switch[0] = true; 70 num_ref_pics[0] = 1; 71 pid_diff[0][0] = 4; 72 73 temporal_idx[1] = 2; 74 temporal_up_switch[1] = true; 75 num_ref_pics[1] = 1; 76 pid_diff[1][0] = 1; 77 78 temporal_idx[2] = 1; 79 temporal_up_switch[2] = true; 80 num_ref_pics[2] = 1; 81 pid_diff[2][0] = 2; 82 83 temporal_idx[3] = 2; 84 temporal_up_switch[3] = true; 85 num_ref_pics[3] = 1; 86 pid_diff[3][0] = 1; 87 break; 88 default: 89 RTC_DCHECK_NOTREACHED(); 90 } 91 } 92 93 void CopyGofInfoVP9(const GofInfoVP9& src) { 94 num_frames_in_gof = src.num_frames_in_gof; 95 for (size_t i = 0; i < num_frames_in_gof; ++i) { 96 temporal_idx[i] = src.temporal_idx[i]; 97 temporal_up_switch[i] = src.temporal_up_switch[i]; 98 num_ref_pics[i] = src.num_ref_pics[i]; 99 for (uint8_t r = 0; r < num_ref_pics[i]; ++r) { 100 pid_diff[i][r] = src.pid_diff[i][r]; 101 } 102 } 103 } 104 105 friend bool operator==(const GofInfoVP9& lhs, const GofInfoVP9& rhs) { 106 if (lhs.num_frames_in_gof != rhs.num_frames_in_gof || 107 lhs.pid_start != rhs.pid_start) 108 return false; 109 for (size_t i = 0; i < lhs.num_frames_in_gof; ++i) { 110 if (lhs.temporal_idx[i] != rhs.temporal_idx[i] || 111 lhs.temporal_up_switch[i] != rhs.temporal_up_switch[i] || 112 lhs.num_ref_pics[i] != rhs.num_ref_pics[i]) { 113 return false; 114 } 115 for (uint8_t r = 0; r < lhs.num_ref_pics[i]; ++r) { 116 if (lhs.pid_diff[i][r] != rhs.pid_diff[i][r]) 117 return false; 118 } 119 } 120 return true; 121 } 122 123 friend bool operator!=(const GofInfoVP9& lhs, const GofInfoVP9& rhs) { 124 return !(lhs == rhs); 125 } 126 127 size_t num_frames_in_gof; 128 uint8_t temporal_idx[kMaxVp9FramesInGof]; 129 bool temporal_up_switch[kMaxVp9FramesInGof]; 130 uint8_t num_ref_pics[kMaxVp9FramesInGof]; 131 uint8_t pid_diff[kMaxVp9FramesInGof][kMaxVp9RefPics]; 132 uint16_t pid_start; 133 }; 134 135 struct RTPVideoHeaderVP9 { 136 void InitRTPVideoHeaderVP9() { 137 inter_pic_predicted = false; 138 flexible_mode = false; 139 beginning_of_frame = false; 140 end_of_frame = false; 141 ss_data_available = false; 142 non_ref_for_inter_layer_pred = false; 143 picture_id = kNoPictureId; 144 max_picture_id = kMaxTwoBytePictureId; 145 tl0_pic_idx = kNoTl0PicIdx; 146 temporal_idx = kNoTemporalIdx; 147 spatial_idx = kNoSpatialIdx; 148 temporal_up_switch = false; 149 inter_layer_predicted = false; 150 gof_idx = kNoGofIdx; 151 num_ref_pics = 0; 152 num_spatial_layers = 1; 153 first_active_layer = 0; 154 end_of_picture = true; 155 } 156 157 friend bool operator==(const RTPVideoHeaderVP9& lhs, 158 const RTPVideoHeaderVP9& rhs) { 159 if (lhs.inter_pic_predicted != rhs.inter_pic_predicted || 160 lhs.flexible_mode != rhs.flexible_mode || 161 lhs.beginning_of_frame != rhs.beginning_of_frame || 162 lhs.end_of_frame != rhs.end_of_frame || 163 lhs.ss_data_available != rhs.ss_data_available || 164 lhs.non_ref_for_inter_layer_pred != rhs.non_ref_for_inter_layer_pred || 165 lhs.picture_id != rhs.picture_id || 166 lhs.max_picture_id != rhs.max_picture_id || 167 lhs.tl0_pic_idx != rhs.tl0_pic_idx || 168 lhs.temporal_idx != rhs.temporal_idx || 169 lhs.spatial_idx != rhs.spatial_idx || lhs.gof_idx != rhs.gof_idx || 170 lhs.temporal_up_switch != rhs.temporal_up_switch || 171 lhs.inter_layer_predicted != rhs.inter_layer_predicted || 172 lhs.num_ref_pics != rhs.num_ref_pics || 173 lhs.end_of_picture != rhs.end_of_picture) { 174 return false; 175 } 176 for (uint8_t i = 0; i < lhs.num_ref_pics; ++i) { 177 if (lhs.pid_diff[i] != rhs.pid_diff[i] || 178 lhs.ref_picture_id[i] != rhs.ref_picture_id[i]) { 179 return false; 180 } 181 } 182 if (lhs.ss_data_available) { 183 if (lhs.spatial_layer_resolution_present != 184 rhs.spatial_layer_resolution_present || 185 lhs.num_spatial_layers != rhs.num_spatial_layers || 186 lhs.first_active_layer != rhs.first_active_layer || 187 lhs.gof != rhs.gof) { 188 return false; 189 } 190 if (lhs.spatial_layer_resolution_present) { 191 for (size_t i = 0; i < lhs.num_spatial_layers; i++) { 192 if (lhs.width[i] != rhs.width[i] || lhs.height[i] != rhs.height[i]) { 193 return false; 194 } 195 } 196 } 197 } 198 return true; 199 } 200 201 friend bool operator!=(const RTPVideoHeaderVP9& lhs, 202 const RTPVideoHeaderVP9& rhs) { 203 return !(lhs == rhs); 204 } 205 206 bool inter_pic_predicted; // This layer frame is dependent on previously 207 // coded frame(s). 208 bool flexible_mode; // This frame is in flexible mode. 209 bool beginning_of_frame; // True if this packet is the first in a VP9 layer 210 // frame. 211 bool end_of_frame; // True if this packet is the last in a VP9 layer frame. 212 bool ss_data_available; // True if SS data is available in this payload 213 // descriptor. 214 bool non_ref_for_inter_layer_pred; // True for frame which is not used as 215 // reference for inter-layer prediction. 216 int16_t picture_id; // PictureID index, 15 bits; 217 // kNoPictureId if PictureID does not exist. 218 int16_t max_picture_id; // Maximum picture ID index; either 0x7F or 0x7FFF; 219 int16_t tl0_pic_idx; // TL0PIC_IDX, 8 bits; 220 // kNoTl0PicIdx means no value provided. 221 uint8_t temporal_idx; // Temporal layer index, or kNoTemporalIdx. 222 uint8_t spatial_idx; // Spatial layer index, or kNoSpatialIdx. 223 bool temporal_up_switch; // True if upswitch to higher frame rate is possible 224 // meaning subsequent higher temporal layer pictures 225 // will not depend on any picture before the current 226 // picture (in coding order) with temporal layer ID 227 // greater than `temporal_idx` of this frame. 228 bool inter_layer_predicted; // Frame is dependent on directly lower spatial 229 // layer frame. 230 231 uint8_t gof_idx; // Index to predefined temporal frame info in SS data. 232 233 uint8_t num_ref_pics; // Number of reference pictures used by this layer 234 // frame. 235 uint8_t pid_diff[kMaxVp9RefPics]; // P_DIFF signaled to derive the PictureID 236 // of the reference pictures. 237 int16_t ref_picture_id[kMaxVp9RefPics]; // PictureID of reference pictures. 238 239 // SS data. 240 size_t num_spatial_layers; // Always populated. 241 size_t first_active_layer; // Not sent on wire, used to adjust ss data. 242 bool spatial_layer_resolution_present; 243 uint16_t width[kMaxVp9NumberOfSpatialLayers]; 244 uint16_t height[kMaxVp9NumberOfSpatialLayers]; 245 GofInfoVP9 gof; 246 247 bool end_of_picture; // This frame is the last frame in picture. 248 }; 249 250 } // namespace webrtc 251 252 #endif // MODULES_VIDEO_CODING_CODECS_VP9_INCLUDE_VP9_GLOBALS_H_