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

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

Issue 336213011: Fix: Changing canPlayType behaviour for MP4 containers (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changing method names Created 6 years, 5 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 | « content/browser/media/media_canplaytype_browsertest.cc ('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 (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
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 AreCodecsListedInSingleLookupTable(
107 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, 106 const MimeExpressionMappings& supported_codecs,
112 const std::vector<std::string>& codecs); 107 const std::vector<std::string>& codecs);
113 108
109 // Returns true if |codecs| is nonempty and all the items in it are present in
110 // either |confirmed_supported_codecs| or |mightbe_supported_codecs|.
111 static bool AreCodecsListedInMultipleLookupTables(
112 const MimeExpressionMappings& confirmed_supported_codecs,
113 const MimeExpressionMappings& mightbe_supported_codecs,
114 const std::vector<std::string>& codecs);
115
114 // For faster lookup, keep hash sets. 116 // For faster lookup, keep hash sets.
115 void InitializeMimeTypeMaps(); 117 void InitializeMimeTypeMaps();
116 118
117 bool GetMimeTypeFromExtensionHelper(const base::FilePath::StringType& ext, 119 bool GetMimeTypeFromExtensionHelper(const base::FilePath::StringType& ext,
118 bool include_platform_types, 120 bool include_platform_types,
119 std::string* mime_type) const; 121 std::string* mime_type) const;
120 122
121 MimeMappings image_map_; 123 MimeMappings image_map_;
122 MimeMappings media_map_; 124 MimeMappings media_map_;
123 MimeMappings non_image_map_; 125 MimeMappings non_image_map_;
124 MimeMappings unsupported_text_map_; 126 MimeMappings unsupported_text_map_;
125 MimeMappings javascript_map_; 127 MimeMappings javascript_map_;
126 MimeMappings codecs_map_; 128 MimeExpressionMappings codecs_map_;
127 129
128 // A map of mime_types and hash map of the supported codecs for the mime_type. 130 // A map of mime_types and hash map of the supported codecs for the mime_type.
129 StrictMappings strict_format_map_; 131 StrictExpressionMappings strict_format_map_;
130 // A map of MP4 mime_types which expect codecs with profile parameter and 132 // A map of mime_types, which expect codecs which are RFC compliant but do not
131 // vector of supported codecs expressions for the mime_type. 133 // have sufficient informatation whether they are supported or not, and vector
132 StrictExpressionMappings strict_mp4_format_map_; 134 // of supported codecs expressions for the mime_type.
135 StrictExpressionMappings inconclusive_format_map_;
133 }; // class MimeUtil 136 }; // class MimeUtil
134 137
135 // This variable is Leaky because we need to access it from WorkerPool threads. 138 // This variable is Leaky because we need to access it from WorkerPool threads.
136 static base::LazyInstance<MimeUtil>::Leaky g_mime_util = 139 static base::LazyInstance<MimeUtil>::Leaky g_mime_util =
137 LAZY_INSTANCE_INITIALIZER; 140 LAZY_INSTANCE_INITIALIZER;
138 141
139 struct MimeInfo { 142 struct MimeInfo {
140 const char* mime_type; 143 const char* mime_type;
141 const char* extensions; // comma separated list 144 const char* extensions; // comma separated list
142 }; 145 };
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 "image/bmp", 282 "image/bmp",
280 "image/vnd.microsoft.icon", // ico 283 "image/vnd.microsoft.icon", // ico
281 "image/x-icon", // ico 284 "image/x-icon", // ico
282 "image/x-xbitmap", // xbm 285 "image/x-xbitmap", // xbm
283 "image/x-png" 286 "image/x-png"
284 }; 287 };
285 288
286 // A list of media types: http://en.wikipedia.org/wiki/Internet_media_type 289 // A list of media types: http://en.wikipedia.org/wiki/Internet_media_type
287 // A comprehensive mime type list: http://plugindoc.mozdev.org/winmime.php 290 // A comprehensive mime type list: http://plugindoc.mozdev.org/winmime.php
288 // This set of codecs is supported by all variations of Chromium. 291 // This set of codecs is supported by all variations of Chromium.
292 // (Except for 'video/ogg', which is not supported by Android.)
289 static const char* const common_media_types[] = { 293 static const char* const common_media_types[] = {
290 // Ogg. 294 // Ogg.
291 "audio/ogg", 295 "audio/ogg",
292 "application/ogg", 296 "application/ogg",
293 #if !defined(OS_ANDROID) // Android doesn't support Ogg Theora.
294 "video/ogg", 297 "video/ogg",
295 #endif
296 298
297 // WebM. 299 // WebM.
298 "video/webm", 300 "video/webm",
299 "audio/webm", 301 "audio/webm",
300 302
301 // Wav. 303 // Wav.
302 "audio/wav", 304 "audio/wav",
303 "audio/x-wav", 305 "audio/x-wav",
304 306
305 #if defined(OS_ANDROID) 307 #if defined(OS_ANDROID)
(...skipping 12 matching lines...) Expand all
318 "audio/x-m4a", 320 "audio/x-m4a",
319 321
320 // MP3. 322 // MP3.
321 "audio/mp3", 323 "audio/mp3",
322 "audio/x-mp3", 324 "audio/x-mp3",
323 "audio/mpeg", 325 "audio/mpeg",
324 }; 326 };
325 327
326 // List of supported codecs when passed in with <source type="...">. 328 // List of supported codecs when passed in with <source type="...">.
327 // This set of codecs is supported by all variations of Chromium. 329 // This set of codecs is supported by all variations of Chromium.
330 // (Except for 'theora' and 'opus' (http://crbug.com/318436), which are not
331 // supported by Android.)
328 // 332 //
329 // Refer to http://wiki.whatwg.org/wiki/Video_type_parameters#Browser_Support 333 // Refer to http://wiki.whatwg.org/wiki/Video_type_parameters#Browser_Support
330 // for more information. 334 // for more information.
331 // 335 //
332 // The codecs for WAV are integers as defined in Appendix A of RFC2361: 336 // The codecs for WAV are integers as defined in Appendix A of RFC2361:
333 // http://tools.ietf.org/html/rfc2361 337 // http://tools.ietf.org/html/rfc2361
334 static const char* const common_media_codecs[] = { 338 static const char* const common_media_codecs[] = {
335 #if !defined(OS_ANDROID) // Android doesn't support Ogg Theora.
336 "theora", 339 "theora",
337 #endif
338 "opus", 340 "opus",
339 "vorbis", 341 "vorbis",
340 "vp8", 342 "vp8",
341 "vp9", 343 "vp9",
342 "1" // WAVE_FORMAT_PCM. 344 "1" // WAVE_FORMAT_PCM.
343 }; 345 };
344 346
345 // List of proprietary codecs only supported by Google Chrome. 347 // List of proprietary codecs only supported by Google Chrome.
346 static const char* const proprietary_media_codecs[] = { 348 static const char* const proprietary_media_codecs[] = {
347 "avc1", 349 "avc1",
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 return false; 438 return false;
437 439
438 // VP9 is supported only in KitKat+ (API Level 19). 440 // VP9 is supported only in KitKat+ (API Level 19).
439 if ((!codec.compare("vp9") || !codec.compare("vp9.0")) && 441 if ((!codec.compare("vp9") || !codec.compare("vp9.0")) &&
440 base::android::BuildInfo::GetInstance()->sdk_int() < 19) { 442 base::android::BuildInfo::GetInstance()->sdk_int() < 19) {
441 return false; 443 return false;
442 } 444 }
443 445
444 // TODO(vigneshv): Change this similar to the VP9 check once Opus is 446 // TODO(vigneshv): Change this similar to the VP9 check once Opus is
445 // supported on Android (http://crbug.com/318436). 447 // supported on Android (http://crbug.com/318436).
446 if (!codec.compare("opus")) { 448 if (!codec.compare("opus"))
449 return false;
450
451 // MPEG-2 AAC is not supported on Android
452 if (!codec.compare("mp4a.67"))
453 return false;
454
455 // H.264 Main and High profiles are not supported on Android
456 if (!codec.compare("avc1.4d40??") || !codec.compare("avc3.4d40??") ||
457 !codec.compare("avc1.4D40??") || !codec.compare("avc3.4D40??") ||
458 !codec.compare("avc1.6400??") || !codec.compare("avc3.6400??")) {
447 return false; 459 return false;
448 } 460 }
461
449 return true; 462 return true;
450 } 463 }
451 464
452 static bool IsMimeTypeSupportedOnAndroid(const std::string& mimeType) { 465 static bool IsMimeTypeSupportedOnAndroid(const std::string& mimeType) {
466 // Ogg Theora is not supported on Android
467 if (!mimeType.compare("video/ogg"))
468 return false;
469
453 // HLS codecs are supported in ICS and above (API level 14) 470 // HLS codecs are supported in ICS and above (API level 14)
454 if ((!mimeType.compare("application/vnd.apple.mpegurl") || 471 if ((!mimeType.compare("application/vnd.apple.mpegurl") ||
455 !mimeType.compare("application/x-mpegurl")) && 472 !mimeType.compare("application/x-mpegurl")) &&
456 base::android::BuildInfo::GetInstance()->sdk_int() < 14) { 473 base::android::BuildInfo::GetInstance()->sdk_int() < 14) {
457 return false; 474 return false;
458 } 475 }
476
459 return true; 477 return true;
460 } 478 }
461 #endif 479 #endif
462 480
463 struct MediaFormatStrict { 481 struct MediaFormatStrict {
464 const char* mime_type; 482 const char* mime_type;
465 const char* codecs_list; 483 const char* codecs_list;
466 }; 484 };
467 485
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: 486 // Following is the list of RFC 6381 compliant codecs:
482 // mp4a.6B - MPEG-1 audio 487 // mp4a.6B - MPEG-1 audio
483 // mp4a.69 - MPEG-2 extension to MPEG-1 488 // mp4a.69 - MPEG-2 extension to MPEG-1
484 // mp4a.67 - MPEG-2 AAC 489 // mp4a.67 - MPEG-2 AAC
485 // mp4a.40.2 - MPEG-4 AAC 490 // mp4a.40.2 - MPEG-4 AAC
486 // mp4a.40.5 - MPEG-4 HE-AAC 491 // mp4a.40.5 - MPEG-4 HE-AACv1
487 // 492 //
488 // avc1.42E0xx - H.264 Baseline 493 // avc1.42E0xx - H.264 Baseline
489 // avc1.4D40xx - H.264 Main 494 // avc1.4D40xx - H.264 Main
490 // avc1.6400xx - H.264 High 495 // avc1.6400xx - H.264 High
496 static const char kProprietaryAudioCodecsExpression[] =
497 "mp4a.6B,mp4a.69,mp4a.67,mp4a.40.2,mp4a.40.5";
498 static const char kProprietaryCodecsExpression[] =
499 "avc1.42E0??,avc1.42e0??,avc1.4D40??,avc1.4d40??,avc1.6400??,"
500 "avc3.42E0??,avc3.42e0??,avc3.4D40??,avc3.4d40??,avc3.6400??,"
501 "mp4a.6B,mp4a.69,mp4a.67,mp4a.40.2,mp4a.40.5";
502
503 static const MediaFormatStrict format_codec_mappings[] = {
504 {"video/webm", "opus,vorbis,vp8,vp8.0,vp9,vp9.0"},
505 {"audio/webm", "opus,vorbis"},
506 {"audio/wav", "1"},
507 {"audio/x-wav", "1"},
508 {"video/ogg", "opus,theora,vorbis"},
509 {"audio/ogg", "opus,vorbis"},
510 {"application/ogg", "opus,theora,vorbis"},
511 {"audio/mpeg", ""},
512 {"audio/mp3", ""},
513 {"audio/x-mp3", ""},
514 {"audio/mp4", kProprietaryAudioCodecsExpression},
515 {"audio/x-m4a", kProprietaryAudioCodecsExpression},
516 {"video/mp4", kProprietaryCodecsExpression},
517 {"video/x-m4v", kProprietaryCodecsExpression},
518 {"application/x-mpegurl", kProprietaryCodecsExpression},
519 {"application/vnd.apple.mpegurl", kProprietaryCodecsExpression}
520 };
521
522 // Following is the list of codecs that are RFC 6381 compliant, but support for
523 // which varies with platform and cannot be determined beforehand.
524 // mp4a.40
525 // avc1
526 // avc3
491 // 527 //
492 // Additionally, several non-RFC compliant codecs are allowed, due to their 528 // Additionally, several non-RFC compliant codecs are allowed, due to their
493 // existing use on web. 529 // existing use on web.
494 // mp4a.40
495 // avc1.xxxxxx 530 // avc1.xxxxxx
496 // avc3.xxxxxx 531 // avc3.xxxxxx
497 // mp4a.6x 532 static const char kInconclusiveProprietaryAudioCodecsExpression[] =
498 static const char kProprietaryAudioCodecsExpression[] = 533 "mp4a.40,mp4a.66,mp4a.68";
499 "mp4a.6?,mp4a.40,mp4a.40.?"; 534 static const char kInconclusiveProprietaryCodecsExpression[] =
500 static const char kProprietaryCodecsExpression[] = 535 "avc1,avc1.??????,avc3,avc3.??????,mp4a.40,mp4a.66,mp4a.68";
501 "avc1,avc3,avc1.??????,avc3.??????,mp4a.6?,mp4a.40,mp4a.40.?";
502 536
503 static const MediaFormatStrict format_mp4_codec_mappings[] = { 537 static const MediaFormatStrict format_inconclusive_codec_mappings[] = {
504 { "audio/mp4", kProprietaryAudioCodecsExpression }, 538 {"audio/mp4", kInconclusiveProprietaryAudioCodecsExpression},
505 { "audio/x-m4a", kProprietaryAudioCodecsExpression }, 539 {"audio/x-m4a", kInconclusiveProprietaryAudioCodecsExpression},
506 { "video/mp4", kProprietaryCodecsExpression }, 540 {"video/mp4", kInconclusiveProprietaryCodecsExpression},
507 { "video/x-m4v", kProprietaryCodecsExpression }, 541 {"video/x-m4v", kInconclusiveProprietaryCodecsExpression},
508 { "application/x-mpegurl", kProprietaryCodecsExpression }, 542 {"application/x-mpegurl", kInconclusiveProprietaryCodecsExpression},
509 { "application/vnd.apple.mpegurl", kProprietaryCodecsExpression } 543 {"application/vnd.apple.mpegurl", kInconclusiveProprietaryCodecsExpression},
510 }; 544 };
511 545
512 MimeUtil::MimeUtil() { 546 MimeUtil::MimeUtil() {
513 InitializeMimeTypeMaps(); 547 InitializeMimeTypeMaps();
514 } 548 }
515 549
516 // static 550 // static
517 bool MimeUtil::AreSupportedCodecs(const MimeMappings& supported_codecs, 551 // Checks all the codecs present in the |codecs| against the entries in
518 const std::vector<std::string>& codecs) { 552 // |supported_codecs|. Returns true only if |codecs| is non-empty and all the
519 if (supported_codecs.empty()) 553 // codecs match |supported_codecs| expressions.
554 bool MimeUtil::AreCodecsListedInSingleLookupTable(
555 const MimeExpressionMappings& supported_codecs,
556 const std::vector<std::string>& codecs) {
557 MimeExpressionMappings empty_vector;
558 return AreCodecsListedInMultipleLookupTables(
559 supported_codecs, empty_vector, codecs);
560 }
561
562 // static
563 // Checks all the codecs present in the |codecs| against the entries in
564 // |supported_codecs|. Returns true only if |codecs| is non-empty and all the
565 // codecs match expression in either |confirmed_supported_codecs| or
566 // |mightbe_supported_codecs|.
567 bool MimeUtil::AreCodecsListedInMultipleLookupTables(
568 const MimeExpressionMappings& confirmed_supported_codecs,
569 const MimeExpressionMappings& mightbe_supported_codecs,
570 const std::vector<std::string>& codecs) {
571 if (confirmed_supported_codecs.empty() && mightbe_supported_codecs.empty())
520 return codecs.empty(); 572 return codecs.empty();
521 573
522 for (size_t i = 0; i < codecs.size(); ++i) { 574 for (size_t i = 0; i < codecs.size(); ++i) {
523 if (supported_codecs.find(codecs[i]) == supported_codecs.end()) 575 std::string matched_codec;
524 return false; 576 for (size_t j = 0; j < confirmed_supported_codecs.size(); ++j) {
525 } 577 if (MatchPattern(base::StringPiece(codecs[i]),
526 return !codecs.empty(); 578 base::StringPiece(confirmed_supported_codecs[j]))) {
527 } 579 matched_codec = confirmed_supported_codecs[j];
528 580 break;
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;
538 for (size_t j = 0; j < supported_codecs.size(); ++j) {
539 if (!MatchPattern(base::StringPiece(codecs[i]),
540 base::StringPiece(supported_codecs[j]))) {
541 continue;
542 } 581 }
582 }
583 for (size_t j = 0;
584 j < mightbe_supported_codecs.size() && matched_codec.empty();
585 ++j) {
586 if (MatchPattern(base::StringPiece(codecs[i]),
587 base::StringPiece(mightbe_supported_codecs[j]))) {
588 matched_codec = mightbe_supported_codecs[j];
589 break;
590 }
591 }
592 if (!matched_codec.empty()) {
543 // If suffix exists, check whether it is hexadecimal. 593 // If suffix exists, check whether it is hexadecimal.
544 for (size_t wildcard_pos = supported_codecs[j].find('?'); 594 for (size_t wildcard_pos = matched_codec.find('?');
545 wildcard_pos != std::string::npos && 595 wildcard_pos != std::string::npos &&
546 wildcard_pos < supported_codecs[j].length(); 596 wildcard_pos < matched_codec.length();
547 wildcard_pos = supported_codecs[j].find('?', wildcard_pos + 1)) { 597 wildcard_pos = matched_codec.find('?', wildcard_pos + 1)) {
548 // Don't enforce case sensitivity, even though it's called for, as it 598 // Don't enforce case sensitivity, even though it's called for, as it
549 // would break some websites. 599 // would break some websites.
550 if (wildcard_pos >= codecs[i].length() || 600 if (wildcard_pos >= codecs[i].length() ||
551 !IsHexDigit(codecs[i].at(wildcard_pos))) { 601 !IsHexDigit(codecs[i].at(wildcard_pos))) {
552 return false; 602 return false;
553 } 603 }
554 } 604 }
555 codec_matched = true; 605 } else {
556 break; 606 return false;
557 } 607 }
558 if (!codec_matched)
559 return false;
560 } 608 }
609
561 return !codecs.empty(); 610 return !codecs.empty();
562 } 611 }
563 612
564 void MimeUtil::InitializeMimeTypeMaps() { 613 void MimeUtil::InitializeMimeTypeMaps() {
565 for (size_t i = 0; i < arraysize(supported_image_types); ++i) 614 for (size_t i = 0; i < arraysize(supported_image_types); ++i)
566 image_map_.insert(supported_image_types[i]); 615 image_map_.insert(supported_image_types[i]);
567 616
568 // Initialize the supported non-image types. 617 // Initialize the supported non-image types.
569 for (size_t i = 0; i < arraysize(supported_non_image_types); ++i) 618 for (size_t i = 0; i < arraysize(supported_non_image_types); ++i)
570 non_image_map_.insert(supported_non_image_types[i]); 619 non_image_map_.insert(supported_non_image_types[i]);
(...skipping 29 matching lines...) Expand all
600 #endif 649 #endif
601 650
602 for (size_t i = 0; i < arraysize(supported_javascript_types); ++i) 651 for (size_t i = 0; i < arraysize(supported_javascript_types); ++i)
603 javascript_map_.insert(supported_javascript_types[i]); 652 javascript_map_.insert(supported_javascript_types[i]);
604 653
605 for (size_t i = 0; i < arraysize(common_media_codecs); ++i) { 654 for (size_t i = 0; i < arraysize(common_media_codecs); ++i) {
606 #if defined(OS_ANDROID) 655 #if defined(OS_ANDROID)
607 if (!IsCodecSupportedOnAndroid(common_media_codecs[i])) 656 if (!IsCodecSupportedOnAndroid(common_media_codecs[i]))
608 continue; 657 continue;
609 #endif 658 #endif
610 codecs_map_.insert(common_media_codecs[i]); 659 codecs_map_.push_back(common_media_codecs[i]);
611 } 660 }
612 #if defined(USE_PROPRIETARY_CODECS) 661 #if defined(USE_PROPRIETARY_CODECS)
613 for (size_t i = 0; i < arraysize(proprietary_media_codecs); ++i) 662 for (size_t i = 0; i < arraysize(proprietary_media_codecs); ++i)
614 codecs_map_.insert(proprietary_media_codecs[i]); 663 codecs_map_.push_back(proprietary_media_codecs[i]);
615 #endif 664 #endif
616 665
617 // Initialize the strict supported media types. 666 // Initialize the strict supported media types.
618 for (size_t i = 0; i < arraysize(format_codec_mappings); ++i) { 667 for (size_t i = 0; i < arraysize(format_codec_mappings); ++i) {
619 std::vector<std::string> mime_type_codecs; 668 std::vector<std::string> mime_type_codecs;
620 ParseCodecString(format_codec_mappings[i].codecs_list, 669 ParseCodecString(format_codec_mappings[i].codecs_list,
621 &mime_type_codecs, 670 &mime_type_codecs,
622 false); 671 false);
623 672
624 MimeMappings codecs; 673 MimeExpressionMappings codecs;
625 for (size_t j = 0; j < mime_type_codecs.size(); ++j) { 674 for (size_t j = 0; j < mime_type_codecs.size(); ++j) {
626 #if defined(OS_ANDROID) 675 #if defined(OS_ANDROID)
627 if (!IsCodecSupportedOnAndroid(mime_type_codecs[j])) 676 if (!IsCodecSupportedOnAndroid(mime_type_codecs[j]))
628 continue; 677 continue;
629 #endif 678 #endif
630 codecs.insert(mime_type_codecs[j]); 679 codecs.push_back(mime_type_codecs[j]);
631 } 680 }
632 strict_format_map_[format_codec_mappings[i].mime_type] = codecs; 681 strict_format_map_[format_codec_mappings[i].mime_type] = codecs;
633 } 682 }
634 for (size_t i = 0; i < arraysize(format_mp4_codec_mappings); ++i) { 683 for (size_t i = 0; i < arraysize(format_inconclusive_codec_mappings); ++i) {
635 std::vector<std::string> mime_type_codecs; 684 std::vector<std::string> mime_type_codecs;
636 ParseCodecString( 685 ParseCodecString(format_inconclusive_codec_mappings[i].codecs_list,
637 format_mp4_codec_mappings[i].codecs_list, &mime_type_codecs, false); 686 &mime_type_codecs,
687 false);
638 688
639 MimeExpressionMappings codecs; 689 MimeExpressionMappings codecs;
640 for (size_t j = 0; j < mime_type_codecs.size(); ++j) 690 for (size_t j = 0; j < mime_type_codecs.size(); ++j) {
691 #if defined(OS_ANDROID)
692 if (!IsCodecSupportedOnAndroid(mime_type_codecs[j]))
693 continue;
694 #endif
641 codecs.push_back(mime_type_codecs[j]); 695 codecs.push_back(mime_type_codecs[j]);
642 strict_mp4_format_map_[format_mp4_codec_mappings[i].mime_type] = codecs; 696 }
697 inconclusive_format_map_[format_inconclusive_codec_mappings[i].mime_type] =
698 codecs;
643 } 699 }
644 } 700 }
645 701
646 bool MimeUtil::IsSupportedImageMimeType(const std::string& mime_type) const { 702 bool MimeUtil::IsSupportedImageMimeType(const std::string& mime_type) const {
647 return image_map_.find(mime_type) != image_map_.end(); 703 return image_map_.find(mime_type) != image_map_.end();
648 } 704 }
649 705
650 bool MimeUtil::IsSupportedMediaMimeType(const std::string& mime_type) const { 706 bool MimeUtil::IsSupportedMediaMimeType(const std::string& mime_type) const {
651 return media_map_.find(mime_type) != media_map_.end(); 707 return media_map_.find(mime_type) != media_map_.end();
652 } 708 }
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
790 for (size_t i = 0; i < arraysize(legal_top_level_types); ++i) { 846 for (size_t i = 0; i < arraysize(legal_top_level_types); ++i) {
791 if (lower_type.compare(legal_top_level_types[i]) == 0) 847 if (lower_type.compare(legal_top_level_types[i]) == 0)
792 return true; 848 return true;
793 } 849 }
794 850
795 return type_string.size() > 2 && StartsWithASCII(type_string, "x-", false); 851 return type_string.size() > 2 && StartsWithASCII(type_string, "x-", false);
796 } 852 }
797 853
798 bool MimeUtil::AreSupportedMediaCodecs( 854 bool MimeUtil::AreSupportedMediaCodecs(
799 const std::vector<std::string>& codecs) const { 855 const std::vector<std::string>& codecs) const {
800 return AreSupportedCodecs(codecs_map_, codecs); 856 return AreCodecsListedInSingleLookupTable(codecs_map_, codecs);
801 } 857 }
802 858
803 void MimeUtil::ParseCodecString(const std::string& codecs, 859 void MimeUtil::ParseCodecString(const std::string& codecs,
804 std::vector<std::string>* codecs_out, 860 std::vector<std::string>* codecs_out,
805 bool strip) { 861 bool strip) {
806 std::string no_quote_codecs; 862 std::string no_quote_codecs;
807 base::TrimString(codecs, "\"", &no_quote_codecs); 863 base::TrimString(codecs, "\"", &no_quote_codecs);
808 base::SplitString(no_quote_codecs, ',', codecs_out); 864 base::SplitString(no_quote_codecs, ',', codecs_out);
809 865
810 if (!strip) 866 if (!strip)
811 return; 867 return;
812 868
813 // Strip everything past the first '.' 869 // Strip everything past the first '.'
814 for (std::vector<std::string>::iterator it = codecs_out->begin(); 870 for (std::vector<std::string>::iterator it = codecs_out->begin();
815 it != codecs_out->end(); 871 it != codecs_out->end();
816 ++it) { 872 ++it) {
817 size_t found = it->find_first_of('.'); 873 size_t found = it->find_first_of('.');
818 if (found != std::string::npos) 874 if (found != std::string::npos)
819 it->resize(found); 875 it->resize(found);
820 } 876 }
821 } 877 }
822 878
823 bool MimeUtil::IsStrictMediaMimeType(const std::string& mime_type) const { 879 bool MimeUtil::IsStrictMediaMimeType(const std::string& mime_type) const {
824 if (strict_format_map_.find(mime_type) == strict_format_map_.end() && 880 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; 881 return false;
827 return true; 882 return true;
828 } 883 }
829 884
830 SupportsType MimeUtil::IsSupportedStrictMediaMimeType( 885 SupportsType MimeUtil::IsSupportedStrictMediaMimeType(
831 const std::string& mime_type, 886 const std::string& mime_type,
832 const std::vector<std::string>& codecs) const { 887 const std::vector<std::string>& codecs) const {
833 StrictMappings::const_iterator it_strict_map = 888 StrictExpressionMappings::const_iterator it_strict_map =
834 strict_format_map_.find(mime_type); 889 strict_format_map_.find(mime_type);
835 if ((it_strict_map != strict_format_map_.end()) && 890 if ((it_strict_map != strict_format_map_.end()) &&
836 AreSupportedCodecs(it_strict_map->second, codecs)) { 891 AreCodecsListedInSingleLookupTable(it_strict_map->second, codecs)) {
837 return IsSupported; 892 return IsSupported;
838 } 893 }
839 894
840 StrictExpressionMappings::const_iterator it_expression_map = 895 StrictExpressionMappings::const_iterator it_expression_map =
841 strict_mp4_format_map_.find(mime_type); 896 inconclusive_format_map_.find(mime_type);
842 if ((it_expression_map != strict_mp4_format_map_.end()) && 897 if (it_expression_map != inconclusive_format_map_.end()) {
843 AreSupportedCodecsWithProfile(it_expression_map->second, codecs)) { 898 bool maybe = false;
844 return MayBeSupported; 899 if (it_strict_map != strict_format_map_.end()) {
900 maybe = AreCodecsListedInMultipleLookupTables(it_strict_map->second,
901 it_expression_map->second,
902 codecs);
903 } else {
904 maybe = AreCodecsListedInSingleLookupTable(it_expression_map->second,
905 codecs);
906 }
907
908 if (maybe)
909 return MayBeSupported;
845 } 910 }
846 911
847 if (codecs.empty()) 912 if (codecs.empty())
848 return MayBeSupported; 913 return MayBeSupported;
849 914
850 return IsNotSupported; 915 return IsNotSupported;
851 } 916 }
852 917
853 void MimeUtil::RemoveProprietaryMediaTypesAndCodecsForTests() { 918 void MimeUtil::RemoveProprietaryMediaTypesAndCodecsForTests() {
854 for (size_t i = 0; i < arraysize(proprietary_media_types); ++i) { 919 for (size_t i = 0; i < arraysize(proprietary_media_types); ++i) {
855 non_image_map_.erase(proprietary_media_types[i]); 920 non_image_map_.erase(proprietary_media_types[i]);
856 media_map_.erase(proprietary_media_types[i]); 921 media_map_.erase(proprietary_media_types[i]);
857 } 922 }
858 for (size_t i = 0; i < arraysize(proprietary_media_codecs); ++i) 923 for (size_t i = 0; i < arraysize(proprietary_media_codecs); ++i) {
859 codecs_map_.erase(proprietary_media_codecs[i]); 924 codecs_map_.erase(std::remove(codecs_map_.begin(),
925 codecs_map_.end(),
926 proprietary_media_codecs[i]),
927 codecs_map_.end());
928 }
860 } 929 }
861 930
862 //---------------------------------------------------------------------------- 931 //----------------------------------------------------------------------------
863 // Wrappers for the singleton 932 // Wrappers for the singleton
864 //---------------------------------------------------------------------------- 933 //----------------------------------------------------------------------------
865 934
866 bool GetMimeTypeFromExtension(const base::FilePath::StringType& ext, 935 bool GetMimeTypeFromExtension(const base::FilePath::StringType& ext,
867 std::string* mime_type) { 936 std::string* mime_type) {
868 return g_mime_util.Get().GetMimeTypeFromExtension(ext, mime_type); 937 return g_mime_util.Get().GetMimeTypeFromExtension(ext, mime_type);
869 } 938 }
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
1175 post_data->append("\r\n" + value + "\r\n"); 1244 post_data->append("\r\n" + value + "\r\n");
1176 } 1245 }
1177 1246
1178 void AddMultipartFinalDelimiterForUpload(const std::string& mime_boundary, 1247 void AddMultipartFinalDelimiterForUpload(const std::string& mime_boundary,
1179 std::string* post_data) { 1248 std::string* post_data) {
1180 DCHECK(post_data); 1249 DCHECK(post_data);
1181 post_data->append("--" + mime_boundary + "--\r\n"); 1250 post_data->append("--" + mime_boundary + "--\r\n");
1182 } 1251 }
1183 1252
1184 } // namespace net 1253 } // namespace net
OLDNEW
« no previous file with comments | « content/browser/media/media_canplaytype_browsertest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698