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

Side by Side Diff: net/base/mime_util.cc

Issue 816353010: Implemented HEVC video demuxing and parsing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address ddorwin@ CR feedback Created 5 years, 9 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 <algorithm> 5 #include <algorithm>
6 #include <iterator> 6 #include <iterator>
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 9
10 #include "base/containers/hash_tables.h" 10 #include "base/containers/hash_tables.h"
(...skipping 27 matching lines...) Expand all
38 MPEG2_AAC_MAIN, 38 MPEG2_AAC_MAIN,
39 MPEG2_AAC_SSR, 39 MPEG2_AAC_SSR,
40 MPEG4_AAC_LC, 40 MPEG4_AAC_LC,
41 MPEG4_AAC_SBR_v1, 41 MPEG4_AAC_SBR_v1,
42 MPEG4_AAC_SBR_PS_v2, 42 MPEG4_AAC_SBR_PS_v2,
43 VORBIS, 43 VORBIS,
44 OPUS, 44 OPUS,
45 H264_BASELINE, 45 H264_BASELINE,
46 H264_MAIN, 46 H264_MAIN,
47 H264_HIGH, 47 H264_HIGH,
48 HEVC_MAIN,
48 VP8, 49 VP8,
49 VP9, 50 VP9,
50 THEORA 51 THEORA
51 }; 52 };
52 53
53 bool GetMimeTypeFromExtension(const base::FilePath::StringType& ext, 54 bool GetMimeTypeFromExtension(const base::FilePath::StringType& ext,
54 std::string* mime_type) const; 55 std::string* mime_type) const;
55 56
56 bool GetMimeTypeFromFile(const base::FilePath& file_path, 57 bool GetMimeTypeFromFile(const base::FilePath& file_path,
57 std::string* mime_type) const; 58 std::string* mime_type) const;
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 case MimeUtil::MPEG4_AAC_LC: 460 case MimeUtil::MPEG4_AAC_LC:
460 case MimeUtil::MPEG4_AAC_SBR_v1: 461 case MimeUtil::MPEG4_AAC_SBR_v1:
461 case MimeUtil::MPEG4_AAC_SBR_PS_v2: 462 case MimeUtil::MPEG4_AAC_SBR_PS_v2:
462 case MimeUtil::H264_BASELINE: 463 case MimeUtil::H264_BASELINE:
463 case MimeUtil::H264_MAIN: 464 case MimeUtil::H264_MAIN:
464 case MimeUtil::H264_HIGH: 465 case MimeUtil::H264_HIGH:
465 case MimeUtil::VP8: 466 case MimeUtil::VP8:
466 case MimeUtil::VORBIS: 467 case MimeUtil::VORBIS:
467 return true; 468 return true;
468 469
470 case MimeUtil::HEVC_MAIN:
471 #if defined(ENABLE_HEVC_DEMUXING)
472 // HEVC/H.265 is supported only in Lollipop+ (API Level 21). According to
473 // http://developer.android.com/reference/android/media/MediaFormat.html
474 return base::android::BuildInfo::GetInstance()->sdk_int() >= 21;
475 #else
476 return false;
477 #endif
478
469 case MimeUtil::MPEG2_AAC_LC: 479 case MimeUtil::MPEG2_AAC_LC:
470 case MimeUtil::MPEG2_AAC_MAIN: 480 case MimeUtil::MPEG2_AAC_MAIN:
471 case MimeUtil::MPEG2_AAC_SSR: 481 case MimeUtil::MPEG2_AAC_SSR:
472 // MPEG-2 variants of AAC are not supported on Android. 482 // MPEG-2 variants of AAC are not supported on Android.
473 return false; 483 return false;
474 484
475 case MimeUtil::VP9: 485 case MimeUtil::VP9:
476 // VP9 is supported only in KitKat+ (API Level 19). 486 // VP9 is supported only in KitKat+ (API Level 19).
477 return base::android::BuildInfo::GetInstance()->sdk_int() >= 19; 487 return base::android::BuildInfo::GetInstance()->sdk_int() >= 19;
478 488
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 "mp4a.66,mp4a.67,mp4a.68,mp4a.69,mp4a.6B,mp4a.40.2,mp4a.40.02,mp4a.40.5," 523 "mp4a.66,mp4a.67,mp4a.68,mp4a.69,mp4a.6B,mp4a.40.2,mp4a.40.02,mp4a.40.5,"
514 "mp4a.40.05,mp4a.40.29"; 524 "mp4a.40.05,mp4a.40.29";
515 static const char kMP4VideoCodecsExpression[] = 525 static const char kMP4VideoCodecsExpression[] =
516 // This is not a complete list of supported avc1 codecs. It is simply used 526 // This is not a complete list of supported avc1 codecs. It is simply used
517 // to register support for the corresponding Codec enum. Instead of using 527 // to register support for the corresponding Codec enum. Instead of using
518 // strings in these three arrays, we should use the Codec enum values. 528 // strings in these three arrays, we should use the Codec enum values.
519 // This will avoid confusion and unnecessary parsing at runtime. 529 // This will avoid confusion and unnecessary parsing at runtime.
520 // kUnambiguousCodecStringMap/kAmbiguousCodecStringMap should be the only 530 // kUnambiguousCodecStringMap/kAmbiguousCodecStringMap should be the only
521 // mapping from strings to codecs. See crbug.com/461009. 531 // mapping from strings to codecs. See crbug.com/461009.
522 "avc1.42E00A,avc1.4D400A,avc1.64000A," 532 "avc1.42E00A,avc1.4D400A,avc1.64000A,"
533 #if defined(ENABLE_HEVC_DEMUXING)
534 // Any valid-looking HEVC string will work here, since these strings are
535 // parsed and mapped to MimeUtil::Codec enum values.
536 "hvc1.1.L0.0,"
537 #endif
523 "mp4a.66,mp4a.67,mp4a.68,mp4a.69,mp4a.6B,mp4a.40.2,mp4a.40.02,mp4a.40.5," 538 "mp4a.66,mp4a.67,mp4a.68,mp4a.69,mp4a.6B,mp4a.40.2,mp4a.40.02,mp4a.40.5,"
524 "mp4a.40.05,mp4a.40.29"; 539 "mp4a.40.05,mp4a.40.29";
525 540
526 // These containers are also included in 541 // These containers are also included in
527 // common_media_types/proprietary_media_types. See crbug.com/461012. 542 // common_media_types/proprietary_media_types. See crbug.com/461012.
528 static const MediaFormatStrict format_codec_mappings[] = { 543 static const MediaFormatStrict format_codec_mappings[] = {
529 {"video/webm", "opus,vorbis,vp8,vp8.0,vp9,vp9.0"}, 544 {"video/webm", "opus,vorbis,vp8,vp8.0,vp9,vp9.0"},
530 {"audio/webm", "opus,vorbis"}, 545 {"audio/webm", "opus,vorbis"},
531 {"audio/wav", "1"}, 546 {"audio/wav", "1"},
532 {"audio/x-wav", "1"}, 547 {"audio/x-wav", "1"},
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after
1018 } else { 1033 } else {
1019 *codec = MimeUtil::H264_BASELINE; 1034 *codec = MimeUtil::H264_BASELINE;
1020 *is_ambiguous = true; 1035 *is_ambiguous = true;
1021 return true; 1036 return true;
1022 } 1037 }
1023 1038
1024 *is_ambiguous = !IsValidH264Level(StringToUpperASCII(codec_id.substr(9))); 1039 *is_ambiguous = !IsValidH264Level(StringToUpperASCII(codec_id.substr(9)));
1025 return true; 1040 return true;
1026 } 1041 }
1027 1042
1043 #if defined(ENABLE_HEVC_DEMUXING)
1044 static bool ParseHEVCCodecID(const std::string& codec_id,
1045 MimeUtil::Codec* codec,
1046 bool* is_ambiguous) {
1047 if (StartsWithASCII(codec_id, "hev1.", true) ||
1048 StartsWithASCII(codec_id, "hvc1.", true)) {
1049 // TODO(servolk): Implement parsing of hevc codec ids as described in
ddorwin 2015/03/25 18:02:58 Is there a bug for this?
servolk 2015/04/29 23:50:33 Created crbug.com/482761
1050 // ETSI TS 126 244 standard section A.2.2, but for now allow any
1051 // HEVC tiers/profiles and let decoder decide if it can handle that.
1052 *codec = MimeUtil::HEVC_MAIN;
1053 *is_ambiguous = true;
ddorwin 2015/03/25 18:02:58 IIRC, this will cause a DCHECK because of line 536
servolk 2015/04/29 23:50:33 Yep, that was causing dchecks, so I've changed is_
1054 return true;
1055 }
1056 return false;
ddorwin 2015/03/25 18:02:58 nit: empty line
servolk 2015/04/29 23:50:33 Done.
1057 }
1058 #endif
1059
1028 bool MimeUtil::StringToCodec(const std::string& codec_id, 1060 bool MimeUtil::StringToCodec(const std::string& codec_id,
1029 Codec* codec, 1061 Codec* codec,
1030 bool* is_ambiguous) const { 1062 bool* is_ambiguous) const {
1031 StringToCodecMappings::const_iterator itr = 1063 StringToCodecMappings::const_iterator itr =
1032 string_to_codec_map_.find(codec_id); 1064 string_to_codec_map_.find(codec_id);
1033 if (itr != string_to_codec_map_.end()) { 1065 if (itr != string_to_codec_map_.end()) {
1034 *codec = itr->second.codec; 1066 *codec = itr->second.codec;
1035 *is_ambiguous = itr->second.is_ambiguous; 1067 *is_ambiguous = itr->second.is_ambiguous;
1036 return true; 1068 return true;
1037 } 1069 }
1038 1070
1039 // If |codec_id| is not in |string_to_codec_map_|, then we assume that it is 1071 // If |codec_id| is not in |string_to_codec_map_|, then we assume that it is
1040 // an H.264 codec ID because currently those are the only ones that can't be 1072 // either H.264 or HEVC/H.265 codec ID because currently those are the only
1041 // stored in the |string_to_codec_map_| and require parsing. 1073 // ones that are not added to the |string_to_codec_map_| and require parsing.
1074
1075 #if defined(ENABLE_HEVC_DEMUXING)
1076 if (ParseHEVCCodecID(codec_id, codec, is_ambiguous)) {
1077 return true;
1078 }
1079 #endif
1080
1042 return ParseH264CodecID(codec_id, codec, is_ambiguous); 1081 return ParseH264CodecID(codec_id, codec, is_ambiguous);
1043 } 1082 }
1044 1083
1045 bool MimeUtil::IsCodecSupported(Codec codec) const { 1084 bool MimeUtil::IsCodecSupported(Codec codec) const {
1046 DCHECK_NE(codec, INVALID_CODEC); 1085 DCHECK_NE(codec, INVALID_CODEC);
1047 1086
1048 #if defined(OS_ANDROID) 1087 #if defined(OS_ANDROID)
1049 if (!IsCodecSupportedOnAndroid(codec)) 1088 if (!IsCodecSupportedOnAndroid(codec))
1050 return false; 1089 return false;
1051 #endif 1090 #endif
1052 1091
1053 return allow_proprietary_codecs_ || !IsCodecProprietary(codec); 1092 return allow_proprietary_codecs_ || !IsCodecProprietary(codec);
1054 } 1093 }
1055 1094
1056 bool MimeUtil::IsCodecProprietary(Codec codec) const { 1095 bool MimeUtil::IsCodecProprietary(Codec codec) const {
1057 switch (codec) { 1096 switch (codec) {
1058 case INVALID_CODEC: 1097 case INVALID_CODEC:
1059 case MP3: 1098 case MP3:
1060 case MPEG2_AAC_LC: 1099 case MPEG2_AAC_LC:
1061 case MPEG2_AAC_MAIN: 1100 case MPEG2_AAC_MAIN:
1062 case MPEG2_AAC_SSR: 1101 case MPEG2_AAC_SSR:
1063 case MPEG4_AAC_LC: 1102 case MPEG4_AAC_LC:
1064 case MPEG4_AAC_SBR_v1: 1103 case MPEG4_AAC_SBR_v1:
1065 case MPEG4_AAC_SBR_PS_v2: 1104 case MPEG4_AAC_SBR_PS_v2:
1066 case H264_BASELINE: 1105 case H264_BASELINE:
1067 case H264_MAIN: 1106 case H264_MAIN:
1068 case H264_HIGH: 1107 case H264_HIGH:
1108 case HEVC_MAIN:
1069 return true; 1109 return true;
1070 1110
1071 case PCM: 1111 case PCM:
1072 case VORBIS: 1112 case VORBIS:
1073 case OPUS: 1113 case OPUS:
1074 case VP8: 1114 case VP8:
1075 case VP9: 1115 case VP9:
1076 case THEORA: 1116 case THEORA:
1077 return false; 1117 return false;
1078 } 1118 }
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
1409 post_data->append("\r\n" + value + "\r\n"); 1449 post_data->append("\r\n" + value + "\r\n");
1410 } 1450 }
1411 1451
1412 void AddMultipartFinalDelimiterForUpload(const std::string& mime_boundary, 1452 void AddMultipartFinalDelimiterForUpload(const std::string& mime_boundary,
1413 std::string* post_data) { 1453 std::string* post_data) {
1414 DCHECK(post_data); 1454 DCHECK(post_data);
1415 post_data->append("--" + mime_boundary + "--\r\n"); 1455 post_data->append("--" + mime_boundary + "--\r\n");
1416 } 1456 }
1417 1457
1418 } // namespace net 1458 } // namespace net
OLDNEW
« content/browser/media/media_canplaytype_browsertest.cc ('K') | « media/test/data/bear-hevc-frag.mp4 ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698