codec.cc revision fbd13286dc280eaa69c562e20e11a38cb393da3d
128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org/* 228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * libjingle 328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * Copyright 2004 Google Inc. 428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * 528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * Redistribution and use in source and binary forms, with or without 628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * modification, are permitted provided that the following conditions are met: 728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * 828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * 1. Redistributions of source code must retain the above copyright notice, 928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * this list of conditions and the following disclaimer. 1028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * 2. Redistributions in binary form must reproduce the above copyright notice, 1128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * this list of conditions and the following disclaimer in the documentation 1228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * and/or other materials provided with the distribution. 1328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * 3. The name of the author may not be used to endorse or promote products 1428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * derived from this software without specific prior written permission. 1528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * 1628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 1728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 1828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 1928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 2128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 2228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 2328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 2428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 2528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org */ 2728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org 2828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org#include "talk/media/base/codec.h" 2928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org 3028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org#include <algorithm> 3128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org#include <sstream> 3228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org 3328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org#include "talk/base/common.h" 34b5a22b14648c53874b4b76368a1a2271d985e875pbos@webrtc.org#include "talk/base/logging.h" 3528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org#include "talk/base/stringencode.h" 3628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org#include "talk/base/stringutils.h" 3728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org 3828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.orgnamespace cricket { 3928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org 4028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.orgstatic const int kMaxStaticPayloadId = 95; 4128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org 4228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.orgbool FeedbackParam::operator==(const FeedbackParam& other) const { 4328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org return _stricmp(other.id().c_str(), id().c_str()) == 0 && 4428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org _stricmp(other.param().c_str(), param().c_str()) == 0; 4528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org} 4628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org 4728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.orgbool FeedbackParams::operator==(const FeedbackParams& other) const { 4828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org return params_ == other.params_; 4928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org} 5028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org 5128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.orgbool FeedbackParams::Has(const FeedbackParam& param) const { 5228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org return std::find(params_.begin(), params_.end(), param) != params_.end(); 5328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org} 5428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org 5528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.orgvoid FeedbackParams::Add(const FeedbackParam& param) { 5628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org if (param.id().empty()) { 5728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org return; 5828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org } 5928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org if (Has(param)) { 6028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org // Param already in |this|. 6128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org return; 6228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org } 6328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org params_.push_back(param); 6428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org ASSERT(!HasDuplicateEntries()); 6528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org} 6628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org 6728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.orgvoid FeedbackParams::Intersect(const FeedbackParams& from) { 6828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org std::vector<FeedbackParam>::iterator iter_to = params_.begin(); 6928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org while (iter_to != params_.end()) { 7028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org if (!from.Has(*iter_to)) { 7128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org iter_to = params_.erase(iter_to); 7228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org } else { 7328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org ++iter_to; 7428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org } 7528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org } 7628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org} 7728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org 7828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.orgbool FeedbackParams::HasDuplicateEntries() const { 7928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org for (std::vector<FeedbackParam>::const_iterator iter = params_.begin(); 8028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org iter != params_.end(); ++iter) { 8128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org for (std::vector<FeedbackParam>::const_iterator found = iter + 1; 8228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org found != params_.end(); ++found) { 8328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org if (*found == *iter) { 8428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org return true; 8528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org } 8628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org } 8728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org } 8828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org return false; 8928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org} 9028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org 9128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.orgbool Codec::Matches(const Codec& codec) const { 9228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org // Match the codec id/name based on the typical static/dynamic name rules. 9328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org // Matching is case-insensitive. 9428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org return (codec.id <= kMaxStaticPayloadId) ? 9528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org (id == codec.id) : (_stricmp(name.c_str(), codec.name.c_str()) == 0); 9628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org} 9728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org 9828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.orgbool Codec::GetParam(const std::string& name, std::string* out) const { 9928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org CodecParameterMap::const_iterator iter = params.find(name); 10028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org if (iter == params.end()) 10128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org return false; 10228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org *out = iter->second; 10328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org return true; 10428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org} 10528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org 10628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.orgbool Codec::GetParam(const std::string& name, int* out) const { 10728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org CodecParameterMap::const_iterator iter = params.find(name); 10828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org if (iter == params.end()) 10928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org return false; 11028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org return talk_base::FromString(iter->second, out); 11128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org} 11228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org 11328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.orgvoid Codec::SetParam(const std::string& name, const std::string& value) { 11428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org params[name] = value; 11528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org} 11628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org 11728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.orgvoid Codec::SetParam(const std::string& name, int value) { 11828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org params[name] = talk_base::ToString(value); 11928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org} 12028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org 121fbd13286dc280eaa69c562e20e11a38cb393da3dbuildbot@webrtc.orgbool Codec::RemoveParam(const std::string& name) { 122fbd13286dc280eaa69c562e20e11a38cb393da3dbuildbot@webrtc.org return params.erase(name) == 1; 123fbd13286dc280eaa69c562e20e11a38cb393da3dbuildbot@webrtc.org} 124fbd13286dc280eaa69c562e20e11a38cb393da3dbuildbot@webrtc.org 12528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.orgvoid Codec::AddFeedbackParam(const FeedbackParam& param) { 12628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org feedback_params.Add(param); 12728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org} 12828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org 12928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.orgbool Codec::HasFeedbackParam(const FeedbackParam& param) const { 13028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org return feedback_params.Has(param); 13128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org} 13228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org 13328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.orgvoid Codec::IntersectFeedbackParams(const Codec& other) { 13428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org feedback_params.Intersect(other.feedback_params); 13528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org} 13628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org 13728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.orgbool AudioCodec::Matches(const AudioCodec& codec) const { 13828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org // If a nonzero clockrate is specified, it must match the actual clockrate. 13928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org // If a nonzero bitrate is specified, it must match the actual bitrate, 14028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org // unless the codec is VBR (0), where we just force the supplied value. 14128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org // The number of channels must match exactly, with the exception 14228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org // that channels=0 is treated synonymously as channels=1, per RFC 14328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org // 4566 section 6: " [The channels] parameter is OPTIONAL and may be 14428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org // omitted if the number of channels is one." 14528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org // Preference is ignored. 14628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org // TODO(juberti): Treat a zero clockrate as 8000Hz, the RTP default clockrate. 14728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org return Codec::Matches(codec) && 14828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org ((codec.clockrate == 0 /*&& clockrate == 8000*/) || 14928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org clockrate == codec.clockrate) && 15028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org (codec.bitrate == 0 || bitrate <= 0 || bitrate == codec.bitrate) && 15128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org ((codec.channels < 2 && channels < 2) || channels == codec.channels); 15228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org} 15328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org 15428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.orgstd::string AudioCodec::ToString() const { 15528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org std::ostringstream os; 15628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org os << "AudioCodec[" << id << ":" << name << ":" << clockrate << ":" << bitrate 15728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org << ":" << channels << ":" << preference << "]"; 15828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org return os.str(); 15928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org} 16028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org 16128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.orgstd::string VideoCodec::ToString() const { 16228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org std::ostringstream os; 16328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org os << "VideoCodec[" << id << ":" << name << ":" << width << ":" << height 16428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org << ":" << framerate << ":" << preference << "]"; 16528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org return os.str(); 16628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org} 16728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org 168b5a22b14648c53874b4b76368a1a2271d985e875pbos@webrtc.orgVideoCodec VideoCodec::CreateRtxCodec(int rtx_payload_type, 169b5a22b14648c53874b4b76368a1a2271d985e875pbos@webrtc.org int associated_payload_type) { 170b5a22b14648c53874b4b76368a1a2271d985e875pbos@webrtc.org VideoCodec rtx_codec(rtx_payload_type, kRtxCodecName, 0, 0, 0, 0); 171b5a22b14648c53874b4b76368a1a2271d985e875pbos@webrtc.org rtx_codec.SetParam(kCodecParamAssociatedPayloadType, associated_payload_type); 172b5a22b14648c53874b4b76368a1a2271d985e875pbos@webrtc.org return rtx_codec; 173b5a22b14648c53874b4b76368a1a2271d985e875pbos@webrtc.org} 174b5a22b14648c53874b4b76368a1a2271d985e875pbos@webrtc.org 175b5a22b14648c53874b4b76368a1a2271d985e875pbos@webrtc.orgVideoCodec::CodecType VideoCodec::GetCodecType() const { 176b5a22b14648c53874b4b76368a1a2271d985e875pbos@webrtc.org const char* payload_name = name.c_str(); 177b5a22b14648c53874b4b76368a1a2271d985e875pbos@webrtc.org if (_stricmp(payload_name, kRedCodecName) == 0) { 178b5a22b14648c53874b4b76368a1a2271d985e875pbos@webrtc.org return CODEC_RED; 179b5a22b14648c53874b4b76368a1a2271d985e875pbos@webrtc.org } 180b5a22b14648c53874b4b76368a1a2271d985e875pbos@webrtc.org if (_stricmp(payload_name, kUlpfecCodecName) == 0) { 181b5a22b14648c53874b4b76368a1a2271d985e875pbos@webrtc.org return CODEC_ULPFEC; 182b5a22b14648c53874b4b76368a1a2271d985e875pbos@webrtc.org } 183b5a22b14648c53874b4b76368a1a2271d985e875pbos@webrtc.org if (_stricmp(payload_name, kRtxCodecName) == 0) { 184b5a22b14648c53874b4b76368a1a2271d985e875pbos@webrtc.org return CODEC_RTX; 185b5a22b14648c53874b4b76368a1a2271d985e875pbos@webrtc.org } 186b5a22b14648c53874b4b76368a1a2271d985e875pbos@webrtc.org 187b5a22b14648c53874b4b76368a1a2271d985e875pbos@webrtc.org return CODEC_VIDEO; 188b5a22b14648c53874b4b76368a1a2271d985e875pbos@webrtc.org} 189b5a22b14648c53874b4b76368a1a2271d985e875pbos@webrtc.org 190b5a22b14648c53874b4b76368a1a2271d985e875pbos@webrtc.orgbool VideoCodec::ValidateCodecFormat() const { 191b5a22b14648c53874b4b76368a1a2271d985e875pbos@webrtc.org if (id < 0 || id > 127) { 192b5a22b14648c53874b4b76368a1a2271d985e875pbos@webrtc.org LOG(LS_ERROR) << "Codec with invalid payload type: " << ToString(); 193b5a22b14648c53874b4b76368a1a2271d985e875pbos@webrtc.org return false; 194b5a22b14648c53874b4b76368a1a2271d985e875pbos@webrtc.org } 195b5a22b14648c53874b4b76368a1a2271d985e875pbos@webrtc.org if (GetCodecType() != CODEC_VIDEO) { 196b5a22b14648c53874b4b76368a1a2271d985e875pbos@webrtc.org return true; 197b5a22b14648c53874b4b76368a1a2271d985e875pbos@webrtc.org } 198b5a22b14648c53874b4b76368a1a2271d985e875pbos@webrtc.org 199b5a22b14648c53874b4b76368a1a2271d985e875pbos@webrtc.org // Video validation from here on. 200b5a22b14648c53874b4b76368a1a2271d985e875pbos@webrtc.org 201b5a22b14648c53874b4b76368a1a2271d985e875pbos@webrtc.org if (width <= 0 || height <= 0) { 202b5a22b14648c53874b4b76368a1a2271d985e875pbos@webrtc.org LOG(LS_ERROR) << "Codec with invalid dimensions: " << ToString(); 203b5a22b14648c53874b4b76368a1a2271d985e875pbos@webrtc.org return false; 204b5a22b14648c53874b4b76368a1a2271d985e875pbos@webrtc.org } 205b5a22b14648c53874b4b76368a1a2271d985e875pbos@webrtc.org int min_bitrate = -1; 206b5a22b14648c53874b4b76368a1a2271d985e875pbos@webrtc.org int max_bitrate = -1; 207b5a22b14648c53874b4b76368a1a2271d985e875pbos@webrtc.org if (GetParam(kCodecParamMinBitrate, &min_bitrate) && 208b5a22b14648c53874b4b76368a1a2271d985e875pbos@webrtc.org GetParam(kCodecParamMaxBitrate, &max_bitrate)) { 209b5a22b14648c53874b4b76368a1a2271d985e875pbos@webrtc.org if (max_bitrate < min_bitrate) { 210b5a22b14648c53874b4b76368a1a2271d985e875pbos@webrtc.org LOG(LS_ERROR) << "Codec with max < min bitrate: " << ToString(); 211b5a22b14648c53874b4b76368a1a2271d985e875pbos@webrtc.org return false; 212b5a22b14648c53874b4b76368a1a2271d985e875pbos@webrtc.org } 213b5a22b14648c53874b4b76368a1a2271d985e875pbos@webrtc.org } 214b5a22b14648c53874b4b76368a1a2271d985e875pbos@webrtc.org return true; 215b5a22b14648c53874b4b76368a1a2271d985e875pbos@webrtc.org} 216b5a22b14648c53874b4b76368a1a2271d985e875pbos@webrtc.org 21728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.orgstd::string DataCodec::ToString() const { 21828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org std::ostringstream os; 21928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org os << "DataCodec[" << id << ":" << name << "]"; 22028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org return os.str(); 22128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org} 22228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org 22328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org} // namespace cricket 224