henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | // This is the implementation of the PacketBuffer class. It is mostly based on |
| 12 | // an STL list. The list is kept sorted at all times so that the next packet to |
| 13 | // decode is at the beginning of the list. |
| 14 | |
henrik.lundin@webrtc.org | 9c55f0f | 2014-06-09 08:10:28 +0000 | [diff] [blame] | 15 | #include "webrtc/modules/audio_coding/neteq/packet_buffer.h" |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 16 | |
| 17 | #include <algorithm> // find_if() |
| 18 | |
kwiberg | 087bd34 | 2017-02-10 08:15:44 -0800 | [diff] [blame] | 19 | #include "webrtc/api/audio_codecs/audio_decoder.h" |
henrik.lundin@webrtc.org | 9c55f0f | 2014-06-09 08:10:28 +0000 | [diff] [blame] | 20 | #include "webrtc/modules/audio_coding/neteq/decoder_database.h" |
minyue-webrtc | fae474c | 2017-07-05 11:17:40 +0200 | [diff] [blame] | 21 | #include "webrtc/modules/audio_coding/neteq/statistics_calculator.h" |
henrik.lundin | 84f8cd6 | 2016-04-26 07:45:16 -0700 | [diff] [blame] | 22 | #include "webrtc/modules/audio_coding/neteq/tick_timer.h" |
Edward Lemur | c20978e | 2017-07-06 19:44:34 +0200 | [diff] [blame] | 23 | #include "webrtc/rtc_base/logging.h" |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 24 | |
| 25 | namespace webrtc { |
henrik.lundin | 067d855 | 2016-09-01 23:19:05 -0700 | [diff] [blame] | 26 | namespace { |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 27 | // Predicate used when inserting packets in the buffer list. |
| 28 | // Operator() returns true when |packet| goes before |new_packet|. |
| 29 | class NewTimestampIsLarger { |
| 30 | public: |
ossu | a73f6c9 | 2016-10-24 08:25:28 -0700 | [diff] [blame] | 31 | explicit NewTimestampIsLarger(const Packet& new_packet) |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 32 | : new_packet_(new_packet) { |
| 33 | } |
ossu | a73f6c9 | 2016-10-24 08:25:28 -0700 | [diff] [blame] | 34 | bool operator()(const Packet& packet) { |
| 35 | return (new_packet_ >= packet); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | private: |
ossu | a73f6c9 | 2016-10-24 08:25:28 -0700 | [diff] [blame] | 39 | const Packet& new_packet_; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 40 | }; |
| 41 | |
henrik.lundin | 067d855 | 2016-09-01 23:19:05 -0700 | [diff] [blame] | 42 | // Returns true if both payload types are known to the decoder database, and |
| 43 | // have the same sample rate. |
| 44 | bool EqualSampleRates(uint8_t pt1, |
| 45 | uint8_t pt2, |
| 46 | const DecoderDatabase& decoder_database) { |
kjellander | 7c85658 | 2017-02-26 19:53:40 -0800 | [diff] [blame] | 47 | auto* di1 = decoder_database.GetDecoderInfo(pt1); |
| 48 | auto* di2 = decoder_database.GetDecoderInfo(pt2); |
henrik.lundin | 067d855 | 2016-09-01 23:19:05 -0700 | [diff] [blame] | 49 | return di1 && di2 && di1->SampleRateHz() == di2->SampleRateHz(); |
| 50 | } |
| 51 | } // namespace |
| 52 | |
henrik.lundin | 84f8cd6 | 2016-04-26 07:45:16 -0700 | [diff] [blame] | 53 | PacketBuffer::PacketBuffer(size_t max_number_of_packets, |
| 54 | const TickTimer* tick_timer) |
| 55 | : max_number_of_packets_(max_number_of_packets), tick_timer_(tick_timer) {} |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 56 | |
| 57 | // Destructor. All packets in the buffer will be destroyed. |
| 58 | PacketBuffer::~PacketBuffer() { |
| 59 | Flush(); |
| 60 | } |
| 61 | |
| 62 | // Flush the buffer. All packets in the buffer will be destroyed. |
| 63 | void PacketBuffer::Flush() { |
ossu | a73f6c9 | 2016-10-24 08:25:28 -0700 | [diff] [blame] | 64 | buffer_.clear(); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 65 | } |
| 66 | |
Karl Wiberg | 7f6c4d4 | 2015-04-09 15:44:22 +0200 | [diff] [blame] | 67 | bool PacketBuffer::Empty() const { |
| 68 | return buffer_.empty(); |
| 69 | } |
| 70 | |
ossu | a73f6c9 | 2016-10-24 08:25:28 -0700 | [diff] [blame] | 71 | int PacketBuffer::InsertPacket(Packet&& packet) { |
| 72 | if (packet.empty()) { |
Henrik Lundin | d67a219 | 2015-08-03 12:54:37 +0200 | [diff] [blame] | 73 | LOG(LS_WARNING) << "InsertPacket invalid packet"; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 74 | return kInvalidPacket; |
| 75 | } |
| 76 | |
ossu | a73f6c9 | 2016-10-24 08:25:28 -0700 | [diff] [blame] | 77 | RTC_DCHECK_GE(packet.priority.codec_level, 0); |
| 78 | RTC_DCHECK_GE(packet.priority.red_level, 0); |
ossu | a70695a | 2016-09-22 02:06:28 -0700 | [diff] [blame] | 79 | |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 80 | int return_val = kOK; |
| 81 | |
ossu | a73f6c9 | 2016-10-24 08:25:28 -0700 | [diff] [blame] | 82 | packet.waiting_time = tick_timer_->GetNewStopwatch(); |
henrik.lundin | 84f8cd6 | 2016-04-26 07:45:16 -0700 | [diff] [blame] | 83 | |
henrik.lundin@webrtc.org | 116ed1d | 2014-04-28 08:20:04 +0000 | [diff] [blame] | 84 | if (buffer_.size() >= max_number_of_packets_) { |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 85 | // Buffer is full. Flush it. |
| 86 | Flush(); |
Henrik Lundin | d67a219 | 2015-08-03 12:54:37 +0200 | [diff] [blame] | 87 | LOG(LS_WARNING) << "Packet buffer flushed"; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 88 | return_val = kFlushed; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | // Get an iterator pointing to the place in the buffer where the new packet |
| 92 | // should be inserted. The list is searched from the back, since the most |
| 93 | // likely case is that the new packet should be near the end of the list. |
| 94 | PacketList::reverse_iterator rit = std::find_if( |
| 95 | buffer_.rbegin(), buffer_.rend(), |
| 96 | NewTimestampIsLarger(packet)); |
minyue@webrtc.org | c803907 | 2014-10-09 10:49:54 +0000 | [diff] [blame] | 97 | |
| 98 | // The new packet is to be inserted to the right of |rit|. If it has the same |
| 99 | // timestamp as |rit|, which has a higher priority, do not insert the new |
| 100 | // packet to list. |
ossu | a73f6c9 | 2016-10-24 08:25:28 -0700 | [diff] [blame] | 101 | if (rit != buffer_.rend() && packet.timestamp == rit->timestamp) { |
minyue@webrtc.org | c803907 | 2014-10-09 10:49:54 +0000 | [diff] [blame] | 102 | return return_val; |
| 103 | } |
| 104 | |
| 105 | // The new packet is to be inserted to the left of |it|. If it has the same |
| 106 | // timestamp as |it|, which has a lower priority, replace |it| with the new |
| 107 | // packet. |
| 108 | PacketList::iterator it = rit.base(); |
ossu | a73f6c9 | 2016-10-24 08:25:28 -0700 | [diff] [blame] | 109 | if (it != buffer_.end() && packet.timestamp == it->timestamp) { |
minyue@webrtc.org | c803907 | 2014-10-09 10:49:54 +0000 | [diff] [blame] | 110 | it = buffer_.erase(it); |
| 111 | } |
ossu | a73f6c9 | 2016-10-24 08:25:28 -0700 | [diff] [blame] | 112 | buffer_.insert(it, std::move(packet)); // Insert the packet at that position. |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 113 | |
| 114 | return return_val; |
| 115 | } |
| 116 | |
henrik.lundin | da8bbf6 | 2016-08-31 03:14:11 -0700 | [diff] [blame] | 117 | int PacketBuffer::InsertPacketList( |
| 118 | PacketList* packet_list, |
| 119 | const DecoderDatabase& decoder_database, |
| 120 | rtc::Optional<uint8_t>* current_rtp_payload_type, |
| 121 | rtc::Optional<uint8_t>* current_cng_rtp_payload_type) { |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 122 | bool flushed = false; |
ossu | a73f6c9 | 2016-10-24 08:25:28 -0700 | [diff] [blame] | 123 | for (auto& packet : *packet_list) { |
| 124 | if (decoder_database.IsComfortNoise(packet.payload_type)) { |
henrik.lundin | da8bbf6 | 2016-08-31 03:14:11 -0700 | [diff] [blame] | 125 | if (*current_cng_rtp_payload_type && |
ossu | a73f6c9 | 2016-10-24 08:25:28 -0700 | [diff] [blame] | 126 | **current_cng_rtp_payload_type != packet.payload_type) { |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 127 | // New CNG payload type implies new codec type. |
henrik.lundin | da8bbf6 | 2016-08-31 03:14:11 -0700 | [diff] [blame] | 128 | *current_rtp_payload_type = rtc::Optional<uint8_t>(); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 129 | Flush(); |
| 130 | flushed = true; |
| 131 | } |
henrik.lundin | da8bbf6 | 2016-08-31 03:14:11 -0700 | [diff] [blame] | 132 | *current_cng_rtp_payload_type = |
ossu | a73f6c9 | 2016-10-24 08:25:28 -0700 | [diff] [blame] | 133 | rtc::Optional<uint8_t>(packet.payload_type); |
| 134 | } else if (!decoder_database.IsDtmf(packet.payload_type)) { |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 135 | // This must be speech. |
henrik.lundin | 067d855 | 2016-09-01 23:19:05 -0700 | [diff] [blame] | 136 | if ((*current_rtp_payload_type && |
ossu | a73f6c9 | 2016-10-24 08:25:28 -0700 | [diff] [blame] | 137 | **current_rtp_payload_type != packet.payload_type) || |
henrik.lundin | 067d855 | 2016-09-01 23:19:05 -0700 | [diff] [blame] | 138 | (*current_cng_rtp_payload_type && |
ossu | a73f6c9 | 2016-10-24 08:25:28 -0700 | [diff] [blame] | 139 | !EqualSampleRates(packet.payload_type, |
henrik.lundin | 067d855 | 2016-09-01 23:19:05 -0700 | [diff] [blame] | 140 | **current_cng_rtp_payload_type, |
| 141 | decoder_database))) { |
henrik.lundin | da8bbf6 | 2016-08-31 03:14:11 -0700 | [diff] [blame] | 142 | *current_cng_rtp_payload_type = rtc::Optional<uint8_t>(); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 143 | Flush(); |
| 144 | flushed = true; |
| 145 | } |
ossu | a73f6c9 | 2016-10-24 08:25:28 -0700 | [diff] [blame] | 146 | *current_rtp_payload_type = rtc::Optional<uint8_t>(packet.payload_type); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 147 | } |
ossu | a73f6c9 | 2016-10-24 08:25:28 -0700 | [diff] [blame] | 148 | int return_val = InsertPacket(std::move(packet)); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 149 | if (return_val == kFlushed) { |
| 150 | // The buffer flushed, but this is not an error. We can still continue. |
| 151 | flushed = true; |
| 152 | } else if (return_val != kOK) { |
| 153 | // An error occurred. Delete remaining packets in list and return. |
ossu | a73f6c9 | 2016-10-24 08:25:28 -0700 | [diff] [blame] | 154 | packet_list->clear(); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 155 | return return_val; |
| 156 | } |
| 157 | } |
ossu | a73f6c9 | 2016-10-24 08:25:28 -0700 | [diff] [blame] | 158 | packet_list->clear(); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 159 | return flushed ? kFlushed : kOK; |
| 160 | } |
| 161 | |
| 162 | int PacketBuffer::NextTimestamp(uint32_t* next_timestamp) const { |
| 163 | if (Empty()) { |
| 164 | return kBufferEmpty; |
| 165 | } |
| 166 | if (!next_timestamp) { |
| 167 | return kInvalidPointer; |
| 168 | } |
ossu | a73f6c9 | 2016-10-24 08:25:28 -0700 | [diff] [blame] | 169 | *next_timestamp = buffer_.front().timestamp; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 170 | return kOK; |
| 171 | } |
| 172 | |
| 173 | int PacketBuffer::NextHigherTimestamp(uint32_t timestamp, |
| 174 | uint32_t* next_timestamp) const { |
| 175 | if (Empty()) { |
| 176 | return kBufferEmpty; |
| 177 | } |
| 178 | if (!next_timestamp) { |
| 179 | return kInvalidPointer; |
| 180 | } |
| 181 | PacketList::const_iterator it; |
| 182 | for (it = buffer_.begin(); it != buffer_.end(); ++it) { |
ossu | a73f6c9 | 2016-10-24 08:25:28 -0700 | [diff] [blame] | 183 | if (it->timestamp >= timestamp) { |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 184 | // Found a packet matching the search. |
ossu | a73f6c9 | 2016-10-24 08:25:28 -0700 | [diff] [blame] | 185 | *next_timestamp = it->timestamp; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 186 | return kOK; |
| 187 | } |
| 188 | } |
| 189 | return kNotFound; |
| 190 | } |
| 191 | |
ossu | 7a37761 | 2016-10-18 04:06:13 -0700 | [diff] [blame] | 192 | const Packet* PacketBuffer::PeekNextPacket() const { |
ossu | a73f6c9 | 2016-10-24 08:25:28 -0700 | [diff] [blame] | 193 | return buffer_.empty() ? nullptr : &buffer_.front(); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 194 | } |
| 195 | |
ossu | a73f6c9 | 2016-10-24 08:25:28 -0700 | [diff] [blame] | 196 | rtc::Optional<Packet> PacketBuffer::GetNextPacket() { |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 197 | if (Empty()) { |
| 198 | // Buffer is empty. |
ossu | a73f6c9 | 2016-10-24 08:25:28 -0700 | [diff] [blame] | 199 | return rtc::Optional<Packet>(); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 200 | } |
| 201 | |
ossu | a73f6c9 | 2016-10-24 08:25:28 -0700 | [diff] [blame] | 202 | rtc::Optional<Packet> packet(std::move(buffer_.front())); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 203 | // Assert that the packet sanity checks in InsertPacket method works. |
ossu | a73f6c9 | 2016-10-24 08:25:28 -0700 | [diff] [blame] | 204 | RTC_DCHECK(!packet->empty()); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 205 | buffer_.pop_front(); |
minyue@webrtc.org | c803907 | 2014-10-09 10:49:54 +0000 | [diff] [blame] | 206 | |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 207 | return packet; |
| 208 | } |
| 209 | |
minyue-webrtc | fae474c | 2017-07-05 11:17:40 +0200 | [diff] [blame] | 210 | int PacketBuffer::DiscardNextPacket(StatisticsCalculator* stats) { |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 211 | if (Empty()) { |
| 212 | return kBufferEmpty; |
| 213 | } |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 214 | // Assert that the packet sanity checks in InsertPacket method works. |
ossu | a73f6c9 | 2016-10-24 08:25:28 -0700 | [diff] [blame] | 215 | RTC_DCHECK(!buffer_.front().empty()); |
| 216 | buffer_.pop_front(); |
minyue-webrtc | fae474c | 2017-07-05 11:17:40 +0200 | [diff] [blame] | 217 | stats->PacketsDiscarded(1); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 218 | return kOK; |
| 219 | } |
| 220 | |
minyue-webrtc | fae474c | 2017-07-05 11:17:40 +0200 | [diff] [blame] | 221 | void PacketBuffer::DiscardOldPackets(uint32_t timestamp_limit, |
| 222 | uint32_t horizon_samples, |
| 223 | StatisticsCalculator* stats) { |
henrik.lundin | 63d146b | 2017-07-05 07:03:34 -0700 | [diff] [blame] | 224 | const size_t old_size = buffer_.size(); |
| 225 | buffer_.remove_if([timestamp_limit, horizon_samples](const Packet& p) { |
| 226 | return timestamp_limit != p.timestamp && |
| 227 | IsObsoleteTimestamp(p.timestamp, timestamp_limit, horizon_samples); |
| 228 | }); |
| 229 | if (old_size > buffer_.size()) { |
| 230 | stats->PacketsDiscarded(old_size - buffer_.size()); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 231 | } |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 232 | } |
| 233 | |
minyue-webrtc | fae474c | 2017-07-05 11:17:40 +0200 | [diff] [blame] | 234 | void PacketBuffer::DiscardAllOldPackets(uint32_t timestamp_limit, |
| 235 | StatisticsCalculator* stats) { |
| 236 | DiscardOldPackets(timestamp_limit, 0, stats); |
Karl Wiberg | 7f6c4d4 | 2015-04-09 15:44:22 +0200 | [diff] [blame] | 237 | } |
| 238 | |
minyue-webrtc | fae474c | 2017-07-05 11:17:40 +0200 | [diff] [blame] | 239 | void PacketBuffer::DiscardPacketsWithPayloadType(uint8_t payload_type, |
| 240 | StatisticsCalculator* stats) { |
| 241 | int packets_discarded = 0; |
ossu | 61a208b | 2016-09-20 01:38:00 -0700 | [diff] [blame] | 242 | for (auto it = buffer_.begin(); it != buffer_.end(); /* */) { |
ossu | a73f6c9 | 2016-10-24 08:25:28 -0700 | [diff] [blame] | 243 | const Packet& packet = *it; |
| 244 | if (packet.payload_type == payload_type) { |
ossu | 61a208b | 2016-09-20 01:38:00 -0700 | [diff] [blame] | 245 | it = buffer_.erase(it); |
minyue-webrtc | fae474c | 2017-07-05 11:17:40 +0200 | [diff] [blame] | 246 | ++packets_discarded; |
ossu | 61a208b | 2016-09-20 01:38:00 -0700 | [diff] [blame] | 247 | } else { |
| 248 | ++it; |
| 249 | } |
| 250 | } |
minyue-webrtc | fae474c | 2017-07-05 11:17:40 +0200 | [diff] [blame] | 251 | if (packets_discarded > 0) |
| 252 | stats->PacketsDiscarded(packets_discarded); |
ossu | 61a208b | 2016-09-20 01:38:00 -0700 | [diff] [blame] | 253 | } |
| 254 | |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 255 | size_t PacketBuffer::NumPacketsInBuffer() const { |
| 256 | return buffer_.size(); |
Karl Wiberg | 7f6c4d4 | 2015-04-09 15:44:22 +0200 | [diff] [blame] | 257 | } |
| 258 | |
ossu | 61a208b | 2016-09-20 01:38:00 -0700 | [diff] [blame] | 259 | size_t PacketBuffer::NumSamplesInBuffer(size_t last_decoded_length) const { |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 260 | size_t num_samples = 0; |
| 261 | size_t last_duration = last_decoded_length; |
ossu | a73f6c9 | 2016-10-24 08:25:28 -0700 | [diff] [blame] | 262 | for (const Packet& packet : buffer_) { |
| 263 | if (packet.frame) { |
ossu | a70695a | 2016-09-22 02:06:28 -0700 | [diff] [blame] | 264 | // TODO(hlundin): Verify that it's fine to count all packets and remove |
| 265 | // this check. |
ossu | a73f6c9 | 2016-10-24 08:25:28 -0700 | [diff] [blame] | 266 | if (packet.priority != Packet::Priority(0, 0)) { |
minyue@webrtc.org | 0aa3ee6 | 2014-05-28 07:48:01 +0000 | [diff] [blame] | 267 | continue; |
minyue@webrtc.org | b28bfa7 | 2014-03-21 12:07:40 +0000 | [diff] [blame] | 268 | } |
ossu | a73f6c9 | 2016-10-24 08:25:28 -0700 | [diff] [blame] | 269 | size_t duration = packet.frame->Duration(); |
ossu | 61a208b | 2016-09-20 01:38:00 -0700 | [diff] [blame] | 270 | if (duration > 0) { |
turaj@webrtc.org | 7b75ac6 | 2013-09-26 00:27:56 +0000 | [diff] [blame] | 271 | last_duration = duration; // Save the most up-to-date (valid) duration. |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 272 | } |
| 273 | } |
turaj@webrtc.org | 7b75ac6 | 2013-09-26 00:27:56 +0000 | [diff] [blame] | 274 | num_samples += last_duration; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 275 | } |
| 276 | return num_samples; |
| 277 | } |
| 278 | |
henrik.lundin@webrtc.org | 116ed1d | 2014-04-28 08:20:04 +0000 | [diff] [blame] | 279 | void PacketBuffer::BufferStat(int* num_packets, int* max_num_packets) const { |
turaj@webrtc.org | 362a55e | 2013-09-20 16:25:28 +0000 | [diff] [blame] | 280 | *num_packets = static_cast<int>(buffer_.size()); |
| 281 | *max_num_packets = static_cast<int>(max_number_of_packets_); |
turaj@webrtc.org | 7df9706 | 2013-08-02 18:07:13 +0000 | [diff] [blame] | 282 | } |
| 283 | |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 284 | } // namespace webrtc |