From 7a539c59bff3d81f745a27aaba25f8367f99af98 Mon Sep 17 00:00:00 2001 From: Edgard Lima Date: Tue, 19 Sep 2006 13:08:35 +0000 Subject: [PATCH] Add Video Orientation interface support to v4l2src. Original commit message from CVS: Add Video Orientation interface support to v4l2src. --- ChangeLog | 9 ++++ sys/v4l2/Makefile.am | 3 +- sys/v4l2/gstv4l2src.c | 16 +++++- sys/v4l2/gstv4l2vidorient.c | 96 +++++++++++++++++++++++++++++++++ sys/v4l2/gstv4l2vidorient.h | 127 ++++++++++++++++++++++++++++++++++++++++++++ tests/icles/v4l2src-test.c | 93 +++++++++++++++++++++++++++++++- 6 files changed, 339 insertions(+), 5 deletions(-) create mode 100644 sys/v4l2/gstv4l2vidorient.c create mode 100644 sys/v4l2/gstv4l2vidorient.h diff --git a/ChangeLog b/ChangeLog index 4714d0c..717c0e9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2006-09-19 Edgard Lima + + * sys/v4l2/Makefile.am: + * sys/v4l2/gstv4l2src.c: + * sys/v4l2/gstv4l2vidorient.c: + * sys/v4l2/gstv4l2vidorient.h: + * tests/icles/v4l2src-test.c: + Add Video Orientation interface support to v4l2src. + 2006-09-19 Wim Taymans * ext/gsm/gstgsmdec.c: (gst_gsmdec_init), diff --git a/sys/v4l2/Makefile.am b/sys/v4l2/Makefile.am index b3f5881..d40e7fe 100644 --- a/sys/v4l2/Makefile.am +++ b/sys/v4l2/Makefile.am @@ -13,6 +13,7 @@ libgstvideo4linux2_la_SOURCES = gstv4l2.c \ gstv4l2object.c \ gstv4l2src.c \ gstv4l2tuner.c \ + gstv4l2vidorient.c \ v4l2_calls.c \ v4l2src_calls.c \ $(xv_source) @@ -33,4 +34,4 @@ libgstvideo4linux2_la_LIBADD = $(GST_PLUGINS_BASE_LIBS) \ noinst_HEADERS = gstv4l2object.h v4l2_calls.h \ gstv4l2src.h v4l2src_calls.h \ gstv4l2tuner.h gstv4l2xoverlay.h \ - gstv4l2colorbalance.h + gstv4l2colorbalance.h gstv4l2vidorient.h diff --git a/sys/v4l2/gstv4l2src.c b/sys/v4l2/gstv4l2src.c index cb6335b..f652539 100644 --- a/sys/v4l2/gstv4l2src.c +++ b/sys/v4l2/gstv4l2src.c @@ -54,6 +54,7 @@ #include "gstv4l2colorbalance.h" #include "gstv4l2tuner.h" #include "gstv4l2xoverlay.h" +#include "gstv4l2vidorient.h" static const GstElementDetails gst_v4l2src_details = GST_ELEMENT_DETAILS ("Video (video4linux2/raw) Source", @@ -138,6 +139,7 @@ GST_IMPLEMENT_V4L2_TUNER_METHODS (GstV4l2Src, gst_v4l2src); #ifdef HAVE_XVIDEO GST_IMPLEMENT_V4L2_XOVERLAY_METHODS (GstV4l2Src, gst_v4l2src); #endif +GST_IMPLEMENT_V4L2_VIDORIENT_METHODS (GstV4l2Src, gst_v4l2src); static gboolean gst_v4l2src_iface_supported (GstImplementsInterface * iface, GType iface_type) @@ -146,10 +148,13 @@ gst_v4l2src_iface_supported (GstImplementsInterface * iface, GType iface_type) #ifdef HAVE_XVIDEO g_assert (iface_type == GST_TYPE_TUNER || - iface_type == GST_TYPE_X_OVERLAY || iface_type == GST_TYPE_COLOR_BALANCE); + iface_type == GST_TYPE_X_OVERLAY || + iface_type == GST_TYPE_COLOR_BALANCE || + iface_type == GST_TYPE_VIDEO_ORIENTATION); #else g_assert (iface_type == GST_TYPE_TUNER || - iface_type == GST_TYPE_COLOR_BALANCE); + iface_type == GST_TYPE_COLOR_BALANCE || + iface_type == GST_TYPE_VIDEO_ORIENTATION); #endif if (v4l2object->video_fd == -1) @@ -197,6 +202,11 @@ gst_v4l2src_init_interfaces (GType type) NULL, NULL, }; + static const GInterfaceInfo v4l2_videoorientation_info = { + (GInterfaceInitFunc) gst_v4l2src_video_orientation_interface_init, + NULL, + NULL, + }; static const GInterfaceInfo v4l2_propertyprobe_info = { (GInterfaceInitFunc) gst_v4l2src_property_probe_interface_init, NULL, @@ -211,6 +221,8 @@ gst_v4l2src_init_interfaces (GType type) #endif g_type_add_interface_static (type, GST_TYPE_COLOR_BALANCE, &v4l2_colorbalance_info); + g_type_add_interface_static (type, + GST_TYPE_VIDEO_ORIENTATION, &v4l2_videoorientation_info); g_type_add_interface_static (type, GST_TYPE_PROPERTY_PROBE, &v4l2_propertyprobe_info); } diff --git a/sys/v4l2/gstv4l2vidorient.c b/sys/v4l2/gstv4l2vidorient.c new file mode 100644 index 0000000..8f9c91a --- /dev/null +++ b/sys/v4l2/gstv4l2vidorient.c @@ -0,0 +1,96 @@ +/* GStreamer + * + * Copyright (C) 2006 Edgard Lima + * + * gstv4l2vidorient.c: video orientation interface implementation for V4L2 + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +#include "gstv4l2vidorient.h" +#include "gstv4l2object.h" +#include "v4l2_calls.h" +#include "v4l2src_calls.h" + +GST_DEBUG_CATEGORY_STATIC (v4l2vo_debug); +#define GST_CAT_DEFAULT v4l2vo_debug + +void +gst_v4l2_video_orientation_interface_init (GstVideoOrientationInterface * klass) +{ + GST_DEBUG_CATEGORY_INIT (v4l2vo_debug, "v4l2vo", 0, + "V4L2 VideoOrientation interface debugging"); +} + + +gboolean +gst_v4l2_video_orientation_get_hflip (GstV4l2Object * v4l2object, + gboolean * flip) +{ + + return gst_v4l2_get_attribute (v4l2object, V4L2_CID_HFLIP, flip); +} + +extern gboolean +gst_v4l2_video_orientation_get_vflip (GstV4l2Object * v4l2object, + gboolean * flip) +{ + return gst_v4l2_get_attribute (v4l2object, V4L2_CID_VFLIP, flip); +} + +extern gboolean +gst_v4l2_video_orientation_get_hcenter (GstV4l2Object * v4l2object, + gint * center) +{ + return gst_v4l2_get_attribute (v4l2object, V4L2_CID_HCENTER, center); +} + +extern gboolean +gst_v4l2_video_orientation_get_vcenter (GstV4l2Object * v4l2object, + gint * center) +{ + return gst_v4l2_get_attribute (v4l2object, V4L2_CID_VCENTER, center); +} + +extern gboolean +gst_v4l2_video_orientation_set_hflip (GstV4l2Object * v4l2object, gboolean flip) +{ + return gst_v4l2_set_attribute (v4l2object, V4L2_CID_HFLIP, flip); +} + +extern gboolean +gst_v4l2_video_orientation_set_vflip (GstV4l2Object * v4l2object, gboolean flip) +{ + return gst_v4l2_set_attribute (v4l2object, V4L2_CID_VFLIP, flip); +} + +extern gboolean +gst_v4l2_video_orientation_set_hcenter (GstV4l2Object * v4l2object, gint center) +{ + return gst_v4l2_set_attribute (v4l2object, V4L2_CID_HCENTER, center); +} + +extern gboolean +gst_v4l2_video_orientation_set_vcenter (GstV4l2Object * v4l2object, gint center) +{ + return gst_v4l2_set_attribute (v4l2object, V4L2_CID_VCENTER, center); +} diff --git a/sys/v4l2/gstv4l2vidorient.h b/sys/v4l2/gstv4l2vidorient.h new file mode 100644 index 0000000..fecaee5 --- /dev/null +++ b/sys/v4l2/gstv4l2vidorient.h @@ -0,0 +1,127 @@ +/* GStreamer + * + * Copyright (C) 2006 Edgard Lima + * + * gstv4l2vidorient.h: video orientation interface implementation for V4L2 + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef __GST_V4L2_VIDORIENT_H__ +#define __GST_V4L2_VIDORIENT_H__ + +#include +#include + +#include "gstv4l2object.h" + +G_BEGIN_DECLS + +extern gboolean +gst_v4l2_video_orientation_get_hflip (GstV4l2Object *v4l2object, gboolean *flip); +extern gboolean +gst_v4l2_video_orientation_get_vflip (GstV4l2Object *v4l2object, gboolean *flip); +extern gboolean +gst_v4l2_video_orientation_get_hcenter (GstV4l2Object *v4l2object, gint *center); +extern gboolean +gst_v4l2_video_orientation_get_vcenter (GstV4l2Object *v4l2object, gint *center); + +extern gboolean +gst_v4l2_video_orientation_set_hflip (GstV4l2Object *v4l2object, gboolean flip); +extern gboolean +gst_v4l2_video_orientation_set_vflip (GstV4l2Object *v4l2object, gboolean flip); +extern gboolean +gst_v4l2_video_orientation_set_hcenter (GstV4l2Object *v4l2object, gint center); +extern gboolean +gst_v4l2_video_orientation_set_vcenter (GstV4l2Object *v4l2object, gint center); + + +extern void +gst_v4l2_video_orientation_interface_init (GstVideoOrientationInterface * klass); + +#define GST_IMPLEMENT_V4L2_VIDORIENT_METHODS(Type, interface_as_function) \ + \ + static gboolean \ + interface_as_function ## _video_orientation_get_hflip (GstVideoOrientation *vo, gboolean *flip) \ + { \ + Type *this = (Type*) vo; \ + return gst_v4l2_video_orientation_get_hflip (this->v4l2object, flip); \ + } \ + \ + static gboolean \ + interface_as_function ## _video_orientation_get_vflip (GstVideoOrientation *vo, gboolean *flip) \ + { \ + Type *this = (Type*) vo; \ + return gst_v4l2_video_orientation_get_vflip (this->v4l2object, flip); \ + } \ + \ + static gboolean \ + interface_as_function ## _video_orientation_get_hcenter (GstVideoOrientation *vo, gint *center) \ + { \ + Type *this = (Type*) vo; \ + return gst_v4l2_video_orientation_get_hcenter (this->v4l2object, center); \ + } \ + \ + static gboolean \ + interface_as_function ## _video_orientation_get_vcenter (GstVideoOrientation *vo, gint *center) \ + { \ + Type *this = (Type*) vo; \ + return gst_v4l2_video_orientation_get_vcenter (this->v4l2object, center); \ + } \ + \ + static gboolean \ + interface_as_function ## _video_orientation_set_hflip (GstVideoOrientation *vo, gboolean flip) \ + { \ + Type *this = (Type*) vo; \ + return gst_v4l2_video_orientation_set_hflip (this->v4l2object, flip); \ + } \ + \ + static gboolean \ + interface_as_function ## _video_orientation_set_vflip (GstVideoOrientation *vo, gboolean flip) \ + { \ + Type *this = (Type*) vo; \ + return gst_v4l2_video_orientation_set_vflip (this->v4l2object, flip); \ + } \ + \ + static gboolean \ + interface_as_function ## _video_orientation_set_hcenter (GstVideoOrientation *vo, gint center) \ + { \ + Type *this = (Type*) vo; \ + return gst_v4l2_video_orientation_set_hcenter (this->v4l2object, center); \ + } \ + \ + static gboolean \ + interface_as_function ## _video_orientation_set_vcenter (GstVideoOrientation *vo, gint center) \ + { \ + Type *this = (Type*) vo; \ + return gst_v4l2_video_orientation_set_vcenter (this->v4l2object, center); \ + } \ + \ + void \ + interface_as_function ## _video_orientation_interface_init (GstVideoOrientationInterface * klass) \ + { \ + /* default virtual functions */ \ + klass->get_hflip = interface_as_function ## _video_orientation_get_hflip; \ + klass->get_vflip = interface_as_function ## _video_orientation_get_vflip; \ + klass->get_hcenter = interface_as_function ## _video_orientation_get_hcenter; \ + klass->get_vcenter = interface_as_function ## _video_orientation_get_vcenter; \ + klass->set_hflip = interface_as_function ## _video_orientation_set_hflip; \ + klass->set_vflip = interface_as_function ## _video_orientation_set_vflip; \ + klass->set_hcenter = interface_as_function ## _video_orientation_set_hcenter; \ + klass->set_vcenter = interface_as_function ## _video_orientation_set_vcenter; \ + } + +#endif /* __GST_V4L2_VIDORIENT_H__ */ diff --git a/tests/icles/v4l2src-test.c b/tests/icles/v4l2src-test.c index 84f2e7c..9689bfb 100644 --- a/tests/icles/v4l2src-test.c +++ b/tests/icles/v4l2src-test.c @@ -5,6 +5,7 @@ #include #include #include +#include GstElement *pipeline, *source, *sink; GMainLoop *loop; @@ -17,6 +18,7 @@ print_options () printf ("i - to change the input\n"); printf ("n - to change the norm\n"); printf ("c - list color balance\n"); + printf ("v - change video orientarion\n"); printf ("e - to exit\n"); } @@ -34,7 +36,8 @@ run_options (char opt) freq = gst_tuner_get_frequency (tuner, channel); - printf ("type the new frequency (current = %lu) (-1 to cancel): ", freq); + printf ("\ntype the new frequency (current = %lu) (-1 to cancel): ", + freq); scanf ("%u", &freq); if (freq != -1) gst_tuner_set_frequency (tuner, channel, freq); @@ -134,13 +137,15 @@ run_options (char opt) controls = gst_color_balance_list_channels (balance); + printf ("\n"); + if (controls == NULL) { printf ("There is no list of colorbalance controls\n"); goto done; } if (controls) { - printf ("\nlist of controls:\n"); + printf ("list of controls:\n"); for (item = controls, index = 0; item != NULL; item = item->next, ++index) { channel = item->data; @@ -165,6 +170,90 @@ run_options (char opt) gst_color_balance_set_value (balance, channel, new_value); } } + case 'v': + { + GstVideoOrientation *vidorient = GST_VIDEO_ORIENTATION (source); + gboolean flip = FALSE; + gint center = 0; + + printf ("\n"); + + if (gst_video_orientation_get_hflip (vidorient, &flip)) { + gint new_value; + + printf ("Horizontal flip is %s\n", flip ? "on" : "off"); + printf ("\ntype 1 to toggle (-1 to cancel): "); + scanf ("%d", &new_value); + if (new_value == 1) { + flip = !flip; + if (gst_video_orientation_set_hflip (vidorient, flip)) { + gst_video_orientation_get_hflip (vidorient, &flip); + printf ("Now horizontal flip is %s\n", flip ? "on" : "off"); + } else { + printf ("Error toggling horizontal flip\n"); + } + } else { + } + } else { + printf ("Horizontal flip control not available\n"); + } + + if (gst_video_orientation_get_vflip (vidorient, &flip)) { + gint new_value; + + printf ("\nVertical flip is %s\n", flip ? "on" : "off"); + printf ("\ntype 1 to toggle (-1 to cancel): "); + scanf ("%d", &new_value); + if (new_value == 1) { + flip = !flip; + if (gst_video_orientation_set_vflip (vidorient, flip)) { + gst_video_orientation_get_vflip (vidorient, &flip); + printf ("Now vertical flip is %s\n", flip ? "on" : "off"); + } else { + printf ("Error toggling vertical flip\n"); + } + } else { + } + } else { + printf ("Vertical flip control not available\n"); + } + + if (gst_video_orientation_get_hcenter (vidorient, ¢er)) { + printf ("Horizontal center is %d\n", center); + printf ("\ntype the new horizontal center value (-1 to cancel): "); + scanf ("%d", ¢er); + if (center != -1) { + if (gst_video_orientation_set_hcenter (vidorient, center)) { + gst_video_orientation_get_hcenter (vidorient, ¢er); + printf ("Now horizontal center is %d\n", center); + } else { + printf ("Error setting horizontal center\n"); + } + } else { + } + } else { + printf ("Horizontal center control not available\n"); + } + + if (gst_video_orientation_get_vcenter (vidorient, ¢er)) { + printf ("Vertical center is %d\n", center); + printf ("\ntype the new vertical center value (-1 to cancel): "); + scanf ("%d", ¢er); + if (center != -1) { + if (gst_video_orientation_set_vcenter (vidorient, center)) { + gst_video_orientation_get_vcenter (vidorient, ¢er); + printf ("Now vertical center is %d\n", center); + } else { + printf ("Error setting vertical center\n"); + } + } else { + } + } else { + printf ("Vertical center control not available\n"); + } + + } + break; break; default: if (opt != 10) -- 2.7.4