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

Unified Diff: webrtc/modules/rtp_rtcp/source/rtcp_packet/feedback_packet.cc

Issue 1175263002: Add packetization and coding/decoding of feedback message format. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Fixed rounding of negative deltas Created 5 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 side-by-side diff with in-line comments
Download patch
Index: webrtc/modules/rtp_rtcp/source/rtcp_packet/feedback_packet.cc
diff --git a/webrtc/modules/rtp_rtcp/source/rtcp_packet/feedback_packet.cc b/webrtc/modules/rtp_rtcp/source/rtcp_packet/feedback_packet.cc
new file mode 100644
index 0000000000000000000000000000000000000000..885901dd5c18b8bbc2698a9a60da94ff81b7f1bf
--- /dev/null
+++ b/webrtc/modules/rtp_rtcp/source/rtcp_packet/feedback_packet.cc
@@ -0,0 +1,622 @@
+/*
+ * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/feedback_packet.h"
+
+#include "webrtc/base/checks.h"
+#include "webrtc/base/logging.h"
+#include "webrtc/modules/rtp_rtcp/source/byte_io.h"
+
+namespace webrtc {
+namespace rtcp {
+
+class FeedbackPacket::PacketStatusChunk {
+ public:
+ virtual ~PacketStatusChunk() {}
+ virtual uint16_t NumSymbols() const = 0;
+ virtual void AppendSymbolsTo(
+ std::vector<FeedbackPacket::StatusSymbol>* vec) const = 0;
+ virtual void WriteTo(uint8_t* buffer) const = 0;
+};
+
+uint8_t EncodeSymbol(FeedbackPacket::StatusSymbol symbol) {
+ switch (symbol) {
+ case FeedbackPacket::StatusSymbol::kNotReceived:
+ return 0;
+ case FeedbackPacket::StatusSymbol::kReceivedSmallDelta:
+ return 1;
+ case FeedbackPacket::StatusSymbol::kReceivedLargeDelta:
+ return 2;
+ case FeedbackPacket::StatusSymbol::kReceivedUntimed:
+ return 3;
+ default:
+ abort();
+ }
+}
+
+FeedbackPacket::StatusSymbol DecodeSymbol(uint8_t value) {
+ switch (value) {
+ case 0:
+ return FeedbackPacket::StatusSymbol::kNotReceived;
+ case 1:
+ return FeedbackPacket::StatusSymbol::kReceivedSmallDelta;
+ case 2:
+ return FeedbackPacket::StatusSymbol::kReceivedLargeDelta;
+ case 3:
+ return FeedbackPacket::StatusSymbol::kReceivedUntimed;
+ default:
+ RTC_NOTREACHED();
+ return FeedbackPacket::StatusSymbol::kNotReceived;
+ }
+}
+
+FeedbackPacket::FeedbackPacket()
+ : base_seq_(-1),
+ base_delta_(-1),
+ feedback_seq_(0),
+ last_seq_(-1),
+ last_timestamp_(-1),
+ first_symbol_cardinality_(0),
+ vec_needs_two_bit_symbols_(false),
+ size_bytes_(8) {
+}
+
+FeedbackPacket::~FeedbackPacket() {
+ for (PacketStatusChunk* chunk : status_chunks_)
+ delete chunk;
+}
+
+class OneBitVectorChunk : public FeedbackPacket::PacketStatusChunk {
+ public:
+ explicit OneBitVectorChunk(
+ std::deque<FeedbackPacket::StatusSymbol>* symbols) {
+ size_t input_size = symbols->size();
+ for (size_t i = 0; i < 14; ++i) {
stefan-webrtc 2015/06/16 08:29:13 What is 14 here? I think it's worth naming it and
sprang_webrtc 2015/06/22 12:20:10 Done.
+ if (i < input_size) {
+ symbols_[i] = symbols->front();
+ symbols->pop_front();
+ } else {
+ symbols_[i] = FeedbackPacket::StatusSymbol::kNotReceived;
+ }
+ }
+ }
+
+ virtual ~OneBitVectorChunk() {}
+
+ uint16_t NumSymbols() const override { return 14; }
+
+ void AppendSymbolsTo(
+ std::vector<FeedbackPacket::StatusSymbol>* vec) const override {
+ vec->insert(vec->end(), &symbols_[0], &symbols_[14]);
+ }
+
+ void WriteTo(uint8_t* buffer) const override {
+ buffer[0] = 0x80;
+ buffer[0] |= EncodeSymbol(symbols_[0]) << 5;
+ buffer[0] |= EncodeSymbol(symbols_[1]) << 4;
+ buffer[0] |= EncodeSymbol(symbols_[2]) << 3;
+ buffer[0] |= EncodeSymbol(symbols_[3]) << 2;
+ buffer[0] |= EncodeSymbol(symbols_[4]) << 1;
+ buffer[0] |= EncodeSymbol(symbols_[5]);
+ buffer[1] = EncodeSymbol(symbols_[6]) << 7;
+ buffer[1] |= EncodeSymbol(symbols_[7]) << 6;
+ buffer[1] |= EncodeSymbol(symbols_[8]) << 5;
+ buffer[1] |= EncodeSymbol(symbols_[9]) << 4;
+ buffer[1] |= EncodeSymbol(symbols_[10]) << 3;
+ buffer[1] |= EncodeSymbol(symbols_[11]) << 2;
+ buffer[1] |= EncodeSymbol(symbols_[12]) << 1;
+ buffer[1] |= EncodeSymbol(symbols_[13]);
+ }
+
+ static OneBitVectorChunk* ParseFrom(const uint8_t* data) {
+ OneBitVectorChunk* chunk = new OneBitVectorChunk();
+
+ size_t index = 0;
+ for (int i = 5; i >= 0; --i)
+ chunk->symbols_[index++] = DecodeSymbol((data[0] >> i) & 0x01);
+ for (int i = 7; i >= 0; --i)
+ chunk->symbols_[index++] = DecodeSymbol((data[1] >> i) & 0x01);
stefan-webrtc 2015/06/16 08:29:13 Probably worth mentioning why this is done in two
sprang_webrtc 2015/06/22 12:20:10 Done.
+
+ return chunk;
+ }
+
+ private:
+ OneBitVectorChunk() {}
+
+ FeedbackPacket::StatusSymbol symbols_[14];
+};
+
+class TwoBitVectorChunk : public FeedbackPacket::PacketStatusChunk {
+ public:
+ explicit TwoBitVectorChunk(
+ std::deque<FeedbackPacket::StatusSymbol>* symbols) {
+ size_t input_size = symbols->size();
+ for (size_t i = 0; i < 7; ++i) {
+ if (i < input_size) {
+ symbols_[i] = symbols->front();
+ symbols->pop_front();
+ } else {
+ symbols_[i] = FeedbackPacket::StatusSymbol::kNotReceived;
+ }
+ }
+ }
+
+ virtual ~TwoBitVectorChunk() {}
+
+ uint16_t NumSymbols() const override { return 7; }
+
+ void AppendSymbolsTo(
+ std::vector<FeedbackPacket::StatusSymbol>* vec) const override {
+ vec->insert(vec->end(), &symbols_[0], &symbols_[7]);
+ }
+
+ void WriteTo(uint8_t* buffer) const override {
+ buffer[0] = 0xC0;
+ buffer[0] |= EncodeSymbol(symbols_[0]) << 4;
+ buffer[0] |= EncodeSymbol(symbols_[1]) << 2;
+ buffer[0] |= EncodeSymbol(symbols_[2]);
+ buffer[1] = EncodeSymbol(symbols_[3]) << 6;
+ buffer[1] |= EncodeSymbol(symbols_[4]) << 4;
+ buffer[1] |= EncodeSymbol(symbols_[5]) << 2;
+ buffer[1] |= EncodeSymbol(symbols_[6]);
+ }
+
+ static TwoBitVectorChunk* ParseFrom(const uint8_t* buffer) {
+ TwoBitVectorChunk* chunk = new TwoBitVectorChunk();
+
+ chunk->symbols_[0] = DecodeSymbol((buffer[0] >> 4) & 0x03);
+ chunk->symbols_[1] = DecodeSymbol((buffer[0] >> 2) & 0x03);
+ chunk->symbols_[2] = DecodeSymbol(buffer[0] & 0x03);
+ chunk->symbols_[3] = DecodeSymbol((buffer[1] >> 6) & 0x03);
+ chunk->symbols_[4] = DecodeSymbol((buffer[1] >> 4) & 0x03);
+ chunk->symbols_[5] = DecodeSymbol((buffer[1] >> 2) & 0x03);
+ chunk->symbols_[6] = DecodeSymbol(buffer[1] & 0x03);
+
+ return chunk;
+ }
+
+ private:
+ TwoBitVectorChunk() {}
+
+ FeedbackPacket::StatusSymbol symbols_[7];
stefan-webrtc 2015/06/16 08:29:13 Why 7? Name the constant and explain.
sprang_webrtc 2015/06/22 12:20:10 Done.
+};
+
+class RunLengthChunk : public FeedbackPacket::PacketStatusChunk {
+ public:
+ RunLengthChunk(FeedbackPacket::StatusSymbol symbol, size_t size)
+ : symbol_(symbol), size_(size) {
+ DCHECK_LE(size, 0x1FFFu);
+ }
+
+ virtual ~RunLengthChunk() {}
+
+ uint16_t NumSymbols() const override { return size_; }
+
+ void AppendSymbolsTo(
+ std::vector<FeedbackPacket::StatusSymbol>* vec) const override {
+ vec->insert(vec->end(), size_, symbol_);
+ }
+
+ void WriteTo(uint8_t* buffer) const override {
stefan-webrtc 2015/06/16 08:29:13 I find this method complicated enough to deserve a
sprang_webrtc 2015/06/22 12:20:10 Done.
+ buffer[0] = EncodeSymbol(symbol_) << 5;
+ buffer[0] |= (size_ >> 8) & 0x1F;
+ buffer[1] = size_ & 0xFF;
+ }
+
+ static RunLengthChunk* ParseFrom(const uint8_t* buffer) {
stefan-webrtc 2015/06/16 08:29:13 Same with this.
sprang_webrtc 2015/06/22 12:20:10 Should be ok with changes above?
stefan-webrtc 2015/07/14 12:14:54 Yes
sprang_webrtc 2015/07/16 11:12:10 Acknowledged.
+ FeedbackPacket::StatusSymbol symbol = DecodeSymbol((buffer[0] >> 5) & 0x03);
+ uint16_t count = ((buffer[0] & 0x1F) << 8) | buffer[1];
+
+ return new RunLengthChunk(symbol, count);
+ }
+
+ private:
+ const FeedbackPacket::StatusSymbol symbol_;
+ const size_t size_;
+};
+
+int64_t FeedbackPacket::Unwrap(uint16_t sequence_number) {
+ if (last_seq_ == -1)
+ return sequence_number;
+
+ int64_t delta = sequence_number - (last_seq_ & 0xFFFF);
+ if (delta <= -0x8FFF) {
stefan-webrtc 2015/06/16 08:29:13 Shouldn't this be -0x7FFF? I wonder if we could r
sprang_webrtc 2015/06/22 12:20:10 Done.
+ // Wrap forward.
+ delta += (1 << 16);
+ } else if (delta > 0x8FFF) {
+ // Wrap backwards.
+ delta -= (1 << 16);
+ }
+
+ return last_seq_ + delta;
+}
+
+void FeedbackPacket::WithBase(uint16_t base_sequence,
+ int64_t prev_timestamp_us,
+ int64_t ref_timestamp_us) {
stefan-webrtc 2015/06/16 08:29:13 Would base_timestamp_us be better? Or is that not
sprang_webrtc 2015/06/22 12:20:10 Changed to use absolute ref time, as per discussio
+ DCHECK_EQ(-1, base_seq_);
+ DCHECK_NE(-1, ref_timestamp_us);
+ base_seq_ = base_sequence;
+ last_seq_ = base_sequence;
+ if (prev_timestamp_us != -1) {
+ base_delta_ = (ref_timestamp_us - prev_timestamp_us) / kBaseScaleFactor;
+ DCHECK_EQ(base_delta_, static_cast<int16_t>(base_delta_));
+
+ // Include precision loss in order to avoid drift.
stefan-webrtc 2015/07/14 12:14:54 Keep this comment, I found it really helpful.
+ last_timestamp_ = prev_timestamp_us + (base_delta_ * kBaseScaleFactor);
+ } else {
+ base_delta_ = 0;
+ last_timestamp_ = ref_timestamp_us;
+ }
+}
+
+void FeedbackPacket::WithFeedbackSequenceNumber(uint8_t feedback_sequence) {
+ feedback_seq_ = feedback_sequence;
+}
+
+bool FeedbackPacket::WithUntimedPacket(uint16_t sequence_number) {
+ DCHECK_NE(-1, base_seq_);
+ int64_t seq = Unwrap(sequence_number);
+ DCHECK_GE(seq, last_seq_);
+ return AddSymbol(StatusSymbol::kReceivedUntimed, sequence_number);
+}
+
+bool FeedbackPacket::WithReceivedPacket(uint16_t sequence_number,
+ int64_t timestamp) {
+ DCHECK_NE(-1, base_seq_);
+ int64_t seq = Unwrap(sequence_number);
+ if (seq != base_seq_) {
+ if (seq <= last_seq_)
+ return false;
+ }
+
+ // Convert to ticks and round.
+ int64_t delta_full = timestamp - last_timestamp_;
+ delta_full +=
+ delta_full < 0 ? -(kDeltaScaleFactor / 2) : kDeltaScaleFactor / 2;
+ delta_full /= kDeltaScaleFactor;
+
+ int16_t delta = static_cast<int16_t>(delta_full);
+ // If larger than 16bit signed, we can't represent it - need new fb packet.
+ if (delta != delta_full) {
+ LOG(LS_WARNING) << "Delta value too large ( >= 2^16 ticks )";
+ return false;
+ }
+
+ StatusSymbol symbol;
+ if (delta >= 0 && delta <= 0xFF) {
+ symbol = StatusSymbol::kReceivedSmallDelta;
+ } else {
+ symbol = StatusSymbol::kReceivedLargeDelta;
+ }
+
+ if (!AddSymbol(symbol, seq))
+ return false;
+
+ receive_deltas_.push_back(delta);
+ last_timestamp_ += delta * kDeltaScaleFactor;
+ return true;
+}
+
+bool FeedbackPacket::AddSymbol(StatusSymbol symbol, int64_t seq) {
+ while (last_seq_ < seq - 1) {
+ if (!Encode(StatusSymbol::kNotReceived))
+ return false;
+ ++last_seq_;
+ }
+
+ if (!Encode(symbol))
+ return false;
+
+ last_seq_ = seq;
+ return true;
+}
+
+bool FeedbackPacket::Encode(StatusSymbol symbol) {
+ if (last_seq_ - base_seq_ + 1 > 0xFFFF) {
+ LOG(LS_WARNING) << "Packet status count too large ( >= 2^16 )";
+ return false;
+ }
+
+ bool is_two_bit = (symbol == StatusSymbol::kReceivedLargeDelta ||
+ symbol == StatusSymbol::kReceivedUntimed);
+ int delta_size;
+ switch (symbol) {
+ case StatusSymbol::kReceivedSmallDelta:
+ delta_size = 1;
+ break;
+ case StatusSymbol::kReceivedLargeDelta:
+ delta_size = 2;
+ break;
+ default:
+ delta_size = 0;
+ }
+
+ if (symbol_vec_.empty()) {
+ if (size_bytes_ + delta_size + 2 > kMaxSizeBytes)
+ return false;
+
+ symbol_vec_.push_back(symbol);
+ vec_needs_two_bit_symbols_ = is_two_bit;
+ first_symbol_cardinality_ = 1;
+ size_bytes_ += delta_size + 2;
+ return true;
+ }
+ if (size_bytes_ + delta_size > kMaxSizeBytes)
+ return false;
+
+ size_t capacity = vec_needs_two_bit_symbols_ ? kTwoBitVectorCapacity
+ : kOneBitVectorCapacity;
+ bool rle_candidate = symbol_vec_.size() == first_symbol_cardinality_ ||
+ first_symbol_cardinality_ > capacity;
+ if (rle_candidate) {
+ if (symbol_vec_.back() == symbol) {
+ ++first_symbol_cardinality_;
+ if (first_symbol_cardinality_ <= capacity) {
+ symbol_vec_.push_back(symbol);
+ } else if (first_symbol_cardinality_ == kRunLengthCapacity) {
+ EmitRunLengthChunk();
+ }
+ size_bytes_ += delta_size;
+ return true;
+ } else if (first_symbol_cardinality_ > capacity) {
+ // Convert from run length to vector.
+ EmitRunLengthChunk();
+ return Encode(symbol);
+ }
+ }
+
+ if (is_two_bit && !vec_needs_two_bit_symbols_) {
+ if (symbol_vec_.size() >= kTwoBitVectorCapacity) {
+ if (size_bytes_ + delta_size + 2 > kMaxSizeBytes)
+ return false;
+ EmitVectorChunk();
+ return Encode(symbol);
+ }
+ vec_needs_two_bit_symbols_ = true;
+ capacity = kTwoBitVectorCapacity;
+ }
+
+ symbol_vec_.push_back(symbol);
+ size_t symbol_vec_size = symbol_vec_.size();
+ if (symbol_vec_size == capacity)
+ EmitVectorChunk();
+
+ size_bytes_ += delta_size;
+ return true;
+}
+
+void FeedbackPacket::EmitRemaining() {
+ if (symbol_vec_.empty())
+ return;
+
+ size_t capacity = vec_needs_two_bit_symbols_ ? kTwoBitVectorCapacity
+ : kOneBitVectorCapacity;
+ if (first_symbol_cardinality_ > capacity) {
+ EmitRunLengthChunk();
+ } else {
+ EmitVectorChunk();
+ }
+}
+
+void FeedbackPacket::EmitVectorChunk() {
+ if (vec_needs_two_bit_symbols_) {
+ status_chunks_.push_back(new TwoBitVectorChunk(&symbol_vec_));
+ } else {
+ status_chunks_.push_back(new OneBitVectorChunk(&symbol_vec_));
+ }
+}
+
+uint16_t FeedbackPacket::GetBaseSequence() const {
+ return base_seq_;
+}
+
+int16_t FeedbackPacket::GetBaseDelta() const {
+ return base_delta_;
+}
+
+int64_t FeedbackPacket::GetBaseDeltaUs() const {
+ return base_delta_ * kBaseScaleFactor;
+}
+
+std::vector<FeedbackPacket::StatusSymbol> FeedbackPacket::GetStatusVector()
+ const {
+ std::vector<FeedbackPacket::StatusSymbol> symbols;
+ for (PacketStatusChunk* chunk : status_chunks_)
+ chunk->AppendSymbolsTo(&symbols);
+ int64_t status_count = last_seq_ - base_seq_ + 1;
+ symbols.erase(symbols.begin() + status_count, symbols.end());
+ return symbols;
+}
+
+std::vector<int16_t> FeedbackPacket::GetReceiveDeltas() const {
+ return receive_deltas_;
+}
+
+std::vector<int64_t> FeedbackPacket::GetReceiveDeltasUs() const {
+ std::vector<int64_t> us_deltas;
+ if (receive_deltas_.empty()) {
+ us_deltas.push_back(base_delta_ * kBaseScaleFactor);
+ return us_deltas;
+ }
+
+ for (int16_t delta : receive_deltas_)
+ us_deltas.push_back(static_cast<int64_t>(delta) * kDeltaScaleFactor);
+ us_deltas[0] += base_delta_ * kBaseScaleFactor;
+
+ return us_deltas;
+}
+
+void FeedbackPacket::EmitRunLengthChunk() {
+ status_chunks_.push_back(
+ new RunLengthChunk(symbol_vec_.front(), first_symbol_cardinality_));
+ symbol_vec_.clear();
+}
+
+bool FeedbackPacket::Create(uint8_t* packet,
+ size_t* position,
+ size_t max_length,
+ PacketReadyCallback* callback) const {
+ if (base_seq_ == -1)
+ return false;
+
+ while (*position + size_bytes_ > max_length) {
+ if (!OnBufferFull(packet, position, callback))
+ return false;
+ }
+
+ DCHECK_LE(base_seq_, 0xFFFF);
+ ByteWriter<uint16_t>::WriteBigEndian(&packet[*position], base_seq_);
+ *position += 2;
+
+ int64_t status_count = last_seq_ - base_seq_ + 1;
+ DCHECK_LE(status_count, 0xFFFF);
+ ByteWriter<uint16_t>::WriteBigEndian(&packet[*position], status_count);
+ *position += 2;
+
+ DCHECK_LE(base_delta_, 0xFFFF);
+ ByteWriter<int16_t>::WriteBigEndian(&packet[*position], base_delta_);
+ *position += 2;
+
+ packet[(*position)++] = feedback_seq_;
+
+ uint16_t size_words = (size_bytes_ + 3) / 4;
+ size_words -= 2; // Excluding header.
+ DCHECK_LE(size_words, 0xFF);
+ packet[(*position)++] = size_words;
+
+ // TODO(sprang): Get rid of this cast.
+ const_cast<FeedbackPacket*>(this)->EmitRemaining();
+ for (PacketStatusChunk* chunk : status_chunks_) {
+ chunk->WriteTo(&packet[*position]);
+ *position += 2;
+ }
+
+ for (int16_t delta : receive_deltas_) {
+ if (delta >= 0 && delta <= 0xFF) {
+ packet[(*position)++] = delta;
+ } else {
+ ByteWriter<int16_t>::WriteBigEndian(&packet[*position], delta);
+ *position += 2;
+ }
+ }
+
+ while ((*position % 4) != 0)
+ packet[(*position)++] = 0;
+
+ return true;
+}
+
+rtc::scoped_ptr<FeedbackPacket> FeedbackPacket::ParseFrom(const uint8_t* buffer,
+ size_t length) {
+ rtc::scoped_ptr<FeedbackPacket> packet(new FeedbackPacket());
+
+ size_t packet_size_words = 0;
+ if (length < kMinSizeBytes ||
+ length < (packet_size_words = buffer[7] * 4) + 8) {
+ LOG(LS_WARNING) << "Buffer too small (" << length
+ << " bytes) to parse feedback packet of "
+ << (packet_size_words * 4 + 8) << "bytes.";
+ return nullptr;
+ }
+
+ packet->base_seq_ = ByteReader<uint16_t>::ReadBigEndian(&buffer[0]);
+ uint16_t num_packets = ByteReader<uint16_t>::ReadBigEndian(&buffer[2]);
+ packet->base_delta_ = ByteReader<int16_t>::ReadBigEndian(&buffer[4]);
+ packet->feedback_seq_ = buffer[6];
+ size_t index = 8;
+
+ if (num_packets == 0) {
+ LOG(LS_WARNING) << "Empty feedback messages not allowed.";
+ return nullptr;
+ }
+ packet->last_seq_ = packet->base_seq_ + num_packets - 1;
+
+ size_t packets_read = 0;
+ while (packets_read < num_packets) {
+ if (index + 2 > length) {
+ LOG(LS_WARNING) << "Buffer overflow while parsing packet.";
+ return nullptr;
+ }
+
+ PacketStatusChunk* chunk =
+ ParseChunk(&buffer[index], num_packets - packets_read);
+ if (chunk == nullptr)
+ return nullptr;
+
+ index += 2;
+ packet->status_chunks_.push_back(chunk);
+ packets_read += chunk->NumSymbols();
+ }
+
+ std::vector<StatusSymbol> symbols = packet->GetStatusVector();
+
+ DCHECK_EQ(num_packets, symbols.size());
+
+ for (StatusSymbol symbol : symbols) {
+ switch (symbol) {
+ case StatusSymbol::kReceivedSmallDelta:
+ if (index + 1 > length) {
+ LOG(LS_WARNING) << "Buffer overflow while parsing packet.";
+ return nullptr;
+ }
+ packet->receive_deltas_.push_back(buffer[index]);
+ ++index;
+ break;
+ case StatusSymbol::kReceivedLargeDelta:
+ if (index + 2 > length) {
+ LOG(LS_WARNING) << "Buffer overflow while parsing packet.";
+ return nullptr;
+ }
+ packet->receive_deltas_.push_back(
+ ByteReader<int16_t>::ReadBigEndian(&buffer[index]));
+ index += 2;
+ break;
+ default:
+ continue;
+ }
+ }
+
+ DCHECK_GE(index, length - 3);
+ DCHECK_LE(index, length);
+
+ return packet;
+}
+
+FeedbackPacket::PacketStatusChunk* FeedbackPacket::ParseChunk(
+ const uint8_t* buffer,
+ size_t max_size) {
+ if (buffer[0] & 0x80) {
+ // First bit set => vector chunk.
+ std::deque<StatusSymbol> symbols;
+ if (buffer[0] & 0x40) {
+ // Second bit set => two bits per symbol vector.
+ return TwoBitVectorChunk::ParseFrom(buffer);
+ }
+
+ // Second bit not set => one bit per symbol vector.
+ return OneBitVectorChunk::ParseFrom(buffer);
+ }
+
+ // First bit not set => RLE chunk.
+ RunLengthChunk* rle_chunk = RunLengthChunk::ParseFrom(buffer);
+ if (rle_chunk->NumSymbols() > max_size) {
+ LOG(LS_WARNING) << "Header/body mismatch. "
+ "RLE block of size "
+ << rle_chunk->NumSymbols() << " but only " << max_size
+ << " left to read.";
+ delete rle_chunk;
+ return nullptr;
+ }
+ return rle_chunk;
+}
+
+} // namespace rtcp
+} // namespace webrtc

Powered by Google App Engine
This is Rietveld 408576698