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

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: addressing comments 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 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 do not
131 // vector of supported codecs expressions for the mime_type. 125 // have sufficient informatation whether they are supported or not, and vector
132 StrictExpressionMappings strict_mp4_format_map_; 126 // of supported codecs expressions for the mime_type.
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 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 "image/bmp", 274 "image/bmp",
280 "image/vnd.microsoft.icon", // ico 275 "image/vnd.microsoft.icon", // ico
281 "image/x-icon", // ico 276 "image/x-icon", // ico
282 "image/x-xbitmap", // xbm 277 "image/x-xbitmap", // xbm
283 "image/x-png" 278 "image/x-png"
284 }; 279 };
285 280
286 // A list of media types: http://en.wikipedia.org/wiki/Internet_media_type 281 // 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 282 // A comprehensive mime type list: http://plugindoc.mozdev.org/winmime.php
288 // This set of codecs is supported by all variations of Chromium. 283 // This set of codecs is supported by all variations of Chromium.
284 // (Except for 'video/ogg', which is not supported by Android.)
289 static const char* const common_media_types[] = { 285 static const char* const common_media_types[] = {
290 // Ogg. 286 // Ogg.
291 "audio/ogg", 287 "audio/ogg",
292 "application/ogg", 288 "application/ogg",
293 #if !defined(OS_ANDROID) // Android doesn't support Ogg Theora.
294 "video/ogg", 289 "video/ogg",
295 #endif
296 290
297 // WebM. 291 // WebM.
298 "video/webm", 292 "video/webm",
299 "audio/webm", 293 "audio/webm",
300 294
301 // Wav. 295 // Wav.
302 "audio/wav", 296 "audio/wav",
303 "audio/x-wav", 297 "audio/x-wav",
304 298
305 #if defined(OS_ANDROID) 299 #if defined(OS_ANDROID)
(...skipping 12 matching lines...) Expand all
318 "audio/x-m4a", 312 "audio/x-m4a",
319 313
320 // MP3. 314 // MP3.
321 "audio/mp3", 315 "audio/mp3",
322 "audio/x-mp3", 316 "audio/x-mp3",
323 "audio/mpeg", 317 "audio/mpeg",
324 }; 318 };
325 319
326 // List of supported codecs when passed in with <source type="...">. 320 // List of supported codecs when passed in with <source type="...">.
327 // This set of codecs is supported by all variations of Chromium. 321 // This set of codecs is supported by all variations of Chromium.
322 // (Except for 'theora' and 'opus' (http://crbug.com/318436), which are not
323 // supported by Android.)
328 // 324 //
329 // Refer to http://wiki.whatwg.org/wiki/Video_type_parameters#Browser_Support 325 // Refer to http://wiki.whatwg.org/wiki/Video_type_parameters#Browser_Support
330 // for more information. 326 // for more information.
331 // 327 //
332 // The codecs for WAV are integers as defined in Appendix A of RFC2361: 328 // The codecs for WAV are integers as defined in Appendix A of RFC2361:
333 // http://tools.ietf.org/html/rfc2361 329 // http://tools.ietf.org/html/rfc2361
334 static const char* const common_media_codecs[] = { 330 static const char* const common_media_codecs[] = {
335 #if !defined(OS_ANDROID) // Android doesn't support Ogg Theora.
336 "theora", 331 "theora",
337 #endif
338 "opus", 332 "opus",
339 "vorbis", 333 "vorbis",
340 "vp8", 334 "vp8",
341 "vp9", 335 "vp9",
342 "1" // WAVE_FORMAT_PCM. 336 "1" // WAVE_FORMAT_PCM.
343 }; 337 };
344 338
345 // List of proprietary codecs only supported by Google Chrome. 339 // List of proprietary codecs only supported by Google Chrome.
346 static const char* const proprietary_media_codecs[] = { 340 static const char* const proprietary_media_codecs[] = {
347 "avc1", 341 "avc1",
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
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("avc3.4d40??") ||
449 !codec.compare("avc1.4D40??") || !codec.compare("avc3.4D40??") ||
450 !codec.compare("avc1.6400??") || !codec.compare("avc3.6400??")) {
447 return false; 451 return false;
448 } 452 }
453
449 return true; 454 return true;
450 } 455 }
451 456
452 static bool IsMimeTypeSupportedOnAndroid(const std::string& mimeType) { 457 static bool IsMimeTypeSupportedOnAndroid(const std::string& mimeType) {
458 // Ogg Theora is not supported on Android
459 if (!mimeType.compare("video/ogg"))
460 return false;
461
453 // HLS codecs are supported in ICS and above (API level 14) 462 // HLS codecs are supported in ICS and above (API level 14)
454 if ((!mimeType.compare("application/vnd.apple.mpegurl") || 463 if ((!mimeType.compare("application/vnd.apple.mpegurl") ||
455 !mimeType.compare("application/x-mpegurl")) && 464 !mimeType.compare("application/x-mpegurl")) &&
456 base::android::BuildInfo::GetInstance()->sdk_int() < 14) { 465 base::android::BuildInfo::GetInstance()->sdk_int() < 14) {
457 return false; 466 return false;
458 } 467 }
468
459 return true; 469 return true;
460 } 470 }
461 #endif 471 #endif
462 472
463 struct MediaFormatStrict { 473 struct MediaFormatStrict {
464 const char* mime_type; 474 const char* mime_type;
465 const char* codecs_list; 475 const char* codecs_list;
466 }; 476 };
467 477
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: 478 // Following is the list of RFC 6381 compliant codecs:
482 // mp4a.6B - MPEG-1 audio 479 // mp4a.6B - MPEG-1 audio
483 // mp4a.69 - MPEG-2 extension to MPEG-1 480 // mp4a.69 - MPEG-2 extension to MPEG-1
484 // mp4a.67 - MPEG-2 AAC 481 // mp4a.67 - MPEG-2 AAC
485 // mp4a.40.2 - MPEG-4 AAC 482 // mp4a.40.2 - MPEG-4 AAC
486 // mp4a.40.5 - MPEG-4 HE-AAC 483 // mp4a.40.5 - MPEG-4 HE-AACv1
487 // 484 //
488 // avc1.42E0xx - H.264 Baseline 485 // avc1.42E0xx - H.264 Baseline
489 // avc1.4D40xx - H.264 Main 486 // avc1.4D40xx - H.264 Main
490 // avc1.6400xx - H.264 High 487 // avc1.6400xx - H.264 High
488 static const char kProprietaryAudioCodecsExpression[] =
489 "mp4a.6B,mp4a.69,mp4a.67,mp4a.40.2,mp4a.40.5";
490 static const char kProprietaryCodecsExpression[] =
491 "avc1.42E0??,avc1.42e0??,avc1.4D40??,avc1.4d40??,avc1.6400??,"
492 "avc3.42E0??,avc3.42e0??,avc3.4D40??,avc3.4d40??,avc3.6400??,"
493 "mp4a.6B,mp4a.69,mp4a.67,mp4a.40.2,mp4a.40.5";
494
495 static const MediaFormatStrict format_codec_mappings[] = {
496 {"video/webm", "opus,vorbis,vp8,vp8.0,vp9,vp9.0"},
497 {"audio/webm", "opus,vorbis"},
498 {"audio/wav", "1"},
499 {"audio/x-wav", "1"},
500 {"video/ogg", "opus,theora,vorbis"},
501 {"audio/ogg", "opus,vorbis"},
502 {"application/ogg", "opus,theora,vorbis"},
503 {"audio/mpeg", ""},
504 {"audio/mp3", ""},
505 {"audio/x-mp3", ""},
506 {"audio/mp4", kProprietaryAudioCodecsExpression},
507 {"audio/x-m4a", kProprietaryAudioCodecsExpression},
508 {"video/mp4", kProprietaryCodecsExpression},
509 {"video/x-m4v", kProprietaryCodecsExpression},
510 {"application/x-mpegurl", kProprietaryCodecsExpression},
511 {"application/vnd.apple.mpegurl", kProprietaryCodecsExpression}
512 };
513
514 // Following is the list of codecs that are RFC 6381 compliant, but support for
515 // which varies with platform and cannot be determined beforehand.
516 // mp4a.40
517 // avc1
518 // avc3
491 // 519 //
492 // Additionally, several non-RFC compliant codecs are allowed, due to their 520 // Additionally, several non-RFC compliant codecs are allowed, due to their
493 // existing use on web. 521 // existing use on web.
494 // mp4a.40
495 // avc1.xxxxxx 522 // avc1.xxxxxx
496 // avc3.xxxxxx 523 // avc3.xxxxxx
497 // mp4a.6x 524 static const char kInconclusiveProprietaryAudioCodecsExpression[] =
498 static const char kProprietaryAudioCodecsExpression[] = 525 "mp4a.40,mp4a.66,mp4a.68";
499 "mp4a.6?,mp4a.40,mp4a.40.?"; 526 static const char kInconclusiveProprietaryCodecsExpression[] =
500 static const char kProprietaryCodecsExpression[] = 527 "avc1,avc1.??????,avc3,avc3.??????,mp4a.40,mp4a.66,mp4a.68";
501 "avc1,avc3,avc1.??????,avc3.??????,mp4a.6?,mp4a.40,mp4a.40.?";
502 528
503 static const MediaFormatStrict format_mp4_codec_mappings[] = { 529 static const MediaFormatStrict format_inconclusive_codec_mappings[] = {
504 { "audio/mp4", kProprietaryAudioCodecsExpression }, 530 {"audio/mp4", kInconclusiveProprietaryAudioCodecsExpression},
505 { "audio/x-m4a", kProprietaryAudioCodecsExpression }, 531 {"audio/x-m4a", kInconclusiveProprietaryAudioCodecsExpression},
506 { "video/mp4", kProprietaryCodecsExpression }, 532 {"video/mp4", kInconclusiveProprietaryCodecsExpression},
507 { "video/x-m4v", kProprietaryCodecsExpression }, 533 {"video/x-m4v", kInconclusiveProprietaryCodecsExpression},
508 { "application/x-mpegurl", kProprietaryCodecsExpression }, 534 {"application/x-mpegurl", kInconclusiveProprietaryCodecsExpression},
509 { "application/vnd.apple.mpegurl", kProprietaryCodecsExpression } 535 {"application/vnd.apple.mpegurl", kInconclusiveProprietaryCodecsExpression}
510 }; 536 };
511 537
512 MimeUtil::MimeUtil() { 538 MimeUtil::MimeUtil() {
513 InitializeMimeTypeMaps(); 539 InitializeMimeTypeMaps();
514 } 540 }
515 541
516 // static 542 // static
517 bool MimeUtil::AreSupportedCodecs(const MimeMappings& supported_codecs, 543 // Checks all the codecs present in the |codecs| against the entries in
518 const std::vector<std::string>& codecs) { 544 // |supported_codecs|. Returns true only if |codecs| is non-empty and all the
545 // codecs match |supported_codecs| expressions.
546 bool MimeUtil::AreSupportedCodecs(
547 const MimeExpressionMappings& supported_codecs,
548 const std::vector<std::string>& codecs) {
519 if (supported_codecs.empty()) 549 if (supported_codecs.empty())
520 return codecs.empty(); 550 return codecs.empty();
521 551
522 for (size_t i = 0; i < codecs.size(); ++i) { 552 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; 553 bool codec_matched = false;
538 for (size_t j = 0; j < supported_codecs.size(); ++j) { 554 for (size_t j = 0; j < supported_codecs.size(); ++j) {
539 if (!MatchPattern(base::StringPiece(codecs[i]), 555 if (!MatchPattern(base::StringPiece(codecs[i]),
540 base::StringPiece(supported_codecs[j]))) { 556 base::StringPiece(supported_codecs[j]))) {
541 continue; 557 continue;
542 } 558 }
543 // If suffix exists, check whether it is hexadecimal. 559 // If suffix exists, check whether it is hexadecimal.
544 for (size_t wildcard_pos = supported_codecs[j].find('?'); 560 for (size_t wildcard_pos = supported_codecs[j].find('?');
545 wildcard_pos != std::string::npos && 561 wildcard_pos != std::string::npos &&
546 wildcard_pos < supported_codecs[j].length(); 562 wildcard_pos < supported_codecs[j].length();
547 wildcard_pos = supported_codecs[j].find('?', wildcard_pos + 1)) { 563 wildcard_pos = supported_codecs[j].find('?', wildcard_pos + 1)) {
548 // Don't enforce case sensitivity, even though it's called for, as it 564 // Don't enforce case sensitivity, even though it's called for, as it
549 // would break some websites. 565 // would break some websites.
550 if (wildcard_pos >= codecs[i].length() || 566 if (wildcard_pos >= codecs[i].length() ||
551 !IsHexDigit(codecs[i].at(wildcard_pos))) { 567 !IsHexDigit(codecs[i].at(wildcard_pos))) {
552 return false; 568 return false;
553 } 569 }
554 } 570 }
555 codec_matched = true; 571 codec_matched = true;
556 break; 572 break;
557 } 573 }
558 if (!codec_matched) 574 if (!codec_matched)
559 return false; 575 return false;
560 } 576 }
577
561 return !codecs.empty(); 578 return !codecs.empty();
562 } 579 }
563 580
564 void MimeUtil::InitializeMimeTypeMaps() { 581 void MimeUtil::InitializeMimeTypeMaps() {
565 for (size_t i = 0; i < arraysize(supported_image_types); ++i) 582 for (size_t i = 0; i < arraysize(supported_image_types); ++i)
566 image_map_.insert(supported_image_types[i]); 583 image_map_.insert(supported_image_types[i]);
567 584
568 // Initialize the supported non-image types. 585 // Initialize the supported non-image types.
569 for (size_t i = 0; i < arraysize(supported_non_image_types); ++i) 586 for (size_t i = 0; i < arraysize(supported_non_image_types); ++i)
570 non_image_map_.insert(supported_non_image_types[i]); 587 non_image_map_.insert(supported_non_image_types[i]);
(...skipping 29 matching lines...) Expand all
600 #endif 617 #endif
601 618
602 for (size_t i = 0; i < arraysize(supported_javascript_types); ++i) 619 for (size_t i = 0; i < arraysize(supported_javascript_types); ++i)
603 javascript_map_.insert(supported_javascript_types[i]); 620 javascript_map_.insert(supported_javascript_types[i]);
604 621
605 for (size_t i = 0; i < arraysize(common_media_codecs); ++i) { 622 for (size_t i = 0; i < arraysize(common_media_codecs); ++i) {
606 #if defined(OS_ANDROID) 623 #if defined(OS_ANDROID)
607 if (!IsCodecSupportedOnAndroid(common_media_codecs[i])) 624 if (!IsCodecSupportedOnAndroid(common_media_codecs[i]))
608 continue; 625 continue;
609 #endif 626 #endif
610 codecs_map_.insert(common_media_codecs[i]); 627 codecs_map_.push_back(common_media_codecs[i]);
611 } 628 }
612 #if defined(USE_PROPRIETARY_CODECS) 629 #if defined(USE_PROPRIETARY_CODECS)
613 for (size_t i = 0; i < arraysize(proprietary_media_codecs); ++i) 630 for (size_t i = 0; i < arraysize(proprietary_media_codecs); ++i)
614 codecs_map_.insert(proprietary_media_codecs[i]); 631 codecs_map_.push_back(proprietary_media_codecs[i]);
615 #endif 632 #endif
616 633
617 // Initialize the strict supported media types. 634 // Initialize the strict supported media types.
618 for (size_t i = 0; i < arraysize(format_codec_mappings); ++i) { 635 for (size_t i = 0; i < arraysize(format_codec_mappings); ++i) {
619 std::vector<std::string> mime_type_codecs; 636 std::vector<std::string> mime_type_codecs;
620 ParseCodecString(format_codec_mappings[i].codecs_list, 637 ParseCodecString(format_codec_mappings[i].codecs_list,
621 &mime_type_codecs, 638 &mime_type_codecs,
622 false); 639 false);
623 640
624 MimeMappings codecs; 641 MimeExpressionMappings codecs;
625 for (size_t j = 0; j < mime_type_codecs.size(); ++j) { 642 for (size_t j = 0; j < mime_type_codecs.size(); ++j) {
626 #if defined(OS_ANDROID) 643 #if defined(OS_ANDROID)
627 if (!IsCodecSupportedOnAndroid(mime_type_codecs[j])) 644 if (!IsCodecSupportedOnAndroid(mime_type_codecs[j]))
628 continue; 645 continue;
629 #endif 646 #endif
630 codecs.insert(mime_type_codecs[j]); 647 codecs.push_back(mime_type_codecs[j]);
631 } 648 }
632 strict_format_map_[format_codec_mappings[i].mime_type] = codecs; 649 strict_format_map_[format_codec_mappings[i].mime_type] = codecs;
633 } 650 }
634 for (size_t i = 0; i < arraysize(format_mp4_codec_mappings); ++i) { 651 for (size_t i = 0; i < arraysize(format_inconclusive_codec_mappings); ++i) {
635 std::vector<std::string> mime_type_codecs; 652 std::vector<std::string> mime_type_codecs;
636 ParseCodecString( 653 ParseCodecString(
637 format_mp4_codec_mappings[i].codecs_list, &mime_type_codecs, false); 654 format_inconclusive_codec_mappings[i].codecs_list, &mime_type_codecs,
655 false);
638 656
639 MimeExpressionMappings codecs; 657 MimeExpressionMappings codecs;
640 for (size_t j = 0; j < mime_type_codecs.size(); ++j) 658 for (size_t j = 0; j < mime_type_codecs.size(); ++j) {
659 #if defined(OS_ANDROID)
660 if (!IsCodecSupportedOnAndroid(mime_type_codecs[j]))
661 continue;
662 #endif
641 codecs.push_back(mime_type_codecs[j]); 663 codecs.push_back(mime_type_codecs[j]);
642 strict_mp4_format_map_[format_mp4_codec_mappings[i].mime_type] = codecs; 664 }
665 inconclusive_format_map_[format_inconclusive_codec_mappings[i].mime_type] =
666 codecs;
643 } 667 }
644 } 668 }
645 669
646 bool MimeUtil::IsSupportedImageMimeType(const std::string& mime_type) const { 670 bool MimeUtil::IsSupportedImageMimeType(const std::string& mime_type) const {
647 return image_map_.find(mime_type) != image_map_.end(); 671 return image_map_.find(mime_type) != image_map_.end();
648 } 672 }
649 673
650 bool MimeUtil::IsSupportedMediaMimeType(const std::string& mime_type) const { 674 bool MimeUtil::IsSupportedMediaMimeType(const std::string& mime_type) const {
651 return media_map_.find(mime_type) != media_map_.end(); 675 return media_map_.find(mime_type) != media_map_.end();
652 } 676 }
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
814 for (std::vector<std::string>::iterator it = codecs_out->begin(); 838 for (std::vector<std::string>::iterator it = codecs_out->begin();
815 it != codecs_out->end(); 839 it != codecs_out->end();
816 ++it) { 840 ++it) {
817 size_t found = it->find_first_of('.'); 841 size_t found = it->find_first_of('.');
818 if (found != std::string::npos) 842 if (found != std::string::npos)
819 it->resize(found); 843 it->resize(found);
820 } 844 }
821 } 845 }
822 846
823 bool MimeUtil::IsStrictMediaMimeType(const std::string& mime_type) const { 847 bool MimeUtil::IsStrictMediaMimeType(const std::string& mime_type) const {
824 if (strict_format_map_.find(mime_type) == strict_format_map_.end() && 848 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; 849 return false;
827 return true; 850 return true;
828 } 851 }
829 852
830 SupportsType MimeUtil::IsSupportedStrictMediaMimeType( 853 SupportsType MimeUtil::IsSupportedStrictMediaMimeType(
831 const std::string& mime_type, 854 const std::string& mime_type,
832 const std::vector<std::string>& codecs) const { 855 const std::vector<std::string>& codecs) const {
833 StrictMappings::const_iterator it_strict_map = 856 StrictExpressionMappings::const_iterator it_strict_map =
834 strict_format_map_.find(mime_type); 857 strict_format_map_.find(mime_type);
835 if ((it_strict_map != strict_format_map_.end()) && 858 if ((it_strict_map != strict_format_map_.end()) &&
836 AreSupportedCodecs(it_strict_map->second, codecs)) { 859 AreSupportedCodecs(it_strict_map->second, codecs)) {
837 return IsSupported; 860 return IsSupported;
838 } 861 }
839 862
840 StrictExpressionMappings::const_iterator it_expression_map = 863 StrictExpressionMappings::const_iterator it_expression_map =
841 strict_mp4_format_map_.find(mime_type); 864 inconclusive_format_map_.find(mime_type);
842 if ((it_expression_map != strict_mp4_format_map_.end()) && 865 if (it_expression_map != inconclusive_format_map_.end()) {
843 AreSupportedCodecsWithProfile(it_expression_map->second, codecs)) { 866 MimeExpressionMappings all_supported_codecs = it_expression_map->second;
amogh.bihani 2014/07/11 09:03:53 Now the coping part has moved here :(. I am sorry
Ryan Sleevi 2014/07/11 18:51:17 I'm sorry, I'm still not clear why you need to sto
844 return MayBeSupported; 867 if (it_strict_map != strict_format_map_.end()) {
868 all_supported_codecs.insert(all_supported_codecs.end(),
869 it_strict_map->second.begin(), it_strict_map->second.end());
870 }
871 if (AreSupportedCodecs(all_supported_codecs, codecs))
872 return MayBeSupported;
845 } 873 }
846 874
847 if (codecs.empty()) 875 if (codecs.empty())
848 return MayBeSupported; 876 return MayBeSupported;
849 877
850 return IsNotSupported; 878 return IsNotSupported;
851 } 879 }
852 880
853 void MimeUtil::RemoveProprietaryMediaTypesAndCodecsForTests() { 881 void MimeUtil::RemoveProprietaryMediaTypesAndCodecsForTests() {
854 for (size_t i = 0; i < arraysize(proprietary_media_types); ++i) { 882 for (size_t i = 0; i < arraysize(proprietary_media_types); ++i) {
855 non_image_map_.erase(proprietary_media_types[i]); 883 non_image_map_.erase(proprietary_media_types[i]);
856 media_map_.erase(proprietary_media_types[i]); 884 media_map_.erase(proprietary_media_types[i]);
857 } 885 }
858 for (size_t i = 0; i < arraysize(proprietary_media_codecs); ++i) 886 for (size_t i = 0; i < arraysize(proprietary_media_codecs); ++i) {
859 codecs_map_.erase(proprietary_media_codecs[i]); 887 codecs_map_.erase(std::remove(codecs_map_.begin(),
888 codecs_map_.end(),
889 proprietary_media_codecs[i]),
890 codecs_map_.end());
891 }
860 } 892 }
861 893
862 //---------------------------------------------------------------------------- 894 //----------------------------------------------------------------------------
863 // Wrappers for the singleton 895 // Wrappers for the singleton
864 //---------------------------------------------------------------------------- 896 //----------------------------------------------------------------------------
865 897
866 bool GetMimeTypeFromExtension(const base::FilePath::StringType& ext, 898 bool GetMimeTypeFromExtension(const base::FilePath::StringType& ext,
867 std::string* mime_type) { 899 std::string* mime_type) {
868 return g_mime_util.Get().GetMimeTypeFromExtension(ext, mime_type); 900 return g_mime_util.Get().GetMimeTypeFromExtension(ext, mime_type);
869 } 901 }
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
1175 post_data->append("\r\n" + value + "\r\n"); 1207 post_data->append("\r\n" + value + "\r\n");
1176 } 1208 }
1177 1209
1178 void AddMultipartFinalDelimiterForUpload(const std::string& mime_boundary, 1210 void AddMultipartFinalDelimiterForUpload(const std::string& mime_boundary,
1179 std::string* post_data) { 1211 std::string* post_data) {
1180 DCHECK(post_data); 1212 DCHECK(post_data);
1181 post_data->append("--" + mime_boundary + "--\r\n"); 1213 post_data->append("--" + mime_boundary + "--\r\n");
1182 } 1214 }
1183 1215
1184 } // namespace net 1216 } // 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