Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <algorithm> | 5 #include <algorithm> |
| 6 #include <iterator> | 6 #include <iterator> |
| 7 #include <map> | 7 #include <map> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #if defined(OS_ANDROID) | |
| 11 #include "base/android/build_info.h" | |
|
scherkus (not reviewing)
2013/11/09 00:20:05
typically #if #includes are put after the first bl
vignesh
2013/11/11 19:55:34
Done.
| |
| 12 #endif | |
| 10 #include "base/containers/hash_tables.h" | 13 #include "base/containers/hash_tables.h" |
| 11 #include "base/lazy_instance.h" | 14 #include "base/lazy_instance.h" |
| 12 #include "base/logging.h" | 15 #include "base/logging.h" |
| 13 #include "base/stl_util.h" | 16 #include "base/stl_util.h" |
| 14 #include "base/strings/string_split.h" | 17 #include "base/strings/string_split.h" |
| 15 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
| 16 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
| 17 #include "net/base/mime_util.h" | 20 #include "net/base/mime_util.h" |
| 18 #include "net/base/platform_mime_util.h" | 21 #include "net/base/platform_mime_util.h" |
| 19 | 22 |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 286 "video/x-m4v", | 289 "video/x-m4v", |
| 287 "audio/mp4", | 290 "audio/mp4", |
| 288 "audio/x-m4a", | 291 "audio/x-m4a", |
| 289 | 292 |
| 290 // MP3. | 293 // MP3. |
| 291 "audio/mp3", | 294 "audio/mp3", |
| 292 "audio/x-mp3", | 295 "audio/x-mp3", |
| 293 "audio/mpeg", | 296 "audio/mpeg", |
| 294 }; | 297 }; |
| 295 | 298 |
| 299 struct CommonMediaCodec { | |
| 300 const char* codec; | |
| 301 #if defined(OS_ANDROID) | |
| 302 const int min_api_level; | |
| 303 #endif | |
| 304 }; | |
| 305 | |
| 296 // List of supported codecs when passed in with <source type="...">. | 306 // List of supported codecs when passed in with <source type="...">. |
| 297 // This set of codecs is supported by all variations of Chromium. | 307 // This set of codecs is supported by all variations of Chromium. |
| 308 // For android this also lists the minimum API level from which the codec is | |
| 309 // supported. | |
| 298 // | 310 // |
| 299 // Refer to http://wiki.whatwg.org/wiki/Video_type_parameters#Browser_Support | 311 // Refer to http://wiki.whatwg.org/wiki/Video_type_parameters#Browser_Support |
| 300 // for more information. | 312 // for more information. |
| 301 // | 313 // |
| 302 // The codecs for WAV are integers as defined in Appendix A of RFC2361: | 314 // The codecs for WAV are integers as defined in Appendix A of RFC2361: |
| 303 // http://tools.ietf.org/html/rfc2361 | 315 // http://tools.ietf.org/html/rfc2361 |
| 304 static const char* const common_media_codecs[] = { | 316 static const CommonMediaCodec common_media_codecs[] = { |
| 305 #if !defined(OS_ANDROID) // Android doesn't support Ogg Theora. | 317 #if !defined(OS_ANDROID) |
| 306 "theora", | 318 { "theora" }, |
| 307 "vp9", // TODO(tomfinegan): Move vp9 back down with vp8 once VP9 is supported | 319 { "vorbis" }, |
| 308 // on Android. https://crbug.com/285016 | 320 { "vp8" }, |
| 321 { "vp9" }, | |
| 322 { "1" } // WAVE_FORMAT_PCM. | |
| 323 #else | |
| 324 { "vorbis", 0 }, | |
| 325 { "vp8", 0 }, | |
| 326 { "vp9", 19 }, // VP9 supported only in Kitkat+. | |
|
scherkus (not reviewing)
2013/11/09 00:20:05
it seems unfortunate to duplicate both lists and m
vignesh
2013/11/11 16:07:10
if duplication is your only concern, then how abou
vignesh
2013/11/11 19:55:34
Hardcoding this as discussed on other comments.
| |
| 327 { "1", 0 } // WAVE_FORMAT_PCM. | |
| 309 #endif | 328 #endif |
| 310 "vorbis", | |
| 311 "vp8", | |
| 312 "1" // WAVE_FORMAT_PCM. | |
| 313 }; | 329 }; |
| 314 | 330 |
| 315 // List of proprietary codecs only supported by Google Chrome. | 331 // List of proprietary codecs only supported by Google Chrome. |
| 316 static const char* const proprietary_media_codecs[] = { | 332 static const char* const proprietary_media_codecs[] = { |
| 317 "avc1", | 333 "avc1", |
| 318 "avc3", | 334 "avc3", |
| 319 "mp4a" | 335 "mp4a" |
| 320 }; | 336 }; |
| 321 | 337 |
| 322 // Note: does not include javascript types list (see supported_javascript_types) | 338 // Note: does not include javascript types list (see supported_javascript_types) |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 405 "text/javascript1.1", | 421 "text/javascript1.1", |
| 406 "text/javascript1.2", | 422 "text/javascript1.2", |
| 407 "text/javascript1.3", | 423 "text/javascript1.3", |
| 408 "text/jscript", | 424 "text/jscript", |
| 409 "text/livescript" | 425 "text/livescript" |
| 410 }; | 426 }; |
| 411 | 427 |
| 412 struct MediaFormatStrict { | 428 struct MediaFormatStrict { |
| 413 const char* mime_type; | 429 const char* mime_type; |
| 414 const char* codecs_list; | 430 const char* codecs_list; |
| 431 #if defined(OS_ANDROID) | |
| 432 const int* min_api_levels; | |
| 433 #endif | |
| 415 }; | 434 }; |
| 416 | 435 |
| 417 static const MediaFormatStrict format_codec_mappings[] = { | 436 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) | 437 #if !defined(OS_ANDROID) |
| 421 { "video/webm", "vorbis,vp8,vp8.0,vp9,vp9.0" }, | 438 { "video/webm", "vorbis,vp8,vp8.0,vp9,vp9.0" }, |
| 422 #else | |
| 423 { "video/webm", "vorbis,vp8,vp8.0" }, | |
| 424 #endif | |
| 425 { "audio/webm", "vorbis" }, | 439 { "audio/webm", "vorbis" }, |
| 426 { "audio/wav", "1" } | 440 { "audio/wav", "1" } |
| 441 #else | |
| 442 { "video/webm", "vorbis,vp8,vp8.0,vp9,vp9.0", (int[]) { 0, 0, 0, 19, 19 } }, | |
| 443 { "audio/webm", "vorbis", (int[]) { 0 } }, | |
| 444 { "audio/wav", "1", (int[]) { 0 } } | |
| 445 #endif | |
| 427 }; | 446 }; |
| 428 | 447 |
| 429 MimeUtil::MimeUtil() { | 448 MimeUtil::MimeUtil() { |
| 430 InitializeMimeTypeMaps(); | 449 InitializeMimeTypeMaps(); |
| 431 } | 450 } |
| 432 | 451 |
| 433 // static | 452 // static |
| 434 bool MimeUtil::AreSupportedCodecs(const MimeMappings& supported_codecs, | 453 bool MimeUtil::AreSupportedCodecs(const MimeMappings& supported_codecs, |
| 435 const std::vector<std::string>& codecs) { | 454 const std::vector<std::string>& codecs) { |
| 436 for (size_t i = 0; i < codecs.size(); ++i) { | 455 for (size_t i = 0; i < codecs.size(); ++i) { |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 464 for (size_t i = 0; i < arraysize(common_media_types); ++i) | 483 for (size_t i = 0; i < arraysize(common_media_types); ++i) |
| 465 media_map_.insert(common_media_types[i]); | 484 media_map_.insert(common_media_types[i]); |
| 466 #if defined(USE_PROPRIETARY_CODECS) | 485 #if defined(USE_PROPRIETARY_CODECS) |
| 467 for (size_t i = 0; i < arraysize(proprietary_media_types); ++i) | 486 for (size_t i = 0; i < arraysize(proprietary_media_types); ++i) |
| 468 media_map_.insert(proprietary_media_types[i]); | 487 media_map_.insert(proprietary_media_types[i]); |
| 469 #endif | 488 #endif |
| 470 | 489 |
| 471 for (size_t i = 0; i < arraysize(supported_javascript_types); ++i) | 490 for (size_t i = 0; i < arraysize(supported_javascript_types); ++i) |
| 472 javascript_map_.insert(supported_javascript_types[i]); | 491 javascript_map_.insert(supported_javascript_types[i]); |
| 473 | 492 |
| 474 for (size_t i = 0; i < arraysize(common_media_codecs); ++i) | 493 for (size_t i = 0; i < arraysize(common_media_codecs); ++i) |
|
scherkus (not reviewing)
2013/11/09 00:31:00
we'll also need { }s for this for loop and one bel
vignesh
2013/11/11 19:55:34
Done.
| |
| 475 codecs_map_.insert(common_media_codecs[i]); | 494 #if defined(OS_ANDROID) |
| 495 if (base::android::BuildInfo::GetInstance()->sdk_int() >= | |
| 496 common_media_codecs[i].min_api_level) | |
| 497 #endif | |
| 498 codecs_map_.insert(common_media_codecs[i].codec); | |
| 476 #if defined(USE_PROPRIETARY_CODECS) | 499 #if defined(USE_PROPRIETARY_CODECS) |
| 477 for (size_t i = 0; i < arraysize(proprietary_media_codecs); ++i) | 500 for (size_t i = 0; i < arraysize(proprietary_media_codecs); ++i) |
| 478 codecs_map_.insert(proprietary_media_codecs[i]); | 501 codecs_map_.insert(proprietary_media_codecs[i]); |
| 479 #endif | 502 #endif |
| 480 | 503 |
| 481 // Initialize the strict supported media types. | 504 // Initialize the strict supported media types. |
| 482 for (size_t i = 0; i < arraysize(format_codec_mappings); ++i) { | 505 for (size_t i = 0; i < arraysize(format_codec_mappings); ++i) { |
| 483 std::vector<std::string> mime_type_codecs; | 506 std::vector<std::string> mime_type_codecs; |
| 484 ParseCodecString(format_codec_mappings[i].codecs_list, | 507 ParseCodecString(format_codec_mappings[i].codecs_list, |
| 485 &mime_type_codecs, | 508 &mime_type_codecs, |
| 486 false); | 509 false); |
| 487 | 510 |
| 488 MimeMappings codecs; | 511 MimeMappings codecs; |
| 489 for (size_t j = 0; j < mime_type_codecs.size(); ++j) | 512 for (size_t j = 0; j < mime_type_codecs.size(); ++j) |
| 513 #if defined(OS_ANDROID) | |
| 514 if (base::android::BuildInfo::GetInstance()->sdk_int() >= | |
| 515 format_codec_mappings[i].min_api_levels[j]) | |
| 516 #endif | |
| 490 codecs.insert(mime_type_codecs[j]); | 517 codecs.insert(mime_type_codecs[j]); |
| 491 strict_format_map_[format_codec_mappings[i].mime_type] = codecs; | 518 strict_format_map_[format_codec_mappings[i].mime_type] = codecs; |
| 492 } | 519 } |
| 493 } | 520 } |
| 494 | 521 |
| 495 bool MimeUtil::IsSupportedImageMimeType(const std::string& mime_type) const { | 522 bool MimeUtil::IsSupportedImageMimeType(const std::string& mime_type) const { |
| 496 return image_map_.find(mime_type) != image_map_.end(); | 523 return image_map_.find(mime_type) != image_map_.end(); |
| 497 } | 524 } |
| 498 | 525 |
| 499 bool MimeUtil::IsSupportedMediaMimeType(const std::string& mime_type) const { | 526 bool MimeUtil::IsSupportedMediaMimeType(const std::string& mime_type) const { |
| (...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1000 post_data->append("\r\n" + value + "\r\n"); | 1027 post_data->append("\r\n" + value + "\r\n"); |
| 1001 } | 1028 } |
| 1002 | 1029 |
| 1003 void AddMultipartFinalDelimiterForUpload(const std::string& mime_boundary, | 1030 void AddMultipartFinalDelimiterForUpload(const std::string& mime_boundary, |
| 1004 std::string* post_data) { | 1031 std::string* post_data) { |
| 1005 DCHECK(post_data); | 1032 DCHECK(post_data); |
| 1006 post_data->append("--" + mime_boundary + "--\r\n"); | 1033 post_data->append("--" + mime_boundary + "--\r\n"); |
| 1007 } | 1034 } |
| 1008 | 1035 |
| 1009 } // namespace net | 1036 } // namespace net |
| OLD | NEW |