OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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 |
11 // This is the implementation of the PacketBuffer class. It is mostly based on | 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 | 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. | 13 // decode is at the beginning of the list. |
14 | 14 |
15 #include "webrtc/modules/audio_coding/neteq/packet_buffer.h" | 15 #include "webrtc/modules/audio_coding/neteq/packet_buffer.h" |
16 | 16 |
17 #include <algorithm> // find_if() | 17 #include <algorithm> // find_if() |
18 | 18 |
19 #include "webrtc/base/logging.h" | 19 #include "webrtc/base/logging.h" |
20 #include "webrtc/modules/audio_coding/codecs/audio_decoder.h" | 20 #include "webrtc/modules/audio_coding/codecs/audio_decoder.h" |
21 #include "webrtc/modules/audio_coding/neteq/decoder_database.h" | 21 #include "webrtc/modules/audio_coding/neteq/decoder_database.h" |
22 #include "webrtc/modules/audio_coding/neteq/tick_timer.h" | 22 #include "webrtc/modules/audio_coding/neteq/tick_timer.h" |
23 | 23 |
24 namespace webrtc { | 24 namespace webrtc { |
25 | 25 namespace { |
26 // Predicate used when inserting packets in the buffer list. | 26 // Predicate used when inserting packets in the buffer list. |
27 // Operator() returns true when |packet| goes before |new_packet|. | 27 // Operator() returns true when |packet| goes before |new_packet|. |
28 class NewTimestampIsLarger { | 28 class NewTimestampIsLarger { |
29 public: | 29 public: |
30 explicit NewTimestampIsLarger(const Packet* new_packet) | 30 explicit NewTimestampIsLarger(const Packet* new_packet) |
31 : new_packet_(new_packet) { | 31 : new_packet_(new_packet) { |
32 } | 32 } |
33 bool operator()(Packet* packet) { | 33 bool operator()(Packet* packet) { |
34 return (*new_packet_ >= *packet); | 34 return (*new_packet_ >= *packet); |
35 } | 35 } |
36 | 36 |
37 private: | 37 private: |
38 const Packet* new_packet_; | 38 const Packet* new_packet_; |
39 }; | 39 }; |
40 | 40 |
41 // Returns true if either payload types is empty; or if both payload types are | |
minyue-webrtc
2016/09/01 09:35:32
"Returns true if either payload types is empty" ca
hlundin-webrtc
2016/09/01 10:31:10
Done.
| |
42 // known to the decoder database, and have the same sample rate. | |
43 bool EqualSampleRates(rtc::Optional<uint8_t> pt1, | |
44 rtc::Optional<uint8_t> pt2, | |
45 const DecoderDatabase& decoder_database) { | |
46 if (!pt1 || !pt2) | |
47 return true; | |
48 auto di1 = decoder_database.GetDecoderInfo(*pt1); | |
49 auto di2 = decoder_database.GetDecoderInfo(*pt2); | |
50 return di1 && di2 && di1->SampleRateHz() == di2->SampleRateHz(); | |
51 } | |
52 } // namespace | |
53 | |
41 PacketBuffer::PacketBuffer(size_t max_number_of_packets, | 54 PacketBuffer::PacketBuffer(size_t max_number_of_packets, |
42 const TickTimer* tick_timer) | 55 const TickTimer* tick_timer) |
43 : max_number_of_packets_(max_number_of_packets), tick_timer_(tick_timer) {} | 56 : max_number_of_packets_(max_number_of_packets), tick_timer_(tick_timer) {} |
44 | 57 |
45 // Destructor. All packets in the buffer will be destroyed. | 58 // Destructor. All packets in the buffer will be destroyed. |
46 PacketBuffer::~PacketBuffer() { | 59 PacketBuffer::~PacketBuffer() { |
47 Flush(); | 60 Flush(); |
48 } | 61 } |
49 | 62 |
50 // Flush the buffer. All packets in the buffer will be destroyed. | 63 // Flush the buffer. All packets in the buffer will be destroyed. |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
119 **current_cng_rtp_payload_type != packet->header.payloadType) { | 132 **current_cng_rtp_payload_type != packet->header.payloadType) { |
120 // New CNG payload type implies new codec type. | 133 // New CNG payload type implies new codec type. |
121 *current_rtp_payload_type = rtc::Optional<uint8_t>(); | 134 *current_rtp_payload_type = rtc::Optional<uint8_t>(); |
122 Flush(); | 135 Flush(); |
123 flushed = true; | 136 flushed = true; |
124 } | 137 } |
125 *current_cng_rtp_payload_type = | 138 *current_cng_rtp_payload_type = |
126 rtc::Optional<uint8_t>(packet->header.payloadType); | 139 rtc::Optional<uint8_t>(packet->header.payloadType); |
127 } else if (!decoder_database.IsDtmf(packet->header.payloadType)) { | 140 } else if (!decoder_database.IsDtmf(packet->header.payloadType)) { |
128 // This must be speech. | 141 // This must be speech. |
129 if (*current_rtp_payload_type && | 142 if ((*current_rtp_payload_type && |
130 **current_rtp_payload_type != packet->header.payloadType) { | 143 **current_rtp_payload_type != packet->header.payloadType) || |
144 !EqualSampleRates(rtc::Optional<uint8_t>(packet->header.payloadType), | |
145 *current_cng_rtp_payload_type, decoder_database)) { | |
131 *current_cng_rtp_payload_type = rtc::Optional<uint8_t>(); | 146 *current_cng_rtp_payload_type = rtc::Optional<uint8_t>(); |
132 Flush(); | 147 Flush(); |
133 flushed = true; | 148 flushed = true; |
134 } | 149 } |
135 *current_rtp_payload_type = | 150 *current_rtp_payload_type = |
136 rtc::Optional<uint8_t>(packet->header.payloadType); | 151 rtc::Optional<uint8_t>(packet->header.payloadType); |
137 } | 152 } |
138 int return_val = InsertPacket(packet); | 153 int return_val = InsertPacket(packet); |
139 packet_list->pop_front(); | 154 packet_list->pop_front(); |
140 if (return_val == kFlushed) { | 155 if (return_val == kFlushed) { |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
288 // Continue while the list is not empty. | 303 // Continue while the list is not empty. |
289 } | 304 } |
290 } | 305 } |
291 | 306 |
292 void PacketBuffer::BufferStat(int* num_packets, int* max_num_packets) const { | 307 void PacketBuffer::BufferStat(int* num_packets, int* max_num_packets) const { |
293 *num_packets = static_cast<int>(buffer_.size()); | 308 *num_packets = static_cast<int>(buffer_.size()); |
294 *max_num_packets = static_cast<int>(max_number_of_packets_); | 309 *max_num_packets = static_cast<int>(max_number_of_packets_); |
295 } | 310 } |
296 | 311 |
297 } // namespace webrtc | 312 } // namespace webrtc |
OLD | NEW |