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
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
/**
|
2010-11-30 14:40:18 +00:00
|
|
|
* SECTION:element-gstcamerabin2
|
2010-11-26 13:14:46 +00:00
|
|
|
*
|
2010-11-30 14:40:18 +00:00
|
|
|
* The gstcamerabin2 element does FIXME stuff.
|
|
|
|
*
|
|
|
|
* Note that camerabin2 is still UNSTABLE, EXPERIMENTAL and under heavy
|
|
|
|
* development.
|
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"
|
|
|
|
|
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,
|
|
|
|
PROP_AUDIO_CAPTURE_CAPS
|
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
|
2010-11-30 23:13:27 +00:00
|
|
|
#define DEFAULT_VID_LOCATION "vid_%d"
|
|
|
|
#define DEFAULT_IMG_LOCATION "img_%d"
|
2010-12-30 03:27:03 +00:00
|
|
|
#define DEFAULT_POST_PREVIEWS TRUE
|
2011-01-21 13:56:52 +00:00
|
|
|
#define DEFAULT_MUTE_AUDIO FALSE
|
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;
|
|
|
|
static void gst_camera_bin_class_init (GstCameraBinClass * klass);
|
|
|
|
static void gst_camera_bin_base_init (gpointer klass);
|
|
|
|
static void gst_camera_bin_init (GstCameraBin * camera);
|
|
|
|
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);
|
|
|
|
|
2010-11-26 13:14:46 +00:00
|
|
|
GType
|
|
|
|
gst_camera_bin_get_type (void)
|
|
|
|
{
|
|
|
|
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 = {
|
|
|
|
sizeof (GstCameraBinClass),
|
|
|
|
(GBaseInitFunc) gst_camera_bin_base_init,
|
|
|
|
NULL,
|
|
|
|
(GClassInitFunc) gst_camera_bin_class_init,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
sizeof (GstCameraBin),
|
|
|
|
0,
|
|
|
|
(GInstanceInitFunc) gst_camera_bin_init,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
gst_camera_bin_type =
|
|
|
|
g_type_register_static (GST_TYPE_PIPELINE, "GstCameraBin2",
|
|
|
|
&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;
|
|
|
|
}
|
|
|
|
|
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 */
|
|
|
|
|
2010-12-15 17:05:54 +00:00
|
|
|
static GstEvent *
|
|
|
|
gst_camera_bin_new_event_renegotiate (void)
|
|
|
|
{
|
|
|
|
return gst_event_new_custom (GST_EVENT_CUSTOM_BOTH,
|
|
|
|
gst_structure_new ("renegotiate", NULL));
|
|
|
|
}
|
|
|
|
|
2010-11-26 20:24:58 +00:00
|
|
|
static void
|
|
|
|
gst_camera_bin_start_capture (GstCameraBin * camerabin)
|
|
|
|
{
|
2011-01-11 17:50:48 +00:00
|
|
|
const GstTagList *taglist;
|
|
|
|
|
2010-11-29 13:45:30 +00:00
|
|
|
GST_DEBUG_OBJECT (camerabin, "Received start-capture");
|
2011-01-11 17:50:48 +00:00
|
|
|
|
|
|
|
taglist = gst_tag_setter_get_tag_list (GST_TAG_SETTER (camerabin));
|
|
|
|
if (taglist) {
|
|
|
|
GstPad *active_pad;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (camerabin, "Pushing tags from application: %"
|
|
|
|
GST_PTR_FORMAT, taglist);
|
|
|
|
|
|
|
|
if (camerabin->mode == MODE_IMAGE) {
|
|
|
|
active_pad = gst_element_get_static_pad (camerabin->src,
|
|
|
|
GST_BASE_CAMERA_SRC_IMAGE_PAD_NAME);
|
|
|
|
} else {
|
|
|
|
active_pad = gst_element_get_static_pad (camerabin->src,
|
|
|
|
GST_BASE_CAMERA_SRC_VIDEO_PAD_NAME);
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_pad_push_event (active_pad,
|
|
|
|
gst_event_new_tag (gst_tag_list_copy (taglist)));
|
|
|
|
gst_object_unref (active_pad);
|
|
|
|
}
|
|
|
|
|
2011-02-15 17:58:28 +00:00
|
|
|
if (camerabin->mode == MODE_VIDEO && camerabin->audio_src) {
|
|
|
|
gst_element_set_state (camerabin->audio_src, GST_STATE_READY);
|
|
|
|
/* need to reset eos status (pads could be flushing) */
|
|
|
|
gst_element_set_state (camerabin->audio_queue, GST_STATE_READY);
|
|
|
|
gst_element_set_state (camerabin->audio_convert, GST_STATE_READY);
|
|
|
|
gst_element_set_state (camerabin->audio_capsfilter, GST_STATE_READY);
|
|
|
|
gst_element_set_state (camerabin->audio_volume, GST_STATE_READY);
|
|
|
|
|
|
|
|
gst_element_sync_state_with_parent (camerabin->audio_queue);
|
|
|
|
gst_element_sync_state_with_parent (camerabin->audio_convert);
|
|
|
|
gst_element_sync_state_with_parent (camerabin->audio_capsfilter);
|
|
|
|
gst_element_sync_state_with_parent (camerabin->audio_volume);
|
|
|
|
}
|
2011-01-20 12:34:39 +00:00
|
|
|
|
2010-11-30 12:28:50 +00:00
|
|
|
g_signal_emit_by_name (camerabin->src, "start-capture", NULL);
|
2011-02-15 17:58:28 +00:00
|
|
|
if (camerabin->mode == MODE_VIDEO && camerabin->audio_src)
|
|
|
|
gst_element_set_state (camerabin->audio_src, GST_STATE_PLAYING);
|
2010-11-26 20:24:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_camera_bin_stop_capture (GstCameraBin * camerabin)
|
|
|
|
{
|
2011-02-28 18:43:46 +00:00
|
|
|
GST_DEBUG_OBJECT (camerabin, "Received stop-capture");
|
2010-12-02 06:44:37 +00:00
|
|
|
if (camerabin->src)
|
|
|
|
g_signal_emit_by_name (camerabin->src, "stop-capture", NULL);
|
2011-01-20 12:34:39 +00:00
|
|
|
|
2011-03-09 17:53:26 +00:00
|
|
|
if (camerabin->mode == MODE_VIDEO && camerabin->audio_src) {
|
|
|
|
gst_element_send_event (camerabin->audio_src, gst_event_new_eos ());
|
2011-01-20 12:34:39 +00:00
|
|
|
gst_element_set_state (camerabin->audio_src, GST_STATE_NULL);
|
2011-03-09 17:53:26 +00:00
|
|
|
}
|
2010-11-26 20:24:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_camera_bin_change_mode (GstCameraBin * camerabin, gint mode)
|
|
|
|
{
|
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)
|
|
|
|
{
|
|
|
|
GstCameraBin *camera = GST_CAMERA_BIN_CAST (user_data);
|
|
|
|
gboolean ready;
|
|
|
|
|
|
|
|
if (camera->mode == MODE_VIDEO) {
|
|
|
|
g_object_get (camera->src, "ready-for-capture", &ready, NULL);
|
|
|
|
if (!ready) {
|
2010-11-30 23:13:27 +00:00
|
|
|
gchar *location;
|
|
|
|
|
2010-12-04 03:27:17 +00:00
|
|
|
/* a video recording is about to start, we reset the videobin to clear eos/flushing state
|
|
|
|
* also need to clean the queue ! capsfilter before it */
|
2010-12-27 14:29:42 +00:00
|
|
|
gst_element_set_state (camera->encodebin, GST_STATE_NULL);
|
|
|
|
gst_element_set_state (camera->videosink, GST_STATE_NULL);
|
2010-12-13 14:53:59 +00:00
|
|
|
gst_element_set_state (camera->videobin_queue, GST_STATE_NULL);
|
|
|
|
gst_element_set_state (camera->videobin_capsfilter, GST_STATE_NULL);
|
|
|
|
location =
|
|
|
|
g_strdup_printf (camera->video_location, camera->video_index++);
|
|
|
|
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);
|
2010-12-27 14:29:42 +00:00
|
|
|
gst_element_set_state (camera->encodebin, GST_STATE_PLAYING);
|
|
|
|
gst_element_set_state (camera->videosink, GST_STATE_PLAYING);
|
2010-12-13 14:53:59 +00:00
|
|
|
gst_element_set_state (camera->videobin_capsfilter, GST_STATE_PLAYING);
|
|
|
|
gst_element_set_state (camera->videobin_queue, GST_STATE_PLAYING);
|
2010-11-30 21:19:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-26 13:14:46 +00:00
|
|
|
static void
|
|
|
|
gst_camera_bin_dispose (GObject * object)
|
|
|
|
{
|
2010-11-26 20:24:58 +00:00
|
|
|
GstCameraBin *camerabin = GST_CAMERA_BIN_CAST (object);
|
|
|
|
|
2010-12-13 14:53:59 +00:00
|
|
|
g_free (camerabin->image_location);
|
|
|
|
g_free (camerabin->video_location);
|
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);
|
|
|
|
if (camerabin->audio_queue)
|
|
|
|
gst_object_unref (camerabin->audio_queue);
|
|
|
|
if (camerabin->audio_convert)
|
|
|
|
gst_object_unref (camerabin->audio_convert);
|
|
|
|
|
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-03-04 09:09:43 +00:00
|
|
|
if (camerabin->encodebin_signal_id)
|
|
|
|
g_signal_handler_disconnect (camerabin->encodebin,
|
|
|
|
camerabin->encodebin_signal_id);
|
|
|
|
|
2010-12-27 14:29:42 +00:00
|
|
|
if (camerabin->videosink)
|
|
|
|
gst_object_unref (camerabin->videosink);
|
|
|
|
if (camerabin->encodebin)
|
|
|
|
gst_object_unref (camerabin->encodebin);
|
2010-12-13 14:53:59 +00:00
|
|
|
if (camerabin->videobin_queue)
|
|
|
|
gst_object_unref (camerabin->videobin_queue);
|
|
|
|
if (camerabin->videobin_capsfilter)
|
|
|
|
gst_object_unref (camerabin->videobin_capsfilter);
|
|
|
|
|
|
|
|
if (camerabin->imagebin)
|
|
|
|
gst_object_unref (camerabin->imagebin);
|
|
|
|
if (camerabin->imagebin_queue)
|
|
|
|
gst_object_unref (camerabin->imagebin_queue);
|
|
|
|
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);
|
|
|
|
|
|
|
|
if (camerabin->user_video_filter)
|
|
|
|
gst_object_unref (camerabin->user_video_filter);
|
|
|
|
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);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
gst_element_class_set_details_simple (element_class, "CameraBin2",
|
|
|
|
"Generic/Bin/Camera", "CameraBin2",
|
|
|
|
"Thiago Santos <thiago.sousa.santos@collabora.co.uk>");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_camera_bin_class_init (GstCameraBinClass * klass)
|
|
|
|
{
|
|
|
|
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);
|
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;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GstCameraBin:mode:
|
|
|
|
*
|
|
|
|
* 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."
|
|
|
|
"Default for images is img_%d and vid_%d for videos",
|
|
|
|
DEFAULT_IMG_LOCATION, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2010-12-13 19:36:19 +00:00
|
|
|
g_object_class_install_property (object_class, PROP_CAMERA_SRC,
|
|
|
|
g_param_spec_object ("camera-src", "Camera source",
|
|
|
|
"The camera source element to be used",
|
|
|
|
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,
|
|
|
|
g_param_spec_object ("audio-src", "Audio source",
|
|
|
|
"The audio source element to be used on video recordings",
|
|
|
|
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,
|
|
|
|
gst_param_spec_mini_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-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",
|
|
|
|
"The video sink of the viewfinder.",
|
|
|
|
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));
|
|
|
|
|
|
|
|
/* 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));
|
|
|
|
|
2010-11-26 20:24:58 +00:00
|
|
|
/**
|
|
|
|
* GstCameraBin::capture-start:
|
|
|
|
* @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,
|
|
|
|
G_STRUCT_OFFSET (GstCameraBinClass, start_capture),
|
|
|
|
NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GstCameraBin::capture-stop:
|
|
|
|
* @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,
|
|
|
|
G_STRUCT_OFFSET (GstCameraBinClass, stop_capture),
|
|
|
|
NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
|
2010-11-26 13:14:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-12-14 21:42:51 +00:00
|
|
|
gst_camera_bin_init (GstCameraBin * 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;
|
|
|
|
camera->video_location = g_strdup (DEFAULT_VID_LOCATION);
|
|
|
|
camera->image_location = g_strdup (DEFAULT_IMG_LOCATION);
|
|
|
|
camera->viewfinderbin = gst_element_factory_make ("viewfinderbin", "vf-bin");
|
|
|
|
|
|
|
|
/* capsfilters are created here as we proxy their caps properties and
|
|
|
|
* this way we avoid having to store the caps while on NULL state to
|
|
|
|
* 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
|
|
|
|
gst_image_capture_bin_post_image_done (GstCameraBin * camera,
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_camera_bin_handle_message (GstBin * bin, GstMessage * message)
|
|
|
|
{
|
|
|
|
if (GST_MESSAGE_TYPE (message) == 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");
|
|
|
|
if (filename) {
|
|
|
|
gst_image_capture_bin_post_image_done (GST_CAMERA_BIN_CAST (bin),
|
|
|
|
filename);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
GST_BIN_CLASS (parent_class)->handle_message (bin, message);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
gst_camera_bin_check_and_replace_filter (GstCameraBin * camera,
|
|
|
|
GstElement ** current_filter, GstElement * new_filter,
|
|
|
|
GstElement * previous_element, GstElement * next_element)
|
|
|
|
{
|
|
|
|
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));
|
|
|
|
gst_element_link_many (previous_element, new_filter, next_element, NULL);
|
|
|
|
} else {
|
|
|
|
gst_element_link (previous_element, next_element);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-04 09:09:43 +00:00
|
|
|
static void
|
|
|
|
encodebin_element_added (GstElement * encodebin, GstElement * new_element,
|
|
|
|
GstCameraBin * camera)
|
|
|
|
{
|
|
|
|
if (g_str_has_prefix (gst_element_get_name (new_element), "audiorate") ||
|
|
|
|
g_str_has_prefix (gst_element_get_name (new_element), "videorate")) {
|
|
|
|
g_object_set (new_element, "skip-to-first", TRUE, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-20 12:34:39 +00:00
|
|
|
#define VIDEO_PAD 1
|
|
|
|
#define AUDIO_PAD 2
|
|
|
|
static GstPad *
|
|
|
|
encodebin_find_pad (GstElement * encodebin, gint pad_type)
|
|
|
|
{
|
|
|
|
GstPad *pad = NULL;
|
|
|
|
GstIterator *iter;
|
|
|
|
gboolean done;
|
|
|
|
|
|
|
|
iter = gst_element_iterate_sink_pads (encodebin);
|
|
|
|
done = FALSE;
|
|
|
|
while (!done) {
|
|
|
|
switch (gst_iterator_next (iter, (gpointer *) & pad)) {
|
|
|
|
case GST_ITERATOR_OK:
|
|
|
|
if (pad_type == VIDEO_PAD) {
|
|
|
|
if (strstr (GST_PAD_NAME (pad), "video") != NULL) {
|
|
|
|
done = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else if (pad_type == AUDIO_PAD) {
|
|
|
|
if (strstr (GST_PAD_NAME (pad), "audio") != NULL) {
|
|
|
|
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;
|
|
|
|
|
|
|
|
klass = GST_ELEMENT_GET_CLASS (encodebin);
|
|
|
|
tmpl = gst_element_class_get_pad_template (klass, pad_type == VIDEO_PAD ?
|
|
|
|
"video_%d" : "audio_%d");
|
|
|
|
|
|
|
|
pad = gst_element_request_pad (encodebin, tmpl, NULL, NULL);
|
|
|
|
gst_object_unref (tmpl);
|
|
|
|
}
|
|
|
|
|
|
|
|
return pad;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_camera_bin_video_profile_has_audio (GstCameraBin * camera)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2010-11-26 17:51:30 +00:00
|
|
|
/**
|
|
|
|
* gst_camera_bin_create_elements:
|
|
|
|
* @param camera: the #GstCameraBin
|
|
|
|
*
|
|
|
|
* Creates all elements inside #GstCameraBin
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
gst_camera_bin_create_elements (GstCameraBin * camera)
|
|
|
|
{
|
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;
|
2010-12-13 19:36:19 +00:00
|
|
|
|
|
|
|
if (!camera->elements_created) {
|
|
|
|
|
2010-12-27 14:29:42 +00:00
|
|
|
camera->encodebin = gst_element_factory_make ("encodebin", NULL);
|
2011-03-04 09:09:43 +00:00
|
|
|
camera->encodebin_signal_id = g_signal_connect (camera->encodebin,
|
|
|
|
"element-added", (GCallback) encodebin_element_added, camera);
|
|
|
|
|
2010-12-27 14:29:42 +00:00
|
|
|
camera->videosink =
|
|
|
|
gst_element_factory_make ("filesink", "videobin-filesink");
|
2010-12-13 19:36:19 +00:00
|
|
|
camera->imagebin = gst_element_factory_make ("imagecapturebin", "imagebin");
|
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 */
|
|
|
|
camera->audio_queue = gst_element_factory_make ("queue", "audio-queue");
|
|
|
|
camera->audio_convert = gst_element_factory_make ("audioconvert",
|
|
|
|
"audio-convert");
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
caps = gst_caps_new_simple ("application/ogg", NULL);
|
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);
|
|
|
|
|
|
|
|
caps = gst_caps_new_simple ("video/x-theora", NULL);
|
|
|
|
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-01-20 12:34:39 +00:00
|
|
|
caps = gst_caps_new_simple ("audio/x-vorbis", NULL);
|
|
|
|
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;
|
2010-12-27 14:29:42 +00:00
|
|
|
}
|
2011-01-11 12:12:24 +00:00
|
|
|
g_object_set (camera->encodebin, "profile", camera->video_profile, NULL);
|
2010-12-13 19:36:19 +00:00
|
|
|
|
|
|
|
camera->videobin_queue =
|
|
|
|
gst_element_factory_make ("queue", "videobin-queue");
|
|
|
|
camera->imagebin_queue =
|
|
|
|
gst_element_factory_make ("queue", "imagebin-queue");
|
|
|
|
camera->viewfinderbin_queue =
|
|
|
|
gst_element_factory_make ("queue", "viewfinderbin-queue");
|
|
|
|
|
2011-02-15 17:59:32 +00:00
|
|
|
g_object_set (camera->viewfinderbin_queue, "leaky", 2, NULL);
|
|
|
|
g_object_set (camera->imagebin_queue, "max-size-time", (guint64) 0, NULL);
|
|
|
|
|
2010-12-13 19:36:19 +00:00
|
|
|
gst_bin_add_many (GST_BIN_CAST (camera),
|
2010-12-27 14:29:42 +00:00
|
|
|
gst_object_ref (camera->encodebin),
|
|
|
|
gst_object_ref (camera->videosink),
|
|
|
|
gst_object_ref (camera->imagebin),
|
2010-12-13 19:36:19 +00:00
|
|
|
gst_object_ref (camera->videobin_queue),
|
|
|
|
gst_object_ref (camera->imagebin_queue),
|
2010-12-14 21:42:51 +00:00
|
|
|
gst_object_ref (camera->viewfinderbin_queue), NULL);
|
2010-12-13 19:36:19 +00:00
|
|
|
|
|
|
|
/* Linking can be optimized TODO */
|
|
|
|
gst_element_link_many (camera->videobin_queue, camera->videobin_capsfilter,
|
2010-12-27 14:29:42 +00:00
|
|
|
NULL);
|
|
|
|
gst_element_link (camera->encodebin, camera->videosink);
|
2011-01-20 12:34:39 +00:00
|
|
|
{
|
|
|
|
GstPad *srcpad;
|
|
|
|
GstPad *sinkpad = NULL;
|
|
|
|
|
|
|
|
srcpad = gst_element_get_static_pad (camera->videobin_capsfilter, "src");
|
|
|
|
sinkpad = encodebin_find_pad (camera->encodebin, VIDEO_PAD);
|
|
|
|
|
|
|
|
gst_pad_link (srcpad, sinkpad);
|
|
|
|
gst_object_unref (sinkpad);
|
|
|
|
gst_object_unref (srcpad);
|
|
|
|
}
|
2010-12-27 14:29:42 +00:00
|
|
|
|
2010-12-13 19:36:19 +00:00
|
|
|
gst_element_link_many (camera->imagebin_queue, camera->imagebin_capsfilter,
|
|
|
|
camera->imagebin, NULL);
|
|
|
|
gst_element_link_many (camera->viewfinderbin_queue,
|
|
|
|
camera->viewfinderbin_capsfilter, camera->viewfinderbin, NULL);
|
|
|
|
/*
|
|
|
|
* 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);
|
2010-12-13 19:36:19 +00:00
|
|
|
|
2010-12-27 14:29:42 +00:00
|
|
|
g_object_set (camera->videosink, "location", camera->video_location, NULL);
|
2010-12-13 19:36:19 +00:00
|
|
|
g_object_set (camera->imagebin, "location", camera->image_location, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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);
|
2010-12-30 03:27:03 +00:00
|
|
|
if (camera->src
|
|
|
|
&& g_object_class_find_property (G_OBJECT_GET_CLASS (camera->src),
|
|
|
|
"preview-caps")) {
|
|
|
|
g_object_set (camera->src, "post-previews", camera->post_previews,
|
2011-01-27 17:39:19 +00:00
|
|
|
"preview-caps", camera->preview_caps, "preview-filter",
|
|
|
|
camera->preview_filter, NULL);
|
2010-12-30 03:27:03 +00:00
|
|
|
}
|
2010-12-13 19:36:19 +00:00
|
|
|
if (new_src) {
|
|
|
|
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);
|
|
|
|
gst_element_link_pads (camera->src, "vfsrc", camera->viewfinderbin_queue,
|
|
|
|
"sink");
|
|
|
|
gst_element_link_pads (camera->src, "imgsrc", camera->imagebin_queue,
|
|
|
|
"sink");
|
|
|
|
gst_element_link_pads (camera->src, "vidsrc", camera->videobin_queue,
|
|
|
|
"sink");
|
|
|
|
}
|
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,
|
|
|
|
camera->user_image_filter, camera->imagebin_queue,
|
|
|
|
camera->imagebin_capsfilter);
|
|
|
|
gst_camera_bin_check_and_replace_filter (camera, &camera->video_filter,
|
|
|
|
camera->user_video_filter, camera->videobin_queue,
|
|
|
|
camera->videobin_capsfilter);
|
|
|
|
gst_camera_bin_check_and_replace_filter (camera, &camera->viewfinder_filter,
|
|
|
|
camera->user_viewfinder_filter, camera->viewfinderbin_queue,
|
|
|
|
camera->viewfinderbin_capsfilter);
|
|
|
|
|
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);
|
|
|
|
gst_bin_remove (GST_BIN_CAST (camera), camera->audio_queue);
|
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_bin_remove (GST_BIN_CAST (camera), camera->audio_convert);
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_element_set_locked_state (camera->audio_src, TRUE);
|
|
|
|
new_audio_src = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (new_audio_src) {
|
|
|
|
gst_bin_add (GST_BIN_CAST (camera), gst_object_ref (camera->audio_src));
|
|
|
|
gst_bin_add (GST_BIN_CAST (camera), gst_object_ref (camera->audio_queue));
|
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));
|
|
|
|
gst_bin_add (GST_BIN_CAST (camera), gst_object_ref (camera->audio_convert));
|
|
|
|
|
|
|
|
gst_element_link_many (camera->audio_src, camera->audio_queue,
|
2011-01-21 13:56:52 +00:00
|
|
|
camera->audio_volume,
|
2011-01-20 12:34:39 +00:00
|
|
|
camera->audio_capsfilter, camera->audio_convert, NULL);
|
|
|
|
{
|
|
|
|
GstPad *srcpad;
|
|
|
|
GstPad *sinkpad = NULL;
|
|
|
|
|
|
|
|
srcpad = gst_element_get_static_pad (camera->audio_convert, "src");
|
|
|
|
sinkpad = encodebin_find_pad (camera->encodebin, AUDIO_PAD);
|
|
|
|
|
|
|
|
gst_pad_link (srcpad, sinkpad);
|
|
|
|
gst_object_unref (srcpad);
|
|
|
|
gst_object_unref (sinkpad);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-26 17:51:30 +00:00
|
|
|
camera->elements_created = TRUE;
|
2010-11-26 13:14:46 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstStateChangeReturn
|
|
|
|
gst_camera_bin_change_state (GstElement * element, GstStateChange trans)
|
|
|
|
{
|
|
|
|
GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
|
|
|
|
GstCameraBin *camera = GST_CAMERA_BIN_CAST (element);
|
|
|
|
|
|
|
|
switch (trans) {
|
|
|
|
case GST_STATE_CHANGE_NULL_TO_READY:
|
|
|
|
if (!gst_camera_bin_create_elements (camera)) {
|
|
|
|
return GST_STATE_CHANGE_FAILURE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
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-01-25 21:10:18 +00:00
|
|
|
if (GST_STATE (camera->videosink) >= GST_STATE_PAUSED)
|
|
|
|
gst_element_set_state (camera->videosink, GST_STATE_READY);
|
2011-01-20 12:34:39 +00:00
|
|
|
if (camera->audio_src)
|
|
|
|
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-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_queue, GST_STATE_READY);
|
|
|
|
gst_element_set_state (camera->audio_volume, GST_STATE_READY);
|
|
|
|
gst_element_set_state (camera->audio_capsfilter, GST_STATE_READY);
|
|
|
|
gst_element_set_state (camera->audio_convert, 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:
|
2010-12-27 14:29:42 +00:00
|
|
|
gst_element_set_state (camera->videosink, GST_STATE_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_queue, GST_STATE_NULL);
|
|
|
|
gst_element_set_state (camera->audio_volume, GST_STATE_NULL);
|
|
|
|
gst_element_set_state (camera->audio_capsfilter, GST_STATE_NULL);
|
|
|
|
gst_element_set_state (camera->audio_convert, GST_STATE_NULL);
|
|
|
|
|
2010-11-26 13:14:46 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-11-30 23:13:27 +00:00
|
|
|
static void
|
|
|
|
gst_camera_bin_set_location (GstCameraBin * camera, const gchar * location)
|
|
|
|
{
|
2010-12-03 15:12:32 +00:00
|
|
|
GST_DEBUG_OBJECT (camera, "Setting mode %d location to %s", camera->mode,
|
|
|
|
location);
|
2010-11-30 23:13:27 +00:00
|
|
|
if (camera->mode == MODE_IMAGE) {
|
2010-12-13 14:53:59 +00:00
|
|
|
if (camera->imagebin)
|
|
|
|
g_object_set (camera->imagebin, "location", location, NULL);
|
|
|
|
g_free (camera->image_location);
|
|
|
|
camera->image_location = g_strdup (location);
|
2010-11-30 23:13:27 +00:00
|
|
|
} else {
|
2010-12-13 14:53:59 +00:00
|
|
|
g_free (camera->video_location);
|
|
|
|
camera->video_location = g_strdup (location);
|
2010-11-30 23:13:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-21 13:56:52 +00:00
|
|
|
static void
|
|
|
|
gst_camera_bin_set_audio_src (GstCameraBin * camera, GstElement * src)
|
|
|
|
{
|
|
|
|
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)
|
|
|
|
g_object_ref (src);
|
|
|
|
camera->user_audio_src = src;
|
|
|
|
}
|
|
|
|
|
2010-12-13 19:36:19 +00:00
|
|
|
static void
|
|
|
|
gst_camera_bin_set_camera_src (GstCameraBin * camera, GstElement * src)
|
|
|
|
{
|
|
|
|
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)
|
|
|
|
g_object_ref (src);
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
GstCameraBin *camera = GST_CAMERA_BIN_CAST (object);
|
|
|
|
|
|
|
|
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));
|
|
|
|
|
|
|
|
g_object_set (camera->audio_capsfilter, "caps",
|
|
|
|
gst_value_get_caps (value), NULL);
|
|
|
|
}
|
|
|
|
break;
|
2010-12-15 17:05:54 +00:00
|
|
|
case PROP_IMAGE_CAPTURE_CAPS:{
|
|
|
|
GstPad *pad = NULL;
|
|
|
|
|
|
|
|
if (camera->src)
|
|
|
|
pad =
|
|
|
|
gst_element_get_static_pad (camera->src,
|
|
|
|
GST_BASE_CAMERA_SRC_IMAGE_PAD_NAME);
|
|
|
|
|
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));
|
|
|
|
|
2010-12-15 17:05:54 +00:00
|
|
|
/* set the capsfilter caps and notify the src to renegotiate */
|
2010-12-14 21:42:51 +00:00
|
|
|
g_object_set (camera->imagebin_capsfilter, "caps",
|
|
|
|
gst_value_get_caps (value), NULL);
|
2010-12-15 17:05:54 +00:00
|
|
|
if (pad) {
|
|
|
|
GST_DEBUG_OBJECT (camera, "Pushing renegotiate on %s",
|
|
|
|
GST_PAD_NAME (pad));
|
|
|
|
GST_PAD_EVENTFUNC (pad) (pad, gst_camera_bin_new_event_renegotiate ());
|
|
|
|
gst_object_unref (pad);
|
|
|
|
}
|
|
|
|
}
|
2010-12-14 21:42:51 +00:00
|
|
|
break;
|
2010-12-15 17:05:54 +00:00
|
|
|
case PROP_VIDEO_CAPTURE_CAPS:{
|
|
|
|
GstPad *pad = NULL;
|
|
|
|
|
|
|
|
if (camera->src)
|
|
|
|
pad =
|
|
|
|
gst_element_get_static_pad (camera->src,
|
|
|
|
GST_BASE_CAMERA_SRC_VIDEO_PAD_NAME);
|
|
|
|
|
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));
|
|
|
|
|
2010-12-15 17:05:54 +00:00
|
|
|
/* set the capsfilter caps and notify the src to renegotiate */
|
2010-12-14 21:42:51 +00:00
|
|
|
g_object_set (camera->videobin_capsfilter, "caps",
|
|
|
|
gst_value_get_caps (value), NULL);
|
2010-12-15 17:05:54 +00:00
|
|
|
if (pad) {
|
|
|
|
GST_DEBUG_OBJECT (camera, "Pushing renegotiate on %s",
|
|
|
|
GST_PAD_NAME (pad));
|
2010-12-26 23:35:47 +00:00
|
|
|
GST_PAD_EVENTFUNC (pad) (pad, gst_camera_bin_new_event_renegotiate ());
|
2010-12-15 17:05:54 +00:00
|
|
|
gst_object_unref (pad);
|
|
|
|
}
|
|
|
|
}
|
2010-12-14 21:42:51 +00:00
|
|
|
break;
|
2011-02-24 21:28:28 +00:00
|
|
|
case PROP_VIEWFINDER_CAPS:{
|
|
|
|
GstPad *pad = NULL;
|
|
|
|
|
|
|
|
if (camera->src)
|
|
|
|
pad =
|
|
|
|
gst_element_get_static_pad (camera->src,
|
|
|
|
GST_BASE_CAMERA_SRC_VIEWFINDER_PAD_NAME);
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (camera,
|
|
|
|
"Setting viewfinder capture caps to %" GST_PTR_FORMAT,
|
|
|
|
gst_value_get_caps (value));
|
|
|
|
|
|
|
|
/* set the capsfilter caps and notify the src to renegotiate */
|
|
|
|
g_object_set (camera->viewfinderbin_capsfilter, "caps",
|
|
|
|
gst_value_get_caps (value), NULL);
|
|
|
|
if (pad) {
|
|
|
|
GST_DEBUG_OBJECT (camera, "Pushing renegotiate on %s",
|
|
|
|
GST_PAD_NAME (pad));
|
|
|
|
GST_PAD_EVENTFUNC (pad) (pad, gst_camera_bin_new_event_renegotiate ());
|
|
|
|
gst_object_unref (pad);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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:
|
|
|
|
camera->video_profile =
|
|
|
|
(GstEncodingProfile *) gst_value_dup_mini_object (value);
|
|
|
|
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-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;
|
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)
|
|
|
|
{
|
|
|
|
GstCameraBin *camera = GST_CAMERA_BIN_CAST (object);
|
|
|
|
|
|
|
|
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:
|
|
|
|
if (camera->mode == MODE_VIDEO) {
|
2010-12-13 14:53:59 +00:00
|
|
|
g_value_set_string (value, camera->video_location);
|
2010-11-30 23:13:27 +00:00
|
|
|
} else {
|
2010-12-13 14:53:59 +00:00
|
|
|
g_value_set_string (value, camera->image_location);
|
2010-11-30 23:13:27 +00:00
|
|
|
}
|
|
|
|
break;
|
2010-12-13 19:36:19 +00:00
|
|
|
case PROP_CAMERA_SRC:
|
|
|
|
g_value_set_object (value, camera->src);
|
|
|
|
break;
|
2011-01-21 13:56:52 +00:00
|
|
|
case PROP_AUDIO_SRC:
|
|
|
|
g_value_set_object (value, camera->audio_src);
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
caps = gst_pad_get_caps_reffed (pad);
|
|
|
|
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;
|
|
|
|
g_object_get (camera->audio_capsfilter, "caps", &caps, NULL);
|
|
|
|
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;
|
|
|
|
g_object_get (camera->imagebin_capsfilter, "caps", &caps, NULL);
|
|
|
|
gst_value_set_caps (value, caps);
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case PROP_VIDEO_CAPTURE_CAPS:{
|
|
|
|
GstCaps *caps = NULL;
|
|
|
|
g_object_get (camera->videobin_capsfilter, "caps", &caps, NULL);
|
|
|
|
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;
|
|
|
|
g_object_get (camera->viewfinderbin_capsfilter, "caps", &caps, NULL);
|
|
|
|
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) {
|
|
|
|
gst_value_set_mini_object (value,
|
|
|
|
(GstMiniObject *) camera->video_profile);
|
|
|
|
}
|
|
|
|
break;
|
2011-01-26 18:27:19 +00:00
|
|
|
case PROP_VIDEO_FILTER:
|
|
|
|
if (camera->video_filter)
|
|
|
|
g_value_set_object (value, camera->video_filter);
|
|
|
|
break;
|
|
|
|
case PROP_IMAGE_FILTER:
|
|
|
|
if (camera->image_filter)
|
|
|
|
g_value_set_object (value, camera->image_filter);
|
|
|
|
break;
|
|
|
|
case PROP_VIEWFINDER_FILTER:
|
|
|
|
if (camera->viewfinder_filter)
|
|
|
|
g_value_set_object (value, camera->viewfinder_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;
|
|
|
|
}
|
2010-11-26 20:24:58 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-26 13:14:46 +00:00
|
|
|
gboolean
|
|
|
|
gst_camera_bin_plugin_init (GstPlugin * plugin)
|
|
|
|
{
|
2010-11-29 13:45:30 +00:00
|
|
|
GST_DEBUG_CATEGORY_INIT (gst_camera_bin_debug, "camerabin2", 0, "CameraBin2");
|
|
|
|
|
2010-11-26 13:14:46 +00:00
|
|
|
return gst_element_register (plugin, "camerabin2", GST_RANK_NONE,
|
|
|
|
gst_camera_bin_get_type ());
|
|
|
|
}
|