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

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

Issue 2153643002: Make video codec support logic overridable via MediaClient (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move is_ambiguous flag handling back to StringToCodec Created 4 years, 4 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 | « media/base/mime_util_internal.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/command_line.h" 7 #include "base/command_line.h"
8 #include "base/strings/string_number_conversions.h" 8 #include "base/strings/string_number_conversions.h"
9 #include "base/strings/string_split.h" 9 #include "base/strings/string_split.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
11 #include "build/build_config.h" 11 #include "build/build_config.h"
12 #include "media/base/media.h" 12 #include "media/base/media.h"
13 #include "media/base/media_client.h"
13 #include "media/base/media_switches.h" 14 #include "media/base/media_switches.h"
14 #include "media/base/video_codecs.h" 15 #include "media/base/video_codecs.h"
15 16
16 #if defined(OS_ANDROID) 17 #if defined(OS_ANDROID)
17 #include "base/android/build_info.h" 18 #include "base/android/build_info.h"
18 #include "media/base/android/media_codec_util.h" 19 #include "media/base/android/media_codec_util.h"
19 #endif 20 #endif
20 21
21 namespace media { 22 namespace media {
22 namespace internal { 23 namespace internal {
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 platform_info_.has_platform_vp9_decoder = 256 platform_info_.has_platform_vp9_decoder =
256 MediaCodecUtil::IsVp9DecoderAvailable(); 257 MediaCodecUtil::IsVp9DecoderAvailable();
257 platform_info_.supports_opus = PlatformHasOpusSupport(); 258 platform_info_.supports_opus = PlatformHasOpusSupport();
258 #endif 259 #endif
259 260
260 InitializeMimeTypeMaps(); 261 InitializeMimeTypeMaps();
261 } 262 }
262 263
263 MimeUtil::~MimeUtil() {} 264 MimeUtil::~MimeUtil() {}
264 265
266 VideoCodec MimeUtilToVideoCodec(MimeUtil::Codec codec) {
267 switch (codec) {
268 case MimeUtil::H264:
269 return kCodecH264;
270 case MimeUtil::HEVC:
271 return kCodecHEVC;
272 case MimeUtil::VP8:
273 return kCodecVP8;
274 case MimeUtil::VP9:
275 return kCodecVP9;
276 case MimeUtil::THEORA:
277 return kCodecTheora;
278 default:
279 break;
280 }
281 return kUnknownVideoCodec;
282 }
283
265 SupportsType MimeUtil::AreSupportedCodecs( 284 SupportsType MimeUtil::AreSupportedCodecs(
266 const CodecSet& supported_codecs, 285 const CodecSet& supported_codecs,
267 const std::vector<std::string>& codecs, 286 const std::vector<std::string>& codecs,
268 const std::string& mime_type_lower_case, 287 const std::string& mime_type_lower_case,
269 bool is_encrypted) const { 288 bool is_encrypted) const {
270 DCHECK(!supported_codecs.empty()); 289 DCHECK(!supported_codecs.empty());
271 DCHECK(!codecs.empty()); 290 DCHECK(!codecs.empty());
272 291
273 SupportsType result = IsSupported; 292 SupportsType result = IsSupported;
274 for (size_t i = 0; i < codecs.size(); ++i) { 293 for (size_t i = 0; i < codecs.size(); ++i) {
275 bool is_ambiguous = true; 294 bool is_ambiguous = true;
276 Codec codec = INVALID_CODEC; 295 Codec codec = INVALID_CODEC;
296 VideoCodecProfile video_profile = VIDEO_CODEC_PROFILE_UNKNOWN;
297 uint8_t video_level = 0;
277 if (!StringToCodec(mime_type_lower_case, codecs[i], &codec, &is_ambiguous, 298 if (!StringToCodec(mime_type_lower_case, codecs[i], &codec, &is_ambiguous,
278 is_encrypted)) { 299 &video_profile, &video_level, is_encrypted)) {
279 return IsNotSupported; 300 return IsNotSupported;
280 } 301 }
281 302
303 VideoCodec video_codec = MimeUtilToVideoCodec(codec);
304
305 if (GetMediaClient() && video_codec != kUnknownVideoCodec &&
306 !GetMediaClient()->IsSupportedVideoConfig(video_codec, video_profile,
307 video_level)) {
308 return IsNotSupported;
309 }
310
282 if (!IsCodecSupported(codec, mime_type_lower_case, is_encrypted) || 311 if (!IsCodecSupported(codec, mime_type_lower_case, is_encrypted) ||
283 supported_codecs.find(codec) == supported_codecs.end()) { 312 supported_codecs.find(codec) == supported_codecs.end()) {
284 return IsNotSupported; 313 return IsNotSupported;
285 } 314 }
286 315
287 if (is_ambiguous) 316 if (is_ambiguous)
288 result = MayBeSupported; 317 result = MayBeSupported;
289 } 318 }
290 319
291 return result; 320 return result;
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 } 661 }
633 } 662 }
634 663
635 return false; 664 return false;
636 } 665 }
637 666
638 bool MimeUtil::StringToCodec(const std::string& mime_type_lower_case, 667 bool MimeUtil::StringToCodec(const std::string& mime_type_lower_case,
639 const std::string& codec_id, 668 const std::string& codec_id,
640 Codec* codec, 669 Codec* codec,
641 bool* is_ambiguous, 670 bool* is_ambiguous,
671 VideoCodecProfile* out_profile,
672 uint8_t* out_level,
642 bool is_encrypted) const { 673 bool is_encrypted) const {
674 DCHECK(out_profile);
675 DCHECK(out_level);
676 *out_profile = VIDEO_CODEC_PROFILE_UNKNOWN;
677 *out_level = 0;
678
643 StringToCodecMappings::const_iterator itr = 679 StringToCodecMappings::const_iterator itr =
644 string_to_codec_map_.find(codec_id); 680 string_to_codec_map_.find(codec_id);
645 if (itr != string_to_codec_map_.end()) { 681 if (itr != string_to_codec_map_.end()) {
646 *codec = itr->second.codec; 682 *codec = itr->second.codec;
647 *is_ambiguous = itr->second.is_ambiguous; 683 *is_ambiguous = itr->second.is_ambiguous;
648 return true; 684 return true;
649 } 685 }
650 686
651 // If |codec_id| is not in |string_to_codec_map_|, then we assume that it is 687 // If |codec_id| is not in |string_to_codec_map_|, then we assume that it is
652 // either H.264 or HEVC/H.265 codec ID because currently those are the only 688 // either H.264 or HEVC/H.265 codec ID because currently those are the only
653 // ones that are not added to the |string_to_codec_map_| and require parsing. 689 // ones that are not added to the |string_to_codec_map_| and require parsing.
654 VideoCodecProfile profile = VIDEO_CODEC_PROFILE_UNKNOWN; 690 if (ParseAVCCodecId(codec_id, out_profile, out_level)) {
655 uint8_t level_idc = 0;
656
657 if (ParseAVCCodecId(codec_id, &profile, &level_idc)) {
658 *codec = MimeUtil::H264; 691 *codec = MimeUtil::H264;
659 switch (profile) { 692 switch (*out_profile) {
660 // HIGH10PROFILE is supported through fallback to the ffmpeg decoder 693 // HIGH10PROFILE is supported through fallback to the ffmpeg decoder
661 // which is not available on Android, or if FFMPEG is not used. 694 // which is not available on Android, or if FFMPEG is not used.
662 #if !defined(MEDIA_DISABLE_FFMPEG) && !defined(OS_ANDROID) 695 #if !defined(MEDIA_DISABLE_FFMPEG) && !defined(OS_ANDROID)
663 case H264PROFILE_HIGH10PROFILE: 696 case H264PROFILE_HIGH10PROFILE:
664 if (is_encrypted) { 697 if (is_encrypted) {
665 // FFmpeg is not generally used for encrypted videos, so we do not 698 // FFmpeg is not generally used for encrypted videos, so we do not
666 // know whether 10-bit is supported. 699 // know whether 10-bit is supported.
667 *is_ambiguous = true; 700 *is_ambiguous = true;
668 break; 701 break;
669 } 702 }
670 // Fall through. 703 // Fall through.
671 #endif 704 #endif
672 705
673 case H264PROFILE_BASELINE: 706 case H264PROFILE_BASELINE:
674 case H264PROFILE_MAIN: 707 case H264PROFILE_MAIN:
675 case H264PROFILE_HIGH: 708 case H264PROFILE_HIGH:
676 *is_ambiguous = !IsValidH264Level(level_idc); 709 *is_ambiguous = !IsValidH264Level(*out_level);
677 break; 710 break;
678 default: 711 default:
679 *is_ambiguous = true; 712 *is_ambiguous = true;
680 } 713 }
681 return true; 714 return true;
682 } 715 }
683 716
684 if (ParseVp9CodecID(mime_type_lower_case, codec_id, &profile)) { 717 if (ParseVp9CodecID(mime_type_lower_case, codec_id, out_profile)) {
685 *codec = MimeUtil::VP9; 718 *codec = MimeUtil::VP9;
686 switch (profile) { 719 *out_level = 1;
720 switch (*out_profile) {
687 case VP9PROFILE_PROFILE0: 721 case VP9PROFILE_PROFILE0:
688 // Profile 0 should always be supported if VP9 is supported. 722 // Profile 0 should always be supported if VP9 is supported.
689 *is_ambiguous = false; 723 *is_ambiguous = false;
690 break; 724 break;
691 default: 725 default:
692 // We don't know if the underlying platform supports these profiles. 726 // We don't know if the underlying platform supports these profiles.
693 // Need to add platform level querying to get supported profiles 727 // Need to add platform level querying to get supported profiles
694 // (crbug/604566). 728 // (crbug/604566).
695 *is_ambiguous = true; 729 *is_ambiguous = true;
696 } 730 }
697 return true; 731 return true;
698 } 732 }
699 733
700 #if BUILDFLAG(ENABLE_HEVC_DEMUXING) 734 #if BUILDFLAG(ENABLE_HEVC_DEMUXING)
701 if (ParseHEVCCodecId(codec_id, &profile, &level_idc)) { 735 if (ParseHEVCCodecId(codec_id, out_profile, out_level)) {
702 // TODO(servolk): Set |is_ambiguous| to true for now to make CanPlayType
703 // return 'maybe' for HEVC codec ids, instead of probably. This needs to be
704 // changed to false after adding platform-level HEVC profile and level
705 // checks, see crbug.com/601949.
706 *is_ambiguous = true;
707 *codec = MimeUtil::HEVC; 736 *codec = MimeUtil::HEVC;
737 *is_ambiguous = false;
708 return true; 738 return true;
709 } 739 }
710 #endif 740 #endif
711 741
712 DVLOG(4) << __FUNCTION__ << ": Unrecognized codec id " << codec_id; 742 DVLOG(4) << __FUNCTION__ << ": Unrecognized codec id " << codec_id;
713 return false; 743 return false;
714 } 744 }
715 745
716 bool MimeUtil::IsCodecSupported(Codec codec, 746 bool MimeUtil::IsCodecSupported(Codec codec,
717 const std::string& mime_type_lower_case, 747 const std::string& mime_type_lower_case,
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
773 const std::string& mime_type_lower_case, 803 const std::string& mime_type_lower_case,
774 bool is_encrypted) const { 804 bool is_encrypted) const {
775 Codec default_codec = Codec::INVALID_CODEC; 805 Codec default_codec = Codec::INVALID_CODEC;
776 if (!GetDefaultCodecLowerCase(mime_type_lower_case, &default_codec)) 806 if (!GetDefaultCodecLowerCase(mime_type_lower_case, &default_codec))
777 return false; 807 return false;
778 return IsCodecSupported(default_codec, mime_type_lower_case, is_encrypted); 808 return IsCodecSupported(default_codec, mime_type_lower_case, is_encrypted);
779 } 809 }
780 810
781 } // namespace internal 811 } // namespace internal
782 } // namespace media 812 } // namespace media
OLDNEW
« no previous file with comments | « media/base/mime_util_internal.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698