| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2004 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2004 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include "webrtc/media/base/codec.h" | 11 #include "webrtc/media/base/codec.h" |
| 12 | 12 |
| 13 #include <algorithm> | 13 #include <algorithm> |
| 14 #include <sstream> | 14 #include <sstream> |
| 15 | 15 |
| 16 #include "webrtc/base/common.h" | 16 #include "webrtc/base/common.h" |
| 17 #include "webrtc/base/logging.h" | 17 #include "webrtc/base/logging.h" |
| 18 #include "webrtc/base/stringencode.h" | 18 #include "webrtc/base/stringencode.h" |
| 19 #include "webrtc/base/stringutils.h" | 19 #include "webrtc/base/stringutils.h" |
| 20 | 20 |
| 21 namespace { | |
| 22 | |
| 23 // Return the contained value for |key| if available, and |default_value| | |
| 24 // otherwise. | |
| 25 std::string GetParamOrDefault(const cricket::Codec& codec, | |
| 26 const std::string& key, | |
| 27 const std::string& default_value) { | |
| 28 cricket::CodecParameterMap::const_iterator iter = codec.params.find(key); | |
| 29 return (iter == codec.params.end()) ? default_value : iter->second; | |
| 30 } | |
| 31 | |
| 32 } // anonymous namespace | |
| 33 | |
| 34 namespace cricket { | 21 namespace cricket { |
| 35 | 22 |
| 36 const int kMaxPayloadId = 127; | 23 const int kMaxPayloadId = 127; |
| 37 | 24 |
| 38 bool FeedbackParam::operator==(const FeedbackParam& other) const { | 25 bool FeedbackParam::operator==(const FeedbackParam& other) const { |
| 39 return _stricmp(other.id().c_str(), id().c_str()) == 0 && | 26 return _stricmp(other.id().c_str(), id().c_str()) == 0 && |
| 40 _stricmp(other.param().c_str(), param().c_str()) == 0; | 27 _stricmp(other.param().c_str(), param().c_str()) == 0; |
| 41 } | 28 } |
| 42 | 29 |
| 43 bool FeedbackParams::operator==(const FeedbackParams& other) const { | 30 bool FeedbackParams::operator==(const FeedbackParams& other) const { |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 | 220 |
| 234 VideoCodec& VideoCodec::operator=(const VideoCodec& c) { | 221 VideoCodec& VideoCodec::operator=(const VideoCodec& c) { |
| 235 Codec::operator=(c); | 222 Codec::operator=(c); |
| 236 return *this; | 223 return *this; |
| 237 } | 224 } |
| 238 | 225 |
| 239 bool VideoCodec::operator==(const VideoCodec& c) const { | 226 bool VideoCodec::operator==(const VideoCodec& c) const { |
| 240 return Codec::operator==(c); | 227 return Codec::operator==(c); |
| 241 } | 228 } |
| 242 | 229 |
| 243 bool VideoCodec::Matches(const VideoCodec& codec) const { | |
| 244 if (!Codec::Matches(codec)) | |
| 245 return false; | |
| 246 // TODO(magjed): It would be better to have this logic in a H264 subclass. See | |
| 247 // http://crbug/webrtc/6385 for more info. | |
| 248 if (!CodecNamesEq(name, kH264CodecName)) | |
| 249 return true; | |
| 250 // H264 codecs need to have matching profile-level-id. | |
| 251 const std::string our_profile_level_id = GetParamOrDefault( | |
| 252 *this, kH264FmtpProfileLevelId, kH264FmtpDefaultProfileLevelId); | |
| 253 const std::string their_profile_level_id = GetParamOrDefault( | |
| 254 codec, kH264FmtpProfileLevelId, kH264FmtpDefaultProfileLevelId); | |
| 255 if (our_profile_level_id == their_profile_level_id) | |
| 256 return true; | |
| 257 // At this point, profile-level-id is not an exact match, but that is still ok | |
| 258 // if only level_idc differs and level asymmetry is allowed. | |
| 259 const bool level_asymmetry_allowed = | |
| 260 GetParamOrDefault(*this, kH264FmtpLevelAsymmetryAllowed, "0") == "1" && | |
| 261 GetParamOrDefault(codec, kH264FmtpLevelAsymmetryAllowed, "0") == "1"; | |
| 262 // Ignore level_idc and compare only profile_idc and profile_iop. | |
| 263 const bool is_profile_match = (our_profile_level_id.substr(0, 4) == | |
| 264 their_profile_level_id.substr(0, 4)); | |
| 265 return level_asymmetry_allowed && is_profile_match; | |
| 266 } | |
| 267 | |
| 268 VideoCodec VideoCodec::CreateRtxCodec(int rtx_payload_type, | 230 VideoCodec VideoCodec::CreateRtxCodec(int rtx_payload_type, |
| 269 int associated_payload_type) { | 231 int associated_payload_type) { |
| 270 VideoCodec rtx_codec(rtx_payload_type, kRtxCodecName); | 232 VideoCodec rtx_codec(rtx_payload_type, kRtxCodecName); |
| 271 rtx_codec.SetParam(kCodecParamAssociatedPayloadType, associated_payload_type); | 233 rtx_codec.SetParam(kCodecParamAssociatedPayloadType, associated_payload_type); |
| 272 return rtx_codec; | 234 return rtx_codec; |
| 273 } | 235 } |
| 274 | 236 |
| 275 VideoCodec::CodecType VideoCodec::GetCodecType() const { | 237 VideoCodec::CodecType VideoCodec::GetCodecType() const { |
| 276 const char* payload_name = name.c_str(); | 238 const char* payload_name = name.c_str(); |
| 277 if (_stricmp(payload_name, kRedCodecName) == 0) { | 239 if (_stricmp(payload_name, kRedCodecName) == 0) { |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 bool HasTransportCc(const Codec& codec) { | 301 bool HasTransportCc(const Codec& codec) { |
| 340 return codec.HasFeedbackParam( | 302 return codec.HasFeedbackParam( |
| 341 FeedbackParam(kRtcpFbParamTransportCc, kParamValueEmpty)); | 303 FeedbackParam(kRtcpFbParamTransportCc, kParamValueEmpty)); |
| 342 } | 304 } |
| 343 | 305 |
| 344 bool CodecNamesEq(const std::string& name1, const std::string& name2) { | 306 bool CodecNamesEq(const std::string& name1, const std::string& name2) { |
| 345 return _stricmp(name1.c_str(), name2.c_str()) == 0; | 307 return _stricmp(name1.c_str(), name2.c_str()) == 0; |
| 346 } | 308 } |
| 347 | 309 |
| 348 } // namespace cricket | 310 } // namespace cricket |
| OLD | NEW |