Update mp4 container check function to be more robust

Consider the file in iso-bmff format if seeing two known
mp4 boxes.

Closes Issue #110

Change-Id: Ifdc76b6c8b7e26a0988ab4f8d4968e1320cb180c
This commit is contained in:
Kongqun Yang 2016-06-10 11:36:46 -07:00 committed by KongQun Yang
parent 60419f26d0
commit 0a9de96eb2
1 changed files with 10 additions and 2 deletions

View File

@ -956,6 +956,7 @@ static bool CheckMov(const uint8_t* buffer, int buffer_size) {
RCHECK(buffer_size > 8); RCHECK(buffer_size > 8);
int offset = 0; int offset = 0;
int boxes_seen = 0;
while (offset + 8 < buffer_size) { while (offset + 8 < buffer_size) {
int atomsize = Read32(buffer + offset); int atomsize = Read32(buffer + offset);
uint32_t atomtype = Read32(buffer + offset + 4); uint32_t atomtype = Read32(buffer + offset + 4);
@ -977,9 +978,16 @@ static bool CheckMov(const uint8_t* buffer, int buffer_size) {
case TAG('s','s','i','x'): case TAG('s','s','i','x'):
case TAG('p','r','f','t'): case TAG('p','r','f','t'):
case TAG('u','u','i','d'): case TAG('u','u','i','d'):
// Assumes that it is an iso-bmff file after seeing two known boxes.
// Note that it is correct only for our use cases as we support only
// a limited number of containers, and there is no other container
// has this behavior.
if (++boxes_seen >= 2)
return true;
break; break;
default: default:
return false; // Ignore unrecognized box.
break;
} }
if (atomsize == 1) { if (atomsize == 1) {
// Indicates that the length is the next 64bits. // Indicates that the length is the next 64bits.
@ -993,7 +1001,7 @@ static bool CheckMov(const uint8_t* buffer, int buffer_size) {
break; // Indicates the last atom or length too big. break; // Indicates the last atom or length too big.
offset += atomsize; offset += atomsize;
} }
return true; return false;
} }
enum MPEGVersion { enum MPEGVersion {