[gstreamer-bugs] [Bug 586570] New: Add GAP Flag support to audioresample
GStreamer (bugzilla.gnome.org)
bugzilla-daemon at bugzilla.gnome.org
Sun Jun 21 13:57:33 PDT 2009
If you have any questions why you received this email, please see the text at
the end of this email. Replies to this email are NOT read, please see the text
at the end of this email. You can add comments to this bug at:
http://bugzilla.gnome.org/show_bug.cgi?id=586570
GStreamer | gst-plugins-base | Ver: git
Summary: Add GAP Flag support to audioresample
Product: GStreamer
Version: git
Platform: Other
OS/Version: Linux
Status: UNCONFIRMED
Severity: normal
Priority: Normal
Component: gst-plugins-base
AssignedTo: gstreamer-bugs at lists.sourceforge.net
ReportedBy: channa at caltech.edu
QAContact: gstreamer-bugs at lists.sourceforge.net
CC: kcannon at ligo.caltech.edu
GNOME version: Unspecified
GNOME milestone: Unspecified
The machinery for audioresample to support the GAP flag is basically there
because it subclasses the GSTBaseTransform. However this one is a bit more
tricky than others. Care must be taken to make sure that the correct buffer is
pushed when skipping the actual audioresamper filter during a GAP flag. I
think this patch does the trick (I have tested it quite a bit).
diff --git a/gst/audioresample/gstaudioresample.c
b/gst/audioresample/gstaudioresample.c
index 0cae09e..1d5c265 100644
--- a/gst/audioresample/gstaudioresample.c
+++ b/gst/audioresample/gstaudioresample.c
@@ -224,6 +224,7 @@ gst_audio_resample_init (GstAudioResample * resample,
resample->need_discont = FALSE;
+ gst_base_transform_set_gap_aware (trans, TRUE);
gst_pad_set_query_function (trans->srcpad, gst_audio_resample_query);
gst_pad_set_query_type_function (trans->srcpad,
gst_audio_resample_query_type);
@@ -929,6 +930,15 @@ gst_audio_resample_process (GstAudioResample * resample,
GstBuffer * inbuf,
gint err = RESAMPLER_ERR_SUCCESS;
guint8 *in_tmp = NULL, *out_tmp = NULL;
gboolean need_convert = (resample->funcs->width != resample->width);
+ guint32 in_latency, latency;
+ gboolean skipGAP;
+
+ /* Used to calculate proper behavior when there is a gap
+ * +1 for downsampling, 0 otherwise */
+ in_latency =
+ resample->funcs->get_input_latency (resample->state) +
+ (resample->inrate >= resample->outrate);
+ latency = in_latency * resample->outrate / resample->inrate;
in_len = GST_BUFFER_SIZE (inbuf) / resample->channels;
out_len = GST_BUFFER_SIZE (outbuf) / resample->channels;
@@ -936,6 +946,11 @@ gst_audio_resample_process (GstAudioResample * resample,
GstBuffer * inbuf,
in_len /= (resample->width / 8);
out_len /= (resample->width / 8);
+ /* Check if we should skip this gap, if it is shorter than the latency times
+ * it will break so we don't skip that GAP; also check the buffer is long
enough */
+ skipGAP = in_len > in_latency
+ && GST_BUFFER_FLAG_IS_SET (inbuf, GST_BUFFER_FLAG_GAP);
+
in_processed = in_len;
out_processed = out_len;
@@ -963,13 +978,20 @@ gst_audio_resample_process (GstAudioResample * resample,
GstBuffer * inbuf,
}
}
- if (need_convert) {
- err = resample->funcs->process (resample->state,
- in_tmp, &in_processed, out_tmp, &out_processed);
+ /* don't bother with the resample filter if it is a gap */
+ if (skipGAP) {
+ GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_GAP);
+ memset (GST_BUFFER_DATA (outbuf), 0, GST_BUFFER_SIZE (outbuf));
+ err = 0;
} else {
- err = resample->funcs->process (resample->state,
- (const guint8 *) GST_BUFFER_DATA (inbuf), &in_processed,
- (guint8 *) GST_BUFFER_DATA (outbuf), &out_processed);
+ if (need_convert) {
+ err = resample->funcs->process (resample->state,
+ in_tmp, &in_processed, out_tmp, &out_processed);
+ } else {
+ err = resample->funcs->process (resample->state,
+ (const guint8 *) GST_BUFFER_DATA (inbuf), &in_processed,
+ (guint8 *) GST_BUFFER_DATA (outbuf), &out_processed);
+ }
}
if (G_UNLIKELY (in_len != in_processed))
@@ -998,6 +1020,12 @@ gst_audio_resample_process (GstAudioResample * resample,
GstBuffer * inbuf,
gst_audio_resample_convert_buffer (resample, out_tmp,
GST_BUFFER_DATA (outbuf), out_processed, TRUE);
+ if (skipGAP) {
+ out_processed -= latency;
+ gst_audio_resample_push_drain (resample);
+ gst_audio_resample_reset_state (resample);
+ }
+
GST_BUFFER_DURATION (outbuf) =
GST_FRAMES_TO_CLOCK_TIME (out_processed, resample->outrate);
GST_BUFFER_SIZE (outbuf) =
--
See http://bugzilla.gnome.org/page.cgi?id=email.html for more info about why you received
this email, why you can't respond via email, how to stop receiving
emails (or reduce the number you receive), and how to contact someone
if you are having problems with the system.
You can add comments to this bug at http://bugzilla.gnome.org/show_bug.cgi?id=586570.
More information about the Gstreamer-bugs
mailing list