1 /*
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 
11 #include "api/audio_codecs/audio_format.h"
12 
13 #include <utility>
14 
15 #include "absl/strings/match.h"
16 
17 namespace webrtc {
18 
19 SdpAudioFormat::SdpAudioFormat(const SdpAudioFormat&) = default;
20 SdpAudioFormat::SdpAudioFormat(SdpAudioFormat&&) = default;
21 
SdpAudioFormat(absl::string_view name,int clockrate_hz,size_t num_channels)22 SdpAudioFormat::SdpAudioFormat(absl::string_view name,
23                                int clockrate_hz,
24                                size_t num_channels)
25     : name(name), clockrate_hz(clockrate_hz), num_channels(num_channels) {}
26 
SdpAudioFormat(absl::string_view name,int clockrate_hz,size_t num_channels,const Parameters & param)27 SdpAudioFormat::SdpAudioFormat(absl::string_view name,
28                                int clockrate_hz,
29                                size_t num_channels,
30                                const Parameters& param)
31     : name(name),
32       clockrate_hz(clockrate_hz),
33       num_channels(num_channels),
34       parameters(param) {}
35 
SdpAudioFormat(absl::string_view name,int clockrate_hz,size_t num_channels,Parameters && param)36 SdpAudioFormat::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 
Matches(const SdpAudioFormat & o) const45 bool SdpAudioFormat::Matches(const SdpAudioFormat& o) const {
46   return absl::EqualsIgnoreCase(name, o.name) &&
47          clockrate_hz == o.clockrate_hz && num_channels == o.num_channels;
48 }
49 
50 SdpAudioFormat::~SdpAudioFormat() = default;
51 SdpAudioFormat& SdpAudioFormat::operator=(const SdpAudioFormat&) = default;
52 SdpAudioFormat& SdpAudioFormat::operator=(SdpAudioFormat&&) = default;
53 
operator ==(const SdpAudioFormat & a,const SdpAudioFormat & b)54 bool operator==(const SdpAudioFormat& a, const SdpAudioFormat& b) {
55   return absl::EqualsIgnoreCase(a.name, b.name) &&
56          a.clockrate_hz == b.clockrate_hz && a.num_channels == b.num_channels &&
57          a.parameters == b.parameters;
58 }
59 
AudioCodecInfo(int sample_rate_hz,size_t num_channels,int bitrate_bps)60 AudioCodecInfo::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) {}
68 
AudioCodecInfo(int sample_rate_hz,size_t num_channels,int default_bitrate_bps,int min_bitrate_bps,int max_bitrate_bps)69 AudioCodecInfo::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 }
85 
86 }  // namespace webrtc
87