qtdemux: Add/Fix comments on the various structure variables
[platform/upstream/gst-plugins-good.git] / gst / isomp4 / atoms.h
1 /* Quicktime muxer plugin for GStreamer
2  * Copyright (C) 2008-2010 Thiago Santos <thiagoss@embedded.ufcg.edu.br>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19 /*
20  * Unless otherwise indicated, Source Code is licensed under MIT license.
21  * See further explanation attached in License Statement (distributed in the file
22  * LICENSE).
23  *
24  * Permission is hereby granted, free of charge, to any person obtaining a copy of
25  * this software and associated documentation files (the "Software"), to deal in
26  * the Software without restriction, including without limitation the rights to
27  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
28  * of the Software, and to permit persons to whom the Software is furnished to do
29  * so, subject to the following conditions:
30  *
31  * The above copyright notice and this permission notice shall be included in all
32  * copies or substantial portions of the Software.
33  *
34  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
35  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
36  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
37  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
38  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
39  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
40  * SOFTWARE.
41  */
42
43 #ifndef __ATOMS_H__
44 #define __ATOMS_H__
45
46 #include <glib.h>
47 #include <string.h>
48
49 #include "descriptors.h"
50 #include "properties.h"
51 #include "fourcc.h"
52
53 /* helper storage struct */
54 #define ATOM_ARRAY(struct_type) \
55 struct { \
56   guint size; \
57   guint len; \
58   struct_type *data; \
59 }
60
61 /* storage helpers */
62
63 #define atom_array_init(array, reserve)                                       \
64 G_STMT_START {                                                                \
65   (array)->len = 0;                                                           \
66   (array)->size = reserve;                                                    \
67   (array)->data = g_malloc (sizeof (*(array)->data) * reserve);               \
68 } G_STMT_END
69
70 #define atom_array_append(array, elmt, inc)                                   \
71 G_STMT_START {                                                                \
72   g_assert ((array)->data);                                                   \
73   g_assert (inc > 0);                                                         \
74   if (G_UNLIKELY ((array)->len == (array)->size)) {                           \
75     (array)->size += inc;                                                     \
76     (array)->data =                                                           \
77         g_realloc ((array)->data, sizeof (*((array)->data)) * (array)->size); \
78   }                                                                           \
79   (array)->data[(array)->len] = elmt;                                         \
80   (array)->len++;                                                             \
81 } G_STMT_END
82
83 #define atom_array_get_len(array)                  ((array)->len)
84 #define atom_array_index(array, index)             ((array)->data[index])
85
86 #define atom_array_clear(array)                                               \
87 G_STMT_START {                                                                \
88   (array)->size = (array)->len = 0;                                           \
89   g_free ((array)->data);                                                     \
90   (array)->data = NULL;                                                       \
91 } G_STMT_END
92
93 /* light-weight context that may influence header atom tree construction */
94 typedef enum _AtomsTreeFlavor
95 {
96   ATOMS_TREE_FLAVOR_MOV,
97   ATOMS_TREE_FLAVOR_ISOM,
98   ATOMS_TREE_FLAVOR_3GP,
99   ATOMS_TREE_FLAVOR_ISML
100 } AtomsTreeFlavor;
101
102 typedef struct _AtomsContext
103 {
104   AtomsTreeFlavor flavor;
105 } AtomsContext;
106
107 AtomsContext* atoms_context_new  (AtomsTreeFlavor flavor);
108 void          atoms_context_free (AtomsContext *context);
109
110 #define METADATA_DATA_FLAG 0x0
111 #define METADATA_TEXT_FLAG 0x1
112
113 /* atom defs and functions */
114
115 /*
116  * Used for storing time related values for some atoms.
117  */
118 typedef struct _TimeInfo
119 {
120   guint64 creation_time;
121   guint64 modification_time;
122   guint32 timescale;
123   guint64 duration;
124 } TimeInfo;
125
126 typedef struct _Atom
127 {
128   guint32 size;
129   guint32 type;
130   guint64 extended_size;
131 } Atom;
132
133 typedef struct _AtomFull
134 {
135   Atom header;
136
137   guint8 version;
138   guint8 flags[3];
139 } AtomFull;
140
141 /*
142  * Generic extension atom
143  */
144 typedef struct _AtomData
145 {
146   Atom header;
147
148   /* not written */
149   guint32 datalen;
150
151   guint8 *data;
152 } AtomData;
153
154 typedef struct _AtomUUID
155 {
156   Atom header;
157
158   guint8 uuid[16];
159
160   /* not written */
161   guint32 datalen;
162
163   guint8 *data;
164 } AtomUUID;
165
166 typedef struct _AtomFTYP
167 {
168   Atom header;
169   guint32 major_brand;
170   guint32 version;
171   guint32 *compatible_brands;
172
173   /* not written */
174   guint32 compatible_brands_size;
175 } AtomFTYP;
176
177 typedef struct _AtomMVHD
178 {
179   AtomFull header;
180
181   /* version 0: 32 bits */
182   TimeInfo time_info;
183
184   guint32 prefered_rate;      /* ISO: 0x00010000 */
185   guint16 volume;             /* ISO: 0x0100 */
186   guint16 reserved3;          /* ISO: 0x0 */
187   guint32 reserved4[2];       /* ISO: 0, 0 */
188   /* ISO: identity matrix =
189    * { 0x00010000, 0, 0, 0, 0x00010000, 0, 0, 0, 0x40000000 } */
190   guint32 matrix[9];
191
192   /* ISO: all 0 */
193   guint32 preview_time;
194   guint32 preview_duration;
195   guint32 poster_time;
196   guint32 selection_time;
197   guint32 selection_duration;
198   guint32 current_time;
199
200   guint32 next_track_id;
201 } AtomMVHD;
202
203 typedef struct _AtomTKHD
204 {
205   AtomFull header;
206
207   /* version 0: 32 bits */
208   /* like the TimeInfo struct, but it has this track_ID inside */
209   guint64 creation_time;
210   guint64 modification_time;
211   guint32 track_ID;
212   guint32 reserved;
213   guint64 duration;
214
215   guint32 reserved2[2];
216   guint16 layer;
217   guint16 alternate_group;
218   guint16 volume;
219   guint16 reserved3;
220
221   /* ISO: identity matrix =
222    * { 0x00010000, 0, 0, 0, 0x00010000, 0, 0, 0, 0x40000000 } */
223   guint32 matrix[9];
224   guint32 width;
225   guint32 height;
226 } AtomTKHD;
227
228 typedef struct _AtomMDHD
229 {
230   AtomFull header;
231
232   /* version 0: 32 bits */
233   TimeInfo time_info;
234
235   /* ISO: packed ISO-639-2/T language code (first bit must be 0) */
236   guint16 language_code;
237   /* ISO: 0 */
238   guint16 quality;
239 } AtomMDHD;
240
241 typedef struct _AtomHDLR
242 {
243   AtomFull header;
244
245   /* ISO: 0 */
246   guint32 component_type;
247   guint32 handler_type;
248   guint32 manufacturer;
249   guint32 flags;
250   guint32 flags_mask;
251   gchar *name;
252
253   AtomsTreeFlavor flavor;
254 } AtomHDLR;
255
256 typedef struct _AtomVMHD
257 {
258   AtomFull header;          /* ISO: flags = 1 */
259
260   guint16 graphics_mode;
261   /* RGB */
262   guint16 opcolor[3];
263 } AtomVMHD;
264
265 typedef struct _AtomSMHD
266 {
267   AtomFull header;
268
269   guint16 balance;
270   guint16 reserved;
271 } AtomSMHD;
272
273 typedef struct _AtomHMHD
274 {
275   AtomFull header;
276
277   guint16 max_pdu_size;
278   guint16 avg_pdu_size;
279   guint32 max_bitrate;
280   guint32 avg_bitrate;
281   guint32 sliding_avg_bitrate;
282 } AtomHMHD;
283
284 typedef struct _AtomURL
285 {
286   AtomFull header;
287
288   gchar *location;
289 } AtomURL;
290
291 typedef struct _AtomDREF
292 {
293   AtomFull header;
294
295   GList *entries;
296 } AtomDREF;
297
298 typedef struct _AtomDINF
299 {
300   Atom header;
301
302   AtomDREF dref;
303 } AtomDINF;
304
305 typedef struct _STTSEntry
306 {
307   guint32 sample_count;
308   gint32 sample_delta;
309 } STTSEntry;
310
311 typedef struct _AtomSTTS
312 {
313   AtomFull header;
314
315   ATOM_ARRAY (STTSEntry) entries;
316 } AtomSTTS;
317
318 typedef struct _AtomSTSS
319 {
320   AtomFull header;
321
322   ATOM_ARRAY (guint32) entries;
323 } AtomSTSS;
324
325 typedef struct _AtomESDS
326 {
327   AtomFull header;
328
329   ESDescriptor es;
330 } AtomESDS;
331
332 typedef struct _AtomFRMA
333 {
334   Atom header;
335
336   guint32 media_type;
337 } AtomFRMA;
338
339 typedef enum _SampleEntryKind
340 {
341   UNKNOWN,
342   AUDIO,
343   VIDEO,
344   SUBTITLE,
345 } SampleEntryKind;
346
347 typedef struct _SampleTableEntry
348 {
349   Atom header;
350
351   guint8 reserved[6];
352   guint16 data_reference_index;
353
354   /* type of entry */
355   SampleEntryKind kind;
356 } SampleTableEntry;
357
358 typedef struct _AtomHintSampleEntry
359 {
360   SampleTableEntry se;
361   guint32 size;
362   guint8 *data;
363 } AtomHintSampleEntry;
364
365 typedef struct _SampleTableEntryMP4V
366 {
367   SampleTableEntry se;
368
369   guint16 version;
370   guint16 revision_level;
371
372   guint32 vendor;                 /* fourcc code */
373   guint32 temporal_quality;
374   guint32 spatial_quality;
375
376   guint16 width;
377   guint16 height;
378
379   guint32 horizontal_resolution;
380   guint32 vertical_resolution;
381   guint32 datasize;
382
383   guint16 frame_count;            /* usually 1 */
384
385   guint8 compressor[32];         /* pascal string, i.e. first byte = length */
386
387   guint16 depth;
388   guint16 color_table_id;
389
390   /* (optional) list of AtomInfo */
391   GList *extension_atoms;
392 } SampleTableEntryMP4V;
393
394 typedef struct _SampleTableEntryMP4A
395 {
396   SampleTableEntry se;
397
398   guint16 version;
399   guint16 revision_level;
400   guint32 vendor;
401
402   guint16 channels;
403   guint16 sample_size;
404   guint16 compression_id;
405   guint16 packet_size;
406
407   guint32 sample_rate;            /* fixed point 16.16 */
408
409   guint32 samples_per_packet;
410   guint32 bytes_per_packet;
411   guint32 bytes_per_frame;
412   guint32 bytes_per_sample;
413
414   /* (optional) list of AtomInfo */
415   GList *extension_atoms;
416 } SampleTableEntryMP4A;
417
418 typedef struct _SampleTableEntryTX3G
419 {
420   SampleTableEntry se;
421
422   guint32 display_flags;
423   guint64 default_text_box;
424   guint16 font_id;
425   guint8  font_face; /* bold=0x1, italic=0x2, underline=0x4 */
426   guint8  font_size; /* should always be 0.05 multiplied by the video track header height */
427   guint32 foreground_color_rgba;
428
429 } SampleTableEntryTX3G;
430
431 typedef struct _AtomSTSD
432 {
433   AtomFull header;
434
435   guint n_entries;
436   /* list of subclasses of SampleTableEntry */
437   GList *entries;
438 } AtomSTSD;
439
440 typedef struct _AtomSTSZ
441 {
442   AtomFull header;
443
444   guint32 sample_size;
445
446   /* need the size here because when sample_size is constant,
447    * the list is empty */
448   guint32 table_size;
449   ATOM_ARRAY (guint32) entries;
450 } AtomSTSZ;
451
452 typedef struct _STSCEntry
453 {
454   guint32 first_chunk;
455   guint32 samples_per_chunk;
456   guint32 sample_description_index;
457 } STSCEntry;
458
459 typedef struct _AtomSTSC
460 {
461   AtomFull header;
462
463   ATOM_ARRAY (STSCEntry) entries;
464 } AtomSTSC;
465
466
467 /*
468  * used for both STCO and CO64
469  * if used as STCO, entries should be truncated to use only 32bits
470  */
471 typedef struct _AtomSTCO64
472 {
473   AtomFull header;
474   /* Global offset to add to entries when serialising */
475   guint32 chunk_offset;
476   ATOM_ARRAY (guint64) entries;
477 } AtomSTCO64;
478
479 typedef struct _CTTSEntry
480 {
481   guint32 samplecount;
482   guint32 sampleoffset;
483 } CTTSEntry;
484
485 typedef struct _AtomCTTS
486 {
487   AtomFull header;
488
489   /* also entry count here */
490   ATOM_ARRAY (CTTSEntry) entries;
491   gboolean do_pts;
492 } AtomCTTS;
493
494 typedef struct _AtomSTBL
495 {
496   Atom header;
497
498   AtomSTSD stsd;
499   AtomSTTS stts;
500   AtomSTSS stss;
501   AtomSTSC stsc;
502   AtomSTSZ stsz;
503   /* NULL if not present */
504   AtomCTTS *ctts;
505
506   AtomSTCO64 stco64;
507 } AtomSTBL;
508
509 typedef struct _AtomMINF
510 {
511   Atom header;
512
513   /* only (exactly) one of those must be present */
514   AtomVMHD *vmhd;
515   AtomSMHD *smhd;
516   AtomHMHD *hmhd;
517
518   AtomHDLR *hdlr;
519   AtomDINF dinf;
520   AtomSTBL stbl;
521 } AtomMINF;
522
523 typedef struct _EditListEntry
524 {
525   /* duration in movie's timescale */
526   guint32 duration;
527   /* start time in media's timescale, -1 for empty */
528   guint32 media_time;
529   guint32 media_rate;  /* fixed point 32 bit */
530 } EditListEntry;
531
532 typedef struct _AtomELST
533 {
534   AtomFull header;
535
536   /* number of entries is implicit */
537   GSList *entries;
538 } AtomELST;
539
540 typedef struct _AtomEDTS
541 {
542   Atom header;
543   AtomELST elst;
544 } AtomEDTS;
545
546 typedef struct _AtomMDIA
547 {
548   Atom header;
549
550   AtomMDHD mdhd;
551   AtomHDLR hdlr;
552   AtomMINF minf;
553 } AtomMDIA;
554
555 typedef struct _AtomILST
556 {
557   Atom header;
558
559   /* list of AtomInfo */
560   GList* entries;
561 } AtomILST;
562
563 typedef struct _AtomTagData
564 {
565   AtomFull header;
566   guint32 reserved;
567
568   guint32 datalen;
569   guint8* data;
570 } AtomTagData;
571
572 typedef struct _AtomTag
573 {
574   Atom header;
575
576   AtomTagData data;
577 } AtomTag;
578
579 typedef struct _AtomMETA
580 {
581   AtomFull header;
582   AtomHDLR hdlr;
583   AtomILST *ilst;
584 } AtomMETA;
585
586 typedef struct _AtomUDTA
587 {
588   Atom header;
589
590   /* list of AtomInfo */
591   GList* entries;
592   /* or list is further down */
593   AtomMETA *meta;
594
595   AtomsContext *context;
596 } AtomUDTA;
597
598 enum TrFlags
599 {
600   TR_DATA_OFFSET              = 0x01,     /* data-offset-present */
601   TR_FIRST_SAMPLE_FLAGS       = 0x04,     /* first-sample-flags-present */
602   TR_SAMPLE_DURATION          = 0x0100,   /* sample-duration-present */
603   TR_SAMPLE_SIZE              = 0x0200,   /* sample-size-present */
604   TR_SAMPLE_FLAGS             = 0x0400,   /* sample-flags-present */
605   TR_COMPOSITION_TIME_OFFSETS = 0x0800    /* sample-composition-time-offsets-presents */
606 };
607
608 enum TfFlags
609 {
610   TF_BASE_DATA_OFFSET         = 0x01,     /* base-data-offset-present */
611   TF_SAMPLE_DESCRIPTION_INDEX = 0x02,     /* sample-description-index-present */
612   TF_DEFAULT_SAMPLE_DURATION  = 0x08,     /* default-sample-duration-present */
613   TF_DEFAULT_SAMPLE_SIZE      = 0x010,    /* default-sample-size-present */
614   TF_DEFAULT_SAMPLE_FLAGS     = 0x020,    /* default-sample-flags-present */
615   TF_DURATION_IS_EMPTY        = 0x010000, /* sample-composition-time-offsets-presents */
616   TF_DEFAULT_BASE_IS_MOOF     = 0x020000  /* default-base-is-moof */
617 };
618
619 typedef struct _AtomTRAK
620 {
621   Atom header;
622
623   AtomTKHD tkhd;
624   AtomEDTS *edts;
625   AtomMDIA mdia;
626   AtomUDTA udta;
627
628   /* some helper info for structural conformity checks */
629   gboolean is_video;
630   gboolean is_h264;
631
632   AtomsContext *context;
633 } AtomTRAK;
634
635 typedef struct _AtomTREX
636 {
637   AtomFull header;
638
639   guint32 track_ID;
640   guint32 default_sample_description_index;
641   guint32 default_sample_duration;
642   guint32 default_sample_size;
643   guint32 default_sample_flags;
644 } AtomTREX;
645
646 typedef struct _AtomMEHD
647 {
648   AtomFull header;
649
650   guint64 fragment_duration;
651 } AtomMEHD;
652
653
654 typedef struct _AtomMVEX
655 {
656   Atom header;
657
658   AtomMEHD mehd;
659
660   /* list of AtomTREX */
661   GList *trexs;
662 } AtomMVEX;
663
664 typedef struct _AtomMFHD
665 {
666   AtomFull header;
667
668   guint32 sequence_number;
669 } AtomMFHD;
670
671 typedef struct _AtomTFHD
672 {
673   AtomFull header;
674
675   guint32 track_ID;
676   guint64 base_data_offset;
677   guint32 sample_description_index;
678   guint32 default_sample_duration;
679   guint32 default_sample_size;
680   guint32 default_sample_flags;
681 } AtomTFHD;
682
683 typedef struct _TRUNSampleEntry
684 {
685   guint32 sample_duration;
686   guint32 sample_size;
687   guint32 sample_flags;
688   guint32 sample_composition_time_offset;
689 } TRUNSampleEntry;
690
691 typedef struct _AtomTRUN
692 {
693   AtomFull header;
694
695   guint32 sample_count;
696   gint32 data_offset;
697   guint32 first_sample_flags;
698
699   /* array of fields */
700   ATOM_ARRAY (TRUNSampleEntry) entries;
701 } AtomTRUN;
702
703 typedef struct _AtomSDTP
704 {
705   AtomFull header;
706
707   /* not serialized */
708   guint32 sample_count;
709
710   /* array of fields */
711   ATOM_ARRAY (guint8) entries;
712 } AtomSDTP;
713
714 typedef struct _AtomTRAF
715 {
716   Atom header;
717
718   AtomTFHD tfhd;
719
720   /* list of AtomTRUN */
721   GList *truns;
722   /* list of AtomSDTP */
723   GList *sdtps;
724 } AtomTRAF;
725
726 typedef struct _AtomMOOF
727 {
728   Atom header;
729
730   AtomMFHD mfhd;
731
732   /* list of AtomTRAF */
733   GList *trafs;
734 } AtomMOOF;
735
736
737 typedef struct _AtomMOOV
738 {
739   /* style */
740   AtomsContext context;
741
742   Atom header;
743
744   AtomMVHD mvhd;
745   AtomMVEX mvex;
746
747   /* list of AtomTRAK */
748   GList *traks;
749   AtomUDTA udta;
750
751   gboolean fragmented;
752   guint32 chunks_offset;
753 } AtomMOOV;
754
755 typedef struct _AtomWAVE
756 {
757   Atom header;
758
759   /* list of AtomInfo */
760   GList *extension_atoms;
761 } AtomWAVE;
762
763 typedef struct _TFRAEntry
764 {
765   guint64 time;
766   guint64 moof_offset;
767   guint32 traf_number;
768   guint32 trun_number;
769   guint32 sample_number;
770 } TFRAEntry;
771
772 typedef struct _AtomTFRA
773 {
774   AtomFull header;
775
776   guint32 track_ID;
777   guint32 lengths;
778   /* array of entries */
779   ATOM_ARRAY (TFRAEntry) entries;
780 } AtomTFRA;
781
782 typedef struct _AtomMFRA
783 {
784   Atom header;
785
786   /* list of tfra */
787   GList *tfras;
788 } AtomMFRA;
789
790 /*
791  * Function to serialize an atom
792  */
793 typedef guint64 (*AtomCopyDataFunc) (Atom *atom, guint8 **buffer, guint64 *size, guint64 *offset);
794
795 /*
796  * Releases memory allocated by an atom
797  */
798 typedef guint64 (*AtomFreeFunc) (Atom *atom);
799
800 /*
801  * Some atoms might have many optional different kinds of child atoms, so this
802  * is useful for enabling generic handling of any atom.
803  * All we need are the two functions (copying it to an array
804  * for serialization and the memory releasing function).
805  */
806 typedef struct _AtomInfo
807 {
808   Atom *atom;
809   AtomCopyDataFunc copy_data_func;
810   AtomFreeFunc free_func;
811 } AtomInfo;
812
813
814 guint64    atom_copy_data              (Atom *atom, guint8 **buffer,
815                                         guint64 *size, guint64* offset);
816
817 AtomFTYP*  atom_ftyp_new               (AtomsContext *context, guint32 major,
818                                         guint32 version, GList *brands);
819 guint64    atom_ftyp_copy_data         (AtomFTYP *ftyp, guint8 **buffer,
820                                         guint64 *size, guint64 *offset);
821 void       atom_ftyp_free              (AtomFTYP *ftyp);
822
823 AtomTRAK*  atom_trak_new               (AtomsContext *context);
824 void       atom_trak_add_samples       (AtomTRAK * trak, guint32 nsamples, guint32 delta,
825                                         guint32 size, guint64 chunk_offset, gboolean sync,
826                                         gint64 pts_offset);
827 void       atom_trak_set_elst_entry    (AtomTRAK * trak, gint index, guint32 duration,
828                                         guint32 media_time, guint32 rate);
829 guint32    atom_trak_get_timescale     (AtomTRAK *trak);
830 guint32    atom_trak_get_id            (AtomTRAK * trak);
831 void       atom_stbl_add_samples       (AtomSTBL * stbl, guint32 nsamples,
832                                         guint32 delta, guint32 size,
833                                         guint64 chunk_offset, gboolean sync,
834                                         gint64 pts_offset);
835
836 AtomMOOV*  atom_moov_new               (AtomsContext *context);
837 void       atom_moov_free              (AtomMOOV *moov);
838 guint64    atom_moov_copy_data         (AtomMOOV *atom, guint8 **buffer, guint64 *size, guint64* offset);
839 void       atom_moov_update_timescale  (AtomMOOV *moov, guint32 timescale);
840 void       atom_moov_update_duration   (AtomMOOV *moov);
841 void       atom_moov_set_fragmented    (AtomMOOV *moov, gboolean fragmented);
842 void       atom_moov_chunks_set_offset (AtomMOOV *moov, guint32 offset);
843 void       atom_moov_add_trak          (AtomMOOV *moov, AtomTRAK *trak);
844 guint      atom_moov_get_trak_count    (AtomMOOV *moov);
845
846 guint64    atom_mvhd_copy_data         (AtomMVHD * atom, guint8 ** buffer,
847                                         guint64 * size, guint64 * offset);
848 void       atom_stco64_chunks_set_offset (AtomSTCO64 * stco64, guint32 offset);
849 guint64    atom_trak_copy_data         (AtomTRAK * atom, guint8 ** buffer,
850                                         guint64 * size, guint64 * offset);
851 void       atom_stbl_clear             (AtomSTBL * stbl);
852 void       atom_stbl_init              (AtomSTBL * stbl);
853 guint64    atom_stss_copy_data         (AtomSTSS *atom, guint8 **buffer,
854                                         guint64 *size, guint64* offset);
855 guint64    atom_stts_copy_data         (AtomSTTS *atom, guint8 **buffer,
856                                         guint64 *size, guint64* offset);
857 guint64    atom_stsc_copy_data         (AtomSTSC *atom, guint8 **buffer,
858                                         guint64 *size, guint64* offset);
859 guint64    atom_stsz_copy_data         (AtomSTSZ *atom, guint8 **buffer,
860                                         guint64 *size, guint64* offset);
861 guint64    atom_ctts_copy_data         (AtomCTTS *atom, guint8 **buffer,
862                                         guint64 *size, guint64* offset);
863 guint64    atom_stco64_copy_data       (AtomSTCO64 *atom, guint8 **buffer,
864                                         guint64 *size, guint64* offset);
865 AtomMOOF*  atom_moof_new               (AtomsContext *context, guint32 sequence_number);
866 void       atom_moof_free              (AtomMOOF *moof);
867 guint64    atom_moof_copy_data         (AtomMOOF *moof, guint8 **buffer, guint64 *size, guint64* offset);
868 AtomTRAF * atom_traf_new               (AtomsContext * context, guint32 track_ID);
869 void       atom_traf_free              (AtomTRAF * traf);
870 void       atom_traf_add_samples       (AtomTRAF * traf, guint32 delta,
871                                         guint32 size, gboolean sync, gint64 pts_offset,
872                                         gboolean sdtp_sync);
873 guint32    atom_traf_get_sample_num    (AtomTRAF * traf);
874 void       atom_moof_add_traf          (AtomMOOF *moof, AtomTRAF *traf);
875
876 AtomMFRA*  atom_mfra_new               (AtomsContext *context);
877 void       atom_mfra_free              (AtomMFRA *mfra);
878 AtomTFRA*  atom_tfra_new               (AtomsContext *context, guint32 track_ID);
879 void       atom_tfra_add_entry         (AtomTFRA *tfra, guint64 dts, guint32 sample_num);
880 void       atom_tfra_update_offset     (AtomTFRA * tfra, guint64 offset);
881 void       atom_mfra_add_tfra          (AtomMFRA *mfra, AtomTFRA *tfra);
882 guint64    atom_mfra_copy_data         (AtomMFRA *mfra, guint8 **buffer, guint64 *size, guint64* offset);
883
884
885 /* media sample description related helpers */
886
887 typedef struct
888 {
889   guint16 version;
890   guint32 fourcc;
891   guint width;
892   guint height;
893   guint depth;
894   guint frame_count;
895   gint color_table_id;
896   guint par_n;
897   guint par_d;
898
899   GstBuffer *codec_data;
900 } VisualSampleEntry;
901
902 typedef struct
903 {
904   guint32 fourcc;
905   guint version;
906   gint compression_id;
907   guint sample_rate;
908   guint channels;
909   guint sample_size;
910   guint bytes_per_packet;
911   guint samples_per_packet;
912   guint bytes_per_sample;
913   guint bytes_per_frame;
914
915   GstBuffer *codec_data;
916 } AudioSampleEntry;
917
918 typedef struct
919 {
920   guint32 fourcc;
921
922   guint8  font_face; /* bold=0x1, italic=0x2, underline=0x4 */
923   guint8  font_size;
924   guint32 foreground_color_rgba;
925 } SubtitleSampleEntry;
926
927 void subtitle_sample_entry_init (SubtitleSampleEntry * entry);
928
929 SampleTableEntryMP4A * atom_trak_set_audio_type (AtomTRAK * trak, AtomsContext * context,
930                                AudioSampleEntry * entry, guint32 scale,
931                                AtomInfo * ext, gint sample_size);
932
933 SampleTableEntryMP4V * atom_trak_set_video_type (AtomTRAK * trak, AtomsContext * context,
934                                VisualSampleEntry * entry, guint32 rate,
935                                GList * ext_atoms_list);
936
937 SampleTableEntryTX3G * atom_trak_set_subtitle_type (AtomTRAK * trak, AtomsContext * context,
938                                SubtitleSampleEntry * entry);
939
940 void atom_trak_update_bitrates (AtomTRAK * trak, guint32 avg_bitrate,
941                                 guint32 max_bitrate);
942
943 void atom_trak_tx3g_update_dimension (AtomTRAK * trak, guint32 width,
944                                       guint32 height);
945
946 void sample_table_entry_add_ext_atom (SampleTableEntry * ste, AtomInfo * ext);
947
948 AtomInfo *   build_codec_data_extension  (guint32 fourcc, const GstBuffer * codec_data);
949 AtomInfo *   build_mov_aac_extension     (AtomTRAK * trak, const GstBuffer * codec_data,
950                                           guint32 avg_bitrate, guint32 max_bitrate);
951 AtomInfo *   build_mov_alac_extension    (const GstBuffer * codec_data);
952 AtomInfo *   build_esds_extension        (AtomTRAK * trak, guint8 object_type,
953                                           guint8 stream_type, const GstBuffer * codec_data,
954                                           guint32 avg_bitrate, guint32 max_bitrate);
955 AtomInfo *   build_btrt_extension        (guint32 buffer_size_db, guint32 avg_bitrate,
956                                           guint32 max_bitrate);
957 AtomInfo *   build_jp2h_extension        (gint width, gint height, const gchar *colorspace,
958                                           gint ncomp, const GValue * cmap_array,
959                                           const GValue * cdef_array);
960
961 AtomInfo *   build_jp2x_extension        (const GstBuffer * prefix);
962 AtomInfo *   build_fiel_extension        (gint fields);
963 AtomInfo *   build_ac3_extension         (guint8 fscod, guint8 bsid,
964                                           guint8 bsmod, guint8 acmod,
965                                           guint8 lfe_on, guint8 bitrate_code);
966 AtomInfo *   build_opus_extension        (guint32 rate, guint8 channels, guint8 mapping_family,
967                                           guint8 stream_count, guint8 coupled_count,
968                                           guint8 channel_mapping[256], guint16 pre_skip,
969                                           guint16 output_gain);
970
971 AtomInfo *   build_amr_extension         (void);
972 AtomInfo *   build_h263_extension        (void);
973 AtomInfo *   build_gama_atom             (gdouble gamma);
974 AtomInfo *   build_SMI_atom              (const GstBuffer *seqh);
975 AtomInfo *   build_ima_adpcm_extension   (gint channels, gint rate,
976                                           gint blocksize);
977 AtomInfo *   build_uuid_xmp_atom         (GstBuffer * xmp);
978
979
980 /*
981  * Meta tags functions
982  */
983 void atom_udta_clear_tags (AtomUDTA *udta);
984 void atom_udta_add_str_tag    (AtomUDTA *udta, guint32 fourcc, const gchar *value);
985 void atom_udta_add_uint_tag   (AtomUDTA *udta, guint32 fourcc, guint32 flags,
986                                guint32 value);
987 void atom_udta_add_tag        (AtomUDTA *udta, guint32 fourcc, guint32 flags,
988                                const guint8 * data, guint size);
989 void atom_udta_add_blob_tag   (AtomUDTA *udta, guint8 *data, guint size);
990
991 void atom_udta_add_3gp_str_tag       (AtomUDTA *udta, guint32 fourcc, const gchar * value);
992 void atom_udta_add_3gp_uint_tag      (AtomUDTA *udta, guint32 fourcc, guint16 value);
993 void atom_udta_add_3gp_str_int_tag   (AtomUDTA *udta, guint32 fourcc, const gchar * value,
994                                       gint16 ivalue);
995 void atom_udta_add_3gp_tag           (AtomUDTA *udta, guint32 fourcc, guint8 * data,
996                                       guint size);
997
998 void atom_udta_add_xmp_tags          (AtomUDTA *udta, GstBuffer * xmp);
999
1000 #define GST_QT_MUX_DEFAULT_TAG_LANGUAGE   "und" /* undefined/unknown */
1001 guint16  language_code               (const char * lang);
1002
1003 #endif /* __ATOMS_H__ */