From ad0c06763d687d6d10665c2d7c6aa6785c71d03b Mon Sep 17 00:00:00 2001 From: "Arwed v. Merkatz" Date: Wed, 25 Aug 2004 14:41:12 +0000 Subject: [PATCH] Interpret BLOCKDURATION and set buffer duration accordingly, enable demuxing of TTA audio from matroska, fixes bugs #... Original commit message from CVS: Interpret BLOCKDURATION and set buffer duration accordingly, enable demuxing of TTA audio from matroska, fixes bugs #148950 and #148951. --- ChangeLog | 6 ++++ gst/matroska/matroska-demux.c | 83 +++++++++++++++++++++++++++---------------- gst/matroska/matroska-ids.h | 1 + 3 files changed, 60 insertions(+), 30 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8a0dee8..ae5031a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,12 @@ * gst/matroska/matroska-demux.c: (gst_matroska_demux_parse_blockgroup), send vorbis headers at the beginning of a stream, fixes bug #141554. + Interpret BLOCKDURATION and set buffer duration accordingly, fixes + bug #148950. + * gst/matroska/matroska-demux.c: (gst_matroska_demux_audio_caps), + (gst_matroska_demux_plugin_init): + * gst/matroska/matroska-ids.h: + enable demuxing of TTA audio streams, fixes bug #148951. * gst/typefind/gsttypefindfunctions.c: (tta_type_find), (plugin_init), enable typefinding for TTA audio files, fixes bug #148711. diff --git a/gst/matroska/matroska-demux.c b/gst/matroska/matroska-demux.c index e4d6378..40e7f5f 100644 --- a/gst/matroska/matroska-demux.c +++ b/gst/matroska/matroska-demux.c @@ -312,6 +312,7 @@ gst_matroska_demux_add_stream (GstMatroskaDemux * demux) demux->src[demux->num_streams] = context; context->index = demux->num_streams; context->type = 0; /* no type yet */ + context->default_duration = 0; demux->num_streams++; /* start with the master */ @@ -1756,7 +1757,13 @@ gst_matroska_demux_parse_blockgroup (GstMatroskaDemux * demux, { GstEbmlRead *ebml = GST_EBML_READ (demux); gboolean res = TRUE; + gboolean readblock = FALSE; guint32 id; + guint64 block_duration = 0; + GstBuffer *buf = NULL; + gint stream = 0, n, laces = 0; + guint size = 0, *lace_size = NULL; + gint64 time = 0; while (res) { if (!(id = gst_ebml_peek_id (ebml, &demux->level_up))) { @@ -1772,11 +1779,8 @@ gst_matroska_demux_parse_blockgroup (GstMatroskaDemux * demux, * of the harder things, so this code is a bit complicated. * See http://www.matroska.org/ for documentation. */ case GST_MATROSKA_ID_BLOCK:{ - GstBuffer *buf; guint8 *data; - gint64 time; - guint size, *lace_size = NULL; - gint n, stream, flags, laces = 0; + gint flags = 0; guint64 num; if (!gst_ebml_read_buffer (ebml, &id, &buf)) { @@ -1921,39 +1925,15 @@ gst_matroska_demux_parse_blockgroup (GstMatroskaDemux * demux, gst_pad_push (demux->src[stream]->pad, GST_DATA (priv)); } - if (res) { - for (n = 0; n < laces; n++) { - GstBuffer *sub = gst_buffer_create_sub (buf, - GST_BUFFER_SIZE (buf) - size, - lace_size[n]); - - if (cluster_time != GST_CLOCK_TIME_NONE) { - if (time < 0 && (-time) > cluster_time) - GST_BUFFER_TIMESTAMP (sub) = cluster_time; - else - GST_BUFFER_TIMESTAMP (sub) = cluster_time + time; - } - /* FIXME: duration */ - - gst_pad_push (demux->src[stream]->pad, GST_DATA (sub)); - - size -= lace_size[n]; - } - } - - g_free (lace_size); - gst_buffer_unref (buf); + readblock = TRUE; break; } case GST_MATROSKA_ID_BLOCKDURATION:{ - guint64 num; - - if (!gst_ebml_read_uint (ebml, &id, &num)) { + if (!gst_ebml_read_uint (ebml, &id, &block_duration)) { res = FALSE; break; } - GST_WARNING ("FIXME: implement support for BlockDuration"); break; } case GST_MATROSKA_ID_REFERENCEBLOCK:{ @@ -1987,6 +1967,40 @@ gst_matroska_demux_parse_blockgroup (GstMatroskaDemux * demux, } } + if (res && readblock) { + guint64 duration = 0; + + if (block_duration) { + duration = block_duration * demux->time_scale; + } else if (demux->src[stream]->default_duration) { + duration = demux->src[stream]->default_duration; + } + for (n = 0; n < laces; n++) { + GstBuffer *sub = gst_buffer_create_sub (buf, + GST_BUFFER_SIZE (buf) - size, + lace_size[n]); + + if (cluster_time != GST_CLOCK_TIME_NONE) { + if (time < 0 && (-time) > cluster_time) + GST_BUFFER_TIMESTAMP (sub) = cluster_time; + else + GST_BUFFER_TIMESTAMP (sub) = cluster_time + time; + } + + /* do all laces have the same lenght? */ + if (duration) { + GST_BUFFER_DURATION (sub) = duration / laces; + } + gst_pad_push (demux->src[stream]->pad, GST_DATA (sub)); + + size -= lace_size[n]; + } + } + + if (readblock) + gst_buffer_unref (buf); + g_free (lace_size); + return res; } @@ -2644,6 +2658,14 @@ gst_matroska_demux_audio_caps (GstMatroskaTrackAudioContext * audiocontext, caps = gst_caps_new_simple ("audio/mpeg", "mpegversion", G_TYPE_INT, mpegversion, NULL); + } else if (!strcmp (codec_id, GST_MATROSKA_CODEC_ID_AUDIO_TTA)) { + if (audiocontext != NULL) { + caps = gst_caps_new_simple ("audio/x-raw-tta", + "width", G_TYPE_INT, audiocontext->bitdepth, NULL); + } else { + caps = gst_caps_from_string ("audio/x-raw-tta, " + "width = (int) { 8, 16, 24 }"); + } } else { GST_WARNING ("Unknown codec '%s', cannot build Caps", codec_id); g_print ("Codec=%s\n", codec_id); @@ -2742,6 +2764,7 @@ gst_matroska_demux_plugin_init (GstPlugin * plugin) GST_MATROSKA_CODEC_ID_AUDIO_AC3, GST_MATROSKA_CODEC_ID_AUDIO_ACM, GST_MATROSKA_CODEC_ID_AUDIO_VORBIS, + GST_MATROSKA_CODEC_ID_AUDIO_TTA, GST_MATROSKA_CODEC_ID_AUDIO_MPEG2, GST_MATROSKA_CODEC_ID_AUDIO_MPEG4, /* TODO: AC3-9/10, Real, Musepack, Quicktime */ /* FILLME */ diff --git a/gst/matroska/matroska-ids.h b/gst/matroska/matroska-ids.h index cb45665..ba55f20 100644 --- a/gst/matroska/matroska-ids.h +++ b/gst/matroska/matroska-ids.h @@ -149,6 +149,7 @@ #define GST_MATROSKA_CODEC_ID_AUDIO_ACM "A_MS/ACM" #define GST_MATROSKA_CODEC_ID_AUDIO_MPEG2 "A_AAC/MPEG2/" #define GST_MATROSKA_CODEC_ID_AUDIO_MPEG4 "A_AAC/MPEG4/" +#define GST_MATROSKA_CODEC_ID_AUDIO_TTA "A_TTA1" /* TODO: AC3-9/10 (?), Real, Musepack, Quicktime */ /* -- 2.7.4