blob: bfddc42bc911876cf59b6eda8507801b1d06a0d9 [file] [log] [blame]
kwibergfce4a942015-10-27 11:40:24 -07001/*
2 * Copyright (c) 2015 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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#include "modules/audio_coding/acm2/rent_a_codec.h"
kwibergfce4a942015-10-27 11:40:24 -070012
kwiberg16c5a962016-02-15 02:27:22 -080013#include <memory>
kwiberg0eb15ed2015-12-17 03:04:15 -080014#include <utility>
15
Niels Möller2edab4c2018-10-22 09:48:08 +020016#include "rtc_base/logging.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020017#include "modules/audio_coding/acm2/acm_codec_database.h"
kwibergfce4a942015-10-27 11:40:24 -070018
19namespace webrtc {
20namespace acm2 {
21
Danil Chapovalovb6021232018-06-19 13:26:36 +020022absl::optional<RentACodec::CodecId> RentACodec::CodecIdByParams(
kwibergfce4a942015-10-27 11:40:24 -070023 const char* payload_name,
24 int sampling_freq_hz,
Peter Kasting69558702016-01-12 16:26:35 -080025 size_t channels) {
kwibergfce4a942015-10-27 11:40:24 -070026 return CodecIdFromIndex(
27 ACMCodecDB::CodecId(payload_name, sampling_freq_hz, channels));
28}
29
Danil Chapovalovb6021232018-06-19 13:26:36 +020030absl::optional<CodecInst> RentACodec::CodecInstById(CodecId codec_id) {
31 absl::optional<int> mi = CodecIndexFromId(codec_id);
Karl Wiberg105edca2018-11-13 12:06:02 +010032 return mi ? absl::optional<CodecInst>(ACMCodecDB::database_[*mi])
33 : absl::nullopt;
kwibergfce4a942015-10-27 11:40:24 -070034}
35
Danil Chapovalovb6021232018-06-19 13:26:36 +020036absl::optional<RentACodec::CodecId> RentACodec::CodecIdByInst(
kwibergd6c0f8c2015-11-06 14:28:00 -080037 const CodecInst& codec_inst) {
38 return CodecIdFromIndex(ACMCodecDB::CodecNumber(codec_inst));
39}
40
Danil Chapovalovb6021232018-06-19 13:26:36 +020041absl::optional<CodecInst> RentACodec::CodecInstByParams(
42 const char* payload_name,
43 int sampling_freq_hz,
44 size_t channels) {
45 absl::optional<CodecId> codec_id =
kwibergfce4a942015-10-27 11:40:24 -070046 CodecIdByParams(payload_name, sampling_freq_hz, channels);
47 if (!codec_id)
Danil Chapovalovb6021232018-06-19 13:26:36 +020048 return absl::nullopt;
49 absl::optional<CodecInst> ci = CodecInstById(*codec_id);
kwibergfce4a942015-10-27 11:40:24 -070050 RTC_DCHECK(ci);
51
52 // Keep the number of channels from the function call. For most codecs it
53 // will be the same value as in default codec settings, but not for all.
54 ci->channels = channels;
55
56 return ci;
57}
58
Danil Chapovalovb6021232018-06-19 13:26:36 +020059absl::optional<NetEqDecoder> RentACodec::NetEqDecoderFromCodecId(
Karl Wibergbe579832015-11-10 22:34:18 +010060 CodecId codec_id,
Peter Kasting69558702016-01-12 16:26:35 -080061 size_t num_channels) {
Danil Chapovalovb6021232018-06-19 13:26:36 +020062 absl::optional<int> i = CodecIndexFromId(codec_id);
kwibergee1879c2015-10-29 06:20:28 -070063 if (!i)
Danil Chapovalovb6021232018-06-19 13:26:36 +020064 return absl::nullopt;
kwibergee1879c2015-10-29 06:20:28 -070065 const NetEqDecoder ned = ACMCodecDB::neteq_decoders_[*i];
Oskar Sundbom12ab00b2017-11-16 15:31:38 +010066 return (ned == NetEqDecoder::kDecoderOpus && num_channels == 2)
67 ? NetEqDecoder::kDecoderOpus_2ch
68 : ned;
kwibergee1879c2015-10-29 06:20:28 -070069}
70
kwibergfce4a942015-10-27 11:40:24 -070071} // namespace acm2
72} // namespace webrtc