2 * Copyright (C) 2010 Stefan Kost <stefan.kost@nokia.com>
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.
19 /* demo for using gstcontroler with camera capture for e.g. bracketing
21 * gcc `pkg-config --cflags --libs gstreamer-0.10 gstreamer-controller-0.10` camctrl.c -o camctrl
24 * - handle stream status and switch capture thread to SCHED_RR/FIFO
25 * - the queue-size controls the controler offset
26 * - right now we work with 1 queued picture and thus active settings for next
28 * - we want some feedback about how precisely a program can be realized
29 * - we might want to adjust the framerate to handle hardware limmits
30 * - we e.g. can't change resolution per frame right now
34 #include <gst/controller/gstinterpolationcontrolsource.h>
37 event_loop (GstElement * bin)
40 GstMessage *message = NULL;
42 bus = gst_element_get_bus (GST_ELEMENT (bin));
45 message = gst_bus_poll (bus, GST_MESSAGE_ANY, -1);
47 switch (message->type) {
49 gst_message_unref (message);
51 case GST_MESSAGE_WARNING:
52 case GST_MESSAGE_ERROR:{
56 gst_message_parse_error (message, &gerror, &debug);
57 gst_object_default_error (GST_MESSAGE_SRC (message), gerror, debug);
58 gst_message_unref (message);
59 g_error_free (gerror);
64 gst_message_unref (message);
71 set_program (GstObject * elem, GstStructure * prog)
73 const GstStructure *s;
74 GstInterpolationControlSource *cs;
82 css = g_hash_table_new (g_str_hash, g_str_equal);
85 dur = gst_util_uint64_scale_int (GST_SECOND, 1, 15);
87 /* loop over each image in prog */
88 for (i = 0; i < gst_structure_n_fields (prog); i++) {
89 GST_DEBUG ("ctrl on %" GST_TIME_FORMAT, GST_TIME_ARGS (ts));
92 gst_structure_get_value (prog, gst_structure_nth_field_name (prog, i));
93 s = gst_value_get_structure (frame);
94 for (j = 0; j < gst_structure_n_fields (s); j++) {
95 name = gst_structure_nth_field_name (s, j);
96 cs = g_hash_table_lookup (css, name);
98 cs = gst_interpolation_control_source_new ();
99 gst_object_add_control_binding (elem,
100 gst_control_binding_new (elem, name, GST_CONTROL_SOURCE (cs)));
101 g_object_set (cs, "mode", GST_INTERPOLATION_MODE_NONE, NULL);
102 g_hash_table_insert (css, (gpointer) name, cs);
103 gst_object_unref (cs);
105 gst_structure_get_double (s, name, &v);
106 gst_timed_value_control_source_set ((GstTimedValueControlSource *) cs, ts,
108 GST_DEBUG (" %s = %lf", name, v);
113 g_hash_table_unref (css);
117 main (gint argc, gchar ** argv)
120 GstElement *src, *fmt, *enc, *sink;
125 gst_init (&argc, &argv);
127 /* create a new bin to hold the elements */
128 bin = gst_pipeline_new ("camera");
130 /* create elements */
131 if (!(sink = gst_element_factory_make ("multifilesink", NULL))) {
132 GST_WARNING ("Can't create element \"multifilesink\"");
135 g_object_set (sink, "location", "image%02d.jpg", NULL);
137 if (!(enc = gst_element_factory_make ("jpegenc", NULL))) {
138 GST_WARNING ("Can't create element \"jpegenc\"");
142 if (!(fmt = gst_element_factory_make ("capsfilter", NULL))) {
143 GST_WARNING ("Can't create element \"capsfilter\"");
148 ("video/x-raw-yuv, width=640, height=480, framerate=(fraction)15/1");
149 g_object_set (fmt, "caps", caps, NULL);
151 if (!(src = gst_element_factory_make ("v4l2src", NULL))) {
152 GST_WARNING ("Can't create element \"v4l2src\"");
155 g_object_set (src, "queue-size", 1, NULL);
157 /* add objects to the main bin */
158 gst_bin_add_many (GST_BIN (bin), src, fmt, enc, sink, NULL);
161 if (!gst_element_link_many (src, fmt, enc, sink, NULL)) {
162 GST_WARNING ("Can't link elements");
166 /* programm a pattern of events */
168 prog = gst_structure_from_string ("program"
169 ", image00=(structure)\"image\\,contrast\\=0.0\\;\""
170 ", image01=(structure)\"image\\,contrast\\=0.3\\;\""
171 ", image02=(structure)\"image\\,contrast\\=1.0\\;\""
172 ", image03=(structure)\"image\\,contrast\\=0.05\\;\";", NULL);
175 prog = gst_structure_from_string ("program"
176 ", image00=(structure)\"image\\,brightness\\=1.0\\,contrast\\=0.0\\;\""
177 ", image01=(structure)\"image\\,brightness\\=0.5\\,contrast\\=0.3\\;\""
178 ", image02=(structure)\"image\\,brightness\\=0.25\\,contrast\\=1.0\\;\""
179 ", image03=(structure)\"image\\,brightness\\=0.0\\,contrast\\=0.05\\;\";",
182 set_program (GST_OBJECT (src), prog);
183 g_object_set (src, "num-buffers", gst_structure_n_fields (prog), NULL);
185 /* prepare playback */
186 gst_element_set_state (bin, GST_STATE_PAUSED);
189 gst_element_set_state (bin, GST_STATE_PLAYING);
191 /* mainloop and wait for eos */
194 /* stop and cleanup */
195 gst_element_set_state (bin, GST_STATE_NULL);
196 gst_object_unref (GST_OBJECT (bin));