diff --git a/include/mp4v2/file.h b/include/mp4v2/file.h index c77577f..00c02e6 100644 --- a/include/mp4v2/file.h +++ b/include/mp4v2/file.h @@ -328,9 +328,12 @@ bool MP4Optimize( * the library. * On error, #MP4_INVALID_FILE_HANDLE. */ +typedef bool( *ShouldParseAtomCallback )( uint32_t ); + MP4V2_EXPORT MP4FileHandle MP4Read( - const char* fileName ); + const char* fileName, + ShouldParseAtomCallback cb = nullptr ); /** Read an existing mp4 file. * @@ -358,13 +361,6 @@ MP4FileHandle MP4ReadProvider( const char* fileName, const MP4FileProvider* fileProvider DEFAULT(NULL) ); -typedef bool( *ShouldParseAtomCallback )( uint32_t ); -MP4V2_EXPORT -void MP4SetShouldParseAtomCallback( - MP4FileHandle hFile, - ShouldParseAtomCallback f -); - /** @} ***********************************************************************/ #endif /* MP4V2_FILE_H */ diff --git a/src/mp4.cpp b/src/mp4.cpp index b7af6aa..462b21d 100644 --- a/src/mp4.cpp +++ b/src/mp4.cpp @@ -87,7 +87,7 @@ const char* MP4GetFilename( MP4FileHandle hFile ) /////////////////////////////////////////////////////////////////////////////// -MP4FileHandle MP4Read( const char* fileName ) +MP4FileHandle MP4Read( const char* fileName, ShouldParseAtomCallback cb/*=nullptr*/ ) { if (!fileName) return MP4_INVALID_FILE_HANDLE; @@ -99,6 +99,10 @@ MP4FileHandle MP4Read( const char* fileName ) try { ASSERT(pFile); + + if ( cb != nullptr ) + pFile->SetShouldParseAtomCallback( cb ); + pFile->Read( fileName, NULL ); return (MP4FileHandle)pFile; } @@ -143,30 +147,6 @@ MP4FileHandle MP4ReadProvider( const char* fileName, const MP4FileProvider* file return MP4_INVALID_FILE_HANDLE; } -/////////////////////////////////////////////////////////////////////////////// - -void MP4SetShouldParseAtomCallback( MP4FileHandle hFile, ShouldParseAtomCallback cb ) -{ - if (!MP4_IS_VALID_FILE_HANDLE(hFile)) - return; - try - { - ASSERT(hFile); - MP4File& file = *static_cast(hFile); - file.SetShouldParseAtomCallback( cb ); - } - catch( Exception* x ) { - mp4v2::impl::log.errorf(*x); - delete x; - } - catch( ... ) { - mp4v2::impl::log.errorf("%s: unknown exception accessing MP4File " - "filename", __FUNCTION__ ); - } - -// g_parseCallback = cb; -} - /////////////////////////////////////////////////////////////////////////////// MP4FileHandle MP4Create (const char* fileName, diff --git a/src/mp4atom.cpp b/src/mp4atom.cpp index bb14325..bdc699a 100644 --- a/src/mp4atom.cpp +++ b/src/mp4atom.cpp @@ -237,7 +237,7 @@ void MP4Atom::Read() // skip parsing of certain atoms ShouldParseAtomCallback cb = m_File.GetShouldParseAtomCallback(); - if ( cb == nullptr || ( cb != nullptr && cb( ATOMID(m_type) ) ) ) + if ( cb == nullptr || cb( ATOMID(m_type) ) ) { ReadProperties();