From 7d13a18c471ce956894069e74f843c4de069cdb9 Mon Sep 17 00:00:00 2001 From: Thulinma Date: Sat, 29 Sep 2012 03:12:51 +0200 Subject: [PATCH] Stability fixes for MP4 lib, fixed MP4 unit test. --- lib/mp4.cpp | 11 ++++++++++- test/abst_test.cpp | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/mp4.cpp b/lib/mp4.cpp index 3d2d8165..50862b73 100644 --- a/lib/mp4.cpp +++ b/lib/mp4.cpp @@ -342,6 +342,9 @@ namespace MP4{ /// \returns True on success, false otherwise. bool Box::reserve(size_t position, size_t current, size_t wanted){ if (current == wanted){return true;} + if (position > boxedSize()){ + wanted += position - boxedSize(); + } if (current < wanted){ //make bigger if (boxedSize() + (wanted-current) > data_size){ @@ -350,6 +353,7 @@ namespace MP4{ void * ret = realloc(data, boxedSize() + (wanted-current)); if (!ret){return false;} data = (char*)ret; + memset(data+boxedSize(), 0, wanted-current);//initialize to 0 data_size = boxedSize() + (wanted-current); } } @@ -757,6 +761,11 @@ namespace MP4{ int countLoc = tempLoc; tempLoc += 4; for (int i = 0; i < no; i++){ + if (i+1 > getInt32(countLoc)){ + setInt32(0,tempLoc); + setInt64(0,tempLoc+4); + setInt32(1,tempLoc+12); + } if (getInt32(tempLoc+12) == 0){tempLoc += 17;}else{tempLoc += 16;} } setInt32(newRun.firstFragment,tempLoc); @@ -878,7 +887,7 @@ namespace MP4{ for (int i = 0; i < getQualityEntryCount(); i++){tempLoc += getStringLen(tempLoc)+1;} int countLoc = tempLoc; tempLoc += 4 + no*8; - if (no+1 < getSegmentRunEntryCount()){ + if (no+1 > getInt32(countLoc)){ setInt32(no+1, countLoc);//set new qualityEntryCount } setInt32(firstSegment,tempLoc); diff --git a/test/abst_test.cpp b/test/abst_test.cpp index 147c87e6..5a19dce7 100644 --- a/test/abst_test.cpp +++ b/test/abst_test.cpp @@ -331,5 +331,5 @@ int main(int argc, char ** argv) { abst.setFragmentRunTable(afrt, 0); if (abst.boxedSize() != __data_len){return 42;} - return memcmp(abst.asBox(), __data, __data_len) << std::endl; + return memcmp(abst.asBox(), __data, __data_len); }