~ubuntu-branches/ubuntu/wily/mkvtoolnix/wily

« back to all changes in this revision

Viewing changes to lib/libmatroska/src/KaxCues.cpp

  • Committer: Package Import Robot
  • Author(s): Christian Marillat
  • Date: 2015-04-26 10:36:27 UTC
  • mfrom: (1.1.29) (4.2.45 sid)
  • Revision ID: package-import@ubuntu.com-20150426103627-k53p8hrai2ynikaa
Tags: 7.8.0-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
** modify it under the terms of the GNU Lesser General Public
10
10
** License as published by the Free Software Foundation; either
11
11
** version 2.1 of the License, or (at your option) any later version.
12
 
** 
 
12
**
13
13
** This library is distributed in the hope that it will be useful,
14
14
** but WITHOUT ANY WARRANTY; without even the implied warranty of
15
15
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
16
** Lesser General Public License for more details.
17
 
** 
 
17
**
18
18
** You should have received a copy of the GNU Lesser General Public
19
19
** License along with this library; if not, write to the Free Software
20
20
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
26
26
**********************************************************************/
27
27
 
28
28
/*!
29
 
        \file
30
 
        \version \$Id: KaxCues.cpp 1265 2007-01-14 17:20:35Z mosu $
31
 
        \author Steve Lhomme     <robux4 @ users.sf.net>
 
29
  \file
 
30
  \version \$Id: KaxCues.cpp 1265 2007-01-14 17:20:35Z mosu $
 
31
  \author Steve Lhomme     <robux4 @ users.sf.net>
32
32
*/
33
33
#include <cassert>
34
34
 
44
44
 
45
45
KaxCues::~KaxCues()
46
46
{
47
 
        assert(myTempReferences.size() == 0); // otherwise that means you have added references and forgot to set the position
 
47
  assert(myTempReferences.size() == 0); // otherwise that means you have added references and forgot to set the position
48
48
}
49
49
/* deprecated and wrong
50
50
bool KaxCues::AddBlockGroup(const KaxBlockGroup & BlockRef)
51
51
{
52
 
        // Do not add the element if it's already present.
53
 
        std::vector<const KaxBlockBlob *>::iterator ListIdx;
54
 
        KaxBlockBlob *BlockReference = new KaxBlockBlob(BLOCK_BLOB_NO_SIMPLE);
55
 
        BlockReference->SetBlockGroup(*const_cast<KaxBlockGroup*>(&BlockRef));
56
 
 
57
 
        for (ListIdx = myTempReferences.begin(); ListIdx != myTempReferences.end(); ListIdx++)
58
 
                if (&(KaxBlockGroup&)*ListIdx == &BlockRef)
59
 
        {
60
 
            delete BlockReference;
61
 
                        return true;
62
 
        }
63
 
 
64
 
        myTempReferences.push_back(BlockReference);
65
 
        return true;
 
52
  // Do not add the element if it's already present.
 
53
  std::vector<const KaxBlockBlob *>::iterator ListIdx;
 
54
  KaxBlockBlob *BlockReference = new KaxBlockBlob(BLOCK_BLOB_NO_SIMPLE);
 
55
  BlockReference->SetBlockGroup(*const_cast<KaxBlockGroup*>(&BlockRef));
 
56
 
 
57
  for (ListIdx = myTempReferences.begin(); ListIdx != myTempReferences.end(); ListIdx++)
 
58
    if (&(KaxBlockGroup&)*ListIdx == &BlockRef) {
 
59
      delete BlockReference;
 
60
      return true;
 
61
    }
 
62
 
 
63
  myTempReferences.push_back(BlockReference);
 
64
  return true;
66
65
}
67
66
*/
68
67
bool KaxCues::AddBlockBlob(const KaxBlockBlob & BlockReference)
69
68
{
70
 
        // Do not add the element if it's already present.
71
 
        std::vector<const KaxBlockBlob *>::iterator ListIdx;
72
 
 
73
 
        for (ListIdx = myTempReferences.begin(); ListIdx != myTempReferences.end(); ++ListIdx)
74
 
                if (*ListIdx == &BlockReference)
75
 
                        return true;
76
 
 
77
 
        myTempReferences.push_back(&BlockReference);
78
 
        return true;
 
69
  // Do not add the element if it's already present.
 
70
  std::vector<const KaxBlockBlob *>::iterator ListIdx;
 
71
 
 
72
  for (ListIdx = myTempReferences.begin(); ListIdx != myTempReferences.end(); ++ListIdx)
 
73
    if (*ListIdx == &BlockReference)
 
74
      return true;
 
75
 
 
76
  myTempReferences.push_back(&BlockReference);
 
77
  return true;
79
78
}
80
79
 
