Remove ACMCodecDB::Codec, and make the rest of ACMCodecDB private
BUG=webrtc:5028
Review URL: https://codereview.webrtc.org/1423043005
Cr-Commit-Position: refs/heads/master@{#10546}
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 0855dd6..b54fc0b 100644
--- a/webrtc/modules/audio_coding/main/acm2/acm_codec_database.cc
+++ b/webrtc/modules/audio_coding/main/acm2/acm_codec_database.cc
@@ -209,20 +209,6 @@
#endif
};
-// Get codec information from database.
-// 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 (static_cast<size_t>(codec_id) >= RentACodec::NumberOfCodecs()) {
- return -1;
- }
-
- // Copy database information for the codec to the output.
- memcpy(codec_inst, &database_[codec_id], sizeof(CodecInst));
-
- return 0;
-}
-
// Enumerator for error codes when asking for codec database id.
enum {
kInvalidCodec = -10,
diff --git a/webrtc/modules/audio_coding/main/acm2/acm_codec_database.h b/webrtc/modules/audio_coding/main/acm2/acm_codec_database.h
index e462e45..28f6874 100644
--- a/webrtc/modules/audio_coding/main/acm2/acm_codec_database.h
+++ b/webrtc/modules/audio_coding/main/acm2/acm_codec_database.h
@@ -27,7 +27,7 @@
// TODO(tlegrand): replace class ACMCodecDB with a namespace.
class ACMCodecDB {
- public:
+ private:
// kMaxNumCodecs - Maximum number of codecs that can be activated in one
// build.
// kMaxNumPacketSize - Maximum number of allowed packet sizes for one codec.
@@ -51,17 +51,6 @@
int channel_support;
};
- // Gets codec information from database at the position in database given by
- // [codec_id].
- // Input:
- // [codec_id] - number that specifies at what position in the database to
- // get the information.
- // Output:
- // [codec_inst] - filled with information about the codec.
- // Return:
- // 0 if successful, otherwise -1.
- static int Codec(int codec_id, CodecInst* codec_inst);
-
// Returns codec id from database, given the information received in the input
// [codec_inst].
// Input:
@@ -74,7 +63,6 @@
static int CodecId(const char* payload_name, int frequency, int channels);
static int ReceiverCodecNumber(const CodecInst& codec_inst);
- private:
// Databases with information about the supported codecs
// database_ - stored information about all codecs: payload type, name,
// sampling frequency, packet size in samples, default channel
diff --git a/webrtc/modules/audio_coding/main/acm2/acm_receiver_unittest_oldapi.cc b/webrtc/modules/audio_coding/main/acm2/acm_receiver_unittest_oldapi.cc
index 6434483..dae24a3 100644
--- a/webrtc/modules/audio_coding/main/acm2/acm_receiver_unittest_oldapi.cc
+++ b/webrtc/modules/audio_coding/main/acm2/acm_receiver_unittest_oldapi.cc
@@ -88,8 +88,8 @@
void TearDown() override {}
void InsertOnePacketOfSilence(int codec_id) {
- CodecInst codec;
- ACMCodecDB::Codec(codec_id, &codec);
+ CodecInst codec =
+ *RentACodec::CodecInstById(*RentACodec::CodecIdFromIndex(codec_id));
if (timestamp_ == 0) { // This is the first time inserting audio.
ASSERT_EQ(0, acm_->RegisterSendCodec(codec));
} else {
diff --git a/webrtc/modules/audio_coding/main/acm2/codec_manager.cc b/webrtc/modules/audio_coding/main/acm2/codec_manager.cc
index 4d24505..40a5473 100644
--- a/webrtc/modules/audio_coding/main/acm2/codec_manager.cc
+++ b/webrtc/modules/audio_coding/main/acm2/codec_manager.cc
@@ -39,8 +39,8 @@
return -1;
}
- int codec_id = ACMCodecDB::CodecNumber(send_codec);
- if (codec_id < 0) {
+ auto maybe_codec_id = RentACodec::CodecIdByInst(send_codec);
+ if (!maybe_codec_id) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, dummy_id,
"Invalid codec setting for the send codec.");
return -1;
@@ -53,14 +53,8 @@
return -1;
}
- const rtc::Maybe<bool> supported_num_channels = [codec_id, &send_codec] {
- auto cid = RentACodec::CodecIdFromIndex(codec_id);
- return cid ? RentACodec::IsSupportedNumChannels(*cid, send_codec.channels)
- : rtc::Maybe<bool>();
- }();
- if (!supported_num_channels)
- return -1;
- if (!*supported_num_channels) {
+ if (!RentACodec::IsSupportedNumChannels(*maybe_codec_id, send_codec.channels)
+ .value_or(false)) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, dummy_id,
"%d number of channels not supportedn for %s.",
send_codec.channels, send_codec.plname);
@@ -82,7 +76,7 @@
return -1;
}
}
- return codec_id;
+ return RentACodec::CodecIndexFromId(*maybe_codec_id).value_or(-1);
}
bool IsIsac(const CodecInst& codec) {
@@ -251,9 +245,10 @@
// Check if the codec is already registered as send codec.
bool new_codec = true;
if (codec_owner_.Encoder()) {
- int new_codec_id = ACMCodecDB::CodecNumber(send_codec_inst_);
- RTC_DCHECK_GE(new_codec_id, 0);
- new_codec = new_codec_id != codec_id;
+ auto new_codec_id = RentACodec::CodecIdByInst(send_codec_inst_);
+ RTC_DCHECK(new_codec_id);
+ auto old_codec_id = RentACodec::CodecIdFromIndex(codec_id);
+ new_codec = !old_codec_id || *new_codec_id != *old_codec_id;
}
if (RedPayloadType(send_codec.plfreq) == -1) {
diff --git a/webrtc/modules/audio_coding/main/acm2/rent_a_codec.cc b/webrtc/modules/audio_coding/main/acm2/rent_a_codec.cc
index 76dc7bb..2a6c37f 100644
--- a/webrtc/modules/audio_coding/main/acm2/rent_a_codec.cc
+++ b/webrtc/modules/audio_coding/main/acm2/rent_a_codec.cc
@@ -29,6 +29,11 @@
return mi ? rtc::Maybe<CodecInst>(Database()[*mi]) : rtc::Maybe<CodecInst>();
}
+rtc::Maybe<RentACodec::CodecId> RentACodec::CodecIdByInst(
+ const CodecInst& codec_inst) {
+ return CodecIdFromIndex(ACMCodecDB::CodecNumber(codec_inst));
+}
+
rtc::Maybe<CodecInst> RentACodec::CodecInstByParams(const char* payload_name,
int sampling_freq_hz,
int channels) {
diff --git a/webrtc/modules/audio_coding/main/acm2/rent_a_codec.h b/webrtc/modules/audio_coding/main/acm2/rent_a_codec.h
index 98052e7..2c85bcf 100644
--- a/webrtc/modules/audio_coding/main/acm2/rent_a_codec.h
+++ b/webrtc/modules/audio_coding/main/acm2/rent_a_codec.h
@@ -148,6 +148,7 @@
int sampling_freq_hz,
int channels);
static rtc::Maybe<CodecInst> CodecInstById(CodecId codec_id);
+ static rtc::Maybe<CodecId> CodecIdByInst(const CodecInst& codec_inst);
static rtc::Maybe<CodecInst> CodecInstByParams(const char* payload_name,
int sampling_freq_hz,
int channels);