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

Side by Side Diff: webrtc/modules/audio_coding/neteq/decoder_database.cc

Issue 1868143002: Convert CNG into C++ and remove it from AudioDecoder (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Disabled CNG death tests on android. Nulled CNG_encoder[k] in RTPencode.cc upon delete. Created 4 years, 8 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 unified diff | Download patch
OLDNEW
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_type_(-1), active_cng_decoder_type_(-1) {
24 }
24 25
25 DecoderDatabase::~DecoderDatabase() {} 26 DecoderDatabase::~DecoderDatabase() = default;
26 27
27 DecoderDatabase::DecoderInfo::~DecoderInfo() { 28 DecoderDatabase::DecoderInfo::~DecoderInfo() {
28 if (!external) delete decoder; 29 if (!external) delete decoder;
29 } 30 }
30 31
31 bool DecoderDatabase::Empty() const { return decoders_.empty(); } 32 bool DecoderDatabase::Empty() const { return decoders_.empty(); }
32 33
33 int DecoderDatabase::Size() const { return static_cast<int>(decoders_.size()); } 34 int DecoderDatabase::Size() const { return static_cast<int>(decoders_.size()); }
34 35
35 void DecoderDatabase::Reset() { 36 void DecoderDatabase::Reset() {
36 decoders_.clear(); 37 decoders_.clear();
37 active_decoder_ = -1; 38 active_decoder_type_ = -1;
38 active_cng_decoder_ = -1; 39 active_cng_decoder_type_ = -1;
39 } 40 }
40 41
41 int DecoderDatabase::RegisterPayload(uint8_t rtp_payload_type, 42 int DecoderDatabase::RegisterPayload(uint8_t rtp_payload_type,
42 NetEqDecoder codec_type, 43 NetEqDecoder codec_type,
43 const std::string& name) { 44 const std::string& name) {
44 if (rtp_payload_type > 0x7F) { 45 if (rtp_payload_type > 0x7F) {
45 return kInvalidRtpPayloadType; 46 return kInvalidRtpPayloadType;
46 } 47 }
47 if (!CodecSupported(codec_type)) { 48 if (!CodecSupported(codec_type)) {
48 return kCodecNotSupported; 49 return kCodecNotSupported;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 return kDecoderExists; 83 return kDecoderExists;
83 } 84 }
84 return kOK; 85 return kOK;
85 } 86 }
86 87
87 int DecoderDatabase::Remove(uint8_t rtp_payload_type) { 88 int DecoderDatabase::Remove(uint8_t rtp_payload_type) {
88 if (decoders_.erase(rtp_payload_type) == 0) { 89 if (decoders_.erase(rtp_payload_type) == 0) {
89 // No decoder with that |rtp_payload_type|. 90 // No decoder with that |rtp_payload_type|.
90 return kDecoderNotFound; 91 return kDecoderNotFound;
91 } 92 }
92 if (active_decoder_ == rtp_payload_type) { 93 if (active_decoder_type_ == rtp_payload_type) {
93 active_decoder_ = -1; // No active decoder. 94 active_decoder_type_ = -1; // No active decoder.
94 } 95 }
95 if (active_cng_decoder_ == rtp_payload_type) { 96 if (active_cng_decoder_type_ == rtp_payload_type) {
96 active_cng_decoder_ = -1; // No active CNG decoder. 97 active_cng_decoder_type_ = -1; // No active CNG decoder.
97 } 98 }
98 return kOK; 99 return kOK;
99 } 100 }
100 101
101 const DecoderDatabase::DecoderInfo* DecoderDatabase::GetDecoderInfo( 102 const DecoderDatabase::DecoderInfo* DecoderDatabase::GetDecoderInfo(
102 uint8_t rtp_payload_type) const { 103 uint8_t rtp_payload_type) const {
103 DecoderMap::const_iterator it = decoders_.find(rtp_payload_type); 104 DecoderMap::const_iterator it = decoders_.find(rtp_payload_type);
104 if (it == decoders_.end()) { 105 if (it == decoders_.end()) {
105 // Decoder not found. 106 // Decoder not found.
106 return NULL; 107 return NULL;
107 } 108 }
108 return &(*it).second; 109 return &(*it).second;
109 } 110 }
110 111
111 uint8_t DecoderDatabase::GetRtpPayloadType( 112 uint8_t DecoderDatabase::GetRtpPayloadType(
112 NetEqDecoder codec_type) const { 113 NetEqDecoder codec_type) const {
113 DecoderMap::const_iterator it; 114 DecoderMap::const_iterator it;
114 for (it = decoders_.begin(); it != decoders_.end(); ++it) { 115 for (it = decoders_.begin(); it != decoders_.end(); ++it) {
115 if ((*it).second.codec_type == codec_type) { 116 if ((*it).second.codec_type == codec_type) {
116 // Match found. 117 // Match found.
117 return (*it).first; 118 return (*it).first;
118 } 119 }
119 } 120 }
120 // No match. 121 // No match.
121 return kRtpPayloadTypeError; 122 return kRtpPayloadTypeError;
122 } 123 }
123 124
124 AudioDecoder* DecoderDatabase::GetDecoder(uint8_t rtp_payload_type) { 125 AudioDecoder* DecoderDatabase::GetDecoder(uint8_t rtp_payload_type) {
125 if (IsDtmf(rtp_payload_type) || IsRed(rtp_payload_type)) { 126 if (IsDtmf(rtp_payload_type) || IsRed(rtp_payload_type) ||
127 IsComfortNoise(rtp_payload_type)) {
126 // These are not real decoders. 128 // These are not real decoders.
127 return NULL; 129 return NULL;
128 } 130 }
129 DecoderMap::iterator it = decoders_.find(rtp_payload_type); 131 DecoderMap::iterator it = decoders_.find(rtp_payload_type);
130 if (it == decoders_.end()) { 132 if (it == decoders_.end()) {
131 // Decoder not found. 133 // Decoder not found.
132 return NULL; 134 return NULL;
133 } 135 }
134 DecoderInfo* info = &(*it).second; 136 DecoderInfo* info = &(*it).second;
135 if (!info->decoder) { 137 if (!info->decoder) {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 } 173 }
172 174
173 int DecoderDatabase::SetActiveDecoder(uint8_t rtp_payload_type, 175 int DecoderDatabase::SetActiveDecoder(uint8_t rtp_payload_type,
174 bool* new_decoder) { 176 bool* new_decoder) {
175 // Check that |rtp_payload_type| exists in the database. 177 // Check that |rtp_payload_type| exists in the database.
176 DecoderMap::const_iterator it = decoders_.find(rtp_payload_type); 178 DecoderMap::const_iterator it = decoders_.find(rtp_payload_type);
177 if (it == decoders_.end()) { 179 if (it == decoders_.end()) {
178 // Decoder not found. 180 // Decoder not found.
179 return kDecoderNotFound; 181 return kDecoderNotFound;
180 } 182 }
183 RTC_CHECK(!IsComfortNoise(rtp_payload_type));
181 assert(new_decoder); 184 assert(new_decoder);
182 *new_decoder = false; 185 *new_decoder = false;
183 if (active_decoder_ < 0) { 186 if (active_decoder_type_ < 0) {
184 // This is the first active decoder. 187 // This is the first active decoder.
185 *new_decoder = true; 188 *new_decoder = true;
186 } else if (active_decoder_ != rtp_payload_type) { 189 } else if (active_decoder_type_ != rtp_payload_type) {
187 // Moving from one active decoder to another. Delete the first one. 190 // Moving from one active decoder to another. Delete the first one.
188 DecoderMap::iterator it = decoders_.find(active_decoder_); 191 DecoderMap::iterator it = decoders_.find(active_decoder_type_);
189 if (it == decoders_.end()) { 192 if (it == decoders_.end()) {
190 // Decoder not found. This should not be possible. 193 // Decoder not found. This should not be possible.
191 assert(false); 194 assert(false);
192 return kDecoderNotFound; 195 return kDecoderNotFound;
193 } 196 }
194 if (!(*it).second.external) { 197 if (!(*it).second.external) {
195 // Delete the AudioDecoder object, unless it is an externally created 198 // Delete the AudioDecoder object, unless it is an externally created
196 // decoder. 199 // decoder.
197 delete (*it).second.decoder; 200 delete (*it).second.decoder;
198 (*it).second.decoder = NULL; 201 (*it).second.decoder = NULL;
199 } 202 }
200 *new_decoder = true; 203 *new_decoder = true;
201 } 204 }
202 active_decoder_ = rtp_payload_type; 205 active_decoder_type_ = rtp_payload_type;
203 return kOK; 206 return kOK;
204 } 207 }
205 208
206 AudioDecoder* DecoderDatabase::GetActiveDecoder() { 209 AudioDecoder* DecoderDatabase::GetActiveDecoder() {
207 if (active_decoder_ < 0) { 210 if (active_decoder_type_ < 0) {
208 // No active decoder. 211 // No active decoder.
209 return NULL; 212 return NULL;
210 } 213 }
211 return GetDecoder(active_decoder_); 214 return GetDecoder(active_decoder_type_);
212 } 215 }
213 216
214 int DecoderDatabase::SetActiveCngDecoder(uint8_t rtp_payload_type) { 217 int DecoderDatabase::SetActiveCngDecoder(uint8_t rtp_payload_type) {
215 // Check that |rtp_payload_type| exists in the database. 218 // Check that |rtp_payload_type| exists in the database.
216 DecoderMap::const_iterator it = decoders_.find(rtp_payload_type); 219 DecoderMap::const_iterator it = decoders_.find(rtp_payload_type);
217 if (it == decoders_.end()) { 220 if (it == decoders_.end()) {
218 // Decoder not found. 221 // Decoder not found.
219 return kDecoderNotFound; 222 return kDecoderNotFound;
220 } 223 }
221 if (active_cng_decoder_ >= 0 && active_cng_decoder_ != rtp_payload_type) { 224 if (active_cng_decoder_type_ >= 0 &&
225 active_cng_decoder_type_ != rtp_payload_type) {
222 // Moving from one active CNG decoder to another. Delete the first one. 226 // Moving from one active CNG decoder to another. Delete the first one.
223 DecoderMap::iterator it = decoders_.find(active_cng_decoder_); 227 DecoderMap::iterator it = decoders_.find(active_cng_decoder_type_);
224 if (it == decoders_.end()) { 228 if (it == decoders_.end()) {
225 // Decoder not found. This should not be possible. 229 // Decoder not found. This should not be possible.
226 assert(false); 230 assert(false);
227 return kDecoderNotFound; 231 return kDecoderNotFound;
228 } 232 }
229 if (!(*it).second.external) { 233 // The CNG decoder should never be provided externally.
230 // Delete the AudioDecoder object, unless it is an externally created 234 RTC_CHECK(!it->second.external);
231 // decoder. 235 active_cng_decoder_.reset();
232 delete (*it).second.decoder;
233 (*it).second.decoder = NULL;
234 }
235 } 236 }
236 active_cng_decoder_ = rtp_payload_type; 237 active_cng_decoder_type_ = rtp_payload_type;
237 return kOK; 238 return kOK;
238 } 239 }
239 240
240 AudioDecoder* DecoderDatabase::GetActiveCngDecoder() { 241 ComfortNoiseDecoder* DecoderDatabase::GetActiveCngDecoder() {
241 if (active_cng_decoder_ < 0) { 242 if (active_cng_decoder_type_ < 0) {
242 // No active CNG decoder. 243 // No active CNG decoder.
243 return NULL; 244 return NULL;
244 } 245 }
245 return GetDecoder(active_cng_decoder_); 246 if (!active_cng_decoder_) {
247 active_cng_decoder_.reset(new ComfortNoiseDecoder);
248 }
249 return active_cng_decoder_.get();
246 } 250 }
247 251
248 int DecoderDatabase::CheckPayloadTypes(const PacketList& packet_list) const { 252 int DecoderDatabase::CheckPayloadTypes(const PacketList& packet_list) const {
249 PacketList::const_iterator it; 253 PacketList::const_iterator it;
250 for (it = packet_list.begin(); it != packet_list.end(); ++it) { 254 for (it = packet_list.begin(); it != packet_list.end(); ++it) {
251 if (decoders_.find((*it)->header.payloadType) == decoders_.end()) { 255 if (decoders_.find((*it)->header.payloadType) == decoders_.end()) {
252 // Payload type is not found. 256 // Payload type is not found.
253 LOG(LS_WARNING) << "CheckPayloadTypes: unknown RTP payload type " 257 LOG(LS_WARNING) << "CheckPayloadTypes: unknown RTP payload type "
254 << static_cast<int>((*it)->header.payloadType); 258 << static_cast<int>((*it)->header.payloadType);
255 return kDecoderNotFound; 259 return kDecoderNotFound;
256 } 260 }
257 } 261 }
258 return kOK; 262 return kOK;
259 } 263 }
260 264
261 265
262 } // namespace webrtc 266 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698