RDK Documentation (Open Sourced RDK Components)
isobmffbuffer.h
Go to the documentation of this file.
1 /*
2  * If not stated otherwise in this file or this component's license file the
3  * following copyright and licenses apply:
4  *
5  * Copyright 2019 RDK Management
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18 */
19 
20 /**
21 * @file isobmffbuffer.h
22 * @brief Header file for ISO Base Media File Format Buffer
23 */
24 
25 #ifndef __ISOBMFFBUFFER_H__
26 #define __ISOBMFFBUFFER_H__
27 
28 #include "isobmffbox.h"
29 #include <stddef.h>
30 #include <vector>
31 #include <string>
32 #include <cstdint>
33 #include "AampLogManager.h"
34 
35 /**
36  * @class IsoBmffBuffer
37  * @brief Class for ISO BMFF Buffer
38  */
40 {
41 private:
42  std::vector<Box*> boxes; //ISOBMFF boxes of associated buffer
43  uint8_t *buffer;
44  size_t bufSize;
45  Box* chunkedBox; //will hold one element only
46  size_t mdatCount;
47  AampLogManager *mLogObj;
48  /**
49  * @fn getFirstPTSInternal
50  *
51  * @param[in] boxes - ISOBMFF boxes
52  * @param[out] pts - pts value
53  * @return true if parse was successful. false otherwise
54  */
55  bool getFirstPTSInternal(const std::vector<Box*> *boxes, uint64_t &pts);
56 
57  /**
58  * @fn getTrackIdInternal
59  *
60  * @param[in] boxes - ISOBMFF boxes
61  * @param[out] track_id - track_id
62  * @return true if parse was successful. false otherwise
63  */
64  bool getTrackIdInternal (const std::vector<Box*> *boxes, uint32_t &track_id);
65 
66  /**
67  * @fn getTimeScaleInternal
68  *
69  * @param[in] boxes - ISOBMFF boxes
70  * @param[out] timeScale - TimeScale value
71  * @param[out] foundMdhd - flag indicates if MDHD box was seen
72  * @return true if parse was successful. false otherwise
73  */
74  bool getTimeScaleInternal(const std::vector<Box*> *boxes, uint32_t &timeScale, bool &foundMdhd);
75 
76  /**
77  * @fn printBoxesInternal
78  *
79  * @param[in] boxes - ISOBMFF boxes
80  * @return void
81  */
82  void printBoxesInternal(const std::vector<Box*> *boxes);
83 
84  /**
85  * @fn parseBoxInternal
86  *
87  * @param[in] boxes - ISOBMFF boxes
88  * @param[in] name - box name to get
89  * @param[out] buf - mdat buffer pointer
90  * @param[out] size - size of mdat buffer
91  * @return bool
92  */
93  bool parseBoxInternal(const std::vector<Box*> *boxes, const char *name, uint8_t *buf, size_t &size);
94 
95  /**
96  * @fn getBoxSizeInternal
97  *
98  * @param[in] boxes - ISOBMFF boxes
99  * @param[in] name - box name to get
100  * @param[out] size - size of mdat buffer
101  * @return bool
102  */
103  bool getBoxSizeInternal(const std::vector<Box*> *boxes, const char *name, size_t &size);
104 
105  /**
106  * @fn getBoxesInternal
107  *
108  * @param[in] boxes - ISOBMFF boxes
109  * @param[in] name - box name to get
110  * @param[out] pBoxes - size of mdat buffer
111  * @return bool
112  */
113  bool getBoxesInternal(const std::vector<Box*> *boxes, const char *name, std::vector<Box*> *pBoxes);
114 
115 public:
116  /**
117  * @brief IsoBmffBuffer constructor
118  */
119  IsoBmffBuffer(AampLogManager *logObj=NULL): mLogObj(logObj), boxes(), buffer(NULL), bufSize(0), chunkedBox(NULL), mdatCount(0)
120  {
121 
122  }
123 
124  /**
125  * @fn ~IsoBmffBuffer
126  */
127  ~IsoBmffBuffer();
128 
129  IsoBmffBuffer(const IsoBmffBuffer&) = delete;
130  IsoBmffBuffer& operator=(const IsoBmffBuffer&) = delete;
131 
132  /**
133  * @fn setBuffer
134  *
135  * @param[in] buf - buffer pointer
136  * @param[in] sz - buffer size
137  * @return void
138  */
139  void setBuffer(uint8_t *buf, size_t sz);
140 
141  /**
142  * @fn parseBuffer
143  * @param[in] correctBoxSize - flag to indicate if box size needs to be corrected
144  * @param[in] newTrackId - new track id to overwrite the existing track id, when value is -1, it will not override
145  * @return true if parse was successful. false otherwise
146  */
147  bool parseBuffer(bool correctBoxSize = false, int newTrackId = -1);
148 
149  /**
150  * @fn restampPTS
151  *
152  * @param[in] offset - pts offset
153  * @param[in] basePts - base pts
154  * @param[in] segment - buffer pointer
155  * @param[in] bufSz - buffer size
156  * @return void
157  */
158  void restampPTS(uint64_t offset, uint64_t basePts, uint8_t *segment, uint32_t bufSz);
159 
160  /**
161  * @fn getFirstPTS
162  *
163  * @param[out] pts - pts value
164  * @return true if parse was successful. false otherwise
165  */
166  bool getFirstPTS(uint64_t &pts);
167 
168  /**
169  * @fn getTrack_id
170  *
171  * @param[out] track_id - track-id
172  * @return true if parse was successful. false otherwise
173  */
174  bool getTrack_id(uint32_t &track_id);
175 
176  /**
177  * @fn PrintPTS
178  * @return tvoid
179  */
180  void PrintPTS(void);
181 
182  /**
183  * @fn getTimeScale
184  *
185  * @param[out] timeScale - TimeScale value
186  * @return true if parse was successful. false otherwise
187  */
188  bool getTimeScale(uint32_t &timeScale);
189 
190  /**
191  * @fn destroyBoxes
192  *
193  * @return void
194  */
195  void destroyBoxes();
196 
197  /**
198  * @fn printBoxes
199  *
200  * @return void
201  */
202  void printBoxes();
203 
204  /**
205  * @fn isInitSegment
206  *
207  * @return true if buffer is an initialization segment. false otherwise
208  */
209  bool isInitSegment();
210 
211  /**
212  * @fn parseMdatBox
213  * @param[out] buf - mdat buffer pointer
214  * @param[out] size - size of mdat buffer
215  * @return true if mdat buffer is available. false otherwise
216  */
217  bool parseMdatBox(uint8_t *buf, size_t &size);
218 
219  /**
220  * @fn getMdatBoxSize
221  * @param[out] size - size of mdat buffer
222  * @return true if buffer size available. false otherwise
223  */
224  bool getMdatBoxSize(size_t &size);
225 
226  /**
227  * @fn getEMSGData
228  *
229  * @param[out] message - messageData from EMSG
230  * @param[out] messageLen - messageLen
231  * @param[out] schemeIdUri - schemeIdUri
232  * @param[out] value - value of Id3
233  * @param[out] presTime - Presentation time
234  * @param[out] timeScale - timeScale of ID3 metadata
235  * @param[out] eventDuration - eventDuration value
236  * @param[out] id - ID of metadata
237  * @return true if parse was successful. false otherwise
238  */
239  bool getEMSGData(uint8_t* &message, uint32_t &messageLen, uint8_t* &schemeIdUri, uint8_t* &value, uint64_t &presTime, uint32_t &timeScale, uint32_t &eventDuration, uint32_t &id);
240 
241  /**
242  * @fn getEMSGInfoInternal
243  *
244  * @param[in] boxes - ISOBMFF boxes
245  * @param[out] message - messageData pointer
246  * @param[out] messageLen - messageLen value
247  * @param[out] schemeIdUri - schemeIdUri
248  * @param[out] value - value of Id3
249  * @param[out] presTime - Presentation time
250  * @param[out] timeScale - timeScale of ID3 metadata
251  * @param[out] eventDuration - eventDuration value
252  * @param[out] id - ID of metadata
253  * @param[out] foundEmsg - flag indicates if EMSG box was seen
254  * @return true if parse was successful. false otherwise
255  */
256  bool getEMSGInfoInternal(const std::vector<Box*> *boxes, uint8_t* &message, uint32_t &messageLen, uint8_t* &schemeIdUri, uint8_t* &value, uint64_t &presTime, uint32_t &timeScale, uint32_t &eventDuration, uint32_t &id, bool &foundEmsg);
257 
258  /**
259  * @fn getMdatBoxCount
260  * @param[out] count - mdat box count
261  * @return true if mdat count available. false otherwise
262  */
263  bool getMdatBoxCount(size_t &count);
264 
265  /**
266  * @fn printMdatBoxes
267  *
268  * @return void
269  */
270  void printMdatBoxes();
271 
272  /**
273  * @fn getTypeOfBoxes
274  * @param[in] name - box name to get
275  * @param[out] stBoxes - List of box handles of a type in a parsed buffer
276  * @return true if Box found. false otherwise
277  */
278  bool getTypeOfBoxes(const char *name, std::vector<Box*> &stBoxes);
279 
280  /**
281  * @fn getChunkedfBox
282  *
283  * @return Box handle if Chunk box found in a parsed buffer. NULL otherwise
284  */
285  Box* getChunkedfBox() const;
286 
287  /**
288  * @fn getParsedBoxes
289  *
290  * @return Box handle list if Box found at index given. NULL otherwise
291  */
292  std::vector<Box*> *getParsedBoxes();
293 
294  /**
295  * @fn getBox
296  * @param[in] name - box name to get
297  * @param[out] index - index of box in a parsed buffer
298  * @return Box handle if Box found at index given. NULL otherwise
299  */
300  Box* getBox(const char *name, size_t &index);
301 
302  /**
303  * @fn getBoxAtIndex
304  * @param[out] index - index of box in a parsed buffer
305  * @return Box handle if Box found at index given. NULL otherwise
306  */
307  Box* getBoxAtIndex(size_t index);
308 
309  /**
310  * @fn printPTSInternal
311  *
312  * @param[in] boxes - ISOBMFF boxes
313  * @return void
314  */
315  void printPTSInternal(const std::vector<Box*> *boxes);
316 
317  /**
318  * @fn getSampleDuration
319  *
320  * @param[in] box - ISOBMFF box
321  * @param[in] fduration - duration to get
322  * @return void
323  */
324  void getSampleDuration(Box *box, uint64_t &fduration);
325 
326  /**
327  * @fn getSampleDurationInernal
328  *
329  * @param[in] boxes - ISOBMFF boxes
330  * @return uint64_t - duration value
331  */
332  uint64_t getSampleDurationInernal(const std::vector<Box*> *boxes);
333 
334  /**
335  * @fn getPts
336  *
337  * @param[in] box - ISOBMFF box
338  * @param[in] fpts - PTS to get
339  * @return void
340  */
341  void getPts(Box *box, uint64_t &fpts);
342 
343  /**
344  * @fn getPtsInternal
345  *
346  * @param[in] boxes - ISOBMFF boxes
347  * @return uint64_t - PTS value
348  */
349  uint64_t getPtsInternal(const std::vector<Box*> *boxes);
350 };
351 
352 
353 #endif /* __ISOBMFFBUFFER_H__ */
AampLogManager.h
Log managed for Aamp.
IsoBmffBuffer::getEMSGInfoInternal
bool getEMSGInfoInternal(const std::vector< Box * > *boxes, uint8_t *&message, uint32_t &messageLen, uint8_t *&schemeIdUri, uint8_t *&value, uint64_t &presTime, uint32_t &timeScale, uint32_t &eventDuration, uint32_t &id, bool &foundEmsg)
Get emsg informations.
Definition: isobmffbuffer.cpp:378
IsoBmffBuffer::getParsedBoxes
std::vector< Box * > * getParsedBoxes()
Get list of box handles in a parsed buffer.
Definition: isobmffbuffer.cpp:481
IsoBmffBuffer::PrintPTS
void PrintPTS(void)
Print PTS of buffer.
Definition: isobmffbuffer.cpp:257
IsoBmffBuffer::getSampleDuration
void getSampleDuration(Box *box, uint64_t &fduration)
Get ISOBMFF box Sample Duration.
Definition: isobmffbuffer.cpp:584
IsoBmffBuffer::~IsoBmffBuffer
~IsoBmffBuffer()
IsoBmffBuffer destructor.
Definition: isobmffbuffer.cpp:33
IsoBmffBuffer::printBoxesInternal
void printBoxesInternal(const std::vector< Box * > *boxes)
Print ISOBMFF boxes.
Definition: isobmffbuffer.cpp:316
IsoBmffBuffer::IsoBmffBuffer
IsoBmffBuffer(AampLogManager *logObj=NULL)
IsoBmffBuffer constructor.
Definition: isobmffbuffer.h:119
IsoBmffBuffer::printPTSInternal
void printPTSInternal(const std::vector< Box * > *boxes)
Print ISOBMFF box PTS.
Definition: isobmffbuffer.cpp:521
IsoBmffBuffer::getBoxAtIndex
Box * getBoxAtIndex(size_t index)
Get box handle in parsed bufferr using index.
Definition: isobmffbuffer.cpp:509
IsoBmffBuffer::parseMdatBox
bool parseMdatBox(uint8_t *buf, size_t &size)
Get mdat buffer handle and size from parsed buffer.
Definition: isobmffbuffer.cpp:79
AampLogManager
AampLogManager Class.
Definition: AampLogManager.h:150
IsoBmffBuffer::getTimeScale
bool getTimeScale(uint32_t &timeScale)
Get TimeScale value of buffer.
Definition: isobmffbuffer.cpp:307
IsoBmffBuffer::getChunkedfBox
Box * getChunkedfBox() const
Get list of box handles in a parsed buffer.
Definition: isobmffbuffer.cpp:473
Box
Base Class for ISO BMFF Box.
Definition: isobmffbox.h:90
IsoBmffBuffer::destroyBoxes
void destroyBoxes()
Release ISOBMFF boxes parsed.
Definition: isobmffbuffer.cpp:177
IsoBmffBuffer::getSampleDurationInernal
uint64_t getSampleDurationInernal(const std::vector< Box * > *boxes)
Get ISOBMFF box Sample Duration.
Definition: isobmffbuffer.cpp:542
IsoBmffBuffer::restampPTS
void restampPTS(uint64_t offset, uint64_t basePts, uint8_t *segment, uint32_t bufSz)
Restamp PTS in a buffer.
Definition: isobmffbuffer.cpp:134
IsoBmffBuffer::parseBoxInternal
bool parseBoxInternal(const std::vector< Box * > *boxes, const char *name, uint8_t *buf, size_t &size)
parse ISOBMFF boxes of a type in a parsed buffer
Definition: isobmffbuffer.cpp:89
IsoBmffBuffer::getMdatBoxCount
bool getMdatBoxCount(size_t &count)
Check mdat buffer count in parsed buffer.
Definition: isobmffbuffer.cpp:440
IsoBmffBuffer::getTypeOfBoxes
bool getTypeOfBoxes(const char *name, std::vector< Box * > &stBoxes)
Get list of box handle in parsed bufferr using name.
Definition: isobmffbuffer.cpp:463
IsoBmffBuffer
Class for ISO BMFF Buffer.
Definition: isobmffbuffer.h:39
IsoBmffBuffer::setBuffer
void setBuffer(uint8_t *buf, size_t sz)
Set buffer.
Definition: isobmffbuffer.cpp:47
IsoBmffBuffer::printMdatBoxes
void printMdatBoxes()
Print ISOBMFF mdat boxes in parsed buffer.
Definition: isobmffbuffer.cpp:452
IsoBmffBuffer::getTrack_id
bool getTrack_id(uint32_t &track_id)
Get track_id from the trak box.
Definition: isobmffbuffer.cpp:265
IsoBmffBuffer::getFirstPTS
bool getFirstPTS(uint64_t &pts)
Get first PTS of buffer.
Definition: isobmffbuffer.cpp:249
IsoBmffBuffer::getPts
void getPts(Box *box, uint64_t &fpts)
Get ISOBMFF box PTS.
Definition: isobmffbuffer.cpp:625
IsoBmffBuffer::getTimeScaleInternal
bool getTimeScaleInternal(const std::vector< Box * > *boxes, uint32_t &timeScale, bool &foundMdhd)
Get TimeScale value of buffer.
Definition: isobmffbuffer.cpp:273
IsoBmffBuffer::getPtsInternal
uint64_t getPtsInternal(const std::vector< Box * > *boxes)
Get ISOBMFF box PTS.
Definition: isobmffbuffer.cpp:595
IsoBmffBuffer::parseBuffer
bool parseBuffer(bool correctBoxSize=false, int newTrackId=-1)
Parse ISOBMFF boxes from buffer.
Definition: isobmffbuffer.cpp:59
isobmffbox.h
Header file for ISO Base Media File Format Boxes.
IsoBmffBuffer::getEMSGData
bool getEMSGData(uint8_t *&message, uint32_t &messageLen, uint8_t *&schemeIdUri, uint8_t *&value, uint64_t &presTime, uint32_t &timeScale, uint32_t &eventDuration, uint32_t &id)
Get information from EMSG box.
Definition: isobmffbuffer.cpp:408
IsoBmffBuffer::getBox
Box * getBox(const char *name, size_t &index)
Get box handle in parsed bufferr using name.
Definition: isobmffbuffer.cpp:489
IsoBmffBuffer::isInitSegment
bool isInitSegment()
Check if buffer is an initialization segment.
Definition: isobmffbuffer.cpp:360
IsoBmffBuffer::printBoxes
void printBoxes()
Print ISOBMFF boxes.
Definition: isobmffbuffer.cpp:352
IsoBmffBuffer::getFirstPTSInternal
bool getFirstPTSInternal(const std::vector< Box * > *boxes, uint64_t &pts)
Get first PTS of buffer.
Definition: isobmffbuffer.cpp:191
IsoBmffBuffer::getBoxSizeInternal
bool getBoxSizeInternal(const std::vector< Box * > *boxes, const char *name, size_t &size)
get ISOBMFF box size of a type
Definition: isobmffbuffer.cpp:117
IsoBmffBuffer::getMdatBoxSize
bool getMdatBoxSize(size_t &size)
Get mdat buffer size.
Definition: isobmffbuffer.cpp:109
IsoBmffBuffer::getTrackIdInternal
bool getTrackIdInternal(const std::vector< Box * > *boxes, uint32_t &track_id)
Get track id from trak box.
Definition: isobmffbuffer.cpp:218
IsoBmffBuffer::getBoxesInternal
bool getBoxesInternal(const std::vector< Box * > *boxes, const char *name, std::vector< Box * > *pBoxes)
get ISOBMFF box list of a type in a parsed buffer
Definition: isobmffbuffer.cpp:417