blob: f1e2afbab50d0ff7d038645e84cf7f256b198e1a [file] [log] [blame]
kwibergb1ed7f02017-06-17 17:30:09 -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/g722/audio_decoder_g722.h"
kwibergb1ed7f02017-06-17 17:30:09 -070012
13#include <memory>
14#include <vector>
15
Karl Wiberg918f50c2018-07-05 11:40:33 +020016#include "absl/memory/memory.h"
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/g722/audio_decoder_g722.h"
Karl Wiberge40468b2017-11-22 10:42:26 +010019#include "rtc_base/numerics/safe_conversions.h"
kwibergb1ed7f02017-06-17 17:30:09 -070020
21namespace webrtc {
22
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +020023absl::optional<AudioDecoderG722::Config> AudioDecoderG722::SdpToConfig(
kwibergb1ed7f02017-06-17 17:30:09 -070024 const SdpAudioFormat& format) {
kwiberge5eb7242017-08-25 03:10:50 -070025 return STR_CASE_CMP(format.name.c_str(), "G722") == 0 &&
kwiberg1b97e262017-06-26 04:19:43 -070026 format.clockrate_hz == 8000 &&
27 (format.num_channels == 1 || format.num_channels == 2)
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +020028 ? absl::optional<Config>(
kwiberg1b97e262017-06-26 04:19:43 -070029 Config{rtc::dchecked_cast<int>(format.num_channels)})
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +020030 : absl::nullopt;
kwibergb1ed7f02017-06-17 17:30:09 -070031}
32
33void AudioDecoderG722::AppendSupportedDecoders(
34 std::vector<AudioCodecSpec>* specs) {
kwiberge5eb7242017-08-25 03:10:50 -070035 specs->push_back({{"G722", 8000, 1}, {16000, 1, 64000}});
kwibergb1ed7f02017-06-17 17:30:09 -070036}
37
38std::unique_ptr<AudioDecoder> AudioDecoderG722::MakeAudioDecoder(
Karl Wiberg17668ec2018-03-01 15:13:27 +010039 Config config,
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +020040 absl::optional<AudioCodecPairId> /*codec_pair_id*/) {
kwiberg1b97e262017-06-26 04:19:43 -070041 switch (config.num_channels) {
42 case 1:
Karl Wiberg918f50c2018-07-05 11:40:33 +020043 return absl::make_unique<AudioDecoderG722Impl>();
kwiberg1b97e262017-06-26 04:19:43 -070044 case 2:
Karl Wiberg918f50c2018-07-05 11:40:33 +020045 return absl::make_unique<AudioDecoderG722StereoImpl>();
kwiberg1b97e262017-06-26 04:19:43 -070046 default:
47 return nullptr;
48 }
kwibergb1ed7f02017-06-17 17:30:09 -070049}
50
51} // namespace webrtc