2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
3 * Copyright (C) <2003> David Schleef <ds@schleef.org>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
22 * This file was (probably) generated from gstnavseek.c,
23 * gstnavseek.c,v 1.7 2003/11/08 02:48:59 dschleef Exp
30 #include "gstnavseek.h"
40 GstStaticPadTemplate navseek_src_template = GST_STATIC_PAD_TEMPLATE ("src",
45 GstStaticPadTemplate navseek_sink_template = GST_STATIC_PAD_TEMPLATE ("sink",
50 static gboolean gst_navseek_sink_event (GstBaseTransform * trans,
52 static GstFlowReturn gst_navseek_transform_ip (GstBaseTransform * basetrans,
54 static gboolean gst_navseek_src_event (GstBaseTransform * trans,
56 static gboolean gst_navseek_stop (GstBaseTransform * trans);
57 static gboolean gst_navseek_start (GstBaseTransform * trans);
59 static void gst_navseek_set_property (GObject * object, guint prop_id,
60 const GValue * value, GParamSpec * pspec);
61 static void gst_navseek_get_property (GObject * object, guint prop_id,
62 GValue * value, GParamSpec * pspec);
64 GType gst_navseek_get_type (void);
65 #define gst_navseek_parent_class parent_class
66 G_DEFINE_TYPE (GstNavSeek, gst_navseek, GST_TYPE_BASE_TRANSFORM);
69 gst_navseek_class_init (GstNavSeekClass * klass)
71 GstBaseTransformClass *gstbasetrans_class;
72 GstElementClass *element_class;
73 GObjectClass *gobject_class;
75 gobject_class = G_OBJECT_CLASS (klass);
76 element_class = GST_ELEMENT_CLASS (klass);
77 gstbasetrans_class = GST_BASE_TRANSFORM_CLASS (klass);
79 gobject_class->set_property = gst_navseek_set_property;
80 gobject_class->get_property = gst_navseek_get_property;
82 g_object_class_install_property (gobject_class,
83 ARG_SEEKOFFSET, g_param_spec_double ("seek-offset", "Seek Offset",
84 "Time in seconds to seek by", 0.0, G_MAXDOUBLE, 5.0,
85 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
87 gst_element_class_add_pad_template (element_class,
88 gst_static_pad_template_get (&navseek_sink_template));
89 gst_element_class_add_pad_template (element_class,
90 gst_static_pad_template_get (&navseek_src_template));
92 gst_element_class_set_details_simple (element_class,
93 "Seek based on left-right arrows", "Filter/Video",
94 "Seek based on navigation keys left-right",
95 "Jan Schmidt <thaytan@mad.scientist.com>");
97 gstbasetrans_class->src_event = GST_DEBUG_FUNCPTR (gst_navseek_src_event);
98 gstbasetrans_class->sink_event = GST_DEBUG_FUNCPTR (gst_navseek_sink_event);
99 gstbasetrans_class->transform_ip =
100 GST_DEBUG_FUNCPTR (gst_navseek_transform_ip);
101 gstbasetrans_class->start = GST_DEBUG_FUNCPTR (gst_navseek_start);
102 gstbasetrans_class->stop = GST_DEBUG_FUNCPTR (gst_navseek_stop);
106 gst_navseek_init (GstNavSeek * navseek)
108 gst_base_transform_set_passthrough (GST_BASE_TRANSFORM (navseek), TRUE);
110 navseek->seek_offset = 5.0;
111 navseek->loop = FALSE;
112 navseek->grab_seg_start = FALSE;
113 navseek->grab_seg_end = FALSE;
114 navseek->segment_start = GST_CLOCK_TIME_NONE;
115 navseek->segment_end = GST_CLOCK_TIME_NONE;
119 gst_navseek_seek (GstNavSeek * navseek, gint64 offset)
125 /* Query for the current time then attempt to set to time + offset */
126 peer_pad = gst_pad_get_peer (GST_BASE_TRANSFORM (navseek)->sinkpad);
127 ret = gst_pad_query_position (peer_pad, GST_FORMAT_TIME, &peer_value);
132 peer_value += offset;
136 event = gst_event_new_seek (1.0, GST_FORMAT_TIME,
137 GST_SEEK_FLAG_ACCURATE | GST_SEEK_FLAG_FLUSH,
138 GST_SEEK_TYPE_SET, peer_value, GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE);
140 gst_pad_send_event (peer_pad, event);
143 gst_object_unref (peer_pad);
147 gst_navseek_change_playback_rate (GstNavSeek * navseek, gdouble rate)
151 gint64 current_position;
153 peer_pad = gst_pad_get_peer (GST_BASE_TRANSFORM (navseek)->sinkpad);
154 ret = gst_pad_query_position (peer_pad, GST_FORMAT_TIME, ¤t_position);
162 start = current_position;
165 /* negative rate: we play from stop to start */
167 stop = current_position;
170 event = gst_event_new_seek (rate, GST_FORMAT_TIME,
171 GST_SEEK_FLAG_ACCURATE | GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_SKIP,
172 GST_SEEK_TYPE_SET, start, GST_SEEK_TYPE_SET, stop);
174 gst_pad_send_event (peer_pad, event);
179 gst_navseek_segseek (GstNavSeek * navseek)
184 if ((navseek->segment_start == GST_CLOCK_TIME_NONE) ||
185 (navseek->segment_end == GST_CLOCK_TIME_NONE) ||
186 (!GST_PAD_IS_LINKED (GST_BASE_TRANSFORM (navseek)->sinkpad))) {
192 gst_event_new_seek (1.0, GST_FORMAT_TIME,
193 GST_SEEK_FLAG_ACCURATE | GST_SEEK_FLAG_SEGMENT,
194 GST_SEEK_TYPE_SET, navseek->segment_start, GST_SEEK_TYPE_SET,
195 navseek->segment_end);
198 gst_event_new_seek (1.0, GST_FORMAT_TIME, GST_SEEK_FLAG_ACCURATE,
199 GST_SEEK_TYPE_SET, navseek->segment_start, GST_SEEK_TYPE_SET,
200 navseek->segment_end);
203 peer_pad = gst_pad_get_peer (GST_BASE_TRANSFORM (navseek)->sinkpad);
204 gst_pad_send_event (peer_pad, event);
205 gst_object_unref (peer_pad);
209 gst_navseek_toggle_play_pause (GstNavSeek * navseek)
211 GstStateChangeReturn sret;
212 GstState current, pending, state;
214 sret = gst_element_get_state (GST_ELEMENT (navseek), ¤t, &pending, 0);
215 if (sret == GST_STATE_CHANGE_FAILURE)
218 state = (pending != GST_STATE_VOID_PENDING) ? pending : current;
220 gst_element_post_message (GST_ELEMENT (navseek),
221 gst_message_new_request_state (GST_OBJECT (navseek),
222 (state == GST_STATE_PLAYING) ? GST_STATE_PAUSED : GST_STATE_PLAYING));
226 gst_navseek_src_event (GstBaseTransform * trans, GstEvent * event)
231 navseek = GST_NAVSEEK (trans);
233 switch (GST_EVENT_TYPE (event)) {
234 case GST_EVENT_NAVIGATION:
236 /* Check for a keyup and convert left/right to a seek event */
237 const GstStructure *structure;
238 const gchar *event_type;
240 structure = gst_event_get_structure (event);
241 g_return_val_if_fail (structure != NULL, FALSE);
243 event_type = gst_structure_get_string (structure, "event");
244 g_return_val_if_fail (event_type != NULL, FALSE);
246 if (strcmp (event_type, "key-press") == 0) {
249 key = gst_structure_get_string (structure, "key");
250 g_return_val_if_fail (key != NULL, FALSE);
252 if (strcmp (key, "Left") == 0) {
253 /* Seek backward by 5 secs */
254 gst_navseek_seek (navseek, -1.0 * navseek->seek_offset * GST_SECOND);
255 } else if (strcmp (key, "Right") == 0) {
257 gst_navseek_seek (navseek, navseek->seek_offset * GST_SECOND);
258 } else if (strcmp (key, "s") == 0) {
259 /* Grab the next frame as the start frame of a segment */
260 navseek->grab_seg_start = TRUE;
261 } else if (strcmp (key, "e") == 0) {
262 /* Grab the next frame as the end frame of a segment */
263 navseek->grab_seg_end = TRUE;
264 } else if (strcmp (key, "l") == 0) {
265 /* Toggle the loop flag. If we have both start and end segment times send a seek */
266 navseek->loop = !navseek->loop;
267 gst_navseek_segseek (navseek);
268 } else if (strcmp (key, "f") == 0) {
270 gst_navseek_change_playback_rate (navseek, 2.0);
271 } else if (strcmp (key, "r") == 0) {
273 gst_navseek_change_playback_rate (navseek, -2.0);
274 } else if (strcmp (key, "n") == 0) {
276 gst_navseek_change_playback_rate (navseek, 1.0);
277 } else if (strcmp (key, "space") == 0) {
278 gst_navseek_toggle_play_pause (navseek);
283 gst_event_unref (event);
292 ret = GST_BASE_TRANSFORM_CLASS (parent_class)->src_event (trans, event);
298 gst_navseek_set_property (GObject * object, guint prop_id,
299 const GValue * value, GParamSpec * pspec)
301 GstNavSeek *navseek = GST_NAVSEEK (object);
305 GST_OBJECT_LOCK (navseek);
306 navseek->seek_offset = g_value_get_double (value);
307 GST_OBJECT_UNLOCK (navseek);
310 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
316 gst_navseek_get_property (GObject * object, guint prop_id,
317 GValue * value, GParamSpec * pspec)
319 GstNavSeek *navseek = GST_NAVSEEK (object);
323 GST_OBJECT_LOCK (navseek);
324 g_value_set_double (value, navseek->seek_offset);
325 GST_OBJECT_UNLOCK (navseek);
328 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
334 gst_navseek_sink_event (GstBaseTransform * trans, GstEvent * event)
336 GstNavSeek *navseek = GST_NAVSEEK (trans);
338 switch (GST_EVENT_TYPE (event)) {
340 GST_OBJECT_LOCK (navseek);
342 gst_navseek_segseek (navseek);
343 GST_OBJECT_UNLOCK (navseek);
348 return GST_BASE_TRANSFORM_CLASS (parent_class)->sink_event (trans, event);
352 gst_navseek_transform_ip (GstBaseTransform * basetrans, GstBuffer * buf)
354 GstNavSeek *navseek = GST_NAVSEEK (basetrans);
356 GST_OBJECT_LOCK (navseek);
358 if (GST_BUFFER_TIMESTAMP_IS_VALID (buf)) {
359 if (navseek->grab_seg_start) {
360 navseek->segment_start = GST_BUFFER_TIMESTAMP (buf);
361 navseek->segment_end = GST_CLOCK_TIME_NONE;
362 navseek->grab_seg_start = FALSE;
365 if (navseek->grab_seg_end) {
366 navseek->segment_end = GST_BUFFER_TIMESTAMP (buf);
367 navseek->grab_seg_end = FALSE;
368 gst_navseek_segseek (navseek);
372 GST_OBJECT_UNLOCK (navseek);
378 gst_navseek_start (GstBaseTransform * trans)
380 /* anything we should be doing here? */
385 gst_navseek_stop (GstBaseTransform * trans)
387 /* anything we should be doing here? */