Home | History | Annotate | Download | only in acm2
      1 /*
      2  *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
      3  *
      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.
      9  */
     10 
     11 #include "webrtc/modules/audio_coding/main/interface/audio_coding_module.h"
     12 
     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"
     18 
     19 namespace webrtc {
     20 
     21 // Create module
     22 AudioCodingModule* AudioCodingModule::Create(int id) {
     23   return Create(id, Clock::GetRealTimeClock());
     24 }
     25 
     26 AudioCodingModule* AudioCodingModule::Create(int id, Clock* clock) {
     27   AudioCodingModule::Config config;
     28   config.id = id;
     29   config.clock = clock;
     30   return new acm2::AudioCodingModuleImpl(config);
     31 }
     32 
     33 // Get number of supported codecs
     34 int AudioCodingModule::NumberOfCodecs() {
     35   return acm2::ACMCodecDB::kNumCodecs;
     36 }
     37 
     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);
     42 }
     43 
     44 // Get supported codec parameters with name, frequency and number of channels.
     45 int AudioCodingModule::Codec(const char* payload_name,
     46                              CodecInst* codec,
     47                              int sampling_freq_hz,
     48                              int channels) {
     49   int codec_id;
     50 
     51   // Get the id of the codec from the database.
     52   codec_id = acm2::ACMCodecDB::CodecId(
     53       payload_name, sampling_freq_hz, channels);
     54   if (codec_id < 0) {
     55     // We couldn't find a matching codec, set the parameters to unacceptable
     56     // values and return.
     57     codec->plname[0] = '\0';
     58     codec->pltype = -1;
     59     codec->pacsize = 0;
     60     codec->rate = 0;
     61     codec->plfreq = 0;
     62     return -1;
     63   }
     64 
     65   // Get default codec settings.
     66   acm2::ACMCodecDB::Codec(codec_id, codec);
     67 
     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;
     71 
     72   return 0;
     73 }
     74 
     75 // Get supported codec Index with name, frequency and number of channels.
     76 int AudioCodingModule::Codec(const char* payload_name,
     77                              int sampling_freq_hz,
     78                              int channels) {
     79   return acm2::ACMCodecDB::CodecId(payload_name, sampling_freq_hz, channels);
     80 }
     81 
     82 // Checks the validity of the parameters of the given codec
     83 bool AudioCodingModule::IsCodecValid(const CodecInst& codec) {
     84   int mirror_id;
     85 
     86   int codec_number = acm2::ACMCodecDB::CodecNumber(codec, &mirror_id);
     87 
     88   if (codec_number < 0) {
     89     WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, -1,
     90                  "Invalid codec setting");
     91     return false;
     92   } else {
     93     return true;
     94   }
     95 }
     96 
     97 }  // namespace webrtc
     98