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

Unified 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, 2 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 side-by-side diff with in-line comments
Download patch
Index: webrtc/modules/audio_coding/main/acm2/acm_codec_database.cc
diff --git a/webrtc/modules/audio_coding/main/acm2/acm_codec_database.cc b/webrtc/modules/audio_coding/main/acm2/acm_codec_database.cc
index bf12530832e1d27825c55d1061c0ac2c3b624762..edd8264540a6163a481bd274b49cd03d9180e70f 100644
--- a/webrtc/modules/audio_coding/main/acm2/acm_codec_database.cc
+++ b/webrtc/modules/audio_coding/main/acm2/acm_codec_database.cc
@@ -223,7 +223,7 @@ const NetEqDecoder ACMCodecDB::neteq_decoders_[] = {
// TODO(tlegrand): replace memcpy with a pointer to the data base memory.
int ACMCodecDB::Codec(int codec_id, CodecInst* codec_inst) {
// Error check to see that codec_id is not out of bounds.
- if ((codec_id < 0) || (codec_id >= kNumCodecs)) {
+ if (static_cast<size_t>(codec_id) >= RentACodec::NumberOfCodecs()) {
return -1;
}
@@ -318,7 +318,7 @@ int ACMCodecDB::CodecId(const CodecInst& codec_inst) {
}
int ACMCodecDB::CodecId(const char* payload_name, int frequency, int channels) {
- for (int id = 0; id < kNumCodecs; id++) {
+ for (const CodecInst& ci : RentACodec::Database()) {
bool name_match = false;
bool frequency_match = false;
bool channels_match = false;
@@ -326,11 +326,11 @@ int ACMCodecDB::CodecId(const char* payload_name, int frequency, int channels) {
// Payload name, sampling frequency and number of channels need to match.
// NOTE! If |frequency| is -1, the frequency is not applicable, and is
// always treated as true, like for RED.
- name_match = (STR_CASE_CMP(database_[id].plname, payload_name) == 0);
- frequency_match = (frequency == database_[id].plfreq) || (frequency == -1);
+ name_match = (STR_CASE_CMP(ci.plname, payload_name) == 0);
+ frequency_match = (frequency == ci.plfreq) || (frequency == -1);
// The number of channels must match for all codecs but Opus.
if (STR_CASE_CMP(payload_name, "opus") != 0) {
- channels_match = (channels == database_[id].channels);
+ channels_match = (channels == ci.channels);
} else {
// For opus we just check that number of channels is valid.
channels_match = (channels == 1 || channels == 2);
@@ -338,7 +338,7 @@ int ACMCodecDB::CodecId(const char* payload_name, int frequency, int channels) {
if (name_match && frequency_match && channels_match) {
// We have found a matching codec in the list.
- return id;
+ return &ci - RentACodec::Database().data();
}
}
@@ -354,12 +354,9 @@ int ACMCodecDB::ReceiverCodecNumber(const CodecInst& codec_inst) {
// Returns the codec sampling frequency for codec with id = "codec_id" in
// database.
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.
- // Error check to see that codec_id is not out of bounds.
- if (codec_id < 0 || codec_id >= kNumCodecs) {
- return -1;
- }
-
- return database_[codec_id].plfreq;
+ const size_t i = static_cast<size_t>(codec_id);
+ 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.
+ return i < db.size() ? db[i].plfreq : -1;
}
// Checks if the payload type is in the valid range.

Powered by Google App Engine
This is Rietveld 408576698