Skip to content

Commit

Permalink
I think I merged all of my changes in correctly here ...
Browse files Browse the repository at this point in the history
  • Loading branch information
dchengTSC committed Jan 21, 2013
1 parent a52db03 commit 0b270e6
Show file tree
Hide file tree
Showing 14 changed files with 248 additions and 2 deletions.
1 change: 1 addition & 0 deletions include/mp4v2/file.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ typedef struct MP4FileProvider_s
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 );
int64_t ( *size)( void* handle );
} MP4FileProvider;

/** Close an mp4 file.
Expand Down
8 changes: 8 additions & 0 deletions include/mp4v2/sample.h
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,14 @@ int8_t MP4GetSampleSync(
MP4TrackId trackId,
MP4SampleId sampleId );


/* */
MP4V2_EXPORT
uint64_t MP4GetSampleFileOffset(
MP4FileHandle hFile,
MP4TrackId trackId,
MP4SampleId sampleId );

/* @} ***********************************************************************/

#endif /* MP4V2_SAMPLE_H */
8 changes: 8 additions & 0 deletions include/mp4v2/track.h
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,14 @@ MP4TrackId MP4AddVideoTrack(
uint16_t height,
uint8_t videoType DEFAULT(MP4_MPEG4_VIDEO_TYPE) );

MP4V2_EXPORT
MP4TrackId MP4AddTSC2VideoTrack(
MP4FileHandle hFile,
uint32_t timeScale,
MP4Duration sampleDuration,
uint16_t width,
uint16_t height );

MP4V2_EXPORT
MP4TrackId MP4AddH264VideoTrack(
MP4FileHandle hFile,
Expand Down
10 changes: 10 additions & 0 deletions include/mp4v2/track_prop.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ bool MP4HaveTrackAtom(
MP4TrackId trackId,
const char* atomname );


MP4V2_EXPORT
bool MP4GetTrackAtomData (
MP4FileHandle hFile,
MP4TrackId trackId,
const char *atomName,
uint8_t ** outAtomData,
uint64_t * outDataSize);


/** Get the track type.
*
* MP4GetTrackType gets the type of the track with the specified track id.
Expand Down
18 changes: 17 additions & 1 deletion libplatform/io/File.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ File::open( std::string name_, Mode mode_ )
if( _provider.open( _name, _mode ))
return true;

FileSystem::getFileSize( _name, _size );
_size = _provider.getSize();
//FileSystem::getFileSize( _name, _size );

_isOpen = true;
return false;
Expand Down Expand Up @@ -129,6 +130,13 @@ File::close()
return false;
}

int64_t File::getSize()
{
int64_t retSize = 0;
FileSystem::getFileSize( _name, retSize );
return retSize;
}

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

CustomFileProvider::CustomFileProvider( const MP4FileProvider& provider )
Expand All @@ -140,6 +148,7 @@ CustomFileProvider::CustomFileProvider( const MP4FileProvider& provider )
bool
CustomFileProvider::open( std::string name, Mode mode )
{
fprintf(stderr, "CustomFileProvider::open()\n");
MP4FileMode fm;
switch( mode ) {
case MODE_READ: fm = FILEMODE_READ; break;
Expand Down Expand Up @@ -180,6 +189,13 @@ CustomFileProvider::close()
return _call.close( _handle );
}

int64_t CustomFileProvider::getSize()
{
fprintf(stderr, "CustomFileProvider::getSize()\n");
assert( _call.size );
return _call.size( _handle );
}

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

}}} // namespace mp4v2::platform::io
5 changes: 5 additions & 0 deletions libplatform/io/File.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class MP4V2_EXPORT FileProvider
virtual bool write( const void* buffer, Size size, Size& nout, Size maxChunkSize ) = 0;
virtual bool close() = 0;

virtual int64_t getSize() = 0;
protected:
FileProvider() { }
};
Expand Down Expand Up @@ -163,6 +164,9 @@ class MP4V2_EXPORT File : public FileProvider

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

int64_t getSize();


private:
std::string _name;
bool _isOpen;
Expand Down Expand Up @@ -196,6 +200,7 @@ class CustomFileProvider : public FileProvider
bool write( const void* buffer, Size size, Size& nout, Size maxChunkSize );
bool close();

int64_t getSize();
private:
MP4FileProvider _call;
void* _handle;
Expand Down
11 changes: 11 additions & 0 deletions libplatform/io/File_posix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ class StandardFileProvider : public FileProvider
bool write( const void* buffer, Size size, Size& nout, Size maxChunkSize );
bool close();

int64_t getSize();

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

///////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -56,6 +59,7 @@ StandardFileProvider::open( std::string name, Mode mode )
}

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

Expand Down Expand Up @@ -96,6 +100,13 @@ StandardFileProvider::close()
return _fstream.fail();
}

int64_t StandardFileProvider::getSize()
{
int64_t retSize = 0;
FileSystem::getFileSize( _name, retSize );
return retSize;
}

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

FileProvider&
Expand Down
51 changes: 51 additions & 0 deletions src/atom_mp4v.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,57 @@ void MP4Mp4vAtom::Generate()
m_pProperties[7]->SetReadOnly(true);
}

///////////////////////////////////////////////////////////////////////////////
MP4Tsc2Atom::MP4Tsc2Atom(MP4File &file)
: MP4Atom(file, "tsc2")
{
AddReserved(*this, "reserved1", 6);
AddProperty(new MP4Integer16Property(*this, "dataReferenceIndex"));
AddReserved(*this, "reserved2", 16);
AddProperty(new MP4Integer16Property(*this, "width"));
AddProperty(new MP4Integer16Property(*this, "height"));
AddReserved(*this, "reserved3", 14);

MP4StringProperty* pProp = new MP4StringProperty(*this, "compressorName");
pProp->SetFixedLength(32);
pProp->SetCountedFormat(true);
// pProp->SetValue("TSC2 Codec");
AddProperty(pProp);
AddReserved(*this, "reserved4", 4); /* 7 */

ExpectChildAtom("colr", Optional, OnlyOne);
ExpectChildAtom("esds", Required, OnlyOne);
ExpectChildAtom("pasp", Optional, OnlyOne);
}

