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
61 typedef struct _AtomsContext
63 AtomsTreeFlavor flavor;
66 AtomsContext* atoms_context_new (AtomsTreeFlavor flavor);
67 void atoms_context_free (AtomsContext *context);
69 #define METADATA_DATA_FLAG 0x0
70 #define METADATA_TEXT_FLAG 0x1
72 /* atom defs and functions */
75 * Used for storing time related values for some atoms.
77 typedef struct _TimeInfo
79 guint64 creation_time;
80 guint64 modification_time;
89 guint64 extended_size;
92 typedef struct _AtomFull
101 * Generic extension atom
103 typedef struct _AtomData
112 typedef struct _AtomFTYP
117 guint32 *compatible_brands;
120 guint32 compatible_brands_size;
123 typedef struct _AtomMVHD
127 /* version 0: 32 bits */
130 guint32 prefered_rate; /* ISO: 0x00010000 */
131 guint16 volume; /* ISO: 0x0100 */
132 guint16 reserved3; /* ISO: 0x0 */
133 guint32 reserved4[2]; /* ISO: 0, 0 */
134 /* ISO: identity matrix =
135 * { 0x00010000, 0, 0, 0, 0x00010000, 0, 0, 0, 0x40000000 } */
139 guint32 preview_time;
140 guint32 preview_duration;
142 guint32 selection_time;
143 guint32 selection_duration;
144 guint32 current_time;
146 guint32 next_track_id;
149 typedef struct _AtomTKHD
153 /* version 0: 32 bits */
154 /* like the TimeInfo struct, but it has this track_ID inside */
155 guint64 creation_time;
156 guint64 modification_time;
161 guint32 reserved2[2];
163 guint16 alternate_group;
167 /* ISO: identity matrix =
168 * { 0x00010000, 0, 0, 0, 0x00010000, 0, 0, 0, 0x40000000 } */
174 typedef struct _AtomMDHD
178 /* version 0: 32 bits */
181 /* ISO: packed ISO-639-2/T language code (first bit must be 0) */
182 guint16 language_code;
187 typedef struct _AtomHDLR
192 guint32 component_type;
193 guint32 handler_type;
194 guint32 manufacturer;
200 typedef struct _AtomVMHD
202 AtomFull header; /* ISO: flags = 1 */
204 guint16 graphics_mode;
209 typedef struct _AtomSMHD
217 typedef struct _AtomHMHD
221 guint16 max_pdu_size;
222 guint16 avg_pdu_size;
225 guint32 sliding_avg_bitrate;
228 typedef struct _AtomURL
235 typedef struct _AtomDREF
242 typedef struct _AtomDINF
249 typedef struct _STTSEntry
251 guint32 sample_count;
255 typedef struct _AtomSTTS
260 /* list of STTSEntry */
264 typedef struct _AtomSTSS
269 /* list of sample indexes (guint32) */
273 typedef struct _AtomESDS
280 typedef struct _AtomFRMA
287 typedef enum _SampleEntryKind
294 typedef struct _SampleTableEntry
299 guint16 data_reference_index;
302 SampleEntryKind kind;
305 typedef struct _AtomHintSampleEntry
310 } AtomHintSampleEntry;
312 typedef struct _SampleTableEntryMP4V
317 guint16 revision_level;
319 guint32 vendor; /* fourcc code */
320 guint32 temporal_quality;
321 guint32 spatial_quality;
326 guint32 horizontal_resolution;
327 guint32 vertical_resolution;
330 guint16 frame_count; /* usually 1 */
332 guint8 compressor[32]; /* pascal string, i.e. first byte = length */
335 guint16 color_table_id;
337 /* (optional) list of AtomInfo */
338 GList *extension_atoms;
339 } SampleTableEntryMP4V;
341 typedef struct _SampleTableEntryMP4A
346 guint16 revision_level;
351 guint16 compression_id;
354 guint32 sample_rate; /* fixed point 16.16 */
356 guint32 samples_per_packet;
357 guint32 bytes_per_packet;
358 guint32 bytes_per_frame;
359 guint32 bytes_per_sample;
361 /* (optional) list of AtomInfo */
362 GList *extension_atoms;
363 } SampleTableEntryMP4A;
365 typedef struct _SampleTableEntryMP4S
370 } SampleTableEntryMP4S;
372 typedef struct _AtomSTSD
377 /* list of subclasses of SampleTableEntry */
381 typedef struct _AtomSTSZ
387 /* need the size here because when sample_size is constant,
388 * the list is empty */
390 /* list of guint32 */
394 typedef struct _STSCEntry
397 guint32 samples_per_chunk;
398 guint32 sample_description_index;
401 typedef struct _AtomSTSC
406 /* list of STSCEntry */
412 * used for both STCO and CO64
413 * if used as STCO, entries should be truncated to use only 32bits
415 typedef struct _AtomSTCO64
420 /* list of guint64 */
424 typedef struct _CTTSEntry
427 guint32 sampleoffset;
430 typedef struct _AtomCTTS
434 /* also entry count here */
439 typedef struct _AtomSTBL
448 /* NULL if not present */
454 typedef struct _AtomMINF
458 /* only (exactly) one of those must be present */
468 typedef struct _AtomMDIA
477 typedef struct _AtomILST
481 /* list of AtomInfo */
485 typedef struct _AtomTagData
494 typedef struct _AtomTag
501 typedef struct _AtomMETA
508 typedef struct _AtomUDTA
515 typedef struct _AtomTRAK
522 /* some helper info for structural conformity checks */
527 typedef struct _AtomMOOV
533 /* list of AtomTRAK */
538 typedef struct _AtomWAVE
542 /* list of AtomInfo */
543 GList *extension_atoms;
548 * Function to serialize an atom
550 typedef guint64 (*AtomCopyDataFunc) (Atom *atom, guint8 **buffer, guint64 *size, guint64 *offset);
553 * Releases memory allocated by an atom
555 typedef guint64 (*AtomFreeFunc) (Atom *atom);
558 * Some atoms might have many optional different kinds of child atoms, so this
559 * is useful for enabling generic handling of any atom.
560 * All we need are the two functions (copying it to an array
561 * for serialization and the memory releasing function).
563 typedef struct _AtomInfo
566 AtomCopyDataFunc copy_data_func;
567 AtomFreeFunc free_func;
571 guint64 atom_copy_data (Atom *atom, guint8 **buffer,
572 guint64 *size, guint64* offset);
574 AtomFTYP* atom_ftyp_new (AtomsContext *context, guint32 major,
575 guint32 version, GList *brands);
576 guint64 atom_ftyp_copy_data (AtomFTYP *ftyp, guint8 **buffer,
577 guint64 *size, guint64 *offset);
578 void atom_ftyp_free (AtomFTYP *ftyp);
580 AtomTRAK* atom_trak_new (AtomsContext *context);
581 void atom_trak_add_samples (AtomTRAK * trak, guint32 nsamples, guint32 delta,
582 guint32 size, guint64 chunk_offset, gboolean sync,
583 gboolean do_pts, gint64 pts_offset);
584 guint32 atom_trak_get_timescale (AtomTRAK *trak);
586 AtomMOOV* atom_moov_new (AtomsContext *context);
587 void atom_moov_free (AtomMOOV *moov);
588 guint64 atom_moov_copy_data (AtomMOOV *atom, guint8 **buffer, guint64 *size, guint64* offset);
589 void atom_moov_update_timescale (AtomMOOV *moov, guint32 timescale);
590 void atom_moov_update_duration (AtomMOOV *moov);
591 void atom_moov_set_64bits (AtomMOOV *moov, gboolean large_file);
592 void atom_moov_chunks_add_offset (AtomMOOV *moov, guint32 offset);
593 void atom_moov_add_trak (AtomMOOV *moov, AtomTRAK *trak);
595 /* media sample description related helpers */
608 GstBuffer *codec_data;
619 guint bytes_per_packet;
620 guint samples_per_packet;
621 guint bytes_per_sample;
622 guint bytes_per_frame;
624 GstBuffer *codec_data;
627 void atom_trak_set_audio_type (AtomTRAK * trak, AtomsContext * context,
628 AudioSampleEntry * entry, guint32 scale,
629 AtomInfo * ext, gint sample_size);
630 void atom_trak_set_video_type (AtomTRAK * trak, AtomsContext * context,
631 VisualSampleEntry * entry, guint32 rate,
634 AtomInfo * build_codec_data_extension (guint32 fourcc, const GstBuffer * codec_data);
635 AtomInfo * build_mov_aac_extension (AtomTRAK * trak, const GstBuffer * codec_data);
636 AtomInfo * build_esds_extension (AtomTRAK * trak, guint8 object_type,
637 guint8 stream_type, const GstBuffer * codec_data);
638 AtomInfo * build_jp2h_extension (AtomTRAK * trak, gint width, gint height,
640 AtomInfo * build_amr_extension ();
641 AtomInfo * build_h263_extension ();
645 * Meta tags functions
647 void atom_moov_add_str_tag (AtomMOOV *moov, guint32 fourcc, const gchar *value);
648 void atom_moov_add_uint_tag (AtomMOOV *moov, guint32 fourcc, guint32 flags,
650 void atom_moov_add_tag (AtomMOOV *moov, guint32 fourcc, guint32 flags,
651 const guint8 * data, guint size);
652 void atom_moov_add_blob_tag (AtomMOOV *moov, guint8 *data, guint size);
654 #endif /* __ATOMS_H__ */