Andy Wingo | b0c01cd | 2002-03-20 21:45:04 +0000 | [diff] [blame] | 1 | /* GStreamer |
Thomas Vander Stichele | bb8c108 | 2001-12-17 19:03:13 +0000 | [diff] [blame] | 2 | * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu> |
| 3 | * |
| 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. |
| 8 | * |
| 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. |
| 13 | * |
| 14 | * You should have received a copy of the GNU Library General Public |
| 15 | * License along with this library; if not, write to the |
Tim-Philipp Müller | 9e1b75f | 2012-11-03 20:38:00 +0000 | [diff] [blame] | 16 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, |
| 17 | * Boston, MA 02110-1301, USA. |
Thomas Vander Stichele | bb8c108 | 2001-12-17 19:03:13 +0000 | [diff] [blame] | 18 | */ |
| 19 | |
Benjamin Otte | f4a7caa | 2003-06-29 19:46:13 +0000 | [diff] [blame] | 20 | #ifdef HAVE_CONFIG_H |
| 21 | #include "config.h" |
| 22 | #endif |
Thomas Vander Stichele | bb8c108 | 2001-12-17 19:03:13 +0000 | [diff] [blame] | 23 | #include <sys/types.h> |
| 24 | #include <sys/stat.h> |
| 25 | #include <fcntl.h> |
| 26 | #include <sys/ioctl.h> |
| 27 | #include <sys/mman.h> |
| 28 | #include <string.h> |
| 29 | |
Andy Wingo | 4359de2 | 2002-03-19 04:10:06 +0000 | [diff] [blame] | 30 | /*#define DEBUG_ENABLED */ |
Thomas Vander Stichele | bb8c108 | 2001-12-17 19:03:13 +0000 | [diff] [blame] | 31 | #include <gstqcamsrc.h> |
Ronald S. Bultje | 95011fd | 2003-07-06 20:49:52 +0000 | [diff] [blame] | 32 | #include <gst/video/video.h> |
Thomas Vander Stichele | bb8c108 | 2001-12-17 19:03:13 +0000 | [diff] [blame] | 33 | |
| 34 | #include "qcamip.h" |
| 35 | |
Thomas Vander Stichele | bdb814f | 2005-12-06 19:55:58 +0000 | [diff] [blame] | 36 | #define AE_NONE 3 |
Thomas Vander Stichele | bb8c108 | 2001-12-17 19:03:13 +0000 | [diff] [blame] | 37 | |
Thomas Vander Stichele | bdb814f | 2005-12-06 19:55:58 +0000 | [diff] [blame] | 38 | #define DEF_WIDTH 320 |
| 39 | #define DEF_HEIGHT 224 |
| 40 | #define DEF_BRIGHTNESS 226 |
| 41 | #define DEF_WHITEBAL 128 |
| 42 | #define DEF_CONTRAST 72 |
| 43 | #define DEF_TOP 1 |
| 44 | #define DEF_LEFT 14 |
| 45 | #define DEF_TRANSFER_SCALE 2 |
| 46 | #define DEF_DEPTH 6 |
| 47 | #define DEF_PORT 0x378 |
| 48 | #define DEF_AUTOEXP AE_NONE |
Thomas Vander Stichele | bb8c108 | 2001-12-17 19:03:13 +0000 | [diff] [blame] | 49 | |
David Schleef | b144bc6 | 2003-12-22 01:47:09 +0000 | [diff] [blame] | 50 | static GstStaticPadTemplate gst_qcamsrc_src_factory = |
Thomas Vander Stichele | 7a778ee | 2004-03-14 22:34:33 +0000 | [diff] [blame] | 51 | GST_STATIC_PAD_TEMPLATE ("src", |
| 52 | GST_PAD_SRC, |
| 53 | GST_PAD_ALWAYS, |
| 54 | GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("I420")) |
| 55 | ); |
Thomas Vander Stichele | bb8c108 | 2001-12-17 19:03:13 +0000 | [diff] [blame] | 56 | |
| 57 | #define GST_TYPE_AUTOEXP_MODE (gst_autoexp_mode_get_type()) |
| 58 | static GType |
| 59 | gst_autoexp_mode_get_type (void) |
| 60 | { |
| 61 | static GType autoexp_mode_type = 0; |
| 62 | static GEnumValue autoexp_modes[] = { |
Thomas Vander Stichele | 7a778ee | 2004-03-14 22:34:33 +0000 | [diff] [blame] | 63 | {AE_ALL_AVG, "0", "Average Picture"}, |
| 64 | {AE_CTR_AVG, "1", "Average Center"}, |
| 65 | {AE_STD_AVG, "2", "Standard Deviation"}, |
| 66 | {AE_NONE, "3", "None"}, |
| 67 | {0, NULL, NULL}, |
Thomas Vander Stichele | bb8c108 | 2001-12-17 19:03:13 +0000 | [diff] [blame] | 68 | }; |
Thomas Vander Stichele | 4fd57bb | 2004-03-15 19:32:27 +0000 | [diff] [blame] | 69 | |
Thomas Vander Stichele | bb8c108 | 2001-12-17 19:03:13 +0000 | [diff] [blame] | 70 | if (!autoexp_mode_type) { |
Thomas Vander Stichele | 7a778ee | 2004-03-14 22:34:33 +0000 | [diff] [blame] | 71 | autoexp_mode_type = |
Thomas Vander Stichele | 4fd57bb | 2004-03-15 19:32:27 +0000 | [diff] [blame] | 72 | g_enum_register_static ("GstAutoExposureMode", autoexp_modes); |
Thomas Vander Stichele | bb8c108 | 2001-12-17 19:03:13 +0000 | [diff] [blame] | 73 | } |
| 74 | return autoexp_mode_type; |
| 75 | } |
| 76 | |
| 77 | /* QCamSrc signals and args */ |
Thomas Vander Stichele | 7a778ee | 2004-03-14 22:34:33 +0000 | [diff] [blame] | 78 | enum |
| 79 | { |
Thomas Vander Stichele | bb8c108 | 2001-12-17 19:03:13 +0000 | [diff] [blame] | 80 | /* FILL ME */ |
| 81 | LAST_SIGNAL |
| 82 | }; |
| 83 | |
Thomas Vander Stichele | 7a778ee | 2004-03-14 22:34:33 +0000 | [diff] [blame] | 84 | enum |
| 85 | { |
Thomas Vander Stichele | bb8c108 | 2001-12-17 19:03:13 +0000 | [diff] [blame] | 86 | ARG_0, |
| 87 | ARG_WIDTH, |
| 88 | ARG_HEIGHT, |
| 89 | ARG_BRIGHTNESS, |
| 90 | ARG_WHITEBAL, |
| 91 | ARG_CONTRAST, |
| 92 | ARG_TOP, |
| 93 | ARG_LEFT, |
| 94 | ARG_TRANSFER_SCALE, |
| 95 | ARG_DEPTH, |
| 96 | ARG_PORT, |
Stéphane Loeuillet | 8ab8444 | 2004-05-21 23:53:08 +0000 | [diff] [blame] | 97 | ARG_AUTOEXP |
Thomas Vander Stichele | bb8c108 | 2001-12-17 19:03:13 +0000 | [diff] [blame] | 98 | }; |
| 99 | |
Thomas Vander Stichele | 7a778ee | 2004-03-14 22:34:33 +0000 | [diff] [blame] | 100 | static void gst_qcamsrc_base_init (gpointer g_class); |
| 101 | static void gst_qcamsrc_class_init (GstQCamSrcClass * klass); |
| 102 | static void gst_qcamsrc_init (GstQCamSrc * qcamsrc); |
Thomas Vander Stichele | bb8c108 | 2001-12-17 19:03:13 +0000 | [diff] [blame] | 103 | |
Thomas Vander Stichele | 7a778ee | 2004-03-14 22:34:33 +0000 | [diff] [blame] | 104 | static void gst_qcamsrc_set_property (GObject * object, guint prop_id, |
| 105 | const GValue * value, GParamSpec * pspec); |
| 106 | static void gst_qcamsrc_get_property (GObject * object, guint prop_id, |
| 107 | GValue * value, GParamSpec * pspec); |
Thomas Vander Stichele | bb8c108 | 2001-12-17 19:03:13 +0000 | [diff] [blame] | 108 | |
Jan Schmidt | 012dfb8 | 2005-09-05 17:20:29 +0000 | [diff] [blame] | 109 | static GstStateChangeReturn gst_qcamsrc_change_state (GstElement * element, |
| 110 | GstStateChange transition); |
Thomas Vander Stichele | 7a778ee | 2004-03-14 22:34:33 +0000 | [diff] [blame] | 111 | static void gst_qcamsrc_close (GstQCamSrc * src); |
| 112 | static gboolean gst_qcamsrc_open (GstQCamSrc * src); |
Thomas Vander Stichele | bb8c108 | 2001-12-17 19:03:13 +0000 | [diff] [blame] | 113 | |
Thomas Vander Stichele | 7a778ee | 2004-03-14 22:34:33 +0000 | [diff] [blame] | 114 | static GstData *gst_qcamsrc_get (GstPad * pad); |
Thomas Vander Stichele | bb8c108 | 2001-12-17 19:03:13 +0000 | [diff] [blame] | 115 | |
| 116 | static GstElementClass *parent_class = NULL; |
Thomas Vander Stichele | 7a778ee | 2004-03-14 22:34:33 +0000 | [diff] [blame] | 117 | |
Andy Wingo | 4359de2 | 2002-03-19 04:10:06 +0000 | [diff] [blame] | 118 | /*//static guint gst_qcamsrc_signals[LAST_SIGNAL] = { 0 }; */ |
Thomas Vander Stichele | bb8c108 | 2001-12-17 19:03:13 +0000 | [diff] [blame] | 119 | |
| 120 | GType |
| 121 | gst_qcamsrc_get_type (void) |
| 122 | { |
| 123 | static GType qcamsrc_type = 0; |
| 124 | |
| 125 | if (!qcamsrc_type) { |
| 126 | static const GTypeInfo qcamsrc_info = { |
Thomas Vander Stichele | 7a778ee | 2004-03-14 22:34:33 +0000 | [diff] [blame] | 127 | sizeof (GstQCamSrcClass), |
Benjamin Otte | eabfbf1 | 2003-11-02 14:47:52 +0000 | [diff] [blame] | 128 | gst_qcamsrc_base_init, |
Thomas Vander Stichele | bb8c108 | 2001-12-17 19:03:13 +0000 | [diff] [blame] | 129 | NULL, |
Thomas Vander Stichele | 7a778ee | 2004-03-14 22:34:33 +0000 | [diff] [blame] | 130 | (GClassInitFunc) gst_qcamsrc_class_init, |
Thomas Vander Stichele | bb8c108 | 2001-12-17 19:03:13 +0000 | [diff] [blame] | 131 | NULL, |
| 132 | NULL, |
Thomas Vander Stichele | 7a778ee | 2004-03-14 22:34:33 +0000 | [diff] [blame] | 133 | sizeof (GstQCamSrc), |
Thomas Vander Stichele | bb8c108 | 2001-12-17 19:03:13 +0000 | [diff] [blame] | 134 | 0, |
Thomas Vander Stichele | 7a778ee | 2004-03-14 22:34:33 +0000 | [diff] [blame] | 135 | (GInstanceInitFunc) gst_qcamsrc_init, |
Thomas Vander Stichele | bb8c108 | 2001-12-17 19:03:13 +0000 | [diff] [blame] | 136 | NULL |
| 137 | }; |
Thomas Vander Stichele | 4fd57bb | 2004-03-15 19:32:27 +0000 | [diff] [blame] | 138 | |
Thomas Vander Stichele | 7a778ee | 2004-03-14 22:34:33 +0000 | [diff] [blame] | 139 | qcamsrc_type = |
Thomas Vander Stichele | 4fd57bb | 2004-03-15 19:32:27 +0000 | [diff] [blame] | 140 | g_type_register_static (GST_TYPE_ELEMENT, "GstQCamSrc", &qcamsrc_info, |
| 141 | 0); |
Thomas Vander Stichele | bb8c108 | 2001-12-17 19:03:13 +0000 | [diff] [blame] | 142 | } |
| 143 | return qcamsrc_type; |
| 144 | } |
Benjamin Otte | 775c758 | 2010-03-18 17:30:26 +0100 | [diff] [blame] | 145 | |
Benjamin Otte | eabfbf1 | 2003-11-02 14:47:52 +0000 | [diff] [blame] | 146 | static void |
| 147 | gst_qcamsrc_base_init (gpointer g_class) |
| 148 | { |
| 149 | GstElementClass *element_class = GST_ELEMENT_CLASS (g_class); |
Thomas Vander Stichele | 7a778ee | 2004-03-14 22:34:33 +0000 | [diff] [blame] | 150 | |
| 151 | gst_element_class_add_pad_template (element_class, |
| 152 | gst_static_pad_template_get (&gst_qcamsrc_src_factory)); |
Tim-Philipp Müller | 32ba17c | 2012-10-17 17:34:26 +0100 | [diff] [blame] | 153 | gst_element_class_set_static_metadata (element_class, "QCam Source", |
Benjamin Otte | 775c758 | 2010-03-18 17:30:26 +0100 | [diff] [blame] | 154 | "Source/Video", |
| 155 | "Read from a QuickCam device", "Wim Taymans <wim.taymans@chello.be>"); |
Benjamin Otte | eabfbf1 | 2003-11-02 14:47:52 +0000 | [diff] [blame] | 156 | } |
Benjamin Otte | 775c758 | 2010-03-18 17:30:26 +0100 | [diff] [blame] | 157 | |
Thomas Vander Stichele | bb8c108 | 2001-12-17 19:03:13 +0000 | [diff] [blame] | 158 | static void |
Thomas Vander Stichele | 7a778ee | 2004-03-14 22:34:33 +0000 | [diff] [blame] | 159 | gst_qcamsrc_class_init (GstQCamSrcClass * klass) |
Thomas Vander Stichele | bb8c108 | 2001-12-17 19:03:13 +0000 | [diff] [blame] | 160 | { |
| 161 | GObjectClass *gobject_class; |
| 162 | GstElementClass *gstelement_class; |
| 163 | |
Thomas Vander Stichele | 7a778ee | 2004-03-14 22:34:33 +0000 | [diff] [blame] | 164 | gobject_class = (GObjectClass *) klass; |
| 165 | gstelement_class = (GstElementClass *) klass; |
Thomas Vander Stichele | bb8c108 | 2001-12-17 19:03:13 +0000 | [diff] [blame] | 166 | |
Stefan Kost | aa99af6 | 2006-04-08 21:48:01 +0000 | [diff] [blame] | 167 | parent_class = g_type_class_peek_parent (klass); |
Thomas Vander Stichele | bb8c108 | 2001-12-17 19:03:13 +0000 | [diff] [blame] | 168 | |
| 169 | g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_WIDTH, |
Thomas Vander Stichele | 7a778ee | 2004-03-14 22:34:33 +0000 | [diff] [blame] | 170 | g_param_spec_int ("width", "width", "width", |
Thomas Vander Stichele | 4fd57bb | 2004-03-15 19:32:27 +0000 | [diff] [blame] | 171 | 0, 320, DEF_WIDTH, G_PARAM_READWRITE)); |
Thomas Vander Stichele | 7a778ee | 2004-03-14 22:34:33 +0000 | [diff] [blame] | 172 | g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_HEIGHT, |
| 173 | g_param_spec_int ("height", "height", "height", |
Thomas Vander Stichele | 4fd57bb | 2004-03-15 19:32:27 +0000 | [diff] [blame] | 174 | 0, 240, DEF_HEIGHT, G_PARAM_READWRITE)); |
Thomas Vander Stichele | 7a778ee | 2004-03-14 22:34:33 +0000 | [diff] [blame] | 175 | g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_BRIGHTNESS, |
| 176 | g_param_spec_int ("brightness", "brightness", "brightness", |
Thomas Vander Stichele | 4fd57bb | 2004-03-15 19:32:27 +0000 | [diff] [blame] | 177 | 0, 255, DEF_BRIGHTNESS, G_PARAM_READWRITE)); |
Thomas Vander Stichele | 7a778ee | 2004-03-14 22:34:33 +0000 | [diff] [blame] | 178 | g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_WHITEBAL, |
| 179 | g_param_spec_int ("whitebal", "whitebal", "whitebal", |
Thomas Vander Stichele | 4fd57bb | 2004-03-15 19:32:27 +0000 | [diff] [blame] | 180 | 0, 255, DEF_WHITEBAL, G_PARAM_READWRITE)); |
Thomas Vander Stichele | 7a778ee | 2004-03-14 22:34:33 +0000 | [diff] [blame] | 181 | g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_CONTRAST, |
| 182 | g_param_spec_int ("contrast", "contrast", "contrast", |
Thomas Vander Stichele | 4fd57bb | 2004-03-15 19:32:27 +0000 | [diff] [blame] | 183 | 0, 255, DEF_CONTRAST, G_PARAM_READWRITE)); |
Thomas Vander Stichele | 7a778ee | 2004-03-14 22:34:33 +0000 | [diff] [blame] | 184 | g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_TOP, |
| 185 | g_param_spec_int ("top", "top", "top", |
Thomas Vander Stichele | 4fd57bb | 2004-03-15 19:32:27 +0000 | [diff] [blame] | 186 | 0, 240, DEF_TOP, G_PARAM_READWRITE)); |
Thomas Vander Stichele | 7a778ee | 2004-03-14 22:34:33 +0000 | [diff] [blame] | 187 | g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_LEFT, |
| 188 | g_param_spec_int ("left", "left", "left", |
Thomas Vander Stichele | 4fd57bb | 2004-03-15 19:32:27 +0000 | [diff] [blame] | 189 | 0, 320, DEF_LEFT, G_PARAM_READWRITE)); |
Thomas Vander Stichele | 7a778ee | 2004-03-14 22:34:33 +0000 | [diff] [blame] | 190 | g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_TRANSFER_SCALE, |
| 191 | g_param_spec_int ("transfer_scale", "transfer_scale", "transfer_scale", |
Thomas Vander Stichele | 4fd57bb | 2004-03-15 19:32:27 +0000 | [diff] [blame] | 192 | 1, 4, DEF_TRANSFER_SCALE, G_PARAM_READWRITE)); |
Thomas Vander Stichele | 7a778ee | 2004-03-14 22:34:33 +0000 | [diff] [blame] | 193 | g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_DEPTH, |
| 194 | g_param_spec_int ("depth", "depth", "depth", |
Thomas Vander Stichele | 4fd57bb | 2004-03-15 19:32:27 +0000 | [diff] [blame] | 195 | 4, 6, DEF_DEPTH, G_PARAM_READWRITE)); |
Thomas Vander Stichele | 7a778ee | 2004-03-14 22:34:33 +0000 | [diff] [blame] | 196 | g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_PORT, |
| 197 | g_param_spec_int ("port", "port", "port", |
Thomas Vander Stichele | 4fd57bb | 2004-03-15 19:32:27 +0000 | [diff] [blame] | 198 | 0, G_MAXINT, DEF_PORT, G_PARAM_READWRITE)); |
Thomas Vander Stichele | 7a778ee | 2004-03-14 22:34:33 +0000 | [diff] [blame] | 199 | g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_AUTOEXP, |
| 200 | g_param_spec_enum ("autoexposure", "autoexposure", "autoexposure", |
Thomas Vander Stichele | 4fd57bb | 2004-03-15 19:32:27 +0000 | [diff] [blame] | 201 | GST_TYPE_AUTOEXP_MODE, DEF_AUTOEXP, G_PARAM_READWRITE)); |
Thomas Vander Stichele | bb8c108 | 2001-12-17 19:03:13 +0000 | [diff] [blame] | 202 | |
| 203 | gobject_class->set_property = gst_qcamsrc_set_property; |
| 204 | gobject_class->get_property = gst_qcamsrc_get_property; |
| 205 | |
| 206 | gstelement_class->change_state = gst_qcamsrc_change_state; |
| 207 | } |
| 208 | |
| 209 | static void |
Thomas Vander Stichele | 7a778ee | 2004-03-14 22:34:33 +0000 | [diff] [blame] | 210 | gst_qcamsrc_init (GstQCamSrc * qcamsrc) |
Thomas Vander Stichele | bb8c108 | 2001-12-17 19:03:13 +0000 | [diff] [blame] | 211 | { |
Thomas Vander Stichele | 7a778ee | 2004-03-14 22:34:33 +0000 | [diff] [blame] | 212 | qcamsrc->srcpad = |
Edward Hervey | b8a1874 | 2007-06-22 10:46:33 +0000 | [diff] [blame] | 213 | gst_pad_new_from_static_template (&gst_qcamsrc_src_factory, "src"); |
Thomas Vander Stichele | 7a778ee | 2004-03-14 22:34:33 +0000 | [diff] [blame] | 214 | gst_element_add_pad (GST_ELEMENT (qcamsrc), qcamsrc->srcpad); |
| 215 | gst_pad_set_get_function (qcamsrc->srcpad, gst_qcamsrc_get); |
Thomas Vander Stichele | bb8c108 | 2001-12-17 19:03:13 +0000 | [diff] [blame] | 216 | |
| 217 | /* if the destination cannot say what it wants, we give this */ |
Thomas Vander Stichele | 7a778ee | 2004-03-14 22:34:33 +0000 | [diff] [blame] | 218 | qcamsrc->qcam = qc_init (); |
Thomas Vander Stichele | bb8c108 | 2001-12-17 19:03:13 +0000 | [diff] [blame] | 219 | qcamsrc->qcam->port = DEF_PORT; |
| 220 | qc_setwidth (qcamsrc->qcam, DEF_WIDTH); |
| 221 | qc_setheight (qcamsrc->qcam, DEF_HEIGHT); |
| 222 | qc_setbrightness (qcamsrc->qcam, DEF_BRIGHTNESS); |
| 223 | qc_setwhitebal (qcamsrc->qcam, DEF_WHITEBAL); |
| 224 | qc_setcontrast (qcamsrc->qcam, DEF_CONTRAST); |
| 225 | qc_settop (qcamsrc->qcam, DEF_TOP); |
| 226 | qc_setleft (qcamsrc->qcam, DEF_LEFT); |
| 227 | qc_settransfer_scale (qcamsrc->qcam, DEF_TRANSFER_SCALE); |
| 228 | qc_setbitdepth (qcamsrc->qcam, DEF_DEPTH); |
| 229 | qcamsrc->autoexposure = DEF_AUTOEXP; |
Thomas Vander Stichele | 7a778ee | 2004-03-14 22:34:33 +0000 | [diff] [blame] | 230 | if (qcamsrc->autoexposure != AE_NONE) |
Thomas Vander Stichele | bb8c108 | 2001-12-17 19:03:13 +0000 | [diff] [blame] | 231 | qcip_set_autoexposure_mode (qcamsrc->autoexposure); |
| 232 | } |
| 233 | |
Thomas Vander Stichele | 7a778ee | 2004-03-14 22:34:33 +0000 | [diff] [blame] | 234 | static GstData * |
| 235 | gst_qcamsrc_get (GstPad * pad) |
Thomas Vander Stichele | bb8c108 | 2001-12-17 19:03:13 +0000 | [diff] [blame] | 236 | { |
| 237 | GstQCamSrc *qcamsrc; |
| 238 | GstBuffer *buf; |
| 239 | scanbuf *scan; |
| 240 | guchar *outdata; |
| 241 | gint i, frame, scale, convert; |
| 242 | |
| 243 | g_return_val_if_fail (pad != NULL, NULL); |
| 244 | |
| 245 | qcamsrc = GST_QCAMSRC (gst_pad_get_parent (pad)); |
| 246 | |
| 247 | scale = qc_gettransfer_scale (qcamsrc->qcam); |
| 248 | |
| 249 | frame = qcamsrc->qcam->width * qcamsrc->qcam->height / (scale * scale); |
| 250 | |
Thomas Vander Stichele | 7a778ee | 2004-03-14 22:34:33 +0000 | [diff] [blame] | 251 | buf = gst_buffer_new (); |
| 252 | outdata = GST_BUFFER_DATA (buf) = g_malloc0 ((frame * 3) / 2); |
| 253 | GST_BUFFER_SIZE (buf) = (frame * 3) / 2; |
Thomas Vander Stichele | bb8c108 | 2001-12-17 19:03:13 +0000 | [diff] [blame] | 254 | |
| 255 | qc_set (qcamsrc->qcam); |
| 256 | if (!GST_PAD_CAPS (pad)) { |
Thomas Vander Stichele | 7a778ee | 2004-03-14 22:34:33 +0000 | [diff] [blame] | 257 | gst_pad_try_set_caps (pad, gst_caps_new_simple ("video/x-raw-yuv", |
Thomas Vander Stichele | 4fd57bb | 2004-03-15 19:32:27 +0000 | [diff] [blame] | 258 | "format", GST_TYPE_FOURCC, "I420", |
| 259 | "width", G_TYPE_INT, qcamsrc->qcam->width / scale, |
| 260 | "height", G_TYPE_INT, qcamsrc->qcam->height / scale, |
| 261 | "framerate", G_TYPE_DOUBLE, 10., NULL)); |
Thomas Vander Stichele | bb8c108 | 2001-12-17 19:03:13 +0000 | [diff] [blame] | 262 | } |
| 263 | scan = qc_scan (qcamsrc->qcam); |
| 264 | |
Andy Wingo | 4359de2 | 2002-03-19 04:10:06 +0000 | [diff] [blame] | 265 | /* FIXME, this doesn't seem to work... */ |
| 266 | /*fixdark(qcamsrc->qcam, scan); */ |
Thomas Vander Stichele | bb8c108 | 2001-12-17 19:03:13 +0000 | [diff] [blame] | 267 | |
Thomas Vander Stichele | 7a778ee | 2004-03-14 22:34:33 +0000 | [diff] [blame] | 268 | if (qcamsrc->autoexposure != AE_NONE) |
| 269 | qcip_autoexposure (qcamsrc->qcam, scan); |
Thomas Vander Stichele | bb8c108 | 2001-12-17 19:03:13 +0000 | [diff] [blame] | 270 | |
Thomas Vander Stichele | 7a778ee | 2004-03-14 22:34:33 +0000 | [diff] [blame] | 271 | convert = (qcamsrc->qcam->bpp == 4 ? 4 : 2); |
| 272 | |
| 273 | for (i = frame; i; i--) { |
| 274 | outdata[i] = scan[i] << convert; |
Thomas Vander Stichele | bb8c108 | 2001-12-17 19:03:13 +0000 | [diff] [blame] | 275 | } |
Thomas Vander Stichele | 7a778ee | 2004-03-14 22:34:33 +0000 | [diff] [blame] | 276 | memset (outdata + frame, 128, frame >> 1); |
Thomas Vander Stichele | bb8c108 | 2001-12-17 19:03:13 +0000 | [diff] [blame] | 277 | g_free (scan); |
| 278 | |
Andy Wingo | c07813a | 2003-10-08 16:08:19 +0000 | [diff] [blame] | 279 | return GST_DATA (buf); |
Thomas Vander Stichele | bb8c108 | 2001-12-17 19:03:13 +0000 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | static void |
Thomas Vander Stichele | 7a778ee | 2004-03-14 22:34:33 +0000 | [diff] [blame] | 283 | gst_qcamsrc_set_property (GObject * object, guint prop_id, const GValue * value, |
| 284 | GParamSpec * pspec) |
Thomas Vander Stichele | bb8c108 | 2001-12-17 19:03:13 +0000 | [diff] [blame] | 285 | { |
| 286 | GstQCamSrc *src; |
| 287 | |
Thomas Vander Stichele | 7a778ee | 2004-03-14 22:34:33 +0000 | [diff] [blame] | 288 | g_return_if_fail (GST_IS_QCAMSRC (object)); |
| 289 | src = GST_QCAMSRC (object); |
Thomas Vander Stichele | bb8c108 | 2001-12-17 19:03:13 +0000 | [diff] [blame] | 290 | |
| 291 | switch (prop_id) { |
| 292 | case ARG_WIDTH: |
| 293 | qc_setwidth (src->qcam, g_value_get_int (value)); |
| 294 | break; |
| 295 | case ARG_HEIGHT: |
| 296 | qc_setheight (src->qcam, g_value_get_int (value)); |
| 297 | break; |
| 298 | case ARG_BRIGHTNESS: |
| 299 | qc_setbrightness (src->qcam, g_value_get_int (value)); |
| 300 | break; |
| 301 | case ARG_WHITEBAL: |
| 302 | qc_setwhitebal (src->qcam, g_value_get_int (value)); |
| 303 | break; |
| 304 | case ARG_CONTRAST: |
| 305 | qc_setcontrast (src->qcam, g_value_get_int (value)); |
| 306 | break; |
| 307 | case ARG_TOP: |
| 308 | qc_settop (src->qcam, g_value_get_int (value)); |
| 309 | break; |
| 310 | case ARG_LEFT: |
| 311 | qc_setleft (src->qcam, g_value_get_int (value)); |
| 312 | break; |
| 313 | case ARG_TRANSFER_SCALE: |
| 314 | qc_settransfer_scale (src->qcam, g_value_get_int (value)); |
| 315 | break; |
| 316 | case ARG_DEPTH: |
| 317 | qc_setbitdepth (src->qcam, g_value_get_int (value)); |
| 318 | break; |
| 319 | case ARG_PORT: |
| 320 | src->qcam->port = g_value_get_int (value); |
| 321 | break; |
| 322 | case ARG_AUTOEXP: |
| 323 | src->autoexposure = g_value_get_enum (value); |
Thomas Vander Stichele | 7a778ee | 2004-03-14 22:34:33 +0000 | [diff] [blame] | 324 | if (src->autoexposure != AE_NONE) |
Thomas Vander Stichele | 4fd57bb | 2004-03-15 19:32:27 +0000 | [diff] [blame] | 325 | qcip_set_autoexposure_mode (src->autoexposure); |
Thomas Vander Stichele | bb8c108 | 2001-12-17 19:03:13 +0000 | [diff] [blame] | 326 | break; |
| 327 | default: |
| 328 | break; |
| 329 | } |
| 330 | } |
| 331 | |
| 332 | static void |
Thomas Vander Stichele | 7a778ee | 2004-03-14 22:34:33 +0000 | [diff] [blame] | 333 | gst_qcamsrc_get_property (GObject * object, guint prop_id, GValue * value, |
| 334 | GParamSpec * pspec) |
Thomas Vander Stichele | bb8c108 | 2001-12-17 19:03:13 +0000 | [diff] [blame] | 335 | { |
| 336 | GstQCamSrc *src; |
| 337 | |
Thomas Vander Stichele | 7a778ee | 2004-03-14 22:34:33 +0000 | [diff] [blame] | 338 | g_return_if_fail (GST_IS_QCAMSRC (object)); |
| 339 | src = GST_QCAMSRC (object); |
Thomas Vander Stichele | bb8c108 | 2001-12-17 19:03:13 +0000 | [diff] [blame] | 340 | |
| 341 | switch (prop_id) { |
| 342 | case ARG_WIDTH: |
| 343 | g_value_set_int (value, qc_getwidth (src->qcam)); |
| 344 | break; |
| 345 | case ARG_HEIGHT: |
| 346 | g_value_set_int (value, qc_getheight (src->qcam)); |
| 347 | break; |
| 348 | case ARG_BRIGHTNESS: |
| 349 | g_value_set_int (value, qc_getbrightness (src->qcam)); |
| 350 | break; |
| 351 | case ARG_WHITEBAL: |
| 352 | g_value_set_int (value, qc_getwhitebal (src->qcam)); |
| 353 | break; |
| 354 | case ARG_CONTRAST: |
| 355 | g_value_set_int (value, qc_getcontrast (src->qcam)); |
| 356 | break; |
| 357 | case ARG_TOP: |
| 358 | g_value_set_int (value, qc_gettop (src->qcam)); |
| 359 | break; |
| 360 | case ARG_LEFT: |
| 361 | g_value_set_int (value, qc_getleft (src->qcam)); |
| 362 | break; |
| 363 | case ARG_TRANSFER_SCALE: |
| 364 | g_value_set_int (value, qc_gettransfer_scale (src->qcam)); |
| 365 | break; |
| 366 | case ARG_DEPTH: |
| 367 | g_value_set_int (value, qc_getbitdepth (src->qcam)); |
| 368 | break; |
| 369 | case ARG_PORT: |
| 370 | g_value_set_int (value, src->qcam->port); |
| 371 | break; |
| 372 | case ARG_AUTOEXP: |
| 373 | g_value_set_enum (value, src->autoexposure); |
| 374 | break; |
| 375 | default: |
| 376 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
| 377 | break; |
| 378 | } |
| 379 | } |
| 380 | |
Jan Schmidt | 012dfb8 | 2005-09-05 17:20:29 +0000 | [diff] [blame] | 381 | static GstStateChangeReturn |
| 382 | gst_qcamsrc_change_state (GstElement * element, GstStateChange transition) |
Thomas Vander Stichele | bb8c108 | 2001-12-17 19:03:13 +0000 | [diff] [blame] | 383 | { |
Thomas Vander Stichele | 7a778ee | 2004-03-14 22:34:33 +0000 | [diff] [blame] | 384 | g_return_val_if_fail (GST_IS_QCAMSRC (element), FALSE); |
Thomas Vander Stichele | bb8c108 | 2001-12-17 19:03:13 +0000 | [diff] [blame] | 385 | |
Jan Schmidt | 012dfb8 | 2005-09-05 17:20:29 +0000 | [diff] [blame] | 386 | switch (transition) { |
| 387 | case GST_STATE_CHANGE_READY_TO_NULL: |
Stefan Kost | 36c2fc2 | 2005-10-12 14:29:55 +0000 | [diff] [blame] | 388 | if (GST_OBJECT_FLAG_IS_SET (element, GST_QCAMSRC_OPEN)) |
Ronald S. Bultje | 2ccd6d4 | 2005-02-03 12:16:00 +0000 | [diff] [blame] | 389 | gst_qcamsrc_close (GST_QCAMSRC (element)); |
| 390 | break; |
Jan Schmidt | 012dfb8 | 2005-09-05 17:20:29 +0000 | [diff] [blame] | 391 | case GST_STATE_CHANGE_NULL_TO_READY: |
Stefan Kost | 36c2fc2 | 2005-10-12 14:29:55 +0000 | [diff] [blame] | 392 | if (!GST_OBJECT_FLAG_IS_SET (element, GST_QCAMSRC_OPEN)) { |
Ronald S. Bultje | 2ccd6d4 | 2005-02-03 12:16:00 +0000 | [diff] [blame] | 393 | GST_DEBUG ("opening"); |
| 394 | if (!gst_qcamsrc_open (GST_QCAMSRC (element))) { |
| 395 | GST_DEBUG ("open failed"); |
Jan Schmidt | 012dfb8 | 2005-09-05 17:20:29 +0000 | [diff] [blame] | 396 | return GST_STATE_CHANGE_FAILURE; |
Ronald S. Bultje | 2ccd6d4 | 2005-02-03 12:16:00 +0000 | [diff] [blame] | 397 | } |
Thomas Vander Stichele | bb8c108 | 2001-12-17 19:03:13 +0000 | [diff] [blame] | 398 | } |
Ronald S. Bultje | 2ccd6d4 | 2005-02-03 12:16:00 +0000 | [diff] [blame] | 399 | break; |
| 400 | default: |
| 401 | break; |
Thomas Vander Stichele | bb8c108 | 2001-12-17 19:03:13 +0000 | [diff] [blame] | 402 | } |
| 403 | |
Thomas Vander Stichele | 7a778ee | 2004-03-14 22:34:33 +0000 | [diff] [blame] | 404 | if (GST_ELEMENT_CLASS (parent_class)->change_state) |
Jan Schmidt | 012dfb8 | 2005-09-05 17:20:29 +0000 | [diff] [blame] | 405 | return GST_ELEMENT_CLASS (parent_class)->change_state (element, transition); |
Thomas Vander Stichele | bb8c108 | 2001-12-17 19:03:13 +0000 | [diff] [blame] | 406 | |
Jan Schmidt | 012dfb8 | 2005-09-05 17:20:29 +0000 | [diff] [blame] | 407 | return GST_STATE_CHANGE_SUCCESS; |
Thomas Vander Stichele | bb8c108 | 2001-12-17 19:03:13 +0000 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | static gboolean |
Thomas Vander Stichele | 7a778ee | 2004-03-14 22:34:33 +0000 | [diff] [blame] | 411 | gst_qcamsrc_open (GstQCamSrc * qcamsrc) |
Thomas Vander Stichele | bb8c108 | 2001-12-17 19:03:13 +0000 | [diff] [blame] | 412 | { |
| 413 | if (qc_open (qcamsrc->qcam)) { |
Ronald S. Bultje | 2ccd6d4 | 2005-02-03 12:16:00 +0000 | [diff] [blame] | 414 | GST_ELEMENT_ERROR (qcamsrc, RESOURCE, OPEN_READ, (NULL), |
| 415 | ("Failed to open QuickCam")); |
Thomas Vander Stichele | bb8c108 | 2001-12-17 19:03:13 +0000 | [diff] [blame] | 416 | return FALSE; |
| 417 | } |
| 418 | |
Stefan Kost | 36c2fc2 | 2005-10-12 14:29:55 +0000 | [diff] [blame] | 419 | GST_OBJECT_FLAG_SET (qcamsrc, GST_QCAMSRC_OPEN); |
Thomas Vander Stichele | bb8c108 | 2001-12-17 19:03:13 +0000 | [diff] [blame] | 420 | |
| 421 | return TRUE; |
| 422 | } |
| 423 | |
| 424 | static void |
Thomas Vander Stichele | 7a778ee | 2004-03-14 22:34:33 +0000 | [diff] [blame] | 425 | gst_qcamsrc_close (GstQCamSrc * src) |
Thomas Vander Stichele | bb8c108 | 2001-12-17 19:03:13 +0000 | [diff] [blame] | 426 | { |
| 427 | qc_close (src->qcam); |
Stefan Kost | 36c2fc2 | 2005-10-12 14:29:55 +0000 | [diff] [blame] | 428 | GST_OBJECT_FLAG_UNSET (src, GST_QCAMSRC_OPEN); |
Thomas Vander Stichele | bb8c108 | 2001-12-17 19:03:13 +0000 | [diff] [blame] | 429 | } |
| 430 | |
| 431 | static gboolean |
Thomas Vander Stichele | 7a778ee | 2004-03-14 22:34:33 +0000 | [diff] [blame] | 432 | plugin_init (GstPlugin * plugin) |
Thomas Vander Stichele | bb8c108 | 2001-12-17 19:03:13 +0000 | [diff] [blame] | 433 | { |
Thomas Vander Stichele | 7a778ee | 2004-03-14 22:34:33 +0000 | [diff] [blame] | 434 | if (!gst_element_register (plugin, "qcamsrc", GST_RANK_NONE, |
Thomas Vander Stichele | 4fd57bb | 2004-03-15 19:32:27 +0000 | [diff] [blame] | 435 | GST_TYPE_QCAMSRC)) |
Benjamin Otte | eabfbf1 | 2003-11-02 14:47:52 +0000 | [diff] [blame] | 436 | return FALSE; |
Thomas Vander Stichele | bb8c108 | 2001-12-17 19:03:13 +0000 | [diff] [blame] | 437 | |
| 438 | return TRUE; |
| 439 | } |
| 440 | |
Thomas Vander Stichele | 7a778ee | 2004-03-14 22:34:33 +0000 | [diff] [blame] | 441 | GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, |
| 442 | GST_VERSION_MINOR, |
Sebastian Dröge | cda192b | 2012-04-05 18:02:56 +0200 | [diff] [blame] | 443 | qcamsrc, |
Thomas Vander Stichele | 7a778ee | 2004-03-14 22:34:33 +0000 | [diff] [blame] | 444 | "Read from a QuickCam device", |
Thomas Vander Stichele | 60f8059 | 2006-04-01 10:09:11 +0000 | [diff] [blame] | 445 | plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN) |