81
80
void KaxCues::PositionSet(const KaxBlockBlob & BlockReference)
82
81
{
83
 
        // look for the element in the temporary references
84
 
        std::vector<const KaxBlockBlob *>::iterator ListIdx;
 
82
  // look for the element in the temporary references
 
83
  std::vector<const KaxBlockBlob *>::iterator ListIdx;
85
84
 
86
 
        for (ListIdx = myTempReferences.begin(); ListIdx != myTempReferences.end(); ++ListIdx) {
87
 
                if (*ListIdx == &BlockReference) {
88
 
                        // found, now add the element to the entry list
89
 
                        KaxCuePoint & NewPoint = AddNewChild<KaxCuePoint>(*this);
90
 
                        NewPoint.PositionSet(BlockReference, GlobalTimecodeScale());
91
 
                        myTempReferences.erase(ListIdx);
92
 
                        break;
93
 
                }
94
 
        }
 
85
  for (ListIdx = myTempReferences.begin(); ListIdx != myTempReferences.end(); ++ListIdx) {
 
86
    if (*ListIdx == &BlockReference) {
 
87
      // found, now add the element to the entry list
 
88
      KaxCuePoint & NewPoint = AddNewChild<KaxCuePoint>(*this);
 
89
      NewPoint.PositionSet(BlockReference, GlobalTimecodeScale());
 
90
      myTempReferences.erase(ListIdx);
 
91
      break;
 
92
    }
 
93
  }
95
94
}
96
95
 
97
96
void KaxCues::PositionSet(const KaxBlockGroup & BlockRef)
98
97
{
99
 
        // look for the element in the temporary references
100
 
        std::vector<const KaxBlockBlob *>::iterator ListIdx;
 
98
  // look for the element in the temporary references
 
99
  std::vector<const KaxBlockBlob *>::iterator ListIdx;
101
100
 
102
 
        for (ListIdx = myTempReferences.begin(); ListIdx != myTempReferences.end(); ++ListIdx) {
103
 
                const KaxInternalBlock &refTmp = **ListIdx;
104
 
                if (refTmp.GlobalTimecode() == BlockRef.GlobalTimecode() &&
105
 
                        refTmp.TrackNum() == BlockRef.TrackNumber()) {
106
 
                        // found, now add the element to the entry list
107
 
                        KaxCuePoint & NewPoint = AddNewChild<KaxCuePoint>(*this);
108
 
                        NewPoint.PositionSet(**ListIdx, GlobalTimecodeScale());
109
 
                        myTempReferences.erase(ListIdx);
110
 
                        break;
111
 
                }
112
 
        }
 
101
  for (ListIdx = myTempReferences.begin(); ListIdx != myTempReferences.end(); ++ListIdx) {
 
102
    const KaxInternalBlock &refTmp = **ListIdx;
 
103
    if (refTmp.GlobalTimecode() == BlockRef.GlobalTimecode() &&
 
104
        refTmp.TrackNum() == BlockRef.TrackNumber()) {
 
105
      // found, now add the element to the entry list
 
106
      KaxCuePoint & NewPoint = AddNewChild<KaxCuePoint>(*this);
 
107
      NewPoint.PositionSet(**ListIdx, GlobalTimecodeScale());
 
108
      myTempReferences.erase(ListIdx);
 
109
      break;
 
110
    }
 
111
  }
113
112
}
114
113
 
