1 /* Quicktime muxer plugin for GStreamer
2 * Copyright (C) 2008 Thiago Sousa Santos <thiagoss@embedded.ufcg.edu.br>
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.
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.
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.
20 * Unless otherwise indicated, Source Code is licensed under MIT license.
21 * See further explanation attached in License Statement (distributed in the file
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:
31 * The above copyright notice and this permission notice shall be included in all
32 * copies or substantial portions of the Software.
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
49 #include "descriptors.h"
50 #include "properties.h"
54 /* light-weight context that may influence header atom tree construction */
55 typedef enum _AtomsTreeFlavor
57 ATOMS_TREE_FLAVOR_MOV,
58 ATOMS_TREE_FLAVOR_ISOM,
62 typedef struct _AtomsContext
64 AtomsTreeFlavor flavor;
67 AtomsContext* atoms_context_new (AtomsTreeFlavor flavor);
68 void atoms_context_free (AtomsContext *context);
70 #define METADATA_DATA_FLAG 0x0
71 #define METADATA_TEXT_FLAG 0x1
73 /* atom defs and functions */
76 * Used for storing time related values for some atoms.
78 typedef struct _TimeInfo
80 guint64 creation_time;
81 guint64 modification_time;
90 guint64 extended_size;
93 typedef struct _AtomFull
102 * Generic extension atom
104 typedef struct _AtomData
113 typedef struct _AtomFTYP
118 guint32 *compatible_brands;
121 guint32 compatible_brands_size;
124 typedef struct _AtomMVHD
128 /* version 0: 32 bits */
131 guint32 prefered_rate; /* ISO: 0x00010000 */
132 guint16 volume; /* ISO: 0x0100 */
133 guint16 reserved3; /* ISO: 0x0 */
134 guint32 reserved4[2]; /* ISO: 0, 0 */
135 /* ISO: identity matrix =
136 * { 0x00010000, 0, 0, 0, 0x00010000, 0, 0, 0, 0x40000000 } */
140 guint32 preview_time;
141 guint32 preview_duration;
143 guint32 selection_time;
144 guint32 selection_duration;
145 guint32 current_time;
147 guint32 next_track_id;
150 typedef struct _AtomTKHD
154 /* version 0: 32 bits */
155 /* like the TimeInfo struct, but it has this track_ID inside */
156 guint64 creation_time;
157 guint64 modification_time;
162 guint32 reserved2[2];
164 guint16 alternate_group;
168 /* ISO: identity matrix =
169 * { 0x00010000, 0, 0, 0, 0x00010000, 0, 0, 0, 0x40000000 } */
175 typedef struct _AtomMDHD
179 /* version 0: 32 bits */
182 /* ISO: packed ISO-639-2/T language code (first bit must be 0) */
183 guint16 language_code;
188 typedef struct _AtomHDLR
193 guint32 component_type;
194 guint32 handler_type;
195 guint32 manufacturer;
201 typedef struct _AtomVMHD
203 AtomFull header; /* ISO: flags = 1 */
205 guint16 graphics_mode;
210 typedef struct _AtomSMHD
218 typedef struct _AtomHMHD
222 guint16 max_pdu_size;
223 guint16 avg_pdu_size;
226 guint32 sliding_avg_bitrate;
229 typedef struct _AtomURL
236 typedef struct _AtomDREF
243 typedef struct _AtomDINF
250 typedef struct _STTSEntry
252 guint32 sample_count;
256 typedef struct _AtomSTTS
261 /* list of STTSEntry */
265 typedef struct _AtomSTSS
270 /* list of sample indexes (guint32) */
274 typedef struct _AtomESDS
281 typedef struct _AtomFRMA
288 typedef enum _SampleEntryKind
295 typedef struct _SampleTableEntry
300 guint16 data_reference_index;
303 SampleEntryKind kind;
306 typedef struct _AtomHintSampleEntry
311 } AtomHintSampleEntry;
313 typedef struct _SampleTableEntryMP4V
318 guint16 revision_level;
320 guint32 vendor; /* fourcc code */
321 guint32 temporal_quality;
322 guint32 spatial_quality;
327 guint32 horizontal_resolution;
328 guint32 vertical_resolution;
331 guint16 frame_count; /* usually 1 */
333 guint8 compressor[32]; /* pascal string, i.e. first byte = length */
336 guint16 color_table_id;
338 /* (optional) list of AtomInfo */
339 GList *extension_atoms;
340 } SampleTableEntryMP4V;
342 typedef struct _SampleTableEntryMP4A
347 guint16 revision_level;
352 guint16 compression_id;
355 guint32 sample_rate; /* fixed point 16.16 */
357 guint32 samples_per_packet;
358 guint32 bytes_per_packet;
359 guint32 bytes_per_frame;
360 guint32 bytes_per_sample;
362 /* (optional) list of AtomInfo */
363 GList *extension_atoms;
364 } SampleTableEntryMP4A;
366 typedef struct _SampleTableEntryMP4S
371 } SampleTableEntryMP4S;
373 typedef struct _AtomSTSD
378 /* list of subclasses of SampleTableEntry */
382 typedef struct _AtomSTSZ
388 /* need the size here because when sample_size is constant,
389 * the list is empty */
391 /* list of guint32 */
395 typedef struct _STSCEntry
398 guint32 samples_per_chunk;
399 guint32 sample_description_index;
402 typedef struct _AtomSTSC
407 /* list of STSCEntry */
413 * used for both STCO and CO64
414 * if used as STCO, entries should be truncated to use only 32bits
416 typedef struct _AtomSTCO64
421 /* list of guint64 */
425 typedef struct _CTTSEntry
428 guint32 sampleoffset;
431 typedef struct _AtomCTTS
435 /* also entry count here */
440 typedef struct _AtomSTBL
449 /* NULL if not present */
455 typedef struct _AtomMINF
459 /* only (exactly) one of those must be present */
469 typedef struct _EditListEntry
471 /* duration in movie's timescale */
473 /* start time in media's timescale, -1 for empty */
475 guint32 media_rate; /* fixed point 32 bit */
478 typedef struct _AtomELST
482 /* number of entries is implicit */
486 typedef struct _AtomEDTS
492 typedef struct _AtomMDIA
501 typedef struct _AtomILST
505 /* list of AtomInfo */
509 typedef struct _AtomTagData
518 typedef struct _AtomTag
525 typedef struct _AtomMETA
532 typedef struct _AtomUDTA
536 /* list of AtomInfo */
538 /* or list is further down */
542 typedef struct _AtomTRAK
550 /* some helper info for structural conformity checks */
555 typedef struct _AtomMOOV
558 AtomsContext context;
564 /* list of AtomTRAK */
569 typedef struct _AtomWAVE
573 /* list of AtomInfo */
574 GList *extension_atoms;
578 * Function to serialize an atom
580 typedef guint64 (*AtomCopyDataFunc) (Atom *atom, guint8 **buffer, guint64 *size, guint64 *offset);
583 * Releases memory allocated by an atom
585 typedef guint64 (*AtomFreeFunc) (Atom *atom);
588 * Some atoms might have many optional different kinds of child atoms, so this
589 * is useful for enabling generic handling of any atom.
590 * All we need are the two functions (copying it to an array
591 * for serialization and the memory releasing function).
593 typedef struct _AtomInfo
596 AtomCopyDataFunc copy_data_func;
597 AtomFreeFunc free_func;
601 guint64 atom_copy_data (Atom *atom, guint8 **buffer,
602 guint64 *size, guint64* offset);
604 AtomFTYP* atom_ftyp_new (AtomsContext *context, guint32 major,
605 guint32 version, GList *brands);
606 guint64 atom_ftyp_copy_data (AtomFTYP *ftyp, guint8 **buffer,
607 guint64 *size, guint64 *offset);
608 void atom_ftyp_free (AtomFTYP *ftyp);
610 AtomTRAK* atom_trak_new (AtomsContext *context);
611 void atom_trak_add_samples (AtomTRAK * trak, guint32 nsamples, guint32 delta,
612 guint32 size, guint64 chunk_offset, gboolean sync,
613 gboolean do_pts, gint64 pts_offset);
614 void atom_trak_add_elst_entry (AtomTRAK * trak, guint32 duration,
615 guint32 media_time, guint32 rate);
616 guint32 atom_trak_get_timescale (AtomTRAK *trak);
618 AtomMOOV* atom_moov_new (AtomsContext *context);
619 void atom_moov_free (AtomMOOV *moov);
620 guint64 atom_moov_copy_data (AtomMOOV *atom, guint8 **buffer, guint64 *size, guint64* offset);
621 void atom_moov_update_timescale (AtomMOOV *moov, guint32 timescale);
622 void atom_moov_update_duration (AtomMOOV *moov);
623 void atom_moov_set_64bits (AtomMOOV *moov, gboolean large_file);
624 void atom_moov_chunks_add_offset (AtomMOOV *moov, guint32 offset);
625 void atom_moov_add_trak (AtomMOOV *moov, AtomTRAK *trak);
627 /* media sample description related helpers */
641 GstBuffer *codec_data;
652 guint bytes_per_packet;
653 guint samples_per_packet;
654 guint bytes_per_sample;
655 guint bytes_per_frame;
657 GstBuffer *codec_data;
660 void atom_trak_set_audio_type (AtomTRAK * trak, AtomsContext * context,
661 AudioSampleEntry * entry, guint32 scale,
662 AtomInfo * ext, gint sample_size);
664 void atom_trak_set_video_type (AtomTRAK * trak, AtomsContext * context,
665 VisualSampleEntry * entry, guint32 rate,
666 GList * ext_atoms_list);
668 AtomInfo * build_codec_data_extension (guint32 fourcc, const GstBuffer * codec_data);
669 AtomInfo * build_mov_aac_extension (AtomTRAK * trak, const GstBuffer * codec_data);
670 AtomInfo * build_esds_extension (AtomTRAK * trak, guint8 object_type,
671 guint8 stream_type, const GstBuffer * codec_data);
672 AtomInfo * build_jp2h_extension (AtomTRAK * trak, gint width, gint height,
674 AtomInfo * build_amr_extension ();
675 AtomInfo * build_h263_extension ();
676 AtomInfo * build_gama_atom (gdouble gamma);
677 AtomInfo * build_SMI_atom (const GstBuffer *seqh);
681 * Meta tags functions
683 void atom_moov_add_str_tag (AtomMOOV *moov, guint32 fourcc, const gchar *value);
684 void atom_moov_add_uint_tag (AtomMOOV *moov, guint32 fourcc, guint32 flags,
686 void atom_moov_add_tag (AtomMOOV *moov, guint32 fourcc, guint32 flags,
687 const guint8 * data, guint size);
688 void atom_moov_add_blob_tag (AtomMOOV *moov, guint8 *data, guint size);
690 void atom_moov_add_3gp_str_tag (AtomMOOV * moov, guint32 fourcc, const gchar * value);
691 void atom_moov_add_3gp_uint_tag (AtomMOOV * moov, guint32 fourcc, guint16 value);
692 void atom_moov_add_3gp_str_int_tag (AtomMOOV * moov, guint32 fourcc, const gchar * value,
694 void atom_moov_add_3gp_tag (AtomMOOV * moov, guint32 fourcc, guint8 * data,
697 #define GST_QT_MUX_DEFAULT_TAG_LANGUAGE "eng"
698 guint16 language_code (const char * lang);
700 #endif /* __ATOMS_H__ */