Added a ParsePayload method to AudioDecoder.
It allows the decoder to split the input up into usable chunks before
they are put into NetEq's PacketBuffer. Eventually, all packet splitting
will move into ParsePayload.
There's currently a base implementation of ParsePayload. It will
generate a single Frame that calls the underlying AudioDecoder for
getting Duration() and to Decode.
BUG=webrtc:5805
BUG=chromium:428099
Review-Url: https://codereview.webrtc.org/2326953003
Cr-Commit-Position: refs/heads/master@{#14300}
diff --git a/webrtc/modules/audio_coding/neteq/packet_buffer.cc b/webrtc/modules/audio_coding/neteq/packet_buffer.cc
index 1c8713c..c5b23dc 100644
--- a/webrtc/modules/audio_coding/neteq/packet_buffer.cc
+++ b/webrtc/modules/audio_coding/neteq/packet_buffer.cc
@@ -68,7 +68,7 @@
}
int PacketBuffer::InsertPacket(Packet* packet) {
- if (!packet || packet->payload.empty()) {
+ if (!packet || packet->empty()) {
if (packet) {
delete packet;
}
@@ -209,7 +209,7 @@
Packet* packet = buffer_.front();
// Assert that the packet sanity checks in InsertPacket method works.
- assert(packet && !packet->payload.empty());
+ RTC_DCHECK(packet && !packet->empty());
buffer_.pop_front();
// Discard other packets with the same timestamp. These are duplicates or
@@ -237,8 +237,8 @@
return kBufferEmpty;
}
// Assert that the packet sanity checks in InsertPacket method works.
- assert(buffer_.front());
- assert(!buffer_.front()->payload.empty());
+ RTC_DCHECK(buffer_.front());
+ RTC_DCHECK(!buffer_.front()->empty());
DeleteFirstPacket(&buffer_);
return kOK;
}
@@ -260,26 +260,32 @@
return DiscardOldPackets(timestamp_limit, 0);
}
+void PacketBuffer::DiscardPacketsWithPayloadType(uint8_t payload_type) {
+ for (auto it = buffer_.begin(); it != buffer_.end(); /* */) {
+ Packet *packet = *it;
+ if (packet->header.payloadType == payload_type) {
+ delete packet;
+ it = buffer_.erase(it);
+ } else {
+ ++it;
+ }
+ }
+}
+
size_t PacketBuffer::NumPacketsInBuffer() const {
return buffer_.size();
}
-size_t PacketBuffer::NumSamplesInBuffer(DecoderDatabase* decoder_database,
- size_t last_decoded_length) const {
- PacketList::const_iterator it;
+size_t PacketBuffer::NumSamplesInBuffer(size_t last_decoded_length) const {
size_t num_samples = 0;
size_t last_duration = last_decoded_length;
- for (it = buffer_.begin(); it != buffer_.end(); ++it) {
- Packet* packet = (*it);
- AudioDecoder* decoder =
- decoder_database->GetDecoder(packet->header.payloadType);
- if (decoder) {
+ for (Packet* packet : buffer_) {
+ if (packet->frame) {
if (!packet->primary) {
continue;
}
- int duration = decoder->PacketDuration(packet->payload.data(),
- packet->payload.size());
- if (duration >= 0) {
+ size_t duration = packet->frame->Duration();
+ if (duration > 0) {
last_duration = duration; // Save the most up-to-date (valid) duration.
}
}