kwiberg | c01c6a4 | 2016-04-28 14:23:32 -0700 | [diff] [blame] | 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "api/audio_codecs/audio_format.h" |
kwiberg | c01c6a4 | 2016-04-28 14:23:32 -0700 | [diff] [blame] | 12 | |
Mirko Bonadei | 7120742 | 2017-09-15 13:58:09 +0200 | [diff] [blame] | 13 | #include "common_types.h" // NOLINT(build/include) |
kwiberg | c4ccd4d | 2016-09-21 10:55:15 -0700 | [diff] [blame] | 14 | |
kwiberg | c01c6a4 | 2016-04-28 14:23:32 -0700 | [diff] [blame] | 15 | namespace webrtc { |
| 16 | |
kwiberg | c01c6a4 | 2016-04-28 14:23:32 -0700 | [diff] [blame] | 17 | SdpAudioFormat::SdpAudioFormat(const SdpAudioFormat&) = default; |
| 18 | SdpAudioFormat::SdpAudioFormat(SdpAudioFormat&&) = default; |
| 19 | |
| 20 | SdpAudioFormat::SdpAudioFormat(const char* name, |
| 21 | int clockrate_hz, |
ossu | a1a040a | 2017-04-06 10:03:21 -0700 | [diff] [blame] | 22 | size_t num_channels) |
kwiberg | c01c6a4 | 2016-04-28 14:23:32 -0700 | [diff] [blame] | 23 | : name(name), clockrate_hz(clockrate_hz), num_channels(num_channels) {} |
| 24 | |
kwiberg | d32bf75 | 2017-01-19 07:03:59 -0800 | [diff] [blame] | 25 | SdpAudioFormat::SdpAudioFormat(const std::string& name, |
| 26 | int clockrate_hz, |
ossu | a1a040a | 2017-04-06 10:03:21 -0700 | [diff] [blame] | 27 | size_t num_channels) |
kwiberg | d32bf75 | 2017-01-19 07:03:59 -0800 | [diff] [blame] | 28 | : name(name), clockrate_hz(clockrate_hz), num_channels(num_channels) {} |
| 29 | |
kwiberg | 5178ee8 | 2016-05-03 01:39:01 -0700 | [diff] [blame] | 30 | SdpAudioFormat::SdpAudioFormat(const char* name, |
| 31 | int clockrate_hz, |
ossu | a1a040a | 2017-04-06 10:03:21 -0700 | [diff] [blame] | 32 | size_t num_channels, |
kwiberg | d32bf75 | 2017-01-19 07:03:59 -0800 | [diff] [blame] | 33 | const Parameters& param) |
kwiberg | 5178ee8 | 2016-05-03 01:39:01 -0700 | [diff] [blame] | 34 | : name(name), |
| 35 | clockrate_hz(clockrate_hz), |
| 36 | num_channels(num_channels), |
kwiberg | d32bf75 | 2017-01-19 07:03:59 -0800 | [diff] [blame] | 37 | parameters(param) {} |
| 38 | |
| 39 | SdpAudioFormat::SdpAudioFormat(const std::string& name, |
| 40 | int clockrate_hz, |
ossu | a1a040a | 2017-04-06 10:03:21 -0700 | [diff] [blame] | 41 | size_t num_channels, |
kwiberg | d32bf75 | 2017-01-19 07:03:59 -0800 | [diff] [blame] | 42 | const Parameters& param) |
| 43 | : name(name), |
| 44 | clockrate_hz(clockrate_hz), |
| 45 | num_channels(num_channels), |
| 46 | parameters(param) {} |
kwiberg | 5178ee8 | 2016-05-03 01:39:01 -0700 | [diff] [blame] | 47 | |
deadbeef | cb38367 | 2017-04-26 16:28:42 -0700 | [diff] [blame] | 48 | bool SdpAudioFormat::Matches(const SdpAudioFormat& o) const { |
| 49 | return STR_CASE_CMP(name.c_str(), o.name.c_str()) == 0 && |
| 50 | clockrate_hz == o.clockrate_hz && num_channels == o.num_channels; |
| 51 | } |
| 52 | |
kwiberg | c01c6a4 | 2016-04-28 14:23:32 -0700 | [diff] [blame] | 53 | SdpAudioFormat::~SdpAudioFormat() = default; |
| 54 | SdpAudioFormat& SdpAudioFormat::operator=(const SdpAudioFormat&) = default; |
| 55 | SdpAudioFormat& SdpAudioFormat::operator=(SdpAudioFormat&&) = default; |
| 56 | |
kwiberg | c4ccd4d | 2016-09-21 10:55:15 -0700 | [diff] [blame] | 57 | bool operator==(const SdpAudioFormat& a, const SdpAudioFormat& b) { |
| 58 | return STR_CASE_CMP(a.name.c_str(), b.name.c_str()) == 0 && |
| 59 | a.clockrate_hz == b.clockrate_hz && a.num_channels == b.num_channels && |
| 60 | a.parameters == b.parameters; |
| 61 | } |
| 62 | |
kwiberg | c01c6a4 | 2016-04-28 14:23:32 -0700 | [diff] [blame] | 63 | void swap(SdpAudioFormat& a, SdpAudioFormat& b) { |
| 64 | using std::swap; |
| 65 | swap(a.name, b.name); |
| 66 | swap(a.clockrate_hz, b.clockrate_hz); |
| 67 | swap(a.num_channels, b.num_channels); |
| 68 | swap(a.parameters, b.parameters); |
| 69 | } |
| 70 | |
| 71 | std::ostream& operator<<(std::ostream& os, const SdpAudioFormat& saf) { |
| 72 | os << "{name: " << saf.name; |
| 73 | os << ", clockrate_hz: " << saf.clockrate_hz; |
| 74 | os << ", num_channels: " << saf.num_channels; |
| 75 | os << ", parameters: {"; |
| 76 | const char* sep = ""; |
| 77 | for (const auto& kv : saf.parameters) { |
| 78 | os << sep << kv.first << ": " << kv.second; |
| 79 | sep = ", "; |
| 80 | } |
| 81 | os << "}}"; |
| 82 | return os; |
| 83 | } |
| 84 | |
ossu | a1a040a | 2017-04-06 10:03:21 -0700 | [diff] [blame] | 85 | AudioCodecInfo::AudioCodecInfo(int sample_rate_hz, |
| 86 | size_t num_channels, |
| 87 | int bitrate_bps) |
| 88 | : AudioCodecInfo(sample_rate_hz, |
| 89 | num_channels, |
| 90 | bitrate_bps, |
| 91 | bitrate_bps, |
| 92 | bitrate_bps) {} |
ossu | 9def800 | 2017-02-09 05:14:32 -0800 | [diff] [blame] | 93 | |
ossu | a1a040a | 2017-04-06 10:03:21 -0700 | [diff] [blame] | 94 | AudioCodecInfo::AudioCodecInfo(int sample_rate_hz, |
| 95 | size_t num_channels, |
| 96 | int default_bitrate_bps, |
| 97 | int min_bitrate_bps, |
| 98 | int max_bitrate_bps) |
| 99 | : sample_rate_hz(sample_rate_hz), |
| 100 | num_channels(num_channels), |
| 101 | default_bitrate_bps(default_bitrate_bps), |
| 102 | min_bitrate_bps(min_bitrate_bps), |
| 103 | max_bitrate_bps(max_bitrate_bps) { |
| 104 | RTC_DCHECK_GT(sample_rate_hz, 0); |
| 105 | RTC_DCHECK_GT(num_channels, 0); |
| 106 | RTC_DCHECK_GE(min_bitrate_bps, 0); |
| 107 | RTC_DCHECK_LE(min_bitrate_bps, default_bitrate_bps); |
| 108 | RTC_DCHECK_GE(max_bitrate_bps, default_bitrate_bps); |
| 109 | } |
ossu | 9def800 | 2017-02-09 05:14:32 -0800 | [diff] [blame] | 110 | |
kwiberg | 96444ae | 2017-06-14 03:27:40 -0700 | [diff] [blame] | 111 | std::ostream& operator<<(std::ostream& os, const AudioCodecInfo& aci) { |
| 112 | os << "{sample_rate_hz: " << aci.sample_rate_hz; |
| 113 | os << ", num_channels: " << aci.num_channels; |
| 114 | os << ", default_bitrate_bps: " << aci.default_bitrate_bps; |
| 115 | os << ", min_bitrate_bps: " << aci.min_bitrate_bps; |
| 116 | os << ", max_bitrate_bps: " << aci.max_bitrate_bps; |
| 117 | os << ", allow_comfort_noise: " << aci.allow_comfort_noise; |
| 118 | os << ", supports_network_adaption: " << aci.supports_network_adaption; |
| 119 | os << "}"; |
| 120 | return os; |
| 121 | } |
| 122 | |
| 123 | std::ostream& operator<<(std::ostream& os, const AudioCodecSpec& acs) { |
| 124 | os << "{format: " << acs.format; |
| 125 | os << ", info: " << acs.info; |
| 126 | os << "}"; |
| 127 | return os; |
| 128 | } |
| 129 | |
kwiberg | c01c6a4 | 2016-04-28 14:23:32 -0700 | [diff] [blame] | 130 | } // namespace webrtc |