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

Side by Side Diff: media/base/container_names.cc

Issue 2797133009: Better detection of MP4 files (Closed)
Patch Set: Created 3 years, 8 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 | « no previous file | media/base/container_names_unittest.cc » ('j') | 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "media/base/container_names.h" 5 #include "media/base/container_names.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <cctype> 9 #include <cctype>
10 #include <limits> 10 #include <limits>
(...skipping 938 matching lines...) Expand 10 before | Expand all | Expand 10 after
949 } 949 }
950 } 950 }
951 951
952 // Additional checks for a MOV/QuickTime/MPEG4 container. 952 // Additional checks for a MOV/QuickTime/MPEG4 container.
953 static bool CheckMov(const uint8_t* buffer, int buffer_size) { 953 static bool CheckMov(const uint8_t* buffer, int buffer_size) {
954 // Reference: ISO/IEC 14496-12:2005(E). 954 // Reference: ISO/IEC 14496-12:2005(E).
955 // (http://standards.iso.org/ittf/PubliclyAvailableStandards/c061988_ISO_IEC_1 4496-12_2012.zip) 955 // (http://standards.iso.org/ittf/PubliclyAvailableStandards/c061988_ISO_IEC_1 4496-12_2012.zip)
956 RCHECK(buffer_size > 8); 956 RCHECK(buffer_size > 8);
957 957
958 int offset = 0; 958 int offset = 0;
959 int valid_top_level_boxes = 0;
959 while (offset + 8 < buffer_size) { 960 while (offset + 8 < buffer_size) {
960 uint32_t atomsize = Read32(buffer + offset); 961 uint32_t atomsize = Read32(buffer + offset);
961 uint32_t atomtype = Read32(buffer + offset + 4); 962 uint32_t atomtype = Read32(buffer + offset + 4);
962 // Only need to check for ones that are valid at the top level. 963
964 // Only need to check for atoms that are valid at the top level. However,
965 // "Boxes with an unrecognized type shall be ignored and skipped." So
966 // simply make sure that at least two recognized top level boxes are found.
967 // This list matches BoxReader::IsValidTopLevelBox().
963 switch (atomtype) { 968 switch (atomtype) {
964 case TAG('f','t','y','p'): 969 case TAG('f', 't', 'y', 'p'):
965 case TAG('p','d','i','n'): 970 case TAG('p', 'd', 'i', 'n'):
966 case TAG('m','o','o','v'): 971 case TAG('b', 'l', 'o', 'c'):
967 case TAG('m','o','o','f'): 972 case TAG('m', 'o', 'o', 'v'):
968 case TAG('m','f','r','a'): 973 case TAG('m', 'o', 'o', 'f'):
969 case TAG('m','d','a','t'): 974 case TAG('m', 'f', 'r', 'a'):
970 case TAG('f','r','e','e'): 975 case TAG('m', 'd', 'a', 't'):
971 case TAG('s','k','i','p'): 976 case TAG('f', 'r', 'e', 'e'):
972 case TAG('m','e','t','a'): 977 case TAG('s', 'k', 'i', 'p'):
973 case TAG('m','e','c','o'): 978 case TAG('m', 'e', 't', 'a'):
974 case TAG('s','t','y','p'): 979 case TAG('m', 'e', 'c', 'o'):
975 case TAG('s','i','d','x'): 980 case TAG('s', 't', 'y', 'p'):
976 case TAG('s','s','i','x'): 981 case TAG('s', 'i', 'd', 'x'):
977 case TAG('p','r','f','t'): 982 case TAG('s', 's', 'i', 'x'):
978 case TAG('b','l','o','c'): 983 case TAG('p', 'r', 'f', 't'):
984 case TAG('u', 'u', 'i', 'd'):
985 case TAG('e', 'm', 's', 'g'):
986 ++valid_top_level_boxes;
979 break; 987 break;
980 default:
981 return false;
982 } 988 }
983 if (atomsize == 1) { 989 if (atomsize == 1) {
984 // Indicates that the length is the next 64bits. 990 // Indicates that the length is the next 64bits.
985 if (offset + 16 > buffer_size) 991 if (offset + 16 > buffer_size)
986 break; 992 break;
987 if (Read32(buffer + offset + 8) != 0) 993 if (Read32(buffer + offset + 8) != 0)
988 break; // Offset is way past buffer size. 994 break; // Offset is way past buffer size.
989 atomsize = Read32(buffer + offset + 12); 995 atomsize = Read32(buffer + offset + 12);
990 } 996 }
991 if (atomsize == 0 || atomsize > static_cast<size_t>(buffer_size)) 997 if (atomsize == 0 || atomsize > static_cast<size_t>(buffer_size))
992 break; // Indicates the last atom or length too big. 998 break; // Indicates the last atom or length too big.
993 offset += atomsize; 999 offset += atomsize;
994 } 1000 }
995 return true; 1001 return valid_top_level_boxes >= 2;
996 } 1002 }
997 1003
998 enum MPEGVersion { 1004 enum MPEGVersion {
999 VERSION_25 = 0, 1005 VERSION_25 = 0,
1000 VERSION_RESERVED, 1006 VERSION_RESERVED,
1001 VERSION_2, 1007 VERSION_2,
1002 VERSION_1 1008 VERSION_1
1003 }; 1009 };
1004 enum MPEGLayer { 1010 enum MPEGLayer {
1005 L_RESERVED = 0, 1011 L_RESERVED = 0,
(...skipping 666 matching lines...) Expand 10 before | Expand all | Expand 10 after
1672 if (CheckEac3(buffer + offset, buffer_size - offset)) 1678 if (CheckEac3(buffer + offset, buffer_size - offset))
1673 return CONTAINER_EAC3; 1679 return CONTAINER_EAC3;
1674 } 1680 }
1675 1681
1676 return CONTAINER_UNKNOWN; 1682 return CONTAINER_UNKNOWN;
1677 } 1683 }
1678 1684
1679 } // namespace container_names 1685 } // namespace container_names
1680 1686
1681 } // namespace media 1687 } // namespace media
OLDNEW
« no previous file with comments | « no previous file | media/base/container_names_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698