summaryrefslogtreecommitdiffstats
path: root/gst/rawparse
diff options
context:
space:
mode:
authorWim Taymans <wim.taymans@gmail.com>2008-06-09 17:57:08 +0000
committerWim Taymans <wim.taymans@gmail.com>2008-06-09 17:57:08 +0000
commit5e88627e2b889fb2dc437d969149656e3cc24d8b (patch)
tree0a4419c215125c6fc40d4df482ba68c366896068 /gst/rawparse
parent409526e5e7226fdec40b1a86ebdce2f3045e3dc0 (diff)
downloadgst-plugins-bad-5e88627e2b889fb2dc437d969149656e3cc24d8b.tar.gz
gst-plugins-bad-5e88627e2b889fb2dc437d969149656e3cc24d8b.tar.bz2
gst-plugins-bad-5e88627e2b889fb2dc437d969149656e3cc24d8b.zip
gst/rawparse/gstrawparse.c: Add simple reverse playback.
Original commit message from CVS: * gst/rawparse/gstrawparse.c: (gst_raw_parse_push_buffer), (gst_raw_parse_loop), (gst_raw_parse_handle_seek_push), (gst_raw_parse_handle_seek_pull): Add simple reverse playback.
Diffstat (limited to 'gst/rawparse')
-rw-r--r--gst/rawparse/gstrawparse.c64
1 files changed, 42 insertions, 22 deletions
diff --git a/gst/rawparse/gstrawparse.c b/gst/rawparse/gstrawparse.c
index b8d2b3b7..d7248d4f 100644
--- a/gst/rawparse/gstrawparse.c
+++ b/gst/rawparse/gstrawparse.c
@@ -216,6 +216,11 @@ gst_raw_parse_push_buffer (GstRawParse * rp, GstBuffer * buffer)
nframes = GST_BUFFER_SIZE (buffer) / rp->framesize;
+ if (rp->segment.rate < 0) {
+ rp->n_frames -= nframes;
+ rp->discont = TRUE;
+ }
+
GST_BUFFER_OFFSET (buffer) = rp->n_frames;
GST_BUFFER_OFFSET_END (buffer) = rp->n_frames + nframes;
@@ -236,8 +241,10 @@ gst_raw_parse_push_buffer (GstRawParse * rp, GstBuffer * buffer)
rp->discont = FALSE;
}
- rp->offset += GST_BUFFER_SIZE (buffer);
- rp->n_frames += nframes;
+ if (rp->segment.rate >= 0) {
+ rp->offset += GST_BUFFER_SIZE (buffer);
+ rp->n_frames += nframes;
+ }
rp->segment.last_stop = GST_BUFFER_TIMESTAMP (buffer);
@@ -324,20 +331,31 @@ gst_raw_parse_loop (GstElement * element)
else
size = rp->framesize;
- if (rp->offset + size > rp->upstream_length) {
- GstFormat fmt = GST_FORMAT_BYTES;
-
- if (!gst_pad_query_peer_duration (rp->sinkpad, &fmt, &rp->upstream_length)) {
- GST_WARNING_OBJECT (rp,
- "Could not get upstream duration, trying to pull frame by frame");
- size = rp->framesize;
- } else if (rp->upstream_length < rp->offset + rp->framesize) {
+ if (rp->segment.rate >= 0) {
+ if (rp->offset + size > rp->upstream_length) {
+ GstFormat fmt = GST_FORMAT_BYTES;
+
+ if (!gst_pad_query_peer_duration (rp->sinkpad, &fmt,
+ &rp->upstream_length)) {
+ GST_WARNING_OBJECT (rp,
+ "Could not get upstream duration, trying to pull frame by frame");
+ size = rp->framesize;
+ } else if (rp->upstream_length < rp->offset + rp->framesize) {
+ ret = GST_FLOW_UNEXPECTED;
+ goto pause;
+ } else if (rp->offset + size > rp->upstream_length) {
+ size = rp->upstream_length - rp->offset;
+ size -= size % rp->framesize;
+ }
+ }
+ } else {
+ if (rp->offset == 0) {
ret = GST_FLOW_UNEXPECTED;
goto pause;
- } else if (rp->offset + size > rp->upstream_length) {
- size = rp->upstream_length - rp->offset;
- size -= size % rp->framesize;
+ } else if (rp->offset < size) {
+ size -= rp->offset;
}
+ rp->offset -= size;
}
ret = gst_pad_pull_range (rp->sinkpad, rp->offset, size, &buffer);
@@ -666,6 +684,10 @@ gst_raw_parse_handle_seek_push (GstRawParse * rp, GstEvent * event)
gst_event_parse_seek (event, &rate, &format, &flags, &start_type, &start,
&stop_type, &stop);
+ /* can't seek backwards yet */
+ if (rate <= 0.0)
+ goto wrong_rate;
+
/* First try if upstream handles the seek */
ret = gst_pad_push_event (rp->sinkpad, event);
if (ret)
@@ -695,6 +717,13 @@ gst_raw_parse_handle_seek_push (GstRawParse * rp, GstEvent * event)
"seeking is only supported in TIME or DEFAULT format");
}
return ret;
+
+ /* ERRORS */
+wrong_rate:
+ {
+ GST_DEBUG_OBJECT (rp, "Seek failed: negative rates not supported yet");
+ return FALSE;
+ }
}
static gboolean
@@ -714,10 +743,6 @@ gst_raw_parse_handle_seek_pull (GstRawParse * rp, GstEvent * event)
gst_event_parse_seek (event, &rate, &format, &flags, &start_type, &start,
&stop_type, &stop);
- /* can't seek backwards yet */
- if (rate <= 0.0)
- goto wrong_rate;
-
/* convert input offsets to time */
ret = gst_raw_parse_convert (rp, format, start, GST_FORMAT_TIME, &start);
ret &= gst_raw_parse_convert (rp, format, stop, GST_FORMAT_TIME, &stop);
@@ -845,11 +870,6 @@ gst_raw_parse_handle_seek_pull (GstRawParse * rp, GstEvent * event)
return ret;
/* ERRORS */
-wrong_rate:
- {
- GST_DEBUG_OBJECT (rp, "Seek failed: negative rates not supported yet");
- return FALSE;
- }
convert_failed:
{
GST_DEBUG_OBJECT (rp, "Seek failed: couldn't convert to byte positions");