2013-09-12 18:30:26 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
2015-11-26 04:44:54 -08:00
|
|
|
#include "webrtc/modules/audio_coding/include/audio_coding_module.h"
|
2013-09-12 18:30:26 +00:00
|
|
|
|
2015-05-11 12:44:23 +02:00
|
|
|
#include "webrtc/base/checks.h"
|
2013-09-12 18:30:26 +00:00
|
|
|
#include "webrtc/common_types.h"
|
2015-11-26 04:44:54 -08:00
|
|
|
#include "webrtc/modules/audio_coding/acm2/audio_coding_module_impl.h"
|
|
|
|
|
#include "webrtc/modules/audio_coding/acm2/rent_a_codec.h"
|
2016-05-25 07:37:43 -07:00
|
|
|
#include "webrtc/modules/audio_coding/codecs/builtin_audio_decoder_factory.h"
|
2015-10-28 18:17:40 +01:00
|
|
|
#include "webrtc/system_wrappers/include/clock.h"
|
|
|
|
|
#include "webrtc/system_wrappers/include/trace.h"
|
2013-09-12 18:30:26 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
|
|
|
|
// Create module
|
|
|
|
|
AudioCodingModule* AudioCodingModule::Create(int id) {
|
2015-05-11 12:44:23 +02:00
|
|
|
Config config;
|
|
|
|
|
config.id = id;
|
|
|
|
|
config.clock = Clock::GetRealTimeClock();
|
2016-05-25 07:37:43 -07:00
|
|
|
config.decoder_factory = CreateBuiltinAudioDecoderFactory();
|
2015-05-11 12:44:23 +02:00
|
|
|
return Create(config);
|
2013-09-19 00:12:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AudioCodingModule* AudioCodingModule::Create(int id, Clock* clock) {
|
2015-05-11 12:44:23 +02:00
|
|
|
Config config;
|
2014-04-28 10:16:57 +00:00
|
|
|
config.id = id;
|
2014-04-29 08:09:31 +00:00
|
|
|
config.clock = clock;
|
2016-05-25 07:37:43 -07:00
|
|
|
config.decoder_factory = CreateBuiltinAudioDecoderFactory();
|
2015-05-11 12:44:23 +02:00
|
|
|
return Create(config);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AudioCodingModule* AudioCodingModule::Create(const Config& config) {
|
2016-05-25 07:37:43 -07:00
|
|
|
if (!config.decoder_factory) {
|
|
|
|
|
// TODO(ossu): Backwards compatibility. Will be removed after a deprecation
|
|
|
|
|
// cycle.
|
|
|
|
|
Config config_copy = config;
|
|
|
|
|
config_copy.decoder_factory = CreateBuiltinAudioDecoderFactory();
|
|
|
|
|
return new acm2::AudioCodingModuleImpl(config_copy);
|
|
|
|
|
}
|
2014-04-29 08:09:31 +00:00
|
|
|
return new acm2::AudioCodingModuleImpl(config);
|
2013-09-12 18:30:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int AudioCodingModule::NumberOfCodecs() {
|
2015-10-27 11:40:24 -07:00
|
|
|
return static_cast<int>(acm2::RentACodec::NumberOfCodecs());
|
2013-09-12 18:30:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int AudioCodingModule::Codec(int list_id, CodecInst* codec) {
|
2015-10-27 11:40:24 -07:00
|
|
|
auto codec_id = acm2::RentACodec::CodecIdFromIndex(list_id);
|
|
|
|
|
if (!codec_id)
|
|
|
|
|
return -1;
|
|
|
|
|
auto ci = acm2::RentACodec::CodecInstById(*codec_id);
|
|
|
|
|
if (!ci)
|
|
|
|
|
return -1;
|
|
|
|
|
*codec = *ci;
|
|
|
|
|
return 0;
|
2013-09-12 18:30:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int AudioCodingModule::Codec(const char* payload_name,
|
|
|
|
|
CodecInst* codec,
|
|
|
|
|
int sampling_freq_hz,
|
Convert channel counts to size_t.
IIRC, this was originally requested by ajm during review of the other size_t conversions I did over the past year, and I agreed it made sense, but wanted to do it separately since those changes were already gargantuan.
BUG=chromium:81439
TEST=none
R=henrik.lundin@webrtc.org, henrika@webrtc.org, kjellander@webrtc.org, minyue@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1316523002 .
Cr-Commit-Position: refs/heads/master@{#11229}
2016-01-12 16:26:35 -08:00
|
|
|
size_t channels) {
|
2015-11-10 22:34:18 +01:00
|
|
|
rtc::Optional<CodecInst> ci = acm2::RentACodec::CodecInstByParams(
|
2013-10-06 04:47:28 +00:00
|
|
|
payload_name, sampling_freq_hz, channels);
|
2015-10-27 11:40:24 -07:00
|
|
|
if (ci) {
|
|
|
|
|
*codec = *ci;
|
|
|
|
|
return 0;
|
|
|
|
|
} else {
|
|
|
|
|
// We couldn't find a matching codec, so set the parameters to unacceptable
|
2013-09-12 18:30:26 +00:00
|
|
|
// values and return.
|
|
|
|
|
codec->plname[0] = '\0';
|
|
|
|
|
codec->pltype = -1;
|
|
|
|
|
codec->pacsize = 0;
|
|
|
|
|
codec->rate = 0;
|
|
|
|
|
codec->plfreq = 0;
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int AudioCodingModule::Codec(const char* payload_name,
|
|
|
|
|
int sampling_freq_hz,
|
Convert channel counts to size_t.
IIRC, this was originally requested by ajm during review of the other size_t conversions I did over the past year, and I agreed it made sense, but wanted to do it separately since those changes were already gargantuan.
BUG=chromium:81439
TEST=none
R=henrik.lundin@webrtc.org, henrika@webrtc.org, kjellander@webrtc.org, minyue@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1316523002 .
Cr-Commit-Position: refs/heads/master@{#11229}
2016-01-12 16:26:35 -08:00
|
|
|
size_t channels) {
|
2015-11-10 22:34:18 +01:00
|
|
|
rtc::Optional<acm2::RentACodec::CodecId> ci =
|
|
|
|
|
acm2::RentACodec::CodecIdByParams(payload_name, sampling_freq_hz,
|
|
|
|
|
channels);
|
2015-10-27 11:40:24 -07:00
|
|
|
if (!ci)
|
|
|
|
|
return -1;
|
2015-11-10 22:34:18 +01:00
|
|
|
rtc::Optional<int> i = acm2::RentACodec::CodecIndexFromId(*ci);
|
2015-10-27 11:40:24 -07:00
|
|
|
return i ? *i : -1;
|
2013-09-12 18:30:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Checks the validity of the parameters of the given codec
|
|
|
|
|
bool AudioCodingModule::IsCodecValid(const CodecInst& codec) {
|
2015-10-27 11:40:24 -07:00
|
|
|
bool valid = acm2::RentACodec::IsCodecValid(codec);
|
|
|
|
|
if (!valid)
|
2013-09-12 18:30:26 +00:00
|
|
|
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, -1,
|
|
|
|
|
"Invalid codec setting");
|
2015-10-27 11:40:24 -07:00
|
|
|
return valid;
|
2013-09-12 18:30:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace webrtc
|