2 * Copyright (C) 2010 Thiago Santos <thiago.sousa.santos@collabora.co.uk>
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., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
20 * SECTION:element-camerabin
23 * CameraBin is a high-level camera object that encapsulates gstreamer
24 * elements, providing an API for controlling a digital camera.
26 * > Note that camerabin is still UNSTABLE and under development.
28 * CameraBin has the following main features:
32 * * Display a viewfinder
33 * * Post preview images for each capture (video and image)
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.
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.
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
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.
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.
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.
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.
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.
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.
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.
89 * The viewfinder resolution can be configured using
90 * #GstCameraBin:viewfinder-caps, these #GstCaps should be a subset of
91 * #GstCameraBin:viewfinder-supported-caps.
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.
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.
106 * ## Example launch line
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.
112 * gst-launch-1.0 -v -m camerabin
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.
134 * - TODO: What happens when an error pops?
135 * - TODO: Should we split properties in image/video variants? We already do so
147 #include <gst/basecamerabinsrc/gstbasecamerasrc.h>
148 #include "gstcamerabin2.h"
149 #include <gst/gst-i18n-plugin.h>
150 #include <gst/pbutils/pbutils.h>
151 #include <gst/glib-compat-private.h>
153 #define GST_CAMERA_BIN2_PROCESSING_INC(c) \
155 gint bef = g_atomic_int_add (&c->processing_counter, 1); \
157 g_object_notify (G_OBJECT (c), "idle"); \
158 GST_DEBUG_OBJECT ((c), "Processing counter incremented to: %d", \
162 #define GST_CAMERA_BIN2_PROCESSING_DEC(c) \
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"); \
168 GST_DEBUG_OBJECT ((c), "Processing counter decremented"); \
171 #define GST_CAMERA_BIN2_RESET_PROCESSING_COUNTER(c) \
173 g_atomic_int_set (&c->processing_counter, 0); \
174 GST_DEBUG_OBJECT ((c), "Processing counter reset"); \
177 GST_DEBUG_CATEGORY_STATIC (gst_camera_bin_debug);
178 #define GST_CAT_DEFAULT gst_camera_bin_debug
188 PROP_IMAGE_CAPTURE_SUPPORTED_CAPS,
189 PROP_VIDEO_CAPTURE_SUPPORTED_CAPS,
190 PROP_IMAGE_CAPTURE_CAPS,
191 PROP_VIDEO_CAPTURE_CAPS,
194 PROP_VIDEO_ENCODING_PROFILE,
197 PROP_VIEWFINDER_FILTER,
199 PROP_VIEWFINDER_SINK,
200 PROP_VIEWFINDER_SUPPORTED_CAPS,
201 PROP_VIEWFINDER_CAPS,
204 PROP_AUDIO_CAPTURE_SUPPORTED_CAPS,
205 PROP_AUDIO_CAPTURE_CAPS,
208 PROP_IMAGE_ENCODING_PROFILE,
217 START_CAPTURE_SIGNAL,
222 static guint camerabin_signals[LAST_SIGNAL];
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
231 #define DEFAULT_AUDIO_SRC "autoaudiosrc"
233 /********************************
234 * Standard GObject boilerplate *
235 * and GObject types *
236 ********************************/
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);
245 static void gst_camera_bin_handle_message (GstBin * bin, GstMessage * message);
246 static gboolean gst_camera_bin_send_event (GstElement * element,
249 #define C_FLAGS(v) ((guint) v)
250 #define GST_TYPE_CAM_FLAGS (gst_cam_flags_get_type())
252 gst_cam_flags_get_type (void)
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"},
266 static volatile GType id = 0;
268 if (g_once_init_enter ((gsize *) & id)) {
271 _id = g_flags_register_static ("GstCamFlags", values);
273 g_once_init_leave ((gsize *) & id, _id);
280 gst_camera_bin2_get_type (void)
282 static GType gst_camera_bin_type = 0;
283 static const GInterfaceInfo camerabin_tagsetter_info = {
289 if (!gst_camera_bin_type) {
290 static const GTypeInfo gst_camera_bin_info = {
291 sizeof (GstCameraBin2Class),
292 (GBaseInitFunc) gst_camera_bin_base_init,
294 (GClassInitFunc) gst_camera_bin_class_init,
297 sizeof (GstCameraBin2),
299 (GInstanceInitFunc) gst_camera_bin_init,
303 gst_camera_bin_type =
304 g_type_register_static (GST_TYPE_PIPELINE, "GstCameraBin",
305 &gst_camera_bin_info, 0);
307 g_type_add_interface_static (gst_camera_bin_type, GST_TYPE_TAG_SETTER,
308 &camerabin_tagsetter_info);
311 return gst_camera_bin_type;
314 /* GObject class functions */
315 static void gst_camera_bin_set_property (GObject * object, guint prop_id,
316 const GValue * value, GParamSpec * pspec);
317 static void gst_camera_bin_get_property (GObject * object, guint prop_id,
318 GValue * value, GParamSpec * pspec);
320 /* Element class functions */
321 static GstStateChangeReturn
322 gst_camera_bin_change_state (GstElement * element, GstStateChange trans);
325 /* Camerabin functions */
328 gst_camera_bin_new_event_file_location (const gchar * location)
330 return gst_event_new_custom (GST_EVENT_CUSTOM_DOWNSTREAM,
331 gst_structure_new ("new-location", "location", G_TYPE_STRING, location,
336 gst_camera_bin_start_capture (GstCameraBin2 * camerabin)
338 const GstTagList *taglist;
339 gint capture_index = camerabin->capture_index;
340 gchar *location = NULL;
341 GST_DEBUG_OBJECT (camerabin, "Received start-capture");
343 /* check that we have a valid location */
344 if (camerabin->mode == MODE_VIDEO) {
345 if (camerabin->location == NULL) {
346 GST_ELEMENT_ERROR (camerabin, RESOURCE, OPEN_WRITE,
347 (_("File location is set to NULL, please set it to a valid filename")), (NULL));
351 g_mutex_lock (&camerabin->video_capture_mutex);
352 while (camerabin->video_state == GST_CAMERA_BIN_VIDEO_FINISHING) {
353 g_cond_wait (&camerabin->video_state_cond,
354 &camerabin->video_capture_mutex);
356 if (camerabin->video_state != GST_CAMERA_BIN_VIDEO_IDLE) {
357 GST_WARNING_OBJECT (camerabin, "Another video recording is ongoing"
358 " (state %d), cannot start a new one", camerabin->video_state);
359 g_mutex_unlock (&camerabin->video_capture_mutex);
362 camerabin->video_state = GST_CAMERA_BIN_VIDEO_STARTING;
365 GST_CAMERA_BIN2_PROCESSING_INC (camerabin);
367 if (camerabin->location)
368 location = g_strdup_printf (camerabin->location, capture_index);
370 if (camerabin->mode == MODE_IMAGE) {
371 /* store the next capture buffer filename */
372 g_mutex_lock (&camerabin->image_capture_mutex);
373 camerabin->image_location_list =
374 g_slist_append (camerabin->image_location_list, g_strdup (location));
375 g_mutex_unlock (&camerabin->image_capture_mutex);
378 if (camerabin->post_previews) {
379 /* Count processing of preview images too */
380 GST_CAMERA_BIN2_PROCESSING_INC (camerabin);
381 /* store the next preview filename */
382 g_mutex_lock (&camerabin->preview_list_mutex);
383 camerabin->preview_location_list =
384 g_slist_append (camerabin->preview_location_list, location);
385 g_mutex_unlock (&camerabin->preview_list_mutex);
390 g_signal_emit_by_name (camerabin->src, "start-capture", NULL);
391 if (camerabin->mode == MODE_VIDEO) {
392 camerabin->audio_send_newseg = TRUE;
393 if (camerabin->audio_src)
394 gst_element_set_state (camerabin->audio_src, GST_STATE_PLAYING);
396 camerabin->video_state = GST_CAMERA_BIN_VIDEO_RECORDING;
397 g_mutex_unlock (&camerabin->video_capture_mutex);
401 * We have to push tags after start capture because the video elements
402 * might be flushing from the previous capture and are reset only on the
403 * notify from ready for capture going to FALSE
405 taglist = gst_tag_setter_get_tag_list (GST_TAG_SETTER (camerabin));
406 GST_DEBUG_OBJECT (camerabin, "Have tags from application: %"
407 GST_PTR_FORMAT, taglist);
409 if (camerabin->mode == MODE_IMAGE) {
410 /* Store image tags in a list and push them later, this prevents
411 start_capture() from blocking in pad_push_event call */
412 g_mutex_lock (&camerabin->image_capture_mutex);
413 camerabin->image_tags_list =
414 g_slist_append (camerabin->image_tags_list,
415 taglist ? gst_tag_list_copy (taglist) : NULL);
416 g_mutex_unlock (&camerabin->image_capture_mutex);
417 } else if (taglist) {
420 active_pad = gst_element_get_static_pad (camerabin->src,
421 GST_BASE_CAMERA_SRC_VIDEO_PAD_NAME);
422 gst_pad_push_event (active_pad,
423 gst_event_new_tag (gst_tag_list_copy (taglist)));
425 gst_object_unref (active_pad);
428 GST_DEBUG_OBJECT (camerabin, "Start-capture end");
432 gst_camera_bin_stop_capture (GstCameraBin2 * camerabin)
434 GST_DEBUG_OBJECT (camerabin, "Received stop-capture");
435 if (camerabin->mode == MODE_VIDEO) {
436 g_mutex_lock (&camerabin->video_capture_mutex);
437 if (camerabin->video_state == GST_CAMERA_BIN_VIDEO_RECORDING) {
439 g_signal_emit_by_name (camerabin->src, "stop-capture", NULL);
441 camerabin->video_state = GST_CAMERA_BIN_VIDEO_FINISHING;
442 if (camerabin->audio_src) {
443 camerabin->audio_drop_eos = FALSE;
444 gst_element_send_event (camerabin->audio_src, gst_event_new_eos ());
447 g_mutex_unlock (&camerabin->video_capture_mutex);
452 gst_camera_bin_change_mode (GstCameraBin2 * camerabin, gint mode)
454 if (mode == camerabin->mode)
457 GST_DEBUG_OBJECT (camerabin, "Changing mode to %d", mode);
459 /* stop any ongoing capture */
460 gst_camera_bin_stop_capture (camerabin);
461 camerabin->mode = mode;
463 g_object_set (camerabin->src, "mode", mode, NULL);
467 gst_camera_bin_src_notify_readyforcapture (GObject * obj, GParamSpec * pspec,
470 GstCameraBin2 *camera = GST_CAMERA_BIN2_CAST (user_data);
473 g_object_get (camera->src, "ready-for-capture", &ready, NULL);
475 gchar *location = NULL;
477 if (camera->mode == MODE_VIDEO) {
478 /* a video recording is about to start, change the filesink location */
479 gst_element_set_state (camera->videosink, GST_STATE_NULL);
480 location = g_strdup_printf (camera->location, camera->capture_index);
481 GST_DEBUG_OBJECT (camera, "Switching videobin location to %s", location);
482 g_object_set (camera->videosink, "location", location, NULL);
484 if (gst_element_set_state (camera->videosink, GST_STATE_PLAYING) ==
485 GST_STATE_CHANGE_FAILURE) {
486 /* Resets the latest state change return, that would be a failure
487 * and could cause problems in a camerabin2 state change */
488 gst_element_set_state (camera->videosink, GST_STATE_NULL);
492 camera->capture_index++;
497 gst_camera_bin_dispose (GObject * object)
499 GstCameraBin2 *camerabin = GST_CAMERA_BIN2_CAST (object);
501 g_free (camerabin->location);
502 g_mutex_clear (&camerabin->preview_list_mutex);
503 g_mutex_clear (&camerabin->image_capture_mutex);
504 g_mutex_clear (&camerabin->video_capture_mutex);
505 g_cond_clear (&camerabin->video_state_cond);
507 if (camerabin->src_capture_notify_id)
508 g_signal_handler_disconnect (camerabin->src,
509 camerabin->src_capture_notify_id);
511 gst_object_unref (camerabin->src);
512 if (camerabin->user_src)
513 gst_object_unref (camerabin->user_src);
515 if (camerabin->audio_src)
516 gst_object_unref (camerabin->audio_src);
517 if (camerabin->user_audio_src)
518 gst_object_unref (camerabin->user_audio_src);
520 if (camerabin->audio_capsfilter)
521 gst_object_unref (camerabin->audio_capsfilter);
522 if (camerabin->audio_volume)
523 gst_object_unref (camerabin->audio_volume);
525 if (camerabin->viewfinderbin)
526 gst_object_unref (camerabin->viewfinderbin);
527 if (camerabin->viewfinderbin_queue)
528 gst_object_unref (camerabin->viewfinderbin_queue);
529 if (camerabin->viewfinderbin_capsfilter)
530 gst_object_unref (camerabin->viewfinderbin_capsfilter);
532 if (camerabin->video_encodebin_signal_id)
533 g_signal_handler_disconnect (camerabin->video_encodebin,
534 camerabin->video_encodebin_signal_id);
536 if (camerabin->videosink)
537 gst_object_unref (camerabin->videosink);
538 if (camerabin->video_encodebin)
539 gst_object_unref (camerabin->video_encodebin);
540 if (camerabin->videobin_capsfilter)
541 gst_object_unref (camerabin->videobin_capsfilter);
543 if (camerabin->image_encodebin_signal_id)
544 g_signal_handler_disconnect (camerabin->image_encodebin,
545 camerabin->image_encodebin_signal_id);
546 if (camerabin->imagesink)
547 gst_object_unref (camerabin->imagesink);
548 if (camerabin->image_encodebin)
549 gst_object_unref (camerabin->image_encodebin);
550 if (camerabin->imagebin_capsfilter)
551 gst_object_unref (camerabin->imagebin_capsfilter);
553 if (camerabin->video_filter)
554 gst_object_unref (camerabin->video_filter);
555 if (camerabin->image_filter)
556 gst_object_unref (camerabin->image_filter);
557 if (camerabin->viewfinder_filter)
558 gst_object_unref (camerabin->viewfinder_filter);
559 if (camerabin->audio_filter)
560 gst_object_unref (camerabin->audio_filter);
562 if (camerabin->user_video_filter)
563 gst_object_unref (camerabin->user_video_filter);
564 if (camerabin->user_audio_filter)
565 gst_object_unref (camerabin->user_audio_filter);
566 if (camerabin->user_image_filter)
567 gst_object_unref (camerabin->user_image_filter);
568 if (camerabin->user_viewfinder_filter)
569 gst_object_unref (camerabin->user_viewfinder_filter);
571 if (camerabin->video_profile)
572 gst_encoding_profile_unref (camerabin->video_profile);
573 if (camerabin->image_profile)
574 gst_encoding_profile_unref (camerabin->image_profile);
576 if (camerabin->preview_caps)
577 gst_caps_replace (&camerabin->preview_caps, NULL);
578 if (camerabin->preview_filter) {
579 gst_object_unref (camerabin->preview_filter);
580 camerabin->preview_filter = NULL;
583 G_OBJECT_CLASS (parent_class)->dispose (object);
587 gst_camera_bin_finalize (GObject * object)
589 G_OBJECT_CLASS (parent_class)->finalize (object);
593 gst_camera_bin_base_init (gpointer g_class)
595 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
597 gst_element_class_set_static_metadata (element_class, "Camera Bin",
598 "Generic/Bin/Camera",
599 "Take image snapshots and record movies from camera",
600 "Thiago Santos <thiago.sousa.santos@collabora.co.uk>");
604 gst_camera_bin_class_init (GstCameraBin2Class * klass)
606 GObjectClass *object_class;
607 GstElementClass *element_class;
608 GstBinClass *bin_class;
610 parent_class = g_type_class_peek_parent (klass);
611 object_class = G_OBJECT_CLASS (klass);
612 element_class = GST_ELEMENT_CLASS (klass);
613 bin_class = GST_BIN_CLASS (klass);
615 object_class->dispose = gst_camera_bin_dispose;
616 object_class->finalize = gst_camera_bin_finalize;
617 object_class->set_property = gst_camera_bin_set_property;
618 object_class->get_property = gst_camera_bin_get_property;
620 element_class->change_state = GST_DEBUG_FUNCPTR (gst_camera_bin_change_state);
621 element_class->send_event = GST_DEBUG_FUNCPTR (gst_camera_bin_send_event);
623 bin_class->handle_message = gst_camera_bin_handle_message;
625 klass->start_capture = gst_camera_bin_start_capture;
626 klass->stop_capture = gst_camera_bin_stop_capture;
629 * GstCameraBin2:mode:
631 * Set the mode of operation: still image capturing or video recording.
633 g_object_class_install_property (object_class, PROP_MODE,
634 g_param_spec_enum ("mode", "Mode",
635 "The capture mode (still image capture or video recording)",
636 GST_TYPE_CAMERABIN_MODE, DEFAULT_MODE,
637 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
639 g_object_class_install_property (object_class, PROP_LOCATION,
640 g_param_spec_string ("location", "Location",
641 "Location to save the captured files. A %d might be used on the"
642 "filename as a placeholder for a numeric index of the capture."
644 DEFAULT_LOCATION, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
646 g_object_class_install_property (object_class, PROP_CAMERA_SRC,
647 g_param_spec_object ("camera-source", "Camera source",
648 "The camera source element to be used. It is only taken into use on"
649 " the next null to ready transition",
650 GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
652 g_object_class_install_property (object_class, PROP_AUDIO_SRC,
653 g_param_spec_object ("audio-source", "Audio source",
654 "The audio source element to be used on video recordings. It is only"
655 " taken into use on the next null to ready transition",
656 GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
658 g_object_class_install_property (object_class, PROP_MUTE_AUDIO,
659 g_param_spec_boolean ("mute", "Mute",
660 "If the audio recording should be muted. Note that this still "
661 "saves audio data to the resulting file, but they are silent. Use "
662 "a video-profile without audio to disable audio completely",
663 DEFAULT_MUTE_AUDIO, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
665 g_object_class_install_property (object_class,
666 PROP_AUDIO_CAPTURE_SUPPORTED_CAPS,
667 g_param_spec_boxed ("audio-capture-supported-caps",
668 "Audio capture supported caps",
669 "Formats supported for capturing audio represented as GstCaps",
670 GST_TYPE_CAPS, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
672 g_object_class_install_property (object_class,
673 PROP_AUDIO_CAPTURE_CAPS,
674 g_param_spec_boxed ("audio-capture-caps",
675 "Audio capture caps",
676 "Format to capture audio for video recording represented as GstCaps",
677 GST_TYPE_CAPS, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
679 g_object_class_install_property (object_class,
680 PROP_IMAGE_CAPTURE_SUPPORTED_CAPS,
681 g_param_spec_boxed ("image-capture-supported-caps",
682 "Image capture supported caps",
683 "Formats supported for capturing images represented as GstCaps",
684 GST_TYPE_CAPS, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
686 g_object_class_install_property (object_class,
687 PROP_VIDEO_CAPTURE_SUPPORTED_CAPS,
688 g_param_spec_boxed ("video-capture-supported-caps",
689 "Video capture supported caps",
690 "Formats supported for capturing videos represented as GstCaps",
691 GST_TYPE_CAPS, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
693 g_object_class_install_property (object_class,
694 PROP_IMAGE_CAPTURE_CAPS,
695 g_param_spec_boxed ("image-capture-caps",
696 "Image capture caps",
697 "Caps for image capture",
698 GST_TYPE_CAPS, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
700 g_object_class_install_property (object_class,
701 PROP_VIDEO_CAPTURE_CAPS,
702 g_param_spec_boxed ("video-capture-caps",
703 "Video capture caps",
704 "Caps for video capture",
705 GST_TYPE_CAPS, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
707 g_object_class_install_property (object_class, PROP_POST_PREVIEWS,
708 g_param_spec_boolean ("post-previews", "Post Previews",
709 "If capture preview images should be posted to the bus",
710 DEFAULT_POST_PREVIEWS, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
712 g_object_class_install_property (object_class, PROP_PREVIEW_CAPS,
713 g_param_spec_boxed ("preview-caps", "Preview caps",
714 "The caps of the preview image to be posted",
715 GST_TYPE_CAPS, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
717 g_object_class_install_property (object_class, PROP_VIDEO_ENCODING_PROFILE,
718 g_param_spec_object ("video-profile", "Video Profile",
719 "The GstEncodingProfile to use for video recording. Audio is enabled "
720 "when this profile supports audio.", GST_TYPE_ENCODING_PROFILE,
721 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
723 g_object_class_install_property (object_class, PROP_IMAGE_FILTER,
724 g_param_spec_object ("image-filter", "Image filter",
725 "The element that will process captured image frames. (Should be"
726 " set on NULL state)",
727 GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
729 g_object_class_install_property (object_class, PROP_VIDEO_FILTER,
730 g_param_spec_object ("video-filter", "Video filter",
731 "The element that will process captured video frames. (Should be"
732 " set on NULL state)",
733 GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
735 g_object_class_install_property (object_class, PROP_VIEWFINDER_FILTER,
736 g_param_spec_object ("viewfinder-filter", "Viewfinder filter",
737 "The element that will process frames going to the viewfinder."
738 " (Should be set on NULL state)",
739 GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
741 g_object_class_install_property (object_class, PROP_AUDIO_FILTER,
742 g_param_spec_object ("audio-filter", "Audio filter",
743 "The element that will process captured audio buffers when recording"
744 ". (Should be set on NULL state)",
745 GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
747 g_object_class_install_property (object_class, PROP_PREVIEW_FILTER,
748 g_param_spec_object ("preview-filter", "Preview filter",
749 "The element that will process preview buffers."
750 " (Should be set on NULL state)",
751 GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
753 g_object_class_install_property (object_class, PROP_VIEWFINDER_SINK,
754 g_param_spec_object ("viewfinder-sink", "Viewfinder sink",
755 "The video sink of the viewfinder. It is only taken into use"
756 " on the next null to ready transition",
757 GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
759 g_object_class_install_property (object_class,
760 PROP_VIEWFINDER_CAPS,
761 g_param_spec_boxed ("viewfinder-caps",
763 "Restricts the caps that can be used on the viewfinder",
764 GST_TYPE_CAPS, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
766 g_object_class_install_property (object_class, PROP_ZOOM,
767 g_param_spec_float ("zoom", "Zoom",
768 "Digital zoom factor (e.g. 1.5 means 1.5x)", MIN_ZOOM, MAX_ZOOM,
769 DEFAULT_ZOOM, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
771 g_object_class_install_property (object_class, PROP_MAX_ZOOM,
772 g_param_spec_float ("max-zoom", "Maximum zoom level (note: may change "
773 "depending on resolution/implementation)",
774 "Digital zoom factor (e.g. 1.5 means 1.5x)", MIN_ZOOM, G_MAXFLOAT,
775 MAX_ZOOM, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
778 * Review before stable
779 * - One problem with using encodebin for images here is how jifmux
780 * autoplugging works. We need to give it a higher rank and fix its
781 * caps (it has image/jpeg on sink and src pads). Preliminary tests
782 * show that jifmux is picked if image/jpeg is the caps of a container
783 * profile. So this could work.
784 * - There seems to be a problem with encodebin for images currently as
785 * it autoplugs a videorate that only starts outputting buffers after
786 * getting the 2nd buffer.
788 g_object_class_install_property (object_class, PROP_IMAGE_ENCODING_PROFILE,
789 g_param_spec_object ("image-profile", "Image Profile",
790 "The GstEncodingProfile to use for image captures.",
791 GST_TYPE_ENCODING_PROFILE,
792 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
795 g_object_class_install_property (object_class, PROP_IDLE,
796 g_param_spec_boolean ("idle", "Idle",
797 "If camerabin2 is idle (not doing captures).", DEFAULT_IDLE,
798 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
800 /* TODO review before going stable
801 * We have viewfinder-supported-caps that returns the caps that the
802 * camerasrc can produce on its viewfinder pad, this could easily be
803 * confused with what the viewfinder-sink accepts.
805 * Do we want to add a 'viewfinder-sink-supported-caps' or maybe change
806 * the name of this property?
808 g_object_class_install_property (object_class,
809 PROP_VIEWFINDER_SUPPORTED_CAPS,
810 g_param_spec_boxed ("viewfinder-supported-caps",
811 "Camera source Viewfinder pad supported caps",
812 "The caps that the camera source can produce on the viewfinder pad",
813 GST_TYPE_CAPS, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
818 * Control the behaviour of encodebin.
820 g_object_class_install_property (object_class, PROP_FLAGS,
821 g_param_spec_flags ("flags", "Flags", "Flags to control behaviour",
822 GST_TYPE_CAM_FLAGS, DEFAULT_FLAGS,
823 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
826 * GstCameraBin2::capture-start:
827 * @camera: the camera bin element
829 * Starts image capture or video recording depending on the Mode.
831 camerabin_signals[START_CAPTURE_SIGNAL] =
832 g_signal_new ("start-capture",
833 G_TYPE_FROM_CLASS (klass),
834 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
835 G_STRUCT_OFFSET (GstCameraBin2Class, start_capture),
836 NULL, NULL, NULL, G_TYPE_NONE, 0);
839 * GstCameraBin2::capture-stop:
840 * @camera: the camera bin element
842 camerabin_signals[STOP_CAPTURE_SIGNAL] =
843 g_signal_new ("stop-capture",
844 G_TYPE_FROM_CLASS (klass),
845 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
846 G_STRUCT_OFFSET (GstCameraBin2Class, stop_capture),
847 NULL, NULL, NULL, G_TYPE_NONE, 0);
849 gst_type_mark_as_plugin_api (GST_TYPE_CAM_FLAGS, 0);
853 gst_camera_bin_init (GstCameraBin2 * camera)
855 camera->post_previews = DEFAULT_POST_PREVIEWS;
856 camera->mode = DEFAULT_MODE;
857 camera->location = g_strdup (DEFAULT_LOCATION);
858 camera->viewfinderbin = gst_element_factory_make ("viewfinderbin", "vf-bin");
859 camera->zoom = DEFAULT_ZOOM;
860 camera->max_zoom = MAX_ZOOM;
861 camera->flags = DEFAULT_FLAGS;
862 g_mutex_init (&camera->preview_list_mutex);
863 g_mutex_init (&camera->image_capture_mutex);
864 g_mutex_init (&camera->video_capture_mutex);
865 g_cond_init (&camera->video_state_cond);
867 /* capsfilters are created here as we proxy their caps properties and
868 * this way we avoid having to store the caps while on NULL state to
870 camera->videobin_capsfilter = gst_element_factory_make ("capsfilter",
871 "videobin-capsfilter");
872 camera->imagebin_capsfilter = gst_element_factory_make ("capsfilter",
873 "imagebin-capsfilter");
874 camera->viewfinderbin_capsfilter = gst_element_factory_make ("capsfilter",
875 "viewfinderbin-capsfilter");
877 gst_bin_add_many (GST_BIN (camera),
878 gst_object_ref (camera->viewfinderbin),
879 gst_object_ref (camera->videobin_capsfilter),
880 gst_object_ref (camera->imagebin_capsfilter),
881 gst_object_ref (camera->viewfinderbin_capsfilter), NULL);
883 /* these elements are only added if they are going to be used */
884 camera->audio_capsfilter = gst_element_factory_make ("capsfilter",
886 camera->audio_volume = gst_element_factory_make ("volume", "audio-volume");
890 gst_image_capture_bin_post_image_done (GstCameraBin2 * camera,
891 const gchar * filename)
895 g_return_if_fail (filename != NULL);
897 msg = gst_message_new_element (GST_OBJECT_CAST (camera),
898 gst_structure_new ("image-done", "filename", G_TYPE_STRING,
901 if (!gst_element_post_message (GST_ELEMENT_CAST (camera), msg))
902 GST_WARNING_OBJECT (camera, "Failed to post image-done message");
906 gst_video_capture_bin_post_video_done (GstCameraBin2 * camera)
910 msg = gst_message_new_element (GST_OBJECT_CAST (camera),
911 gst_structure_new_empty ("video-done"));
913 if (!gst_element_post_message (GST_ELEMENT_CAST (camera), msg))
914 GST_WARNING_OBJECT (camera, "Failed to post video-done message");
918 gst_camera_bin_skip_next_preview (GstCameraBin2 * camerabin)
922 g_mutex_lock (&camerabin->preview_list_mutex);
923 if (camerabin->preview_location_list) {
924 location = camerabin->preview_location_list->data;
925 GST_DEBUG_OBJECT (camerabin, "Skipping preview for %s", location);
927 camerabin->preview_location_list =
928 g_slist_delete_link (camerabin->preview_location_list,
929 camerabin->preview_location_list);
930 GST_CAMERA_BIN2_PROCESSING_DEC (camerabin);
932 GST_WARNING_OBJECT (camerabin, "No previews to skip");
934 g_mutex_unlock (&camerabin->preview_list_mutex);
938 gst_camera_bin_finish_video_file (GstCameraBin2 * camerabin)
940 /* make sure the file is closed */
941 gst_element_set_state (camerabin->videosink, GST_STATE_NULL);
943 gst_video_capture_bin_post_video_done (camerabin);
944 GST_CAMERA_BIN2_PROCESSING_DEC (camerabin);
948 gst_camera_bin_video_reset_elements (gpointer u_data)
950 GstCameraBin2 *camerabin = GST_CAMERA_BIN2_CAST (u_data);
952 GST_DEBUG_OBJECT (camerabin, "Resetting video elements state");
953 g_mutex_lock (&camerabin->video_capture_mutex);
955 gst_camera_bin_finish_video_file (camerabin);
957 /* reset element states to clear eos/flushing pads */
958 gst_element_set_state (camerabin->video_encodebin, GST_STATE_READY);
959 gst_element_set_state (camerabin->videobin_capsfilter, GST_STATE_READY);
960 if (camerabin->video_filter) {
961 gst_element_set_state (camerabin->video_filter, GST_STATE_READY);
962 gst_element_sync_state_with_parent (camerabin->video_filter);
964 gst_element_sync_state_with_parent (camerabin->videobin_capsfilter);
965 gst_element_sync_state_with_parent (camerabin->video_encodebin);
967 if (camerabin->audio_src) {
968 gst_element_set_state (camerabin->audio_capsfilter, GST_STATE_READY);
969 gst_element_set_state (camerabin->audio_volume, GST_STATE_READY);
970 gst_element_set_state (camerabin->audio_src, GST_STATE_READY);
972 if (camerabin->audio_filter) {
973 gst_element_set_state (camerabin->audio_filter, GST_STATE_READY);
974 gst_element_sync_state_with_parent (camerabin->audio_filter);
977 gst_element_sync_state_with_parent (camerabin->audio_capsfilter);
978 gst_element_sync_state_with_parent (camerabin->audio_volume);
982 GST_DEBUG_OBJECT (camerabin, "Setting video state to idle");
983 camerabin->video_state = GST_CAMERA_BIN_VIDEO_IDLE;
984 g_cond_signal (&camerabin->video_state_cond);
985 g_mutex_unlock (&camerabin->video_capture_mutex);
987 gst_object_unref (camerabin);
992 gst_camera_bin_handle_message (GstBin * bin, GstMessage * message)
994 GstCameraBin2 *camerabin = GST_CAMERA_BIN2_CAST (bin);
995 gboolean dec_counter = FALSE;
997 switch (GST_MESSAGE_TYPE (message)) {
998 case GST_MESSAGE_ELEMENT:{
999 const GstStructure *structure = gst_message_get_structure (message);
1000 const gchar *filename;
1002 if (gst_structure_has_name (structure, "GstMultiFileSink")) {
1003 filename = gst_structure_get_string (structure, "filename");
1004 GST_DEBUG_OBJECT (bin, "Got file save message from multifilesink, "
1005 "image %s has been saved", filename);
1007 gst_image_capture_bin_post_image_done (GST_CAMERA_BIN2_CAST (bin),
1011 } else if (gst_structure_has_name (structure, "preview-image")) {
1012 gchar *location = NULL;
1014 g_mutex_lock (&camerabin->preview_list_mutex);
1015 if (camerabin->preview_location_list) {
1016 location = camerabin->preview_location_list->data;
1017 camerabin->preview_location_list =
1018 g_slist_delete_link (camerabin->preview_location_list,
1019 camerabin->preview_location_list);
1020 GST_DEBUG_OBJECT (camerabin, "Adding preview location to preview "
1021 "message '%s'", location);
1023 GST_WARNING_OBJECT (camerabin, "Unexpected preview message received, "
1024 "won't be able to put location field into the message. This can "
1025 "happen if the source is posting previews while camerabin2 is "
1028 g_mutex_unlock (&camerabin->preview_list_mutex);
1031 GstStructure *new_structure;
1032 GValue value = { 0 };
1034 g_value_init (&value, G_TYPE_STRING);
1035 g_value_take_string (&value, location);
1037 /* need to do a copy because the structure isn't mutable */
1038 new_structure = gst_structure_copy (structure);
1039 gst_structure_take_value (new_structure, "location", &value);
1041 gst_message_unref (message);
1043 gst_message_new_element (GST_OBJECT_CAST (camerabin),
1047 GST_LOG_OBJECT (bin, "received preview-image message");
1052 case GST_MESSAGE_WARNING:{
1054 gchar *debug = NULL;
1056 gst_message_parse_warning (message, &err, &debug);
1057 if (err->domain == GST_RESOURCE_ERROR) {
1058 /* some capturing failed */
1059 GST_WARNING_OBJECT (bin, "Capture failed, reason: %s - %s",
1060 err->message, debug);
1061 if (camerabin->post_previews) {
1062 gst_camera_bin_skip_next_preview (camerabin);
1070 case GST_MESSAGE_EOS:{
1071 GstElement *src = GST_ELEMENT (GST_MESSAGE_SRC (message));
1072 if (src == GST_CAMERA_BIN2_CAST (bin)->videosink) {
1074 g_mutex_lock (&camerabin->video_capture_mutex);
1075 GST_DEBUG_OBJECT (bin, "EOS from video branch");
1076 if (camerabin->video_state == GST_CAMERA_BIN_VIDEO_FINISHING) {
1077 if (!g_thread_try_new ("reset-element-thread",
1078 gst_camera_bin_video_reset_elements,
1079 gst_object_ref (camerabin), NULL)) {
1080 GST_WARNING_OBJECT (camerabin,
1081 "Failed to create thread to "
1082 "reset video elements' state, video recordings may not work "
1084 gst_object_unref (camerabin);
1085 camerabin->video_state = GST_CAMERA_BIN_VIDEO_IDLE;
1087 } else if (camerabin->video_state == GST_CAMERA_BIN_VIDEO_IDLE) {
1088 GST_DEBUG_OBJECT (camerabin, "Received EOS from video branch but "
1089 "video recording is idle, ignoring");
1091 GST_WARNING_OBJECT (camerabin, "Received EOS from video branch but "
1092 "video is recording and stop-capture wasn't requested");
1093 g_assert_not_reached ();
1096 g_mutex_unlock (&camerabin->video_capture_mutex);
1104 GST_BIN_CLASS (parent_class)->handle_message (bin, message);
1107 GST_CAMERA_BIN2_PROCESSING_DEC (camerabin);
1112 * ... ! previous_element [ ! current_filter ] ! next_element ! ...
1115 * ... ! previous_element [ ! new_filter ] ! next_element ! ...
1117 * Where current_filter and new_filter might or might not be NULL
1120 gst_camera_bin_check_and_replace_filter (GstCameraBin2 * camera,
1121 GstElement ** current_filter, GstElement * new_filter,
1122 GstElement * previous_element, GstElement * next_element,
1123 const gchar * prev_elem_pad)
1125 if (*current_filter == new_filter) {
1126 GST_DEBUG_OBJECT (camera, "Current filter is the same as the previous, "
1127 "no switch needed.");
1131 GST_DEBUG_OBJECT (camera, "Replacing current filter (%s) with new filter "
1132 "(%s)", *current_filter ? GST_ELEMENT_NAME (*current_filter) : "null",
1133 new_filter ? GST_ELEMENT_NAME (new_filter) : "null");
1135 if (*current_filter) {
1136 gst_bin_remove (GST_BIN_CAST (camera), *current_filter);
1137 gst_object_unref (*current_filter);
1138 *current_filter = NULL;
1140 /* unlink the pads */
1141 gst_element_unlink (previous_element, next_element);
1145 *current_filter = gst_object_ref (new_filter);
1146 gst_bin_add (GST_BIN_CAST (camera), gst_object_ref (new_filter));
1149 if (prev_elem_pad) {
1151 gst_element_link_pads (previous_element, prev_elem_pad, new_filter, NULL);
1152 gst_element_link (new_filter, next_element);
1154 gst_element_link_pads (previous_element, prev_elem_pad, next_element,
1159 gst_element_link_many (previous_element, new_filter, next_element, NULL);
1161 gst_element_link (previous_element, next_element);
1166 encodebin_element_added (GstElement * encodebin, GstElement * new_element,
1167 GstCameraBin2 * camera)
1169 GstElementFactory *factory = gst_element_get_factory (new_element);
1171 if (factory != NULL) {
1172 if (strcmp (GST_OBJECT_NAME (factory), "audiorate") == 0 ||
1173 strcmp (GST_OBJECT_NAME (factory), "videorate") == 0) {
1174 g_object_set (new_element, "skip-to-first", TRUE, NULL);
1178 if (GST_IS_TAG_SETTER (new_element)) {
1179 GstTagSetter *tagsetter = GST_TAG_SETTER (new_element);
1181 gst_tag_setter_set_tag_merge_mode (tagsetter, GST_TAG_MERGE_REPLACE);
1188 encodebin_find_pad (GstCameraBin2 * camera, GstElement * encodebin,
1191 GValue value = { 0 };
1196 GST_DEBUG_OBJECT (camera, "Looking at encodebin pads, searching for %s pad",
1197 pad_type == VIDEO_PAD ? "video" : "audio");
1199 iter = gst_element_iterate_sink_pads (encodebin);
1202 switch (gst_iterator_next (iter, &value)) {
1203 case GST_ITERATOR_OK:
1204 pad = g_value_dup_object (&value);
1205 g_value_unset (&value);
1206 if (pad_type == VIDEO_PAD) {
1207 if (strstr (GST_PAD_NAME (pad), "video") != NULL) {
1208 GST_DEBUG_OBJECT (camera, "Found video pad %s", GST_PAD_NAME (pad));
1212 } else if (pad_type == AUDIO_PAD) {
1213 if (strstr (GST_PAD_NAME (pad), "audio") != NULL) {
1214 GST_DEBUG_OBJECT (camera, "Found audio pad %s", GST_PAD_NAME (pad));
1219 gst_object_unref (pad);
1222 case GST_ITERATOR_RESYNC:
1223 gst_iterator_resync (iter);
1225 case GST_ITERATOR_ERROR:
1229 case GST_ITERATOR_DONE:
1235 gst_iterator_free (iter);
1237 /* no static pad, try requesting one */
1239 GstElementClass *klass;
1240 GstPadTemplate *tmpl;
1242 GST_DEBUG_OBJECT (camera, "No pads found, trying to request one");
1244 klass = GST_ELEMENT_GET_CLASS (encodebin);
1245 tmpl = gst_element_class_get_pad_template (klass, pad_type == VIDEO_PAD ?
1246 "video_%u" : "audio_%u");
1249 GST_DEBUG_OBJECT (camera, "No templates found, can't request pad");
1253 pad = gst_element_request_pad (encodebin, tmpl, NULL, NULL);
1254 GST_DEBUG_OBJECT (camera, "Got pad: %s", pad ? GST_PAD_NAME (pad) : "null");
1261 gst_camera_bin_video_profile_has_audio (GstCameraBin2 * camera)
1265 g_return_val_if_fail (camera->video_profile != NULL, FALSE);
1267 if (GST_IS_ENCODING_VIDEO_PROFILE (camera->video_profile))
1271 gst_encoding_container_profile_get_profiles ((GstEncodingContainerProfile
1272 *) camera->video_profile); list; list = g_list_next (list)) {
1273 GstEncodingProfile *profile = (GstEncodingProfile *) list->data;
1275 if (GST_IS_ENCODING_AUDIO_PROFILE (profile))
1282 static GstPadLinkReturn
1283 gst_camera_bin_link_encodebin (GstCameraBin2 * camera, GstElement * encodebin,
1284 GstElement * element, gint padtype)
1286 GstPadLinkReturn ret;
1288 GstPad *sinkpad = NULL;
1290 srcpad = gst_element_get_static_pad (element, "src");
1291 g_assert (srcpad != NULL);
1293 sinkpad = encodebin_find_pad (camera, encodebin, padtype);
1295 /* there may be no available sink pad for encodebin in some situations:
1296 * e.g. missing elements or incompatible padtype */
1297 if (sinkpad == NULL) {
1298 gst_object_unref (srcpad);
1299 return GST_PAD_LINK_REFUSED;
1302 ret = gst_pad_link_full (srcpad, sinkpad, GST_PAD_LINK_CHECK_CAPS);
1303 gst_object_unref (sinkpad);
1304 gst_object_unref (srcpad);
1310 gst_camera_bin_src_notify_max_zoom_cb (GObject * self, GParamSpec * pspec,
1313 GParamSpecFloat *zoom_pspec;
1314 GstCameraBin2 *camera = (GstCameraBin2 *) user_data;
1316 g_object_get (self, "max-zoom", &camera->max_zoom, NULL);
1317 GST_DEBUG_OBJECT (camera, "Max zoom updated to %f", camera->max_zoom);
1319 /* update zoom pspec */
1321 G_PARAM_SPEC_FLOAT (g_object_class_find_property (G_OBJECT_GET_CLASS
1322 (G_OBJECT (camera)), "zoom"));
1323 zoom_pspec->maximum = camera->max_zoom;
1325 g_object_notify (G_OBJECT (camera), "max-zoom");
1329 gst_camera_bin_src_notify_zoom_cb (GObject * self, GParamSpec * pspec,
1332 GstCameraBin2 *camera = (GstCameraBin2 *) user_data;
1334 g_object_get (self, "zoom", &camera->zoom, NULL);
1335 GST_DEBUG_OBJECT (camera, "Zoom updated to %f", camera->zoom);
1336 g_object_notify (G_OBJECT (camera), "zoom");
1339 static GstPadProbeReturn
1340 gst_camera_bin_image_src_buffer_probe (GstPad * pad, GstPadProbeInfo * info,
1343 GstPadProbeReturn ret = GST_PAD_PROBE_OK;
1344 GstCameraBin2 *camerabin = data;
1346 gchar *location = NULL;
1350 g_mutex_lock (&camerabin->image_capture_mutex);
1352 /* Push pending image tags */
1353 if (camerabin->image_tags_list) {
1354 tags = camerabin->image_tags_list->data;
1355 camerabin->image_tags_list =
1356 g_slist_delete_link (camerabin->image_tags_list,
1357 camerabin->image_tags_list);
1358 GST_DEBUG_OBJECT (camerabin, "Pushing tags from application: %"
1359 GST_PTR_FORMAT, tags);
1361 peer = gst_pad_get_peer (pad);
1362 gst_pad_send_event (peer, gst_event_new_tag (tags));
1363 gst_object_unref (peer);
1366 GST_DEBUG_OBJECT (camerabin, "No tags from application to send");
1369 /* Push image location event */
1370 if (camerabin->image_location_list) {
1371 location = camerabin->image_location_list->data;
1372 camerabin->image_location_list =
1373 g_slist_delete_link (camerabin->image_location_list,
1374 camerabin->image_location_list);
1375 GST_DEBUG_OBJECT (camerabin, "Sending image location change to '%s'",
1378 GST_DEBUG_OBJECT (camerabin, "No filename location change to send");
1379 g_mutex_unlock (&camerabin->image_capture_mutex);
1382 g_mutex_unlock (&camerabin->image_capture_mutex);
1385 evt = gst_camera_bin_new_event_file_location (location);
1386 peer = gst_pad_get_peer (pad);
1387 gst_pad_send_event (peer, evt);
1388 gst_object_unref (peer);
1391 /* This means we don't have to encode the capture, it is used for
1392 * signaling the application just wants the preview */
1393 ret = GST_PAD_PROBE_DROP;
1394 GST_CAMERA_BIN2_PROCESSING_DEC (camerabin);
1401 static GstPadProbeReturn
1402 gst_camera_bin_image_sink_event_probe (GstPad * pad, GstPadProbeInfo * info,
1405 GstCameraBin2 *camerabin = data;
1406 GstEvent *event = GST_EVENT (info->data);
1408 switch (GST_EVENT_TYPE (event)) {
1409 case GST_EVENT_CUSTOM_DOWNSTREAM:{
1410 if (gst_event_has_name (event, "new-location")) {
1411 const GstStructure *structure = gst_event_get_structure (event);
1412 const gchar *filename = gst_structure_get_string (structure,
1415 gst_element_set_state (camerabin->imagesink, GST_STATE_NULL);
1416 GST_DEBUG_OBJECT (camerabin, "Setting filename to imagesink: %s",
1418 g_object_set (camerabin->imagesink, "location", filename, NULL);
1419 if (gst_element_set_state (camerabin->imagesink, GST_STATE_PLAYING) ==
1420 GST_STATE_CHANGE_FAILURE) {
1421 /* Resets the latest state change return, that would be a failure
1422 * and could cause problems in a camerabin2 state change */
1423 gst_element_set_state (camerabin->imagesink, GST_STATE_NULL);
1432 return GST_PAD_PROBE_OK;
1435 static GstPadProbeReturn
1436 gst_camera_bin_audio_src_data_probe (GstPad * pad, GstPadProbeInfo * info,
1439 GstCameraBin2 *camera = data;
1440 gboolean ret = GST_PAD_PROBE_OK;
1442 if (GST_IS_BUFFER (info->data)) {
1443 if (G_UNLIKELY (camera->audio_send_newseg)) {
1444 GstBuffer *buf = GST_BUFFER_CAST (info->data);
1445 GstClockTime ts = GST_BUFFER_TIMESTAMP (buf);
1449 if (!GST_CLOCK_TIME_IS_VALID (ts)) {
1453 peer = gst_pad_get_peer (pad);
1454 g_return_val_if_fail (peer != NULL, TRUE);
1456 gst_segment_init (&segment, GST_FORMAT_TIME);
1458 gst_pad_send_event (peer, gst_event_new_segment (&segment));
1460 gst_object_unref (peer);
1462 camera->audio_send_newseg = FALSE;
1465 GstEvent *event = GST_EVENT_CAST (data);
1466 if (GST_EVENT_TYPE (event) == GST_EVENT_EOS) {
1467 /* we only let an EOS pass when the user is stopping a capture */
1468 if (camera->audio_drop_eos) {
1469 ret = GST_PAD_PROBE_DROP;
1471 camera->audio_drop_eos = TRUE;
1472 /* should already be false, but reinforce in case no buffers get
1474 camera->audio_send_newseg = FALSE;
1476 } else if (GST_EVENT_TYPE (event) == GST_EVENT_SEGMENT) {
1477 ret = GST_PAD_PROBE_DROP;
1485 * gst_camera_bin_create_elements:
1486 * @param camera: the #GstCameraBin2
1488 * Creates all elements inside #GstCameraBin2
1490 * Each of the pads on the camera source is linked as follows:
1491 * .pad ! queue ! capsfilter ! correspondingbin
1493 * Where 'correspondingbin' is the bin appropriate for
1494 * the camera source pad.
1497 gst_camera_bin_create_elements (GstCameraBin2 * camera)
1499 gboolean new_src = FALSE;
1500 gboolean new_audio_src = FALSE;
1502 gboolean profile_switched = FALSE;
1503 const gchar *missing_element_name;
1504 gint encbin_flags = 0;
1506 if (!camera->elements_created) {
1507 /* Check that elements created in _init were really created */
1508 if (!(camera->audio_capsfilter && camera->videobin_capsfilter &&
1509 camera->imagebin_capsfilter && camera->viewfinderbin_capsfilter)) {
1510 missing_element_name = "capsfilter";
1511 goto missing_element;
1514 camera->video_encodebin =
1515 gst_element_factory_make ("encodebin", "video-encodebin");
1516 if (!camera->video_encodebin) {
1517 missing_element_name = "encodebin";
1518 goto missing_element;
1520 camera->video_encodebin_signal_id =
1521 g_signal_connect (camera->video_encodebin, "element-added",
1522 (GCallback) encodebin_element_added, camera);
1525 gst_element_factory_make ("filesink", "videobin-filesink");
1526 if (!camera->videosink) {
1527 missing_element_name = "filesink";
1528 goto missing_element;
1530 g_object_set (camera->videosink, "async", FALSE, NULL);
1532 /* audio elements */
1533 if (!camera->audio_volume) {
1534 missing_element_name = "volume";
1535 goto missing_element;
1538 if (camera->video_profile == NULL) {
1539 GstEncodingContainerProfile *prof;
1542 caps = gst_caps_new_empty_simple ("application/ogg");
1543 prof = gst_encoding_container_profile_new ("ogg", "theora+vorbis+ogg",
1545 gst_caps_unref (caps);
1547 caps = gst_caps_new_empty_simple ("video/x-theora");
1548 if (!gst_encoding_container_profile_add_profile (prof,
1549 (GstEncodingProfile *) gst_encoding_video_profile_new (caps,
1551 GST_WARNING_OBJECT (camera, "Failed to create encoding profiles");
1553 gst_caps_unref (caps);
1555 caps = gst_caps_new_empty_simple ("audio/x-vorbis");
1556 if (!gst_encoding_container_profile_add_profile (prof,
1557 (GstEncodingProfile *) gst_encoding_audio_profile_new (caps,
1559 GST_WARNING_OBJECT (camera, "Failed to create encoding profiles");
1561 gst_caps_unref (caps);
1563 camera->video_profile = (GstEncodingProfile *) prof;
1564 camera->video_profile_switch = TRUE;
1567 camera->image_encodebin =
1568 gst_element_factory_make ("encodebin", "image-encodebin");
1569 if (!camera->image_encodebin) {
1570 missing_element_name = "encodebin";
1571 goto missing_element;
1573 /* durations have no meaning for image captures */
1574 g_object_set (camera->image_encodebin, "queue-time-max", (guint64) 0, NULL);
1576 camera->image_encodebin_signal_id =
1577 g_signal_connect (camera->image_encodebin, "element-added",
1578 (GCallback) encodebin_element_added, camera);
1581 gst_element_factory_make ("multifilesink", "imagebin-filesink");
1582 if (!camera->imagesink) {
1583 missing_element_name = "multifilesink";
1584 goto missing_element;
1586 g_object_set (camera->imagesink, "async", FALSE, "post-messages", TRUE,
1589 if (camera->image_profile == NULL) {
1590 GstEncodingVideoProfile *vprof;
1593 caps = gst_caps_new_empty_simple ("image/jpeg");
1594 vprof = gst_encoding_video_profile_new (caps, NULL, NULL, 1);
1595 gst_encoding_video_profile_set_variableframerate (vprof, TRUE);
1597 gst_caps_unref (caps);
1598 camera->image_profile = (GstEncodingProfile *) vprof;
1599 camera->image_profile_switch = TRUE;
1602 camera->viewfinderbin_queue =
1603 gst_element_factory_make ("queue", "viewfinderbin-queue");
1604 if (!camera->viewfinderbin_queue) {
1605 missing_element_name = "queue";
1606 goto missing_element;
1609 g_object_set (camera->viewfinderbin_queue, "leaky", 2, "silent", TRUE,
1610 "max-size-time", (guint64) 0, "max-size-bytes", (guint) 0,
1611 "max-size-buffers", (guint) 1, NULL);
1613 gst_bin_add_many (GST_BIN_CAST (camera),
1614 gst_object_ref (camera->video_encodebin),
1615 gst_object_ref (camera->videosink),
1616 gst_object_ref (camera->image_encodebin),
1617 gst_object_ref (camera->imagesink),
1618 gst_object_ref (camera->viewfinderbin_queue), NULL);
1620 gst_element_link_pads_full (camera->video_encodebin, "src",
1621 camera->videosink, "sink", GST_PAD_LINK_CHECK_NOTHING);
1622 gst_element_link_pads_full (camera->image_encodebin, "src",
1623 camera->imagesink, "sink", GST_PAD_LINK_CHECK_NOTHING);
1624 gst_element_link_pads_full (camera->viewfinderbin_queue, "src",
1625 camera->viewfinderbin_capsfilter, "sink", GST_PAD_LINK_CHECK_CAPS);
1626 gst_element_link_pads_full (camera->viewfinderbin_capsfilter, "src",
1627 camera->viewfinderbin, "sink", GST_PAD_LINK_CHECK_CAPS);
1630 /* set an event probe to watch for custom location changes */
1633 srcpad = gst_element_get_static_pad (camera->image_encodebin, "src");
1635 gst_pad_add_probe (srcpad, GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM,
1636 gst_camera_bin_image_sink_event_probe, camera, NULL);
1638 gst_object_unref (srcpad);
1642 * Video can't get into playing as its internal filesink will open
1643 * a file for writing and leave it empty if unused.
1645 * Its state is managed using the current mode and the source's
1646 * ready-for-capture notify callback. When we are at video mode and
1647 * the source's ready-for-capture goes to FALSE it means it is
1648 * starting recording, so we should prepare the video bin.
1650 gst_element_set_locked_state (camera->videosink, TRUE);
1651 gst_element_set_locked_state (camera->imagesink, TRUE);
1653 g_object_set (camera->videosink, "location", camera->location, NULL);
1654 g_object_set (camera->imagesink, "location", camera->location, NULL);
1657 /* propagate the flags property by translating appropriate values
1658 * to GstEncFlags values */
1659 if (camera->flags & GST_CAM_FLAG_NO_AUDIO_CONVERSION)
1660 encbin_flags |= (1 << 0);
1661 if (camera->flags & GST_CAM_FLAG_NO_VIDEO_CONVERSION)
1662 encbin_flags |= (1 << 1);
1663 g_object_set (camera->video_encodebin, "flags", encbin_flags, NULL);
1665 /* image encodebin has only video branch so disable its conversion elements
1667 if (camera->flags & GST_CAM_FLAG_NO_IMAGE_CONVERSION)
1668 g_object_set (camera->image_encodebin, "flags", (1 << 1), NULL);
1670 g_object_set (camera->viewfinderbin, "disable-converters",
1671 camera->flags & GST_CAM_FLAG_NO_VIEWFINDER_CONVERSION ? TRUE : FALSE,
1674 if (camera->video_profile_switch) {
1675 GST_DEBUG_OBJECT (camera, "Switching video-encodebin's profile");
1676 g_object_set (camera->video_encodebin, "profile", camera->video_profile,
1678 if (GST_PAD_LINK_FAILED (gst_camera_bin_link_encodebin (camera,
1679 camera->video_encodebin, camera->videobin_capsfilter,
1683 camera->video_profile_switch = FALSE;
1685 /* used to trigger relinking further down */
1686 profile_switched = TRUE;
1689 if (camera->image_profile_switch) {
1690 GST_DEBUG_OBJECT (camera, "Switching image-encodebin's profile");
1691 g_object_set (camera->image_encodebin, "profile", camera->image_profile,
1693 if (GST_PAD_LINK_FAILED (gst_camera_bin_link_encodebin (camera,
1694 camera->image_encodebin, camera->imagebin_capsfilter,
1698 camera->image_profile_switch = FALSE;
1701 /* check if we need to replace the camera src */
1703 if (camera->user_src && camera->user_src != camera->src) {
1705 if (camera->src_capture_notify_id)
1706 g_signal_handler_disconnect (camera->src,
1707 camera->src_capture_notify_id);
1709 gst_bin_remove (GST_BIN_CAST (camera), camera->src);
1710 gst_object_unref (camera->src);
1716 if (camera->user_src) {
1717 camera->src = gst_object_ref (camera->user_src);
1720 gst_element_factory_make ("wrappercamerabinsrc", "camerasrc");
1726 g_assert (camera->src != NULL);
1727 g_object_set (camera->src, "mode", camera->mode, NULL);
1729 if (g_object_class_find_property (G_OBJECT_GET_CLASS (camera->src),
1731 g_object_set (camera->src, "post-previews", camera->post_previews,
1732 "preview-caps", camera->preview_caps, "preview-filter",
1733 camera->preview_filter, NULL);
1735 g_signal_connect (G_OBJECT (camera->src), "notify::zoom",
1736 (GCallback) gst_camera_bin_src_notify_zoom_cb, camera);
1737 g_object_set (camera->src, "zoom", camera->zoom, NULL);
1738 g_signal_connect (G_OBJECT (camera->src), "notify::max-zoom",
1739 (GCallback) gst_camera_bin_src_notify_max_zoom_cb, camera);
1742 GstPad *imgsrc = gst_element_get_static_pad (camera->src, "imgsrc");
1744 gst_bin_add (GST_BIN_CAST (camera), gst_object_ref (camera->src));
1745 camera->src_capture_notify_id = g_signal_connect (G_OBJECT (camera->src),
1746 "notify::ready-for-capture",
1747 G_CALLBACK (gst_camera_bin_src_notify_readyforcapture), camera);
1749 if (!gst_element_link_pads (camera->src, "vfsrc",
1750 camera->viewfinderbin_queue, "sink")) {
1751 GST_ERROR_OBJECT (camera,
1752 "Failed to link camera source's vfsrc pad to viewfinder queue");
1756 if (!gst_element_link_pads (camera->src, "imgsrc",
1757 camera->imagebin_capsfilter, "sink")) {
1758 GST_ERROR_OBJECT (camera,
1759 "Failed to link camera source's imgsrc pad to image bin capsfilter");
1762 if (!gst_element_link_pads (camera->src, "vidsrc",
1763 camera->videobin_capsfilter, "sink")) {
1764 GST_ERROR_OBJECT (camera,
1765 "Failed to link camera source's vidsrc pad to video bin capsfilter");
1769 gst_pad_add_probe (imgsrc, GST_PAD_PROBE_TYPE_BUFFER,
1770 gst_camera_bin_image_src_buffer_probe, camera, NULL);
1771 gst_object_unref (imgsrc);
1774 gst_camera_bin_check_and_replace_filter (camera, &camera->image_filter,
1775 camera->user_image_filter, camera->src, camera->imagebin_capsfilter,
1777 gst_camera_bin_check_and_replace_filter (camera, &camera->video_filter,
1778 camera->user_video_filter, camera->src, camera->videobin_capsfilter,
1780 gst_camera_bin_check_and_replace_filter (camera, &camera->viewfinder_filter,
1781 camera->user_viewfinder_filter, camera->viewfinderbin_queue,
1782 camera->viewfinderbin_capsfilter, NULL);
1784 /* check if we need to replace the camera audio src */
1785 has_audio = gst_camera_bin_video_profile_has_audio (camera);
1786 if (camera->audio_src) {
1787 if ((camera->user_audio_src && camera->user_audio_src != camera->audio_src)
1789 gst_bin_remove (GST_BIN_CAST (camera), camera->audio_src);
1790 gst_bin_remove (GST_BIN_CAST (camera), camera->audio_volume);
1791 gst_bin_remove (GST_BIN_CAST (camera), camera->audio_capsfilter);
1792 gst_object_unref (camera->audio_src);
1793 camera->audio_src = NULL;
1797 if (!camera->audio_src && has_audio) {
1798 if (camera->user_audio_src) {
1799 camera->audio_src = gst_object_ref (camera->user_audio_src);
1802 gst_element_factory_make (DEFAULT_AUDIO_SRC, "audiosrc");
1803 if (!camera->audio_src) {
1804 missing_element_name = DEFAULT_AUDIO_SRC;
1805 goto missing_element;
1809 gst_element_set_locked_state (camera->audio_src, TRUE);
1810 new_audio_src = TRUE;
1813 if (new_audio_src) {
1816 if (g_object_class_find_property (G_OBJECT_GET_CLASS (camera->audio_src),
1818 g_object_set (camera->audio_src, "provide-clock", FALSE, NULL);
1820 gst_bin_add (GST_BIN_CAST (camera), gst_object_ref (camera->audio_src));
1821 gst_bin_add (GST_BIN_CAST (camera), gst_object_ref (camera->audio_volume));
1822 gst_bin_add (GST_BIN_CAST (camera),
1823 gst_object_ref (camera->audio_capsfilter));
1825 gst_element_link_pads_full (camera->audio_src, "src",
1826 camera->audio_volume, "sink", GST_PAD_LINK_CHECK_CAPS);
1827 gst_element_link_pads_full (camera->audio_volume, "src",
1828 camera->audio_capsfilter, "sink", GST_PAD_LINK_CHECK_CAPS);
1830 srcpad = gst_element_get_static_pad (camera->audio_src, "src");
1832 /* drop EOS for audiosrc elements that push them on state_changes
1833 * (basesrc does this) */
1834 gst_pad_add_probe (srcpad, GST_PAD_PROBE_TYPE_DATA_DOWNSTREAM,
1835 gst_camera_bin_audio_src_data_probe, camera, NULL);
1837 gst_object_unref (srcpad);
1840 gst_camera_bin_check_and_replace_filter (camera, &camera->audio_filter,
1841 camera->user_audio_filter, camera->audio_src, camera->audio_volume,
1845 if ((profile_switched && has_audio) || new_audio_src) {
1846 if (GST_PAD_LINK_FAILED (gst_camera_bin_link_encodebin (camera,
1847 camera->video_encodebin, camera->audio_capsfilter,
1853 camera->elements_created = TRUE;
1857 gst_element_post_message (GST_ELEMENT_CAST (camera),
1858 gst_missing_element_message_new (GST_ELEMENT_CAST (camera),
1859 missing_element_name));
1860 GST_ELEMENT_ERROR (camera, CORE, MISSING_PLUGIN,
1861 (_("Missing element '%s' - check your GStreamer installation."),
1862 missing_element_name), (NULL));
1866 /* FIXME properly clean up */
1871 _gst_tag_list_unref_maybe (GstTagList * taglist)
1874 gst_tag_list_unref (taglist);
1877 static GstStateChangeReturn
1878 gst_camera_bin_change_state (GstElement * element, GstStateChange trans)
1880 GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
1881 GstCameraBin2 *camera = GST_CAMERA_BIN2_CAST (element);
1885 case GST_STATE_CHANGE_NULL_TO_READY:
1886 if (!gst_camera_bin_create_elements (camera)) {
1887 return GST_STATE_CHANGE_FAILURE;
1890 case GST_STATE_CHANGE_READY_TO_PAUSED:
1891 GST_CAMERA_BIN2_RESET_PROCESSING_COUNTER (camera);
1892 camera->audio_drop_eos = TRUE;
1893 camera->audio_send_newseg = FALSE;
1895 case GST_STATE_CHANGE_PAUSED_TO_READY:
1896 if (GST_STATE (camera->videosink) >= GST_STATE_PAUSED)
1897 gst_element_set_state (camera->videosink, GST_STATE_READY);
1898 if (GST_STATE (camera->imagesink) >= GST_STATE_PAUSED)
1899 gst_element_set_state (camera->imagesink, GST_STATE_READY);
1901 case GST_STATE_CHANGE_READY_TO_NULL:
1902 gst_element_set_state (camera->videosink, GST_STATE_NULL);
1903 gst_element_set_state (camera->imagesink, GST_STATE_NULL);
1909 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, trans);
1912 case GST_STATE_CHANGE_PAUSED_TO_READY:
1913 if (camera->audio_src && GST_STATE (camera->audio_src) >= GST_STATE_READY)
1914 gst_element_set_state (camera->audio_src, GST_STATE_READY);
1916 gst_tag_setter_reset_tags (GST_TAG_SETTER (camera));
1917 GST_CAMERA_BIN2_RESET_PROCESSING_COUNTER (camera);
1918 camera->video_state = GST_CAMERA_BIN_VIDEO_IDLE;
1920 g_mutex_lock (&camera->image_capture_mutex);
1921 g_slist_foreach (camera->image_location_list, (GFunc) g_free, NULL);
1922 g_slist_free (camera->image_location_list);
1923 camera->image_location_list = NULL;
1925 g_slist_foreach (camera->image_tags_list,
1926 (GFunc) _gst_tag_list_unref_maybe, NULL);
1927 g_slist_free (camera->image_tags_list);
1928 camera->image_tags_list = NULL;
1929 g_mutex_unlock (&camera->image_capture_mutex);
1931 g_mutex_lock (&camera->preview_list_mutex);
1932 g_slist_foreach (camera->preview_location_list, (GFunc) g_free, NULL);
1933 g_slist_free (camera->preview_location_list);
1934 camera->preview_location_list = NULL;
1935 g_mutex_unlock (&camera->preview_list_mutex);
1937 /* explicitly set to READY as they might be outside of the bin */
1938 gst_element_set_state (camera->audio_volume, GST_STATE_READY);
1939 gst_element_set_state (camera->audio_capsfilter, GST_STATE_READY);
1941 case GST_STATE_CHANGE_READY_TO_NULL:
1942 if (camera->audio_src)
1943 gst_element_set_state (camera->audio_src, GST_STATE_NULL);
1945 /* explicitly set to NULL as they might be outside of the bin */
1946 gst_element_set_state (camera->audio_volume, GST_STATE_NULL);
1947 gst_element_set_state (camera->audio_capsfilter, GST_STATE_NULL);
1958 gst_camera_bin_send_event (GstElement * element, GstEvent * event)
1960 GstCameraBin2 *camera = GST_CAMERA_BIN2_CAST (element);
1963 /* avoid losing our ref to send_event */
1964 gst_event_ref (event);
1966 res = GST_ELEMENT_CLASS (parent_class)->send_event (element, event);
1967 switch (GST_EVENT_TYPE (event)) {
1972 if (camera->videosink) {
1973 gst_element_get_state (camera->videosink, ¤t, NULL, 0);
1974 if (current <= GST_STATE_READY)
1975 gst_element_post_message (camera->videosink,
1976 gst_message_new_eos (GST_OBJECT (camera->videosink)));
1978 if (camera->imagesink) {
1979 gst_element_get_state (camera->imagesink, ¤t, NULL, 0);
1980 if (current <= GST_STATE_READY)
1981 gst_element_post_message (camera->imagesink,
1982 gst_message_new_eos (GST_OBJECT (camera->imagesink)));
1991 gst_event_unref (event);
1996 gst_camera_bin_set_location (GstCameraBin2 * camera, const gchar * location)
1998 GST_DEBUG_OBJECT (camera, "Setting mode %d location to %s", camera->mode,
2000 g_free (camera->location);
2001 camera->location = g_strdup (location);
2005 gst_camera_bin_set_audio_src (GstCameraBin2 * camera, GstElement * src)
2007 GST_DEBUG_OBJECT (GST_OBJECT (camera),
2008 "Setting audio source %" GST_PTR_FORMAT, src);
2010 if (camera->user_audio_src)
2011 g_object_unref (camera->user_audio_src);
2014 gst_object_ref (src);
2015 camera->user_audio_src = src;
2019 gst_camera_bin_set_camera_src (GstCameraBin2 * camera, GstElement * src)
2021 GST_DEBUG_OBJECT (GST_OBJECT (camera),
2022 "Setting camera source %" GST_PTR_FORMAT, src);
2024 if (camera->user_src)
2025 g_object_unref (camera->user_src);
2028 gst_object_ref (src);
2029 camera->user_src = src;
2033 gst_camera_bin_set_property (GObject * object, guint prop_id,
2034 const GValue * value, GParamSpec * pspec)
2036 GstCameraBin2 *camera = GST_CAMERA_BIN2_CAST (object);
2040 gst_camera_bin_change_mode (camera, g_value_get_enum (value));
2043 gst_camera_bin_set_location (camera, g_value_get_string (value));
2045 case PROP_CAMERA_SRC:
2046 gst_camera_bin_set_camera_src (camera, g_value_get_object (value));
2048 case PROP_AUDIO_SRC:
2049 gst_camera_bin_set_audio_src (camera, g_value_get_object (value));
2051 case PROP_MUTE_AUDIO:
2052 g_object_set (camera->audio_volume, "mute", g_value_get_boolean (value),
2055 case PROP_AUDIO_CAPTURE_CAPS:{
2056 GST_DEBUG_OBJECT (camera,
2057 "Setting audio capture caps to %" GST_PTR_FORMAT,
2058 gst_value_get_caps (value));
2060 if (G_LIKELY (camera->audio_capsfilter)) {
2061 g_object_set (camera->audio_capsfilter, "caps",
2062 gst_value_get_caps (value), NULL);
2064 GST_WARNING_OBJECT (camera, "Audio capsfilter missing");
2068 case PROP_IMAGE_CAPTURE_CAPS:{
2070 GST_DEBUG_OBJECT (camera,
2071 "Setting image capture caps to %" GST_PTR_FORMAT,
2072 gst_value_get_caps (value));
2074 if (G_LIKELY (camera->imagebin_capsfilter)) {
2075 g_object_set (camera->imagebin_capsfilter, "caps",
2076 gst_value_get_caps (value), NULL);
2078 GST_WARNING_OBJECT (camera, "Image capsfilter missing");
2082 case PROP_VIDEO_CAPTURE_CAPS:{
2083 GST_DEBUG_OBJECT (camera,
2084 "Setting video capture caps to %" GST_PTR_FORMAT,
2085 gst_value_get_caps (value));
2087 if (G_LIKELY (camera->videobin_capsfilter)) {
2088 g_object_set (camera->videobin_capsfilter, "caps",
2089 gst_value_get_caps (value), NULL);
2091 GST_WARNING_OBJECT (camera, "Video capsfilter missing");
2096 case PROP_VIEWFINDER_CAPS:{
2097 GST_DEBUG_OBJECT (camera,
2098 "Setting viewfinder capture caps to %" GST_PTR_FORMAT,
2099 gst_value_get_caps (value));
2101 if (G_LIKELY (camera->viewfinderbin_capsfilter)) {
2102 g_object_set (camera->viewfinderbin_capsfilter, "caps",
2103 gst_value_get_caps (value), NULL);
2105 GST_WARNING_OBJECT (camera, "Viewfinder capsfilter missing");
2109 case PROP_POST_PREVIEWS:
2110 camera->post_previews = g_value_get_boolean (value);
2112 && g_object_class_find_property (G_OBJECT_GET_CLASS (camera->src),
2114 g_object_set (camera->src, "post-previews", camera->post_previews,
2117 case PROP_PREVIEW_CAPS:
2118 gst_caps_replace (&camera->preview_caps,
2119 (GstCaps *) gst_value_get_caps (value));
2121 && g_object_class_find_property (G_OBJECT_GET_CLASS (camera->src),
2123 g_object_set (camera->src, "preview-caps", camera->preview_caps, NULL);
2125 case PROP_VIDEO_ENCODING_PROFILE:
2126 if (camera->video_profile)
2127 gst_encoding_profile_unref (camera->video_profile);
2128 camera->video_profile = (GstEncodingProfile *) g_value_dup_object (value);
2129 camera->video_profile_switch = TRUE;
2131 case PROP_IMAGE_FILTER:
2132 if (camera->user_image_filter)
2133 g_object_unref (camera->user_image_filter);
2135 camera->user_image_filter = g_value_dup_object (value);
2137 case PROP_VIDEO_FILTER:
2138 if (camera->user_video_filter)
2139 g_object_unref (camera->user_video_filter);
2141 camera->user_video_filter = g_value_dup_object (value);
2143 case PROP_VIEWFINDER_FILTER:
2144 if (camera->user_viewfinder_filter)
2145 g_object_unref (camera->user_viewfinder_filter);
2147 camera->user_viewfinder_filter = g_value_dup_object (value);
2149 case PROP_PREVIEW_FILTER:
2150 if (camera->preview_filter)
2151 g_object_unref (camera->preview_filter);
2153 camera->preview_filter = g_value_dup_object (value);
2155 && g_object_class_find_property (G_OBJECT_GET_CLASS (camera->src),
2157 g_object_set (camera->src, "preview-filter", camera->preview_filter,
2160 case PROP_AUDIO_FILTER:
2161 if (camera->user_audio_filter)
2162 g_object_unref (camera->user_audio_filter);
2164 camera->user_audio_filter = g_value_dup_object (value);
2166 case PROP_VIEWFINDER_SINK:
2167 g_object_set (camera->viewfinderbin, "video-sink",
2168 g_value_get_object (value), NULL);
2171 camera->zoom = g_value_get_float (value);
2172 /* limit to max-zoom */
2173 if (camera->zoom > camera->max_zoom) {
2174 GST_DEBUG_OBJECT (camera, "Clipping zoom %f to max-zoom %f",
2175 camera->zoom, camera->max_zoom);
2176 camera->zoom = camera->max_zoom;
2179 g_object_set (camera->src, "zoom", camera->zoom, NULL);
2181 case PROP_IMAGE_ENCODING_PROFILE:
2182 if (camera->image_profile)
2183 gst_encoding_profile_unref (camera->image_profile);
2184 camera->image_profile = (GstEncodingProfile *) g_value_dup_object (value);
2186 /* make sure we set variable framerate here to prevent videorate from
2187 * being used in encodebin. It will always keep a buffer stored
2188 * internally and push it when a second one arrives. This breaks
2189 * the image capture */
2190 if (GST_IS_ENCODING_VIDEO_PROFILE (camera->image_profile))
2191 gst_encoding_video_profile_set_variableframerate (
2192 (GstEncodingVideoProfile *) camera->image_profile, TRUE);
2193 else if (GST_IS_ENCODING_CONTAINER_PROFILE (camera->image_profile)) {
2194 const GList *profs =
2195 gst_encoding_container_profile_get_profiles (
2196 (GstEncodingContainerProfile *) camera->image_profile);
2197 for (; profs; profs = g_list_next (profs)) {
2198 if (GST_IS_ENCODING_VIDEO_PROFILE (profs->data)) {
2199 gst_encoding_video_profile_set_variableframerate (profs->data,
2204 camera->image_profile_switch = TRUE;
2207 camera->flags = g_value_get_flags (value);
2210 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2216 gst_camera_bin_get_property (GObject * object, guint prop_id,
2217 GValue * value, GParamSpec * pspec)
2219 GstCameraBin2 *camera = GST_CAMERA_BIN2_CAST (object);
2223 g_value_set_enum (value, camera->mode);
2226 g_value_set_string (value, camera->location);
2228 case PROP_CAMERA_SRC:
2229 g_value_set_object (value, camera->user_src);
2231 case PROP_AUDIO_SRC:
2232 g_value_set_object (value, camera->user_audio_src);
2234 case PROP_MUTE_AUDIO:{
2237 g_object_get (camera->audio_volume, "mute", &mute, NULL);
2238 g_value_set_boolean (value, mute);
2241 case PROP_AUDIO_CAPTURE_SUPPORTED_CAPS:
2242 case PROP_VIDEO_CAPTURE_SUPPORTED_CAPS:
2243 case PROP_VIEWFINDER_SUPPORTED_CAPS:
2244 case PROP_IMAGE_CAPTURE_SUPPORTED_CAPS:{
2246 GstElement *element;
2248 const gchar *padname;
2250 if (prop_id == PROP_VIDEO_CAPTURE_SUPPORTED_CAPS) {
2251 element = camera->src;
2252 padname = GST_BASE_CAMERA_SRC_VIDEO_PAD_NAME;
2253 } else if (prop_id == PROP_IMAGE_CAPTURE_SUPPORTED_CAPS) {
2254 element = camera->src;
2255 padname = GST_BASE_CAMERA_SRC_IMAGE_PAD_NAME;
2256 } else if (prop_id == PROP_VIEWFINDER_SUPPORTED_CAPS) {
2257 element = camera->src;
2258 padname = GST_BASE_CAMERA_SRC_VIEWFINDER_PAD_NAME;
2260 element = camera->audio_src;
2265 pad = gst_element_get_static_pad (element, padname);
2267 g_assert (pad != NULL);
2269 /* TODO not sure if we want get_caps or get_allowed_caps to already
2270 * consider the full pipeline scenario and avoid picking a caps that
2271 * won't negotiate. Need to take care on the special case of the
2272 * pad being unlinked.
2274 caps = gst_pad_query_caps (pad, NULL);
2276 gst_value_set_caps (value, caps);
2277 gst_caps_unref (caps);
2280 gst_object_unref (pad);
2282 GST_DEBUG_OBJECT (camera, "Source not created, can't get "
2287 case PROP_AUDIO_CAPTURE_CAPS:{
2288 GstCaps *caps = NULL;
2289 if (G_LIKELY (camera->audio_capsfilter)) {
2290 g_object_get (camera->audio_capsfilter, "caps", &caps, NULL);
2292 GST_WARNING ("Missing audio capsfilter");
2294 gst_value_set_caps (value, caps);
2295 gst_caps_unref (caps);
2298 case PROP_IMAGE_CAPTURE_CAPS:{
2299 GstCaps *caps = NULL;
2300 if (G_LIKELY (camera->imagebin_capsfilter)) {
2301 g_object_get (camera->imagebin_capsfilter, "caps", &caps, NULL);
2303 GST_WARNING ("Missing imagebin capsfilter");
2305 gst_value_set_caps (value, caps);
2306 gst_caps_unref (caps);
2309 case PROP_VIDEO_CAPTURE_CAPS:{
2310 GstCaps *caps = NULL;
2311 if (G_LIKELY (camera->videobin_capsfilter)) {
2312 g_object_get (camera->videobin_capsfilter, "caps", &caps, NULL);
2314 GST_WARNING ("Missing imagebin capsfilter");
2316 gst_value_set_caps (value, caps);
2317 gst_caps_unref (caps);
2320 case PROP_VIEWFINDER_CAPS:{
2321 GstCaps *caps = NULL;
2322 if (G_LIKELY (camera->viewfinderbin_capsfilter)) {
2323 g_object_get (camera->viewfinderbin_capsfilter, "caps", &caps, NULL);
2325 GST_WARNING ("Missing imagebin capsfilter");
2327 gst_value_set_caps (value, caps);
2328 gst_caps_unref (caps);
2331 case PROP_POST_PREVIEWS:
2332 g_value_set_boolean (value, camera->post_previews);
2334 case PROP_PREVIEW_CAPS:
2335 if (camera->preview_caps)
2336 gst_value_set_caps (value, camera->preview_caps);
2338 case PROP_VIDEO_ENCODING_PROFILE:
2339 if (camera->video_profile) {
2340 g_value_set_object (value, camera->video_profile);
2343 case PROP_VIDEO_FILTER:
2344 if (camera->user_video_filter)
2345 g_value_set_object (value, camera->user_video_filter);
2347 case PROP_IMAGE_FILTER:
2348 if (camera->user_image_filter)
2349 g_value_set_object (value, camera->user_image_filter);
2351 case PROP_VIEWFINDER_FILTER:
2352 if (camera->user_viewfinder_filter)
2353 g_value_set_object (value, camera->user_viewfinder_filter);
2355 case PROP_AUDIO_FILTER:
2356 if (camera->user_audio_filter)
2357 g_value_set_object (value, camera->user_audio_filter);
2359 case PROP_PREVIEW_FILTER:
2360 if (camera->preview_filter)
2361 g_value_set_object (value, camera->preview_filter);
2363 case PROP_VIEWFINDER_SINK:{
2366 g_object_get (camera->viewfinderbin, "video-sink", &sink, NULL);
2367 g_value_take_object (value, sink);
2371 g_value_set_float (value, camera->zoom);
2374 g_value_set_float (value, camera->max_zoom);
2376 case PROP_IMAGE_ENCODING_PROFILE:
2377 if (camera->image_profile) {
2378 g_value_set_object (value, camera->image_profile);
2382 g_value_set_boolean (value,
2383 g_atomic_int_get (&camera->processing_counter) == 0);
2386 g_value_set_flags (value, camera->flags);
2389 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2395 gst_camera_bin2_plugin_init (GstPlugin * plugin)
2397 GST_DEBUG_CATEGORY_INIT (gst_camera_bin_debug, "camerabin", 0, "CameraBin");
2399 return gst_element_register (plugin, "camerabin", GST_RANK_NONE,
2400 gst_camera_bin2_get_type ());