Comment #1 on issue 168 by
Nicholas...@gmail.com: Better FileProvider API
http://code.google.com/p/mp4v2/issues/detail?id=168
At my employer we too have to use the file provider API and have made
changes to that code. While we do have actual files to read and write we
also need to build an MP4 in memory. Specifically, we build MP4 files of
short coded video sequences that are guaranteed to begin with an I frame.
The issue with the file provider is that it does not provide an abstraction
for getting the file size. It assumes the construct is a real file and
calls a function that expects a genuine file descriptor. This may be OK in
*NIX since most things are file descriptors even if it is not a file on
disk. However, in Windows the API call to get file information fails
because the file provider is not a real file (that is, the file provider
cannot return a handle that is compatible with the Win32 API call for
getting file size).
As stated, I have made changes to accommodate my needs. I don't want to
maintain a personal vendor branch and would like to contribute my changes
back to the community. I have provided a patch file of my changes. Allow
me to describe those changes. I'll be as brief as possible.
I strived for changes that are non-breaking to existing compiled projects.
However, this was not 100% possible. However, reading the discussion from
the OP's link shows that a breaking change isn't entirely taboo.
The first change was to provide additional MP4Create functions. I followed
the style of the MP4Read functions. Thus, I have added two new functions
named MP4CreatProvider and MP4CreateProviderEx. This is a non-breaking
change. The implementation of MP4Create and MP4CreateEx have been modified
to simply call into MP4CreateProviderEx. Default arguments have been
preserved. The original MP4Create and MP4CreateEx functions retain their
behavior in that a NULL provider is used under the hood, which results in
the StandardFileProvider instance being used.
The second change was to add an additional function pointer to the
MP4FileProvider interface. This is a breaking change. I had a choice
between adding a "tell" operation or a "getSize" operation. With "tell"
you would seek to the end and then call "tell" to get the current
position. A problem of that strategy is it could potentially be expensive,
say you were dealing with a large MP4 movie from a SAN drive (maybe a
unrealistic example but you get my point). Thus, I decided on "getSize"
because that implies a cheap operation (reading the file meta data as
opposed to seeking through the whole file).
Lastly, for all intents and purposes I made a very conscience effort to
keep the style and design of the existing code. All spacing, alignments,
naming style, parameter placement, comments, etc., have been written to
faithfully match its neighboring code. I hope this helps with the adoption
of the patch. Please also note that I develop for the Windows platform so
my changes are tested on that platform. I do not have as thorough of a
test for *NIX platforms.
Any feedback is appreciated. Thank you.
Nicholas
Attachments:
MP4CreateProvider.patch 13.9 KB