webrtc/api/audio_codecs/audio_format.cc
Taylor Brandstetter bd7392829a Revert "Reland "Remove our stream << overloads from non-test build targets.""
This reverts commit d7ee72041f.

Reason for revert: Broke downstream build which was using SdpAudioFormat operator<<

Original change's description:
> Reland "Remove our stream << overloads from non-test build targets."
> 
> This is a reland of c841d18d25
> 
> Original change's description:
> > Remove our stream << overloads from non-test build targets.
> >
> > Most are removed entirely, but RtcErrorType, RtpTransceiverDirection, IPAddress and
> > SocketAddress are kept behind gtest's #ifdef UNIT_TEST.
> >
> > Bug: webrtc:8982
> > Change-Id: I36db19891e7d25aeacb08b9a08aa2b4004765e70
> > Reviewed-on: https://webrtc-review.googlesource.com/64143
> > Commit-Queue: Jonas Olsson <jonasolsson@webrtc.org>
> > Reviewed-by: Benjamin Wright <benwright@webrtc.org>
> > Reviewed-by: Taylor Brandstetter <deadbeef@webrtc.org>
> > Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
> > Reviewed-by: Åsa Persson <asapersson@webrtc.org>
> > Cr-Commit-Position: refs/heads/master@{#22916}
> 
> TBR=deadbeef@webrtc.org,kwiberg@webrtc.org,asapersson@webrtc.org,jonasolsson@webrtc.org,benwright@webrtc.org
> 
> Bug: webrtc:8982
> Change-Id: Ibe08c6270e5e693eb661a6ce9e8f074b34ef8123
> Reviewed-on: https://webrtc-review.googlesource.com/71161
> Commit-Queue: Jonas Olsson <jonasolsson@webrtc.org>
> Reviewed-by: Jonas Olsson <jonasolsson@webrtc.org>
> Cr-Commit-Position: refs/heads/master@{#22949}

TBR=deadbeef@webrtc.org,kwiberg@webrtc.org,asapersson@webrtc.org,jonasolsson@webrtc.org,benwright@webrtc.org

Change-Id: I3c2b18ec2877d68a522ecbae7a2955c4eecf36df
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: webrtc:8982
Reviewed-on: https://webrtc-review.googlesource.com/71446
Reviewed-by: Taylor Brandstetter <deadbeef@webrtc.org>
Commit-Queue: Taylor Brandstetter <deadbeef@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#22963}
2018-04-20 15:58:25 +00:00

130 lines
4.6 KiB
C++

/*
* Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "api/audio_codecs/audio_format.h"
#include "common_types.h" // NOLINT(build/include)
namespace webrtc {
SdpAudioFormat::SdpAudioFormat(const SdpAudioFormat&) = default;
SdpAudioFormat::SdpAudioFormat(SdpAudioFormat&&) = default;
SdpAudioFormat::SdpAudioFormat(const char* name,
int clockrate_hz,
size_t num_channels)
: name(name), clockrate_hz(clockrate_hz), num_channels(num_channels) {}
SdpAudioFormat::SdpAudioFormat(const std::string& name,
int clockrate_hz,
size_t num_channels)
: name(name), clockrate_hz(clockrate_hz), num_channels(num_channels) {}
SdpAudioFormat::SdpAudioFormat(const char* name,
int clockrate_hz,
size_t num_channels,
const Parameters& param)
: name(name),
clockrate_hz(clockrate_hz),
num_channels(num_channels),
parameters(param) {}
SdpAudioFormat::SdpAudioFormat(const std::string& name,
int clockrate_hz,
size_t num_channels,
const Parameters& param)
: name(name),
clockrate_hz(clockrate_hz),
num_channels(num_channels),
parameters(param) {}
bool SdpAudioFormat::Matches(const SdpAudioFormat& o) const {
return STR_CASE_CMP(name.c_str(), o.name.c_str()) == 0 &&
clockrate_hz == o.clockrate_hz && num_channels == o.num_channels;
}
SdpAudioFormat::~SdpAudioFormat() = default;
SdpAudioFormat& SdpAudioFormat::operator=(const SdpAudioFormat&) = default;
SdpAudioFormat& SdpAudioFormat::operator=(SdpAudioFormat&&) = default;
bool operator==(const SdpAudioFormat& a, const SdpAudioFormat& b) {
return STR_CASE_CMP(a.name.c_str(), b.name.c_str()) == 0 &&
a.clockrate_hz == b.clockrate_hz && a.num_channels == b.num_channels &&
a.parameters == b.parameters;
}
void swap(SdpAudioFormat& a, SdpAudioFormat& b) {
using std::swap;
swap(a.name, b.name);
swap(a.clockrate_hz, b.clockrate_hz);
swap(a.num_channels, b.num_channels);
swap(a.parameters, b.parameters);
}
std::ostream& operator<<(std::ostream& os, const SdpAudioFormat& saf) {
os << "{name: " << saf.name;
os << ", clockrate_hz: " << saf.clockrate_hz;
os << ", num_channels: " << saf.num_channels;
os << ", parameters: {";
const char* sep = "";
for (const auto& kv : saf.parameters) {
os << sep << kv.first << ": " << kv.second;
sep = ", ";
}
os << "}}";
return os;
}
AudioCodecInfo::AudioCodecInfo(int sample_rate_hz,
size_t num_channels,
int bitrate_bps)
: AudioCodecInfo(sample_rate_hz,
num_channels,
bitrate_bps,
bitrate_bps,
bitrate_bps) {}
AudioCodecInfo::AudioCodecInfo(int sample_rate_hz,
size_t num_channels,
int default_bitrate_bps,
int min_bitrate_bps,
int max_bitrate_bps)
: sample_rate_hz(sample_rate_hz),
num_channels(num_channels),
default_bitrate_bps(default_bitrate_bps),
min_bitrate_bps(min_bitrate_bps),
max_bitrate_bps(max_bitrate_bps) {
RTC_DCHECK_GT(sample_rate_hz, 0);
RTC_DCHECK_GT(num_channels, 0);
RTC_DCHECK_GE(min_bitrate_bps, 0);
RTC_DCHECK_LE(min_bitrate_bps, default_bitrate_bps);
RTC_DCHECK_GE(max_bitrate_bps, default_bitrate_bps);
}
std::ostream& operator<<(std::ostream& os, const AudioCodecInfo& aci) {
os << "{sample_rate_hz: " << aci.sample_rate_hz;
os << ", num_channels: " << aci.num_channels;
os << ", default_bitrate_bps: " << aci.default_bitrate_bps;
os << ", min_bitrate_bps: " << aci.min_bitrate_bps;
os << ", max_bitrate_bps: " << aci.max_bitrate_bps;
os << ", allow_comfort_noise: " << aci.allow_comfort_noise;
os << ", supports_network_adaption: " << aci.supports_network_adaption;
os << "}";
return os;
}
std::ostream& operator<<(std::ostream& os, const AudioCodecSpec& acs) {
os << "{format: " << acs.format;
os << ", info: " << acs.info;
os << "}";
return os;
}
} // namespace webrtc