Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(27)

Side by Side Diff: webrtc/modules/rtp_rtcp/source/rtp_format_vp9.cc

Issue 1411923004: Update scalability structure data according to updates in the RTP payload profile. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
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|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 // G: | N_G | (OPTIONAL)
132 // +-+-+-+-+-+-+-+-+ -|
131 // N_G: | T |U| R |-|-| (OPTIONAL) . 133 // N_G: | T |U| R |-|-| (OPTIONAL) .
132 // +-+-+-+-+-+-+-+-+ -| . N_G + 1 times 134 // +-+-+-+-+-+-+-+-+ -| . N_G times
133 // | P_DIFF | (OPTIONAL) . R times . 135 // | P_DIFF | (OPTIONAL) . R times .
134 // +-+-+-+-+-+-+-+-+ -| -| 136 // +-+-+-+-+-+-+-+-+ -| -|
135 // 137 //
136 size_t SsDataLength(const RTPVideoHeaderVP9& hdr) { 138 size_t SsDataLength(const RTPVideoHeaderVP9& hdr) {
137 if (!hdr.ss_data_available) 139 if (!hdr.ss_data_available)
138 return 0; 140 return 0;
139 141
140 RTC_DCHECK_GT(hdr.num_spatial_layers, 0U); 142 RTC_DCHECK_GT(hdr.num_spatial_layers, 0U);
141 RTC_DCHECK_LE(hdr.num_spatial_layers, kMaxVp9NumberOfSpatialLayers); 143 RTC_DCHECK_LE(hdr.num_spatial_layers, kMaxVp9NumberOfSpatialLayers);
142 RTC_DCHECK_GT(hdr.gof.num_frames_in_gof, 0U);
143 RTC_DCHECK_LE(hdr.gof.num_frames_in_gof, kMaxVp9FramesInGof); 144 RTC_DCHECK_LE(hdr.gof.num_frames_in_gof, kMaxVp9FramesInGof);
144 size_t length = 1; // V 145 size_t length = 1; // V
145 if (hdr.spatial_layer_resolution_present) { 146 if (hdr.spatial_layer_resolution_present) {
146 length += 4 * hdr.num_spatial_layers; // Y 147 length += 4 * hdr.num_spatial_layers; // Y
147 } 148 }
149 if (hdr.gof.num_frames_in_gof > 0) {
150 ++length; // G
151 }
148 // N_G 152 // N_G
149 length += hdr.gof.num_frames_in_gof; // T, U, R 153 length += hdr.gof.num_frames_in_gof; // T, U, R
150 for (size_t i = 0; i < hdr.gof.num_frames_in_gof; ++i) { 154 for (size_t i = 0; i < hdr.gof.num_frames_in_gof; ++i) {
151 RTC_DCHECK_LE(hdr.gof.num_ref_pics[i], kMaxVp9RefPics); 155 RTC_DCHECK_LE(hdr.gof.num_ref_pics[i], kMaxVp9RefPics);
152 length += hdr.gof.num_ref_pics[i]; // R times 156 length += hdr.gof.num_ref_pics[i]; // R times
153 } 157 }
154 return length; 158 return length;
155 } 159 }
156 160
157 size_t PayloadDescriptorLengthMinusSsData(const RTPVideoHeaderVP9& hdr) { 161 size_t PayloadDescriptorLengthMinusSsData(const RTPVideoHeaderVP9& hdr) {
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 RETURN_FALSE_ON_ERROR(writer->WriteBits(x_bit ? 1 : 0, 1)); 267 RETURN_FALSE_ON_ERROR(writer->WriteBits(x_bit ? 1 : 0, 1));
264 RETURN_FALSE_ON_ERROR(writer->WriteBits(n_bit ? 1 : 0, 1)); 268 RETURN_FALSE_ON_ERROR(writer->WriteBits(n_bit ? 1 : 0, 1));
265 } 269 }
266 } 270 }
267 return true; 271 return true;
268 } 272 }
269 273
270 // Scalability structure (SS). 274 // Scalability structure (SS).
271 // 275 //
272 // +-+-+-+-+-+-+-+-+ 276 // +-+-+-+-+-+-+-+-+
273 // V: | N_S |Y| N_G | 277 // V: | N_S |Y|G|-|-|-|
274 // +-+-+-+-+-+-+-+-+ -| 278 // +-+-+-+-+-+-+-+-+ -|
275 // Y: | WIDTH | (OPTIONAL) . 279 // Y: | WIDTH | (OPTIONAL) .
276 // + + . 280 // + + .
277 // | | (OPTIONAL) . 281 // | | (OPTIONAL) .
278 // +-+-+-+-+-+-+-+-+ . N_S + 1 times 282 // +-+-+-+-+-+-+-+-+ . N_S + 1 times
279 // | HEIGHT | (OPTIONAL) . 283 // | HEIGHT | (OPTIONAL) .
280 // + + . 284 // + + .
281 // | | (OPTIONAL) . 285 // | | (OPTIONAL) .
282 // +-+-+-+-+-+-+-+-+ -| -| 286 // +-+-+-+-+-+-+-+-+ -|
287 // G: | N_G | (OPTIONAL)
288 // +-+-+-+-+-+-+-+-+ -|
283 // N_G: | T |U| R |-|-| (OPTIONAL) . 289 // N_G: | T |U| R |-|-| (OPTIONAL) .
284 // +-+-+-+-+-+-+-+-+ -| . N_G + 1 times 290 // +-+-+-+-+-+-+-+-+ -| . N_G times
285 // | P_DIFF | (OPTIONAL) . R times . 291 // | P_DIFF | (OPTIONAL) . R times .
286 // +-+-+-+-+-+-+-+-+ -| -| 292 // +-+-+-+-+-+-+-+-+ -| -|
287 // 293 //
288 bool WriteSsData(const RTPVideoHeaderVP9& vp9, rtc::BitBufferWriter* writer) { 294 bool WriteSsData(const RTPVideoHeaderVP9& vp9, rtc::BitBufferWriter* writer) {
289 RTC_DCHECK_GT(vp9.num_spatial_layers, 0U); 295 RTC_DCHECK_GT(vp9.num_spatial_layers, 0U);
290 RTC_DCHECK_LE(vp9.num_spatial_layers, kMaxVp9NumberOfSpatialLayers); 296 RTC_DCHECK_LE(vp9.num_spatial_layers, kMaxVp9NumberOfSpatialLayers);
291 RTC_DCHECK_GT(vp9.gof.num_frames_in_gof, 0U);
292 RTC_DCHECK_LE(vp9.gof.num_frames_in_gof, kMaxVp9FramesInGof); 297 RTC_DCHECK_LE(vp9.gof.num_frames_in_gof, kMaxVp9FramesInGof);
298 bool g_bit = vp9.gof.num_frames_in_gof > 0;
293 299
294 RETURN_FALSE_ON_ERROR(writer->WriteBits(vp9.num_spatial_layers - 1, 3)); 300 RETURN_FALSE_ON_ERROR(writer->WriteBits(vp9.num_spatial_layers - 1, 3));
295 RETURN_FALSE_ON_ERROR( 301 RETURN_FALSE_ON_ERROR(
296 writer->WriteBits(vp9.spatial_layer_resolution_present ? 1 : 0, 1)); 302 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)); 303 RETURN_FALSE_ON_ERROR(writer->WriteBits(g_bit ? 1 : 0, 1)); // G
304 RETURN_FALSE_ON_ERROR(writer->WriteBits(kReservedBitValue0, 3));
298 305
299 if (vp9.spatial_layer_resolution_present) { 306 if (vp9.spatial_layer_resolution_present) {
300 for (size_t i = 0; i < vp9.num_spatial_layers; ++i) { 307 for (size_t i = 0; i < vp9.num_spatial_layers; ++i) {
301 RETURN_FALSE_ON_ERROR(writer->WriteUInt16(vp9.width[i])); 308 RETURN_FALSE_ON_ERROR(writer->WriteUInt16(vp9.width[i]));
302 RETURN_FALSE_ON_ERROR(writer->WriteUInt16(vp9.height[i])); 309 RETURN_FALSE_ON_ERROR(writer->WriteUInt16(vp9.height[i]));
303 } 310 }
304 } 311 }
312 if (g_bit) {
313 RETURN_FALSE_ON_ERROR(writer->WriteUInt8(vp9.gof.num_frames_in_gof));
314 }
305 for (size_t i = 0; i < vp9.gof.num_frames_in_gof; ++i) { 315 for (size_t i = 0; i < vp9.gof.num_frames_in_gof; ++i) {
306 RETURN_FALSE_ON_ERROR(writer->WriteBits(vp9.gof.temporal_idx[i], 3)); 316 RETURN_FALSE_ON_ERROR(writer->WriteBits(vp9.gof.temporal_idx[i], 3));
307 RETURN_FALSE_ON_ERROR( 317 RETURN_FALSE_ON_ERROR(
308 writer->WriteBits(vp9.gof.temporal_up_switch[i] ? 1 : 0, 1)); 318 writer->WriteBits(vp9.gof.temporal_up_switch[i] ? 1 : 0, 1));
309 RETURN_FALSE_ON_ERROR(writer->WriteBits(vp9.gof.num_ref_pics[i], 2)); 319 RETURN_FALSE_ON_ERROR(writer->WriteBits(vp9.gof.num_ref_pics[i], 2));
310 RETURN_FALSE_ON_ERROR(writer->WriteBits(kReservedBitValue0, 2)); 320 RETURN_FALSE_ON_ERROR(writer->WriteBits(kReservedBitValue0, 2));
311 for (size_t r = 0; r < vp9.gof.num_ref_pics[i]; ++r) { 321 for (size_t r = 0; r < vp9.gof.num_ref_pics[i]; ++r) {
312 RETURN_FALSE_ON_ERROR(writer->WriteUInt8(vp9.gof.pid_diff[i][r])); 322 RETURN_FALSE_ON_ERROR(writer->WriteUInt8(vp9.gof.pid_diff[i][r]));
313 } 323 }
314 } 324 }
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 } 437 }
428 vp9->ref_picture_id[vp9->num_ref_pics++] = scaled_pid - p_diff; 438 vp9->ref_picture_id[vp9->num_ref_pics++] = scaled_pid - p_diff;
429 } while (n_bit); 439 } while (n_bit);
430 440
431 return true; 441 return true;
432 } 442 }
433 443
434 // Scalability structure (SS). 444 // Scalability structure (SS).
435 // 445 //
436 // +-+-+-+-+-+-+-+-+ 446 // +-+-+-+-+-+-+-+-+
437 // V: | N_S |Y| N_G | 447 // V: | N_S |Y|G|-|-|-|
438 // +-+-+-+-+-+-+-+-+ -| 448 // +-+-+-+-+-+-+-+-+ -|
439 // Y: | WIDTH | (OPTIONAL) . 449 // Y: | WIDTH | (OPTIONAL) .
440 // + + . 450 // + + .
441 // | | (OPTIONAL) . 451 // | | (OPTIONAL) .
442 // +-+-+-+-+-+-+-+-+ . N_S + 1 times 452 // +-+-+-+-+-+-+-+-+ . N_S + 1 times
443 // | HEIGHT | (OPTIONAL) . 453 // | HEIGHT | (OPTIONAL) .
444 // + + . 454 // + + .
445 // | | (OPTIONAL) . 455 // | | (OPTIONAL) .
446 // +-+-+-+-+-+-+-+-+ -| -| 456 // +-+-+-+-+-+-+-+-+ -|
457 // G: | N_G | (OPTIONAL)
458 // +-+-+-+-+-+-+-+-+ -|
447 // N_G: | T |U| R |-|-| (OPTIONAL) . 459 // N_G: | T |U| R |-|-| (OPTIONAL) .
448 // +-+-+-+-+-+-+-+-+ -| . N_G + 1 times 460 // +-+-+-+-+-+-+-+-+ -| . N_G times
449 // | P_DIFF | (OPTIONAL) . R times . 461 // | P_DIFF | (OPTIONAL) . R times .
450 // +-+-+-+-+-+-+-+-+ -| -| 462 // +-+-+-+-+-+-+-+-+ -| -|
451 // 463 //
452 bool ParseSsData(rtc::BitBuffer* parser, RTPVideoHeaderVP9* vp9) { 464 bool ParseSsData(rtc::BitBuffer* parser, RTPVideoHeaderVP9* vp9) {
453 uint32_t n_s, y_bit, n_g; 465 uint32_t n_s, y_bit, g_bit;
454 RETURN_FALSE_ON_ERROR(parser->ReadBits(&n_s, 3)); 466 RETURN_FALSE_ON_ERROR(parser->ReadBits(&n_s, 3));
455 RETURN_FALSE_ON_ERROR(parser->ReadBits(&y_bit, 1)); 467 RETURN_FALSE_ON_ERROR(parser->ReadBits(&y_bit, 1));
456 RETURN_FALSE_ON_ERROR(parser->ReadBits(&n_g, 4)); 468 RETURN_FALSE_ON_ERROR(parser->ReadBits(&g_bit, 1));
469 RETURN_FALSE_ON_ERROR(parser->ConsumeBits(3));
457 vp9->num_spatial_layers = n_s + 1; 470 vp9->num_spatial_layers = n_s + 1;
458 vp9->spatial_layer_resolution_present = y_bit ? true : false; 471 vp9->spatial_layer_resolution_present = y_bit ? true : false;
459 vp9->gof.num_frames_in_gof = n_g + 1; 472 vp9->gof.num_frames_in_gof = 0;
460 473
461 if (y_bit) { 474 if (y_bit) {
462 for (size_t i = 0; i < vp9->num_spatial_layers; ++i) { 475 for (size_t i = 0; i < vp9->num_spatial_layers; ++i) {
463 RETURN_FALSE_ON_ERROR(parser->ReadUInt16(&vp9->width[i])); 476 RETURN_FALSE_ON_ERROR(parser->ReadUInt16(&vp9->width[i]));
464 RETURN_FALSE_ON_ERROR(parser->ReadUInt16(&vp9->height[i])); 477 RETURN_FALSE_ON_ERROR(parser->ReadUInt16(&vp9->height[i]));
465 } 478 }
466 } 479 }
480 if (g_bit) {
481 uint8_t n_g;
482 RETURN_FALSE_ON_ERROR(parser->ReadUInt8(&n_g));
483 vp9->gof.num_frames_in_gof = n_g;
484 }
467 for (size_t i = 0; i < vp9->gof.num_frames_in_gof; ++i) { 485 for (size_t i = 0; i < vp9->gof.num_frames_in_gof; ++i) {
468 uint32_t t, u_bit, r; 486 uint32_t t, u_bit, r;
469 RETURN_FALSE_ON_ERROR(parser->ReadBits(&t, 3)); 487 RETURN_FALSE_ON_ERROR(parser->ReadBits(&t, 3));
470 RETURN_FALSE_ON_ERROR(parser->ReadBits(&u_bit, 1)); 488 RETURN_FALSE_ON_ERROR(parser->ReadBits(&u_bit, 1));
471 RETURN_FALSE_ON_ERROR(parser->ReadBits(&r, 2)); 489 RETURN_FALSE_ON_ERROR(parser->ReadBits(&r, 2));
472 RETURN_FALSE_ON_ERROR(parser->ConsumeBits(2)); 490 RETURN_FALSE_ON_ERROR(parser->ConsumeBits(2));
473 vp9->gof.temporal_idx[i] = t; 491 vp9->gof.temporal_idx[i] = t;
474 vp9->gof.temporal_up_switch[i] = u_bit ? true : false; 492 vp9->gof.temporal_up_switch[i] = u_bit ? true : false;
475 vp9->gof.num_ref_pics[i] = r; 493 vp9->gof.num_ref_pics[i] = r;
476 494
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
756 if (parsed_payload->payload_length == 0) { 774 if (parsed_payload->payload_length == 0) {
757 LOG(LS_ERROR) << "Failed parsing VP9 payload data."; 775 LOG(LS_ERROR) << "Failed parsing VP9 payload data.";
758 return false; 776 return false;
759 } 777 }
760 parsed_payload->payload = 778 parsed_payload->payload =
761 payload + payload_length - parsed_payload->payload_length; 779 payload + payload_length - parsed_payload->payload_length;
762 780
763 return true; 781 return true;
764 } 782 }
765 } // namespace webrtc 783 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/interface/module_common_types.h ('k') | webrtc/modules/rtp_rtcp/source/rtp_format_vp9_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698