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

Side by Side Diff: webrtc/modules/audio_coding/main/acm2/acm_codec_database.cc

Issue 1412683006: RentACodec: New class that takes over part of ACMCodecDB's job (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 5 years, 1 month 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
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 , kDecoderAVT 216 , kDecoderAVT
217 #ifdef WEBRTC_CODEC_RED 217 #ifdef WEBRTC_CODEC_RED
218 , kDecoderRED 218 , kDecoderRED
219 #endif 219 #endif
220 }; 220 };
221 221
222 // Get codec information from database. 222 // Get codec information from database.
223 // TODO(tlegrand): replace memcpy with a pointer to the data base memory. 223 // TODO(tlegrand): replace memcpy with a pointer to the data base memory.
224 int ACMCodecDB::Codec(int codec_id, CodecInst* codec_inst) { 224 int ACMCodecDB::Codec(int codec_id, CodecInst* codec_inst) {
225 // Error check to see that codec_id is not out of bounds. 225 // Error check to see that codec_id is not out of bounds.
226 if ((codec_id < 0) || (codec_id >= kNumCodecs)) { 226 if (static_cast<size_t>(codec_id) >= RentACodec::NumberOfCodecs()) {
227 return -1; 227 return -1;
228 } 228 }
229 229
230 // Copy database information for the codec to the output. 230 // Copy database information for the codec to the output.
231 memcpy(codec_inst, &database_[codec_id], sizeof(CodecInst)); 231 memcpy(codec_inst, &database_[codec_id], sizeof(CodecInst));
232 232
233 return 0; 233 return 0;
234 } 234 }
235 235
236 // Enumerator for error codes when asking for codec database id. 236 // Enumerator for error codes when asking for codec database id.
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 // codec list. Need to check all three since some codecs have several codec 311 // codec list. Need to check all three since some codecs have several codec
312 // entries with different frequencies and/or channels. 312 // entries with different frequencies and/or channels.
313 // Does not check other codec settings, such as payload type and packet size. 313 // Does not check other codec settings, such as payload type and packet size.
314 // Returns the id of the codec, or -1 if no match is found. 314 // Returns the id of the codec, or -1 if no match is found.
315 int ACMCodecDB::CodecId(const CodecInst& codec_inst) { 315 int ACMCodecDB::CodecId(const CodecInst& codec_inst) {
316 return (CodecId(codec_inst.plname, codec_inst.plfreq, 316 return (CodecId(codec_inst.plname, codec_inst.plfreq,
317 codec_inst.channels)); 317 codec_inst.channels));
318 } 318 }
319 319
320 int ACMCodecDB::CodecId(const char* payload_name, int frequency, int channels) { 320 int ACMCodecDB::CodecId(const char* payload_name, int frequency, int channels) {
321 for (int id = 0; id < kNumCodecs; id++) { 321 for (const CodecInst& ci : RentACodec::Database()) {
322 bool name_match = false; 322 bool name_match = false;
323 bool frequency_match = false; 323 bool frequency_match = false;
324 bool channels_match = false; 324 bool channels_match = false;
325 325
326 // Payload name, sampling frequency and number of channels need to match. 326 // Payload name, sampling frequency and number of channels need to match.
327 // NOTE! If |frequency| is -1, the frequency is not applicable, and is 327 // NOTE! If |frequency| is -1, the frequency is not applicable, and is
328 // always treated as true, like for RED. 328 // always treated as true, like for RED.
329 name_match = (STR_CASE_CMP(database_[id].plname, payload_name) == 0); 329 name_match = (STR_CASE_CMP(ci.plname, payload_name) == 0);
330 frequency_match = (frequency == database_[id].plfreq) || (frequency == -1); 330 frequency_match = (frequency == ci.plfreq) || (frequency == -1);
331 // The number of channels must match for all codecs but Opus. 331 // The number of channels must match for all codecs but Opus.
332 if (STR_CASE_CMP(payload_name, "opus") != 0) { 332 if (STR_CASE_CMP(payload_name, "opus") != 0) {
333 channels_match = (channels == database_[id].channels); 333 channels_match = (channels == ci.channels);
334 } else { 334 } else {
335 // For opus we just check that number of channels is valid. 335 // For opus we just check that number of channels is valid.
336 channels_match = (channels == 1 || channels == 2); 336 channels_match = (channels == 1 || channels == 2);
337 } 337 }
338 338
339 if (name_match && frequency_match && channels_match) { 339 if (name_match && frequency_match && channels_match) {
340 // We have found a matching codec in the list. 340 // We have found a matching codec in the list.
341 return id; 341 return &ci - RentACodec::Database().data();
342 } 342 }
343 } 343 }
344 344
345 // We didn't find a matching codec. 345 // We didn't find a matching codec.
346 return -1; 346 return -1;
347 } 347 }
348 // Gets codec id number from database for the receiver. 348 // Gets codec id number from database for the receiver.
349 int ACMCodecDB::ReceiverCodecNumber(const CodecInst& codec_inst) { 349 int ACMCodecDB::ReceiverCodecNumber(const CodecInst& codec_inst) {
350 // Look for a matching codec in the database. 350 // Look for a matching codec in the database.
351 return CodecId(codec_inst); 351 return CodecId(codec_inst);
352 } 352 }
353 353
354 // Returns the codec sampling frequency for codec with id = "codec_id" in 354 // Returns the codec sampling frequency for codec with id = "codec_id" in
355 // database. 355 // database.
356 int ACMCodecDB::CodecFreq(int codec_id) { 356 int ACMCodecDB::CodecFreq(int codec_id) {
the sun 2015/10/27 11:56:43 const?
kwiberg-webrtc 2015/10/27 12:16:46 Where?
the sun 2015/10/27 12:27:40 On the method
kwiberg-webrtc 2015/10/27 12:33:17 It's static.
357 // Error check to see that codec_id is not out of bounds. 357 const size_t i = static_cast<size_t>(codec_id);
358 if (codec_id < 0 || codec_id >= kNumCodecs) { 358 auto db = RentACodec::Database();
the sun 2015/10/27 11:56:43 const auto?
kwiberg-webrtc 2015/10/27 12:16:46 Sure, it might be worth it even though it's easy t
the sun 2015/10/27 12:27:40 Good. Thing is though, when I read this I don't se
kwiberg-webrtc 2015/10/27 12:33:17 Ah, good point.
359 return -1; 359 return i < db.size() ? db[i].plfreq : -1;
360 }
361
362 return database_[codec_id].plfreq;
363 } 360 }
364 361
365 // Checks if the payload type is in the valid range. 362 // Checks if the payload type is in the valid range.
366 bool ACMCodecDB::ValidPayloadType(int payload_type) { 363 bool ACMCodecDB::ValidPayloadType(int payload_type) {
367 return (payload_type >= 0) && (payload_type <= 127); 364 return (payload_type >= 0) && (payload_type <= 127);
368 } 365 }
369 366
370 } // namespace acm2 367 } // namespace acm2
371 368
372 } // namespace webrtc 369 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698