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 | |
kwiberg | 087bd34 | 2017-02-10 08:15:44 -0800 | [diff] [blame] | 11 | #include "webrtc/api/audio_codecs/audio_format.h" |
kwiberg | c01c6a4 | 2016-04-28 14:23:32 -0700 | [diff] [blame] | 12 | |
kwiberg | c4ccd4d | 2016-09-21 10:55:15 -0700 | [diff] [blame] | 13 | #include "webrtc/common_types.h" |
| 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, |
| 22 | int num_channels) |
| 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, |
| 27 | int num_channels) |
| 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, |
| 32 | int 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, |
| 41 | int num_channels, |
| 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 | |
kwiberg | c01c6a4 | 2016-04-28 14:23:32 -0700 | [diff] [blame] | 48 | SdpAudioFormat::~SdpAudioFormat() = default; |
| 49 | SdpAudioFormat& SdpAudioFormat::operator=(const SdpAudioFormat&) = default; |
| 50 | SdpAudioFormat& SdpAudioFormat::operator=(SdpAudioFormat&&) = default; |
| 51 | |
kwiberg | c4ccd4d | 2016-09-21 10:55:15 -0700 | [diff] [blame] | 52 | bool operator==(const SdpAudioFormat& a, const SdpAudioFormat& b) { |
| 53 | return STR_CASE_CMP(a.name.c_str(), b.name.c_str()) == 0 && |
| 54 | a.clockrate_hz == b.clockrate_hz && a.num_channels == b.num_channels && |
| 55 | a.parameters == b.parameters; |
| 56 | } |
| 57 | |
kwiberg | c01c6a4 | 2016-04-28 14:23:32 -0700 | [diff] [blame] | 58 | void swap(SdpAudioFormat& a, SdpAudioFormat& b) { |
| 59 | using std::swap; |
| 60 | swap(a.name, b.name); |
| 61 | swap(a.clockrate_hz, b.clockrate_hz); |
| 62 | swap(a.num_channels, b.num_channels); |
| 63 | swap(a.parameters, b.parameters); |
| 64 | } |
| 65 | |
| 66 | std::ostream& operator<<(std::ostream& os, const SdpAudioFormat& saf) { |
| 67 | os << "{name: " << saf.name; |
| 68 | os << ", clockrate_hz: " << saf.clockrate_hz; |
| 69 | os << ", num_channels: " << saf.num_channels; |
| 70 | os << ", parameters: {"; |
| 71 | const char* sep = ""; |
| 72 | for (const auto& kv : saf.parameters) { |
| 73 | os << sep << kv.first << ": " << kv.second; |
| 74 | sep = ", "; |
| 75 | } |
| 76 | os << "}}"; |
| 77 | return os; |
| 78 | } |
| 79 | |
kwiberg | 087bd34 | 2017-02-10 08:15:44 -0800 | [diff] [blame] | 80 | AudioCodecSpec::AudioCodecSpec(const SdpAudioFormat& format) : format(format) {} |
ossu | 9def800 | 2017-02-09 05:14:32 -0800 | [diff] [blame] | 81 | |
| 82 | AudioCodecSpec::AudioCodecSpec(SdpAudioFormat&& format) |
| 83 | : format(std::move(format)) {} |
| 84 | |
kwiberg | c01c6a4 | 2016-04-28 14:23:32 -0700 | [diff] [blame] | 85 | } // namespace webrtc |