2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
11 #include "webrtc/modules/audio_coding/main/interface/audio_coding_module.h"
13 #include "webrtc/common_types.h"
14 #include "webrtc/modules/audio_coding/main/acm2/acm_codec_database.h"
15 #include "webrtc/modules/audio_coding/main/acm2/audio_coding_module_impl.h"
16 #include "webrtc/system_wrappers/interface/clock.h"
17 #include "webrtc/system_wrappers/interface/trace.h"
22 AudioCodingModule* AudioCodingModule::Create(int id) {
23 return Create(id, Clock::GetRealTimeClock());
26 AudioCodingModule* AudioCodingModule::Create(int id, Clock* clock) {
27 AudioCodingModule::Config config;
30 return new acm2::AudioCodingModuleImpl(config);
33 // Get number of supported codecs
34 int AudioCodingModule::NumberOfCodecs() {
35 return acm2::ACMCodecDB::kNumCodecs;
38 // Get supported codec parameters with id
39 int AudioCodingModule::Codec(int list_id, CodecInst* codec) {
40 // Get the codec settings for the codec with the given list ID
41 return acm2::ACMCodecDB::Codec(list_id, codec);
44 // Get supported codec parameters with name, frequency and number of channels.
45 int AudioCodingModule::Codec(const char* payload_name,
51 // Get the id of the codec from the database.
52 codec_id = acm2::ACMCodecDB::CodecId(
53 payload_name, sampling_freq_hz, channels);
55 // We couldn't find a matching codec, set the parameters to unacceptable
57 codec->plname[0] = '\0';
65 // Get default codec settings.
66 acm2::ACMCodecDB::Codec(codec_id, codec);
68 // Keep the number of channels from the function call. For most codecs it
69 // will be the same value as in default codec settings, but not for all.
70 codec->channels = channels;
75 // Get supported codec Index with name, frequency and number of channels.
76 int AudioCodingModule::Codec(const char* payload_name,
79 return acm2::ACMCodecDB::CodecId(payload_name, sampling_freq_hz, channels);
82 // Checks the validity of the parameters of the given codec
83 bool AudioCodingModule::IsCodecValid(const CodecInst& codec) {
86 int codec_number = acm2::ACMCodecDB::CodecNumber(codec, &mirror_id);
88 if (codec_number < 0) {
89 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, -1,
90 "Invalid codec setting");