From: Thomas V. S. <tho...@pd...> - 2004-06-23 16:07:33
|
CVS Root: /home/cvs/gstreamer Module: gst-plugins Changes by: thomasvs Date: Wed Jun 23 2004 09:07:31 PDT Branch: BRANCH-RELEASE-0_8_2 Log message: drop overlapping samples; get bytes_per_sample from caps Modified files: . : ChangeLog gst/audiorate : gstaudiorate.c Links: http://freedesktop.org/cgi-bin/viewcvs.cgi/gstreamer/gst-plugins/ChangeLog.diff?r1=1.788.2.7&r2=1.788.2.8 http://freedesktop.org/cgi-bin/viewcvs.cgi/gstreamer/gst-plugins/gst/audiorate/gstaudiorate.c.diff?r1=1.1&r2=1.1.2.1 ====Begin Diffs==== Index: ChangeLog =================================================================== RCS file: /home/cvs/gstreamer/gst-plugins/ChangeLog,v retrieving revision 1.788.2.7 retrieving revision 1.788.2.8 diff -u -d -r1.788.2.7 -r1.788.2.8 --- ChangeLog 23 Jun 2004 15:43:25 -0000 1.788.2.7 +++ ChangeLog 23 Jun 2004 16:07:19 -0000 1.788.2.8 @@ -1,5 +1,13 @@ 2004-06-23 Thomas Vander Stichele <thomas at apestaart dot org> + * gst/audiorate/gstaudiorate.c: (gst_audiorate_class_init), + (gst_audiorate_link), (gst_audiorate_init), (gst_audiorate_chain), + (gst_audiorate_set_property), (gst_audiorate_get_property): + get bytes_per_sample from caps + drop overlapping samples + +2004-06-23 Thomas Vander Stichele <thomas at apestaart dot org> * ext/alsa/gstalsasrc.c: (gst_alsa_src_loop): set offset and offset_end Index: gstaudiorate.c RCS file: /home/cvs/gstreamer/gst-plugins/gst/audiorate/gstaudiorate.c,v retrieving revision 1.1 retrieving revision 1.1.2.1 diff -u -d -r1.1 -r1.1.2.1 --- gstaudiorate.c 17 Jun 2004 13:45:50 -0000 1.1 +++ gstaudiorate.c 23 Jun 2004 16:07:19 -0000 1.1.2.1 @@ -45,10 +45,13 @@ GstPad *sinkpad, *srcpad; + gint bytes_per_sample; /* audio state */ guint64 next_offset; guint64 in, out, add, drop; + gboolean silent; }; struct _GstAudiorateClass @@ -70,6 +73,8 @@ LAST_SIGNAL +#define DEFAULT_SILENT TRUE enum { ARG_0, @@ -77,6 +82,7 @@ ARG_OUT, ARG_ADD, ARG_DROP, + ARG_SILENT, /* FILL ME */ @@ -162,11 +168,16 @@ g_param_spec_uint64 ("out", "Out", "Number of output samples", 0, G_MAXUINT64, 0, G_PARAM_READABLE)); g_object_class_install_property (object_class, ARG_ADD, - g_param_spec_uint64 ("duplicate", "Duplicate", + g_param_spec_uint64 ("add", "Add", "Number of added samples", 0, G_MAXUINT64, 0, G_PARAM_READABLE)); g_object_class_install_property (object_class, ARG_DROP, g_param_spec_uint64 ("drop", "Drop", "Number of dropped samples", 0, G_MAXUINT64, 0, G_PARAM_READABLE)); + g_object_class_install_property (object_class, ARG_SILENT, + g_param_spec_boolean ("silent", "silent", + "Don't emit notify for dropped and duplicated frames", + DEFAULT_SILENT, G_PARAM_READWRITE)); object_class->set_property = gst_audiorate_set_property; object_class->get_property = gst_audiorate_get_property; @@ -181,6 +192,7 @@ GstStructure *structure; GstPad *otherpad; GstPadLinkReturn res; + gint ret, channels, depth; audiorate = GST_AUDIORATE (gst_pad_get_parent (pad)); @@ -193,6 +205,13 @@ 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; } @@ -217,10 +236,12 @@ 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; audiorate->add = 0; + audiorate->silent = DEFAULT_SILENT; static void @@ -250,17 +271,18 @@ in_offset = GST_BUFFER_OFFSET (buf); in_offset_end = GST_BUFFER_OFFSET_END (buf); + 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) { GstBuffer *fill; - gint bytes_per_sample, fillsize; + gint fillsize; guint64 fillsamples; - /* FIXME: use caps to get this */ - bytes_per_sample = in_size / (in_offset_end - in_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); memset (GST_BUFFER_DATA (fill), 0, fillsize); @@ -272,10 +294,43 @@ gst_pad_push (audiorate->srcpad, GST_DATA (fill)); audiorate->out++; - audiorate->add++; + audiorate->add += fillsamples; + if (!audiorate->silent) + g_object_notify (G_OBJECT (audiorate), "add"); } else if (in_offset < audiorate->next_offset) { - g_warning ("overlapping samples, implement me"); - audiorate->drop++; + /* need to remove samples */ + if (in_offset_end <= audiorate->next_offset) { + audiorate->drop += in_size / audiorate->bytes_per_sample; + /* we can drop the buffer completely */ + gst_buffer_unref (buf); + if (!audiorate->silent) + g_object_notify (G_OBJECT (audiorate), "drop"); + return; + } else { + gint truncsamples, truncsize, leftsize; + GstBuffer *trunc; + /* truncate buffer */ + truncsamples = audiorate->next_offset - in_offset; + truncsize = truncsamples * audiorate->bytes_per_sample; + leftsize = in_size - truncsize; + trunc = gst_buffer_create_sub (buf, truncsize, in_size); + GST_BUFFER_DURATION (trunc) = in_duration * leftsize / in_size; + GST_BUFFER_TIMESTAMP (trunc) = + in_time + in_duration - GST_BUFFER_DURATION (trunc); + GST_BUFFER_OFFSET (trunc) = audiorate->next_offset; + GST_BUFFER_OFFSET_END (trunc) = in_offset_end; + buf = trunc; + audiorate->drop += truncsamples; + } } gst_pad_push (audiorate->srcpad, GST_DATA (buf)); audiorate->out++; @@ -287,9 +342,12 @@ gst_audiorate_set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec) - //GstAudiorate *audiorate = GST_AUDIORATE (object); + GstAudiorate *audiorate = GST_AUDIORATE (object); switch (prop_id) { + case ARG_SILENT: + audiorate->silent = g_value_get_boolean (value); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -315,6 +373,9 @@ case ARG_DROP: g_value_set_uint64 (value, audiorate->drop); + g_value_set_boolean (value, audiorate->silent); |