diff --git a/libplatform/io/FileSystem_win32.cpp b/libplatform/io/FileSystem_win32.cpp index 4a21381..e5b82af 100644 --- a/libplatform/io/FileSystem_win32.cpp +++ b/libplatform/io/FileSystem_win32.cpp @@ -32,7 +32,7 @@ getAttributes ( string path_ ) // the places it's called. ostringstream msg; msg << "can't convert file to UTF-16(" << filename.utf8 << ")"; - throw new Exception(msg.str(),__FILE__,__LINE__,__FUNCTION__); + throw new EXCEPTION(msg.str()); } DWORD attributes = ::GetFileAttributesW(filename); @@ -49,7 +49,7 @@ getAttributes ( string path_ ) // Anything else is an error ostringstream msg; msg << "GetFileAttributes(" << filename.utf8 << ") failed (" << last_err << ")"; - throw new Exception(msg.str(),__FILE__,__LINE__,__FUNCTION__); + throw new EXCEPTION(msg.str()); } // path exists so return its attributes diff --git a/libutil/TrackModifier.cpp b/libutil/TrackModifier.cpp index 2fdae7e..2cb7bf4 100644 --- a/libutil/TrackModifier.cpp +++ b/libutil/TrackModifier.cpp @@ -143,7 +143,7 @@ TrackModifier::fromString( const string& src, bool& dst ) if( iss.rdstate() != ios::eofbit ) { ostringstream oss; oss << "invalid value: " << src; - throw new Exception( oss.str(), __FILE__, __LINE__, __FUNCTION__ ); + throw new EXCEPTION(oss.str()); } } @@ -160,7 +160,7 @@ TrackModifier::fromString( const string& src, float& dst ) if( iss.rdstate() != ios::eofbit ) { ostringstream oss; oss << "invalid value: " << src; - throw new Exception( oss.str(), __FILE__, __LINE__, __FUNCTION__ ); + throw new EXCEPTION(oss.str()); } return dst; @@ -176,7 +176,7 @@ TrackModifier::fromString( const string& src, uint16_t& dst ) if( iss.rdstate() != ios::eofbit ) { ostringstream oss; oss << "invalid value: " << src; - throw new Exception( oss.str(), __FILE__, __LINE__, __FUNCTION__ ); + throw new EXCEPTION(oss.str()); } return dst; @@ -203,7 +203,7 @@ TrackModifier::refTrackAtom( MP4File& file, uint16_t index ) if( !trak ) { oss.str( "" ); oss << "trackIndex " << index << " not found"; - throw new Exception( oss.str(), __FILE__, __LINE__, __FUNCTION__ ); + throw new EXCEPTION(oss.str()); } return *trak; @@ -474,7 +474,7 @@ TrackModifier::Properties::refProperty( const char* name ) if( !_trackModifier._track.FindProperty( name, &property )) { ostringstream oss; oss << "trackId " << _trackModifier.trackId << " property '" << name << "' not found"; - throw new Exception( oss.str(), __FILE__, __LINE__, __FUNCTION__ ); + throw new EXCEPTION(oss.str()); } return *property; diff --git a/src/3gp.cpp b/src/3gp.cpp index f6ec12e..87b0e6e 100644 --- a/src/3gp.cpp +++ b/src/3gp.cpp @@ -41,7 +41,7 @@ void MP4File::Make3GPCompliant(const char* fileName, char* majorBrand, uint32_t if (majorBrand) { if (!supportedBrands || !supportedBrandsCount) { - throw new Exception("Invalid parameters", __FILE__, __LINE__, __FUNCTION__); + throw new EXCEPTION("Invalid parameters"); } } diff --git a/src/exception.cpp b/src/exception.cpp index ddc60d7..e0a6cec 100644 --- a/src/exception.cpp +++ b/src/exception.cpp @@ -29,6 +29,14 @@ namespace mp4v2 { namespace impl { /////////////////////////////////////////////////////////////////////////////// +Exception::Exception( const string& what_ ) + : what(what_) + , line(0) +{ +} + +/////////////////////////////////////////////////////////////////////////////// + Exception::Exception( const string& what_, const char *file_, int line_, @@ -55,13 +63,28 @@ Exception::msg() const { ostringstream retval; - retval << function << ": " << what << " (" << file << "," << line << ")"; + if( !function.empty() ) + retval << function << ": "; + + retval << what; + + if( !file.empty() ) + retval << " (" << file << "," << line << ")"; return retval.str(); } /////////////////////////////////////////////////////////////////////////////// +PlatformException::PlatformException( const string& what_, + int errno_ ) + : Exception(what_) + , m_errno(errno_) +{ +} + +/////////////////////////////////////////////////////////////////////////////// + PlatformException::PlatformException( const string& what_, int errno_, const char *file_, @@ -85,8 +108,13 @@ PlatformException::msg() const { ostringstream retval; - retval << function << ": " << what << ": errno: " << m_errno << " (" << - file << "," << line << ")"; + if( !function.empty() ) + retval << function << ": "; + + retval << what << ": errno: " << m_errno; + + if( !file.empty() ) + retval << " (" << file << "," << line << ")"; return retval.str(); } diff --git a/src/exception.h b/src/exception.h index f0e2e4e..ca0aeab 100644 --- a/src/exception.h +++ b/src/exception.h @@ -29,9 +29,18 @@ namespace mp4v2 { namespace impl { /////////////////////////////////////////////////////////////////////////////// +#ifdef NDEBUG +#define EXCEPTION(message) mp4v2::impl::Exception(message) +#define PLATFORM_EXCEPTION(message, errno) mp4v2::impl::PlatformException(message, errno) +#else +#define EXCEPTION(message) mp4v2::impl::Exception(message, __FILE__, __LINE__, __FUNCTION__) +#define PLATFORM_EXCEPTION(message, errno) mp4v2::impl::PlatformException(message, errno, __FILE__, __LINE__, __FUNCTION__) +#endif + class MP4V2_EXPORT Exception { public: + explicit Exception( const string& what_ ); explicit Exception( const string& what_, const char *file_, int line_, @@ -50,6 +59,8 @@ class MP4V2_EXPORT Exception class MP4V2_EXPORT PlatformException : public Exception { public: + explicit PlatformException( const string& what_, + int errno_ ); explicit PlatformException( const string& what_, int errno_, const char *file_, diff --git a/src/isma.cpp b/src/isma.cpp index 007455d..7d8467a 100644 --- a/src/isma.cpp +++ b/src/isma.cpp @@ -40,7 +40,9 @@ static const uint8_t BifsV2Config[3] = { void MP4File::MakeIsmaCompliant(bool addIsmaComplianceSdp) { - ProtectWriteOperation(__FILE__, __LINE__, __FUNCTION__); + if( !IsWriteMode() ) { + throw new EXCEPTION("operation not permitted in read mode"); + } if (m_useIsma) { // already done diff --git a/src/mp4array.h b/src/mp4array.h index 69d470a..54a3e73 100644 --- a/src/mp4array.h +++ b/src/mp4array.h @@ -74,7 +74,7 @@ class MP4Array { \ void Insert(type newElement, MP4ArrayIndex newIndex) { \ if (newIndex > m_numElements) { \ - throw new PlatformException("illegal array index", ERANGE, __FILE__, __LINE__, __FUNCTION__); \ + throw new PLATFORM_EXCEPTION("illegal array index", ERANGE); \ } \ if (m_numElements == m_maxNumElements) { \ m_maxNumElements = max(m_maxNumElements, (MP4ArrayIndex)1) * 2; \ @@ -91,7 +91,7 @@ class MP4Array { if (!ValidIndex(index)) { \ ostringstream msg; \ msg << "illegal array index: " << index << " of " << m_numElements; \ - throw new PlatformException(msg.str().c_str(), ERANGE, __FILE__, __LINE__, __FUNCTION__); \ + throw new PLATFORM_EXCEPTION(msg.str().c_str(), ERANGE); \ } \ m_numElements--; \ if (index < m_numElements) { \ @@ -103,7 +103,7 @@ class MP4Array { m_numElements = newSize; \ m_maxNumElements = newSize; \ if ( (uint64_t) m_maxNumElements * sizeof(type) > 0xFFFFFFFF ) \ - throw new PlatformException("requested array size exceeds 4GB", ERANGE, __FILE__, __LINE__, __FUNCTION__); /* prevent overflow */ \ + throw new PLATFORM_EXCEPTION("requested array size exceeds 4GB", ERANGE); /* prevent overflow */ \ m_elements = (type*)MP4Realloc(m_elements, \ m_maxNumElements * sizeof(type)); \ } \ @@ -115,7 +115,7 @@ class MP4Array { else { \ ostringstream msg; \ msg << "illegal array index: " << index << " of " << m_numElements; \ - throw new PlatformException(msg.str().c_str(), ERANGE, __FILE__, __LINE__, __FUNCTION__ ); \ + throw new PLATFORM_EXCEPTION(msg.str().c_str(), ERANGE); \ } \ } \ \ diff --git a/src/mp4atom.cpp b/src/mp4atom.cpp index bdc699a..a819658 100644 --- a/src/mp4atom.cpp +++ b/src/mp4atom.cpp @@ -148,7 +148,7 @@ MP4Atom* MP4Atom::ReadAtom(MP4File& file, MP4Atom* pParentAtom) ostringstream oss; oss << "Invalid atom size in '" << type << "' atom, dataSize = " << dataSize << " cannot be less than hdrSize = " << static_cast( hdrSize ); log.errorf( "%s: \"%s\": %s", __FUNCTION__, file.GetFilename().c_str(), oss.str().c_str() ); - throw new Exception( oss.str().c_str(), __FILE__, __LINE__, __FUNCTION__ ); + throw new EXCEPTION(oss.str().c_str()); } dataSize -= hdrSize; @@ -396,7 +396,7 @@ void MP4Atom::ReadProperties(uint32_t startIndex, uint32_t count) ostringstream oss; oss << "atom '" << GetType() << "' is too small; overrun at property: " << m_pProperties[i]->GetName(); - throw new Exception( oss.str().c_str(), __FILE__, __LINE__, __FUNCTION__ ); + throw new EXCEPTION(oss.str().c_str()); } MP4LogLevel thisVerbosity = diff --git a/src/mp4container.cpp b/src/mp4container.cpp index acfbd29..c9a255e 100644 --- a/src/mp4container.cpp +++ b/src/mp4container.cpp @@ -60,7 +60,7 @@ void MP4Container::FindIntegerProperty(const char* name, MP4Property** ppProperty, uint32_t* pIndex) { if (!FindProperty(name, ppProperty, pIndex)) { - throw new Exception("no such property", __FILE__, __LINE__, __FUNCTION__); + throw new EXCEPTION("no such property"); } switch ((*ppProperty)->GetType()) { @@ -71,7 +71,7 @@ void MP4Container::FindIntegerProperty(const char* name, case Integer64Property: break; default: - throw new Exception("type mismatch", __FILE__, __LINE__, __FUNCTION__); + throw new EXCEPTION("type mismatch"); } } @@ -99,10 +99,10 @@ void MP4Container::FindFloatProperty(const char* name, MP4Property** ppProperty, uint32_t* pIndex) { if (!FindProperty(name, ppProperty, pIndex)) { - throw new Exception("no such property", __FILE__, __LINE__, __FUNCTION__); + throw new EXCEPTION("no such property"); } if ((*ppProperty)->GetType() != Float32Property) { - throw new Exception("type mismatch", __FILE__, __LINE__, __FUNCTION__); + throw new EXCEPTION("type mismatch"); } } @@ -130,10 +130,10 @@ void MP4Container::FindStringProperty(const char* name, MP4Property** ppProperty, uint32_t* pIndex) { if (!FindProperty(name, ppProperty, pIndex)) { - throw new Exception("no such property", __FILE__, __LINE__, __FUNCTION__); + throw new EXCEPTION("no such property"); } if ((*ppProperty)->GetType() != StringProperty) { - throw new Exception("type mismatch", __FILE__, __LINE__, __FUNCTION__); + throw new EXCEPTION("type mismatch"); } } @@ -161,10 +161,10 @@ void MP4Container::FindBytesProperty(const char* name, MP4Property** ppProperty, uint32_t* pIndex) { if (!FindProperty(name, ppProperty, pIndex)) { - throw new Exception("no such property", __FILE__, __LINE__, __FUNCTION__); + throw new EXCEPTION("no such property"); } if ((*ppProperty)->GetType() != BytesProperty) { - throw new Exception("type mismatch", __FILE__, __LINE__, __FUNCTION__); + throw new EXCEPTION("type mismatch"); } } diff --git a/src/mp4descriptor.cpp b/src/mp4descriptor.cpp index 202deb1..38c08d4 100644 --- a/src/mp4descriptor.cpp +++ b/src/mp4descriptor.cpp @@ -137,7 +137,7 @@ void MP4Descriptor::ReadProperties(MP4File& file, } else { log.errorf("%s: \"%s\": Overran descriptor, tag %u data size %u property %u", __FUNCTION__, file.GetFilename().c_str(), m_tag, m_size, i); - throw new Exception("overran descriptor",__FILE__, __LINE__, __FUNCTION__); + throw new EXCEPTION("overran descriptor"); } } } diff --git a/src/mp4file.cpp b/src/mp4file.cpp index 2160bd8..77685e3 100644 --- a/src/mp4file.cpp +++ b/src/mp4file.cpp @@ -34,6 +34,11 @@ namespace mp4v2 { namespace impl { /////////////////////////////////////////////////////////////////////////////// +#define PROTECT_WRITE_OPERATION() \ + if( !IsWriteMode() ) {\ + throw new EXCEPTION("operation not permitted in read mode"); \ + } + MP4File::MP4File( ) : m_file ( NULL ) , m_fileOriginalSize ( 0 ) @@ -206,9 +211,7 @@ bool MP4File::Modify( const char* fileName ) // multiple moov atoms?!? if (pAtom != pMoovAtom) { - throw new Exception( - "Badly formed mp4 file, multiple moov atoms", - __FILE__,__LINE__,__FUNCTION__); + throw new EXCEPTION("Badly formed mp4 file, multiple moov atoms"); } if (lastAtomIsMoov) { @@ -397,7 +400,7 @@ void MP4File::Open( const char* name, File::Mode mode, const MP4FileProvider* pr if( m_file->open() ) { ostringstream msg; msg << "open(" << name << ") failed"; - throw new Exception( msg.str(), __FILE__, __LINE__, __FUNCTION__); + throw new EXCEPTION(msg.str()); } switch( mode ) { @@ -628,15 +631,7 @@ void MP4File::Close(uint32_t options) void MP4File::Rename(const char* oldFileName, const char* newFileName) { if( FileSystem::rename( oldFileName, newFileName )) - throw new PlatformException( sys::getLastErrorStr(), sys::getLastError(), __FILE__, __LINE__, __FUNCTION__ ); -} - -void MP4File::ProtectWriteOperation(const char* file, - int line, - const char* func ) -{ - if( !IsWriteMode() ) - throw new Exception( "operation not permitted in read mode", file, line, func ); + throw new PLATFORM_EXCEPTION(sys::getLastErrorStr(), sys::getLastError()); } MP4Track* MP4File::GetTrack(MP4TrackId trackId) @@ -745,7 +740,7 @@ void MP4File::FindIntegerProperty(const char* name, if (!FindProperty(name, ppProperty, pIndex)) { ostringstream msg; msg << "no such property - " << name; - throw new Exception(msg.str(), __FILE__, __LINE__, __FUNCTION__); + throw new EXCEPTION(msg.str()); } switch ((*ppProperty)->GetType()) { @@ -758,7 +753,7 @@ void MP4File::FindIntegerProperty(const char* name, default: ostringstream msg; msg << "type mismatch - property " << name << " type " << (*ppProperty)->GetType(); - throw new Exception(msg.str(), __FILE__, __LINE__, __FUNCTION__); + throw new EXCEPTION(msg.str()); } } @@ -774,7 +769,7 @@ uint64_t MP4File::GetIntegerProperty(const char* name) void MP4File::SetIntegerProperty(const char* name, uint64_t value) { - ProtectWriteOperation(__FILE__, __LINE__, __FUNCTION__); + PROTECT_WRITE_OPERATION(); MP4Property* pProperty = NULL; uint32_t index = 0; @@ -790,12 +785,12 @@ void MP4File::FindFloatProperty(const char* name, if (!FindProperty(name, ppProperty, pIndex)) { ostringstream msg; msg << "no such property - " << name; - throw new Exception(msg.str(), __FILE__, __LINE__, __FUNCTION__); + throw new EXCEPTION(msg.str()); } if ((*ppProperty)->GetType() != Float32Property) { ostringstream msg; msg << "type mismatch - property " << name << " type " << (*ppProperty)->GetType(); - throw new Exception(msg.str(), __FILE__, __LINE__, __FUNCTION__); + throw new EXCEPTION(msg.str()); } } @@ -811,7 +806,7 @@ float MP4File::GetFloatProperty(const char* name) void MP4File::SetFloatProperty(const char* name, float value) { - ProtectWriteOperation(__FILE__, __LINE__, __FUNCTION__); + PROTECT_WRITE_OPERATION(); MP4Property* pProperty; uint32_t index; @@ -827,12 +822,12 @@ void MP4File::FindStringProperty(const char* name, if (!FindProperty(name, ppProperty, pIndex)) { ostringstream msg; msg << "no such property - " << name; - throw new Exception(msg.str(), __FILE__, __LINE__, __FUNCTION__); + throw new EXCEPTION(msg.str()); } if ((*ppProperty)->GetType() != StringProperty) { ostringstream msg; msg << "type mismatch - property " << name << " type " << (*ppProperty)->GetType(); - throw new Exception(msg.str(), __FILE__, __LINE__, __FUNCTION__); + throw new EXCEPTION(msg.str()); } } @@ -848,7 +843,7 @@ const char* MP4File::GetStringProperty(const char* name) void MP4File::SetStringProperty(const char* name, const char* value) { - ProtectWriteOperation(__FILE__, __LINE__, __FUNCTION__); + PROTECT_WRITE_OPERATION(); MP4Property* pProperty; uint32_t index; @@ -864,12 +859,12 @@ void MP4File::FindBytesProperty(const char* name, if (!FindProperty(name, ppProperty, pIndex)) { ostringstream msg; msg << "no such property " << name; - throw new Exception(msg.str(), __FILE__, __LINE__, __FUNCTION__); + throw new EXCEPTION(msg.str()); } if ((*ppProperty)->GetType() != BytesProperty) { ostringstream msg; msg << "type mismatch - property " << name << " - type " << (*ppProperty)->GetType(); - throw new Exception(msg.str(), __FILE__, __LINE__, __FUNCTION__); + throw new EXCEPTION(msg.str()); } } @@ -887,7 +882,7 @@ void MP4File::GetBytesProperty(const char* name, void MP4File::SetBytesProperty(const char* name, const uint8_t* pValue, uint32_t valueSize) { - ProtectWriteOperation(__FILE__, __LINE__, __FUNCTION__); + PROTECT_WRITE_OPERATION(); MP4Property* pProperty; uint32_t index; @@ -902,7 +897,7 @@ void MP4File::SetBytesProperty(const char* name, MP4TrackId MP4File::AddTrack(const char* type, uint32_t timeScale) { - ProtectWriteOperation(__FILE__, __LINE__, __FUNCTION__); + PROTECT_WRITE_OPERATION(); // create and add new trak atom MP4Atom* pTrakAtom = AddChildAtom("moov", "trak"); @@ -1166,7 +1161,7 @@ MP4TrackId MP4File::AddODTrack() // until a demonstrated need emerges // we limit ourselves to one object description track if (m_odTrackId != MP4_INVALID_TRACK_ID) { - throw new Exception("object description track already exists",__FILE__, __LINE__, __FUNCTION__); + throw new EXCEPTION("object description track already exists"); } m_odTrackId = AddSystemsTrack(MP4_OD_TRACK_TYPE); @@ -1441,7 +1436,7 @@ MP4TrackId MP4File::AddAC3AudioTrack( if (pSampleRateProperty) { pSampleRateProperty->SetValue(samplingRate); } else { - throw new Exception("no ac-3.samplingRate property", __FILE__, __LINE__, __FUNCTION__); + throw new EXCEPTION("no ac-3.samplingRate property"); } MP4BitfieldProperty* pBitfieldProperty = NULL; @@ -1452,7 +1447,7 @@ MP4TrackId MP4File::AddAC3AudioTrack( pBitfieldProperty->SetValue(fscod); pBitfieldProperty = NULL; } else { - throw new Exception("no dac3.fscod property", __FILE__, __LINE__, __FUNCTION__); + throw new EXCEPTION("no dac3.fscod property"); } FindProperty(MakeTrackName(trackId, "mdia.minf.stbl.stsd.ac-3.dac3.bsid"), @@ -1461,7 +1456,7 @@ MP4TrackId MP4File::AddAC3AudioTrack( pBitfieldProperty->SetValue(bsid); pBitfieldProperty = NULL; } else { - throw new Exception("no dac3.bsid property", __FILE__, __LINE__, __FUNCTION__); + throw new EXCEPTION("no dac3.bsid property"); } FindProperty(MakeTrackName(trackId, "mdia.minf.stbl.stsd.ac-3.dac3.bsmod"), @@ -1470,7 +1465,7 @@ MP4TrackId MP4File::AddAC3AudioTrack( pBitfieldProperty->SetValue(bsmod); pBitfieldProperty = NULL; } else { - throw new Exception("no dac3.bsmod property", __FILE__, __LINE__, __FUNCTION__); + throw new EXCEPTION("no dac3.bsmod property"); } FindProperty(MakeTrackName(trackId, "mdia.minf.stbl.stsd.ac-3.dac3.acmod"), @@ -1479,7 +1474,7 @@ MP4TrackId MP4File::AddAC3AudioTrack( pBitfieldProperty->SetValue(acmod); pBitfieldProperty = NULL; } else { - throw new Exception("no dac3.acmod property", __FILE__, __LINE__, __FUNCTION__); + throw new EXCEPTION("no dac3.acmod property"); } FindProperty(MakeTrackName(trackId, "mdia.minf.stbl.stsd.ac-3.dac3.lfeon"), @@ -1488,7 +1483,7 @@ MP4TrackId MP4File::AddAC3AudioTrack( pBitfieldProperty->SetValue(lfeon); pBitfieldProperty = NULL; } else { - throw new Exception("no dac3.lfeon property", __FILE__, __LINE__, __FUNCTION__); + throw new EXCEPTION("no dac3.lfeon property"); } FindProperty(MakeTrackName(trackId, "mdia.minf.stbl.stsd.ac-3.dac3.bit_rate_code"), @@ -1497,7 +1492,7 @@ MP4TrackId MP4File::AddAC3AudioTrack( pBitfieldProperty->SetValue(bit_rate_code); pBitfieldProperty = NULL; } else { - throw new Exception("no dac3.bit_rate_code property", __FILE__, __LINE__, __FUNCTION__); + throw new EXCEPTION("no dac3.bit_rate_code property"); } AddDescendantAtoms(MakeTrackName(trackId, NULL), "udta.name"); @@ -2346,7 +2341,7 @@ void MP4File::AddChapter(MP4TrackId chapterTrackId, MP4Duration chapterDuration, { if (MP4_INVALID_TRACK_ID == chapterTrackId) { - throw new Exception("No chapter track given",__FILE__, __LINE__, __FUNCTION__); + throw new EXCEPTION("No chapter track given"); } uint32_t sampleLength = 0; @@ -2816,7 +2811,7 @@ void MP4File::ChangeMovieTimeScale(uint32_t timescale) void MP4File::DeleteTrack(MP4TrackId trackId) { - ProtectWriteOperation(__FILE__, __LINE__, __FUNCTION__); + PROTECT_WRITE_OPERATION(); uint32_t trakIndex = FindTrakAtomIndex(trackId); uint16_t trackIndex = FindTrackIndex(trackId); @@ -2906,7 +2901,7 @@ MP4TrackId MP4File::AllocTrackId() } // extreme case where mp4 file has 2^16 tracks in it - throw new Exception("too many existing tracks", __FILE__, __LINE__, __FUNCTION__); + throw new EXCEPTION("too many existing tracks"); return MP4_INVALID_TRACK_ID; // to keep MSVC happy } @@ -2945,7 +2940,7 @@ MP4TrackId MP4File::FindTrackId(uint16_t trackIndex, ostringstream msg; msg << "Track index doesn't exist - track " << trackIndex << " type " << type; - throw new Exception(msg.str(),__FILE__, __LINE__, __FUNCTION__); + throw new EXCEPTION(msg.str()); return MP4_INVALID_TRACK_ID; // satisfy MS compiler } @@ -2959,7 +2954,7 @@ uint16_t MP4File::FindTrackIndex(MP4TrackId trackId) ostringstream msg; msg << "Track id " << trackId << " doesn't exist"; - throw new Exception(msg.str(),__FILE__, __LINE__, __FUNCTION__); + throw new EXCEPTION(msg.str()); return (uint16_t)-1; // satisfy MS compiler } @@ -2975,7 +2970,7 @@ uint16_t MP4File::FindTrakAtomIndex(MP4TrackId trackId) ostringstream msg; msg << "Track id " << trackId << " doesn't exist"; - throw new Exception(msg.str(),__FILE__, __LINE__, __FUNCTION__); + throw new EXCEPTION(msg.str()); return (uint16_t)-1; // satisfy MS compiler } @@ -3063,7 +3058,7 @@ void MP4File::WriteSample( MP4Duration renderingOffset, bool isSyncSample ) { - ProtectWriteOperation(__FILE__, __LINE__, __FUNCTION__); + PROTECT_WRITE_OPERATION(); m_pTracks[FindTrackIndex(trackId)]->WriteSample( pBytes, numBytes, duration, renderingOffset, isSyncSample ); m_pModificationProperty->SetValue( MP4GetAbsTimestamp() ); @@ -3078,7 +3073,7 @@ void MP4File::WriteSampleDependency( bool isSyncSample, uint32_t dependencyFlags ) { - ProtectWriteOperation(__FILE__, __LINE__, __FUNCTION__); + PROTECT_WRITE_OPERATION(); m_pTracks[FindTrackIndex(trackId)]->WriteSampleDependency( pBytes, numBytes, duration, renderingOffset, isSyncSample, dependencyFlags ); m_pModificationProperty->SetValue( MP4GetAbsTimestamp() ); @@ -3087,7 +3082,7 @@ void MP4File::WriteSampleDependency( void MP4File::SetSampleRenderingOffset(MP4TrackId trackId, MP4SampleId sampleId, MP4Duration renderingOffset) { - ProtectWriteOperation(__FILE__, __LINE__, __FUNCTION__); + PROTECT_WRITE_OPERATION(); m_pTracks[FindTrackIndex(trackId)]-> SetSampleRenderingOffset(sampleId, renderingOffset); @@ -3225,7 +3220,7 @@ bool MP4File::GetTrackLanguage( MP4TrackId trackId, char* code ) bool MP4File::SetTrackLanguage( MP4TrackId trackId, const char* code ) { - ProtectWriteOperation(__FILE__, __LINE__, __FUNCTION__); + PROTECT_WRITE_OPERATION(); ostringstream oss; oss << "moov.trak[" << FindTrakAtomIndex(trackId) << "].mdia.mdhd.language"; @@ -3274,7 +3269,7 @@ bool MP4File::GetTrackName( MP4TrackId trackId, char** name ) bool MP4File::SetTrackName( MP4TrackId trackId, const char* name ) { - ProtectWriteOperation(__FILE__, __LINE__, __FUNCTION__); + PROTECT_WRITE_OPERATION(); char atomstring[40]; MP4Atom *pMetaAtom; MP4BytesProperty *pMetadataProperty = NULL; @@ -3320,7 +3315,7 @@ uint32_t MP4File::GetTimeScale() void MP4File::SetTimeScale(uint32_t value) { if (value == 0) { - throw new Exception("invalid value", __FILE__, __LINE__, __FUNCTION__); + throw new EXCEPTION("invalid value"); } m_pTimeScaleProperty->SetValue(value); } @@ -3482,7 +3477,7 @@ uint32_t MP4File::GetTrackTimeScale(MP4TrackId trackId) void MP4File::SetTrackTimeScale(MP4TrackId trackId, uint32_t value) { if (value == 0) { - throw new Exception("invalid value", __FILE__, __LINE__, __FUNCTION__); + throw new EXCEPTION("invalid value"); } SetTrackIntegerProperty(trackId, "mdia.mdhd.timeScale", value); } @@ -3631,7 +3626,7 @@ void MP4File::SetTrackESConfiguration(MP4TrackId trackId, (MP4Property**)&pConfigDescrProperty) == false || pConfigDescrProperty == NULL) { // probably trackId refers to a hint track - throw new Exception("no such property", __FILE__, __LINE__, __FUNCTION__); + throw new EXCEPTION("no such property"); } // lookup the property to store the configuration @@ -3758,7 +3753,7 @@ void MP4File::SetHintTrackSdp(MP4TrackId hintTrackId, const char* sdpString) MP4Track* pTrack = m_pTracks[FindTrackIndex(hintTrackId)]; if (strcmp(pTrack->GetType(), MP4_HINT_TRACK_TYPE)) { - throw new Exception("track is not a hint track", __FILE__, __LINE__, __FUNCTION__); + throw new EXCEPTION("track is not a hint track"); } (void)AddDescendantAtoms( @@ -3798,7 +3793,7 @@ void MP4File::GetHintTrackRtpPayload( MP4Track* pTrack = m_pTracks[FindTrackIndex(hintTrackId)]; if (strcmp(pTrack->GetType(), MP4_HINT_TRACK_TYPE)) { - throw new Exception("track is not a hint track", __FILE__, __LINE__, __FUNCTION__); + throw new EXCEPTION("track is not a hint track"); } ((MP4RtpHintTrack*)pTrack)->GetPayload( @@ -3814,7 +3809,7 @@ void MP4File::SetHintTrackRtpPayload(MP4TrackId hintTrackId, MP4Track* pTrack = m_pTracks[FindTrackIndex(hintTrackId)]; if (strcmp(pTrack->GetType(), MP4_HINT_TRACK_TYPE)) { - throw new Exception("track is not a hint track", __FILE__, __LINE__, __FUNCTION__); + throw new EXCEPTION("track is not a hint track"); } uint8_t payloadNumber; @@ -3863,8 +3858,7 @@ uint8_t MP4File::AllocRtpPayloadNumber() } if (payload >= 128) { - throw new Exception("no more available rtp payload numbers", - __FILE__, __LINE__, __FUNCTION__); + throw new EXCEPTION("no more available rtp payload numbers"); } return payload; @@ -3876,8 +3870,7 @@ MP4TrackId MP4File::GetHintTrackReferenceTrackId( MP4Track* pTrack = m_pTracks[FindTrackIndex(hintTrackId)]; if (strcmp(pTrack->GetType(), MP4_HINT_TRACK_TYPE)) { - throw new Exception("track is not a hint track", - __FILE__, __LINE__, __FUNCTION__); + throw new EXCEPTION("track is not a hint track"); } MP4Track* pRefTrack = ((MP4RtpHintTrack*)pTrack)->GetRefTrack(); @@ -3896,7 +3889,7 @@ void MP4File::ReadRtpHint( MP4Track* pTrack = m_pTracks[FindTrackIndex(hintTrackId)]; if (strcmp(pTrack->GetType(), MP4_HINT_TRACK_TYPE)) { - throw new Exception("track is not a hint track", __FILE__, __LINE__, __FUNCTION__); + throw new EXCEPTION("track is not a hint track"); } ((MP4RtpHintTrack*)pTrack)-> ReadHint(hintSampleId, pNumPackets); @@ -3908,8 +3901,7 @@ uint16_t MP4File::GetRtpHintNumberOfPackets( MP4Track* pTrack = m_pTracks[FindTrackIndex(hintTrackId)]; if (strcmp(pTrack->GetType(), MP4_HINT_TRACK_TYPE)) { - throw new Exception("track is not a hint track", - __FILE__, __LINE__, __FUNCTION__); + throw new EXCEPTION("track is not a hint track"); } return ((MP4RtpHintTrack*)pTrack)->GetHintNumberOfPackets(); } @@ -3921,8 +3913,7 @@ int8_t MP4File::GetRtpPacketBFrame( MP4Track* pTrack = m_pTracks[FindTrackIndex(hintTrackId)]; if (strcmp(pTrack->GetType(), MP4_HINT_TRACK_TYPE)) { - throw new Exception("track is not a hint track", - __FILE__, __LINE__, __FUNCTION__); + throw new EXCEPTION("track is not a hint track"); } return ((MP4RtpHintTrack*)pTrack)->GetPacketBFrame(packetIndex); } @@ -3934,8 +3925,7 @@ int32_t MP4File::GetRtpPacketTransmitOffset( MP4Track* pTrack = m_pTracks[FindTrackIndex(hintTrackId)]; if (strcmp(pTrack->GetType(), MP4_HINT_TRACK_TYPE)) { - throw new Exception("track is not a hint track", - __FILE__, __LINE__, __FUNCTION__); + throw new EXCEPTION("track is not a hint track"); } return ((MP4RtpHintTrack*)pTrack)->GetPacketTransmitOffset(packetIndex); } @@ -3952,7 +3942,7 @@ void MP4File::ReadRtpPacket( MP4Track* pTrack = m_pTracks[FindTrackIndex(hintTrackId)]; if (strcmp(pTrack->GetType(), MP4_HINT_TRACK_TYPE)) { - throw new Exception("track is not a hint track", __FILE__, __LINE__, __FUNCTION__); + throw new EXCEPTION("track is not a hint track"); } ((MP4RtpHintTrack*)pTrack)->ReadPacket( packetIndex, ppBytes, pNumBytes, @@ -3965,7 +3955,7 @@ MP4Timestamp MP4File::GetRtpTimestampStart( MP4Track* pTrack = m_pTracks[FindTrackIndex(hintTrackId)]; if (strcmp(pTrack->GetType(), MP4_HINT_TRACK_TYPE)) { - throw new Exception("track is not a hint track", __FILE__, __LINE__, __FUNCTION__); + throw new EXCEPTION("track is not a hint track"); } return ((MP4RtpHintTrack*)pTrack)->GetRtpTimestampStart(); } @@ -3977,8 +3967,7 @@ void MP4File::SetRtpTimestampStart( MP4Track* pTrack = m_pTracks[FindTrackIndex(hintTrackId)]; if (strcmp(pTrack->GetType(), MP4_HINT_TRACK_TYPE)) { - throw new Exception("track is not a hint track", - __FILE__, __LINE__, __FUNCTION__); + throw new EXCEPTION("track is not a hint track"); } ((MP4RtpHintTrack*)pTrack)->SetRtpTimestampStart(rtpStart); } @@ -3986,12 +3975,12 @@ void MP4File::SetRtpTimestampStart( void MP4File::AddRtpHint(MP4TrackId hintTrackId, bool isBframe, uint32_t timestampOffset) { - ProtectWriteOperation(__FILE__, __LINE__, __FUNCTION__); + PROTECT_WRITE_OPERATION(); MP4Track* pTrack = m_pTracks[FindTrackIndex(hintTrackId)]; if (strcmp(pTrack->GetType(), MP4_HINT_TRACK_TYPE)) { - throw new Exception("track is not a hint track", __FILE__, __LINE__, __FUNCTION__); + throw new EXCEPTION("track is not a hint track"); } ((MP4RtpHintTrack*)pTrack)->AddHint(isBframe, timestampOffset); } @@ -3999,12 +3988,12 @@ void MP4File::AddRtpHint(MP4TrackId hintTrackId, void MP4File::AddRtpPacket( MP4TrackId hintTrackId, bool setMbit, int32_t transmitOffset) { - ProtectWriteOperation(__FILE__, __LINE__, __FUNCTION__); + PROTECT_WRITE_OPERATION(); MP4Track* pTrack = m_pTracks[FindTrackIndex(hintTrackId)]; if (strcmp(pTrack->GetType(), MP4_HINT_TRACK_TYPE)) { - throw new Exception("track is not a hint track", __FILE__, __LINE__, __FUNCTION__); + throw new EXCEPTION("track is not a hint track"); } ((MP4RtpHintTrack*)pTrack)->AddPacket(setMbit, transmitOffset); } @@ -4012,13 +4001,12 @@ void MP4File::AddRtpPacket( void MP4File::AddRtpImmediateData(MP4TrackId hintTrackId, const uint8_t* pBytes, uint32_t numBytes) { - ProtectWriteOperation(__FILE__, __LINE__, __FUNCTION__); + PROTECT_WRITE_OPERATION(); MP4Track* pTrack = m_pTracks[FindTrackIndex(hintTrackId)]; if (strcmp(pTrack->GetType(), MP4_HINT_TRACK_TYPE)) { - throw new Exception("track is not a hint track", - __FILE__, __LINE__, __FUNCTION__); + throw new EXCEPTION("track is not a hint track"); } ((MP4RtpHintTrack*)pTrack)->AddImmediateData(pBytes, numBytes); } @@ -4026,13 +4014,12 @@ void MP4File::AddRtpImmediateData(MP4TrackId hintTrackId, void MP4File::AddRtpSampleData(MP4TrackId hintTrackId, MP4SampleId sampleId, uint32_t dataOffset, uint32_t dataLength) { - ProtectWriteOperation(__FILE__, __LINE__, __FUNCTION__); + PROTECT_WRITE_OPERATION(); MP4Track* pTrack = m_pTracks[FindTrackIndex(hintTrackId)]; if (strcmp(pTrack->GetType(), MP4_HINT_TRACK_TYPE)) { - throw new Exception("track is not a hint track", - __FILE__, __LINE__, __FUNCTION__); + throw new EXCEPTION("track is not a hint track"); } ((MP4RtpHintTrack*)pTrack)->AddSampleData( sampleId, dataOffset, dataLength); @@ -4040,13 +4027,12 @@ void MP4File::AddRtpSampleData(MP4TrackId hintTrackId, void MP4File::AddRtpESConfigurationPacket(MP4TrackId hintTrackId) { - ProtectWriteOperation(__FILE__, __LINE__, __FUNCTION__); + PROTECT_WRITE_OPERATION(); MP4Track* pTrack = m_pTracks[FindTrackIndex(hintTrackId)]; if (strcmp(pTrack->GetType(), MP4_HINT_TRACK_TYPE)) { - throw new Exception("track is not a hint track", - __FILE__, __LINE__, __FUNCTION__); + throw new EXCEPTION("track is not a hint track"); } ((MP4RtpHintTrack*)pTrack)->AddESConfigurationPacket(); } @@ -4054,13 +4040,12 @@ void MP4File::AddRtpESConfigurationPacket(MP4TrackId hintTrackId) void MP4File::WriteRtpHint(MP4TrackId hintTrackId, MP4Duration duration, bool isSyncSample) { - ProtectWriteOperation(__FILE__, __LINE__, __FUNCTION__); + PROTECT_WRITE_OPERATION(); MP4Track* pTrack = m_pTracks[FindTrackIndex(hintTrackId)]; if (strcmp(pTrack->GetType(), MP4_HINT_TRACK_TYPE)) { - throw new Exception("track is not a hint track", - __FILE__, __LINE__, __FUNCTION__); + throw new EXCEPTION("track is not a hint track"); } ((MP4RtpHintTrack*)pTrack)->WriteHint(duration, isSyncSample); } @@ -4157,7 +4142,7 @@ MP4EditId MP4File::AddTrackEdit( MP4TrackId trackId, MP4EditId editId) { - ProtectWriteOperation(__FILE__, __LINE__, __FUNCTION__); + PROTECT_WRITE_OPERATION(); return m_pTracks[FindTrackIndex(trackId)]->AddEdit(editId); } @@ -4165,7 +4150,7 @@ void MP4File::DeleteTrackEdit( MP4TrackId trackId, MP4EditId editId) { - ProtectWriteOperation(__FILE__, __LINE__, __FUNCTION__); + PROTECT_WRITE_OPERATION(); m_pTracks[FindTrackIndex(trackId)]->DeleteEdit(editId); } diff --git a/src/mp4file.h b/src/mp4file.h index d4142f9..7661498 100644 --- a/src/mp4file.h +++ b/src/mp4file.h @@ -877,8 +877,6 @@ class MP4File void Rename(const char* existingFileName, const char* newFileName); - void ProtectWriteOperation(const char* file, int line, const char *func); - void FindIntegerProperty(const char* name, MP4Property** ppProperty, uint32_t* pIndex = NULL); void FindFloatProperty(const char* name, diff --git a/src/mp4file_io.cpp b/src/mp4file_io.cpp index c965df1..2f89208 100644 --- a/src/mp4file_io.cpp +++ b/src/mp4file_io.cpp @@ -44,7 +44,7 @@ void MP4File::SetPosition( uint64_t pos, File* file ) { if( m_memoryBuffer ) { if( pos >= m_memoryBufferSize ) - throw new Exception( "position out of range", __FILE__, __LINE__, __FUNCTION__ ); + throw new EXCEPTION("position out of range"); m_memoryBufferPosition = pos; return; } @@ -54,7 +54,7 @@ void MP4File::SetPosition( uint64_t pos, File* file ) ASSERT( file ); if( file->seek( pos )) - throw new PlatformException( "seek failed", sys::getLastError(), __FILE__, __LINE__, __FUNCTION__ ); + throw new PLATFORM_EXCEPTION("seek failed", sys::getLastError()); } uint64_t MP4File::GetSize( File* file ) @@ -79,7 +79,7 @@ void MP4File::ReadBytes( uint8_t* buf, uint32_t bufsiz, File* file ) if( m_memoryBuffer ) { if( m_memoryBufferPosition + bufsiz > m_memoryBufferSize ) - throw new Exception( "not enough bytes, reached end-of-memory", __FILE__, __LINE__, __FUNCTION__ ); + throw new EXCEPTION("not enough bytes, reached end-of-memory"); memcpy( buf, &m_memoryBuffer[m_memoryBufferPosition], bufsiz ); m_memoryBufferPosition += bufsiz; return; @@ -91,9 +91,9 @@ void MP4File::ReadBytes( uint8_t* buf, uint32_t bufsiz, File* file ) ASSERT( file ); File::Size nin; if( file->read( buf, bufsiz, nin )) - throw new PlatformException( "read failed", sys::getLastError(), __FILE__, __LINE__, __FUNCTION__ ); + throw new PLATFORM_EXCEPTION("read failed", sys::getLastError()); if( nin != bufsiz ) - throw new Exception( "not enough bytes, reached end-of-file", __FILE__, __LINE__, __FUNCTION__ ); + throw new EXCEPTION("not enough bytes, reached end-of-file"); } void MP4File::PeekBytes( uint8_t* buf, uint32_t bufsiz, File* file ) @@ -160,9 +160,9 @@ void MP4File::WriteBytes( uint8_t* buf, uint32_t bufsiz, File* file ) ASSERT( file ); File::Size nout; if( file->write( buf, bufsiz, nout )) - throw new PlatformException( "write failed", sys::getLastError(), __FILE__, __LINE__, __FUNCTION__ ); + throw new PLATFORM_EXCEPTION("write failed", sys::getLastError()); if( nout != bufsiz ) - throw new Exception( "not all bytes written", __FILE__, __LINE__, __FUNCTION__ ); + throw new EXCEPTION("not all bytes written"); } uint64_t MP4File::ReadUInt(uint8_t size) @@ -283,7 +283,7 @@ void MP4File::WriteFixed16(float value) if (value >= 0x100) { ostringstream msg; msg << value << " out of range"; - throw new PlatformException(msg.str().c_str(), ERANGE, __FILE__, __LINE__, __FUNCTION__); + throw new PLATFORM_EXCEPTION(msg.str().c_str(), ERANGE); } uint8_t iPart = (uint8_t)value; @@ -306,7 +306,7 @@ void MP4File::WriteFixed32(float value) if (value >= 0x10000) { ostringstream msg; msg << value << " out of range"; - throw new PlatformException(msg.str().c_str(), ERANGE, __FILE__, __LINE__, __FUNCTION__); + throw new PLATFORM_EXCEPTION(msg.str().c_str(), ERANGE); } uint16_t iPart = (uint16_t)value; @@ -380,8 +380,7 @@ char* MP4File::ReadCountedString(uint8_t charSize, bool allowExpandedCount, uint charLength += b; ix++; if (ix > 25) - throw new PlatformException("Counted string too long 25 * 255",ERANGE, - __FILE__, __LINE__, __FUNCTION__); + throw new PLATFORM_EXCEPTION("Counted string too long 25 * 255", ERANGE); } while (b == 255); } else { charLength = ReadUInt8(); @@ -450,7 +449,7 @@ void MP4File::WriteCountedString(char* string, if (charLength > 255) { ostringstream msg; msg << "Length is " << charLength; - throw new PlatformException(msg.str().c_str(), ERANGE, __FILE__, __LINE__, __FUNCTION__); + throw new PLATFORM_EXCEPTION(msg.str().c_str(), ERANGE); } // Write the count WriteUInt8(charLength); @@ -545,7 +544,7 @@ void MP4File::WriteMpegLength(uint32_t value, bool compact) if (value > 0x0FFFFFFF) { ostringstream msg; msg << "out of range: " << value; - throw new PlatformException(msg.str().c_str(), ERANGE, __FILE__, __LINE__, __FUNCTION__ ); + throw new PLATFORM_EXCEPTION(msg.str().c_str(), ERANGE); } int8_t numBytes; diff --git a/src/mp4property.cpp b/src/mp4property.cpp index d75f9e1..9d723fd 100644 --- a/src/mp4property.cpp +++ b/src/mp4property.cpp @@ -355,7 +355,7 @@ void MP4StringProperty::SetValue(const char* value, uint32_t index) if (m_readOnly) { ostringstream msg; msg << "property " << m_name << "is read-only"; - throw new PlatformException(msg.str().c_str(), EACCES, __FILE__, __LINE__, __FUNCTION__ ); + throw new PLATFORM_EXCEPTION(msg.str().c_str(), EACCES); } MP4Free(m_values[index]); @@ -525,13 +525,13 @@ void MP4BytesProperty::SetValue(const uint8_t* pValue, uint32_t valueSize, if (m_readOnly) { ostringstream msg; msg << "property " << m_name << "is read-only"; - throw new PlatformException(msg.str().c_str(), EACCES, __FILE__, __LINE__, __FUNCTION__ ); + throw new PLATFORM_EXCEPTION(msg.str().c_str(), EACCES); } if (m_fixedValueSize) { if (valueSize > m_fixedValueSize) { ostringstream msg; msg << GetParentAtom().GetType() << "." << GetName() << " value size " << valueSize << " exceeds fixed value size " << m_fixedValueSize; - throw new Exception(msg.str().c_str(), __FILE__, __LINE__, __FUNCTION__ ); + throw new EXCEPTION(msg.str().c_str()); } if (m_values[index] == NULL) { m_values[index] = (uint8_t*)MP4Calloc(m_fixedValueSize); @@ -556,8 +556,7 @@ void MP4BytesProperty::SetValue(const uint8_t* pValue, uint32_t valueSize, void MP4BytesProperty::SetValueSize(uint32_t valueSize, uint32_t index) { if (m_fixedValueSize) { - throw new Exception("can't change size of fixed sized property", - __FILE__, __LINE__, __FUNCTION__ ); + throw new EXCEPTION("can't change size of fixed sized property"); } if (m_values[index] != NULL) { m_values[index] = (uint8_t*)MP4Realloc(m_values[index], valueSize); diff --git a/src/mp4property.h b/src/mp4property.h index a874c56..3401a2b 100644 --- a/src/mp4property.h +++ b/src/mp4property.h @@ -156,7 +156,7 @@ class MP4IntegerProperty : public MP4Property { if (m_readOnly) { \ ostringstream msg; \ msg << "property is read-only: " << m_name; \ - throw new PlatformException(msg.str().c_str(), EACCES, __FILE__, __LINE__, __FUNCTION__); \ + throw new PLATFORM_EXCEPTION(msg.str().c_str(), EACCES); \ } \ m_values[index] = value; \ } \ @@ -264,7 +264,7 @@ class MP4Float32Property : public MP4Property { if (m_readOnly) { ostringstream msg; msg << "property is read-only: " << m_name; - throw new PlatformException(msg.str().c_str(), EACCES, __FILE__, __LINE__, __FUNCTION__); + throw new PLATFORM_EXCEPTION(msg.str().c_str(), EACCES); } m_values[index] = value; } diff --git a/src/mp4track.cpp b/src/mp4track.cpp index 4b8fc9d..49d0a26 100644 --- a/src/mp4track.cpp +++ b/src/mp4track.cpp @@ -232,7 +232,7 @@ MP4Track::MP4Track(MP4File& file, MP4Atom& trakAtom) // was everything found? if (!success) { - throw new Exception("invalid track", __FILE__, __LINE__, __FUNCTION__ ); + throw new EXCEPTION("invalid track"); } CalculateBytesPerSample(); @@ -277,7 +277,7 @@ void MP4Track::ReadSample( uint32_t* dependencyFlags ) { if( sampleId == MP4_INVALID_SAMPLE_ID ) - throw new Exception( "sample id can't be zero", __FILE__, __LINE__, __FUNCTION__ ); + throw new EXCEPTION("sample id can't be zero"); if( hasDependencyFlags ) *hasDependencyFlags = !m_sdtpLog.empty(); @@ -288,7 +288,7 @@ void MP4Track::ReadSample( } else { if( sampleId > m_sdtpLog.size() ) - throw new Exception( "sample id > sdtp logsize", __FILE__, __LINE__, __FUNCTION__ ); + throw new EXCEPTION("sample id > sdtp logsize"); *dependencyFlags = m_sdtpLog[sampleId-1]; // sampleId is 1-based } } @@ -301,14 +301,13 @@ void MP4Track::ReadSample( File* fin = GetSampleFile( sampleId ); if( fin == (File*)-1 ) - throw new Exception( "sample is located in an inaccessible file", __FILE__, __LINE__, __FUNCTION__ ); + throw new EXCEPTION("sample is located in an inaccessible file"); uint64_t fileOffset = GetSampleFileOffset(sampleId); uint32_t sampleSize = GetSampleSize(sampleId); if (*ppBytes != NULL && *pNumBytes < sampleSize) { - throw new Exception("sample buffer is too small", - __FILE__, __LINE__, __FUNCTION__ ); + throw new EXCEPTION("sample buffer is too small"); } *pNumBytes = sampleSize; @@ -370,8 +369,7 @@ void MP4Track::ReadSampleFragment( uint8_t* pDest) { if (sampleId == MP4_INVALID_SAMPLE_ID) { - throw new Exception("invalid sample id", - __FILE__, __LINE__, __FUNCTION__ ); + throw new EXCEPTION("invalid sample id"); } if (sampleId != m_cachedReadSampleId) { @@ -389,8 +387,7 @@ void MP4Track::ReadSampleFragment( } if (sampleOffset + sampleLength > m_cachedReadSampleSize) { - throw new Exception("offset and/or length are too large", - __FILE__, __LINE__, __FUNCTION__ ); + throw new EXCEPTION("offset and/or length are too large"); } memcpy(pDest, &m_pCachedReadSample[sampleOffset], sampleLength); @@ -410,7 +407,7 @@ void MP4Track::WriteSample( m_trackId, m_writeSampleId, numBytes, numBytes); if (pBytes == NULL && numBytes > 0) { - throw new Exception("no sample data", __FILE__, __LINE__, __FUNCTION__ ); + throw new EXCEPTION("no sample data"); } if (m_isAmr == AMR_UNINITIALIZED ) { @@ -864,7 +861,7 @@ uint32_t MP4Track::GetSampleStscIndex(MP4SampleId sampleId) uint32_t numStscs = m_pStscCountProperty->GetValue(); if (numStscs == 0) { - throw new Exception("No data chunks exist", __FILE__, __LINE__, __FUNCTION__ ); + throw new EXCEPTION("No data chunks exist"); } for (stscIndex = 0; stscIndex < numStscs; stscIndex++) { @@ -919,7 +916,7 @@ File* MP4Track::GetSampleFile( MP4SampleId sampleId ) if ( ::strcmp( pFtypAtom->majorBrand.GetValue(), "qt " ) == 0 ) return nullptr; } - throw new Exception( "invalid stsd entry", __FILE__, __LINE__, __FUNCTION__ ); + throw new EXCEPTION("invalid stsd entry"); } uint32_t drefIndex = pDrefIndexProperty->GetValue(); @@ -1114,8 +1111,7 @@ void MP4Track::GetSampleTimes(MP4SampleId sampleId, elapsed += sampleCount * sampleDelta; } - throw new Exception("sample id out of range", - __FILE__, __LINE__, __FUNCTION__ ); + throw new EXCEPTION("sample id out of range"); } MP4SampleId MP4Track::GetSampleIdFromTime( @@ -1155,8 +1151,7 @@ MP4SampleId MP4Track::GetSampleIdFromTime( elapsed += sampleCount * sampleDelta; } - throw new Exception("time out of range", - __FILE__, __LINE__, __FUNCTION__); + throw new EXCEPTION("time out of range"); return 0; // satisfy MS compiler } @@ -1209,8 +1204,7 @@ uint32_t MP4Track::GetSampleCttsIndex(MP4SampleId sampleId, sid += sampleCount; } - throw new Exception("sample id out of range", - __FILE__, __LINE__, __FUNCTION__ ); + throw new EXCEPTION("sample id out of range"); return 0; // satisfy MS compiler } @@ -1704,14 +1698,12 @@ MP4EditId MP4Track::AddEdit(MP4EditId editId) void MP4Track::DeleteEdit(MP4EditId editId) { if (editId == MP4_INVALID_EDIT_ID) { - throw new Exception("edit id can't be zero", - __FILE__, __LINE__, __FUNCTION__ ); + throw new EXCEPTION("edit id can't be zero"); } if (!m_pElstCountProperty || m_pElstCountProperty->GetValue() == 0) { - throw new Exception("no edits exist", - __FILE__, __LINE__, __FUNCTION__ ); + throw new EXCEPTION("no edits exist"); } m_pElstMediaTimeProperty->DeleteValue(editId - 1); @@ -1879,8 +1871,7 @@ MP4SampleId MP4Track::GetSampleIdFromEditTime( return sampleId; } - throw new Exception("time out of range", - __FILE__, __LINE__, __FUNCTION__ ); + throw new EXCEPTION("time out of range"); } else { // no edit list sampleId = GetSampleIdFromTime(editWhen, false); diff --git a/src/mp4util.cpp b/src/mp4util.cpp index 8a915b2..de2e5cf 100644 --- a/src/mp4util.cpp +++ b/src/mp4util.cpp @@ -258,7 +258,7 @@ uint64_t MP4ConvertTime(uint64_t t, { // avoid float point exception if (oldTimeScale == 0) { - throw new Exception("division by zero", __FILE__, __LINE__, __FUNCTION__ ); + throw new EXCEPTION("division by zero"); } if (oldTimeScale == newTimeScale) return t; diff --git a/src/mp4util.h b/src/mp4util.h index b33bb44..9a477b9 100644 --- a/src/mp4util.h +++ b/src/mp4util.h @@ -33,15 +33,22 @@ namespace mp4v2 { namespace impl { #ifndef ASSERT # define ASSERT(expr) \ if (!(expr)) { \ - throw new Exception("assert failure: " LIBMPV42_STRINGIFY((expr)), __FILE__, __LINE__, __FUNCTION__ ); \ + throw new EXCEPTION("assert failure: " LIBMPV42_STRINGIFY((expr))); \ } #endif -#define WARNING(expr) \ - if (expr) { \ - log.errorf("Warning (%s) in %s at line %u", \ - LIBMPV42_STRINGIFY(expr), __FILE__, __LINE__); \ - } +#ifdef NDEBUG +# define WARNING(expr) \ + if (expr) { \ + log.errorf("Warning: %s", LIBMPV42_STRINGIFY(expr)); \ + } +#else +# define WARNING(expr) \ + if (expr) { \ + log.errorf("Warning (%s) in %s at line %u", \ + LIBMPV42_STRINGIFY(expr), __FILE__, __LINE__); \ + } +#endif /////////////////////////////////////////////////////////////////////////////// @@ -55,7 +62,7 @@ inline void* MP4Malloc(size_t size) { if (size == 0) return NULL; void* p = malloc(size); if (p == NULL && size > 0) { - throw new PlatformException("malloc failed",errno,__FILE__,__LINE__,__FUNCTION__); + throw new PLATFORM_EXCEPTION("malloc failed", errno); } return p; } @@ -79,7 +86,7 @@ inline void* MP4Realloc(void* p, uint32_t newSize) { void* temp = realloc(p, newSize); if (temp == NULL && newSize > 0) { - throw new PlatformException("malloc failed",errno,__FILE__,__LINE__,__FUNCTION__); + throw new PLATFORM_EXCEPTION("malloc failed", errno); } return temp; } diff --git a/src/qtff/ColorParameterBox.cpp b/src/qtff/ColorParameterBox.cpp index 7581c63..4a0a306 100644 --- a/src/qtff/ColorParameterBox.cpp +++ b/src/qtff/ColorParameterBox.cpp @@ -41,14 +41,14 @@ ColorParameterBox::add( MP4FileHandle file, uint16_t trackIndex, const Item& ite MP4Atom* coding; if( !MP4_IS_VALID_FILE_HANDLE( file )) - throw new Exception( "invalid file handle", __FILE__, __LINE__, __FUNCTION__ ); + throw new EXCEPTION("invalid file handle"); if( findCoding( file, trackIndex, coding )) - throw new Exception( "supported coding not found", __FILE__, __LINE__, __FUNCTION__ ); + throw new EXCEPTION("supported coding not found"); MP4Atom* colr; if( !findColorParameterBox( file, *coding, colr )) - throw new Exception( "colr-box already exists", __FILE__, __LINE__, __FUNCTION__ ); + throw new EXCEPTION("colr-box already exists"); colr = MP4Atom::CreateAtom( *((MP4File *)file), coding, BOX_CODE.c_str() ); coding->AddChildAtom( colr ); @@ -92,11 +92,11 @@ ColorParameterBox::get( MP4FileHandle file, uint16_t trackIndex, Item& item ) MP4Atom* coding; if( findCoding( file, trackIndex, coding )) - throw new Exception( "supported coding not found", __FILE__, __LINE__, __FUNCTION__ ); + throw new EXCEPTION("supported coding not found"); MP4Atom* colr; if( findColorParameterBox( file, *coding, colr )) - throw new Exception( "colr-box not found", __FILE__, __LINE__, __FUNCTION__ ); + throw new EXCEPTION("colr-box not found"); MP4Integer16Property* primariesIndex; MP4Integer16Property* transferFunctionIndex; @@ -171,11 +171,11 @@ ColorParameterBox::remove( MP4FileHandle file, uint16_t trackIndex ) { MP4Atom* coding; if( findCoding( file, trackIndex, coding )) - throw new Exception( "supported coding not found", __FILE__, __LINE__, __FUNCTION__ ); + throw new EXCEPTION("supported coding not found"); MP4Atom* colr; if( findColorParameterBox( file, *coding, colr )) - throw new Exception( "colr-box not found", __FILE__, __LINE__, __FUNCTION__ ); + throw new EXCEPTION("colr-box not found"); coding->DeleteChildAtom( colr ); delete colr; @@ -199,11 +199,11 @@ ColorParameterBox::set( MP4FileHandle file, uint16_t trackIndex, const Item& ite { MP4Atom* coding; if( findCoding( file, trackIndex, coding )) - throw new Exception( "supported coding not found", __FILE__, __LINE__, __FUNCTION__ ); + throw new EXCEPTION("supported coding not found"); MP4Atom* colr; if( findColorParameterBox( file, *coding, colr )) - throw new Exception( "colr-box not found", __FILE__, __LINE__, __FUNCTION__ ); + throw new EXCEPTION("colr-box not found"); MP4Integer16Property* primariesIndex; MP4Integer16Property* transferFunctionIndex; @@ -268,7 +268,7 @@ ColorParameterBox::Item::convertFromCSV( const string& text ) xss << "invalid ColorParameterBox format" << " (expecting: INDEX1,INDEX2,INDEX3)" << " got: " << text; - throw new Exception( xss.str(), __FILE__, __LINE__, __FUNCTION__ ); + throw new EXCEPTION(xss.str()); } } diff --git a/src/qtff/PictureAspectRatioBox.cpp b/src/qtff/PictureAspectRatioBox.cpp index 4fe5916..d10456c 100644 --- a/src/qtff/PictureAspectRatioBox.cpp +++ b/src/qtff/PictureAspectRatioBox.cpp @@ -41,14 +41,14 @@ PictureAspectRatioBox::add( MP4FileHandle file, uint16_t trackIndex, const Item& MP4Atom* coding; if( !MP4_IS_VALID_FILE_HANDLE( file )) - throw new Exception( "invalid file handle", __FILE__, __LINE__, __FUNCTION__ ); + throw new EXCEPTION("invalid file handle"); if( findCoding( file, trackIndex, coding )) - throw new Exception( "supported coding not found", __FILE__, __LINE__, __FUNCTION__ ); + throw new EXCEPTION("supported coding not found"); MP4Atom* pasp; if( !findPictureAspectRatioBox( file, *coding, pasp )) - throw new Exception( "pasp-box already exists", __FILE__, __LINE__, __FUNCTION__ ); + throw new EXCEPTION("pasp-box already exists"); pasp = MP4Atom::CreateAtom( *((MP4File *)file), coding, BOX_CODE.c_str() ); coding->AddChildAtom( pasp ); @@ -84,11 +84,11 @@ PictureAspectRatioBox::get( MP4FileHandle file, uint16_t trackIndex, Item& item MP4Atom* coding; if( findCoding( file, trackIndex, coding )) - throw new Exception( "supported coding not found", __FILE__, __LINE__, __FUNCTION__ ); + throw new EXCEPTION("supported coding not found"); MP4Atom* pasp; if( findPictureAspectRatioBox( file, *coding, pasp )) - throw new Exception( "pasp-box not found", __FILE__, __LINE__, __FUNCTION__ ); + throw new EXCEPTION("pasp-box not found"); MP4Integer16Property* hSpacing; MP4Integer16Property* vSpacing; @@ -159,11 +159,11 @@ PictureAspectRatioBox::remove( MP4FileHandle file, uint16_t trackIndex ) { MP4Atom* coding; if( findCoding( file, trackIndex, coding )) - throw new Exception( "supported coding not found", __FILE__, __LINE__, __FUNCTION__ ); + throw new EXCEPTION("supported coding not found"); MP4Atom* pasp; if( findPictureAspectRatioBox( file, *coding, pasp )) - throw new Exception( "pasp-box not found", __FILE__, __LINE__, __FUNCTION__ ); + throw new EXCEPTION("pasp-box not found"); coding->DeleteChildAtom( pasp ); delete pasp; @@ -187,11 +187,11 @@ PictureAspectRatioBox::set( MP4FileHandle file, uint16_t trackIndex, const Item& { MP4Atom* coding; if( findCoding( file, trackIndex, coding )) - throw new Exception( "supported coding not found", __FILE__, __LINE__, __FUNCTION__ ); + throw new EXCEPTION("supported coding not found"); MP4Atom* pasp; if( findPictureAspectRatioBox( file, *coding, pasp )) - throw new Exception( "pasp-box not found", __FILE__, __LINE__, __FUNCTION__ ); + throw new EXCEPTION("pasp-box not found"); MP4Integer16Property* hSpacing; MP4Integer16Property* vSpacing; @@ -258,7 +258,7 @@ PictureAspectRatioBox::Item::convertFromCSV( const string& text ) xss << "invalid PcitureAspectRatioBox format" << " (expecting: hSpacing,vSpacing)" << " got: " << text; - throw new Exception( xss.str(), __FILE__, __LINE__, __FUNCTION__ ); + throw new EXCEPTION(xss.str()); } } diff --git a/src/qtff/coding.cpp b/src/qtff/coding.cpp index 29eaf77..dd2e47f 100644 --- a/src/qtff/coding.cpp +++ b/src/qtff/coding.cpp @@ -54,29 +54,29 @@ findCoding( MP4FileHandle file, uint16_t trackIndex, MP4Atom*& coding ) if( trackIndex == numeric_limits::max() ) { ostringstream xss; xss << "invalid track-index: " << trackIndex; - throw new Exception( xss.str(), __FILE__, __LINE__, __FUNCTION__ ); + throw new EXCEPTION(xss.str()); } ostringstream oss; oss << "moov.trak[" << trackIndex << "].mdia.hdlr"; MP4Atom* hdlr = mp4.FindAtom( oss.str().c_str() ); if( !hdlr ) - throw new Exception( "media handler not found", __FILE__, __LINE__, __FUNCTION__ ); + throw new EXCEPTION("media handler not found"); MP4StringProperty* handlerType; if( !hdlr->FindProperty( "hdlr.handlerType", (MP4Property**)&handlerType )) - throw new Exception( "media handler type-property not found", __FILE__, __LINE__, __FUNCTION__ ); + throw new EXCEPTION("media handler type-property not found"); const string video = "vide"; if( video != handlerType->GetValue() ) - throw new Exception( "video-track required", __FILE__, __LINE__, __FUNCTION__ ); + throw new EXCEPTION("video-track required"); oss.str( "" ); oss.clear(); oss << "moov.trak[" << trackIndex << "].mdia.minf.stbl.stsd"; MP4Atom* stsd = mp4.FindAtom( oss.str().c_str() ); if( !stsd ) - throw new Exception( "media handler type-property not found", __FILE__, __LINE__, __FUNCTION__ ); + throw new EXCEPTION("media handler type-property not found"); // find first atom which is a supported coding const uint32_t atomc = stsd->GetNumberOfChildAtoms(); diff --git a/src/rtphint.cpp b/src/rtphint.cpp index 787c9fb..b106c00 100644 --- a/src/rtphint.cpp +++ b/src/rtphint.cpp @@ -148,8 +148,7 @@ void MP4RtpHintTrack::ReadHint( uint16_t MP4RtpHintTrack::GetHintNumberOfPackets() { if (m_pReadHint == NULL) { - throw new Exception("no hint has been read", - __FILE__, __LINE__, __FUNCTION__); + throw new EXCEPTION("no hint has been read"); } return m_pReadHint->GetNumberOfPackets(); } @@ -157,8 +156,7 @@ uint16_t MP4RtpHintTrack::GetHintNumberOfPackets() bool MP4RtpHintTrack::GetPacketBFrame(uint16_t packetIndex) { if (m_pReadHint == NULL) { - throw new Exception("no hint has been read", - __FILE__, __LINE__, __FUNCTION__); + throw new EXCEPTION("no hint has been read"); } MP4RtpPacket* pPacket = m_pReadHint->GetPacket(packetIndex); @@ -169,8 +167,7 @@ bool MP4RtpHintTrack::GetPacketBFrame(uint16_t packetIndex) uint16_t MP4RtpHintTrack::GetPacketTransmitOffset(uint16_t packetIndex) { if (m_pReadHint == NULL) { - throw new Exception("no hint has been read", - __FILE__, __LINE__, __FUNCTION__); + throw new EXCEPTION("no hint has been read"); } MP4RtpPacket* pPacket = @@ -188,12 +185,10 @@ void MP4RtpHintTrack::ReadPacket( bool addPayload) { if (m_pReadHint == NULL) { - throw new Exception("no hint has been read", - __FILE__, __LINE__, __FUNCTION__); + throw new EXCEPTION("no hint has been read"); } if (!addHeader && !addPayload) { - throw new Exception("no data requested", - __FILE__, __LINE__, __FUNCTION__); + throw new EXCEPTION("no data requested"); } MP4RtpPacket* pPacket = @@ -458,7 +453,7 @@ void MP4RtpHintTrack::AddHint(bool isBFrame, uint32_t timestampOffset) } if (m_pWriteHint) { - throw new Exception("unwritten hint is still pending", __FILE__, __LINE__, __FUNCTION__); + throw new EXCEPTION("unwritten hint is still pending"); } m_pWriteHint = new MP4RtpHint(*this); @@ -472,7 +467,7 @@ void MP4RtpHintTrack::AddHint(bool isBFrame, uint32_t timestampOffset) void MP4RtpHintTrack::AddPacket(bool setMbit, int32_t transmitOffset) { if (m_pWriteHint == NULL) { - throw new Exception("no hint pending", __FILE__, __LINE__, __FUNCTION__); + throw new EXCEPTION("no hint pending"); } MP4RtpPacket* pPacket = m_pWriteHint->AddPacket(); @@ -499,21 +494,19 @@ void MP4RtpHintTrack::AddImmediateData( uint32_t numBytes) { if (m_pWriteHint == NULL) { - throw new Exception("no hint pending", __FILE__, __LINE__, __FUNCTION__ ); + throw new EXCEPTION("no hint pending"); } MP4RtpPacket* pPacket = m_pWriteHint->GetCurrentPacket(); if (pPacket == NULL) { - throw new Exception("no packet pending", __FILE__, __LINE__, __FUNCTION__); + throw new EXCEPTION("no packet pending"); } if (pBytes == NULL || numBytes == 0) { - throw new Exception("no data", - __FILE__, __LINE__, __FUNCTION__ ); + throw new EXCEPTION("no data"); } if (numBytes > 14) { - throw new Exception("data size is larger than 14 bytes", - __FILE__, __LINE__, __FUNCTION__ ); + throw new EXCEPTION("data size is larger than 14 bytes"); } MP4RtpImmediateData* pData = new MP4RtpImmediateData(*pPacket); @@ -534,12 +527,12 @@ void MP4RtpHintTrack::AddSampleData( uint32_t dataLength) { if (m_pWriteHint == NULL) { - throw new Exception("no hint pending", __FILE__, __LINE__, __FUNCTION__ ); + throw new EXCEPTION("no hint pending"); } MP4RtpPacket* pPacket = m_pWriteHint->GetCurrentPacket(); if (pPacket == NULL) { - throw new Exception("no packet pending", __FILE__, __LINE__, __FUNCTION__ ); + throw new EXCEPTION("no packet pending"); } MP4RtpSampleData* pData = new MP4RtpSampleData(*pPacket); @@ -558,7 +551,7 @@ void MP4RtpHintTrack::AddSampleData( void MP4RtpHintTrack::AddESConfigurationPacket() { if (m_pWriteHint == NULL) { - throw new Exception("no hint pending", __FILE__, __LINE__, __FUNCTION__ ); + throw new EXCEPTION("no hint pending"); } uint8_t* pConfig = NULL; @@ -574,7 +567,7 @@ void MP4RtpHintTrack::AddESConfigurationPacket() ASSERT(m_pMaxPacketSizeProperty); if (configSize > m_pMaxPacketSizeProperty->GetValue()) { - throw new Exception("ES configuration is too large for RTP payload", __FILE__, __LINE__, __FUNCTION__ ); + throw new EXCEPTION("ES configuration is too large for RTP payload"); } AddPacket(false); @@ -603,7 +596,7 @@ void MP4RtpHintTrack::AddESConfigurationPacket() void MP4RtpHintTrack::WriteHint(MP4Duration duration, bool isSyncSample) { if (m_pWriteHint == NULL) { - throw new Exception("no hint pending", __FILE__, __LINE__, __FUNCTION__ ); + throw new EXCEPTION("no hint pending"); } uint8_t* pBytes; @@ -894,7 +887,7 @@ void MP4RtpPacket::Read(MP4File& file) pData = new MP4RtpSampleDescriptionData(*this); break; default: - throw new Exception("unknown packet data entry type", __FILE__, __LINE__, __FUNCTION__ ); + throw new EXCEPTION("unknown packet data entry type"); } m_rtpData.Add(pData); @@ -911,7 +904,7 @@ void MP4RtpPacket::ReadExtra(MP4File& file) int32_t extraLength = (int32_t)file.ReadUInt32(); if (extraLength < 4) { - throw new Exception("bad packet extra info length", __FILE__, __LINE__, __FUNCTION__ ); + throw new EXCEPTION("bad packet extra info length"); } extraLength -= 4; @@ -920,7 +913,7 @@ void MP4RtpPacket::ReadExtra(MP4File& file) uint32_t entryTag = file.ReadUInt32(); if (entryLength < 8) { - throw new Exception("bad packet extra info entry length", __FILE__, __LINE__, __FUNCTION__ ); + throw new EXCEPTION("bad packet extra info entry length"); } if (entryTag == STRTOINT32("rtpo") && entryLength == 12) { @@ -935,7 +928,7 @@ void MP4RtpPacket::ReadExtra(MP4File& file) } if (extraLength < 0) { - throw new Exception("invalid packet extra info length", __FILE__, __LINE__, __FUNCTION__ ); + throw new EXCEPTION("invalid packet extra info length"); } } @@ -1318,7 +1311,7 @@ void MP4RtpSampleDescriptionData::GetData(uint8_t* pDest) // bad reference if (pSdAtom == NULL) { - throw new Exception("invalid sample description index", __FILE__, __LINE__, __FUNCTION__ ); + throw new EXCEPTION("invalid sample description index"); } // check validity of the upcoming copy @@ -1328,8 +1321,7 @@ void MP4RtpSampleDescriptionData::GetData(uint8_t* pDest) ((MP4Integer32Property*)m_pProperties[4])->GetValue(); if (offset + length > pSdAtom->GetSize()) { - throw new Exception("offset and/or length are too large", - __FILE__, __LINE__, __FUNCTION__); + throw new EXCEPTION("offset and/or length are too large"); } // now we use the raw file to get the desired bytes