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 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 void TargetBitrate::Create(uint8_t* buffer) const { | |
69 buffer[0] = kBlockType; | |
70 buffer[1] = 0; // Reserved. | |
71 const size_t block_length_words = (BlockLength() / 4) - 1; | |
72 ByteWriter<uint16_t>::WriteBigEndian(&buffer[2], block_length_words); | |
73 | |
74 size_t index = kTargetBitrateHeaderSizeBytes; | |
75 for (const BitrateItem& item : bitrates_) { | |
76 buffer[index] = (item.spatial_layer << 4) | item.temporal_layer; | |
77 ByteWriter<uint32_t, 3>::WriteBigEndian(&buffer[index + 1], | |
78 item.target_bitrate_kbps); | |
79 index += kBitrateItemSizeBytes; | |
80 } | |
81 } | |
82 | |
83 bool TargetBitrate::Parse(const uint8_t* block, uint16_t block_length) { | 68 bool TargetBitrate::Parse(const uint8_t* block, uint16_t block_length) { |
84 if (block_length < 1) { | 69 if (block_length < 1) { |
85 LOG(LS_WARNING) | 70 LOG(LS_WARNING) |
86 << "Cannot parse TargetBitrate RTCP packet: Too little payload data (" | 71 << "Cannot parse TargetBitrate RTCP packet: Too little payload data (" |
87 << kTargetBitrateHeaderSizeBytes << " bytes needed, got " | 72 << kTargetBitrateHeaderSizeBytes << " bytes needed, got " |
88 << block_length * 4 << ")."; | 73 << block_length * 4 << ")."; |
89 return false; | 74 return false; |
90 } | 75 } |
91 | 76 |
92 // Validate block header (should already have been parsed and checked). | 77 // Validate block header (should already have been parsed and checked). |
(...skipping 25 matching lines...) Expand all Loading... | |
118 RTC_DCHECK_LE(target_bitrate_kbps, 0x00FFFFFFU); | 103 RTC_DCHECK_LE(target_bitrate_kbps, 0x00FFFFFFU); |
119 bitrates_.push_back( | 104 bitrates_.push_back( |
120 BitrateItem(spatial_layer, temporal_layer, target_bitrate_kbps)); | 105 BitrateItem(spatial_layer, temporal_layer, target_bitrate_kbps)); |
121 } | 106 } |
122 | 107 |
123 const std::vector<TargetBitrate::BitrateItem>& | 108 const std::vector<TargetBitrate::BitrateItem>& |
124 TargetBitrate::GetTargetBitrates() const { | 109 TargetBitrate::GetTargetBitrates() const { |
125 return bitrates_; | 110 return bitrates_; |
126 } | 111 } |
127 | 112 |
113 void TargetBitrate::Create(uint8_t* buffer) const { | |
danilchap
2017/06/16 12:51:40
move it a bit more - after next (BlockLength) func
eladalon
2017/06/16 13:15:04
Done.
| |
114 buffer[0] = kBlockType; | |
115 buffer[1] = 0; // Reserved. | |
116 const size_t block_length_words = (BlockLength() / 4) - 1; | |
117 ByteWriter<uint16_t>::WriteBigEndian(&buffer[2], block_length_words); | |
118 | |
119 size_t index = kTargetBitrateHeaderSizeBytes; | |
120 for (const BitrateItem& item : bitrates_) { | |
121 buffer[index] = (item.spatial_layer << 4) | item.temporal_layer; | |
122 ByteWriter<uint32_t, 3>::WriteBigEndian(&buffer[index + 1], | |
123 item.target_bitrate_kbps); | |
124 index += kBitrateItemSizeBytes; | |
125 } | |
126 } | |
127 | |
128 size_t TargetBitrate::BlockLength() const { | 128 size_t TargetBitrate::BlockLength() const { |
129 return kTargetBitrateHeaderSizeBytes + | 129 return kTargetBitrateHeaderSizeBytes + |
130 bitrates_.size() * kBitrateItemSizeBytes; | 130 bitrates_.size() * kBitrateItemSizeBytes; |
131 } | 131 } |
132 | 132 |
133 } // namespace rtcp | 133 } // namespace rtcp |
134 } // namespace webrtc | 134 } // namespace webrtc |
OLD | NEW |