2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 /*#define DEBUG_ENABLED */
25 #include <gstvideoflip.h>
26 #include <videoflip.h>
30 /* elementfactory information */
31 static GstElementDetails videoflip_details =
32 GST_ELEMENT_DETAILS ("Video scaler",
33 "Filter/Effect/Video",
35 "Wim Taymans <wim.taymans@chello.be>");
37 /* GstVideoflip signals and args */
51 static void gst_videoflip_base_init (gpointer g_class);
52 static void gst_videoflip_class_init (GstVideoflipClass * klass);
53 static void gst_videoflip_init (GstVideoflip * videoflip);
55 static void gst_videoflip_set_property (GObject * object, guint prop_id,
56 const GValue * value, GParamSpec * pspec);
57 static void gst_videoflip_get_property (GObject * object, guint prop_id,
58 GValue * value, GParamSpec * pspec);
60 static void gst_videoflip_chain (GstPad * pad, GstData * _data);
61 static GstCaps *gst_videoflip_get_capslist (void);
64 static GstElementClass *parent_class = NULL;
66 #define GST_TYPE_VIDEOFLIP_METHOD (gst_videoflip_method_get_type())
69 gst_videoflip_method_get_type (void)
71 static GType videoflip_method_type = 0;
72 static GEnumValue videoflip_methods[] = {
73 {GST_VIDEOFLIP_METHOD_IDENTITY, "0", "Identity (no rotation)"},
74 {GST_VIDEOFLIP_METHOD_90R, "1", "Rotate right 90 degrees"},
75 {GST_VIDEOFLIP_METHOD_180, "2", "Rotate 180 degrees"},
76 {GST_VIDEOFLIP_METHOD_90L, "3", "Rotate left 90 degrees"},
77 {GST_VIDEOFLIP_METHOD_HORIZ, "4", "Flip horizontally"},
78 {GST_VIDEOFLIP_METHOD_VERT, "5", "Flip vertically"},
79 {GST_VIDEOFLIP_METHOD_TRANS, "6",
80 "Flip across upper left/lower right diagonal"},
81 {GST_VIDEOFLIP_METHOD_OTHER, "7",
82 "Flip across upper right/lower left diagonal"},
85 if (!videoflip_method_type) {
86 videoflip_method_type = g_enum_register_static ("GstVideoflipMethod",
89 return videoflip_method_type;
92 static GstPadTemplate *
93 gst_videoflip_src_template_factory (void)
95 /* well, actually RGB too, but since there's no RGB format anyway */
96 GstCaps *caps = gst_caps_from_string ("video/x-raw-yuv, "
97 "width = (int) [ 0, MAX ], "
98 "height = (int) [ 0, MAX ], " "framerate = (double) [ 0, MAX ]");
100 caps = gst_caps_intersect (caps, gst_videoflip_get_capslist ());
102 return gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS, caps);
105 static GstPadTemplate *
106 gst_videoflip_sink_template_factory (void)
108 GstCaps *caps = gst_caps_from_string ("video/x-raw-yuv, "
109 "width = (int) [ 0, MAX ], "
110 "height = (int) [ 0, MAX ], " "framerate = (double) [ 0, MAX ]");
112 caps = gst_caps_intersect (caps, gst_videoflip_get_capslist ());
114 return gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS, caps);
118 gst_videoflip_get_type (void)
120 static GType videoflip_type = 0;
122 if (!videoflip_type) {
123 static const GTypeInfo videoflip_info = {
124 sizeof (GstVideoflipClass),
125 gst_videoflip_base_init,
127 (GClassInitFunc) gst_videoflip_class_init,
130 sizeof (GstVideoflip),
132 (GInstanceInitFunc) gst_videoflip_init,
135 g_type_register_static (GST_TYPE_ELEMENT, "GstVideoflip",
138 return videoflip_type;
142 gst_videoflip_base_init (gpointer g_class)
144 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
146 gst_element_class_set_details (element_class, &videoflip_details);
148 gst_element_class_add_pad_template (element_class,
149 gst_videoflip_sink_template_factory ());
150 gst_element_class_add_pad_template (element_class,
151 gst_videoflip_src_template_factory ());
154 gst_videoflip_class_init (GstVideoflipClass * klass)
156 GObjectClass *gobject_class;
157 GstElementClass *gstelement_class;
159 gobject_class = (GObjectClass *) klass;
160 gstelement_class = (GstElementClass *) klass;
162 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_METHOD,
163 g_param_spec_enum ("method", "method", "method",
164 GST_TYPE_VIDEOFLIP_METHOD, GST_VIDEOFLIP_METHOD_90R,
167 parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
169 gobject_class->set_property = gst_videoflip_set_property;
170 gobject_class->get_property = gst_videoflip_get_property;
175 gst_videoflip_get_capslist (void)
178 GstStructure *structure;
181 caps = gst_caps_new_empty ();
182 for (i = 0; i < videoflip_n_formats; i++) {
183 structure = videoflip_get_cap (videoflip_formats + i);
184 gst_caps_append_structure (caps, structure);
191 gst_videoflip_sink_getcaps (GstPad * pad)
193 GstVideoflip *videoflip;
194 GstCaps *capslist = NULL;
200 GST_DEBUG ("gst_videoflip_sink_getcaps");
201 videoflip = GST_VIDEOFLIP (gst_pad_get_parent (pad));
203 /* get list of peer's caps */
204 if (pad == videoflip->srcpad) {
205 peercaps = gst_pad_get_allowed_caps (videoflip->sinkpad);
207 peercaps = gst_pad_get_allowed_caps (videoflip->srcpad);
210 /* FIXME videoflip doesn't allow passthru of video formats it
211 * doesn't understand. */
212 /* Look through our list of caps and find those that match with
213 * the peer's formats. Create a list of them. */
214 for (i = 0; i < videoflip_n_formats; i++) {
216 gst_caps_new_full (videoflip_get_cap (videoflip_formats + i), NULL);
217 if (gst_caps_is_always_compatible (fromcaps, peercaps)) {
218 gst_caps_append (capslist, fromcaps);
221 gst_caps_free (peercaps);
223 sizecaps = gst_caps_from_string ("video/x-raw-yuv, "
224 "width = (int) [ 0, MAX ], "
225 "height = (int) [ 0, MAX ], " "framerate = (double) [ 0, MAX ]");
227 caps = gst_caps_intersect (capslist, sizecaps);
228 gst_caps_free (sizecaps);
234 static GstPadLinkReturn
235 gst_videoflip_src_link (GstPad * pad, const GstCaps * caps)
237 GstVideoflip *videoflip;
238 GstStructure *structure;
241 GST_DEBUG ("gst_videoflip_src_link");
242 videoflip = GST_VIDEOFLIP (gst_pad_get_parent (pad));
244 structure = gst_caps_get_structure (caps, 0);
246 videoflip->format = videoflip_find_by_caps (caps);
247 g_return_val_if_fail (videoflip->format, GST_PAD_LINK_REFUSED);
249 ret = gst_structure_get_int (structure, "width", &videoflip->to_width);
250 ret &= gst_structure_get_int (structure, "height", &videoflip->to_height);
253 return GST_PAD_LINK_REFUSED;
255 return GST_PAD_LINK_OK;
258 static GstPadLinkReturn
259 gst_videoflip_sink_link (GstPad * pad, const GstCaps * caps)
261 GstVideoflip *videoflip;
262 GstStructure *structure;
265 GST_DEBUG ("gst_videoflip_sink_link");
266 videoflip = GST_VIDEOFLIP (gst_pad_get_parent (pad));
268 structure = gst_caps_get_structure (caps, 0);
270 videoflip->format = videoflip_find_by_caps (caps);
271 g_return_val_if_fail (videoflip->format, GST_PAD_LINK_REFUSED);
273 ret = gst_structure_get_int (structure, "width", &videoflip->from_width);
274 ret &= gst_structure_get_int (structure, "height", &videoflip->from_height);
277 return GST_PAD_LINK_REFUSED;
279 return GST_PAD_LINK_OK;
283 gst_videoflip_init (GstVideoflip * videoflip)
285 GST_DEBUG ("gst_videoflip_init");
287 gst_pad_new_from_template (gst_videoflip_sink_template_factory (),
289 gst_element_add_pad (GST_ELEMENT (videoflip), videoflip->sinkpad);
290 gst_pad_set_chain_function (videoflip->sinkpad, gst_videoflip_chain);
291 gst_pad_set_link_function (videoflip->sinkpad, gst_videoflip_sink_link);
292 gst_pad_set_getcaps_function (videoflip->sinkpad, gst_videoflip_sink_getcaps);
295 gst_pad_new_from_template (gst_videoflip_src_template_factory (), "src");
296 gst_element_add_pad (GST_ELEMENT (videoflip), videoflip->srcpad);
297 gst_pad_set_link_function (videoflip->srcpad, gst_videoflip_src_link);
298 //gst_pad_set_getcaps_function(videoflip->srcpad,gst_videoflip_getcaps);
300 videoflip->inited = FALSE;
301 videoflip->force_size = FALSE;
306 gst_videoflip_chain (GstPad * pad, GstData * _data)
308 GstBuffer *buf = GST_BUFFER (_data);
309 GstVideoflip *videoflip;
314 GST_DEBUG ("gst_videoflip_chain");
316 g_return_if_fail (pad != NULL);
317 g_return_if_fail (GST_IS_PAD (pad));
318 g_return_if_fail (buf != NULL);
320 videoflip = GST_VIDEOFLIP (gst_pad_get_parent (pad));
321 g_return_if_fail (videoflip->inited);
323 data = GST_BUFFER_DATA (buf);
324 size = GST_BUFFER_SIZE (buf);
326 if (videoflip->passthru) {
327 gst_pad_push (videoflip->srcpad, GST_DATA (buf));
331 GST_DEBUG ("gst_videoflip_chain: got buffer of %ld bytes in '%s'", size,
332 GST_OBJECT_NAME (videoflip));
335 ("size=%ld from=%dx%d to=%dx%d fromsize=%ld (should be %d) tosize=%d",
336 size, videoflip->from_width, videoflip->from_height, videoflip->to_width,
337 videoflip->to_height, size, videoflip->from_buf_size,
338 videoflip->to_buf_size);
340 g_return_if_fail (size == videoflip->from_buf_size);
342 outbuf = gst_buffer_new ();
343 /* FIXME: handle bufferpools */
344 GST_BUFFER_SIZE (outbuf) = videoflip->to_buf_size;
345 GST_BUFFER_DATA (outbuf) = g_malloc (videoflip->to_buf_size);
346 GST_BUFFER_TIMESTAMP (outbuf) = GST_BUFFER_TIMESTAMP (buf);
348 g_return_if_fail (videoflip->format);
349 GST_DEBUG ("format %s", videoflip->format->fourcc);
350 g_return_if_fail (videoflip->format->scale);
352 videoflip->format->scale (videoflip, GST_BUFFER_DATA (outbuf), data);
354 GST_DEBUG ("gst_videoflip_chain: pushing buffer of %d bytes in '%s'",
355 GST_BUFFER_SIZE (outbuf), GST_OBJECT_NAME (videoflip));
357 gst_pad_push (videoflip->srcpad, GST_DATA (outbuf));
359 gst_buffer_unref (buf);
363 gst_videoflip_set_property (GObject * object, guint prop_id,
364 const GValue * value, GParamSpec * pspec)
368 /* it's not null if we got it, but it might not be ours */
369 g_return_if_fail (GST_IS_VIDEOFLIP (object));
370 src = GST_VIDEOFLIP (object);
372 GST_DEBUG ("gst_videoflip_set_property");
375 src->method = g_value_get_enum (value);
383 gst_videoflip_get_property (GObject * object, guint prop_id, GValue * value,
388 /* it's not null if we got it, but it might not be ours */
389 g_return_if_fail (GST_IS_VIDEOFLIP (object));
390 src = GST_VIDEOFLIP (object);
394 g_value_set_enum (value, src->method);
397 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
404 plugin_init (GstPlugin * plugin)
406 return gst_element_register (plugin, "videoflip", GST_RANK_NONE,
410 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
413 "Resizes video", plugin_init, VERSION, GST_LICENSE, GST_PACKAGE, GST_ORIGIN)