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 30 matching lines...) Expand all Loading... |
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 |
128 size_t TargetBitrate::BlockLength() const { | 113 size_t TargetBitrate::BlockLength() const { |
129 return kTargetBitrateHeaderSizeBytes + | 114 return kTargetBitrateHeaderSizeBytes + |
130 bitrates_.size() * kBitrateItemSizeBytes; | 115 bitrates_.size() * kBitrateItemSizeBytes; |
131 } | 116 } |
132 | 117 |
| 118 void TargetBitrate::Create(uint8_t* buffer) const { |
| 119 buffer[0] = kBlockType; |
| 120 buffer[1] = 0; // Reserved. |
| 121 const size_t block_length_words = (BlockLength() / 4) - 1; |
| 122 ByteWriter<uint16_t>::WriteBigEndian(&buffer[2], block_length_words); |
| 123 |
| 124 size_t index = kTargetBitrateHeaderSizeBytes; |
| 125 for (const BitrateItem& item : bitrates_) { |
| 126 buffer[index] = (item.spatial_layer << 4) | item.temporal_layer; |
| 127 ByteWriter<uint32_t, 3>::WriteBigEndian(&buffer[index + 1], |
| 128 item.target_bitrate_kbps); |
| 129 index += kBitrateItemSizeBytes; |
| 130 } |
| 131 } |
| 132 |
133 } // namespace rtcp | 133 } // namespace rtcp |
134 } // namespace webrtc | 134 } // namespace webrtc |
OLD | NEW |