OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 // P,F: | P_DIFF |X|N| . has to be specified. | 99 // P,F: | P_DIFF |X|N| . has to be specified. |
100 // +-+-+-+-+-+-+-+-+ . up to 3 times | 100 // +-+-+-+-+-+-+-+-+ . up to 3 times |
101 // X: |EXTENDED P_DIFF| . X=1: Extended P_DIFF is used (14 | 101 // X: |EXTENDED P_DIFF| . X=1: Extended P_DIFF is used (14 |
102 // +-+-+-+-+-+-+-+-+ -| bits). Else 6 bits are used. | 102 // +-+-+-+-+-+-+-+-+ -| bits). Else 6 bits are used. |
103 // N=1: An additional P_DIFF follows | 103 // N=1: An additional P_DIFF follows |
104 // current P_DIFF. | 104 // current P_DIFF. |
105 size_t RefIndicesLength(const RTPVideoHeaderVP9& hdr) { | 105 size_t RefIndicesLength(const RTPVideoHeaderVP9& hdr) { |
106 if (!hdr.inter_pic_predicted || !hdr.flexible_mode) | 106 if (!hdr.inter_pic_predicted || !hdr.flexible_mode) |
107 return 0; | 107 return 0; |
108 | 108 |
109 DCHECK_GT(hdr.num_ref_pics, 0U); | 109 RTC_DCHECK_GT(hdr.num_ref_pics, 0U); |
110 DCHECK_LE(hdr.num_ref_pics, kMaxVp9RefPics); | 110 RTC_DCHECK_LE(hdr.num_ref_pics, kMaxVp9RefPics); |
111 size_t length = 0; | 111 size_t length = 0; |
112 for (size_t i = 0; i < hdr.num_ref_pics; ++i) { | 112 for (size_t i = 0; i < hdr.num_ref_pics; ++i) { |
113 length += hdr.pid_diff[i] > 0x3F ? 2 : 1; // P_DIFF > 6 bits => extended | 113 length += hdr.pid_diff[i] > 0x3F ? 2 : 1; // P_DIFF > 6 bits => extended |
114 } | 114 } |
115 return length; | 115 return length; |
116 } | 116 } |
117 | 117 |
118 // Scalability structure (SS). | 118 // Scalability structure (SS). |
119 // | 119 // |
120 // +-+-+-+-+-+-+-+-+ | 120 // +-+-+-+-+-+-+-+-+ |
121 // V: | N_S |Y| N_G | | 121 // V: | N_S |Y| N_G | |
122 // +-+-+-+-+-+-+-+-+ -| | 122 // +-+-+-+-+-+-+-+-+ -| |
123 // Y: | WIDTH | (OPTIONAL) . | 123 // Y: | WIDTH | (OPTIONAL) . |
124 // + + . | 124 // + + . |
125 // | | (OPTIONAL) . | 125 // | | (OPTIONAL) . |
126 // +-+-+-+-+-+-+-+-+ . N_S + 1 times | 126 // +-+-+-+-+-+-+-+-+ . N_S + 1 times |
127 // | HEIGHT | (OPTIONAL) . | 127 // | HEIGHT | (OPTIONAL) . |
128 // + + . | 128 // + + . |
129 // | | (OPTIONAL) . | 129 // | | (OPTIONAL) . |
130 // +-+-+-+-+-+-+-+-+ -| -| | 130 // +-+-+-+-+-+-+-+-+ -| -| |
131 // N_G: | T |U| R |-|-| (OPTIONAL) . | 131 // N_G: | T |U| R |-|-| (OPTIONAL) . |
132 // +-+-+-+-+-+-+-+-+ -| . N_G + 1 times | 132 // +-+-+-+-+-+-+-+-+ -| . N_G + 1 times |
133 // | P_DIFF | (OPTIONAL) . R times . | 133 // | P_DIFF | (OPTIONAL) . R times . |
134 // +-+-+-+-+-+-+-+-+ -| -| | 134 // +-+-+-+-+-+-+-+-+ -| -| |
135 // | 135 // |
136 size_t SsDataLength(const RTPVideoHeaderVP9& hdr) { | 136 size_t SsDataLength(const RTPVideoHeaderVP9& hdr) { |
137 if (!hdr.ss_data_available) | 137 if (!hdr.ss_data_available) |
138 return 0; | 138 return 0; |
139 | 139 |
140 DCHECK_GT(hdr.num_spatial_layers, 0U); | 140 RTC_DCHECK_GT(hdr.num_spatial_layers, 0U); |
141 DCHECK_LE(hdr.num_spatial_layers, kMaxVp9NumberOfSpatialLayers); | 141 RTC_DCHECK_LE(hdr.num_spatial_layers, kMaxVp9NumberOfSpatialLayers); |
142 DCHECK_GT(hdr.gof.num_frames_in_gof, 0U); | 142 RTC_DCHECK_GT(hdr.gof.num_frames_in_gof, 0U); |
143 DCHECK_LE(hdr.gof.num_frames_in_gof, kMaxVp9FramesInGof); | 143 RTC_DCHECK_LE(hdr.gof.num_frames_in_gof, kMaxVp9FramesInGof); |
144 size_t length = 1; // V | 144 size_t length = 1; // V |
145 if (hdr.spatial_layer_resolution_present) { | 145 if (hdr.spatial_layer_resolution_present) { |
146 length += 4 * hdr.num_spatial_layers; // Y | 146 length += 4 * hdr.num_spatial_layers; // Y |
147 } | 147 } |
148 // N_G | 148 // N_G |
149 length += hdr.gof.num_frames_in_gof; // T, U, R | 149 length += hdr.gof.num_frames_in_gof; // T, U, R |
150 for (size_t i = 0; i < hdr.gof.num_frames_in_gof; ++i) { | 150 for (size_t i = 0; i < hdr.gof.num_frames_in_gof; ++i) { |
151 DCHECK_LE(hdr.gof.num_ref_pics[i], kMaxVp9RefPics); | 151 RTC_DCHECK_LE(hdr.gof.num_ref_pics[i], kMaxVp9RefPics); |
152 length += hdr.gof.num_ref_pics[i]; // R times | 152 length += hdr.gof.num_ref_pics[i]; // R times |
153 } | 153 } |
154 return length; | 154 return length; |
155 } | 155 } |
156 | 156 |
157 size_t PayloadDescriptorLengthMinusSsData(const RTPVideoHeaderVP9& hdr) { | 157 size_t PayloadDescriptorLengthMinusSsData(const RTPVideoHeaderVP9& hdr) { |
158 return kFixedPayloadDescriptorBytes + PictureIdLength(hdr) + | 158 return kFixedPayloadDescriptorBytes + PictureIdLength(hdr) + |
159 LayerInfoLength(hdr) + RefIndicesLength(hdr); | 159 LayerInfoLength(hdr) + RefIndicesLength(hdr); |
160 } | 160 } |
161 | 161 |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 // | HEIGHT | (OPTIONAL) . | 279 // | HEIGHT | (OPTIONAL) . |
280 // + + . | 280 // + + . |
281 // | | (OPTIONAL) . | 281 // | | (OPTIONAL) . |
282 // +-+-+-+-+-+-+-+-+ -| -| | 282 // +-+-+-+-+-+-+-+-+ -| -| |
283 // N_G: | T |U| R |-|-| (OPTIONAL) . | 283 // N_G: | T |U| R |-|-| (OPTIONAL) . |
284 // +-+-+-+-+-+-+-+-+ -| . N_G + 1 times | 284 // +-+-+-+-+-+-+-+-+ -| . N_G + 1 times |
285 // | P_DIFF | (OPTIONAL) . R times . | 285 // | P_DIFF | (OPTIONAL) . R times . |
286 // +-+-+-+-+-+-+-+-+ -| -| | 286 // +-+-+-+-+-+-+-+-+ -| -| |
287 // | 287 // |
288 bool WriteSsData(const RTPVideoHeaderVP9& vp9, rtc::BitBufferWriter* writer) { | 288 bool WriteSsData(const RTPVideoHeaderVP9& vp9, rtc::BitBufferWriter* writer) { |
289 DCHECK_GT(vp9.num_spatial_layers, 0U); | 289 RTC_DCHECK_GT(vp9.num_spatial_layers, 0U); |
290 DCHECK_LE(vp9.num_spatial_layers, kMaxVp9NumberOfSpatialLayers); | 290 RTC_DCHECK_LE(vp9.num_spatial_layers, kMaxVp9NumberOfSpatialLayers); |
291 DCHECK_GT(vp9.gof.num_frames_in_gof, 0U); | 291 RTC_DCHECK_GT(vp9.gof.num_frames_in_gof, 0U); |
292 DCHECK_LE(vp9.gof.num_frames_in_gof, kMaxVp9FramesInGof); | 292 RTC_DCHECK_LE(vp9.gof.num_frames_in_gof, kMaxVp9FramesInGof); |
293 | 293 |
294 RETURN_FALSE_ON_ERROR(writer->WriteBits(vp9.num_spatial_layers - 1, 3)); | 294 RETURN_FALSE_ON_ERROR(writer->WriteBits(vp9.num_spatial_layers - 1, 3)); |
295 RETURN_FALSE_ON_ERROR( | 295 RETURN_FALSE_ON_ERROR( |
296 writer->WriteBits(vp9.spatial_layer_resolution_present ? 1 : 0, 1)); | 296 writer->WriteBits(vp9.spatial_layer_resolution_present ? 1 : 0, 1)); |
297 RETURN_FALSE_ON_ERROR(writer->WriteBits(vp9.gof.num_frames_in_gof - 1, 4)); | 297 RETURN_FALSE_ON_ERROR(writer->WriteBits(vp9.gof.num_frames_in_gof - 1, 4)); |
298 | 298 |
299 if (vp9.spatial_layer_resolution_present) { | 299 if (vp9.spatial_layer_resolution_present) { |
300 for (size_t i = 0; i < vp9.num_spatial_layers; ++i) { | 300 for (size_t i = 0; i < vp9.num_spatial_layers; ++i) { |
301 RETURN_FALSE_ON_ERROR(writer->WriteUInt16(vp9.width[i])); | 301 RETURN_FALSE_ON_ERROR(writer->WriteUInt16(vp9.width[i])); |
302 RETURN_FALSE_ON_ERROR(writer->WriteUInt16(vp9.height[i])); | 302 RETURN_FALSE_ON_ERROR(writer->WriteUInt16(vp9.height[i])); |
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
756 if (parsed_payload->payload_length == 0) { | 756 if (parsed_payload->payload_length == 0) { |
757 LOG(LS_ERROR) << "Failed parsing VP9 payload data."; | 757 LOG(LS_ERROR) << "Failed parsing VP9 payload data."; |
758 return false; | 758 return false; |
759 } | 759 } |
760 parsed_payload->payload = | 760 parsed_payload->payload = |
761 payload + payload_length - parsed_payload->payload_length; | 761 payload + payload_length - parsed_payload->payload_length; |
762 | 762 |
763 return true; | 763 return true; |
764 } | 764 } |
765 } // namespace webrtc | 765 } // namespace webrtc |
OLD | NEW |