From 9e8a13a4fdbf459b1384c8cdc4ad85e13b6e23f0 Mon Sep 17 00:00:00 2001 From: Matthias Grundmann Date: Fri, 14 Apr 2017 11:41:19 -0700 Subject: [PATCH 1/8] Support reading mp4 container structure from file offset. Support reading mp4 container structure from file offset. --- include/mp4v2/file.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/include/mp4v2/file.h b/include/mp4v2/file.h index b2124d2..6ad03ca 100644 --- a/include/mp4v2/file.h +++ b/include/mp4v2/file.h @@ -404,6 +404,18 @@ MP4V2_EXPORT MP4FileHandle MP4Read( const char* fileName ); +/** Generalized version of above MP4Read, supporting reading a MP4 file at + * the specific file offset. + * + * @param fileName As for MP4Read + * @param fileOffset seek offset in file that MP4 container structure starts + * at. + */ +MP4V2_EXPORT +MP4FileHandle MP4ReadFromOffset( + const char* fileName, + int64_t seekOffset); + /** Read an existing mp4 file. * * MP4ReadProvider is the first call that should be used when you want to just From eae3a9ef1a5a14bc40cd77b74ef27598cedfc076 Mon Sep 17 00:00:00 2001 From: Matthias Grundmann Date: Fri, 14 Apr 2017 11:44:23 -0700 Subject: [PATCH 2/8] Update mp4.cpp --- src/mp4.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/mp4.cpp b/src/mp4.cpp index 1016f79..83a189f 100644 --- a/src/mp4.cpp +++ b/src/mp4.cpp @@ -89,6 +89,10 @@ const char* MP4GetFilename( MP4FileHandle hFile ) MP4FileHandle MP4Read( const char* fileName ) { + return MP4ReadFromOffset(fileName, 0); +} + +MP4FileHandle MP4ReadFromOffset( const char* fileName, int64_t seekOffset) { if (!fileName) return MP4_INVALID_FILE_HANDLE; @@ -99,6 +103,7 @@ MP4FileHandle MP4Read( const char* fileName ) try { ASSERT(pFile); + pFile->SetInitialSeekOffset( seekOffset ); pFile->Read( fileName, NULL ); return (MP4FileHandle)pFile; } From dddbfe52dc0bbd38f049c096014ec27c0bfc5fa6 Mon Sep 17 00:00:00 2001 From: Matthias Grundmann Date: Fri, 14 Apr 2017 11:46:09 -0700 Subject: [PATCH 3/8] Update mp4file.h --- src/mp4file.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/mp4file.h b/src/mp4file.h index 960505e..5c6bdaf 100644 --- a/src/mp4file.h +++ b/src/mp4file.h @@ -91,6 +91,7 @@ class MP4File bool CopyClose( const string& copyFileName ); void Dump( bool dumpImplicits = false ); void Close(uint32_t flags = 0); + void SetInitialSeekOffset(int64_t seekOffset); bool Use64Bits(const char *atomName); void Check64BitStatus(const char *atomName); @@ -954,6 +955,7 @@ class MP4File File* m_file; uint64_t m_fileOriginalSize; uint32_t m_createFlags; + int64_t m_initialSeekOffset; MP4Atom* m_pRootAtom; MP4Integer32Array m_trakIds; From 3f633b6fd9d76daaef0b443326bc3b12dda16c47 Mon Sep 17 00:00:00 2001 From: Matthias Grundmann Date: Fri, 14 Apr 2017 11:48:01 -0700 Subject: [PATCH 4/8] Update mp4file.cpp --- src/mp4file.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/mp4file.cpp b/src/mp4file.cpp index 86f386b..5bd3645 100644 --- a/src/mp4file.cpp +++ b/src/mp4file.cpp @@ -59,6 +59,7 @@ void MP4File::Init() m_memoryBuffer = NULL; m_memoryBufferSize = 0; m_memoryBufferPosition = 0; + m_initialSeekOffset = 0; m_numReadBits = 0; m_bufReadBits = 0; @@ -414,8 +415,8 @@ void MP4File::Open( const char* name, File::Mode mode, const MP4FileProvider* pr void MP4File::ReadFromFile() { - // ensure we start at beginning of file - SetPosition(0); + // ensure we start at beginning of file or at specified seek offset. + SetPosition(m_initialSeekOffset); // create a new root atom ASSERT(m_pRootAtom == NULL); @@ -624,6 +625,10 @@ void MP4File::Close(uint32_t options) m_file = NULL; } +void MP4File::SetInitialSeekOffset(int64_t seekOffset) { + m_initialSeekOffset = seekOffset; +} + void MP4File::Rename(const char* oldFileName, const char* newFileName) { if( FileSystem::rename( oldFileName, newFileName )) From 550a8ae9885dbb838da23ef841cacc770b7e5d07 Mon Sep 17 00:00:00 2001 From: Matthias Grundmann Date: Tue, 25 Apr 2017 09:29:34 -0700 Subject: [PATCH 5/8] Update mp4file.cpp --- src/mp4file.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/mp4file.cpp b/src/mp4file.cpp index 5bd3645..cf3da11 100644 --- a/src/mp4file.cpp +++ b/src/mp4file.cpp @@ -415,8 +415,7 @@ void MP4File::Open( const char* name, File::Mode mode, const MP4FileProvider* pr void MP4File::ReadFromFile() { - // ensure we start at beginning of file or at specified seek offset. - SetPosition(m_initialSeekOffset); + SetPosition(0); // create a new root atom ASSERT(m_pRootAtom == NULL); From 17a39e6d82d453c324fb4fe0673a4a043a9eea99 Mon Sep 17 00:00:00 2001 From: Matthias Grundmann Date: Tue, 25 Apr 2017 09:31:09 -0700 Subject: [PATCH 6/8] Update mp4file_io.cpp --- src/mp4file_io.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/mp4file_io.cpp b/src/mp4file_io.cpp index d16d87f..da1299d 100644 --- a/src/mp4file_io.cpp +++ b/src/mp4file_io.cpp @@ -37,7 +37,7 @@ uint64_t MP4File::GetPosition( File* file ) file = m_file; ASSERT( file ); - return file->position; + return file->position - m_initialSeekOffset; } void MP4File::SetPosition( uint64_t pos, File* file ) @@ -53,7 +53,7 @@ void MP4File::SetPosition( uint64_t pos, File* file ) file = m_file; ASSERT( file ); - if( file->seek( pos )) + if( file->seek( pos + m_initialSeekOffset )) throw new PlatformException( "seek failed", sys::getLastError(), __FILE__, __LINE__, __FUNCTION__ ); } @@ -66,7 +66,7 @@ uint64_t MP4File::GetSize( File* file ) file = m_file; ASSERT( file ); - return file->size; + return file->size - m_initialSeekOffset; } void MP4File::ReadBytes( uint8_t* buf, uint32_t bufsiz, File* file ) From 2f4db819d574c5f7d959e80babd9594c8d05bdf6 Mon Sep 17 00:00:00 2001 From: Matthias Grundmann Date: Fri, 11 Aug 2017 13:46:48 -0700 Subject: [PATCH 7/8] Update file.h same functionality for read provider --- include/mp4v2/file.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/include/mp4v2/file.h b/include/mp4v2/file.h index 6ad03ca..139e4d0 100644 --- a/include/mp4v2/file.h +++ b/include/mp4v2/file.h @@ -444,4 +444,18 @@ MP4FileHandle MP4ReadProvider( /** @} ***********************************************************************/ +/** Generalized version of above MP4Read, supporting reading a MP4 file at + * the specific file offset. + * + * @param fileName As for MP4Read + * @param fileOffset seek offset in file that MP4 container structure starts + * at. + */ + +MP4V2_EXPORT +MP4FileHandle MP4ReadProviderFromOffset( + const char* fileName, + const MP4FileProvider* fileProvider, + int64_t seekOffset ); + #endif /* MP4V2_FILE_H */ From 986bc4918216e2c55aefe372dcd49ef1d02a0786 Mon Sep 17 00:00:00 2001 From: Matthias Grundmann Date: Fri, 11 Aug 2017 13:51:54 -0700 Subject: [PATCH 8/8] Update mp4.cpp add reader provider impl --- src/mp4.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/mp4.cpp b/src/mp4.cpp index 83a189f..156514c 100644 --- a/src/mp4.cpp +++ b/src/mp4.cpp @@ -122,6 +122,12 @@ MP4FileHandle MP4ReadFromOffset( const char* fileName, int64_t seekOffset) { } MP4FileHandle MP4ReadProvider( const char* fileName, const MP4FileProvider* fileProvider ) +{ + return MP4ReadProviderFromOffset(fileName, fileProvider, 0); +} + +MP4FileHandle MP4ReadProviderFromOffset( + const char* fileName, const MP4FileProvider* fileProvider, int64_t seekOffset) { if (!fileName) return MP4_INVALID_FILE_HANDLE; @@ -131,6 +137,7 @@ MP4FileHandle MP4ReadProvider( const char* fileName, const MP4FileProvider* file return MP4_INVALID_FILE_HANDLE; try { + pFile->SetInitialSeekOffset( seekOffset ); pFile->Read( fileName, fileProvider ); return (MP4FileHandle)pFile; } @@ -147,7 +154,7 @@ MP4FileHandle MP4ReadProvider( const char* fileName, const MP4FileProvider* file delete pFile; return MP4_INVALID_FILE_HANDLE; } - + /////////////////////////////////////////////////////////////////////////////// MP4FileHandle MP4Create (const char* fileName,