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 #include "webrtc/modules/audio_coding/neteq/decoder_database.h" | 11 #include "webrtc/modules/audio_coding/neteq/decoder_database.h" |
12 | 12 |
13 #include <assert.h> | 13 #include <assert.h> |
14 #include <utility> // pair | 14 #include <utility> // pair |
15 | 15 |
16 #include "webrtc/base/checks.h" | 16 #include "webrtc/base/checks.h" |
17 #include "webrtc/base/logging.h" | 17 #include "webrtc/base/logging.h" |
18 #include "webrtc/modules/audio_coding/codecs/audio_decoder.h" | 18 #include "webrtc/modules/audio_coding/codecs/audio_decoder.h" |
19 | 19 |
20 namespace webrtc { | 20 namespace webrtc { |
21 | 21 |
22 DecoderDatabase::DecoderDatabase() | 22 DecoderDatabase::DecoderDatabase() |
23 : active_decoder_(-1), active_cng_decoder_(-1) {} | 23 : active_decoder_(-1), active_cng_decoder_(-1), |
24 active_cng_dec_inst_(nullptr) { } | |
24 | 25 |
25 DecoderDatabase::~DecoderDatabase() {} | 26 DecoderDatabase::~DecoderDatabase() { |
27 if (active_cng_dec_inst_) | |
28 WebRtcCng_FreeDec(active_cng_dec_inst_); | |
kwiberg-webrtc
2016/04/09 07:34:49
Having to write destructor code manually is almost
ossu
2016/04/11 08:31:10
I think wrapping it is probably the best. This is
hlundin-webrtc
2016/04/11 11:33:00
I think it is ok to leave some of this debt behind
| |
29 } | |
26 | 30 |
27 DecoderDatabase::DecoderInfo::~DecoderInfo() { | 31 DecoderDatabase::DecoderInfo::~DecoderInfo() { |
28 if (!external) delete decoder; | 32 if (!external) delete decoder; |
29 } | 33 } |
30 | 34 |
31 bool DecoderDatabase::Empty() const { return decoders_.empty(); } | 35 bool DecoderDatabase::Empty() const { return decoders_.empty(); } |
32 | 36 |
33 int DecoderDatabase::Size() const { return static_cast<int>(decoders_.size()); } | 37 int DecoderDatabase::Size() const { return static_cast<int>(decoders_.size()); } |
34 | 38 |
35 void DecoderDatabase::Reset() { | 39 void DecoderDatabase::Reset() { |
(...skipping 79 matching lines...) Loading... | |
115 if ((*it).second.codec_type == codec_type) { | 119 if ((*it).second.codec_type == codec_type) { |
116 // Match found. | 120 // Match found. |
117 return (*it).first; | 121 return (*it).first; |
118 } | 122 } |
119 } | 123 } |
120 // No match. | 124 // No match. |
121 return kRtpPayloadTypeError; | 125 return kRtpPayloadTypeError; |
122 } | 126 } |
123 | 127 |
124 AudioDecoder* DecoderDatabase::GetDecoder(uint8_t rtp_payload_type) { | 128 AudioDecoder* DecoderDatabase::GetDecoder(uint8_t rtp_payload_type) { |
125 if (IsDtmf(rtp_payload_type) || IsRed(rtp_payload_type)) { | 129 if (IsDtmf(rtp_payload_type) || IsRed(rtp_payload_type) || |
130 IsComfortNoise(rtp_payload_type)) { | |
126 // These are not real decoders. | 131 // These are not real decoders. |
127 return NULL; | 132 return NULL; |
128 } | 133 } |
129 DecoderMap::iterator it = decoders_.find(rtp_payload_type); | 134 DecoderMap::iterator it = decoders_.find(rtp_payload_type); |
130 if (it == decoders_.end()) { | 135 if (it == decoders_.end()) { |
131 // Decoder not found. | 136 // Decoder not found. |
132 return NULL; | 137 return NULL; |
133 } | 138 } |
134 DecoderInfo* info = &(*it).second; | 139 DecoderInfo* info = &(*it).second; |
135 if (!info->decoder) { | 140 if (!info->decoder) { |
(...skipping 35 matching lines...) Loading... | |
171 } | 176 } |
172 | 177 |
173 int DecoderDatabase::SetActiveDecoder(uint8_t rtp_payload_type, | 178 int DecoderDatabase::SetActiveDecoder(uint8_t rtp_payload_type, |
174 bool* new_decoder) { | 179 bool* new_decoder) { |
175 // Check that |rtp_payload_type| exists in the database. | 180 // Check that |rtp_payload_type| exists in the database. |
176 DecoderMap::const_iterator it = decoders_.find(rtp_payload_type); | 181 DecoderMap::const_iterator it = decoders_.find(rtp_payload_type); |
177 if (it == decoders_.end()) { | 182 if (it == decoders_.end()) { |
178 // Decoder not found. | 183 // Decoder not found. |
179 return kDecoderNotFound; | 184 return kDecoderNotFound; |
180 } | 185 } |
186 RTC_CHECK(!IsComfortNoise(rtp_payload_type)); | |
181 assert(new_decoder); | 187 assert(new_decoder); |
182 *new_decoder = false; | 188 *new_decoder = false; |
183 if (active_decoder_ < 0) { | 189 if (active_decoder_ < 0) { |
184 // This is the first active decoder. | 190 // This is the first active decoder. |
185 *new_decoder = true; | 191 *new_decoder = true; |
186 } else if (active_decoder_ != rtp_payload_type) { | 192 } else if (active_decoder_ != rtp_payload_type) { |
187 // Moving from one active decoder to another. Delete the first one. | 193 // Moving from one active decoder to another. Delete the first one. |
188 DecoderMap::iterator it = decoders_.find(active_decoder_); | 194 DecoderMap::iterator it = decoders_.find(active_decoder_); |
189 if (it == decoders_.end()) { | 195 if (it == decoders_.end()) { |
190 // Decoder not found. This should not be possible. | 196 // Decoder not found. This should not be possible. |
(...skipping 28 matching lines...) Loading... | |
219 return kDecoderNotFound; | 225 return kDecoderNotFound; |
220 } | 226 } |
221 if (active_cng_decoder_ >= 0 && active_cng_decoder_ != rtp_payload_type) { | 227 if (active_cng_decoder_ >= 0 && active_cng_decoder_ != rtp_payload_type) { |
222 // Moving from one active CNG decoder to another. Delete the first one. | 228 // Moving from one active CNG decoder to another. Delete the first one. |
223 DecoderMap::iterator it = decoders_.find(active_cng_decoder_); | 229 DecoderMap::iterator it = decoders_.find(active_cng_decoder_); |
224 if (it == decoders_.end()) { | 230 if (it == decoders_.end()) { |
225 // Decoder not found. This should not be possible. | 231 // Decoder not found. This should not be possible. |
226 assert(false); | 232 assert(false); |
227 return kDecoderNotFound; | 233 return kDecoderNotFound; |
228 } | 234 } |
229 if (!(*it).second.external) { | 235 RTC_CHECK(!(*it).second.external); |
kwiberg-webrtc
2016/04/09 07:34:49
Since you're rewriting this line anyway, please ch
ossu
2016/04/11 08:31:10
Acknowledged.
| |
230 // Delete the AudioDecoder object, unless it is an externally created | 236 if (active_cng_dec_inst_) { |
231 // decoder. | 237 WebRtcCng_FreeDec(active_cng_dec_inst_); |
232 delete (*it).second.decoder; | 238 active_cng_dec_inst_ = nullptr; |
233 (*it).second.decoder = NULL; | |
234 } | 239 } |
235 } | 240 } |
236 active_cng_decoder_ = rtp_payload_type; | 241 active_cng_decoder_ = rtp_payload_type; |
237 return kOK; | 242 return kOK; |
238 } | 243 } |
239 | 244 |
240 AudioDecoder* DecoderDatabase::GetActiveCngDecoder() { | 245 CNG_dec_inst* DecoderDatabase::GetActiveCngDecoder() { |
241 if (active_cng_decoder_ < 0) { | 246 if (active_cng_decoder_ < 0) { |
242 // No active CNG decoder. | 247 // No active CNG decoder. |
243 return NULL; | 248 return NULL; |
244 } | 249 } |
245 return GetDecoder(active_cng_decoder_); | 250 if (!active_cng_dec_inst_) { |
251 RTC_CHECK_EQ(0, WebRtcCng_CreateDec(&active_cng_dec_inst_)); | |
252 WebRtcCng_InitDec(active_cng_dec_inst_); | |
253 } | |
254 return active_cng_dec_inst_; | |
246 } | 255 } |
247 | 256 |
248 int DecoderDatabase::CheckPayloadTypes(const PacketList& packet_list) const { | 257 int DecoderDatabase::CheckPayloadTypes(const PacketList& packet_list) const { |
249 PacketList::const_iterator it; | 258 PacketList::const_iterator it; |
250 for (it = packet_list.begin(); it != packet_list.end(); ++it) { | 259 for (it = packet_list.begin(); it != packet_list.end(); ++it) { |
251 if (decoders_.find((*it)->header.payloadType) == decoders_.end()) { | 260 if (decoders_.find((*it)->header.payloadType) == decoders_.end()) { |
252 // Payload type is not found. | 261 // Payload type is not found. |
253 LOG(LS_WARNING) << "CheckPayloadTypes: unknown RTP payload type " | 262 LOG(LS_WARNING) << "CheckPayloadTypes: unknown RTP payload type " |
254 << static_cast<int>((*it)->header.payloadType); | 263 << static_cast<int>((*it)->header.payloadType); |
255 return kDecoderNotFound; | 264 return kDecoderNotFound; |
256 } | 265 } |
257 } | 266 } |
258 return kOK; | 267 return kOK; |
259 } | 268 } |
260 | 269 |
261 | 270 |
262 } // namespace webrtc | 271 } // namespace webrtc |
OLD | NEW |