blob: ed7163471a91d79759faf1e97c787ba84919641a [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
Niels Möller2edab4c2018-10-22 09:48:08 +020016#include "absl/strings/match.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020017#include "modules/audio_coding/codecs/g722/audio_decoder_g722.h"
Karl Wiberge40468b2017-11-22 10:42:26 +010018#include "rtc_base/numerics/safe_conversions.h"
kwibergb1ed7f02017-06-17 17:30:09 -070019
20namespace webrtc {
21
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +020022absl::optional<AudioDecoderG722::Config> AudioDecoderG722::SdpToConfig(
kwibergb1ed7f02017-06-17 17:30:09 -070023 const SdpAudioFormat& format) {
Ivo Creusendeb1b1b2021-11-24 19:29:10 +000024 if (absl::EqualsIgnoreCase(format.name, "G722") &&
25 format.clockrate_hz == 8000 &&
26 (format.num_channels == 1 || format.num_channels == 2)) {
27 return Config{rtc::dchecked_cast<int>(format.num_channels)};
28 }
29 return absl::nullopt;
kwibergb1ed7f02017-06-17 17:30:09 -070030}
31
32void AudioDecoderG722::AppendSupportedDecoders(
33 std::vector<AudioCodecSpec>* specs) {
kwiberge5eb7242017-08-25 03:10:50 -070034 specs->push_back({{"G722", 8000, 1}, {16000, 1, 64000}});
kwibergb1ed7f02017-06-17 17:30:09 -070035}
36
37std::unique_ptr<AudioDecoder> AudioDecoderG722::MakeAudioDecoder(
Karl Wiberg17668ec2018-03-01 15:13:27 +010038 Config config,
Jonas Oreland6e2b9e22022-03-15 14:29:00 +010039 absl::optional<AudioCodecPairId> /*codec_pair_id*/,
Jonas Orelande62c2f22022-03-29 11:04:48 +020040 const FieldTrialsView* field_trials) {
Ivo Creusendeb1b1b2021-11-24 19:29:10 +000041 if (!config.IsOk()) {
42 RTC_DCHECK_NOTREACHED();
43 return nullptr;
44 }
kwiberg1b97e262017-06-26 04:19:43 -070045 switch (config.num_channels) {
46 case 1:
Mirko Bonadei317a1f02019-09-17 17:06:18 +020047 return std::make_unique<AudioDecoderG722Impl>();
kwiberg1b97e262017-06-26 04:19:43 -070048 case 2:
Mirko Bonadei317a1f02019-09-17 17:06:18 +020049 return std::make_unique<AudioDecoderG722StereoImpl>();
kwiberg1b97e262017-06-26 04:19:43 -070050 default:
Ivo Creusendeb1b1b2021-11-24 19:29:10 +000051 RTC_DCHECK_NOTREACHED();
kwiberg1b97e262017-06-26 04:19:43 -070052 return nullptr;
53 }
kwibergb1ed7f02017-06-17 17:30:09 -070054}
55
56} // namespace webrtc