1 /*
2 * Copyright (c) 2017 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
11 #include "api/audio_codecs/isac/audio_encoder_isac_fix.h"
12
13 #include <memory>
14
15 #include "absl/strings/match.h"
16 #include "modules/audio_coding/codecs/isac/fix/include/audio_encoder_isacfix.h"
17 #include "rtc_base/string_to_number.h"
18
19 namespace webrtc {
20
SdpToConfig(const SdpAudioFormat & format)21 absl::optional<AudioEncoderIsacFix::Config> AudioEncoderIsacFix::SdpToConfig(
22 const SdpAudioFormat& format) {
23 if (absl::EqualsIgnoreCase(format.name, "ISAC") &&
24 format.clockrate_hz == 16000 && format.num_channels == 1) {
25 Config config;
26 const auto ptime_iter = format.parameters.find("ptime");
27 if (ptime_iter != format.parameters.end()) {
28 const auto ptime = rtc::StringToNumber<int>(ptime_iter->second);
29 if (ptime && *ptime >= 60) {
30 config.frame_size_ms = 60;
31 }
32 }
33 return config;
34 } else {
35 return absl::nullopt;
36 }
37 }
38
AppendSupportedEncoders(std::vector<AudioCodecSpec> * specs)39 void AudioEncoderIsacFix::AppendSupportedEncoders(
40 std::vector<AudioCodecSpec>* specs) {
41 const SdpAudioFormat fmt = {"ISAC", 16000, 1};
42 const AudioCodecInfo info = QueryAudioEncoder(*SdpToConfig(fmt));
43 specs->push_back({fmt, info});
44 }
45
QueryAudioEncoder(AudioEncoderIsacFix::Config config)46 AudioCodecInfo AudioEncoderIsacFix::QueryAudioEncoder(
47 AudioEncoderIsacFix::Config config) {
48 RTC_DCHECK(config.IsOk());
49 return {16000, 1, 32000, 10000, 32000};
50 }
51
MakeAudioEncoder(AudioEncoderIsacFix::Config config,int payload_type,absl::optional<AudioCodecPairId>)52 std::unique_ptr<AudioEncoder> AudioEncoderIsacFix::MakeAudioEncoder(
53 AudioEncoderIsacFix::Config config,
54 int payload_type,
55 absl::optional<AudioCodecPairId> /*codec_pair_id*/) {
56 RTC_DCHECK(config.IsOk());
57 AudioEncoderIsacFixImpl::Config c;
58 c.frame_size_ms = config.frame_size_ms;
59 c.bit_rate = config.bit_rate;
60 c.payload_type = payload_type;
61 return std::make_unique<AudioEncoderIsacFixImpl>(c);
62 }
63
64 } // namespace webrtc
65