OLD | NEW |
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 |
11 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/target_bitrate.h" | 11 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/target_bitrate.h" |
12 | 12 |
13 #include "webrtc/base/checks.h" | 13 #include "webrtc/base/checks.h" |
14 #include "webrtc/base/logging.h" | |
15 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" | 14 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" |
16 | 15 |
17 namespace webrtc { | 16 namespace webrtc { |
18 namespace rtcp { | 17 namespace rtcp { |
19 constexpr size_t kTargetBitrateHeaderSizeBytes = 4; | 18 constexpr size_t kTargetBitrateHeaderSizeBytes = 4; |
20 constexpr uint8_t TargetBitrate::kBlockType; | 19 constexpr uint8_t TargetBitrate::kBlockType; |
21 const size_t TargetBitrate::kBitrateItemSizeBytes = 4; | 20 const size_t TargetBitrate::kBitrateItemSizeBytes = 4; |
22 | 21 |
23 TargetBitrate::BitrateItem::BitrateItem() | 22 TargetBitrate::BitrateItem::BitrateItem() |
24 : spatial_layer(0), temporal_layer(0), target_bitrate_kbps(0) {} | 23 : spatial_layer(0), temporal_layer(0), target_bitrate_kbps(0) {} |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 // | 57 // |
59 // As an example of how S and T are intended to be used, VP8 simulcast will | 58 // 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 | 59 // use a separate TargetBitrate message per stream, since they are transmitted |
61 // on separate SSRCs, with temporal layers grouped by stream. | 60 // 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 | 61 // 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. | 62 // temporal layer combo used shall be specified in the TargetBitrate packet. |
64 | 63 |
65 TargetBitrate::TargetBitrate() {} | 64 TargetBitrate::TargetBitrate() {} |
66 TargetBitrate::~TargetBitrate() {} | 65 TargetBitrate::~TargetBitrate() {} |
67 | 66 |
68 bool TargetBitrate::Parse(const uint8_t* block, uint16_t block_length) { | 67 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). | 68 // Validate block header (should already have been parsed and checked). |
78 RTC_DCHECK_EQ(block[0], kBlockType); | 69 RTC_DCHECK_EQ(block[0], kBlockType); |
79 RTC_DCHECK_EQ(block_length, ByteReader<uint16_t>::ReadBigEndian(&block[2])); | 70 RTC_DCHECK_EQ(block_length, ByteReader<uint16_t>::ReadBigEndian(&block[2])); |
80 | 71 |
81 // Header specifies block length - 1, but since we ignore the header, which | 72 // 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. | 73 // occupies exactly on block, we can just treat this as payload length. |
83 const size_t payload_bytes = block_length * 4; | 74 const size_t payload_bytes = block_length * 4; |
84 const size_t num_items = payload_bytes / kBitrateItemSizeBytes; | 75 const size_t num_items = payload_bytes / kBitrateItemSizeBytes; |
85 size_t index = kTargetBitrateHeaderSizeBytes; | 76 size_t index = kTargetBitrateHeaderSizeBytes; |
86 bitrates_.clear(); | 77 bitrates_.clear(); |
87 for (size_t i = 0; i < num_items; ++i) { | 78 for (size_t i = 0; i < num_items; ++i) { |
88 uint8_t layers = block[index]; | 79 uint8_t layers = block[index]; |
89 uint32_t bitrate_kbps = | 80 uint32_t bitrate_kbps = |
90 ByteReader<uint32_t, 3>::ReadBigEndian(&block[index + 1]); | 81 ByteReader<uint32_t, 3>::ReadBigEndian(&block[index + 1]); |
91 index += kBitrateItemSizeBytes; | 82 index += kBitrateItemSizeBytes; |
92 AddTargetBitrate((layers >> 4) & 0x0F, layers & 0x0F, bitrate_kbps); | 83 AddTargetBitrate((layers >> 4) & 0x0F, layers & 0x0F, bitrate_kbps); |
93 } | 84 } |
94 | |
95 return true; | |
96 } | 85 } |
97 | 86 |
98 void TargetBitrate::AddTargetBitrate(uint8_t spatial_layer, | 87 void TargetBitrate::AddTargetBitrate(uint8_t spatial_layer, |
99 uint8_t temporal_layer, | 88 uint8_t temporal_layer, |
100 uint32_t target_bitrate_kbps) { | 89 uint32_t target_bitrate_kbps) { |
101 RTC_DCHECK_LE(spatial_layer, 0x0F); | 90 RTC_DCHECK_LE(spatial_layer, 0x0F); |
102 RTC_DCHECK_LE(temporal_layer, 0x0F); | 91 RTC_DCHECK_LE(temporal_layer, 0x0F); |
103 RTC_DCHECK_LE(target_bitrate_kbps, 0x00FFFFFFU); | 92 RTC_DCHECK_LE(target_bitrate_kbps, 0x00FFFFFFU); |
104 bitrates_.push_back( | 93 bitrates_.push_back( |
105 BitrateItem(spatial_layer, temporal_layer, target_bitrate_kbps)); | 94 BitrateItem(spatial_layer, temporal_layer, target_bitrate_kbps)); |
(...skipping 19 matching lines...) Expand all Loading... |
125 for (const BitrateItem& item : bitrates_) { | 114 for (const BitrateItem& item : bitrates_) { |
126 buffer[index] = (item.spatial_layer << 4) | item.temporal_layer; | 115 buffer[index] = (item.spatial_layer << 4) | item.temporal_layer; |
127 ByteWriter<uint32_t, 3>::WriteBigEndian(&buffer[index + 1], | 116 ByteWriter<uint32_t, 3>::WriteBigEndian(&buffer[index + 1], |
128 item.target_bitrate_kbps); | 117 item.target_bitrate_kbps); |
129 index += kBitrateItemSizeBytes; | 118 index += kBitrateItemSizeBytes; |
130 } | 119 } |
131 } | 120 } |
132 | 121 |
133 } // namespace rtcp | 122 } // namespace rtcp |
134 } // namespace webrtc | 123 } // namespace webrtc |
OLD | NEW |