blob: 874a8a5111fa6542c64291d7935948213122aa14 [file] [log] [blame]
kwiberg7ea6e592017-08-16 06:12:57 -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/L16/audio_decoder_L16.h"
kwiberg7ea6e592017-08-16 06:12:57 -070012
Mirko Bonadei317a1f02019-09-17 17:06:18 +020013#include <memory>
14
Niels Möller2edab4c2018-10-22 09:48:08 +020015#include "absl/strings/match.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020016#include "modules/audio_coding/codecs/pcm16b/audio_decoder_pcm16b.h"
17#include "modules/audio_coding/codecs/pcm16b/pcm16b_common.h"
Karl Wiberge40468b2017-11-22 10:42:26 +010018#include "rtc_base/numerics/safe_conversions.h"
kwiberg7ea6e592017-08-16 06:12:57 -070019
20namespace webrtc {
21
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +020022absl::optional<AudioDecoderL16::Config> AudioDecoderL16::SdpToConfig(
kwiberg7ea6e592017-08-16 06:12:57 -070023 const SdpAudioFormat& format) {
24 Config config;
25 config.sample_rate_hz = format.clockrate_hz;
kwiberg2a596542017-08-22 03:43:28 -070026 config.num_channels = rtc::checked_cast<int>(format.num_channels);
Ivo Creusendeb1b1b2021-11-24 19:29:10 +000027 if (absl::EqualsIgnoreCase(format.name, "L16") && config.IsOk()) {
28 return config;
29 }
30 return absl::nullopt;
kwiberg7ea6e592017-08-16 06:12:57 -070031}
32
33void AudioDecoderL16::AppendSupportedDecoders(
34 std::vector<AudioCodecSpec>* specs) {
35 Pcm16BAppendSupportedCodecSpecs(specs);
36}
37
38std::unique_ptr<AudioDecoder> AudioDecoderL16::MakeAudioDecoder(
Karl Wiberg17668ec2018-03-01 15:13:27 +010039 const Config& config,
Jonas Oreland6e2b9e22022-03-15 14:29:00 +010040 absl::optional<AudioCodecPairId> /*codec_pair_id*/,
41 const WebRtcKeyValueConfig* field_trials) {
Ivo Creusendeb1b1b2021-11-24 19:29:10 +000042 if (!config.IsOk()) {
43 return nullptr;
44 }
45 return std::make_unique<AudioDecoderPcm16B>(config.sample_rate_hz,
46 config.num_channels);
kwiberg7ea6e592017-08-16 06:12:57 -070047}
48
49} // namespace webrtc