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

Side by Side Diff: media/base/mime_util_internal.cc

Issue 1677133003: Implemented parsing of HEVC codec ids (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@parse-codec-id
Patch Set: Fixed unit test Created 4 years, 10 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
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/base/mime_util_internal.h" 5 #include "media/base/mime_util_internal.h"
6 6
7 #include "base/strings/string_number_conversions.h" 7 #include "base/strings/string_number_conversions.h"
8 #include "base/strings/string_split.h" 8 #include "base/strings/string_split.h"
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 // Valid levels taken from Table A-1 in ISO/IEC 14496-10. 222 // Valid levels taken from Table A-1 in ISO/IEC 14496-10.
223 // Level_idc represents the standard level represented as decimal number 223 // Level_idc represents the standard level represented as decimal number
224 // multiplied by ten, e.g. level_idc==32 corresponds to level==3.2 224 // multiplied by ten, e.g. level_idc==32 corresponds to level==3.2
225 return ((level_idc >= 10 && level_idc <= 13) || 225 return ((level_idc >= 10 && level_idc <= 13) ||
226 (level_idc >= 20 && level_idc <= 22) || 226 (level_idc >= 20 && level_idc <= 22) ||
227 (level_idc >= 30 && level_idc <= 32) || 227 (level_idc >= 30 && level_idc <= 32) ||
228 (level_idc >= 40 && level_idc <= 42) || 228 (level_idc >= 40 && level_idc <= 42) ||
229 (level_idc >= 50 && level_idc <= 51)); 229 (level_idc >= 50 && level_idc <= 51));
230 } 230 }
231 231
232 #if BUILDFLAG(ENABLE_HEVC_DEMUXING)
233 // ISO/IEC FDIS 14496-15 standard section E.3 describes the syntax of codec ids
234 // reserved for HEVC. According to that spec HEVC codec id must start with
235 // either "hev1." or "hvc1.". We don't yet support full parsing of HEVC codec
236 // ids, but since no other codec id starts with those string we'll just treat
237 // any string starting with "hev1." or "hvc1." as valid HEVC codec ids.
238 // crbug.com/482761
239 static bool ParseHEVCCodecID(const std::string& codec_id,
240 MimeUtil::Codec* codec,
241 bool* is_ambiguous) {
242 if (base::StartsWith(codec_id, "hev1.", base::CompareCase::SENSITIVE) ||
243 base::StartsWith(codec_id, "hvc1.", base::CompareCase::SENSITIVE)) {
244 *codec = MimeUtil::HEVC_MAIN;
245
246 // TODO(servolk): Full HEVC codec id parsing is not implemented yet (see
247 // crbug.com/482761). So treat HEVC codec ids as ambiguous for now.
248 *is_ambiguous = true;
249
250 // TODO(servolk): Most HEVC codec ids are treated as ambiguous (see above),
251 // but we need to recognize at least one valid unambiguous HEVC codec id,
252 // which is added into kMP4VideoCodecsExpression. We need it to be
253 // unambiguous to avoid DCHECK(!is_ambiguous) in InitializeMimeTypeMaps. We
254 // also use these in unit tests (see
255 // content/browser/media/media_canplaytype_browsertest.cc).
256 // Remove this workaround after crbug.com/482761 is fixed.
257 if (codec_id == "hev1.1.6.L93.B0" || codec_id == "hvc1.1.6.L93.B0") {
258 *is_ambiguous = false;
259 }
260
261 return true;
262 }
263
264 return false;
265 }
266 #endif
267
268 MimeUtil::MimeUtil() : allow_proprietary_codecs_(false) { 232 MimeUtil::MimeUtil() : allow_proprietary_codecs_(false) {
269 InitializeMimeTypeMaps(); 233 InitializeMimeTypeMaps();
270 } 234 }
271 235
272 MimeUtil::~MimeUtil() {} 236 MimeUtil::~MimeUtil() {}
273 237
274 SupportsType MimeUtil::AreSupportedCodecs( 238 SupportsType MimeUtil::AreSupportedCodecs(
275 const CodecSet& supported_codecs, 239 const CodecSet& supported_codecs,
276 const std::vector<std::string>& codecs) const { 240 const std::vector<std::string>& codecs) const {
277 DCHECK(!supported_codecs.empty()); 241 DCHECK(!supported_codecs.empty());
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 string_to_codec_map_.find(codec_id); 379 string_to_codec_map_.find(codec_id);
416 if (itr != string_to_codec_map_.end()) { 380 if (itr != string_to_codec_map_.end()) {
417 *codec = itr->second.codec; 381 *codec = itr->second.codec;
418 *is_ambiguous = itr->second.is_ambiguous; 382 *is_ambiguous = itr->second.is_ambiguous;
419 return true; 383 return true;
420 } 384 }
421 385
422 // If |codec_id| is not in |string_to_codec_map_|, then we assume that it is 386 // If |codec_id| is not in |string_to_codec_map_|, then we assume that it is
423 // either H.264 or HEVC/H.265 codec ID because currently those are the only 387 // either H.264 or HEVC/H.265 codec ID because currently those are the only
424 // ones that are not added to the |string_to_codec_map_| and require parsing. 388 // ones that are not added to the |string_to_codec_map_| and require parsing.
389 VideoCodecProfile profile = VIDEO_CODEC_PROFILE_UNKNOWN;
390 uint8_t level_idc = 0;
425 391
426 #if BUILDFLAG(ENABLE_HEVC_DEMUXING) 392 #if BUILDFLAG(ENABLE_HEVC_DEMUXING)
427 if (ParseHEVCCodecID(codec_id, codec, is_ambiguous)) { 393 if (ParseHEVCCodecId(codec_id, &profile, &level_idc)) {
394 *is_ambiguous = false;
395 *codec = MimeUtil::HEVC;
428 return true; 396 return true;
429 } 397 }
430 #endif 398 #endif
431 399
432 VideoCodecProfile profile = VIDEO_CODEC_PROFILE_UNKNOWN;
433 uint8_t level_idc = 0;
434 if (ParseAVCCodecId(codec_id, &profile, &level_idc)) { 400 if (ParseAVCCodecId(codec_id, &profile, &level_idc)) {
435 *codec = MimeUtil::H264; 401 *codec = MimeUtil::H264;
436 *is_ambiguous = 402 *is_ambiguous =
437 (profile != H264PROFILE_BASELINE && profile != H264PROFILE_MAIN && 403 (profile != H264PROFILE_BASELINE && profile != H264PROFILE_MAIN &&
438 profile != H264PROFILE_HIGH) || 404 profile != H264PROFILE_HIGH) ||
439 !IsValidH264Level(level_idc); 405 !IsValidH264Level(level_idc);
440 return true; 406 return true;
441 } 407 }
442 408
443 DVLOG(4) << __FUNCTION__ << ": Unrecognized codec id " << codec_id; 409 DVLOG(4) << __FUNCTION__ << ": Unrecognized codec id " << codec_id;
(...skipping 17 matching lines...) Expand all
461 case AC3: 427 case AC3:
462 case EAC3: 428 case EAC3:
463 case MP3: 429 case MP3:
464 case MPEG2_AAC_LC: 430 case MPEG2_AAC_LC:
465 case MPEG2_AAC_MAIN: 431 case MPEG2_AAC_MAIN:
466 case MPEG2_AAC_SSR: 432 case MPEG2_AAC_SSR:
467 case MPEG4_AAC_LC: 433 case MPEG4_AAC_LC:
468 case MPEG4_AAC_SBR_v1: 434 case MPEG4_AAC_SBR_v1:
469 case MPEG4_AAC_SBR_PS_v2: 435 case MPEG4_AAC_SBR_PS_v2:
470 case H264: 436 case H264:
471 case HEVC_MAIN: 437 case HEVC:
472 return true; 438 return true;
473 439
474 case PCM: 440 case PCM:
475 case VORBIS: 441 case VORBIS:
476 case OPUS: 442 case OPUS:
477 case VP8: 443 case VP8:
478 case VP9: 444 case VP9:
479 case THEORA: 445 case THEORA:
480 return false; 446 return false;
481 } 447 }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 case MPEG2_AAC_LC: 498 case MPEG2_AAC_LC:
533 case MPEG2_AAC_MAIN: 499 case MPEG2_AAC_MAIN:
534 case MPEG2_AAC_SSR: 500 case MPEG2_AAC_SSR:
535 // MPEG-2 variants of AAC are not supported on Android. 501 // MPEG-2 variants of AAC are not supported on Android.
536 return false; 502 return false;
537 503
538 case OPUS: 504 case OPUS:
539 // Opus is supported only in Lollipop+ (API Level 21). 505 // Opus is supported only in Lollipop+ (API Level 21).
540 return base::android::BuildInfo::GetInstance()->sdk_int() >= 21; 506 return base::android::BuildInfo::GetInstance()->sdk_int() >= 21;
541 507
542 case HEVC_MAIN: 508 case HEVC:
543 #if BUILDFLAG(ENABLE_HEVC_DEMUXING) 509 #if BUILDFLAG(ENABLE_HEVC_DEMUXING)
544 // HEVC/H.265 is supported in Lollipop+ (API Level 21), according to 510 // HEVC/H.265 is supported in Lollipop+ (API Level 21), according to
545 // http://developer.android.com/reference/android/media/MediaFormat.html 511 // http://developer.android.com/reference/android/media/MediaFormat.html
546 return base::android::BuildInfo::GetInstance()->sdk_int() >= 21; 512 return base::android::BuildInfo::GetInstance()->sdk_int() >= 21;
547 #else 513 #else
548 return false; 514 return false;
549 #endif 515 #endif
550 516
551 case VP9: 517 case VP9:
552 // VP9 is supported only in KitKat+ (API Level 19). 518 // VP9 is supported only in KitKat+ (API Level 19).
553 return base::android::BuildInfo::GetInstance()->sdk_int() >= 19; 519 return base::android::BuildInfo::GetInstance()->sdk_int() >= 19;
554 520
555 case THEORA: 521 case THEORA:
556 return false; 522 return false;
557 } 523 }
558 524
559 return false; 525 return false;
560 } 526 }
561 #endif 527 #endif
562 528
563 } // namespace internal 529 } // namespace internal
564 } // namespace media 530 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698