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