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

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