13f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org/* 23f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 33f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org * 43f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org * Use of this source code is governed by a BSD-style license 53f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org * that can be found in the LICENSE file in the root of the source 63f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org * tree. An additional intellectual property rights grant can be found 73f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org * in the file PATENTS. All contributing project authors may 83f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org * be found in the AUTHORS file in the root of the source tree. 93f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org */ 103f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org 113f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org#include "webrtc/modules/audio_coding/main/interface/audio_coding_module.h" 123f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org 133f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org#include "webrtc/common_types.h" 14ed0b4fb2f28fa291e726fc1cf6852611f2176392turaj@webrtc.org#include "webrtc/modules/audio_coding/main/acm2/acm_codec_database.h" 15ed0b4fb2f28fa291e726fc1cf6852611f2176392turaj@webrtc.org#include "webrtc/modules/audio_coding/main/acm2/audio_coding_module_impl.h" 164d081990603c0fc3c08a81523efc811b8e0828baturaj@webrtc.org#include "webrtc/system_wrappers/interface/clock.h" 173f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org#include "webrtc/system_wrappers/interface/trace.h" 183f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org 193f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.orgnamespace webrtc { 203f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org 213f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org// Create module 223f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.orgAudioCodingModule* AudioCodingModule::Create(int id) { 236c7fe5b17eb1734c0578cc19846afcc829be330bhenrik.lundin@webrtc.org return Create(id, Clock::GetRealTimeClock()); 244d081990603c0fc3c08a81523efc811b8e0828baturaj@webrtc.org} 254d081990603c0fc3c08a81523efc811b8e0828baturaj@webrtc.org 264d081990603c0fc3c08a81523efc811b8e0828baturaj@webrtc.orgAudioCodingModule* AudioCodingModule::Create(int id, Clock* clock) { 276c7fe5b17eb1734c0578cc19846afcc829be330bhenrik.lundin@webrtc.org AudioCodingModule::Config config; 286c7fe5b17eb1734c0578cc19846afcc829be330bhenrik.lundin@webrtc.org config.id = id; 29f9cbb15535000ad8af4a9c55a24f135c2cc59e6chenrik.lundin@webrtc.org config.clock = clock; 30f9cbb15535000ad8af4a9c55a24f135c2cc59e6chenrik.lundin@webrtc.org return new acm2::AudioCodingModuleImpl(config); 313f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org} 323f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org 333f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org// Get number of supported codecs 343f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.orgint AudioCodingModule::NumberOfCodecs() { 350a1c75a50d10621f70d5921c5b8b9c0eb144bb42turaj@webrtc.org return acm2::ACMCodecDB::kNumCodecs; 363f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org} 373f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org 383f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org// Get supported codec parameters with id 393f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.orgint AudioCodingModule::Codec(int list_id, CodecInst* codec) { 403f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org // Get the codec settings for the codec with the given list ID 410a1c75a50d10621f70d5921c5b8b9c0eb144bb42turaj@webrtc.org return acm2::ACMCodecDB::Codec(list_id, codec); 423f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org} 433f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org 443f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org// Get supported codec parameters with name, frequency and number of channels. 453f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.orgint AudioCodingModule::Codec(const char* payload_name, 463f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org CodecInst* codec, 473f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org int sampling_freq_hz, 483f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org int channels) { 493f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org int codec_id; 503f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org 513f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org // Get the id of the codec from the database. 520a1c75a50d10621f70d5921c5b8b9c0eb144bb42turaj@webrtc.org codec_id = acm2::ACMCodecDB::CodecId( 530a1c75a50d10621f70d5921c5b8b9c0eb144bb42turaj@webrtc.org payload_name, sampling_freq_hz, channels); 543f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org if (codec_id < 0) { 553f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org // We couldn't find a matching codec, set the parameters to unacceptable 563f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org // values and return. 573f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org codec->plname[0] = '\0'; 583f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org codec->pltype = -1; 593f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org codec->pacsize = 0; 603f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org codec->rate = 0; 613f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org codec->plfreq = 0; 623f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org return -1; 633f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org } 643f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org 653f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org // Get default codec settings. 660a1c75a50d10621f70d5921c5b8b9c0eb144bb42turaj@webrtc.org acm2::ACMCodecDB::Codec(codec_id, codec); 673f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org 683f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org // Keep the number of channels from the function call. For most codecs it 693f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org // will be the same value as in default codec settings, but not for all. 703f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org codec->channels = channels; 713f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org 723f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org return 0; 733f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org} 743f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org 753f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org// Get supported codec Index with name, frequency and number of channels. 763f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.orgint AudioCodingModule::Codec(const char* payload_name, 773f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org int sampling_freq_hz, 783f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org int channels) { 790a1c75a50d10621f70d5921c5b8b9c0eb144bb42turaj@webrtc.org return acm2::ACMCodecDB::CodecId(payload_name, sampling_freq_hz, channels); 803f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org} 813f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org 823f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org// Checks the validity of the parameters of the given codec 833f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.orgbool AudioCodingModule::IsCodecValid(const CodecInst& codec) { 843f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org int mirror_id; 853f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org 860a1c75a50d10621f70d5921c5b8b9c0eb144bb42turaj@webrtc.org int codec_number = acm2::ACMCodecDB::CodecNumber(codec, &mirror_id); 873f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org 883f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org if (codec_number < 0) { 893f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, -1, 903f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org "Invalid codec setting"); 913f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org return false; 923f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org } else { 933f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org return true; 943f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org } 953f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org} 963f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org 9785e6dae81428a1c646276bf1148937e986d4f5d7henrik.lundin@webrtc.orgAudioCoding* AudioCoding::Create(const Config& config) { 9885e6dae81428a1c646276bf1148937e986d4f5d7henrik.lundin@webrtc.org return new AudioCodingImpl(config); 9985e6dae81428a1c646276bf1148937e986d4f5d7henrik.lundin@webrtc.org} 10085e6dae81428a1c646276bf1148937e986d4f5d7henrik.lundin@webrtc.org 1013f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org} // namespace webrtc 102