Skip to content

Commit

Permalink
Build Fix
Browse files Browse the repository at this point in the history
- last changeset broke build, this src/impl.h change should
  have been included with it.

libmp4v2 namespace mp4v2::util
- documented itmf and qtff subnamespaces.
- qtff supports COLR and PASP atom management and exports
  a C++ interface for libtuil/util usage.
- itmf supports ILST COVER-ART atom management and exports
  a C++ interface for libtuil/util usage.
- added special namespace mp4v2::util to export

Utilities
- continuing major work on overhaul.
- mp4art, mp4file, mp4track, and mp4subtitle now set
  file I/O verbosity even for all of their actions.
  prior behavior was that only mp4file --dump used
  --debug CLI option.
- mp4art, mp4track now use the new MP4CopyClose()
  mechanism to allow for full manipulation of atom tree.
- added COLR management support to mp4track.
- added PASP management support to mp4track.

Documentation
- minor style tweak to doxygen.

TODO
- assert Cygwin and VStudio builds are sane.
  • Loading branch information
Kona8lend authored and Kona8lend committed Dec 11, 2008
1 parent 332a5ac commit 0054d41
Show file tree
Hide file tree
Showing 15 changed files with 1,737 additions and 102 deletions.
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ AC_ARG_ENABLE([mingw_mt],
###############################################################################

AC_PROG_CXX
AC_LIBTOOL_WIN32_DLL
#AC_LIBTOOL_WIN32_DLL
AC_PROG_LIBTOOL

AC_CHECK_PROG([FOUND_HELP2MAN],[help2man],[yes],[no])
Expand Down
5 changes: 4 additions & 1 deletion doc/doxygen/project.css
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,12 @@ h1 small a {

p,ul {
margin-top: 1em;
margin-bottom: 1em;
}

/* ----------------------------------*/

dl ul,
ul ul {
margin-top: 0;
margin-bottom: 0;
Expand Down Expand Up @@ -312,7 +314,8 @@ div.memdoc {
-moz-border-radius-bottomright: 0.5em;
}

div.memproto, div.memdoc {
div.memproto,
div.memdoc {
padding-left: 1em;
padding-right: 1em;
}
Expand Down
119 changes: 86 additions & 33 deletions libutil/Utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
///////////////////////////////////////////////////////////////////////////////

#include "impl.h"
#include "src/mp4error.h"

namespace mp4v2 { namespace util {

Expand All @@ -32,7 +33,6 @@ Utility::Utility( string name_, int argc_, char** argv_ )
, _name ( name_ )
, _argc ( argc_ )
, _argv ( argv_ )
, _optimize ( false )
, _dryrun ( false )
, _keepgoing ( false )
, _overwrite ( false )
Expand Down Expand Up @@ -67,18 +67,29 @@ Utility::batch( int argi )
if( !(argi < _argc) )
return SUCCESS;

bool result = FAILURE;
bool batchResult = FAILURE;
for( int i = argi; i < _argc; i++ ) {
if( job( _argv[i] )) {
if( !_keepgoing )
return FAILURE;
bool subResult = FAILURE;
try {
if( !job( _argv[i] )) {
batchResult = SUCCESS;
subResult = SUCCESS;
}
}
else {
result = SUCCESS;
catch( mp4v2::impl::MP4Error* x ) {
x->Print( stderr );
delete x;
}
catch( UtilException* x ) {
herrf( "%s\n", x->what.c_str() );
delete x;
}
}

return result;
if( !_keepgoing && subResult == FAILURE )
return FAILURE;
}

return batchResult;
}

///////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -251,23 +262,44 @@ Utility::job( string arg )

// perform job
JobContext job( arg );
const bool result = utility_job( job );
bool result = FAILURE;
try {
result = utility_job( job );
}
catch( mp4v2::impl::MP4Error* x ) {
x->Print( stderr );
delete x;
}
catch( UtilException* x ) {
herrf( "%s\n", x->what.c_str() );
delete x;
}

// close file handle flagged with job
if( job.fileHandle != MP4_INVALID_FILE_HANDLE ) {
if( result == SUCCESS && job.fileWasModified ) {
string tfile = job.file;
tfile += ".tmp";

verbose2f( "writing %s\n", tfile.c_str() );
if( !MP4CopyClose( job.fileHandle, tfile.c_str() ))
hwarnf( "write failed: %s\n", job.file.c_str() );

verbose2f( "renaming %s -> %s\n", tfile.c_str(), job.file.c_str() );
if( io::FileSystem::rename( tfile, job.file ))
hwarnf( "rename failed: %s -> %s\n", tfile.c_str(), job.file.c_str() );
}
else {
verbose2f( "closing %s\n", job.file.c_str() );
MP4Close( job.fileHandle );
}
}

// free data flagged with job
list<void*>::iterator ie = job.tofree.end();
for( list<void*>::iterator it = job.tofree.begin(); it != ie; it++ )
free( *it );

// close file handle flagged with job
if( job.fileHandle != MP4_INVALID_FILE_HANDLE )
MP4Close( job.fileHandle );

// invoke optimize if flagged
if( _optimize && job.optimizeApplicable ) {
verbose1f( "optimizing %s\n", job.file.c_str() );
if( !MP4Optimize( job.file.c_str(), NULL ))
hwarnf( "optimize failed: %s\n", job.file.c_str() );
}

verbose2f( "job end\n" );
_jobCount++;
Expand All @@ -279,10 +311,18 @@ Utility::job( string arg )
bool
Utility::herrf( const char* format, ... )
{
fprintf( stdout, (_keepgoing ? "WARNING: " : "ERROR: ") );
va_list ap;
va_start( ap, format );
vfprintf( stdout, format, ap );

if( _keepgoing ) {
fprintf( stdout, "WARNING: " );
vfprintf( stdout, format, ap );
}
else {
fprintf( stderr, "ERROR: " );
vfprintf( stderr, format, ap );
}

va_end( ap );
return FAILURE;
}
Expand Down Expand Up @@ -387,6 +427,26 @@ Utility::printVersion( bool extended )

bool
Utility::process()
{
bool rv = true;

try {
rv = process_impl();
}
catch( UtilException* x ) {
// rare usage of herrf, make sure its not a warning header.
_keepgoing = false;
herrf( "%s\n", x->what.c_str() );
delete x;
}

return rv;
}

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

bool
Utility::process_impl()
{
formatGroups();

Expand All @@ -408,18 +468,14 @@ Utility::process()

bool handled = false;
if( utility_option( code, handled ))
break;
return FAILURE;
if( handled )
continue;

if( codes.find( code ) == codes.end() )
continue;

switch( code ) {
case 'z':
_optimize = true;
break;

case 'y':
_dryrun = true;
break;
Expand Down Expand Up @@ -586,9 +642,6 @@ Utility::verbose3f( const char* format, ... )
const bool Utility::SUCCESS = false;
const bool Utility::FAILURE = true;

const Utility::Option Utility::STD_OPTIMIZE( 'z', false, "optimize", false, LC_NONE,
"optimize mp4 file after modification" );

const Utility::Option Utility::STD_DRYRUN( 'y', false, "dryrun", false, LC_NONE,
"do not actually create or modify any files" );

Expand Down Expand Up @@ -720,9 +773,9 @@ Utility::Option::Option(
///////////////////////////////////////////////////////////////////////////////

Utility::JobContext::JobContext( string file_ )
: file ( file_ )
, fileHandle ( MP4_INVALID_FILE_HANDLE )
, optimizeApplicable ( false )
: file ( file_ )
, fileHandle ( MP4_INVALID_FILE_HANDLE )
, fileWasModified ( false )
{
}

Expand Down
4 changes: 2 additions & 2 deletions libutil/Utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class Utility

const string file; //!< file job is working on
MP4FileHandle fileHandle; //!< handle of file, if applicable to job
bool optimizeApplicable; //!< indicate file optimization is applicable
bool fileWasModified; //!< indicate file was modified
list<void*> tofree; //!< memory to free at end of job
};

Expand Down Expand Up @@ -148,6 +148,7 @@ class Utility
void formatGroups();
void debugUpdate( uint32_t );
void verbose( uint32_t, const char*, va_list );
bool process_impl();

private:
string _help;
Expand All @@ -161,7 +162,6 @@ class Utility
char* const* const _argv; //!< arg vector

// common options state
bool _optimize; //!< optimize mp4 file after modification
bool _strict; //!< strict compatibliity
bool _dryrun; //!< dry-run, no writing is actually performed
bool _keepgoing; //!< contine batch processing even after error
Expand Down
1 change: 1 addition & 0 deletions src/impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace mp4v2 { namespace impl {
///////////////////////////////////////////////////////////////////////////////

#include "util.h"
#include "mp4error.h"
#include "mp4util.h"
#include "mp4array.h"
#include "mp4track.h"
Expand Down
17 changes: 3 additions & 14 deletions src/itmf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@ ArtList::~ArtList()
bool
artAdd( MP4FileHandle file, const ArtItem& item )
{
if( file == MP4_INVALID_FILE_HANDLE )
return true;
MP4File& mp4 = *((MP4File*)file);

const char* const covr_name = "moov.udta.meta.ilst.covr";
Expand All @@ -101,10 +99,10 @@ artAdd( MP4FileHandle file, const ArtItem& item )
MP4Atom* atom = covr->GetChildAtom( i );

MP4BytesProperty* metadata = NULL;
if ( !atom->FindProperty( "data.metadata", (MP4Property**)&metadata ))
if( !atom->FindProperty( "data.metadata", (MP4Property**)&metadata ))
continue;

if ( metadata->GetCount() )
if( metadata->GetCount() )
continue;

data = atom;
Expand All @@ -116,6 +114,7 @@ artAdd( MP4FileHandle file, const ArtItem& item )
if( !data ) {
data = MP4Atom::CreateAtom( "data" );
covr->AddChildAtom( data );
data->Generate();
index = covr->GetNumberOfChildAtoms() - 1;
}

Expand All @@ -128,9 +127,6 @@ bool
artGet( MP4FileHandle file, ArtItem& item, uint32_t index )
{
item.reset();

if( file == MP4_INVALID_FILE_HANDLE )
return true;
MP4File& mp4 = *((MP4File*)file);

MP4Atom* covr = mp4.FindAtom( "moov.udta.meta.ilst.covr" );
Expand Down Expand Up @@ -161,9 +157,6 @@ bool
artList( MP4FileHandle file, ArtList& out )
{
out.clear();

if( file == MP4_INVALID_FILE_HANDLE )
return true;
MP4File& mp4 = *((MP4File*)file);

const uint32_t artc = mp4.GetMetadataCoverArtCount();
Expand All @@ -179,8 +172,6 @@ artList( MP4FileHandle file, ArtList& out )
bool
artRemove( MP4FileHandle file, uint32_t index )
{
if( file == MP4_INVALID_FILE_HANDLE )
return true;
MP4File& mp4 = *((MP4File*)file);

if( index == numeric_limits<uint32_t>::max() )
Expand Down Expand Up @@ -211,8 +202,6 @@ artRemove( MP4FileHandle file, uint32_t index )
bool
artSet( MP4FileHandle file, const ArtItem& item, uint32_t index )
{
if( file == MP4_INVALID_FILE_HANDLE )
return true;
MP4File& mp4 = *((MP4File*)file);

MP4Atom* covr = mp4.FindAtom( "moov.udta.meta.ilst.covr" );
Expand Down
Loading

0 comments on commit 0054d41

Please sign in to comment.