summaryrefslogtreecommitdiffstats
path: root/gst/goom
diff options
context:
space:
mode:
authorWim Taymans <wim.taymans@gmail.com>2007-03-06 13:21:23 +0000
committerWim Taymans <wim.taymans@gmail.com>2007-03-06 13:21:23 +0000
commit0dcf0cebb9a69c4d5a44bc7def1577b9fb433057 (patch)
treea07652ca3f31bba990a46979062426c577c64a40 /gst/goom
parente1fcfeab25f58a5ee81e0087a80d186e1efc0313 (diff)
gst/goom/gstgoom.*: Document, fix and improve goom adapter behaviour.
Original commit message from CVS: * gst/goom/gstgoom.c: (gst_goom_src_setcaps), (get_buffer), (gst_goom_chain): * gst/goom/gstgoom.h: Document, fix and improve goom adapter behaviour. Fixes #407006.
Diffstat (limited to 'gst/goom')
-rw-r--r--gst/goom/gstgoom.c38
-rw-r--r--gst/goom/gstgoom.h2
2 files changed, 25 insertions, 15 deletions
diff --git a/gst/goom/gstgoom.c b/gst/goom/gstgoom.c
index a52b1a86..ca9b3111 100644
--- a/gst/goom/gstgoom.c
+++ b/gst/goom/gstgoom.c
@@ -257,6 +257,7 @@ gst_goom_src_setcaps (GstPad * pad, GstCaps * caps)
goom->duration =
gst_util_uint64_scale_int (GST_SECOND, goom->fps_d, goom->fps_n);
goom->spf = gst_util_uint64_scale_int (goom->rate, goom->fps_d, goom->fps_n);
+ goom->bpf = goom->spf * goom->bps;
GST_DEBUG_OBJECT (goom, "dimension %dx%d, framerate %d/%d, spf %d",
goom->width, goom->height, goom->fps_n, goom->fps_d, goom->spf);
@@ -409,13 +410,9 @@ get_buffer (GstGoom * goom, GstBuffer ** outbuf)
gst_pad_alloc_buffer_and_set_caps (goom->srcpad,
GST_BUFFER_OFFSET_NONE, goom->outsize,
GST_PAD_CAPS (goom->srcpad), outbuf);
-
if (ret != GST_FLOW_OK)
return ret;
- if (*outbuf == NULL)
- return GST_FLOW_ERROR;
-
return GST_FLOW_OK;
}
@@ -425,7 +422,6 @@ gst_goom_chain (GstPad * pad, GstBuffer * buffer)
GstGoom *goom;
GstFlowReturn ret;
GstBuffer *outbuf = NULL;
- guint avail;
goom = GST_GOOM (gst_pad_get_parent (pad));
@@ -453,18 +449,28 @@ gst_goom_chain (GstPad * pad, GstBuffer * buffer)
"Input buffer has %d samples, time=%" G_GUINT64_FORMAT,
GST_BUFFER_SIZE (buffer) / goom->bps, GST_BUFFER_TIMESTAMP (buffer));
+ /* Collect samples until we have enough for an output frame */
gst_adapter_push (goom->adapter, buffer);
ret = GST_FLOW_OK;
- /* Collect samples until we have enough for an output frame */
- avail = gst_adapter_available (goom->adapter);
- GST_DEBUG_OBJECT (goom, "avail now %u", avail);
- while (avail > MAX (GOOM_SAMPLES, goom->spf) * goom->bps) {
+ while (TRUE) {
const guint16 *data;
gboolean need_skip;
guchar *out_frame;
gint i;
+ guint avail, to_flush;
+
+ avail = gst_adapter_available (goom->adapter);
+ GST_DEBUG_OBJECT (goom, "avail now %u", avail);
+
+ /* we need GOOM_SAMPLES to get a meaningful result from goom. */
+ if (avail < (GOOM_SAMPLES * goom->bps))
+ break;
+
+ /* we also need enough samples to produce one frame at least */
+ if (avail < goom->bpf)
+ break;
GST_DEBUG_OBJECT (goom, "processing buffer");
@@ -487,6 +493,7 @@ gst_goom_chain (GstPad * pad, GstBuffer * buffer)
}
}
+ /* get next GOOM_SAMPLES, we have at least this amount of samples */
data =
(const guint16 *) gst_adapter_peek (goom->adapter,
GOOM_SAMPLES * goom->bps);
@@ -531,15 +538,16 @@ gst_goom_chain (GstPad * pad, GstBuffer * buffer)
if (goom->next_ts != -1)
goom->next_ts += goom->duration;
- GST_DEBUG_OBJECT (goom, "finished frame, flushing %u samples from input",
- goom->spf);
- gst_adapter_flush (goom->adapter, MIN (avail, goom->spf * goom->bps));
+ /* Now flush the samples we needed for this frame, which might be more than
+ * the samples we used (GOOM_SAMPLES). */
+ to_flush = goom->bpf;
+
+ GST_DEBUG_OBJECT (goom, "finished frame, flushing %u bytes from input",
+ to_flush);
+ gst_adapter_flush (goom->adapter, to_flush);
if (ret != GST_FLOW_OK)
break;
-
- avail = gst_adapter_available (goom->adapter);
- GST_DEBUG_OBJECT (goom, "avail now %u", avail);
}
if (outbuf != NULL)
diff --git a/gst/goom/gstgoom.h b/gst/goom/gstgoom.h
index e3432dea..9c25f453 100644
--- a/gst/goom/gstgoom.h
+++ b/gst/goom/gstgoom.h
@@ -60,6 +60,8 @@ struct _GstGoom
/* samples per frame */
guint spf;
+ /* bytes per frame */
+ guint bpf;
/* goom stuff */
gint16 datain[2][GOOM_SAMPLES];