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 mime_types, which expect codecs which are RFC compliant but are |
acolwell GONE FROM CHROMIUM
2014/07/01 17:28:16
nit: s/but are/but/
| |
125 // do not have sufficient informatation whether they are supported or not, and | |
131 // vector of supported codecs expressions for the mime_type. | 126 // vector of supported codecs expressions for the mime_type. |
132 StrictExpressionMappings strict_mp4_format_map_; | 127 StrictExpressionMappings inconclusive_format_map_; |
133 }; // class MimeUtil | 128 }; // class MimeUtil |
134 | 129 |
135 // This variable is Leaky because we need to access it from WorkerPool threads. | 130 // This variable is Leaky because we need to access it from WorkerPool threads. |
136 static base::LazyInstance<MimeUtil>::Leaky g_mime_util = | 131 static base::LazyInstance<MimeUtil>::Leaky g_mime_util = |
137 LAZY_INSTANCE_INITIALIZER; | 132 LAZY_INSTANCE_INITIALIZER; |
138 | 133 |
139 struct MimeInfo { | 134 struct MimeInfo { |
140 const char* mime_type; | 135 const char* mime_type; |
141 const char* extensions; // comma separated list | 136 const char* extensions; // comma separated list |
142 }; | 137 }; |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
325 | 320 |
326 // List of supported codecs when passed in with <source type="...">. | 321 // List of supported codecs when passed in with <source type="...">. |
327 // This set of codecs is supported by all variations of Chromium. | 322 // This set of codecs is supported by all variations of Chromium. |
328 // | 323 // |
329 // Refer to http://wiki.whatwg.org/wiki/Video_type_parameters#Browser_Support | 324 // Refer to http://wiki.whatwg.org/wiki/Video_type_parameters#Browser_Support |
330 // for more information. | 325 // for more information. |
331 // | 326 // |
332 // The codecs for WAV are integers as defined in Appendix A of RFC2361: | 327 // The codecs for WAV are integers as defined in Appendix A of RFC2361: |
333 // http://tools.ietf.org/html/rfc2361 | 328 // http://tools.ietf.org/html/rfc2361 |
334 static const char* const common_media_codecs[] = { | 329 static const char* const common_media_codecs[] = { |
335 #if !defined(OS_ANDROID) // Android doesn't support Ogg Theora. | 330 #if !defined(OS_ANDROID) // Android doesn't support Ogg Theora. |
acolwell GONE FROM CHROMIUM
2014/07/01 17:28:16
I think you can drop this #if since IsCodecSupport
| |
336 "theora", | 331 "theora", |
337 #endif | 332 #endif |
338 "opus", | 333 "opus", |
339 "vorbis", | 334 "vorbis", |
340 "vp8", | 335 "vp8", |
341 "vp9", | 336 "vp9", |
342 "1" // WAVE_FORMAT_PCM. | 337 "1" // WAVE_FORMAT_PCM. |
343 }; | 338 }; |
344 | 339 |
345 // List of proprietary codecs only supported by Google Chrome. | 340 // List of proprietary codecs only supported by Google Chrome. |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
436 return false; | 431 return false; |
437 | 432 |
438 // VP9 is supported only in KitKat+ (API Level 19). | 433 // VP9 is supported only in KitKat+ (API Level 19). |
439 if ((!codec.compare("vp9") || !codec.compare("vp9.0")) && | 434 if ((!codec.compare("vp9") || !codec.compare("vp9.0")) && |
440 base::android::BuildInfo::GetInstance()->sdk_int() < 19) { | 435 base::android::BuildInfo::GetInstance()->sdk_int() < 19) { |
441 return false; | 436 return false; |
442 } | 437 } |
443 | 438 |
444 // TODO(vigneshv): Change this similar to the VP9 check once Opus is | 439 // TODO(vigneshv): Change this similar to the VP9 check once Opus is |
445 // supported on Android (http://crbug.com/318436). | 440 // supported on Android (http://crbug.com/318436). |
446 if (!codec.compare("opus")) { | 441 if (!codec.compare("opus")) |
442 return false; | |
443 | |
444 // MPEG-2 AAC is not supported on Android | |
445 if (!codec.compare("mp4a.67")) | |
446 return false; | |
447 | |
448 // H.264 Main and High profiles are not supported on Android | |
449 if (!codec.compare("avc1.4d40??") || !codec.compare("avc3.4d40??") || | |
450 !codec.compare("avc1.4D40??") || !codec.compare("avc3.4D40??") || | |
451 !codec.compare("avc1.6400??") || !codec.compare("avc3.6400??")) { | |
447 return false; | 452 return false; |
448 } | 453 } |
454 | |
449 return true; | 455 return true; |
450 } | 456 } |
451 | 457 |
452 static bool IsMimeTypeSupportedOnAndroid(const std::string& mimeType) { | 458 static bool IsMimeTypeSupportedOnAndroid(const std::string& mimeType) { |
453 // HLS codecs are supported in ICS and above (API level 14) | 459 // HLS codecs are supported in ICS and above (API level 14) |
454 if ((!mimeType.compare("application/vnd.apple.mpegurl") || | 460 if ((!mimeType.compare("application/vnd.apple.mpegurl") || |
455 !mimeType.compare("application/x-mpegurl")) && | 461 !mimeType.compare("application/x-mpegurl")) && |
456 base::android::BuildInfo::GetInstance()->sdk_int() < 14) { | 462 base::android::BuildInfo::GetInstance()->sdk_int() < 14) { |
457 return false; | 463 return false; |
458 } | 464 } |
459 return true; | 465 return true; |
460 } | 466 } |
461 #endif | 467 #endif |
462 | 468 |
463 struct MediaFormatStrict { | 469 struct MediaFormatStrict { |
464 const char* mime_type; | 470 const char* mime_type; |
465 const char* codecs_list; | 471 const char* codecs_list; |
466 }; | 472 }; |
467 | 473 |
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: | 474 // Following is the list of RFC 6381 compliant codecs: |
482 // mp4a.6B - MPEG-1 audio | 475 // mp4a.6B - MPEG-1 audio |
483 // mp4a.69 - MPEG-2 extension to MPEG-1 | 476 // mp4a.69 - MPEG-2 extension to MPEG-1 |
484 // mp4a.67 - MPEG-2 AAC | 477 // mp4a.67 - MPEG-2 AAC |
485 // mp4a.40.2 - MPEG-4 AAC | 478 // mp4a.40.2 - MPEG-4 AAC |
486 // mp4a.40.5 - MPEG-4 HE-AAC | 479 // mp4a.40.5 - MPEG-4 HE-AACv1 |
487 // | 480 // |
488 // avc1.42E0xx - H.264 Baseline | 481 // avc1.42E0xx - H.264 Baseline |
489 // avc1.4D40xx - H.264 Main | 482 // avc1.4D40xx - H.264 Main |
490 // avc1.6400xx - H.264 High | 483 // avc1.6400xx - H.264 High |
484 static const char kProprietaryAudioCodecsExpression[] = | |
485 "mp4a.6B,mp4a.69,mp4a.67,mp4a.40.2,mp4a.40.5"; | |
486 static const char kProprietaryCodecsExpression[] = | |
487 "avc1.42E0??,avc1.42e0??,avc1.4D40??,avc1.4d40??,avc1.6400??," | |
488 "avc3.42E0??,avc3.42e0??,avc3.4D40??,avc3.4d40??,avc3.6400??," | |
489 "mp4a.6B,mp4a.69,mp4a.67,mp4a.40.2,mp4a.40.5"; | |
490 | |
491 static const MediaFormatStrict format_codec_mappings[] = { | |
492 {"video/webm", "opus,vorbis,vp8,vp8.0,vp9,vp9.0"}, | |
493 {"audio/webm", "opus,vorbis"}, | |
494 {"audio/wav", "1"}, | |
495 {"audio/x-wav", "1"}, | |
496 {"video/ogg", "opus,theora,vorbis"}, | |
497 {"audio/ogg", "opus,vorbis"}, | |
498 {"application/ogg", "opus,theora,vorbis"}, | |
499 {"audio/mpeg", ""}, | |
500 {"audio/mp3", ""}, | |
501 {"audio/x-mp3", ""}, | |
502 {"audio/mp4", kProprietaryAudioCodecsExpression}, | |
503 {"audio/x-m4a", kProprietaryAudioCodecsExpression}, | |
504 {"video/mp4", kProprietaryCodecsExpression}, | |
505 {"video/x-m4v", kProprietaryCodecsExpression}, | |
506 {"application/x-mpegurl", kProprietaryCodecsExpression}, | |
507 {"application/vnd.apple.mpegurl", kProprietaryCodecsExpression} | |
508 }; | |
509 | |
510 // Following is the list of codecs that are RFC 6381 compliant but browser | |
511 // cannot be sure whether the platform supports them or not | |
512 // mp4a.40 | |
513 // avc1 | |
514 // avc3 | |
491 // | 515 // |
492 // Additionally, several non-RFC compliant codecs are allowed, due to their | 516 // Additionally, several non-RFC compliant codecs are allowed, due to their |
493 // existing use on web. | 517 // existing use on web. |
494 // mp4a.40 | |
495 // avc1.xxxxxx | 518 // avc1.xxxxxx |
496 // avc3.xxxxxx | 519 // avc3.xxxxxx |
497 // mp4a.6x | 520 static const char kInconclusiveProprietaryAudioCodecsExpression[] = |
498 static const char kProprietaryAudioCodecsExpression[] = | 521 "mp4a.40,mp4a.66,mp4a.68"; |
499 "mp4a.6?,mp4a.40,mp4a.40.?"; | 522 static const char kInconclusiveProprietaryCodecsExpression[] = |
500 static const char kProprietaryCodecsExpression[] = | 523 "avc1,avc1.??????,avc3,avc3.??????,mp4a.40,mp4a.66,mp4a.68"; |
501 "avc1,avc3,avc1.??????,avc3.??????,mp4a.6?,mp4a.40,mp4a.40.?"; | |
502 | 524 |
503 static const MediaFormatStrict format_mp4_codec_mappings[] = { | 525 static const MediaFormatStrict format_inconclusive_codec_mappings[] = { |
504 { "audio/mp4", kProprietaryAudioCodecsExpression }, | 526 {"audio/mp4", kInconclusiveProprietaryAudioCodecsExpression}, |
505 { "audio/x-m4a", kProprietaryAudioCodecsExpression }, | 527 {"audio/x-m4a", kInconclusiveProprietaryAudioCodecsExpression}, |
506 { "video/mp4", kProprietaryCodecsExpression }, | 528 {"video/mp4", kInconclusiveProprietaryCodecsExpression}, |
507 { "video/x-m4v", kProprietaryCodecsExpression }, | 529 {"video/x-m4v", kInconclusiveProprietaryCodecsExpression}, |
508 { "application/x-mpegurl", kProprietaryCodecsExpression }, | 530 {"application/x-mpegurl", kInconclusiveProprietaryCodecsExpression}, |
509 { "application/vnd.apple.mpegurl", kProprietaryCodecsExpression } | 531 {"application/vnd.apple.mpegurl", kInconclusiveProprietaryCodecsExpression} |
510 }; | 532 }; |
511 | 533 |
512 MimeUtil::MimeUtil() { | 534 MimeUtil::MimeUtil() { |
513 InitializeMimeTypeMaps(); | 535 InitializeMimeTypeMaps(); |
514 } | 536 } |
515 | 537 |
516 // static | 538 // static |
517 bool MimeUtil::AreSupportedCodecs(const MimeMappings& supported_codecs, | 539 // Checks all the codecs present in the |codecs| against the entries in |
518 const std::vector<std::string>& codecs) { | 540 // |supported_codecs|. Returns true only if |codecs| is non-empty and all the |
541 // codecs match |supported_codecs| expressions. | |
542 bool MimeUtil::AreSupportedCodecs( | |
543 const MimeExpressionMappings& supported_codecs, | |
544 const std::vector<std::string>& codecs) { | |
519 if (supported_codecs.empty()) | 545 if (supported_codecs.empty()) |
520 return codecs.empty(); | 546 return codecs.empty(); |
521 | 547 |
522 for (size_t i = 0; i < codecs.size(); ++i) { | 548 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; | 549 bool codec_matched = false; |
538 for (size_t j = 0; j < supported_codecs.size(); ++j) { | 550 for (size_t j = 0; j < supported_codecs.size(); ++j) { |
539 if (!MatchPattern(base::StringPiece(codecs[i]), | 551 if (!MatchPattern(base::StringPiece(codecs[i]), |
540 base::StringPiece(supported_codecs[j]))) { | 552 base::StringPiece(supported_codecs[j]))) { |
541 continue; | 553 continue; |
542 } | 554 } |
543 // If suffix exists, check whether it is hexadecimal. | 555 // If suffix exists, check whether it is hexadecimal. |
544 for (size_t wildcard_pos = supported_codecs[j].find('?'); | 556 for (size_t wildcard_pos = supported_codecs[j].find('?'); |
545 wildcard_pos != std::string::npos && | 557 wildcard_pos != std::string::npos && |
546 wildcard_pos < supported_codecs[j].length(); | 558 wildcard_pos < supported_codecs[j].length(); |
547 wildcard_pos = supported_codecs[j].find('?', wildcard_pos + 1)) { | 559 wildcard_pos = supported_codecs[j].find('?', wildcard_pos + 1)) { |
548 // Don't enforce case sensitivity, even though it's called for, as it | 560 // Don't enforce case sensitivity, even though it's called for, as it |
549 // would break some websites. | 561 // would break some websites. |
550 if (wildcard_pos >= codecs[i].length() || | 562 if (wildcard_pos >= codecs[i].length() || |
551 !IsHexDigit(codecs[i].at(wildcard_pos))) { | 563 !IsHexDigit(codecs[i].at(wildcard_pos))) { |
552 return false; | 564 return false; |
553 } | 565 } |
554 } | 566 } |
555 codec_matched = true; | 567 codec_matched = true; |
556 break; | 568 break; |
557 } | 569 } |
558 if (!codec_matched) | 570 if (!codec_matched) |
559 return false; | 571 return false; |
560 } | 572 } |
573 | |
561 return !codecs.empty(); | 574 return !codecs.empty(); |
562 } | 575 } |
563 | 576 |
564 void MimeUtil::InitializeMimeTypeMaps() { | 577 void MimeUtil::InitializeMimeTypeMaps() { |
565 for (size_t i = 0; i < arraysize(supported_image_types); ++i) | 578 for (size_t i = 0; i < arraysize(supported_image_types); ++i) |
566 image_map_.insert(supported_image_types[i]); | 579 image_map_.insert(supported_image_types[i]); |
567 | 580 |
568 // Initialize the supported non-image types. | 581 // Initialize the supported non-image types. |
569 for (size_t i = 0; i < arraysize(supported_non_image_types); ++i) | 582 for (size_t i = 0; i < arraysize(supported_non_image_types); ++i) |
570 non_image_map_.insert(supported_non_image_types[i]); | 583 non_image_map_.insert(supported_non_image_types[i]); |
(...skipping 29 matching lines...) Expand all Loading... | |
600 #endif | 613 #endif |
601 | 614 |
602 for (size_t i = 0; i < arraysize(supported_javascript_types); ++i) | 615 for (size_t i = 0; i < arraysize(supported_javascript_types); ++i) |
603 javascript_map_.insert(supported_javascript_types[i]); | 616 javascript_map_.insert(supported_javascript_types[i]); |
604 | 617 |
605 for (size_t i = 0; i < arraysize(common_media_codecs); ++i) { | 618 for (size_t i = 0; i < arraysize(common_media_codecs); ++i) { |
606 #if defined(OS_ANDROID) | 619 #if defined(OS_ANDROID) |
607 if (!IsCodecSupportedOnAndroid(common_media_codecs[i])) | 620 if (!IsCodecSupportedOnAndroid(common_media_codecs[i])) |
608 continue; | 621 continue; |
609 #endif | 622 #endif |
610 codecs_map_.insert(common_media_codecs[i]); | 623 codecs_map_.push_back(common_media_codecs[i]); |
611 } | 624 } |
612 #if defined(USE_PROPRIETARY_CODECS) | 625 #if defined(USE_PROPRIETARY_CODECS) |
613 for (size_t i = 0; i < arraysize(proprietary_media_codecs); ++i) | 626 for (size_t i = 0; i < arraysize(proprietary_media_codecs); ++i) |
614 codecs_map_.insert(proprietary_media_codecs[i]); | 627 codecs_map_.push_back(proprietary_media_codecs[i]); |
615 #endif | 628 #endif |
616 | 629 |
617 // Initialize the strict supported media types. | 630 // Initialize the strict supported media types. |
618 for (size_t i = 0; i < arraysize(format_codec_mappings); ++i) { | 631 for (size_t i = 0; i < arraysize(format_codec_mappings); ++i) { |
619 std::vector<std::string> mime_type_codecs; | 632 std::vector<std::string> mime_type_codecs; |
620 ParseCodecString(format_codec_mappings[i].codecs_list, | 633 ParseCodecString(format_codec_mappings[i].codecs_list, |
621 &mime_type_codecs, | 634 &mime_type_codecs, |
622 false); | 635 false); |
623 | 636 |
624 MimeMappings codecs; | 637 MimeExpressionMappings codecs; |
625 for (size_t j = 0; j < mime_type_codecs.size(); ++j) { | 638 for (size_t j = 0; j < mime_type_codecs.size(); ++j) { |
626 #if defined(OS_ANDROID) | 639 #if defined(OS_ANDROID) |
627 if (!IsCodecSupportedOnAndroid(mime_type_codecs[j])) | 640 if (!IsCodecSupportedOnAndroid(mime_type_codecs[j])) |
628 continue; | 641 continue; |
629 #endif | 642 #endif |
630 codecs.insert(mime_type_codecs[j]); | 643 codecs.push_back(mime_type_codecs[j]); |
631 } | 644 } |
632 strict_format_map_[format_codec_mappings[i].mime_type] = codecs; | 645 strict_format_map_[format_codec_mappings[i].mime_type] = codecs; |
633 } | 646 } |
634 for (size_t i = 0; i < arraysize(format_mp4_codec_mappings); ++i) { | 647 for (size_t i = 0; i < arraysize(format_inconclusive_codec_mappings); ++i) { |
635 std::vector<std::string> mime_type_codecs; | 648 std::vector<std::string> mime_type_codecs; |
636 ParseCodecString( | 649 ParseCodecString( |
637 format_mp4_codec_mappings[i].codecs_list, &mime_type_codecs, false); | 650 format_inconclusive_codec_mappings[i].codecs_list, &mime_type_codecs, |
651 false); | |
638 | 652 |
639 MimeExpressionMappings codecs; | 653 MimeExpressionMappings codecs; |
640 for (size_t j = 0; j < mime_type_codecs.size(); ++j) | 654 for (size_t j = 0; j < mime_type_codecs.size(); ++j) { |
655 #if defined(OS_ANDROID) | |
656 if (!IsCodecSupportedOnAndroid(mime_type_codecs[j])) | |
657 continue; | |
658 #endif | |
641 codecs.push_back(mime_type_codecs[j]); | 659 codecs.push_back(mime_type_codecs[j]); |
642 strict_mp4_format_map_[format_mp4_codec_mappings[i].mime_type] = codecs; | 660 } |
661 // Merge codecs from conclusive list into inconclusive list so that querries | |
662 // with one conclusive and one inconclusive codec do not get an empty | |
663 // string in reply. | |
664 StrictExpressionMappings::const_iterator it = strict_format_map_.find( | |
665 format_inconclusive_codec_mappings[i].mime_type); | |
666 if (it != strict_format_map_.end()) | |
667 codecs.insert(codecs.end(), it->second.begin(), it->second.end()); | |
668 inconclusive_format_map_[format_inconclusive_codec_mappings[i].mime_type] = | |
669 codecs; | |
643 } | 670 } |
644 } | 671 } |
645 | 672 |
646 bool MimeUtil::IsSupportedImageMimeType(const std::string& mime_type) const { | 673 bool MimeUtil::IsSupportedImageMimeType(const std::string& mime_type) const { |
647 return image_map_.find(mime_type) != image_map_.end(); | 674 return image_map_.find(mime_type) != image_map_.end(); |
648 } | 675 } |
649 | 676 |
650 bool MimeUtil::IsSupportedMediaMimeType(const std::string& mime_type) const { | 677 bool MimeUtil::IsSupportedMediaMimeType(const std::string& mime_type) const { |
651 return media_map_.find(mime_type) != media_map_.end(); | 678 return media_map_.find(mime_type) != media_map_.end(); |
652 } | 679 } |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
814 for (std::vector<std::string>::iterator it = codecs_out->begin(); | 841 for (std::vector<std::string>::iterator it = codecs_out->begin(); |
815 it != codecs_out->end(); | 842 it != codecs_out->end(); |
816 ++it) { | 843 ++it) { |
817 size_t found = it->find_first_of('.'); | 844 size_t found = it->find_first_of('.'); |
818 if (found != std::string::npos) | 845 if (found != std::string::npos) |
819 it->resize(found); | 846 it->resize(found); |
820 } | 847 } |
821 } | 848 } |
822 | 849 |
823 bool MimeUtil::IsStrictMediaMimeType(const std::string& mime_type) const { | 850 bool MimeUtil::IsStrictMediaMimeType(const std::string& mime_type) const { |
824 if (strict_format_map_.find(mime_type) == strict_format_map_.end() && | 851 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; | 852 return false; |
827 return true; | 853 return true; |
828 } | 854 } |
829 | 855 |
830 SupportsType MimeUtil::IsSupportedStrictMediaMimeType( | 856 SupportsType MimeUtil::IsSupportedStrictMediaMimeType( |
831 const std::string& mime_type, | 857 const std::string& mime_type, |
832 const std::vector<std::string>& codecs) const { | 858 const std::vector<std::string>& codecs) const { |
833 StrictMappings::const_iterator it_strict_map = | 859 StrictExpressionMappings::const_iterator it_strict_map = |
834 strict_format_map_.find(mime_type); | 860 strict_format_map_.find(mime_type); |
835 if ((it_strict_map != strict_format_map_.end()) && | 861 if ((it_strict_map != strict_format_map_.end()) && |
836 AreSupportedCodecs(it_strict_map->second, codecs)) { | 862 AreSupportedCodecs(it_strict_map->second, codecs)) { |
837 return IsSupported; | 863 return IsSupported; |
838 } | 864 } |
839 | 865 |
840 StrictExpressionMappings::const_iterator it_expression_map = | 866 StrictExpressionMappings::const_iterator it_expression_map = |
841 strict_mp4_format_map_.find(mime_type); | 867 inconclusive_format_map_.find(mime_type); |
842 if ((it_expression_map != strict_mp4_format_map_.end()) && | 868 if ((it_expression_map != inconclusive_format_map_.end()) && |
843 AreSupportedCodecsWithProfile(it_expression_map->second, codecs)) { | 869 AreSupportedCodecs(it_expression_map->second, codecs)) { |
844 return MayBeSupported; | 870 return MayBeSupported; |
845 } | 871 } |
846 | 872 |
847 if (codecs.empty()) | 873 if (codecs.empty()) |
848 return MayBeSupported; | 874 return MayBeSupported; |
849 | 875 |
850 return IsNotSupported; | 876 return IsNotSupported; |
851 } | 877 } |
852 | 878 |
853 void MimeUtil::RemoveProprietaryMediaTypesAndCodecsForTests() { | 879 void MimeUtil::RemoveProprietaryMediaTypesAndCodecsForTests() { |
854 for (size_t i = 0; i < arraysize(proprietary_media_types); ++i) { | 880 for (size_t i = 0; i < arraysize(proprietary_media_types); ++i) { |
855 non_image_map_.erase(proprietary_media_types[i]); | 881 non_image_map_.erase(proprietary_media_types[i]); |
856 media_map_.erase(proprietary_media_types[i]); | 882 media_map_.erase(proprietary_media_types[i]); |
857 } | 883 } |
858 for (size_t i = 0; i < arraysize(proprietary_media_codecs); ++i) | 884 for (size_t i = 0; i < arraysize(proprietary_media_codecs); ++i) { |
859 codecs_map_.erase(proprietary_media_codecs[i]); | 885 codecs_map_.erase(std::remove(codecs_map_.begin(), |
886 codecs_map_.end(), | |
887 proprietary_media_codecs[i]), | |
888 codecs_map_.end()); | |
889 } | |
860 } | 890 } |
861 | 891 |
862 //---------------------------------------------------------------------------- | 892 //---------------------------------------------------------------------------- |
863 // Wrappers for the singleton | 893 // Wrappers for the singleton |
864 //---------------------------------------------------------------------------- | 894 //---------------------------------------------------------------------------- |
865 | 895 |
866 bool GetMimeTypeFromExtension(const base::FilePath::StringType& ext, | 896 bool GetMimeTypeFromExtension(const base::FilePath::StringType& ext, |
867 std::string* mime_type) { | 897 std::string* mime_type) { |
868 return g_mime_util.Get().GetMimeTypeFromExtension(ext, mime_type); | 898 return g_mime_util.Get().GetMimeTypeFromExtension(ext, mime_type); |
869 } | 899 } |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1175 post_data->append("\r\n" + value + "\r\n"); | 1205 post_data->append("\r\n" + value + "\r\n"); |
1176 } | 1206 } |
1177 | 1207 |
1178 void AddMultipartFinalDelimiterForUpload(const std::string& mime_boundary, | 1208 void AddMultipartFinalDelimiterForUpload(const std::string& mime_boundary, |
1179 std::string* post_data) { | 1209 std::string* post_data) { |
1180 DCHECK(post_data); | 1210 DCHECK(post_data); |
1181 post_data->append("--" + mime_boundary + "--\r\n"); | 1211 post_data->append("--" + mime_boundary + "--\r\n"); |
1182 } | 1212 } |
1183 | 1213 |
1184 } // namespace net | 1214 } // namespace net |
OLD | NEW |