blob: 472a07943588312b7e5575e783b9de0b98374d0e [file] [log] [blame]
kwiberg96d74bb2017-06-30 05:24:56 -07001/*
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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#include "api/audio_codecs/opus/audio_decoder_opus.h"
kwiberg96d74bb2017-06-30 05:24:56 -070012
13#include <memory>
14#include <utility>
15#include <vector>
16
Mirko Bonadei71207422017-09-15 13:58:09 +020017#include "common_types.h" // NOLINT(build/include)
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020018#include "modules/audio_coding/codecs/opus/audio_decoder_opus.h"
19#include "rtc_base/ptr_util.h"
kwiberg96d74bb2017-06-30 05:24:56 -070020
21namespace webrtc {
22
23rtc::Optional<AudioDecoderOpus::Config> AudioDecoderOpus::SdpToConfig(
24 const SdpAudioFormat& format) {
Oskar Sundbom90657302017-11-16 10:52:34 +010025 const auto num_channels = [&]() -> rtc::Optional<int> {
kwiberg96d74bb2017-06-30 05:24:56 -070026 auto stereo = format.parameters.find("stereo");
27 if (stereo != format.parameters.end()) {
28 if (stereo->second == "0") {
Oskar Sundbom90657302017-11-16 10:52:34 +010029 return 1;
kwiberg96d74bb2017-06-30 05:24:56 -070030 } else if (stereo->second == "1") {
Oskar Sundbom90657302017-11-16 10:52:34 +010031 return 2;
kwiberg96d74bb2017-06-30 05:24:56 -070032 } else {
Oskar Sundbom90657302017-11-16 10:52:34 +010033 return rtc::nullopt; // Bad stereo parameter.
kwiberg96d74bb2017-06-30 05:24:56 -070034 }
35 }
Oskar Sundbom90657302017-11-16 10:52:34 +010036 return 1; // Default to mono.
kwiberg96d74bb2017-06-30 05:24:56 -070037 }();
38 if (STR_CASE_CMP(format.name.c_str(), "opus") == 0 &&
39 format.clockrate_hz == 48000 && format.num_channels == 2 &&
40 num_channels) {
Oskar Sundbom90657302017-11-16 10:52:34 +010041 return Config{*num_channels};
kwiberg96d74bb2017-06-30 05:24:56 -070042 } else {
Oskar Sundbom90657302017-11-16 10:52:34 +010043 return rtc::nullopt;
kwiberg96d74bb2017-06-30 05:24:56 -070044 }
45}
46
47void AudioDecoderOpus::AppendSupportedDecoders(
48 std::vector<AudioCodecSpec>* specs) {
49 AudioCodecInfo opus_info{48000, 1, 64000, 6000, 510000};
50 opus_info.allow_comfort_noise = false;
51 opus_info.supports_network_adaption = true;
52 SdpAudioFormat opus_format(
53 {"opus", 48000, 2, {{"minptime", "10"}, {"useinbandfec", "1"}}});
54 specs->push_back({std::move(opus_format), std::move(opus_info)});
55}
56
57std::unique_ptr<AudioDecoder> AudioDecoderOpus::MakeAudioDecoder(
58 Config config) {
59 return rtc::MakeUnique<AudioDecoderOpusImpl>(config.num_channels);
60}
61
62} // namespace webrtc