"Fossies" - the Fresh Open Source Software Archive

Member "gst-plugins-good-1.20.3/gst/isomp4/atoms.h" (15 Jun 2022, 30517 Bytes) of package /linux/misc/gst-plugins-good-1.20.3.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "atoms.h" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 1.18.6_vs_1.20.0.

    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 #include <gst/video/video.h>
   49 
   50 #include "descriptors.h"
   51 #include "properties.h"
   52 #include "fourcc.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   gboolean force_create_timecode_trak;
  107 } AtomsContext;
  108 
  109 AtomsContext* atoms_context_new  (AtomsTreeFlavor flavor, gboolean force_create_timecode_trak);
  110 void          atoms_context_free (AtomsContext *context);
  111 
  112 #define METADATA_DATA_FLAG 0x0
  113 #define METADATA_TEXT_FLAG 0x1
  114 
  115 /* atom defs and functions */
  116 
  117 typedef struct _AtomInfo AtomInfo;
  118 
  119 /*
  120  * Used for storing time related values for some atoms.
  121  */
  122 typedef struct _TimeInfo
  123 {
  124   guint64 creation_time;
  125   guint64 modification_time;
  126   guint32 timescale;
  127   guint64 duration;
  128 } TimeInfo;
  129 
  130 typedef struct _Atom
  131 {
  132   guint32 size;
  133   guint32 type;
  134   guint64 extended_size;
  135 } Atom;
  136 
  137 typedef struct _AtomFull
  138 {
  139   Atom header;
  140 
  141   guint8 version;
  142   guint8 flags[3];
  143 } AtomFull;
  144 
  145 /*
  146  * Generic extension atom
  147  */
  148 typedef struct _AtomData
  149 {
  150   Atom header;
  151 
  152   /* not written */
  153   guint32 datalen;
  154 
  155   guint8 *data;
  156 } AtomData;
  157 
  158 typedef struct _AtomUUID
  159 {
  160   Atom header;
  161 
  162   guint8 uuid[16];
  163 
  164   /* not written */
  165   guint32 datalen;
  166 
  167   guint8 *data;
  168 } AtomUUID;
  169 
  170 typedef struct _AtomFTYP
  171 {
  172   Atom header;
  173   guint32 major_brand;
  174   guint32 version;
  175   guint32 *compatible_brands;
  176 
  177   /* not written */
  178   guint32 compatible_brands_size;
  179 } AtomFTYP;
  180 
  181 typedef struct _AtomMVHD
  182 {
  183   AtomFull header;
  184 
  185   /* version 0: 32 bits */
  186   TimeInfo time_info;
  187 
  188   guint32 prefered_rate;      /* ISO: 0x00010000 */
  189   guint16 volume;             /* ISO: 0x0100 */
  190   guint16 reserved3;          /* ISO: 0x0 */
  191   guint32 reserved4[2];       /* ISO: 0, 0 */
  192   /* ISO: identity matrix =
  193    * { 0x00010000, 0, 0, 0, 0x00010000, 0, 0, 0, 0x40000000 } */
  194   guint32 matrix[9];
  195 
  196   /* ISO: all 0 */
  197   guint32 preview_time;
  198   guint32 preview_duration;
  199   guint32 poster_time;
  200   guint32 selection_time;
  201   guint32 selection_duration;
  202   guint32 current_time;
  203 
  204   guint32 next_track_id;
  205 } AtomMVHD;
  206 
  207 typedef struct _AtomTKHD
  208 {
  209   AtomFull header;
  210 
  211   /* version 0: 32 bits */
  212   /* like the TimeInfo struct, but it has this track_ID inside */
  213   guint64 creation_time;
  214   guint64 modification_time;
  215   guint32 track_ID;
  216   guint32 reserved;
  217   guint64 duration;
  218 
  219   guint32 reserved2[2];
  220   guint16 layer;
  221   guint16 alternate_group;
  222   guint16 volume;
  223   guint16 reserved3;
  224 
  225   /* ISO: identity matrix =
  226    * { 0x00010000, 0, 0, 0, 0x00010000, 0, 0, 0, 0x40000000 } */
  227   guint32 matrix[9];
  228   guint32 width;
  229   guint32 height;
  230 } AtomTKHD;
  231 
  232 typedef struct _AtomMDHD
  233 {
  234   AtomFull header;
  235 
  236   /* version 0: 32 bits */
  237   TimeInfo time_info;
  238 
  239   /* ISO: packed ISO-639-2/T language code (first bit must be 0) */
  240   guint16 language_code;
  241   /* ISO: 0 */
  242   guint16 quality;
  243 } AtomMDHD;
  244 
  245 typedef struct _AtomHDLR
  246 {
  247   AtomFull header;
  248 
  249   /* ISO: 0 */
  250   guint32 component_type;
  251   guint32 handler_type;
  252   guint32 manufacturer;
  253   guint32 flags;
  254   guint32 flags_mask;
  255   gchar *name;
  256 
  257   AtomsTreeFlavor flavor;
  258 } AtomHDLR;
  259 
  260 typedef struct _AtomVMHD
  261 {
  262   AtomFull header;          /* ISO: flags = 1 */
  263 
  264   guint16 graphics_mode;
  265   /* RGB */
  266   guint16 opcolor[3];
  267 } AtomVMHD;
  268 
  269 typedef struct _AtomSMHD
  270 {
  271   AtomFull header;
  272 
  273   guint16 balance;
  274   guint16 reserved;
  275 } AtomSMHD;
  276 
  277 typedef struct _AtomHMHD
  278 {
  279   AtomFull header;
  280 
  281   guint16 max_pdu_size;
  282   guint16 avg_pdu_size;
  283   guint32 max_bitrate;
  284   guint32 avg_bitrate;
  285   guint32 sliding_avg_bitrate;
  286 } AtomHMHD;
  287 
  288 typedef struct _AtomTCMI
  289 {
  290   AtomFull header;
  291 
  292   guint16 text_font;
  293   guint16 text_face;
  294   guint16 text_size;
  295   guint16 text_color[3];
  296   guint16 bg_color[3];
  297   gchar *font_name;
  298 } AtomTCMI;
  299 
  300 typedef struct _AtomTMCD
  301 {
  302   Atom header;
  303 
  304   AtomTCMI tcmi;
  305 } AtomTMCD;
  306 
  307 typedef struct _AtomGMIN
  308 {
  309   AtomFull header;
  310 
  311   guint16 graphics_mode;
  312   guint16 opcolor[3];
  313   guint8 balance;
  314   guint8 reserved;
  315 
  316 } AtomGMIN;
  317 
  318 typedef struct _AtomGMHD
  319 {
  320   Atom header;
  321 
  322   /* Only gmin is required in a gmhd atom
  323    * The other fields are optional */
  324   AtomGMIN gmin;
  325   AtomTMCD *tmcd;
  326 
  327 } AtomGMHD;
  328 
  329 typedef struct _AtomNMHD
  330 {
  331   Atom header;
  332   guint32 flags;
  333 } AtomNMHD;
  334 
  335 typedef struct _AtomURL
  336 {
  337   AtomFull header;
  338 
  339   gchar *location;
  340 } AtomURL;
  341 
  342 typedef struct _AtomDREF
  343 {
  344   AtomFull header;
  345 
  346   GList *entries;
  347 } AtomDREF;
  348 
  349 typedef struct _AtomDINF
  350 {
  351   Atom header;
  352 
  353   AtomDREF dref;
  354 } AtomDINF;
  355 
  356 typedef struct _STTSEntry
  357 {
  358   guint32 sample_count;
  359   gint32 sample_delta;
  360 } STTSEntry;
  361 
  362 typedef struct _AtomSTTS
  363 {
  364   AtomFull header;
  365 
  366   ATOM_ARRAY (STTSEntry) entries;
  367 } AtomSTTS;
  368 
  369 typedef struct _AtomSTSS
  370 {
  371   AtomFull header;
  372 
  373   ATOM_ARRAY (guint32) entries;
  374 } AtomSTSS;
  375 
  376 typedef struct _AtomESDS
  377 {
  378   AtomFull header;
  379 
  380   ESDescriptor es;
  381 } AtomESDS;
  382 
  383 typedef struct _AtomFRMA
  384 {
  385   Atom header;
  386 
  387   guint32 media_type;
  388 } AtomFRMA;
  389 
  390 typedef enum _SampleEntryKind
  391 {
  392   UNKNOWN,
  393   AUDIO,
  394   VIDEO,
  395   SUBTITLE,
  396   TIMECODE,
  397   CLOSEDCAPTION
  398 } SampleEntryKind;
  399 
  400 typedef struct _SampleTableEntry
  401 {
  402   Atom header;
  403 
  404   guint8 reserved[6];
  405   guint16 data_reference_index;
  406 
  407   /* type of entry */
  408   SampleEntryKind kind;
  409 } SampleTableEntry;
  410 
  411 typedef struct _AtomHintSampleEntry
  412 {
  413   SampleTableEntry se;
  414   guint32 size;
  415   guint8 *data;
  416 } AtomHintSampleEntry;
  417 
  418 typedef struct _SampleTableEntryMP4V
  419 {
  420   SampleTableEntry se;
  421 
  422   guint16 version;
  423   guint16 revision_level;
  424 
  425   guint32 vendor;                 /* fourcc code */
  426   guint32 temporal_quality;
  427   guint32 spatial_quality;
  428 
  429   guint16 width;
  430   guint16 height;
  431 
  432   guint32 horizontal_resolution;
  433   guint32 vertical_resolution;
  434   guint32 datasize;
  435 
  436   guint16 frame_count;            /* usually 1 */
  437 
  438   guint8 compressor[32];         /* pascal string, i.e. first byte = length */
  439 
  440   guint16 depth;
  441   guint16 color_table_id;
  442 
  443   /* (optional) list of AtomInfo */
  444   GList *extension_atoms;
  445 } SampleTableEntryMP4V;
  446 
  447 typedef struct _SampleTableEntryMP4A
  448 {
  449   SampleTableEntry se;
  450 
  451   guint16 version;
  452   guint16 revision_level;
  453   guint32 vendor;
  454 
  455   guint16 channels;
  456   guint16 sample_size;
  457   guint16 compression_id;
  458   guint16 packet_size;
  459 
  460   guint32 sample_rate;            /* fixed point 16.16 */
  461 
  462   guint32 samples_per_packet;
  463   guint32 bytes_per_packet;
  464   guint32 bytes_per_frame;
  465   guint32 bytes_per_sample;
  466 
  467   /* (optional) list of AtomInfo */
  468   GList *extension_atoms;
  469 } SampleTableEntryMP4A;
  470 
  471 typedef struct _AtomNAME
  472 {
  473   Atom header;
  474 
  475   guint8 language_code;
  476   gchar *name;
  477 } AtomNAME;
  478 
  479 typedef struct _SampleTableEntryTMCD
  480 {
  481   SampleTableEntry se;
  482 
  483   guint32 tc_flags;
  484   guint32 timescale;
  485   guint32 frame_duration;
  486   guint8 n_frames;
  487 
  488   AtomNAME name;
  489 
  490 } SampleTableEntryTMCD;
  491 
  492 typedef struct _SampleTableEntryTX3G
  493 {
  494   SampleTableEntry se;
  495 
  496   guint32 display_flags;
  497   guint64 default_text_box;
  498   guint16 font_id;
  499   guint8  font_face; /* bold=0x1, italic=0x2, underline=0x4 */
  500   guint8  font_size; /* should always be 0.05 multiplied by the video track header height */
  501   guint32 foreground_color_rgba;
  502 
  503 } SampleTableEntryTX3G;
  504 
  505 typedef struct _AtomSTSD
  506 {
  507   AtomFull header;
  508 
  509   guint n_entries;
  510   /* list of subclasses of SampleTableEntry */
  511   GList *entries;
  512 } AtomSTSD;
  513 
  514 typedef struct _AtomSTSZ
  515 {
  516   AtomFull header;
  517 
  518   guint32 sample_size;
  519 
  520   /* need the size here because when sample_size is constant,
  521    * the list is empty */
  522   guint32 table_size;
  523   ATOM_ARRAY (guint32) entries;
  524 } AtomSTSZ;
  525 
  526 typedef struct _STSCEntry
  527 {
  528   guint32 first_chunk;
  529   guint32 samples_per_chunk;
  530   guint32 sample_description_index;
  531 } STSCEntry;
  532 
  533 typedef struct _AtomSTSC
  534 {
  535   AtomFull header;
  536 
  537   ATOM_ARRAY (STSCEntry) entries;
  538 } AtomSTSC;
  539 
  540 /* FIXME: this can support multiple tracks */
  541 typedef struct _AtomTREF
  542 {
  543   Atom header;
  544 
  545   guint32 reftype;
  546   ATOM_ARRAY (guint32) entries;
  547 } AtomTREF;
  548 
  549 /*
  550  * used for both STCO and CO64
  551  * The table will be written out as STCO automatically when
  552  * the offsets being written will fit in a 32-bit table,
  553  * otherwise it is written as CO64
  554  */
  555 typedef struct _AtomSTCO64
  556 {
  557   AtomFull header;
  558   /* Global offset to add to entries when serialising */
  559   guint32 chunk_offset;
  560   /* Maximum offset stored in the table */
  561   guint64 max_offset;
  562   ATOM_ARRAY (guint64) entries;
  563 } AtomSTCO64;
  564 
  565 typedef struct _CTTSEntry
  566 {
  567   guint32 samplecount;
  568   guint32 sampleoffset;
  569 } CTTSEntry;
  570 
  571 typedef struct _AtomCTTS
  572 {
  573   AtomFull header;
  574 
  575   /* also entry count here */
  576   ATOM_ARRAY (CTTSEntry) entries;
  577   gboolean do_pts;
  578 } AtomCTTS;
  579 
  580 typedef struct _AtomSVMI
  581 {
  582   AtomFull header;
  583 
  584   guint8 stereoscopic_composition_type;
  585   gboolean is_left_first;
  586 } AtomSVMI;
  587 
  588 typedef struct _AtomSTBL
  589 {
  590   Atom header;
  591 
  592   AtomSTSD stsd;
  593   AtomSTTS stts;
  594   AtomSTSS stss;
  595   AtomSTSC stsc;
  596   AtomSTSZ stsz;
  597   /* NULL if not present */
  598   AtomCTTS *ctts;
  599   /* NULL if not present */
  600   AtomSVMI *svmi;
  601 
  602   AtomSTCO64 stco64;
  603 } AtomSTBL;
  604 
  605 typedef struct _AtomMINF
  606 {
  607   Atom header;
  608 
  609   /* only (exactly) one of those must be present */
  610   AtomVMHD *vmhd;
  611   AtomSMHD *smhd;
  612   AtomHMHD *hmhd;
  613   AtomGMHD *gmhd;
  614   AtomNMHD *nmhd;
  615 
  616   AtomHDLR *hdlr;
  617   AtomDINF dinf;
  618   AtomSTBL stbl;
  619 } AtomMINF;
  620 
  621 typedef struct _EditListEntry
  622 {
  623   /* duration in movie's timescale */
  624   guint32 duration;
  625   /* start time in media's timescale, -1 for empty */
  626   guint32 media_time;
  627   guint32 media_rate;  /* fixed point 32 bit */
  628 } EditListEntry;
  629 
  630 typedef struct _AtomELST
  631 {
  632   AtomFull header;
  633 
  634   /* number of entries is implicit */
  635   GSList *entries;
  636 } AtomELST;
  637 
  638 typedef struct _AtomEDTS
  639 {
  640   Atom header;
  641   AtomELST elst;
  642 } AtomEDTS;
  643 
  644 typedef struct _AtomMDIA
  645 {
  646   Atom header;
  647 
  648   AtomMDHD mdhd;
  649   AtomHDLR hdlr;
  650   AtomMINF minf;
  651 } AtomMDIA;
  652 
  653 typedef struct _AtomILST
  654 {
  655   Atom header;
  656 
  657   /* list of AtomInfo */
  658   GList* entries;
  659 } AtomILST;
  660 
  661 typedef struct _AtomTagData
  662 {
  663   AtomFull header;
  664   guint32 reserved;
  665 
  666   guint32 datalen;
  667   guint8* data;
  668 } AtomTagData;
  669 
  670 typedef struct _AtomTag
  671 {
  672   Atom header;
  673 
  674   AtomTagData data;
  675 } AtomTag;
  676 
  677 typedef struct _AtomMETA
  678 {
  679   AtomFull header;
  680   AtomHDLR hdlr;
  681   AtomILST *ilst;
  682 } AtomMETA;
  683 
  684 typedef struct _AtomUDTA
  685 {
  686   Atom header;
  687 
  688   /* list of AtomInfo */
  689   GList* entries;
  690   /* or list is further down */
  691   AtomMETA *meta;
  692 
  693   AtomsContext *context;
  694 } AtomUDTA;
  695 
  696 enum TrFlags
  697 {
  698   TR_DATA_OFFSET              = 0x01,     /* data-offset-present */
  699   TR_FIRST_SAMPLE_FLAGS       = 0x04,     /* first-sample-flags-present */
  700   TR_SAMPLE_DURATION          = 0x0100,   /* sample-duration-present */
  701   TR_SAMPLE_SIZE              = 0x0200,   /* sample-size-present */
  702   TR_SAMPLE_FLAGS             = 0x0400,   /* sample-flags-present */
  703   TR_COMPOSITION_TIME_OFFSETS = 0x0800    /* sample-composition-time-offsets-presents */
  704 };
  705 
  706 enum TfFlags
  707 {
  708   TF_BASE_DATA_OFFSET         = 0x01,     /* base-data-offset-present */
  709   TF_SAMPLE_DESCRIPTION_INDEX = 0x02,     /* sample-description-index-present */
  710   TF_DEFAULT_SAMPLE_DURATION  = 0x08,     /* default-sample-duration-present */
  711   TF_DEFAULT_SAMPLE_SIZE      = 0x010,    /* default-sample-size-present */
  712   TF_DEFAULT_SAMPLE_FLAGS     = 0x020,    /* default-sample-flags-present */
  713   TF_DURATION_IS_EMPTY        = 0x010000, /* sample-composition-time-offsets-presents */
  714   TF_DEFAULT_BASE_IS_MOOF     = 0x020000  /* default-base-is-moof */
  715 };
  716 
  717 /* Timecode flags */
  718 enum TcFlags
  719 {
  720   TC_DROP_FRAME = 0x0001,   /* Drop-frame timecode */
  721   TC_24H_MAX = 0x0002,      /* Whether the timecode wraps after 24 hours */
  722   TC_NEGATIVE_OK = 0x0004,  /* Whether negative time values are OK */
  723   TC_COUNTER = 0x0008       /* Whether the time value corresponds to a tape counter value */
  724 };
  725 
  726 typedef struct _AtomTRAK
  727 {
  728   Atom header;
  729 
  730   AtomTKHD tkhd;
  731   AtomInfo *tapt;
  732   AtomEDTS *edts;
  733   AtomMDIA mdia;
  734   AtomUDTA udta;
  735   AtomTREF *tref;
  736 
  737   /* some helper info for structural conformity checks */
  738   gboolean is_video;
  739   gboolean is_h264;
  740 
  741   AtomsContext *context;
  742 } AtomTRAK;
  743 
  744 typedef struct _AtomTREX
  745 {
  746   AtomFull header;
  747 
  748   guint32 track_ID;
  749   guint32 default_sample_description_index;
  750   guint32 default_sample_duration;
  751   guint32 default_sample_size;
  752   guint32 default_sample_flags;
  753 } AtomTREX;
  754 
  755 typedef struct _AtomMEHD
  756 {
  757   AtomFull header;
  758 
  759   guint64 fragment_duration;
  760 } AtomMEHD;
  761 
  762 
  763 typedef struct _AtomMVEX
  764 {
  765   Atom header;
  766 
  767   AtomMEHD mehd;
  768 
  769   /* list of AtomTREX */
  770   GList *trexs;
  771 } AtomMVEX;
  772 
  773 typedef struct _AtomMFHD
  774 {
  775   AtomFull header;
  776 
  777   guint32 sequence_number;
  778 } AtomMFHD;
  779 
  780 typedef struct _AtomTFHD
  781 {
  782   AtomFull header;
  783 
  784   guint32 track_ID;
  785   guint64 base_data_offset;
  786   guint32 sample_description_index;
  787   guint32 default_sample_duration;
  788   guint32 default_sample_size;
  789   guint32 default_sample_flags;
  790 } AtomTFHD;
  791 
  792 typedef struct _AtomTFDT
  793 {
  794   AtomFull header;
  795 
  796   guint64 base_media_decode_time;
  797 } AtomTFDT;
  798 
  799 typedef struct _TRUNSampleEntry
  800 {
  801   guint32 sample_duration;
  802   guint32 sample_size;
  803   guint32 sample_flags;
  804   guint32 sample_composition_time_offset;
  805 } TRUNSampleEntry;
  806 
  807 typedef struct _AtomTRUN
  808 {
  809   AtomFull header;
  810 
  811   guint32 sample_count;
  812   gint32 data_offset;
  813   guint32 first_sample_flags;
  814 
  815   /* array of fields */
  816   ATOM_ARRAY (TRUNSampleEntry) entries;
  817 } AtomTRUN;
  818 
  819 typedef struct _AtomSDTP
  820 {
  821   AtomFull header;
  822 
  823   /* not serialized */
  824   guint32 sample_count;
  825 
  826   /* array of fields */
  827   ATOM_ARRAY (guint8) entries;
  828 } AtomSDTP;
  829 
  830 typedef struct _AtomTRAF
  831 {
  832   Atom header;
  833 
  834   AtomTFHD tfhd;
  835 
  836   AtomTFDT tfdt;
  837 
  838   /* list of AtomTRUN. */
  839   GList *truns;
  840   /* list of AtomSDTP */
  841   GList *sdtps;
  842 } AtomTRAF;
  843 
  844 typedef struct _AtomMOOF
  845 {
  846   Atom header;
  847 
  848   AtomMFHD mfhd;
  849 
  850   /* list of AtomTRAF */
  851   GList *trafs;
  852 
  853   guint64 traf_offset;
  854 } AtomMOOF;
  855 
  856 
  857 typedef struct _AtomMOOV
  858 {
  859   /* style */
  860   AtomsContext context;
  861 
  862   Atom header;
  863 
  864   AtomMVHD mvhd;
  865   AtomMVEX mvex;
  866 
  867   /* list of AtomTRAK */
  868   GList *traks;
  869   AtomUDTA udta;
  870 
  871   gboolean fragmented;
  872   guint32 chunks_offset;
  873 } AtomMOOV;
  874 
  875 typedef struct _AtomWAVE
  876 {
  877   Atom header;
  878 
  879   /* list of AtomInfo */
  880   GList *extension_atoms;
  881 } AtomWAVE;
  882 
  883 typedef struct _TFRAEntry
  884 {
  885   guint64 time;
  886   guint64 moof_offset;
  887   guint32 traf_number;
  888   guint32 trun_number;
  889   guint32 sample_number;
  890 } TFRAEntry;
  891 
  892 typedef struct _AtomTFRA
  893 {
  894   AtomFull header;
  895 
  896   guint32 track_ID;
  897   guint32 lengths;
  898   /* array of entries */
  899   ATOM_ARRAY (TFRAEntry) entries;
  900 } AtomTFRA;
  901 
  902 typedef struct _AtomMFRA
  903 {
  904   Atom header;
  905 
  906   /* list of tfra */
  907   GList *tfras;
  908 } AtomMFRA;
  909 
  910 /*
  911  * Function to serialize an atom
  912  */
  913 typedef guint64 (*AtomCopyDataFunc) (Atom *atom, guint8 **buffer, guint64 *size, guint64 *offset);
  914 
  915 /*
  916  * Releases memory allocated by an atom
  917  */
  918 typedef guint64 (*AtomFreeFunc) (Atom *atom);
  919 
  920 /*
  921  * Some atoms might have many optional different kinds of child atoms, so this
  922  * is useful for enabling generic handling of any atom.
  923  * All we need are the two functions (copying it to an array
  924  * for serialization and the memory releasing function).
  925  */
  926 struct _AtomInfo
  927 {
  928   Atom *atom;
  929   AtomCopyDataFunc copy_data_func;
  930   AtomFreeFunc free_func;
  931 };
  932 
  933 guint64    atoms_get_current_qt_time   (void);
  934 
  935 guint64    atom_copy_data              (Atom *atom, guint8 **buffer,
  936                                         guint64 *size, guint64* offset);
  937 
  938 AtomFTYP*  atom_ftyp_new               (AtomsContext *context, guint32 major,
  939                                         guint32 version, GList *brands);
  940 guint64    atom_ftyp_copy_data         (AtomFTYP *ftyp, guint8 **buffer,
  941                                         guint64 *size, guint64 *offset);
  942 void       atom_ftyp_free              (AtomFTYP *ftyp);
  943 
  944 AtomTRAK*  atom_trak_new               (AtomsContext *context);
  945 void       atom_trak_add_samples       (AtomTRAK * trak, guint32 nsamples, guint32 delta,
  946                                         guint32 size, guint64 chunk_offset, gboolean sync,
  947                                         gint64 pts_offset);
  948 void       atom_trak_set_elst_entry    (AtomTRAK * trak, gint index, guint32 duration,
  949                                         guint32 media_time, guint32 rate);
  950 void       atom_trak_edts_clear        (AtomTRAK * trak);
  951 guint32    atom_trak_get_timescale     (AtomTRAK *trak);
  952 guint32    atom_trak_get_id            (AtomTRAK * trak);
  953 void       atom_trak_set_constant_size_samples (AtomTRAK * trak, guint32 sample_size);
  954 void       atom_stbl_add_samples       (AtomSTBL * stbl, guint32 nsamples,
  955                                         guint32 delta, guint32 size,
  956                                         guint64 chunk_offset, gboolean sync,
  957                                         gint64 pts_offset);
  958 void       atom_stsc_add_new_entry     (AtomSTSC * stsc,
  959                                         guint32 first_chunk, guint32 nsamples, guint32 sample_description_index);
  960 
  961 AtomMOOV*  atom_moov_new               (AtomsContext *context);
  962 void       atom_moov_free              (AtomMOOV *moov);
  963 guint64    atom_moov_copy_data         (AtomMOOV *atom, guint8 **buffer, guint64 *size, guint64* offset);
  964 void       atom_moov_update_timescale  (AtomMOOV *moov, guint32 timescale);
  965 void       atom_moov_update_duration   (AtomMOOV *moov);
  966 void       atom_moov_set_fragmented    (AtomMOOV *moov, gboolean fragmented);
  967 void       atom_moov_chunks_set_offset (AtomMOOV *moov, guint32 offset);
  968 void       atom_moov_add_trak          (AtomMOOV *moov, AtomTRAK *trak);
  969 guint      atom_moov_get_trak_count    (AtomMOOV *moov);
  970 
  971 guint      atom_framerate_to_timescale (gint fps_n, gint fps_d);
  972 
  973 guint64    atom_mvhd_copy_data         (AtomMVHD * atom, guint8 ** buffer,
  974                                         guint64 * size, guint64 * offset);
  975 void       atom_stco64_chunks_set_offset (AtomSTCO64 * stco64, guint32 offset);
  976 guint64    atom_trak_copy_data         (AtomTRAK * atom, guint8 ** buffer,
  977                                         guint64 * size, guint64 * offset);
  978 void       atom_stbl_clear             (AtomSTBL * stbl);
  979 void       atom_stbl_init              (AtomSTBL * stbl);
  980 guint64    atom_stss_copy_data         (AtomSTSS *atom, guint8 **buffer,
  981                                         guint64 *size, guint64* offset);
  982 guint64    atom_stts_copy_data         (AtomSTTS *atom, guint8 **buffer,
  983                                         guint64 *size, guint64* offset);
  984 guint64    atom_stsc_copy_data         (AtomSTSC *atom, guint8 **buffer,
  985                                         guint64 *size, guint64* offset);
  986 guint64    atom_stsz_copy_data         (AtomSTSZ *atom, guint8 **buffer,
  987                                         guint64 *size, guint64* offset);
  988 guint64    atom_ctts_copy_data         (AtomCTTS *atom, guint8 **buffer,
  989                                         guint64 *size, guint64* offset);
  990 guint64    atom_svmi_copy_data         (AtomSVMI *atom, guint8 **buffer,
  991                                         guint64 *size, guint64* offset);
  992 AtomSVMI * atom_svmi_new (guint8 stereoscopic_composition_type, gboolean is_left_first);
  993 guint64    atom_stco64_copy_data       (AtomSTCO64 *atom, guint8 **buffer,
  994                                         guint64 *size, guint64* offset);
  995 AtomMOOF*  atom_moof_new               (AtomsContext *context, guint32 sequence_number);
  996 void       atom_moof_free              (AtomMOOF *moof);
  997 guint64    atom_moof_copy_data         (AtomMOOF *moof, guint8 **buffer, guint64 *size, guint64* offset);
  998 void       atom_moof_set_base_offset   (AtomMOOF * moof, guint64 offset);
  999 AtomTRAF * atom_traf_new               (AtomsContext * context, guint32 track_ID);
 1000 void       atom_traf_free              (AtomTRAF * traf);
 1001 void       atom_traf_set_base_decode_time (AtomTRAF * traf, guint64 base_decode_time);
 1002 void       atom_traf_add_samples       (AtomTRAF * traf, guint32 nsamples, guint32 delta,
 1003                                         guint32 size, gint32 data_offset, gboolean sync,
 1004                                         gint64 pts_offset, gboolean sdtp_sync);
 1005 guint32    atom_traf_get_sample_num    (AtomTRAF * traf);
 1006 void       atom_trun_set_offset        (AtomTRUN * trun, gint32 offset);
 1007 void       atom_moof_add_traf          (AtomMOOF *moof, AtomTRAF *traf);
 1008 
 1009 AtomMFRA*  atom_mfra_new               (AtomsContext *context);
 1010 void       atom_mfra_free              (AtomMFRA *mfra);
 1011 AtomTFRA*  atom_tfra_new               (AtomsContext *context, guint32 track_ID);
 1012 void       atom_tfra_add_entry         (AtomTFRA *tfra, guint64 dts, guint32 sample_num);
 1013 void       atom_tfra_update_offset     (AtomTFRA * tfra, guint64 offset);
 1014 void       atom_mfra_add_tfra          (AtomMFRA *mfra, AtomTFRA *tfra);
 1015 guint64    atom_mfra_copy_data         (AtomMFRA *mfra, guint8 **buffer, guint64 *size, guint64* offset);
 1016 
 1017 
 1018 /* media sample description related helpers */
 1019 typedef struct
 1020 {
 1021   guint16 version;
 1022   guint32 fourcc;
 1023   guint width;
 1024   guint height;
 1025   guint depth;
 1026   guint frame_count;
 1027   gint color_table_id;
 1028   guint par_n;
 1029   guint par_d;
 1030 
 1031   GstBuffer *codec_data;
 1032 } VisualSampleEntry;
 1033 
 1034 typedef struct
 1035 {
 1036   guint32 fourcc;
 1037   guint version;
 1038   gint compression_id;
 1039   guint sample_rate;
 1040   guint channels;
 1041   guint sample_size;
 1042   guint bytes_per_packet;
 1043   guint samples_per_packet;
 1044   guint bytes_per_sample;
 1045   guint bytes_per_frame;
 1046 
 1047   GstBuffer *codec_data;
 1048 } AudioSampleEntry;
 1049 
 1050 typedef struct
 1051 {
 1052   guint32 fourcc;
 1053 
 1054   guint8  font_face; /* bold=0x1, italic=0x2, underline=0x4 */
 1055   guint8  font_size;
 1056   guint32 foreground_color_rgba;
 1057 } SubtitleSampleEntry;
 1058 
 1059 void subtitle_sample_entry_init (SubtitleSampleEntry * entry);
 1060 
 1061 SampleTableEntryMP4A * atom_trak_set_audio_type (AtomTRAK * trak, AtomsContext * context,
 1062                                AudioSampleEntry * entry, guint32 scale,
 1063                                AtomInfo * ext, gint sample_size);
 1064 
 1065 SampleTableEntryMP4V * atom_trak_set_video_type (AtomTRAK * trak, AtomsContext * context,
 1066                                VisualSampleEntry * entry, guint32 rate,
 1067                                GList * ext_atoms_list);
 1068 
 1069 SampleTableEntryTX3G * atom_trak_set_subtitle_type (AtomTRAK * trak, AtomsContext * context,
 1070                                SubtitleSampleEntry * entry);
 1071 
 1072 SampleTableEntryTMCD *
 1073 atom_trak_set_timecode_type (AtomTRAK * trak, AtomsContext * context, guint trak_timescale, GstVideoTimeCode * tc);
 1074 
 1075 SampleTableEntry * atom_trak_set_caption_type (AtomTRAK *trak, AtomsContext *context,
 1076                            guint32 trak_timescale, guint32 caption_type);
 1077 
 1078 void atom_trak_update_bitrates (AtomTRAK * trak, guint32 avg_bitrate,
 1079                                 guint32 max_bitrate);
 1080 
 1081 void atom_trak_tx3g_update_dimension (AtomTRAK * trak, guint32 width,
 1082                                       guint32 height);
 1083 
 1084 void sample_table_entry_add_ext_atom (SampleTableEntry * ste, AtomInfo * ext);
 1085 
 1086 AtomInfo *   build_codec_data_extension  (guint32 fourcc, const GstBuffer * codec_data);
 1087 AtomInfo *   build_mov_aac_extension     (AtomTRAK * trak, const GstBuffer * codec_data,
 1088                                           guint32 avg_bitrate, guint32 max_bitrate);
 1089 AtomInfo *   build_mov_alac_extension    (const GstBuffer * codec_data);
 1090 AtomInfo *   build_esds_extension        (AtomTRAK * trak, guint8 object_type,
 1091                                           guint8 stream_type, const GstBuffer * codec_data,
 1092                                           guint32 avg_bitrate, guint32 max_bitrate);
 1093 AtomInfo *   build_btrt_extension        (guint32 buffer_size_db, guint32 avg_bitrate,
 1094                                           guint32 max_bitrate);
 1095 AtomInfo *   build_jp2h_extension        (gint width, gint height, const gchar *colorspace,
 1096                                           gint ncomp, const GValue * cmap_array,
 1097                                           const GValue * cdef_array);
 1098 
 1099 AtomInfo *   build_jp2x_extension        (const GstBuffer * prefix);
 1100 AtomInfo *   build_fiel_extension        (GstVideoInterlaceMode mode, GstVideoFieldOrder order);
 1101 AtomInfo *   build_colr_extension        (const GstVideoColorimetry *colorimetry, gboolean is_mp4);
 1102 AtomInfo *   build_clap_extension        (gint width_n, gint width_d, gint height_n, gint height_d, gint h_off_n, gint h_off_d, gint v_off_n, gint v_off_d);
 1103 AtomInfo *   build_tapt_extension        (gint clef_width, gint clef_height, gint prof_width, gint prof_height, gint enof_width, gint enof_height);
 1104 
 1105 
 1106 AtomInfo *   build_ac3_extension         (guint8 fscod, guint8 bsid,
 1107                                           guint8 bsmod, guint8 acmod,
 1108                                           guint8 lfe_on, guint8 bitrate_code);
 1109 AtomInfo *   build_opus_extension        (guint32 rate, guint8 channels, guint8 mapping_family,
 1110                                           guint8 stream_count, guint8 coupled_count,
 1111                                           guint8 channel_mapping[256], guint16 pre_skip,
 1112                                           guint16 output_gain);
 1113 
 1114 AtomInfo *   build_amr_extension         (void);
 1115 AtomInfo *   build_h263_extension        (void);
 1116 AtomInfo *   build_gama_atom             (gdouble gamma);
 1117 AtomInfo *   build_SMI_atom              (const GstBuffer *seqh);
 1118 AtomInfo *   build_ima_adpcm_extension   (gint channels, gint rate,
 1119                                           gint blocksize);
 1120 AtomInfo *   build_uuid_xmp_atom         (GstBuffer * xmp);
 1121 
 1122 
 1123 /*
 1124  * Meta tags functions
 1125  */
 1126 void atom_udta_clear_tags (AtomUDTA *udta);
 1127 void atom_udta_add_str_tag    (AtomUDTA *udta, guint32 fourcc, const gchar *value);
 1128 void atom_udta_add_uint_tag   (AtomUDTA *udta, guint32 fourcc, guint32 flags,
 1129                                guint32 value);
 1130 void atom_udta_add_tag        (AtomUDTA *udta, guint32 fourcc, guint32 flags,
 1131                                const guint8 * data, guint size);
 1132 void atom_udta_add_blob_tag   (AtomUDTA *udta, guint8 *data, guint size);
 1133 
 1134 void atom_udta_add_3gp_str_tag       (AtomUDTA *udta, guint32 fourcc, const gchar * value);
 1135 void atom_udta_add_3gp_uint_tag      (AtomUDTA *udta, guint32 fourcc, guint16 value);
 1136 void atom_udta_add_3gp_str_int_tag   (AtomUDTA *udta, guint32 fourcc, const gchar * value,
 1137                                       gint16 ivalue);
 1138 void atom_udta_add_3gp_tag           (AtomUDTA *udta, guint32 fourcc, guint8 * data,
 1139                                       guint size);
 1140 
 1141 void atom_udta_add_xmp_tags          (AtomUDTA *udta, GstBuffer * xmp);
 1142 
 1143 AtomTREF * atom_tref_new (guint32 reftype);
 1144 void atom_tref_add_entry (AtomTREF * tref, guint32 sample);
 1145 
 1146 #define GST_QT_MUX_DEFAULT_TAG_LANGUAGE   "und" /* undefined/unknown */
 1147 guint16  language_code               (const char * lang);
 1148 
 1149 #endif /* __ATOMS_H__ */