Lines Matching refs:buffer
30 // Helper function to read 2 bytes (16 bits, big endian) from a buffer.
35 // Helper function to read 3 bytes (24 bits, big endian) from a buffer.
40 // Helper function to read 4 bytes (32 bits, big endian) from a buffer.
45 // Helper function to read 4 bytes (32 bits, little endian) from a buffer.
50 // Helper function to do buffer comparisons with a string without going off the
51 // end of the buffer.
52 static bool StartsWith(const uint8* buffer,
57 memcmp(buffer, prefix, prefix_size) == 0);
60 // Helper function to do buffer comparisons with another buffer (to allow for
61 // embedded \0 in the comparison) without going off the end of the buffer.
62 static bool StartsWith(const uint8* buffer,
67 memcmp(buffer, prefix, prefix_size) == 0);
94 static bool CheckAac(const uint8* buffer, int buffer_size) {
101 BitReader reader(buffer + offset, 6);
133 static bool CheckAc3(const uint8* buffer, int buffer_size) {
143 BitReader reader(buffer + offset, 6);
168 static bool CheckEac3(const uint8* buffer, int buffer_size) {
178 BitReader reader(buffer + offset, 6);
206 static bool CheckBink(const uint8* buffer, int buffer_size) {
211 RCHECK(Read32LE(buffer + 8) > 0);
214 int width = Read32LE(buffer + 20);
218 int height = Read32LE(buffer + 24);
222 RCHECK(Read32LE(buffer + 28) > 0);
225 RCHECK(Read32LE(buffer + 32) > 0);
228 return (Read32LE(buffer + 40) <= 256);
232 static bool CheckCaf(const uint8* buffer, int buffer_size) {
236 BitReader reader(buffer, buffer_size);
273 static bool CheckDts(const uint8* buffer, int buffer_size) {
280 BitReader reader(buffer + offset, 11);
328 static bool CheckDV(const uint8* buffer, int buffer_size) {
337 BitReader reader(buffer + offset, 11);
391 static bool CheckGsm(const uint8* buffer, int buffer_size) {
401 RCHECK((buffer[offset] & 0xf0) == 0xd0);
408 // is the current location in the buffer, and is updated. |bytes_needed| is the
409 // number of bytes that must remain in the buffer when |start_code| is found.
410 // Returns true if start_code found (and enough space in the buffer after it),
412 static bool AdvanceToStartCode(const uint8* buffer,
425 uint32 next = Read24(buffer + *offset);
434 static bool CheckH261(const uint8* buffer, int buffer_size) {
443 if (!AdvanceToStartCode(buffer, buffer_size, &offset, 4, 20, 0x10)) {
444 // No start code found (or off end of buffer), so success if
450 // at least 4 bytes remaining in the buffer.
451 BitReader reader(buffer + offset, buffer_size - offset);
458 // out of bits assume that the buffer is correctly formatted.
468 // bits, then assume that the buffer up to here is correct, and the buffer
482 static bool CheckH263(const uint8* buffer, int buffer_size) {
492 if (!AdvanceToStartCode(buffer, buffer_size, &offset, 9, 22, 0x20)) {
493 // No start code found (or off end of buffer), so success if
499 // at least 9 bytes remaining in the buffer.
500 BitReader reader(buffer + offset, 9);
550 static bool CheckH264(const uint8* buffer, int buffer_size) {
560 if (!AdvanceToStartCode(buffer, buffer_size, &offset, 4, 24, 1)) {
561 // No start code found (or off end of buffer), so success if
567 // at least 4 bytes remaining in the buffer.
568 BitReader reader(buffer + offset, 4);
606 static bool CheckHls(const uint8* buffer, int buffer_size) {
611 if (StartsWith(buffer, buffer_size, kHlsSignature)) {
613 // "#EXT-X-MEDIA-SEQUENCE:" somewhere in the buffer. Other playlists (like
618 if (buffer[offset] == '#') {
619 if (StartsWith(buffer + offset, buffer_size - offset, kHls1) ||
620 StartsWith(buffer + offset, buffer_size - offset, kHls2) ||
621 StartsWith(buffer + offset, buffer_size - offset, kHls3)) {
632 static bool CheckMJpeg(const uint8* buffer, int buffer_size) {
642 RCHECK(buffer[offset] == 0xff);
643 uint8 code = buffer[offset + 1];
669 int length = Read16(buffer + offset + 2) + 2;
675 int number_components = buffer[offset + 4];
681 if (buffer[offset] == 0xff && buffer[offset + 1] != 0)
701 static bool CheckMpeg2ProgramStream(const uint8* buffer, int buffer_size) {
707 BitReader reader(buffer + offset, 14);
770 while (offset + 6 < buffer_size && Read24(buffer + offset) == 1) {
772 int stream_id = buffer[offset + 3];
786 int pes_length = Read16(buffer + offset + 4);
791 // Success as we are off the end of the buffer and liked everything
792 // in the buffer.
799 static bool CheckMpeg2TransportStream(const uint8* buffer, int buffer_size) {
809 while (buffer[offset] != kMpeg2SyncWord && offset < 20) {
815 BitReader reader(buffer + offset, 6);
850 if (buffer[offset + 188] == kMpeg2SyncWord)
852 else if (buffer[offset + 192] == kMpeg2SyncWord)
854 else if (buffer[offset + 204] == kMpeg2SyncWord)
872 static bool CheckMpeg4BitStream(const uint8* buffer, int buffer_size) {
885 if (!AdvanceToStartCode(buffer, buffer_size, &offset, 6, 24, 1)) {
892 // at least 6 bytes remaining in the buffer.
893 BitReader reader(buffer + offset, 6);
948 static bool CheckMov(const uint8* buffer, int buffer_size) {
955 int atomsize = Read32(buffer + offset);
956 uint32 atomtype = Read32(buffer + offset + 4);
982 if (Read32(buffer + offset + 8) != 0)
983 break; // Offset is way past buffer size.
984 atomsize = Read32(buffer + offset + 12);
1083 static int GetMp3HeaderSize(const uint8* buffer, int buffer_size) {
1085 int size = ((buffer[6] & 0x7f) << 21) + ((buffer[7] & 0x7f) << 14) +
1086 ((buffer[8] & 0x7f) << 7) + (buffer[9] & 0x7f) + 10;
1087 if (buffer[5] & 0x10) // Footer added?
1093 static bool CheckMp3(const uint8* buffer, int buffer_size, bool seenHeader) {
1100 offset = GetMp3HeaderSize(buffer, buffer_size);
1103 while (offset < buffer_size && buffer[offset] == 0)
1109 buffer + offset, buffer_size - offset, &framesize));
1116 // Off the end of the buffer, return success if a few valid headers seen.
1120 // Check that the next characters in |buffer| represent a number. The format
1124 static bool VerifyNumber(const uint8* buffer,
1131 while (isspace(buffer[*offset])) {
1138 while (--max_digits >= 0 && isdigit(buffer[*offset])) {
1149 // Check that the next character in |buffer| is one of |c1| or |c2|. |c2| is
1152 static inline bool VerifyCharacters(const uint8* buffer,
1158 char c = static_cast<char>(buffer[(*offset)++]);
1163 static bool CheckSrt(const uint8* buffer, int buffer_size) {
1168 int offset = StartsWith(buffer, buffer_size, UTF8_BYTE_ORDER_MARK) ? 3 : 0;
1169 RCHECK(VerifyNumber(buffer, buffer_size, &offset, 100));
1170 RCHECK(VerifyCharacters(buffer, buffer_size, &offset, '\n', '\r'));
1173 while (VerifyCharacters(buffer, buffer_size, &offset, '\n', '\r')) {}
1179 RCHECK(VerifyNumber(buffer, buffer_size, &offset, 100));
1180 RCHECK(VerifyCharacters(buffer, buffer_size, &offset, ':', 0));
1181 RCHECK(VerifyNumber(buffer, buffer_size, &offset, 2));
1182 RCHECK(VerifyCharacters(buffer, buffer_size, &offset, ':', 0));
1183 RCHECK(VerifyNumber(buffer, buffer_size, &offset, 2));
1184 RCHECK(VerifyCharacters(buffer, buffer_size, &offset, ',', '.'));
1185 RCHECK(VerifyNumber(buffer, buffer_size, &offset, 3));
1186 RCHECK(VerifyCharacters(buffer, buffer_size, &offset, ' ', 0));
1187 RCHECK(VerifyCharacters(buffer, buffer_size, &offset, '-', 0));
1188 RCHECK(VerifyCharacters(buffer, buffer_size, &offset, '-', 0));
1189 RCHECK(VerifyCharacters(buffer, buffer_size, &offset, '>', 0));
1190 RCHECK(VerifyCharacters(buffer, buffer_size, &offset, ' ', 0));
1191 RCHECK(VerifyNumber(buffer, buffer_size, &offset, 100));
1192 RCHECK(VerifyCharacters(buffer, buffer_size, &offset, ':', 0));
1193 RCHECK(VerifyNumber(buffer, buffer_size, &offset, 2));
1194 RCHECK(VerifyCharacters(buffer, buffer_size, &offset, ':', 0));
1195 RCHECK(VerifyNumber(buffer, buffer_size, &offset, 2));
1196 RCHECK(VerifyCharacters(buffer, buffer_size, &offset, ',', '.'));
1197 RCHECK(VerifyNumber(buffer, buffer_size, &offset, 3));
1204 // If it is an invalid encoding or the end of the buffer is reached,
1226 // If it is an invalid coding or the end of the buffer is reached,
1227 // return something that will go off the end of the buffer.
1239 // Incorrect format (more than 7 leading 0's) or off the end of the buffer.
1246 static bool CheckWebm(const uint8* buffer, int buffer_size) {
1250 BitReader reader(buffer, buffer_size);
1299 static bool CheckVC1(const uint8* buffer, int buffer_size) {
1309 if (buffer[0] == 0xc5 &&
1310 Read32(buffer + 4) == 0x04 &&
1311 Read32(buffer + 20) == 0x0c) {
1313 BitReader reader(buffer + 8, 12);
1353 // Buffer isn't Bitstream Metadata, so scan for start codes.
1359 if (!AdvanceToStartCode(buffer, buffer_size, &offset, 5, 24, 1)) {
1367 // at least 5 bytes remaining in the buffer.
1368 BitReader reader(buffer + offset, 5);
1418 // Attempt to determine the container type from the buffer provided. This is
1419 // a simple pass, that uses the first 4 bytes of the buffer as an index to get
1421 static MediaContainerName LookupContainerByFirst4(const uint8* buffer,
1427 uint32 first4 = Read32(buffer);
1430 if (CheckWebm(buffer, buffer_size))
1435 if (StartsWith(buffer,
1444 if (StartsWith(buffer, buffer_size, kAmrSignature))
1449 if (CheckHls(buffer, buffer_size))
1454 if (buffer[4] == 0 && buffer[5] == 0)
1467 if (CheckBink(buffer, buffer_size))
1472 if (CheckCaf(buffer, buffer_size))
1478 Read16(buffer + 11) <= 2048 &&
1479 Read16(buffer + 13) <= 2048) {
1485 if (Read32(buffer + 4) == TAG('D','H','D','R'))
1496 if (Read32(buffer + 4) != 0 && Read32(buffer + 8) != 0)
1508 if (buffer[5] == 0 && Read32(buffer + 5) > 8)
1513 switch (Read32(buffer + 8)) {
1524 if (Read32(buffer + 8) == TAG('O','N','2','f'))
1529 if (buffer[5] <= 7)
1534 if (buffer_size > 16 && Read32(buffer + 12) == TAG('d','s','6','4'))
1539 switch (Read32(buffer + 8)) {
1551 if (StartsWith(buffer, buffer_size, kAssSignature))
1556 if (StartsWith(buffer, buffer_size, kAssBomSignature))
1564 if (CheckDts(buffer, buffer_size))
1569 if (StartsWith(buffer,
1587 if (CheckMp3(buffer, buffer_size, true))
1593 uint32 first2 = Read16(buffer);
1596 if (CheckAc3(buffer, buffer_size))
1598 if (CheckEac3(buffer, buffer_size))
1606 if (CheckAac(buffer, buffer_size))
1612 if (CheckMp3(buffer, buffer_size, false))
1618 // Attempt to determine the container name from the buffer provided.
1619 MediaContainerName DetermineContainer(const uint8* buffer, int buffer_size) {
1620 DCHECK(buffer);
1623 if (CheckMov(buffer, buffer_size))
1628 MediaContainerName result = LookupContainerByFirst4(buffer, buffer_size);
1632 // Additional checks that may scan a portion of the buffer.
1633 if (CheckMpeg2ProgramStream(buffer, buffer_size))
1635 if (CheckMpeg2TransportStream(buffer, buffer_size))
1637 if (CheckMJpeg(buffer, buffer_size))
1639 if (CheckDV(buffer, buffer_size))
1641 if (CheckH261(buffer, buffer_size))
1643 if (CheckH263(buffer, buffer_size))
1645 if (CheckH264(buffer, buffer_size))
1647 if (CheckMpeg4BitStream(buffer, buffer_size))
1649 if (CheckVC1(buffer, buffer_size))
1651 if (CheckSrt(buffer, buffer_size))
1653 if (CheckGsm(buffer, buffer_size))
1659 if (AdvanceToStartCode(buffer, buffer_size, &offset, 4, 16, kAc3SyncWord)) {
1660 if (CheckAc3(buffer + offset, buffer_size - offset))
1662 if (CheckEac3(buffer + offset, buffer_size - offset))