blob: 2a529a49ee5b5a87def17f1ffd7481d2340511da [file] [log] [blame]
kwibergc01c6a42016-04-28 14:23:32 -07001/*
2 * Copyright (c) 2016 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/audio_format.h"
kwibergc01c6a42016-04-28 14:23:32 -070012
Mirko Bonadei1c546052019-02-04 14:50:38 +010013#include <utility>
14
Niels Möller2edab4c2018-10-22 09:48:08 +020015#include "absl/strings/match.h"
kwibergc4ccd4d2016-09-21 10:55:15 -070016
kwibergc01c6a42016-04-28 14:23:32 -070017namespace webrtc {
18
kwibergc01c6a42016-04-28 14:23:32 -070019SdpAudioFormat::SdpAudioFormat(const SdpAudioFormat&) = default;
20SdpAudioFormat::SdpAudioFormat(SdpAudioFormat&&) = default;
21
Karl Wiberg24744a92018-08-15 15:23:08 +020022SdpAudioFormat::SdpAudioFormat(absl::string_view name,
kwibergc01c6a42016-04-28 14:23:32 -070023 int clockrate_hz,
ossua1a040a2017-04-06 10:03:21 -070024 size_t num_channels)
kwibergc01c6a42016-04-28 14:23:32 -070025 : name(name), clockrate_hz(clockrate_hz), num_channels(num_channels) {}
26
Karl Wiberg24744a92018-08-15 15:23:08 +020027SdpAudioFormat::SdpAudioFormat(absl::string_view name,
kwibergd32bf752017-01-19 07:03:59 -080028 int clockrate_hz,
ossua1a040a2017-04-06 10:03:21 -070029 size_t num_channels,
kwibergd32bf752017-01-19 07:03:59 -080030 const Parameters& param)
31 : name(name),
32 clockrate_hz(clockrate_hz),
33 num_channels(num_channels),
34 parameters(param) {}
kwiberg5178ee82016-05-03 01:39:01 -070035
Mirko Bonadei1c546052019-02-04 14:50:38 +010036SdpAudioFormat::SdpAudioFormat(absl::string_view name,
37 int clockrate_hz,
38 size_t num_channels,
39 Parameters&& param)
40 : name(name),
41 clockrate_hz(clockrate_hz),
42 num_channels(num_channels),
43 parameters(std::move(param)) {}
44
deadbeefcb383672017-04-26 16:28:42 -070045bool SdpAudioFormat::Matches(const SdpAudioFormat& o) const {
Niels Möller2edab4c2018-10-22 09:48:08 +020046 return absl::EqualsIgnoreCase(name, o.name) &&
deadbeefcb383672017-04-26 16:28:42 -070047 clockrate_hz == o.clockrate_hz && num_channels == o.num_channels;
48}
49
kwibergc01c6a42016-04-28 14:23:32 -070050SdpAudioFormat::~SdpAudioFormat() = default;
51SdpAudioFormat& SdpAudioFormat::operator=(const SdpAudioFormat&) = default;
52SdpAudioFormat& SdpAudioFormat::operator=(SdpAudioFormat&&) = default;
53
kwibergc4ccd4d2016-09-21 10:55:15 -070054bool operator==(const SdpAudioFormat& a, const SdpAudioFormat& b) {
Niels Möller2edab4c2018-10-22 09:48:08 +020055 return absl::EqualsIgnoreCase(a.name, b.name) &&
kwibergc4ccd4d2016-09-21 10:55:15 -070056 a.clockrate_hz == b.clockrate_hz && a.num_channels == b.num_channels &&
57 a.parameters == b.parameters;
58}
59
ossua1a040a2017-04-06 10:03:21 -070060AudioCodecInfo::AudioCodecInfo(int sample_rate_hz,
61 size_t num_channels,
62 int bitrate_bps)
63 : AudioCodecInfo(sample_rate_hz,
64 num_channels,
65 bitrate_bps,
66 bitrate_bps,
67 bitrate_bps) {}
ossu9def8002017-02-09 05:14:32 -080068
ossua1a040a2017-04-06 10:03:21 -070069AudioCodecInfo::AudioCodecInfo(int sample_rate_hz,
70 size_t num_channels,
71 int default_bitrate_bps,
72 int min_bitrate_bps,
73 int max_bitrate_bps)
74 : sample_rate_hz(sample_rate_hz),
75 num_channels(num_channels),
76 default_bitrate_bps(default_bitrate_bps),
77 min_bitrate_bps(min_bitrate_bps),
78 max_bitrate_bps(max_bitrate_bps) {
79 RTC_DCHECK_GT(sample_rate_hz, 0);
80 RTC_DCHECK_GT(num_channels, 0);
81 RTC_DCHECK_GE(min_bitrate_bps, 0);
82 RTC_DCHECK_LE(min_bitrate_bps, default_bitrate_bps);
83 RTC_DCHECK_GE(max_bitrate_bps, default_bitrate_bps);
84}
ossu9def8002017-02-09 05:14:32 -080085
kwibergc01c6a42016-04-28 14:23:32 -070086} // namespace webrtc