From 69bfb3a0be345da56f43f580421526b8475538a8 Mon Sep 17 00:00:00 2001 From: Thulinma Date: Sat, 13 Dec 2014 16:54:40 +0100 Subject: [PATCH] Various MP4 lib optimizations. --- lib/mp4.cpp | 7 ++----- lib/mp4_generic.cpp | 15 +++++++++------ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/mp4.cpp b/lib/mp4.cpp index 43eb422a..aba667a5 100644 --- a/lib/mp4.cpp +++ b/lib/mp4.cpp @@ -479,8 +479,7 @@ namespace MP4 { return; } } - newData = htonl(newData); - memcpy(data + index, (char *) &newData, 4); + ((int *)(data + index))[0] = htonl(newData); } /// Gets the 32 bits integer at the given index. @@ -494,9 +493,7 @@ namespace MP4 { } setInt32(0, index - payloadOffset); } - uint32_t result; - memcpy((char *) &result, data + index, 4); - return ntohl(result); + return ntohl(((int *)(data + index))[0]); } /// Sets the 64 bits integer at the given index. diff --git a/lib/mp4_generic.cpp b/lib/mp4_generic.cpp index d098ff67..12f4af35 100644 --- a/lib/mp4_generic.cpp +++ b/lib/mp4_generic.cpp @@ -2251,13 +2251,16 @@ namespace MP4 { } void STCO::setChunkOffset(uint32_t newChunkOffset, uint32_t no) { - if (no + 1 > getEntryCount()) { - for (unsigned int i = getEntryCount(); i < no; i++) { - setInt32(0, 8 + i * 4);//filling undefined entries - } - setEntryCount(no + 1); - } setInt32(newChunkOffset, 8 + no * 4); + uint32_t entryCount = getEntryCount(); + //if entrycount is lower than new entry count, update it and fill any skipped entries with zeroes. + if (no + 1 > entryCount) { + setEntryCount(no + 1); + //fill undefined entries, if any (there's only undefined entries if we skipped an entry) + if (no > entryCount){ + memset(data+payloadOffset+8+entryCount*4, 0, 4*(no-entryCount)); + } + } } uint32_t STCO::getChunkOffset(uint32_t no) {