From: Steve Lhomme Date: Fri, 19 Mar 2010 15:35:26 +0000 (+0000) Subject: introduce filepos_t for all the file position values (depends wether the system can... X-Git-Tag: release-0.9.0~42 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c805d4e4b95f27600a8e5e90e45bcbcba5547e9d;p=libmatroska introduce filepos_t for all the file position values (depends wether the system can handle 32 bits or 64 bits offsets) git-svn-id: https://matroska.svn.sourceforge.net/svnroot/matroska/trunk/libmatroska@44 a6f86f6d-0131-4f8e-9e7b-e335508773d5 --- diff --git a/matroska/FileKax.h b/matroska/FileKax.h index 3d60d07..9c15430 100644 --- a/matroska/FileKax.h +++ b/matroska/FileKax.h @@ -63,7 +63,7 @@ class MATROSKA_DLL_API FileMatroska { FileMatroska(IOCallback & output); ~FileMatroska(); #ifdef OLD - uint32 RenderHead(const std::string & aEncoderApp); + filepos_t RenderHead(const std::string & aEncoderApp); uint32 ReadHead(); uint32 ReadTracks(); uint32 ReadCodec(); diff --git a/matroska/KaxBlock.h b/matroska/KaxBlock.h index d11ed7b..fb1064f 100644 --- a/matroska/KaxBlock.h +++ b/matroska/KaxBlock.h @@ -209,8 +209,8 @@ class KaxInternalBlock : public EbmlBinary { /*! \note override this function to generate the Data/Size on the fly, unlike the usual binary elements */ - uint64 UpdateSize(bool bSaveDefault = false, bool bForceRender = false); - uint64 ReadData(IOCallback & input, ScopeMode ReadFully = SCOPE_ALL_DATA); + filepos_t UpdateSize(bool bSaveDefault = false, bool bForceRender = false); + filepos_t ReadData(IOCallback & input, ScopeMode ReadFully = SCOPE_ALL_DATA); /*! \brief Only read the head of the Block (not internal data) @@ -264,7 +264,7 @@ class KaxInternalBlock : public EbmlBinary { bool mInvisible; uint64 FirstFrameLocation; - uint32 RenderData(IOCallback & output, bool bForceRender, bool bSaveDefault = false); + filepos_t RenderData(IOCallback & output, bool bForceRender, bool bSaveDefault = false); KaxCluster * ParentCluster; bool bIsSimple; @@ -360,7 +360,7 @@ class MATROSKA_DLL_API KaxBlockVirtual : public EbmlBinary { /*! \note override this function to generate the Data/Size on the fly, unlike the usual binary elements */ - uint64 UpdateSize(bool bSaveDefault = false, bool bForceRender = false); + filepos_t UpdateSize(bool bSaveDefault = false, bool bForceRender = false); void SetParent(const KaxCluster & aParentCluster) {ParentCluster = &aParentCluster;} diff --git a/matroska/KaxBlockData.h b/matroska/KaxBlockData.h index 38a5706..00dde60 100644 --- a/matroska/KaxBlockData.h +++ b/matroska/KaxBlockData.h @@ -65,7 +65,7 @@ class MATROSKA_DLL_API KaxReferenceBlock : public EbmlSInteger { /*! \brief override this method to compute the timecode value */ - virtual uint64 UpdateSize(bool bSaveDefault = false, bool bForceRender = false); + virtual filepos_t UpdateSize(bool bSaveDefault = false, bool bForceRender = false); const KaxBlockBlob & RefBlock() const; void SetReferencedBlock(const KaxBlockBlob * aRefdBlock); diff --git a/matroska/KaxCluster.h b/matroska/KaxCluster.h index edd62af..80d86d2 100644 --- a/matroska/KaxCluster.h +++ b/matroska/KaxCluster.h @@ -76,7 +76,7 @@ class MATROSKA_DLL_API KaxCluster : public EbmlMaster { /*! \brief Render the data to the stream and retrieve the position of BlockGroups for later cue entries */ - uint32 Render(IOCallback & output, KaxCues & CueToUpdate, bool bSaveDefault = false); + filepos_t Render(IOCallback & output, KaxCues & CueToUpdate, bool bSaveDefault = false); /*! \return the global timecode of this Cluster diff --git a/matroska/KaxCues.h b/matroska/KaxCues.h index fe7459f..0de85e0 100644 --- a/matroska/KaxCues.h +++ b/matroska/KaxCues.h @@ -65,7 +65,7 @@ class MATROSKA_DLL_API KaxCues : public EbmlMaster { /*! \brief override to sort by timecode/track */ - uint32 Render(IOCallback & output, bool bSaveDefault = false) { + filepos_t Render(IOCallback & output, bool bSaveDefault = false) { Sort(); return EbmlMaster::Render(output, bSaveDefault); } diff --git a/matroska/KaxTrackVideo.h b/matroska/KaxTrackVideo.h index 9d5edb8..55d5923 100644 --- a/matroska/KaxTrackVideo.h +++ b/matroska/KaxTrackVideo.h @@ -176,7 +176,7 @@ class MATROSKA_DLL_API KaxVideoFrameRate : public EbmlFloat { public: KaxVideoFrameRate() {} KaxVideoFrameRate(const KaxVideoFrameRate & ElementToClone) :EbmlFloat(ElementToClone) {} - uint32 RenderData(IOCallback & output, bool bForceRender, bool bSaveDefault); + filepos_t RenderData(IOCallback & output, bool bForceRender, bool bSaveDefault); EBML_CONCRETE_CLASS(KaxVideoFrameRate) }; diff --git a/src/FileKax.cpp b/src/FileKax.cpp index 392886b..c366288 100644 --- a/src/FileKax.cpp +++ b/src/FileKax.cpp @@ -1,449 +1,449 @@ -/**************************************************************************** -** libmatroska : parse Matroska files, see http://www.matroska.org/ -** -** -** -** Copyright (C) 2002-2003 Steve Lhomme. All rights reserved. -** -** This file is part of libmatroska. -** -** This library is free software; you can redistribute it and/or -** modify it under the terms of the GNU Lesser General Public -** License as published by the Free Software Foundation; either -** version 2.1 of the License, or (at your option) any later version. -** -** This library is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -** Lesser General Public License for more details. -** -** You should have received a copy of the GNU Lesser General Public -** License along with this library; if not, write to the Free Software -** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -** -** See http://www.matroska.org/license/lgpl/ for LGPL licensing information.** -** Contact license@matroska.org if any conditions of this licensing are -** not clear to you. -** -**********************************************************************/ - -/*! - \file - \version \$Id: FileKax.cpp 640 2004-07-09 21:05:36Z mosu $ - \author Steve Lhomme -*/ -//#include "StdInclude.h" -#include "matroska/FileKax.h" -//#include "Cluster.h" -//#include "Track.h" -//#include "Block.h" -//#include "Frame.h" -//#include "Version.h" - -START_LIBMATROSKA_NAMESPACE - -//typedef Track *TrackID; - -FileMatroska::FileMatroska(IOCallback & output) - :myFile(output) -#ifdef OLD - ,myCurrReadBlock(NULL) - ,myMinClusterSize(5*1024) // 5KB is the min size of a cluster - ,myMaxClusterSize(2*1024*1024) // 2MB is the max size of a cluster - ,myCurrReadBlockTrack(0) - ,myCurrWriteCluster(2*1024*1024) // myMaxClusterSize - ,myCurrReadCluster(NULL) - ,myReadBlockNumber(0) -#endif // OLD -{ -#ifdef OLD - myStreamInfo.MainHeaderSize = TypeHeader::default_size() + - ActualHeader::default_size() + - ExtendedInfo::default_size() + - ContentInfo::default_size(); - myStreamInfo.TrackEntrySize = Track::default_size(); - myStreamInfo.BlockHeadSize = BLOCK_HEADER_SIZE; - myStreamInfo.ClusterHeadSize = CLUSTER_HEADER_SIZE; - myStreamInfo.ClusterFootSize = CLUSTER_TRAILER_SIZE; -#endif // OLD -} - -FileMatroska::~FileMatroska() -{ -// if (myCurrCluster != NULL) -// throw 0; // there are some data left to write -// if (myCurrReadCluster != NULL || myCurrReadBlock != NULL) -// throw 0; // there are some data left to write -} - -#ifdef OLD -void FileMatroska::SetMaxClusterSize(const uint32 value) -{ - myMaxClusterSize = value; - myCurrWriteCluster.setMaxSize(value); -} - -void FileMatroska::Close(const uint32 aTimeLength) -{ - Flush(); - - // get the file size - myFile.setFilePointer(0,seek_end); - myMainHeader.type_SetSize(myFile.getFilePointer()); - - // rewrite the header at the beginning - myFile.setFilePointer(0,seek_beginning); - - // get the Track-entry size - uint32 track_entries_size = 0; - for (size_t i=0; idefault_size(); - } - - myStreamInfo.TrackEntriesSize = track_entries_size; - myStreamInfo.TimeLength = aTimeLength; - myMainHeader.Render(myFile, myStreamInfo); - - for (i=0; idefault_size(); - } - - std::string aStr = LIB_NAME; - aStr += " "; - aStr += VERSION; - myStreamInfo.EncoderLib = aStr; - - myStreamInfo.EncoderApp = aEncoderApp; - - myStreamInfo.TrackEntryPosition = 0 + myStreamInfo.MainHeaderSize; - myStreamInfo.TrackEntriesSize = myTracks.size() * myStreamInfo.TrackEntrySize; - - myStreamInfo.CodecEntryPosition = myStreamInfo.MainHeaderSize + myStreamInfo.TrackEntriesSize; - myStreamInfo.CodecEntrySize = 4; - for (i=0; iCodecSize(); - } - - // Main Header - uint32 result = myMainHeader.Render(myFile, myStreamInfo); - - // Track Entries - for (i=0; iRenderEntry(myFile, i+1); - } - myStreamInfo.ClusterPosition = myStreamInfo.CodecEntryPosition + myStreamInfo.CodecEntrySize; - - // Codec Header - result = CodecHeader::Render(myFile, myTracks); - - return result; - } - catch (exception & Ex) - { - throw Ex; - } -} - -/*! - \return 0 if the track was not created, or a valid track number -*/ -Track * FileMatroska::CreateTrack(const track_type aType) -{ - myTracks.push_back(new Track(aType)); - return myTracks.back(); -} - -/*Track *FileMatroska::findTrack(Track * aTrack) const -{ - for (size_t i=0; iSetName(aName); - } -} - -void FileMatroska::track_SetLaced(Track * aTrack, bool bLaced) -{ - if (IsMyTrack(aTrack)) - { - aTrack->SetLaced(bLaced); - } -} - -bool FileMatroska::AddFrame(Track * aTrack, const uint32 aTimecode, const binary *aFrame, const uint32 aFrameSize, - bool aKeyFrame, bool aBFrame) -{ - try { - // make sure we know that track - if (IsMyTrack(aTrack)) - { - // pass the cluster to the track - // handle the creation of a new cluster if needed - if (aTrack->AddFrame(aTimecode, aFrame, aFrameSize, aKeyFrame, aBFrame)) - { - while (!aTrack->SerialiseBlock(myCurrWriteCluster)) - { - /// \todo handle errors - uint32 aNbBlock; - myStreamInfo.ClusterSize += myCurrWriteCluster.Render(myFile, aNbBlock); - myStreamInfo.NumberBlock += aNbBlock; - myCurrWriteCluster.Flush(); - } - } - return true; - } - return false; - } - catch (exception & Ex) - { - throw Ex; - } -} - -void FileMatroska::Flush() -{ - uint32 aNbBlock; - myStreamInfo.ClusterSize += myCurrWriteCluster.Render(myFile,aNbBlock); - myStreamInfo.NumberBlock += aNbBlock; -} - -uint32 FileMatroska::ReadHead() -{ - try { - uint32 result = myMainHeader.Read(myFile, myStreamInfo); - - return result; - } - catch (exception & Ex) - { - throw Ex; - } -} - -uint32 FileMatroska::ReadTracks() -{ - try { - uint32 result = 0; - - // seek to the start of the Track Entries - myFile.setFilePointer(myStreamInfo.TrackEntryPosition); - // get the number of Track Entries - uint8 TrackNumber = myStreamInfo.TrackEntriesSize / myStreamInfo.TrackEntrySize; - // read all the Track Entries - myTracks.clear(); - for (uint8 TrackIdx = 0; TrackIdx::const_iterator i = myTracks.begin(); i != myTracks.end(); i ++) - { - if (*i == aTrack) - break; - } - - if (i != myTracks.end()) - return true; - else - return false; -} - -void FileMatroska::SelectReadingTrack(Track * aTrack, bool select) -{ - if (IsMyTrack(aTrack)) - { - // here we have the right track - // check if it's not already selected - for (std::vector::iterator j = mySelectedTracks.begin(); - j != mySelectedTracks.end(); j ++) - { - if (*j == aTrack->TrackNumber()) - break; - } - - if (select && j == mySelectedTracks.end()) - mySelectedTracks.push_back(aTrack->TrackNumber()); - else if (!select && j != mySelectedTracks.end()) - mySelectedTracks.erase(j); - - std::sort(mySelectedTracks.begin(), mySelectedTracks.end()); - } -} - -inline bool FileMatroska::IsReadingTrack(const uint8 aTrackNumber) const -{ - for (std::vector::const_iterator trackIdx = mySelectedTracks.begin(); - trackIdx != mySelectedTracks.end() && *trackIdx < aTrackNumber; - trackIdx++) - {} - - if (trackIdx == mySelectedTracks.end()) - return false; - else - return true; -} - -// - -void FileMatroska::Track_GetInfo(const Track * aTrack, TrackInfo & aTrackInfo) const -{ - if (IsMyTrack(aTrack)) - { - aTrack->GetInfo(aTrackInfo); - } -} - -// Audio related getters/setters - -void FileMatroska::Track_GetInfo_Audio(const Track * aTrack, TrackInfoAudio & aTrackInfo) const -{ - if (IsMyTrack(aTrack)) - { - aTrack->GetInfoAudio(aTrackInfo); - } -} - -void FileMatroska::Track_SetInfo_Audio(Track * aTrack, const TrackInfoAudio & aTrackInfo) -{ - if (IsMyTrack(aTrack)) - { - aTrack->SetInfoAudio(aTrackInfo); - } -} - -// Video related getters/setters - -void FileMatroska::Track_GetInfo_Video(const Track * aTrack, TrackInfoVideo & aTrackInfo) const -{ - if (IsMyTrack(aTrack)) - { - aTrack->GetInfoVideo(aTrackInfo); - } -} - -void FileMatroska::Track_SetInfo_Video(Track * aTrack, const TrackInfoVideo & aTrackInfo) -{ - if (IsMyTrack(aTrack)) - { - aTrack->SetInfoVideo(aTrackInfo); - } -} - -/*! - \todo exit when there is no Block left -*/ -bool FileMatroska::ReadFrame(Track * & aTrack, uint32 & aTimecode, const binary * & aFrame, uint32 & aFrameSize, - bool & aKeyFrame, bool & aBFrame) -{ - if (myCurrReadBlockTrack == 0) - { - do { - if (myReadBlockNumber >= myStreamInfo.NumberBlock) - { -// myReadBlockNumber = myStreamInfo.NumberBlock; - return false; - } - - // get the next frame in the file - if (!myCurrReadCluster.BlockLeft()) - { - myCurrReadCluster.Flush(); - try { - myCurrReadCluster.FindHead(myFile); - } - catch (exception & Ex) - { - return false; - } - } - - myCurrReadCluster.GetBlock( myCurrReadBlock, myCurrReadBlockSize, myCurrReadBlockTrack ); - myReadBlockNumber++; - } while (!IsReadingTrack(myCurrReadBlockTrack)); - - // get the track associated (normally from myTracks) - aTrack = myTracks[myCurrReadBlockTrack-1]; - // get the next frame from the current block - aTrack->HandleBlock(myCurrReadBlock, myCurrReadBlockSize); - } - else - { - // get the track associated (normally from myTracks) - aTrack = myTracks[myCurrReadBlockTrack-1]; - } - - Frame * myReadFrame; - aTrack->GetNextFrame(aTimecode, myReadFrame, aKeyFrame, aBFrame); - aFrame = myReadFrame->buf(); - aFrameSize = myReadFrame->length(); - - if (aTrack->NoFrameLeft()) - { - aTrack->FlushBlock(); - myCurrReadBlockTrack = 0; - } - - return true; -} -#endif // OLD - -END_LIBMATROSKA_NAMESPACE +/**************************************************************************** +** libmatroska : parse Matroska files, see http://www.matroska.org/ +** +** +** +** Copyright (C) 2002-2003 Steve Lhomme. All rights reserved. +** +** This file is part of libmatroska. +** +** This library is free software; you can redistribute it and/or +** modify it under the terms of the GNU Lesser General Public +** License as published by the Free Software Foundation; either +** version 2.1 of the License, or (at your option) any later version. +** +** This library is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** Lesser General Public License for more details. +** +** You should have received a copy of the GNU Lesser General Public +** License along with this library; if not, write to the Free Software +** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +** +** See http://www.matroska.org/license/lgpl/ for LGPL licensing information.** +** Contact license@matroska.org if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ + +/*! + \file + \version \$Id: FileKax.cpp 640 2004-07-09 21:05:36Z mosu $ + \author Steve Lhomme +*/ +//#include "StdInclude.h" +#include "matroska/FileKax.h" +//#include "Cluster.h" +//#include "Track.h" +//#include "Block.h" +//#include "Frame.h" +//#include "Version.h" + +START_LIBMATROSKA_NAMESPACE + +//typedef Track *TrackID; + +FileMatroska::FileMatroska(IOCallback & output) + :myFile(output) +#ifdef OLD + ,myCurrReadBlock(NULL) + ,myMinClusterSize(5*1024) // 5KB is the min size of a cluster + ,myMaxClusterSize(2*1024*1024) // 2MB is the max size of a cluster + ,myCurrReadBlockTrack(0) + ,myCurrWriteCluster(2*1024*1024) // myMaxClusterSize + ,myCurrReadCluster(NULL) + ,myReadBlockNumber(0) +#endif // OLD +{ +#ifdef OLD + myStreamInfo.MainHeaderSize = TypeHeader::default_size() + + ActualHeader::default_size() + + ExtendedInfo::default_size() + + ContentInfo::default_size(); + myStreamInfo.TrackEntrySize = Track::default_size(); + myStreamInfo.BlockHeadSize = BLOCK_HEADER_SIZE; + myStreamInfo.ClusterHeadSize = CLUSTER_HEADER_SIZE; + myStreamInfo.ClusterFootSize = CLUSTER_TRAILER_SIZE; +#endif // OLD +} + +FileMatroska::~FileMatroska() +{ +// if (myCurrCluster != NULL) +// throw 0; // there are some data left to write +// if (myCurrReadCluster != NULL || myCurrReadBlock != NULL) +// throw 0; // there are some data left to write +} + +#ifdef OLD +void FileMatroska::SetMaxClusterSize(const uint32 value) +{ + myMaxClusterSize = value; + myCurrWriteCluster.setMaxSize(value); +} + +void FileMatroska::Close(const uint32 aTimeLength) +{ + Flush(); + + // get the file size + myFile.setFilePointer(0,seek_end); + myMainHeader.type_SetSize(myFile.getFilePointer()); + + // rewrite the header at the beginning + myFile.setFilePointer(0,seek_beginning); + + // get the Track-entry size + uint32 track_entries_size = 0; + for (size_t i=0; idefault_size(); + } + + myStreamInfo.TrackEntriesSize = track_entries_size; + myStreamInfo.TimeLength = aTimeLength; + myMainHeader.Render(myFile, myStreamInfo); + + for (i=0; idefault_size(); + } + + std::string aStr = LIB_NAME; + aStr += " "; + aStr += VERSION; + myStreamInfo.EncoderLib = aStr; + + myStreamInfo.EncoderApp = aEncoderApp; + + myStreamInfo.TrackEntryPosition = 0 + myStreamInfo.MainHeaderSize; + myStreamInfo.TrackEntriesSize = myTracks.size() * myStreamInfo.TrackEntrySize; + + myStreamInfo.CodecEntryPosition = myStreamInfo.MainHeaderSize + myStreamInfo.TrackEntriesSize; + myStreamInfo.CodecEntrySize = 4; + for (i=0; iCodecSize(); + } + + // Main Header + filepos_t result = myMainHeader.Render(myFile, myStreamInfo); + + // Track Entries + for (i=0; iRenderEntry(myFile, i+1); + } + myStreamInfo.ClusterPosition = myStreamInfo.CodecEntryPosition + myStreamInfo.CodecEntrySize; + + // Codec Header + result = CodecHeader::Render(myFile, myTracks); + + return result; + } + catch (exception & Ex) + { + throw Ex; + } +} + +/*! + \return 0 if the track was not created, or a valid track number +*/ +Track * FileMatroska::CreateTrack(const track_type aType) +{ + myTracks.push_back(new Track(aType)); + return myTracks.back(); +} + +/*Track *FileMatroska::findTrack(Track * aTrack) const +{ + for (size_t i=0; iSetName(aName); + } +} + +void FileMatroska::track_SetLaced(Track * aTrack, bool bLaced) +{ + if (IsMyTrack(aTrack)) + { + aTrack->SetLaced(bLaced); + } +} + +bool FileMatroska::AddFrame(Track * aTrack, const uint32 aTimecode, const binary *aFrame, const uint32 aFrameSize, + bool aKeyFrame, bool aBFrame) +{ + try { + // make sure we know that track + if (IsMyTrack(aTrack)) + { + // pass the cluster to the track + // handle the creation of a new cluster if needed + if (aTrack->AddFrame(aTimecode, aFrame, aFrameSize, aKeyFrame, aBFrame)) + { + while (!aTrack->SerialiseBlock(myCurrWriteCluster)) + { + /// \todo handle errors + uint32 aNbBlock; + myStreamInfo.ClusterSize += myCurrWriteCluster.Render(myFile, aNbBlock); + myStreamInfo.NumberBlock += aNbBlock; + myCurrWriteCluster.Flush(); + } + } + return true; + } + return false; + } + catch (exception & Ex) + { + throw Ex; + } +} + +void FileMatroska::Flush() +{ + uint32 aNbBlock; + myStreamInfo.ClusterSize += myCurrWriteCluster.Render(myFile,aNbBlock); + myStreamInfo.NumberBlock += aNbBlock; +} + +uint32 FileMatroska::ReadHead() +{ + try { + uint32 result = myMainHeader.Read(myFile, myStreamInfo); + + return result; + } + catch (exception & Ex) + { + throw Ex; + } +} + +uint32 FileMatroska::ReadTracks() +{ + try { + uint32 result = 0; + + // seek to the start of the Track Entries + myFile.setFilePointer(myStreamInfo.TrackEntryPosition); + // get the number of Track Entries + uint8 TrackNumber = myStreamInfo.TrackEntriesSize / myStreamInfo.TrackEntrySize; + // read all the Track Entries + myTracks.clear(); + for (uint8 TrackIdx = 0; TrackIdx::const_iterator i = myTracks.begin(); i != myTracks.end(); i ++) + { + if (*i == aTrack) + break; + } + + if (i != myTracks.end()) + return true; + else + return false; +} + +void FileMatroska::SelectReadingTrack(Track * aTrack, bool select) +{ + if (IsMyTrack(aTrack)) + { + // here we have the right track + // check if it's not already selected + for (std::vector::iterator j = mySelectedTracks.begin(); + j != mySelectedTracks.end(); j ++) + { + if (*j == aTrack->TrackNumber()) + break; + } + + if (select && j == mySelectedTracks.end()) + mySelectedTracks.push_back(aTrack->TrackNumber()); + else if (!select && j != mySelectedTracks.end()) + mySelectedTracks.erase(j); + + std::sort(mySelectedTracks.begin(), mySelectedTracks.end()); + } +} + +inline bool FileMatroska::IsReadingTrack(const uint8 aTrackNumber) const +{ + for (std::vector::const_iterator trackIdx = mySelectedTracks.begin(); + trackIdx != mySelectedTracks.end() && *trackIdx < aTrackNumber; + trackIdx++) + {} + + if (trackIdx == mySelectedTracks.end()) + return false; + else + return true; +} + +// + +void FileMatroska::Track_GetInfo(const Track * aTrack, TrackInfo & aTrackInfo) const +{ + if (IsMyTrack(aTrack)) + { + aTrack->GetInfo(aTrackInfo); + } +} + +// Audio related getters/setters + +void FileMatroska::Track_GetInfo_Audio(const Track * aTrack, TrackInfoAudio & aTrackInfo) const +{ + if (IsMyTrack(aTrack)) + { + aTrack->GetInfoAudio(aTrackInfo); + } +} + +void FileMatroska::Track_SetInfo_Audio(Track * aTrack, const TrackInfoAudio & aTrackInfo) +{ + if (IsMyTrack(aTrack)) + { + aTrack->SetInfoAudio(aTrackInfo); + } +} + +// Video related getters/setters + +void FileMatroska::Track_GetInfo_Video(const Track * aTrack, TrackInfoVideo & aTrackInfo) const +{ + if (IsMyTrack(aTrack)) + { + aTrack->GetInfoVideo(aTrackInfo); + } +} + +void FileMatroska::Track_SetInfo_Video(Track * aTrack, const TrackInfoVideo & aTrackInfo) +{ + if (IsMyTrack(aTrack)) + { + aTrack->SetInfoVideo(aTrackInfo); + } +} + +/*! + \todo exit when there is no Block left +*/ +bool FileMatroska::ReadFrame(Track * & aTrack, uint32 & aTimecode, const binary * & aFrame, uint32 & aFrameSize, + bool & aKeyFrame, bool & aBFrame) +{ + if (myCurrReadBlockTrack == 0) + { + do { + if (myReadBlockNumber >= myStreamInfo.NumberBlock) + { +// myReadBlockNumber = myStreamInfo.NumberBlock; + return false; + } + + // get the next frame in the file + if (!myCurrReadCluster.BlockLeft()) + { + myCurrReadCluster.Flush(); + try { + myCurrReadCluster.FindHead(myFile); + } + catch (exception & Ex) + { + return false; + } + } + + myCurrReadCluster.GetBlock( myCurrReadBlock, myCurrReadBlockSize, myCurrReadBlockTrack ); + myReadBlockNumber++; + } while (!IsReadingTrack(myCurrReadBlockTrack)); + + // get the track associated (normally from myTracks) + aTrack = myTracks[myCurrReadBlockTrack-1]; + // get the next frame from the current block + aTrack->HandleBlock(myCurrReadBlock, myCurrReadBlockSize); + } + else + { + // get the track associated (normally from myTracks) + aTrack = myTracks[myCurrReadBlockTrack-1]; + } + + Frame * myReadFrame; + aTrack->GetNextFrame(aTimecode, myReadFrame, aKeyFrame, aBFrame); + aFrame = myReadFrame->buf(); + aFrameSize = myReadFrame->length(); + + if (aTrack->NoFrameLeft()) + { + aTrack->FlushBlock(); + myCurrReadBlockTrack = 0; + } + + return true; +} +#endif // OLD + +END_LIBMATROSKA_NAMESPACE diff --git a/src/KaxBlock.cpp b/src/KaxBlock.cpp index 19543aa..2965218 100644 --- a/src/KaxBlock.cpp +++ b/src/KaxBlock.cpp @@ -239,7 +239,7 @@ LacingType KaxInternalBlock::GetBestLacingType() const { return LACING_EBML; } -uint64 KaxInternalBlock::UpdateSize(bool bSaveDefault, bool bForceRender) +filepos_t KaxInternalBlock::UpdateSize(bool bSaveDefault, bool bForceRender) { LacingType LacingHere; assert(EbmlBinary::GetBuffer() == NULL); // Data is not used for KaxInternalBlock @@ -303,7 +303,7 @@ KaxBlockVirtual::KaxBlockVirtual(const KaxBlockVirtual & ElementToClone) SetValueIsSet(false); } -uint64 KaxBlockVirtual::UpdateSize(bool bSaveDefault, bool bForceRender) +filepos_t KaxBlockVirtual::UpdateSize(bool bSaveDefault, bool bForceRender) { assert(TrackNumber < 0x4000); binary *cursor = EbmlBinary::GetBuffer(); @@ -331,7 +331,7 @@ uint64 KaxBlockVirtual::UpdateSize(bool bSaveDefault, bool bForceRender) \todo more optimisation is possible (render the Block head and don't copy the buffer in memory, care should be taken with the allocation of Data) \todo the actual timecode to write should be retrieved from the Cluster from here */ -uint32 KaxInternalBlock::RenderData(IOCallback & output, bool bForceRender, bool bSaveDefault) +filepos_t KaxInternalBlock::RenderData(IOCallback & output, bool bForceRender, bool bSaveDefault) { if (myBuffers.size() == 0) { return 0; @@ -510,9 +510,9 @@ uint64 KaxInternalBlock::ReadInternalHead(IOCallback & input) /*! \todo better zero copy handling */ -uint64 KaxInternalBlock::ReadData(IOCallback & input, ScopeMode ReadFully) +filepos_t KaxInternalBlock::ReadData(IOCallback & input, ScopeMode ReadFully) { - uint64 Result; + filepos_t Result; FirstFrameLocation = input.getFilePointer(); // will be updated accordingly below diff --git a/src/KaxBlockData.cpp b/src/KaxBlockData.cpp index 31533b8..1dd6da4 100644 --- a/src/KaxBlockData.cpp +++ b/src/KaxBlockData.cpp @@ -107,7 +107,7 @@ const KaxBlockBlob & KaxReferenceBlock::RefBlock() const return *RefdBlock; } -uint64 KaxReferenceBlock::UpdateSize(bool bSaveDefault, bool bForceRender) +filepos_t KaxReferenceBlock::UpdateSize(bool bSaveDefault, bool bForceRender) { if (!bTimecodeSet) { assert(RefdBlock != NULL); diff --git a/src/KaxCluster.cpp b/src/KaxCluster.cpp index c110b09..adadf53 100644 --- a/src/KaxCluster.cpp +++ b/src/KaxCluster.cpp @@ -172,9 +172,9 @@ bool KaxCluster::AddFrame(const KaxTrackEntry & track, uint64 timecode, DataBuff /*! \todo only put the Blocks written in the cue entries */ -uint32 KaxCluster::Render(IOCallback & output, KaxCues & CueToUpdate, bool bSaveDefault) +filepos_t KaxCluster::Render(IOCallback & output, KaxCues & CueToUpdate, bool bSaveDefault) { - uint32 Result = 0; + filepos_t Result = 0; size_t TrkIndex, Index; // update the Timecode of the Cluster before writing diff --git a/src/KaxTrackVideo.cpp b/src/KaxTrackVideo.cpp index 89dd977..077e627 100644 --- a/src/KaxTrackVideo.cpp +++ b/src/KaxTrackVideo.cpp @@ -125,7 +125,7 @@ KaxTrackVideo::KaxTrackVideo() :EbmlMaster(KaxTrackVideo_Context) {} -uint32 KaxVideoFrameRate::RenderData(IOCallback & output, bool bForceRender, bool bSaveDefault) +filepos_t KaxVideoFrameRate::RenderData(IOCallback & output, bool bForceRender, bool bSaveDefault) { assert(false); // no you are not allowed to use this element ! return 0;