| OLD | NEW |
| 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 Loading... |
| 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 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 457 case MimeUtil::MPEG4_AAC_LC: | 458 case MimeUtil::MPEG4_AAC_LC: |
| 458 case MimeUtil::MPEG4_AAC_SBR_v1: | 459 case MimeUtil::MPEG4_AAC_SBR_v1: |
| 459 case MimeUtil::MPEG4_AAC_SBR_PS_v2: | 460 case MimeUtil::MPEG4_AAC_SBR_PS_v2: |
| 460 case MimeUtil::H264_BASELINE: | 461 case MimeUtil::H264_BASELINE: |
| 461 case MimeUtil::H264_MAIN: | 462 case MimeUtil::H264_MAIN: |
| 462 case MimeUtil::H264_HIGH: | 463 case MimeUtil::H264_HIGH: |
| 463 case MimeUtil::VP8: | 464 case MimeUtil::VP8: |
| 464 case MimeUtil::VORBIS: | 465 case MimeUtil::VORBIS: |
| 465 return true; | 466 return true; |
| 466 | 467 |
| 468 case MimeUtil::HEVC_MAIN: |
| 469 return false; |
| 470 |
| 467 case MimeUtil::MPEG2_AAC_LC: | 471 case MimeUtil::MPEG2_AAC_LC: |
| 468 case MimeUtil::MPEG2_AAC_MAIN: | 472 case MimeUtil::MPEG2_AAC_MAIN: |
| 469 case MimeUtil::MPEG2_AAC_SSR: | 473 case MimeUtil::MPEG2_AAC_SSR: |
| 470 // MPEG-2 variants of AAC are not supported on Android. | 474 // MPEG-2 variants of AAC are not supported on Android. |
| 471 return false; | 475 return false; |
| 472 | 476 |
| 473 case MimeUtil::VP9: | 477 case MimeUtil::VP9: |
| 474 // VP9 is supported only in KitKat+ (API Level 19). | 478 // VP9 is supported only in KitKat+ (API Level 19). |
| 475 return base::android::BuildInfo::GetInstance()->sdk_int() >= 19; | 479 return base::android::BuildInfo::GetInstance()->sdk_int() >= 19; |
| 476 | 480 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 515 // compatibility) | 519 // compatibility) |
| 516 // mp4a.40.29 - MPEG-4 HE-AAC v2 (AAC LC + SBR + PS) | 520 // mp4a.40.29 - MPEG-4 HE-AAC v2 (AAC LC + SBR + PS) |
| 517 // | 521 // |
| 518 // avc1.42E0xx - H.264 Baseline | 522 // avc1.42E0xx - H.264 Baseline |
| 519 // avc1.4D40xx - H.264 Main | 523 // avc1.4D40xx - H.264 Main |
| 520 // avc1.6400xx - H.264 High | 524 // avc1.6400xx - H.264 High |
| 521 static const char kMP4AudioCodecsExpression[] = | 525 static const char kMP4AudioCodecsExpression[] = |
| 522 "mp4a.66,mp4a.67,mp4a.68,mp4a.69,mp4a.6B,mp4a.40.2,mp4a.40.02,mp4a.40.5," | 526 "mp4a.66,mp4a.67,mp4a.68,mp4a.69,mp4a.6B,mp4a.40.2,mp4a.40.02,mp4a.40.5," |
| 523 "mp4a.40.05,mp4a.40.29"; | 527 "mp4a.40.05,mp4a.40.29"; |
| 524 static const char kMP4VideoCodecsExpression[] = | 528 static const char kMP4VideoCodecsExpression[] = |
| 525 "avc1.42E00A,avc1.4D400A,avc1.64000A," | 529 "avc1.42E00A,avc1.4D400A,avc1.64000A,hev1,hvc1," |
| 526 "mp4a.66,mp4a.67,mp4a.68,mp4a.69,mp4a.6B,mp4a.40.2,mp4a.40.02,mp4a.40.5," | 530 "mp4a.66,mp4a.67,mp4a.68,mp4a.69,mp4a.6B,mp4a.40.2,mp4a.40.02,mp4a.40.5," |
| 527 "mp4a.40.05,mp4a.40.29"; | 531 "mp4a.40.05,mp4a.40.29"; |
| 528 | 532 |
| 529 static const MediaFormatStrict format_codec_mappings[] = { | 533 static const MediaFormatStrict format_codec_mappings[] = { |
| 530 { "video/webm", "opus,vorbis,vp8,vp8.0,vp9,vp9.0" }, | 534 { "video/webm", "opus,vorbis,vp8,vp8.0,vp9,vp9.0" }, |
| 531 { "audio/webm", "opus,vorbis" }, | 535 { "audio/webm", "opus,vorbis" }, |
| 532 { "audio/wav", "1" }, | 536 { "audio/wav", "1" }, |
| 533 { "audio/x-wav", "1" }, | 537 { "audio/x-wav", "1" }, |
| 534 { "video/ogg", "opus,theora,vorbis" }, | 538 { "video/ogg", "opus,theora,vorbis" }, |
| 535 { "audio/ogg", "opus,vorbis" }, | 539 { "audio/ogg", "opus,vorbis" }, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 549 const char* const codec_id; | 553 const char* const codec_id; |
| 550 MimeUtil::Codec codec; | 554 MimeUtil::Codec codec; |
| 551 }; | 555 }; |
| 552 | 556 |
| 553 // List of codec IDs that provide enough information to determine the | 557 // List of codec IDs that provide enough information to determine the |
| 554 // codec and profile being requested. | 558 // codec and profile being requested. |
| 555 // | 559 // |
| 556 // The "mp4a" strings come from RFC 6381. | 560 // The "mp4a" strings come from RFC 6381. |
| 557 static const CodecIDMappings kUnambiguousCodecIDs[] = { | 561 static const CodecIDMappings kUnambiguousCodecIDs[] = { |
| 558 {"1", MimeUtil::PCM}, // We only allow this for WAV so it isn't ambiguous. | 562 {"1", MimeUtil::PCM}, // We only allow this for WAV so it isn't ambiguous. |
| 563 #if defined(ENABLE_HEVC_DEMUXING) |
| 564 {"hev1", MimeUtil::HEVC_MAIN}, |
| 565 {"hvc1", MimeUtil::HEVC_MAIN}, |
| 566 #endif |
| 559 {"mp3", MimeUtil::MP3}, | 567 {"mp3", MimeUtil::MP3}, |
| 560 {"mp4a.66", MimeUtil::MPEG2_AAC_MAIN}, | 568 {"mp4a.66", MimeUtil::MPEG2_AAC_MAIN}, |
| 561 {"mp4a.67", MimeUtil::MPEG2_AAC_LC}, | 569 {"mp4a.67", MimeUtil::MPEG2_AAC_LC}, |
| 562 {"mp4a.68", MimeUtil::MPEG2_AAC_SSR}, | 570 {"mp4a.68", MimeUtil::MPEG2_AAC_SSR}, |
| 563 {"mp4a.69", MimeUtil::MP3}, | 571 {"mp4a.69", MimeUtil::MP3}, |
| 564 {"mp4a.6B", MimeUtil::MP3}, | 572 {"mp4a.6B", MimeUtil::MP3}, |
| 565 {"mp4a.40.2", MimeUtil::MPEG4_AAC_LC}, | 573 {"mp4a.40.2", MimeUtil::MPEG4_AAC_LC}, |
| 566 {"mp4a.40.02", MimeUtil::MPEG4_AAC_LC}, | 574 {"mp4a.40.02", MimeUtil::MPEG4_AAC_LC}, |
| 567 {"mp4a.40.5", MimeUtil::MPEG4_AAC_SBR_v1}, | 575 {"mp4a.40.5", MimeUtil::MPEG4_AAC_SBR_v1}, |
| 568 {"mp4a.40.05", MimeUtil::MPEG4_AAC_SBR_v1}, | 576 {"mp4a.40.05", MimeUtil::MPEG4_AAC_SBR_v1}, |
| (...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1001 Codec* codec, | 1009 Codec* codec, |
| 1002 bool* is_ambiguous) const { | 1010 bool* is_ambiguous) const { |
| 1003 StringToCodecMappings::const_iterator itr = | 1011 StringToCodecMappings::const_iterator itr = |
| 1004 string_to_codec_map_.find(codec_id); | 1012 string_to_codec_map_.find(codec_id); |
| 1005 if (itr != string_to_codec_map_.end()) { | 1013 if (itr != string_to_codec_map_.end()) { |
| 1006 *codec = itr->second.codec; | 1014 *codec = itr->second.codec; |
| 1007 *is_ambiguous = itr->second.is_ambiguous; | 1015 *is_ambiguous = itr->second.is_ambiguous; |
| 1008 return true; | 1016 return true; |
| 1009 } | 1017 } |
| 1010 | 1018 |
| 1019 #if defined(ENABLE_HEVC_DEMUXING) |
| 1020 if (StartsWithASCII(codec_id, "hev1.", true) || |
| 1021 StartsWithASCII(codec_id, "hvc1.", true)) { |
| 1022 // TODO(servolk): Implement parsing of hevc codec ids as described in |
| 1023 // ETSI TS 126 244 standard section A.2.2, but for now allow any |
| 1024 // HEVC tiers/profiles and let decoder decide if it can handle that. |
| 1025 *codec = MimeUtil::HEVC_MAIN; |
| 1026 *is_ambiguous = false; |
| 1027 return true; |
| 1028 } |
| 1029 #endif |
| 1030 |
| 1011 // If |codec_id| is not in |string_to_codec_map_|, then we assume that it is | 1031 // If |codec_id| is not in |string_to_codec_map_|, then we assume that it is |
| 1012 // an H.264 codec ID because currently those are the only ones that can't be | 1032 // an H.264 codec ID because currently those are the only ones that can't be |
| 1013 // stored in the |string_to_codec_map_| and require parsing. | 1033 // stored in the |string_to_codec_map_| and require parsing. |
| 1014 return ParseH264CodecID(codec_id, codec, is_ambiguous); | 1034 return ParseH264CodecID(codec_id, codec, is_ambiguous); |
| 1015 } | 1035 } |
| 1016 | 1036 |
| 1017 bool MimeUtil::IsCodecSupported(Codec codec) const { | 1037 bool MimeUtil::IsCodecSupported(Codec codec) const { |
| 1018 DCHECK_NE(codec, INVALID_CODEC); | 1038 DCHECK_NE(codec, INVALID_CODEC); |
| 1019 | 1039 |
| 1020 #if defined(OS_ANDROID) | 1040 #if defined(OS_ANDROID) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1031 case MP3: | 1051 case MP3: |
| 1032 case MPEG2_AAC_LC: | 1052 case MPEG2_AAC_LC: |
| 1033 case MPEG2_AAC_MAIN: | 1053 case MPEG2_AAC_MAIN: |
| 1034 case MPEG2_AAC_SSR: | 1054 case MPEG2_AAC_SSR: |
| 1035 case MPEG4_AAC_LC: | 1055 case MPEG4_AAC_LC: |
| 1036 case MPEG4_AAC_SBR_v1: | 1056 case MPEG4_AAC_SBR_v1: |
| 1037 case MPEG4_AAC_SBR_PS_v2: | 1057 case MPEG4_AAC_SBR_PS_v2: |
| 1038 case H264_BASELINE: | 1058 case H264_BASELINE: |
| 1039 case H264_MAIN: | 1059 case H264_MAIN: |
| 1040 case H264_HIGH: | 1060 case H264_HIGH: |
| 1061 case HEVC_MAIN: |
| 1041 return true; | 1062 return true; |
| 1042 | 1063 |
| 1043 case PCM: | 1064 case PCM: |
| 1044 case VORBIS: | 1065 case VORBIS: |
| 1045 case OPUS: | 1066 case OPUS: |
| 1046 case VP8: | 1067 case VP8: |
| 1047 case VP9: | 1068 case VP9: |
| 1048 case THEORA: | 1069 case THEORA: |
| 1049 return false; | 1070 return false; |
| 1050 } | 1071 } |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1379 post_data->append("\r\n" + value + "\r\n"); | 1400 post_data->append("\r\n" + value + "\r\n"); |
| 1380 } | 1401 } |
| 1381 | 1402 |
| 1382 void AddMultipartFinalDelimiterForUpload(const std::string& mime_boundary, | 1403 void AddMultipartFinalDelimiterForUpload(const std::string& mime_boundary, |
| 1383 std::string* post_data) { | 1404 std::string* post_data) { |
| 1384 DCHECK(post_data); | 1405 DCHECK(post_data); |
| 1385 post_data->append("--" + mime_boundary + "--\r\n"); | 1406 post_data->append("--" + mime_boundary + "--\r\n"); |
| 1386 } | 1407 } |
| 1387 | 1408 |
| 1388 } // namespace net | 1409 } // namespace net |
| OLD | NEW |