From ecab77b7e4c7b6f3563680f680f56f03b5dbfaeb Mon Sep 17 00:00:00 2001 From: Thomas Vander Stichele Date: Mon, 26 Mar 2007 20:56:35 +0000 Subject: [PATCH] ext/vorbis/vorbisdec.c (vorbis_dec_push_forward, vorbis_handle_data_packet): Original commit message from CVS: * ext/vorbis/vorbisdec.c (vorbis_dec_push_forward, vorbis_handle_data_packet): Correctly set DURATION to generate a timestamp-continuous stream. One bug left at the end; see ihttp://bugzilla.gnome.org/show_bug.cgi?id=423086 * tests/check/Makefile.am: * tests/check/pipelines/vorbisenc.c (GST_START_TEST): Add a test to check this. Without the above patch this test fails. --- ChangeLog | 11 +++++++++++ ext/vorbis/vorbisdec.c | 25 ++++++++++++++++++++++--- tests/check/Makefile.am | 8 +++++++- tests/check/pipelines/vorbisenc.c | 2 +- 4 files changed, 41 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 097eb5e47e..3d2422d903 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2007-03-26 Thomas Vander Stichele + + * ext/vorbis/vorbisdec.c (vorbis_dec_push_forward, + vorbis_handle_data_packet): + Correctly set DURATION to generate a timestamp-continuous stream. + One bug left at the end; see + ihttp://bugzilla.gnome.org/show_bug.cgi?id=423086 + * tests/check/Makefile.am: + * tests/check/pipelines/vorbisenc.c (GST_START_TEST): + Add a test to check this. Without the above patch this test fails. + 2007-03-26 Jan Schmidt * gst-libs/gst/rtp/Makefile.am: diff --git a/ext/vorbis/vorbisdec.c b/ext/vorbis/vorbisdec.c index 340267f7bd..58c3fd90ab 100644 --- a/ext/vorbis/vorbisdec.c +++ b/ext/vorbis/vorbisdec.c @@ -867,11 +867,15 @@ vorbis_dec_push_forward (GstVorbisDec * dec, GstBuffer * buf) } else { if (G_UNLIKELY (dec->queued)) { gint64 size; + GstClockTime ts; GList *walk; GST_DEBUG_OBJECT (dec, "first buffer with offset %lld", outoffset); + ts = gst_util_uint64_scale_int (outoffset, GST_SECOND, dec->vi.rate); size = g_list_length (dec->queued); + /* we walk the queued up list in reverse, and set the buffer fields + * calculating backwards */ for (walk = g_list_last (dec->queued); walk; walk = g_list_previous (walk)) { GstBuffer *buffer = GST_BUFFER (walk->data); @@ -882,8 +886,14 @@ vorbis_dec_push_forward (GstVorbisDec * dec, GstBuffer * buf) GST_BUFFER_OFFSET (buffer) = outoffset; GST_BUFFER_TIMESTAMP (buffer) = gst_util_uint64_scale_int (outoffset, GST_SECOND, dec->vi.rate); + GST_BUFFER_DURATION (buffer) = GST_CLOCK_DIFF (GST_BUFFER_TIMESTAMP + (buffer), ts); + ts = GST_BUFFER_TIMESTAMP (buffer); GST_DEBUG_OBJECT (dec, "patch buffer %" G_GUINT64_FORMAT - " offset %" G_GUINT64_FORMAT, size, outoffset); + ", offset %" G_GUINT64_FORMAT ", timestamp %" GST_TIME_FORMAT + ", duration %" GST_TIME_FORMAT, size, outoffset, + GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buffer)), + GST_TIME_ARGS (GST_BUFFER_DURATION (buffer))); size--; } for (walk = dec->queued; walk; walk = g_list_next (walk)) { @@ -970,6 +980,7 @@ vorbis_handle_data_packet (GstVorbisDec * vd, ogg_packet * packet) if ((sample_count = vorbis_synthesis_pcmout (&vd->vd, NULL)) == 0) goto done; + GST_LOG_OBJECT (vd, "%d samples ready for reading", sample_count); size = sample_count * vd->vi.channels * sizeof (float); /* alloc buffer for it */ @@ -996,7 +1007,7 @@ vorbis_handle_data_packet (GstVorbisDec * vd, ogg_packet * packet) vd->granulepos = packet->granulepos - sample_count; if (vd->cur_timestamp != GST_CLOCK_TIME_NONE) { - /* we have incomming timestamps */ + /* we have incoming timestamps */ timestamp = vd->cur_timestamp; GST_DEBUG_OBJECT (vd, "cur_timestamp: %" GST_TIME_FORMAT " + %" GST_TIME_FORMAT " = %" @@ -1008,12 +1019,20 @@ vorbis_handle_data_packet (GstVorbisDec * vd, ogg_packet * packet) vd->vi.rate); GST_BUFFER_OFFSET_END (out) = GST_BUFFER_OFFSET (out) + sample_count; } else { - /* we have incomming granulepos */ + /* we have incoming granulepos */ GST_BUFFER_OFFSET (out) = vd->granulepos; if (vd->granulepos != -1) { + GST_DEBUG_OBJECT (vd, "granulepos: %" G_GINT64_FORMAT, vd->granulepos); GST_BUFFER_OFFSET_END (out) = vd->granulepos + sample_count; timestamp = gst_util_uint64_scale_int (vd->granulepos, GST_SECOND, vd->vi.rate); + GST_DEBUG_OBJECT (vd, "corresponding timestamp %" GST_TIME_FORMAT, + GST_TIME_ARGS (timestamp)); + /* calculate a nano-second accurate duration */ + GST_BUFFER_DURATION (out) = GST_CLOCK_DIFF (timestamp, + (vd->granulepos + sample_count) * GST_SECOND / vd->vi.rate); + GST_DEBUG_OBJECT (vd, "set duration %" GST_TIME_FORMAT, + GST_TIME_ARGS (GST_BUFFER_DURATION (out))); } else { timestamp = -1; } diff --git a/tests/check/Makefile.am b/tests/check/Makefile.am index c91a6ad5db..cd0a1b23c8 100644 --- a/tests/check/Makefile.am +++ b/tests/check/Makefile.am @@ -44,7 +44,8 @@ check_pango = endif if USE_VORBIS -check_vorbis = elements/vorbisdec pipelines/vorbisenc elements/vorbistag +check_vorbis = elements/vorbisdec pipelines/vorbisenc pipelines/vorbisdec \ + elements/vorbistag else check_vorbis = endif @@ -217,6 +218,11 @@ libs_video_LDADD = \ $(GST_BASE_LIBS) \ $(LDADD) +# this seemingly useless CFLAGS line is here only to avoid +# vorbisdec.$(OBJEXT) by triggering creation of pipelines_vorbisdec.$(OBJEXT) +# instead +pipelines_vorbisdec_CFLAGS = $(AM_CFLAGS) + pipelines_oggmux_LDADD = $(LDADD) $(OGG_LIBS) pipelines_oggmux_CFLAGS = $(AM_CFLAGS) $(OGG_CFLAGS) diff --git a/tests/check/pipelines/vorbisenc.c b/tests/check/pipelines/vorbisenc.c index 2fadd771cc..5d12ac54a4 100644 --- a/tests/check/pipelines/vorbisenc.c +++ b/tests/check/pipelines/vorbisenc.c @@ -187,7 +187,7 @@ GST_START_TEST (test_timestamps) GError *error = NULL; pipe_str = g_strdup_printf ("audiotestsrc" - " ! audio/x-raw-int,rate=44100" " ! audioconvert ! vorbisenc ! fakesink"); + " ! audio/x-raw-int,rate=44100 ! audioconvert ! vorbisenc ! fakesink"); bin = gst_parse_launch (pipe_str, &error); fail_unless (bin != NULL, "Error parsing pipeline: %s",