Index: media/base/container_names.cc |
diff --git a/media/base/container_names.cc b/media/base/container_names.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..513ee2c2e248e3b37e0994d665d7a286bfa445ff |
--- /dev/null |
+++ b/media/base/container_names.cc |
@@ -0,0 +1,2249 @@ |
+// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "media/base/container_names.h" |
+ |
+#include "base/basictypes.h" |
+#include "base/logging.h" |
+#include "base/metrics/sparse_histogram.h" |
+ |
+namespace media { |
+ |
+#define TAG(a, b, c, d) \ |
+ ((static_cast<uint8_t>(a) << 24) | (static_cast<uint8_t>(b) << 16) | \ |
+ (static_cast<uint8_t>(c) << 8) | (static_cast<uint8_t>(d))) |
+ |
+// Helper function to read 2 bytes (16 bits, big endian) from a buffer. |
+static uint32_t Read16(const uint8_t* p) { |
+ return p[0] << 8 | p[1]; |
+} |
+ |
+// Helper function to read 3 bytes (24 bits, big endian) from a buffer. |
+static uint32_t Read24(const uint8_t* p) { |
+ return p[0] << 16 | p[1] << 8 | p[2]; |
+} |
+ |
+// Helper function to read 4 bytes (32 bits, big endian) from a buffer. |
+static uint32_t Read32(const uint8_t* p) { |
+ return p[0] << 24 | p[1] << 16 | p[2] << 8 | p[3]; |
+} |
+ |
+// Helper function to do buffer comparisons without going off the end |
+// of the buffer. |
+static bool CompareEqual(const uint8_t* buffer, |
xhwang
2013/05/03 19:59:06
This function is checking that "search" is a prefi
jrummell
2013/05/03 23:56:21
Done.
|
+ size_t buffer_size, |
+ const char* search, |
+ size_t search_size) { |
+ return (search_size <= buffer_size && |
+ memcmp(buffer, search, search_size) == 0); |
+} |
+ |
+// Comparison function used by lower_bound which returns true |
+// if the first argument is less than the second. |
xhwang
2013/05/03 19:59:06
s/less than the second/less than the second in lex
jrummell
2013/05/03 23:56:21
Done.
|
+static bool ContainerNameMappingComparer(const ContainerNameMapping& a, |
+ const char* b) { |
+ return strcasecmp(a.name, b) < 0; |
+} |
+ |
+// Output a container value to the histogram. |
+static void LogContainerToHistogram(FFmpegContainerName container, |
+ bool is_guess) { |
+ int metric = 2 * container; |
+ if (is_guess) |
+ ++metric; |
+ |
+ UMA_HISTOGRAM_SPARSE_SLOWLY("Media.DetectedContainer", metric); |
+} |
+ |
+// For some formats the signature is a bunch of characters. They are defined |
+// below. Note that the first 4 characters of the string may be used as a TAG |
+// in LookupContainerByFirst4. |
+#define BYTE_ORDER_MARK "\xef\xbb\xbf" |
+ |
+static const char kAmrSignature[] = "#!AMR"; |
+static const char kApcSignature[] = "CRYO_APC"; |
+static const char kAsfSignature[] = |
+ "\x30\x26\xb2\x75\x8e\x66\xcf\x11\xa6\xd9\x00\xaa\x00\x62\xce\x6c"; |
+static const char kAssSignature[] = "[Script Info]"; |
+static const char kAssBomSignature[] = BYTE_ORDER_MARK "[Script Info]"; |
+static const char kConcatSignature[] = "ffconcat version 1.0"; |
+static const char kDnxhdSignature[] = "\x00\x00\x02\x80\x01"; |
+static const char kFfSignature[] = ";FFMETADATA"; |
+static const char kHlsSignature[] = "#EXTM3U"; |
+static const char kIdfSignature[] = |
+ "\x04\x31\x2e\x34\x00\x00\x00\x00\x4f\x00\x15\x00"; |
+static const char kIlbcSignature[] = "#!iLBC"; |
+static const char kIssSignature[] = "IMA_ADPCM_Sound"; |
+static const char kIv8Signature[] = "\x01\x01\x03\xb8\x80\x60"; |
+static const char kJvSignature[] = " Compression by John M Phillips Copyright " |
+ "(C) 1995 The Bitmap Brothers Ltd."; |
+static const char kLibnutSignature[] = "nut/multimedia container"; |
+static const char kLxfSignature[] = "LEITCH\x00\x00"; |
+static const char kNuv1Signature[] = "NuppelVideo"; |
+static const char kNuv2Signature[] = "MythTVVideo"; |
+static const char kPafSignature[] = |
+ "Packed Animation File V1.0\n(c) 1992-96 Amazing Studio\x0a\x1a"; |
+static const char kRealSignature[] = "<window"; |
+static const char kRealBomSignature[] = BYTE_ORDER_MARK "<window"; |
+static const char kRplSignature[] = "ARMovie\x0A"; |
+static const char kSamiSignature[] = "<SAMI>"; |
+static const char kSamiBomSignature[] = BYTE_ORDER_MARK "<SAMI>"; |
+static const char kSmjpegSignature[] = "\x00\x0aSMJPEG"; |
+static const char kVivoSignature[] = "\r\nVersion:Vivo/"; |
+static const char kVobsubSignature[] = "# VobSub index file,"; |
+static const char kVocSignature[] = "Creative Voice File\x1A"; |
+static const char kW64Signature[] = |
+ "riff\x2e\x91\xcf\x11\xa5\xd6\x28\xdb\x04\xc1\x00\x00"; |
+static const char kW64Signature2[] = |
+ "wave\xf3\xac\xd3\x11\x8c\xd1\x00\xc0\x4f\x8e\xdb\x8a"; |
+static const char kWebvttSignature[] = "WEBVTT"; |
+static const char kWebvttBomSignature[] = BYTE_ORDER_MARK "WEBVTT"; |
+static const char kWtvSignature[] = |
+ "\xb7\xd8\x00\x20\x37\x49\xda\x11\xa6\x4e\x00\x07\xe9\x5e\xad\x8d"; |
+static const char kYuv4Signature[] = "YUV4MPEG2"; |
+ |
+const uint16_t ac3_frame_size_table[38][3] = { |
xhwang
2013/05/03 19:59:06
use kCamelCase for consts?
jrummell
2013/05/03 23:56:21
Done.
|
+ { 128, 138, 192 }, { 128, 140, 192 }, { 160, 174, 240 }, { 160, 176, 240 }, |
+ { 192, 208, 288 }, { 192, 210, 288 }, { 224, 242, 336 }, { 224, 244, 336 }, |
+ { 256, 278, 384 }, { 256, 280, 384 }, { 320, 348, 480 }, { 320, 350, 480 }, |
+ { 384, 416, 576 }, { 384, 418, 576 }, { 448, 486, 672 }, { 448, 488, 672 }, |
+ { 512, 556, 768 }, { 512, 558, 768 }, { 640, 696, 960 }, { 640, 698, 960 }, |
+ { 768, 834, 1152 }, { 768, 836, 1152 }, { 896, 974, 1344 }, |
+ { 896, 976, 1344 }, { 1024, 1114, 1536 }, { 1024, 1116, 1536 }, |
+ { 1280, 1392, 1920 }, { 1280, 1394, 1920 }, { 1536, 1670, 2304 }, |
+ { 1536, 1672, 2304 }, { 1792, 1950, 2688 }, { 1792, 1952, 2688 }, |
+ { 2048, 2228, 3072 }, { 2048, 2230, 3072 }, { 2304, 2506, 3456 }, |
+ { 2304, 2508, 3456 }, { 2560, 2768, 3840 }, { 2560, 2770, 3840 }, |
+}; |
+ |
+// Checks for an ADTS AAC container. |
+static bool check_aac(const uint8_t buffer[], size_t buffer_size) { |
xhwang
2013/05/03 19:59:06
use const uint8_t* and int?
jrummell
2013/05/03 23:56:21
Done.
|
+ // ADTS header is 7 or 9 bytes |
+ // (from http://wiki.multimedia.cx/index.php?title=ADTS) |
+ size_t offset = 0; |
+ while (offset + 5 < buffer_size) { |
+ uint32_t syncword = (Read16(buffer + offset) >> 4) & 0xfff; |
xhwang
2013/05/03 19:59:06
we are using uint32_t in this function even for 16
jrummell
2013/05/03 23:56:21
Done.
|
+ uint32_t layer = (buffer[offset + 1] >> 1) & 0x3; |
+ uint32_t frequency_index = (buffer[offset + 2] >> 2) & 0xf; |
+ uint32_t size = (Read24(buffer + offset + 3) >> 5) & 0x1fff; |
+ if (syncword != 0xfff || layer != 0 || frequency_index == 15) |
+ return false; |
+ offset += size; |
+ } |
+ return true; |
xhwang
2013/05/03 19:59:06
So if buffer_size is <= 5, we return true here. Is
jrummell
2013/05/03 23:56:21
Done.
|
+} |
+ |
+// Checks for an AC3 container. |
+static bool check_ac3(const uint8_t buffer[], size_t buffer_size) { |
+ // AC3 container looks like syncinfo | bsi | audblk * 6 | aux | check. |
+ // from spec @ http://www.atsc.org/cms/standards/A52-2012(12-17).pdf |
+ size_t offset = 0; |
+ |
+ while (offset + 6 < buffer_size) { |
+ // Verify syncinfo (5 bytes) |
+ if (Read16(buffer + offset) != 0x0b77) |
+ return false; |
+ int sample_rate_code = (buffer[offset + 4] >> 6) & 0x03; |
+ if (sample_rate_code == 3) // reserved |
+ return false; |
+ int frame_size_code = buffer[offset + 4] & 0x3f; |
+ if (frame_size_code >= 38) |
+ return false; |
+ |
+ // Verify bsi (no fixed alignment) |
+ int bit_stream_id = (buffer[offset + 5] >> 3) & 0x1f; |
+ if (bit_stream_id >= 10) // normally 8 or 6 |
+ return false; |
+ |
+ offset += ac3_frame_size_table[frame_size_code][sample_rate_code]; |
+ } |
+ return true; |
xhwang
2013/05/03 19:59:06
ditto
jrummell
2013/05/03 23:56:21
Done.
|
+} |
+ |
+// Checks for an EAC3 container (very similar to AC3) |
+static bool check_eac3(const uint8_t buffer[], size_t buffer_size) { |
+ // EAC3 container looks like syncinfo | bsi | audfrm | audblk* | aux | check. |
+ // from spec @ http://www.atsc.org/cms/standards/A52-2012(12-17).pdf |
+ size_t offset = 0; |
+ |
+ while (offset + 6 < buffer_size) { |
+ // Verify syncinfo (5 bytes) |
+ if (Read16(buffer + offset) != 0x0b77) |
+ return false; |
+ |
+ // Verify bsi (no fixed alignment) |
+ int stream_type = (buffer[offset + 2] > 6) & 0x3; |
+ if (stream_type == 3) |
+ return false; |
+ int frame_size = ((Read16(buffer + offset + 2) & 0x7ff) + 1) * 2; |
+ if (frame_size < 7) |
+ return false; |
+ int bit_stream_id = (buffer[offset + 5] >> 3) & 0x1f; |
+ if (bit_stream_id != 16) |
+ return false; |
+ |
+ offset += frame_size; |
+ } |
+ return true; |
xhwang
2013/05/03 19:59:06
ditto
jrummell
2013/05/03 23:56:21
Done.
|
+} |
+ |
+// Additional checks for an ACT container. |
+static bool check_act(const uint8_t buffer[], size_t buffer_size) { |
+ if (buffer_size < 512 || Read32(buffer + 16) != 16) |
+ return false; |
+ // Most of the first 512 bytes should be 0. |
+ for (int i = 44; i < 256; ++i) |
+ if (buffer[i] != 0) |
+ return false; |
+ if (buffer[256] != 0x84) |
+ return false; |
+ for (int i = 264; i < 512; ++i) |
+ if (buffer[i] != 0) |
+ return false; |
+ return true; |
+} |
+ |
+// Additional checks for an AEA container. |
+static bool check_aea(const uint8_t buffer[], size_t buffer_size) { |
+ if (buffer_size < 2260) |
+ return false; |
+ int channels = buffer[264]; |
+ return ((channels == 1 || channels == 2) && |
+ buffer[2048] == buffer[2259] && |
+ buffer[2049] == buffer[2258]); |
+} |
+ |
+// Additional checks for a BINK container. |
+static bool check_bink(const uint8_t buffer[], size_t buffer_size) { |
+ if (buffer_size < 36) |
+ return false; |
+ uint32_t frames = Read32(buffer + 8); |
+ uint32_t width = Read32(buffer + 20); |
+ uint32_t height = Read32(buffer + 24); |
+ uint32_t fps = Read32(buffer + 28); |
+ uint32_t den = Read32(buffer + 32); |
+ return (frames > 0 && fps > 0 && den > 0 && |
+ (width > 0 && width <= 7680) && |
+ (height > 0 && height <= 4800)); |
+} |
+ |
+// Additional checks for a C93 container. |
+static bool check_c93(const uint8_t buffer[], size_t buffer_size) { |
+ uint16_t index = 1; |
+ if (buffer_size < 20) |
+ return false; |
+ for (int i = 0; i < 16; i += 4) { |
+ if (Read16(buffer + i) != index || !buffer[i + 2] || !buffer[i + 3]) |
+ return false; |
+ index += buffer[i + 2]; |
xhwang
2013/05/03 19:59:06
just double check, so we are not using buffer[i +
jrummell
2013/05/03 23:56:21
This is what is in ffmpeg (https://code.google.com
xhwang
2013/05/06 23:51:27
ok, thanks for the link.
Ilya Sherman
2013/05/07 00:10:51
Just double-checking: Is it consistent with ffmpeg
|
+ } |
xhwang
2013/05/03 19:59:06
indent
jrummell
2013/05/03 23:56:21
Done.
|
+ return true; |
+} |
+ |
+// Additional checks for a CDXL container. |
+static bool check_cdxl(const uint8_t buffer[], size_t buffer_size) { |
+ if (buffer_size < 32) |
+ return false; |
+ uint8_t type = buffer[0]; |
+ uint32_t current_size = Read32(buffer + 2); |
+ uint32_t width = Read16(buffer + 14); |
+ uint32_t height = Read16(buffer + 16); |
+ uint8_t plane1 = buffer[18]; |
+ uint8_t plane2 = buffer[19]; |
+ uint32_t palette_size = Read16(buffer + 20); |
+ uint32_t audio_size = Read16(buffer + 22); |
+ uint32_t image_size = width * height * plane2 / 8; |
+ return (type == 1 && |
+ palette_size <= 512 && |
+ plane1 != 0 && |
+ plane2 != 0 && |
+ width != 0 && |
+ height != 0 && |
+ current_size >= audio_size + palette_size + image_size + 32 && |
+ Read32(buffer + 24) == 0 && |
+ Read32(buffer + 28) == 0 && |
+ Read16(buffer + 10) == 0); |
+} |
+ |
+// Additional checks for a DNXHD container. |
+static bool check_dnxhd(const uint8_t buffer[], size_t buffer_size) { |
+ if (buffer_size < 42) |
+ return false; |
+ uint32_t height = Read16(buffer + 24); |
+ uint32_t width = Read16(buffer + 26); |
+ uint32_t compression = Read16(buffer + 40); |
+ return (CompareEqual(buffer, |
+ buffer_size, |
+ kDnxhdSignature, |
+ sizeof(kDnxhdSignature) - 1) && |
+ height > 0 && width > 0 && compression >= 1235 && |
+ compression <= 1253); |
+} |
+ |
+// Additional checks for a DSICIN container. |
+static bool check_dsicin(const uint8_t buffer[], size_t buffer_size) { |
+ return (buffer_size > 17 && |
+ Read32(buffer + 12) == 22050 && |
+ buffer[16] == 16 && |
+ buffer[17] == 0); |
+} |
+ |
+// Additional checks for an IDCIN container. |
+static bool check_idcin(const uint8_t buffer[], size_t buffer_size) { |
+ if (buffer_size < 20) |
xhwang
2013/05/03 19:59:06
s/</<=/ ? It seems we only need 20 bytes.
jrummell
2013/05/03 23:56:21
Correct. If we have 20 bytes we can test. If it's
|
+ return false; |
+ uint32_t width = Read32(buffer); |
+ uint32_t height = Read32(buffer + 4); |
+ uint32_t rate = Read32(buffer + 8); |
+ uint32_t bytes = Read32(buffer + 12); |
+ uint32_t channels = Read32(buffer + 16); |
+ return (width > 0 && width <= 1024 && |
+ height > 0 && height <= 1024 && |
+ rate >= 8000 && rate <= 48000 && |
+ bytes <= 2 && |
+ channels <= 2); |
+} |
+ |
+#define HLS1 "#EXT-X-STREAM-INF:" |
+#define HLS2 "#EXT-X-TARGETDURATION:" |
+#define HLS3 "#EXT-X-MEDIA-SEQUENCE:" |
xhwang
2013/05/03 19:59:06
here and 359-362: use const instead of macro?
|
+ |
+// Additional checks for a HLS container. |
+static bool check_hls(const uint8_t buffer[], size_t buffer_size) { |
+ if (CompareEqual(buffer, |
+ buffer_size, |
+ kHlsSignature, |
+ sizeof(kHlsSignature) - 1)) { |
+ // Need to find "#EXT-X-STREAM-INF:", "#EXT-X-TARGETDURATION:", |
+ // or "#EXT-X-MEDIA-SEQUENCE:" somewhere in the buffer |
+ size_t offset = sizeof(kHlsSignature) - 1; |
+ while (offset < buffer_size) { |
+ if (buffer[offset] == '#') { |
+ if (CompareEqual(buffer + offset, |
+ buffer_size - offset, |
+ HLS1, |
+ strlen(HLS1)) || |
+ CompareEqual(buffer + offset, |
+ buffer_size - offset, |
+ HLS2, |
+ strlen(HLS2)) || |
+ CompareEqual(buffer + offset, |
+ buffer_size - offset, |
+ HLS3, |
+ strlen(HLS3))) |
+ return true; |
+ } |
+ ++offset; |
+ } |
+ } |
+ return false; |
+} |
+ |
+// Checks for a LOAS container. |
+static bool check_loas(const uint8_t buffer[], size_t buffer_size) { |
+ // LOAS header is 3 bytes. |
+ // (from ISO/IEC 14496-3:2005, page 51) |
+ size_t offset = 0; |
+ while (offset + 3 < buffer_size) { |
+ uint32_t header = Read24(buffer); |
+ uint32_t syncword = (header >> 13) & 0x7ff; |
+ uint32_t audio_length = (header & 0x1fff); |
+ if (syncword != 0x2b7 || audio_length < 4) |
+ return false; |
+ offset += audio_length + 3 /* header */; |
+ } |
+ return true; |
xhwang
2013/05/03 19:59:06
ditto about buffer_size check
jrummell
2013/05/03 23:56:21
Done.
|
+} |
+ |
+#define VISUAL_OBJECT_SEQUENCE_START_CODE 0xb0 |
+#define VISUAL_OBJECT_SEQUENCE_END_CODE 0xb1 |
+#define VISUAL_OBJECT_START_CODE 0xb5 |
+#define VOP_START_CODE 0xb6 |
+ |
+// Checks for a M4V (raw MPEG4) container. |
+static bool check_m4v(const uint8_t buffer[], size_t buffer_size) { |
+ // Defined in ISO/IEC 14496-2:2001. |
+ // However, no length ... simply scan for start code values |
+ // Expect to see SEQ | VO1 | VOL* | VO2 ... |
+ size_t offset = 0; |
+ int sequence_start_count = 0; |
+ int sequence_end_count = 0; |
+ int visual_object_count = 0; |
+ int vop_count = 0; |
+ while (offset + 4 < buffer_size) { |
+ uint32_t start_code = Read24(buffer + offset); |
+ if (start_code == 1) { |
+ // Fail if it is a reserved value. |
+ if (buffer[offset] >= 0x30 && buffer[offset] <= 0xaf) |
+ return false; |
+ if (buffer[offset] >= 0xb7 && buffer[offset] <= 0xb9) |
+ return false; |
+ |
+ switch (buffer[offset]) { |
+ case VISUAL_OBJECT_SEQUENCE_START_CODE: |
+ ++sequence_start_count; |
+ break; |
+ case VISUAL_OBJECT_SEQUENCE_END_CODE: |
+ if (++sequence_end_count > sequence_start_count) |
+ return false; |
+ break; |
+ case VISUAL_OBJECT_START_CODE: |
+ ++visual_object_count; |
+ break; |
+ case VOP_START_CODE: |
+ if (++vop_count > visual_object_count) |
+ return false; |
+ break; |
+ } |
+ offset += 4; |
+ } |
+ else { |
+ // Start codes can start on any byte boundary |
+ ++offset; |
+ } |
+ } |
+ // Not a complete sequence in memory, so return true if we've seen a |
+ // visual_object_sequence_start_code and a visual_object_start_code. |
+ return (sequence_start_count > 0 && visual_object_count > 0); |
+} |
+ |
+// Additional checks for a MM container. |
+static bool check_mm(const uint8_t buffer[], size_t buffer_size) { |
+ if (buffer_size < 16) |
+ return false; |
+ uint32_t length = Read32(buffer + 2); |
+ uint32_t fps = Read16(buffer + 8); |
+ uint32_t width = Read16(buffer + 12); |
+ uint32_t height = Read16(buffer + 14); |
+ uint32_t type = (length + 2 < buffer_size) ? Read16(buffer + length) : 0; |
xhwang
2013/05/03 19:59:06
here, length looks like type_offset.. then on line
jrummell
2013/05/03 23:56:21
Done.
|
+ return ((length == 22 || length == 24) && |
+ fps > 0 && fps <= 60 && |
+ width > 0 && width <= 2048 && |
+ height > 0 && height <= 2048 && |
+ type > 0 && type < 50); |
+} |
+ |
+// Additional checks for a MOV container. |
+static bool check_mov(const uint8_t buffer[], size_t buffer_size) { |
xhwang
2013/05/03 19:59:06
ditto, shall we check buffer_size?
jrummell
2013/05/03 23:56:21
Done.
|
+ size_t offset = 0; |
+ while (offset + 16 < buffer_size) { |
+ uint32_t atomsize = Read32(buffer + offset); |
+ uint32_t atomtype = Read32(buffer + offset + 4); |
+ // Valid atoms from http://www.mp4ra.org/atoms.html |
+ switch (atomtype) { |
+ case TAG('a','i','n','f'): |
+ case TAG('a','v','c','n'): |
+ case TAG('b','l','o','c'): |
+ case TAG('b','p','c','c'): |
+ case TAG('b','u','f','f'): |
+ case TAG('b','x','m','l'): |
+ case TAG('c','c','i','d'): |
+ case TAG('c','d','e','f'): |
+ case TAG('c','m','a','p'): |
+ case TAG('c','o','6','4'): |
+ case TAG('c','o','l','r'): |
+ case TAG('c','r','h','d'): |
+ case TAG('c','s','l','g'): |
+ case TAG('c','t','t','s'): |
+ case TAG('c','v','r','u'): |
+ case TAG('d','i','n','f'): |
+ case TAG('d','r','e','f'): |
+ case TAG('d','s','g','d'): |
+ case TAG('d','s','t','g'): |
+ case TAG('e','d','t','s'): |
+ case TAG('e','l','s','t'): |
+ case TAG('f','e','c','i'): |
+ case TAG('f','e','c','r'): |
+ case TAG('f','i','i','n'): |
+ case TAG('f','i','r','e'): |
+ case TAG('f','p','a','r'): |
+ case TAG('f','r','e','e'): |
+ case TAG('f','r','m','a'): |
+ case TAG('f','t','y','p'): |
+ case TAG('g','i','t','n'): |
+ case TAG('g','r','p','i'): |
+ case TAG('h','d','l','r'): |
+ case TAG('h','m','h','d'): |
+ case TAG('h','p','i','x'): |
+ case TAG('i','c','n','u'): |
+ case TAG('I','D','3','2'): |
+ case TAG('i','d','a','t'): |
+ case TAG('i','h','d','r'): |
+ case TAG('i','i','n','f'): |
+ case TAG('i','l','o','c'): |
+ case TAG('i','m','i','f'): |
+ case TAG('i','n','f','u'): |
+ case TAG('i','o','d','s'): |
+ case TAG('i','p','h','d'): |
+ case TAG('i','p','m','c'): |
+ case TAG('i','p','r','o'): |
+ case TAG('i','r','e','f'): |
+ case TAG('j','P',' ',' '): |
+ case TAG('j','p','2','c'): |
+ case TAG('j','p','2','h'): |
+ case TAG('j','p','2','i'): |
+ case TAG('l','r','c','u'): |
+ case TAG('m','7','h','d'): |
+ case TAG('m','d','a','t'): |
+ case TAG('m','d','h','d'): |
+ case TAG('m','d','i','a'): |
+ case TAG('m','d','r','i'): |
+ case TAG('m','e','c','o'): |
+ case TAG('m','e','h','d'): |
+ case TAG('m','e','r','e'): |
+ case TAG('m','e','t','a'): |
+ case TAG('m','f','h','d'): |
+ case TAG('m','f','r','a'): |
+ case TAG('m','f','r','o'): |
+ case TAG('m','i','n','f'): |
+ case TAG('m','j','h','d'): |
+ case TAG('m','o','o','f'): |
+ case TAG('m','o','o','v'): |
+ case TAG('m','v','c','g'): |
+ case TAG('m','v','c','i'): |
+ case TAG('m','v','e','x'): |
+ case TAG('m','v','h','d'): |
+ case TAG('m','v','r','a'): |
+ case TAG('n','m','h','d'): |
+ case TAG('o','c','h','d'): |
+ case TAG('o','d','a','f'): |
+ case TAG('o','d','d','a'): |
+ case TAG('o','d','h','d'): |
+ case TAG('o','d','h','e'): |
+ case TAG('o','d','r','b'): |
+ case TAG('o','d','r','m'): |
+ case TAG('o','d','t','t'): |
+ case TAG('o','h','d','r'): |
+ case TAG('p','a','d','b'): |
+ case TAG('p','a','e','n'): |
+ case TAG('p','c','l','r'): |
+ case TAG('p','d','i','n'): |
+ case TAG('p','i','t','m'): |
+ case TAG('r','e','s',' '): |
+ case TAG('r','e','s','c'): |
+ case TAG('r','e','s','d'): |
+ case TAG('s','b','g','p'): |
+ case TAG('s','c','h','i'): |
+ case TAG('s','c','h','m'): |
+ case TAG('s','d','e','p'): |
+ case TAG('s','d','h','d'): |
+ case TAG('s','d','t','p'): |
+ case TAG('s','d','v','p'): |
+ case TAG('s','e','g','r'): |
+ case TAG('s','e','n','c'): |
+ case TAG('s','g','p','d'): |
+ case TAG('s','i','d','x'): |
+ case TAG('s','i','n','f'): |
+ case TAG('s','k','i','p'): |
+ case TAG('s','m','h','d'): |
+ case TAG('s','r','m','b'): |
+ case TAG('s','r','m','c'): |
+ case TAG('s','r','p','p'): |
+ case TAG('s','t','b','l'): |
+ case TAG('s','t','c','o'): |
+ case TAG('s','t','d','p'): |
+ case TAG('s','t','h','d'): |
+ case TAG('s','t','s','c'): |
+ case TAG('s','t','s','d'): |
+ case TAG('s','t','s','h'): |
+ case TAG('s','t','s','s'): |
+ case TAG('s','t','s','z'): |
+ case TAG('s','t','t','s'): |
+ case TAG('s','t','y','p'): |
+ case TAG('s','t','z','2'): |
+ case TAG('s','u','b','s'): |
+ case TAG('s','w','t','c'): |
+ case TAG('t','f','a','d'): |
+ case TAG('t','f','h','d'): |
+ case TAG('t','f','m','a'): |
+ case TAG('t','f','r','a'): |
+ case TAG('t','i','b','r'): |
+ case TAG('t','i','r','i'): |
+ case TAG('t','k','h','d'): |
+ case TAG('t','r','a','f'): |
+ case TAG('t','r','a','k'): |
+ case TAG('t','r','e','f'): |
+ case TAG('t','r','e','x'): |
+ case TAG('t','r','g','r'): |
+ case TAG('t','r','i','k'): |
+ case TAG('t','r','u','n'): |
+ case TAG('u','d','t','a'): |
+ case TAG('u','i','n','f'): |
+ case TAG('U','I','T','S'): |
+ case TAG('u','l','s','t'): |
+ case TAG('u','r','l',' '): |
+ case TAG('u','u','i','d'): |
+ case TAG('v','m','h','d'): |
+ case TAG('v','w','d','i'): |
+ case TAG('x','m','l',' '): |
+ case TAG('C','o','d','e'): |
+ case TAG('a','l','b','m'): |
+ case TAG('a','n','g','l'): |
+ case TAG('a','u','t','h'): |
+ case TAG('c','l','f','n'): |
+ case TAG('c','l','i','d'): |
+ case TAG('c','l','s','f'): |
+ case TAG('c','m','i','d'): |
+ case TAG('c','m','n','m'): |
+ case TAG('c','o','l','l'): |
+ case TAG('c','p','r','t'): |
+ case TAG('d','a','t','e'): |
+ case TAG('d','s','c','p'): |
+ case TAG('g','n','r','e'): |
+ case TAG('h','n','t','i'): |
+ case TAG('k','y','w','d'): |
+ case TAG('l','o','c','i'): |
+ case TAG('m','a','n','u'): |
+ case TAG('m','o','d','l'): |
+ case TAG('p','e','r','f'): |
+ case TAG('r','e','e','l'): |
+ case TAG('r','t','n','g'): |
+ case TAG('s','c','e','n'): |
+ case TAG('s','h','o','t'): |
+ case TAG('s','l','n','o'): |
+ case TAG('s','t','r','k'): |
+ case TAG('t','h','m','b'): |
+ case TAG('t','s','e','l'): |
+ case TAG('t','i','t','l'): |
+ case TAG('u','r','a','t'): |
+ case TAG('y','r','r','c'): |
+ case TAG('c','l','i','p'): |
+ case TAG('c','r','g','n'): |
+ case TAG('c','t','a','b'): |
+ case TAG('d','c','f','D'): |
+ case TAG('e','l','n','g'): |
+ case TAG('i','m','a','p'): |
+ case TAG('k','m','a','t'): |
+ case TAG('l','o','a','d'): |
+ case TAG('m','a','t','t'): |
+ case TAG('p','n','o','t'): |
+ case TAG('w','i','d','e'): |
+ break; |
+ default: |
+ return false; |
+ } |
+ if (atomsize == 0) |
+ break; // indicates the last atom |
+ if (atomsize == 1) { |
+ // Indicates that the length is the next 64bits. |
+ if (Read32(buffer + offset + 8) != 0) |
+ break; // offset is way past buffer size |
+ atomsize = Read32(buffer + offset + 12); |
+ } |
+ offset += atomsize; |
+ } |
+ return true; |
+} |
+ |
+enum MPEGVersion { |
+ Version25 = 0, |
+ v_reserved, |
+ Version2, |
+ Version1 |
+}; |
+enum MPEGlayer { |
+ l_reserved = 0, |
+ Layer3, |
+ Layer2, |
+ Layer1 |
+}; |
+ |
+static int Sample_Rate_Table[4][4] = { |
+ { 11025, 12000, 8000, 0 }, // v2.5 |
+ { 0, 0, 0, 0 }, // not used |
+ { 22050, 24000, 16000, 0 }, // v2 |
+ { 44100, 48000, 32000, 0 } // v1 |
+}; |
+ |
+static int Bit_Rate_Table_v1_l1[16] = |
+ { 0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448, 0 }; |
xhwang
2013/05/03 19:59:06
here and below, 4 space indentation.
jrummell
2013/05/03 23:56:21
Reformatted to what clang-format does.
|
+static int Bit_Rate_Table_v1_l2[16] = |
+ { 0, 32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384, 0 }; |
+static int Bit_Rate_Table_v1_l3[16] = |
+ { 0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 0 }; |
+static int Bit_Rate_Table_v2_l1[16] = |
+ { 0, 32, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, 256, 0 }; |
+static int Bit_Rate_Table_v2_l23[16] = |
+ { 0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160, 0 }; |
+ |
+static bool valid_mpeg_audio_frame_header(uint32_t header, size_t* framesize) { |
+ *framesize = 0; |
+ // first 11 bits must be all set |
+ if ((header & 0xffe00000) != 0xffe00000) |
+ return false; |
+ // version (bits 20-19) can not be 01 |
+ int version = (header >> 19) & 0x3; |
+ if (version == 1) |
+ return false; |
+ // layer (bits 18-17) can not be 00 |
+ int layer = (header >> 17) & 0x3; |
+ if (layer == 0) |
+ return false; |
+ // bitrate (bits 15-12) can not be 1111 |
+ int bitrate_index = (header >> 12) & 0xf; |
+ if (bitrate_index == 0xf) |
+ return false; |
+ // sampling (bits 11-10) can not be 11 |
+ int sampling_index = (header >> 10) & 0x3; |
+ if (sampling_index == 3) |
+ return false; |
+ |
+ // Frame size: |
+ // For Layer I files = (12 * BitRate / SampleRate + Padding) * 4 |
+ // For others = 144 * BitRate / SampleRate + Padding |
+ // Unfortunately, BitRate and SampleRate are coded |
+ int padding = (header >> 9) & 0x1; |
+ int sampling_rate = Sample_Rate_Table[version][sampling_index]; |
+ int bitrate; |
+ if (version == Version1) { |
+ if (layer == Layer1) |
+ bitrate = Bit_Rate_Table_v1_l1[bitrate_index]; |
+ else if (layer == Layer2) |
+ bitrate = Bit_Rate_Table_v1_l2[bitrate_index]; |
+ else |
+ bitrate = Bit_Rate_Table_v1_l3[bitrate_index]; |
+ } |
+ else { |
+ if (layer == Layer1) |
+ bitrate = Bit_Rate_Table_v2_l1[bitrate_index]; |
+ else |
+ bitrate = Bit_Rate_Table_v2_l23[bitrate_index]; |
+ } |
+ if (layer == Layer1) |
+ *framesize = ((12000 * bitrate) / sampling_rate + padding) * 4; |
+ else |
+ *framesize = (144000 * bitrate) / sampling_rate + padding; |
+ return (bitrate > 0 && sampling_rate > 0); |
+} |
+ |
+// Extract a size encoded the MP3 way |
+static uint32_t get_mp3_header_size(const uint8_t buffer[]) { |
+ uint32_t size = ((buffer[6] & 0x7f) << 21) + |
+ ((buffer[7] & 0x7f) << 14) + |
+ ((buffer[8] & 0x7f) << 7) + |
+ (buffer[9] & 0x7f) + |
xhwang
2013/05/03 19:59:06
indent
jrummell
2013/05/03 23:56:21
Done.
|
+ 10; |
+ if (buffer[5] & 0x10) // footer added? |
+ size += 10; |
+ return size; |
+} |
+ |
+// Additional checks for a MP3 container. |
+static bool check_mp3(const uint8_t buffer[], |
+ size_t buffer_size, |
+ bool seenHeader) { |
xhwang
2013/05/03 19:59:06
ditto, check buffer_size?
jrummell
2013/05/03 23:56:21
Not sure why? We only return true if we see at lea
|
+ size_t framesize; |
+ size_t numSeen = 0; |
+ size_t offset = 0; |
+ if (seenHeader) |
+ offset = get_mp3_header_size(buffer); |
+ while (offset + 3 <= buffer_size && |
+ valid_mpeg_audio_frame_header(Read32(buffer + offset), &framesize)) { |
+ ++numSeen; |
+ offset += framesize; |
+ } |
+ return (numSeen > 10 || offset >= buffer_size); |
+} |
+ |
+// Extract an encoded MPC size, returning the value and |
+// the number of characters used by the size. |
+static int64_t get_mpc8_header_size(const uint8_t* b, size_t* count) { |
xhwang
2013/05/03 19:59:06
s/b/buffer and s/count/buffer_size to be consisten
jrummell
2013/05/03 23:56:21
Done s/b/buffer. However, the second is the number
|
+ int64_t size = 0; |
+ uint8_t c; |
+ *count = 0; |
+ do { |
+ c = *b++; |
+ if (++(*count) > 10) |
+ return -1; |
+ size = (size << 7) | (c & 0x7f); |
+ } while (c & 0x80); |
+ return size; |
+} |
+ |
+// Additional checks for a MPC8 container. |
+static bool check_mpc8(const uint8_t buffer[], size_t buffer_size) { |
+ size_t offset = 4; |
+ while (offset < buffer_size - 14) { |
xhwang
2013/05/03 19:59:06
size_t -14 is dangerous.
jrummell
2013/05/03 23:56:21
Done.
|
+ if (!isupper(buffer[offset]) || !isupper(buffer[offset + 1])) |
xhwang
2013/05/03 19:59:06
include what you use, add #include <cctype> ?
jrummell
2013/05/03 23:56:21
Done.
|
+ return false; |
+ |
+ size_t size_characters; |
+ int64_t size = get_mpc8_header_size(buffer + offset, &size_characters); |
+ if (size < 2) |
+ return false; |
+ if (buffer[offset] == 'S' && buffer[offset + 1] == 'H') { |
+ return (size >= 11 && size <= 28 && |
+ Read32(buffer + offset + size_characters + 2) != 0); |
+ } |
+ offset = offset + size + size_characters; |
+ } |
+ return false; |
+} |
+ |
+// Additional checks for a MSNWCTCP container. |
+static bool check_msnwctcp(const uint8_t buffer[], size_t buffer_size) { |
+ // The FFmpeg probe scans through the complete buffer looking for |
+ // a matching header. This code only looks for it at the beginning |
+ // of the buffer. |
+ uint32_t width = Read16(buffer + 2); |
xhwang
2013/05/03 19:59:06
check buffer_size before starting to read?
jrummell
2013/05/03 23:56:21
All the checks tagged with "Additional" are only c
|
+ uint32_t height = Read16(buffer + 4); |
+ if (!(width == 320 && height == 240) && !(width == 160 && height == 120)) |
+ return false; |
+ return (buffer_size > 16 && Read32(buffer + 12) != TAG('M','L','2','0')); |
+} |
+ |
+// Additional checks for a MTV container. |
+static bool check_mtv(const uint8_t buffer[], size_t buffer_size) { |
+ if (buffer_size < 58) |
+ return false; |
+ uint32_t bpp = Read16(buffer + 50); |
+ if (bpp != 16) |
+ return false; |
+ uint32_t width = Read16(buffer + 52); |
+ uint32_t height = Read16(buffer + 54); |
+ uint32_t segment_size = Read16(buffer + 56); |
+ return ((width != 0 && height != 0) || (segment_size != 0)); |
+} |
+ |
+// Additional checks for a NC container. |
+static bool check_nc(const uint8_t buffer[], size_t buffer_size) { |
+ uint32_t size = Read16(buffer + 5); |
xhwang
2013/05/03 19:59:06
check buffer_size before reading?
jrummell
2013/05/03 23:56:21
Done.
|
+ return (size + 20 < buffer_size && Read32(buffer + size + 16) == 0x1a5); |
+} |
+ |
+// Additional checks for a NSV container, only if the header isn't |
+// at the start of the file. |
+static bool check_nsv(const uint8_t buffer[], size_t buffer_size) { |
+ // Get the chunk size and check if at the end we are getting 0xBEEF |
+ if (buffer_size < 24) |
+ return false; |
+ size_t vsize = Read24(buffer + 19) >> 4; |
+ size_t asize = Read16(buffer + 22); |
+ size_t offset = 24 + asize + vsize; |
+ return (offset + 2 <= buffer_size && Read16(buffer + offset) == 0xbeef); |
+} |
+ |
+// Additional checks for an OMA container. |
+static bool check_oma(const uint8_t buffer[], size_t buffer_size) { |
+ if (buffer[4] != 0) |
xhwang
2013/05/03 19:59:06
check buffer_size before read?
jrummell
2013/05/03 23:56:21
Done.
|
+ return false; |
+ uint32_t tag_len = get_mp3_header_size(buffer); |
+ if (tag_len > buffer_size - 6) |
+ return false; |
+ return (Read24(buffer + tag_len) == TAG(0,'E','A','3') && |
+ buffer[tag_len + 4] == 0 && buffer[tag_len + 5] == 96); |
+} |
+ |
+// Additional checks for a PJS container. |
+static bool check_pjs(const uint8_t buffer[], size_t buffer_size) { |
+ size_t offset = 0; |
+ while (buffer[offset] != '"' && offset < buffer_size - 2) |
+ ++offset; |
+ ++offset; |
+ while (buffer[offset] != '"' && offset < buffer_size) { |
+ if (buffer[offset] == '\n' || buffer[offset] == '\r') |
+ return false; |
+ ++offset; |
+ } |
+ return true; |
+} |
+ |
+// Additional checks for a PVA container. |
+static bool check_pva(const uint8_t buffer[], size_t buffer_size) { |
+ uint32_t length = Read16(buffer + 6); |
+ if (buffer[4] != 0x55 || (buffer[5] & 0xe0) != 0 || length > 6136) |
+ return false; |
+ if (buffer_size < length + 8) |
+ return false; |
+ return (buffer[length] == 'A' && |
+ buffer[length + 1] == 'V' && |
+ (buffer[length + 2] == 1 || buffer[length + 2] == 2) && |
+ buffer[length + 4] == 0x55 && |
+ (buffer[5] & 0xe0) == 0 && |
+ Read16(buffer + length + 6) <= 6136); |
+} |
+ |
+// Additional checks for a TIERTEXSEQ container. |
+static bool check_tiertexseq(const uint8_t buffer[], size_t buffer_size) { |
+ // No real header, but first 256 bytes are always 0 |
+ if (buffer_size < 257) |
+ return false; |
+ for (int i = 0; i < 256; ++i) |
+ if (buffer[i] != 0) |
+ return false; |
+ return (buffer[256] != 0 && buffer[257] != 0); |
+} |
+ |
+// Additional checks for a TMV container. |
+static bool check_tmv(const uint8_t buffer[], size_t buffer_size) { |
+ return (Read16(buffer + 4) >= 5000 && // sample rate |
+ Read16(buffer + 6) >= 41 && // audio size |
+ buffer[8] == 0 && // compression method |
+ buffer[9] != 0 && // width |
+ buffer[10] != 0); // height |
+} |
+ |
+// Additional checks for a VIVO container. |
+static bool check_vivo(const uint8_t buffer[], size_t buffer_size) { |
+ if (buffer[0] != 0) |
+ return false; |
+ uint32_t length = buffer[1] & 0x7f; |
+ size_t offset = 2; |
+ if ((buffer[1] & 0x80) != 0) { |
+ if (buffer[2] & 0x80) |
+ return false; |
+ length = (length << 7) + (buffer[2] & 0x7f); |
+ offset = 3; |
+ } |
+ if (length < 21 || length > 1024 || offset + 16 > buffer_size) |
+ return false; |
+ return (CompareEqual(buffer + offset, |
+ buffer_size - offset, |
+ kVivoSignature, |
+ sizeof(kVivoSignature) - 1) && |
+ buffer[offset + 16] >= '0' && buffer[offset + 16] <= '2'); |
+} |
+ |
+// Additional checks for a VMD container. |
+static bool check_vmd(const uint8_t buffer[], size_t buffer_size) { |
+ if (buffer_size < 16) |
+ return false; |
+ uint32_t width = Read16(buffer + 12); |
+ uint32_t height = Read16(buffer + 14); |
+ return (width > 0 && width <= 2048 && height > 0 && height <= 2048); |
+} |
+ |
+// Additional checks for a VQF container. |
+static bool check_vqf(const uint8_t buffer[], size_t buffer_size) { |
+ return (CompareEqual(buffer + 4, buffer_size - 4, "97012000", 8) || |
+ CompareEqual(buffer + 4, buffer_size - 4, "00052200", 8)); |
+} |
+ |
+// Read a Matroska TAG, updating offset to point past it. |
+static int get_vtag(const uint8_t buffer[], size_t* offset) { |
+ // Size of the tag is determined the same way as VINT, |
+ // but the bit is not removed. Maximum of 4 bytes. |
+ int result = buffer[*offset]; |
+ if ((result & 0x80) != 0) { |
+ // It is a one byte tag |
+ ++*offset; |
+ } |
+ else if ((result & 0x40) != 0) { |
+ // It is a 2 byte tag |
+ result = Read16(buffer + *offset); |
+ *offset += 2; |
+ } |
+ else if ((result & 0x20) != 0) { |
+ // It is a 3 byte tag |
+ result = Read24(buffer + *offset); |
+ *offset += 3; |
+ } |
+ else { |
+ // It is a 4 byte tag |
+ result = Read32(buffer + *offset); |
+ *offset += 4; |
+ } |
+ return result; |
+} |
+ |
+// Read a Matroska VINT, updating offset to point past it. |
+static int get_vint(const uint8_t buffer[], size_t* offset) { |
+ // Length = 1 + [number_of_leading_zero_bits]. |
+ int size = 1; |
+ int mask = 0x80; |
+ uint8_t b = buffer[*offset]; |
+ while (mask > 0 && (b & mask) == 0) { |
+ ++size; |
+ mask = mask >> 1; |
+ } |
+ |
+ // Now that we know the size, use the remaining bits plus |
+ // following bytes to get the value. |
+ int result = buffer[(*offset)++] & (mask - 1); |
+ while (--size > 0) |
+ result = (result << 8) | buffer[(*offset)++]; |
+ return result; |
+} |
+ |
+// Additional checks for a WEBM container. |
+static bool check_webm(const uint8_t buffer[], size_t buffer_size) { |
+ size_t offset = 4; |
+ int header_size = get_vint(buffer, &offset); |
+ size_t lastoffset = offset + header_size; |
+ if (lastoffset > buffer_size) |
+ return false; |
+ while (offset < lastoffset) { |
+ int tag = get_vtag(buffer, &offset); |
+ int tagsize = get_vint(buffer, &offset); |
+ switch (tag) { |
+ case 0x4286: // EBMLVersion |
+ case 0x42f7: // EBMLReadVersion |
+ case 0x42f2: // EBMLMaxIdLength |
+ case 0x42f3: // EBMLMaxSizeLength |
+ case 0x4287: // DocTypeVersion |
+ case 0x4285: // DocTypeReadVersion |
+ case 0xec: // void |
+ case 0xbf: // CRC32 |
+ offset += tagsize; |
+ break; |
+ case 0x4282: // EBMLDocType |
+ return ( |
+ (tagsize >= 4 && |
+ CompareEqual(buffer + offset, buffer_size - offset, "webm", 4)) || |
+ (tagsize >= 8 && |
+ CompareEqual( |
+ buffer + offset, buffer_size - offset, "matroska", 8))); |
+ default: |
+ // Unrecognized tag |
+ return false; |
+ } |
+ } |
+ return false; |
+} |
+ |
+// Additional checks for a WSAUD container. |
+static bool check_wsaud(const uint8_t buffer[], size_t buffer_size) { |
+ uint32_t sample_rate = Read16(buffer); |
+ if (sample_rate < 8000 || sample_rate > 48000) |
+ return false; |
+ if ((buffer[10] & 0xfc) != 0 || (buffer[11] != 1 && buffer[11] != 99)) |
+ return false; |
+ return (buffer_size > 20 && Read32(buffer + 16) == 0x0000deaf); |
+} |
+ |
+// Additional checks for a XA container. |
+static bool check_xa(const uint8_t buffer[], size_t buffer_size) { |
+ if (buffer_size < 14) |
+ return false; |
+ uint32_t channels = Read16(buffer + 10); |
+ if (channels < 1 || channels > 8) |
+ return false; |
+ uint32_t srate = Read16(buffer + 12); |
+ if (srate < 1 || srate > 192000) |
+ return false; |
+ uint32_t bits_per_sample = Read16(buffer + 10); |
+ return (bits_per_sample >= 4 || bits_per_sample <= 32); |
+} |
+ |
+// Additional checks for a XBIN container. |
+static bool check_xbin(const uint8_t buffer[], size_t buffer_size) { |
+ uint32_t x = Read16(buffer + 5); |
+ return (buffer[4] == 0x1a && |
+ x > 0 && x <= 160 && |
+ buffer[9] > 0 && buffer[9] <= 32); |
+} |
+ |
+// Additional checks for a XMV container. |
+static bool check_xmv(const uint8_t buffer[], size_t buffer_size) { |
+ if (buffer_size < 18) |
+ return false; |
+ uint32_t version = Read16(buffer + 16); |
+ return (Read32(buffer + 12) == TAG('x','o','b','X') && |
+ version > 0 && version <= 4); |
+} |
+ |
+// Additional checks for a YOP container. |
+static bool check_yop(const uint8_t buffer[], size_t buffer_size) { |
+ return (buffer_size > 20 && |
+ buffer[2] < 10 && |
+ buffer[3] < 10 && |
+ buffer[6] != 0 && |
+ buffer[7] != 0 && |
+ (buffer[8] & 1) == 0 && |
+ (buffer[10] & 1) == 0 && |
+ Read16(buffer + 18) >= 920 && |
+ Read16(buffer + 18) < |
+ static_cast<uint32_t>(buffer[12] * 3 + 4 + buffer[7] * 2048)); |
+} |
+ |
+// Attempt to determine the container type from the buffer provided. This is |
+// a simple pass, that uses the first 4 bytes of the buffer as an index to get |
+// a rough idea of the container format. It covers the following containers |
+// (those with * are not fully covered): |
+// 4xm, act, aea, aiff, amr, anm, apc, ape, aqtitle, asf, ass, ast, au, avi, |
+// avr, avs, bethsoftvid, bfi, bink, bit, brstm, c93, caff, cdxl, concat, |
+// dfa, dnxhd, dsicin, dtshd, dxa, ea, epaf, ffm, ffmetadata, file_cpk, flac, |
+// flic, flv, frm, gif, gxf, hls, ico, idf, iff, ilbc, ircam, iss, iv8, ivf, |
+// jv, libnut, lmlm4, lvf, lxf, mgsts, mm, mmf, mov, mp3*, mpc, mpc8, |
+// msnwctcp*, mtv, mv, nc, nistsphere, nsv*, nut, nuv, ogg, oma, paf, pmp, |
+// pva, pvf, qcp, r3d, realtext, rl2, rm, roq, rpl, sami, siff, smjpeg, smk, |
+// smush, sol, sox, swf, tak, thp, tiertexseq, tmv, tta, txd, vc1test, vivo, |
+// vmd, vobsub, voc, vqf, w64, wav, wc3movie, webm, webvtt, wsaud, wsvqa, |
+// wtv, wv, xa, xbin, xmv, xwma, yop, yuv4mpegpipe |
+static FFmpegContainerName LookupContainerByFirst4(const uint8 buffer[], |
+ size_t buffer_size) { |
+ // Minimum size that the code expects to exist without checking size. |
+ if (buffer_size < 12) |
+ return CONTAINER_UNKNOWN; |
+ |
+ uint32_t first4 = Read32(buffer); |
+ uint32_t second4 = Read32(buffer + 4); |
+ uint32_t third4 = Read32(buffer + 8); |
+ uint32_t next; |
+ |
+ switch (first4) { |
+ case 0: |
+ if (buffer_size > 16 && |
+ Read16(buffer + 4) == 0x1bc && |
+ Read32(buffer + 10) == 0 && |
+ Read16(buffer + 14) == 0xe1e2) |
+ return CONTAINER_GXF; |
+ if (check_mm(buffer, buffer_size)) |
+ return CONTAINER_MM; |
+ if (second4 > 0 && second4 <= 1024 * 1024 && Read24(buffer + 8) == 1) |
+ return CONTAINER_LMLM4; |
+ if (check_tiertexseq(buffer, buffer_size)) |
+ return CONTAINER_TIERTEXSEQ; |
+ break; |
+ case 1: |
+ if (second4 > 0 && second4 <= 1024 * 1024 && Read24(buffer + 8) == 1) |
+ return CONTAINER_LMLM4; |
+ if (Read16(buffer + 4) != 0) |
+ return CONTAINER_ICO; |
+ break; |
+ case 2: |
+ if (second4 > 0 && second4 <= 1024 * 1024 && Read24(buffer + 8) == 1) |
+ return CONTAINER_LMLM4; |
+ break; |
+ case 4: |
+ if (second4 > 0 && second4 <= 1024 * 1024 && |
+ (Read16(buffer + 8) & 0xfffe) == 0xfffc) |
+ return CONTAINER_LMLM4; |
+ break; |
+ case 0xe: |
+ if (buffer_size > 16 && second4 == 0x50 && Read32(buffer + 12) == 0x34) |
+ return CONTAINER_MGSTS; |
+ break; |
+ case 0x16: |
+ if (third4 == 0x1803ffff || third4 == 0x1003ffff) |
+ return CONTAINER_TXD; |
+ break; |
+ case 0x1a5: |
+ if (check_nc(buffer, buffer_size)) |
+ return CONTAINER_NC; |
+ break; |
+ case TAG('\x00','\x00','\x02','\x80'): |
+ if (check_dnxhd(buffer, buffer_size)) |
+ return CONTAINER_DNXHD; |
+ break; |
+ case 0x800: |
+ if (check_aea(buffer, buffer_size)) |
+ return CONTAINER_AEA; |
+ break; |
+ case 0x001800a0: |
+ case 0x00180140: |
+ if (check_msnwctcp(buffer, buffer_size)) |
+ return CONTAINER_MSNWCTCP; |
+ break; |
+ case TAG('\x00','\x0a','S','M'): |
+ if (CompareEqual(buffer, |
+ buffer_size, |
+ kSmjpegSignature, |
+ sizeof(kSmjpegSignature) - 1)) |
+ return CONTAINER_SMJPEG; |
+ break; |
+ case 0x1084ffff: |
+ if (Read16(buffer + 4) == 0xffff) |
+ return CONTAINER_ROQ; |
+ break; |
+ case TAG('\x01','\x01','\x03','\xb8'): |
+ if (CompareEqual(buffer, |
+ buffer_size, |
+ kIv8Signature, |
+ sizeof(kIv8Signature) - 1)) |
+ return CONTAINER_IV8; |
+ break; |
+ case TAG('\x04','\x31','\x2e','\x34'): |
+ if (CompareEqual(buffer, |
+ buffer_size, |
+ kIdfSignature, |
+ sizeof(kIdfSignature) - 1)) |
+ return CONTAINER_IDF; |
+ break; |
+ case TAG('\x0b','\x8d','S','O'): |
+ case TAG('\x0c','\x0d','S','O'): |
+ case TAG('\x0c','\x8d','S','O'): |
+ if (buffer[4] == 'L' && buffer[5] == 0) |
+ return CONTAINER_SOL; |
+ break; |
+ case 0x1a45dfa3: |
+ if (check_webm(buffer, buffer_size)) |
+ return CONTAINER_WEBM; |
+ break; |
+ case TAG('.','s','n','d'): |
+ return CONTAINER_AU; |
+ case TAG('\x30','\x26','\xB2','\x75'): |
+ if (CompareEqual(buffer, |
+ buffer_size, |
+ kAsfSignature, |
+ sizeof(kAsfSignature) - 1)) |
+ return CONTAINER_ASF; |
+ break; |
+ case TAG(' ','p','a','f'): |
+ if (buffer_size > 24 && |
+ second4 == 0 && third4 == 0 && |
+ Read32(buffer + 12) != 0 && |
+ Read32(buffer + 20) != 0) |
+ return CONTAINER_EPAF; |
+ break; |
+ case TAG('#','!','A','M'): |
+ if (CompareEqual(buffer, |
+ buffer_size, |
+ kAmrSignature, |
+ sizeof(kAmrSignature) - 1)) |
+ return CONTAINER_AMR; |
+ break; |
+ case TAG('#','!','i','L'): |
+ if (CompareEqual(buffer, |
+ buffer_size, |
+ kIlbcSignature, |
+ sizeof(kIlbcSignature) - 1)) |
+ return CONTAINER_ILBC; |
+ break; |
+ case TAG('#','E','X','T'): |
+ if (check_hls(buffer, buffer_size)) |
+ return CONTAINER_HLS; |
+ break; |
+ case TAG('#',' ','V','o'): |
+ if (CompareEqual(buffer, |
+ buffer_size, |
+ kVobsubSignature, |
+ sizeof(kVobsubSignature) - 1)) |
+ return CONTAINER_VOBSUB; |
+ break; |
+ case TAG('.','R','M','F'): |
+ if (buffer[4] == 0 && buffer[5] == 0) |
+ return CONTAINER_RM; |
+ break; |
+ case TAG('.','r','a','\xfd'): |
+ return CONTAINER_RM; |
+ case TAG('.','S','o','X'): |
+ case TAG('X','o','S','.'): |
+ return CONTAINER_SOX; |
+ case TAG('1','S','N','h'): |
+ case TAG('S','C','H','l'): |
+ case TAG('S','E','A','D'): |
+ case TAG('S','H','E','N'): |
+ case TAG('k','V','G','T'): |
+ case TAG('M','A','D','k'): |
+ case TAG('M','P','C','h'): |
+ case TAG('M','V','h','d'): |
+ if ((second4 > 0x0fffff) && ((second4 & 0x0f0ff) != 0)) |
+ return CONTAINER_EA; |
+ break; |
+ case TAG('2','B','I','T'): |
+ return CONTAINER_AVR; |
+ case TAG('A','N','I','M'): |
+ if (third4 == TAG('A','H','D','R')) |
+ return CONTAINER_SMUSH; |
+ break; |
+ case TAG('A','R','M','o'): |
+ if (CompareEqual(buffer, |
+ buffer_size, |
+ kRplSignature, |
+ sizeof(kRplSignature) - 1)) |
+ return CONTAINER_RPL; |
+ break; |
+ case TAG('B','B','C','D'): |
+ return CONTAINER_DIRAC; |
+ case TAG('B','F','&','I'): |
+ return CONTAINER_BFI; |
+ case TAG(';','F','F','M'): |
+ if (CompareEqual(buffer, |
+ buffer_size, |
+ kFfSignature, |
+ sizeof(kFfSignature) - 1)) |
+ return CONTAINER_FFMETADATA; |
+ break; |
+ case TAG('B','I','K','b'): |
+ case TAG('B','I','K','f'): |
+ case TAG('B','I','K','g'): |
+ case TAG('B','I','K','h'): |
+ case TAG('B','I','K','i'): |
+ if (check_bink(buffer, buffer_size)) |
+ return CONTAINER_BINK; |
+ break; |
+ case TAG('c','a','f','f'): |
+ if (Read16(buffer + 4) == 1) |
+ return CONTAINER_CAF; |
+ break; |
+ case TAG('C','r','e','a'): |
+ if (CompareEqual(buffer, |
+ buffer_size, |
+ kVocSignature, |
+ sizeof(kVocSignature) - 1)) |
+ return CONTAINER_VOC; |
+ break; |
+ case TAG('C','R','Y','O'): |
+ if (CompareEqual(buffer, |
+ buffer_size, |
+ kApcSignature, |
+ sizeof(kApcSignature) - 1)) |
+ return CONTAINER_APC; |
+ break; |
+ case TAG('D','E','X','A'): |
+ if (buffer_size > 15 && |
+ Read16(buffer + 11) <= 2048 && |
+ Read16(buffer + 13) <= 2048) |
+ return CONTAINER_DXA; |
+ break; |
+ case TAG('D','K','I','F'): |
+ if (second4 == 32) |
+ return CONTAINER_IVF; |
+ break; |
+ case TAG('D','T','S','H'): |
+ if (second4 == TAG('D','H','D','R')) |
+ return CONTAINER_DTSHD; |
+ break; |
+ case TAG('D','F','I','A'): |
+ return CONTAINER_DFA; |
+ case TAG('\x64','\xa3','\x01','\x00'): |
+ case TAG('\x64','\xa3','\x02','\x00'): |
+ case TAG('\x64','\xa3','\x03','\x00'): |
+ case TAG('\x64','\xa3','\x04','\x00'): |
+ case TAG('\x00','\x01','\xa3','\x64'): |
+ case TAG('\x00','\x02','\xa3','\x64'): |
+ case TAG('\x00','\x03','\xa3','\x64'): |
+ if (second4 != 0 && third4 != 0) |
+ return CONTAINER_IRCAM; |
+ break; |
+ case TAG('e','a','3','\x03'): |
+ if (check_oma(buffer, buffer_size)) |
+ return CONTAINER_OMA; |
+ break; |
+ case TAG('f','a','p',' '): |
+ if (buffer_size > 24 && |
+ second4 == 0 && third4 == 1 && |
+ Read32(buffer + 12) != 0 && |
+ Read32(buffer + 20) != 0) |
+ return CONTAINER_EPAF; |
+ break; |
+ case TAG('f','f','c','o'): |
+ if (CompareEqual(buffer, |
+ buffer_size, |
+ kConcatSignature, |
+ sizeof(kConcatSignature) - 1)) |
+ return CONTAINER_CONCAT; |
+ break; |
+ case TAG('F','F','M','1'): |
+ case TAG('F','F','M','2'): |
+ return CONTAINER_FFM; |
+ case TAG('F','I','L','M'): |
+ return CONTAINER_FILM_CPK; |
+ case TAG('f','L','a','C'): |
+ return CONTAINER_FLAC; |
+ case TAG('F','L','V','\x00'): |
+ case TAG('F','L','V','\x01'): |
+ case TAG('F','L','V','\x02'): |
+ case TAG('F','L','V','\x03'): |
+ case TAG('F','L','V','\x04'): |
+ if (buffer[5] == 0 && Read32(buffer + 5) > 8) |
+ return CONTAINER_FLV; |
+ break; |
+ case TAG('F','O','R','M'): |
+ switch (third4) { |
+ case TAG('A','I','F','F'): |
+ case TAG('A','I','F','C'): |
+ return CONTAINER_AIFF; |
+ case TAG('8','S','V','X'): |
+ case TAG('1','6','S','V'): |
+ case TAG('M','A','U','D'): |
+ case TAG('P','B','M',' '): |
+ case TAG('A','C','B','M'): |
+ case TAG('D','E','E','P'): |
+ case TAG('I','L','B','M'): |
+ case TAG('R','G','B','8'): |
+ case TAG('R','G','B','N'): |
+ return CONTAINER_IFF; |
+ case TAG('M','O','V','E'): |
+ return CONTAINER_WC3MOVIE; |
+ case TAG('R','L','V','2'): |
+ case TAG('R','L','V','3'): |
+ return CONTAINER_RL2; |
+ case TAG('W','V','Q','A'): |
+ return CONTAINER_WSVQA; |
+ } |
+ break; |
+ case TAG('G','I','F','8'): |
+ if ((buffer[4] == '7' || buffer[4] == '9') && |
+ buffer[5] == 'a' && |
+ Read16(buffer + 6) != 0 && |
+ Read16(buffer + 8) != 0) |
+ return CONTAINER_GIF; |
+ break; |
+ case TAG('I','M','A','_'): |
+ if (CompareEqual(buffer, |
+ buffer_size, |
+ kIssSignature, |
+ sizeof(kIssSignature) - 1)) |
+ return CONTAINER_ISS; |
+ break; |
+ case TAG('k','!','\x00','\x40'): |
+ case TAG('k','!','\x00','\x50'): |
+ return CONTAINER_BIT; |
+ case TAG('L','E','I','T'): |
+ if (CompareEqual(buffer, |
+ buffer_size, |
+ kLxfSignature, |
+ sizeof(kLxfSignature) - 1)) |
+ return CONTAINER_LXF; |
+ break; |
+ case TAG('L','P','F',' '): |
+ if (buffer_size > 24 && |
+ Read32(buffer + 16) == TAG('A','N','I','M') && |
+ Read16(buffer + 20) != 0 && |
+ Read16(buffer + 22) != 0) |
+ return CONTAINER_ANM; |
+ break; |
+ case TAG('L','V','F','F'): |
+ return CONTAINER_LVF; |
+ case TAG('M','A','C',' '): |
+ return CONTAINER_APE; |
+ case TAG('M','M','M','D'): |
+ if (third4 == TAG('C','N','T','I')) |
+ return CONTAINER_MMF; |
+ break; |
+ case TAG('M','O','V','I'): |
+ if (Read16(buffer + 4) < 3) |
+ return CONTAINER_MV; |
+ break; |
+ case TAG('M','P','+','\x07'): |
+ case TAG('M','P','+','\x17'): |
+ return CONTAINER_MPC; |
+ case TAG('M','P','C','K'): |
+ if (check_mpc8(buffer, buffer_size)) |
+ return CONTAINER_MPC8; |
+ break; |
+ case TAG('N','I','S','T'): |
+ if (second4 == TAG('_','1','A','\x0a')) |
+ return CONTAINER_NISTSPHERE; |
+ break; |
+ case TAG('N','M','\x7a','\x56'): |
+ if (second4 == TAG('\x1F','\x5F','\x04','\xAD')) |
+ return CONTAINER_NUT; |
+ break; |
+ case TAG('N','S','V','f'): |
+ case TAG('N','S','V','s'): |
+ return CONTAINER_NSV; |
+ case TAG('n','u','t','/'): |
+ if (CompareEqual(buffer, |
+ buffer_size, |
+ kLibnutSignature, |
+ sizeof(kLibnutSignature) - 1)) |
+ return CONTAINER_LIBNUT; |
+ break; |
+ case TAG('N','u','p','p'): |
+ if (CompareEqual(buffer, |
+ buffer_size, |
+ kNuv1Signature, |
+ sizeof(kNuv1Signature) - 1)) |
+ return CONTAINER_NUV; |
+ break; |
+ case TAG('M','y','t','h'): |
+ if (CompareEqual(buffer, |
+ buffer_size, |
+ kNuv2Signature, |
+ sizeof(kNuv2Signature) - 1)) |
+ return CONTAINER_NUV; |
+ break; |
+ case TAG('O','N','2',' '): |
+ if (third4 == TAG('O','N','2','f')) |
+ return CONTAINER_AVI; |
+ case TAG('O','g','g','S'): |
+ if (buffer[5] <= 7) |
+ return CONTAINER_OGG; |
+ break; |
+ case TAG('P','a','c','k'): |
+ if (CompareEqual(buffer, |
+ buffer_size, |
+ kPafSignature, |
+ sizeof(kPafSignature) - 1)) |
+ return CONTAINER_PAF; |
+ break; |
+ case TAG('p','m','p','m'): |
+ if (Read32(buffer + 4) == 1) |
+ return CONTAINER_PMP; |
+ break; |
+ case TAG('P','V','F','1'): |
+ if (buffer[4] == '\n') |
+ return CONTAINER_PVF; |
+ break; |
+ case TAG('R','F','6','4'): |
+ if (buffer_size > 16 && Read32(buffer + 12) == TAG('d','s','6','4')) |
+ return CONTAINER_WAV; |
+ break; |
+ case TAG('r','i','f','f'): |
+ if (CompareEqual(buffer, |
+ buffer_size, |
+ kW64Signature, |
+ sizeof(kW64Signature) - 1) && |
+ CompareEqual(buffer + 24, |
+ buffer_size - 24, |
+ kW64Signature2, |
+ sizeof(kW64Signature2) - 1)) |
+ return CONTAINER_W64; |
+ break; |
+ case TAG('R','I','F','F'): |
+ switch (third4) { |
+ case TAG('4','X','M','V'): |
+ return CONTAINER_4XM; |
+ case TAG('A','V','I',' '): |
+ case TAG('A','V','I','X'): |
+ case TAG('A','V','I','\x19'): |
+ case TAG('A','M','V',' '): |
+ return CONTAINER_AVI; |
+ case TAG('Q','L','C','M'): |
+ if (buffer_size > 16 && Read32(buffer + 12) == TAG('f','m','t',' ')) |
+ return CONTAINER_QCP; |
+ break; |
+ case TAG('W','A','V','E'): |
+ // possibly ACT or WAV |
+ return (check_act(buffer, buffer_size)) ? |
+ CONTAINER_ACT : CONTAINER_WAV; |
+ case TAG('X','W','M','A'): |
+ return CONTAINER_XWMA; |
+ } |
+ break; |
+ case TAG('R','S','T','M'): |
+ next = Read16(buffer + 4); |
+ if (next == 0xfffe || next == 0xfeff) |
+ return CONTAINER_BRSTM; |
+ break; |
+ case TAG('S','A','N','M'): |
+ if (third4 == TAG('S','H','D','R')) |
+ return CONTAINER_SMUSH; |
+ break; |
+ case TAG('S','I','F','F'): |
+ if (third4 == TAG('V','B','V','1') || third4 == TAG('S','O','U','N')) |
+ return CONTAINER_SIFF; |
+ break; |
+ case TAG('S','M','K','2'): |
+ case TAG('S','M','K','4'): |
+ return CONTAINER_SMK; |
+ case TAG('S','T','R','M'): |
+ if (buffer_size > 18 && Read16(buffer + 10) && Read16(buffer + 12) && |
+ Read16(buffer + 16)) |
+ return CONTAINER_AST; |
+ break; |
+ case TAG('t','B','a','K'): |
+ return CONTAINER_TAK; |
+ case TAG('T','H','P','\x00'): |
+ return CONTAINER_THP; |
+ case TAG('T','M','A','V'): |
+ if (check_tmv(buffer, buffer_size)) |
+ return CONTAINER_TMV; |
+ break; |
+ case TAG('T','T','A','1'): |
+ return CONTAINER_TTA; |
+ case TAG('\x55','\xaa','\x00','\x00'): |
+ if (check_dsicin(buffer, buffer_size)) |
+ return CONTAINER_DSICIN; |
+ break; |
+ case TAG('T','W','I','N'): |
+ if (check_vqf(buffer, buffer_size)) |
+ return CONTAINER_VQF; |
+ break; |
+ case TAG('V','I','D','\x00'): |
+ return CONTAINER_BETHSOFTVID; |
+ case TAG('w','W','\x10','\x00'): |
+ return CONTAINER_AVS; |
+ case TAG('w','v','p','k'): |
+ return CONTAINER_WV; |
+ case TAG('X','A','\x00','\x00'): |
+ case TAG('X','A','I','\x00'): |
+ case TAG('X','A','J','\x00'): |
+ if (check_xa(buffer, buffer_size)) |
+ return CONTAINER_XA; |
+ break; |
+ case TAG('X','B','I','N'): |
+ if (check_xbin(buffer, buffer_size)) |
+ return CONTAINER_XBIN; |
+ break; |
+ case TAG('Y','U','V','4'): |
+ if (CompareEqual(buffer, |
+ buffer_size, |
+ kYuv4Signature, |
+ sizeof(kYuv4Signature) - 1)) |
+ return CONTAINER_YUV4MPEGPIPE; |
+ break; |
+ case TAG('W','E','B','V'): |
+ if (CompareEqual(buffer, |
+ buffer_size, |
+ kWebvttSignature, |
+ sizeof(kWebvttSignature) - 1)) |
+ return CONTAINER_WEBVTT; |
+ break; |
+ case TAG('\xef','\xbb','\xbf','W'): |
+ if (CompareEqual(buffer, |
+ buffer_size, |
+ kWebvttBomSignature, |
+ sizeof(kWebvttBomSignature) - 1)) |
+ return CONTAINER_WEBVTT; |
+ break; |
+ case TAG('[','S','c','r'): |
+ if (CompareEqual(buffer, |
+ buffer_size, |
+ kAssSignature, |
+ sizeof(kAssSignature) - 1)) |
+ return CONTAINER_ASS; |
+ break; |
+ case TAG('\xef','\xbb','\xbf','['): |
+ if (CompareEqual(buffer, |
+ buffer_size, |
+ kAssBomSignature, |
+ sizeof(kAssBomSignature) - 1)) |
+ return CONTAINER_ASS; |
+ break; |
+ case TAG('<','w','i','n'): |
+ if (CompareEqual(buffer, |
+ buffer_size, |
+ kRealSignature, |
+ sizeof(kRealSignature) - 1)) |
+ return CONTAINER_REALTEXT; |
+ break; |
+ case TAG('<','S','A','M'): |
+ if (CompareEqual(buffer, |
+ buffer_size, |
+ kSamiSignature, |
+ sizeof(kSamiSignature) - 1)) |
+ return CONTAINER_SAMI; |
+ break; |
+ case TAG('\xef','\xbb','\xbf','<'): |
+ if (CompareEqual(buffer, |
+ buffer_size, |
+ kRealBomSignature, |
+ sizeof(kRealBomSignature) - 1)) |
+ return CONTAINER_REALTEXT; |
+ if (CompareEqual(buffer, |
+ buffer_size, |
+ kSamiBomSignature, |
+ sizeof(kSamiBomSignature) - 1)) |
+ return CONTAINER_SAMI; |
+ break; |
+ case TAG('\xb7','\xd8','\x00','\x20'): |
+ if (CompareEqual(buffer, |
+ buffer_size, |
+ kWtvSignature, |
+ sizeof(kWtvSignature) - 1)) |
+ return CONTAINER_WTV; |
+ break; |
+ } |
+ |
+ // Now try a few different ones that look at something other |
+ // than the first 4 bytes |
+ uint32_t first3 = first4 & 0xffffff00; |
+ switch (first3) { |
+ case TAG('A','M','V',0): |
+ if (check_mtv(buffer, buffer_size)) |
+ return CONTAINER_MTV; |
+ break; |
+ case TAG('C','W','S',0): |
+ case TAG('F','W','S',0): |
+ return CONTAINER_SWF; |
+ case TAG('F','R','M',0): |
+ if (Read16(buffer + 4) != 0 && Read16(buffer + 6) != 0) |
+ return CONTAINER_FRM; |
+ break; |
+ case TAG('A','V','\x01',0): |
+ case TAG('A','V','\x02',0): |
+ if (check_pva(buffer, buffer_size)) |
+ return CONTAINER_PVA; |
+ break; |
+ case TAG('I','D','3',0): |
+ if (check_mp3(buffer, buffer_size, true)) |
+ return CONTAINER_MP3; |
+ break; |
+ } |
+ |
+ // Maybe the first 2 characters are something we can use. |
+ uint32_t first2 = first4 & 0xffff0000; |
+ switch (first2) { |
+ case 0x032e0000: |
+ if (check_vmd(buffer, buffer_size)) |
+ return CONTAINER_VMD; |
+ break; |
+ case 0x04000000: |
+ case 0x04040000: |
+ case 0x040c0000: |
+ case 0x04140000: |
+ return CONTAINER_EA_CDATA; |
+ case TAG('J','V',0,0): |
+ if (CompareEqual(buffer + 4, |
+ buffer_size - 4, |
+ kJvSignature, |
+ sizeof(kJvSignature) - 1)) |
+ return CONTAINER_JV; |
+ break; |
+ case 0x0b770000: |
+ if (check_ac3(buffer, buffer_size)) |
+ return CONTAINER_AC3; |
+ if (check_eac3(buffer, buffer_size)) |
+ return CONTAINER_EAC3; |
+ break; |
+ case TAG('Y','O',0,0): |
+ if (check_yop(buffer, buffer_size)) |
+ return CONTAINER_JV; |
+ break; |
+ case 0xfff00000: |
+ case 0xfff10000: |
+ case 0xfff80000: |
+ case 0xfff90000: |
+ if (check_aac(buffer, buffer_size)) |
+ return CONTAINER_AAC; |
+ break; |
+ } |
+ |
+ // Now try the second set of 4 characters. |
+ switch (second4) { |
+ case 4: |
+ if (buffer_size > 24 && buffer[3] == 0xc5 && Read32(buffer + 20) == 0xc) |
+ return CONTAINER_VC1TEST; |
+ break; |
+ case TAG('R','E','D','1'): |
+ return CONTAINER_R3D; |
+ } |
+ |
+ switch (Read16(buffer + 4)) { |
+ case 0xaf11: |
+ case 0xaf12: |
+ case 0xaf13: |
+ if (buffer_size > 20 && |
+ third4 <= 4096 && |
+ Read16(buffer + 10) <= 4096 && |
+ (Read16(buffer + 16) == 0xf1fa || Read32(buffer + 16) <= 2000)) |
+ return CONTAINER_FLIC; |
+ break; |
+ } |
+ |
+ // Lastly, there are some that are other simple checks but don't fit |
+ // the above case statements. |
+ if (check_c93(buffer, buffer_size)) |
+ return CONTAINER_C93; |
+ if (check_cdxl(buffer, buffer_size)) |
+ return CONTAINER_CDXL; |
+ if (check_idcin(buffer, buffer_size)) |
+ return CONTAINER_IDCIN; |
+ if (check_loas(buffer, buffer_size)) |
+ return CONTAINER_LOAS; |
+ if (check_m4v(buffer, buffer_size)) |
+ return CONTAINER_M4V; |
+ if (check_mov(buffer, buffer_size)) |
+ return CONTAINER_MOV; |
+ if (check_vivo(buffer, buffer_size)) |
+ return CONTAINER_VIVO; |
+ if (check_wsaud(buffer, buffer_size)) |
+ return CONTAINER_WSAUD; |
+ if (check_xmv(buffer, buffer_size)) |
+ return CONTAINER_XMV; |
+ // Check if the file is in MP3 format without the header |
+ if (check_mp3(buffer, buffer_size, false)) |
+ return CONTAINER_MP3; |
+ |
+ // skip over starting 0's, and see if it is MP3/AC3/EAC3 |
+ if (buffer[0] == 0) { |
+ size_t offset = 1; |
+ size_t remaining = buffer_size - 1; |
+ while (remaining > 0 && buffer[offset] == 0) { |
+ ++offset; |
+ --remaining; |
+ } |
+ if (remaining > 32) { |
+ // not worth trying if only a small number of bytes left |
+ if (Read16(buffer + offset) == 0x0b77) { |
+ if (check_ac3(buffer + offset, remaining)) |
+ return CONTAINER_AC3; |
+ if (check_eac3(buffer + offset, remaining)) |
+ return CONTAINER_EAC3; |
+ } |
+ else if (check_mp3(buffer + offset, remaining, false)) |
+ return CONTAINER_MP3; |
+ } |
+ } |
+ |
+ return CONTAINER_UNKNOWN; |
+} |
+ |
+static const char ipm_string[] = "Interplay MVE File\x1A\0\x1A"; |
+static const char mxf_string[] = |
+ "\x06\x0e\x2b\x34\x02\x05\x01\x01\x0d\x01\x02\x01\x01\x02"; |
+static const char sub1_string[] = "******** START SCRIPT ********"; |
+ |
+// Attempt to determine the container type by scanning for a set of strings, |
+// character by character. It covers the following containers: |
+// ipmovie, mxf, subviewer1 |
+static FFmpegContainerName LookupContainerByStringScan(const uint8 buffer[], |
+ size_t buffer_size) { |
+ size_t offset = 0; |
+ size_t remaining = buffer_size; |
+ while (offset + 4 < buffer_size) { |
+ uint32_t tag = Read32(buffer + offset); |
+ switch (tag) { |
+ case TAG('I','n','t','e'): |
+ if (CompareEqual(buffer + offset, |
+ remaining, |
+ ipm_string, |
+ sizeof(ipm_string) - 1)) |
+ return CONTAINER_IPMOVIE; |
+ break; |
+ case 0x060e2b34: |
+ if (CompareEqual(buffer + offset, |
+ remaining, |
+ mxf_string, |
+ sizeof(mxf_string) - 1)) |
+ return CONTAINER_MXF; |
+ break; |
+ case TAG('*','*','*','*'): |
+ if (CompareEqual(buffer + offset, |
+ remaining, |
+ sub1_string, |
+ sizeof(sub1_string) - 1)) |
+ return CONTAINER_SUBVIEWER1; |
+ break; |
+ case TAG('N','S','V','s'): |
+ if (check_nsv(buffer + offset, remaining)) |
+ return CONTAINER_NSV; |
+ break; |
+ case 0x001800a0: |
+ case 0x00180140: |
+ if (check_msnwctcp(buffer + offset, remaining)) |
+ return CONTAINER_MSNWCTCP; |
+ break; |
+ } |
+ |
+ // Not found, move forward to next character. |
+ ++offset; |
+ --remaining; |
+ } |
+ |
+ // didn't find a string match for any of the formats |
+ return CONTAINER_UNKNOWN; |
+} |
+ |
+// Helper function to do limited scanf functionality without going off |
+// the end of the buffer. |
+static bool SaferScanf(const uint8_t* buffer, |
+ size_t buffer_size, |
+ const char* format) { |
+ // This function only supports the following items in the format string: |
+ // %<maxlength>d -- integer (can start with +/-, maxlength is optional) |
+ // %<maxlength>u -- unsigned integer (only digits, maxlength is optional) |
+ // %c -- any single character |
+ // %[<characters>] -- character must be one of the set |
+ // -- everything else is a literal |
+ // This code assumes that format is correct. |
+ size_t offset = 0; |
+ while (offset < buffer_size) { |
+ // Determine next format item. |
+ if (*format == '\0') { |
+ // End of format string, success. |
+ return true; |
+ } else if (*format != '%') { |
+ // Not a specifier, so it must match exactly |
+ if (buffer[offset] != *format) |
+ return false; |
+ ++offset; |
+ } else { |
+ ++format; |
+ int maxLength = 0; |
+ int numSeen = 0; |
+ while (isdigit(*format)) { |
+ maxLength = maxLength * 10 + (*format - '0'); |
+ ++format; |
+ } |
+ if (maxLength < 1) // If not specified set it to 100 to simplify below |
+ maxLength = 100; |
+ switch (*format) { |
+ case 'c': |
+ ++offset; // Don't care what the character is |
+ break; |
+ case 'd': |
+ if (buffer[offset] == '+' || buffer[offset] == '-') |
+ ++offset; |
+ case 'u': |
+ // need to process up to maxLength digits |
+ while (offset < buffer_size && |
+ --maxLength >= 0 && |
+ isdigit(buffer[offset])) { |
+ ++numSeen; |
+ ++offset; |
+ } |
+ if (numSeen == 0) // No digits, so it is not a match for %d/%u |
+ return false; |
+ break; |
+ case '[': |
+ ++format; // Skip [ |
+ while (*format != ']') { |
+ if (buffer[offset] == *format) { |
+ ++numSeen; |
+ } |
+ ++format; |
+ } |
+ if (numSeen == 0) // No character match |
+ return false; |
+ ++offset; // Skip the character matched |
+ break; |
+ default: |
+ NOTREACHED(); |
+ } |
+ } |
+ // Move to the next format specification. |
+ ++format; |
+ } |
+ // Out of buffer, so it doesn't match |
+ return false; |
+} |
+ |
+// Attempt to determine the container type by scanning for a set of strings, |
+// line by line. It covers the following containers: |
+// microdvd, mpl2, mpsub, pjs, sdp, srt, subviewer, vplayer |
+static FFmpegContainerName LookupContainerByStringLine(const uint8 buffer[], |
+ size_t buffer_size) { |
+ size_t offset = CompareEqual(buffer, buffer_size, BYTE_ORDER_MARK, 3) ? 3 : 0; |
+ size_t lines = 0; |
+ |
+ // PJS is a scan from the beginning only. |
+ if (SaferScanf(buffer, buffer_size, "%d,%d,%c")) |
+ if (check_pjs(buffer, buffer_size)) |
+ return CONTAINER_PJS; |
+ |
+ // Same for VPLAYER. |
+ if (SaferScanf(buffer, buffer_size, "%d:%d:%d.%d%[: =]")) |
+ return CONTAINER_VPLAYER; |
+ |
+ // Same for AQTITLE |
+ if (SaferScanf(buffer, buffer_size, "-->> %d")) |
+ return CONTAINER_AQTITLE; |
+ |
+ while (offset < buffer_size) { |
+ const uint8_t* ptr = buffer + offset; |
+ size_t remaining = buffer_size - offset;; |
+ |
+ if (*ptr == '{' && lines < 3) { |
+ if (SaferScanf(ptr, remaining, "{%d}{}%c") || |
+ SaferScanf(ptr, remaining, "{%d}{%d}%c") || |
+ SaferScanf(ptr, remaining, "{DEFAULT}{}%c")) |
+ return CONTAINER_MICRODVD; |
+ } |
+ |
+ if (*ptr == '[' && lines < 3) { |
+ if (SaferScanf(ptr, remaining, "[%64d][%64d]%c") || |
+ SaferScanf(ptr, remaining, "[%64d][]%c")) |
+ return CONTAINER_MPL2; |
+ } |
+ |
+ if (*ptr == 'F') { |
+ if (SaferScanf(ptr, remaining, "FORMAT=%d") || |
+ SaferScanf(ptr, remaining, "FORMAT=TIME")) |
+ return CONTAINER_MPSUB; |
+ } |
+ |
+ if (*ptr == 'c') { |
+ if (CompareEqual(ptr, remaining, "c=IN IP", 7)) |
+ return CONTAINER_SDP; |
+ } |
+ |
+ if (isdigit(*ptr) && lines < 3) { |
+ if (SaferScanf( |
+ ptr, remaining, "%d:%2d:%2d%[,.]%3d --> %d:%2d:%2d%[,.]%3d")) |
+ return CONTAINER_SRT; |
+ } |
+ |
+ if (isdigit(*ptr) && lines < 1) { |
+ if (SaferScanf(ptr, remaining, "%u:%u:%u.%u,%u:%u:%u.%u%c") || |
+ CompareEqual(ptr, remaining, "[INFORMATION]", 13)) |
+ return CONTAINER_SUBVIEWER; |
+ } |
+ |
+ // Find the end of the line. |
+ while (buffer[offset] != '\n' && buffer[offset] != '\r' && |
+ offset < buffer_size) |
+ ++offset; |
+ |
+ // Skip the \n\r. |
+ while ((buffer[offset] == '\n' || buffer[offset] == '\r') && |
+ offset < buffer_size) |
+ ++offset; |
+ ++lines; |
+ } |
+ |
+ // Didn't find a string match for any of the formats. |
+ return CONTAINER_UNKNOWN; |
+} |
+ |
+// The strings in the list below are the ones returned by FFmpeg. |
+// This would be the string from AVInputFormat.name. The list is |
+// sorted by string alphabetically, so that we can use a binary |
+// search when looking for a container by name. |
+const ContainerNameMapping ContainerNames::container_name_mapping[] = { |
+ { CONTAINER_4XM, "4xm" }, |
+ { CONTAINER_AAC, "aac" }, |
+ { CONTAINER_AC3, "ac3" }, |
+ { CONTAINER_ACT, "act" }, |
+ { CONTAINER_ADF, "adf" }, |
+ { CONTAINER_ADX, "adx" }, |
+ { CONTAINER_AEA, "aea" }, |
+ { CONTAINER_AFC, "afc" }, |
+ { CONTAINER_AIFF, "aiff" }, |
+ { CONTAINER_ALAW, "alaw" }, |
+ { CONTAINER_ALSA, "alsa" }, |
+ { CONTAINER_AMR, "amr" }, |
+ { CONTAINER_ANM, "anm" }, |
+ { CONTAINER_APC, "apc" }, |
+ { CONTAINER_APE, "ape" }, |
+ { CONTAINER_AQTITLE, "aqtitle" }, |
+ { CONTAINER_ASF, "asf" }, |
+ { CONTAINER_ASS, "ass" }, |
+ { CONTAINER_AST, "ast" }, |
+ { CONTAINER_AU, "au" }, |
+ { CONTAINER_AVI, "avi" }, |
+ { CONTAINER_AVISYNTH, "avisynth" }, |
+ { CONTAINER_AVR, "avr" }, |
+ { CONTAINER_AVS, "avs" }, |
+ { CONTAINER_BETHSOFTVID, "bethsoftvid" }, |
+ { CONTAINER_BFI, "bfi" }, |
+ { CONTAINER_BIN, "bin" }, |
+ { CONTAINER_BINK, "bink" }, |
+ { CONTAINER_BIT, "bit" }, |
+ { CONTAINER_BKTR, "bktr" }, |
+ { CONTAINER_BMV, "bmv" }, |
+ { CONTAINER_BRSTM, "brstm" }, |
+ { CONTAINER_C93, "c93" }, |
+ { CONTAINER_CAF, "caf" }, |
+ { CONTAINER_CAVSVIDEO, "cavsvideo" }, |
+ { CONTAINER_CDG, "cdg" }, |
+ { CONTAINER_CDXL, "cdxl" }, |
+ { CONTAINER_CONCAT, "concat" }, |
+ { CONTAINER_DAUD, "daud" }, |
+ { CONTAINER_DFA, "dfa" }, |
+ { CONTAINER_DIRAC, "dirac" }, |
+ { CONTAINER_DNXHD, "dnxhd" }, |
+ { CONTAINER_DSHOW, "dshow" }, |
+ { CONTAINER_DSICIN, "dsicin" }, |
+ { CONTAINER_DTS, "dts" }, |
+ { CONTAINER_DTSHD, "dtshd" }, |
+ { CONTAINER_DV, "dv" }, |
+ { CONTAINER_DV1394, "dv1394" }, |
+ { CONTAINER_DXA, "dxa" }, |
+ { CONTAINER_EA, "ea" }, |
+ { CONTAINER_EA_CDATA, "ea_cdata" }, |
+ { CONTAINER_EAC3, "eac3" }, |
+ { CONTAINER_EPAF, "epaf" }, |
+ { CONTAINER_F32BE, "f32be" }, |
+ { CONTAINER_F32LE, "f32le" }, |
+ { CONTAINER_F64BE, "f64be" }, |
+ { CONTAINER_F64LE, "f64le" }, |
+ { CONTAINER_FBDEV, "fbdev" }, |
+ { CONTAINER_FFM, "ffm" }, |
+ { CONTAINER_FFMETADATA, "ffmetadata" }, |
+ { CONTAINER_FILM_CPK, "film_cpk" }, |
+ { CONTAINER_FILMSTRIP, "filmstrip" }, |
+ { CONTAINER_FLAC, "flac" }, |
+ { CONTAINER_FLIC, "flic" }, |
+ { CONTAINER_FLV, "flv" }, |
+ { CONTAINER_FRM, "frm" }, |
+ { CONTAINER_G722, "g722" }, |
+ { CONTAINER_G723_1, "g723_1" }, |
+ { CONTAINER_G729, "g729" }, |
+ { CONTAINER_GIF, "gif" }, |
+ { CONTAINER_GSM, "gsm" }, |
+ { CONTAINER_GXF, "gxf" }, |
+ { CONTAINER_H261, "h261" }, |
+ { CONTAINER_H263, "h263" }, |
+ { CONTAINER_H264, "h264" }, |
+ { CONTAINER_HLS, "hls,applehttp" }, |
+ { CONTAINER_ICO, "ico" }, |
+ { CONTAINER_IDCIN, "idcin" }, |
+ { CONTAINER_IDF, "idf" }, |
+ { CONTAINER_IEC61883, "iec61883" }, |
+ { CONTAINER_IFF, "iff" }, |
+ { CONTAINER_ILBC, "ilbc" }, |
+ { CONTAINER_IMAGE2, "image2" }, |
+ { CONTAINER_IMAGE2PIPE, "image2pipe" }, |
+ { CONTAINER_INGENIENT, "ingenient" }, |
+ { CONTAINER_IPMOVIE, "ipmovie" }, |
+ { CONTAINER_IRCAM, "ircam" }, |
+ { CONTAINER_ISS, "iss" }, |
+ { CONTAINER_IV8, "iv8" }, |
+ { CONTAINER_IVF, "ivf" }, |
+ { CONTAINER_JACK, "jack" }, |
+ { CONTAINER_JACOSUB, "jacosub" }, |
+ { CONTAINER_JV, "jv" }, |
+ { CONTAINER_LATM, "latm" }, |
+ { CONTAINER_LAVFI, "lavfi" }, |
+ { CONTAINER_LIBCDIO, "libcdio" }, |
+ { CONTAINER_LIBDC1394, "libdc1394" }, |
+ { CONTAINER_LIBMODPLUG, "libmodplug" }, |
+ { CONTAINER_LIBNUT, "libnut" }, |
+ { CONTAINER_LMLM4, "lmlm4" }, |
+ { CONTAINER_LOAS, "loas" }, |
+ { CONTAINER_LVF, "lvf" }, |
+ { CONTAINER_LXF, "lxf" }, |
+ { CONTAINER_M4V, "m4v" }, |
+ { CONTAINER_WEBM, "matroska,webm" }, |
+ { CONTAINER_MGSTS, "mgsts" }, |
+ { CONTAINER_MICRODVD, "microdvd" }, |
+ { CONTAINER_MJPEG, "mjpeg" }, |
+ { CONTAINER_MLP, "mlp" }, |
+ { CONTAINER_MM, "mm" }, |
+ { CONTAINER_MMF, "mmf" }, |
+ { CONTAINER_MOV, "mov,mp4,m4a,3gp,3g2,mj2" }, |
+ { CONTAINER_MP3, "mp3" }, |
+ { CONTAINER_MPC, "mpc" }, |
+ { CONTAINER_MPC8, "mpc8" }, |
+ { CONTAINER_MPEG, "mpeg" }, |
+ { CONTAINER_MPEGTS, "mpegts" }, |
+ { CONTAINER_MPEGTSRAW, "mpegtsraw" }, |
+ { CONTAINER_MPEGVIDEO, "mpegvideo" }, |
+ { CONTAINER_MPL2, "mpl2" }, |
+ { CONTAINER_MPSUB, "mpsub" }, |
+ { CONTAINER_MSNWCTCP, "msnwctcp" }, |
+ { CONTAINER_MTV, "mtv" }, |
+ { CONTAINER_MULAW, "mulaw" }, |
+ { CONTAINER_MV, "mv" }, |
+ { CONTAINER_MVI, "mvi" }, |
+ { CONTAINER_MXF, "mxf" }, |
+ { CONTAINER_MXG, "mxg" }, |
+ { CONTAINER_NC, "nc" }, |
+ { CONTAINER_NISTSPHERE, "nistsphere" }, |
+ { CONTAINER_NSV, "nsv" }, |
+ { CONTAINER_NUT, "nut" }, |
+ { CONTAINER_NUV, "nuv" }, |
+ { CONTAINER_OGG, "ogg" }, |
+ { CONTAINER_OMA, "oma" }, |
+ { CONTAINER_OPENAL, "openal" }, |
+ { CONTAINER_OSS, "oss" }, |
+ { CONTAINER_PAF, "paf" }, |
+ { CONTAINER_PJS, "pjs" }, |
+ { CONTAINER_PMP, "pmp" }, |
+ { CONTAINER_PSXSTR, "psxstr" }, |
+ { CONTAINER_PULSE, "pulse" }, |
+ { CONTAINER_PVA, "pva" }, |
+ { CONTAINER_PVF, "pvf" }, |
+ { CONTAINER_QCP, "qcp" }, |
+ { CONTAINER_R3D, "r3d" }, |
+ { CONTAINER_RAWVIDEO, "rawvideo" }, |
+ { CONTAINER_RDT, "rdt" }, |
+ { CONTAINER_REALTEXT, "realtext" }, |
+ { CONTAINER_RL2, "rl2" }, |
+ { CONTAINER_RM, "rm" }, |
+ { CONTAINER_ROQ, "roq" }, |
+ { CONTAINER_RPL, "rpl" }, |
+ { CONTAINER_RSO, "rso" }, |
+ { CONTAINER_RTP, "rtp" }, |
+ { CONTAINER_RTSP, "rtsp" }, |
+ { CONTAINER_S16BE, "s16be" }, |
+ { CONTAINER_S16LE, "s16le" }, |
+ { CONTAINER_S24BE, "s24be" }, |
+ { CONTAINER_S24LE, "s24le" }, |
+ { CONTAINER_S32BE, "s32be" }, |
+ { CONTAINER_S32LE, "s32le" }, |
+ { CONTAINER_S8, "s8" }, |
+ { CONTAINER_SAMI, "sami" }, |
+ { CONTAINER_SAP, "sap" }, |
+ { CONTAINER_SBG, "sbg" }, |
+ { CONTAINER_SDP, "sdp" }, |
+ { CONTAINER_SHN, "shn" }, |
+ { CONTAINER_SIFF, "siff" }, |
+ { CONTAINER_SMJPEG, "smjpeg" }, |
+ { CONTAINER_SMK, "smk" }, |
+ { CONTAINER_SMUSH, "smush" }, |
+ { CONTAINER_SNDIO, "sndio" }, |
+ { CONTAINER_SOL, "sol" }, |
+ { CONTAINER_SOX, "sox" }, |
+ { CONTAINER_SPDIF, "spdif" }, |
+ { CONTAINER_SRT, "srt" }, |
+ { CONTAINER_SUBVIEWER, "subviewer" }, |
+ { CONTAINER_SUBVIEWER1, "subviewer1" }, |
+ { CONTAINER_SWF, "swf" }, |
+ { CONTAINER_TAK, "tak" }, |
+ { CONTAINER_TEDCAPTIONS, "tedcaptions" }, |
+ { CONTAINER_THP, "thp" }, |
+ { CONTAINER_TIERTEXSEQ, "tiertexseq" }, |
+ { CONTAINER_TMV, "tmv" }, |
+ { CONTAINER_TRUEHD, "truehd" }, |
+ { CONTAINER_TTA, "tta" }, |
+ { CONTAINER_TTY, "tty" }, |
+ { CONTAINER_TXD, "txd" }, |
+ { CONTAINER_VC1, "vc1" }, |
+ { CONTAINER_VC1TEST, "vc1test" }, |
+ { CONTAINER_VFWCAP, "vfwcap" }, |
+ { CONTAINER_V4L, "video4linux,v4l" }, |
+ { CONTAINER_V4L2, "video4linux2,v4l2" }, |
+ { CONTAINER_VIVO, "vivo" }, |
+ { CONTAINER_VMD, "vmd" }, |
+ { CONTAINER_VOBSUB, "vobsub" }, |
+ { CONTAINER_VOC, "voc" }, |
+ { CONTAINER_VPLAYER, "vplayer" }, |
+ { CONTAINER_VQF, "vqf" }, |
+ { CONTAINER_W64, "w64" }, |
+ { CONTAINER_WAV, "wav" }, |
+ { CONTAINER_WC3MOVIE, "wc3movie" }, |
+ { CONTAINER_WEBVTT, "webvtt" }, |
+ { CONTAINER_WSAUD, "wsaud" }, |
+ { CONTAINER_WSVQA, "wsvqa" }, |
+ { CONTAINER_WTV, "wtv" }, |
+ { CONTAINER_WV, "wv" }, |
+ { CONTAINER_X11GRAB, "x11grab" }, |
+ { CONTAINER_XA, "xa" }, |
+ { CONTAINER_XBIN, "xbin" }, |
+ { CONTAINER_XMV, "xmv" }, |
+ { CONTAINER_XWMA, "xwma" }, |
+ { CONTAINER_YOP, "yop" }, |
+ { CONTAINER_YUV4MPEGPIPE, "yuv4mpegpipe" } |
+}; |
+ |
+// Returns the number of elements in container_name_mapping. |
+const int ContainerNames::ContainerNameMappingSize() { |
+ return arraysize(container_name_mapping); |
+} |
+ |
+// Lookup a container name using the list above (container_name_mapping) |
+// to determine the container enum. If not found (recent addition to |
+// FFmpeg or a name change), return CONTAINER_UNKNOWN. |
+FFmpegContainerName ContainerNames::LookupContainer( |
+ const char* container_name) { |
+ DCHECK(container_name); |
+ const ContainerNameMapping* found = |
+ std::lower_bound(container_name_mapping, |
+ container_name_mapping + ContainerNameMappingSize() - 1, |
+ container_name, |
+ ContainerNameMappingComparer); |
+ return (strcasecmp(found->name, container_name) == 0) ? found->id |
+ : CONTAINER_UNKNOWN; |
+} |
+ |
+// Attempt to determine the container name from the buffer provided. |
+FFmpegContainerName ContainerNames::DetermineContainer(const uint8 buffer[], |
+ size_t buffer_size) { |
+ // TODO(jrummell): The following formats are not scanned for |
+ // cavsvideo, dts, dv, h261, h263, h264, jacosub, |
+ // mpeg, mpegts, mpegvideo, psxstr, sbg, spdif, tedcaptions |
+ |
+ // First attempt the simple checks, that typically look at just the |
+ // first few bytes of the file. |
+ FFmpegContainerName result = LookupContainerByFirst4(buffer, buffer_size); |
+ if (result != CONTAINER_UNKNOWN) |
+ return result; |
+ |
+ // No success with simple test, so attempt to determine the container by |
+ // looking for strings in the buffer. |
+ result = LookupContainerByStringScan(buffer, buffer_size); |
+ if (result != CONTAINER_UNKNOWN) |
+ return result; |
+ return LookupContainerByStringLine(buffer, buffer_size); |
+} |
+ |
+// Log the container based on the name returned by FFmpeg. |
+void ContainerNames::LogContainer(const char* container_name) { |
+ FFmpegContainerName container = LookupContainer(container_name); |
+ LogContainerToHistogram(container, false); |
+} |
+ |
+// Log the container by examining the first part of the stream. |
+void ContainerNames::LogContainer(const uint8 buffer[], size_t buffer_size) { |
+ FFmpegContainerName container = DetermineContainer(buffer, buffer_size); |
+ LogContainerToHistogram(container, true); |
+} |
+ |
+} // namespace media |