kwiberg | 96d74bb | 2017-06-30 05:24:56 -0700 | [diff] [blame] | 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "api/audio_codecs/opus/audio_decoder_opus.h" |
kwiberg | 96d74bb | 2017-06-30 05:24:56 -0700 | [diff] [blame] | 12 | |
| 13 | #include <memory> |
| 14 | #include <utility> |
| 15 | #include <vector> |
| 16 | |
Mirko Bonadei | 7120742 | 2017-09-15 13:58:09 +0200 | [diff] [blame] | 17 | #include "common_types.h" // NOLINT(build/include) |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 18 | #include "modules/audio_coding/codecs/opus/audio_decoder_opus.h" |
| 19 | #include "rtc_base/ptr_util.h" |
kwiberg | 96d74bb | 2017-06-30 05:24:56 -0700 | [diff] [blame] | 20 | |
| 21 | namespace webrtc { |
| 22 | |
| 23 | rtc::Optional<AudioDecoderOpus::Config> AudioDecoderOpus::SdpToConfig( |
| 24 | const SdpAudioFormat& format) { |
Oskar Sundbom | 9065730 | 2017-11-16 10:52:34 +0100 | [diff] [blame] | 25 | const auto num_channels = [&]() -> rtc::Optional<int> { |
kwiberg | 96d74bb | 2017-06-30 05:24:56 -0700 | [diff] [blame] | 26 | auto stereo = format.parameters.find("stereo"); |
| 27 | if (stereo != format.parameters.end()) { |
| 28 | if (stereo->second == "0") { |
Oskar Sundbom | 9065730 | 2017-11-16 10:52:34 +0100 | [diff] [blame] | 29 | return 1; |
kwiberg | 96d74bb | 2017-06-30 05:24:56 -0700 | [diff] [blame] | 30 | } else if (stereo->second == "1") { |
Oskar Sundbom | 9065730 | 2017-11-16 10:52:34 +0100 | [diff] [blame] | 31 | return 2; |
kwiberg | 96d74bb | 2017-06-30 05:24:56 -0700 | [diff] [blame] | 32 | } else { |
Oskar Sundbom | 9065730 | 2017-11-16 10:52:34 +0100 | [diff] [blame] | 33 | return rtc::nullopt; // Bad stereo parameter. |
kwiberg | 96d74bb | 2017-06-30 05:24:56 -0700 | [diff] [blame] | 34 | } |
| 35 | } |
Oskar Sundbom | 9065730 | 2017-11-16 10:52:34 +0100 | [diff] [blame] | 36 | return 1; // Default to mono. |
kwiberg | 96d74bb | 2017-06-30 05:24:56 -0700 | [diff] [blame] | 37 | }(); |
| 38 | if (STR_CASE_CMP(format.name.c_str(), "opus") == 0 && |
| 39 | format.clockrate_hz == 48000 && format.num_channels == 2 && |
| 40 | num_channels) { |
Oskar Sundbom | 9065730 | 2017-11-16 10:52:34 +0100 | [diff] [blame] | 41 | return Config{*num_channels}; |
kwiberg | 96d74bb | 2017-06-30 05:24:56 -0700 | [diff] [blame] | 42 | } else { |
Oskar Sundbom | 9065730 | 2017-11-16 10:52:34 +0100 | [diff] [blame] | 43 | return rtc::nullopt; |
kwiberg | 96d74bb | 2017-06-30 05:24:56 -0700 | [diff] [blame] | 44 | } |
| 45 | } |
| 46 | |
| 47 | void 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 | |
| 57 | std::unique_ptr<AudioDecoder> AudioDecoderOpus::MakeAudioDecoder( |
| 58 | Config config) { |
| 59 | return rtc::MakeUnique<AudioDecoderOpusImpl>(config.num_channels); |
| 60 | } |
| 61 | |
| 62 | } // namespace webrtc |