OLD | NEW |
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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 std::vector<TransportFeedback::StatusSymbol>* vec) const override { | 127 std::vector<TransportFeedback::StatusSymbol>* vec) const override { |
128 vec->insert(vec->end(), &symbols_[0], &symbols_[kCapacity]); | 128 vec->insert(vec->end(), &symbols_[0], &symbols_[kCapacity]); |
129 } | 129 } |
130 | 130 |
131 void WriteTo(uint8_t* buffer) const override { | 131 void WriteTo(uint8_t* buffer) const override { |
132 const int kSymbolsInFirstByte = 6; | 132 const int kSymbolsInFirstByte = 6; |
133 const int kSymbolsInSecondByte = 8; | 133 const int kSymbolsInSecondByte = 8; |
134 buffer[0] = 0x80u; | 134 buffer[0] = 0x80u; |
135 for (int i = 0; i < kSymbolsInFirstByte; ++i) { | 135 for (int i = 0; i < kSymbolsInFirstByte; ++i) { |
136 uint8_t encoded_symbol = EncodeSymbol(symbols_[i]); | 136 uint8_t encoded_symbol = EncodeSymbol(symbols_[i]); |
137 DCHECK_LE(encoded_symbol, 1u); | 137 RTC_DCHECK_LE(encoded_symbol, 1u); |
138 buffer[0] |= encoded_symbol << (kSymbolsInFirstByte - (i + 1)); | 138 buffer[0] |= encoded_symbol << (kSymbolsInFirstByte - (i + 1)); |
139 } | 139 } |
140 buffer[1] = 0x00u; | 140 buffer[1] = 0x00u; |
141 for (int i = 0; i < kSymbolsInSecondByte; ++i) { | 141 for (int i = 0; i < kSymbolsInSecondByte; ++i) { |
142 uint8_t encoded_symbol = EncodeSymbol(symbols_[i + kSymbolsInFirstByte]); | 142 uint8_t encoded_symbol = EncodeSymbol(symbols_[i + kSymbolsInFirstByte]); |
143 DCHECK_LE(encoded_symbol, 1u); | 143 RTC_DCHECK_LE(encoded_symbol, 1u); |
144 buffer[1] |= encoded_symbol << (kSymbolsInSecondByte - (i + 1)); | 144 buffer[1] |= encoded_symbol << (kSymbolsInSecondByte - (i + 1)); |
145 } | 145 } |
146 } | 146 } |
147 | 147 |
148 static OneBitVectorChunk* ParseFrom(const uint8_t* data) { | 148 static OneBitVectorChunk* ParseFrom(const uint8_t* data) { |
149 OneBitVectorChunk* chunk = new OneBitVectorChunk(); | 149 OneBitVectorChunk* chunk = new OneBitVectorChunk(); |
150 | 150 |
151 size_t index = 0; | 151 size_t index = 0; |
152 for (int i = 5; i >= 0; --i) // Last 5 bits from first byte. | 152 for (int i = 5; i >= 0; --i) // Last 5 bits from first byte. |
153 chunk->symbols_[index++] = DecodeSymbol((data[0] >> i) & 0x01); | 153 chunk->symbols_[index++] = DecodeSymbol((data[0] >> i) & 0x01); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | 241 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
242 // | 242 // |
243 // T = 0 | 243 // T = 0 |
244 // S = symbol, see (Encode|Decode)Symbol | 244 // S = symbol, see (Encode|Decode)Symbol |
245 // Run Length = Unsigned integer denoting the run length of the symbol | 245 // Run Length = Unsigned integer denoting the run length of the symbol |
246 | 246 |
247 class RunLengthChunk : public PacketStatusChunk { | 247 class RunLengthChunk : public PacketStatusChunk { |
248 public: | 248 public: |
249 RunLengthChunk(TransportFeedback::StatusSymbol symbol, size_t size) | 249 RunLengthChunk(TransportFeedback::StatusSymbol symbol, size_t size) |
250 : symbol_(symbol), size_(size) { | 250 : symbol_(symbol), size_(size) { |
251 DCHECK_LE(size, 0x1FFFu); | 251 RTC_DCHECK_LE(size, 0x1FFFu); |
252 } | 252 } |
253 | 253 |
254 virtual ~RunLengthChunk() {} | 254 virtual ~RunLengthChunk() {} |
255 | 255 |
256 uint16_t NumSymbols() const override { return size_; } | 256 uint16_t NumSymbols() const override { return size_; } |
257 | 257 |
258 void AppendSymbolsTo( | 258 void AppendSymbolsTo( |
259 std::vector<TransportFeedback::StatusSymbol>* vec) const override { | 259 std::vector<TransportFeedback::StatusSymbol>* vec) const override { |
260 vec->insert(vec->end(), size_, symbol_); | 260 vec->insert(vec->end(), size_, symbol_); |
261 } | 261 } |
262 | 262 |
263 void WriteTo(uint8_t* buffer) const override { | 263 void WriteTo(uint8_t* buffer) const override { |
264 buffer[0] = EncodeSymbol(symbol_) << 5; // Write S (T = 0 implicitly) | 264 buffer[0] = EncodeSymbol(symbol_) << 5; // Write S (T = 0 implicitly) |
265 buffer[0] |= (size_ >> 8) & 0x1F; // 5 most significant bits of run length. | 265 buffer[0] |= (size_ >> 8) & 0x1F; // 5 most significant bits of run length. |
266 buffer[1] = size_ & 0xFF; // 8 least significant bits of run length. | 266 buffer[1] = size_ & 0xFF; // 8 least significant bits of run length. |
267 } | 267 } |
268 | 268 |
269 static RunLengthChunk* ParseFrom(const uint8_t* buffer) { | 269 static RunLengthChunk* ParseFrom(const uint8_t* buffer) { |
270 DCHECK_EQ(0, buffer[0] & 0x80); | 270 RTC_DCHECK_EQ(0, buffer[0] & 0x80); |
271 TransportFeedback::StatusSymbol symbol = | 271 TransportFeedback::StatusSymbol symbol = |
272 DecodeSymbol((buffer[0] >> 5) & 0x03); | 272 DecodeSymbol((buffer[0] >> 5) & 0x03); |
273 uint16_t count = (static_cast<uint16_t>(buffer[0] & 0x1F) << 8) | buffer[1]; | 273 uint16_t count = (static_cast<uint16_t>(buffer[0] & 0x1F) << 8) | buffer[1]; |
274 | 274 |
275 return new RunLengthChunk(symbol, count); | 275 return new RunLengthChunk(symbol, count); |
276 } | 276 } |
277 | 277 |
278 private: | 278 private: |
279 const TransportFeedback::StatusSymbol symbol_; | 279 const TransportFeedback::StatusSymbol symbol_; |
280 const size_t size_; | 280 const size_t size_; |
(...skipping 26 matching lines...) Expand all Loading... |
307 | 307 |
308 uint32_t TransportFeedback::GetPacketSenderSsrc() const { | 308 uint32_t TransportFeedback::GetPacketSenderSsrc() const { |
309 return packet_sender_ssrc_; | 309 return packet_sender_ssrc_; |
310 } | 310 } |
311 | 311 |
312 uint32_t TransportFeedback::GetMediaSourceSsrc() const { | 312 uint32_t TransportFeedback::GetMediaSourceSsrc() const { |
313 return media_source_ssrc_; | 313 return media_source_ssrc_; |
314 } | 314 } |
315 void TransportFeedback::WithBase(uint16_t base_sequence, | 315 void TransportFeedback::WithBase(uint16_t base_sequence, |
316 int64_t ref_timestamp_us) { | 316 int64_t ref_timestamp_us) { |
317 DCHECK_EQ(-1, base_seq_); | 317 RTC_DCHECK_EQ(-1, base_seq_); |
318 DCHECK_NE(-1, ref_timestamp_us); | 318 RTC_DCHECK_NE(-1, ref_timestamp_us); |
319 base_seq_ = base_sequence; | 319 base_seq_ = base_sequence; |
320 last_seq_ = base_sequence; | 320 last_seq_ = base_sequence; |
321 base_time_ = ref_timestamp_us / kBaseScaleFactor; | 321 base_time_ = ref_timestamp_us / kBaseScaleFactor; |
322 last_timestamp_ = base_time_ * kBaseScaleFactor; | 322 last_timestamp_ = base_time_ * kBaseScaleFactor; |
323 } | 323 } |
324 | 324 |
325 void TransportFeedback::WithFeedbackSequenceNumber(uint8_t feedback_sequence) { | 325 void TransportFeedback::WithFeedbackSequenceNumber(uint8_t feedback_sequence) { |
326 feedback_seq_ = feedback_sequence; | 326 feedback_seq_ = feedback_sequence; |
327 } | 327 } |
328 | 328 |
329 bool TransportFeedback::WithReceivedPacket(uint16_t sequence_number, | 329 bool TransportFeedback::WithReceivedPacket(uint16_t sequence_number, |
330 int64_t timestamp) { | 330 int64_t timestamp) { |
331 DCHECK_NE(-1, base_seq_); | 331 RTC_DCHECK_NE(-1, base_seq_); |
332 int64_t seq = Unwrap(sequence_number); | 332 int64_t seq = Unwrap(sequence_number); |
333 if (seq != base_seq_ && seq <= last_seq_) | 333 if (seq != base_seq_ && seq <= last_seq_) |
334 return false; | 334 return false; |
335 | 335 |
336 // Convert to ticks and round. | 336 // Convert to ticks and round. |
337 int64_t delta_full = timestamp - last_timestamp_; | 337 int64_t delta_full = timestamp - last_timestamp_; |
338 delta_full += | 338 delta_full += |
339 delta_full < 0 ? -(kDeltaScaleFactor / 2) : kDeltaScaleFactor / 2; | 339 delta_full < 0 ? -(kDeltaScaleFactor / 2) : kDeltaScaleFactor / 2; |
340 delta_full /= kDeltaScaleFactor; | 340 delta_full /= kDeltaScaleFactor; |
341 | 341 |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
513 // symbol_vec. | 513 // symbol_vec. |
514 first_symbol_cardinality_ = 1; | 514 first_symbol_cardinality_ = 1; |
515 for (size_t i = 1; i < symbol_vec_.size(); ++i) { | 515 for (size_t i = 1; i < symbol_vec_.size(); ++i) { |
516 if (symbol_vec_[i] != symbol_vec_[0]) | 516 if (symbol_vec_[i] != symbol_vec_[0]) |
517 break; | 517 break; |
518 ++first_symbol_cardinality_; | 518 ++first_symbol_cardinality_; |
519 } | 519 } |
520 } | 520 } |
521 | 521 |
522 void TransportFeedback::EmitRunLengthChunk() { | 522 void TransportFeedback::EmitRunLengthChunk() { |
523 DCHECK_GE(first_symbol_cardinality_, symbol_vec_.size()); | 523 RTC_DCHECK_GE(first_symbol_cardinality_, symbol_vec_.size()); |
524 status_chunks_.push_back( | 524 status_chunks_.push_back( |
525 new RunLengthChunk(symbol_vec_.front(), first_symbol_cardinality_)); | 525 new RunLengthChunk(symbol_vec_.front(), first_symbol_cardinality_)); |
526 symbol_vec_.clear(); | 526 symbol_vec_.clear(); |
527 } | 527 } |
528 | 528 |
529 size_t TransportFeedback::BlockLength() const { | 529 size_t TransportFeedback::BlockLength() const { |
530 return size_bytes_; | 530 return size_bytes_; |
531 } | 531 } |
532 | 532 |
533 uint16_t TransportFeedback::GetBaseSequence() const { | 533 uint16_t TransportFeedback::GetBaseSequence() const { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
578 return false; | 578 return false; |
579 } | 579 } |
580 | 580 |
581 CreateHeader(kFeedbackMessageType, kPayloadType, HeaderLength(), packet, | 581 CreateHeader(kFeedbackMessageType, kPayloadType, HeaderLength(), packet, |
582 position); | 582 position); |
583 ByteWriter<uint32_t>::WriteBigEndian(&packet[*position], packet_sender_ssrc_); | 583 ByteWriter<uint32_t>::WriteBigEndian(&packet[*position], packet_sender_ssrc_); |
584 *position += 4; | 584 *position += 4; |
585 ByteWriter<uint32_t>::WriteBigEndian(&packet[*position], media_source_ssrc_); | 585 ByteWriter<uint32_t>::WriteBigEndian(&packet[*position], media_source_ssrc_); |
586 *position += 4; | 586 *position += 4; |
587 | 587 |
588 DCHECK_LE(base_seq_, 0xFFFF); | 588 RTC_DCHECK_LE(base_seq_, 0xFFFF); |
589 ByteWriter<uint16_t>::WriteBigEndian(&packet[*position], base_seq_); | 589 ByteWriter<uint16_t>::WriteBigEndian(&packet[*position], base_seq_); |
590 *position += 2; | 590 *position += 2; |
591 | 591 |
592 int64_t status_count = last_seq_ - base_seq_ + 1; | 592 int64_t status_count = last_seq_ - base_seq_ + 1; |
593 DCHECK_LE(status_count, 0xFFFF); | 593 RTC_DCHECK_LE(status_count, 0xFFFF); |
594 ByteWriter<uint16_t>::WriteBigEndian(&packet[*position], status_count); | 594 ByteWriter<uint16_t>::WriteBigEndian(&packet[*position], status_count); |
595 *position += 2; | 595 *position += 2; |
596 | 596 |
597 ByteWriter<int32_t, 3>::WriteBigEndian(&packet[*position], | 597 ByteWriter<int32_t, 3>::WriteBigEndian(&packet[*position], |
598 static_cast<int32_t>(base_time_)); | 598 static_cast<int32_t>(base_time_)); |
599 *position += 3; | 599 *position += 3; |
600 | 600 |
601 packet[(*position)++] = feedback_seq_; | 601 packet[(*position)++] = feedback_seq_; |
602 | 602 |
603 // TODO(sprang): Get rid of this cast. | 603 // TODO(sprang): Get rid of this cast. |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
707 if (chunk == nullptr) | 707 if (chunk == nullptr) |
708 return nullptr; | 708 return nullptr; |
709 | 709 |
710 index += 2; | 710 index += 2; |
711 packet->status_chunks_.push_back(chunk); | 711 packet->status_chunks_.push_back(chunk); |
712 packets_read += chunk->NumSymbols(); | 712 packets_read += chunk->NumSymbols(); |
713 } | 713 } |
714 | 714 |
715 std::vector<StatusSymbol> symbols = packet->GetStatusVector(); | 715 std::vector<StatusSymbol> symbols = packet->GetStatusVector(); |
716 | 716 |
717 DCHECK_EQ(num_packets, symbols.size()); | 717 RTC_DCHECK_EQ(num_packets, symbols.size()); |
718 | 718 |
719 for (StatusSymbol symbol : symbols) { | 719 for (StatusSymbol symbol : symbols) { |
720 switch (symbol) { | 720 switch (symbol) { |
721 case StatusSymbol::kReceivedSmallDelta: | 721 case StatusSymbol::kReceivedSmallDelta: |
722 if (index + 1 > end_index) { | 722 if (index + 1 > end_index) { |
723 LOG(LS_WARNING) << "Buffer overflow while parsing packet."; | 723 LOG(LS_WARNING) << "Buffer overflow while parsing packet."; |
724 return nullptr; | 724 return nullptr; |
725 } | 725 } |
726 packet->receive_deltas_.push_back(buffer[index]); | 726 packet->receive_deltas_.push_back(buffer[index]); |
727 ++index; | 727 ++index; |
728 break; | 728 break; |
729 case StatusSymbol::kReceivedLargeDelta: | 729 case StatusSymbol::kReceivedLargeDelta: |
730 if (index + 2 > end_index) { | 730 if (index + 2 > end_index) { |
731 LOG(LS_WARNING) << "Buffer overflow while parsing packet."; | 731 LOG(LS_WARNING) << "Buffer overflow while parsing packet."; |
732 return nullptr; | 732 return nullptr; |
733 } | 733 } |
734 packet->receive_deltas_.push_back( | 734 packet->receive_deltas_.push_back( |
735 ByteReader<int16_t>::ReadBigEndian(&buffer[index])); | 735 ByteReader<int16_t>::ReadBigEndian(&buffer[index])); |
736 index += 2; | 736 index += 2; |
737 break; | 737 break; |
738 default: | 738 default: |
739 continue; | 739 continue; |
740 } | 740 } |
741 } | 741 } |
742 | 742 |
743 DCHECK_GE(index, end_index - 3); | 743 RTC_DCHECK_GE(index, end_index - 3); |
744 DCHECK_LE(index, end_index); | 744 RTC_DCHECK_LE(index, end_index); |
745 | 745 |
746 return packet; | 746 return packet; |
747 } | 747 } |
748 | 748 |
749 PacketStatusChunk* TransportFeedback::ParseChunk(const uint8_t* buffer, | 749 PacketStatusChunk* TransportFeedback::ParseChunk(const uint8_t* buffer, |
750 size_t max_size) { | 750 size_t max_size) { |
751 if (buffer[0] & 0x80) { | 751 if (buffer[0] & 0x80) { |
752 // First bit set => vector chunk. | 752 // First bit set => vector chunk. |
753 std::deque<StatusSymbol> symbols; | 753 std::deque<StatusSymbol> symbols; |
754 if (buffer[0] & 0x40) { | 754 if (buffer[0] & 0x40) { |
(...skipping 12 matching lines...) Expand all Loading... |
767 "RLE block of size " << rle_chunk->NumSymbols() | 767 "RLE block of size " << rle_chunk->NumSymbols() |
768 << " but only " << max_size << " left to read."; | 768 << " but only " << max_size << " left to read."; |
769 delete rle_chunk; | 769 delete rle_chunk; |
770 return nullptr; | 770 return nullptr; |
771 } | 771 } |
772 return rle_chunk; | 772 return rle_chunk; |
773 } | 773 } |
774 | 774 |
775 } // namespace rtcp | 775 } // namespace rtcp |
776 } // namespace webrtc | 776 } // namespace webrtc |
OLD | NEW |