[mp4v2] r506 committed - Fix for issue 168: modifications to file provider so that client can s...

32 views
Skip to first unread message

mp...@googlecode.com

unread,
Oct 17, 2014, 6:03:34 PM10/17/14
to mp...@googlegroups.com
Revision: 506
Author: Nicholas...@gmail.com
Date: Fri Oct 17 22:03:13 2014 UTC
Log: Fix for issue 168: modifications to file provider so that client
can supply memory buffers that behave like files.
https://code.google.com/p/mp4v2/source/detail?r=506

Modified:
/trunk/include/mp4v2/file.h
/trunk/libplatform/io/File.cpp
/trunk/libplatform/io/File.h
/trunk/libplatform/io/File_posix.cpp
/trunk/libplatform/io/File_win32.cpp
/trunk/src/mp4.cpp
/trunk/src/mp4file.cpp
/trunk/src/mp4file.h

=======================================
--- /trunk/include/mp4v2/file.h Sun Jun 26 06:49:00 2011 UTC
+++ /trunk/include/mp4v2/file.h Fri Oct 17 22:03:13 2014 UTC
@@ -35,11 +35,12 @@
*/
typedef struct MP4FileProvider_s
{
- void* ( *open )( const char* name, MP4FileMode mode );
- int ( *seek )( void* handle, int64_t pos );
- int ( *read )( void* handle, void* buffer, int64_t size, int64_t*
nin, int64_t maxChunkSize );
- int ( *write )( void* handle, const void* buffer, int64_t size,
int64_t* nout, int64_t maxChunkSize );
- int ( *close )( void* handle );
+ void* ( *open )( const char* name, MP4FileMode mode );
+ int ( *seek )( void* handle, int64_t pos );
+ int ( *read )( void* handle, void* buffer, int64_t size, int64_t*
nin, int64_t maxChunkSize );
+ int ( *write )( void* handle, const void* buffer, int64_t size,
int64_t* nout, int64_t maxChunkSize );
+ int ( *close )( void* handle );
+ int ( *getSize )( void* handle, int64_t* nout );
} MP4FileProvider;

