Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 274 const std::vector<std::string>& codecs, | 274 const std::vector<std::string>& codecs, |
| 275 const std::string& mime_type_lower_case, | 275 const std::string& mime_type_lower_case, |
| 276 bool is_encrypted) const { | 276 bool is_encrypted) const { |
| 277 DCHECK(!supported_codecs.empty()); | 277 DCHECK(!supported_codecs.empty()); |
| 278 DCHECK(!codecs.empty()); | 278 DCHECK(!codecs.empty()); |
| 279 | 279 |
| 280 SupportsType result = IsSupported; | 280 SupportsType result = IsSupported; |
| 281 for (size_t i = 0; i < codecs.size(); ++i) { | 281 for (size_t i = 0; i < codecs.size(); ++i) { |
| 282 bool is_ambiguous = true; | 282 bool is_ambiguous = true; |
| 283 Codec codec = INVALID_CODEC; | 283 Codec codec = INVALID_CODEC; |
| 284 if (!StringToCodec(codecs[i], &codec, &is_ambiguous)) | 284 if (!StringToCodec(codecs[i], &codec, &is_ambiguous, is_encrypted)) |
| 285 return IsNotSupported; | 285 return IsNotSupported; |
| 286 | 286 |
| 287 if (!IsCodecSupported(codec, mime_type_lower_case, is_encrypted) || | 287 if (!IsCodecSupported(codec, mime_type_lower_case, is_encrypted) || |
| 288 supported_codecs.find(codec) == supported_codecs.end()) { | 288 supported_codecs.find(codec) == supported_codecs.end()) { |
| 289 return IsNotSupported; | 289 return IsNotSupported; |
| 290 } | 290 } |
| 291 | 291 |
| 292 if (is_ambiguous) | 292 if (is_ambiguous) |
| 293 result = MayBeSupported; | 293 result = MayBeSupported; |
| 294 } | 294 } |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 315 // Initialize the supported media formats. | 315 // Initialize the supported media formats. |
| 316 for (size_t i = 0; i < arraysize(kFormatCodecMappings); ++i) { | 316 for (size_t i = 0; i < arraysize(kFormatCodecMappings); ++i) { |
| 317 std::vector<std::string> mime_type_codecs; | 317 std::vector<std::string> mime_type_codecs; |
| 318 ParseCodecString(kFormatCodecMappings[i].codecs_list, &mime_type_codecs, | 318 ParseCodecString(kFormatCodecMappings[i].codecs_list, &mime_type_codecs, |
| 319 false); | 319 false); |
| 320 | 320 |
| 321 CodecSet codecs; | 321 CodecSet codecs; |
| 322 for (size_t j = 0; j < mime_type_codecs.size(); ++j) { | 322 for (size_t j = 0; j < mime_type_codecs.size(); ++j) { |
| 323 Codec codec = INVALID_CODEC; | 323 Codec codec = INVALID_CODEC; |
| 324 bool is_ambiguous = true; | 324 bool is_ambiguous = true; |
| 325 CHECK(StringToCodec(mime_type_codecs[j], &codec, &is_ambiguous)); | 325 CHECK(StringToCodec(mime_type_codecs[j], &codec, &is_ambiguous, false)); |
| 326 DCHECK(!is_ambiguous); | 326 DCHECK(!is_ambiguous); |
| 327 codecs.insert(codec); | 327 codecs.insert(codec); |
| 328 } | 328 } |
| 329 | 329 |
| 330 media_format_map_[kFormatCodecMappings[i].mime_type] = codecs; | 330 media_format_map_[kFormatCodecMappings[i].mime_type] = codecs; |
| 331 } | 331 } |
| 332 } | 332 } |
| 333 | 333 |
| 334 bool MimeUtil::IsSupportedMediaMimeType(const std::string& mime_type) const { | 334 bool MimeUtil::IsSupportedMediaMimeType(const std::string& mime_type) const { |
| 335 return media_format_map_.find(base::ToLowerASCII(mime_type)) != | 335 return media_format_map_.find(base::ToLowerASCII(mime_type)) != |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 524 // Otherwise, platform support is required. | 524 // Otherwise, platform support is required. |
| 525 return platform_info.supports_vp9; | 525 return platform_info.supports_vp9; |
| 526 } | 526 } |
| 527 } | 527 } |
| 528 | 528 |
| 529 return false; | 529 return false; |
| 530 } | 530 } |
| 531 | 531 |
| 532 bool MimeUtil::StringToCodec(const std::string& codec_id, | 532 bool MimeUtil::StringToCodec(const std::string& codec_id, |
| 533 Codec* codec, | 533 Codec* codec, |
| 534 bool* is_ambiguous) const { | 534 bool* is_ambiguous, |
| 535 bool is_encrypted) const { | |
| 535 StringToCodecMappings::const_iterator itr = | 536 StringToCodecMappings::const_iterator itr = |
| 536 string_to_codec_map_.find(codec_id); | 537 string_to_codec_map_.find(codec_id); |
| 537 if (itr != string_to_codec_map_.end()) { | 538 if (itr != string_to_codec_map_.end()) { |
| 538 *codec = itr->second.codec; | 539 *codec = itr->second.codec; |
| 539 *is_ambiguous = itr->second.is_ambiguous; | 540 *is_ambiguous = itr->second.is_ambiguous; |
| 540 return true; | 541 return true; |
| 541 } | 542 } |
| 542 | 543 |
| 543 // If |codec_id| is not in |string_to_codec_map_|, then we assume that it is | 544 // If |codec_id| is not in |string_to_codec_map_|, then we assume that it is |
| 544 // either H.264 or HEVC/H.265 codec ID because currently those are the only | 545 // either H.264 or HEVC/H.265 codec ID because currently those are the only |
| 545 // ones that are not added to the |string_to_codec_map_| and require parsing. | 546 // ones that are not added to the |string_to_codec_map_| and require parsing. |
| 546 | 547 |
| 547 #if BUILDFLAG(ENABLE_HEVC_DEMUXING) | 548 #if BUILDFLAG(ENABLE_HEVC_DEMUXING) |
| 548 if (ParseHEVCCodecID(codec_id, codec, is_ambiguous)) { | 549 if (ParseHEVCCodecID(codec_id, codec, is_ambiguous)) { |
| 549 return true; | 550 return true; |
| 550 } | 551 } |
| 551 #endif | 552 #endif |
| 552 | 553 |
| 553 VideoCodecProfile profile = VIDEO_CODEC_PROFILE_UNKNOWN; | 554 VideoCodecProfile profile = VIDEO_CODEC_PROFILE_UNKNOWN; |
| 554 uint8_t level_idc = 0; | 555 uint8_t level_idc = 0; |
| 555 if (ParseAVCCodecId(codec_id, &profile, &level_idc)) { | 556 if (ParseAVCCodecId(codec_id, &profile, &level_idc)) { |
| 556 *codec = MimeUtil::H264; | 557 *codec = MimeUtil::H264; |
| 557 *is_ambiguous = | 558 switch (profile) { |
| 558 (profile != H264PROFILE_BASELINE && profile != H264PROFILE_MAIN && | 559 // HIGH10PROFILE is supported through fallback to the ffmpeg decoder. |
|
ddorwin
2016/03/31 22:31:12
nit: , which
hubbe
2016/04/01 00:20:59
Done.
| |
| 559 profile != H264PROFILE_HIGH) || | 560 // Which is not available on Android, chromium builds or if |
|
ddorwin
2016/03/31 22:31:12
Chromium is irrelevant to this (that's handled els
hubbe
2016/04/01 00:20:58
Done.
| |
| 560 !IsValidH264Level(level_idc); | 561 // FFMPEG has been disabled. |
|
ddorwin
2016/03/31 22:31:12
nit suggestion: s/has been disabled/is not used/.
hubbe
2016/04/01 00:20:59
Done.
| |
| 562 #if !defined(MEDIA_DISABLE_FFMPEG) && !defined(OS_ANDROID) | |
|
ddorwin
2016/03/31 22:31:12
:) +dalecurtis to confirm this logic.
We should p
DaleCurtis
2016/03/31 22:58:44
this is correct. android doesn't have ff_h264.
hubbe
2016/04/01 00:20:59
Acknowledged.
hubbe
2016/04/01 00:20:59
Acknowledged.
| |
| 563 case H264PROFILE_HIGH10PROFILE: | |
|
ddorwin
2016/03/31 22:31:12
It might be nicer to always have this case and put
hubbe
2016/04/01 00:20:58
Tried it, but I didn't like how it turned out.
| |
| 564 if (is_encrypted) { | |
| 565 // Currently we do not support EME on 10-bit videos. | |
|
ddorwin
2016/03/31 22:31:12
More accurately, especially since we don't return
hubbe
2016/04/01 00:20:59
Done.
| |
| 566 *is_ambiguous = true; | |
| 567 break; | |
| 568 } | |
|
ddorwin
2016/03/31 22:31:12
Add an explicit comment to "fall through" so it's
hubbe
2016/04/01 00:20:59
Done.
| |
| 569 #endif | |
| 570 | |
| 571 case H264PROFILE_BASELINE: | |
| 572 case H264PROFILE_MAIN: | |
| 573 case H264PROFILE_HIGH: | |
| 574 | |
| 575 *is_ambiguous = !IsValidH264Level(level_idc); | |
| 576 break; | |
| 577 default: | |
| 578 *is_ambiguous = true; | |
| 579 } | |
| 561 return true; | 580 return true; |
| 562 } | 581 } |
| 563 | 582 |
| 564 DVLOG(4) << __FUNCTION__ << ": Unrecognized codec id " << codec_id; | 583 DVLOG(4) << __FUNCTION__ << ": Unrecognized codec id " << codec_id; |
| 565 return false; | 584 return false; |
| 566 } | 585 } |
| 567 | 586 |
| 568 bool MimeUtil::IsCodecSupported(Codec codec, | 587 bool MimeUtil::IsCodecSupported(Codec codec, |
| 569 const std::string& mime_type_lower_case, | 588 const std::string& mime_type_lower_case, |
| 570 bool is_encrypted) const { | 589 bool is_encrypted) const { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 625 const std::string& mime_type_lower_case, | 644 const std::string& mime_type_lower_case, |
| 626 bool is_encrypted) const { | 645 bool is_encrypted) const { |
| 627 Codec default_codec = Codec::INVALID_CODEC; | 646 Codec default_codec = Codec::INVALID_CODEC; |
| 628 if (!GetDefaultCodecLowerCase(mime_type_lower_case, &default_codec)) | 647 if (!GetDefaultCodecLowerCase(mime_type_lower_case, &default_codec)) |
| 629 return false; | 648 return false; |
| 630 return IsCodecSupported(default_codec, mime_type_lower_case, is_encrypted); | 649 return IsCodecSupported(default_codec, mime_type_lower_case, is_encrypted); |
| 631 } | 650 } |
| 632 | 651 |
| 633 } // namespace internal | 652 } // namespace internal |
| 634 } // namespace media | 653 } // namespace media |
| OLD | NEW |