~xubuntu-dev/ubiquity/lp1437180_feh

« back to all changes in this revision

Viewing changes to src/webcam/webcam.c

  • Committer: Colin Watson
  • Date: 2012-04-30 23:38:41 UTC
  • mfrom: (5402 trunk)
  • mto: This revision was merged to the branch mainline in revision 5403.
  • Revision ID: cjwatson@canonical.com-20120430233841-xb0qsk46lnhski7m
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
 * w = UbiquityWebcam.Webcam()
29
29
 */
30
30
 
 
31
#include <assert.h>
 
32
 
 
33
#include <glib-object.h>
 
34
#include <gtk/gtk.h>
 
35
 
31
36
#define G_UDEV_API_IS_SUBJECT_TO_CHANGE 1
32
37
#include <gudev/gudev.h>
33
38
 
37
42
static gboolean message_cb (GstBus *bus, GstMessage *msg, gpointer data);
38
43
static GstBusSyncReply window_id_cb (GstBus *bus, GstMessage *msg, gpointer data);
39
44
 
40
 
G_DEFINE_TYPE (UbiquityWebcam, ubiquity_webcam, GTK_TYPE_VBOX)
 
45
G_DEFINE_TYPE (UbiquityWebcam, ubiquity_webcam, GTK_TYPE_BOX)
41
46
 
42
47
#define UBIQUITY_WEBCAM_PRIVATE(o) \
43
48
        (G_TYPE_INSTANCE_GET_PRIVATE ((o), UBIQUITY_TYPE_WEBCAM, UbiquityWebcamPrivate))
55
60
        GstBus *bus;
56
61
};
57
62
 
 
63
enum {
 
64
        PROP_0,
 
65
        PROP_BUTTON
 
66
};
 
67
 
58
68
static gulong video_window_xid = 0;
59
69
 
60
70
static void
 
71
ubiquity_webcam_get_property (GObject *object, guint prop_id, GValue *value,
 
72
                              GParamSpec *pspec) {
 
73
        UbiquityWebcamPrivate *priv = UBIQUITY_WEBCAM_PRIVATE (object);
 
74
 
 
75
        switch (prop_id) {
 
76
                case PROP_BUTTON:
 
77
                        g_value_set_object (value, (GObject *) priv->button);
 
78
                        break;
 
79
                default:
 
80
                        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id,
 
81
                                                           pspec);
 
82
        }
 
83
}
 
84
 
 
85
static void
61
86
ubiquity_webcam_class_init (UbiquityWebcamClass *klass) {
62
87
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
63
88
        GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
64
 
        GtkVBoxClass *vbox_class = GTK_VBOX_CLASS (klass);
 
89
        GtkBoxClass *box_class = GTK_BOX_CLASS (klass);
 
90
 
 
91
        object_class->get_property = ubiquity_webcam_get_property;
 
92
 
 
93
        g_object_class_install_property (
 
94
                object_class, PROP_BUTTON,
 
95
                g_param_spec_object (
 
96
                        "take-button", "'Take Photo' button",
 
97
                        "The button that may be pressed to take a photo",
 
98
                        GTK_TYPE_WIDGET,
 
99
                        G_PARAM_READABLE | G_PARAM_STATIC_NAME |
 
100
                        G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
65
101
 
66
102
        g_type_class_add_private (klass, sizeof (UbiquityWebcamPrivate));
67
103
}
74
110
static void
75
111
ubiquity_webcam_init (UbiquityWebcam *self) {
76
112
        UbiquityWebcamPrivate *priv;
 
113
        gint width = 172, height = 129;
 
114
 
 
115
        assert (width * 3 == height * 4); /* 4x3 ratio */
 
116
 
77
117
        priv = self->priv = UBIQUITY_WEBCAM_PRIVATE (self);
78
118
 
 
119
        gtk_orientable_set_orientation (GTK_ORIENTABLE (self),
 
120
                                        GTK_ORIENTATION_VERTICAL);
79
121
        gtk_box_set_spacing (GTK_BOX (self), 1);
80
122
        priv->drawing_area = gtk_drawing_area_new ();
81
 
        gtk_widget_set_size_request (priv->drawing_area, 320, 240);
 
123
        gtk_widget_set_size_request (priv->drawing_area, width, height);
82
124
        g_signal_connect (priv->drawing_area, "realize",
83
125
                        G_CALLBACK(drawing_area_realized_cb), NULL);
84
126
        gtk_widget_set_double_buffered (priv->drawing_area, FALSE);
91
133
 
92
134
        priv->camerabin = gst_element_factory_make ("camerabin2" , "cam");
93
135
        priv->viewfinder_caps = gst_caps_new_simple ("video/x-raw-rgb",
94
 
                "width", G_TYPE_INT, 320, "height", G_TYPE_INT, 240, NULL);
 
136
                "width", G_TYPE_INT, 640,
 
137
                "height", G_TYPE_INT, 480, NULL);
95
138
        g_object_set (G_OBJECT (priv->camerabin),
96
139
                "viewfinder-caps", priv->viewfinder_caps, NULL);
97
140
    g_signal_new ("image-captured",
129
172
        priv->testsrc = gst_element_factory_make ("videotestsrc", NULL);
130
173
        g_object_set (G_OBJECT (priv->testsrc), "is-live", TRUE,
131
174
                "peer-alloc", FALSE, NULL);
132
 
        g_object_set (G_OBJECT (priv->src), "video-src", priv->testsrc, NULL);
133
 
        g_object_set (G_OBJECT (priv->camerabin), "camera-src", priv->src, NULL);
 
175
        g_object_set (G_OBJECT (priv->src), "video-source", priv->testsrc, NULL);
 
176
        g_object_set (G_OBJECT (priv->camerabin), "camera-source", priv->src, NULL);
134
177
        ubiquity_webcam_stop (webcam);
135
178
        ubiquity_webcam_play (webcam);
136
179
        gst_object_ref (priv->src);
156
199
void
157
200
ubiquity_webcam_play (UbiquityWebcam *webcam) {
158
201
        UbiquityWebcamPrivate *priv = UBIQUITY_WEBCAM_PRIVATE (webcam);
 
202
        if (!priv || !priv->camerabin)
 
203
                return;
159
204
        if (gst_element_set_state (priv->camerabin, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE) {
160
205
                g_print ("setting camerabin to PLAYING failed\n");
161
206
                return;
165
210
void
166
211
ubiquity_webcam_stop (UbiquityWebcam *webcam) {
167
212
        UbiquityWebcamPrivate *priv = UBIQUITY_WEBCAM_PRIVATE (webcam);
 
213
        if (!priv || !priv->camerabin)
 
214
                return;
168
215
        if (gst_element_set_state (priv->camerabin, GST_STATE_NULL) == GST_STATE_CHANGE_FAILURE) {
169
216
                g_print ("setting camerabin to STOPPED failed\n");
170
217
                return;
213
260
                g_print ("Failed to create pngenc.\n");
214
261
                return;
215
262
        }
216
 
        g_object_set (G_OBJECT(camerabin), "image-capture-encoder", camerabin, NULL);
217
263
        g_object_set (G_OBJECT(camerabin), "location", "/tmp/webcam_photo.jpg", NULL);
218
264
        g_object_set (G_OBJECT(camerabin), "post-previews", FALSE, NULL);
219
265
        g_signal_emit_by_name (camerabin, "start-capture", NULL);