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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
86 SupportsType IsSupportedStrictMediaMimeType( | 86 SupportsType IsSupportedStrictMediaMimeType( |
87 const std::string& mime_type, | 87 const std::string& mime_type, |
88 const std::vector<std::string>& codecs) const; | 88 const std::vector<std::string>& codecs) const; |
89 | 89 |
90 void RemoveProprietaryMediaTypesAndCodecsForTests(); | 90 void RemoveProprietaryMediaTypesAndCodecsForTests(); |
91 | 91 |
92 private: | 92 private: |
93 friend struct base::DefaultLazyInstanceTraits<MimeUtil>; | 93 friend struct base::DefaultLazyInstanceTraits<MimeUtil>; |
94 | 94 |
95 typedef base::hash_set<std::string> MimeMappings; | 95 typedef base::hash_set<std::string> MimeMappings; |
96 typedef std::map<std::string, MimeMappings> StrictMappings; | |
97 | 96 |
98 typedef std::vector<std::string> MimeExpressionMappings; | 97 typedef std::vector<std::string> MimeExpressionMappings; |
99 typedef std::map<std::string, MimeExpressionMappings> | 98 typedef std::map<std::string, MimeExpressionMappings> |
100 StrictExpressionMappings; | 99 StrictExpressionMappings; |
101 | 100 |
102 MimeUtil(); | 101 MimeUtil(); |
103 | 102 |
104 // Returns true if |codecs| is nonempty and all the items in it are present in | 103 // Returns true if |codecs| is nonempty and all the items in it are present in |
105 // |supported_codecs|. | 104 // |supported_codecs|. |
106 static bool AreSupportedCodecs(const MimeMappings& supported_codecs, | 105 static bool AreSupportedCodecs(const MimeExpressionMappings& supported_codecs, |
107 const std::vector<std::string>& codecs); | 106 const std::vector<std::string>& codecs); |
108 // Returns true is |codecs| is nonempty and all the items in it match with the | |
109 // codecs expression in |supported_codecs|. | |
110 static bool AreSupportedCodecsWithProfile( | |
111 const MimeExpressionMappings& supported_codecs, | |
112 const std::vector<std::string>& codecs); | |
113 | 107 |
114 // For faster lookup, keep hash sets. | 108 // For faster lookup, keep hash sets. |
115 void InitializeMimeTypeMaps(); | 109 void InitializeMimeTypeMaps(); |
116 | 110 |
117 bool GetMimeTypeFromExtensionHelper(const base::FilePath::StringType& ext, | 111 bool GetMimeTypeFromExtensionHelper(const base::FilePath::StringType& ext, |
118 bool include_platform_types, | 112 bool include_platform_types, |
119 std::string* mime_type) const; | 113 std::string* mime_type) const; |
120 | 114 |
121 MimeMappings image_map_; | 115 MimeMappings image_map_; |
122 MimeMappings media_map_; | 116 MimeMappings media_map_; |
123 MimeMappings non_image_map_; | 117 MimeMappings non_image_map_; |
124 MimeMappings unsupported_text_map_; | 118 MimeMappings unsupported_text_map_; |
125 MimeMappings javascript_map_; | 119 MimeMappings javascript_map_; |
126 MimeMappings codecs_map_; | 120 MimeExpressionMappings codecs_map_; |
127 | 121 |
128 // A map of mime_types and hash map of the supported codecs for the mime_type. | 122 // A map of mime_types and hash map of the supported codecs for the mime_type. |
129 StrictMappings strict_format_map_; | 123 StrictExpressionMappings strict_format_map_; |
130 // A map of MP4 mime_types which expect codecs with profile parameter and | 124 // A map of MP4 mime_types which expect codecs with profile parameter and |
acolwell GONE FROM CHROMIUM
2014/06/30 20:00:06
nit: I think the comment needs updating since the
| |
131 // vector of supported codecs expressions for the mime_type. | 125 // vector of supported codecs expressions for the mime_type. |
132 StrictExpressionMappings strict_mp4_format_map_; | 126 StrictExpressionMappings inconclusive_format_map_; |
133 }; // class MimeUtil | 127 }; // class MimeUtil |
134 | 128 |
135 // This variable is Leaky because we need to access it from WorkerPool threads. | 129 // This variable is Leaky because we need to access it from WorkerPool threads. |
136 static base::LazyInstance<MimeUtil>::Leaky g_mime_util = | 130 static base::LazyInstance<MimeUtil>::Leaky g_mime_util = |
137 LAZY_INSTANCE_INITIALIZER; | 131 LAZY_INSTANCE_INITIALIZER; |
138 | 132 |
139 struct MimeInfo { | 133 struct MimeInfo { |
140 const char* mime_type; | 134 const char* mime_type; |
141 const char* extensions; // comma separated list | 135 const char* extensions; // comma separated list |
142 }; | 136 }; |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
436 return false; | 430 return false; |
437 | 431 |
438 // VP9 is supported only in KitKat+ (API Level 19). | 432 // VP9 is supported only in KitKat+ (API Level 19). |
439 if ((!codec.compare("vp9") || !codec.compare("vp9.0")) && | 433 if ((!codec.compare("vp9") || !codec.compare("vp9.0")) && |
440 base::android::BuildInfo::GetInstance()->sdk_int() < 19) { | 434 base::android::BuildInfo::GetInstance()->sdk_int() < 19) { |
441 return false; | 435 return false; |
442 } | 436 } |
443 | 437 |
444 // TODO(vigneshv): Change this similar to the VP9 check once Opus is | 438 // TODO(vigneshv): Change this similar to the VP9 check once Opus is |
445 // supported on Android (http://crbug.com/318436). | 439 // supported on Android (http://crbug.com/318436). |
446 if (!codec.compare("opus")) { | 440 if (!codec.compare("opus")) |
441 return false; | |
442 | |
443 // MPEG-2 AAC is not supported on Android | |
444 if (!codec.compare("mp4a.67")) | |
445 return false; | |
446 | |
447 // H.264 Main and High profiles are not supported on Android | |
448 if (!codec.compare("avc1.4d40??") || !codec.compare("avc1.4D40??") || | |
449 !codec.compare("avc1.6400??")) { | |
447 return false; | 450 return false; |
448 } | 451 } |
452 | |
449 return true; | 453 return true; |
450 } | 454 } |
451 | 455 |
452 static bool IsMimeTypeSupportedOnAndroid(const std::string& mimeType) { | 456 static bool IsMimeTypeSupportedOnAndroid(const std::string& mimeType) { |
453 // HLS codecs are supported in ICS and above (API level 14) | 457 // HLS codecs are supported in ICS and above (API level 14) |
454 if ((!mimeType.compare("application/vnd.apple.mpegurl") || | 458 if ((!mimeType.compare("application/vnd.apple.mpegurl") || |
455 !mimeType.compare("application/x-mpegurl")) && | 459 !mimeType.compare("application/x-mpegurl")) && |
456 base::android::BuildInfo::GetInstance()->sdk_int() < 14) { | 460 base::android::BuildInfo::GetInstance()->sdk_int() < 14) { |
457 return false; | 461 return false; |
458 } | 462 } |
459 return true; | 463 return true; |
460 } | 464 } |
461 #endif | 465 #endif |
462 | 466 |
463 struct MediaFormatStrict { | 467 struct MediaFormatStrict { |
464 const char* mime_type; | 468 const char* mime_type; |
465 const char* codecs_list; | 469 const char* codecs_list; |
466 }; | 470 }; |
467 | 471 |
468 static const MediaFormatStrict format_codec_mappings[] = { | |
469 { "video/webm", "opus,vorbis,vp8,vp8.0,vp9,vp9.0" }, | |
470 { "audio/webm", "opus,vorbis" }, | |
471 { "audio/wav", "1" }, | |
472 { "audio/x-wav", "1" }, | |
473 { "video/ogg", "opus,theora,vorbis" }, | |
474 { "audio/ogg", "opus,vorbis" }, | |
475 { "application/ogg", "opus,theora,vorbis" }, | |
476 { "audio/mpeg", "" }, | |
477 { "audio/mp3", "" }, | |
478 { "audio/x-mp3", "" } | |
479 }; | |
480 | |
481 // Following is the list of RFC 6381 compliant codecs: | 472 // Following is the list of RFC 6381 compliant codecs: |
482 // mp4a.6B - MPEG-1 audio | 473 // mp4a.6B - MPEG-1 audio |
483 // mp4a.69 - MPEG-2 extension to MPEG-1 | 474 // mp4a.69 - MPEG-2 extension to MPEG-1 |
484 // mp4a.67 - MPEG-2 AAC | 475 // mp4a.67 - MPEG-2 AAC |
485 // mp4a.40.2 - MPEG-4 AAC | 476 // mp4a.40.2 - MPEG-4 AAC |
486 // mp4a.40.5 - MPEG-4 HE-AAC | 477 // mp4a.40.5 - MPEG-4 HE-AACv1 |
478 // mp4a.40.29 - MPEG-4 HE-AACv2 | |
acolwell GONE FROM CHROMIUM
2014/06/30 20:00:07
This should be added in a different CL. This is a
amogh.bihani
2014/07/01 12:53:57
Oh Ok! Becuase of what was reported in Bug 387604,
acolwell GONE FROM CHROMIUM
2014/07/01 17:28:16
It will eventually, but that should be as part of
| |
487 // | 479 // |
488 // avc1.42E0xx - H.264 Baseline | 480 // avc1.42E0xx - H.264 Baseline |
489 // avc1.4D40xx - H.264 Main | 481 // avc1.4D40xx - H.264 Main |
490 // avc1.6400xx - H.264 High | 482 // avc1.6400xx - H.264 High |
491 // | 483 // |
484 // FIXME(amogh.bihani): Find out the profile parameters for avc3 and support | |
485 // only them, just like avc1. | |
acolwell GONE FROM CHROMIUM
2014/06/30 20:00:07
avc3 is the same as avc1. The only difference is t
| |
486 static const char kProprietaryAudioCodecsExpression[] = | |
487 "mp4a.6B,mp4a.69,mp4a.67,mp4a.40.2,mp4a.40.5,mp4a.40.29"; | |
acolwell GONE FROM CHROMIUM
2014/06/30 20:00:06
remove mp4a.40.29 here and below. It should be add
| |
488 static const char kProprietaryCodecsExpression[] = | |
489 "avc1.42E0??,avc1.42e0??,avc1.4D40??,avc1.4d40??,avc1.6400??,avc3.??????," | |
490 "mp4a.6B,mp4a.69,mp4a.67,mp4a.40.2,mp4a.40.5,mp4a.40.29"; | |
491 | |
492 static const MediaFormatStrict format_codec_mappings[] = { | |
493 {"video/webm", "opus,vorbis,vp8,vp8.0,vp9,vp9.0"}, | |
494 {"audio/webm", "opus,vorbis"}, | |
495 {"audio/wav", "1"}, | |
496 {"audio/x-wav", "1"}, | |
497 {"video/ogg", "opus,theora,vorbis"}, | |
498 {"audio/ogg", "opus,vorbis"}, | |
499 {"application/ogg", "opus,theora,vorbis"}, | |
500 {"audio/mpeg", ""}, | |
501 {"audio/mp3", ""}, | |
502 {"audio/x-mp3", ""}, | |
503 {"audio/mp4", kProprietaryAudioCodecsExpression}, | |
504 {"audio/x-m4a", kProprietaryAudioCodecsExpression}, | |
505 {"video/mp4", kProprietaryCodecsExpression}, | |
506 {"video/x-m4v", kProprietaryCodecsExpression}, | |
507 {"application/x-mpegurl", kProprietaryCodecsExpression}, | |
508 {"application/vnd.apple.mpegurl", kProprietaryCodecsExpression} | |
509 }; | |
510 | |
511 // Following is the list of codecs that are RFC 6381 compliant but browser | |
512 // cannot be sure whether the platform supports them or not | |
513 // mp4a.40 | |
514 // avc1 | |
515 // avc3 | |
516 // | |
492 // Additionally, several non-RFC compliant codecs are allowed, due to their | 517 // Additionally, several non-RFC compliant codecs are allowed, due to their |
493 // existing use on web. | 518 // existing use on web. |
494 // mp4a.40 | |
495 // avc1.xxxxxx | 519 // avc1.xxxxxx |
496 // avc3.xxxxxx | 520 // avc3.xxxxxx |
497 // mp4a.6x | 521 // mp4a.6x |
498 static const char kProprietaryAudioCodecsExpression[] = | 522 // |
499 "mp4a.6?,mp4a.40,mp4a.40.?"; | 523 // TODO(amogh.bihani): Add avc3.?????? to the 'inconclusive' list when exact |
500 static const char kProprietaryCodecsExpression[] = | 524 // profile parameters for avc3 are found and it is removed from |
501 "avc1,avc3,avc1.??????,avc3.??????,mp4a.6?,mp4a.40,mp4a.40.?"; | 525 // kProprietaryCodecsExpression list. |
526 static const char kInconclusiveProprietaryAudioCodecsExpression[] = | |
527 "mp4a.6?,mp4a.40"; | |
acolwell GONE FROM CHROMIUM
2014/06/30 20:00:07
Why do we want mp4a.6? ? 66,68 are the only 2 othe
| |
528 static const char kInconclusiveProprietaryCodecsExpression[] = | |
529 "avc1,avc1.??????,avc3,mp4a.6?,mp4a.40"; | |
502 | 530 |
503 static const MediaFormatStrict format_mp4_codec_mappings[] = { | 531 static const MediaFormatStrict format_inconclusive_codec_mappings[] = { |
504 { "audio/mp4", kProprietaryAudioCodecsExpression }, | 532 {"audio/mp4", kInconclusiveProprietaryAudioCodecsExpression}, |
505 { "audio/x-m4a", kProprietaryAudioCodecsExpression }, | 533 {"audio/x-m4a", kInconclusiveProprietaryAudioCodecsExpression}, |
506 { "video/mp4", kProprietaryCodecsExpression }, | 534 {"video/mp4", kInconclusiveProprietaryCodecsExpression}, |
507 { "video/x-m4v", kProprietaryCodecsExpression }, | 535 {"video/x-m4v", kInconclusiveProprietaryCodecsExpression}, |
508 { "application/x-mpegurl", kProprietaryCodecsExpression }, | 536 {"application/x-mpegurl", kInconclusiveProprietaryCodecsExpression}, |
509 { "application/vnd.apple.mpegurl", kProprietaryCodecsExpression } | 537 {"application/vnd.apple.mpegurl", kInconclusiveProprietaryCodecsExpression} |
510 }; | 538 }; |
511 | 539 |
512 MimeUtil::MimeUtil() { | 540 MimeUtil::MimeUtil() { |
513 InitializeMimeTypeMaps(); | 541 InitializeMimeTypeMaps(); |
514 } | 542 } |
515 | 543 |
516 // static | 544 // static |
517 bool MimeUtil::AreSupportedCodecs(const MimeMappings& supported_codecs, | 545 // Checks all the codecs present in the |codecs| against the entries in |
518 const std::vector<std::string>& codecs) { | 546 // |supported_codecs|. Returns true only if |codecs| is non-empty and all the |
547 // codecs match |supported_codecs| expressions. | |
548 bool MimeUtil::AreSupportedCodecs( | |
549 const MimeExpressionMappings& supported_codecs, | |
550 const std::vector<std::string>& codecs) { | |
519 if (supported_codecs.empty()) | 551 if (supported_codecs.empty()) |
520 return codecs.empty(); | 552 return codecs.empty(); |
521 | 553 |
522 for (size_t i = 0; i < codecs.size(); ++i) { | 554 for (size_t i = 0; i < codecs.size(); ++i) { |
523 if (supported_codecs.find(codecs[i]) == supported_codecs.end()) | |
524 return false; | |
525 } | |
526 return !codecs.empty(); | |
527 } | |
528 | |
529 // Checks all the codecs present in the |codecs| against the entries in | |
530 // |supported_codecs|. Returns true only if |codecs| is non-empty and all the | |
531 // codecs match |supported_codecs| expressions. | |
532 bool MimeUtil::AreSupportedCodecsWithProfile( | |
533 const MimeExpressionMappings& supported_codecs, | |
534 const std::vector<std::string>& codecs) { | |
535 DCHECK(!supported_codecs.empty()); | |
536 for (size_t i = 0; i < codecs.size(); ++i) { | |
537 bool codec_matched = false; | 555 bool codec_matched = false; |
538 for (size_t j = 0; j < supported_codecs.size(); ++j) { | 556 for (size_t j = 0; j < supported_codecs.size(); ++j) { |
539 if (!MatchPattern(base::StringPiece(codecs[i]), | 557 if (!MatchPattern(base::StringPiece(codecs[i]), |
540 base::StringPiece(supported_codecs[j]))) { | 558 base::StringPiece(supported_codecs[j]))) { |
541 continue; | 559 continue; |
542 } | 560 } |
543 // If suffix exists, check whether it is hexadecimal. | 561 // If suffix exists, check whether it is hexadecimal. |
544 for (size_t wildcard_pos = supported_codecs[j].find('?'); | 562 for (size_t wildcard_pos = supported_codecs[j].find('?'); |
545 wildcard_pos != std::string::npos && | 563 wildcard_pos != std::string::npos && |
546 wildcard_pos < supported_codecs[j].length(); | 564 wildcard_pos < supported_codecs[j].length(); |
547 wildcard_pos = supported_codecs[j].find('?', wildcard_pos + 1)) { | 565 wildcard_pos = supported_codecs[j].find('?', wildcard_pos + 1)) { |
548 // Don't enforce case sensitivity, even though it's called for, as it | 566 // Don't enforce case sensitivity, even though it's called for, as it |
549 // would break some websites. | 567 // would break some websites. |
550 if (wildcard_pos >= codecs[i].length() || | 568 if (wildcard_pos >= codecs[i].length() || |
551 !IsHexDigit(codecs[i].at(wildcard_pos))) { | 569 !IsHexDigit(codecs[i].at(wildcard_pos))) { |
552 return false; | 570 return false; |
553 } | 571 } |
554 } | 572 } |
555 codec_matched = true; | 573 codec_matched = true; |
556 break; | 574 break; |
557 } | 575 } |
558 if (!codec_matched) | 576 if (!codec_matched) |
559 return false; | 577 return false; |
560 } | 578 } |
579 | |
561 return !codecs.empty(); | 580 return !codecs.empty(); |
562 } | 581 } |
563 | 582 |
564 void MimeUtil::InitializeMimeTypeMaps() { | 583 void MimeUtil::InitializeMimeTypeMaps() { |
565 for (size_t i = 0; i < arraysize(supported_image_types); ++i) | 584 for (size_t i = 0; i < arraysize(supported_image_types); ++i) |
566 image_map_.insert(supported_image_types[i]); | 585 image_map_.insert(supported_image_types[i]); |
567 | 586 |
568 // Initialize the supported non-image types. | 587 // Initialize the supported non-image types. |
569 for (size_t i = 0; i < arraysize(supported_non_image_types); ++i) | 588 for (size_t i = 0; i < arraysize(supported_non_image_types); ++i) |
570 non_image_map_.insert(supported_non_image_types[i]); | 589 non_image_map_.insert(supported_non_image_types[i]); |
(...skipping 29 matching lines...) Expand all Loading... | |
600 #endif | 619 #endif |
601 | 620 |
602 for (size_t i = 0; i < arraysize(supported_javascript_types); ++i) | 621 for (size_t i = 0; i < arraysize(supported_javascript_types); ++i) |
603 javascript_map_.insert(supported_javascript_types[i]); | 622 javascript_map_.insert(supported_javascript_types[i]); |
604 | 623 |
605 for (size_t i = 0; i < arraysize(common_media_codecs); ++i) { | 624 for (size_t i = 0; i < arraysize(common_media_codecs); ++i) { |
606 #if defined(OS_ANDROID) | 625 #if defined(OS_ANDROID) |
607 if (!IsCodecSupportedOnAndroid(common_media_codecs[i])) | 626 if (!IsCodecSupportedOnAndroid(common_media_codecs[i])) |
608 continue; | 627 continue; |
609 #endif | 628 #endif |
610 codecs_map_.insert(common_media_codecs[i]); | 629 codecs_map_.push_back(common_media_codecs[i]); |
611 } | 630 } |
612 #if defined(USE_PROPRIETARY_CODECS) | 631 #if defined(USE_PROPRIETARY_CODECS) |
613 for (size_t i = 0; i < arraysize(proprietary_media_codecs); ++i) | 632 for (size_t i = 0; i < arraysize(proprietary_media_codecs); ++i) |
614 codecs_map_.insert(proprietary_media_codecs[i]); | 633 codecs_map_.push_back(proprietary_media_codecs[i]); |
615 #endif | 634 #endif |
616 | 635 |
617 // Initialize the strict supported media types. | 636 // Initialize the strict supported media types. |
618 for (size_t i = 0; i < arraysize(format_codec_mappings); ++i) { | 637 for (size_t i = 0; i < arraysize(format_codec_mappings); ++i) { |
619 std::vector<std::string> mime_type_codecs; | 638 std::vector<std::string> mime_type_codecs; |
620 ParseCodecString(format_codec_mappings[i].codecs_list, | 639 ParseCodecString(format_codec_mappings[i].codecs_list, |
621 &mime_type_codecs, | 640 &mime_type_codecs, |
622 false); | 641 false); |
623 | 642 |
624 MimeMappings codecs; | 643 MimeExpressionMappings codecs; |
625 for (size_t j = 0; j < mime_type_codecs.size(); ++j) { | 644 for (size_t j = 0; j < mime_type_codecs.size(); ++j) { |
626 #if defined(OS_ANDROID) | 645 #if defined(OS_ANDROID) |
627 if (!IsCodecSupportedOnAndroid(mime_type_codecs[j])) | 646 if (!IsCodecSupportedOnAndroid(mime_type_codecs[j])) |
628 continue; | 647 continue; |
629 #endif | 648 #endif |
630 codecs.insert(mime_type_codecs[j]); | 649 codecs.push_back(mime_type_codecs[j]); |
631 } | 650 } |
632 strict_format_map_[format_codec_mappings[i].mime_type] = codecs; | 651 strict_format_map_[format_codec_mappings[i].mime_type] = codecs; |
633 } | 652 } |
634 for (size_t i = 0; i < arraysize(format_mp4_codec_mappings); ++i) { | 653 for (size_t i = 0; i < arraysize(format_inconclusive_codec_mappings); ++i) { |
635 std::vector<std::string> mime_type_codecs; | 654 std::vector<std::string> mime_type_codecs; |
636 ParseCodecString( | 655 ParseCodecString( |
637 format_mp4_codec_mappings[i].codecs_list, &mime_type_codecs, false); | 656 format_inconclusive_codec_mappings[i].codecs_list, &mime_type_codecs, |
657 false); | |
638 | 658 |
639 MimeExpressionMappings codecs; | 659 MimeExpressionMappings codecs; |
640 for (size_t j = 0; j < mime_type_codecs.size(); ++j) | 660 for (size_t j = 0; j < mime_type_codecs.size(); ++j) { |
661 #if defined(OS_ANDROID) | |
662 if (!IsCodecSupportedOnAndroid(mime_type_codecs[j])) | |
663 continue; | |
664 #endif | |
641 codecs.push_back(mime_type_codecs[j]); | 665 codecs.push_back(mime_type_codecs[j]); |
642 strict_mp4_format_map_[format_mp4_codec_mappings[i].mime_type] = codecs; | 666 } |
667 // Merge codecs from conclusive list into inconclusive list so that querries | |
668 // with one conclusive and one inconclusive codec do not get an empty | |
669 // string in reply. | |
670 StrictExpressionMappings::const_iterator it = strict_format_map_.find( | |
671 format_inconclusive_codec_mappings[i].mime_type); | |
672 codecs.insert(codecs.end(), it->second.begin(), it->second.end()); | |
acolwell GONE FROM CHROMIUM
2014/06/30 20:00:06
Don't you need to protect this with a (it != stric
| |
673 inconclusive_format_map_[format_inconclusive_codec_mappings[i].mime_type] = | |
674 codecs; | |
643 } | 675 } |
644 } | 676 } |
645 | 677 |
646 bool MimeUtil::IsSupportedImageMimeType(const std::string& mime_type) const { | 678 bool MimeUtil::IsSupportedImageMimeType(const std::string& mime_type) const { |
647 return image_map_.find(mime_type) != image_map_.end(); | 679 return image_map_.find(mime_type) != image_map_.end(); |
648 } | 680 } |
649 | 681 |
650 bool MimeUtil::IsSupportedMediaMimeType(const std::string& mime_type) const { | 682 bool MimeUtil::IsSupportedMediaMimeType(const std::string& mime_type) const { |
651 return media_map_.find(mime_type) != media_map_.end(); | 683 return media_map_.find(mime_type) != media_map_.end(); |
652 } | 684 } |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
814 for (std::vector<std::string>::iterator it = codecs_out->begin(); | 846 for (std::vector<std::string>::iterator it = codecs_out->begin(); |
815 it != codecs_out->end(); | 847 it != codecs_out->end(); |
816 ++it) { | 848 ++it) { |
817 size_t found = it->find_first_of('.'); | 849 size_t found = it->find_first_of('.'); |
818 if (found != std::string::npos) | 850 if (found != std::string::npos) |
819 it->resize(found); | 851 it->resize(found); |
820 } | 852 } |
821 } | 853 } |
822 | 854 |
823 bool MimeUtil::IsStrictMediaMimeType(const std::string& mime_type) const { | 855 bool MimeUtil::IsStrictMediaMimeType(const std::string& mime_type) const { |
824 if (strict_format_map_.find(mime_type) == strict_format_map_.end() && | 856 if (strict_format_map_.find(mime_type) == strict_format_map_.end()) |
825 strict_mp4_format_map_.find(mime_type) == strict_mp4_format_map_.end()) | |
826 return false; | 857 return false; |
827 return true; | 858 return true; |
828 } | 859 } |
829 | 860 |
830 SupportsType MimeUtil::IsSupportedStrictMediaMimeType( | 861 SupportsType MimeUtil::IsSupportedStrictMediaMimeType( |
831 const std::string& mime_type, | 862 const std::string& mime_type, |
832 const std::vector<std::string>& codecs) const { | 863 const std::vector<std::string>& codecs) const { |
833 StrictMappings::const_iterator it_strict_map = | 864 StrictExpressionMappings::const_iterator it_strict_map = |
834 strict_format_map_.find(mime_type); | 865 strict_format_map_.find(mime_type); |
835 if ((it_strict_map != strict_format_map_.end()) && | 866 if ((it_strict_map != strict_format_map_.end()) && |
836 AreSupportedCodecs(it_strict_map->second, codecs)) { | 867 AreSupportedCodecs(it_strict_map->second, codecs)) { |
837 return IsSupported; | 868 return IsSupported; |
838 } | 869 } |
839 | 870 |
840 StrictExpressionMappings::const_iterator it_expression_map = | 871 StrictExpressionMappings::const_iterator it_expression_map = |
841 strict_mp4_format_map_.find(mime_type); | 872 inconclusive_format_map_.find(mime_type); |
842 if ((it_expression_map != strict_mp4_format_map_.end()) && | 873 if ((it_expression_map != inconclusive_format_map_.end()) && |
843 AreSupportedCodecsWithProfile(it_expression_map->second, codecs)) { | 874 AreSupportedCodecs(it_expression_map->second, codecs)) { |
844 return MayBeSupported; | 875 return MayBeSupported; |
845 } | 876 } |
846 | 877 |
847 if (codecs.empty()) | 878 if (codecs.empty()) |
848 return MayBeSupported; | 879 return MayBeSupported; |
849 | 880 |
850 return IsNotSupported; | 881 return IsNotSupported; |
851 } | 882 } |
852 | 883 |
853 void MimeUtil::RemoveProprietaryMediaTypesAndCodecsForTests() { | 884 void MimeUtil::RemoveProprietaryMediaTypesAndCodecsForTests() { |
854 for (size_t i = 0; i < arraysize(proprietary_media_types); ++i) { | 885 for (size_t i = 0; i < arraysize(proprietary_media_types); ++i) { |
855 non_image_map_.erase(proprietary_media_types[i]); | 886 non_image_map_.erase(proprietary_media_types[i]); |
856 media_map_.erase(proprietary_media_types[i]); | 887 media_map_.erase(proprietary_media_types[i]); |
857 } | 888 } |
858 for (size_t i = 0; i < arraysize(proprietary_media_codecs); ++i) | 889 if (codecs_map_.size() == |
acolwell GONE FROM CHROMIUM
2014/06/30 20:00:06
This looks REALLY brittle. Why can't you just stic
amogh.bihani
2014/07/01 12:53:57
Now we do not have exact strings, we have expressi
| |
859 codecs_map_.erase(proprietary_media_codecs[i]); | 890 arraysize(common_media_types) + arraysize(proprietary_media_types)) { |
891 codecs_map_.erase(codecs_map_.end() - arraysize(proprietary_media_types), | |
892 codecs_map_.end()); | |
893 } | |
860 } | 894 } |
861 | 895 |
862 //---------------------------------------------------------------------------- | 896 //---------------------------------------------------------------------------- |
863 // Wrappers for the singleton | 897 // Wrappers for the singleton |
864 //---------------------------------------------------------------------------- | 898 //---------------------------------------------------------------------------- |
865 | 899 |
866 bool GetMimeTypeFromExtension(const base::FilePath::StringType& ext, | 900 bool GetMimeTypeFromExtension(const base::FilePath::StringType& ext, |
867 std::string* mime_type) { | 901 std::string* mime_type) { |
868 return g_mime_util.Get().GetMimeTypeFromExtension(ext, mime_type); | 902 return g_mime_util.Get().GetMimeTypeFromExtension(ext, mime_type); |
869 } | 903 } |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1175 post_data->append("\r\n" + value + "\r\n"); | 1209 post_data->append("\r\n" + value + "\r\n"); |
1176 } | 1210 } |
1177 | 1211 |
1178 void AddMultipartFinalDelimiterForUpload(const std::string& mime_boundary, | 1212 void AddMultipartFinalDelimiterForUpload(const std::string& mime_boundary, |
1179 std::string* post_data) { | 1213 std::string* post_data) { |
1180 DCHECK(post_data); | 1214 DCHECK(post_data); |
1181 post_data->append("--" + mime_boundary + "--\r\n"); | 1215 post_data->append("--" + mime_boundary + "--\r\n"); |
1182 } | 1216 } |
1183 | 1217 |
1184 } // namespace net | 1218 } // namespace net |
OLD | NEW |