Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(595)

Side by Side Diff: webrtc/media/base/codec.cc

Issue 2347863003: H264 codec: Check profile-level-id when matching (Closed)
Patch Set: Fix hta comments Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/media/base/codec.h ('k') | webrtc/media/base/codec_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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;
tommi 2016/10/25 09:19:58 nit: this function should just return |const char
magjed_webrtc 2016/10/25 10:58:01 The reason for not returning char* was that CodecP
30 }
31
32 } // anonymous namespace
33
21 namespace cricket { 34 namespace cricket {
22 35
23 const int kMaxPayloadId = 127; 36 const int kMaxPayloadId = 127;
24 37
25 bool FeedbackParam::operator==(const FeedbackParam& other) const { 38 bool FeedbackParam::operator==(const FeedbackParam& other) const {
26 return _stricmp(other.id().c_str(), id().c_str()) == 0 && 39 return _stricmp(other.id().c_str(), id().c_str()) == 0 &&
27 _stricmp(other.param().c_str(), param().c_str()) == 0; 40 _stricmp(other.param().c_str(), param().c_str()) == 0;
28 } 41 }
29 42
30 bool FeedbackParams::operator==(const FeedbackParams& other) const { 43 bool FeedbackParams::operator==(const FeedbackParams& other) const {
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 height = c.height; 251 height = c.height;
239 framerate = c.framerate; 252 framerate = c.framerate;
240 return *this; 253 return *this;
241 } 254 }
242 255
243 bool VideoCodec::operator==(const VideoCodec& c) const { 256 bool VideoCodec::operator==(const VideoCodec& c) const {
244 return width == c.width && height == c.height && framerate == c.framerate && 257 return width == c.width && height == c.height && framerate == c.framerate &&
245 Codec::operator==(c); 258 Codec::operator==(c);
246 } 259 }
247 260
261 bool VideoCodec::Matches(const VideoCodec& codec) const {
262 if (!Codec::Matches(codec))
263 return false;
264 // TODO(magjed): It would be better to have this logic in a H264 subclass. See
265 // http://crbug/webrtc/6385 for more info.
266 if (!CodecNamesEq(name, kH264CodecName))
267 return true;
268 // H264 codecs need to have matching profile-level-id.
269 const std::string our_profile_level_id = GetParamOrDefault(
270 *this, kH264FmtpProfileLevelId, kH264FmtpDefaultProfileLevelId);
271 const std::string their_profile_level_id = GetParamOrDefault(
272 codec, kH264FmtpProfileLevelId, kH264FmtpDefaultProfileLevelId);
273 if (our_profile_level_id == their_profile_level_id)
274 return true;
275 // At this point, profile-level-id is not an exact match, but that is still ok
276 // if only level_idc differs and level asymmetry is allowed.
277 const bool level_asymmetry_allowed =
278 GetParamOrDefault(*this, kH264FmtpLevelAsymmetryAllowed, "0") == "1" &&
279 GetParamOrDefault(codec, kH264FmtpLevelAsymmetryAllowed, "0") == "1";
tommi 2016/10/25 09:19:58 nit: "0" -> "" (or nullptr?)
magjed_webrtc 2016/10/25 10:58:01 Yes, should be possible. I wanted to be clear here
280 // Ignore level_idc and compare only profile_idc and profile_iop.
281 const bool is_profile_match = (our_profile_level_id.substr(0, 4) ==
282 their_profile_level_id.substr(0, 4));
tommi 2016/10/25 09:19:58 three nits: * do you know if our_profile_level_id
hta-webrtc 2016/10/25 09:36:25 1) profile-level-id is always six characters; anyt
magjed_webrtc 2016/10/25 10:58:01 I will add explicit functionality for parsing the
283 return level_asymmetry_allowed && is_profile_match;
tommi 2016/10/25 09:19:58 nit: if level_asymmetry_allowed is required, you m
magjed_webrtc 2016/10/25 10:58:01 Sure. As long as the code is as clear as possible.
284 }
285
248 VideoCodec VideoCodec::CreateRtxCodec(int rtx_payload_type, 286 VideoCodec VideoCodec::CreateRtxCodec(int rtx_payload_type,
249 int associated_payload_type) { 287 int associated_payload_type) {
250 VideoCodec rtx_codec(rtx_payload_type, kRtxCodecName, 0, 0, 0); 288 VideoCodec rtx_codec(rtx_payload_type, kRtxCodecName, 0, 0, 0);
251 rtx_codec.SetParam(kCodecParamAssociatedPayloadType, associated_payload_type); 289 rtx_codec.SetParam(kCodecParamAssociatedPayloadType, associated_payload_type);
252 return rtx_codec; 290 return rtx_codec;
253 } 291 }
254 292
255 VideoCodec::CodecType VideoCodec::GetCodecType() const { 293 VideoCodec::CodecType VideoCodec::GetCodecType() const {
256 const char* payload_name = name.c_str(); 294 const char* payload_name = name.c_str();
257 if (_stricmp(payload_name, kRedCodecName) == 0) { 295 if (_stricmp(payload_name, kRedCodecName) == 0) {
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 bool HasTransportCc(const Codec& codec) { 362 bool HasTransportCc(const Codec& codec) {
325 return codec.HasFeedbackParam( 363 return codec.HasFeedbackParam(
326 FeedbackParam(kRtcpFbParamTransportCc, kParamValueEmpty)); 364 FeedbackParam(kRtcpFbParamTransportCc, kParamValueEmpty));
327 } 365 }
328 366
329 bool CodecNamesEq(const std::string& name1, const std::string& name2) { 367 bool CodecNamesEq(const std::string& name1, const std::string& name2) {
330 return _stricmp(name1.c_str(), name2.c_str()) == 0; 368 return _stricmp(name1.c_str(), name2.c_str()) == 0;
331 } 369 }
332 370
333 } // namespace cricket 371 } // namespace cricket
OLDNEW
« no previous file with comments | « webrtc/media/base/codec.h ('k') | webrtc/media/base/codec_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698