diff options
author | Mark Nauwelaerts <mark.nauwelaerts@collabora.co.uk> | 2010-11-19 17:41:41 +0100 |
---|---|---|
committer | Mark Nauwelaerts <mark.nauwelaerts@collabora.co.uk> | 2010-11-19 19:21:37 +0100 |
commit | 5abdd9ab03660506419e26da56890516bfe1f1bc (patch) | |
tree | 306cff5edc5e24ae6135333f1940f4cc89d187f2 /gst/qtmux | |
parent | 083c26aca86904f5540da1c56c7c2eca68cbcd77 (diff) |
qtmux: include sdtp atoms for ismv fragmented files
Based on patch by Marc-André Lureau <mlureau@flumotion.com>
Diffstat (limited to 'gst/qtmux')
-rw-r--r-- | gst/qtmux/atoms.c | 84 | ||||
-rw-r--r-- | gst/qtmux/atoms.h | 16 | ||||
-rw-r--r-- | gst/qtmux/gstqtmux.c | 3 |
3 files changed, 99 insertions, 4 deletions
diff --git a/gst/qtmux/atoms.c b/gst/qtmux/atoms.c index 755607857..2fcb45f2b 100644 --- a/gst/qtmux/atoms.c +++ b/gst/qtmux/atoms.c @@ -3324,6 +3324,14 @@ atom_trun_free (AtomTRUN * trun) g_free (trun); } +static void +atom_sdtp_free (AtomSDTP * sdtp) +{ + atom_full_clear (&sdtp->header); + atom_array_clear (&sdtp->entries); + g_free (sdtp); +} + void atom_traf_free (AtomTRAF * traf) { @@ -3337,6 +3345,14 @@ atom_traf_free (AtomTRAF * traf) g_list_free (traf->truns); traf->truns = NULL; + walker = traf->sdtps; + while (walker) { + atom_sdtp_free ((AtomSDTP *) walker->data); + walker = g_list_next (walker); + } + g_list_free (traf->sdtps); + traf->sdtps = NULL; + g_free (traf); } @@ -3453,6 +3469,24 @@ atom_trun_copy_data (AtomTRUN * trun, guint8 ** buffer, guint64 * size, } static guint64 +atom_sdtp_copy_data (AtomSDTP * sdtp, guint8 ** buffer, guint64 * size, + guint64 * offset) +{ + guint64 original_offset = *offset; + + if (!atom_full_copy_data (&sdtp->header, buffer, size, offset)) { + return 0; + } + + /* all entries at once */ + prop_copy_fixed_size_string (&atom_array_index (&sdtp->entries, 0), + atom_array_get_len (&sdtp->entries), buffer, size, offset); + + atom_write_size (buffer, size, offset, original_offset); + return *offset - original_offset; +} + +static guint64 atom_traf_copy_data (AtomTRAF * traf, guint8 ** buffer, guint64 * size, guint64 * offset, guint32 * data_offset) { @@ -3475,6 +3509,14 @@ atom_traf_copy_data (AtomTRAF * traf, guint8 ** buffer, guint64 * size, walker = g_list_next (walker); } + walker = g_list_first (traf->sdtps); + while (walker != NULL) { + if (!atom_sdtp_copy_data ((AtomSDTP *) walker->data, buffer, size, offset)) { + return 0; + } + walker = g_list_next (walker); + } + atom_write_size (buffer, size, offset, original_offset); return *offset - original_offset; } @@ -3551,6 +3593,38 @@ atom_trun_new (void) } static void +atom_sdtp_init (AtomSDTP * sdtp) +{ + guint8 flags[3] = { 0, 0, 0 }; + + atom_full_init (&sdtp->header, FOURCC_sdtp, 0, 0, 0, flags); + atom_array_init (&sdtp->entries, 512); +} + +static AtomSDTP * +atom_sdtp_new (AtomsContext * context) +{ + AtomSDTP *sdtp = g_new0 (AtomSDTP, 1); + + atom_sdtp_init (sdtp); + return sdtp; +} + +static void +atom_traf_add_sdtp (AtomTRAF * traf, AtomSDTP * sdtp) +{ + traf->sdtps = g_list_append (traf->sdtps, sdtp); +} + +static void +atom_sdtp_add_samples (AtomSDTP * sdtp, guint8 val) +{ + /* it does not make much/any sense according to specs, + * but that's how MS isml samples seem to do it */ + atom_array_append (&sdtp->entries, val, 256); +} + +static void atom_trun_add_samples (AtomTRUN * trun, guint32 delta, guint32 size, guint32 flags, gboolean do_pts, gint64 pts_offset) { @@ -3574,6 +3648,9 @@ atom_traf_init (AtomTRAF * traf, AtomsContext * context, guint32 track_ID) atom_header_set (&traf->header, FOURCC_traf, 0, 0); atom_tfhd_init (&traf->tfhd, track_ID); traf->truns = NULL; + + if (context->flavor == ATOMS_TREE_FLAVOR_ISML) + atom_traf_add_sdtp (traf, atom_sdtp_new (context)); } AtomTRAF * @@ -3593,14 +3670,14 @@ atom_traf_add_trun (AtomTRAF * traf, AtomTRUN * trun) void atom_traf_add_samples (AtomTRAF * traf, guint32 delta, guint32 size, - gboolean sync, gboolean do_pts, gint64 pts_offset) + gboolean sync, gboolean do_pts, gint64 pts_offset, gboolean sdtp_sync) { AtomTRUN *trun; guint32 flags; /* 0x10000 is sample-is-difference-sample flag * low byte stuff is what ismv uses */ - flags = sync ? 0x0040 : 0x1000c; + flags = (sync ? 0x0 : 0x10000) | (sdtp_sync ? 0x40 : 0xc0); if (G_UNLIKELY (!traf->truns)) { trun = atom_trun_new (); @@ -3641,6 +3718,9 @@ atom_traf_add_samples (AtomTRAF * traf, guint32 delta, guint32 size, atom_trun_add_samples (traf->truns->data, delta, size, flags, do_pts, pts_offset); + + if (traf->sdtps) + atom_sdtp_add_samples (traf->sdtps->data, 0x10 | ((flags & 0xff) >> 4)); } guint32 diff --git a/gst/qtmux/atoms.h b/gst/qtmux/atoms.h index a3ec67a1d..d074df429 100644 --- a/gst/qtmux/atoms.h +++ b/gst/qtmux/atoms.h @@ -684,6 +684,17 @@ typedef struct _AtomTRUN ATOM_ARRAY (TRUNSampleEntry) entries; } AtomTRUN; +typedef struct _AtomSDTP +{ + AtomFull header; + + /* not serialized */ + guint32 sample_count; + + /* array of fields */ + ATOM_ARRAY (guint8) entries; +} AtomSDTP; + typedef struct _AtomTRAF { Atom header; @@ -692,6 +703,8 @@ typedef struct _AtomTRAF /* list of AtomTRUN */ GList *truns; + /* list of AtomSDTP */ + GList *sdtps; } AtomTRAF; typedef struct _AtomMOOF @@ -839,7 +852,8 @@ AtomTRAF * atom_traf_new (AtomsContext * context, guint32 track_ID void atom_traf_free (AtomTRAF * traf); void atom_traf_add_samples (AtomTRAF * traf, guint32 delta, guint32 size, gboolean sync, - gboolean do_pts, gint64 pts_offset); + gboolean do_pts, gint64 pts_offset, + gboolean sdtp_sync); guint32 atom_traf_get_sample_num (AtomTRAF * traf); void atom_moof_add_traf (AtomMOOF *moof, AtomTRAF *traf); diff --git a/gst/qtmux/gstqtmux.c b/gst/qtmux/gstqtmux.c index b54ed0531..2841599b0 100644 --- a/gst/qtmux/gstqtmux.c +++ b/gst/qtmux/gstqtmux.c @@ -1875,7 +1875,8 @@ init: } /* add buffer and metadata */ - atom_traf_add_samples (pad->traf, delta, size, sync, do_pts, pts_offset); + atom_traf_add_samples (pad->traf, delta, size, sync, do_pts, pts_offset, + pad->sync && sync); atom_array_append (&pad->fragment_buffers, buf, 256); pad->fragment_duration -= delta; |