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

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

Issue 66863003: Add VP9 to canPlayType on Android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: hardcoding vp9 android version check Created 7 years, 1 month 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 | « no previous file | 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"
11 #include "base/lazy_instance.h" 11 #include "base/lazy_instance.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/stl_util.h" 13 #include "base/stl_util.h"
14 #include "base/strings/string_split.h" 14 #include "base/strings/string_split.h"
15 #include "base/strings/string_util.h" 15 #include "base/strings/string_util.h"
16 #include "base/strings/utf_string_conversions.h" 16 #include "base/strings/utf_string_conversions.h"
17 #include "net/base/mime_util.h" 17 #include "net/base/mime_util.h"
18 #include "net/base/platform_mime_util.h" 18 #include "net/base/platform_mime_util.h"
19 19
20 #if defined(OS_ANDROID)
21 #include "base/android/build_info.h"
22 #endif
23
20 using std::string; 24 using std::string;
21 25
22 namespace { 26 namespace {
23 27
24 struct MediaType { 28 struct MediaType {
25 const char name[12]; 29 const char name[12];
26 const char matcher[13]; 30 const char matcher[13];
27 }; 31 };
28 32
29 static const MediaType kIanaMediaTypes[] = { 33 static const MediaType kIanaMediaTypes[] = {
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 // This set of codecs is supported by all variations of Chromium. 301 // This set of codecs is supported by all variations of Chromium.
298 // 302 //
299 // Refer to http://wiki.whatwg.org/wiki/Video_type_parameters#Browser_Support 303 // Refer to http://wiki.whatwg.org/wiki/Video_type_parameters#Browser_Support
300 // for more information. 304 // for more information.
301 // 305 //
302 // The codecs for WAV are integers as defined in Appendix A of RFC2361: 306 // The codecs for WAV are integers as defined in Appendix A of RFC2361:
303 // http://tools.ietf.org/html/rfc2361 307 // http://tools.ietf.org/html/rfc2361
304 static const char* const common_media_codecs[] = { 308 static const char* const common_media_codecs[] = {
305 #if !defined(OS_ANDROID) // Android doesn't support Ogg Theora. 309 #if !defined(OS_ANDROID) // Android doesn't support Ogg Theora.
306 "theora", 310 "theora",
307 "vp9", // TODO(tomfinegan): Move vp9 back down with vp8 once VP9 is supported
308 // on Android. https://crbug.com/285016
309 #endif 311 #endif
310 "vorbis", 312 "vorbis",
311 "vp8", 313 "vp8",
314 "vp9",
312 "1" // WAVE_FORMAT_PCM. 315 "1" // WAVE_FORMAT_PCM.
313 }; 316 };
314 317
315 // List of proprietary codecs only supported by Google Chrome. 318 // List of proprietary codecs only supported by Google Chrome.
316 static const char* const proprietary_media_codecs[] = { 319 static const char* const proprietary_media_codecs[] = {
317 "avc1", 320 "avc1",
318 "avc3", 321 "avc3",
319 "mp4a" 322 "mp4a"
320 }; 323 };
321 324
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 "application/javascript", 405 "application/javascript",
403 "application/ecmascript", 406 "application/ecmascript",
404 "application/x-javascript", 407 "application/x-javascript",
405 "text/javascript1.1", 408 "text/javascript1.1",
406 "text/javascript1.2", 409 "text/javascript1.2",
407 "text/javascript1.3", 410 "text/javascript1.3",
408 "text/jscript", 411 "text/jscript",
409 "text/livescript" 412 "text/livescript"
410 }; 413 };
411 414
415 #if defined(OS_ANDROID)
416 static bool IsCodecSupportedOnAndroid(std::string codec) {
scherkus (not reviewing) 2013/11/11 21:33:46 const-ref
vignesh 2013/11/12 00:02:48 Done.
417 // VP9 is supported only in KitKat+ (API Level 19).
418 if ((!codec.compare("vp9") || !codec.compare("vp9.0")) &&
419 base::android::BuildInfo::GetInstance()->sdk_int() < 19)
420 return false;
qinmin 2013/11/11 21:52:50 you need {} as the if statement contains multiple
vignesh 2013/11/12 00:02:48 Done.
421 return true;
422 }
423 #endif
424
412 struct MediaFormatStrict { 425 struct MediaFormatStrict {
413 const char* mime_type; 426 const char* mime_type;
414 const char* codecs_list; 427 const char* codecs_list;
415 }; 428 };
416 429
417 static const MediaFormatStrict format_codec_mappings[] = { 430 static const MediaFormatStrict format_codec_mappings[] = {
418 // TODO(tomfinegan): Remove this if/else when VP9 is supported on Android.
419 // https://crbug.com/285016
420 #if !defined(OS_ANDROID)
421 { "video/webm", "vorbis,vp8,vp8.0,vp9,vp9.0" }, 431 { "video/webm", "vorbis,vp8,vp8.0,vp9,vp9.0" },
422 #else
423 { "video/webm", "vorbis,vp8,vp8.0" },
424 #endif
425 { "audio/webm", "vorbis" }, 432 { "audio/webm", "vorbis" },
426 { "audio/wav", "1" } 433 { "audio/wav", "1" }
427 }; 434 };
428 435
429 MimeUtil::MimeUtil() { 436 MimeUtil::MimeUtil() {
430 InitializeMimeTypeMaps(); 437 InitializeMimeTypeMaps();
431 } 438 }
432 439
433 // static 440 // static
434 bool MimeUtil::AreSupportedCodecs(const MimeMappings& supported_codecs, 441 bool MimeUtil::AreSupportedCodecs(const MimeMappings& supported_codecs,
(...skipping 29 matching lines...) Expand all
464 for (size_t i = 0; i < arraysize(common_media_types); ++i) 471 for (size_t i = 0; i < arraysize(common_media_types); ++i)
465 media_map_.insert(common_media_types[i]); 472 media_map_.insert(common_media_types[i]);
466 #if defined(USE_PROPRIETARY_CODECS) 473 #if defined(USE_PROPRIETARY_CODECS)
467 for (size_t i = 0; i < arraysize(proprietary_media_types); ++i) 474 for (size_t i = 0; i < arraysize(proprietary_media_types); ++i)
468 media_map_.insert(proprietary_media_types[i]); 475 media_map_.insert(proprietary_media_types[i]);
469 #endif 476 #endif
470 477
471 for (size_t i = 0; i < arraysize(supported_javascript_types); ++i) 478 for (size_t i = 0; i < arraysize(supported_javascript_types); ++i)
472 javascript_map_.insert(supported_javascript_types[i]); 479 javascript_map_.insert(supported_javascript_types[i]);
473 480
474 for (size_t i = 0; i < arraysize(common_media_codecs); ++i) 481 for (size_t i = 0; i < arraysize(common_media_codecs); ++i) {
482 #if defined(OS_ANDROID)
483 if (IsCodecSupportedOnAndroid(common_media_codecs[i]))
scherkus (not reviewing) 2013/11/11 21:33:46 technically line 485 should be indented as this if
vignesh 2013/11/12 00:02:48 Nice idea. Done.
484 #endif
475 codecs_map_.insert(common_media_codecs[i]); 485 codecs_map_.insert(common_media_codecs[i]);
486 }
476 #if defined(USE_PROPRIETARY_CODECS) 487 #if defined(USE_PROPRIETARY_CODECS)
477 for (size_t i = 0; i < arraysize(proprietary_media_codecs); ++i) 488 for (size_t i = 0; i < arraysize(proprietary_media_codecs); ++i)
478 codecs_map_.insert(proprietary_media_codecs[i]); 489 codecs_map_.insert(proprietary_media_codecs[i]);
479 #endif 490 #endif
480 491
481 // Initialize the strict supported media types. 492 // Initialize the strict supported media types.
482 for (size_t i = 0; i < arraysize(format_codec_mappings); ++i) { 493 for (size_t i = 0; i < arraysize(format_codec_mappings); ++i) {
483 std::vector<std::string> mime_type_codecs; 494 std::vector<std::string> mime_type_codecs;
484 ParseCodecString(format_codec_mappings[i].codecs_list, 495 ParseCodecString(format_codec_mappings[i].codecs_list,
485 &mime_type_codecs, 496 &mime_type_codecs,
486 false); 497 false);
487 498
488 MimeMappings codecs; 499 MimeMappings codecs;
489 for (size_t j = 0; j < mime_type_codecs.size(); ++j) 500 for (size_t j = 0; j < mime_type_codecs.size(); ++j) {
501 #if defined(OS_ANDROID)
502 if (IsCodecSupportedOnAndroid(mime_type_codecs[j]))
scherkus (not reviewing) 2013/11/11 21:33:46 ditto
vignesh 2013/11/12 00:02:48 Done.
503 #endif
490 codecs.insert(mime_type_codecs[j]); 504 codecs.insert(mime_type_codecs[j]);
505 }
491 strict_format_map_[format_codec_mappings[i].mime_type] = codecs; 506 strict_format_map_[format_codec_mappings[i].mime_type] = codecs;
492 } 507 }
493 } 508 }
494 509
495 bool MimeUtil::IsSupportedImageMimeType(const std::string& mime_type) const { 510 bool MimeUtil::IsSupportedImageMimeType(const std::string& mime_type) const {
496 return image_map_.find(mime_type) != image_map_.end(); 511 return image_map_.find(mime_type) != image_map_.end();
497 } 512 }
498 513
499 bool MimeUtil::IsSupportedMediaMimeType(const std::string& mime_type) const { 514 bool MimeUtil::IsSupportedMediaMimeType(const std::string& mime_type) const {
500 return media_map_.find(mime_type) != media_map_.end(); 515 return media_map_.find(mime_type) != media_map_.end();
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after
1000 post_data->append("\r\n" + value + "\r\n"); 1015 post_data->append("\r\n" + value + "\r\n");
1001 } 1016 }
1002 1017
1003 void AddMultipartFinalDelimiterForUpload(const std::string& mime_boundary, 1018 void AddMultipartFinalDelimiterForUpload(const std::string& mime_boundary,
1004 std::string* post_data) { 1019 std::string* post_data) {
1005 DCHECK(post_data); 1020 DCHECK(post_data);
1006 post_data->append("--" + mime_boundary + "--\r\n"); 1021 post_data->append("--" + mime_boundary + "--\r\n");
1007 } 1022 }
1008 1023
1009 } // namespace net 1024 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698