Coverage Report

Created: 2025-07-18 08:04

/src/vlc/contrib/x86_64-unknown-linux-gnu/include/matroska/KaxCluster.h
Line
Count
Source (jump to first uncovered line)
1
/****************************************************************************
2
** libmatroska : parse Matroska files, see http://www.matroska.org/
3
**
4
** <file/class description>
5
**
6
** Copyright (C) 2002-2010 Steve Lhomme.  All rights reserved.
7
**
8
** This library is free software; you can redistribute it and/or
9
** modify it under the terms of the GNU Lesser General Public
10
** License as published by the Free Software Foundation; either
11
** version 2.1 of the License, or (at your option) any later version.
12
**
13
** This library is distributed in the hope that it will be useful,
14
** but WITHOUT ANY WARRANTY; without even the implied warranty of
15
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
** Lesser General Public License for more details.
17
**
18
** You should have received a copy of the GNU Lesser General Public
19
** License along with this library; if not, write to the Free Software
20
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21
**
22
** See http://www.gnu.org/licenses/lgpl-2.1.html for LGPL licensing information.**
23
** Contact license@matroska.org if any conditions of this licensing are
24
** not clear to you.
25
**
26
**********************************************************************/
27
28
/*!
29
  \file
30
  \version \$Id: KaxCluster.h,v 1.10 2004/04/14 23:26:17 robux4 Exp $
31
  \author Steve Lhomme     <robux4 @ users.sf.net>
32
  \author Julien Coloos    <suiryc @ users.sf.net>
33
34
*/
35
#ifndef LIBMATROSKA_CLUSTER_H
36
#define LIBMATROSKA_CLUSTER_H
37
38
#include "matroska/KaxTypes.h"
39
#include "ebml/EbmlMaster.h"
40
#include "matroska/KaxTracks.h"
41
#include "matroska/KaxBlock.h"
42
#include "matroska/KaxCues.h"
43
#include "matroska/KaxDefines.h"
44
45
using namespace libebml;
46
47
namespace libmatroska {
48
49
class KaxSegment;
50
51
DECLARE_MKX_MASTER_CONS(KaxCluster)
52
  public:
53
    /*!
54
      \brief Addition of a frame without references
55
56
      \param timecode the timecode is expressed in nanoseconds, relative to the beggining of the Segment
57
    */
58
    bool AddFrame(const KaxTrackEntry & track, uint64 timecode, DataBuffer & buffer, KaxBlockGroup * & MyNewBlock, LacingType lacing = LACING_AUTO);
59
    /*!
60
      \brief Addition of a frame with a backward reference (P frame)
61
      \param timecode the timecode is expressed in nanoseconds, relative to the beggining of the Segment
62
63
    */
64
    bool AddFrame(const KaxTrackEntry & track, uint64 timecode, DataBuffer & buffer, KaxBlockGroup * & MyNewBlock, const KaxBlockGroup & PastBlock, LacingType lacing = LACING_AUTO);
65
66
    /*!
67
      \brief Addition of a frame with a backward+forward reference (B frame)
68
      \param timecode the timecode is expressed in nanoseconds, relative to the beggining of the Segment
69
70
    */
71
    bool AddFrame(const KaxTrackEntry & track, uint64 timecode, DataBuffer & buffer, KaxBlockGroup * & MyNewBlock, const KaxBlockGroup & PastBlock, const KaxBlockGroup & ForwBlock, LacingType lacing = LACING_AUTO);
72
73
    /*!
74
      \brief Render the data to the stream and retrieve the position of BlockGroups for later cue entries
75
    */
76
    filepos_t Render(IOCallback & output, KaxCues & CueToUpdate, bool bSaveDefault = false);
77
78
    /*!
79
      \return the global timecode of this Cluster
80
    */
81
    uint64 GlobalTimecode() const;
82
83
    KaxBlockGroup & GetNewBlock();
84
85
    /*!
86
      \brief release all the frames of all Blocks
87
      \note this is a convenience to be able to keep Clusters+Blocks in memory (for future reference) withouht being a memory hog
88
    */
89
    void ReleaseFrames();
90
91
    /*!
92
      \brief return the position offset compared to the beggining of the Segment
93
    */
94
    uint64 GetPosition() const;
95
96
0
    void SetParent(const KaxSegment & aParentSegment) {ParentSegment = &aParentSegment;}
97
98
0
    void SetPreviousTimecode(uint64 aPreviousTimecode, int64 aTimecodeScale) {
99
0
      bPreviousTimecodeIsSet = true;
100
0
      PreviousTimecode = aPreviousTimecode;
101
0
      SetGlobalTimecodeScale(aTimecodeScale);
102
0
    }
103
104
    /*!
105
      \note dirty hack to get the mandatory data back after reading
106
      \todo there should be a better way to get mandatory data
107
    */
108
51
    void InitTimecode(uint64 aTimecode, int64 aTimecodeScale) {
109
51
      SetGlobalTimecodeScale(aTimecodeScale);
110
51
      MinTimecode = MaxTimecode = PreviousTimecode = aTimecode * TimecodeScale;
111
51
      bFirstFrameInside = bPreviousTimecodeIsSet = true;
112
51
    }
113
114
    int16 GetBlockLocalTimecode(uint64 GlobalTimecode) const;
115
116
    uint64 GetBlockGlobalTimecode(int16 LocalTimecode);
117
118
51
    void SetGlobalTimecodeScale(uint64 aGlobalTimecodeScale) {
119
51
      TimecodeScale = aGlobalTimecodeScale;
120
51
      bTimecodeScaleIsSet = true;
121
51
    }
122
0
    uint64 GlobalTimecodeScale() const {
123
0
      assert(bTimecodeScaleIsSet);
124
0
      return TimecodeScale;
125
0
    }
126
127
    bool SetSilentTrackUsed()
128
0
    {
129
0
      bSilentTracksUsed = true;
130
0
      return FindFirstElt(EBML_INFO(KaxClusterSilentTracks), true) != nullptr;
131
0
    }
132
133
    bool AddBlockBlob(KaxBlockBlob * NewBlob);
134
135
0
    const KaxSegment *GetParentSegment() const { return ParentSegment; }
136
137
  protected:
138
    KaxBlockBlob     * currentNewBlob;
139
    std::vector<KaxBlockBlob*> Blobs;
140
    KaxBlockGroup    * currentNewBlock{nullptr};
141
    const KaxSegment * ParentSegment{nullptr};
142
143
    uint64 MinTimecode, MaxTimecode, PreviousTimecode;
144
    int64  TimecodeScale;
145
146
    bool   bFirstFrameInside{false}; // used to speed research
147
    bool   bPreviousTimecodeIsSet{false};
148
    bool   bTimecodeScaleIsSet{false};
149
    bool   bSilentTracksUsed{false};
150
151
    /*!
152
      \note method used internally
153
    */
154
    bool AddFrameInternal(const KaxTrackEntry & track, uint64 timecode, DataBuffer & buffer, KaxBlockGroup * & MyNewBlock, const KaxBlockGroup * PastBlock, const KaxBlockGroup * ForwBlock, LacingType lacing);
155
};
156
157
} // namespace libmatroska
158
159
#endif // LIBMATROSKA_CLUSTER_H