mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-06-07 07:58:51 +00:00
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.
This commit is contained in:
parent
ee5531f7cd
commit
796529c197
3 changed files with 67 additions and 11 deletions
|
@ -1,3 +1,12 @@
|
||||||
|
2004-06-24 Wim Taymans <wim@fluendo.com>
|
||||||
|
|
||||||
|
* 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 <otte@gnome.org>
|
2004-06-24 Benjamin Otte <otte@gnome.org>
|
||||||
|
|
||||||
* ext/kio/Makefile.am:
|
* ext/kio/Makefile.am:
|
||||||
|
|
|
@ -45,6 +45,8 @@ struct _GstAudiorate
|
||||||
|
|
||||||
GstPad *sinkpad, *srcpad;
|
GstPad *sinkpad, *srcpad;
|
||||||
|
|
||||||
|
gint bytes_per_sample;
|
||||||
|
|
||||||
/* audio state */
|
/* audio state */
|
||||||
guint64 next_offset;
|
guint64 next_offset;
|
||||||
|
|
||||||
|
@ -190,6 +192,7 @@ gst_audiorate_link (GstPad * pad, const GstCaps * caps)
|
||||||
GstStructure *structure;
|
GstStructure *structure;
|
||||||
GstPad *otherpad;
|
GstPad *otherpad;
|
||||||
GstPadLinkReturn res;
|
GstPadLinkReturn res;
|
||||||
|
gint ret, channels, depth;
|
||||||
|
|
||||||
audiorate = GST_AUDIORATE (gst_pad_get_parent (pad));
|
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);
|
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;
|
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_link_function (audiorate->srcpad, gst_audiorate_link);
|
||||||
gst_pad_set_getcaps_function (audiorate->srcpad, gst_pad_proxy_getcaps);
|
gst_pad_set_getcaps_function (audiorate->srcpad, gst_pad_proxy_getcaps);
|
||||||
|
|
||||||
|
audiorate->bytes_per_sample = 1;
|
||||||
audiorate->in = 0;
|
audiorate->in = 0;
|
||||||
audiorate->out = 0;
|
audiorate->out = 0;
|
||||||
audiorate->drop = 0;
|
audiorate->drop = 0;
|
||||||
|
@ -241,7 +252,6 @@ gst_audiorate_chain (GstPad * pad, GstData * data)
|
||||||
GstClockTime in_time, in_duration;
|
GstClockTime in_time, in_duration;
|
||||||
guint64 in_offset, in_offset_end;
|
guint64 in_offset, in_offset_end;
|
||||||
gint in_size;
|
gint in_size;
|
||||||
gint bytes_per_sample;
|
|
||||||
|
|
||||||
audiorate = GST_AUDIORATE (gst_pad_get_parent (pad));
|
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 = GST_BUFFER_OFFSET (buf);
|
||||||
in_offset_end = GST_BUFFER_OFFSET_END (buf);
|
in_offset_end = GST_BUFFER_OFFSET_END (buf);
|
||||||
|
|
||||||
/* FIXME: use caps to get this */
|
if (in_offset == GST_CLOCK_TIME_NONE || in_offset_end == GST_CLOCK_TIME_NONE) {
|
||||||
bytes_per_sample = in_size / (in_offset_end - in_offset);
|
g_warning ("audiorate got buffer without offsets");
|
||||||
|
}
|
||||||
|
|
||||||
/* do we need to insert samples */
|
/* do we need to insert samples */
|
||||||
if (in_offset > audiorate->next_offset) {
|
if (in_offset > audiorate->next_offset) {
|
||||||
|
@ -271,11 +282,13 @@ gst_audiorate_chain (GstPad * pad, GstData * data)
|
||||||
guint64 fillsamples;
|
guint64 fillsamples;
|
||||||
|
|
||||||
fillsamples = in_offset - audiorate->next_offset;
|
fillsamples = in_offset - audiorate->next_offset;
|
||||||
fillsize = fillsamples * bytes_per_sample;
|
fillsize = fillsamples * audiorate->bytes_per_sample;
|
||||||
|
|
||||||
fill = gst_buffer_new_and_alloc (fillsize);
|
fill = gst_buffer_new_and_alloc (fillsize);
|
||||||
memset (GST_BUFFER_DATA (fill), 0, 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_DURATION (fill) = in_duration * fillsize / in_size;
|
||||||
GST_BUFFER_TIMESTAMP (fill) = in_time - GST_BUFFER_DURATION (fill);
|
GST_BUFFER_TIMESTAMP (fill) = in_time - GST_BUFFER_DURATION (fill);
|
||||||
GST_BUFFER_OFFSET (fill) = audiorate->next_offset;
|
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) {
|
} else if (in_offset < audiorate->next_offset) {
|
||||||
/* need to remove samples */
|
/* need to remove samples */
|
||||||
if (in_offset_end <= audiorate->next_offset) {
|
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 */
|
/* we can drop the buffer completely */
|
||||||
gst_buffer_unref (buf);
|
gst_buffer_unref (buf);
|
||||||
|
@ -300,12 +317,12 @@ gst_audiorate_chain (GstPad * pad, GstData * data)
|
||||||
|
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
gint truncsamples, truncsize, leftsize;
|
guint64 truncsamples, truncsize, leftsize;
|
||||||
GstBuffer *trunc;
|
GstBuffer *trunc;
|
||||||
|
|
||||||
/* truncate buffer */
|
/* truncate buffer */
|
||||||
truncsamples = audiorate->next_offset - in_offset;
|
truncsamples = audiorate->next_offset - in_offset;
|
||||||
truncsize = truncsamples * bytes_per_sample;
|
truncsize = truncsamples * audiorate->bytes_per_sample;
|
||||||
leftsize = in_size - truncsize;
|
leftsize = in_size - truncsize;
|
||||||
|
|
||||||
trunc = gst_buffer_create_sub (buf, truncsize, in_size);
|
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 (trunc) = audiorate->next_offset;
|
||||||
GST_BUFFER_OFFSET_END (trunc) = in_offset_end;
|
GST_BUFFER_OFFSET_END (trunc) = in_offset_end;
|
||||||
|
|
||||||
|
GST_LOG_OBJECT (audiorate, "truncating %lld samples", truncsamples);
|
||||||
|
|
||||||
gst_buffer_unref (buf);
|
gst_buffer_unref (buf);
|
||||||
buf = trunc;
|
buf = trunc;
|
||||||
|
|
||||||
|
|
|
@ -339,12 +339,29 @@ gst_videorate_chain (GstPad * pad, GstData * data)
|
||||||
prevtime = GST_BUFFER_TIMESTAMP (videorate->prevbuf);
|
prevtime = GST_BUFFER_TIMESTAMP (videorate->prevbuf);
|
||||||
intime = GST_BUFFER_TIMESTAMP (buf);
|
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++;
|
videorate->in++;
|
||||||
|
|
||||||
/* got 2 buffers, see which one is the best */
|
/* got 2 buffers, see which one is the best */
|
||||||
do {
|
do {
|
||||||
diff1 = abs (prevtime - videorate->next_ts);
|
diff1 = ABS (prevtime - videorate->next_ts);
|
||||||
diff2 = abs (intime - videorate->next_ts) * videorate->new_pref;
|
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 */
|
/* output first one when its the best */
|
||||||
if (diff1 <= diff2) {
|
if (diff1 <= diff2) {
|
||||||
|
@ -360,6 +377,10 @@ gst_videorate_chain (GstPad * pad, GstData * data)
|
||||||
GST_BUFFER_DURATION (outbuf) =
|
GST_BUFFER_DURATION (outbuf) =
|
||||||
videorate->next_ts - GST_BUFFER_TIMESTAMP (outbuf);
|
videorate->next_ts - GST_BUFFER_TIMESTAMP (outbuf);
|
||||||
gst_pad_push (videorate->srcpad, GST_DATA (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 */
|
/* continue while the first one was the best */
|
||||||
}
|
}
|
||||||
|
@ -376,9 +397,16 @@ gst_videorate_chain (GstPad * pad, GstData * data)
|
||||||
videorate->drop++;
|
videorate->drop++;
|
||||||
if (!videorate->silent)
|
if (!videorate->silent)
|
||||||
g_object_notify (G_OBJECT (videorate), "drop");
|
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,
|
GST_LOG_OBJECT (videorate,
|
||||||
// videorate->in, videorate->out, videorate->drop, videorate->dup);
|
"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 */
|
/* swap in new one when it's the best */
|
||||||
gst_buffer_unref (videorate->prevbuf);
|
gst_buffer_unref (videorate->prevbuf);
|
||||||
|
|
Loading…
Reference in a new issue