blob: 81ed299ddb66aaf836967d4f446f73e908bc7211 [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 Bonadei71207422017-09-15 13:58:09 +020013#include "common_types.h" // NOLINT(build/include)
kwibergc4ccd4d2016-09-21 10:55:15 -070014
kwibergc01c6a42016-04-28 14:23:32 -070015namespace webrtc {
16
kwibergc01c6a42016-04-28 14:23:32 -070017SdpAudioFormat::SdpAudioFormat(const SdpAudioFormat&) = default;
18SdpAudioFormat::SdpAudioFormat(SdpAudioFormat&&) = default;
19
Karl Wiberg24744a92018-08-15 15:23:08 +020020SdpAudioFormat::SdpAudioFormat(absl::string_view name,
kwibergc01c6a42016-04-28 14:23:32 -070021 int clockrate_hz,
ossua1a040a2017-04-06 10:03:21 -070022 size_t num_channels)
kwibergc01c6a42016-04-28 14:23:32 -070023 : name(name), clockrate_hz(clockrate_hz), num_channels(num_channels) {}
24
Karl Wiberg24744a92018-08-15 15:23:08 +020025SdpAudioFormat::SdpAudioFormat(absl::string_view name,
kwibergd32bf752017-01-19 07:03:59 -080026 int clockrate_hz,
ossua1a040a2017-04-06 10:03:21 -070027 size_t num_channels,
kwibergd32bf752017-01-19 07:03:59 -080028 const Parameters& param)
29 : name(name),
30 clockrate_hz(clockrate_hz),
31 num_channels(num_channels),
32 parameters(param) {}
kwiberg5178ee82016-05-03 01:39:01 -070033
deadbeefcb383672017-04-26 16:28:42 -070034bool SdpAudioFormat::Matches(const SdpAudioFormat& o) const {
35 return STR_CASE_CMP(name.c_str(), o.name.c_str()) == 0 &&
36 clockrate_hz == o.clockrate_hz && num_channels == o.num_channels;
37}
38
kwibergc01c6a42016-04-28 14:23:32 -070039SdpAudioFormat::~SdpAudioFormat() = default;
40SdpAudioFormat& SdpAudioFormat::operator=(const SdpAudioFormat&) = default;
41SdpAudioFormat& SdpAudioFormat::operator=(SdpAudioFormat&&) = default;
42
kwibergc4ccd4d2016-09-21 10:55:15 -070043bool operator==(const SdpAudioFormat& a, const SdpAudioFormat& b) {
44 return STR_CASE_CMP(a.name.c_str(), b.name.c_str()) == 0 &&
45 a.clockrate_hz == b.clockrate_hz && a.num_channels == b.num_channels &&
46 a.parameters == b.parameters;
47}
48
kwibergc01c6a42016-04-28 14:23:32 -070049void swap(SdpAudioFormat& a, SdpAudioFormat& b) {
50 using std::swap;
51 swap(a.name, b.name);
52 swap(a.clockrate_hz, b.clockrate_hz);
53 swap(a.num_channels, b.num_channels);
54 swap(a.parameters, b.parameters);
55}
56
ossua1a040a2017-04-06 10:03:21 -070057AudioCodecInfo::AudioCodecInfo(int sample_rate_hz,
58 size_t num_channels,
59 int bitrate_bps)
60 : AudioCodecInfo(sample_rate_hz,
61 num_channels,
62 bitrate_bps,
63 bitrate_bps,
64 bitrate_bps) {}
ossu9def8002017-02-09 05:14:32 -080065
ossua1a040a2017-04-06 10:03:21 -070066AudioCodecInfo::AudioCodecInfo(int sample_rate_hz,
67 size_t num_channels,
68 int default_bitrate_bps,
69 int min_bitrate_bps,
70 int max_bitrate_bps)
71 : sample_rate_hz(sample_rate_hz),
72 num_channels(num_channels),
73 default_bitrate_bps(default_bitrate_bps),
74 min_bitrate_bps(min_bitrate_bps),
75 max_bitrate_bps(max_bitrate_bps) {
76 RTC_DCHECK_GT(sample_rate_hz, 0);
77 RTC_DCHECK_GT(num_channels, 0);
78 RTC_DCHECK_GE(min_bitrate_bps, 0);
79 RTC_DCHECK_LE(min_bitrate_bps, default_bitrate_bps);
80 RTC_DCHECK_GE(max_bitrate_bps, default_bitrate_bps);
81}
ossu9def8002017-02-09 05:14:32 -080082
kwibergc01c6a42016-04-28 14:23:32 -070083} // namespace webrtc