From 796529c197304fabad3e17c8b38d214e9975dbb0 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Thu, 24 Jun 2004 12:45:27 +0000 Subject: [PATCH] gst/: Added some logging, fixed an overflow bug in videorate. Original commit message from CVS: * gst/audiorate/gstaudiorate.c: (gst_audiorate_link), (gst_audiorate_init), (gst_audiorate_chain), (gst_audiorate_set_property), (gst_audiorate_get_property): * gst/videorate/gstvideorate.c: (gst_videorate_class_init), (gst_videorate_chain): Added some logging, fixed an overflow bug in videorate. --- ChangeLog | 9 +++++++++ gst/audiorate/gstaudiorate.c | 33 ++++++++++++++++++++++++++------- gst/videorate/gstvideorate.c | 36 ++++++++++++++++++++++++++++++++---- 3 files changed, 67 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index a1992340bf..5629dfb910 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2004-06-24 Wim Taymans + + * gst/audiorate/gstaudiorate.c: (gst_audiorate_link), + (gst_audiorate_init), (gst_audiorate_chain), + (gst_audiorate_set_property), (gst_audiorate_get_property): + * gst/videorate/gstvideorate.c: (gst_videorate_class_init), + (gst_videorate_chain): + Added some logging, fixed an overflow bug in videorate. + 2004-06-24 Benjamin Otte * ext/kio/Makefile.am: diff --git a/gst/audiorate/gstaudiorate.c b/gst/audiorate/gstaudiorate.c index 9299fff030..a2f7cd1413 100644 --- a/gst/audiorate/gstaudiorate.c +++ b/gst/audiorate/gstaudiorate.c @@ -45,6 +45,8 @@ struct _GstAudiorate GstPad *sinkpad, *srcpad; + gint bytes_per_sample; + /* audio state */ guint64 next_offset; @@ -190,6 +192,7 @@ gst_audiorate_link (GstPad * pad, const GstCaps * caps) GstStructure *structure; GstPad *otherpad; GstPadLinkReturn res; + gint ret, channels, depth; audiorate = GST_AUDIORATE (gst_pad_get_parent (pad)); @@ -202,6 +205,13 @@ gst_audiorate_link (GstPad * pad, const GstCaps * caps) structure = gst_caps_get_structure (caps, 0); + ret = gst_structure_get_int (structure, "channels", &channels); + ret &= gst_structure_get_int (structure, "depth", &depth); + + audiorate->bytes_per_sample = channels * (depth / 8); + if (audiorate->bytes_per_sample == 0) + audiorate->bytes_per_sample = 1; + return GST_PAD_LINK_OK; } @@ -226,6 +236,7 @@ gst_audiorate_init (GstAudiorate * audiorate) gst_pad_set_link_function (audiorate->srcpad, gst_audiorate_link); gst_pad_set_getcaps_function (audiorate->srcpad, gst_pad_proxy_getcaps); + audiorate->bytes_per_sample = 1; audiorate->in = 0; audiorate->out = 0; audiorate->drop = 0; @@ -241,7 +252,6 @@ gst_audiorate_chain (GstPad * pad, GstData * data) GstClockTime in_time, in_duration; guint64 in_offset, in_offset_end; gint in_size; - gint bytes_per_sample; audiorate = GST_AUDIORATE (gst_pad_get_parent (pad)); @@ -261,8 +271,9 @@ gst_audiorate_chain (GstPad * pad, GstData * data) in_offset = GST_BUFFER_OFFSET (buf); in_offset_end = GST_BUFFER_OFFSET_END (buf); - /* FIXME: use caps to get this */ - bytes_per_sample = in_size / (in_offset_end - in_offset); + if (in_offset == GST_CLOCK_TIME_NONE || in_offset_end == GST_CLOCK_TIME_NONE) { + g_warning ("audiorate got buffer without offsets"); + } /* do we need to insert samples */ if (in_offset > audiorate->next_offset) { @@ -271,11 +282,13 @@ gst_audiorate_chain (GstPad * pad, GstData * data) guint64 fillsamples; fillsamples = in_offset - audiorate->next_offset; - fillsize = fillsamples * bytes_per_sample; + fillsize = fillsamples * audiorate->bytes_per_sample; fill = gst_buffer_new_and_alloc (fillsize); memset (GST_BUFFER_DATA (fill), 0, fillsize); + GST_LOG_OBJECT (audiorate, "inserting %lld samples", fillsamples); + GST_BUFFER_DURATION (fill) = in_duration * fillsize / in_size; GST_BUFFER_TIMESTAMP (fill) = in_time - GST_BUFFER_DURATION (fill); GST_BUFFER_OFFSET (fill) = audiorate->next_offset; @@ -290,7 +303,11 @@ gst_audiorate_chain (GstPad * pad, GstData * data) } else if (in_offset < audiorate->next_offset) { /* need to remove samples */ if (in_offset_end <= audiorate->next_offset) { - audiorate->drop += in_size / bytes_per_sample; + guint64 drop = in_size / audiorate->bytes_per_sample; + + audiorate->drop += drop; + + GST_LOG_OBJECT (audiorate, "dropping %lld samples", drop); /* we can drop the buffer completely */ gst_buffer_unref (buf); @@ -300,12 +317,12 @@ gst_audiorate_chain (GstPad * pad, GstData * data) return; } else { - gint truncsamples, truncsize, leftsize; + guint64 truncsamples, truncsize, leftsize; GstBuffer *trunc; /* truncate buffer */ truncsamples = audiorate->next_offset - in_offset; - truncsize = truncsamples * bytes_per_sample; + truncsize = truncsamples * audiorate->bytes_per_sample; leftsize = in_size - truncsize; trunc = gst_buffer_create_sub (buf, truncsize, in_size); @@ -315,6 +332,8 @@ gst_audiorate_chain (GstPad * pad, GstData * data) GST_BUFFER_OFFSET (trunc) = audiorate->next_offset; GST_BUFFER_OFFSET_END (trunc) = in_offset_end; + GST_LOG_OBJECT (audiorate, "truncating %lld samples", truncsamples); + gst_buffer_unref (buf); buf = trunc; diff --git a/gst/videorate/gstvideorate.c b/gst/videorate/gstvideorate.c index 63d3b6e9af..dc54fad962 100644 --- a/gst/videorate/gstvideorate.c +++ b/gst/videorate/gstvideorate.c @@ -339,12 +339,29 @@ gst_videorate_chain (GstPad * pad, GstData * data) prevtime = GST_BUFFER_TIMESTAMP (videorate->prevbuf); intime = GST_BUFFER_TIMESTAMP (buf); + GST_LOG_OBJECT (videorate, + "videorate: prev buf %" GST_TIME_FORMAT " new buf %" GST_TIME_FORMAT + " outgoing ts %" GST_TIME_FORMAT "\n", GST_TIME_ARGS (prevtime), + GST_TIME_ARGS (intime), GST_TIME_ARGS (videorate->next_ts)); + videorate->in++; /* got 2 buffers, see which one is the best */ do { - diff1 = abs (prevtime - videorate->next_ts); - diff2 = abs (intime - videorate->next_ts) * videorate->new_pref; + diff1 = ABS (prevtime - videorate->next_ts); + diff2 = ABS (intime - videorate->next_ts); + + /* take absolute values, beware: abs and ABS don't work for gint64 */ + if (diff1 < 0) + diff1 = -diff1; + if (diff2 < 0) + diff2 = -diff2; + + GST_LOG_OBJECT (videorate, + "videorate: diff with prev %" GST_TIME_FORMAT " diff with new %" + GST_TIME_FORMAT " outgoing ts %" GST_TIME_FORMAT "\n", + GST_TIME_ARGS (diff1), GST_TIME_ARGS (diff2), + GST_TIME_ARGS (videorate->next_ts)); /* output first one when its the best */ if (diff1 <= diff2) { @@ -360,6 +377,10 @@ gst_videorate_chain (GstPad * pad, GstData * data) GST_BUFFER_DURATION (outbuf) = videorate->next_ts - GST_BUFFER_TIMESTAMP (outbuf); gst_pad_push (videorate->srcpad, GST_DATA (outbuf)); + + GST_LOG_OBJECT (videorate, + "videorate: old is best, dup, outgoing ts %" GST_TIME_FORMAT " \n", + GST_TIME_ARGS (videorate->next_ts)); } /* continue while the first one was the best */ } @@ -376,9 +397,16 @@ gst_videorate_chain (GstPad * pad, GstData * data) videorate->drop++; if (!videorate->silent) g_object_notify (G_OBJECT (videorate), "drop"); + GST_LOG_OBJECT (videorate, + "videorate: new is best, old never used, drop, outgoing ts %" + GST_TIME_FORMAT " \n", GST_TIME_ARGS (videorate->next_ts)); } -// g_print ("swap: diff1 %lld, diff2 %lld, in %d, out %d, drop %d, dup %d\n", diff1, diff2, -// videorate->in, videorate->out, videorate->drop, videorate->dup); + GST_LOG_OBJECT (videorate, + "videorate: left loop, putting new in old, diff1 %" GST_TIME_FORMAT + ", diff2 %" GST_TIME_FORMAT + ", in %lld, out %lld, drop %lld, dup %lld\n", GST_TIME_ARGS (diff1), + GST_TIME_ARGS (diff2), videorate->in, videorate->out, videorate->drop, + videorate->dup); /* swap in new one when it's the best */ gst_buffer_unref (videorate->prevbuf);