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

Side by Side Diff: webrtc/modules/rtp_rtcp/source/rtcp_packet/target_bitrate.cc

Issue 2947633003: Allow parsing empty RTCP TargetBitrate messages, but stop sending them. (Closed)
Patch Set: Created 3 years, 6 months 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) 2016 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2016 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 // 58 //
59 // As an example of how S and T are intended to be used, VP8 simulcast will 59 // As an example of how S and T are intended to be used, VP8 simulcast will
60 // use a separate TargetBitrate message per stream, since they are transmitted 60 // use a separate TargetBitrate message per stream, since they are transmitted
61 // on separate SSRCs, with temporal layers grouped by stream. 61 // on separate SSRCs, with temporal layers grouped by stream.
62 // If VP9 SVC is used, there will be only one SSRC, so each spatial and 62 // If VP9 SVC is used, there will be only one SSRC, so each spatial and
63 // temporal layer combo used shall be specified in the TargetBitrate packet. 63 // temporal layer combo used shall be specified in the TargetBitrate packet.
64 64
65 TargetBitrate::TargetBitrate() {} 65 TargetBitrate::TargetBitrate() {}
66 TargetBitrate::~TargetBitrate() {} 66 TargetBitrate::~TargetBitrate() {}
67 67
68 bool TargetBitrate::Parse(const uint8_t* block, uint16_t block_length) { 68 void TargetBitrate::Parse(const uint8_t* block, uint16_t block_length) {
69 if (block_length < 1) {
70 LOG(LS_WARNING)
71 << "Cannot parse TargetBitrate RTCP packet: Too little payload data ("
72 << kTargetBitrateHeaderSizeBytes << " bytes needed, got "
73 << block_length * 4 << ").";
74 return false;
75 }
76
77 // Validate block header (should already have been parsed and checked). 69 // Validate block header (should already have been parsed and checked).
78 RTC_DCHECK_EQ(block[0], kBlockType); 70 RTC_DCHECK_EQ(block[0], kBlockType);
79 RTC_DCHECK_EQ(block_length, ByteReader<uint16_t>::ReadBigEndian(&block[2])); 71 RTC_DCHECK_EQ(block_length, ByteReader<uint16_t>::ReadBigEndian(&block[2]));
80 72
81 // Header specifies block length - 1, but since we ignore the header, which 73 // Header specifies block length - 1, but since we ignore the header, which
82 // occupies exactly on block, we can just treat this as payload length. 74 // occupies exactly on block, we can just treat this as payload length.
83 const size_t payload_bytes = block_length * 4; 75 const size_t payload_bytes = block_length * 4;
84 const size_t num_items = payload_bytes / kBitrateItemSizeBytes; 76 const size_t num_items = payload_bytes / kBitrateItemSizeBytes;
85 size_t index = kTargetBitrateHeaderSizeBytes; 77 size_t index = kTargetBitrateHeaderSizeBytes;
86 bitrates_.clear(); 78 bitrates_.clear();
87 for (size_t i = 0; i < num_items; ++i) { 79 for (size_t i = 0; i < num_items; ++i) {
88 uint8_t layers = block[index]; 80 uint8_t layers = block[index];
89 uint32_t bitrate_kbps = 81 uint32_t bitrate_kbps =
90 ByteReader<uint32_t, 3>::ReadBigEndian(&block[index + 1]); 82 ByteReader<uint32_t, 3>::ReadBigEndian(&block[index + 1]);
91 index += kBitrateItemSizeBytes; 83 index += kBitrateItemSizeBytes;
92 AddTargetBitrate((layers >> 4) & 0x0F, layers & 0x0F, bitrate_kbps); 84 AddTargetBitrate((layers >> 4) & 0x0F, layers & 0x0F, bitrate_kbps);
93 } 85 }
94
95 return true;
96 } 86 }
97 87
98 void TargetBitrate::AddTargetBitrate(uint8_t spatial_layer, 88 void TargetBitrate::AddTargetBitrate(uint8_t spatial_layer,
99 uint8_t temporal_layer, 89 uint8_t temporal_layer,
100 uint32_t target_bitrate_kbps) { 90 uint32_t target_bitrate_kbps) {
101 RTC_DCHECK_LE(spatial_layer, 0x0F); 91 RTC_DCHECK_LE(spatial_layer, 0x0F);
102 RTC_DCHECK_LE(temporal_layer, 0x0F); 92 RTC_DCHECK_LE(temporal_layer, 0x0F);
103 RTC_DCHECK_LE(target_bitrate_kbps, 0x00FFFFFFU); 93 RTC_DCHECK_LE(target_bitrate_kbps, 0x00FFFFFFU);
104 bitrates_.push_back( 94 bitrates_.push_back(
105 BitrateItem(spatial_layer, temporal_layer, target_bitrate_kbps)); 95 BitrateItem(spatial_layer, temporal_layer, target_bitrate_kbps));
(...skipping 19 matching lines...) Expand all
125 for (const BitrateItem& item : bitrates_) { 115 for (const BitrateItem& item : bitrates_) {
126 buffer[index] = (item.spatial_layer << 4) | item.temporal_layer; 116 buffer[index] = (item.spatial_layer << 4) | item.temporal_layer;
127 ByteWriter<uint32_t, 3>::WriteBigEndian(&buffer[index + 1], 117 ByteWriter<uint32_t, 3>::WriteBigEndian(&buffer[index + 1],
128 item.target_bitrate_kbps); 118 item.target_bitrate_kbps);
129 index += kBitrateItemSizeBytes; 119 index += kBitrateItemSizeBytes;
130 } 120 }
131 } 121 }
132 122
133 } // namespace rtcp 123 } // namespace rtcp
134 } // namespace webrtc 124 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698