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

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

Issue 812643005: Re-add AC3/EAC3 audio demuxing support (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed unit tests Created 5 years, 9 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
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 30 matching lines...) Expand all
41 MPEG4_AAC_SBR_v1, 41 MPEG4_AAC_SBR_v1,
42 MPEG4_AAC_SBR_PS_v2, 42 MPEG4_AAC_SBR_PS_v2,
43 VORBIS, 43 VORBIS,
44 OPUS, 44 OPUS,
45 H264_BASELINE, 45 H264_BASELINE,
46 H264_MAIN, 46 H264_MAIN,
47 H264_HIGH, 47 H264_HIGH,
48 VP8, 48 VP8,
49 VP9, 49 VP9,
50 THEORA 50 THEORA
51 #if defined(ENABLE_AC3_EAC3_AUDIO_DEMUXING)
52 ,
53 AC3,
54 EAC3
55 #endif
51 }; 56 };
52 57
53 bool GetMimeTypeFromExtension(const base::FilePath::StringType& ext, 58 bool GetMimeTypeFromExtension(const base::FilePath::StringType& ext,
54 std::string* mime_type) const; 59 std::string* mime_type) const;
55 60
56 bool GetMimeTypeFromFile(const base::FilePath& file_path, 61 bool GetMimeTypeFromFile(const base::FilePath& file_path,
57 std::string* mime_type) const; 62 std::string* mime_type) const;
58 63
59 bool GetWellKnownMimeTypeFromExtension(const base::FilePath::StringType& ext, 64 bool GetWellKnownMimeTypeFromExtension(const base::FilePath::StringType& ext,
60 std::string* mime_type) const; 65 std::string* mime_type) const;
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 case MimeUtil::VP8: 470 case MimeUtil::VP8:
466 case MimeUtil::VORBIS: 471 case MimeUtil::VORBIS:
467 return true; 472 return true;
468 473
469 case MimeUtil::MPEG2_AAC_LC: 474 case MimeUtil::MPEG2_AAC_LC:
470 case MimeUtil::MPEG2_AAC_MAIN: 475 case MimeUtil::MPEG2_AAC_MAIN:
471 case MimeUtil::MPEG2_AAC_SSR: 476 case MimeUtil::MPEG2_AAC_SSR:
472 // MPEG-2 variants of AAC are not supported on Android. 477 // MPEG-2 variants of AAC are not supported on Android.
473 return false; 478 return false;
474 479
480 #if defined(ENABLE_AC3_EAC3_AUDIO_DEMUXING)
481 case MimeUtil::AC3:
482 case MimeUtil::EAC3:
483 // TODO(servolk): Revisit this for AC3/EAC3 support on AndroidTV
484 return false;
485 #endif
486
475 case MimeUtil::VP9: 487 case MimeUtil::VP9:
476 // VP9 is supported only in KitKat+ (API Level 19). 488 // VP9 is supported only in KitKat+ (API Level 19).
477 return base::android::BuildInfo::GetInstance()->sdk_int() >= 19; 489 return base::android::BuildInfo::GetInstance()->sdk_int() >= 19;
478 490
479 case MimeUtil::OPUS: 491 case MimeUtil::OPUS:
480 // Opus is supported only in Lollipop+ (API Level 21). 492 // Opus is supported only in Lollipop+ (API Level 21).
481 return base::android::BuildInfo::GetInstance()->sdk_int() >= 21; 493 return base::android::BuildInfo::GetInstance()->sdk_int() >= 21;
482 494
483 case MimeUtil::THEORA: 495 case MimeUtil::THEORA:
484 return false; 496 return false;
(...skipping 29 matching lines...) Expand all
514 // mp4a.40.5 - MPEG-4 HE-AAC v1 (AAC LC + SBR) 526 // mp4a.40.5 - MPEG-4 HE-AAC v1 (AAC LC + SBR)
515 // mp4a.40.05 - MPEG-4 HE-AAC v1 (AAC LC + SBR) (leading 0 in aud-oti for 527 // mp4a.40.05 - MPEG-4 HE-AAC v1 (AAC LC + SBR) (leading 0 in aud-oti for
516 // compatibility) 528 // compatibility)
517 // mp4a.40.29 - MPEG-4 HE-AAC v2 (AAC LC + SBR + PS) 529 // mp4a.40.29 - MPEG-4 HE-AAC v2 (AAC LC + SBR + PS)
518 // 530 //
519 // avc1.42E0xx - H.264 Baseline 531 // avc1.42E0xx - H.264 Baseline
520 // avc1.4D40xx - H.264 Main 532 // avc1.4D40xx - H.264 Main
521 // avc1.6400xx - H.264 High 533 // avc1.6400xx - H.264 High
522 static const char kMP4AudioCodecsExpression[] = 534 static const char kMP4AudioCodecsExpression[] =
523 "mp4a.66,mp4a.67,mp4a.68,mp4a.69,mp4a.6B,mp4a.40.2,mp4a.40.02,mp4a.40.5," 535 "mp4a.66,mp4a.67,mp4a.68,mp4a.69,mp4a.6B,mp4a.40.2,mp4a.40.02,mp4a.40.5,"
536 #if defined(ENABLE_AC3_EAC3_AUDIO_DEMUXING)
537 "ac-3,ec-3," // Note: only one variant of eac codec string is sufficient
538 // here since these are converted into enums in
539 // InitializeMimeTypeMaps
540 #endif
524 "mp4a.40.05,mp4a.40.29"; 541 "mp4a.40.05,mp4a.40.29";
525 static const char kMP4VideoCodecsExpression[] = 542 static const char kMP4VideoCodecsExpression[] =
526 // This is not a complete list of supported avc1 codecs. It is simply used 543 // This is not a complete list of supported avc1 codecs. It is simply used
527 // to register support for the corresponding Codec enum. Instead of using 544 // to register support for the corresponding Codec enum. Instead of using
528 // strings in these three arrays, we should use the Codec enum values. 545 // strings in these three arrays, we should use the Codec enum values.
529 // This will avoid confusion and unnecessary parsing at runtime. 546 // This will avoid confusion and unnecessary parsing at runtime.
530 // kUnambiguousCodecStringMap/kAmbiguousCodecStringMap should be the only 547 // kUnambiguousCodecStringMap/kAmbiguousCodecStringMap should be the only
531 // mapping from strings to codecs. See crbug.com/461009. 548 // mapping from strings to codecs. See crbug.com/461009.
532 "avc1.42E00A,avc1.4D400A,avc1.64000A," 549 "avc1.42E00A,avc1.4D400A,avc1.64000A,"
550 #if defined(ENABLE_AC3_EAC3_AUDIO_DEMUXING)
551 "ac-3,ec-3," // Note: only one variant of eac codec string is sufficient
552 // here since these are converted into enums in
553 // InitializeMimeTypeMaps
554 #endif
533 "mp4a.66,mp4a.67,mp4a.68,mp4a.69,mp4a.6B,mp4a.40.2,mp4a.40.02,mp4a.40.5," 555 "mp4a.66,mp4a.67,mp4a.68,mp4a.69,mp4a.6B,mp4a.40.2,mp4a.40.02,mp4a.40.5,"
534 "mp4a.40.05,mp4a.40.29"; 556 "mp4a.40.05,mp4a.40.29";
535 557
536 // These containers are also included in 558 // These containers are also included in
537 // common_media_types/proprietary_media_types. See crbug.com/461012. 559 // common_media_types/proprietary_media_types. See crbug.com/461012.
538 static const MediaFormatStrict format_codec_mappings[] = { 560 static const MediaFormatStrict format_codec_mappings[] = {
539 {"video/webm", "opus,vorbis,vp8,vp8.0,vp9,vp9.0"}, 561 {"video/webm", "opus,vorbis,vp8,vp8.0,vp9,vp9.0"},
540 {"audio/webm", "opus,vorbis"}, 562 {"audio/webm", "opus,vorbis"},
541 {"audio/wav", "1"}, 563 {"audio/wav", "1"},
542 {"audio/x-wav", "1"}, 564 {"audio/x-wav", "1"},
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
576 {"mp4a.66", MimeUtil::MPEG2_AAC_MAIN}, 598 {"mp4a.66", MimeUtil::MPEG2_AAC_MAIN},
577 {"mp4a.67", MimeUtil::MPEG2_AAC_LC}, 599 {"mp4a.67", MimeUtil::MPEG2_AAC_LC},
578 {"mp4a.68", MimeUtil::MPEG2_AAC_SSR}, 600 {"mp4a.68", MimeUtil::MPEG2_AAC_SSR},
579 {"mp4a.69", MimeUtil::MP3}, 601 {"mp4a.69", MimeUtil::MP3},
580 {"mp4a.6B", MimeUtil::MP3}, 602 {"mp4a.6B", MimeUtil::MP3},
581 {"mp4a.40.2", MimeUtil::MPEG4_AAC_LC}, 603 {"mp4a.40.2", MimeUtil::MPEG4_AAC_LC},
582 {"mp4a.40.02", MimeUtil::MPEG4_AAC_LC}, 604 {"mp4a.40.02", MimeUtil::MPEG4_AAC_LC},
583 {"mp4a.40.5", MimeUtil::MPEG4_AAC_SBR_v1}, 605 {"mp4a.40.5", MimeUtil::MPEG4_AAC_SBR_v1},
584 {"mp4a.40.05", MimeUtil::MPEG4_AAC_SBR_v1}, 606 {"mp4a.40.05", MimeUtil::MPEG4_AAC_SBR_v1},
585 {"mp4a.40.29", MimeUtil::MPEG4_AAC_SBR_PS_v2}, 607 {"mp4a.40.29", MimeUtil::MPEG4_AAC_SBR_PS_v2},
608 #if defined(ENABLE_AC3_EAC3_AUDIO_DEMUXING)
609 {"ac-3", MimeUtil::AC3},
610 {"ec-3", MimeUtil::EAC3},
611 {"mp4a.a5", MimeUtil::AC3},
612 {"mp4a.a6", MimeUtil::EAC3},
613 #endif
586 {"vorbis", MimeUtil::VORBIS}, 614 {"vorbis", MimeUtil::VORBIS},
587 {"opus", MimeUtil::OPUS}, 615 {"opus", MimeUtil::OPUS},
588 {"vp8", MimeUtil::VP8}, 616 {"vp8", MimeUtil::VP8},
589 {"vp8.0", MimeUtil::VP8}, 617 {"vp8.0", MimeUtil::VP8},
590 {"vp9", MimeUtil::VP9}, 618 {"vp9", MimeUtil::VP9},
591 {"vp9.0", MimeUtil::VP9}, 619 {"vp9.0", MimeUtil::VP9},
592 {"theora", MimeUtil::THEORA}}; 620 {"theora", MimeUtil::THEORA}};
593 621
594 // List of codec IDs that are ambiguous and don't provide 622 // List of codec IDs that are ambiguous and don't provide
595 // enough information to determine the codec and profile. 623 // enough information to determine the codec and profile.
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
901 base::TrimString(codecs, "\"", &no_quote_codecs); 929 base::TrimString(codecs, "\"", &no_quote_codecs);
902 base::SplitString(no_quote_codecs, ',', codecs_out); 930 base::SplitString(no_quote_codecs, ',', codecs_out);
903 931
904 if (!strip) 932 if (!strip)
905 return; 933 return;
906 934
907 // Strip everything past the first '.' 935 // Strip everything past the first '.'
908 for (std::vector<std::string>::iterator it = codecs_out->begin(); 936 for (std::vector<std::string>::iterator it = codecs_out->begin();
909 it != codecs_out->end(); 937 it != codecs_out->end();
910 ++it) { 938 ++it) {
939 #if defined(ENABLE_AC3_EAC3_AUDIO_DEMUXING)
940 // We need to know the codec subtype to properly support AC3/EAC3.
941 // Do not strip the first '.' for mp4a.a5 and mp4a.a6.
942 if (it->compare("mp4a.a5") == 0 || it->compare("mp4a.a6") == 0) {
943 continue;
944 }
945 #endif
911 size_t found = it->find_first_of('.'); 946 size_t found = it->find_first_of('.');
912 if (found != std::string::npos) 947 if (found != std::string::npos)
913 it->resize(found); 948 it->resize(found);
914 } 949 }
915 } 950 }
916 951
917 bool MimeUtil::IsStrictMediaMimeType(const std::string& mime_type) const { 952 bool MimeUtil::IsStrictMediaMimeType(const std::string& mime_type) const {
918 return strict_format_map_.find(base::StringToLowerASCII(mime_type)) != 953 return strict_format_map_.find(base::StringToLowerASCII(mime_type)) !=
919 strict_format_map_.end(); 954 strict_format_map_.end();
920 } 955 }
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
1077 case MP3: 1112 case MP3:
1078 case MPEG2_AAC_LC: 1113 case MPEG2_AAC_LC:
1079 case MPEG2_AAC_MAIN: 1114 case MPEG2_AAC_MAIN:
1080 case MPEG2_AAC_SSR: 1115 case MPEG2_AAC_SSR:
1081 case MPEG4_AAC_LC: 1116 case MPEG4_AAC_LC:
1082 case MPEG4_AAC_SBR_v1: 1117 case MPEG4_AAC_SBR_v1:
1083 case MPEG4_AAC_SBR_PS_v2: 1118 case MPEG4_AAC_SBR_PS_v2:
1084 case H264_BASELINE: 1119 case H264_BASELINE:
1085 case H264_MAIN: 1120 case H264_MAIN:
1086 case H264_HIGH: 1121 case H264_HIGH:
1122 #if defined(ENABLE_AC3_EAC3_AUDIO_DEMUXING)
1123 case AC3:
1124 case EAC3:
1125 #endif
1087 return true; 1126 return true;
1088 1127
1089 case PCM: 1128 case PCM:
1090 case VORBIS: 1129 case VORBIS:
1091 case OPUS: 1130 case OPUS:
1092 case VP8: 1131 case VP8:
1093 case VP9: 1132 case VP9:
1094 case THEORA: 1133 case THEORA:
1095 return false; 1134 return false;
1096 } 1135 }
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
1427 post_data->append("\r\n" + value + "\r\n"); 1466 post_data->append("\r\n" + value + "\r\n");
1428 } 1467 }
1429 1468
1430 void AddMultipartFinalDelimiterForUpload(const std::string& mime_boundary, 1469 void AddMultipartFinalDelimiterForUpload(const std::string& mime_boundary,
1431 std::string* post_data) { 1470 std::string* post_data) {
1432 DCHECK(post_data); 1471 DCHECK(post_data);
1433 post_data->append("--" + mime_boundary + "--\r\n"); 1472 post_data->append("--" + mime_boundary + "--\r\n");
1434 } 1473 }
1435 1474
1436 } // namespace net 1475 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698