1 /*****************************************************************
2 |
3 |    AP4 - sample entries
4 |
5 |    Copyright 2002-2008 Axiomatic Systems, LLC
6 |
7 |
8 |    This file is part of Bento4/AP4 (MP4 Atom Processing Library).
9 |
10 |    Unless you have obtained Bento4 under a difference license,
11 |    this version of Bento4 is Bento4|GPL.
12 |    Bento4|GPL is free software; you can redistribute it and/or modify
13 |    it under the terms of the GNU General Public License as published by
14 |    the Free Software Foundation; either version 2, or (at your option)
15 |    any later version.
16 |
17 |    Bento4|GPL is distributed in the hope that it will be useful,
18 |    but WITHOUT ANY WARRANTY; without even the implied warranty of
19 |    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 |    GNU General Public License for more details.
21 |
22 |    You should have received a copy of the GNU General Public License
23 |    along with Bento4|GPL; see the file COPYING.  If not, write to the
24 |    Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
25 |    02111-1307, USA.
26 |
27  ****************************************************************/
28 
29 #ifndef _AP4_SAMPLE_ENTRY_H_
30 #define _AP4_SAMPLE_ENTRY_H_
31 
32 /*----------------------------------------------------------------------
33 |   includes
34 +---------------------------------------------------------------------*/
35 #include "Ap4Types.h"
36 #include "Ap4List.h"
37 #include "Ap4Atom.h"
38 #include "Ap4EsdsAtom.h"
39 #include "Ap4AtomFactory.h"
40 #include "Ap4ContainerAtom.h"
41 
42 /*----------------------------------------------------------------------
43 |   class references
44 +---------------------------------------------------------------------*/
45 class AP4_SampleDescription;
46 class AP4_AvccAtom;
47 class AP4_HvccAtom;
48 
49 /*----------------------------------------------------------------------
50 |   AP4_SampleEntry
51 +---------------------------------------------------------------------*/
52 class AP4_SampleEntry : public AP4_ContainerAtom
53 {
54  public:
55     AP4_IMPLEMENT_DYNAMIC_CAST_D(AP4_SampleEntry, AP4_ContainerAtom)
56 
57     // methods
58     AP4_SampleEntry(AP4_Atom::Type format, const AP4_AtomParent* details = NULL);
59     AP4_SampleEntry(AP4_Atom::Type   format,
60                     AP4_Size         size,
61                     AP4_ByteStream&  stream,
62                     AP4_AtomFactory& atom_factory);
~AP4_SampleEntry()63     virtual ~AP4_SampleEntry() {}
64 
GetDataReferenceIndex()65     AP4_UI16           GetDataReferenceIndex() { return m_DataReferenceIndex; }
66     virtual AP4_Result Write(AP4_ByteStream& stream);
67     virtual AP4_Result Inspect(AP4_AtomInspector& inspector);
68     virtual AP4_SampleDescription* ToSampleDescription();
69 
70     // AP4_Atom methods
71     virtual AP4_Atom*  Clone();
72 
73     // AP4_AtomParent methods
74     virtual void OnChildChanged(AP4_Atom* child);
75 
76  protected:
77     // constructor
78     AP4_SampleEntry(AP4_Atom::Type format, AP4_Size size);
79 
80     // methods
81     virtual void       Read(AP4_ByteStream& stream, AP4_AtomFactory& atom_factory);
82     virtual AP4_Size   GetFieldsSize();
83     virtual AP4_Result ReadFields(AP4_ByteStream& stream);
84     virtual AP4_Result WriteFields(AP4_ByteStream& stream);
85     virtual AP4_Result InspectFields(AP4_AtomInspector& inspector);
86 
87     // members
88     AP4_UI08 m_Reserved1[6];         // = 0
89     AP4_UI16 m_DataReferenceIndex;
90 };
91 
92 /*----------------------------------------------------------------------
93 |   AP4_UnknownSampleEntry
94 +---------------------------------------------------------------------*/
95 class AP4_UnknownSampleEntry : public AP4_SampleEntry
96 {
97  public:
98     // constructors
99     AP4_UnknownSampleEntry(AP4_Atom::Type type, AP4_Size size, AP4_ByteStream& stream);
100     AP4_UnknownSampleEntry(AP4_Atom::Type type, AP4_DataBuffer& payload);
101 
102     // AP4_Atom methods
103     AP4_Atom* Clone();
104 
105     // AP4_SampleEntry methods
106     virtual AP4_SampleDescription* ToSampleDescription();
107 
108     // accessors
GetPayload()109     const AP4_DataBuffer& GetPayload() { return m_Payload; }
110 
111  protected:
112     // methods
113     virtual AP4_Size   GetFieldsSize();
114     virtual AP4_Result ReadFields(AP4_ByteStream& stream);
115     virtual AP4_Result WriteFields(AP4_ByteStream& stream);
116 
117     // members
118     AP4_DataBuffer m_Payload;
119 };
120 
121 /*----------------------------------------------------------------------
122 |   AP4_AudioSampleEntry
123 +---------------------------------------------------------------------*/
124 class AP4_AudioSampleEntry : public AP4_SampleEntry
125 {
126 public:
127     // methods
128     AP4_AudioSampleEntry(AP4_Atom::Type   format,
129                          AP4_UI32         sample_rate,
130                          AP4_UI16         sample_size,
131                          AP4_UI16         channel_count);
132     AP4_AudioSampleEntry(AP4_Atom::Type   format,
133                          AP4_Size         size,
134                          AP4_ByteStream&  stream,
135                          AP4_AtomFactory& atom_factory);
136 
137     // accessors
138     AP4_UI32 GetSampleRate();
GetSampleSize()139     AP4_UI16 GetSampleSize() { return m_SampleSize; }
140     AP4_UI16 GetChannelCount();
141 
142     // methods
143     AP4_SampleDescription* ToSampleDescription();
144 
145 protected:
146     // methods
147     virtual AP4_Size   GetFieldsSize();
148     virtual AP4_Result ReadFields(AP4_ByteStream& stream);
149     virtual AP4_Result WriteFields(AP4_ByteStream& stream);
150     virtual AP4_Result InspectFields(AP4_AtomInspector& inspector);
151 
152     // members
153     AP4_UI16 m_QtVersion;       // 0, 1 or 2
154     AP4_UI16 m_QtRevision;      // 0
155     AP4_UI32 m_QtVendor;        // 0
156     AP4_UI16 m_ChannelCount;
157     AP4_UI16 m_SampleSize;
158     AP4_UI16 m_QtCompressionId; // 0 or -2
159     AP4_UI16 m_QtPacketSize;    // always 0
160     AP4_UI32 m_SampleRate;      // 16.16 fixed point
161 
162     AP4_UI32 m_QtV1SamplesPerPacket;
163     AP4_UI32 m_QtV1BytesPerPacket;
164     AP4_UI32 m_QtV1BytesPerFrame;
165     AP4_UI32 m_QtV1BytesPerSample;
166 
167     AP4_UI32 m_QtV2StructSize;
168     double   m_QtV2SampleRate64;
169     AP4_UI32 m_QtV2ChannelCount;
170     AP4_UI32 m_QtV2Reserved;
171     AP4_UI32 m_QtV2BitsPerChannel;
172     AP4_UI32 m_QtV2FormatSpecificFlags;
173     AP4_UI32 m_QtV2BytesPerAudioPacket;
174     AP4_UI32 m_QtV2LPCMFramesPerAudioPacket;
175     AP4_DataBuffer m_QtV2Extension;
176 };
177 
178 /*----------------------------------------------------------------------
179 |   AP4_VisualSampleEntry
180 +---------------------------------------------------------------------*/
181 class AP4_VisualSampleEntry : public AP4_SampleEntry
182 {
183 public:
184     // methods
185     AP4_VisualSampleEntry(AP4_Atom::Type    format,
186                           AP4_UI16          width,
187                           AP4_UI16          height,
188                           AP4_UI16          depth,
189                           const char*           compressor_name,
190                           const AP4_AtomParent* details = NULL);
191     AP4_VisualSampleEntry(AP4_Atom::Type   format,
192                           AP4_Size         size,
193                           AP4_ByteStream&  stream,
194                           AP4_AtomFactory& atom_factory);
195 
196     // accessors
GetWidth()197     AP4_UI16    GetWidth()          { return m_Width;  }
GetHeight()198     AP4_UI16    GetHeight()         { return m_Height; }
GetHorizResolution()199     AP4_UI32    GetHorizResolution(){ return m_HorizResolution;  }
GetVertResolution()200     AP4_UI32    GetVertResolution() { return m_VertResolution; }
GetDepth()201     AP4_UI16    GetDepth()          { return m_Depth;  }
GetCompressorName()202     const char* GetCompressorName() { return m_CompressorName.GetChars(); }
203 
204     // methods
205     AP4_SampleDescription* ToSampleDescription();
206 
207 protected:
208     // methods
209     virtual AP4_Size   GetFieldsSize();
210     virtual AP4_Result ReadFields(AP4_ByteStream& stream);
211     virtual AP4_Result WriteFields(AP4_ByteStream& stream);
212     virtual AP4_Result InspectFields(AP4_AtomInspector& inspector);
213 
214     //members
215     AP4_UI16   m_Predefined1;     // = 0
216     AP4_UI16   m_Reserved2;       // = 0
217     AP4_UI08   m_Predefined2[12]; // = 0
218     AP4_UI16   m_Width;
219     AP4_UI16   m_Height;
220     AP4_UI32   m_HorizResolution; // = 0x00480000 (72 dpi)
221     AP4_UI32   m_VertResolution;  // = 0x00480000 (72 dpi)
222     AP4_UI32   m_Reserved3;       // = 0
223     AP4_UI16   m_FrameCount;      // = 1
224     AP4_String m_CompressorName;
225     AP4_UI16   m_Depth;           // = 0x0018
226     AP4_UI16   m_Predefined3;     // = 0xFFFF
227 };
228 
229 /*----------------------------------------------------------------------
230 |   AP4_MpegSystemSampleEntry
231 +---------------------------------------------------------------------*/
232 class AP4_MpegSystemSampleEntry : public AP4_SampleEntry
233 {
234 public:
235     // constructors
236     AP4_MpegSystemSampleEntry(AP4_UI32          type,
237                               AP4_EsDescriptor* descriptor);
238     AP4_MpegSystemSampleEntry(AP4_UI32         type,
239                               AP4_Size         size,
240                               AP4_ByteStream&  stream,
241                               AP4_AtomFactory& atom_factory);
242 
243     // methods
244     AP4_SampleDescription* ToSampleDescription();
245 };
246 
247 /*----------------------------------------------------------------------
248 |   AP4_MpegAudioSampleEntry
249 +---------------------------------------------------------------------*/
250 class AP4_MpegAudioSampleEntry : public AP4_AudioSampleEntry
251 {
252 public:
253     // constructors
254     AP4_MpegAudioSampleEntry(AP4_UI32          type,
255                              AP4_UI32          sample_rate,
256                              AP4_UI16          sample_size,
257                              AP4_UI16          channel_count,
258                              AP4_EsDescriptor* descriptor);
259     AP4_MpegAudioSampleEntry(AP4_UI32         type,
260                              AP4_Size         size,
261                              AP4_ByteStream&  stream,
262                              AP4_AtomFactory& atom_factory);
263 
264     // methods
265     AP4_SampleDescription* ToSampleDescription();
266 };
267 
268 /*----------------------------------------------------------------------
269  |   AP4_Ac3SampleEntry
270  +---------------------------------------------------------------------*/
271 class AP4_Ac3SampleEntry : public AP4_AudioSampleEntry
272 {
273 public:
274     AP4_Ac3SampleEntry(AP4_UI32              format,
275                        AP4_UI32              sample_rate,
276                        AP4_UI16              sample_size,
277                        AP4_UI16              channel_count,
278                        const AP4_AtomParent* details);
279     AP4_Ac3SampleEntry(AP4_UI32         type,
280                        AP4_Size         size,
281                        AP4_ByteStream&  stream,
282                        AP4_AtomFactory& atom_factory);
283 
284     // inherited from AP4_SampleEntry
285     virtual AP4_SampleDescription* ToSampleDescription();
286 };
287 
288 /*----------------------------------------------------------------------
289 |   AP4_Eac3SampleEntry
290 +---------------------------------------------------------------------*/
291 class AP4_Eac3SampleEntry : public AP4_AudioSampleEntry
292 {
293 public:
294     AP4_Eac3SampleEntry(AP4_UI32              format,
295                         AP4_UI32              sample_rate,
296                         AP4_UI16              sample_size,
297                         AP4_UI16              channel_count,
298                         const AP4_AtomParent* details);
299     AP4_Eac3SampleEntry(AP4_UI32         type,
300                         AP4_Size         size,
301                         AP4_ByteStream&  stream,
302                         AP4_AtomFactory& atom_factory);
303 
304     // inherited from AP4_SampleEntry
305     virtual AP4_SampleDescription* ToSampleDescription();
306 };
307 
308 
309 /*----------------------------------------------------------------------
310 |   AP4_Ac4SampleEntry
311 +---------------------------------------------------------------------*/
312 class AP4_Ac4SampleEntry : public AP4_AudioSampleEntry
313 {
314 public:
315     AP4_Ac4SampleEntry(AP4_UI32              format,
316                        AP4_UI32              sample_rate,
317                        AP4_UI16              sample_size,
318                        AP4_UI16              channel_count,
319                        const AP4_AtomParent* details);
320     AP4_Ac4SampleEntry(AP4_UI32         type,
321                        AP4_Size         size,
322                        AP4_ByteStream&  stream,
323                        AP4_AtomFactory& atom_factory);
324 
325     // inherited from AP4_SampleEntry
326     virtual AP4_SampleDescription* ToSampleDescription();
327 };
328 
329 /*----------------------------------------------------------------------
330 |   AP4_MpegVideoSampleEntry
331 +---------------------------------------------------------------------*/
332 class AP4_MpegVideoSampleEntry : public AP4_VisualSampleEntry
333 {
334 public:
335     // constructors
336     AP4_MpegVideoSampleEntry(AP4_UI32          type,
337                              AP4_UI16          width,
338                              AP4_UI16          height,
339                              AP4_UI16          depth,
340                              const char*       compressor_name,
341                              AP4_EsDescriptor* descriptor);
342     AP4_MpegVideoSampleEntry(AP4_UI32         type,
343                              AP4_Size         size,
344                              AP4_ByteStream&  stream,
345                              AP4_AtomFactory& atom_factory);
346 
347     // methods
348     AP4_SampleDescription* ToSampleDescription();
349 };
350 
351 /*----------------------------------------------------------------------
352 |   AP4_Mp4sSampleEntry
353 +---------------------------------------------------------------------*/
354 class AP4_Mp4sSampleEntry : public AP4_MpegSystemSampleEntry
355 {
356  public:
357     // constructors
358     AP4_Mp4sSampleEntry(AP4_Size         size,
359                         AP4_ByteStream&  stream,
360                         AP4_AtomFactory& atom_factory);
361     AP4_Mp4sSampleEntry(AP4_EsDescriptor* descriptor);
362 
363     // methods
364     AP4_SampleDescription* ToSampleDescription();
365 };
366 
367 /*----------------------------------------------------------------------
368 |   AP4_Mp4aSampleEntry
369 +---------------------------------------------------------------------*/
370 class AP4_Mp4aSampleEntry : public AP4_MpegAudioSampleEntry
371 {
372  public:
373     // constructors
374     AP4_Mp4aSampleEntry(AP4_Size         size,
375                         AP4_ByteStream&  stream,
376                         AP4_AtomFactory& atom_factory);
377     AP4_Mp4aSampleEntry(AP4_UI32          sample_rate,
378                         AP4_UI16          sample_size,
379                         AP4_UI16          channel_count,
380                         AP4_EsDescriptor* descriptor);
381 };
382 
383 /*----------------------------------------------------------------------
384 |   AP4_Mp4vSampleEntry
385 +---------------------------------------------------------------------*/
386 class AP4_Mp4vSampleEntry : public AP4_MpegVideoSampleEntry
387 {
388  public:
389     // constructors
390     AP4_Mp4vSampleEntry(AP4_Size         size,
391                         AP4_ByteStream&  stream,
392                         AP4_AtomFactory& atom_factory);
393 
394     AP4_Mp4vSampleEntry(AP4_UI16          width,
395                         AP4_UI16          height,
396                         AP4_UI16          depth,
397                         const char*       compressor_name,
398                         AP4_EsDescriptor* descriptor);
399 };
400 
401 /*----------------------------------------------------------------------
402 |   AP4_AvcSampleEntry
403 +---------------------------------------------------------------------*/
404 class AP4_AvcSampleEntry : public AP4_VisualSampleEntry
405 {
406 public:
407     // constructors
408     AP4_AvcSampleEntry(AP4_UI32         format, // avc1, avc2, avc3, avc4
409                        AP4_Size         size,
410                        AP4_ByteStream&  stream,
411                        AP4_AtomFactory& atom_factory);
412 
413     AP4_AvcSampleEntry(AP4_UI32            format, // avc1, avc2, avc3, avc4
414                        AP4_UI16            width,
415                        AP4_UI16            height,
416                        AP4_UI16            depth,
417                        const char*         compressor_name,
418                        const AP4_AtomParent* details);
419 
420     // inherited from AP4_SampleEntry
421     virtual AP4_SampleDescription* ToSampleDescription();
422 };
423 
424 /*----------------------------------------------------------------------
425 |   AP4_HevcSampleEntry
426 +---------------------------------------------------------------------*/
427 class AP4_HevcSampleEntry : public AP4_VisualSampleEntry
428 {
429 public:
430     // constructors
431     AP4_HevcSampleEntry(AP4_UI32         format, // hvc1, hev1
432                         AP4_Size         size,
433                         AP4_ByteStream&  stream,
434                         AP4_AtomFactory& atom_factory);
435 
436     AP4_HevcSampleEntry(AP4_UI32            format, // hvc1, hev1
437                         AP4_UI16            width,
438                         AP4_UI16            height,
439                         AP4_UI16            depth,
440                         const char*         compressor_name,
441                         const AP4_AtomParent* details);
442 
443     // inherited from AP4_SampleEntry
444     virtual AP4_SampleDescription* ToSampleDescription();
445 };
446 
447 /*----------------------------------------------------------------------
448 |   AP4_Av1SampleEntry
449 +---------------------------------------------------------------------*/
450 class AP4_Av1SampleEntry : public AP4_VisualSampleEntry
451 {
452 public:
453     // constructors
454     AP4_Av1SampleEntry(AP4_UI32         format, // av01
455                        AP4_Size         size,
456                        AP4_ByteStream&  stream,
457                        AP4_AtomFactory& atom_factory);
458 
459     AP4_Av1SampleEntry(AP4_UI32              format, // av01
460                        AP4_UI16              width,
461                        AP4_UI16              height,
462                        AP4_UI16              depth,
463                        const char*           compressor_name,
464                        const AP4_AtomParent* details);
465 
466     // inherited from AP4_SampleEntry
467     virtual AP4_SampleDescription* ToSampleDescription();
468 };
469 
470 /*----------------------------------------------------------------------
471 |   AP4_RtpHintSampleEntry
472 +---------------------------------------------------------------------*/
473 class AP4_RtpHintSampleEntry : public AP4_SampleEntry
474 {
475 public:
476     // methods
477     AP4_RtpHintSampleEntry(AP4_UI16 hint_track_version,
478                            AP4_UI16 highest_compatible_version,
479                            AP4_UI32 max_packet_size,
480                            AP4_UI32 timescale);
481     AP4_RtpHintSampleEntry(AP4_Size         size,
482                            AP4_ByteStream&  stream,
483                            AP4_AtomFactory& atom_factory);
484 
485 protected:
486     // methods
487     virtual AP4_Size   GetFieldsSize();
488     virtual AP4_Result ReadFields(AP4_ByteStream& stream);
489     virtual AP4_Result WriteFields(AP4_ByteStream& stream);
490     virtual AP4_Result InspectFields(AP4_AtomInspector& inspector);
491 
492     // members
493     AP4_UI16 m_HintTrackVersion;
494     AP4_UI16 m_HighestCompatibleVersion;
495     AP4_UI32 m_MaxPacketSize;
496 };
497 
498 /*----------------------------------------------------------------------
499 |   AP4_SubtitleSampleEntry
500 +---------------------------------------------------------------------*/
501 class AP4_SubtitleSampleEntry : public AP4_SampleEntry
502 {
503 public:
504     // methods
505     AP4_SubtitleSampleEntry(AP4_Atom::Type format,
506                             const char* namespce,
507                             const char* schema_location,
508                             const char* image_mime_type);
509     AP4_SubtitleSampleEntry(AP4_Atom::Type   format,
510                             AP4_Size         size,
511                             AP4_ByteStream&  stream,
512                             AP4_AtomFactory& atom_factory);
513 
514     // accessors
515 
516     // methods
517     AP4_SampleDescription* ToSampleDescription();
518 
519 protected:
520     // methods
521     virtual AP4_Size   GetFieldsSize();
522     virtual AP4_Result ReadFields(AP4_ByteStream& stream);
523     virtual AP4_Result WriteFields(AP4_ByteStream& stream);
524     virtual AP4_Result InspectFields(AP4_AtomInspector& inspector);
525 
526     // members
527     AP4_String m_Namespace;
528     AP4_String m_SchemaLocation;
529     AP4_String m_ImageMimeType;
530 };
531 
532 #endif // _AP4_SAMPLE_ENTRY_H_
533