OLD | NEW |
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 <cctype> | 7 #include <cctype> |
8 #include <limits> | 8 #include <limits> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 // Verify video frames per second specified. | 224 // Verify video frames per second specified. |
225 RCHECK(Read32LE(buffer + 32) > 0); | 225 RCHECK(Read32LE(buffer + 32) > 0); |
226 | 226 |
227 // Number of audio tracks must be 256 or less. | 227 // Number of audio tracks must be 256 or less. |
228 return (Read32LE(buffer + 40) <= 256); | 228 return (Read32LE(buffer + 40) <= 256); |
229 } | 229 } |
230 | 230 |
231 // Additional checks for a CAF container. | 231 // Additional checks for a CAF container. |
232 static bool CheckCaf(const uint8* buffer, int buffer_size) { | 232 static bool CheckCaf(const uint8* buffer, int buffer_size) { |
233 // Reference: Apple Core Audio Format Specification 1.0 | 233 // Reference: Apple Core Audio Format Specification 1.0 |
234 // (http://goo.gl/Vgb9r) | 234 // (https://developer.apple.com/library/mac/#documentation/MusicAudio/Referenc
e/CAFSpec/CAF_spec/CAF_spec.html) |
235 RCHECK(buffer_size >= 52); | 235 RCHECK(buffer_size >= 52); |
236 BitReader reader(buffer, buffer_size); | 236 BitReader reader(buffer, buffer_size); |
237 | 237 |
238 // mFileType should be "caff". | 238 // mFileType should be "caff". |
239 RCHECK(ReadBits(&reader, 32) == TAG('c', 'a', 'f', 'f')); | 239 RCHECK(ReadBits(&reader, 32) == TAG('c', 'a', 'f', 'f')); |
240 | 240 |
241 // mFileVersion should be 1. | 241 // mFileVersion should be 1. |
242 RCHECK(ReadBits(&reader, 16) == 1); | 242 RCHECK(ReadBits(&reader, 16) == 1); |
243 | 243 |
244 // Skip mFileFlags. | 244 // Skip mFileFlags. |
(...skipping 20 matching lines...) Expand all Loading... |
265 static bool kSamplingFrequencyValid[16] = { false, true, true, true, false, | 265 static bool kSamplingFrequencyValid[16] = { false, true, true, true, false, |
266 false, true, true, true, false, | 266 false, true, true, true, false, |
267 false, true, true, true, false, | 267 false, true, true, true, false, |
268 false }; | 268 false }; |
269 static bool kExtAudioIdValid[8] = { true, false, true, false, false, false, | 269 static bool kExtAudioIdValid[8] = { true, false, true, false, false, false, |
270 true, false }; | 270 true, false }; |
271 | 271 |
272 // Additional checks for a DTS container. | 272 // Additional checks for a DTS container. |
273 static bool CheckDts(const uint8* buffer, int buffer_size) { | 273 static bool CheckDts(const uint8* buffer, int buffer_size) { |
274 // Reference: ETSI TS 102 114 V1.3.1 (2011-08) | 274 // Reference: ETSI TS 102 114 V1.3.1 (2011-08) |
275 // (http://goo.gl/FhHrk) | 275 // (http://www.etsi.org/deliver/etsi_ts/102100_102199/102114/01.03.01_60/ts_10
2114v010301p.pdf) |
276 RCHECK(buffer_size > 11); | 276 RCHECK(buffer_size > 11); |
277 | 277 |
278 int offset = 0; | 278 int offset = 0; |
279 while (offset + 11 < buffer_size) { | 279 while (offset + 11 < buffer_size) { |
280 BitReader reader(buffer + offset, 11); | 280 BitReader reader(buffer + offset, 11); |
281 | 281 |
282 // Verify sync word. | 282 // Verify sync word. |
283 RCHECK(ReadBits(&reader, 32) == 0x7ffe8001); | 283 RCHECK(ReadBits(&reader, 32) == 0x7ffe8001); |
284 | 284 |
285 // Skip frame type and deficit sample count. | 285 // Skip frame type and deficit sample count. |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 RCHECK(ReadBits(&reader, 2) != 3); | 320 RCHECK(ReadBits(&reader, 2) != 3); |
321 | 321 |
322 offset += frame_size + 1; | 322 offset += frame_size + 1; |
323 } | 323 } |
324 return true; | 324 return true; |
325 } | 325 } |
326 | 326 |
327 // Checks for a DV container. | 327 // Checks for a DV container. |
328 static bool CheckDV(const uint8* buffer, int buffer_size) { | 328 static bool CheckDV(const uint8* buffer, int buffer_size) { |
329 // Reference: SMPTE 314M (Annex A has differences with IEC 61834). | 329 // Reference: SMPTE 314M (Annex A has differences with IEC 61834). |
330 // (http://goo.gl/kMn6p) | 330 // (http://standards.smpte.org/content/978-1-61482-454-1/st-314-2005/SEC1.body
.pdf) |
331 RCHECK(buffer_size > 11); | 331 RCHECK(buffer_size > 11); |
332 | 332 |
333 int offset = 0; | 333 int offset = 0; |
334 int current_sequence_number = -1; | 334 int current_sequence_number = -1; |
335 int last_block_number[6]; | 335 int last_block_number[6]; |
336 while (offset + 11 < buffer_size) { | 336 while (offset + 11 < buffer_size) { |
337 BitReader reader(buffer + offset, 11); | 337 BitReader reader(buffer + offset, 11); |
338 | 338 |
339 // Decode ID data. Sections 5, 6, and 7 are reserved. | 339 // Decode ID data. Sections 5, 6, and 7 are reserved. |
340 int section = ReadBits(&reader, 3); | 340 int section = ReadBits(&reader, 3); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 // Move to next block. | 383 // Move to next block. |
384 offset += 80; | 384 offset += 80; |
385 } | 385 } |
386 return true; | 386 return true; |
387 } | 387 } |
388 | 388 |
389 | 389 |
390 // Checks for a GSM container. | 390 // Checks for a GSM container. |
391 static bool CheckGsm(const uint8* buffer, int buffer_size) { | 391 static bool CheckGsm(const uint8* buffer, int buffer_size) { |
392 // Reference: ETSI EN 300 961 V8.1.1 | 392 // Reference: ETSI EN 300 961 V8.1.1 |
393 // (http://goo.gl/h2VDS) | 393 // (http://www.etsi.org/deliver/etsi_en/300900_300999/300961/08.01.01_60/en_30
0961v080101p.pdf) |
394 // also http://tools.ietf.org/html/rfc3551#page-24 | 394 // also http://tools.ietf.org/html/rfc3551#page-24 |
395 // GSM files have a 33 byte block, only first 4 bits are fixed. | 395 // GSM files have a 33 byte block, only first 4 bits are fixed. |
396 RCHECK(buffer_size >= 1024); // Need enough data to do a decent check. | 396 RCHECK(buffer_size >= 1024); // Need enough data to do a decent check. |
397 | 397 |
398 int offset = 0; | 398 int offset = 0; |
399 while (offset < buffer_size) { | 399 while (offset < buffer_size) { |
400 // First 4 bits of each block are xD. | 400 // First 4 bits of each block are xD. |
401 RCHECK((buffer[offset] & 0xf0) == 0xd0); | 401 RCHECK((buffer[offset] & 0xf0) == 0xd0); |
402 offset += 33; | 402 offset += 33; |
403 } | 403 } |
(...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
940 break; | 940 break; |
941 } | 941 } |
942 // Skip this block. | 942 // Skip this block. |
943 offset += 6; | 943 offset += 6; |
944 } | 944 } |
945 } | 945 } |
946 | 946 |
947 // Additional checks for a MOV/QuickTime/MPEG4 container. | 947 // Additional checks for a MOV/QuickTime/MPEG4 container. |
948 static bool CheckMov(const uint8* buffer, int buffer_size) { | 948 static bool CheckMov(const uint8* buffer, int buffer_size) { |
949 // Reference: ISO/IEC 14496-12:2005(E). | 949 // Reference: ISO/IEC 14496-12:2005(E). |
950 // (http://goo.gl/OWH0Q) | 950 // (http://standards.iso.org/ittf/PubliclyAvailableStandards/c061988_ISO_IEC_1
4496-12_2012.zip) |
951 RCHECK(buffer_size > 8); | 951 RCHECK(buffer_size > 8); |
952 | 952 |
953 int offset = 0; | 953 int offset = 0; |
954 while (offset + 8 < buffer_size) { | 954 while (offset + 8 < buffer_size) { |
955 int atomsize = Read32(buffer + offset); | 955 int atomsize = Read32(buffer + offset); |
956 uint32 atomtype = Read32(buffer + offset + 4); | 956 uint32 atomtype = Read32(buffer + offset + 4); |
957 // Only need to check for ones that are valid at the top level. | 957 // Only need to check for ones that are valid at the top level. |
958 switch (atomtype) { | 958 switch (atomtype) { |
959 case TAG('f','t','y','p'): | 959 case TAG('f','t','y','p'): |
960 case TAG('p','d','i','n'): | 960 case TAG('p','d','i','n'): |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1291 | 1291 |
1292 enum VC1StartCodes { | 1292 enum VC1StartCodes { |
1293 VC1_FRAME_START_CODE = 0x0d, | 1293 VC1_FRAME_START_CODE = 0x0d, |
1294 VC1_ENTRY_POINT_START_CODE = 0x0e, | 1294 VC1_ENTRY_POINT_START_CODE = 0x0e, |
1295 VC1_SEQUENCE_START_CODE = 0x0f | 1295 VC1_SEQUENCE_START_CODE = 0x0f |
1296 }; | 1296 }; |
1297 | 1297 |
1298 // Checks for a VC1 bitstream container. | 1298 // Checks for a VC1 bitstream container. |
1299 static bool CheckVC1(const uint8* buffer, int buffer_size) { | 1299 static bool CheckVC1(const uint8* buffer, int buffer_size) { |
1300 // Reference: SMPTE 421M | 1300 // Reference: SMPTE 421M |
1301 // (http://goo.gl/fLvaE) | 1301 // (http://standards.smpte.org/content/978-1-61482-555-5/st-421-2006/SEC1.body
.pdf) |
1302 // However, no length ... simply scan for start code values. | 1302 // However, no length ... simply scan for start code values. |
1303 // Expect to see SEQ | [ [ ENTRY ] PIC* ]* | 1303 // Expect to see SEQ | [ [ ENTRY ] PIC* ]* |
1304 // Note tags are very similar to H.264. | 1304 // Note tags are very similar to H.264. |
1305 | 1305 |
1306 RCHECK(buffer_size >= 24); | 1306 RCHECK(buffer_size >= 24); |
1307 | 1307 |
1308 // First check for Bitstream Metadata Serialization (Annex L) | 1308 // First check for Bitstream Metadata Serialization (Annex L) |
1309 if (buffer[0] == 0xc5 && | 1309 if (buffer[0] == 0xc5 && |
1310 Read32(buffer + 4) == 0x04 && | 1310 Read32(buffer + 4) == 0x04 && |
1311 Read32(buffer + 20) == 0x0c) { | 1311 Read32(buffer + 20) == 0x0c) { |
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1662 if (CheckEac3(buffer + offset, buffer_size - offset)) | 1662 if (CheckEac3(buffer + offset, buffer_size - offset)) |
1663 return CONTAINER_EAC3; | 1663 return CONTAINER_EAC3; |
1664 } | 1664 } |
1665 | 1665 |
1666 return CONTAINER_UNKNOWN; | 1666 return CONTAINER_UNKNOWN; |
1667 } | 1667 } |
1668 | 1668 |
1669 } // namespace container_names | 1669 } // namespace container_names |
1670 | 1670 |
1671 } // namespace media | 1671 } // namespace media |
OLD | NEW |