1 /* Quicktime muxer plugin for GStreamer
2 * Copyright (C) 2008-2010 Thiago Santos <thiagoss@embedded.ufcg.edu.br>
3 * Copyright (C) 2008 Mark Nauwelaerts <mnauw@users.sf.net>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
21 * Unless otherwise indicated, Source Code is licensed under MIT license.
22 * See further explanation attached in License Statement (distributed in the file
25 * Permission is hereby granted, free of charge, to any person obtaining a copy of
26 * this software and associated documentation files (the "Software"), to deal in
27 * the Software without restriction, including without limitation the rights to
28 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
29 * of the Software, and to permit persons to whom the Software is furnished to do
30 * so, subject to the following conditions:
32 * The above copyright notice and this permission notice shall be included in all
33 * copies or substantial portions of the Software.
35 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
36 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
37 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
38 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
39 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
40 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
49 #include <gst/base/gstbytewriter.h>
50 #include <gst/tag/tag.h>
53 * Creates a new AtomsContext for the given flavor.
56 atoms_context_new (AtomsTreeFlavor flavor)
58 AtomsContext *context = g_new0 (AtomsContext, 1);
59 context->flavor = flavor;
64 * Frees an AtomsContext and all memory associated with it
67 atoms_context_free (AtomsContext * context)
72 /* -- creation, initialization, clear and free functions -- */
74 #define SECS_PER_DAY (24 * 60 * 60)
75 #define LEAP_YEARS_FROM_1904_TO_1970 17
78 get_current_qt_time (void)
82 g_get_current_time (&timeval);
83 /* FIXME this should use UTC coordinated time */
84 return timeval.tv_sec + (((1970 - 1904) * (guint64) 365) +
85 LEAP_YEARS_FROM_1904_TO_1970) * SECS_PER_DAY;
89 common_time_info_init (TimeInfo * ti)
91 ti->creation_time = ti->modification_time = get_current_qt_time ();
97 atom_header_set (Atom * header, guint32 fourcc, gint32 size, gint64 ext_size)
99 header->type = fourcc;
101 header->extended_size = ext_size;
105 atom_clear (Atom * atom)
110 atom_full_init (AtomFull * full, guint32 fourcc, gint32 size, gint64 ext_size,
111 guint8 version, guint8 flags[3])
113 atom_header_set (&(full->header), fourcc, size, ext_size);
114 full->version = version;
115 full->flags[0] = flags[0];
116 full->flags[1] = flags[1];
117 full->flags[2] = flags[2];
121 atom_full_clear (AtomFull * full)
123 atom_clear (&full->header);
127 atom_full_free (AtomFull * full)
129 atom_full_clear (full);
134 build_atom_info_wrapper (Atom * atom, gpointer copy_func, gpointer free_func)
136 AtomInfo *info = NULL;
139 info = g_new0 (AtomInfo, 1);
142 info->copy_data_func = copy_func;
143 info->free_func = free_func;
150 atom_info_list_prepend_atom (GList * ai, Atom * atom,
151 AtomCopyDataFunc copy_func, AtomFreeFunc free_func)
154 return g_list_prepend (ai,
155 build_atom_info_wrapper (atom, copy_func, free_func));
161 atom_info_list_free (GList * ai)
164 AtomInfo *info = (AtomInfo *) ai->data;
166 info->free_func (info->atom);
168 ai = g_list_delete_link (ai, ai);
173 atom_data_new (guint32 fourcc)
175 AtomData *data = g_new0 (AtomData, 1);
177 atom_header_set (&data->header, fourcc, 0, 0);
182 atom_data_alloc_mem (AtomData * data, guint32 size)
187 data->data = g_new0 (guint8, size);
188 data->datalen = size;
192 atom_data_new_from_gst_buffer (guint32 fourcc, const GstBuffer * buf)
194 AtomData *data = atom_data_new (fourcc);
196 atom_data_alloc_mem (data, GST_BUFFER_SIZE (buf));
197 g_memmove (data->data, GST_BUFFER_DATA (buf), GST_BUFFER_SIZE (buf));
202 atom_data_free (AtomData * data)
204 atom_clear (&data->header);
210 atom_ftyp_init (AtomFTYP * ftyp, guint32 major, guint32 version, GList * brands)
215 atom_header_set (&ftyp->header, FOURCC_ftyp, 16, 0);
216 ftyp->major_brand = major;
217 ftyp->version = version;
219 /* always include major brand as compatible brand */
220 ftyp->compatible_brands_size = g_list_length (brands) + 1;
221 ftyp->compatible_brands = g_new (guint32, ftyp->compatible_brands_size);
223 ftyp->compatible_brands[0] = major;
225 for (it = brands; it != NULL; it = g_list_next (it)) {
226 ftyp->compatible_brands[index++] = GPOINTER_TO_UINT (it->data);
231 atom_ftyp_new (AtomsContext * context, guint32 major, guint32 version,
234 AtomFTYP *ftyp = g_new0 (AtomFTYP, 1);
236 atom_ftyp_init (ftyp, major, version, brands);
241 atom_ftyp_free (AtomFTYP * ftyp)
243 atom_clear (&ftyp->header);
244 g_free (ftyp->compatible_brands);
245 ftyp->compatible_brands = NULL;
250 atom_esds_init (AtomESDS * esds)
252 guint8 flags[3] = { 0, 0, 0 };
254 atom_full_init (&esds->header, FOURCC_esds, 0, 0, 0, flags);
255 desc_es_init (&esds->es);
261 AtomESDS *esds = g_new0 (AtomESDS, 1);
263 atom_esds_init (esds);
268 atom_esds_free (AtomESDS * esds)
270 atom_full_clear (&esds->header);
271 desc_es_descriptor_clear (&esds->es);
278 AtomFRMA *frma = g_new0 (AtomFRMA, 1);
280 atom_header_set (&frma->header, FOURCC_frma, 0, 0);
285 atom_frma_free (AtomFRMA * frma)
287 atom_clear (&frma->header);
294 AtomWAVE *wave = g_new0 (AtomWAVE, 1);
296 atom_header_set (&wave->header, FOURCC_wave, 0, 0);
301 atom_wave_free (AtomWAVE * wave)
303 atom_clear (&wave->header);
304 atom_info_list_free (wave->extension_atoms);
309 atom_elst_init (AtomELST * elst)
311 guint8 flags[3] = { 0, 0, 0 };
312 atom_full_init (&elst->header, FOURCC_elst, 0, 0, 0, flags);
317 atom_elst_clear (AtomELST * elst)
321 atom_full_clear (&elst->header);
322 walker = elst->entries;
324 g_free ((EditListEntry *) walker->data);
325 walker = g_slist_next (walker);
327 g_slist_free (elst->entries);
331 atom_edts_init (AtomEDTS * edts)
333 atom_header_set (&edts->header, FOURCC_edts, 0, 0);
334 atom_elst_init (&edts->elst);
338 atom_edts_clear (AtomEDTS * edts)
340 atom_clear (&edts->header);
341 atom_elst_clear (&edts->elst);
347 AtomEDTS *edts = g_new0 (AtomEDTS, 1);
348 atom_edts_init (edts);
353 atom_edts_free (AtomEDTS * edts)
355 atom_edts_clear (edts);
360 atom_sample_entry_init (SampleTableEntry * se, guint32 type)
362 atom_header_set (&se->header, type, 0, 0);
364 memset (se->reserved, 0, sizeof (guint8) * 6);
365 se->data_reference_index = 0;
369 atom_sample_entry_free (SampleTableEntry * se)
371 atom_clear (&se->header);
375 sample_entry_mp4a_init (SampleTableEntryMP4A * mp4a)
377 atom_sample_entry_init (&mp4a->se, FOURCC_mp4a);
380 mp4a->revision_level = 0;
383 mp4a->sample_size = 16;
384 mp4a->compression_id = 0;
385 mp4a->packet_size = 0;
386 mp4a->sample_rate = 0;
387 /* following only used if version is 1 */
388 mp4a->samples_per_packet = 0;
389 mp4a->bytes_per_packet = 0;
390 mp4a->bytes_per_frame = 0;
391 mp4a->bytes_per_sample = 0;
393 mp4a->extension_atoms = NULL;
396 static SampleTableEntryMP4A *
397 sample_entry_mp4a_new (void)
399 SampleTableEntryMP4A *mp4a = g_new0 (SampleTableEntryMP4A, 1);
401 sample_entry_mp4a_init (mp4a);
406 sample_entry_mp4a_free (SampleTableEntryMP4A * mp4a)
408 atom_sample_entry_free (&mp4a->se);
409 atom_info_list_free (mp4a->extension_atoms);
414 sample_entry_mp4v_init (SampleTableEntryMP4V * mp4v, AtomsContext * context)
416 atom_sample_entry_init (&mp4v->se, FOURCC_mp4v);
419 mp4v->revision_level = 0;
422 mp4v->temporal_quality = 0;
423 mp4v->spatial_quality = 0;
425 /* qt and ISO base media do not contradict, and examples agree */
426 mp4v->horizontal_resolution = 0x00480000;
427 mp4v->vertical_resolution = 0x00480000;
430 mp4v->frame_count = 1;
432 memset (mp4v->compressor, 0, sizeof (guint8) * 32);
435 mp4v->color_table_id = 0;
437 mp4v->extension_atoms = NULL;
441 sample_entry_mp4v_free (SampleTableEntryMP4V * mp4v)
443 atom_sample_entry_free (&mp4v->se);
444 atom_info_list_free (mp4v->extension_atoms);
448 static SampleTableEntryMP4V *
449 sample_entry_mp4v_new (AtomsContext * context)
451 SampleTableEntryMP4V *mp4v = g_new0 (SampleTableEntryMP4V, 1);
453 sample_entry_mp4v_init (mp4v, context);
458 atom_stsd_init (AtomSTSD * stsd)
460 guint8 flags[3] = { 0, 0, 0 };
462 atom_full_init (&stsd->header, FOURCC_stsd, 0, 0, 0, flags);
463 stsd->entries = NULL;
468 atom_stsd_remove_entries (AtomSTSD * stsd)
472 walker = stsd->entries;
475 SampleTableEntry *se = (SampleTableEntry *) aux->data;
477 walker = g_list_next (walker);
478 stsd->entries = g_list_remove_link (stsd->entries, aux);
482 sample_entry_mp4a_free ((SampleTableEntryMP4A *) se);
485 sample_entry_mp4v_free ((SampleTableEntryMP4V *) se);
488 /* best possible cleanup */
489 atom_sample_entry_free (se);
497 atom_stsd_clear (AtomSTSD * stsd)
499 atom_stsd_remove_entries (stsd);
500 atom_full_clear (&stsd->header);
504 atom_ctts_init (AtomCTTS * ctts)
506 guint8 flags[3] = { 0, 0, 0 };
508 atom_full_init (&ctts->header, FOURCC_ctts, 0, 0, 0, flags);
509 atom_array_init (&ctts->entries, 128);
515 AtomCTTS *ctts = g_new0 (AtomCTTS, 1);
517 atom_ctts_init (ctts);
522 atom_ctts_free (AtomCTTS * ctts)
524 atom_full_clear (&ctts->header);
525 atom_array_clear (&ctts->entries);
530 atom_stts_init (AtomSTTS * stts)
532 guint8 flags[3] = { 0, 0, 0 };
534 atom_full_init (&stts->header, FOURCC_stts, 0, 0, 0, flags);
535 atom_array_init (&stts->entries, 512);
539 atom_stts_clear (AtomSTTS * stts)
541 atom_full_clear (&stts->header);
542 atom_array_clear (&stts->entries);
546 atom_stsz_init (AtomSTSZ * stsz)
548 guint8 flags[3] = { 0, 0, 0 };
550 atom_full_init (&stsz->header, FOURCC_stsz, 0, 0, 0, flags);
551 atom_array_init (&stsz->entries, 1024);
552 stsz->sample_size = 0;
553 stsz->table_size = 0;
557 atom_stsz_clear (AtomSTSZ * stsz)
559 atom_full_clear (&stsz->header);
560 atom_array_clear (&stsz->entries);
561 stsz->table_size = 0;
565 atom_stsc_init (AtomSTSC * stsc)
567 guint8 flags[3] = { 0, 0, 0 };
569 atom_full_init (&stsc->header, FOURCC_stsc, 0, 0, 0, flags);
570 atom_array_init (&stsc->entries, 128);
574 atom_stsc_clear (AtomSTSC * stsc)
576 atom_full_clear (&stsc->header);
577 atom_array_clear (&stsc->entries);
581 atom_co64_init (AtomSTCO64 * co64)
583 guint8 flags[3] = { 0, 0, 0 };
585 atom_full_init (&co64->header, FOURCC_co64, 0, 0, 0, flags);
586 atom_array_init (&co64->entries, 256);
590 atom_stco64_clear (AtomSTCO64 * stco64)
592 atom_full_clear (&stco64->header);
593 atom_array_clear (&stco64->entries);
597 atom_stss_init (AtomSTSS * stss)
599 guint8 flags[3] = { 0, 0, 0 };
601 atom_full_init (&stss->header, FOURCC_stss, 0, 0, 0, flags);
602 atom_array_init (&stss->entries, 128);
606 atom_stss_clear (AtomSTSS * stss)
608 atom_full_clear (&stss->header);
609 atom_array_clear (&stss->entries);
613 atom_stbl_init (AtomSTBL * stbl)
615 atom_header_set (&stbl->header, FOURCC_stbl, 0, 0);
617 atom_stts_init (&stbl->stts);
618 atom_stss_init (&stbl->stss);
619 atom_stsd_init (&stbl->stsd);
620 atom_stsz_init (&stbl->stsz);
621 atom_stsc_init (&stbl->stsc);
624 atom_co64_init (&stbl->stco64);
628 atom_stbl_clear (AtomSTBL * stbl)
630 atom_clear (&stbl->header);
631 atom_stsd_clear (&stbl->stsd);
632 atom_stts_clear (&stbl->stts);
633 atom_stss_clear (&stbl->stss);
634 atom_stsc_clear (&stbl->stsc);
635 atom_stsz_clear (&stbl->stsz);
637 atom_ctts_free (stbl->ctts);
639 atom_stco64_clear (&stbl->stco64);
643 atom_vmhd_init (AtomVMHD * vmhd, AtomsContext * context)
645 guint8 flags[3] = { 0, 0, 1 };
647 atom_full_init (&vmhd->header, FOURCC_vmhd, 0, 0, 0, flags);
648 vmhd->graphics_mode = 0x0;
649 memset (vmhd->opcolor, 0, sizeof (guint16) * 3);
651 if (context->flavor == ATOMS_TREE_FLAVOR_MOV) {
652 vmhd->graphics_mode = 0x40;
653 vmhd->opcolor[0] = 32768;
654 vmhd->opcolor[1] = 32768;
655 vmhd->opcolor[2] = 32768;
660 atom_vmhd_new (AtomsContext * context)
662 AtomVMHD *vmhd = g_new0 (AtomVMHD, 1);
664 atom_vmhd_init (vmhd, context);
669 atom_vmhd_free (AtomVMHD * vmhd)
671 atom_full_clear (&vmhd->header);
676 atom_smhd_init (AtomSMHD * smhd)
678 guint8 flags[3] = { 0, 0, 0 };
680 atom_full_init (&smhd->header, FOURCC_smhd, 0, 0, 0, flags);
688 AtomSMHD *smhd = g_new0 (AtomSMHD, 1);
690 atom_smhd_init (smhd);
695 atom_smhd_free (AtomSMHD * smhd)
697 atom_full_clear (&smhd->header);
702 atom_hmhd_free (AtomHMHD * hmhd)
704 atom_full_clear (&hmhd->header);
709 atom_hdlr_init (AtomHDLR * hdlr)
711 guint8 flags[3] = { 0, 0, 0 };
713 atom_full_init (&hdlr->header, FOURCC_hdlr, 0, 0, 0, flags);
715 hdlr->component_type = 0;
716 hdlr->handler_type = 0;
717 hdlr->manufacturer = 0;
719 hdlr->flags_mask = 0;
720 hdlr->name = g_strdup ("");
726 AtomHDLR *hdlr = g_new0 (AtomHDLR, 1);
728 atom_hdlr_init (hdlr);
733 atom_hdlr_clear (AtomHDLR * hdlr)
735 atom_full_clear (&hdlr->header);
743 atom_hdlr_free (AtomHDLR * hdlr)
745 atom_hdlr_clear (hdlr);
750 atom_url_init (AtomURL * url)
752 guint8 flags[3] = { 0, 0, 1 };
754 atom_full_init (&url->header, FOURCC_url_, 0, 0, 0, flags);
755 url->location = NULL;
759 atom_url_free (AtomURL * url)
761 atom_full_clear (&url->header);
763 g_free (url->location);
764 url->location = NULL;
772 AtomURL *url = g_new0 (AtomURL, 1);
781 guint8 flags[3] = { 0, 0, 1 };
782 AtomFull *alis = g_new0 (AtomFull, 1);
784 atom_full_init (alis, FOURCC_alis, 0, 0, 0, flags);
789 atom_dref_init (AtomDREF * dref, AtomsContext * context)
791 guint8 flags[3] = { 0, 0, 0 };
793 atom_full_init (&dref->header, FOURCC_dref, 0, 0, 0, flags);
795 /* in either case, alis or url init arranges to set self-contained flag */
796 if (context->flavor == ATOMS_TREE_FLAVOR_MOV) {
797 /* alis dref for qt */
798 AtomFull *alis = atom_alis_new ();
799 dref->entries = g_list_append (dref->entries, alis);
801 /* url for iso spec, as 'alis' not specified there */
802 AtomURL *url = atom_url_new ();
803 dref->entries = g_list_append (dref->entries, url);
808 atom_dref_clear (AtomDREF * dref)
812 atom_full_clear (&dref->header);
813 walker = dref->entries;
816 Atom *atom = (Atom *) aux->data;
818 walker = g_list_next (walker);
819 dref->entries = g_list_remove_link (dref->entries, aux);
820 switch (atom->type) {
822 atom_full_free ((AtomFull *) atom);
825 atom_url_free ((AtomURL *) atom);
828 /* we do nothing, better leak than crash */
836 atom_dinf_init (AtomDINF * dinf, AtomsContext * context)
838 atom_header_set (&dinf->header, FOURCC_dinf, 0, 0);
839 atom_dref_init (&dinf->dref, context);
843 atom_dinf_clear (AtomDINF * dinf)
845 atom_clear (&dinf->header);
846 atom_dref_clear (&dinf->dref);
850 atom_minf_init (AtomMINF * minf, AtomsContext * context)
852 atom_header_set (&minf->header, FOURCC_minf, 0, 0);
858 if (context->flavor == ATOMS_TREE_FLAVOR_MOV) {
859 minf->hdlr = atom_hdlr_new ();
860 minf->hdlr->component_type = FOURCC_dhlr;
861 minf->hdlr->handler_type = FOURCC_alis;
865 atom_dinf_init (&minf->dinf, context);
866 atom_stbl_init (&minf->stbl);
870 atom_minf_clear_handlers (AtomMINF * minf)
873 atom_vmhd_free (minf->vmhd);
877 atom_smhd_free (minf->smhd);
881 atom_hmhd_free (minf->hmhd);
887 atom_minf_clear (AtomMINF * minf)
889 atom_clear (&minf->header);
890 atom_minf_clear_handlers (minf);
892 atom_hdlr_free (minf->hdlr);
894 atom_dinf_clear (&minf->dinf);
895 atom_stbl_clear (&minf->stbl);
899 atom_mdhd_init (AtomMDHD * mdhd)
901 guint8 flags[3] = { 0, 0, 0 };
903 atom_full_init (&mdhd->header, FOURCC_mdhd, 0, 0, 0, flags);
904 common_time_info_init (&mdhd->time_info);
905 mdhd->language_code = 0;
910 atom_mdhd_clear (AtomMDHD * mdhd)
912 atom_full_clear (&mdhd->header);
916 atom_mdia_init (AtomMDIA * mdia, AtomsContext * context)
918 atom_header_set (&mdia->header, FOURCC_mdia, 0, 0);
920 atom_mdhd_init (&mdia->mdhd);
921 atom_hdlr_init (&mdia->hdlr);
922 atom_minf_init (&mdia->minf, context);
926 atom_mdia_clear (AtomMDIA * mdia)
928 atom_clear (&mdia->header);
929 atom_mdhd_clear (&mdia->mdhd);
930 atom_hdlr_clear (&mdia->hdlr);
931 atom_minf_clear (&mdia->minf);
935 atom_tkhd_init (AtomTKHD * tkhd, AtomsContext * context)
940 * 2 -> track in movie
941 * 4 -> track in preview
943 guint8 flags[3] = { 0, 0, 7 };
945 atom_full_init (&tkhd->header, FOURCC_tkhd, 0, 0, 0, flags);
947 tkhd->creation_time = tkhd->modification_time = get_current_qt_time ();
952 tkhd->reserved2[0] = tkhd->reserved2[1] = 0;
954 tkhd->alternate_group = 0;
957 memset (tkhd->matrix, 0, sizeof (guint32) * 9);
958 tkhd->matrix[0] = 1 << 16;
959 tkhd->matrix[4] = 1 << 16;
960 tkhd->matrix[8] = 16384 << 16;
966 atom_tkhd_clear (AtomTKHD * tkhd)
968 atom_full_clear (&tkhd->header);
972 atom_trak_init (AtomTRAK * trak, AtomsContext * context)
974 atom_header_set (&trak->header, FOURCC_trak, 0, 0);
976 atom_tkhd_init (&trak->tkhd, context);
978 atom_mdia_init (&trak->mdia, context);
982 atom_trak_new (AtomsContext * context)
984 AtomTRAK *trak = g_new0 (AtomTRAK, 1);
986 atom_trak_init (trak, context);
991 atom_trak_clear (AtomTRAK * trak)
993 atom_clear (&trak->header);
994 atom_tkhd_clear (&trak->tkhd);
996 atom_edts_free (trak->edts);
997 atom_mdia_clear (&trak->mdia);
1001 atom_trak_free (AtomTRAK * trak)
1003 atom_trak_clear (trak);
1008 atom_ilst_init (AtomILST * ilst)
1010 atom_header_set (&ilst->header, FOURCC_ilst, 0, 0);
1011 ilst->entries = NULL;
1015 atom_ilst_new (void)
1017 AtomILST *ilst = g_new0 (AtomILST, 1);
1019 atom_ilst_init (ilst);
1024 atom_ilst_free (AtomILST * ilst)
1027 atom_info_list_free (ilst->entries);
1028 atom_clear (&ilst->header);
1033 atom_meta_init (AtomMETA * meta)
1035 guint8 flags[3] = { 0, 0, 0 };
1037 atom_full_init (&meta->header, FOURCC_meta, 0, 0, 0, flags);
1038 atom_hdlr_init (&meta->hdlr);
1039 /* FIXME (ISOM says this is always 0) */
1040 meta->hdlr.component_type = FOURCC_mhlr;
1041 meta->hdlr.handler_type = FOURCC_mdir;
1046 atom_meta_new (void)
1048 AtomMETA *meta = g_new0 (AtomMETA, 1);
1050 atom_meta_init (meta);
1055 atom_meta_free (AtomMETA * meta)
1057 atom_full_clear (&meta->header);
1058 atom_hdlr_clear (&meta->hdlr);
1060 atom_ilst_free (meta->ilst);
1066 atom_udta_init (AtomUDTA * udta)
1068 atom_header_set (&udta->header, FOURCC_udta, 0, 0);
1073 atom_udta_new (void)
1075 AtomUDTA *udta = g_new0 (AtomUDTA, 1);
1077 atom_udta_init (udta);
1082 atom_udta_free (AtomUDTA * udta)
1084 atom_clear (&udta->header);
1086 atom_meta_free (udta->meta);
1089 atom_info_list_free (udta->entries);
1094 atom_tag_data_init (AtomTagData * data)
1096 guint8 flags[] = { 0, 0, 0 };
1098 atom_full_init (&data->header, FOURCC_data, 0, 0, 0, flags);
1102 atom_tag_data_clear (AtomTagData * data)
1104 atom_full_clear (&data->header);
1105 g_free (data->data);
1110 * Fourcc is the tag fourcc
1111 * flags will be truncated to 24bits
1114 atom_tag_new (guint32 fourcc, guint32 flags_as_uint)
1116 AtomTag *tag = g_new0 (AtomTag, 1);
1118 tag->header.type = fourcc;
1119 atom_tag_data_init (&tag->data);
1120 tag->data.header.flags[2] = flags_as_uint & 0xFF;
1121 tag->data.header.flags[1] = (flags_as_uint & 0xFF00) >> 8;
1122 tag->data.header.flags[0] = (flags_as_uint & 0xFF0000) >> 16;
1127 atom_tag_free (AtomTag * tag)
1129 atom_clear (&tag->header);
1130 atom_tag_data_clear (&tag->data);
1135 atom_mvhd_init (AtomMVHD * mvhd)
1137 guint8 flags[3] = { 0, 0, 0 };
1139 atom_full_init (&(mvhd->header), FOURCC_mvhd, sizeof (AtomMVHD), 0, 0, flags);
1141 common_time_info_init (&mvhd->time_info);
1143 mvhd->prefered_rate = 1 << 16;
1144 mvhd->volume = 1 << 8;
1145 mvhd->reserved3 = 0;
1146 memset (mvhd->reserved4, 0, sizeof (guint32[2]));
1148 memset (mvhd->matrix, 0, sizeof (guint32[9]));
1149 mvhd->matrix[0] = 1 << 16;
1150 mvhd->matrix[4] = 1 << 16;
1151 mvhd->matrix[8] = 16384 << 16;
1153 mvhd->preview_time = 0;
1154 mvhd->preview_duration = 0;
1155 mvhd->poster_time = 0;
1156 mvhd->selection_time = 0;
1157 mvhd->selection_duration = 0;
1158 mvhd->current_time = 0;
1160 mvhd->next_track_id = 1;
1164 atom_mvhd_clear (AtomMVHD * mvhd)
1166 atom_full_clear (&mvhd->header);
1170 atom_moov_init (AtomMOOV * moov, AtomsContext * context)
1172 atom_header_set (&(moov->header), FOURCC_moov, 0, 0);
1173 atom_mvhd_init (&(moov->mvhd));
1176 moov->context = *context;
1180 atom_moov_new (AtomsContext * context)
1182 AtomMOOV *moov = g_new0 (AtomMOOV, 1);
1184 atom_moov_init (moov, context);
1189 atom_moov_free (AtomMOOV * moov)
1193 atom_clear (&moov->header);
1194 atom_mvhd_clear (&moov->mvhd);
1196 walker = moov->traks;
1198 atom_trak_free ((AtomTRAK *) walker->data);
1199 walker = g_list_next (walker);
1201 g_list_free (moov->traks);
1205 atom_udta_free (moov->udta);
1212 /* -- end of init / free -- */
1214 /* -- copy data functions -- */
1217 atom_full_get_version (AtomFull * full)
1219 return full->version;
1223 common_time_info_copy_data (TimeInfo * ti, gboolean trunc_to_32,
1224 guint8 ** buffer, guint64 * size, guint64 * offset)
1226 guint64 original_offset = *offset;
1229 prop_copy_uint32 ((guint32) ti->creation_time, buffer, size, offset);
1230 prop_copy_uint32 ((guint32) ti->modification_time, buffer, size, offset);
1231 prop_copy_uint32 (ti->timescale, buffer, size, offset);
1232 prop_copy_uint32 ((guint32) ti->duration, buffer, size, offset);
1234 prop_copy_uint64 (ti->creation_time, buffer, size, offset);
1235 prop_copy_uint64 (ti->modification_time, buffer, size, offset);
1236 prop_copy_uint32 (ti->timescale, buffer, size, offset);
1237 prop_copy_uint64 (ti->duration, buffer, size, offset);
1239 return *offset - original_offset;
1243 atom_write_size (guint8 ** buffer, guint64 * size, guint64 * offset,
1246 /* this only works for non-extended atom size, which is OK
1247 * (though it could be made to do mem_move, etc and write extended size) */
1248 prop_copy_uint32 (*offset - atom_pos, buffer, size, &atom_pos);
1252 atom_copy_data (Atom * atom, guint8 ** buffer, guint64 * size, guint64 * offset)
1254 guint64 original_offset = *offset;
1256 /* copies type and size */
1257 prop_copy_uint32 (atom->size, buffer, size, offset);
1258 prop_copy_fourcc (atom->type, buffer, size, offset);
1260 /* extended size needed */
1261 if (atom->size == 1) {
1262 /* really should not happen other than with mdat atom;
1263 * would be a problem for size (re)write code, not to mention memory */
1264 g_return_val_if_fail (atom->type == FOURCC_mdat, 0);
1265 prop_copy_uint64 (atom->extended_size, buffer, size, offset);
1268 return *offset - original_offset;
1272 atom_full_copy_data (AtomFull * atom, guint8 ** buffer, guint64 * size,
1275 guint64 original_offset = *offset;
1277 if (!atom_copy_data (&atom->header, buffer, size, offset)) {
1281 prop_copy_uint8 (atom->version, buffer, size, offset);
1282 prop_copy_uint8_array (atom->flags, 3, buffer, size, offset);
1284 atom_write_size (buffer, size, offset, original_offset);
1285 return *offset - original_offset;
1289 atom_info_list_copy_data (GList * ai, guint8 ** buffer, guint64 * size,
1292 guint64 original_offset = *offset;
1295 AtomInfo *info = (AtomInfo *) ai->data;
1297 if (!info->copy_data_func (info->atom, buffer, size, offset)) {
1300 ai = g_list_next (ai);
1303 return *offset - original_offset;
1307 atom_data_copy_data (AtomData * data, guint8 ** buffer, guint64 * size,
1310 guint64 original_offset = *offset;
1312 if (!atom_copy_data (&data->header, buffer, size, offset)) {
1316 prop_copy_uint8_array (data->data, data->datalen, buffer, size, offset);
1318 atom_write_size (buffer, size, offset, original_offset);
1319 return *offset - original_offset;
1323 atom_ftyp_copy_data (AtomFTYP * ftyp, guint8 ** buffer, guint64 * size,
1326 guint64 original_offset = *offset;
1328 if (!atom_copy_data (&ftyp->header, buffer, size, offset)) {
1331 prop_copy_fourcc (ftyp->major_brand, buffer, size, offset);
1332 prop_copy_uint32 (ftyp->version, buffer, size, offset);
1334 prop_copy_fourcc_array (ftyp->compatible_brands, ftyp->compatible_brands_size,
1335 buffer, size, offset);
1337 atom_write_size (buffer, size, offset, original_offset);
1338 return *offset - original_offset;
1342 atom_mvhd_copy_data (AtomMVHD * atom, guint8 ** buffer, guint64 * size,
1346 guint64 original_offset = *offset;
1348 if (!atom_full_copy_data (&(atom->header), buffer, size, offset)) {
1352 version = atom_full_get_version (&(atom->header));
1354 common_time_info_copy_data (&atom->time_info, TRUE, buffer, size, offset);
1355 } else if (version == 1) {
1356 common_time_info_copy_data (&atom->time_info, FALSE, buffer, size, offset);
1358 *offset = original_offset;
1362 prop_copy_uint32 (atom->prefered_rate, buffer, size, offset);
1363 prop_copy_uint16 (atom->volume, buffer, size, offset);
1364 prop_copy_uint16 (atom->reserved3, buffer, size, offset);
1365 prop_copy_uint32_array (atom->reserved4, 2, buffer, size, offset);
1366 prop_copy_uint32_array (atom->matrix, 9, buffer, size, offset);
1367 prop_copy_uint32 (atom->preview_time, buffer, size, offset);
1368 prop_copy_uint32 (atom->preview_duration, buffer, size, offset);
1369 prop_copy_uint32 (atom->poster_time, buffer, size, offset);
1370 prop_copy_uint32 (atom->selection_time, buffer, size, offset);
1371 prop_copy_uint32 (atom->selection_duration, buffer, size, offset);
1372 prop_copy_uint32 (atom->current_time, buffer, size, offset);
1374 prop_copy_uint32 (atom->next_track_id, buffer, size, offset);
1376 atom_write_size (buffer, size, offset, original_offset);
1377 return *offset - original_offset;
1381 atom_tkhd_copy_data (AtomTKHD * tkhd, guint8 ** buffer, guint64 * size,
1384 guint64 original_offset = *offset;
1386 if (!atom_full_copy_data (&tkhd->header, buffer, size, offset)) {
1390 if (atom_full_get_version (&tkhd->header) == 0) {
1391 prop_copy_uint32 ((guint32) tkhd->creation_time, buffer, size, offset);
1392 prop_copy_uint32 ((guint32) tkhd->modification_time, buffer, size, offset);
1393 prop_copy_uint32 (tkhd->track_ID, buffer, size, offset);
1394 prop_copy_uint32 (tkhd->reserved, buffer, size, offset);
1395 prop_copy_uint32 ((guint32) tkhd->duration, buffer, size, offset);
1397 prop_copy_uint64 (tkhd->creation_time, buffer, size, offset);
1398 prop_copy_uint64 (tkhd->modification_time, buffer, size, offset);
1399 prop_copy_uint32 (tkhd->track_ID, buffer, size, offset);
1400 prop_copy_uint32 (tkhd->reserved, buffer, size, offset);
1401 prop_copy_uint64 (tkhd->duration, buffer, size, offset);
1404 prop_copy_uint32_array (tkhd->reserved2, 2, buffer, size, offset);
1405 prop_copy_uint16 (tkhd->layer, buffer, size, offset);
1406 prop_copy_uint16 (tkhd->alternate_group, buffer, size, offset);
1407 prop_copy_uint16 (tkhd->volume, buffer, size, offset);
1408 prop_copy_uint16 (tkhd->reserved3, buffer, size, offset);
1409 prop_copy_uint32_array (tkhd->matrix, 9, buffer, size, offset);
1411 prop_copy_uint32 (tkhd->width, buffer, size, offset);
1412 prop_copy_uint32 (tkhd->height, buffer, size, offset);
1414 atom_write_size (buffer, size, offset, original_offset);
1415 return *offset - original_offset;
1419 atom_hdlr_copy_data (AtomHDLR * hdlr, guint8 ** buffer, guint64 * size,
1422 guint64 original_offset = *offset;
1424 if (!atom_full_copy_data (&hdlr->header, buffer, size, offset)) {
1428 prop_copy_fourcc (hdlr->component_type, buffer, size, offset);
1429 prop_copy_fourcc (hdlr->handler_type, buffer, size, offset);
1430 prop_copy_fourcc (hdlr->manufacturer, buffer, size, offset);
1431 prop_copy_uint32 (hdlr->flags, buffer, size, offset);
1432 prop_copy_uint32 (hdlr->flags_mask, buffer, size, offset);
1434 prop_copy_size_string ((guint8 *) hdlr->name, strlen (hdlr->name), buffer,
1437 atom_write_size (buffer, size, offset, original_offset);
1438 return *offset - original_offset;
1442 atom_vmhd_copy_data (AtomVMHD * vmhd, guint8 ** buffer, guint64 * size,
1445 guint64 original_offset = *offset;
1447 if (!atom_full_copy_data (&vmhd->header, buffer, size, offset)) {
1450 prop_copy_uint16 (vmhd->graphics_mode, buffer, size, offset);
1451 prop_copy_uint16_array (vmhd->opcolor, 3, buffer, size, offset);
1453 atom_write_size (buffer, size, offset, original_offset);
1454 return original_offset - *offset;
1458 atom_smhd_copy_data (AtomSMHD * smhd, guint8 ** buffer, guint64 * size,
1461 guint64 original_offset = *offset;
1463 if (!atom_full_copy_data (&smhd->header, buffer, size, offset)) {
1466 prop_copy_uint16 (smhd->balance, buffer, size, offset);
1467 prop_copy_uint16 (smhd->reserved, buffer, size, offset);
1469 atom_write_size (buffer, size, offset, original_offset);
1470 return original_offset - *offset;
1474 atom_hmhd_copy_data (AtomHMHD * hmhd, guint8 ** buffer, guint64 * size,
1477 guint64 original_offset = *offset;
1479 if (!atom_full_copy_data (&hmhd->header, buffer, size, offset)) {
1482 prop_copy_uint16 (hmhd->max_pdu_size, buffer, size, offset);
1483 prop_copy_uint16 (hmhd->avg_pdu_size, buffer, size, offset);
1484 prop_copy_uint32 (hmhd->max_bitrate, buffer, size, offset);
1485 prop_copy_uint32 (hmhd->avg_bitrate, buffer, size, offset);
1486 prop_copy_uint32 (hmhd->sliding_avg_bitrate, buffer, size, offset);
1488 atom_write_size (buffer, size, offset, original_offset);
1489 return original_offset - *offset;
1493 atom_url_same_file_flag (AtomURL * url)
1495 return (url->header.flags[2] & 0x1) == 1;
1499 atom_url_copy_data (AtomURL * url, guint8 ** buffer, guint64 * size,
1502 guint64 original_offset = *offset;
1504 if (!atom_full_copy_data (&url->header, buffer, size, offset)) {
1508 if (!atom_url_same_file_flag (url)) {
1509 prop_copy_null_terminated_string (url->location, buffer, size, offset);
1512 atom_write_size (buffer, size, offset, original_offset);
1513 return original_offset - *offset;
1517 atom_stts_copy_data (AtomSTTS * stts, guint8 ** buffer, guint64 * size,
1520 guint64 original_offset = *offset;
1523 if (!atom_full_copy_data (&stts->header, buffer, size, offset)) {
1527 prop_copy_uint32 (atom_array_get_len (&stts->entries), buffer, size, offset);
1528 /* minimize realloc */
1529 prop_copy_ensure_buffer (buffer, size, offset,
1530 8 * atom_array_get_len (&stts->entries));
1531 for (i = 0; i < atom_array_get_len (&stts->entries); i++) {
1532 STTSEntry *entry = &atom_array_index (&stts->entries, i);
1534 prop_copy_uint32 (entry->sample_count, buffer, size, offset);
1535 prop_copy_int32 (entry->sample_delta, buffer, size, offset);
1538 atom_write_size (buffer, size, offset, original_offset);
1539 return *offset - original_offset;
1543 atom_sample_entry_copy_data (SampleTableEntry * se, guint8 ** buffer,
1544 guint64 * size, guint64 * offset)
1546 guint64 original_offset = *offset;
1548 if (!atom_copy_data (&se->header, buffer, size, offset)) {
1552 prop_copy_uint8_array (se->reserved, 6, buffer, size, offset);
1553 prop_copy_uint16 (se->data_reference_index, buffer, size, offset);
1555 return *offset - original_offset;
1559 atom_esds_copy_data (AtomESDS * esds, guint8 ** buffer, guint64 * size,
1562 guint64 original_offset = *offset;
1564 if (!atom_full_copy_data (&esds->header, buffer, size, offset)) {
1567 if (!desc_es_descriptor_copy_data (&esds->es, buffer, size, offset)) {
1571 atom_write_size (buffer, size, offset, original_offset);
1572 return *offset - original_offset;
1576 atom_frma_copy_data (AtomFRMA * frma, guint8 ** buffer,
1577 guint64 * size, guint64 * offset)
1579 guint64 original_offset = *offset;
1581 if (!atom_copy_data (&(frma->header), buffer, size, offset))
1584 prop_copy_fourcc (frma->media_type, buffer, size, offset);
1586 atom_write_size (buffer, size, offset, original_offset);
1587 return *offset - original_offset;
1591 atom_mp4s_copy_data (SampleTableEntryMP4S * mp4s, guint8 ** buffer,
1592 guint64 * size, guint64 * offset)
1594 guint64 original_offset = *offset;
1596 if (!atom_sample_entry_copy_data (&mp4s->se, buffer, size, offset)) {
1599 if (!atom_esds_copy_data (&mp4s->es, buffer, size, offset)) {
1603 atom_write_size (buffer, size, offset, original_offset);
1604 return *offset - original_offset;
1608 atom_hint_sample_entry_copy_data (AtomHintSampleEntry * hse, guint8 ** buffer,
1609 guint64 * size, guint64 * offset)
1611 guint64 original_offset = *offset;
1613 if (!atom_sample_entry_copy_data (&hse->se, buffer, size, offset)) {
1617 prop_copy_uint32 (hse->size, buffer, size, offset);
1618 prop_copy_uint8_array (hse->data, hse->size, buffer, size, offset);
1620 atom_write_size (buffer, size, offset, original_offset);
1621 return *offset - original_offset;
1625 sample_entry_mp4a_copy_data (SampleTableEntryMP4A * mp4a, guint8 ** buffer,
1626 guint64 * size, guint64 * offset)
1628 guint64 original_offset = *offset;
1630 if (!atom_sample_entry_copy_data (&mp4a->se, buffer, size, offset)) {
1634 prop_copy_uint16 (mp4a->version, buffer, size, offset);
1635 prop_copy_uint16 (mp4a->revision_level, buffer, size, offset);
1636 prop_copy_uint32 (mp4a->vendor, buffer, size, offset);
1637 prop_copy_uint16 (mp4a->channels, buffer, size, offset);
1638 prop_copy_uint16 (mp4a->sample_size, buffer, size, offset);
1639 prop_copy_uint16 (mp4a->compression_id, buffer, size, offset);
1640 prop_copy_uint16 (mp4a->packet_size, buffer, size, offset);
1641 prop_copy_uint32 (mp4a->sample_rate, buffer, size, offset);
1643 /* this should always be 0 for mp4 flavor */
1644 if (mp4a->version == 1) {
1645 prop_copy_uint32 (mp4a->samples_per_packet, buffer, size, offset);
1646 prop_copy_uint32 (mp4a->bytes_per_packet, buffer, size, offset);
1647 prop_copy_uint32 (mp4a->bytes_per_frame, buffer, size, offset);
1648 prop_copy_uint32 (mp4a->bytes_per_sample, buffer, size, offset);
1651 if (mp4a->extension_atoms) {
1652 if (!atom_info_list_copy_data (mp4a->extension_atoms, buffer, size, offset))
1656 atom_write_size (buffer, size, offset, original_offset);
1657 return *offset - original_offset;
1661 sample_entry_mp4v_copy_data (SampleTableEntryMP4V * mp4v, guint8 ** buffer,
1662 guint64 * size, guint64 * offset)
1664 guint64 original_offset = *offset;
1666 if (!atom_sample_entry_copy_data (&mp4v->se, buffer, size, offset)) {
1670 prop_copy_uint16 (mp4v->version, buffer, size, offset);
1671 prop_copy_uint16 (mp4v->revision_level, buffer, size, offset);
1672 prop_copy_fourcc (mp4v->vendor, buffer, size, offset);
1673 prop_copy_uint32 (mp4v->temporal_quality, buffer, size, offset);
1674 prop_copy_uint32 (mp4v->spatial_quality, buffer, size, offset);
1676 prop_copy_uint16 (mp4v->width, buffer, size, offset);
1677 prop_copy_uint16 (mp4v->height, buffer, size, offset);
1679 prop_copy_uint32 (mp4v->horizontal_resolution, buffer, size, offset);
1680 prop_copy_uint32 (mp4v->vertical_resolution, buffer, size, offset);
1681 prop_copy_uint32 (mp4v->datasize, buffer, size, offset);
1683 prop_copy_uint16 (mp4v->frame_count, buffer, size, offset);
1685 prop_copy_fixed_size_string ((guint8 *) mp4v->compressor, 32, buffer, size,
1688 prop_copy_uint16 (mp4v->depth, buffer, size, offset);
1689 prop_copy_uint16 (mp4v->color_table_id, buffer, size, offset);
1692 if (mp4v->extension_atoms &&
1693 !atom_info_list_copy_data (mp4v->extension_atoms, buffer, size, offset))
1696 atom_write_size (buffer, size, offset, original_offset);
1697 return *offset - original_offset;
1701 atom_stsz_copy_data (AtomSTSZ * stsz, guint8 ** buffer, guint64 * size,
1704 guint64 original_offset = *offset;
1707 if (!atom_full_copy_data (&stsz->header, buffer, size, offset)) {
1711 prop_copy_uint32 (stsz->sample_size, buffer, size, offset);
1712 prop_copy_uint32 (stsz->table_size, buffer, size, offset);
1713 if (stsz->sample_size == 0) {
1714 /* minimize realloc */
1715 prop_copy_ensure_buffer (buffer, size, offset, 4 * stsz->table_size);
1716 /* entry count must match sample count */
1717 g_assert (atom_array_get_len (&stsz->entries) == stsz->table_size);
1718 for (i = 0; i < atom_array_get_len (&stsz->entries); i++) {
1719 prop_copy_uint32 (atom_array_index (&stsz->entries, i), buffer, size,
1724 atom_write_size (buffer, size, offset, original_offset);
1725 return *offset - original_offset;
1729 atom_stsc_copy_data (AtomSTSC * stsc, guint8 ** buffer, guint64 * size,
1732 guint64 original_offset = *offset;
1735 if (!atom_full_copy_data (&stsc->header, buffer, size, offset)) {
1739 prop_copy_uint32 (atom_array_get_len (&stsc->entries), buffer, size, offset);
1740 /* minimize realloc */
1741 prop_copy_ensure_buffer (buffer, size, offset,
1742 12 * atom_array_get_len (&stsc->entries));
1744 for (i = 0; i < atom_array_get_len (&stsc->entries); i++) {
1745 STSCEntry *entry = &atom_array_index (&stsc->entries, i);
1747 prop_copy_uint32 (entry->first_chunk, buffer, size, offset);
1748 prop_copy_uint32 (entry->samples_per_chunk, buffer, size, offset);
1749 prop_copy_uint32 (entry->sample_description_index, buffer, size, offset);
1752 atom_write_size (buffer, size, offset, original_offset);
1753 return *offset - original_offset;
1757 atom_ctts_copy_data (AtomCTTS * ctts, guint8 ** buffer, guint64 * size,
1760 guint64 original_offset = *offset;
1763 if (!atom_full_copy_data (&ctts->header, buffer, size, offset)) {
1767 prop_copy_uint32 (atom_array_get_len (&ctts->entries), buffer, size, offset);
1768 /* minimize realloc */
1769 prop_copy_ensure_buffer (buffer, size, offset,
1770 8 * atom_array_get_len (&ctts->entries));
1771 for (i = 0; i < atom_array_get_len (&ctts->entries); i++) {
1772 CTTSEntry *entry = &atom_array_index (&ctts->entries, i);
1774 prop_copy_uint32 (entry->samplecount, buffer, size, offset);
1775 prop_copy_uint32 (entry->sampleoffset, buffer, size, offset);
1778 atom_write_size (buffer, size, offset, original_offset);
1779 return *offset - original_offset;
1783 atom_stco64_copy_data (AtomSTCO64 * stco64, guint8 ** buffer, guint64 * size,
1786 guint64 original_offset = *offset;
1788 gboolean trunc_to_32 = stco64->header.header.type == FOURCC_stco;
1790 if (!atom_full_copy_data (&stco64->header, buffer, size, offset)) {
1794 prop_copy_uint32 (atom_array_get_len (&stco64->entries), buffer, size,
1797 /* minimize realloc */
1798 prop_copy_ensure_buffer (buffer, size, offset,
1799 8 * atom_array_get_len (&stco64->entries));
1800 for (i = 0; i < atom_array_get_len (&stco64->entries); i++) {
1801 guint64 *value = &atom_array_index (&stco64->entries, i);
1804 prop_copy_uint32 ((guint32) * value, buffer, size, offset);
1806 prop_copy_uint64 (*value, buffer, size, offset);
1810 atom_write_size (buffer, size, offset, original_offset);
1811 return *offset - original_offset;
1815 atom_stss_copy_data (AtomSTSS * stss, guint8 ** buffer, guint64 * size,
1818 guint64 original_offset = *offset;
1821 if (atom_array_get_len (&stss->entries) == 0) {
1822 /* FIXME not needing this atom might be confused with error while copying */
1826 if (!atom_full_copy_data (&stss->header, buffer, size, offset)) {
1830 prop_copy_uint32 (atom_array_get_len (&stss->entries), buffer, size, offset);
1831 /* minimize realloc */
1832 prop_copy_ensure_buffer (buffer, size, offset,
1833 4 * atom_array_get_len (&stss->entries));
1834 for (i = 0; i < atom_array_get_len (&stss->entries); i++) {
1835 prop_copy_uint32 (atom_array_index (&stss->entries, i), buffer, size,
1839 atom_write_size (buffer, size, offset, original_offset);
1840 return *offset - original_offset;
1844 atom_stsd_copy_data (AtomSTSD * stsd, guint8 ** buffer, guint64 * size,
1847 guint64 original_offset = *offset;
1850 if (!atom_full_copy_data (&stsd->header, buffer, size, offset)) {
1854 prop_copy_uint32 (stsd->n_entries, buffer, size, offset);
1856 for (walker = g_list_last (stsd->entries); walker != NULL;
1857 walker = g_list_previous (walker)) {
1858 SampleTableEntry *se = (SampleTableEntry *) walker->data;
1860 switch (((Atom *) walker->data)->type) {
1862 if (!sample_entry_mp4a_copy_data ((SampleTableEntryMP4A *) walker->data,
1863 buffer, size, offset)) {
1868 if (!atom_mp4s_copy_data ((SampleTableEntryMP4S *) walker->data,
1869 buffer, size, offset)) {
1874 if (!sample_entry_mp4v_copy_data ((SampleTableEntryMP4V *) walker->data,
1875 buffer, size, offset)) {
1880 if (se->kind == VIDEO) {
1881 if (!sample_entry_mp4v_copy_data ((SampleTableEntryMP4V *)
1882 walker->data, buffer, size, offset)) {
1885 } else if (se->kind == AUDIO) {
1886 if (!sample_entry_mp4a_copy_data ((SampleTableEntryMP4A *)
1887 walker->data, buffer, size, offset)) {
1891 if (!atom_hint_sample_entry_copy_data (
1892 (AtomHintSampleEntry *) walker->data, buffer, size, offset)) {
1900 atom_write_size (buffer, size, offset, original_offset);
1901 return *offset - original_offset;
1905 atom_stbl_copy_data (AtomSTBL * stbl, guint8 ** buffer, guint64 * size,
1908 guint64 original_offset = *offset;
1910 if (!atom_copy_data (&stbl->header, buffer, size, offset)) {
1914 if (!atom_stsd_copy_data (&stbl->stsd, buffer, size, offset)) {
1917 if (!atom_stts_copy_data (&stbl->stts, buffer, size, offset)) {
1920 /* this atom is optional, so let's check if we need it
1921 * (to avoid false error) */
1922 if (atom_array_get_len (&stbl->stss.entries)) {
1923 if (!atom_stss_copy_data (&stbl->stss, buffer, size, offset)) {
1928 if (!atom_stsc_copy_data (&stbl->stsc, buffer, size, offset)) {
1931 if (!atom_stsz_copy_data (&stbl->stsz, buffer, size, offset)) {
1935 if (!atom_ctts_copy_data (stbl->ctts, buffer, size, offset)) {
1939 if (!atom_stco64_copy_data (&stbl->stco64, buffer, size, offset)) {
1943 atom_write_size (buffer, size, offset, original_offset);
1944 return original_offset - *offset;
1949 atom_dref_copy_data (AtomDREF * dref, guint8 ** buffer, guint64 * size,
1952 guint64 original_offset = *offset;
1955 if (!atom_full_copy_data (&dref->header, buffer, size, offset)) {
1959 prop_copy_uint32 (g_list_length (dref->entries), buffer, size, offset);
1961 walker = dref->entries;
1962 while (walker != NULL) {
1963 Atom *atom = (Atom *) walker->data;
1965 if (atom->type == FOURCC_url_) {
1966 atom_url_copy_data ((AtomURL *) atom, buffer, size, offset);
1967 } else if (atom->type == FOURCC_alis) {
1968 atom_full_copy_data ((AtomFull *) atom, buffer, size, offset);
1970 g_error ("Unsupported atom used inside dref atom");
1972 walker = g_list_next (walker);
1975 atom_write_size (buffer, size, offset, original_offset);
1976 return *offset - original_offset;
1980 atom_dinf_copy_data (AtomDINF * dinf, guint8 ** buffer, guint64 * size,
1983 guint64 original_offset = *offset;
1985 if (!atom_copy_data (&dinf->header, buffer, size, offset)) {
1989 if (!atom_dref_copy_data (&dinf->dref, buffer, size, offset)) {
1993 atom_write_size (buffer, size, offset, original_offset);
1994 return original_offset - *offset;
1998 atom_minf_copy_data (AtomMINF * minf, guint8 ** buffer, guint64 * size,
2001 guint64 original_offset = *offset;
2003 if (!atom_copy_data (&minf->header, buffer, size, offset)) {
2008 if (!atom_vmhd_copy_data (minf->vmhd, buffer, size, offset)) {
2011 } else if (minf->smhd) {
2012 if (!atom_smhd_copy_data (minf->smhd, buffer, size, offset)) {
2015 } else if (minf->hmhd) {
2016 if (!atom_hmhd_copy_data (minf->hmhd, buffer, size, offset)) {
2022 if (!atom_hdlr_copy_data (minf->hdlr, buffer, size, offset)) {
2027 if (!atom_dinf_copy_data (&minf->dinf, buffer, size, offset)) {
2030 if (!atom_stbl_copy_data (&minf->stbl, buffer, size, offset)) {
2034 atom_write_size (buffer, size, offset, original_offset);
2035 return *offset - original_offset;
2039 atom_mdhd_copy_data (AtomMDHD * mdhd, guint8 ** buffer, guint64 * size,
2042 guint64 original_offset = *offset;
2044 if (!atom_full_copy_data (&mdhd->header, buffer, size, offset)) {
2048 if (!common_time_info_copy_data (&mdhd->time_info,
2049 atom_full_get_version (&mdhd->header) == 0, buffer, size, offset)) {
2053 prop_copy_uint16 (mdhd->language_code, buffer, size, offset);
2054 prop_copy_uint16 (mdhd->quality, buffer, size, offset);
2056 atom_write_size (buffer, size, offset, original_offset);
2057 return *offset - original_offset;
2061 atom_mdia_copy_data (AtomMDIA * mdia, guint8 ** buffer, guint64 * size,
2064 guint64 original_offset = *offset;
2066 if (!atom_copy_data (&mdia->header, buffer, size, offset)) {
2069 if (!atom_mdhd_copy_data (&mdia->mdhd, buffer, size, offset)) {
2072 if (!atom_hdlr_copy_data (&mdia->hdlr, buffer, size, offset)) {
2076 if (!atom_minf_copy_data (&mdia->minf, buffer, size, offset)) {
2080 atom_write_size (buffer, size, offset, original_offset);
2081 return *offset - original_offset;
2085 atom_elst_copy_data (AtomELST * elst, guint8 ** buffer, guint64 * size,
2088 guint64 original_offset = *offset;
2091 if (!atom_full_copy_data (&elst->header, buffer, size, offset)) {
2095 prop_copy_uint32 (g_slist_length (elst->entries), buffer, size, offset);
2097 for (walker = elst->entries; walker != NULL; walker = g_slist_next (walker)) {
2098 EditListEntry *entry = (EditListEntry *) walker->data;
2099 prop_copy_uint32 (entry->duration, buffer, size, offset);
2100 prop_copy_uint32 (entry->media_time, buffer, size, offset);
2101 prop_copy_uint32 (entry->media_rate, buffer, size, offset);
2103 atom_write_size (buffer, size, offset, original_offset);
2104 return *offset - original_offset;
2108 atom_edts_copy_data (AtomEDTS * edts, guint8 ** buffer, guint64 * size,
2111 guint64 original_offset = *offset;
2113 if (!atom_copy_data (&(edts->header), buffer, size, offset))
2116 if (!atom_elst_copy_data (&(edts->elst), buffer, size, offset))
2119 atom_write_size (buffer, size, offset, original_offset);
2120 return *offset - original_offset;
2124 atom_trak_copy_data (AtomTRAK * trak, guint8 ** buffer, guint64 * size,
2127 guint64 original_offset = *offset;
2129 if (!atom_copy_data (&trak->header, buffer, size, offset)) {
2132 if (!atom_tkhd_copy_data (&trak->tkhd, buffer, size, offset)) {
2136 if (!atom_edts_copy_data (trak->edts, buffer, size, offset)) {
2141 if (!atom_mdia_copy_data (&trak->mdia, buffer, size, offset)) {
2145 atom_write_size (buffer, size, offset, original_offset);
2146 return *offset - original_offset;
2150 atom_tag_data_copy_data (AtomTagData * data, guint8 ** buffer, guint64 * size,
2153 guint64 original_offset = *offset;
2155 if (!atom_full_copy_data (&data->header, buffer, size, offset)) {
2159 prop_copy_uint32 (data->reserved, buffer, size, offset);
2160 prop_copy_uint8_array (data->data, data->datalen, buffer, size, offset);
2162 atom_write_size (buffer, size, offset, original_offset);
2163 return *offset - original_offset;
2167 atom_tag_copy_data (AtomTag * tag, guint8 ** buffer, guint64 * size,
2170 guint64 original_offset = *offset;
2172 if (!atom_copy_data (&tag->header, buffer, size, offset)) {
2176 if (!atom_tag_data_copy_data (&tag->data, buffer, size, offset)) {
2180 atom_write_size (buffer, size, offset, original_offset);
2181 return *offset - original_offset;
2185 atom_ilst_copy_data (AtomILST * ilst, guint8 ** buffer, guint64 * size,
2188 guint64 original_offset = *offset;
2190 if (!atom_copy_data (&ilst->header, buffer, size, offset)) {
2194 if (ilst->entries &&
2195 !atom_info_list_copy_data (ilst->entries, buffer, size, offset))
2198 atom_write_size (buffer, size, offset, original_offset);
2199 return *offset - original_offset;
2203 atom_meta_copy_data (AtomMETA * meta, guint8 ** buffer, guint64 * size,
2206 guint64 original_offset = *offset;
2208 if (!atom_full_copy_data (&meta->header, buffer, size, offset)) {
2211 if (!atom_hdlr_copy_data (&meta->hdlr, buffer, size, offset)) {
2215 if (!atom_ilst_copy_data (meta->ilst, buffer, size, offset)) {
2220 atom_write_size (buffer, size, offset, original_offset);
2221 return *offset - original_offset;
2225 atom_udta_copy_data (AtomUDTA * udta, guint8 ** buffer, guint64 * size,
2228 guint64 original_offset = *offset;
2230 if (!atom_copy_data (&udta->header, buffer, size, offset)) {
2234 if (!atom_meta_copy_data (udta->meta, buffer, size, offset)) {
2238 if (udta->entries) {
2240 if (!atom_info_list_copy_data (udta->entries, buffer, size, offset))
2244 atom_write_size (buffer, size, offset, original_offset);
2245 return *offset - original_offset;
2249 atom_moov_copy_data (AtomMOOV * atom, guint8 ** buffer, guint64 * size,
2252 guint64 original_offset = *offset;
2255 if (!atom_copy_data (&(atom->header), buffer, size, offset))
2258 if (!atom_mvhd_copy_data (&(atom->mvhd), buffer, size, offset))
2261 walker = g_list_first (atom->traks);
2262 while (walker != NULL) {
2263 if (!atom_trak_copy_data ((AtomTRAK *) walker->data, buffer, size, offset)) {
2266 walker = g_list_next (walker);
2270 if (!atom_udta_copy_data (atom->udta, buffer, size, offset)) {
2275 atom_write_size (buffer, size, offset, original_offset);
2276 return *offset - original_offset;
2280 atom_wave_copy_data (AtomWAVE * wave, guint8 ** buffer,
2281 guint64 * size, guint64 * offset)
2283 guint64 original_offset = *offset;
2285 if (!atom_copy_data (&(wave->header), buffer, size, offset))
2288 if (wave->extension_atoms) {
2289 if (!atom_info_list_copy_data (wave->extension_atoms, buffer, size, offset))
2293 atom_write_size (buffer, size, offset, original_offset);
2294 return *offset - original_offset;
2297 /* -- end of copy data functions -- */
2299 /* -- general functions, API and support functions */
2301 /* add samples to tables */
2304 atom_stsc_add_new_entry (AtomSTSC * stsc, guint32 first_chunk, guint32 nsamples)
2309 if ((len = atom_array_get_len (&stsc->entries)) &&
2310 ((atom_array_index (&stsc->entries, len - 1)).samples_per_chunk ==
2314 nentry.first_chunk = first_chunk;
2315 nentry.samples_per_chunk = nsamples;
2316 nentry.sample_description_index = 1;
2317 atom_array_append (&stsc->entries, nentry, 128);
2321 atom_stts_add_entry (AtomSTTS * stts, guint32 sample_count, gint32 sample_delta)
2323 STTSEntry *entry = NULL;
2325 if (G_LIKELY (atom_array_get_len (&stts->entries) != 0))
2326 entry = &atom_array_index (&stts->entries,
2327 atom_array_get_len (&stts->entries) - 1);
2329 if (entry && entry->sample_delta == sample_delta) {
2330 entry->sample_count += sample_count;
2334 nentry.sample_count = sample_count;
2335 nentry.sample_delta = sample_delta;
2336 atom_array_append (&stts->entries, nentry, 256);
2341 atom_stsz_add_entry (AtomSTSZ * stsz, guint32 nsamples, guint32 size)
2345 stsz->table_size += nsamples;
2346 if (stsz->sample_size != 0) {
2347 /* it is constant size, we don't need entries */
2350 for (i = 0; i < nsamples; i++) {
2351 atom_array_append (&stsz->entries, size, 1024);
2356 atom_stco64_get_entry_count (AtomSTCO64 * stco64)
2358 return atom_array_get_len (&stco64->entries);
2362 atom_stco64_add_entry (AtomSTCO64 * stco64, guint64 entry)
2364 atom_array_append (&stco64->entries, entry, 256);
2368 atom_stss_add_entry (AtomSTSS * stss, guint32 sample)
2370 atom_array_append (&stss->entries, sample, 512);
2374 atom_stbl_add_stss_entry (AtomSTBL * stbl)
2376 guint32 sample_index = stbl->stsz.table_size;
2378 atom_stss_add_entry (&stbl->stss, sample_index);
2382 atom_ctts_add_entry (AtomCTTS * ctts, guint32 nsamples, guint32 offset)
2384 CTTSEntry *entry = NULL;
2386 if (G_LIKELY (atom_array_get_len (&ctts->entries) != 0))
2387 entry = &atom_array_index (&ctts->entries,
2388 atom_array_get_len (&ctts->entries) - 1);
2390 if (entry == NULL || entry->sampleoffset != offset) {
2393 nentry.samplecount = nsamples;
2394 nentry.sampleoffset = offset;
2395 atom_array_append (&ctts->entries, nentry, 256);
2397 entry->samplecount += nsamples;
2402 atom_stbl_add_ctts_entry (AtomSTBL * stbl, guint32 nsamples, guint32 offset)
2404 if (stbl->ctts == NULL) {
2405 stbl->ctts = atom_ctts_new ();
2407 atom_ctts_add_entry (stbl->ctts, nsamples, offset);
2411 atom_stbl_add_samples (AtomSTBL * stbl, guint32 nsamples, guint32 delta,
2412 guint32 size, guint64 chunk_offset, gboolean sync,
2413 gboolean do_pts, gint64 pts_offset)
2415 atom_stts_add_entry (&stbl->stts, nsamples, delta);
2416 atom_stsz_add_entry (&stbl->stsz, nsamples, size);
2417 atom_stco64_add_entry (&stbl->stco64, chunk_offset);
2418 atom_stsc_add_new_entry (&stbl->stsc,
2419 atom_stco64_get_entry_count (&stbl->stco64), nsamples);
2421 atom_stbl_add_stss_entry (stbl);
2423 atom_stbl_add_ctts_entry (stbl, nsamples, pts_offset);
2427 atom_trak_add_samples (AtomTRAK * trak, guint32 nsamples, guint32 delta,
2428 guint32 size, guint64 chunk_offset, gboolean sync,
2429 gboolean do_pts, gint64 pts_offset)
2431 AtomSTBL *stbl = &trak->mdia.minf.stbl;
2432 atom_stbl_add_samples (stbl, nsamples, delta, size, chunk_offset, sync,
2433 do_pts, pts_offset);
2436 /* trak and moov molding */
2439 atom_trak_get_timescale (AtomTRAK * trak)
2441 return trak->mdia.mdhd.time_info.timescale;
2445 atom_trak_set_id (AtomTRAK * trak, guint32 id)
2447 trak->tkhd.track_ID = id;
2451 atom_moov_add_trak (AtomMOOV * moov, AtomTRAK * trak)
2453 atom_trak_set_id (trak, moov->mvhd.next_track_id++);
2454 moov->traks = g_list_append (moov->traks, trak);
2458 atom_trak_get_duration (AtomTRAK * trak)
2460 return trak->tkhd.duration;
2464 atom_stts_get_total_duration (AtomSTTS * stts)
2469 for (i = 0; i < atom_array_get_len (&stts->entries); i++) {
2470 STTSEntry *entry = &atom_array_index (&stts->entries, i);
2472 sum += (guint64) (entry->sample_count) * entry->sample_delta;
2478 atom_trak_update_duration (AtomTRAK * trak, guint64 moov_timescale)
2480 trak->mdia.mdhd.time_info.duration =
2481 atom_stts_get_total_duration (&trak->mdia.minf.stbl.stts);
2482 if (trak->mdia.mdhd.time_info.timescale != 0) {
2483 trak->tkhd.duration =
2484 gst_util_uint64_scale (trak->mdia.mdhd.time_info.duration,
2485 moov_timescale, trak->mdia.mdhd.time_info.timescale);
2487 trak->tkhd.duration = 0;
2492 atom_moov_get_timescale (AtomMOOV * moov)
2494 return moov->mvhd.time_info.timescale;
2498 atom_moov_update_timescale (AtomMOOV * moov, guint32 timescale)
2500 moov->mvhd.time_info.timescale = timescale;
2504 atom_moov_update_duration (AtomMOOV * moov)
2506 GList *traks = moov->traks;
2507 guint64 dur, duration = 0;
2510 AtomTRAK *trak = (AtomTRAK *) traks->data;
2512 atom_trak_update_duration (trak, atom_moov_get_timescale (moov));
2513 dur = atom_trak_get_duration (trak);
2516 traks = g_list_next (traks);
2518 moov->mvhd.time_info.duration = duration;
2522 atom_set_type (Atom * atom, guint32 fourcc)
2524 atom->type = fourcc;
2528 atom_stbl_set_64bits (AtomSTBL * stbl, gboolean use)
2531 atom_set_type (&stbl->stco64.header.header, FOURCC_co64);
2533 atom_set_type (&stbl->stco64.header.header, FOURCC_stco);
2538 atom_trak_set_64bits (AtomTRAK * trak, gboolean use)
2540 atom_stbl_set_64bits (&trak->mdia.minf.stbl, use);
2544 atom_moov_set_64bits (AtomMOOV * moov, gboolean large_file)
2546 GList *traks = moov->traks;
2549 AtomTRAK *trak = (AtomTRAK *) traks->data;
2551 atom_trak_set_64bits (trak, large_file);
2552 traks = g_list_next (traks);
2557 atom_stco64_chunks_add_offset (AtomSTCO64 * stco64, guint32 offset)
2561 for (i = 0; i < atom_array_get_len (&stco64->entries); i++) {
2562 guint64 *value = &atom_array_index (&stco64->entries, i);
2569 atom_moov_chunks_add_offset (AtomMOOV * moov, guint32 offset)
2571 GList *traks = moov->traks;
2574 AtomTRAK *trak = (AtomTRAK *) traks->data;
2576 atom_stco64_chunks_add_offset (&trak->mdia.minf.stbl.stco64, offset);
2577 traks = g_list_next (traks);
2582 * Meta tags functions
2585 atom_moov_init_metatags (AtomMOOV * moov, AtomsContext * context)
2588 moov->udta = atom_udta_new ();
2590 if (context->flavor != ATOMS_TREE_FLAVOR_3GP) {
2591 if (!moov->udta->meta) {
2592 moov->udta->meta = atom_meta_new ();
2594 if (!moov->udta->meta->ilst) {
2595 moov->udta->meta->ilst = atom_ilst_new ();
2601 atom_tag_data_alloc_data (AtomTagData * data, guint size)
2603 if (data->data != NULL) {
2604 g_free (data->data);
2606 data->data = g_new0 (guint8, size);
2607 data->datalen = size;
2611 atom_moov_append_tag (AtomMOOV * moov, AtomInfo * tag)
2615 atom_moov_init_metatags (moov, &moov->context);
2616 if (moov->udta->meta)
2617 entries = &moov->udta->meta->ilst->entries;
2619 entries = &moov->udta->entries;
2620 *entries = g_list_append (*entries, tag);
2624 atom_moov_add_tag (AtomMOOV * moov, guint32 fourcc, guint32 flags,
2625 const guint8 * data, guint size)
2630 tag = atom_tag_new (fourcc, flags);
2632 atom_tag_data_alloc_data (tdata, size);
2633 g_memmove (tdata->data, data, size);
2635 atom_moov_append_tag (moov,
2636 build_atom_info_wrapper ((Atom *) tag, atom_tag_copy_data,
2641 atom_moov_add_str_tag (AtomMOOV * moov, guint32 fourcc, const gchar * value)
2643 gint len = strlen (value);
2646 atom_moov_add_tag (moov, fourcc, METADATA_TEXT_FLAG, (guint8 *) value, len);
2650 atom_moov_add_uint_tag (AtomMOOV * moov, guint32 fourcc, guint32 flags,
2653 guint8 data[8] = { 0, };
2656 GST_WRITE_UINT16_BE (data, value);
2657 atom_moov_add_tag (moov, fourcc, flags, data, 2);
2659 GST_WRITE_UINT32_BE (data + 2, value);
2660 atom_moov_add_tag (moov, fourcc, flags, data, 8);
2665 atom_moov_add_blob_tag (AtomMOOV * moov, guint8 * data, guint size)
2667 AtomData *data_atom;
2675 /* blob is unparsed atom;
2676 * extract size and fourcc, and wrap remainder in data atom */
2677 len = GST_READ_UINT32_BE (data);
2678 fourcc = GST_READ_UINT32_LE (data + 4);
2682 buf = gst_buffer_new ();
2683 GST_BUFFER_SIZE (buf) = len - 8;
2684 GST_BUFFER_DATA (buf) = data + 8;
2686 data_atom = atom_data_new_from_gst_buffer (fourcc, buf);
2687 gst_buffer_unref (buf);
2689 atom_moov_append_tag (moov,
2690 build_atom_info_wrapper ((Atom *) data_atom, atom_data_copy_data,
2695 atom_moov_add_3gp_tag (AtomMOOV * moov, guint32 fourcc, guint8 * data,
2698 AtomData *data_atom;
2702 /* need full atom */
2703 buf = gst_buffer_new_and_alloc (size + 4);
2704 bdata = GST_BUFFER_DATA (buf);
2705 /* full atom: version and flags */
2706 GST_WRITE_UINT32_BE (bdata, 0);
2707 memcpy (bdata + 4, data, size);
2709 data_atom = atom_data_new_from_gst_buffer (fourcc, buf);
2710 gst_buffer_unref (buf);
2712 atom_moov_append_tag (moov,
2713 build_atom_info_wrapper ((Atom *) data_atom, atom_data_copy_data,
2718 language_code (const char *lang)
2720 g_return_val_if_fail (lang != NULL, 0);
2721 g_return_val_if_fail (strlen (lang) == 3, 0);
2723 return (((lang[0] - 0x60) & 0x1F) << 10) + (((lang[1] - 0x60) & 0x1F) << 5) +
2724 ((lang[2] - 0x60) & 0x1F);
2728 atom_moov_add_3gp_str_int_tag (AtomMOOV * moov, guint32 fourcc,
2729 const gchar * value, gint16 ivalue)
2731 gint len = 0, size = 0;
2735 len = strlen (value);
2742 data = g_malloc (size + 3);
2743 /* language tag and null-terminated UTF-8 string */
2745 GST_WRITE_UINT16_BE (data, language_code (GST_QT_MUX_DEFAULT_TAG_LANGUAGE));
2746 /* include 0 terminator */
2747 memcpy (data + 2, value, len + 1);
2749 /* 16-bit unsigned int if standalone, otherwise 8-bit */
2752 GST_WRITE_UINT16_BE (data + size - 2, ivalue);
2754 GST_WRITE_UINT8 (data + size - 2, ivalue & 0xFF);
2759 atom_moov_add_3gp_tag (moov, fourcc, data, size);
2764 atom_moov_add_3gp_str_tag (AtomMOOV * moov, guint32 fourcc, const gchar * value)
2766 atom_moov_add_3gp_str_int_tag (moov, fourcc, value, -1);
2770 atom_moov_add_3gp_uint_tag (AtomMOOV * moov, guint32 fourcc, guint16 value)
2772 atom_moov_add_3gp_str_int_tag (moov, fourcc, NULL, value);
2776 atom_moov_add_xmp_tags (AtomMOOV * moov, const GstTagList * tags)
2778 GstBuffer *xmpbuffer = gst_tag_list_to_xmp_buffer (tags, TRUE);
2779 AtomData *data_atom = NULL;
2781 data_atom = atom_data_new_from_gst_buffer (FOURCC_XMP_, xmpbuffer);
2782 gst_buffer_unref (xmpbuffer);
2784 atom_moov_init_metatags (moov, &moov->context);
2786 moov->udta->entries = g_list_append (moov->udta->entries,
2787 build_atom_info_wrapper ((Atom *) data_atom, atom_data_copy_data,
2792 * Functions for specifying media types
2796 atom_minf_set_audio (AtomMINF * minf)
2798 atom_minf_clear_handlers (minf);
2799 minf->smhd = atom_smhd_new ();
2803 atom_minf_set_video (AtomMINF * minf, AtomsContext * context)
2805 atom_minf_clear_handlers (minf);
2806 minf->vmhd = atom_vmhd_new (context);
2810 atom_hdlr_set_type (AtomHDLR * hdlr, AtomsContext * context, guint32 comp_type,
2813 if (context->flavor == ATOMS_TREE_FLAVOR_MOV) {
2814 hdlr->component_type = comp_type;
2816 hdlr->handler_type = hdlr_type;
2820 atom_hdlr_set_name (AtomHDLR * hdlr, const char *name)
2823 g_free (hdlr->name);
2824 hdlr->name = g_strdup (name);
2828 atom_mdia_set_hdlr_type_audio (AtomMDIA * mdia, AtomsContext * context)
2830 atom_hdlr_set_type (&mdia->hdlr, context, FOURCC_mhlr, FOURCC_soun);
2831 /* Some players (low-end hardware) check for this name, which is what
2832 * QuickTime itself sets */
2833 atom_hdlr_set_name (&mdia->hdlr, "SoundHandler");
2837 atom_mdia_set_hdlr_type_video (AtomMDIA * mdia, AtomsContext * context)
2839 atom_hdlr_set_type (&mdia->hdlr, context, FOURCC_mhlr, FOURCC_vide);
2840 /* Some players (low-end hardware) check for this name, which is what
2841 * QuickTime itself sets */
2842 atom_hdlr_set_name (&mdia->hdlr, "VideoHandler");
2846 atom_mdia_set_audio (AtomMDIA * mdia, AtomsContext * context)
2848 atom_mdia_set_hdlr_type_audio (mdia, context);
2849 atom_minf_set_audio (&mdia->minf);
2853 atom_mdia_set_video (AtomMDIA * mdia, AtomsContext * context)
2855 atom_mdia_set_hdlr_type_video (mdia, context);
2856 atom_minf_set_video (&mdia->minf, context);
2860 atom_tkhd_set_audio (AtomTKHD * tkhd)
2862 tkhd->volume = 0x0100;
2863 tkhd->width = tkhd->height = 0;
2867 atom_tkhd_set_video (AtomTKHD * tkhd, AtomsContext * context, guint32 width,
2872 /* qt and ISO base media do not contradict, and examples agree */
2873 tkhd->width = width;
2874 tkhd->height = height;
2878 atom_edts_add_entry (AtomEDTS * edts, EditListEntry * entry)
2880 edts->elst.entries = g_slist_append (edts->elst.entries, entry);
2884 * Adds a new entry to this trak edits list
2885 * duration is in the moov's timescale
2886 * media_time is the offset in the media time to start from (media's timescale)
2887 * rate is a 32 bits fixed-point
2890 atom_trak_add_elst_entry (AtomTRAK * trak, guint32 duration, guint32 media_time,
2893 EditListEntry *entry = g_new (EditListEntry, 1);
2895 entry->duration = duration;
2896 entry->media_time = media_time;
2897 entry->media_rate = rate;
2899 if (trak->edts == NULL) {
2900 trak->edts = atom_edts_new ();
2902 atom_edts_add_entry (trak->edts, entry);
2905 /* re-negotiation is prevented at top-level, so only 1 entry expected.
2906 * Quite some more care here and elsewhere may be needed to
2907 * support several entries */
2908 static SampleTableEntryMP4A *
2909 atom_trak_add_audio_entry (AtomTRAK * trak, AtomsContext * context,
2912 AtomSTSD *stsd = &trak->mdia.minf.stbl.stsd;
2913 SampleTableEntryMP4A *mp4a = sample_entry_mp4a_new ();
2915 mp4a->se.header.type = type;
2916 mp4a->se.kind = AUDIO;
2917 mp4a->compression_id = -1;
2918 mp4a->se.data_reference_index = 1;
2920 stsd->entries = g_list_prepend (stsd->entries, mp4a);
2925 static SampleTableEntryMP4V *
2926 atom_trak_add_video_entry (AtomTRAK * trak, AtomsContext * context,
2929 SampleTableEntryMP4V *mp4v = sample_entry_mp4v_new (context);
2930 AtomSTSD *stsd = &trak->mdia.minf.stbl.stsd;
2932 mp4v->se.header.type = type;
2933 mp4v->se.kind = VIDEO;
2934 mp4v->se.data_reference_index = 1;
2935 mp4v->horizontal_resolution = 72 << 16;
2936 mp4v->vertical_resolution = 72 << 16;
2937 if (context->flavor == ATOMS_TREE_FLAVOR_MOV) {
2938 mp4v->spatial_quality = 512;
2939 mp4v->temporal_quality = 512;
2942 stsd->entries = g_list_prepend (stsd->entries, mp4v);
2948 atom_trak_set_constant_size_samples (AtomTRAK * trak, guint32 sample_size)
2950 trak->mdia.minf.stbl.stsz.sample_size = sample_size;
2954 atom_trak_set_audio (AtomTRAK * trak, AtomsContext * context)
2956 atom_tkhd_set_audio (&trak->tkhd);
2957 atom_mdia_set_audio (&trak->mdia, context);
2961 atom_trak_set_video (AtomTRAK * trak, AtomsContext * context, guint32 width,
2964 atom_tkhd_set_video (&trak->tkhd, context, width, height);
2965 atom_mdia_set_video (&trak->mdia, context);
2969 atom_trak_set_audio_commons (AtomTRAK * trak, AtomsContext * context,
2972 atom_trak_set_audio (trak, context);
2973 trak->mdia.mdhd.time_info.timescale = rate;
2977 atom_trak_set_video_commons (AtomTRAK * trak, AtomsContext * context,
2978 guint32 rate, guint32 width, guint32 height)
2980 atom_trak_set_video (trak, context, width, height);
2981 trak->mdia.mdhd.time_info.timescale = rate;
2982 trak->tkhd.width = width << 16;
2983 trak->tkhd.height = height << 16;
2987 atom_trak_set_audio_type (AtomTRAK * trak, AtomsContext * context,
2988 AudioSampleEntry * entry, guint32 scale, AtomInfo * ext, gint sample_size)
2990 SampleTableEntryMP4A *ste;
2992 atom_trak_set_audio_commons (trak, context, scale);
2993 atom_stsd_remove_entries (&trak->mdia.minf.stbl.stsd);
2994 ste = atom_trak_add_audio_entry (trak, context, entry->fourcc);
2996 trak->is_video = FALSE;
2997 trak->is_h264 = FALSE;
2999 ste->version = entry->version;
3000 ste->compression_id = entry->compression_id;
3001 ste->sample_size = entry->sample_size;
3002 ste->sample_rate = entry->sample_rate << 16;
3003 ste->channels = entry->channels;
3005 ste->samples_per_packet = entry->samples_per_packet;
3006 ste->bytes_per_sample = entry->bytes_per_sample;
3007 ste->bytes_per_packet = entry->bytes_per_packet;
3008 ste->bytes_per_frame = entry->bytes_per_frame;
3011 ste->extension_atoms = g_list_prepend (ste->extension_atoms, ext);
3013 /* 0 size means variable size */
3014 atom_trak_set_constant_size_samples (trak, sample_size);
3018 build_pasp_extension (AtomTRAK * trak, gint par_width, gint par_height)
3020 AtomData *atom_data;
3024 buf = gst_buffer_new_and_alloc (8);
3025 data = GST_BUFFER_DATA (buf);
3027 /* ihdr = image header box */
3028 GST_WRITE_UINT32_BE (data, par_width);
3029 GST_WRITE_UINT32_BE (data + 4, par_height);
3031 atom_data = atom_data_new_from_gst_buffer (FOURCC_pasp, buf);
3032 gst_buffer_unref (buf);
3034 return build_atom_info_wrapper ((Atom *) atom_data, atom_data_copy_data,
3039 atom_trak_set_video_type (AtomTRAK * trak, AtomsContext * context,
3040 VisualSampleEntry * entry, guint32 scale, GList * ext_atoms_list)
3042 SampleTableEntryMP4V *ste;
3043 gint dwidth, dheight;
3044 gint par_n = 0, par_d = 0;
3046 if ((entry->par_n != 1 || entry->par_d != 1) &&
3047 (entry->par_n != entry->par_d)) {
3048 par_n = entry->par_n;
3049 par_d = entry->par_d;
3052 dwidth = entry->width;
3053 dheight = entry->height;
3054 /* ISO file spec says track header w/h indicates track's visual presentation
3055 * (so this together with pixels w/h implicitly defines PAR) */
3056 if (par_n && (context->flavor != ATOMS_TREE_FLAVOR_MOV)) {
3057 if (par_n > par_d) {
3058 dwidth = entry->width * par_n / par_d;
3059 dheight = entry->height;
3061 dwidth = entry->width * par_n / par_d;
3062 dheight = entry->height;
3066 atom_trak_set_video_commons (trak, context, scale, dwidth, dheight);
3067 atom_stsd_remove_entries (&trak->mdia.minf.stbl.stsd);
3068 ste = atom_trak_add_video_entry (trak, context, entry->fourcc);
3070 trak->is_video = TRUE;
3071 trak->is_h264 = (entry->fourcc == FOURCC_avc1);
3073 ste->version = entry->version;
3074 ste->width = entry->width;
3075 ste->height = entry->height;
3076 ste->depth = entry->depth;
3077 ste->color_table_id = entry->color_table_id;
3078 ste->frame_count = entry->frame_count;
3081 ste->extension_atoms = g_list_concat (ste->extension_atoms, ext_atoms_list);
3083 /* QT spec has a pasp extension atom in stsd that can hold PAR */
3084 if (par_n && (context->flavor == ATOMS_TREE_FLAVOR_MOV)) {
3085 ste->extension_atoms = g_list_append (ste->extension_atoms,
3086 build_pasp_extension (trak, par_n, par_d));
3090 /* some sample description construction helpers */
3093 build_esds_extension (AtomTRAK * trak, guint8 object_type, guint8 stream_type,
3094 const GstBuffer * codec_data)
3099 track_id = trak->tkhd.track_ID;
3101 esds = atom_esds_new ();
3102 esds->es.id = track_id & 0xFFFF;
3103 esds->es.dec_conf_desc.object_type = object_type;
3104 esds->es.dec_conf_desc.stream_type = stream_type << 2 | 0x01;
3106 /* optional DecoderSpecificInfo */
3108 DecoderSpecificInfoDescriptor *desc;
3110 esds->es.dec_conf_desc.dec_specific_info = desc =
3111 desc_dec_specific_info_new ();
3112 desc_dec_specific_info_alloc_data (desc, GST_BUFFER_SIZE (codec_data));
3114 memcpy (desc->data, GST_BUFFER_DATA (codec_data),
3115 GST_BUFFER_SIZE (codec_data));
3118 return build_atom_info_wrapper ((Atom *) esds, atom_esds_copy_data,
3123 build_mov_wave_extension (AtomTRAK * trak, guint32 fourcc, AtomInfo * atom1,
3124 AtomInfo * atom2, gboolean terminator)
3130 /* Build WAVE atom for sample table entry */
3131 wave = atom_wave_new ();
3133 /* Prepend Terminator atom to the WAVE list first, so it ends up last */
3135 ext_atom = (Atom *) atom_data_new (FOURCC_null);
3136 wave->extension_atoms =
3137 atom_info_list_prepend_atom (wave->extension_atoms, (Atom *) ext_atom,
3138 (AtomCopyDataFunc) atom_data_copy_data, (AtomFreeFunc) atom_data_free);
3141 /* Add supplied atoms to WAVE */
3143 wave->extension_atoms = g_list_prepend (wave->extension_atoms, atom2);
3145 wave->extension_atoms = g_list_prepend (wave->extension_atoms, atom1);
3147 /* Add FRMA to the WAVE */
3148 frma = atom_frma_new ();
3149 frma->media_type = fourcc;
3151 wave->extension_atoms =
3152 atom_info_list_prepend_atom (wave->extension_atoms, (Atom *) frma,
3153 (AtomCopyDataFunc) atom_frma_copy_data, (AtomFreeFunc) atom_frma_free);
3155 return build_atom_info_wrapper ((Atom *) wave, atom_wave_copy_data,
3160 build_mov_aac_extension (AtomTRAK * trak, const GstBuffer * codec_data)
3162 AtomInfo *esds, *mp4a;
3165 /* Add ESDS atom to WAVE */
3166 esds = build_esds_extension (trak, ESDS_OBJECT_TYPE_MPEG4_P3,
3167 ESDS_STREAM_TYPE_AUDIO, codec_data);
3169 /* Add MP4A atom to the WAVE:
3170 * not really in spec, but makes offset based players happy */
3171 buf = gst_buffer_new_and_alloc (4);
3172 *((guint32 *) GST_BUFFER_DATA (buf)) = 0;
3173 mp4a = build_codec_data_extension (FOURCC_mp4a, buf);
3174 gst_buffer_unref (buf);
3176 return build_mov_wave_extension (trak, FOURCC_mp4a, mp4a, esds, TRUE);
3180 build_mov_alac_extension (AtomTRAK * trak, const GstBuffer * codec_data)
3184 alac = build_codec_data_extension (FOURCC_alac, codec_data);
3186 return build_mov_wave_extension (trak, FOURCC_alac, NULL, alac, TRUE);
3190 build_fiel_extension (gint fields)
3192 AtomData *atom_data;
3199 buf = gst_buffer_new_and_alloc (1);
3200 GST_BUFFER_DATA (buf)[0] = (guint8) fields;
3203 atom_data_new_from_gst_buffer (GST_MAKE_FOURCC ('f', 'i', 'e', 'l'), buf);
3204 gst_buffer_unref (buf);
3206 return build_atom_info_wrapper ((Atom *) atom_data, atom_data_copy_data,
3211 build_jp2x_extension (const GstBuffer * prefix)
3213 AtomData *atom_data;
3220 atom_data_new_from_gst_buffer (GST_MAKE_FOURCC ('j', 'p', '2', 'x'),
3223 return build_atom_info_wrapper ((Atom *) atom_data, atom_data_copy_data,
3228 build_jp2h_extension (AtomTRAK * trak, gint width, gint height, guint32 fourcc,
3229 gint ncomp, const GValue * cmap_array, const GValue * cdef_array)
3231 AtomData *atom_data;
3235 gint idhr_size = 22;
3236 gint colr_size = 15;
3237 gint cmap_size = 0, cdef_size = 0;
3238 gint cmap_array_size = 0;
3239 gint cdef_array_size = 0;
3240 GstByteWriter writer;
3242 g_return_val_if_fail (cmap_array == NULL ||
3243 GST_VALUE_HOLDS_ARRAY (cmap_array), NULL);
3244 g_return_val_if_fail (cdef_array == NULL ||
3245 GST_VALUE_HOLDS_ARRAY (cdef_array), NULL);
3247 if (fourcc == GST_MAKE_FOURCC ('s', 'R', 'G', 'B')) {
3251 } else if (fourcc == GST_MAKE_FOURCC ('G', 'R', 'A', 'Y')) {
3255 } else if (fourcc == GST_MAKE_FOURCC ('s', 'Y', 'U', 'V')) {
3263 cmap_array_size = gst_value_array_get_size (cmap_array);
3264 cmap_size = 8 + cmap_array_size * 4;
3267 cdef_array_size = gst_value_array_get_size (cdef_array);
3268 cdef_size = 8 + 2 + cdef_array_size * 6;
3271 buf = gst_buffer_new_and_alloc (idhr_size + colr_size + cmap_size +
3273 gst_byte_writer_init_with_buffer (&writer, buf, FALSE);
3275 /* ihdr = image header box */
3276 gst_byte_writer_put_uint32_be (&writer, 22);
3277 gst_byte_writer_put_uint32_le (&writer, GST_MAKE_FOURCC ('i', 'h', 'd', 'r'));
3278 gst_byte_writer_put_uint32_be (&writer, height);
3279 gst_byte_writer_put_uint32_be (&writer, width);
3280 gst_byte_writer_put_uint16_be (&writer, ncomp);
3281 /* 8 bits per component, unsigned */
3282 gst_byte_writer_put_uint8 (&writer, 0x7);
3283 /* compression type; reserved */
3284 gst_byte_writer_put_uint8 (&writer, 0x7);
3285 /* colour space (un)known */
3286 gst_byte_writer_put_uint8 (&writer, 0x0);
3287 /* intellectual property right (box present) */
3288 gst_byte_writer_put_uint8 (&writer, 0x0);
3290 /* colour specification box */
3291 gst_byte_writer_put_uint32_be (&writer, 15);
3292 gst_byte_writer_put_uint32_le (&writer, GST_MAKE_FOURCC ('c', 'o', 'l', 'r'));
3294 /* specification method: enumerated */
3295 gst_byte_writer_put_uint8 (&writer, 0x1);
3296 /* precedence; reserved */
3297 gst_byte_writer_put_uint8 (&writer, 0x0);
3298 /* approximation; reserved */
3299 gst_byte_writer_put_uint8 (&writer, 0x0);
3300 /* enumerated colourspace */
3301 gst_byte_writer_put_uint32_be (&writer, cenum);
3304 gst_byte_writer_put_uint32_be (&writer, cmap_size);
3305 gst_byte_writer_put_uint32_le (&writer,
3306 GST_MAKE_FOURCC ('c', 'm', 'a', 'p'));
3307 for (i = 0; i < cmap_array_size; i++) {
3313 item = gst_value_array_get_value (cmap_array, i);
3314 value = g_value_get_int (item);
3316 /* value is '(mtyp << 24) | (pcol << 16) | cmp' */
3317 cmp = value & 0xFFFF;
3319 pcol = (value >> 16) & 0xFF;
3322 GST_WARNING ("MTYP of cmap atom signals Pallete Mapping, but we don't "
3323 "handle Pallete mapping atoms yet");
3325 gst_byte_writer_put_uint16_be (&writer, cmp);
3326 gst_byte_writer_put_uint8 (&writer, mtyp);
3327 gst_byte_writer_put_uint8 (&writer, pcol);
3332 gst_byte_writer_put_uint32_be (&writer, cdef_size);
3333 gst_byte_writer_put_uint32_le (&writer,
3334 GST_MAKE_FOURCC ('c', 'd', 'e', 'f'));
3335 gst_byte_writer_put_uint16_be (&writer, cdef_array_size);
3336 for (i = 0; i < cdef_array_size; i++) {
3339 item = gst_value_array_get_value (cdef_array, i);
3340 value = g_value_get_int (item);
3342 gst_byte_writer_put_uint16_be (&writer, i);
3344 gst_byte_writer_put_uint16_be (&writer, 0);
3345 gst_byte_writer_put_uint16_be (&writer, value);
3346 } else if (value < 0) {
3347 gst_byte_writer_put_uint16_be (&writer, -value);
3348 gst_byte_writer_put_uint16_be (&writer, 0); /* TODO what here? */
3350 gst_byte_writer_put_uint16_be (&writer, 1);
3351 gst_byte_writer_put_uint16_be (&writer, 0);
3356 g_assert (gst_byte_writer_get_remaining (&writer) == 0);
3358 atom_data = atom_data_new_from_gst_buffer (FOURCC_jp2h, buf);
3359 gst_buffer_unref (buf);
3361 return build_atom_info_wrapper ((Atom *) atom_data, atom_data_copy_data,
3366 build_codec_data_extension (guint32 fourcc, const GstBuffer * codec_data)
3369 AtomInfo *result = NULL;
3372 data = atom_data_new_from_gst_buffer (fourcc, codec_data);
3373 result = build_atom_info_wrapper ((Atom *) data, atom_data_copy_data,
3381 build_amr_extension (void)
3387 buf = gst_buffer_new ();
3388 GST_BUFFER_DATA (buf) = ext;
3389 GST_BUFFER_SIZE (buf) = sizeof (ext);
3392 GST_WRITE_UINT32_LE (ext, 0);
3393 /* decoder version */
3394 GST_WRITE_UINT8 (ext + 4, 0);
3395 /* mode set (all modes) */
3396 GST_WRITE_UINT16_BE (ext + 5, 0x81FF);
3397 /* mode change period (no restriction) */
3398 GST_WRITE_UINT8 (ext + 7, 0);
3399 /* frames per sample */
3400 GST_WRITE_UINT8 (ext + 8, 1);
3402 res = build_codec_data_extension (GST_MAKE_FOURCC ('d', 'a', 'm', 'r'), buf);
3403 gst_buffer_unref (buf);
3408 build_h263_extension (void)
3414 buf = gst_buffer_new ();
3415 GST_BUFFER_DATA (buf) = ext;
3416 GST_BUFFER_SIZE (buf) = sizeof (ext);
3419 GST_WRITE_UINT32_LE (ext, 0);
3420 /* decoder version */
3421 GST_WRITE_UINT8 (ext + 4, 0);
3422 /* level / profile */
3423 /* FIXME ? maybe ? obtain somewhere; baseline for now */
3424 GST_WRITE_UINT8 (ext + 5, 10);
3425 GST_WRITE_UINT8 (ext + 6, 0);
3427 res = build_codec_data_extension (GST_MAKE_FOURCC ('d', '2', '6', '3'), buf);
3428 gst_buffer_unref (buf);
3433 build_gama_atom (gdouble gamma)
3439 /* convert to uint32 from fixed point */
3440 gamma_fp = (guint32) 65536 *gamma;
3442 buf = gst_buffer_new_and_alloc (4);
3443 GST_WRITE_UINT32_BE (GST_BUFFER_DATA (buf), gamma_fp);
3444 res = build_codec_data_extension (FOURCC_gama, buf);
3445 gst_buffer_unref (buf);
3450 build_SMI_atom (const GstBuffer * seqh)
3455 /* the seqh plus its size and fourcc */
3456 buf = gst_buffer_new_and_alloc (GST_BUFFER_SIZE (seqh) + 8);
3458 GST_WRITE_UINT32_LE (GST_BUFFER_DATA (buf), FOURCC_SEQH);
3459 GST_WRITE_UINT32_BE (GST_BUFFER_DATA (buf) + 4, GST_BUFFER_SIZE (seqh));
3460 memcpy (GST_BUFFER_DATA (buf) + 8, GST_BUFFER_DATA (seqh),
3461 GST_BUFFER_SIZE (seqh));
3462 res = build_codec_data_extension (FOURCC_SMI_, buf);
3463 gst_buffer_unref (buf);
3468 build_ima_adpcm_atom (gint channels, gint rate, gint blocksize)
3470 AtomData *atom_data;
3473 const gint ima_adpcm_atom_size = 20;
3475 gint samplesperblock;
3478 /* The FOURCC for WAV codecs in QT is 'ms' followed by the 16 bit wave codec
3479 identifier. Note that the identifier here is big-endian, but when used
3480 within the WAVE header (below), it's little endian. */
3481 fourcc = MS_WAVE_FOURCC (0x11);
3483 buf = gst_buffer_new_and_alloc (ima_adpcm_atom_size);
3484 data = GST_BUFFER_DATA (buf);
3486 /* This atom's content is a WAVE header, including 2 bytes of extra data.
3487 Note that all of this is little-endian, unlike most stuff in qt. */
3488 /* 4 bytes header per channel (including 1 sample). Then 2 samples per byte
3489 for the rest. Simplifies to this. */
3490 samplesperblock = 2 * blocksize / channels - 7;
3491 bytespersec = rate * blocksize / samplesperblock;
3492 GST_WRITE_UINT16_LE (data, 0x11);
3493 GST_WRITE_UINT16_LE (data + 2, channels);
3494 GST_WRITE_UINT32_LE (data + 4, rate);
3495 GST_WRITE_UINT32_LE (data + 8, bytespersec);
3496 GST_WRITE_UINT16_LE (data + 12, blocksize);
3497 GST_WRITE_UINT16_LE (data + 14, 4);
3498 GST_WRITE_UINT16_LE (data + 16, 2); /* Two extra bytes */
3499 GST_WRITE_UINT16_LE (data + 18, samplesperblock);
3501 atom_data = atom_data_new_from_gst_buffer (fourcc, buf);
3502 gst_buffer_unref (buf);
3504 return build_atom_info_wrapper ((Atom *) atom_data, atom_data_copy_data,
3509 build_ima_adpcm_extension (gint channels, gint rate, gint blocksize)
3516 wave = atom_wave_new ();
3518 /* Prepend Terminator atom to the WAVE list first, so it ends up last */
3519 ext_atom = (Atom *) atom_data_new (FOURCC_null);
3520 wave->extension_atoms =
3521 atom_info_list_prepend_atom (wave->extension_atoms, (Atom *) ext_atom,
3522 (AtomCopyDataFunc) atom_data_copy_data, (AtomFreeFunc) atom_data_free);
3524 /* Add wave ima adpcm atom to WAVE */
3525 wave->extension_atoms = g_list_prepend (wave->extension_atoms,
3526 build_ima_adpcm_atom (channels, rate, blocksize));
3528 /* Add FRMA to the WAVE */
3529 frma = atom_frma_new ();
3530 frma->media_type = MS_WAVE_FOURCC (0x11);
3532 wave->extension_atoms =
3533 atom_info_list_prepend_atom (wave->extension_atoms, (Atom *) frma,
3534 (AtomCopyDataFunc) atom_frma_copy_data, (AtomFreeFunc) atom_frma_free);
3536 return build_atom_info_wrapper ((Atom *) wave, atom_wave_copy_data,