From: Steve Lhomme Date: Fri, 30 Apr 2010 08:28:24 +0000 (+0000) Subject: v1/v2: Add support for const iterators where necessary X-Git-Tag: release-0.9.0~5 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=dfed1be31e0fddcc26bf43357db32478daa044e9;p=libmatroska v1/v2: Add support for const iterators where necessary git-svn-id: https://matroska.svn.sourceforge.net/svnroot/matroska/trunk/libmatroska@149 a6f86f6d-0131-4f8e-9e7b-e335508773d5 --- diff --git a/src/KaxCues.cpp b/src/KaxCues.cpp index dc588b6..9fd123b 100644 --- a/src/KaxCues.cpp +++ b/src/KaxCues.cpp @@ -1,166 +1,166 @@ -/**************************************************************************** -** libmatroska : parse Matroska files, see http://www.matroska.org/ -** -** -** -** Copyright (C) 2002-2010 Steve Lhomme. All rights reserved. -** -** 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: KaxCues.cpp 1265 2007-01-14 17:20:35Z mosu $ - \author Steve Lhomme -*/ -#include - -#include "matroska/KaxCues.h" -#include "matroska/KaxCuesData.h" -#include "matroska/KaxContexts.h" -#include "ebml/EbmlStream.h" -#include "matroska/KaxDefines.h" - -// sub elements -START_LIBMATROSKA_NAMESPACE - -DEFINE_START_SEMANTIC(KaxCues) -DEFINE_SEMANTIC_ITEM(true, false, KaxCuePoint) -DEFINE_END_SEMANTIC(KaxCues) - -DEFINE_MKX_MASTER(KaxCues, 0x1C53BB6B, 4, KaxSegment, "Cues"); - -KaxCues::~KaxCues() -{ - assert(myTempReferences.size() == 0); // otherwise that means you have added references and forgot to set the position -} - -bool KaxCues::AddBlockGroup(const KaxBlockGroup & BlockRef) -{ - // Do not add the element if it's already present. - std::vector::iterator ListIdx; - KaxBlockBlob &BlockReference = *(new KaxBlockBlob(BLOCK_BLOB_NO_SIMPLE)); - BlockReference.SetBlockGroup(*const_cast(&BlockRef)); - - for (ListIdx = myTempReferences.begin(); ListIdx != myTempReferences.end(); ListIdx++) - if (*ListIdx == &BlockReference) - return true; - - myTempReferences.push_back(&BlockReference); - return true; -} - -bool KaxCues::AddBlockBlob(const KaxBlockBlob & BlockReference) -{ - // Do not add the element if it's already present. - std::vector::iterator ListIdx; - - for (ListIdx = myTempReferences.begin(); ListIdx != myTempReferences.end(); ListIdx++) - if (*ListIdx == &BlockReference) - return true; - - myTempReferences.push_back(&BlockReference); - return true; -} - -void KaxCues::PositionSet(const KaxBlockBlob & BlockReference) -{ - // look for the element in the temporary references - std::vector::iterator ListIdx; - - for (ListIdx = myTempReferences.begin(); ListIdx != myTempReferences.end(); ListIdx++) { - if (*ListIdx == &BlockReference) { - // found, now add the element to the entry list - KaxCuePoint & NewPoint = AddNewChild(*this); - NewPoint.PositionSet(BlockReference, GlobalTimecodeScale()); - myTempReferences.erase(ListIdx); - break; - } - } -} - -void KaxCues::PositionSet(const KaxBlockGroup & BlockRef) -{ - // look for the element in the temporary references - std::vector::iterator ListIdx; - - for (ListIdx = myTempReferences.begin(); ListIdx != myTempReferences.end(); ListIdx++) { - const KaxInternalBlock &refTmp = **ListIdx; - if (refTmp.GlobalTimecode() == BlockRef.GlobalTimecode() && - refTmp.TrackNum() == BlockRef.TrackNumber()) { - // found, now add the element to the entry list - KaxCuePoint & NewPoint = AddNewChild(*this); - NewPoint.PositionSet(**ListIdx, GlobalTimecodeScale()); - myTempReferences.erase(ListIdx); - break; - } - } -} - -/*! - \warning Assume that the list has been sorted (Sort()) -*/ -const KaxCuePoint * KaxCues::GetTimecodePoint(uint64 aTimecode) const -{ - uint64 TimecodeToLocate = aTimecode / GlobalTimecodeScale(); - const KaxCuePoint * aPointPrev = NULL; - uint64 aPrevTime = 0; - const KaxCuePoint * aPointNext = NULL; - uint64 aNextTime = EBML_PRETTYLONGINT(0xFFFFFFFFFFFF); - - EBML_MASTER_ITERATOR Itr; - for (Itr = begin(); Itr != end(); ++Itr) - { - if (EbmlId(*(*Itr)) == EBML_ID(KaxCuePoint)) { - const KaxCuePoint *tmp = static_cast(*Itr); - // check the tile - const KaxCueTime *aTime = static_cast(tmp->FindFirstElt(EBML_INFO(KaxCueTime))); - if (aTime != NULL) - { - uint64 _Time = uint64(*aTime); - if (_Time > aPrevTime && _Time < TimecodeToLocate) { - aPrevTime = _Time; - aPointPrev = tmp; - } - if (_Time < aNextTime && _Time > TimecodeToLocate) { - aNextTime= _Time; - aPointNext = tmp; - } - } - } - } - - return aPointPrev; -} - -uint64 KaxCues::GetTimecodePosition(uint64 aTimecode) const -{ - const KaxCuePoint * aPoint = GetTimecodePoint(aTimecode); - if (aPoint == NULL) - return 0; - - const KaxCueTrackPositions * aTrack = aPoint->GetSeekPosition(); - if (aTrack == NULL) - return 0; - - return aTrack->ClusterPosition(); -} - -END_LIBMATROSKA_NAMESPACE +/**************************************************************************** +** libmatroska : parse Matroska files, see http://www.matroska.org/ +** +** +** +** Copyright (C) 2002-2010 Steve Lhomme. All rights reserved. +** +** 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: KaxCues.cpp 1265 2007-01-14 17:20:35Z mosu $ + \author Steve Lhomme +*/ +#include + +#include "matroska/KaxCues.h" +#include "matroska/KaxCuesData.h" +#include "matroska/KaxContexts.h" +#include "ebml/EbmlStream.h" +#include "matroska/KaxDefines.h" + +// sub elements +START_LIBMATROSKA_NAMESPACE + +DEFINE_START_SEMANTIC(KaxCues) +DEFINE_SEMANTIC_ITEM(true, false, KaxCuePoint) +DEFINE_END_SEMANTIC(KaxCues) + +DEFINE_MKX_MASTER(KaxCues, 0x1C53BB6B, 4, KaxSegment, "Cues"); + +KaxCues::~KaxCues() +{ + assert(myTempReferences.size() == 0); // otherwise that means you have added references and forgot to set the position +} + +bool KaxCues::AddBlockGroup(const KaxBlockGroup & BlockRef) +{ + // Do not add the element if it's already present. + std::vector::iterator ListIdx; + KaxBlockBlob &BlockReference = *(new KaxBlockBlob(BLOCK_BLOB_NO_SIMPLE)); + BlockReference.SetBlockGroup(*const_cast(&BlockRef)); + + for (ListIdx = myTempReferences.begin(); ListIdx != myTempReferences.end(); ListIdx++) + if (*ListIdx == &BlockReference) + return true; + + myTempReferences.push_back(&BlockReference); + return true; +} + +bool KaxCues::AddBlockBlob(const KaxBlockBlob & BlockReference) +{ + // Do not add the element if it's already present. + std::vector::iterator ListIdx; + + for (ListIdx = myTempReferences.begin(); ListIdx != myTempReferences.end(); ListIdx++) + if (*ListIdx == &BlockReference) + return true; + + myTempReferences.push_back(&BlockReference); + return true; +} + +void KaxCues::PositionSet(const KaxBlockBlob & BlockReference) +{ + // look for the element in the temporary references + std::vector::iterator ListIdx; + + for (ListIdx = myTempReferences.begin(); ListIdx != myTempReferences.end(); ListIdx++) { + if (*ListIdx == &BlockReference) { + // found, now add the element to the entry list + KaxCuePoint & NewPoint = AddNewChild(*this); + NewPoint.PositionSet(BlockReference, GlobalTimecodeScale()); + myTempReferences.erase(ListIdx); + break; + } + } +} + +void KaxCues::PositionSet(const KaxBlockGroup & BlockRef) +{ + // look for the element in the temporary references + std::vector::iterator ListIdx; + + for (ListIdx = myTempReferences.begin(); ListIdx != myTempReferences.end(); ListIdx++) { + const KaxInternalBlock &refTmp = **ListIdx; + if (refTmp.GlobalTimecode() == BlockRef.GlobalTimecode() && + refTmp.TrackNum() == BlockRef.TrackNumber()) { + // found, now add the element to the entry list + KaxCuePoint & NewPoint = AddNewChild(*this); + NewPoint.PositionSet(**ListIdx, GlobalTimecodeScale()); + myTempReferences.erase(ListIdx); + break; + } + } +} + +/*! + \warning Assume that the list has been sorted (Sort()) +*/ +const KaxCuePoint * KaxCues::GetTimecodePoint(uint64 aTimecode) const +{ + uint64 TimecodeToLocate = aTimecode / GlobalTimecodeScale(); + const KaxCuePoint * aPointPrev = NULL; + uint64 aPrevTime = 0; + const KaxCuePoint * aPointNext = NULL; + uint64 aNextTime = EBML_PRETTYLONGINT(0xFFFFFFFFFFFF); + + EBML_MASTER_CONST_ITERATOR Itr; + for (Itr = begin(); Itr != end(); ++Itr) + { + if (EbmlId(*(*Itr)) == EBML_ID(KaxCuePoint)) { + const KaxCuePoint *tmp = static_cast(*Itr); + // check the tile + const KaxCueTime *aTime = static_cast(tmp->FindFirstElt(EBML_INFO(KaxCueTime))); + if (aTime != NULL) + { + uint64 _Time = uint64(*aTime); + if (_Time > aPrevTime && _Time < TimecodeToLocate) { + aPrevTime = _Time; + aPointPrev = tmp; + } + if (_Time < aNextTime && _Time > TimecodeToLocate) { + aNextTime= _Time; + aPointNext = tmp; + } + } + } + } + + return aPointPrev; +} + +uint64 KaxCues::GetTimecodePosition(uint64 aTimecode) const +{ + const KaxCuePoint * aPoint = GetTimecodePoint(aTimecode); + if (aPoint == NULL) + return 0; + + const KaxCueTrackPositions * aTrack = aPoint->GetSeekPosition(); + if (aTrack == NULL) + return 0; + + return aTrack->ClusterPosition(); +} + +END_LIBMATROSKA_NAMESPACE diff --git a/src/KaxSeekHead.cpp b/src/KaxSeekHead.cpp index 64cf02a..f653cb1 100644 --- a/src/KaxSeekHead.cpp +++ b/src/KaxSeekHead.cpp @@ -1,163 +1,163 @@ -/**************************************************************************** -** libmatroska : parse Matroska files, see http://www.matroska.org/ -** -** -** -** Copyright (C) 2002-2010 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: KaxSeekHead.cpp 640 2004-07-09 21:05:36Z mosu $ - \author Steve Lhomme -*/ -#include "matroska/KaxSeekHead.h" -#include "matroska/KaxContexts.h" -#include "matroska/KaxSegment.h" -#include "matroska/KaxCues.h" -#include "matroska/KaxDefines.h" - -using namespace LIBEBML_NAMESPACE; - -// sub elements -START_LIBMATROSKA_NAMESPACE - -DEFINE_START_SEMANTIC(KaxSeekHead) -DEFINE_SEMANTIC_ITEM(true, false, KaxSeek) -DEFINE_END_SEMANTIC(KaxSeekHead) - -DEFINE_START_SEMANTIC(KaxSeek) -DEFINE_SEMANTIC_ITEM(true, true, KaxSeekID) -DEFINE_SEMANTIC_ITEM(true, true, KaxSeekPosition) -DEFINE_END_SEMANTIC(KaxSeek) - -DEFINE_MKX_MASTER (KaxSeekHead, 0x114D9B74, 4, KaxSegment, "SeekHeader"); -DEFINE_MKX_MASTER (KaxSeek, 0x4DBB, 2, KaxSeekHead, "SeekPoint"); -DEFINE_MKX_BINARY (KaxSeekID, 0x53AB, 2, KaxSeek, "SeekID"); -DEFINE_MKX_UINTEGER(KaxSeekPosition, 0x53AC, 2, KaxSeek, "SeekPosition"); - -/*! - \todo verify that the element is not already in the list -*/ -void KaxSeekHead::IndexThis(const EbmlElement & aElt, const KaxSegment & ParentSegment) -{ - // create a new point - KaxSeek & aNewPoint = AddNewChild(*this); - - // add the informations to this element - KaxSeekPosition & aNewPos = GetChild(aNewPoint); - *static_cast(&aNewPos) = ParentSegment.GetRelativePosition(aElt); - - KaxSeekID & aNewID = GetChild(aNewPoint); - binary ID[4]; - ((const EbmlId&)aElt).Fill(ID); - aNewID.CopyBuffer(ID, EBML_ID_LENGTH((const EbmlId&)aElt)); -} - -KaxSeek * KaxSeekHead::FindFirstOf(const EbmlCallbacks & Callbacks) const -{ - // parse all the Entries and find the first to match the type - KaxSeek * aElt = static_cast(FindFirstElt(EBML_INFO(KaxSeek))); - while (aElt != NULL) - { - KaxSeekID * aId = NULL; - EBML_MASTER_ITERATOR Itr; - for (Itr = aElt->begin(); Itr != aElt->end(); ++Itr) - { - if (EbmlId(*(*Itr)) == EBML_ID(KaxSeekID)) { - aId = static_cast(*Itr); - EbmlId aEbmlId(aId->GetBuffer(), aId->GetSize()); - if (aEbmlId == EBML_INFO_ID(Callbacks)) - { - return aElt; - } - break; - } - } - aElt = static_cast(FindNextElt(*aElt)); - } - - return NULL; -} - -KaxSeek * KaxSeekHead::FindNextOf(const KaxSeek &aPrev) const -{ - EBML_MASTER_ITERATOR Itr; - KaxSeek *tmp; - - // look for the previous in the list - for (Itr = begin(); Itr != end(); ++Itr) - { - if (*Itr == static_cast(&aPrev)) - break; - } - - if (Itr != end()) - { - ++Itr; - for (; Itr != end(); ++Itr) - { - if (EbmlId(*(*Itr)) == EBML_ID(KaxSeek)) - { - tmp = (KaxSeek *)(*Itr); - if (tmp->IsEbmlId(aPrev)) - return tmp; - } - } - } - - return NULL; -} - -int64 KaxSeek::Location() const -{ - KaxSeekPosition *aPos = static_cast(FindFirstElt(EBML_INFO(KaxSeekPosition))); - if (aPos == NULL) - return 0; - return uint64(*aPos); -} - -bool KaxSeek::IsEbmlId(const EbmlId & aId) const -{ - KaxSeekID *_Id = static_cast(FindFirstElt(EBML_INFO(KaxSeekID))); - if (_Id == NULL) - return false; - EbmlId aEbmlId(_Id->GetBuffer(), _Id->GetSize()); - return (aId == aEbmlId); -} - -bool KaxSeek::IsEbmlId(const KaxSeek & aPoint) const -{ - KaxSeekID *_IdA = static_cast(FindFirstElt(EBML_INFO(KaxSeekID))); - if (_IdA == NULL) - return false; - KaxSeekID *_IdB = static_cast(aPoint.FindFirstElt(EBML_INFO(KaxSeekID))); - if (_IdB == NULL) - return false; - EbmlId aEbmlIdA(_IdA->GetBuffer(), _IdA->GetSize()); - EbmlId aEbmlIdB(_IdB->GetBuffer(), _IdB->GetSize()); - return (aEbmlIdA == aEbmlIdB); -} - -END_LIBMATROSKA_NAMESPACE +/**************************************************************************** +** libmatroska : parse Matroska files, see http://www.matroska.org/ +** +** +** +** Copyright (C) 2002-2010 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: KaxSeekHead.cpp 640 2004-07-09 21:05:36Z mosu $ + \author Steve Lhomme +*/ +#include "matroska/KaxSeekHead.h" +#include "matroska/KaxContexts.h" +#include "matroska/KaxSegment.h" +#include "matroska/KaxCues.h" +#include "matroska/KaxDefines.h" + +using namespace LIBEBML_NAMESPACE; + +// sub elements +START_LIBMATROSKA_NAMESPACE + +DEFINE_START_SEMANTIC(KaxSeekHead) +DEFINE_SEMANTIC_ITEM(true, false, KaxSeek) +DEFINE_END_SEMANTIC(KaxSeekHead) + +DEFINE_START_SEMANTIC(KaxSeek) +DEFINE_SEMANTIC_ITEM(true, true, KaxSeekID) +DEFINE_SEMANTIC_ITEM(true, true, KaxSeekPosition) +DEFINE_END_SEMANTIC(KaxSeek) + +DEFINE_MKX_MASTER (KaxSeekHead, 0x114D9B74, 4, KaxSegment, "SeekHeader"); +DEFINE_MKX_MASTER (KaxSeek, 0x4DBB, 2, KaxSeekHead, "SeekPoint"); +DEFINE_MKX_BINARY (KaxSeekID, 0x53AB, 2, KaxSeek, "SeekID"); +DEFINE_MKX_UINTEGER(KaxSeekPosition, 0x53AC, 2, KaxSeek, "SeekPosition"); + +/*! + \todo verify that the element is not already in the list +*/ +void KaxSeekHead::IndexThis(const EbmlElement & aElt, const KaxSegment & ParentSegment) +{ + // create a new point + KaxSeek & aNewPoint = AddNewChild(*this); + + // add the informations to this element + KaxSeekPosition & aNewPos = GetChild(aNewPoint); + *static_cast(&aNewPos) = ParentSegment.GetRelativePosition(aElt); + + KaxSeekID & aNewID = GetChild(aNewPoint); + binary ID[4]; + ((const EbmlId&)aElt).Fill(ID); + aNewID.CopyBuffer(ID, EBML_ID_LENGTH((const EbmlId&)aElt)); +} + +KaxSeek * KaxSeekHead::FindFirstOf(const EbmlCallbacks & Callbacks) const +{ + // parse all the Entries and find the first to match the type + KaxSeek * aElt = static_cast(FindFirstElt(EBML_INFO(KaxSeek))); + while (aElt != NULL) + { + KaxSeekID * aId = NULL; + EBML_MASTER_ITERATOR Itr; + for (Itr = aElt->begin(); Itr != aElt->end(); ++Itr) + { + if (EbmlId(*(*Itr)) == EBML_ID(KaxSeekID)) { + aId = static_cast(*Itr); + EbmlId aEbmlId(aId->GetBuffer(), aId->GetSize()); + if (aEbmlId == EBML_INFO_ID(Callbacks)) + { + return aElt; + } + break; + } + } + aElt = static_cast(FindNextElt(*aElt)); + } + + return NULL; +} + +KaxSeek * KaxSeekHead::FindNextOf(const KaxSeek &aPrev) const +{ + EBML_MASTER_CONST_ITERATOR Itr; + KaxSeek *tmp; + + // look for the previous in the list + for (Itr = begin(); Itr != end(); ++Itr) + { + if (*Itr == static_cast(&aPrev)) + break; + } + + if (Itr != end()) + { + ++Itr; + for (; Itr != end(); ++Itr) + { + if (EbmlId(*(*Itr)) == EBML_ID(KaxSeek)) + { + tmp = (KaxSeek *)(*Itr); + if (tmp->IsEbmlId(aPrev)) + return tmp; + } + } + } + + return NULL; +} + +int64 KaxSeek::Location() const +{ + KaxSeekPosition *aPos = static_cast(FindFirstElt(EBML_INFO(KaxSeekPosition))); + if (aPos == NULL) + return 0; + return uint64(*aPos); +} + +bool KaxSeek::IsEbmlId(const EbmlId & aId) const +{ + KaxSeekID *_Id = static_cast(FindFirstElt(EBML_INFO(KaxSeekID))); + if (_Id == NULL) + return false; + EbmlId aEbmlId(_Id->GetBuffer(), _Id->GetSize()); + return (aId == aEbmlId); +} + +bool KaxSeek::IsEbmlId(const KaxSeek & aPoint) const +{ + KaxSeekID *_IdA = static_cast(FindFirstElt(EBML_INFO(KaxSeekID))); + if (_IdA == NULL) + return false; + KaxSeekID *_IdB = static_cast(aPoint.FindFirstElt(EBML_INFO(KaxSeekID))); + if (_IdB == NULL) + return false; + EbmlId aEbmlIdA(_IdA->GetBuffer(), _IdA->GetSize()); + EbmlId aEbmlIdB(_IdB->GetBuffer(), _IdB->GetSize()); + return (aEbmlIdA == aEbmlIdB); +} + +END_LIBMATROSKA_NAMESPACE