2010-11-26 13:14:46 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 2010 Thiago Santos <thiago.sousa.santos@collabora.co.uk>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
2012-11-03 20:38:00 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2010-11-26 13:14:46 +00:00
|
|
|
*/
|
|
|
|
/**
|
2016-07-08 13:42:18 +00:00
|
|
|
* SECTION:element-camerabin
|
2017-03-08 18:01:13 +00:00
|
|
|
* @title: camerabin
|
2010-11-26 13:14:46 +00:00
|
|
|
*
|
2016-07-08 13:42:18 +00:00
|
|
|
* CameraBin is a high-level camera object that encapsulates gstreamer
|
2011-08-05 18:48:53 +00:00
|
|
|
* elements, providing an API for controlling a digital camera.
|
2010-11-30 14:40:18 +00:00
|
|
|
*
|
2017-03-08 18:01:13 +00:00
|
|
|
* > Note that camerabin is still UNSTABLE and under development.
|
2011-07-07 22:55:59 +00:00
|
|
|
*
|
2016-07-08 13:42:18 +00:00
|
|
|
* CameraBin has the following main features:
|
2017-03-08 18:01:13 +00:00
|
|
|
*
|
|
|
|
* * Record videos
|
|
|
|
* * Capture pictures
|
|
|
|
* * Display a viewfinder
|
|
|
|
* * Post preview images for each capture (video and image)
|
|
|
|
*
|
|
|
|
* ## Usage
|
|
|
|
*
|
2016-07-08 13:42:18 +00:00
|
|
|
* Camerabin can be created using gst_element_factory_make() just like
|
2011-08-05 18:48:53 +00:00
|
|
|
* any other element. Video or image capture mode can be selected using
|
2012-04-30 16:56:16 +00:00
|
|
|
* the #GstCameraBin:mode property and the file to save the capture is
|
|
|
|
* selected using #GstCameraBin:location property.
|
2011-08-05 18:48:53 +00:00
|
|
|
*
|
2016-07-08 13:42:18 +00:00
|
|
|
* After creating camerabin, applications might want to do some
|
2011-08-05 18:48:53 +00:00
|
|
|
* customization (there's a section about this below), then select
|
|
|
|
* the desired mode and start capturing.
|
|
|
|
*
|
2019-05-25 14:57:57 +00:00
|
|
|
* In image capture mode, just send a #GstCameraBin::start-capture and a
|
2011-08-05 18:48:53 +00:00
|
|
|
* picture will be captured. When the picture is stored on the selected
|
|
|
|
* location, a %GST_MESSAGE_ELEMENT named 'image-done' will be posted on
|
|
|
|
* the #GstBus.
|
|
|
|
*
|
2019-05-25 14:57:57 +00:00
|
|
|
* In video capture mode, send a #GstCameraBin::start-capture to start
|
|
|
|
* recording, then send a #GstCameraBin::stop-capture to stop recording.
|
2011-08-05 18:48:53 +00:00
|
|
|
* Note that both signals are asynchronous, so, calling
|
2019-05-25 14:57:57 +00:00
|
|
|
* #GstCameraBin::stop-capture doesn't guarantee that the video has been
|
2011-08-06 15:13:22 +00:00
|
|
|
* properly finished yet. Applications should wait for the 'video-done'
|
|
|
|
* message to be posted on the bus.
|
2011-08-05 18:48:53 +00:00
|
|
|
*
|
2012-04-30 16:56:16 +00:00
|
|
|
* In both modes, if #GstCameraBin:post-previews is %TRUE, a #GstBuffer
|
2011-08-05 18:48:53 +00:00
|
|
|
* will be post to the #GstBus in a field named 'buffer', in a
|
|
|
|
* 'preview-image' message of type %GST_MESSAGE_ELEMENT.
|
2017-03-08 18:01:13 +00:00
|
|
|
*
|
2011-08-05 18:48:53 +00:00
|
|
|
|
2017-03-08 18:01:13 +00:00
|
|
|
*
|
|
|
|
* ## Customization
|
|
|
|
*
|
2016-07-08 13:42:18 +00:00
|
|
|
* Camerabin provides various customization properties, allowing the user
|
2011-08-05 18:48:53 +00:00
|
|
|
* to set custom filters, selecting the viewfinder sink and formats to
|
|
|
|
* use to encode the captured images/videos.
|
|
|
|
*
|
2016-07-08 13:42:18 +00:00
|
|
|
* #GstEncodingProfile<!-- -->s are used to tell camerabin which formats it
|
2011-08-05 18:48:53 +00:00
|
|
|
* should encode the captures to, those should be set to
|
2012-04-30 16:56:16 +00:00
|
|
|
* #GstCameraBin:image-profile and #GstCameraBin:video-profile. Default is
|
2011-08-05 18:48:53 +00:00
|
|
|
* jpeg for images, and ogg (theora and vorbis) for video. If a profile without
|
|
|
|
* an audio stream is set for video, audio will be disabled on recordings.
|
|
|
|
*
|
2012-04-30 16:56:16 +00:00
|
|
|
* #GstCameraBin:preview-caps can be used to select which format preview
|
2011-08-05 18:48:53 +00:00
|
|
|
* images should be posted on the #GstBus. It has to be a raw video format.
|
|
|
|
*
|
2016-07-08 13:42:18 +00:00
|
|
|
* Camerabin has a #GstCameraBin:camera-source property so applications can
|
2011-08-05 18:48:53 +00:00
|
|
|
* set their source that will provide buffers for the viewfinder and for
|
|
|
|
* captures. This camera source is a special type of source that has 3 pads.
|
|
|
|
* To use a 'regular' source with a single pad you should use
|
2019-05-25 14:57:57 +00:00
|
|
|
* #GstWrapperCameraBinSrc, it will adapt your source and provide 3 pads.
|
2011-08-05 18:48:53 +00:00
|
|
|
*
|
|
|
|
* Applications can also select the desired viewfinder sink using
|
2012-04-30 16:56:16 +00:00
|
|
|
* #GstCameraBin:viewfinder-sink, it is also possible to select the audio
|
|
|
|
* source using #GstCameraBin:audio-source.
|
2011-08-05 18:48:53 +00:00
|
|
|
*
|
|
|
|
* The viewfinder resolution can be configured using
|
2012-04-30 16:56:16 +00:00
|
|
|
* #GstCameraBin:viewfinder-caps, these #GstCaps should be a subset of
|
|
|
|
* #GstCameraBin:viewfinder-supported-caps.
|
2011-08-05 18:48:53 +00:00
|
|
|
*
|
2016-07-08 13:42:18 +00:00
|
|
|
* To select the desired resolution for captures, camerabin provides
|
2012-04-30 16:56:16 +00:00
|
|
|
* #GstCameraBin:image-capture-caps and #GstCameraBin:video-capture-caps,
|
2011-08-05 18:48:53 +00:00
|
|
|
* these caps must be a subset of what the source can produce. The allowed
|
2012-04-30 16:56:16 +00:00
|
|
|
* caps can be probed using #GstCameraBin:image-capture-supported-caps and
|
|
|
|
* #GstCameraBin:video-capture-supported-caps. In an analogous way, there
|
|
|
|
* are #GstCameraBin:audio-capture-caps and
|
|
|
|
* #GstCameraBin:audio-capture-supported-caps.
|
2011-08-05 18:48:53 +00:00
|
|
|
*
|
2012-04-30 16:56:16 +00:00
|
|
|
* Camerabin also allows applications to insert custom #GstElements on any
|
2011-08-05 18:48:53 +00:00
|
|
|
* of its branches: video capture, image capture, viewfinder and preview.
|
2012-04-30 16:56:16 +00:00
|
|
|
* Check #GstCameraBin:video-filter, #GstCameraBin:image-filter,
|
|
|
|
* #GstCameraBin:viewfinder-filter and #GstCameraBin:preview-filter.
|
2011-08-05 18:48:53 +00:00
|
|
|
*
|
2017-03-08 18:01:13 +00:00
|
|
|
* ## Example launch line
|
|
|
|
*
|
2016-07-08 13:42:18 +00:00
|
|
|
* Unfortunately, camerabin can't be really used from gst-launch-1.0, as you
|
|
|
|
* need to send signals to control it. The following pipeline might be able
|
2011-08-05 18:48:53 +00:00
|
|
|
* to show the viewfinder using all the default elements.
|
2011-07-07 22:55:59 +00:00
|
|
|
* |[
|
2015-12-14 02:09:46 +00:00
|
|
|
* gst-launch-1.0 -v -m camerabin
|
2011-07-07 22:55:59 +00:00
|
|
|
* ]|
|
2017-03-08 18:01:13 +00:00
|
|
|
*
|
2011-07-07 22:55:59 +00:00
|
|
|
|
2010-11-26 13:14:46 +00:00
|
|
|
*/
|
|
|
|
|
2010-11-30 21:19:20 +00:00
|
|
|
/*
|
|
|
|
* Detail Topics:
|
|
|
|
*
|
2010-12-27 14:29:42 +00:00
|
|
|
* videorecordingbin state management (for now on called 'videobin')
|
2010-12-13 14:53:59 +00:00
|
|
|
* - The problem: keeping videobin state in sync with camerabin will make it
|
2010-11-30 21:19:20 +00:00
|
|
|
* go to playing when it might not be used, causing its internal
|
|
|
|
* filesink to open a file that might be left blank.
|
2010-12-13 14:53:59 +00:00
|
|
|
* - The solution: videobin state is set to locked upon its creation and camerabin
|
2010-11-30 21:19:20 +00:00
|
|
|
* registers itself on the notify::ready-for-capture of the src.
|
|
|
|
* Whenever the src readyness goes to FALSE it means a new
|
2010-12-13 14:53:59 +00:00
|
|
|
* capture is starting. If we are on video mode, the videobin's
|
2010-11-30 21:19:20 +00:00
|
|
|
* state is set to NULL and then PLAYING (in between this we
|
|
|
|
* have room to set the destination filename).
|
|
|
|
* There is no problem to leave it on playing after an EOS, so
|
|
|
|
* no action is taken on stop-capture.
|
2011-01-26 18:27:19 +00:00
|
|
|
*
|
2010-11-30 21:19:20 +00:00
|
|
|
* - TODO: What happens when an error pops?
|
2011-01-26 18:27:19 +00:00
|
|
|
* - TODO: Should we split properties in image/video variants? We already do so
|
|
|
|
* for some of them
|
2010-11-30 21:19:20 +00:00
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2010-11-26 13:14:46 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2011-01-20 12:34:39 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2010-12-13 22:36:41 +00:00
|
|
|
#include <gst/basecamerabinsrc/gstbasecamerasrc.h>
|
2010-11-26 13:14:46 +00:00
|
|
|
#include "gstcamerabin2.h"
|
2022-03-25 13:59:23 +00:00
|
|
|
#include <glib/gi18n-lib.h>
|
2011-04-28 19:05:53 +00:00
|
|
|
#include <gst/pbutils/pbutils.h>
|
2012-01-27 14:49:58 +00:00
|
|
|
#include <gst/glib-compat-private.h>
|
2010-11-26 13:14:46 +00:00
|
|
|
|
2011-07-07 22:55:59 +00:00
|
|
|
#define GST_CAMERA_BIN2_PROCESSING_INC(c) \
|
2011-03-15 18:11:01 +00:00
|
|
|
{ \
|
2015-03-14 12:24:53 +00:00
|
|
|
gint bef = g_atomic_int_add (&c->processing_counter, 1); \
|
2011-03-15 18:11:01 +00:00
|
|
|
if (bef == 0) \
|
|
|
|
g_object_notify (G_OBJECT (c), "idle"); \
|
2011-08-05 16:34:08 +00:00
|
|
|
GST_DEBUG_OBJECT ((c), "Processing counter incremented to: %d", \
|
2011-03-15 18:11:01 +00:00
|
|
|
bef + 1); \
|
|
|
|
}
|
|
|
|
|
2011-07-07 22:55:59 +00:00
|
|
|
#define GST_CAMERA_BIN2_PROCESSING_DEC(c) \
|
2011-03-15 18:11:01 +00:00
|
|
|
{ \
|
2011-11-11 12:58:30 +00:00
|
|
|
if (g_atomic_int_dec_and_test (&c->processing_counter)) { \
|
2011-03-15 18:11:01 +00:00
|
|
|
g_object_notify (G_OBJECT (c), "idle"); \
|
2011-11-11 12:58:30 +00:00
|
|
|
GST_DEBUG_OBJECT ((c), "Camerabin now idle"); \
|
|
|
|
} \
|
2011-03-15 18:11:01 +00:00
|
|
|
GST_DEBUG_OBJECT ((c), "Processing counter decremented"); \
|
|
|
|
}
|
|
|
|
|
2011-07-07 22:55:59 +00:00
|
|
|
#define GST_CAMERA_BIN2_RESET_PROCESSING_COUNTER(c) \
|
2011-03-15 18:11:01 +00:00
|
|
|
{ \
|
|
|
|
g_atomic_int_set (&c->processing_counter, 0); \
|
|
|
|
GST_DEBUG_OBJECT ((c), "Processing counter reset"); \
|
|
|
|
}
|
|
|
|
|
2010-11-29 13:45:30 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (gst_camera_bin_debug);
|
|
|
|
#define GST_CAT_DEFAULT gst_camera_bin_debug
|
2010-11-26 13:14:46 +00:00
|
|
|
|
2010-11-29 13:45:30 +00:00
|
|
|
/* prototypes */
|
2010-11-26 13:14:46 +00:00
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
2010-11-26 20:24:58 +00:00
|
|
|
PROP_0,
|
2010-11-30 23:13:27 +00:00
|
|
|
PROP_MODE,
|
2010-12-13 02:03:21 +00:00
|
|
|
PROP_LOCATION,
|
2010-12-13 19:36:19 +00:00
|
|
|
PROP_CAMERA_SRC,
|
2010-12-13 02:03:21 +00:00
|
|
|
PROP_IMAGE_CAPTURE_SUPPORTED_CAPS,
|
2010-12-14 21:42:51 +00:00
|
|
|
PROP_VIDEO_CAPTURE_SUPPORTED_CAPS,
|
|
|
|
PROP_IMAGE_CAPTURE_CAPS,
|
2010-12-30 03:27:03 +00:00
|
|
|
PROP_VIDEO_CAPTURE_CAPS,
|
|
|
|
PROP_POST_PREVIEWS,
|
2011-01-11 12:12:24 +00:00
|
|
|
PROP_PREVIEW_CAPS,
|
2011-01-26 18:27:19 +00:00
|
|
|
PROP_VIDEO_ENCODING_PROFILE,
|
|
|
|
PROP_IMAGE_FILTER,
|
|
|
|
PROP_VIDEO_FILTER,
|
2011-01-27 17:39:19 +00:00
|
|
|
PROP_VIEWFINDER_FILTER,
|
2011-02-04 15:36:14 +00:00
|
|
|
PROP_PREVIEW_FILTER,
|
2011-02-24 21:28:28 +00:00
|
|
|
PROP_VIEWFINDER_SINK,
|
|
|
|
PROP_VIEWFINDER_SUPPORTED_CAPS,
|
2011-01-21 13:56:52 +00:00
|
|
|
PROP_VIEWFINDER_CAPS,
|
|
|
|
PROP_AUDIO_SRC,
|
|
|
|
PROP_MUTE_AUDIO,
|
|
|
|
PROP_AUDIO_CAPTURE_SUPPORTED_CAPS,
|
2011-03-08 08:43:58 +00:00
|
|
|
PROP_AUDIO_CAPTURE_CAPS,
|
2011-03-15 13:11:43 +00:00
|
|
|
PROP_ZOOM,
|
2011-03-18 14:49:12 +00:00
|
|
|
PROP_MAX_ZOOM,
|
2011-04-28 13:11:36 +00:00
|
|
|
PROP_IMAGE_ENCODING_PROFILE,
|
2011-06-30 09:09:44 +00:00
|
|
|
PROP_IDLE,
|
2011-08-11 21:59:07 +00:00
|
|
|
PROP_FLAGS,
|
|
|
|
PROP_AUDIO_FILTER
|
2010-11-26 13:14:46 +00:00
|
|
|
};
|
|
|
|
|
2010-11-26 20:24:58 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
/* action signals */
|
|
|
|
START_CAPTURE_SIGNAL,
|
|
|
|
STOP_CAPTURE_SIGNAL,
|
|
|
|
/* emit signals */
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
static guint camerabin_signals[LAST_SIGNAL];
|
|
|
|
|
|
|
|
#define DEFAULT_MODE MODE_IMAGE
|
2011-06-22 21:58:29 +00:00
|
|
|
#define DEFAULT_LOCATION "cap_%d"
|
2011-11-08 10:09:41 +00:00
|
|
|
#define DEFAULT_POST_PREVIEWS FALSE
|
2011-01-21 13:56:52 +00:00
|
|
|
#define DEFAULT_MUTE_AUDIO FALSE
|
2011-03-15 18:11:01 +00:00
|
|
|
#define DEFAULT_IDLE TRUE
|
2011-06-30 09:09:44 +00:00
|
|
|
#define DEFAULT_FLAGS 0
|
2010-11-26 20:24:58 +00:00
|
|
|
|
2011-01-20 12:34:39 +00:00
|
|
|
#define DEFAULT_AUDIO_SRC "autoaudiosrc"
|
|
|
|
|
2010-11-26 13:14:46 +00:00
|
|
|
/********************************
|
|
|
|
* Standard GObject boilerplate *
|
2010-11-26 20:24:58 +00:00
|
|
|
* and GObject types *
|
2010-11-26 13:14:46 +00:00
|
|
|
********************************/
|
|
|
|
|
|
|
|
static GstPipelineClass *parent_class;
|
2011-07-07 22:55:59 +00:00
|
|
|
static void gst_camera_bin_class_init (GstCameraBin2Class * klass);
|
2010-11-26 13:14:46 +00:00
|
|
|
static void gst_camera_bin_base_init (gpointer klass);
|
2011-07-07 22:55:59 +00:00
|
|
|
static void gst_camera_bin_init (GstCameraBin2 * camera);
|
2010-11-26 13:14:46 +00:00
|
|
|
static void gst_camera_bin_dispose (GObject * object);
|
|
|
|
static void gst_camera_bin_finalize (GObject * object);
|
|
|
|
|
2011-01-14 11:12:25 +00:00
|
|
|
static void gst_camera_bin_handle_message (GstBin * bin, GstMessage * message);
|
2011-05-12 11:17:28 +00:00
|
|
|
static gboolean gst_camera_bin_send_event (GstElement * element,
|
|
|
|
GstEvent * event);
|
2011-01-14 11:12:25 +00:00
|
|
|
|
2011-06-30 09:09:44 +00:00
|
|
|
#define C_FLAGS(v) ((guint) v)
|
|
|
|
#define GST_TYPE_CAM_FLAGS (gst_cam_flags_get_type())
|
|
|
|
static GType
|
|
|
|
gst_cam_flags_get_type (void)
|
|
|
|
{
|
|
|
|
static const GFlagsValue values[] = {
|
|
|
|
{C_FLAGS (GST_CAM_FLAG_NO_AUDIO_CONVERSION), "Do not use audio conversion "
|
2011-07-28 15:56:12 +00:00
|
|
|
"elements", "no-audio-conversion"},
|
2011-06-30 09:09:44 +00:00
|
|
|
{C_FLAGS (GST_CAM_FLAG_NO_VIDEO_CONVERSION), "Do not use video conversion "
|
2011-07-28 15:56:12 +00:00
|
|
|
"elements", "no-video-conversion"},
|
2011-08-23 14:58:33 +00:00
|
|
|
{C_FLAGS (GST_CAM_FLAG_NO_VIEWFINDER_CONVERSION),
|
|
|
|
"Do not use viewfinder conversion " "elements",
|
|
|
|
"no-viewfinder-conversion"},
|
2011-09-01 13:57:50 +00:00
|
|
|
{C_FLAGS (GST_CAM_FLAG_NO_IMAGE_CONVERSION), "Do not use image conversion "
|
|
|
|
"elements", "no-image-conversion"},
|
2011-06-30 09:09:44 +00:00
|
|
|
{0, NULL, NULL}
|
|
|
|
};
|
2021-03-22 03:34:36 +00:00
|
|
|
static GType id = 0;
|
2011-06-30 09:09:44 +00:00
|
|
|
|
|
|
|
if (g_once_init_enter ((gsize *) & id)) {
|
|
|
|
GType _id;
|
|
|
|
|
|
|
|
_id = g_flags_register_static ("GstCamFlags", values);
|
|
|
|
|
|
|
|
g_once_init_leave ((gsize *) & id, _id);
|
|
|
|
}
|
|
|
|
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
2010-11-26 13:14:46 +00:00
|
|
|
GType
|
2011-07-07 22:55:59 +00:00
|
|
|
gst_camera_bin2_get_type (void)
|
2010-11-26 13:14:46 +00:00
|
|
|
{
|
|
|
|
static GType gst_camera_bin_type = 0;
|
2011-01-11 17:50:48 +00:00
|
|
|
static const GInterfaceInfo camerabin_tagsetter_info = {
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
};
|
2010-11-26 13:14:46 +00:00
|
|
|
|
|
|
|
if (!gst_camera_bin_type) {
|
|
|
|
static const GTypeInfo gst_camera_bin_info = {
|
2011-07-07 22:55:59 +00:00
|
|
|
sizeof (GstCameraBin2Class),
|
2010-11-26 13:14:46 +00:00
|
|
|
(GBaseInitFunc) gst_camera_bin_base_init,
|
|
|
|
NULL,
|
|
|
|
(GClassInitFunc) gst_camera_bin_class_init,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
2011-07-07 22:55:59 +00:00
|
|
|
sizeof (GstCameraBin2),
|
2010-11-26 13:14:46 +00:00
|
|
|
0,
|
|
|
|
(GInstanceInitFunc) gst_camera_bin_init,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
gst_camera_bin_type =
|
2012-04-30 16:56:16 +00:00
|
|
|
g_type_register_static (GST_TYPE_PIPELINE, "GstCameraBin",
|
2010-11-26 13:14:46 +00:00
|
|
|
&gst_camera_bin_info, 0);
|
2011-01-11 17:50:48 +00:00
|
|
|
|
|
|
|
g_type_add_interface_static (gst_camera_bin_type, GST_TYPE_TAG_SETTER,
|
|
|
|
&camerabin_tagsetter_info);
|
2010-11-26 13:14:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return gst_camera_bin_type;
|
|
|
|
}
|
|
|
|
|
2021-02-25 14:22:15 +00:00
|
|
|
GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (camerabin, "camerabin", GST_RANK_NONE,
|
|
|
|
gst_camera_bin2_get_type (), GST_DEBUG_CATEGORY_INIT (gst_camera_bin_debug,
|
|
|
|
"camerabin", 0, "CameraBin");
|
|
|
|
);
|
|
|
|
|
2010-11-26 20:24:58 +00:00
|
|
|
/* GObject class functions */
|
2010-11-30 23:15:47 +00:00
|
|
|
static void gst_camera_bin_set_property (GObject * object, guint prop_id,
|
2010-11-26 20:24:58 +00:00
|
|
|
const GValue * value, GParamSpec * pspec);
|
2010-11-30 23:15:47 +00:00
|
|
|
static void gst_camera_bin_get_property (GObject * object, guint prop_id,
|
2010-11-26 20:24:58 +00:00
|
|
|
GValue * value, GParamSpec * pspec);
|
|
|
|
|
2010-11-26 13:14:46 +00:00
|
|
|
/* Element class functions */
|
|
|
|
static GstStateChangeReturn
|
|
|
|
gst_camera_bin_change_state (GstElement * element, GstStateChange trans);
|
|
|
|
|
2010-11-26 20:24:58 +00:00
|
|
|
|
|
|
|
/* Camerabin functions */
|
|
|
|
|
2011-06-22 19:27:00 +00:00
|
|
|
static GstEvent *
|
|
|
|
gst_camera_bin_new_event_file_location (const gchar * location)
|
|
|
|
{
|
|
|
|
return gst_event_new_custom (GST_EVENT_CUSTOM_DOWNSTREAM,
|
|
|
|
gst_structure_new ("new-location", "location", G_TYPE_STRING, location,
|
|
|
|
NULL));
|
|
|
|
}
|
|
|
|
|
2010-11-26 20:24:58 +00:00
|
|
|
static void
|
2011-07-07 22:55:59 +00:00
|
|
|
gst_camera_bin_start_capture (GstCameraBin2 * camerabin)
|
2010-11-26 20:24:58 +00:00
|
|
|
{
|
2011-01-11 17:50:48 +00:00
|
|
|
const GstTagList *taglist;
|
2011-09-29 21:03:25 +00:00
|
|
|
gint capture_index = camerabin->capture_index;
|
|
|
|
gchar *location = NULL;
|
2010-11-29 13:45:30 +00:00
|
|
|
GST_DEBUG_OBJECT (camerabin, "Received start-capture");
|
2011-05-20 18:25:08 +00:00
|
|
|
|
|
|
|
/* check that we have a valid location */
|
2011-11-10 19:11:56 +00:00
|
|
|
if (camerabin->mode == MODE_VIDEO) {
|
|
|
|
if (camerabin->location == NULL) {
|
|
|
|
GST_ELEMENT_ERROR (camerabin, RESOURCE, OPEN_WRITE,
|
|
|
|
(_("File location is set to NULL, please set it to a valid filename")), (NULL));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-01-19 10:34:26 +00:00
|
|
|
g_mutex_lock (&camerabin->video_capture_mutex);
|
2011-11-10 19:53:40 +00:00
|
|
|
while (camerabin->video_state == GST_CAMERA_BIN_VIDEO_FINISHING) {
|
2012-01-19 10:34:26 +00:00
|
|
|
g_cond_wait (&camerabin->video_state_cond,
|
|
|
|
&camerabin->video_capture_mutex);
|
2011-11-10 19:53:40 +00:00
|
|
|
}
|
2011-11-10 19:11:56 +00:00
|
|
|
if (camerabin->video_state != GST_CAMERA_BIN_VIDEO_IDLE) {
|
|
|
|
GST_WARNING_OBJECT (camerabin, "Another video recording is ongoing"
|
|
|
|
" (state %d), cannot start a new one", camerabin->video_state);
|
2012-01-19 10:34:26 +00:00
|
|
|
g_mutex_unlock (&camerabin->video_capture_mutex);
|
2011-11-10 19:11:56 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
camerabin->video_state = GST_CAMERA_BIN_VIDEO_STARTING;
|
2011-05-20 18:25:08 +00:00
|
|
|
}
|
|
|
|
|
2011-07-07 22:55:59 +00:00
|
|
|
GST_CAMERA_BIN2_PROCESSING_INC (camerabin);
|
2011-01-11 17:50:48 +00:00
|
|
|
|
2011-09-29 21:03:25 +00:00
|
|
|
if (camerabin->location)
|
|
|
|
location = g_strdup_printf (camerabin->location, capture_index);
|
|
|
|
|
2012-08-30 01:05:56 +00:00
|
|
|
if (camerabin->mode == MODE_IMAGE) {
|
2011-06-22 19:27:00 +00:00
|
|
|
/* store the next capture buffer filename */
|
2012-01-19 10:34:26 +00:00
|
|
|
g_mutex_lock (&camerabin->image_capture_mutex);
|
2011-06-22 19:27:00 +00:00
|
|
|
camerabin->image_location_list =
|
2011-09-29 21:03:25 +00:00
|
|
|
g_slist_append (camerabin->image_location_list, g_strdup (location));
|
2012-01-19 10:34:26 +00:00
|
|
|
g_mutex_unlock (&camerabin->image_capture_mutex);
|
2011-04-26 17:53:35 +00:00
|
|
|
}
|
|
|
|
|
2011-11-09 14:17:15 +00:00
|
|
|
if (camerabin->post_previews) {
|
|
|
|
/* Count processing of preview images too */
|
|
|
|
GST_CAMERA_BIN2_PROCESSING_INC (camerabin);
|
|
|
|
/* store the next preview filename */
|
2012-01-19 10:34:26 +00:00
|
|
|
g_mutex_lock (&camerabin->preview_list_mutex);
|
2011-11-09 14:17:15 +00:00
|
|
|
camerabin->preview_location_list =
|
|
|
|
g_slist_append (camerabin->preview_location_list, location);
|
2012-01-19 10:34:26 +00:00
|
|
|
g_mutex_unlock (&camerabin->preview_list_mutex);
|
2011-11-09 14:17:15 +00:00
|
|
|
} else {
|
|
|
|
g_free (location);
|
|
|
|
}
|
2011-09-29 21:03:25 +00:00
|
|
|
|
2011-04-26 17:53:35 +00:00
|
|
|
g_signal_emit_by_name (camerabin->src, "start-capture", NULL);
|
2011-11-10 19:11:56 +00:00
|
|
|
if (camerabin->mode == MODE_VIDEO) {
|
2011-12-19 19:49:08 +00:00
|
|
|
camerabin->audio_send_newseg = TRUE;
|
2011-11-10 19:11:56 +00:00
|
|
|
if (camerabin->audio_src)
|
|
|
|
gst_element_set_state (camerabin->audio_src, GST_STATE_PLAYING);
|
|
|
|
|
|
|
|
camerabin->video_state = GST_CAMERA_BIN_VIDEO_RECORDING;
|
2012-01-19 10:34:26 +00:00
|
|
|
g_mutex_unlock (&camerabin->video_capture_mutex);
|
2011-11-10 19:11:56 +00:00
|
|
|
}
|
2011-04-26 17:53:35 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We have to push tags after start capture because the video elements
|
|
|
|
* might be flushing from the previous capture and are reset only on the
|
|
|
|
* notify from ready for capture going to FALSE
|
|
|
|
*/
|
2011-01-11 17:50:48 +00:00
|
|
|
taglist = gst_tag_setter_get_tag_list (GST_TAG_SETTER (camerabin));
|
2011-11-09 14:45:27 +00:00
|
|
|
GST_DEBUG_OBJECT (camerabin, "Have tags from application: %"
|
|
|
|
GST_PTR_FORMAT, taglist);
|
|
|
|
|
|
|
|
if (camerabin->mode == MODE_IMAGE) {
|
|
|
|
/* Store image tags in a list and push them later, this prevents
|
|
|
|
start_capture() from blocking in pad_push_event call */
|
2012-01-19 10:34:26 +00:00
|
|
|
g_mutex_lock (&camerabin->image_capture_mutex);
|
2011-11-09 14:45:27 +00:00
|
|
|
camerabin->image_tags_list =
|
|
|
|
g_slist_append (camerabin->image_tags_list,
|
|
|
|
taglist ? gst_tag_list_copy (taglist) : NULL);
|
2012-01-19 10:34:26 +00:00
|
|
|
g_mutex_unlock (&camerabin->image_capture_mutex);
|
2011-11-09 14:45:27 +00:00
|
|
|
} else if (taglist) {
|
2011-01-11 17:50:48 +00:00
|
|
|
GstPad *active_pad;
|
|
|
|
|
2011-11-09 14:45:27 +00:00
|
|
|
active_pad = gst_element_get_static_pad (camerabin->src,
|
|
|
|
GST_BASE_CAMERA_SRC_VIDEO_PAD_NAME);
|
|
|
|
gst_pad_push_event (active_pad,
|
2012-07-28 23:04:35 +00:00
|
|
|
gst_event_new_tag (gst_tag_list_copy (taglist)));
|
2011-01-11 17:50:48 +00:00
|
|
|
|
2011-11-09 14:45:27 +00:00
|
|
|
gst_object_unref (active_pad);
|
2011-01-11 17:50:48 +00:00
|
|
|
}
|
2011-11-09 14:45:27 +00:00
|
|
|
|
2011-11-09 12:41:44 +00:00
|
|
|
GST_DEBUG_OBJECT (camerabin, "Start-capture end");
|
2010-11-26 20:24:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-07-07 22:55:59 +00:00
|
|
|
gst_camera_bin_stop_capture (GstCameraBin2 * camerabin)
|
2010-11-26 20:24:58 +00:00
|
|
|
{
|
2011-02-28 18:43:46 +00:00
|
|
|
GST_DEBUG_OBJECT (camerabin, "Received stop-capture");
|
2011-11-10 19:11:56 +00:00
|
|
|
if (camerabin->mode == MODE_VIDEO) {
|
2012-01-19 10:34:26 +00:00
|
|
|
g_mutex_lock (&camerabin->video_capture_mutex);
|
2011-11-10 19:11:56 +00:00
|
|
|
if (camerabin->video_state == GST_CAMERA_BIN_VIDEO_RECORDING) {
|
|
|
|
if (camerabin->src)
|
|
|
|
g_signal_emit_by_name (camerabin->src, "stop-capture", NULL);
|
|
|
|
|
|
|
|
camerabin->video_state = GST_CAMERA_BIN_VIDEO_FINISHING;
|
|
|
|
if (camerabin->audio_src) {
|
|
|
|
camerabin->audio_drop_eos = FALSE;
|
|
|
|
gst_element_send_event (camerabin->audio_src, gst_event_new_eos ());
|
|
|
|
}
|
|
|
|
}
|
2012-01-19 10:34:26 +00:00
|
|
|
g_mutex_unlock (&camerabin->video_capture_mutex);
|
2011-03-09 17:53:26 +00:00
|
|
|
}
|
2010-11-26 20:24:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-07-07 22:55:59 +00:00
|
|
|
gst_camera_bin_change_mode (GstCameraBin2 * camerabin, gint mode)
|
2010-11-26 20:24:58 +00:00
|
|
|
{
|
2010-11-30 12:28:50 +00:00
|
|
|
if (mode == camerabin->mode)
|
|
|
|
return;
|
|
|
|
|
2010-12-03 15:12:32 +00:00
|
|
|
GST_DEBUG_OBJECT (camerabin, "Changing mode to %d", mode);
|
|
|
|
|
2010-11-26 20:24:58 +00:00
|
|
|
/* stop any ongoing capture */
|
|
|
|
gst_camera_bin_stop_capture (camerabin);
|
|
|
|
camerabin->mode = mode;
|
2010-12-02 06:44:37 +00:00
|
|
|
if (camerabin->src)
|
|
|
|
g_object_set (camerabin->src, "mode", mode, NULL);
|
2010-11-26 20:24:58 +00:00
|
|
|
}
|
|
|
|
|
2010-11-30 21:19:20 +00:00
|
|
|
static void
|
|
|
|
gst_camera_bin_src_notify_readyforcapture (GObject * obj, GParamSpec * pspec,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
2011-07-07 22:55:59 +00:00
|
|
|
GstCameraBin2 *camera = GST_CAMERA_BIN2_CAST (user_data);
|
2010-11-30 21:19:20 +00:00
|
|
|
gboolean ready;
|
|
|
|
|
2011-04-28 13:11:36 +00:00
|
|
|
g_object_get (camera->src, "ready-for-capture", &ready, NULL);
|
|
|
|
if (!ready) {
|
|
|
|
gchar *location = NULL;
|
2010-11-30 23:13:27 +00:00
|
|
|
|
2011-04-28 13:11:36 +00:00
|
|
|
if (camera->mode == MODE_VIDEO) {
|
2011-11-10 19:53:40 +00:00
|
|
|
/* a video recording is about to start, change the filesink location */
|
2010-12-27 14:29:42 +00:00
|
|
|
gst_element_set_state (camera->videosink, GST_STATE_NULL);
|
2011-09-29 21:03:25 +00:00
|
|
|
location = g_strdup_printf (camera->location, camera->capture_index);
|
2010-12-13 14:53:59 +00:00
|
|
|
GST_DEBUG_OBJECT (camera, "Switching videobin location to %s", location);
|
2010-12-27 14:29:42 +00:00
|
|
|
g_object_set (camera->videosink, "location", location, NULL);
|
2010-11-30 23:13:27 +00:00
|
|
|
g_free (location);
|
2011-09-15 20:35:44 +00:00
|
|
|
if (gst_element_set_state (camera->videosink, GST_STATE_PLAYING) ==
|
|
|
|
GST_STATE_CHANGE_FAILURE) {
|
|
|
|
/* Resets the latest state change return, that would be a failure
|
|
|
|
* and could cause problems in a camerabin2 state change */
|
|
|
|
gst_element_set_state (camera->videosink, GST_STATE_NULL);
|
|
|
|
}
|
2010-11-30 21:19:20 +00:00
|
|
|
}
|
2011-09-29 21:03:25 +00:00
|
|
|
|
|
|
|
camera->capture_index++;
|
2010-11-30 21:19:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-26 13:14:46 +00:00
|
|
|
static void
|
|
|
|
gst_camera_bin_dispose (GObject * object)
|
|
|
|
{
|
2011-07-07 22:55:59 +00:00
|
|
|
GstCameraBin2 *camerabin = GST_CAMERA_BIN2_CAST (object);
|
2010-11-26 20:24:58 +00:00
|
|
|
|
2011-06-22 21:58:29 +00:00
|
|
|
g_free (camerabin->location);
|
2012-01-19 10:34:26 +00:00
|
|
|
g_mutex_clear (&camerabin->preview_list_mutex);
|
|
|
|
g_mutex_clear (&camerabin->image_capture_mutex);
|
|
|
|
g_mutex_clear (&camerabin->video_capture_mutex);
|
|
|
|
g_cond_clear (&camerabin->video_state_cond);
|
2010-11-30 23:13:27 +00:00
|
|
|
|
2010-11-30 21:19:20 +00:00
|
|
|
if (camerabin->src_capture_notify_id)
|
|
|
|
g_signal_handler_disconnect (camerabin->src,
|
|
|
|
camerabin->src_capture_notify_id);
|
2010-11-29 21:53:34 +00:00
|
|
|
if (camerabin->src)
|
|
|
|
gst_object_unref (camerabin->src);
|
2010-12-13 19:36:19 +00:00
|
|
|
if (camerabin->user_src)
|
|
|
|
gst_object_unref (camerabin->user_src);
|
2010-11-26 20:24:58 +00:00
|
|
|
|
2011-01-20 12:34:39 +00:00
|
|
|
if (camerabin->audio_src)
|
|
|
|
gst_object_unref (camerabin->audio_src);
|
|
|
|
if (camerabin->user_audio_src)
|
|
|
|
gst_object_unref (camerabin->user_audio_src);
|
|
|
|
|
|
|
|
if (camerabin->audio_capsfilter)
|
|
|
|
gst_object_unref (camerabin->audio_capsfilter);
|
2011-03-11 13:32:35 +00:00
|
|
|
if (camerabin->audio_volume)
|
|
|
|
gst_object_unref (camerabin->audio_volume);
|
2011-01-20 12:34:39 +00:00
|
|
|
|
2010-12-13 14:53:59 +00:00
|
|
|
if (camerabin->viewfinderbin)
|
|
|
|
gst_object_unref (camerabin->viewfinderbin);
|
|
|
|
if (camerabin->viewfinderbin_queue)
|
|
|
|
gst_object_unref (camerabin->viewfinderbin_queue);
|
|
|
|
if (camerabin->viewfinderbin_capsfilter)
|
|
|
|
gst_object_unref (camerabin->viewfinderbin_capsfilter);
|
2010-11-30 21:19:20 +00:00
|
|
|
|
2011-04-28 13:11:36 +00:00
|
|
|
if (camerabin->video_encodebin_signal_id)
|
|
|
|
g_signal_handler_disconnect (camerabin->video_encodebin,
|
|
|
|
camerabin->video_encodebin_signal_id);
|
2011-03-04 09:09:43 +00:00
|
|
|
|
2010-12-27 14:29:42 +00:00
|
|
|
if (camerabin->videosink)
|
|
|
|
gst_object_unref (camerabin->videosink);
|
2011-04-28 13:11:36 +00:00
|
|
|
if (camerabin->video_encodebin)
|
|
|
|
gst_object_unref (camerabin->video_encodebin);
|
2010-12-13 14:53:59 +00:00
|
|
|
if (camerabin->videobin_capsfilter)
|
|
|
|
gst_object_unref (camerabin->videobin_capsfilter);
|
|
|
|
|
2011-04-28 13:11:36 +00:00
|
|
|
if (camerabin->image_encodebin_signal_id)
|
|
|
|
g_signal_handler_disconnect (camerabin->image_encodebin,
|
|
|
|
camerabin->image_encodebin_signal_id);
|
|
|
|
if (camerabin->imagesink)
|
|
|
|
gst_object_unref (camerabin->imagesink);
|
|
|
|
if (camerabin->image_encodebin)
|
|
|
|
gst_object_unref (camerabin->image_encodebin);
|
2010-12-13 14:53:59 +00:00
|
|
|
if (camerabin->imagebin_capsfilter)
|
|
|
|
gst_object_unref (camerabin->imagebin_capsfilter);
|
2010-11-30 23:13:27 +00:00
|
|
|
|
2011-01-26 18:27:19 +00:00
|
|
|
if (camerabin->video_filter)
|
|
|
|
gst_object_unref (camerabin->video_filter);
|
|
|
|
if (camerabin->image_filter)
|
|
|
|
gst_object_unref (camerabin->image_filter);
|
|
|
|
if (camerabin->viewfinder_filter)
|
|
|
|
gst_object_unref (camerabin->viewfinder_filter);
|
2011-08-11 21:59:07 +00:00
|
|
|
if (camerabin->audio_filter)
|
|
|
|
gst_object_unref (camerabin->audio_filter);
|
2011-01-26 18:27:19 +00:00
|
|
|
|
|
|
|
if (camerabin->user_video_filter)
|
|
|
|
gst_object_unref (camerabin->user_video_filter);
|
2011-08-11 21:59:07 +00:00
|
|
|
if (camerabin->user_audio_filter)
|
|
|
|
gst_object_unref (camerabin->user_audio_filter);
|
2011-01-26 18:27:19 +00:00
|
|
|
if (camerabin->user_image_filter)
|
|
|
|
gst_object_unref (camerabin->user_image_filter);
|
|
|
|
if (camerabin->user_viewfinder_filter)
|
|
|
|
gst_object_unref (camerabin->user_viewfinder_filter);
|
|
|
|
|
2011-01-26 14:40:43 +00:00
|
|
|
if (camerabin->video_profile)
|
|
|
|
gst_encoding_profile_unref (camerabin->video_profile);
|
2011-04-28 13:11:36 +00:00
|
|
|
if (camerabin->image_profile)
|
|
|
|
gst_encoding_profile_unref (camerabin->image_profile);
|
2011-01-26 14:40:43 +00:00
|
|
|
|
|
|
|
if (camerabin->preview_caps)
|
|
|
|
gst_caps_replace (&camerabin->preview_caps, NULL);
|
2011-01-27 17:39:19 +00:00
|
|
|
if (camerabin->preview_filter) {
|
|
|
|
gst_object_unref (camerabin->preview_filter);
|
|
|
|
camerabin->preview_filter = NULL;
|
|
|
|
}
|
2011-01-26 14:40:43 +00:00
|
|
|
|
2010-11-26 13:14:46 +00:00
|
|
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_camera_bin_finalize (GObject * object)
|
|
|
|
{
|
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_camera_bin_base_init (gpointer g_class)
|
|
|
|
{
|
|
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
|
|
|
|
|
2012-10-17 16:34:26 +00:00
|
|
|
gst_element_class_set_static_metadata (element_class, "Camera Bin",
|
2012-04-30 16:56:16 +00:00
|
|
|
"Generic/Bin/Camera",
|
|
|
|
"Take image snapshots and record movies from camera",
|
2010-11-26 13:14:46 +00:00
|
|
|
"Thiago Santos <thiago.sousa.santos@collabora.co.uk>");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-07-07 22:55:59 +00:00
|
|
|
gst_camera_bin_class_init (GstCameraBin2Class * klass)
|
2010-11-26 13:14:46 +00:00
|
|
|
{
|
|
|
|
GObjectClass *object_class;
|
|
|
|
GstElementClass *element_class;
|
2011-01-14 11:12:25 +00:00
|
|
|
GstBinClass *bin_class;
|
2010-11-26 13:14:46 +00:00
|
|
|
|
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
|
|
|
object_class = G_OBJECT_CLASS (klass);
|
|
|
|
element_class = GST_ELEMENT_CLASS (klass);
|
2011-01-14 11:12:25 +00:00
|
|
|
bin_class = GST_BIN_CLASS (klass);
|
2010-11-26 13:14:46 +00:00
|
|
|
|
|
|
|
object_class->dispose = gst_camera_bin_dispose;
|
|
|
|
object_class->finalize = gst_camera_bin_finalize;
|
2010-11-30 23:15:47 +00:00
|
|
|
object_class->set_property = gst_camera_bin_set_property;
|
|
|
|
object_class->get_property = gst_camera_bin_get_property;
|
2010-11-26 13:14:46 +00:00
|
|
|
|
|
|
|
element_class->change_state = GST_DEBUG_FUNCPTR (gst_camera_bin_change_state);
|
2011-05-12 11:17:28 +00:00
|
|
|
element_class->send_event = GST_DEBUG_FUNCPTR (gst_camera_bin_send_event);
|
2010-11-26 20:24:58 +00:00
|
|
|
|
2011-01-14 11:12:25 +00:00
|
|
|
bin_class->handle_message = gst_camera_bin_handle_message;
|
|
|
|
|
2010-11-26 20:24:58 +00:00
|
|
|
klass->start_capture = gst_camera_bin_start_capture;
|
|
|
|
klass->stop_capture = gst_camera_bin_stop_capture;
|
|
|
|
|
|
|
|
/**
|
2011-07-07 22:55:59 +00:00
|
|
|
* GstCameraBin2:mode:
|
2010-11-26 20:24:58 +00:00
|
|
|
*
|
|
|
|
* Set the mode of operation: still image capturing or video recording.
|
|
|
|
*/
|
|
|
|
g_object_class_install_property (object_class, PROP_MODE,
|
|
|
|
g_param_spec_enum ("mode", "Mode",
|
|
|
|
"The capture mode (still image capture or video recording)",
|
|
|
|
GST_TYPE_CAMERABIN_MODE, DEFAULT_MODE,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2010-11-30 23:13:27 +00:00
|
|
|
g_object_class_install_property (object_class, PROP_LOCATION,
|
|
|
|
g_param_spec_string ("location", "Location",
|
|
|
|
"Location to save the captured files. A %d might be used on the"
|
|
|
|
"filename as a placeholder for a numeric index of the capture."
|
2011-06-22 21:58:29 +00:00
|
|
|
"Default is cap_%d",
|
|
|
|
DEFAULT_LOCATION, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2010-11-30 23:13:27 +00:00
|
|
|
|
2010-12-13 19:36:19 +00:00
|
|
|
g_object_class_install_property (object_class, PROP_CAMERA_SRC,
|
2011-05-26 02:29:25 +00:00
|
|
|
g_param_spec_object ("camera-source", "Camera source",
|
2011-05-11 21:35:40 +00:00
|
|
|
"The camera source element to be used. It is only taken into use on"
|
|
|
|
" the next null to ready transition",
|
2010-12-13 19:36:19 +00:00
|
|
|
GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2011-01-21 13:56:52 +00:00
|
|
|
g_object_class_install_property (object_class, PROP_AUDIO_SRC,
|
2011-05-26 02:29:25 +00:00
|
|
|
g_param_spec_object ("audio-source", "Audio source",
|
2011-05-11 21:35:40 +00:00
|
|
|
"The audio source element to be used on video recordings. It is only"
|
|
|
|
" taken into use on the next null to ready transition",
|
2011-01-21 13:56:52 +00:00
|
|
|
GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
|
|
|
g_object_class_install_property (object_class, PROP_MUTE_AUDIO,
|
|
|
|
g_param_spec_boolean ("mute", "Mute",
|
|
|
|
"If the audio recording should be muted. Note that this still "
|
|
|
|
"saves audio data to the resulting file, but they are silent. Use "
|
|
|
|
"a video-profile without audio to disable audio completely",
|
|
|
|
DEFAULT_MUTE_AUDIO, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
PROP_AUDIO_CAPTURE_SUPPORTED_CAPS,
|
|
|
|
g_param_spec_boxed ("audio-capture-supported-caps",
|
|
|
|
"Audio capture supported caps",
|
|
|
|
"Formats supported for capturing audio represented as GstCaps",
|
|
|
|
GST_TYPE_CAPS, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
PROP_AUDIO_CAPTURE_CAPS,
|
|
|
|
g_param_spec_boxed ("audio-capture-caps",
|
|
|
|
"Audio capture caps",
|
|
|
|
"Format to capture audio for video recording represented as GstCaps",
|
|
|
|
GST_TYPE_CAPS, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2010-12-13 02:03:21 +00:00
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
PROP_IMAGE_CAPTURE_SUPPORTED_CAPS,
|
|
|
|
g_param_spec_boxed ("image-capture-supported-caps",
|
|
|
|
"Image capture supported caps",
|
|
|
|
"Formats supported for capturing images represented as GstCaps",
|
|
|
|
GST_TYPE_CAPS, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
PROP_VIDEO_CAPTURE_SUPPORTED_CAPS,
|
|
|
|
g_param_spec_boxed ("video-capture-supported-caps",
|
|
|
|
"Video capture supported caps",
|
|
|
|
"Formats supported for capturing videos represented as GstCaps",
|
|
|
|
GST_TYPE_CAPS, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2010-12-14 21:42:51 +00:00
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
PROP_IMAGE_CAPTURE_CAPS,
|
|
|
|
g_param_spec_boxed ("image-capture-caps",
|
|
|
|
"Image capture caps",
|
|
|
|
"Caps for image capture",
|
|
|
|
GST_TYPE_CAPS, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
PROP_VIDEO_CAPTURE_CAPS,
|
|
|
|
g_param_spec_boxed ("video-capture-caps",
|
|
|
|
"Video capture caps",
|
|
|
|
"Caps for video capture",
|
|
|
|
GST_TYPE_CAPS, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2010-12-30 03:27:03 +00:00
|
|
|
g_object_class_install_property (object_class, PROP_POST_PREVIEWS,
|
|
|
|
g_param_spec_boolean ("post-previews", "Post Previews",
|
|
|
|
"If capture preview images should be posted to the bus",
|
|
|
|
DEFAULT_POST_PREVIEWS, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
|
|
|
g_object_class_install_property (object_class, PROP_PREVIEW_CAPS,
|
|
|
|
g_param_spec_boxed ("preview-caps", "Preview caps",
|
|
|
|
"The caps of the preview image to be posted",
|
|
|
|
GST_TYPE_CAPS, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2010-12-13 02:03:21 +00:00
|
|
|
|
2011-01-11 12:12:24 +00:00
|
|
|
g_object_class_install_property (object_class, PROP_VIDEO_ENCODING_PROFILE,
|
2012-01-02 14:55:21 +00:00
|
|
|
g_param_spec_object ("video-profile", "Video Profile",
|
2011-01-21 13:56:52 +00:00
|
|
|
"The GstEncodingProfile to use for video recording. Audio is enabled "
|
|
|
|
"when this profile supports audio.", GST_TYPE_ENCODING_PROFILE,
|
2011-01-11 12:12:24 +00:00
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2011-01-26 18:27:19 +00:00
|
|
|
g_object_class_install_property (object_class, PROP_IMAGE_FILTER,
|
|
|
|
g_param_spec_object ("image-filter", "Image filter",
|
|
|
|
"The element that will process captured image frames. (Should be"
|
|
|
|
" set on NULL state)",
|
|
|
|
GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
|
|
|
g_object_class_install_property (object_class, PROP_VIDEO_FILTER,
|
|
|
|
g_param_spec_object ("video-filter", "Video filter",
|
|
|
|
"The element that will process captured video frames. (Should be"
|
|
|
|
" set on NULL state)",
|
|
|
|
GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
|
|
|
g_object_class_install_property (object_class, PROP_VIEWFINDER_FILTER,
|
|
|
|
g_param_spec_object ("viewfinder-filter", "Viewfinder filter",
|
|
|
|
"The element that will process frames going to the viewfinder."
|
|
|
|
" (Should be set on NULL state)",
|
|
|
|
GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2011-08-11 21:59:07 +00:00
|
|
|
g_object_class_install_property (object_class, PROP_AUDIO_FILTER,
|
|
|
|
g_param_spec_object ("audio-filter", "Audio filter",
|
|
|
|
"The element that will process captured audio buffers when recording"
|
|
|
|
". (Should be set on NULL state)",
|
|
|
|
GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2011-01-27 17:39:19 +00:00
|
|
|
g_object_class_install_property (object_class, PROP_PREVIEW_FILTER,
|
|
|
|
g_param_spec_object ("preview-filter", "Preview filter",
|
|
|
|
"The element that will process preview buffers."
|
|
|
|
" (Should be set on NULL state)",
|
|
|
|
GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2011-02-04 15:36:14 +00:00
|
|
|
g_object_class_install_property (object_class, PROP_VIEWFINDER_SINK,
|
|
|
|
g_param_spec_object ("viewfinder-sink", "Viewfinder sink",
|
2011-05-11 21:35:40 +00:00
|
|
|
"The video sink of the viewfinder. It is only taken into use"
|
|
|
|
" on the next null to ready transition",
|
2011-02-04 15:36:14 +00:00
|
|
|
GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2011-01-26 18:27:19 +00:00
|
|
|
|
2011-02-24 21:28:28 +00:00
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
PROP_VIEWFINDER_CAPS,
|
|
|
|
g_param_spec_boxed ("viewfinder-caps",
|
|
|
|
"Viewfinder caps",
|
|
|
|
"Restricts the caps that can be used on the viewfinder",
|
|
|
|
GST_TYPE_CAPS, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2011-03-08 08:43:58 +00:00
|
|
|
g_object_class_install_property (object_class, PROP_ZOOM,
|
|
|
|
g_param_spec_float ("zoom", "Zoom",
|
|
|
|
"Digital zoom factor (e.g. 1.5 means 1.5x)", MIN_ZOOM, MAX_ZOOM,
|
|
|
|
DEFAULT_ZOOM, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2011-03-18 14:49:12 +00:00
|
|
|
g_object_class_install_property (object_class, PROP_MAX_ZOOM,
|
|
|
|
g_param_spec_float ("max-zoom", "Maximum zoom level (note: may change "
|
|
|
|
"depending on resolution/implementation)",
|
|
|
|
"Digital zoom factor (e.g. 1.5 means 1.5x)", MIN_ZOOM, G_MAXFLOAT,
|
|
|
|
MAX_ZOOM, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2011-03-15 13:11:43 +00:00
|
|
|
/* TODO
|
|
|
|
* Review before stable
|
|
|
|
* - One problem with using encodebin for images here is how jifmux
|
|
|
|
* autoplugging works. We need to give it a higher rank and fix its
|
|
|
|
* caps (it has image/jpeg on sink and src pads). Preliminary tests
|
|
|
|
* show that jifmux is picked if image/jpeg is the caps of a container
|
|
|
|
* profile. So this could work.
|
|
|
|
* - There seems to be a problem with encodebin for images currently as
|
2019-09-02 19:08:44 +00:00
|
|
|
* it autoplugs a videorate that only starts outputting buffers after
|
2011-03-15 13:11:43 +00:00
|
|
|
* getting the 2nd buffer.
|
|
|
|
*/
|
2011-04-28 13:11:36 +00:00
|
|
|
g_object_class_install_property (object_class, PROP_IMAGE_ENCODING_PROFILE,
|
2012-01-02 14:55:21 +00:00
|
|
|
g_param_spec_object ("image-profile", "Image Profile",
|
2011-04-28 13:11:36 +00:00
|
|
|
"The GstEncodingProfile to use for image captures.",
|
|
|
|
GST_TYPE_ENCODING_PROFILE,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2011-03-15 13:11:43 +00:00
|
|
|
|
|
|
|
|
2011-03-15 18:11:01 +00:00
|
|
|
g_object_class_install_property (object_class, PROP_IDLE,
|
|
|
|
g_param_spec_boolean ("idle", "Idle",
|
|
|
|
"If camerabin2 is idle (not doing captures).", DEFAULT_IDLE,
|
|
|
|
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2011-02-24 21:28:28 +00:00
|
|
|
/* TODO review before going stable
|
|
|
|
* We have viewfinder-supported-caps that returns the caps that the
|
|
|
|
* camerasrc can produce on its viewfinder pad, this could easily be
|
|
|
|
* confused with what the viewfinder-sink accepts.
|
|
|
|
*
|
|
|
|
* Do we want to add a 'viewfinder-sink-supported-caps' or maybe change
|
|
|
|
* the name of this property?
|
|
|
|
*/
|
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
PROP_VIEWFINDER_SUPPORTED_CAPS,
|
|
|
|
g_param_spec_boxed ("viewfinder-supported-caps",
|
|
|
|
"Camera source Viewfinder pad supported caps",
|
|
|
|
"The caps that the camera source can produce on the viewfinder pad",
|
|
|
|
GST_TYPE_CAPS, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2011-06-30 09:09:44 +00:00
|
|
|
/**
|
|
|
|
* GstCameraBin:flags
|
|
|
|
*
|
|
|
|
* Control the behaviour of encodebin.
|
|
|
|
*/
|
|
|
|
g_object_class_install_property (object_class, PROP_FLAGS,
|
|
|
|
g_param_spec_flags ("flags", "Flags", "Flags to control behaviour",
|
|
|
|
GST_TYPE_CAM_FLAGS, DEFAULT_FLAGS,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2010-11-26 20:24:58 +00:00
|
|
|
/**
|
2011-07-07 22:55:59 +00:00
|
|
|
* GstCameraBin2::capture-start:
|
2010-11-26 20:24:58 +00:00
|
|
|
* @camera: the camera bin element
|
|
|
|
*
|
|
|
|
* Starts image capture or video recording depending on the Mode.
|
|
|
|
*/
|
|
|
|
camerabin_signals[START_CAPTURE_SIGNAL] =
|
|
|
|
g_signal_new ("start-capture",
|
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
|
2011-07-07 22:55:59 +00:00
|
|
|
G_STRUCT_OFFSET (GstCameraBin2Class, start_capture),
|
2019-08-27 05:59:27 +00:00
|
|
|
NULL, NULL, NULL, G_TYPE_NONE, 0);
|
2010-11-26 20:24:58 +00:00
|
|
|
|
|
|
|
/**
|
2011-07-07 22:55:59 +00:00
|
|
|
* GstCameraBin2::capture-stop:
|
2010-11-26 20:24:58 +00:00
|
|
|
* @camera: the camera bin element
|
|
|
|
*/
|
|
|
|
camerabin_signals[STOP_CAPTURE_SIGNAL] =
|
|
|
|
g_signal_new ("stop-capture",
|
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
|
2011-07-07 22:55:59 +00:00
|
|
|
G_STRUCT_OFFSET (GstCameraBin2Class, stop_capture),
|
2019-08-27 05:59:27 +00:00
|
|
|
NULL, NULL, NULL, G_TYPE_NONE, 0);
|
2020-05-31 07:18:00 +00:00
|
|
|
|
2020-06-05 22:40:42 +00:00
|
|
|
gst_type_mark_as_plugin_api (GST_TYPE_CAM_FLAGS, 0);
|
2010-11-26 13:14:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-07-07 22:55:59 +00:00
|
|
|
gst_camera_bin_init (GstCameraBin2 * camera)
|
2010-11-26 13:14:46 +00:00
|
|
|
{
|
2010-12-30 03:27:03 +00:00
|
|
|
camera->post_previews = DEFAULT_POST_PREVIEWS;
|
2010-12-14 21:42:51 +00:00
|
|
|
camera->mode = DEFAULT_MODE;
|
2011-06-22 21:58:29 +00:00
|
|
|
camera->location = g_strdup (DEFAULT_LOCATION);
|
2010-12-14 21:42:51 +00:00
|
|
|
camera->viewfinderbin = gst_element_factory_make ("viewfinderbin", "vf-bin");
|
2011-03-08 08:43:58 +00:00
|
|
|
camera->zoom = DEFAULT_ZOOM;
|
2011-03-18 14:49:12 +00:00
|
|
|
camera->max_zoom = MAX_ZOOM;
|
2011-06-30 09:09:44 +00:00
|
|
|
camera->flags = DEFAULT_FLAGS;
|
2012-01-19 10:34:26 +00:00
|
|
|
g_mutex_init (&camera->preview_list_mutex);
|
|
|
|
g_mutex_init (&camera->image_capture_mutex);
|
|
|
|
g_mutex_init (&camera->video_capture_mutex);
|
|
|
|
g_cond_init (&camera->video_state_cond);
|
2010-12-14 21:42:51 +00:00
|
|
|
|
|
|
|
/* capsfilters are created here as we proxy their caps properties and
|
2020-06-23 14:03:04 +00:00
|
|
|
* this way we avoid having to store the caps while on NULL state to
|
2010-12-14 21:42:51 +00:00
|
|
|
* set them later */
|
|
|
|
camera->videobin_capsfilter = gst_element_factory_make ("capsfilter",
|
|
|
|
"videobin-capsfilter");
|
|
|
|
camera->imagebin_capsfilter = gst_element_factory_make ("capsfilter",
|
|
|
|
"imagebin-capsfilter");
|
|
|
|
camera->viewfinderbin_capsfilter = gst_element_factory_make ("capsfilter",
|
|
|
|
"viewfinderbin-capsfilter");
|
|
|
|
|
|
|
|
gst_bin_add_many (GST_BIN (camera),
|
|
|
|
gst_object_ref (camera->viewfinderbin),
|
|
|
|
gst_object_ref (camera->videobin_capsfilter),
|
|
|
|
gst_object_ref (camera->imagebin_capsfilter),
|
|
|
|
gst_object_ref (camera->viewfinderbin_capsfilter), NULL);
|
2011-01-20 12:34:39 +00:00
|
|
|
|
2011-01-21 13:56:52 +00:00
|
|
|
/* these elements are only added if they are going to be used */
|
2011-01-20 12:34:39 +00:00
|
|
|
camera->audio_capsfilter = gst_element_factory_make ("capsfilter",
|
|
|
|
"audio-capsfilter");
|
2011-01-21 13:56:52 +00:00
|
|
|
camera->audio_volume = gst_element_factory_make ("volume", "audio-volume");
|
2010-11-26 13:14:46 +00:00
|
|
|
}
|
|
|
|
|
2011-01-14 11:12:25 +00:00
|
|
|
static void
|
2011-07-07 22:55:59 +00:00
|
|
|
gst_image_capture_bin_post_image_done (GstCameraBin2 * camera,
|
2011-01-14 11:12:25 +00:00
|
|
|
const gchar * filename)
|
|
|
|
{
|
|
|
|
GstMessage *msg;
|
|
|
|
|
|
|
|
g_return_if_fail (filename != NULL);
|
|
|
|
|
|
|
|
msg = gst_message_new_element (GST_OBJECT_CAST (camera),
|
|
|
|
gst_structure_new ("image-done", "filename", G_TYPE_STRING,
|
|
|
|
filename, NULL));
|
|
|
|
|
|
|
|
if (!gst_element_post_message (GST_ELEMENT_CAST (camera), msg))
|
|
|
|
GST_WARNING_OBJECT (camera, "Failed to post image-done message");
|
|
|
|
}
|
|
|
|
|
2011-08-06 15:13:22 +00:00
|
|
|
static void
|
|
|
|
gst_video_capture_bin_post_video_done (GstCameraBin2 * camera)
|
|
|
|
{
|
|
|
|
GstMessage *msg;
|
|
|
|
|
|
|
|
msg = gst_message_new_element (GST_OBJECT_CAST (camera),
|
2011-12-23 19:33:45 +00:00
|
|
|
gst_structure_new_empty ("video-done"));
|
2011-08-06 15:13:22 +00:00
|
|
|
|
|
|
|
if (!gst_element_post_message (GST_ELEMENT_CAST (camera), msg))
|
|
|
|
GST_WARNING_OBJECT (camera, "Failed to post video-done message");
|
|
|
|
}
|
|
|
|
|
2011-11-01 14:47:46 +00:00
|
|
|
static void
|
|
|
|
gst_camera_bin_skip_next_preview (GstCameraBin2 * camerabin)
|
|
|
|
{
|
|
|
|
gchar *location;
|
|
|
|
|
2012-01-19 10:34:26 +00:00
|
|
|
g_mutex_lock (&camerabin->preview_list_mutex);
|
2011-11-01 14:47:46 +00:00
|
|
|
if (camerabin->preview_location_list) {
|
|
|
|
location = camerabin->preview_location_list->data;
|
|
|
|
GST_DEBUG_OBJECT (camerabin, "Skipping preview for %s", location);
|
|
|
|
g_free (location);
|
|
|
|
camerabin->preview_location_list =
|
|
|
|
g_slist_delete_link (camerabin->preview_location_list,
|
|
|
|
camerabin->preview_location_list);
|
|
|
|
GST_CAMERA_BIN2_PROCESSING_DEC (camerabin);
|
|
|
|
} else {
|
|
|
|
GST_WARNING_OBJECT (camerabin, "No previews to skip");
|
|
|
|
}
|
2012-01-19 10:34:26 +00:00
|
|
|
g_mutex_unlock (&camerabin->preview_list_mutex);
|
2011-11-01 14:47:46 +00:00
|
|
|
}
|
|
|
|
|
2013-11-07 01:13:13 +00:00
|
|
|
static void
|
|
|
|
gst_camera_bin_finish_video_file (GstCameraBin2 * camerabin)
|
|
|
|
{
|
|
|
|
/* make sure the file is closed */
|
|
|
|
gst_element_set_state (camerabin->videosink, GST_STATE_NULL);
|
|
|
|
|
|
|
|
gst_video_capture_bin_post_video_done (camerabin);
|
|
|
|
GST_CAMERA_BIN2_PROCESSING_DEC (camerabin);
|
|
|
|
}
|
|
|
|
|
2011-11-10 19:53:40 +00:00
|
|
|
static gpointer
|
|
|
|
gst_camera_bin_video_reset_elements (gpointer u_data)
|
|
|
|
{
|
|
|
|
GstCameraBin2 *camerabin = GST_CAMERA_BIN2_CAST (u_data);
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (camerabin, "Resetting video elements state");
|
2012-01-19 10:34:26 +00:00
|
|
|
g_mutex_lock (&camerabin->video_capture_mutex);
|
2011-11-10 19:53:40 +00:00
|
|
|
|
2013-11-07 01:13:13 +00:00
|
|
|
gst_camera_bin_finish_video_file (camerabin);
|
|
|
|
|
2011-11-10 19:53:40 +00:00
|
|
|
/* reset element states to clear eos/flushing pads */
|
|
|
|
gst_element_set_state (camerabin->video_encodebin, GST_STATE_READY);
|
|
|
|
gst_element_set_state (camerabin->videobin_capsfilter, GST_STATE_READY);
|
2011-11-18 06:31:32 +00:00
|
|
|
if (camerabin->video_filter) {
|
|
|
|
gst_element_set_state (camerabin->video_filter, GST_STATE_READY);
|
|
|
|
gst_element_sync_state_with_parent (camerabin->video_filter);
|
|
|
|
}
|
2011-11-14 19:55:37 +00:00
|
|
|
gst_element_sync_state_with_parent (camerabin->videobin_capsfilter);
|
|
|
|
gst_element_sync_state_with_parent (camerabin->video_encodebin);
|
|
|
|
|
|
|
|
if (camerabin->audio_src) {
|
|
|
|
gst_element_set_state (camerabin->audio_capsfilter, GST_STATE_READY);
|
|
|
|
gst_element_set_state (camerabin->audio_volume, GST_STATE_READY);
|
2015-03-14 17:29:02 +00:00
|
|
|
gst_element_set_state (camerabin->audio_src, GST_STATE_READY);
|
2011-11-14 19:55:37 +00:00
|
|
|
|
2011-11-18 06:31:32 +00:00
|
|
|
if (camerabin->audio_filter) {
|
|
|
|
gst_element_set_state (camerabin->audio_filter, GST_STATE_READY);
|
|
|
|
gst_element_sync_state_with_parent (camerabin->audio_filter);
|
|
|
|
}
|
|
|
|
|
2011-11-14 19:55:37 +00:00
|
|
|
gst_element_sync_state_with_parent (camerabin->audio_capsfilter);
|
|
|
|
gst_element_sync_state_with_parent (camerabin->audio_volume);
|
|
|
|
|
|
|
|
}
|
2011-11-10 19:53:40 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (camerabin, "Setting video state to idle");
|
|
|
|
camerabin->video_state = GST_CAMERA_BIN_VIDEO_IDLE;
|
2012-01-19 10:34:26 +00:00
|
|
|
g_cond_signal (&camerabin->video_state_cond);
|
|
|
|
g_mutex_unlock (&camerabin->video_capture_mutex);
|
2011-11-10 19:53:40 +00:00
|
|
|
|
|
|
|
gst_object_unref (camerabin);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-01-14 11:12:25 +00:00
|
|
|
static void
|
|
|
|
gst_camera_bin_handle_message (GstBin * bin, GstMessage * message)
|
|
|
|
{
|
2011-09-29 21:03:25 +00:00
|
|
|
GstCameraBin2 *camerabin = GST_CAMERA_BIN2_CAST (bin);
|
2011-11-08 11:08:20 +00:00
|
|
|
gboolean dec_counter = FALSE;
|
2011-09-29 21:03:25 +00:00
|
|
|
|
2011-03-23 15:38:36 +00:00
|
|
|
switch (GST_MESSAGE_TYPE (message)) {
|
|
|
|
case GST_MESSAGE_ELEMENT:{
|
|
|
|
const GstStructure *structure = gst_message_get_structure (message);
|
|
|
|
const gchar *filename;
|
|
|
|
|
|
|
|
if (gst_structure_has_name (structure, "GstMultiFileSink")) {
|
|
|
|
filename = gst_structure_get_string (structure, "filename");
|
2011-09-16 03:32:02 +00:00
|
|
|
GST_DEBUG_OBJECT (bin, "Got file save message from multifilesink, "
|
|
|
|
"image %s has been saved", filename);
|
2011-03-23 15:38:36 +00:00
|
|
|
if (filename) {
|
2011-07-07 22:55:59 +00:00
|
|
|
gst_image_capture_bin_post_image_done (GST_CAMERA_BIN2_CAST (bin),
|
2011-03-23 15:38:36 +00:00
|
|
|
filename);
|
|
|
|
}
|
2011-11-08 11:08:20 +00:00
|
|
|
dec_counter = TRUE;
|
2011-09-29 21:03:25 +00:00
|
|
|
} else if (gst_structure_has_name (structure, "preview-image")) {
|
2011-10-12 15:09:18 +00:00
|
|
|
gchar *location = NULL;
|
2011-09-29 21:03:25 +00:00
|
|
|
|
2012-01-19 10:34:26 +00:00
|
|
|
g_mutex_lock (&camerabin->preview_list_mutex);
|
2011-10-12 15:09:18 +00:00
|
|
|
if (camerabin->preview_location_list) {
|
|
|
|
location = camerabin->preview_location_list->data;
|
|
|
|
camerabin->preview_location_list =
|
|
|
|
g_slist_delete_link (camerabin->preview_location_list,
|
|
|
|
camerabin->preview_location_list);
|
|
|
|
GST_DEBUG_OBJECT (camerabin, "Adding preview location to preview "
|
|
|
|
"message '%s'", location);
|
|
|
|
} else {
|
|
|
|
GST_WARNING_OBJECT (camerabin, "Unexpected preview message received, "
|
|
|
|
"won't be able to put location field into the message. This can "
|
|
|
|
"happen if the source is posting previews while camerabin2 is "
|
|
|
|
"shutting down");
|
|
|
|
}
|
2012-01-19 10:34:26 +00:00
|
|
|
g_mutex_unlock (&camerabin->preview_list_mutex);
|
2011-09-29 21:03:25 +00:00
|
|
|
|
2011-10-12 15:09:18 +00:00
|
|
|
if (location) {
|
2014-05-30 05:10:25 +00:00
|
|
|
GstStructure *new_structure;
|
2011-12-27 14:59:16 +00:00
|
|
|
GValue value = { 0 };
|
2014-05-30 05:10:25 +00:00
|
|
|
|
2011-12-27 14:59:16 +00:00
|
|
|
g_value_init (&value, G_TYPE_STRING);
|
|
|
|
g_value_take_string (&value, location);
|
2014-05-30 05:10:25 +00:00
|
|
|
|
|
|
|
/* need to do a copy because the structure isn't mutable */
|
|
|
|
new_structure = gst_structure_copy (structure);
|
|
|
|
gst_structure_take_value (new_structure, "location", &value);
|
|
|
|
|
|
|
|
gst_message_unref (message);
|
|
|
|
message =
|
|
|
|
gst_message_new_element (GST_OBJECT_CAST (camerabin),
|
|
|
|
new_structure);
|
2011-10-12 15:09:18 +00:00
|
|
|
}
|
2011-11-01 13:38:33 +00:00
|
|
|
|
|
|
|
GST_LOG_OBJECT (bin, "received preview-image message");
|
2011-11-08 11:08:20 +00:00
|
|
|
dec_counter = TRUE;
|
2011-01-14 11:12:25 +00:00
|
|
|
}
|
|
|
|
}
|
2011-03-23 15:38:36 +00:00
|
|
|
break;
|
|
|
|
case GST_MESSAGE_WARNING:{
|
|
|
|
GError *err = NULL;
|
|
|
|
gchar *debug = NULL;
|
|
|
|
|
|
|
|
gst_message_parse_warning (message, &err, &debug);
|
|
|
|
if (err->domain == GST_RESOURCE_ERROR) {
|
|
|
|
/* some capturing failed */
|
2011-09-16 03:32:02 +00:00
|
|
|
GST_WARNING_OBJECT (bin, "Capture failed, reason: %s - %s",
|
|
|
|
err->message, debug);
|
2011-11-01 14:47:46 +00:00
|
|
|
if (camerabin->post_previews) {
|
|
|
|
gst_camera_bin_skip_next_preview (camerabin);
|
|
|
|
}
|
2011-11-08 11:08:20 +00:00
|
|
|
dec_counter = TRUE;
|
2011-03-23 15:38:36 +00:00
|
|
|
}
|
2011-12-14 11:32:50 +00:00
|
|
|
g_error_free (err);
|
|
|
|
g_free (debug);
|
2011-03-23 15:38:36 +00:00
|
|
|
}
|
2011-03-23 19:32:19 +00:00
|
|
|
break;
|
|
|
|
case GST_MESSAGE_EOS:{
|
|
|
|
GstElement *src = GST_ELEMENT (GST_MESSAGE_SRC (message));
|
2011-07-07 22:55:59 +00:00
|
|
|
if (src == GST_CAMERA_BIN2_CAST (bin)->videosink) {
|
2011-11-10 19:53:40 +00:00
|
|
|
|
2012-01-19 10:34:26 +00:00
|
|
|
g_mutex_lock (&camerabin->video_capture_mutex);
|
2011-03-23 19:32:19 +00:00
|
|
|
GST_DEBUG_OBJECT (bin, "EOS from video branch");
|
2014-07-23 16:37:05 +00:00
|
|
|
if (camerabin->video_state == GST_CAMERA_BIN_VIDEO_FINISHING) {
|
|
|
|
if (!g_thread_try_new ("reset-element-thread",
|
|
|
|
gst_camera_bin_video_reset_elements,
|
|
|
|
gst_object_ref (camerabin), NULL)) {
|
|
|
|
GST_WARNING_OBJECT (camerabin,
|
|
|
|
"Failed to create thread to "
|
|
|
|
"reset video elements' state, video recordings may not work "
|
|
|
|
"anymore");
|
|
|
|
gst_object_unref (camerabin);
|
|
|
|
camerabin->video_state = GST_CAMERA_BIN_VIDEO_IDLE;
|
|
|
|
}
|
|
|
|
} else if (camerabin->video_state == GST_CAMERA_BIN_VIDEO_IDLE) {
|
|
|
|
GST_DEBUG_OBJECT (camerabin, "Received EOS from video branch but "
|
|
|
|
"video recording is idle, ignoring");
|
|
|
|
} else {
|
|
|
|
GST_WARNING_OBJECT (camerabin, "Received EOS from video branch but "
|
|
|
|
"video is recording and stop-capture wasn't requested");
|
|
|
|
g_assert_not_reached ();
|
2011-11-10 19:53:40 +00:00
|
|
|
}
|
|
|
|
|
2012-01-19 10:34:26 +00:00
|
|
|
g_mutex_unlock (&camerabin->video_capture_mutex);
|
2011-03-23 19:32:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2011-03-23 15:38:36 +00:00
|
|
|
default:
|
|
|
|
break;
|
2011-01-14 11:12:25 +00:00
|
|
|
}
|
2014-04-09 14:24:13 +00:00
|
|
|
|
|
|
|
GST_BIN_CLASS (parent_class)->handle_message (bin, message);
|
2011-11-08 11:08:20 +00:00
|
|
|
|
|
|
|
if (dec_counter)
|
|
|
|
GST_CAMERA_BIN2_PROCESSING_DEC (camerabin);
|
2011-01-14 11:12:25 +00:00
|
|
|
}
|
|
|
|
|
2011-01-26 18:27:19 +00:00
|
|
|
/*
|
|
|
|
* Transforms:
|
|
|
|
* ... ! previous_element [ ! current_filter ] ! next_element ! ...
|
|
|
|
*
|
|
|
|
* into:
|
|
|
|
* ... ! previous_element [ ! new_filter ] ! next_element ! ...
|
|
|
|
*
|
|
|
|
* Where current_filter and new_filter might or might not be NULL
|
|
|
|
*/
|
|
|
|
static void
|
2011-07-07 22:55:59 +00:00
|
|
|
gst_camera_bin_check_and_replace_filter (GstCameraBin2 * camera,
|
2011-01-26 18:27:19 +00:00
|
|
|
GstElement ** current_filter, GstElement * new_filter,
|
2011-06-29 13:18:47 +00:00
|
|
|
GstElement * previous_element, GstElement * next_element,
|
|
|
|
const gchar * prev_elem_pad)
|
2011-01-26 18:27:19 +00:00
|
|
|
{
|
|
|
|
if (*current_filter == new_filter) {
|
|
|
|
GST_DEBUG_OBJECT (camera, "Current filter is the same as the previous, "
|
|
|
|
"no switch needed.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (camera, "Replacing current filter (%s) with new filter "
|
|
|
|
"(%s)", *current_filter ? GST_ELEMENT_NAME (*current_filter) : "null",
|
|
|
|
new_filter ? GST_ELEMENT_NAME (new_filter) : "null");
|
|
|
|
|
|
|
|
if (*current_filter) {
|
|
|
|
gst_bin_remove (GST_BIN_CAST (camera), *current_filter);
|
|
|
|
gst_object_unref (*current_filter);
|
|
|
|
*current_filter = NULL;
|
|
|
|
} else {
|
|
|
|
/* unlink the pads */
|
|
|
|
gst_element_unlink (previous_element, next_element);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (new_filter) {
|
|
|
|
*current_filter = gst_object_ref (new_filter);
|
|
|
|
gst_bin_add (GST_BIN_CAST (camera), gst_object_ref (new_filter));
|
2011-06-29 13:18:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (prev_elem_pad) {
|
|
|
|
if (new_filter) {
|
|
|
|
gst_element_link_pads (previous_element, prev_elem_pad, new_filter, NULL);
|
|
|
|
gst_element_link (new_filter, next_element);
|
|
|
|
} else {
|
|
|
|
gst_element_link_pads (previous_element, prev_elem_pad, next_element,
|
|
|
|
NULL);
|
|
|
|
}
|
2011-01-26 18:27:19 +00:00
|
|
|
} else {
|
2011-06-29 13:18:47 +00:00
|
|
|
if (new_filter)
|
|
|
|
gst_element_link_many (previous_element, new_filter, next_element, NULL);
|
|
|
|
else
|
|
|
|
gst_element_link (previous_element, next_element);
|
2011-01-26 18:27:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-04 09:09:43 +00:00
|
|
|
static void
|
|
|
|
encodebin_element_added (GstElement * encodebin, GstElement * new_element,
|
2011-07-07 22:55:59 +00:00
|
|
|
GstCameraBin2 * camera)
|
2011-03-04 09:09:43 +00:00
|
|
|
{
|
2011-03-11 10:34:23 +00:00
|
|
|
GstElementFactory *factory = gst_element_get_factory (new_element);
|
|
|
|
|
|
|
|
if (factory != NULL) {
|
2011-12-23 19:33:45 +00:00
|
|
|
if (strcmp (GST_OBJECT_NAME (factory), "audiorate") == 0 ||
|
|
|
|
strcmp (GST_OBJECT_NAME (factory), "videorate") == 0) {
|
2011-03-11 10:34:23 +00:00
|
|
|
g_object_set (new_element, "skip-to-first", TRUE, NULL);
|
|
|
|
}
|
2011-03-04 09:09:43 +00:00
|
|
|
}
|
2011-06-23 01:25:18 +00:00
|
|
|
|
2012-09-12 12:42:09 +00:00
|
|
|
if (GST_IS_TAG_SETTER (new_element)) {
|
|
|
|
GstTagSetter *tagsetter = GST_TAG_SETTER (new_element);
|
2011-06-23 01:25:18 +00:00
|
|
|
|
2012-09-12 12:42:09 +00:00
|
|
|
gst_tag_setter_set_tag_merge_mode (tagsetter, GST_TAG_MERGE_REPLACE);
|
|
|
|
}
|
2011-03-04 09:09:43 +00:00
|
|
|
}
|
|
|
|
|
2011-01-20 12:34:39 +00:00
|
|
|
#define VIDEO_PAD 1
|
|
|
|
#define AUDIO_PAD 2
|
|
|
|
static GstPad *
|
2011-07-07 22:55:59 +00:00
|
|
|
encodebin_find_pad (GstCameraBin2 * camera, GstElement * encodebin,
|
2011-04-28 13:11:36 +00:00
|
|
|
gint pad_type)
|
2011-01-20 12:34:39 +00:00
|
|
|
{
|
2011-12-23 19:33:45 +00:00
|
|
|
GValue value = { 0 };
|
2011-01-20 12:34:39 +00:00
|
|
|
GstPad *pad = NULL;
|
|
|
|
GstIterator *iter;
|
|
|
|
gboolean done;
|
2011-03-14 17:33:57 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (camera, "Looking at encodebin pads, searching for %s pad",
|
2011-04-04 11:28:32 +00:00
|
|
|
pad_type == VIDEO_PAD ? "video" : "audio");
|
2011-01-20 12:34:39 +00:00
|
|
|
|
|
|
|
iter = gst_element_iterate_sink_pads (encodebin);
|
|
|
|
done = FALSE;
|
|
|
|
while (!done) {
|
2011-12-23 19:33:45 +00:00
|
|
|
switch (gst_iterator_next (iter, &value)) {
|
2011-01-20 12:34:39 +00:00
|
|
|
case GST_ITERATOR_OK:
|
2011-12-23 19:33:45 +00:00
|
|
|
pad = g_value_dup_object (&value);
|
|
|
|
g_value_unset (&value);
|
2011-01-20 12:34:39 +00:00
|
|
|
if (pad_type == VIDEO_PAD) {
|
|
|
|
if (strstr (GST_PAD_NAME (pad), "video") != NULL) {
|
2011-03-14 17:33:57 +00:00
|
|
|
GST_DEBUG_OBJECT (camera, "Found video pad %s", GST_PAD_NAME (pad));
|
2011-01-20 12:34:39 +00:00
|
|
|
done = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else if (pad_type == AUDIO_PAD) {
|
|
|
|
if (strstr (GST_PAD_NAME (pad), "audio") != NULL) {
|
2011-03-14 17:33:57 +00:00
|
|
|
GST_DEBUG_OBJECT (camera, "Found audio pad %s", GST_PAD_NAME (pad));
|
2011-01-20 12:34:39 +00:00
|
|
|
done = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
gst_object_unref (pad);
|
|
|
|
pad = NULL;
|
|
|
|
break;
|
|
|
|
case GST_ITERATOR_RESYNC:
|
|
|
|
gst_iterator_resync (iter);
|
|
|
|
break;
|
|
|
|
case GST_ITERATOR_ERROR:
|
|
|
|
pad = NULL;
|
|
|
|
done = TRUE;
|
|
|
|
break;
|
|
|
|
case GST_ITERATOR_DONE:
|
|
|
|
pad = NULL;
|
|
|
|
done = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
gst_iterator_free (iter);
|
|
|
|
|
|
|
|
/* no static pad, try requesting one */
|
|
|
|
if (pad == NULL) {
|
|
|
|
GstElementClass *klass;
|
|
|
|
GstPadTemplate *tmpl;
|
|
|
|
|
2011-03-14 17:33:57 +00:00
|
|
|
GST_DEBUG_OBJECT (camera, "No pads found, trying to request one");
|
|
|
|
|
2011-01-20 12:34:39 +00:00
|
|
|
klass = GST_ELEMENT_GET_CLASS (encodebin);
|
|
|
|
tmpl = gst_element_class_get_pad_template (klass, pad_type == VIDEO_PAD ?
|
2012-08-29 00:01:55 +00:00
|
|
|
"video_%u" : "audio_%u");
|
|
|
|
|
|
|
|
if (!tmpl) {
|
|
|
|
GST_DEBUG_OBJECT (camera, "No templates found, can't request pad");
|
|
|
|
return NULL;
|
|
|
|
}
|
2011-01-20 12:34:39 +00:00
|
|
|
|
|
|
|
pad = gst_element_request_pad (encodebin, tmpl, NULL, NULL);
|
2011-03-14 17:33:57 +00:00
|
|
|
GST_DEBUG_OBJECT (camera, "Got pad: %s", pad ? GST_PAD_NAME (pad) : "null");
|
2011-01-20 12:34:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return pad;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2011-07-07 22:55:59 +00:00
|
|
|
gst_camera_bin_video_profile_has_audio (GstCameraBin2 * camera)
|
2011-01-20 12:34:39 +00:00
|
|
|
{
|
|
|
|
const GList *list;
|
|
|
|
|
|
|
|
g_return_val_if_fail (camera->video_profile != NULL, FALSE);
|
|
|
|
|
|
|
|
if (GST_IS_ENCODING_VIDEO_PROFILE (camera->video_profile))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
for (list =
|
|
|
|
gst_encoding_container_profile_get_profiles ((GstEncodingContainerProfile
|
|
|
|
*) camera->video_profile); list; list = g_list_next (list)) {
|
|
|
|
GstEncodingProfile *profile = (GstEncodingProfile *) list->data;
|
|
|
|
|
|
|
|
if (GST_IS_ENCODING_AUDIO_PROFILE (profile))
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2011-03-11 19:20:52 +00:00
|
|
|
static GstPadLinkReturn
|
2011-07-07 22:55:59 +00:00
|
|
|
gst_camera_bin_link_encodebin (GstCameraBin2 * camera, GstElement * encodebin,
|
2011-04-28 13:11:36 +00:00
|
|
|
GstElement * element, gint padtype)
|
2011-03-11 19:20:52 +00:00
|
|
|
{
|
|
|
|
GstPadLinkReturn ret;
|
|
|
|
GstPad *srcpad;
|
|
|
|
GstPad *sinkpad = NULL;
|
|
|
|
|
|
|
|
srcpad = gst_element_get_static_pad (element, "src");
|
2011-04-28 17:37:22 +00:00
|
|
|
g_assert (srcpad != NULL);
|
|
|
|
|
2011-04-28 13:11:36 +00:00
|
|
|
sinkpad = encodebin_find_pad (camera, encodebin, padtype);
|
2011-03-14 17:33:57 +00:00
|
|
|
|
2011-04-28 17:37:22 +00:00
|
|
|
/* there may be no available sink pad for encodebin in some situations:
|
|
|
|
* e.g. missing elements or incompatible padtype */
|
|
|
|
if (sinkpad == NULL) {
|
|
|
|
gst_object_unref (srcpad);
|
|
|
|
return GST_PAD_LINK_REFUSED;
|
|
|
|
}
|
2011-03-11 19:20:52 +00:00
|
|
|
|
2011-08-31 16:29:17 +00:00
|
|
|
ret = gst_pad_link_full (srcpad, sinkpad, GST_PAD_LINK_CHECK_CAPS);
|
2011-03-11 19:20:52 +00:00
|
|
|
gst_object_unref (sinkpad);
|
|
|
|
gst_object_unref (srcpad);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-03-18 14:49:12 +00:00
|
|
|
static void
|
|
|
|
gst_camera_bin_src_notify_max_zoom_cb (GObject * self, GParamSpec * pspec,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
2015-03-06 12:49:20 +00:00
|
|
|
GParamSpecFloat *zoom_pspec;
|
2011-07-07 22:55:59 +00:00
|
|
|
GstCameraBin2 *camera = (GstCameraBin2 *) user_data;
|
2011-03-18 14:49:12 +00:00
|
|
|
|
|
|
|
g_object_get (self, "max-zoom", &camera->max_zoom, NULL);
|
|
|
|
GST_DEBUG_OBJECT (camera, "Max zoom updated to %f", camera->max_zoom);
|
2015-03-06 12:49:20 +00:00
|
|
|
|
|
|
|
/* update zoom pspec */
|
|
|
|
zoom_pspec =
|
|
|
|
G_PARAM_SPEC_FLOAT (g_object_class_find_property (G_OBJECT_GET_CLASS
|
|
|
|
(G_OBJECT (camera)), "zoom"));
|
|
|
|
zoom_pspec->maximum = camera->max_zoom;
|
|
|
|
|
2011-03-18 14:49:12 +00:00
|
|
|
g_object_notify (G_OBJECT (camera), "max-zoom");
|
|
|
|
}
|
|
|
|
|
2011-09-12 19:50:10 +00:00
|
|
|
static void
|
|
|
|
gst_camera_bin_src_notify_zoom_cb (GObject * self, GParamSpec * pspec,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GstCameraBin2 *camera = (GstCameraBin2 *) user_data;
|
|
|
|
|
|
|
|
g_object_get (self, "zoom", &camera->zoom, NULL);
|
|
|
|
GST_DEBUG_OBJECT (camera, "Zoom updated to %f", camera->zoom);
|
|
|
|
g_object_notify (G_OBJECT (camera), "zoom");
|
|
|
|
}
|
|
|
|
|
2011-12-23 19:33:45 +00:00
|
|
|
static GstPadProbeReturn
|
|
|
|
gst_camera_bin_image_src_buffer_probe (GstPad * pad, GstPadProbeInfo * info,
|
2011-06-22 19:27:00 +00:00
|
|
|
gpointer data)
|
|
|
|
{
|
2011-12-23 19:33:45 +00:00
|
|
|
GstPadProbeReturn ret = GST_PAD_PROBE_OK;
|
2011-07-07 22:55:59 +00:00
|
|
|
GstCameraBin2 *camerabin = data;
|
2011-06-22 19:27:00 +00:00
|
|
|
GstEvent *evt;
|
|
|
|
gchar *location = NULL;
|
|
|
|
GstPad *peer;
|
2011-11-09 12:41:44 +00:00
|
|
|
GstTagList *tags;
|
|
|
|
|
2012-01-19 10:34:26 +00:00
|
|
|
g_mutex_lock (&camerabin->image_capture_mutex);
|
2011-11-09 15:21:37 +00:00
|
|
|
|
2011-11-09 12:41:44 +00:00
|
|
|
/* Push pending image tags */
|
|
|
|
if (camerabin->image_tags_list) {
|
|
|
|
tags = camerabin->image_tags_list->data;
|
|
|
|
camerabin->image_tags_list =
|
|
|
|
g_slist_delete_link (camerabin->image_tags_list,
|
|
|
|
camerabin->image_tags_list);
|
|
|
|
GST_DEBUG_OBJECT (camerabin, "Pushing tags from application: %"
|
|
|
|
GST_PTR_FORMAT, tags);
|
2011-11-09 14:45:27 +00:00
|
|
|
if (tags) {
|
|
|
|
peer = gst_pad_get_peer (pad);
|
2012-07-28 23:04:35 +00:00
|
|
|
gst_pad_send_event (peer, gst_event_new_tag (tags));
|
2011-11-09 14:45:27 +00:00
|
|
|
gst_object_unref (peer);
|
|
|
|
}
|
2011-11-09 12:41:44 +00:00
|
|
|
} else {
|
|
|
|
GST_DEBUG_OBJECT (camerabin, "No tags from application to send");
|
|
|
|
}
|
2011-06-22 19:27:00 +00:00
|
|
|
|
2011-11-09 12:41:44 +00:00
|
|
|
/* Push image location event */
|
2011-06-22 19:27:00 +00:00
|
|
|
if (camerabin->image_location_list) {
|
|
|
|
location = camerabin->image_location_list->data;
|
|
|
|
camerabin->image_location_list =
|
|
|
|
g_slist_delete_link (camerabin->image_location_list,
|
|
|
|
camerabin->image_location_list);
|
2011-07-22 08:38:30 +00:00
|
|
|
GST_DEBUG_OBJECT (camerabin, "Sending image location change to '%s'",
|
2011-06-22 19:27:00 +00:00
|
|
|
location);
|
|
|
|
} else {
|
|
|
|
GST_DEBUG_OBJECT (camerabin, "No filename location change to send");
|
2012-01-19 10:34:26 +00:00
|
|
|
g_mutex_unlock (&camerabin->image_capture_mutex);
|
2011-07-22 08:38:30 +00:00
|
|
|
return ret;
|
2011-06-22 19:27:00 +00:00
|
|
|
}
|
2012-01-19 10:34:26 +00:00
|
|
|
g_mutex_unlock (&camerabin->image_capture_mutex);
|
2011-06-22 19:27:00 +00:00
|
|
|
|
2011-07-22 08:38:30 +00:00
|
|
|
if (location) {
|
|
|
|
evt = gst_camera_bin_new_event_file_location (location);
|
|
|
|
peer = gst_pad_get_peer (pad);
|
|
|
|
gst_pad_send_event (peer, evt);
|
|
|
|
gst_object_unref (peer);
|
|
|
|
g_free (location);
|
|
|
|
} else {
|
|
|
|
/* This means we don't have to encode the capture, it is used for
|
|
|
|
* signaling the application just wants the preview */
|
2011-12-23 19:33:45 +00:00
|
|
|
ret = GST_PAD_PROBE_DROP;
|
2011-07-22 08:38:30 +00:00
|
|
|
GST_CAMERA_BIN2_PROCESSING_DEC (camerabin);
|
|
|
|
}
|
2011-06-22 19:27:00 +00:00
|
|
|
|
2011-07-22 08:38:30 +00:00
|
|
|
return ret;
|
2011-06-22 19:27:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-12-23 19:33:45 +00:00
|
|
|
static GstPadProbeReturn
|
|
|
|
gst_camera_bin_image_sink_event_probe (GstPad * pad, GstPadProbeInfo * info,
|
2011-06-22 19:27:00 +00:00
|
|
|
gpointer data)
|
|
|
|
{
|
2011-07-07 22:55:59 +00:00
|
|
|
GstCameraBin2 *camerabin = data;
|
2011-12-23 19:33:45 +00:00
|
|
|
GstEvent *event = GST_EVENT (info->data);
|
2011-06-22 19:27:00 +00:00
|
|
|
|
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
|
|
|
case GST_EVENT_CUSTOM_DOWNSTREAM:{
|
|
|
|
if (gst_event_has_name (event, "new-location")) {
|
|
|
|
const GstStructure *structure = gst_event_get_structure (event);
|
|
|
|
const gchar *filename = gst_structure_get_string (structure,
|
|
|
|
"location");
|
|
|
|
|
|
|
|
gst_element_set_state (camerabin->imagesink, GST_STATE_NULL);
|
|
|
|
GST_DEBUG_OBJECT (camerabin, "Setting filename to imagesink: %s",
|
|
|
|
filename);
|
|
|
|
g_object_set (camerabin->imagesink, "location", filename, NULL);
|
2011-09-15 20:35:44 +00:00
|
|
|
if (gst_element_set_state (camerabin->imagesink, GST_STATE_PLAYING) ==
|
|
|
|
GST_STATE_CHANGE_FAILURE) {
|
|
|
|
/* Resets the latest state change return, that would be a failure
|
|
|
|
* and could cause problems in a camerabin2 state change */
|
|
|
|
gst_element_set_state (camerabin->imagesink, GST_STATE_NULL);
|
|
|
|
}
|
2011-06-22 19:27:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-12-23 19:33:45 +00:00
|
|
|
return GST_PAD_PROBE_OK;
|
2011-06-22 19:27:00 +00:00
|
|
|
}
|
|
|
|
|
2011-12-23 19:33:45 +00:00
|
|
|
static GstPadProbeReturn
|
2011-12-30 10:41:17 +00:00
|
|
|
gst_camera_bin_audio_src_data_probe (GstPad * pad, GstPadProbeInfo * info,
|
2011-08-21 17:41:28 +00:00
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GstCameraBin2 *camera = data;
|
2011-12-23 19:33:45 +00:00
|
|
|
gboolean ret = GST_PAD_PROBE_OK;
|
2011-08-21 17:41:28 +00:00
|
|
|
|
2012-09-06 04:53:07 +00:00
|
|
|
if (GST_IS_BUFFER (info->data)) {
|
2011-12-19 19:49:08 +00:00
|
|
|
if (G_UNLIKELY (camera->audio_send_newseg)) {
|
2012-09-06 04:53:07 +00:00
|
|
|
GstBuffer *buf = GST_BUFFER_CAST (info->data);
|
2011-12-19 19:49:08 +00:00
|
|
|
GstClockTime ts = GST_BUFFER_TIMESTAMP (buf);
|
|
|
|
GstPad *peer;
|
2011-12-30 10:41:17 +00:00
|
|
|
GstSegment segment;
|
2011-12-19 19:49:08 +00:00
|
|
|
|
|
|
|
if (!GST_CLOCK_TIME_IS_VALID (ts)) {
|
|
|
|
ts = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
peer = gst_pad_get_peer (pad);
|
|
|
|
g_return_val_if_fail (peer != NULL, TRUE);
|
|
|
|
|
2011-12-30 10:41:17 +00:00
|
|
|
gst_segment_init (&segment, GST_FORMAT_TIME);
|
|
|
|
segment.start = ts;
|
|
|
|
gst_pad_send_event (peer, gst_event_new_segment (&segment));
|
2011-12-19 19:49:08 +00:00
|
|
|
|
|
|
|
gst_object_unref (peer);
|
|
|
|
|
|
|
|
camera->audio_send_newseg = FALSE;
|
|
|
|
}
|
|
|
|
} else {
|
2011-12-30 10:41:17 +00:00
|
|
|
GstEvent *event = GST_EVENT_CAST (data);
|
2011-12-19 19:49:08 +00:00
|
|
|
if (GST_EVENT_TYPE (event) == GST_EVENT_EOS) {
|
|
|
|
/* we only let an EOS pass when the user is stopping a capture */
|
|
|
|
if (camera->audio_drop_eos) {
|
2011-12-30 10:41:17 +00:00
|
|
|
ret = GST_PAD_PROBE_DROP;
|
2011-12-19 19:49:08 +00:00
|
|
|
} else {
|
|
|
|
camera->audio_drop_eos = TRUE;
|
|
|
|
/* should already be false, but reinforce in case no buffers get
|
|
|
|
* pushed */
|
|
|
|
camera->audio_send_newseg = FALSE;
|
|
|
|
}
|
2011-12-30 10:41:17 +00:00
|
|
|
} else if (GST_EVENT_TYPE (event) == GST_EVENT_SEGMENT) {
|
2011-12-23 19:33:45 +00:00
|
|
|
ret = GST_PAD_PROBE_DROP;
|
2011-08-21 17:41:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-11-26 17:51:30 +00:00
|
|
|
/**
|
|
|
|
* gst_camera_bin_create_elements:
|
2011-07-07 22:55:59 +00:00
|
|
|
* @param camera: the #GstCameraBin2
|
2010-11-26 17:51:30 +00:00
|
|
|
*
|
2011-07-07 22:55:59 +00:00
|
|
|
* Creates all elements inside #GstCameraBin2
|
2010-11-26 17:51:30 +00:00
|
|
|
*
|
|
|
|
* Each of the pads on the camera source is linked as follows:
|
|
|
|
* .pad ! queue ! capsfilter ! correspondingbin
|
|
|
|
*
|
|
|
|
* Where 'correspondingbin' is the bin appropriate for
|
|
|
|
* the camera source pad.
|
|
|
|
*/
|
2010-11-26 13:14:46 +00:00
|
|
|
static gboolean
|
2011-07-07 22:55:59 +00:00
|
|
|
gst_camera_bin_create_elements (GstCameraBin2 * camera)
|
2010-11-26 13:14:46 +00:00
|
|
|
{
|
2010-12-13 19:36:19 +00:00
|
|
|
gboolean new_src = FALSE;
|
2011-01-20 12:34:39 +00:00
|
|
|
gboolean new_audio_src = FALSE;
|
|
|
|
gboolean has_audio;
|
2011-03-11 19:20:52 +00:00
|
|
|
gboolean profile_switched = FALSE;
|
2011-04-28 19:05:53 +00:00
|
|
|
const gchar *missing_element_name;
|
2011-06-30 09:09:44 +00:00
|
|
|
gint encbin_flags = 0;
|
2010-12-13 19:36:19 +00:00
|
|
|
|
|
|
|
if (!camera->elements_created) {
|
2011-08-03 16:12:18 +00:00
|
|
|
/* Check that elements created in _init were really created */
|
|
|
|
if (!(camera->audio_capsfilter && camera->videobin_capsfilter &&
|
|
|
|
camera->imagebin_capsfilter && camera->viewfinderbin_capsfilter)) {
|
|
|
|
missing_element_name = "capsfilter";
|
|
|
|
goto missing_element;
|
|
|
|
}
|
2010-12-13 19:36:19 +00:00
|
|
|
|
2011-06-22 18:37:44 +00:00
|
|
|
camera->video_encodebin =
|
|
|
|
gst_element_factory_make ("encodebin", "video-encodebin");
|
2011-04-28 13:11:36 +00:00
|
|
|
if (!camera->video_encodebin) {
|
2011-04-28 19:05:53 +00:00
|
|
|
missing_element_name = "encodebin";
|
|
|
|
goto missing_element;
|
|
|
|
}
|
2011-04-28 13:11:36 +00:00
|
|
|
camera->video_encodebin_signal_id =
|
|
|
|
g_signal_connect (camera->video_encodebin, "element-added",
|
|
|
|
(GCallback) encodebin_element_added, camera);
|
2011-03-04 09:09:43 +00:00
|
|
|
|
2010-12-27 14:29:42 +00:00
|
|
|
camera->videosink =
|
|
|
|
gst_element_factory_make ("filesink", "videobin-filesink");
|
2011-08-03 18:21:17 +00:00
|
|
|
if (!camera->videosink) {
|
|
|
|
missing_element_name = "filesink";
|
|
|
|
goto missing_element;
|
|
|
|
}
|
2010-12-27 14:29:42 +00:00
|
|
|
g_object_set (camera->videosink, "async", FALSE, NULL);
|
|
|
|
|
2011-01-20 12:34:39 +00:00
|
|
|
/* audio elements */
|
2011-04-28 19:05:53 +00:00
|
|
|
if (!camera->audio_volume) {
|
|
|
|
missing_element_name = "volume";
|
|
|
|
goto missing_element;
|
|
|
|
}
|
2011-01-20 12:34:39 +00:00
|
|
|
|
2011-01-11 12:12:24 +00:00
|
|
|
if (camera->video_profile == NULL) {
|
2010-12-27 14:29:42 +00:00
|
|
|
GstEncodingContainerProfile *prof;
|
|
|
|
GstCaps *caps;
|
|
|
|
|
2011-12-30 10:41:17 +00:00
|
|
|
caps = gst_caps_new_empty_simple ("application/ogg");
|
2011-01-20 12:34:39 +00:00
|
|
|
prof = gst_encoding_container_profile_new ("ogg", "theora+vorbis+ogg",
|
|
|
|
caps, NULL);
|
2010-12-27 14:29:42 +00:00
|
|
|
gst_caps_unref (caps);
|
|
|
|
|
2011-12-30 10:41:17 +00:00
|
|
|
caps = gst_caps_new_empty_simple ("video/x-theora");
|
2010-12-27 14:29:42 +00:00
|
|
|
if (!gst_encoding_container_profile_add_profile (prof,
|
|
|
|
(GstEncodingProfile *) gst_encoding_video_profile_new (caps,
|
|
|
|
NULL, NULL, 1))) {
|
|
|
|
GST_WARNING_OBJECT (camera, "Failed to create encoding profiles");
|
|
|
|
}
|
|
|
|
gst_caps_unref (caps);
|
2011-01-11 12:12:24 +00:00
|
|
|
|
2011-12-30 10:41:17 +00:00
|
|
|
caps = gst_caps_new_empty_simple ("audio/x-vorbis");
|
2011-01-20 12:34:39 +00:00
|
|
|
if (!gst_encoding_container_profile_add_profile (prof,
|
|
|
|
(GstEncodingProfile *) gst_encoding_audio_profile_new (caps,
|
|
|
|
NULL, NULL, 1))) {
|
|
|
|
GST_WARNING_OBJECT (camera, "Failed to create encoding profiles");
|
|
|
|
}
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
|
2011-01-11 12:12:24 +00:00
|
|
|
camera->video_profile = (GstEncodingProfile *) prof;
|
2011-04-28 13:11:36 +00:00
|
|
|
camera->video_profile_switch = TRUE;
|
|
|
|
}
|
|
|
|
|
2011-06-22 18:37:44 +00:00
|
|
|
camera->image_encodebin =
|
|
|
|
gst_element_factory_make ("encodebin", "image-encodebin");
|
2011-04-28 13:11:36 +00:00
|
|
|
if (!camera->image_encodebin) {
|
|
|
|
missing_element_name = "encodebin";
|
|
|
|
goto missing_element;
|
|
|
|
}
|
2011-08-03 16:57:09 +00:00
|
|
|
/* durations have no meaning for image captures */
|
|
|
|
g_object_set (camera->image_encodebin, "queue-time-max", (guint64) 0, NULL);
|
|
|
|
|
2011-04-28 13:11:36 +00:00
|
|
|
camera->image_encodebin_signal_id =
|
|
|
|
g_signal_connect (camera->image_encodebin, "element-added",
|
|
|
|
(GCallback) encodebin_element_added, camera);
|
|
|
|
|
|
|
|
camera->imagesink =
|
|
|
|
gst_element_factory_make ("multifilesink", "imagebin-filesink");
|
|
|
|
if (!camera->imagesink) {
|
|
|
|
missing_element_name = "multifilesink";
|
|
|
|
goto missing_element;
|
|
|
|
}
|
|
|
|
g_object_set (camera->imagesink, "async", FALSE, "post-messages", TRUE,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
if (camera->image_profile == NULL) {
|
2011-05-13 19:27:17 +00:00
|
|
|
GstEncodingVideoProfile *vprof;
|
2011-04-28 13:11:36 +00:00
|
|
|
GstCaps *caps;
|
|
|
|
|
2011-12-30 10:41:17 +00:00
|
|
|
caps = gst_caps_new_empty_simple ("image/jpeg");
|
2011-05-13 19:27:17 +00:00
|
|
|
vprof = gst_encoding_video_profile_new (caps, NULL, NULL, 1);
|
|
|
|
gst_encoding_video_profile_set_variableframerate (vprof, TRUE);
|
2011-04-28 13:11:36 +00:00
|
|
|
|
2011-05-13 19:27:17 +00:00
|
|
|
gst_caps_unref (caps);
|
2012-05-01 18:08:47 +00:00
|
|
|
camera->image_profile = (GstEncodingProfile *) vprof;
|
2011-04-28 13:11:36 +00:00
|
|
|
camera->image_profile_switch = TRUE;
|
2010-12-27 14:29:42 +00:00
|
|
|
}
|
2010-12-13 19:36:19 +00:00
|
|
|
|
|
|
|
camera->viewfinderbin_queue =
|
|
|
|
gst_element_factory_make ("queue", "viewfinderbin-queue");
|
2011-08-03 18:21:17 +00:00
|
|
|
if (!camera->viewfinderbin_queue) {
|
|
|
|
missing_element_name = "queue";
|
|
|
|
goto missing_element;
|
|
|
|
}
|
2010-12-13 19:36:19 +00:00
|
|
|
|
2011-03-11 21:23:22 +00:00
|
|
|
g_object_set (camera->viewfinderbin_queue, "leaky", 2, "silent", TRUE,
|
2011-08-26 12:43:14 +00:00
|
|
|
"max-size-time", (guint64) 0, "max-size-bytes", (guint) 0,
|
|
|
|
"max-size-buffers", (guint) 1, NULL);
|
2011-02-15 17:59:32 +00:00
|
|
|
|
2010-12-13 19:36:19 +00:00
|
|
|
gst_bin_add_many (GST_BIN_CAST (camera),
|
2011-04-28 13:11:36 +00:00
|
|
|
gst_object_ref (camera->video_encodebin),
|
2010-12-27 14:29:42 +00:00
|
|
|
gst_object_ref (camera->videosink),
|
2011-04-28 13:11:36 +00:00
|
|
|
gst_object_ref (camera->image_encodebin),
|
|
|
|
gst_object_ref (camera->imagesink),
|
2010-12-14 21:42:51 +00:00
|
|
|
gst_object_ref (camera->viewfinderbin_queue), NULL);
|
2010-12-13 19:36:19 +00:00
|
|
|
|
2011-08-24 04:03:32 +00:00
|
|
|
gst_element_link_pads_full (camera->video_encodebin, "src",
|
|
|
|
camera->videosink, "sink", GST_PAD_LINK_CHECK_NOTHING);
|
|
|
|
gst_element_link_pads_full (camera->image_encodebin, "src",
|
|
|
|
camera->imagesink, "sink", GST_PAD_LINK_CHECK_NOTHING);
|
|
|
|
gst_element_link_pads_full (camera->viewfinderbin_queue, "src",
|
|
|
|
camera->viewfinderbin_capsfilter, "sink", GST_PAD_LINK_CHECK_CAPS);
|
|
|
|
gst_element_link_pads_full (camera->viewfinderbin_capsfilter, "src",
|
|
|
|
camera->viewfinderbin, "sink", GST_PAD_LINK_CHECK_CAPS);
|
2011-06-22 19:27:00 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
/* set an event probe to watch for custom location changes */
|
|
|
|
GstPad *srcpad;
|
|
|
|
|
|
|
|
srcpad = gst_element_get_static_pad (camera->image_encodebin, "src");
|
|
|
|
|
2011-12-23 19:33:45 +00:00
|
|
|
gst_pad_add_probe (srcpad, GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM,
|
2012-07-28 21:04:57 +00:00
|
|
|
gst_camera_bin_image_sink_event_probe, camera, NULL);
|
2011-06-22 19:27:00 +00:00
|
|
|
|
|
|
|
gst_object_unref (srcpad);
|
|
|
|
}
|
|
|
|
|
2010-12-13 19:36:19 +00:00
|
|
|
/*
|
|
|
|
* Video can't get into playing as its internal filesink will open
|
|
|
|
* a file for writing and leave it empty if unused.
|
|
|
|
*
|
|
|
|
* Its state is managed using the current mode and the source's
|
|
|
|
* ready-for-capture notify callback. When we are at video mode and
|
|
|
|
* the source's ready-for-capture goes to FALSE it means it is
|
|
|
|
* starting recording, so we should prepare the video bin.
|
|
|
|
*/
|
2010-12-27 14:29:42 +00:00
|
|
|
gst_element_set_locked_state (camera->videosink, TRUE);
|
2011-04-28 13:11:36 +00:00
|
|
|
gst_element_set_locked_state (camera->imagesink, TRUE);
|
2010-12-13 19:36:19 +00:00
|
|
|
|
2011-06-22 21:58:29 +00:00
|
|
|
g_object_set (camera->videosink, "location", camera->location, NULL);
|
|
|
|
g_object_set (camera->imagesink, "location", camera->location, NULL);
|
2010-12-13 19:36:19 +00:00
|
|
|
}
|
2011-04-28 13:11:36 +00:00
|
|
|
|
2011-08-23 22:13:21 +00:00
|
|
|
/* propagate the flags property by translating appropriate values
|
|
|
|
* to GstEncFlags values */
|
|
|
|
if (camera->flags & GST_CAM_FLAG_NO_AUDIO_CONVERSION)
|
|
|
|
encbin_flags |= (1 << 0);
|
|
|
|
if (camera->flags & GST_CAM_FLAG_NO_VIDEO_CONVERSION)
|
|
|
|
encbin_flags |= (1 << 1);
|
|
|
|
g_object_set (camera->video_encodebin, "flags", encbin_flags, NULL);
|
|
|
|
|
2011-09-01 13:57:50 +00:00
|
|
|
/* image encodebin has only video branch so disable its conversion elements
|
|
|
|
* appropriately */
|
|
|
|
if (camera->flags & GST_CAM_FLAG_NO_IMAGE_CONVERSION)
|
|
|
|
g_object_set (camera->image_encodebin, "flags", (1 << 1), NULL);
|
|
|
|
|
2011-08-23 14:58:33 +00:00
|
|
|
g_object_set (camera->viewfinderbin, "disable-converters",
|
2011-08-31 18:33:10 +00:00
|
|
|
camera->flags & GST_CAM_FLAG_NO_VIEWFINDER_CONVERSION ? TRUE : FALSE,
|
|
|
|
NULL);
|
2011-08-23 14:58:33 +00:00
|
|
|
|
2011-04-28 13:11:36 +00:00
|
|
|
if (camera->video_profile_switch) {
|
2011-12-30 03:02:19 +00:00
|
|
|
GST_DEBUG_OBJECT (camera, "Switching video-encodebin's profile");
|
2011-04-28 13:11:36 +00:00
|
|
|
g_object_set (camera->video_encodebin, "profile", camera->video_profile,
|
|
|
|
NULL);
|
2011-04-28 17:37:22 +00:00
|
|
|
if (GST_PAD_LINK_FAILED (gst_camera_bin_link_encodebin (camera,
|
2011-04-28 13:11:36 +00:00
|
|
|
camera->video_encodebin, camera->videobin_capsfilter,
|
|
|
|
VIDEO_PAD))) {
|
2011-04-28 17:37:22 +00:00
|
|
|
goto fail;
|
|
|
|
}
|
2011-04-28 13:11:36 +00:00
|
|
|
camera->video_profile_switch = FALSE;
|
2011-03-11 19:20:52 +00:00
|
|
|
|
|
|
|
/* used to trigger relinking further down */
|
|
|
|
profile_switched = TRUE;
|
|
|
|
}
|
2010-12-13 19:36:19 +00:00
|
|
|
|
2011-04-28 13:11:36 +00:00
|
|
|
if (camera->image_profile_switch) {
|
2011-12-30 03:02:19 +00:00
|
|
|
GST_DEBUG_OBJECT (camera, "Switching image-encodebin's profile");
|
2011-04-28 13:11:36 +00:00
|
|
|
g_object_set (camera->image_encodebin, "profile", camera->image_profile,
|
|
|
|
NULL);
|
|
|
|
if (GST_PAD_LINK_FAILED (gst_camera_bin_link_encodebin (camera,
|
|
|
|
camera->image_encodebin, camera->imagebin_capsfilter,
|
|
|
|
VIDEO_PAD))) {
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
camera->image_profile_switch = FALSE;
|
|
|
|
}
|
|
|
|
|
2010-12-13 19:36:19 +00:00
|
|
|
/* check if we need to replace the camera src */
|
|
|
|
if (camera->src) {
|
|
|
|
if (camera->user_src && camera->user_src != camera->src) {
|
|
|
|
|
|
|
|
if (camera->src_capture_notify_id)
|
|
|
|
g_signal_handler_disconnect (camera->src,
|
|
|
|
camera->src_capture_notify_id);
|
|
|
|
|
|
|
|
gst_bin_remove (GST_BIN_CAST (camera), camera->src);
|
|
|
|
gst_object_unref (camera->src);
|
|
|
|
camera->src = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!camera->src) {
|
|
|
|
if (camera->user_src) {
|
|
|
|
camera->src = gst_object_ref (camera->user_src);
|
|
|
|
} else {
|
2010-12-14 20:23:10 +00:00
|
|
|
camera->src =
|
|
|
|
gst_element_factory_make ("wrappercamerabinsrc", "camerasrc");
|
2010-12-13 19:36:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
new_src = TRUE;
|
|
|
|
}
|
2010-11-30 21:19:20 +00:00
|
|
|
|
2010-12-13 19:36:19 +00:00
|
|
|
g_assert (camera->src != NULL);
|
2010-12-13 14:53:59 +00:00
|
|
|
g_object_set (camera->src, "mode", camera->mode, NULL);
|
2011-03-08 08:43:58 +00:00
|
|
|
if (camera->src) {
|
|
|
|
if (g_object_class_find_property (G_OBJECT_GET_CLASS (camera->src),
|
|
|
|
"preview-caps")) {
|
|
|
|
g_object_set (camera->src, "post-previews", camera->post_previews,
|
|
|
|
"preview-caps", camera->preview_caps, "preview-filter",
|
|
|
|
camera->preview_filter, NULL);
|
|
|
|
}
|
2011-09-12 19:50:10 +00:00
|
|
|
g_signal_connect (G_OBJECT (camera->src), "notify::zoom",
|
|
|
|
(GCallback) gst_camera_bin_src_notify_zoom_cb, camera);
|
2011-03-08 08:43:58 +00:00
|
|
|
g_object_set (camera->src, "zoom", camera->zoom, NULL);
|
2011-03-18 14:49:12 +00:00
|
|
|
g_signal_connect (G_OBJECT (camera->src), "notify::max-zoom",
|
|
|
|
(GCallback) gst_camera_bin_src_notify_max_zoom_cb, camera);
|
2010-12-30 03:27:03 +00:00
|
|
|
}
|
2010-12-13 19:36:19 +00:00
|
|
|
if (new_src) {
|
2011-06-22 19:27:00 +00:00
|
|
|
GstPad *imgsrc = gst_element_get_static_pad (camera->src, "imgsrc");
|
|
|
|
|
2010-12-13 19:36:19 +00:00
|
|
|
gst_bin_add (GST_BIN_CAST (camera), gst_object_ref (camera->src));
|
|
|
|
camera->src_capture_notify_id = g_signal_connect (G_OBJECT (camera->src),
|
|
|
|
"notify::ready-for-capture",
|
|
|
|
G_CALLBACK (gst_camera_bin_src_notify_readyforcapture), camera);
|
2014-04-08 17:54:26 +00:00
|
|
|
|
|
|
|
if (!gst_element_link_pads (camera->src, "vfsrc",
|
2014-07-23 16:37:05 +00:00
|
|
|
camera->viewfinderbin_queue, "sink")) {
|
2014-04-08 17:54:26 +00:00
|
|
|
GST_ERROR_OBJECT (camera,
|
|
|
|
"Failed to link camera source's vfsrc pad to viewfinder queue");
|
|
|
|
goto fail;
|
|
|
|
}
|
2011-08-03 16:57:09 +00:00
|
|
|
|
|
|
|
if (!gst_element_link_pads (camera->src, "imgsrc",
|
|
|
|
camera->imagebin_capsfilter, "sink")) {
|
|
|
|
GST_ERROR_OBJECT (camera,
|
|
|
|
"Failed to link camera source's imgsrc pad to image bin capsfilter");
|
|
|
|
goto fail;
|
|
|
|
}
|
2011-06-29 13:18:47 +00:00
|
|
|
if (!gst_element_link_pads (camera->src, "vidsrc",
|
|
|
|
camera->videobin_capsfilter, "sink")) {
|
|
|
|
GST_ERROR_OBJECT (camera,
|
|
|
|
"Failed to link camera source's vidsrc pad to video bin capsfilter");
|
|
|
|
goto fail;
|
|
|
|
}
|
2011-06-22 19:27:00 +00:00
|
|
|
|
2011-12-23 19:33:45 +00:00
|
|
|
gst_pad_add_probe (imgsrc, GST_PAD_PROBE_TYPE_BUFFER,
|
2012-07-28 21:04:57 +00:00
|
|
|
gst_camera_bin_image_src_buffer_probe, camera, NULL);
|
2011-06-22 19:27:00 +00:00
|
|
|
gst_object_unref (imgsrc);
|
2010-12-13 19:36:19 +00:00
|
|
|
}
|
2010-11-30 23:13:27 +00:00
|
|
|
|
2011-01-26 18:27:19 +00:00
|
|
|
gst_camera_bin_check_and_replace_filter (camera, &camera->image_filter,
|
2011-08-03 16:57:09 +00:00
|
|
|
camera->user_image_filter, camera->src, camera->imagebin_capsfilter,
|
|
|
|
"imgsrc");
|
2011-01-26 18:27:19 +00:00
|
|
|
gst_camera_bin_check_and_replace_filter (camera, &camera->video_filter,
|
2011-06-29 13:18:47 +00:00
|
|
|
camera->user_video_filter, camera->src, camera->videobin_capsfilter,
|
|
|
|
"vidsrc");
|
2011-01-26 18:27:19 +00:00
|
|
|
gst_camera_bin_check_and_replace_filter (camera, &camera->viewfinder_filter,
|
|
|
|
camera->user_viewfinder_filter, camera->viewfinderbin_queue,
|
2011-06-29 13:18:47 +00:00
|
|
|
camera->viewfinderbin_capsfilter, NULL);
|
2011-01-26 18:27:19 +00:00
|
|
|
|
2011-01-20 12:34:39 +00:00
|
|
|
/* check if we need to replace the camera audio src */
|
|
|
|
has_audio = gst_camera_bin_video_profile_has_audio (camera);
|
|
|
|
if (camera->audio_src) {
|
|
|
|
if ((camera->user_audio_src && camera->user_audio_src != camera->audio_src)
|
|
|
|
|| !has_audio) {
|
|
|
|
gst_bin_remove (GST_BIN_CAST (camera), camera->audio_src);
|
2011-01-21 13:56:52 +00:00
|
|
|
gst_bin_remove (GST_BIN_CAST (camera), camera->audio_volume);
|
2011-01-20 12:34:39 +00:00
|
|
|
gst_bin_remove (GST_BIN_CAST (camera), camera->audio_capsfilter);
|
|
|
|
gst_object_unref (camera->audio_src);
|
|
|
|
camera->audio_src = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!camera->audio_src && has_audio) {
|
|
|
|
if (camera->user_audio_src) {
|
|
|
|
camera->audio_src = gst_object_ref (camera->user_audio_src);
|
|
|
|
} else {
|
|
|
|
camera->audio_src =
|
|
|
|
gst_element_factory_make (DEFAULT_AUDIO_SRC, "audiosrc");
|
2011-08-03 18:21:17 +00:00
|
|
|
if (!camera->audio_src) {
|
|
|
|
missing_element_name = DEFAULT_AUDIO_SRC;
|
|
|
|
goto missing_element;
|
|
|
|
}
|
2011-01-20 12:34:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gst_element_set_locked_state (camera->audio_src, TRUE);
|
|
|
|
new_audio_src = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (new_audio_src) {
|
2011-08-21 17:41:28 +00:00
|
|
|
GstPad *srcpad;
|
|
|
|
|
2011-07-28 15:56:12 +00:00
|
|
|
if (g_object_class_find_property (G_OBJECT_GET_CLASS (camera->audio_src),
|
|
|
|
"provide-clock")) {
|
|
|
|
g_object_set (camera->audio_src, "provide-clock", FALSE, NULL);
|
|
|
|
}
|
2011-01-20 12:34:39 +00:00
|
|
|
gst_bin_add (GST_BIN_CAST (camera), gst_object_ref (camera->audio_src));
|
2011-01-21 13:56:52 +00:00
|
|
|
gst_bin_add (GST_BIN_CAST (camera), gst_object_ref (camera->audio_volume));
|
2011-01-20 12:34:39 +00:00
|
|
|
gst_bin_add (GST_BIN_CAST (camera),
|
|
|
|
gst_object_ref (camera->audio_capsfilter));
|
|
|
|
|
2011-11-28 19:35:48 +00:00
|
|
|
gst_element_link_pads_full (camera->audio_src, "src",
|
|
|
|
camera->audio_volume, "sink", GST_PAD_LINK_CHECK_CAPS);
|
|
|
|
gst_element_link_pads_full (camera->audio_volume, "src",
|
|
|
|
camera->audio_capsfilter, "sink", GST_PAD_LINK_CHECK_CAPS);
|
2011-08-21 17:41:28 +00:00
|
|
|
|
|
|
|
srcpad = gst_element_get_static_pad (camera->audio_src, "src");
|
|
|
|
|
|
|
|
/* drop EOS for audiosrc elements that push them on state_changes
|
|
|
|
* (basesrc does this) */
|
2011-12-30 10:41:17 +00:00
|
|
|
gst_pad_add_probe (srcpad, GST_PAD_PROBE_TYPE_DATA_DOWNSTREAM,
|
2012-07-28 21:04:57 +00:00
|
|
|
gst_camera_bin_audio_src_data_probe, camera, NULL);
|
2011-08-21 17:41:28 +00:00
|
|
|
|
|
|
|
gst_object_unref (srcpad);
|
2011-03-11 19:20:52 +00:00
|
|
|
}
|
2011-08-11 21:59:07 +00:00
|
|
|
if (has_audio) {
|
|
|
|
gst_camera_bin_check_and_replace_filter (camera, &camera->audio_filter,
|
|
|
|
camera->user_audio_filter, camera->audio_src, camera->audio_volume,
|
|
|
|
"src");
|
|
|
|
}
|
2011-01-20 12:34:39 +00:00
|
|
|
|
2011-03-11 19:20:52 +00:00
|
|
|
if ((profile_switched && has_audio) || new_audio_src) {
|
2011-04-28 17:37:22 +00:00
|
|
|
if (GST_PAD_LINK_FAILED (gst_camera_bin_link_encodebin (camera,
|
2011-06-29 13:18:47 +00:00
|
|
|
camera->video_encodebin, camera->audio_capsfilter,
|
|
|
|
AUDIO_PAD))) {
|
2011-04-28 17:37:22 +00:00
|
|
|
goto fail;
|
|
|
|
}
|
2011-01-20 12:34:39 +00:00
|
|
|
}
|
|
|
|
|
2010-11-26 17:51:30 +00:00
|
|
|
camera->elements_created = TRUE;
|
2010-11-26 13:14:46 +00:00
|
|
|
return TRUE;
|
2011-04-28 17:37:22 +00:00
|
|
|
|
2011-04-28 19:05:53 +00:00
|
|
|
missing_element:
|
|
|
|
gst_element_post_message (GST_ELEMENT_CAST (camera),
|
|
|
|
gst_missing_element_message_new (GST_ELEMENT_CAST (camera),
|
|
|
|
missing_element_name));
|
|
|
|
GST_ELEMENT_ERROR (camera, CORE, MISSING_PLUGIN,
|
|
|
|
(_("Missing element '%s' - check your GStreamer installation."),
|
|
|
|
missing_element_name), (NULL));
|
|
|
|
goto fail;
|
|
|
|
|
2011-04-28 17:37:22 +00:00
|
|
|
fail:
|
|
|
|
/* FIXME properly clean up */
|
|
|
|
return FALSE;
|
2010-11-26 13:14:46 +00:00
|
|
|
}
|
|
|
|
|
2011-11-09 14:45:27 +00:00
|
|
|
static void
|
2012-08-04 15:31:30 +00:00
|
|
|
_gst_tag_list_unref_maybe (GstTagList * taglist)
|
2011-11-09 14:45:27 +00:00
|
|
|
{
|
|
|
|
if (taglist)
|
2012-08-04 15:31:30 +00:00
|
|
|
gst_tag_list_unref (taglist);
|
2011-11-09 14:45:27 +00:00
|
|
|
}
|
|
|
|
|
2010-11-26 13:14:46 +00:00
|
|
|
static GstStateChangeReturn
|
|
|
|
gst_camera_bin_change_state (GstElement * element, GstStateChange trans)
|
|
|
|
{
|
|
|
|
GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
|
2011-07-07 22:55:59 +00:00
|
|
|
GstCameraBin2 *camera = GST_CAMERA_BIN2_CAST (element);
|
2010-11-26 13:14:46 +00:00
|
|
|
|
2011-08-21 17:41:28 +00:00
|
|
|
|
2010-11-26 13:14:46 +00:00
|
|
|
switch (trans) {
|
|
|
|
case GST_STATE_CHANGE_NULL_TO_READY:
|
|
|
|
if (!gst_camera_bin_create_elements (camera)) {
|
|
|
|
return GST_STATE_CHANGE_FAILURE;
|
|
|
|
}
|
|
|
|
break;
|
2011-03-15 18:11:01 +00:00
|
|
|
case GST_STATE_CHANGE_READY_TO_PAUSED:
|
2011-07-07 22:55:59 +00:00
|
|
|
GST_CAMERA_BIN2_RESET_PROCESSING_COUNTER (camera);
|
2011-08-21 17:41:28 +00:00
|
|
|
camera->audio_drop_eos = TRUE;
|
2011-12-19 19:49:08 +00:00
|
|
|
camera->audio_send_newseg = FALSE;
|
2011-03-15 18:11:01 +00:00
|
|
|
break;
|
2011-03-31 11:08:48 +00:00
|
|
|
case GST_STATE_CHANGE_PAUSED_TO_READY:
|
|
|
|
if (GST_STATE (camera->videosink) >= GST_STATE_PAUSED)
|
|
|
|
gst_element_set_state (camera->videosink, GST_STATE_READY);
|
2011-04-28 13:11:36 +00:00
|
|
|
if (GST_STATE (camera->imagesink) >= GST_STATE_PAUSED)
|
|
|
|
gst_element_set_state (camera->imagesink, GST_STATE_READY);
|
2011-03-31 11:08:48 +00:00
|
|
|
break;
|
|
|
|
case GST_STATE_CHANGE_READY_TO_NULL:
|
|
|
|
gst_element_set_state (camera->videosink, GST_STATE_NULL);
|
2011-04-28 13:11:36 +00:00
|
|
|
gst_element_set_state (camera->imagesink, GST_STATE_NULL);
|
2011-03-31 11:08:48 +00:00
|
|
|
break;
|
2010-11-26 13:14:46 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, trans);
|
|
|
|
|
|
|
|
switch (trans) {
|
2010-12-27 14:29:42 +00:00
|
|
|
case GST_STATE_CHANGE_PAUSED_TO_READY:
|
2011-03-11 13:32:35 +00:00
|
|
|
if (camera->audio_src && GST_STATE (camera->audio_src) >= GST_STATE_READY)
|
2011-01-20 12:34:39 +00:00
|
|
|
gst_element_set_state (camera->audio_src, GST_STATE_READY);
|
2011-01-25 21:10:18 +00:00
|
|
|
|
2011-01-11 17:50:48 +00:00
|
|
|
gst_tag_setter_reset_tags (GST_TAG_SETTER (camera));
|
2011-07-07 22:55:59 +00:00
|
|
|
GST_CAMERA_BIN2_RESET_PROCESSING_COUNTER (camera);
|
2011-11-10 19:11:56 +00:00
|
|
|
camera->video_state = GST_CAMERA_BIN_VIDEO_IDLE;
|
2011-02-15 17:58:28 +00:00
|
|
|
|
2012-01-19 10:34:26 +00:00
|
|
|
g_mutex_lock (&camera->image_capture_mutex);
|
2011-06-23 19:11:55 +00:00
|
|
|
g_slist_foreach (camera->image_location_list, (GFunc) g_free, NULL);
|
|
|
|
g_slist_free (camera->image_location_list);
|
2011-06-22 19:27:00 +00:00
|
|
|
camera->image_location_list = NULL;
|
|
|
|
|
2011-11-09 14:45:27 +00:00
|
|
|
g_slist_foreach (camera->image_tags_list,
|
2012-08-04 15:31:30 +00:00
|
|
|
(GFunc) _gst_tag_list_unref_maybe, NULL);
|
2011-11-09 12:41:44 +00:00
|
|
|
g_slist_free (camera->image_tags_list);
|
|
|
|
camera->image_tags_list = NULL;
|
2012-01-19 10:34:26 +00:00
|
|
|
g_mutex_unlock (&camera->image_capture_mutex);
|
2011-11-09 12:41:44 +00:00
|
|
|
|
2012-01-19 10:34:26 +00:00
|
|
|
g_mutex_lock (&camera->preview_list_mutex);
|
2011-09-29 21:03:25 +00:00
|
|
|
g_slist_foreach (camera->preview_location_list, (GFunc) g_free, NULL);
|
|
|
|
g_slist_free (camera->preview_location_list);
|
|
|
|
camera->preview_location_list = NULL;
|
2012-01-19 10:34:26 +00:00
|
|
|
g_mutex_unlock (&camera->preview_list_mutex);
|
2011-09-29 21:03:25 +00:00
|
|
|
|
2011-02-15 17:58:28 +00:00
|
|
|
/* explicitly set to READY as they might be outside of the bin */
|
|
|
|
gst_element_set_state (camera->audio_volume, GST_STATE_READY);
|
|
|
|
gst_element_set_state (camera->audio_capsfilter, GST_STATE_READY);
|
2010-12-27 14:29:42 +00:00
|
|
|
break;
|
2010-11-26 13:14:46 +00:00
|
|
|
case GST_STATE_CHANGE_READY_TO_NULL:
|
2011-01-20 12:34:39 +00:00
|
|
|
if (camera->audio_src)
|
|
|
|
gst_element_set_state (camera->audio_src, GST_STATE_NULL);
|
2011-02-15 17:58:28 +00:00
|
|
|
|
|
|
|
/* explicitly set to NULL as they might be outside of the bin */
|
|
|
|
gst_element_set_state (camera->audio_volume, GST_STATE_NULL);
|
|
|
|
gst_element_set_state (camera->audio_capsfilter, GST_STATE_NULL);
|
|
|
|
|
2010-11-26 13:14:46 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-05-12 11:17:28 +00:00
|
|
|
static gboolean
|
|
|
|
gst_camera_bin_send_event (GstElement * element, GstEvent * event)
|
|
|
|
{
|
2011-07-07 22:55:59 +00:00
|
|
|
GstCameraBin2 *camera = GST_CAMERA_BIN2_CAST (element);
|
2011-05-12 11:17:28 +00:00
|
|
|
gboolean res;
|
|
|
|
|
2011-12-27 13:20:48 +00:00
|
|
|
/* avoid losing our ref to send_event */
|
|
|
|
gst_event_ref (event);
|
|
|
|
|
2011-05-12 11:17:28 +00:00
|
|
|
res = GST_ELEMENT_CLASS (parent_class)->send_event (element, event);
|
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
|
|
|
case GST_EVENT_EOS:
|
|
|
|
{
|
|
|
|
GstState current;
|
|
|
|
|
|
|
|
if (camera->videosink) {
|
|
|
|
gst_element_get_state (camera->videosink, ¤t, NULL, 0);
|
|
|
|
if (current <= GST_STATE_READY)
|
|
|
|
gst_element_post_message (camera->videosink,
|
|
|
|
gst_message_new_eos (GST_OBJECT (camera->videosink)));
|
|
|
|
}
|
|
|
|
if (camera->imagesink) {
|
|
|
|
gst_element_get_state (camera->imagesink, ¤t, NULL, 0);
|
|
|
|
if (current <= GST_STATE_READY)
|
|
|
|
gst_element_post_message (camera->imagesink,
|
|
|
|
gst_message_new_eos (GST_OBJECT (camera->imagesink)));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-12-27 13:20:48 +00:00
|
|
|
gst_event_unref (event);
|
2011-05-12 11:17:28 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2010-11-30 23:13:27 +00:00
|
|
|
static void
|
2011-07-07 22:55:59 +00:00
|
|
|
gst_camera_bin_set_location (GstCameraBin2 * camera, const gchar * location)
|
2010-11-30 23:13:27 +00:00
|
|
|
{
|
2010-12-03 15:12:32 +00:00
|
|
|
GST_DEBUG_OBJECT (camera, "Setting mode %d location to %s", camera->mode,
|
|
|
|
location);
|
2011-06-22 21:58:29 +00:00
|
|
|
g_free (camera->location);
|
|
|
|
camera->location = g_strdup (location);
|
2010-11-30 23:13:27 +00:00
|
|
|
}
|
|
|
|
|
2011-01-21 13:56:52 +00:00
|
|
|
static void
|
2011-07-07 22:55:59 +00:00
|
|
|
gst_camera_bin_set_audio_src (GstCameraBin2 * camera, GstElement * src)
|
2011-01-21 13:56:52 +00:00
|
|
|
{
|
|
|
|
GST_DEBUG_OBJECT (GST_OBJECT (camera),
|
|
|
|
"Setting audio source %" GST_PTR_FORMAT, src);
|
|
|
|
|
|
|
|
if (camera->user_audio_src)
|
|
|
|
g_object_unref (camera->user_audio_src);
|
|
|
|
|
|
|
|
if (src)
|
2014-07-26 15:46:01 +00:00
|
|
|
gst_object_ref (src);
|
2011-01-21 13:56:52 +00:00
|
|
|
camera->user_audio_src = src;
|
|
|
|
}
|
|
|
|
|
2010-12-13 19:36:19 +00:00
|
|
|
static void
|
2011-07-07 22:55:59 +00:00
|
|
|
gst_camera_bin_set_camera_src (GstCameraBin2 * camera, GstElement * src)
|
2010-12-13 19:36:19 +00:00
|
|
|
{
|
|
|
|
GST_DEBUG_OBJECT (GST_OBJECT (camera),
|
|
|
|
"Setting camera source %" GST_PTR_FORMAT, src);
|
|
|
|
|
|
|
|
if (camera->user_src)
|
|
|
|
g_object_unref (camera->user_src);
|
|
|
|
|
|
|
|
if (src)
|
2014-07-26 15:46:01 +00:00
|
|
|
gst_object_ref (src);
|
2010-12-13 19:36:19 +00:00
|
|
|
camera->user_src = src;
|
|
|
|
}
|
|
|
|
|
2010-11-26 20:24:58 +00:00
|
|
|
static void
|
2010-11-30 23:15:47 +00:00
|
|
|
gst_camera_bin_set_property (GObject * object, guint prop_id,
|
2010-11-26 20:24:58 +00:00
|
|
|
const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
2011-07-07 22:55:59 +00:00
|
|
|
GstCameraBin2 *camera = GST_CAMERA_BIN2_CAST (object);
|
2010-11-26 20:24:58 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_MODE:
|
|
|
|
gst_camera_bin_change_mode (camera, g_value_get_enum (value));
|
|
|
|
break;
|
2010-11-30 23:13:27 +00:00
|
|
|
case PROP_LOCATION:
|
|
|
|
gst_camera_bin_set_location (camera, g_value_get_string (value));
|
|
|
|
break;
|
2010-12-13 19:36:19 +00:00
|
|
|
case PROP_CAMERA_SRC:
|
|
|
|
gst_camera_bin_set_camera_src (camera, g_value_get_object (value));
|
|
|
|
break;
|
2011-01-21 13:56:52 +00:00
|
|
|
case PROP_AUDIO_SRC:
|
|
|
|
gst_camera_bin_set_audio_src (camera, g_value_get_object (value));
|
|
|
|
break;
|
|
|
|
case PROP_MUTE_AUDIO:
|
|
|
|
g_object_set (camera->audio_volume, "mute", g_value_get_boolean (value),
|
|
|
|
NULL);
|
|
|
|
break;
|
|
|
|
case PROP_AUDIO_CAPTURE_CAPS:{
|
|
|
|
GST_DEBUG_OBJECT (camera,
|
|
|
|
"Setting audio capture caps to %" GST_PTR_FORMAT,
|
|
|
|
gst_value_get_caps (value));
|
|
|
|
|
2011-08-18 18:12:56 +00:00
|
|
|
if (G_LIKELY (camera->audio_capsfilter)) {
|
|
|
|
g_object_set (camera->audio_capsfilter, "caps",
|
|
|
|
gst_value_get_caps (value), NULL);
|
|
|
|
} else {
|
|
|
|
GST_WARNING_OBJECT (camera, "Audio capsfilter missing");
|
|
|
|
}
|
2011-01-21 13:56:52 +00:00
|
|
|
}
|
|
|
|
break;
|
2010-12-15 17:05:54 +00:00
|
|
|
case PROP_IMAGE_CAPTURE_CAPS:{
|
|
|
|
|
2010-12-18 02:06:45 +00:00
|
|
|
GST_DEBUG_OBJECT (camera,
|
|
|
|
"Setting image capture caps to %" GST_PTR_FORMAT,
|
|
|
|
gst_value_get_caps (value));
|
|
|
|
|
2011-08-18 18:12:56 +00:00
|
|
|
if (G_LIKELY (camera->imagebin_capsfilter)) {
|
|
|
|
g_object_set (camera->imagebin_capsfilter, "caps",
|
|
|
|
gst_value_get_caps (value), NULL);
|
|
|
|
} else {
|
|
|
|
GST_WARNING_OBJECT (camera, "Image capsfilter missing");
|
|
|
|
}
|
2010-12-15 17:05:54 +00:00
|
|
|
}
|
2010-12-14 21:42:51 +00:00
|
|
|
break;
|
2010-12-15 17:05:54 +00:00
|
|
|
case PROP_VIDEO_CAPTURE_CAPS:{
|
2010-12-18 02:06:45 +00:00
|
|
|
GST_DEBUG_OBJECT (camera,
|
|
|
|
"Setting video capture caps to %" GST_PTR_FORMAT,
|
|
|
|
gst_value_get_caps (value));
|
|
|
|
|
2011-08-18 18:12:56 +00:00
|
|
|
if (G_LIKELY (camera->videobin_capsfilter)) {
|
|
|
|
g_object_set (camera->videobin_capsfilter, "caps",
|
|
|
|
gst_value_get_caps (value), NULL);
|
|
|
|
} else {
|
|
|
|
GST_WARNING_OBJECT (camera, "Video capsfilter missing");
|
|
|
|
}
|
|
|
|
|
2010-12-15 17:05:54 +00:00
|
|
|
}
|
2010-12-14 21:42:51 +00:00
|
|
|
break;
|
2011-02-24 21:28:28 +00:00
|
|
|
case PROP_VIEWFINDER_CAPS:{
|
|
|
|
GST_DEBUG_OBJECT (camera,
|
|
|
|
"Setting viewfinder capture caps to %" GST_PTR_FORMAT,
|
|
|
|
gst_value_get_caps (value));
|
|
|
|
|
2011-08-18 18:12:56 +00:00
|
|
|
if (G_LIKELY (camera->viewfinderbin_capsfilter)) {
|
|
|
|
g_object_set (camera->viewfinderbin_capsfilter, "caps",
|
|
|
|
gst_value_get_caps (value), NULL);
|
|
|
|
} else {
|
|
|
|
GST_WARNING_OBJECT (camera, "Viewfinder capsfilter missing");
|
|
|
|
}
|
2011-02-24 21:28:28 +00:00
|
|
|
}
|
|
|
|
break;
|
2010-12-30 03:27:03 +00:00
|
|
|
case PROP_POST_PREVIEWS:
|
|
|
|
camera->post_previews = g_value_get_boolean (value);
|
|
|
|
if (camera->src
|
|
|
|
&& g_object_class_find_property (G_OBJECT_GET_CLASS (camera->src),
|
|
|
|
"post-previews"))
|
|
|
|
g_object_set (camera->src, "post-previews", camera->post_previews,
|
|
|
|
NULL);
|
|
|
|
break;
|
|
|
|
case PROP_PREVIEW_CAPS:
|
|
|
|
gst_caps_replace (&camera->preview_caps,
|
|
|
|
(GstCaps *) gst_value_get_caps (value));
|
|
|
|
if (camera->src
|
|
|
|
&& g_object_class_find_property (G_OBJECT_GET_CLASS (camera->src),
|
|
|
|
"preview-caps"))
|
|
|
|
g_object_set (camera->src, "preview-caps", camera->preview_caps, NULL);
|
|
|
|
break;
|
2011-01-11 12:12:24 +00:00
|
|
|
case PROP_VIDEO_ENCODING_PROFILE:
|
2011-03-11 19:20:52 +00:00
|
|
|
if (camera->video_profile)
|
|
|
|
gst_encoding_profile_unref (camera->video_profile);
|
2012-05-02 18:24:26 +00:00
|
|
|
camera->video_profile = (GstEncodingProfile *) g_value_dup_object (value);
|
2011-04-28 13:11:36 +00:00
|
|
|
camera->video_profile_switch = TRUE;
|
2011-01-11 12:12:24 +00:00
|
|
|
break;
|
2011-01-26 18:27:19 +00:00
|
|
|
case PROP_IMAGE_FILTER:
|
|
|
|
if (camera->user_image_filter)
|
|
|
|
g_object_unref (camera->user_image_filter);
|
|
|
|
|
|
|
|
camera->user_image_filter = g_value_dup_object (value);
|
|
|
|
break;
|
|
|
|
case PROP_VIDEO_FILTER:
|
|
|
|
if (camera->user_video_filter)
|
|
|
|
g_object_unref (camera->user_video_filter);
|
|
|
|
|
|
|
|
camera->user_video_filter = g_value_dup_object (value);
|
|
|
|
break;
|
|
|
|
case PROP_VIEWFINDER_FILTER:
|
|
|
|
if (camera->user_viewfinder_filter)
|
|
|
|
g_object_unref (camera->user_viewfinder_filter);
|
|
|
|
|
|
|
|
camera->user_viewfinder_filter = g_value_dup_object (value);
|
|
|
|
break;
|
2011-01-27 17:39:19 +00:00
|
|
|
case PROP_PREVIEW_FILTER:
|
|
|
|
if (camera->preview_filter)
|
|
|
|
g_object_unref (camera->preview_filter);
|
|
|
|
|
|
|
|
camera->preview_filter = g_value_dup_object (value);
|
|
|
|
if (camera->src
|
|
|
|
&& g_object_class_find_property (G_OBJECT_GET_CLASS (camera->src),
|
|
|
|
"preview-filter"))
|
|
|
|
g_object_set (camera->src, "preview-filter", camera->preview_filter,
|
|
|
|
NULL);
|
|
|
|
break;
|
2011-08-11 21:59:07 +00:00
|
|
|
case PROP_AUDIO_FILTER:
|
|
|
|
if (camera->user_audio_filter)
|
|
|
|
g_object_unref (camera->user_audio_filter);
|
|
|
|
|
|
|
|
camera->user_audio_filter = g_value_dup_object (value);
|
|
|
|
break;
|
2011-02-04 15:36:14 +00:00
|
|
|
case PROP_VIEWFINDER_SINK:
|
|
|
|
g_object_set (camera->viewfinderbin, "video-sink",
|
|
|
|
g_value_get_object (value), NULL);
|
|
|
|
break;
|
2011-03-08 08:43:58 +00:00
|
|
|
case PROP_ZOOM:
|
|
|
|
camera->zoom = g_value_get_float (value);
|
2011-03-18 14:49:12 +00:00
|
|
|
/* limit to max-zoom */
|
|
|
|
if (camera->zoom > camera->max_zoom) {
|
|
|
|
GST_DEBUG_OBJECT (camera, "Clipping zoom %f to max-zoom %f",
|
|
|
|
camera->zoom, camera->max_zoom);
|
|
|
|
camera->zoom = camera->max_zoom;
|
|
|
|
}
|
2011-03-08 08:43:58 +00:00
|
|
|
if (camera->src)
|
|
|
|
g_object_set (camera->src, "zoom", camera->zoom, NULL);
|
|
|
|
break;
|
2011-04-28 13:11:36 +00:00
|
|
|
case PROP_IMAGE_ENCODING_PROFILE:
|
|
|
|
if (camera->image_profile)
|
|
|
|
gst_encoding_profile_unref (camera->image_profile);
|
2012-05-02 18:24:26 +00:00
|
|
|
camera->image_profile = (GstEncodingProfile *) g_value_dup_object (value);
|
2012-05-04 20:05:38 +00:00
|
|
|
|
|
|
|
/* make sure we set variable framerate here to prevent videorate from
|
|
|
|
* being used in encodebin. It will always keep a buffer stored
|
|
|
|
* internally and push it when a second one arrives. This breaks
|
|
|
|
* the image capture */
|
|
|
|
if (GST_IS_ENCODING_VIDEO_PROFILE (camera->image_profile))
|
|
|
|
gst_encoding_video_profile_set_variableframerate (
|
|
|
|
(GstEncodingVideoProfile *) camera->image_profile, TRUE);
|
|
|
|
else if (GST_IS_ENCODING_CONTAINER_PROFILE (camera->image_profile)) {
|
|
|
|
const GList *profs =
|
|
|
|
gst_encoding_container_profile_get_profiles (
|
|
|
|
(GstEncodingContainerProfile *) camera->image_profile);
|
|
|
|
for (; profs; profs = g_list_next (profs)) {
|
|
|
|
if (GST_IS_ENCODING_VIDEO_PROFILE (profs->data)) {
|
|
|
|
gst_encoding_video_profile_set_variableframerate (profs->data,
|
|
|
|
TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-04-28 13:11:36 +00:00
|
|
|
camera->image_profile_switch = TRUE;
|
2011-03-15 13:11:43 +00:00
|
|
|
break;
|
2011-06-30 09:09:44 +00:00
|
|
|
case PROP_FLAGS:
|
|
|
|
camera->flags = g_value_get_flags (value);
|
|
|
|
break;
|
2010-11-26 20:24:58 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-11-30 23:15:47 +00:00
|
|
|
gst_camera_bin_get_property (GObject * object, guint prop_id,
|
2010-11-26 20:24:58 +00:00
|
|
|
GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
2011-07-07 22:55:59 +00:00
|
|
|
GstCameraBin2 *camera = GST_CAMERA_BIN2_CAST (object);
|
2010-11-26 20:24:58 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_MODE:
|
|
|
|
g_value_set_enum (value, camera->mode);
|
|
|
|
break;
|
2010-11-30 23:13:27 +00:00
|
|
|
case PROP_LOCATION:
|
2011-06-22 21:58:29 +00:00
|
|
|
g_value_set_string (value, camera->location);
|
2010-11-30 23:13:27 +00:00
|
|
|
break;
|
2010-12-13 19:36:19 +00:00
|
|
|
case PROP_CAMERA_SRC:
|
2011-05-11 21:35:40 +00:00
|
|
|
g_value_set_object (value, camera->user_src);
|
2010-12-13 19:36:19 +00:00
|
|
|
break;
|
2011-01-21 13:56:52 +00:00
|
|
|
case PROP_AUDIO_SRC:
|
2011-05-11 21:35:40 +00:00
|
|
|
g_value_set_object (value, camera->user_audio_src);
|
2011-01-21 13:56:52 +00:00
|
|
|
break;
|
|
|
|
case PROP_MUTE_AUDIO:{
|
|
|
|
gboolean mute;
|
|
|
|
|
|
|
|
g_object_get (camera->audio_volume, "mute", &mute, NULL);
|
|
|
|
g_value_set_boolean (value, mute);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PROP_AUDIO_CAPTURE_SUPPORTED_CAPS:
|
2010-12-13 02:03:21 +00:00
|
|
|
case PROP_VIDEO_CAPTURE_SUPPORTED_CAPS:
|
2011-02-24 21:28:28 +00:00
|
|
|
case PROP_VIEWFINDER_SUPPORTED_CAPS:
|
2010-12-13 02:03:21 +00:00
|
|
|
case PROP_IMAGE_CAPTURE_SUPPORTED_CAPS:{
|
|
|
|
GstPad *pad;
|
2011-01-21 13:56:52 +00:00
|
|
|
GstElement *element;
|
2010-12-13 02:03:21 +00:00
|
|
|
GstCaps *caps;
|
|
|
|
const gchar *padname;
|
|
|
|
|
|
|
|
if (prop_id == PROP_VIDEO_CAPTURE_SUPPORTED_CAPS) {
|
2011-01-21 13:56:52 +00:00
|
|
|
element = camera->src;
|
2010-12-13 02:03:21 +00:00
|
|
|
padname = GST_BASE_CAMERA_SRC_VIDEO_PAD_NAME;
|
2011-02-24 21:28:28 +00:00
|
|
|
} else if (prop_id == PROP_IMAGE_CAPTURE_SUPPORTED_CAPS) {
|
2011-01-21 13:56:52 +00:00
|
|
|
element = camera->src;
|
2010-12-13 02:03:21 +00:00
|
|
|
padname = GST_BASE_CAMERA_SRC_IMAGE_PAD_NAME;
|
2011-01-21 13:56:52 +00:00
|
|
|
} else if (prop_id == PROP_VIEWFINDER_SUPPORTED_CAPS) {
|
|
|
|
element = camera->src;
|
2011-02-24 21:28:28 +00:00
|
|
|
padname = GST_BASE_CAMERA_SRC_VIEWFINDER_PAD_NAME;
|
2011-01-21 13:56:52 +00:00
|
|
|
} else {
|
|
|
|
element = camera->audio_src;
|
|
|
|
padname = "src";
|
2010-12-13 02:03:21 +00:00
|
|
|
}
|
|
|
|
|
2011-01-21 13:56:52 +00:00
|
|
|
if (element) {
|
|
|
|
pad = gst_element_get_static_pad (element, padname);
|
2010-12-13 02:03:21 +00:00
|
|
|
|
|
|
|
g_assert (pad != NULL);
|
|
|
|
|
|
|
|
/* TODO not sure if we want get_caps or get_allowed_caps to already
|
|
|
|
* consider the full pipeline scenario and avoid picking a caps that
|
|
|
|
* won't negotiate. Need to take care on the special case of the
|
|
|
|
* pad being unlinked.
|
|
|
|
*/
|
2011-12-23 19:33:45 +00:00
|
|
|
caps = gst_pad_query_caps (pad, NULL);
|
2010-12-13 02:03:21 +00:00
|
|
|
if (caps) {
|
|
|
|
gst_value_set_caps (value, caps);
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_object_unref (pad);
|
|
|
|
} else {
|
2011-01-21 13:56:52 +00:00
|
|
|
GST_DEBUG_OBJECT (camera, "Source not created, can't get "
|
2010-12-13 02:03:21 +00:00
|
|
|
"supported caps");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2011-01-21 13:56:52 +00:00
|
|
|
case PROP_AUDIO_CAPTURE_CAPS:{
|
|
|
|
GstCaps *caps = NULL;
|
2011-08-18 18:12:56 +00:00
|
|
|
if (G_LIKELY (camera->audio_capsfilter)) {
|
|
|
|
g_object_get (camera->audio_capsfilter, "caps", &caps, NULL);
|
|
|
|
} else {
|
|
|
|
GST_WARNING ("Missing audio capsfilter");
|
|
|
|
}
|
2011-01-21 13:56:52 +00:00
|
|
|
gst_value_set_caps (value, caps);
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
}
|
|
|
|
break;
|
2010-12-14 21:42:51 +00:00
|
|
|
case PROP_IMAGE_CAPTURE_CAPS:{
|
|
|
|
GstCaps *caps = NULL;
|
2011-08-18 18:12:56 +00:00
|
|
|
if (G_LIKELY (camera->imagebin_capsfilter)) {
|
|
|
|
g_object_get (camera->imagebin_capsfilter, "caps", &caps, NULL);
|
|
|
|
} else {
|
|
|
|
GST_WARNING ("Missing imagebin capsfilter");
|
|
|
|
}
|
2010-12-14 21:42:51 +00:00
|
|
|
gst_value_set_caps (value, caps);
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case PROP_VIDEO_CAPTURE_CAPS:{
|
|
|
|
GstCaps *caps = NULL;
|
2011-08-18 18:12:56 +00:00
|
|
|
if (G_LIKELY (camera->videobin_capsfilter)) {
|
|
|
|
g_object_get (camera->videobin_capsfilter, "caps", &caps, NULL);
|
|
|
|
} else {
|
|
|
|
GST_WARNING ("Missing imagebin capsfilter");
|
|
|
|
}
|
2010-12-14 21:42:51 +00:00
|
|
|
gst_value_set_caps (value, caps);
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
}
|
|
|
|
break;
|
2011-02-24 21:28:28 +00:00
|
|
|
case PROP_VIEWFINDER_CAPS:{
|
|
|
|
GstCaps *caps = NULL;
|
2011-08-18 18:12:56 +00:00
|
|
|
if (G_LIKELY (camera->viewfinderbin_capsfilter)) {
|
|
|
|
g_object_get (camera->viewfinderbin_capsfilter, "caps", &caps, NULL);
|
|
|
|
} else {
|
|
|
|
GST_WARNING ("Missing imagebin capsfilter");
|
|
|
|
}
|
2011-02-24 21:28:28 +00:00
|
|
|
gst_value_set_caps (value, caps);
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
}
|
|
|
|
break;
|
2010-12-30 03:27:03 +00:00
|
|
|
case PROP_POST_PREVIEWS:
|
|
|
|
g_value_set_boolean (value, camera->post_previews);
|
|
|
|
break;
|
|
|
|
case PROP_PREVIEW_CAPS:
|
|
|
|
if (camera->preview_caps)
|
|
|
|
gst_value_set_caps (value, camera->preview_caps);
|
|
|
|
break;
|
2011-01-11 12:12:24 +00:00
|
|
|
case PROP_VIDEO_ENCODING_PROFILE:
|
|
|
|
if (camera->video_profile) {
|
2012-05-02 18:24:26 +00:00
|
|
|
g_value_set_object (value, camera->video_profile);
|
2011-01-11 12:12:24 +00:00
|
|
|
}
|
|
|
|
break;
|
2011-01-26 18:27:19 +00:00
|
|
|
case PROP_VIDEO_FILTER:
|
2011-05-11 21:35:40 +00:00
|
|
|
if (camera->user_video_filter)
|
|
|
|
g_value_set_object (value, camera->user_video_filter);
|
2011-01-26 18:27:19 +00:00
|
|
|
break;
|
|
|
|
case PROP_IMAGE_FILTER:
|
2011-05-11 21:35:40 +00:00
|
|
|
if (camera->user_image_filter)
|
|
|
|
g_value_set_object (value, camera->user_image_filter);
|
2011-01-26 18:27:19 +00:00
|
|
|
break;
|
|
|
|
case PROP_VIEWFINDER_FILTER:
|
2011-05-11 21:35:40 +00:00
|
|
|
if (camera->user_viewfinder_filter)
|
|
|
|
g_value_set_object (value, camera->user_viewfinder_filter);
|
2011-01-26 18:27:19 +00:00
|
|
|
break;
|
2011-08-11 21:59:07 +00:00
|
|
|
case PROP_AUDIO_FILTER:
|
|
|
|
if (camera->user_audio_filter)
|
|
|
|
g_value_set_object (value, camera->user_audio_filter);
|
|
|
|
break;
|
2011-01-27 17:39:19 +00:00
|
|
|
case PROP_PREVIEW_FILTER:
|
|
|
|
if (camera->preview_filter)
|
|
|
|
g_value_set_object (value, camera->preview_filter);
|
|
|
|
break;
|
2011-02-04 15:36:14 +00:00
|
|
|
case PROP_VIEWFINDER_SINK:{
|
|
|
|
GstElement *sink;
|
|
|
|
|
|
|
|
g_object_get (camera->viewfinderbin, "video-sink", &sink, NULL);
|
|
|
|
g_value_take_object (value, sink);
|
|
|
|
break;
|
|
|
|
}
|
2011-03-08 08:43:58 +00:00
|
|
|
case PROP_ZOOM:
|
|
|
|
g_value_set_float (value, camera->zoom);
|
|
|
|
break;
|
2011-03-18 14:49:12 +00:00
|
|
|
case PROP_MAX_ZOOM:
|
|
|
|
g_value_set_float (value, camera->max_zoom);
|
|
|
|
break;
|
2011-04-28 13:11:36 +00:00
|
|
|
case PROP_IMAGE_ENCODING_PROFILE:
|
|
|
|
if (camera->image_profile) {
|
2012-05-02 18:24:26 +00:00
|
|
|
g_value_set_object (value, camera->image_profile);
|
2011-04-28 13:11:36 +00:00
|
|
|
}
|
2011-03-15 13:11:43 +00:00
|
|
|
break;
|
2011-03-15 18:11:01 +00:00
|
|
|
case PROP_IDLE:
|
|
|
|
g_value_set_boolean (value,
|
|
|
|
g_atomic_int_get (&camera->processing_counter) == 0);
|
|
|
|
break;
|
2011-06-30 09:09:44 +00:00
|
|
|
case PROP_FLAGS:
|
|
|
|
g_value_set_flags (value, camera->flags);
|
|
|
|
break;
|
2010-11-26 20:24:58 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|