blob: d80e6bf928a8616687922f76a787fcef214b882a [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_encoder_L16.h"
kwiberg7ea6e592017-08-16 06:12:57 -070012
Mirko Bonadei71207422017-09-15 13:58:09 +020013#include "common_types.h" // NOLINT(build/include)
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020014#include "modules/audio_coding/codecs/pcm16b/audio_encoder_pcm16b.h"
15#include "modules/audio_coding/codecs/pcm16b/pcm16b_common.h"
Karl Wiberge40468b2017-11-22 10:42:26 +010016#include "rtc_base/numerics/safe_conversions.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020017#include "rtc_base/ptr_util.h"
kwiberg7ea6e592017-08-16 06:12:57 -070018
19namespace webrtc {
20
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +020021absl::optional<AudioEncoderL16::Config> AudioEncoderL16::SdpToConfig(
kwiberg7ea6e592017-08-16 06:12:57 -070022 const SdpAudioFormat& format) {
Karl Wibergeea063f2017-09-14 13:49:13 +020023 if (!rtc::IsValueInRangeForNumericType<int>(format.num_channels)) {
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +020024 return absl::nullopt;
Karl Wibergeea063f2017-09-14 13:49:13 +020025 }
kwiberg7ea6e592017-08-16 06:12:57 -070026 Config config;
27 config.sample_rate_hz = format.clockrate_hz;
Karl Wibergeea063f2017-09-14 13:49:13 +020028 config.num_channels = rtc::dchecked_cast<int>(format.num_channels);
kwiberg7ea6e592017-08-16 06:12:57 -070029 return STR_CASE_CMP(format.name.c_str(), "L16") == 0 && config.IsOk()
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +020030 ? absl::optional<Config>(config)
31 : absl::nullopt;
kwiberg7ea6e592017-08-16 06:12:57 -070032}
33
34void AudioEncoderL16::AppendSupportedEncoders(
35 std::vector<AudioCodecSpec>* specs) {
36 Pcm16BAppendSupportedCodecSpecs(specs);
37}
38
39AudioCodecInfo AudioEncoderL16::QueryAudioEncoder(
40 const AudioEncoderL16::Config& config) {
41 RTC_DCHECK(config.IsOk());
42 return {config.sample_rate_hz,
43 rtc::dchecked_cast<size_t>(config.num_channels),
44 config.sample_rate_hz * config.num_channels * 16};
45}
46
47std::unique_ptr<AudioEncoder> AudioEncoderL16::MakeAudioEncoder(
48 const AudioEncoderL16::Config& config,
Karl Wiberg17668ec2018-03-01 15:13:27 +010049 int payload_type,
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +020050 absl::optional<AudioCodecPairId> /*codec_pair_id*/) {
kwiberg7ea6e592017-08-16 06:12:57 -070051 RTC_DCHECK(config.IsOk());
52 AudioEncoderPcm16B::Config c;
53 c.sample_rate_hz = config.sample_rate_hz;
54 c.num_channels = config.num_channels;
55 c.frame_size_ms = config.frame_size_ms;
56 c.payload_type = payload_type;
57 return rtc::MakeUnique<AudioEncoderPcm16B>(c);
58}
59
60} // namespace webrtc