2015-10-27 11:40:24 -07:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2015 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "modules/audio_coding/acm2/rent_a_codec.h"
|
2015-10-27 11:40:24 -07:00
|
|
|
|
2016-02-15 02:27:22 -08:00
|
|
|
#include <memory>
|
2015-12-17 03:04:15 -08:00
|
|
|
#include <utility>
|
|
|
|
|
|
2018-10-22 09:48:08 +02:00
|
|
|
#include "rtc_base/logging.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "modules/audio_coding/acm2/acm_codec_database.h"
|
2015-10-27 11:40:24 -07:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
namespace acm2 {
|
|
|
|
|
|
2018-06-19 13:26:36 +02:00
|
|
|
absl::optional<RentACodec::CodecId> RentACodec::CodecIdByParams(
|
2015-10-27 11:40:24 -07:00
|
|
|
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-10-27 11:40:24 -07:00
|
|
|
return CodecIdFromIndex(
|
|
|
|
|
ACMCodecDB::CodecId(payload_name, sampling_freq_hz, channels));
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-19 13:26:36 +02:00
|
|
|
absl::optional<CodecInst> RentACodec::CodecInstById(CodecId codec_id) {
|
|
|
|
|
absl::optional<int> mi = CodecIndexFromId(codec_id);
|
2018-11-13 12:06:02 +01:00
|
|
|
return mi ? absl::optional<CodecInst>(ACMCodecDB::database_[*mi])
|
|
|
|
|
: absl::nullopt;
|
2015-10-27 11:40:24 -07:00
|
|
|
}
|
|
|
|
|
|
2018-06-19 13:26:36 +02:00
|
|
|
absl::optional<RentACodec::CodecId> RentACodec::CodecIdByInst(
|
2015-11-06 14:28:00 -08:00
|
|
|
const CodecInst& codec_inst) {
|
|
|
|
|
return CodecIdFromIndex(ACMCodecDB::CodecNumber(codec_inst));
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-19 13:26:36 +02:00
|
|
|
absl::optional<CodecInst> RentACodec::CodecInstByParams(
|
|
|
|
|
const char* payload_name,
|
|
|
|
|
int sampling_freq_hz,
|
|
|
|
|
size_t channels) {
|
|
|
|
|
absl::optional<CodecId> codec_id =
|
2015-10-27 11:40:24 -07:00
|
|
|
CodecIdByParams(payload_name, sampling_freq_hz, channels);
|
|
|
|
|
if (!codec_id)
|
2018-06-19 13:26:36 +02:00
|
|
|
return absl::nullopt;
|
|
|
|
|
absl::optional<CodecInst> ci = CodecInstById(*codec_id);
|
2015-10-27 11:40:24 -07:00
|
|
|
RTC_DCHECK(ci);
|
|
|
|
|
|
|
|
|
|
// Keep the number of channels from the function call. For most codecs it
|
|
|
|
|
// will be the same value as in default codec settings, but not for all.
|
|
|
|
|
ci->channels = channels;
|
|
|
|
|
|
|
|
|
|
return ci;
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-19 13:26:36 +02:00
|
|
|
absl::optional<NetEqDecoder> RentACodec::NetEqDecoderFromCodecId(
|
2015-11-10 22:34:18 +01:00
|
|
|
CodecId codec_id,
|
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 num_channels) {
|
2018-06-19 13:26:36 +02:00
|
|
|
absl::optional<int> i = CodecIndexFromId(codec_id);
|
2015-10-29 06:20:28 -07:00
|
|
|
if (!i)
|
2018-06-19 13:26:36 +02:00
|
|
|
return absl::nullopt;
|
2015-10-29 06:20:28 -07:00
|
|
|
const NetEqDecoder ned = ACMCodecDB::neteq_decoders_[*i];
|
2017-11-16 15:31:38 +01:00
|
|
|
return (ned == NetEqDecoder::kDecoderOpus && num_channels == 2)
|
|
|
|
|
? NetEqDecoder::kDecoderOpus_2ch
|
|
|
|
|
: ned;
|
2015-10-29 06:20:28 -07:00
|
|
|
}
|
|
|
|
|
|
2015-10-27 11:40:24 -07:00
|
|
|
} // namespace acm2
|
|
|
|
|
} // namespace webrtc
|