/** Close an mp4 file.
@@ -121,6 +122,78 @@
char** compatibleBrands DEFAULT(0),
uint32_t compatibleBrandsCount DEFAULT(0) );

+/** Create a new mp4 file.
+ *
+ * MP4CreateProvider is the first call that should be used when you want
to
+ * create a new, empty mp4 file. It is equivalent to opening a file for
+ * writing, but also involved with creation of necessary mp4 framework
+ * structures. ie. invoking MP4CreateProvider() followed by MP4Close()
will
+ * result in a file with a non-zero size.
+ *
+ * @param fileName pathname of the file to be created.
+ * On Windows, this should be a UTF-8 encoded string.
+ * On other platforms, it should be an 8-bit encoding that is
+ * appropriate for the platform, locale, file system, etc.
+ * (prefer to use UTF-8 when possible).
+ * @param flags bitmask that allows the user to set 64-bit values for
+ * data or time atoms. Valid bits may be any combination of:
+ * @li #MP4_CREATE_64BIT_DATA
+ * @li #MP4_CREATE_64BIT_TIME
+ * @param fileProvider custom implementation of file I/O operations.
+ * All functions in structure must be implemented.
+ * The structure is immediately copied internally.
+ *
+ * @return On success a handle of the newly created file for use in
+ * subsequent calls to the library.
+ * On error, #MP4_INVALID_FILE_HANDLE.
+ */
+MP4V2_EXPORT
+MP4FileHandle MP4CreateProvider(
+ const char* fileName,
+ uint32_t flags DEFAULT(0),
+ const MP4FileProvider* fileProvider DEFAULT(NULL) );
+
+/** Create a new mp4 file with extended options.
+ *
+ * MP4CreateProviderEx is an extended version of MP4CreateProvider().
+ *
+ * @param fileName pathname of the file to be created.
+ * On Windows, this should be a UTF-8 encoded string.
+ * On other platforms, it should be an 8-bit encoding that is
+ * appropriate for the platform, locale, file system, etc.
+ * (prefer to use UTF-8 when possible).
+ * @param flags bitmask that allows the user to set 64-bit values for
+ * data or time atoms. Valid bits may be any combination of:
+ * @li #MP4_CREATE_64BIT_DATA
+ * @li #MP4_CREATE_64BIT_TIME
+ * @param fileProvider custom implementation of file I/O operations.
+ * All functions in structure must be implemented.
+ * The structure is immediately copied internally.
+ * @param add_ftyp if true an <b>ftyp</b> atom is automatically created.
+ * @param add_iods if true an <b>iods</b> atom is automatically created.
+ * @param majorBrand <b>ftyp</b> brand identifier.
+ * @param minorVersion <b>ftyp</b> informative integer for the minor
version
+ * of the major brand.
+ * @param compatibleBrands <b>ftyp</b> list of compatible brands.
+ * @param compatibleBrandsCount is the count of items specified in
+ * compatibleBrands.
+ *
+ * @return On success a handle of the newly created file for use in
+ * subsequent calls to the library.
+ * On error, #MP4_INVALID_FILE_HANDLE.
+ */
+MP4V2_EXPORT
+MP4FileHandle MP4CreateProviderEx(
+ const char* fileName,
+ uint32_t flags DEFAULT(0),
+ const MP4FileProvider* fileProvider DEFAULT(NULL),
+ int add_ftyp DEFAULT(1),
+ int add_iods DEFAULT(1),
+ char* majorBrand DEFAULT(0),
+ uint32_t minorVersion DEFAULT(0),
+ char** compatibleBrands DEFAULT(0),
+ uint32_t compatibleBrandsCount DEFAULT(0) );
+
/** Dump mp4 file contents as ASCII either to stdout or the
* log callback (@p see MP4SetLogCallback)
*
=======================================
--- /trunk/libplatform/io/File.cpp Mon May 11 22:56:32 2009 UTC
+++ /trunk/libplatform/io/File.cpp Fri Oct 17 22:03:13 2014 UTC
@@ -63,7 +63,8 @@
if( _provider.open( _name, _mode ))
return true;

- FileSystem::getFileSize( _name, _size );
+ if( _provider.getSize( _size ))
+ return true;

_isOpen = true;
return false;
@@ -128,6 +129,15 @@
_isOpen = false;
return false;
}
+
+bool
+File::getSize( Size& nout )
+{
+ if( !_isOpen )
+ return false;
+
+ return _provider.getSize( nout );
+}


///////////////////////////////////////////////////////////////////////////////

@@ -179,6 +189,12 @@
{
return _call.close( _handle );
}
+
+bool
+CustomFileProvider::getSize( Size& nout )
+{
+ return _call.getSize( _handle, &nout );
+}


///////////////////////////////////////////////////////////////////////////////

=======================================
--- /trunk/libplatform/io/File.h Fri Apr 2 20:17:07 2010 UTC
+++ /trunk/libplatform/io/File.h Fri Oct 17 22:03:13 2014 UTC
@@ -30,6 +30,7 @@
virtual bool read( void* buffer, Size size, Size& nin, Size
maxChunkSize ) = 0;
virtual bool write( const void* buffer, Size size, Size& nout, Size
maxChunkSize ) = 0;
virtual bool close() = 0;
+ virtual bool getSize( Size& nout ) = 0;

protected:
FileProvider() { }
@@ -163,6 +164,18 @@

bool write( const void* buffer, Size size, Size& nout, Size
maxChunkSize = 0 );

+
///////////////////////////////////////////////////////////////////////////
+ //!
+ //! Get size of file in bytes.
+ //!
+ //! @param nout output indicating the size of the file in bytes.
+ //!
+ //! @return true on failure, false on success.
+ //!
+
///////////////////////////////////////////////////////////////////////////
+
+ bool getSize( Size& nout );
+
private:
std::string _name;
bool _isOpen;
@@ -195,6 +208,7 @@
bool read( void* buffer, Size size, Size& nin, Size maxChunkSize );
bool write( const void* buffer, Size size, Size& nout, Size
maxChunkSize );
bool close();
+ bool getSize( Size& nout );

private:
MP4FileProvider _call;
=======================================
--- /trunk/libplatform/io/File_posix.cpp Mon May 11 22:56:32 2009 UTC
+++ /trunk/libplatform/io/File_posix.cpp Fri Oct 17 22:03:13 2014 UTC
@@ -14,11 +14,13 @@
bool read( void* buffer, Size size, Size& nin, Size maxChunkSize );
bool write( const void* buffer, Size size, Size& nout, Size
maxChunkSize );
bool close();
+ bool getSize( Size& nout );

private:
bool _seekg;
bool _seekp;
std::fstream _fstream;
+ std::string _name;
};


///////////////////////////////////////////////////////////////////////////////
@@ -56,6 +58,7 @@
}

_fstream.open( name.c_str(), om );
+ _name = name;
return _fstream.fail();
}

@@ -95,6 +98,17 @@
_fstream.close();
return _fstream.fail();
}
+
+bool
+StandardFileProvider::getSize( Size& nout )
+{
+ bool retval;
+
+ // getFileSize will log if it fails
+ retval = FileSystem::getFileSize( _name, nout );
+
+ return retval;
+}


///////////////////////////////////////////////////////////////////////////////

=======================================
--- /trunk/libplatform/io/File_win32.cpp Thu Feb 3 21:46:27 2011 UTC
+++ /trunk/libplatform/io/File_win32.cpp Fri Oct 17 22:03:13 2014 UTC
@@ -37,6 +37,7 @@
bool read( void* buffer, Size size, Size& nin, Size maxChunkSize );
bool write( const void* buffer, Size size, Size& nout, Size
maxChunkSize );
bool close();
+ bool getSize( Size& nout );

private:
HANDLE _handle;
@@ -244,6 +245,26 @@
// we return 0/false to indicate success, so negate.
return !retval;
}
+
+/**
+ * Get the size of a the file in bytes
+ *
+ * @param nout populated with the size of the file in
+ * bytes if the function succeeds
+ *
+ * @retval false successfully got the file size
+ * @retval true error getting the file size
+ */
+bool
+StandardFileProvider::getSize( Size& nout )
+{
+ BOOL retval;
+
+ // getFileSize will log if it fails
+ retval = FileSystem::getFileSize( _name, nout );
+
+ return retval;
+}


