Internal change
PiperOrigin-RevId: 153190657
Change-Id: I3ba0b8bc16730516a6b30ee932de5ad65020d8db
diff --git a/include/mp4v2/file.h b/include/mp4v2/file.h
index b2124d2..0da200e 100644
--- a/include/mp4v2/file.h
+++ b/include/mp4v2/file.h
@@ -404,6 +404,19 @@
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
diff --git a/src/mp4.cpp b/src/mp4.cpp
index 80a609a..53fcdfa 100644
--- a/src/mp4.cpp
+++ b/src/mp4.cpp
@@ -89,6 +89,10 @@
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 @@
try
{
ASSERT(pFile);
+ pFile->SetInitialSeekOffset( seekOffset );
pFile->Read( fileName, NULL );
return (MP4FileHandle)pFile;
}
diff --git a/src/mp4file.cpp b/src/mp4file.cpp
index 8597154..73772a7 100644
--- a/src/mp4file.cpp
+++ b/src/mp4file.cpp
@@ -59,6 +59,7 @@
m_memoryBuffer = NULL;
m_memoryBufferSize = 0;
m_memoryBufferPosition = 0;
+ m_initialSeekOffset = 0;
m_numReadBits = 0;
m_bufReadBits = 0;
@@ -416,8 +417,8 @@
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);
@@ -626,6 +627,10 @@
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 ))
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 @@
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 @@
File* m_file;
uint64_t m_fileOriginalSize;
uint32_t m_createFlags;
+ int64_t m_initialSeekOffset;
MP4Atom* m_pRootAtom;
MP4Integer32Array m_trakIds;