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

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

Powered by Google App Engine
This is Rietveld 408576698