void MP4Tsc2Atom::Generate()
{
MP4Atom::Generate();

((MP4Integer16Property*)m_pProperties[1])->SetValue(1);

// property reserved3 has non-zero fixed values
static uint8_t reserved3[14] = {
0x00, 0x48, 0x00, 0x00,
0x00, 0x48, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x01,
};
m_pProperties[5]->SetReadOnly(false);
((MP4BytesProperty*)m_pProperties[5])->
SetValue(reserved3, sizeof(reserved3));
m_pProperties[5]->SetReadOnly(true);

// property reserved4 has non-zero fixed values
static uint8_t reserved4[4] = {
0x00, 0x18, 0xFF, 0xFF,
};
m_pProperties[7]->SetReadOnly(false);
((MP4BytesProperty*)m_pProperties[7])->
SetValue(reserved4, sizeof(reserved4));
m_pProperties[7]->SetReadOnly(true);
}

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

}
Expand Down
10 changes: 10 additions & 0 deletions src/atoms.h
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,16 @@ class MP4Mp4vAtom : public MP4Atom {
MP4Mp4vAtom &operator= ( const MP4Mp4vAtom &src );
};

class MP4Tsc2Atom : public MP4Atom {
public:
MP4Tsc2Atom(MP4File &file);
void Generate();
private:
MP4Tsc2Atom();
MP4Tsc2Atom( const MP4Tsc2Atom &src );
MP4Tsc2Atom &operator= ( const MP4Tsc2Atom &src );
};


class MP4S263Atom : public MP4Atom {
public:
Expand Down
66 changes: 66 additions & 0 deletions src/mp4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1108,6 +1108,34 @@ MP4FileHandle MP4ReadProvider( const char* fileName, const MP4FileProvider* file
return MP4_INVALID_TRACK_ID;
}

MP4TrackId MP4AddTSC2VideoTrack(
MP4FileHandle hFile,
uint32_t timeScale,
MP4Duration sampleDuration,
uint16_t width,
uint16_t height)
{
if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
try {
MP4File *pFile = (MP4File *)hFile;

return pFile->AddTSC2VideoTrack(timeScale,
sampleDuration,
width,
height);
}
catch( Exception* x ) {
mp4v2::impl::log.errorf(*x);
delete x;
}
catch( ... ) {
mp4v2::impl::log.errorf( "%s: failed", __FUNCTION__ );
}
}
return MP4_INVALID_TRACK_ID;
}


MP4TrackId MP4AddEncVideoTrack(MP4FileHandle hFile,
uint32_t timeScale,
MP4Duration sampleDuration,
Expand Down Expand Up @@ -2721,6 +2749,22 @@ MP4FileHandle MP4ReadProvider( const char* fileName, const MP4FileProvider* file
return false;
}

bool MP4GetTrackAtomData (MP4FileHandle hFile, MP4TrackId trackId, const char *atomName, uint8_t ** outAtomData, uint64_t * outDataSize)
{
if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
try {
return ((MP4File *)hFile)->GetTrackAtomData(trackId, atomName, outAtomData, outDataSize);
} catch( Exception* x ) {
mp4v2::impl::log.errorf(*x);
delete x;
}
catch( ... ) {
mp4v2::impl::log.errorf( "%s: failed", __FUNCTION__ );
}
}
return false;
}

bool MP4GetTrackIntegerProperty (
MP4FileHandle hFile, MP4TrackId trackId,
const char* propName,
Expand Down Expand Up @@ -3138,6 +3182,28 @@ MP4FileHandle MP4ReadProvider( const char* fileName, const MP4FileProvider* file
return 0;
}

uint64_t MP4GetSampleFileOffset(
MP4FileHandle hFile,
MP4TrackId trackId,
MP4SampleId sampleId )
{
if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
try {
return ((MP4File*)hFile)->GetSampleFileOffset(
trackId, sampleId);
}
catch( Exception* x ) {
mp4v2::impl::log.errorf(*x);
delete x;
}
catch( ... ) {
mp4v2::impl::log.errorf( "%s: failed", __FUNCTION__ );
}
}
return 0;
}


uint32_t MP4GetTrackMaxSampleSize(
MP4FileHandle hFile,
MP4TrackId trackId)
Expand Down
5 changes: 5 additions & 0 deletions src/mp4atom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -979,6 +979,11 @@ MP4Atom::factory( MP4File &file, MP4Atom* parent, const char* type )
return new MP4TfhdAtom(file);
if( ATOMID(type) == ATOMID("trun") )
return new MP4TrunAtom(file);

if( ATOMID(type) == ATOMID("tsc2") )
return new MP4Tsc2Atom(file);


if( ATOMID(type) == ATOMID("twos") )
return new MP4SoundAtom( file, type );
break;
Expand Down
Loading

0 comments on commit 0b270e6

Please sign in to comment.