mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-14 06:10:40 +01:00

We want to get rid of the whole thing, really, but these two were easy. Bug: webrtc:8396 Change-Id: I9292bf077caca171c9f5fe63695b6333cf22547d Reviewed-on: https://webrtc-review.googlesource.com/c/104763 Commit-Queue: Karl Wiberg <kwiberg@webrtc.org> Reviewed-by: Ivo Creusen <ivoc@webrtc.org> Cr-Commit-Position: refs/heads/master@{#25618}
72 lines
2.2 KiB
C++
72 lines
2.2 KiB
C++
/*
|
|
* 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.
|
|
*/
|
|
|
|
#include "modules/audio_coding/acm2/rent_a_codec.h"
|
|
|
|
#include <memory>
|
|
#include <utility>
|
|
|
|
#include "rtc_base/logging.h"
|
|
#include "modules/audio_coding/acm2/acm_codec_database.h"
|
|
|
|
namespace webrtc {
|
|
namespace acm2 {
|
|
|
|
absl::optional<RentACodec::CodecId> RentACodec::CodecIdByParams(
|
|
const char* payload_name,
|
|
int sampling_freq_hz,
|
|
size_t channels) {
|
|
return CodecIdFromIndex(
|
|
ACMCodecDB::CodecId(payload_name, sampling_freq_hz, channels));
|
|
}
|
|
|
|
absl::optional<CodecInst> RentACodec::CodecInstById(CodecId codec_id) {
|
|
absl::optional<int> mi = CodecIndexFromId(codec_id);
|
|
return mi ? absl::optional<CodecInst>(ACMCodecDB::database_[*mi])
|
|
: absl::nullopt;
|
|
}
|
|
|
|
absl::optional<RentACodec::CodecId> RentACodec::CodecIdByInst(
|
|
const CodecInst& codec_inst) {
|
|
return CodecIdFromIndex(ACMCodecDB::CodecNumber(codec_inst));
|
|
}
|
|
|
|
absl::optional<CodecInst> RentACodec::CodecInstByParams(
|
|
const char* payload_name,
|
|
int sampling_freq_hz,
|
|
size_t channels) {
|
|
absl::optional<CodecId> codec_id =
|
|
CodecIdByParams(payload_name, sampling_freq_hz, channels);
|
|
if (!codec_id)
|
|
return absl::nullopt;
|
|
absl::optional<CodecInst> ci = CodecInstById(*codec_id);
|
|
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;
|
|
}
|
|
|
|
absl::optional<NetEqDecoder> RentACodec::NetEqDecoderFromCodecId(
|
|
CodecId codec_id,
|
|
size_t num_channels) {
|
|
absl::optional<int> i = CodecIndexFromId(codec_id);
|
|
if (!i)
|
|
return absl::nullopt;
|
|
const NetEqDecoder ned = ACMCodecDB::neteq_decoders_[*i];
|
|
return (ned == NetEqDecoder::kDecoderOpus && num_channels == 2)
|
|
? NetEqDecoder::kDecoderOpus_2ch
|
|
: ned;
|
|
}
|
|
|
|
} // namespace acm2
|
|
} // namespace webrtc
|