115
114
/*!
116
 
        \warning Assume that the list has been sorted (Sort())
 
115
  \warning Assume that the list has been sorted (Sort())
117
116
*/
118
117
const KaxCuePoint * KaxCues::GetTimecodePoint(uint64 aTimecode) const
119
118
{
120
 
        uint64 TimecodeToLocate = aTimecode / GlobalTimecodeScale();
121
 
        const KaxCuePoint * aPointPrev = NULL;
122
 
        uint64 aPrevTime = 0;
123
 
        uint64 aNextTime = EBML_PRETTYLONGINT(0xFFFFFFFFFFFF);
124
 
 
125
 
    EBML_MASTER_CONST_ITERATOR Itr;
126
 
        for (Itr = begin(); Itr != end(); ++Itr)
127
 
    {
128
 
                if (EbmlId(*(*Itr)) == EBML_ID(KaxCuePoint)) {
129
 
                        const KaxCuePoint *tmp = static_cast<const KaxCuePoint *>(*Itr);
130
 
                        // check the tile
131
 
                        const KaxCueTime *aTime = static_cast<const KaxCueTime *>(tmp->FindFirstElt(EBML_INFO(KaxCueTime)));
132
 
                        if (aTime != NULL)
133
 
                        {
134
 
                                uint64 _Time = uint64(*aTime);
135
 
                                if (_Time > aPrevTime && _Time < TimecodeToLocate) {
136
 
                                        aPrevTime = _Time;
137
 
                                        aPointPrev = tmp;
138
 
                                }
139
 
                                if (_Time < aNextTime && _Time > TimecodeToLocate) {
140
 
                                        aNextTime= _Time;
141
 
                                }
142
 
                        }
143
 
                }
144
 
        }
145
 
 
146
 
        return aPointPrev;
 
119
  uint64 TimecodeToLocate = aTimecode / GlobalTimecodeScale();
 
120
  const KaxCuePoint * aPointPrev = NULL;
 
121
  uint64 aPrevTime = 0;
 
122
  uint64 aNextTime = EBML_PRETTYLONGINT(0xFFFFFFFFFFFF);
 
123
 
 
124
  EBML_MASTER_CONST_ITERATOR Itr;
 
125
  for (Itr = begin(); Itr != end(); ++Itr) {
 
126
    if (EbmlId(*(*Itr)) == EBML_ID(KaxCuePoint)) {
 
127
      const KaxCuePoint *tmp = static_cast<const KaxCuePoint *>(*Itr);
 
128
      // check the tile
 
129
      const KaxCueTime *aTime = static_cast<const KaxCueTime *>(tmp->FindFirstElt(EBML_INFO(KaxCueTime)));
 
130
      if (aTime != NULL) {
 
131
        uint64 _Time = uint64(*aTime);
 
132
        if (_Time > aPrevTime && _Time < TimecodeToLocate) {
 
133
          aPrevTime = _Time;
 
134
          aPointPrev = tmp;
 
135
        }
 
136
        if (_Time < aNextTime && _Time > TimecodeToLocate) {
 
137
          aNextTime= _Time;
 
138
        }
 
139
      }
 
140
    }
 
141
  }
 
142
 
 
143
  return aPointPrev;
147
144
}
148
145
 
149
146
uint64 KaxCues::GetTimecodePosition(uint64 aTimecode) const
150
147
{
151
 
        const KaxCuePoint * aPoint = GetTimecodePoint(aTimecode);
152
 
        if (aPoint == NULL)
153
 
                return 0;
154
 
 
155
 
        const KaxCueTrackPositions * aTrack = aPoint->GetSeekPosition();
156
 
        if (aTrack == NULL)
157
 
                return 0;
158
 
 
159
 
        return aTrack->ClusterPosition();
 
148
  const KaxCuePoint * aPoint = GetTimecodePoint(aTimecode);
 
149
  if (aPoint == NULL)
 
150
    return 0;
 
151
 
 
152
  const KaxCueTrackPositions * aTrack = aPoint->GetSeekPosition();
 
153
  if (aTrack == NULL)
 
154
    return 0;
 
155
 
 
156
  return aTrack->ClusterPosition();
160
157
}
161
158
 
162
159
END_LIBMATROSKA_NAMESPACE