///////////////////////////////////////////////////////////////////////////////

=======================================
--- /trunk/src/mp4.cpp Thu Oct 16 19:57:24 2014 UTC
+++ /trunk/src/mp4.cpp Fri Oct 17 22:03:13 2014 UTC
@@ -146,9 +146,9 @@

///////////////////////////////////////////////////////////////////////////////

MP4FileHandle MP4Create (const char* fileName,
- uint32_t flags)
+ uint32_t flags)
{
- return MP4CreateEx(fileName, flags);
+ return MP4CreateProviderEx(fileName, flags);
}

MP4FileHandle MP4CreateEx (const char* fileName,
@@ -159,6 +159,29 @@
uint32_t minorVersion,
char** supportedBrands,
uint32_t supportedBrandsCount)
+ {
+ return MP4CreateProviderEx(fileName, flags, NULL,
+ add_ftyp, add_iods,
+ majorBrand, minorVersion,
+ supportedBrands, supportedBrandsCount);
+ }
+
+ MP4FileHandle MP4CreateProvider (const char* fileName,
+ uint32_t flags,
+ const MP4FileProvider* fileProvider)
+ {
+ return MP4CreateProviderEx(fileName, flags, fileProvider);
+ }
+
+ MP4FileHandle MP4CreateProviderEx (const char* fileName,
+ uint32_t flags,
+ const MP4FileProvider* fileProvider,
+ int add_ftyp,
+ int add_iods,
+ char* majorBrand,
+ uint32_t minorVersion,
+ char** supportedBrands,
+ uint32_t supportedBrandsCount)
{
if (!fileName)
return MP4_INVALID_FILE_HANDLE;
@@ -170,7 +193,8 @@
try {
ASSERT(pFile);
// LATER useExtensibleFormat, moov first, then mvex's
- pFile->Create(fileName, flags, add_ftyp, add_iods,
+ pFile->Create(fileName, flags, fileProvider,
+ add_ftyp, add_iods,
majorBrand, minorVersion,
supportedBrands, supportedBrandsCount);
return (MP4FileHandle)pFile;
@@ -188,6 +212,8 @@
delete pFile;
return MP4_INVALID_FILE_HANDLE;
}
+
+///////////////////////////////////////////////////////////////////////////////

MP4FileHandle MP4Modify(const char* fileName,
uint32_t flags)
=======================================
--- /trunk/src/mp4file.cpp Sun May 20 20:41:37 2012 UTC
+++ /trunk/src/mp4file.cpp Fri Oct 17 22:03:13 2014 UTC
@@ -97,17 +97,18 @@
CacheProperties();
}

-void MP4File::Create( const char* fileName,
- uint32_t flags,
- int add_ftyp,
- int add_iods,
- char* majorBrand,
- uint32_t minorVersion,
- char** supportedBrands,
- uint32_t supportedBrandsCount )
+void MP4File::Create( const char* fileName,
+ uint32_t flags,
+ const MP4FileProvider* provider,
+ int add_ftyp,
+ int add_iods,
+ char* majorBrand,
+ uint32_t minorVersion,
+ char** supportedBrands,
+ uint32_t supportedBrandsCount )
{
m_createFlags = flags;
- Open( fileName, File::MODE_CREATE, NULL );
+ Open( fileName, File::MODE_CREATE, provider );

// generate a skeletal atom tree
m_pRootAtom = MP4Atom::CreateAtom(*this, NULL, NULL);
=======================================
--- /trunk/src/mp4file.h Sun Jun 26 06:49:00 2011 UTC
+++ /trunk/src/mp4file.h Fri Oct 17 22:03:13 2014 UTC
@@ -74,14 +74,15 @@
// file ops

///////////////////////////////////////////////////////////////////////////

- void Create( const char* fileName,
- uint32_t flags,
- int add_ftyp = 1,
- int add_iods = 1,
- char* majorBrand = NULL,
- uint32_t minorVersion = 0,
- char** supportedBrands = NULL,
- uint32_t supportedBrandsCount = 0 );
+ void Create( const char* fileName,
+ uint32_t flags,
+ const MP4FileProvider* provider = NULL,
+ int add_ftyp = 1,
+ int add_iods = 1,
+ char* majorBrand = NULL,
+ uint32_t minorVersion = 0,
+ char** supportedBrands = NULL,
+ uint32_t supportedBrandsCount = 0 );

const std::string &GetFilename() const;
void Read( const char* name, const MP4FileProvider* provider );
Reply all
Reply to author
Forward
0 new messages