Debian Codegraph @

gst/camerabin2/gstcamerabin2.c

raw symbols SCIP
1 /* GStreamer
2 * Copyright (C) 2010 Thiago Santos <[email protected]>
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
16 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19 /**
20 * SECTION:element-camerabin
21 * @title: camerabin
22 *
23 * CameraBin is a high-level camera object that encapsulates gstreamer
24 * elements, providing an API for controlling a digital camera.
25 *
26 * > Note that camerabin is still UNSTABLE and under development.
27 *
28 * CameraBin has the following main features:
29 *
30 * * Record videos
31 * * Capture pictures
32 * * Display a viewfinder
33 * * Post preview images for each capture (video and image)
34 *
35 * ## Usage
36 *
37 * Camerabin can be created using gst_element_factory_make() just like
38 * any other element. Video or image capture mode can be selected using
39 * the #GstCameraBin:mode property and the file to save the capture is
40 * selected using #GstCameraBin:location property.
41 *
42 * After creating camerabin, applications might want to do some
43 * customization (there's a section about this below), then select
44 * the desired mode and start capturing.
45 *
46 * In image capture mode, just send a #GstCameraBin::start-capture and a
47 * picture will be captured. When the picture is stored on the selected
48 * location, a %GST_MESSAGE_ELEMENT named 'image-done' will be posted on
49 * the #GstBus.
50 *
51 * In video capture mode, send a #GstCameraBin::start-capture to start
52 * recording, then send a #GstCameraBin::stop-capture to stop recording.
53 * Note that both signals are asynchronous, so, calling
54 * #GstCameraBin::stop-capture doesn't guarantee that the video has been
55 * properly finished yet. Applications should wait for the 'video-done'
56 * message to be posted on the bus.
57 *
58 * In both modes, if #GstCameraBin:post-previews is %TRUE, a #GstBuffer
59 * will be post to the #GstBus in a field named 'buffer', in a
60 * 'preview-image' message of type %GST_MESSAGE_ELEMENT.
61 *
62
63 *
64 * ## Customization
65 *
66 * Camerabin provides various customization properties, allowing the user
67 * to set custom filters, selecting the viewfinder sink and formats to
68 * use to encode the captured images/videos.
69 *
70 * #GstEncodingProfile<!-- -->s are used to tell camerabin which formats it
71 * should encode the captures to, those should be set to
72 * #GstCameraBin:image-profile and #GstCameraBin:video-profile. Default is
73 * jpeg for images, and ogg (theora and vorbis) for video. If a profile without
74 * an audio stream is set for video, audio will be disabled on recordings.
75 *
76 * #GstCameraBin:preview-caps can be used to select which format preview
77 * images should be posted on the #GstBus. It has to be a raw video format.
78 *
79 * Camerabin has a #GstCameraBin:camera-source property so applications can
80 * set their source that will provide buffers for the viewfinder and for
81 * captures. This camera source is a special type of source that has 3 pads.
82 * To use a 'regular' source with a single pad you should use
83 * #GstWrapperCameraBinSrc, it will adapt your source and provide 3 pads.
84 *
85 * Applications can also select the desired viewfinder sink using
86 * #GstCameraBin:viewfinder-sink, it is also possible to select the audio
87 * source using #GstCameraBin:audio-source.
88 *
89 * The viewfinder resolution can be configured using
90 * #GstCameraBin:viewfinder-caps, these #GstCaps should be a subset of
91 * #GstCameraBin:viewfinder-supported-caps.
92 *
93 * To select the desired resolution for captures, camerabin provides
94 * #GstCameraBin:image-capture-caps and #GstCameraBin:video-capture-caps,
95 * these caps must be a subset of what the source can produce. The allowed
96 * caps can be probed using #GstCameraBin:image-capture-supported-caps and
97 * #GstCameraBin:video-capture-supported-caps. In an analogous way, there
98 * are #GstCameraBin:audio-capture-caps and
99 * #GstCameraBin:audio-capture-supported-caps.
100 *
101 * Camerabin also allows applications to insert custom #GstElements on any
102 * of its branches: video capture, image capture, viewfinder and preview.
103 * Check #GstCameraBin:video-filter, #GstCameraBin:image-filter,
104 * #GstCameraBin:viewfinder-filter and #GstCameraBin:preview-filter.
105 *
106 * ## Example launch line
107 *
108 * Unfortunately, camerabin can't be really used from gst-launch-1.0, as you
109 * need to send signals to control it. The following pipeline might be able
110 * to show the viewfinder using all the default elements.
111 * |[
112 * gst-launch-1.0 -v -m camerabin
113 * ]|
114 *
115
116 */
117
118 /*
119 * Detail Topics:
120 *
121 * videorecordingbin state management (for now on called 'videobin')
122 * - The problem: keeping videobin state in sync with camerabin will make it
123 * go to playing when it might not be used, causing its internal
124 * filesink to open a file that might be left blank.
125 * - The solution: videobin state is set to locked upon its creation and camerabin
126 * registers itself on the notify::ready-for-capture of the src.
127 * Whenever the src readyness goes to FALSE it means a new
128 * capture is starting. If we are on video mode, the videobin's
129 * state is set to NULL and then PLAYING (in between this we
130 * have room to set the destination filename).
131 * There is no problem to leave it on playing after an EOS, so
132 * no action is taken on stop-capture.
133 *
134 * - TODO: What happens when an error pops?
135 * - TODO: Should we split properties in image/video variants? We already do so
136 * for some of them
137 *
138 *
139 */
140
141 #ifdef HAVE_CONFIG_H
142 #include "config.h"
143 #endif
144
145 #include <string.h>
146
147 #include <gst/basecamerabinsrc/gstbasecamerasrc.h>
148 #include "gstcamerabin2.h"
149 #include <glib/gi18n-lib.h>
150 #include <gst/pbutils/pbutils.h>
151 #include <gst/glib-compat-private.h>
152
153 #define GST_CAMERA_BIN2_PROCESSING_INC(c) \
154 { \
155 gint bef = g_atomic_int_add (&c->processing_counter, 1); \
156 if (bef == 0) \
157 g_object_notify (G_OBJECT (c), "idle"); \
158 GST_DEBUG_OBJECT ((c), "Processing counter incremented to: %d", \
159 bef + 1); \
160 }
161
162 #define GST_CAMERA_BIN2_PROCESSING_DEC(c) \
163 { \
164 if (g_atomic_int_dec_and_test (&c->processing_counter)) { \
165 g_object_notify (G_OBJECT (c), "idle"); \
166 GST_DEBUG_OBJECT ((c), "Camerabin now idle"); \
167 } \
168 GST_DEBUG_OBJECT ((c), "Processing counter decremented"); \
169 }
170
171 #define GST_CAMERA_BIN2_RESET_PROCESSING_COUNTER(c) \
172 { \
173 g_atomic_int_set (&c->processing_counter, 0); \
174 GST_DEBUG_OBJECT ((c), "Processing counter reset"); \
175 }
176
177 GST_DEBUG_CATEGORY_STATIC (gst_camera_bin_debug);
178 #define GST_CAT_DEFAULT gst_camera_bin_debug
179
180 /* prototypes */
181
182 enum
183 {
184 PROP_0,
185 PROP_MODE,
186 PROP_LOCATION,
187 PROP_CAMERA_SRC,
188 PROP_IMAGE_CAPTURE_SUPPORTED_CAPS,
189 PROP_VIDEO_CAPTURE_SUPPORTED_CAPS,
190 PROP_IMAGE_CAPTURE_CAPS,
191 PROP_VIDEO_CAPTURE_CAPS,
192 PROP_POST_PREVIEWS,
193 PROP_PREVIEW_CAPS,
194 PROP_VIDEO_ENCODING_PROFILE,
195 PROP_IMAGE_FILTER,
196 PROP_VIDEO_FILTER,
197 PROP_VIEWFINDER_FILTER,
198 PROP_PREVIEW_FILTER,
199 PROP_VIEWFINDER_SINK,
200 PROP_VIEWFINDER_SUPPORTED_CAPS,
201 PROP_VIEWFINDER_CAPS,
202 PROP_AUDIO_SRC,
203 PROP_MUTE_AUDIO,
204 PROP_AUDIO_CAPTURE_SUPPORTED_CAPS,
205 PROP_AUDIO_CAPTURE_CAPS,
206 PROP_ZOOM,
207 PROP_MAX_ZOOM,
208 PROP_IMAGE_ENCODING_PROFILE,
209 PROP_IDLE,
210 PROP_FLAGS,
211 PROP_AUDIO_FILTER
212 };
213
214 enum
215 {
216 /* action signals */
217 START_CAPTURE_SIGNAL,
218 STOP_CAPTURE_SIGNAL,
219 /* emit signals */
220 LAST_SIGNAL
221 };
222 static guint camerabin_signals[LAST_SIGNAL];
223
224 #define DEFAULT_MODE MODE_IMAGE
225 #define DEFAULT_LOCATION "cap_%d"
226 #define DEFAULT_POST_PREVIEWS FALSE
227 #define DEFAULT_MUTE_AUDIO FALSE
228 #define DEFAULT_IDLE TRUE
229 #define DEFAULT_FLAGS 0
230
231 #define DEFAULT_AUDIO_SRC "autoaudiosrc"
232
233 /********************************
234 * Standard GObject boilerplate *
235 * and GObject types *
236 ********************************/
237
238 static GstPipelineClass *parent_class;
239 static void gst_camera_bin_class_init (GstCameraBin2Class * klass);
240 static void gst_camera_bin_base_init (gpointer klass);
241 static void gst_camera_bin_init (GstCameraBin2 * camera);
242 static void gst_camera_bin_dispose (GObject * object);
243 static void gst_camera_bin_finalize (GObject * object);
244
245 static void gst_camera_bin_handle_message (GstBin * bin, GstMessage * message);
246 static gboolean gst_camera_bin_send_event (GstElement * element,
247 GstEvent * event);
248
249 #define C_FLAGS(v) ((guint) v)
250 #define GST_TYPE_CAM_FLAGS (gst_cam_flags_get_type())
251 static GType
252 gst_cam_flags_get_type (void)
253 {
254 static const GFlagsValue values[] = {
255 {C_FLAGS (GST_CAM_FLAG_NO_AUDIO_CONVERSION), "Do not use audio conversion "
256 "elements", "no-audio-conversion"},
257 {C_FLAGS (GST_CAM_FLAG_NO_VIDEO_CONVERSION), "Do not use video conversion "
258 "elements", "no-video-conversion"},
259 {C_FLAGS (GST_CAM_FLAG_NO_VIEWFINDER_CONVERSION),
260 "Do not use viewfinder conversion " "elements",
261 "no-viewfinder-conversion"},
262 {C_FLAGS (GST_CAM_FLAG_NO_IMAGE_CONVERSION), "Do not use image conversion "
263 "elements", "no-image-conversion"},
264 {0, NULL, NULL}
265 };
266 static GType id = 0;
267
268 if (g_once_init_enter ((gsize *) & id)) {
269 GType _id;
270
271 _id = g_flags_register_static ("GstCamFlags", values);
272
273 g_once_init_leave ((gsize *) & id, _id);
274 }
275
276 return id;
277 }
278
279 GType
280 gst_camera_bin2_get_type (void)
281 {
282 static GType gst_camera_bin_type = 0;
283 static const GInterfaceInfo camerabin_tagsetter_info = {
284 NULL,
285 NULL,
286 NULL,
287 };
288
289 if (!gst_camera_bin_type) {
290 static const GTypeInfo gst_camera_bin_info = {
291 sizeof (GstCameraBin2Class),
292 (GBaseInitFunc) gst_camera_bin_base_init,
293 NULL,
294 (GClassInitFunc) gst_camera_bin_class_init,
295 NULL,
296 NULL,
297 sizeof (GstCameraBin2),
298 0,
299 (GInstanceInitFunc) gst_camera_bin_init,
300 NULL
301 };
302
303 gst_camera_bin_type =
304 g_type_register_static (GST_TYPE_PIPELINE, "GstCameraBin",
305 &gst_camera_bin_info, 0);
306
307 g_type_add_interface_static (gst_camera_bin_type, GST_TYPE_TAG_SETTER,
308 &camerabin_tagsetter_info);
309 }
310
311 return gst_camera_bin_type;
312 }
313
314 GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (camerabin, "camerabin", GST_RANK_NONE,
315 gst_camera_bin2_get_type (), GST_DEBUG_CATEGORY_INIT (gst_camera_bin_debug,
316 "camerabin", 0, "CameraBin");
317 );
318
319 /* GObject class functions */
320 static void gst_camera_bin_set_property (GObject * object, guint prop_id,
321 const GValue * value, GParamSpec * pspec);
322 static void gst_camera_bin_get_property (GObject * object, guint prop_id,
323 GValue * value, GParamSpec * pspec);
324
325 /* Element class functions */
326 static GstStateChangeReturn
327 gst_camera_bin_change_state (GstElement * element, GstStateChange trans);
328
329
330 /* Camerabin functions */
331
332 static GstEvent *
333 gst_camera_bin_new_event_file_location (const gchar * location)
334 {
335 return gst_event_new_custom (GST_EVENT_CUSTOM_DOWNSTREAM,
336 gst_structure_new ("new-location", "location", G_TYPE_STRING, location,
337 NULL));
338 }
339
340 static void
341 gst_camera_bin_start_capture (GstCameraBin2 * camerabin)
342 {
343 const GstTagList *taglist;
344 gint capture_index = camerabin->capture_index;
345 gchar *location = NULL;
346 GST_DEBUG_OBJECT (camerabin, "Received start-capture");
347
348 /* check that we have a valid location */
349 if (camerabin->mode == MODE_VIDEO) {
350 if (camerabin->location == NULL) {
351 GST_ELEMENT_ERROR (camerabin, RESOURCE, OPEN_WRITE,
352 (_("File location is set to NULL, please set it to a valid filename")), (NULL));
353 return;
354 }
355
356 g_mutex_lock (&camerabin->video_capture_mutex);
357 while (camerabin->video_state == GST_CAMERA_BIN_VIDEO_FINISHING) {
358 g_cond_wait (&camerabin->video_state_cond,
359 &camerabin->video_capture_mutex);
360 }
361 if (camerabin->video_state != GST_CAMERA_BIN_VIDEO_IDLE) {
362 GST_WARNING_OBJECT (camerabin, "Another video recording is ongoing"
363 " (state %d), cannot start a new one", camerabin->video_state);
364 g_mutex_unlock (&camerabin->video_capture_mutex);
365 return;
366 }
367 camerabin->video_state = GST_CAMERA_BIN_VIDEO_STARTING;
368 }
369
370 GST_CAMERA_BIN2_PROCESSING_INC (camerabin);
371
372 if (camerabin->location)
373 location = g_strdup_printf (camerabin->location, capture_index);
374
375 if (camerabin->mode == MODE_IMAGE) {
376 /* store the next capture buffer filename */
377 g_mutex_lock (&camerabin->image_capture_mutex);
378 camerabin->image_location_list =
379 g_slist_append (camerabin->image_location_list, g_strdup (location));
380 g_mutex_unlock (&camerabin->image_capture_mutex);
381 }
382
383 if (camerabin->post_previews) {
384 /* Count processing of preview images too */
385 GST_CAMERA_BIN2_PROCESSING_INC (camerabin);
386 /* store the next preview filename */
387 g_mutex_lock (&camerabin->preview_list_mutex);
388 camerabin->preview_location_list =
389 g_slist_append (camerabin->preview_location_list, location);
390 g_mutex_unlock (&camerabin->preview_list_mutex);
391 } else {
392 g_free (location);
393 }
394
395 g_signal_emit_by_name (camerabin->src, "start-capture", NULL);
396 if (camerabin->mode == MODE_VIDEO) {
397 camerabin->audio_send_newseg = TRUE;
398 if (camerabin->audio_src)
399 gst_element_set_state (camerabin->audio_src, GST_STATE_PLAYING);
400
401 camerabin->video_state = GST_CAMERA_BIN_VIDEO_RECORDING;
402 g_mutex_unlock (&camerabin->video_capture_mutex);
403 }
404
405 /*
406 * We have to push tags after start capture because the video elements
407 * might be flushing from the previous capture and are reset only on the
408 * notify from ready for capture going to FALSE
409 */
410 taglist = gst_tag_setter_get_tag_list (GST_TAG_SETTER (camerabin));
411 GST_DEBUG_OBJECT (camerabin, "Have tags from application: %"
412 GST_PTR_FORMAT, taglist);
413
414 if (camerabin->mode == MODE_IMAGE) {
415 /* Store image tags in a list and push them later, this prevents
416 start_capture() from blocking in pad_push_event call */
417 g_mutex_lock (&camerabin->image_capture_mutex);
418 camerabin->image_tags_list =
419 g_slist_append (camerabin->image_tags_list,
420 taglist ? gst_tag_list_copy (taglist) : NULL);
421 g_mutex_unlock (&camerabin->image_capture_mutex);
422 } else if (taglist) {
423 GstPad *active_pad;
424
425 active_pad = gst_element_get_static_pad (camerabin->src,
426 GST_BASE_CAMERA_SRC_VIDEO_PAD_NAME);
427 gst_pad_push_event (active_pad,
428 gst_event_new_tag (gst_tag_list_copy (taglist)));
429
430 gst_object_unref (active_pad);
431 }
432
433 GST_DEBUG_OBJECT (camerabin, "Start-capture end");
434 }
435
436 static void
437 gst_camera_bin_stop_capture (GstCameraBin2 * camerabin)
438 {
439 GST_DEBUG_OBJECT (camerabin, "Received stop-capture");
440 if (camerabin->mode == MODE_VIDEO) {
441 g_mutex_lock (&camerabin->video_capture_mutex);
442 if (camerabin->video_state == GST_CAMERA_BIN_VIDEO_RECORDING) {
443 if (camerabin->src)
444 g_signal_emit_by_name (camerabin->src, "stop-capture", NULL);
445
446 camerabin->video_state = GST_CAMERA_BIN_VIDEO_FINISHING;
447 if (camerabin->audio_src) {
448 camerabin->audio_drop_eos = FALSE;
449 gst_element_send_event (camerabin->audio_src, gst_event_new_eos ());
450 }
451 }
452 g_mutex_unlock (&camerabin->video_capture_mutex);
453 }
454 }
455
456 static void
457 gst_camera_bin_change_mode (GstCameraBin2 * camerabin, gint mode)
458 {
459 if (mode == camerabin->mode)
460 return;
461
462 GST_DEBUG_OBJECT (camerabin, "Changing mode to %d", mode);
463
464 /* stop any ongoing capture */
465 gst_camera_bin_stop_capture (camerabin);
466 camerabin->mode = mode;
467 if (camerabin->src)
468 g_object_set (camerabin->src, "mode", mode, NULL);
469 }
470
471 static void
472 gst_camera_bin_src_notify_readyforcapture (GObject * obj, GParamSpec * pspec,
473 gpointer user_data)
474 {
475 GstCameraBin2 *camera = GST_CAMERA_BIN2_CAST (user_data);
476 gboolean ready;
477
478 g_object_get (camera->src, "ready-for-capture", &ready, NULL);
479 if (!ready) {
480 gchar *location = NULL;
481
482 if (camera->mode == MODE_VIDEO) {
483 /* a video recording is about to start, change the filesink location */
484 gst_element_set_state (camera->videosink, GST_STATE_NULL);
485 location = g_strdup_printf (camera->location, camera->capture_index);
486 GST_DEBUG_OBJECT (camera, "Switching videobin location to %s", location);
487 g_object_set (camera->videosink, "location", location, NULL);
488 g_free (location);
489 if (gst_element_set_state (camera->videosink, GST_STATE_PLAYING) ==
490 GST_STATE_CHANGE_FAILURE) {
491 /* Resets the latest state change return, that would be a failure
492 * and could cause problems in a camerabin2 state change */
493 gst_element_set_state (camera->videosink, GST_STATE_NULL);
494 }
495 }
496
497 camera->capture_index++;
498 }
499 }
500
501 static void
502 gst_camera_bin_dispose (GObject * object)
503 {
504 GstCameraBin2 *camerabin = GST_CAMERA_BIN2_CAST (object);
505
506 g_free (camerabin->location);
507 g_mutex_clear (&camerabin->preview_list_mutex);
508 g_mutex_clear (&camerabin->image_capture_mutex);
509 g_mutex_clear (&camerabin->video_capture_mutex);
510 g_cond_clear (&camerabin->video_state_cond);
511
512 if (camerabin->src_capture_notify_id)
513 g_signal_handler_disconnect (camerabin->src,
514 camerabin->src_capture_notify_id);
515 if (camerabin->src)
516 gst_object_unref (camerabin->src);
517 if (camerabin->user_src)
518 gst_object_unref (camerabin->user_src);
519
520 if (camerabin->audio_src)
521 gst_object_unref (camerabin->audio_src);
522 if (camerabin->user_audio_src)
523 gst_object_unref (camerabin->user_audio_src);
524
525 if (camerabin->audio_capsfilter)
526 gst_object_unref (camerabin->audio_capsfilter);
527 if (camerabin->audio_volume)
528 gst_object_unref (camerabin->audio_volume);
529
530 if (camerabin->viewfinderbin)
531 gst_object_unref (camerabin->viewfinderbin);
532 if (camerabin->viewfinderbin_queue)
533 gst_object_unref (camerabin->viewfinderbin_queue);
534 if (camerabin->viewfinderbin_capsfilter)
535 gst_object_unref (camerabin->viewfinderbin_capsfilter);
536
537 if (camerabin->video_encodebin_signal_id)
538 g_signal_handler_disconnect (camerabin->video_encodebin,
539 camerabin->video_encodebin_signal_id);
540
541 if (camerabin->videosink)
542 gst_object_unref (camerabin->videosink);
543 if (camerabin->video_encodebin)
544 gst_object_unref (camerabin->video_encodebin);
545 if (camerabin->videobin_capsfilter)
546 gst_object_unref (camerabin->videobin_capsfilter);
547
548 if (camerabin->image_encodebin_signal_id)
549 g_signal_handler_disconnect (camerabin->image_encodebin,
550 camerabin->image_encodebin_signal_id);
551 if (camerabin->imagesink)
552 gst_object_unref (camerabin->imagesink);
553 if (camerabin->image_encodebin)
554 gst_object_unref (camerabin->image_encodebin);
555 if (camerabin->imagebin_capsfilter)
556 gst_object_unref (camerabin->imagebin_capsfilter);
557
558 if (camerabin->video_filter)
559 gst_object_unref (camerabin->video_filter);
560 if (camerabin->image_filter)
561 gst_object_unref (camerabin->image_filter);
562 if (camerabin->viewfinder_filter)
563 gst_object_unref (camerabin->viewfinder_filter);
564 if (camerabin->audio_filter)
565 gst_object_unref (camerabin->audio_filter);
566
567 if (camerabin->user_video_filter)
568 gst_object_unref (camerabin->user_video_filter);
569 if (camerabin->user_audio_filter)
570 gst_object_unref (camerabin->user_audio_filter);
571 if (camerabin->user_image_filter)
572 gst_object_unref (camerabin->user_image_filter);
573 if (camerabin->user_viewfinder_filter)
574 gst_object_unref (camerabin->user_viewfinder_filter);
575
576 if (camerabin->video_profile)
577 gst_encoding_profile_unref (camerabin->video_profile);
578 if (camerabin->image_profile)
579 gst_encoding_profile_unref (camerabin->image_profile);
580
581 if (camerabin->preview_caps)
582 gst_caps_replace (&camerabin->preview_caps, NULL);
583 if (camerabin->preview_filter) {
584 gst_object_unref (camerabin->preview_filter);
585 camerabin->preview_filter = NULL;
586 }
587
588 G_OBJECT_CLASS (parent_class)->dispose (object);
589 }
590
591 static void
592 gst_camera_bin_finalize (GObject * object)
593 {
594 G_OBJECT_CLASS (parent_class)->finalize (object);
595 }
596
597 static void
598 gst_camera_bin_base_init (gpointer g_class)
599 {
600 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
601
602 gst_element_class_set_static_metadata (element_class, "Camera Bin",
603 "Generic/Bin/Camera",
604 "Take image snapshots and record movies from camera",
605 "Thiago Santos <[email protected]>");
606 }
607
608 static void
609 gst_camera_bin_class_init (GstCameraBin2Class * klass)
610 {
611 GObjectClass *object_class;
612 GstElementClass *element_class;
613 GstBinClass *bin_class;
614
615 parent_class = g_type_class_peek_parent (klass);
616 object_class = G_OBJECT_CLASS (klass);
617 element_class = GST_ELEMENT_CLASS (klass);
618 bin_class = GST_BIN_CLASS (klass);
619
620 object_class->dispose = gst_camera_bin_dispose;
621 object_class->finalize = gst_camera_bin_finalize;
622 object_class->set_property = gst_camera_bin_set_property;
623 object_class->get_property = gst_camera_bin_get_property;
624
625 element_class->change_state = GST_DEBUG_FUNCPTR (gst_camera_bin_change_state);
626 element_class->send_event = GST_DEBUG_FUNCPTR (gst_camera_bin_send_event);
627
628 bin_class->handle_message = gst_camera_bin_handle_message;
629
630 klass->start_capture = gst_camera_bin_start_capture;
631 klass->stop_capture = gst_camera_bin_stop_capture;
632
633 /**
634 * GstCameraBin2:mode:
635 *
636 * Set the mode of operation: still image capturing or video recording.
637 */
638 g_object_class_install_property (object_class, PROP_MODE,
639 g_param_spec_enum ("mode", "Mode",
640 "The capture mode (still image capture or video recording)",
641 GST_TYPE_CAMERABIN_MODE, DEFAULT_MODE,
642 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
643
644 g_object_class_install_property (object_class, PROP_LOCATION,
645 g_param_spec_string ("location", "Location",
646 "Location to save the captured files. A %d might be used on the"
647 "filename as a placeholder for a numeric index of the capture."
648 "Default is cap_%d",
649 DEFAULT_LOCATION, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
650
651 g_object_class_install_property (object_class, PROP_CAMERA_SRC,
652 g_param_spec_object ("camera-source", "Camera source",
653 "The camera source element to be used. It is only taken into use on"
654 " the next null to ready transition",
655 GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
656
657 g_object_class_install_property (object_class, PROP_AUDIO_SRC,
658 g_param_spec_object ("audio-source", "Audio source",
659 "The audio source element to be used on video recordings. It is only"
660 " taken into use on the next null to ready transition",
661 GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
662
663 g_object_class_install_property (object_class, PROP_MUTE_AUDIO,
664 g_param_spec_boolean ("mute", "Mute",
665 "If the audio recording should be muted. Note that this still "
666 "saves audio data to the resulting file, but they are silent. Use "
667 "a video-profile without audio to disable audio completely",
668 DEFAULT_MUTE_AUDIO, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
669
670 g_object_class_install_property (object_class,
671 PROP_AUDIO_CAPTURE_SUPPORTED_CAPS,
672 g_param_spec_boxed ("audio-capture-supported-caps",
673 "Audio capture supported caps",
674 "Formats supported for capturing audio represented as GstCaps",
675 GST_TYPE_CAPS, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
676
677 g_object_class_install_property (object_class,
678 PROP_AUDIO_CAPTURE_CAPS,
679 g_param_spec_boxed ("audio-capture-caps",
680 "Audio capture caps",
681 "Format to capture audio for video recording represented as GstCaps",
682 GST_TYPE_CAPS, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
683
684 g_object_class_install_property (object_class,
685 PROP_IMAGE_CAPTURE_SUPPORTED_CAPS,
686 g_param_spec_boxed ("image-capture-supported-caps",
687 "Image capture supported caps",
688 "Formats supported for capturing images represented as GstCaps",
689 GST_TYPE_CAPS, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
690
691 g_object_class_install_property (object_class,
692 PROP_VIDEO_CAPTURE_SUPPORTED_CAPS,
693 g_param_spec_boxed ("video-capture-supported-caps",
694 "Video capture supported caps",
695 "Formats supported for capturing videos represented as GstCaps",
696 GST_TYPE_CAPS, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
697
698 g_object_class_install_property (object_class,
699 PROP_IMAGE_CAPTURE_CAPS,
700 g_param_spec_boxed ("image-capture-caps",
701 "Image capture caps",
702 "Caps for image capture",
703 GST_TYPE_CAPS, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
704
705 g_object_class_install_property (object_class,
706 PROP_VIDEO_CAPTURE_CAPS,
707 g_param_spec_boxed ("video-capture-caps",
708 "Video capture caps",
709 "Caps for video capture",
710 GST_TYPE_CAPS, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
711
712 g_object_class_install_property (object_class, PROP_POST_PREVIEWS,
713 g_param_spec_boolean ("post-previews", "Post Previews",
714 "If capture preview images should be posted to the bus",
715 DEFAULT_POST_PREVIEWS, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
716
717 g_object_class_install_property (object_class, PROP_PREVIEW_CAPS,
718 g_param_spec_boxed ("preview-caps", "Preview caps",
719 "The caps of the preview image to be posted",
720 GST_TYPE_CAPS, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
721
722 g_object_class_install_property (object_class, PROP_VIDEO_ENCODING_PROFILE,
723 g_param_spec_object ("video-profile", "Video Profile",
724 "The GstEncodingProfile to use for video recording. Audio is enabled "
725 "when this profile supports audio.", GST_TYPE_ENCODING_PROFILE,
726 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
727
728 g_object_class_install_property (object_class, PROP_IMAGE_FILTER,
729 g_param_spec_object ("image-filter", "Image filter",
730 "The element that will process captured image frames. (Should be"
731 " set on NULL state)",
732 GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
733
734 g_object_class_install_property (object_class, PROP_VIDEO_FILTER,
735 g_param_spec_object ("video-filter", "Video filter",
736 "The element that will process captured video frames. (Should be"
737 " set on NULL state)",
738 GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
739
740 g_object_class_install_property (object_class, PROP_VIEWFINDER_FILTER,
741 g_param_spec_object ("viewfinder-filter", "Viewfinder filter",
742 "The element that will process frames going to the viewfinder."
743 " (Should be set on NULL state)",
744 GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
745
746 g_object_class_install_property (object_class, PROP_AUDIO_FILTER,
747 g_param_spec_object ("audio-filter", "Audio filter",
748 "The element that will process captured audio buffers when recording"
749 ". (Should be set on NULL state)",
750 GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
751
752 g_object_class_install_property (object_class, PROP_PREVIEW_FILTER,
753 g_param_spec_object ("preview-filter", "Preview filter",
754 "The element that will process preview buffers."
755 " (Should be set on NULL state)",
756 GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
757
758 g_object_class_install_property (object_class, PROP_VIEWFINDER_SINK,
759 g_param_spec_object ("viewfinder-sink", "Viewfinder sink",
760 "The video sink of the viewfinder. It is only taken into use"
761 " on the next null to ready transition",
762 GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
763
764 g_object_class_install_property (object_class,
765 PROP_VIEWFINDER_CAPS,
766 g_param_spec_boxed ("viewfinder-caps",
767 "Viewfinder caps",
768 "Restricts the caps that can be used on the viewfinder",
769 GST_TYPE_CAPS, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
770
771 g_object_class_install_property (object_class, PROP_ZOOM,
772 g_param_spec_float ("zoom", "Zoom",
773 "Digital zoom factor (e.g. 1.5 means 1.5x)", MIN_ZOOM, MAX_ZOOM,
774 DEFAULT_ZOOM, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
775
776 g_object_class_install_property (object_class, PROP_MAX_ZOOM,
777 g_param_spec_float ("max-zoom", "Maximum zoom level (note: may change "
778 "depending on resolution/implementation)",
779 "Digital zoom factor (e.g. 1.5 means 1.5x)", MIN_ZOOM, G_MAXFLOAT,
780 MAX_ZOOM, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
781
782 /* TODO
783 * Review before stable
784 * - One problem with using encodebin for images here is how jifmux
785 * autoplugging works. We need to give it a higher rank and fix its
786 * caps (it has image/jpeg on sink and src pads). Preliminary tests
787 * show that jifmux is picked if image/jpeg is the caps of a container
788 * profile. So this could work.
789 * - There seems to be a problem with encodebin for images currently as
790 * it autoplugs a videorate that only starts outputting buffers after
791 * getting the 2nd buffer.
792 */
793 g_object_class_install_property (object_class, PROP_IMAGE_ENCODING_PROFILE,
794 g_param_spec_object ("image-profile", "Image Profile",
795 "The GstEncodingProfile to use for image captures.",
796 GST_TYPE_ENCODING_PROFILE,
797 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
798
799
800 g_object_class_install_property (object_class, PROP_IDLE,
801 g_param_spec_boolean ("idle", "Idle",
802 "If camerabin2 is idle (not doing captures).", DEFAULT_IDLE,
803 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
804
805 /* TODO review before going stable
806 * We have viewfinder-supported-caps that returns the caps that the
807 * camerasrc can produce on its viewfinder pad, this could easily be
808 * confused with what the viewfinder-sink accepts.
809 *
810 * Do we want to add a 'viewfinder-sink-supported-caps' or maybe change
811 * the name of this property?
812 */
813 g_object_class_install_property (object_class,
814 PROP_VIEWFINDER_SUPPORTED_CAPS,
815 g_param_spec_boxed ("viewfinder-supported-caps",
816 "Camera source Viewfinder pad supported caps",
817 "The caps that the camera source can produce on the viewfinder pad",
818 GST_TYPE_CAPS, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
819
820 /**
821 * GstCameraBin:flags
822 *
823 * Control the behaviour of encodebin.
824 */
825 g_object_class_install_property (object_class, PROP_FLAGS,
826 g_param_spec_flags ("flags", "Flags", "Flags to control behaviour",
827 GST_TYPE_CAM_FLAGS, DEFAULT_FLAGS,
828 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
829
830 /**
831 * GstCameraBin2::capture-start:
832 * @camera: the camera bin element
833 *
834 * Starts image capture or video recording depending on the Mode.
835 */
836 camerabin_signals[START_CAPTURE_SIGNAL] =
837 g_signal_new ("start-capture",
838 G_TYPE_FROM_CLASS (klass),
839 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
840 G_STRUCT_OFFSET (GstCameraBin2Class, start_capture),
841 NULL, NULL, NULL, G_TYPE_NONE, 0);
842
843 /**
844 * GstCameraBin2::capture-stop:
845 * @camera: the camera bin element
846 */
847 camerabin_signals[STOP_CAPTURE_SIGNAL] =
848 g_signal_new ("stop-capture",
849 G_TYPE_FROM_CLASS (klass),
850 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
851 G_STRUCT_OFFSET (GstCameraBin2Class, stop_capture),
852 NULL, NULL, NULL, G_TYPE_NONE, 0);
853
854 gst_type_mark_as_plugin_api (GST_TYPE_CAM_FLAGS, 0);
855 }
856
857 static void
858 gst_camera_bin_init (GstCameraBin2 * camera)
859 {
860 camera->post_previews = DEFAULT_POST_PREVIEWS;
861 camera->mode = DEFAULT_MODE;
862 camera->location = g_strdup (DEFAULT_LOCATION);
863 camera->viewfinderbin = gst_element_factory_make ("viewfinderbin", "vf-bin");
864 camera->zoom = DEFAULT_ZOOM;
865 camera->max_zoom = MAX_ZOOM;
866 camera->flags = DEFAULT_FLAGS;
867 g_mutex_init (&camera->preview_list_mutex);
868 g_mutex_init (&camera->image_capture_mutex);
869 g_mutex_init (&camera->video_capture_mutex);
870 g_cond_init (&camera->video_state_cond);
871
872 /* capsfilters are created here as we proxy their caps properties and
873 * this way we avoid having to store the caps while on NULL state to
874 * set them later */
875 camera->videobin_capsfilter = gst_element_factory_make ("capsfilter",
876 "videobin-capsfilter");
877 camera->imagebin_capsfilter = gst_element_factory_make ("capsfilter",
878 "imagebin-capsfilter");
879 camera->viewfinderbin_capsfilter = gst_element_factory_make ("capsfilter",
880 "viewfinderbin-capsfilter");
881
882 gst_bin_add_many (GST_BIN (camera),
883 gst_object_ref (camera->viewfinderbin),
884 gst_object_ref (camera->videobin_capsfilter),
885 gst_object_ref (camera->imagebin_capsfilter),
886 gst_object_ref (camera->viewfinderbin_capsfilter), NULL);
887
888 /* these elements are only added if they are going to be used */
889 camera->audio_capsfilter = gst_element_factory_make ("capsfilter",
890 "audio-capsfilter");
891 camera->audio_volume = gst_element_factory_make ("volume", "audio-volume");
892 }
893
894 static void
895 gst_image_capture_bin_post_image_done (GstCameraBin2 * camera,
896 const gchar * filename)
897 {
898 GstMessage *msg;
899
900 g_return_if_fail (filename != NULL);
901
902 msg = gst_message_new_element (GST_OBJECT_CAST (camera),
903 gst_structure_new ("image-done", "filename", G_TYPE_STRING,
904 filename, NULL));
905
906 if (!gst_element_post_message (GST_ELEMENT_CAST (camera), msg))
907 GST_WARNING_OBJECT (camera, "Failed to post image-done message");
908 }
909
910 static void
911 gst_video_capture_bin_post_video_done (GstCameraBin2 * camera)
912 {
913 GstMessage *msg;
914
915 msg = gst_message_new_element (GST_OBJECT_CAST (camera),
916 gst_structure_new_empty ("video-done"));
917
918 if (!gst_element_post_message (GST_ELEMENT_CAST (camera), msg))
919 GST_WARNING_OBJECT (camera, "Failed to post video-done message");
920 }
921
922 static void
923 gst_camera_bin_skip_next_preview (GstCameraBin2 * camerabin)
924 {
925 gchar *location;
926
927 g_mutex_lock (&camerabin->preview_list_mutex);
928 if (camerabin->preview_location_list) {
929 location = camerabin->preview_location_list->data;
930 GST_DEBUG_OBJECT (camerabin, "Skipping preview for %s", location);
931 g_free (location);
932 camerabin->preview_location_list =
933 g_slist_delete_link (camerabin->preview_location_list,
934 camerabin->preview_location_list);
935 GST_CAMERA_BIN2_PROCESSING_DEC (camerabin);
936 } else {
937 GST_WARNING_OBJECT (camerabin, "No previews to skip");
938 }
939 g_mutex_unlock (&camerabin->preview_list_mutex);
940 }
941
942 static void
943 gst_camera_bin_finish_video_file (GstCameraBin2 * camerabin)
944 {
945 /* make sure the file is closed */
946 gst_element_set_state (camerabin->videosink, GST_STATE_NULL);
947
948 gst_video_capture_bin_post_video_done (camerabin);
949 GST_CAMERA_BIN2_PROCESSING_DEC (camerabin);
950 }
951
952 static gpointer
953 gst_camera_bin_video_reset_elements (gpointer u_data)
954 {
955 GstCameraBin2 *camerabin = GST_CAMERA_BIN2_CAST (u_data);
956
957 GST_DEBUG_OBJECT (camerabin, "Resetting video elements state");
958 g_mutex_lock (&camerabin->video_capture_mutex);
959
960 gst_camera_bin_finish_video_file (camerabin);
961
962 /* reset element states to clear eos/flushing pads */
963 gst_element_set_state (camerabin->video_encodebin, GST_STATE_READY);
964 gst_element_set_state (camerabin->videobin_capsfilter, GST_STATE_READY);
965 if (camerabin->video_filter) {
966 gst_element_set_state (camerabin->video_filter, GST_STATE_READY);
967 gst_element_sync_state_with_parent (camerabin->video_filter);
968 }
969 gst_element_sync_state_with_parent (camerabin->videobin_capsfilter);
970 gst_element_sync_state_with_parent (camerabin->video_encodebin);
971
972 if (camerabin->audio_src) {
973 gst_element_set_state (camerabin->audio_capsfilter, GST_STATE_READY);
974 gst_element_set_state (camerabin->audio_volume, GST_STATE_READY);
975 gst_element_set_state (camerabin->audio_src, GST_STATE_READY);
976
977 if (camerabin->audio_filter) {
978 gst_element_set_state (camerabin->audio_filter, GST_STATE_READY);
979 gst_element_sync_state_with_parent (camerabin->audio_filter);
980 }
981
982 gst_element_sync_state_with_parent (camerabin->audio_capsfilter);
983 gst_element_sync_state_with_parent (camerabin->audio_volume);
984
985 }
986
987 GST_DEBUG_OBJECT (camerabin, "Setting video state to idle");
988 camerabin->video_state = GST_CAMERA_BIN_VIDEO_IDLE;
989 g_cond_signal (&camerabin->video_state_cond);
990 g_mutex_unlock (&camerabin->video_capture_mutex);
991
992 gst_object_unref (camerabin);
993 return NULL;
994 }
995
996 static void
997 gst_camera_bin_handle_message (GstBin * bin, GstMessage * message)
998 {
999 GstCameraBin2 *camerabin = GST_CAMERA_BIN2_CAST (bin);
1000 gboolean dec_counter = FALSE;
1001
1002 switch (GST_MESSAGE_TYPE (message)) {
1003 case GST_MESSAGE_ELEMENT:{
1004 const GstStructure *structure = gst_message_get_structure (message);
1005 const gchar *filename;
1006
1007 if (gst_structure_has_name (structure, "GstMultiFileSink")) {
1008 filename = gst_structure_get_string (structure, "filename");
1009 GST_DEBUG_OBJECT (bin, "Got file save message from multifilesink, "
1010 "image %s has been saved", filename);
1011 if (filename) {
1012 gst_image_capture_bin_post_image_done (GST_CAMERA_BIN2_CAST (bin),
1013 filename);
1014 }
1015 dec_counter = TRUE;
1016 } else if (gst_structure_has_name (structure, "preview-image")) {
1017 gchar *location = NULL;
1018
1019 g_mutex_lock (&camerabin->preview_list_mutex);
1020 if (camerabin->preview_location_list) {
1021 location = camerabin->preview_location_list->data;
1022 camerabin->preview_location_list =
1023 g_slist_delete_link (camerabin->preview_location_list,
1024 camerabin->preview_location_list);
1025 GST_DEBUG_OBJECT (camerabin, "Adding preview location to preview "
1026 "message '%s'", location);
1027 } else {
1028 GST_WARNING_OBJECT (camerabin, "Unexpected preview message received, "
1029 "won't be able to put location field into the message. This can "
1030 "happen if the source is posting previews while camerabin2 is "
1031 "shutting down");
1032 }
1033 g_mutex_unlock (&camerabin->preview_list_mutex);
1034
1035 if (location) {
1036 GstStructure *new_structure;
1037 GValue value = { 0 };
1038
1039 g_value_init (&value, G_TYPE_STRING);
1040 g_value_take_string (&value, location);
1041
1042 /* need to do a copy because the structure isn't mutable */
1043 new_structure = gst_structure_copy (structure);
1044 gst_structure_take_value (new_structure, "location", &value);
1045
1046 gst_message_unref (message);
1047 message =
1048 gst_message_new_element (GST_OBJECT_CAST (camerabin),
1049 new_structure);
1050 }
1051
1052 GST_LOG_OBJECT (bin, "received preview-image message");
1053 dec_counter = TRUE;
1054 }
1055 }
1056 break;
1057 case GST_MESSAGE_WARNING:{
1058 GError *err = NULL;
1059 gchar *debug = NULL;
1060
1061 gst_message_parse_warning (message, &err, &debug);
1062 if (err->domain == GST_RESOURCE_ERROR) {
1063 /* some capturing failed */
1064 GST_WARNING_OBJECT (bin, "Capture failed, reason: %s - %s",
1065 err->message, debug);
1066 if (camerabin->post_previews) {
1067 gst_camera_bin_skip_next_preview (camerabin);
1068 }
1069 dec_counter = TRUE;
1070 }
1071 g_error_free (err);
1072 g_free (debug);
1073 }
1074 break;
1075 case GST_MESSAGE_EOS:{
1076 GstElement *src = GST_ELEMENT (GST_MESSAGE_SRC (message));
1077 if (src == GST_CAMERA_BIN2_CAST (bin)->videosink) {
1078
1079 g_mutex_lock (&camerabin->video_capture_mutex);
1080 GST_DEBUG_OBJECT (bin, "EOS from video branch");
1081 if (camerabin->video_state == GST_CAMERA_BIN_VIDEO_FINISHING) {
1082 GThread *thread = g_thread_try_new ("reset-element-thread",
1083 gst_camera_bin_video_reset_elements,
1084 gst_object_ref (camerabin), NULL);
1085 if (!thread) {
1086 GST_WARNING_OBJECT (camerabin,
1087 "Failed to create thread to "
1088 "reset video elements' state, video recordings may not work "
1089 "anymore");
1090 gst_object_unref (camerabin);
1091 camerabin->video_state = GST_CAMERA_BIN_VIDEO_IDLE;
1092 }
1093 g_clear_pointer (&thread, g_thread_unref);
1094 } else if (camerabin->video_state == GST_CAMERA_BIN_VIDEO_IDLE) {
1095 GST_DEBUG_OBJECT (camerabin, "Received EOS from video branch but "
1096 "video recording is idle, ignoring");
1097 } else {
1098 GST_WARNING_OBJECT (camerabin, "Received EOS from video branch but "
1099 "video is recording and stop-capture wasn't requested");
1100 g_assert_not_reached ();
1101 }
1102
1103 g_mutex_unlock (&camerabin->video_capture_mutex);
1104 }
1105 }
1106 break;
1107 default:
1108 break;
1109 }
1110
1111 GST_BIN_CLASS (parent_class)->handle_message (bin, message);
1112
1113 if (dec_counter)
1114 GST_CAMERA_BIN2_PROCESSING_DEC (camerabin);
1115 }
1116
1117 /*
1118 * Transforms:
1119 * ... ! previous_element [ ! current_filter ] ! next_element ! ...
1120 *
1121 * into:
1122 * ... ! previous_element [ ! new_filter ] ! next_element ! ...
1123 *
1124 * Where current_filter and new_filter might or might not be NULL
1125 */
1126 static void
1127 gst_camera_bin_check_and_replace_filter (GstCameraBin2 * camera,
1128 GstElement ** current_filter, GstElement * new_filter,
1129 GstElement * previous_element, GstElement * next_element,
1130 const gchar * prev_elem_pad)
1131 {
1132 if (*current_filter == new_filter) {
1133 GST_DEBUG_OBJECT (camera, "Current filter is the same as the previous, "
1134 "no switch needed.");
1135 return;
1136 }
1137
1138 GST_DEBUG_OBJECT (camera, "Replacing current filter (%s) with new filter "
1139 "(%s)", *current_filter ? GST_ELEMENT_NAME (*current_filter) : "null",
1140 new_filter ? GST_ELEMENT_NAME (new_filter) : "null");
1141
1142 if (*current_filter) {
1143 gst_bin_remove (GST_BIN_CAST (camera), *current_filter);
1144 gst_object_unref (*current_filter);
1145 *current_filter = NULL;
1146 } else {
1147 /* unlink the pads */
1148 gst_element_unlink (previous_element, next_element);
1149 }
1150
1151 if (new_filter) {
1152 *current_filter = gst_object_ref (new_filter);
1153 gst_bin_add (GST_BIN_CAST (camera), gst_object_ref (new_filter));
1154 }
1155
1156 if (prev_elem_pad) {
1157 if (new_filter) {
1158 gst_element_link_pads (previous_element, prev_elem_pad, new_filter, NULL);
1159 gst_element_link (new_filter, next_element);
1160 } else {
1161 gst_element_link_pads (previous_element, prev_elem_pad, next_element,
1162 NULL);
1163 }
1164 } else {
1165 if (new_filter)
1166 gst_element_link_many (previous_element, new_filter, next_element, NULL);
1167 else
1168 gst_element_link (previous_element, next_element);
1169 }
1170 }
1171
1172 static void
1173 encodebin_element_added (GstElement * encodebin, GstElement * new_element,
1174 GstCameraBin2 * camera)
1175 {
1176 GstElementFactory *factory = gst_element_get_factory (new_element);
1177
1178 if (factory != NULL) {
1179 if (strcmp (GST_OBJECT_NAME (factory), "audiorate") == 0 ||
1180 strcmp (GST_OBJECT_NAME (factory), "videorate") == 0) {
1181 g_object_set (new_element, "skip-to-first", TRUE, NULL);
1182 }
1183 }
1184
1185 if (GST_IS_TAG_SETTER (new_element)) {
1186 GstTagSetter *tagsetter = GST_TAG_SETTER (new_element);
1187
1188 gst_tag_setter_set_tag_merge_mode (tagsetter, GST_TAG_MERGE_REPLACE);
1189 }
1190 }
1191
1192 #define VIDEO_PAD 1
1193 #define AUDIO_PAD 2
1194 static GstPad *
1195 encodebin_find_pad (GstCameraBin2 * camera, GstElement * encodebin,
1196 gint pad_type)
1197 {
1198 GValue value = { 0 };
1199 GstPad *pad = NULL;
1200 GstIterator *iter;
1201 gboolean done;
1202
1203 GST_DEBUG_OBJECT (camera, "Looking at encodebin pads, searching for %s pad",
1204 pad_type == VIDEO_PAD ? "video" : "audio");
1205
1206 iter = gst_element_iterate_sink_pads (encodebin);
1207 done = FALSE;
1208 while (!done) {
1209 switch (gst_iterator_next (iter, &value)) {
1210 case GST_ITERATOR_OK:
1211 pad = g_value_dup_object (&value);
1212 g_value_unset (&value);
1213 if (pad_type == VIDEO_PAD) {
1214 if (strstr (GST_PAD_NAME (pad), "video") != NULL) {
1215 GST_DEBUG_OBJECT (camera, "Found video pad %s", GST_PAD_NAME (pad));
1216 done = TRUE;
1217 break;
1218 }
1219 } else if (pad_type == AUDIO_PAD) {
1220 if (strstr (GST_PAD_NAME (pad), "audio") != NULL) {
1221 GST_DEBUG_OBJECT (camera, "Found audio pad %s", GST_PAD_NAME (pad));
1222 done = TRUE;
1223 break;
1224 }
1225 }
1226 gst_object_unref (pad);
1227 pad = NULL;
1228 break;
1229 case GST_ITERATOR_RESYNC:
1230 gst_iterator_resync (iter);
1231 break;
1232 case GST_ITERATOR_ERROR:
1233 pad = NULL;
1234 done = TRUE;
1235 break;
1236 case GST_ITERATOR_DONE:
1237 pad = NULL;
1238 done = TRUE;
1239 break;
1240 }
1241 }
1242 gst_iterator_free (iter);
1243
1244 /* no static pad, try requesting one */
1245 if (pad == NULL) {
1246 GstElementClass *klass;
1247 GstPadTemplate *tmpl;
1248
1249 GST_DEBUG_OBJECT (camera, "No pads found, trying to request one");
1250
1251 klass = GST_ELEMENT_GET_CLASS (encodebin);
1252 tmpl = gst_element_class_get_pad_template (klass, pad_type == VIDEO_PAD ?
1253 "video_%u" : "audio_%u");
1254
1255 if (!tmpl) {
1256 GST_DEBUG_OBJECT (camera, "No templates found, can't request pad");
1257 return NULL;
1258 }
1259
1260 pad = gst_element_request_pad (encodebin, tmpl, NULL, NULL);
1261 GST_DEBUG_OBJECT (camera, "Got pad: %s", pad ? GST_PAD_NAME (pad) : "null");
1262 }
1263
1264 return pad;
1265 }
1266
1267 static gboolean
1268 gst_camera_bin_video_profile_has_audio (GstCameraBin2 * camera)
1269 {
1270 const GList *list;
1271
1272 g_return_val_if_fail (camera->video_profile != NULL, FALSE);
1273
1274 if (GST_IS_ENCODING_VIDEO_PROFILE (camera->video_profile))
1275 return FALSE;
1276
1277 for (list =
1278 gst_encoding_container_profile_get_profiles ((GstEncodingContainerProfile
1279 *) camera->video_profile); list; list = g_list_next (list)) {
1280 GstEncodingProfile *profile = (GstEncodingProfile *) list->data;
1281
1282 if (GST_IS_ENCODING_AUDIO_PROFILE (profile))
1283 return TRUE;
1284 }
1285
1286 return FALSE;
1287 }
1288
1289 static GstPadLinkReturn
1290 gst_camera_bin_link_encodebin (GstCameraBin2 * camera, GstElement * encodebin,
1291 GstElement * element, gint padtype)
1292 {
1293 GstPadLinkReturn ret;
1294 GstPad *srcpad;
1295 GstPad *sinkpad = NULL;
1296
1297 srcpad = gst_element_get_static_pad (element, "src");
1298 g_assert (srcpad != NULL);
1299
1300 sinkpad = encodebin_find_pad (camera, encodebin, padtype);
1301
1302 /* there may be no available sink pad for encodebin in some situations:
1303 * e.g. missing elements or incompatible padtype */
1304 if (sinkpad == NULL) {
1305 gst_object_unref (srcpad);
1306 return GST_PAD_LINK_REFUSED;
1307 }
1308
1309 ret = gst_pad_link_full (srcpad, sinkpad, GST_PAD_LINK_CHECK_CAPS);
1310 gst_object_unref (sinkpad);
1311 gst_object_unref (srcpad);
1312
1313 return ret;
1314 }
1315
1316 static void
1317 gst_camera_bin_src_notify_max_zoom_cb (GObject * self, GParamSpec * pspec,
1318 gpointer user_data)
1319 {
1320 GParamSpecFloat *zoom_pspec;
1321 GstCameraBin2 *camera = (GstCameraBin2 *) user_data;
1322
1323 g_object_get (self, "max-zoom", &camera->max_zoom, NULL);
1324 GST_DEBUG_OBJECT (camera, "Max zoom updated to %f", camera->max_zoom);
1325
1326 /* update zoom pspec */
1327 zoom_pspec =
1328 G_PARAM_SPEC_FLOAT (g_object_class_find_property (G_OBJECT_GET_CLASS
1329 (G_OBJECT (camera)), "zoom"));
1330 zoom_pspec->maximum = camera->max_zoom;
1331
1332 g_object_notify (G_OBJECT (camera), "max-zoom");
1333 }
1334
1335 static void
1336 gst_camera_bin_src_notify_zoom_cb (GObject * self, GParamSpec * pspec,
1337 gpointer user_data)
1338 {
1339 GstCameraBin2 *camera = (GstCameraBin2 *) user_data;
1340
1341 g_object_get (self, "zoom", &camera->zoom, NULL);
1342 GST_DEBUG_OBJECT (camera, "Zoom updated to %f", camera->zoom);
1343 g_object_notify (G_OBJECT (camera), "zoom");
1344 }
1345
1346 static GstPadProbeReturn
1347 gst_camera_bin_image_src_buffer_probe (GstPad * pad, GstPadProbeInfo * info,
1348 gpointer data)
1349 {
1350 GstPadProbeReturn ret = GST_PAD_PROBE_OK;
1351 GstCameraBin2 *camerabin = data;
1352 GstEvent *evt;
1353 gchar *location = NULL;
1354 GstPad *peer;
1355 GstTagList *tags;
1356
1357 g_mutex_lock (&camerabin->image_capture_mutex);
1358
1359 /* Push pending image tags */
1360 if (camerabin->image_tags_list) {
1361 tags = camerabin->image_tags_list->data;
1362 camerabin->image_tags_list =
1363 g_slist_delete_link (camerabin->image_tags_list,
1364 camerabin->image_tags_list);
1365 GST_DEBUG_OBJECT (camerabin, "Pushing tags from application: %"
1366 GST_PTR_FORMAT, tags);
1367 if (tags) {
1368 peer = gst_pad_get_peer (pad);
1369 gst_pad_send_event (peer, gst_event_new_tag (tags));
1370 gst_object_unref (peer);
1371 }
1372 } else {
1373 GST_DEBUG_OBJECT (camerabin, "No tags from application to send");
1374 }
1375
1376 /* Push image location event */
1377 if (camerabin->image_location_list) {
1378 location = camerabin->image_location_list->data;
1379 camerabin->image_location_list =
1380 g_slist_delete_link (camerabin->image_location_list,
1381 camerabin->image_location_list);
1382 GST_DEBUG_OBJECT (camerabin, "Sending image location change to '%s'",
1383 location);
1384 } else {
1385 GST_DEBUG_OBJECT (camerabin, "No filename location change to send");
1386 g_mutex_unlock (&camerabin->image_capture_mutex);
1387 return ret;
1388 }
1389 g_mutex_unlock (&camerabin->image_capture_mutex);
1390
1391 if (location) {
1392 evt = gst_camera_bin_new_event_file_location (location);
1393 peer = gst_pad_get_peer (pad);
1394 gst_pad_send_event (peer, evt);
1395 gst_object_unref (peer);
1396 g_free (location);
1397 } else {
1398 /* This means we don't have to encode the capture, it is used for
1399 * signaling the application just wants the preview */
1400 ret = GST_PAD_PROBE_DROP;
1401 GST_CAMERA_BIN2_PROCESSING_DEC (camerabin);
1402 }
1403
1404 return ret;
1405 }
1406
1407
1408 static GstPadProbeReturn
1409 gst_camera_bin_image_sink_event_probe (GstPad * pad, GstPadProbeInfo * info,
1410 gpointer data)
1411 {
1412 GstCameraBin2 *camerabin = data;
1413 GstEvent *event = GST_EVENT (info->data);
1414
1415 switch (GST_EVENT_TYPE (event)) {
1416 case GST_EVENT_CUSTOM_DOWNSTREAM:{
1417 if (gst_event_has_name (event, "new-location")) {
1418 const GstStructure *structure = gst_event_get_structure (event);
1419 const gchar *filename = gst_structure_get_string (structure,
1420 "location");
1421
1422 gst_element_set_state (camerabin->imagesink, GST_STATE_NULL);
1423 GST_DEBUG_OBJECT (camerabin, "Setting filename to imagesink: %s",
1424 filename);
1425 g_object_set (camerabin->imagesink, "location", filename, NULL);
1426 if (gst_element_set_state (camerabin->imagesink, GST_STATE_PLAYING) ==
1427 GST_STATE_CHANGE_FAILURE) {
1428 /* Resets the latest state change return, that would be a failure
1429 * and could cause problems in a camerabin2 state change */
1430 gst_element_set_state (camerabin->imagesink, GST_STATE_NULL);
1431 }
1432 }
1433 }
1434 break;
1435 default:
1436 break;
1437 }
1438
1439 return GST_PAD_PROBE_OK;
1440 }
1441
1442 static GstPadProbeReturn
1443 gst_camera_bin_audio_src_data_probe (GstPad * pad, GstPadProbeInfo * info,
1444 gpointer data)
1445 {
1446 GstCameraBin2 *camera = data;
1447 gboolean ret = GST_PAD_PROBE_OK;
1448
1449 if (GST_IS_BUFFER (info->data)) {
1450 if (G_UNLIKELY (camera->audio_send_newseg)) {
1451 GstBuffer *buf = GST_BUFFER_CAST (info->data);
1452 GstClockTime ts = GST_BUFFER_TIMESTAMP (buf);
1453 GstPad *peer;
1454 GstSegment segment;
1455
1456 if (!GST_CLOCK_TIME_IS_VALID (ts)) {
1457 ts = 0;
1458 }
1459
1460 peer = gst_pad_get_peer (pad);
1461 g_return_val_if_fail (peer != NULL, TRUE);
1462
1463 gst_segment_init (&segment, GST_FORMAT_TIME);
1464 segment.start = ts;
1465 gst_pad_send_event (peer, gst_event_new_segment (&segment));
1466
1467 gst_object_unref (peer);
1468
1469 camera->audio_send_newseg = FALSE;
1470 }
1471 } else {
1472 GstEvent *event = GST_EVENT_CAST (data);
1473 if (GST_EVENT_TYPE (event) == GST_EVENT_EOS) {
1474 /* we only let an EOS pass when the user is stopping a capture */
1475 if (camera->audio_drop_eos) {
1476 ret = GST_PAD_PROBE_DROP;
1477 } else {
1478 camera->audio_drop_eos = TRUE;
1479 /* should already be false, but reinforce in case no buffers get
1480 * pushed */
1481 camera->audio_send_newseg = FALSE;
1482 }
1483 } else if (GST_EVENT_TYPE (event) == GST_EVENT_SEGMENT) {
1484 ret = GST_PAD_PROBE_DROP;
1485 }
1486 }
1487
1488 return ret;
1489 }
1490
1491 /**
1492 * gst_camera_bin_create_elements:
1493 * @param camera: the #GstCameraBin2
1494 *
1495 * Creates all elements inside #GstCameraBin2
1496 *
1497 * Each of the pads on the camera source is linked as follows:
1498 * .pad ! queue ! capsfilter ! correspondingbin
1499 *
1500 * Where 'correspondingbin' is the bin appropriate for
1501 * the camera source pad.
1502 */
1503 static gboolean
1504 gst_camera_bin_create_elements (GstCameraBin2 * camera)
1505 {
1506 gboolean new_src = FALSE;
1507 gboolean new_audio_src = FALSE;
1508 gboolean has_audio;
1509 gboolean profile_switched = FALSE;
1510 const gchar *missing_element_name;
1511 gint encbin_flags = 0;
1512
1513 if (!camera->elements_created) {
1514 /* Check that elements created in _init were really created */
1515 if (!(camera->audio_capsfilter && camera->videobin_capsfilter &&
1516 camera->imagebin_capsfilter && camera->viewfinderbin_capsfilter)) {
1517 missing_element_name = "capsfilter";
1518 goto missing_element;
1519 }
1520
1521 camera->video_encodebin =
1522 gst_element_factory_make ("encodebin", "video-encodebin");
1523 if (!camera->video_encodebin) {
1524 missing_element_name = "encodebin";
1525 goto missing_element;
1526 }
1527 camera->video_encodebin_signal_id =
1528 g_signal_connect (camera->video_encodebin, "element-added",
1529 (GCallback) encodebin_element_added, camera);
1530
1531 camera->videosink =
1532 gst_element_factory_make ("filesink", "videobin-filesink");
1533 if (!camera->videosink) {
1534 missing_element_name = "filesink";
1535 goto missing_element;
1536 }
1537 g_object_set (camera->videosink, "async", FALSE, NULL);
1538
1539 /* audio elements */
1540 if (!camera->audio_volume) {
1541 missing_element_name = "volume";
1542 goto missing_element;
1543 }
1544
1545 if (camera->video_profile == NULL) {
1546 GstEncodingContainerProfile *prof;
1547 GstCaps *caps;
1548
1549 caps = gst_caps_new_empty_simple ("application/ogg");
1550 prof = gst_encoding_container_profile_new ("ogg", "theora+vorbis+ogg",
1551 caps, NULL);
1552 gst_caps_unref (caps);
1553
1554 caps = gst_caps_new_empty_simple ("video/x-theora");
1555 if (!gst_encoding_container_profile_add_profile (prof,
1556 (GstEncodingProfile *) gst_encoding_video_profile_new (caps,
1557 NULL, NULL, 1))) {
1558 GST_WARNING_OBJECT (camera, "Failed to create encoding profiles");
1559 }
1560 gst_caps_unref (caps);
1561
1562 caps = gst_caps_new_empty_simple ("audio/x-vorbis");
1563 if (!gst_encoding_container_profile_add_profile (prof,
1564 (GstEncodingProfile *) gst_encoding_audio_profile_new (caps,
1565 NULL, NULL, 1))) {
1566 GST_WARNING_OBJECT (camera, "Failed to create encoding profiles");
1567 }
1568 gst_caps_unref (caps);
1569
1570 camera->video_profile = (GstEncodingProfile *) prof;
1571 camera->video_profile_switch = TRUE;
1572 }
1573
1574 camera->image_encodebin =
1575 gst_element_factory_make ("encodebin", "image-encodebin");
1576 if (!camera->image_encodebin) {
1577 missing_element_name = "encodebin";
1578 goto missing_element;
1579 }
1580 /* durations have no meaning for image captures */
1581 g_object_set (camera->image_encodebin, "queue-time-max", (guint64) 0, NULL);
1582
1583 camera->image_encodebin_signal_id =
1584 g_signal_connect (camera->image_encodebin, "element-added",
1585 (GCallback) encodebin_element_added, camera);
1586
1587 camera->imagesink =
1588 gst_element_factory_make ("multifilesink", "imagebin-filesink");
1589 if (!camera->imagesink) {
1590 missing_element_name = "multifilesink";
1591 goto missing_element;
1592 }
1593 g_object_set (camera->imagesink, "async", FALSE, "post-messages", TRUE,
1594 NULL);
1595
1596 if (camera->image_profile == NULL) {
1597 GstEncodingVideoProfile *vprof;
1598 GstCaps *caps;
1599
1600 caps = gst_caps_new_empty_simple ("image/jpeg");
1601 vprof = gst_encoding_video_profile_new (caps, NULL, NULL, 1);
1602 gst_encoding_video_profile_set_variableframerate (vprof, TRUE);
1603
1604 gst_caps_unref (caps);
1605 camera->image_profile = (GstEncodingProfile *) vprof;
1606 camera->image_profile_switch = TRUE;
1607 }
1608
1609 camera->viewfinderbin_queue =
1610 gst_element_factory_make ("queue", "viewfinderbin-queue");
1611 if (!camera->viewfinderbin_queue) {
1612 missing_element_name = "queue";
1613 goto missing_element;
1614 }
1615
1616 g_object_set (camera->viewfinderbin_queue, "leaky", 2, "silent", TRUE,
1617 "max-size-time", (guint64) 0, "max-size-bytes", (guint) 0,
1618 "max-size-buffers", (guint) 1, NULL);
1619
1620 gst_bin_add_many (GST_BIN_CAST (camera),
1621 gst_object_ref (camera->video_encodebin),
1622 gst_object_ref (camera->videosink),
1623 gst_object_ref (camera->image_encodebin),
1624 gst_object_ref (camera->imagesink),
1625 gst_object_ref (camera->viewfinderbin_queue), NULL);
1626
1627 gst_element_link_pads_full (camera->video_encodebin, "src",
1628 camera->videosink, "sink", GST_PAD_LINK_CHECK_NOTHING);
1629 gst_element_link_pads_full (camera->image_encodebin, "src",
1630 camera->imagesink, "sink", GST_PAD_LINK_CHECK_NOTHING);
1631 gst_element_link_pads_full (camera->viewfinderbin_queue, "src",
1632 camera->viewfinderbin_capsfilter, "sink", GST_PAD_LINK_CHECK_CAPS);
1633 gst_element_link_pads_full (camera->viewfinderbin_capsfilter, "src",
1634 camera->viewfinderbin, "sink", GST_PAD_LINK_CHECK_CAPS);
1635
1636 {
1637 /* set an event probe to watch for custom location changes */
1638 GstPad *srcpad;
1639
1640 srcpad = gst_element_get_static_pad (camera->image_encodebin, "src");
1641
1642 gst_pad_add_probe (srcpad, GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM,
1643 gst_camera_bin_image_sink_event_probe, camera, NULL);
1644
1645 gst_object_unref (srcpad);
1646 }
1647
1648 /*
1649 * Video can't get into playing as its internal filesink will open
1650 * a file for writing and leave it empty if unused.
1651 *
1652 * Its state is managed using the current mode and the source's
1653 * ready-for-capture notify callback. When we are at video mode and
1654 * the source's ready-for-capture goes to FALSE it means it is
1655 * starting recording, so we should prepare the video bin.
1656 */
1657 gst_element_set_locked_state (camera->videosink, TRUE);
1658 gst_element_set_locked_state (camera->imagesink, TRUE);
1659
1660 g_object_set (camera->videosink, "location", camera->location, NULL);
1661 g_object_set (camera->imagesink, "location", camera->location, NULL);
1662 }
1663
1664 /* propagate the flags property by translating appropriate values
1665 * to GstEncFlags values */
1666 if (camera->flags & GST_CAM_FLAG_NO_AUDIO_CONVERSION)
1667 encbin_flags |= (1 << 0);
1668 if (camera->flags & GST_CAM_FLAG_NO_VIDEO_CONVERSION)
1669 encbin_flags |= (1 << 1);
1670 g_object_set (camera->video_encodebin, "flags", encbin_flags, NULL);
1671
1672 /* image encodebin has only video branch so disable its conversion elements
1673 * appropriately */
1674 if (camera->flags & GST_CAM_FLAG_NO_IMAGE_CONVERSION)
1675 g_object_set (camera->image_encodebin, "flags", (1 << 1), NULL);
1676
1677 g_object_set (camera->viewfinderbin, "disable-converters",
1678 camera->flags & GST_CAM_FLAG_NO_VIEWFINDER_CONVERSION ? TRUE : FALSE,
1679 NULL);
1680
1681 if (camera->video_profile_switch) {
1682 GST_DEBUG_OBJECT (camera, "Switching video-encodebin's profile");
1683 g_object_set (camera->video_encodebin, "profile", camera->video_profile,
1684 NULL);
1685 if (GST_PAD_LINK_FAILED (gst_camera_bin_link_encodebin (camera,
1686 camera->video_encodebin, camera->videobin_capsfilter,
1687 VIDEO_PAD))) {
1688 goto fail;
1689 }
1690 camera->video_profile_switch = FALSE;
1691
1692 /* used to trigger relinking further down */
1693 profile_switched = TRUE;
1694 }
1695
1696 if (camera->image_profile_switch) {
1697 GST_DEBUG_OBJECT (camera, "Switching image-encodebin's profile");
1698 g_object_set (camera->image_encodebin, "profile", camera->image_profile,
1699 NULL);
1700 if (GST_PAD_LINK_FAILED (gst_camera_bin_link_encodebin (camera,
1701 camera->image_encodebin, camera->imagebin_capsfilter,
1702 VIDEO_PAD))) {
1703 goto fail;
1704 }
1705 camera->image_profile_switch = FALSE;
1706 }
1707
1708 /* check if we need to replace the camera src */
1709 if (camera->src) {
1710 if (camera->user_src && camera->user_src != camera->src) {
1711
1712 if (camera->src_capture_notify_id)
1713 g_signal_handler_disconnect (camera->src,
1714 camera->src_capture_notify_id);
1715
1716 gst_bin_remove (GST_BIN_CAST (camera), camera->src);
1717 gst_object_unref (camera->src);
1718 camera->src = NULL;
1719 }
1720 }
1721
1722 if (!camera->src) {
1723 if (camera->user_src) {
1724 camera->src = gst_object_ref (camera->user_src);
1725 } else {
1726 camera->src =
1727 gst_element_factory_make ("wrappercamerabinsrc", "camerasrc");
1728 }
1729
1730 new_src = TRUE;
1731 }
1732
1733 g_assert (camera->src != NULL);
1734 g_object_set (camera->src, "mode", camera->mode, NULL);
1735 if (camera->src) {
1736 if (g_object_class_find_property (G_OBJECT_GET_CLASS (camera->src),
1737 "preview-caps")) {
1738 g_object_set (camera->src, "post-previews", camera->post_previews,
1739 "preview-caps", camera->preview_caps, "preview-filter",
1740 camera->preview_filter, NULL);
1741 }
1742 g_signal_connect (G_OBJECT (camera->src), "notify::zoom",
1743 (GCallback) gst_camera_bin_src_notify_zoom_cb, camera);
1744 g_object_set (camera->src, "zoom", camera->zoom, NULL);
1745 g_signal_connect (G_OBJECT (camera->src), "notify::max-zoom",
1746 (GCallback) gst_camera_bin_src_notify_max_zoom_cb, camera);
1747 }
1748 if (new_src) {
1749 GstPad *imgsrc = gst_element_get_static_pad (camera->src, "imgsrc");
1750
1751 gst_bin_add (GST_BIN_CAST (camera), gst_object_ref (camera->src));
1752 camera->src_capture_notify_id = g_signal_connect (G_OBJECT (camera->src),
1753 "notify::ready-for-capture",
1754 G_CALLBACK (gst_camera_bin_src_notify_readyforcapture), camera);
1755
1756 if (!gst_element_link_pads (camera->src, "vfsrc",
1757 camera->viewfinderbin_queue, "sink")) {
1758 GST_ERROR_OBJECT (camera,
1759 "Failed to link camera source's vfsrc pad to viewfinder queue");
1760 goto fail;
1761 }
1762
1763 if (camera->image_filter) {
1764 if (!gst_element_link_pads (camera->src, "imgsrc",
1765 camera->image_filter, NULL)) {
1766 GST_ERROR_OBJECT (camera,
1767 "Failed to link camera source's imgsrc pad to image filter");
1768 goto fail;
1769 }
1770 } else {
1771 if (!gst_element_link_pads (camera->src, "imgsrc",
1772 camera->imagebin_capsfilter, "sink")) {
1773 GST_ERROR_OBJECT (camera,
1774 "Failed to link camera source's imgsrc pad to image bin capsfilter");
1775 goto fail;
1776 }
1777 }
1778
1779 if (camera->video_filter) {
1780 if (!gst_element_link_pads (camera->src, "vidsrc",
1781 camera->video_filter, NULL)) {
1782 GST_ERROR_OBJECT (camera,
1783 "Failed to link camera source's vidsrc pad to video filter");
1784 goto fail;
1785 }
1786 } else {
1787 if (!gst_element_link_pads (camera->src, "vidsrc",
1788 camera->videobin_capsfilter, "sink")) {
1789 GST_ERROR_OBJECT (camera,
1790 "Failed to link camera source's vidsrc pad to video bin capsfilter");
1791 goto fail;
1792 }
1793 }
1794
1795 gst_pad_add_probe (imgsrc, GST_PAD_PROBE_TYPE_BUFFER,
1796 gst_camera_bin_image_src_buffer_probe, camera, NULL);
1797 gst_object_unref (imgsrc);
1798 }
1799
1800 gst_camera_bin_check_and_replace_filter (camera, &camera->image_filter,
1801 camera->user_image_filter, camera->src, camera->imagebin_capsfilter,
1802 "imgsrc");
1803 gst_camera_bin_check_and_replace_filter (camera, &camera->video_filter,
1804 camera->user_video_filter, camera->src, camera->videobin_capsfilter,
1805 "vidsrc");
1806 gst_camera_bin_check_and_replace_filter (camera, &camera->viewfinder_filter,
1807 camera->user_viewfinder_filter, camera->viewfinderbin_queue,
1808 camera->viewfinderbin_capsfilter, NULL);
1809
1810 /* check if we need to replace the camera audio src */
1811 has_audio = gst_camera_bin_video_profile_has_audio (camera);
1812 if (camera->audio_src) {
1813 if ((camera->user_audio_src && camera->user_audio_src != camera->audio_src)
1814 || !has_audio) {
1815 gst_bin_remove (GST_BIN_CAST (camera), camera->audio_src);
1816 gst_bin_remove (GST_BIN_CAST (camera), camera->audio_volume);
1817 gst_bin_remove (GST_BIN_CAST (camera), camera->audio_capsfilter);
1818 gst_object_unref (camera->audio_src);
1819 camera->audio_src = NULL;
1820 }
1821 }
1822
1823 if (!camera->audio_src && has_audio) {
1824 if (camera->user_audio_src) {
1825 camera->audio_src = gst_object_ref (camera->user_audio_src);
1826 } else {
1827 camera->audio_src =
1828 gst_element_factory_make (DEFAULT_AUDIO_SRC, "audiosrc");
1829 if (!camera->audio_src) {
1830 missing_element_name = DEFAULT_AUDIO_SRC;
1831 goto missing_element;
1832 }
1833 }
1834
1835 gst_element_set_locked_state (camera->audio_src, TRUE);
1836 new_audio_src = TRUE;
1837 }
1838
1839 if (new_audio_src) {
1840 GstPad *srcpad;
1841
1842 if (g_object_class_find_property (G_OBJECT_GET_CLASS (camera->audio_src),
1843 "provide-clock")) {
1844 g_object_set (camera->audio_src, "provide-clock", FALSE, NULL);
1845 }
1846 gst_bin_add (GST_BIN_CAST (camera), gst_object_ref (camera->audio_src));
1847 gst_bin_add (GST_BIN_CAST (camera), gst_object_ref (camera->audio_volume));
1848 gst_bin_add (GST_BIN_CAST (camera),
1849 gst_object_ref (camera->audio_capsfilter));
1850
1851 gst_element_link_pads_full (camera->audio_src, "src",
1852 camera->audio_volume, "sink", GST_PAD_LINK_CHECK_CAPS);
1853 gst_element_link_pads_full (camera->audio_volume, "src",
1854 camera->audio_capsfilter, "sink", GST_PAD_LINK_CHECK_CAPS);
1855
1856 srcpad = gst_element_get_static_pad (camera->audio_src, "src");
1857
1858 /* drop EOS for audiosrc elements that push them on state_changes
1859 * (basesrc does this) */
1860 gst_pad_add_probe (srcpad, GST_PAD_PROBE_TYPE_DATA_DOWNSTREAM,
1861 gst_camera_bin_audio_src_data_probe, camera, NULL);
1862
1863 gst_object_unref (srcpad);
1864 }
1865 if (has_audio) {
1866 gst_camera_bin_check_and_replace_filter (camera, &camera->audio_filter,
1867 camera->user_audio_filter, camera->audio_src, camera->audio_volume,
1868 "src");
1869 }
1870
1871 if ((profile_switched && has_audio) || new_audio_src) {
1872 if (GST_PAD_LINK_FAILED (gst_camera_bin_link_encodebin (camera,
1873 camera->video_encodebin, camera->audio_capsfilter,
1874 AUDIO_PAD))) {
1875 goto fail;
1876 }
1877 }
1878
1879 camera->elements_created = TRUE;
1880 return TRUE;
1881
1882 missing_element:
1883 gst_element_post_message (GST_ELEMENT_CAST (camera),
1884 gst_missing_element_message_new (GST_ELEMENT_CAST (camera),
1885 missing_element_name));
1886 GST_ELEMENT_ERROR (camera, CORE, MISSING_PLUGIN,
1887 (_("Missing element '%s' - check your GStreamer installation."),
1888 missing_element_name), (NULL));
1889 goto fail;
1890
1891 fail:
1892 /* FIXME properly clean up */
1893 return FALSE;
1894 }
1895
1896 static void
1897 _gst_tag_list_unref_maybe (GstTagList * taglist)
1898 {
1899 if (taglist)
1900 gst_tag_list_unref (taglist);
1901 }
1902
1903 static GstStateChangeReturn
1904 gst_camera_bin_change_state (GstElement * element, GstStateChange trans)
1905 {
1906 GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
1907 GstCameraBin2 *camera = GST_CAMERA_BIN2_CAST (element);
1908
1909
1910 switch (trans) {
1911 case GST_STATE_CHANGE_NULL_TO_READY:
1912 if (!gst_camera_bin_create_elements (camera)) {
1913 return GST_STATE_CHANGE_FAILURE;
1914 }
1915 break;
1916 case GST_STATE_CHANGE_READY_TO_PAUSED:
1917 GST_CAMERA_BIN2_RESET_PROCESSING_COUNTER (camera);
1918 camera->audio_drop_eos = TRUE;
1919 camera->audio_send_newseg = FALSE;
1920 break;
1921 case GST_STATE_CHANGE_PAUSED_TO_READY:
1922 if (GST_STATE (camera->videosink) >= GST_STATE_PAUSED)
1923 gst_element_set_state (camera->videosink, GST_STATE_READY);
1924 if (GST_STATE (camera->imagesink) >= GST_STATE_PAUSED)
1925 gst_element_set_state (camera->imagesink, GST_STATE_READY);
1926 break;
1927 case GST_STATE_CHANGE_READY_TO_NULL:
1928 gst_element_set_state (camera->videosink, GST_STATE_NULL);
1929 gst_element_set_state (camera->imagesink, GST_STATE_NULL);
1930 break;
1931 default:
1932 break;
1933 }
1934
1935 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, trans);
1936
1937 switch (trans) {
1938 case GST_STATE_CHANGE_PAUSED_TO_READY:
1939 if (camera->audio_src && GST_STATE (camera->audio_src) >= GST_STATE_READY)
1940 gst_element_set_state (camera->audio_src, GST_STATE_READY);
1941
1942 gst_tag_setter_reset_tags (GST_TAG_SETTER (camera));
1943 GST_CAMERA_BIN2_RESET_PROCESSING_COUNTER (camera);
1944 camera->video_state = GST_CAMERA_BIN_VIDEO_IDLE;
1945
1946 g_mutex_lock (&camera->image_capture_mutex);
1947 g_slist_foreach (camera->image_location_list, (GFunc) g_free, NULL);
1948 g_slist_free (camera->image_location_list);
1949 camera->image_location_list = NULL;
1950
1951 g_slist_foreach (camera->image_tags_list,
1952 (GFunc) _gst_tag_list_unref_maybe, NULL);
1953 g_slist_free (camera->image_tags_list);
1954 camera->image_tags_list = NULL;
1955 g_mutex_unlock (&camera->image_capture_mutex);
1956
1957 g_mutex_lock (&camera->preview_list_mutex);
1958 g_slist_foreach (camera->preview_location_list, (GFunc) g_free, NULL);
1959 g_slist_free (camera->preview_location_list);
1960 camera->preview_location_list = NULL;
1961 g_mutex_unlock (&camera->preview_list_mutex);
1962
1963 /* explicitly set to READY as they might be outside of the bin */
1964 gst_element_set_state (camera->audio_volume, GST_STATE_READY);
1965 gst_element_set_state (camera->audio_capsfilter, GST_STATE_READY);
1966 break;
1967 case GST_STATE_CHANGE_READY_TO_NULL:
1968 if (camera->audio_src)
1969 gst_element_set_state (camera->audio_src, GST_STATE_NULL);
1970
1971 /* explicitly set to NULL as they might be outside of the bin */
1972 gst_element_set_state (camera->audio_volume, GST_STATE_NULL);
1973 gst_element_set_state (camera->audio_capsfilter, GST_STATE_NULL);
1974
1975 break;
1976 default:
1977 break;
1978 }
1979
1980 return ret;
1981 }
1982
1983 static gboolean
1984 gst_camera_bin_send_event (GstElement * element, GstEvent * event)
1985 {
1986 GstCameraBin2 *camera = GST_CAMERA_BIN2_CAST (element);
1987 gboolean res;
1988
1989 /* avoid losing our ref to send_event */
1990 gst_event_ref (event);
1991
1992 res = GST_ELEMENT_CLASS (parent_class)->send_event (element, event);
1993 switch (GST_EVENT_TYPE (event)) {
1994 case GST_EVENT_EOS:
1995 {
1996 GstState current;
1997
1998 if (camera->videosink) {
1999 gst_element_get_state (camera->videosink, &current, NULL, 0);
2000 if (current <= GST_STATE_READY)
2001 gst_element_post_message (camera->videosink,
2002 gst_message_new_eos (GST_OBJECT (camera->videosink)));
2003 }
2004 if (camera->imagesink) {
2005 gst_element_get_state (camera->imagesink, &current, NULL, 0);
2006 if (current <= GST_STATE_READY)
2007 gst_element_post_message (camera->imagesink,
2008 gst_message_new_eos (GST_OBJECT (camera->imagesink)));
2009 }
2010 break;
2011 }
2012
2013 default:
2014 break;
2015 }
2016
2017 gst_event_unref (event);
2018 return res;
2019 }
2020
2021 static void
2022 gst_camera_bin_set_location (GstCameraBin2 * camera, const gchar * location)
2023 {
2024 GST_DEBUG_OBJECT (camera, "Setting mode %d location to %s", camera->mode,
2025 location);
2026 g_free (camera->location);
2027 camera->location = g_strdup (location);
2028 }
2029
2030 static void
2031 gst_camera_bin_set_audio_src (GstCameraBin2 * camera, GstElement * src)
2032 {
2033 GST_DEBUG_OBJECT (GST_OBJECT (camera),
2034 "Setting audio source %" GST_PTR_FORMAT, src);
2035
2036 if (camera->user_audio_src)
2037 g_object_unref (camera->user_audio_src);
2038
2039 if (src)
2040 gst_object_ref (src);
2041 camera->user_audio_src = src;
2042 }
2043
2044 static void
2045 gst_camera_bin_set_camera_src (GstCameraBin2 * camera, GstElement * src)
2046 {
2047 GST_DEBUG_OBJECT (GST_OBJECT (camera),
2048 "Setting camera source %" GST_PTR_FORMAT, src);
2049
2050 if (camera->user_src)
2051 g_object_unref (camera->user_src);
2052
2053 if (src)
2054 gst_object_ref (src);
2055 camera->user_src = src;
2056 }
2057
2058 static void
2059 gst_camera_bin_set_property (GObject * object, guint prop_id,
2060 const GValue * value, GParamSpec * pspec)
2061 {
2062 GstCameraBin2 *camera = GST_CAMERA_BIN2_CAST (object);
2063
2064 switch (prop_id) {
2065 case PROP_MODE:
2066 gst_camera_bin_change_mode (camera, g_value_get_enum (value));
2067 break;
2068 case PROP_LOCATION:
2069 gst_camera_bin_set_location (camera, g_value_get_string (value));
2070 break;
2071 case PROP_CAMERA_SRC:
2072 gst_camera_bin_set_camera_src (camera, g_value_get_object (value));
2073 break;
2074 case PROP_AUDIO_SRC:
2075 gst_camera_bin_set_audio_src (camera, g_value_get_object (value));
2076 break;
2077 case PROP_MUTE_AUDIO:
2078 g_object_set (camera->audio_volume, "mute", g_value_get_boolean (value),
2079 NULL);
2080 break;
2081 case PROP_AUDIO_CAPTURE_CAPS:{
2082 GST_DEBUG_OBJECT (camera,
2083 "Setting audio capture caps to %" GST_PTR_FORMAT,
2084 gst_value_get_caps (value));
2085
2086 if (G_LIKELY (camera->audio_capsfilter)) {
2087 g_object_set (camera->audio_capsfilter, "caps",
2088 gst_value_get_caps (value), NULL);
2089 } else {
2090 GST_WARNING_OBJECT (camera, "Audio capsfilter missing");
2091 }
2092 }
2093 break;
2094 case PROP_IMAGE_CAPTURE_CAPS:{
2095
2096 GST_DEBUG_OBJECT (camera,
2097 "Setting image capture caps to %" GST_PTR_FORMAT,
2098 gst_value_get_caps (value));
2099
2100 if (G_LIKELY (camera->imagebin_capsfilter)) {
2101 g_object_set (camera->imagebin_capsfilter, "caps",
2102 gst_value_get_caps (value), NULL);
2103 } else {
2104 GST_WARNING_OBJECT (camera, "Image capsfilter missing");
2105 }
2106 }
2107 break;
2108 case PROP_VIDEO_CAPTURE_CAPS:{
2109 GST_DEBUG_OBJECT (camera,
2110 "Setting video capture caps to %" GST_PTR_FORMAT,
2111 gst_value_get_caps (value));
2112
2113 if (G_LIKELY (camera->videobin_capsfilter)) {
2114 g_object_set (camera->videobin_capsfilter, "caps",
2115 gst_value_get_caps (value), NULL);
2116 } else {
2117 GST_WARNING_OBJECT (camera, "Video capsfilter missing");
2118 }
2119
2120 }
2121 break;
2122 case PROP_VIEWFINDER_CAPS:{
2123 GST_DEBUG_OBJECT (camera,
2124 "Setting viewfinder capture caps to %" GST_PTR_FORMAT,
2125 gst_value_get_caps (value));
2126
2127 if (G_LIKELY (camera->viewfinderbin_capsfilter)) {
2128 g_object_set (camera->viewfinderbin_capsfilter, "caps",
2129 gst_value_get_caps (value), NULL);
2130 } else {
2131 GST_WARNING_OBJECT (camera, "Viewfinder capsfilter missing");
2132 }
2133 }
2134 break;
2135 case PROP_POST_PREVIEWS:
2136 camera->post_previews = g_value_get_boolean (value);
2137 if (camera->src
2138 && g_object_class_find_property (G_OBJECT_GET_CLASS (camera->src),
2139 "post-previews"))
2140 g_object_set (camera->src, "post-previews", camera->post_previews,
2141 NULL);
2142 break;
2143 case PROP_PREVIEW_CAPS:
2144 gst_caps_replace (&camera->preview_caps,
2145 (GstCaps *) gst_value_get_caps (value));
2146 if (camera->src
2147 && g_object_class_find_property (G_OBJECT_GET_CLASS (camera->src),
2148 "preview-caps"))
2149 g_object_set (camera->src, "preview-caps", camera->preview_caps, NULL);
2150 break;
2151 case PROP_VIDEO_ENCODING_PROFILE:
2152 if (camera->video_profile)
2153 gst_encoding_profile_unref (camera->video_profile);
2154 camera->video_profile = (GstEncodingProfile *) g_value_dup_object (value);
2155 camera->video_profile_switch = TRUE;
2156 break;
2157 case PROP_IMAGE_FILTER:
2158 if (camera->user_image_filter)
2159 g_object_unref (camera->user_image_filter);
2160
2161 camera->user_image_filter = g_value_dup_object (value);
2162 break;
2163 case PROP_VIDEO_FILTER:
2164 if (camera->user_video_filter)
2165 g_object_unref (camera->user_video_filter);
2166
2167 camera->user_video_filter = g_value_dup_object (value);
2168 break;
2169 case PROP_VIEWFINDER_FILTER:
2170 if (camera->user_viewfinder_filter)
2171 g_object_unref (camera->user_viewfinder_filter);
2172
2173 camera->user_viewfinder_filter = g_value_dup_object (value);
2174 break;
2175 case PROP_PREVIEW_FILTER:
2176 if (camera->preview_filter)
2177 g_object_unref (camera->preview_filter);
2178
2179 camera->preview_filter = g_value_dup_object (value);
2180 if (camera->src
2181 && g_object_class_find_property (G_OBJECT_GET_CLASS (camera->src),
2182 "preview-filter"))
2183 g_object_set (camera->src, "preview-filter", camera->preview_filter,
2184 NULL);
2185 break;
2186 case PROP_AUDIO_FILTER:
2187 if (camera->user_audio_filter)
2188 g_object_unref (camera->user_audio_filter);
2189
2190 camera->user_audio_filter = g_value_dup_object (value);
2191 break;
2192 case PROP_VIEWFINDER_SINK:
2193 g_object_set (camera->viewfinderbin, "video-sink",
2194 g_value_get_object (value), NULL);
2195 break;
2196 case PROP_ZOOM:
2197 camera->zoom = g_value_get_float (value);
2198 /* limit to max-zoom */
2199 if (camera->zoom > camera->max_zoom) {
2200 GST_DEBUG_OBJECT (camera, "Clipping zoom %f to max-zoom %f",
2201 camera->zoom, camera->max_zoom);
2202 camera->zoom = camera->max_zoom;
2203 }
2204 if (camera->src)
2205 g_object_set (camera->src, "zoom", camera->zoom, NULL);
2206 break;
2207 case PROP_IMAGE_ENCODING_PROFILE:
2208 if (camera->image_profile)
2209 gst_encoding_profile_unref (camera->image_profile);
2210 camera->image_profile = (GstEncodingProfile *) g_value_dup_object (value);
2211
2212 /* make sure we set variable framerate here to prevent videorate from
2213 * being used in encodebin. It will always keep a buffer stored
2214 * internally and push it when a second one arrives. This breaks
2215 * the image capture */
2216 if (GST_IS_ENCODING_VIDEO_PROFILE (camera->image_profile))
2217 gst_encoding_video_profile_set_variableframerate (
2218 (GstEncodingVideoProfile *) camera->image_profile, TRUE);
2219 else if (GST_IS_ENCODING_CONTAINER_PROFILE (camera->image_profile)) {
2220 const GList *profs =
2221 gst_encoding_container_profile_get_profiles (
2222 (GstEncodingContainerProfile *) camera->image_profile);
2223 for (; profs; profs = g_list_next (profs)) {
2224 if (GST_IS_ENCODING_VIDEO_PROFILE (profs->data)) {
2225 gst_encoding_video_profile_set_variableframerate (profs->data,
2226 TRUE);
2227 }
2228 }
2229 }
2230 camera->image_profile_switch = TRUE;
2231 break;
2232 case PROP_FLAGS:
2233 camera->flags = g_value_get_flags (value);
2234 break;
2235 default:
2236 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2237 break;
2238 }
2239 }
2240
2241 static void
2242 gst_camera_bin_get_property (GObject * object, guint prop_id,
2243 GValue * value, GParamSpec * pspec)
2244 {
2245 GstCameraBin2 *camera = GST_CAMERA_BIN2_CAST (object);
2246
2247 switch (prop_id) {
2248 case PROP_MODE:
2249 g_value_set_enum (value, camera->mode);
2250 break;
2251 case PROP_LOCATION:
2252 g_value_set_string (value, camera->location);
2253 break;
2254 case PROP_CAMERA_SRC:
2255 g_value_set_object (value, camera->user_src);
2256 break;
2257 case PROP_AUDIO_SRC:
2258 g_value_set_object (value, camera->user_audio_src);
2259 break;
2260 case PROP_MUTE_AUDIO:{
2261 gboolean mute;
2262
2263 g_object_get (camera->audio_volume, "mute", &mute, NULL);
2264 g_value_set_boolean (value, mute);
2265 break;
2266 }
2267 case PROP_AUDIO_CAPTURE_SUPPORTED_CAPS:
2268 case PROP_VIDEO_CAPTURE_SUPPORTED_CAPS:
2269 case PROP_VIEWFINDER_SUPPORTED_CAPS:
2270 case PROP_IMAGE_CAPTURE_SUPPORTED_CAPS:{
2271 GstPad *pad;
2272 GstElement *element;
2273 GstCaps *caps;
2274 const gchar *padname;
2275
2276 if (prop_id == PROP_VIDEO_CAPTURE_SUPPORTED_CAPS) {
2277 element = camera->src;
2278 padname = GST_BASE_CAMERA_SRC_VIDEO_PAD_NAME;
2279 } else if (prop_id == PROP_IMAGE_CAPTURE_SUPPORTED_CAPS) {
2280 element = camera->src;
2281 padname = GST_BASE_CAMERA_SRC_IMAGE_PAD_NAME;
2282 } else if (prop_id == PROP_VIEWFINDER_SUPPORTED_CAPS) {
2283 element = camera->src;
2284 padname = GST_BASE_CAMERA_SRC_VIEWFINDER_PAD_NAME;
2285 } else {
2286 element = camera->audio_src;
2287 padname = "src";
2288 }
2289
2290 if (element) {
2291 pad = gst_element_get_static_pad (element, padname);
2292
2293 g_assert (pad != NULL);
2294
2295 /* TODO not sure if we want get_caps or get_allowed_caps to already
2296 * consider the full pipeline scenario and avoid picking a caps that
2297 * won't negotiate. Need to take care on the special case of the
2298 * pad being unlinked.
2299 */
2300 caps = gst_pad_query_caps (pad, NULL);
2301 if (caps) {
2302 gst_value_set_caps (value, caps);
2303 gst_caps_unref (caps);
2304 }
2305
2306 gst_object_unref (pad);
2307 } else {
2308 GST_DEBUG_OBJECT (camera, "Source not created, can't get "
2309 "supported caps");
2310 }
2311 }
2312 break;
2313 case PROP_AUDIO_CAPTURE_CAPS:{
2314 GstCaps *caps = NULL;
2315 if (G_LIKELY (camera->audio_capsfilter)) {
2316 g_object_get (camera->audio_capsfilter, "caps", &caps, NULL);
2317 } else {
2318 GST_WARNING ("Missing audio capsfilter");
2319 }
2320 gst_value_set_caps (value, caps);
2321 gst_caps_unref (caps);
2322 }
2323 break;
2324 case PROP_IMAGE_CAPTURE_CAPS:{
2325 GstCaps *caps = NULL;
2326 if (G_LIKELY (camera->imagebin_capsfilter)) {
2327 g_object_get (camera->imagebin_capsfilter, "caps", &caps, NULL);
2328 } else {
2329 GST_WARNING ("Missing imagebin capsfilter");
2330 }
2331 gst_value_set_caps (value, caps);
2332 gst_caps_unref (caps);
2333 }
2334 break;
2335 case PROP_VIDEO_CAPTURE_CAPS:{
2336 GstCaps *caps = NULL;
2337 if (G_LIKELY (camera->videobin_capsfilter)) {
2338 g_object_get (camera->videobin_capsfilter, "caps", &caps, NULL);
2339 } else {
2340 GST_WARNING ("Missing imagebin capsfilter");
2341 }
2342 gst_value_set_caps (value, caps);
2343 gst_caps_unref (caps);
2344 }
2345 break;
2346 case PROP_VIEWFINDER_CAPS:{
2347 GstCaps *caps = NULL;
2348 if (G_LIKELY (camera->viewfinderbin_capsfilter)) {
2349 g_object_get (camera->viewfinderbin_capsfilter, "caps", &caps, NULL);
2350 } else {
2351 GST_WARNING ("Missing imagebin capsfilter");
2352 }
2353 gst_value_set_caps (value, caps);
2354 gst_caps_unref (caps);
2355 }
2356 break;
2357 case PROP_POST_PREVIEWS:
2358 g_value_set_boolean (value, camera->post_previews);
2359 break;
2360 case PROP_PREVIEW_CAPS:
2361 if (camera->preview_caps)
2362 gst_value_set_caps (value, camera->preview_caps);
2363 break;
2364 case PROP_VIDEO_ENCODING_PROFILE:
2365 if (camera->video_profile) {
2366 g_value_set_object (value, camera->video_profile);
2367 }
2368 break;
2369 case PROP_VIDEO_FILTER:
2370 if (camera->user_video_filter)
2371 g_value_set_object (value, camera->user_video_filter);
2372 break;
2373 case PROP_IMAGE_FILTER:
2374 if (camera->user_image_filter)
2375 g_value_set_object (value, camera->user_image_filter);
2376 break;
2377 case PROP_VIEWFINDER_FILTER:
2378 if (camera->user_viewfinder_filter)
2379 g_value_set_object (value, camera->user_viewfinder_filter);
2380 break;
2381 case PROP_AUDIO_FILTER:
2382 if (camera->user_audio_filter)
2383 g_value_set_object (value, camera->user_audio_filter);
2384 break;
2385 case PROP_PREVIEW_FILTER:
2386 if (camera->preview_filter)
2387 g_value_set_object (value, camera->preview_filter);
2388 break;
2389 case PROP_VIEWFINDER_SINK:{
2390 GstElement *sink;
2391
2392 g_object_get (camera->viewfinderbin, "video-sink", &sink, NULL);
2393 g_value_take_object (value, sink);
2394 break;
2395 }
2396 case PROP_ZOOM:
2397 g_value_set_float (value, camera->zoom);
2398 break;
2399 case PROP_MAX_ZOOM:
2400 g_value_set_float (value, camera->max_zoom);
2401 break;
2402 case PROP_IMAGE_ENCODING_PROFILE:
2403 if (camera->image_profile) {
2404 g_value_set_object (value, camera->image_profile);
2405 }
2406 break;
2407 case PROP_IDLE:
2408 g_value_set_boolean (value,
2409 g_atomic_int_get (&camera->processing_counter) == 0);
2410 break;
2411 case PROP_FLAGS:
2412 g_value_set_flags (value, camera->flags);
2413 break;
2414 default:
2415 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2416 break;
2417 }
2418 }