757
687
+ basecamerasrc_signals[START_CAPTURE_SIGNAL] =
758
+ g_signal_new ("start-capture",
688
+ g_signal_new_class_handler ("start-capture",
759
689
+ G_TYPE_FROM_CLASS (klass),
760
690
+ G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
761
+ G_STRUCT_OFFSET (GstBaseCameraSrcClass, private_start_capture),
691
+ G_CALLBACK (gst_base_camera_src_start_capture),
762
692
+ NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
764
694
+ basecamerasrc_signals[STOP_CAPTURE_SIGNAL] =
765
+ g_signal_new ("stop-capture",
695
+ g_signal_new_class_handler ("stop-capture",
766
696
+ G_TYPE_FROM_CLASS (klass),
767
697
+ G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
768
+ G_STRUCT_OFFSET (GstBaseCameraSrcClass, private_stop_capture),
698
+ G_CALLBACK (gst_base_camera_src_stop_capture),
769
699
+ NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
771
+ /* TODO these should be moved to a private struct
772
+ * that is allocated sequentially to the main struct as said at:
773
+ * http://library.gnome.org/devel/gobject/unstable/gobject-Type-Information.html#g-type-add-class-private
775
+ klass->private_start_capture = gst_base_camera_src_start_capture;
776
+ klass->private_stop_capture = gst_base_camera_src_stop_capture;
778
701
+ gstelement_class->change_state = gst_base_camera_src_change_state;
1107
1025
+#include "gstcamerabinpreview.h"
1108
1026
+#include "gstbasecamerasrc.h"
1110
+static GstFlowReturn
1111
+gst_camerabin_preview_pipeline_new_preroll (GstAppSink * appsink,
1112
+ gpointer user_data)
1028
+GST_DEBUG_CATEGORY_EXTERN (base_camera_src_debug);
1029
+#define GST_CAT_DEFAULT base_camera_src_debug
1031
+static void _gst_camerabin_preview_set_caps (GstCameraBinPreviewPipelineData *
1032
+ preview, GstCaps * caps);
1035
+bus_callback (GstBus * bus, GstMessage * message, gpointer user_data)
1114
+ GstBuffer *buffer;
1116
+ buffer = gst_app_sink_pull_preroll (appsink);
1117
+ gst_buffer_unref (buffer);
1119
+ return GST_FLOW_OK;
1037
+ switch (GST_MESSAGE_TYPE (message)) {
1038
+ case GST_MESSAGE_ERROR:{
1040
+ GstCameraBinPreviewPipelineData *data;
1044
+ gst_message_parse_error (message, &err, NULL);
1045
+ GST_WARNING ("Error from preview pipeline: %s", err->message);
1046
+ g_error_free (err);
1048
+ /* TODO Not sure if we should post an Error or Warning here */
1049
+ GST_ELEMENT_ERROR (data, CORE, FAILED,
1050
+ ("fatal error in preview pipeline, disposing the pipeline"), (NULL));
1052
+ /* Possible error situations:
1053
+ * 1) cond_wait pending. prevent deadlock by signalling the cond
1054
+ * 2) preview_pipeline_post called with new buffer to handle. returns
1055
+ * because data->pipeline is set to null
1056
+ * 3) new preview caps incoming. returns because data->pipeline is null
1059
+ if (data->pipeline) {
1060
+ gst_element_set_state (data->pipeline, GST_STATE_NULL);
1061
+ gst_object_unref (data->pipeline);
1062
+ data->pipeline = NULL;
1065
+ g_cond_signal (data->processing_cond);
1122
1075
+static GstFlowReturn
1162
1123
+ GstCameraBinPreviewPipelineData *data;
1163
1124
+ GstElement *csp;
1165
1125
+ GstElement *vscale;
1166
1126
+ gboolean added = FALSE;
1127
+ gboolean linkfail = FALSE;
1167
1129
+ GstAppSinkCallbacks callbacks = { 0, };
1169
+ data = g_new (GstCameraBinPreviewPipelineData, 1);
1131
+ data = g_new0 (GstCameraBinPreviewPipelineData, 1);
1171
1133
+ data->pipeline = gst_pipeline_new ("preview-pipeline");
1172
1134
+ data->appsrc = gst_element_factory_make ("appsrc", "preview-appsrc");
1173
+ data->capsfilter = gst_element_factory_make ("capsfilter",
1174
+ "preview-capsfilter");
1175
1135
+ data->appsink = gst_element_factory_make ("appsink", "preview-appsink");
1176
+ csp = gst_element_factory_make ("ffmpegcolorspace", "preview-csp0");
1177
+ csp2 = gst_element_factory_make ("ffmpegcolorspace", "preview-csp1");
1136
+ csp = gst_element_factory_make ("ffmpegcolorspace", "preview-csp");
1178
1137
+ vscale = gst_element_factory_make ("videoscale", "preview-vscale");
1180
+ if (!data->appsrc || !data->capsfilter || !data->appsink || !csp ||
1181
+ !csp2 || !vscale) {
1139
+ if (!data->appsrc || !data->appsink || !csp || !vscale) {
1185
+ gst_bin_add_many (GST_BIN (data->pipeline), data->appsrc, data->capsfilter,
1186
+ data->appsink, csp, csp2, vscale, NULL);
1143
+ g_object_set (data->appsrc, "emit-signals", FALSE, NULL);
1144
+ g_object_set (data->appsink, "sync", FALSE, "enable-last-buffer",
1147
+ gst_bin_add_many (GST_BIN (data->pipeline), data->appsrc,
1148
+ data->appsink, csp, vscale, NULL);
1188
1150
+ gst_bin_add (GST_BIN (data->pipeline), gst_object_ref (filter));
1189
1151
+ added = TRUE;
1191
1153
+ if (filter) {
1192
+ if (!gst_element_link_many (data->appsrc, filter, csp, vscale, csp2,
1193
+ data->capsfilter, data->appsink, NULL))
1155
+ GST_PAD_LINK_FAILED (gst_element_link_pads_full (data->appsrc, "src",
1156
+ filter, NULL, GST_PAD_LINK_CHECK_NOTHING));
1158
+ GST_PAD_LINK_FAILED (gst_element_link_pads_full (filter, NULL,
1159
+ vscale, "sink", GST_PAD_LINK_CHECK_CAPS));
1196
+ if (!gst_element_link_many (data->appsrc, csp, vscale, csp2,
1197
+ data->capsfilter, data->appsink, NULL))
1201
+ callbacks.new_preroll = gst_camerabin_preview_pipeline_new_preroll;
1162
+ GST_PAD_LINK_FAILED (gst_element_link_pads_full (data->appsrc, "src",
1163
+ vscale, "sink", GST_PAD_LINK_CHECK_NOTHING));
1167
+ GST_PAD_LINK_FAILED (gst_element_link_pads_full (vscale, "src", csp,
1168
+ "sink", GST_PAD_LINK_CHECK_NOTHING));
1170
+ GST_PAD_LINK_FAILED (gst_element_link_pads_full (csp, "src",
1171
+ data->appsink, "sink", GST_PAD_LINK_CHECK_NOTHING));
1174
+ GST_WARNING ("Failed to link preview pipeline elements");
1202
1178
+ callbacks.new_buffer = gst_camerabin_preview_pipeline_new_buffer;
1203
1179
+ gst_app_sink_set_callbacks ((GstAppSink *) data->appsink, &callbacks, data,
1182
+ bus = gst_pipeline_get_bus (GST_PIPELINE (data->pipeline));
1183
+ gst_bus_add_watch (bus, bus_callback, data);
1184
+ gst_object_unref (bus);
1206
1186
+ g_object_set (data->appsink, "sync", FALSE, NULL);
1208
1188
+ data->element = element;
1209
1189
+ data->filter = filter;
1190
+ data->vscale = vscale;
1192
+ data->processing_lock = g_mutex_new ();
1193
+ data->processing_cond = g_cond_new ();
1195
+ data->pending_preview_caps = NULL;
1196
+ data->processing = 0;
1264
1257
+ g_return_val_if_fail (preview->pipeline != NULL, FALSE);
1265
1258
+ g_return_val_if_fail (buffer, FALSE);
1260
+ g_mutex_lock (preview->processing_lock);
1261
+ g_return_val_if_fail (preview->pipeline != NULL, FALSE);
1263
+ if (preview->pending_preview_caps) {
1264
+ if (preview->processing > 0) {
1265
+ g_cond_wait (preview->processing_cond, preview->processing_lock);
1267
+ _gst_camerabin_preview_set_caps (preview, preview->pending_preview_caps);
1268
+ gst_caps_replace (&preview->pending_preview_caps, NULL);
1271
+ preview->processing++;
1267
1273
+ gst_app_src_push_buffer ((GstAppSrc *) preview->appsrc,
1268
1274
+ gst_buffer_ref (buffer));
1276
+ g_mutex_unlock (preview->processing_lock);
1274
+ * gst_camerabin_preview_set_caps:
1275
+ * @preview: the #GstCameraBinPreviewPipelineData
1276
+ * @caps: the #GstCaps to be set
1278
+ * The caps that preview buffers should have when posted
1282
+gst_camerabin_preview_set_caps (GstCameraBinPreviewPipelineData * preview,
1282
+_gst_camerabin_preview_set_caps (GstCameraBinPreviewPipelineData * preview,
1283
1283
+ GstCaps * caps)
1285
1285
+ GstState state, pending;
1286
1286
+ GstStateChangeReturn ret;
1288
1288
+ g_return_if_fail (preview != NULL);
1289
+ g_return_if_fail (preview->pipeline != NULL);
1290
1291
+ ret = gst_element_get_state (preview->pipeline, &state, &pending, 0);
1291
1292
+ if (ret == GST_STATE_CHANGE_FAILURE) {
1293
1294
+ state = GST_STATE_PLAYING;
1294
1295
+ pending = GST_STATE_VOID_PENDING;
1297
1297
+ gst_element_set_state (preview->pipeline, GST_STATE_NULL);
1298
+ g_object_set (preview->capsfilter, "caps", caps, NULL);
1298
+ g_object_set (preview->appsink, "caps", caps, NULL);
1299
1299
+ if (pending != GST_STATE_VOID_PENDING)
1300
1300
+ state = pending;
1301
1301
+ gst_element_set_state (preview->pipeline, state);
1303
Index: trunk/gst-libs/gst/basecamerabinsrc/gstcamerabinpreview.h
1305
+ * gst_camerabin_preview_set_caps:
1306
+ * @preview: the #GstCameraBinPreviewPipelineData
1307
+ * @caps: the #GstCaps to be set (a new ref will be taken)
1309
+ * The caps that preview buffers should have when posted
1313
+gst_camerabin_preview_set_caps (GstCameraBinPreviewPipelineData * preview,
1316
+ g_return_if_fail (preview != NULL);
1318
+ g_mutex_lock (preview->processing_lock);
1320
+ if (preview->processing == 0) {
1321
+ _gst_camerabin_preview_set_caps (preview, caps);
1323
+ GST_DEBUG ("Preview pipeline busy, storing new caps as pending");
1324
+ gst_caps_replace (&preview->pending_preview_caps, caps);
1326
+ g_mutex_unlock (preview->processing_lock);
1330
+ * gst_camerabin_preview_set_filter:
1331
+ * @preview: the #GstCameraBinPreviewPipelineData
1332
+ * @filter: Custom filter to process preview data (an extra ref is taken)
1334
+ * Set the filter element into preview pipeline.
1336
+ * Returns: %TRUE on success
1339
+gst_camerabin_preview_set_filter (GstCameraBinPreviewPipelineData * preview,
1340
+ GstElement * filter)
1342
+ gboolean ret = TRUE;
1345
+ g_return_val_if_fail (preview != NULL, FALSE);
1347
+ GST_DEBUG ("Preview pipeline setting new filter %p", filter);
1349
+ g_mutex_lock (preview->processing_lock);
1351
+ gst_element_get_state (preview->pipeline, ¤t, NULL, 0);
1353
+ if (preview->processing == 0 && current == GST_STATE_NULL) {
1354
+ gboolean linkfail = FALSE;
1356
+ if (preview->filter) {
1357
+ /* Unlink and remove old filter */
1358
+ gst_element_unlink (preview->appsrc, preview->filter);
1359
+ gst_element_unlink (preview->filter, preview->vscale);
1360
+ gst_bin_remove (GST_BIN (preview->pipeline), preview->filter);
1362
+ /* Make room for filter by breaking the link between appsrc and vcale */
1363
+ gst_element_unlink (preview->appsrc, preview->vscale);
1367
+ /* Add and link the new filter between appsrc and vscale */
1368
+ gst_bin_add (GST_BIN (preview->pipeline), gst_object_ref (filter));
1371
+ GST_PAD_LINK_FAILED (gst_element_link_pads_full (preview->appsrc,
1372
+ "src", filter, NULL, GST_PAD_LINK_CHECK_NOTHING));
1375
+ GST_PAD_LINK_FAILED (gst_element_link_pads_full (filter, NULL,
1376
+ preview->vscale, "sink", GST_PAD_LINK_CHECK_CAPS));
1378
+ /* No filter was given. Just link the appsrc to vscale directly */
1380
+ GST_PAD_LINK_FAILED (gst_element_link_pads_full (preview->appsrc,
1381
+ "src", preview->vscale, "sink", GST_PAD_LINK_CHECK_NOTHING));
1385
+ GST_WARNING ("Linking the filter to pipeline failed");
1388
+ GST_DEBUG ("Linking the filter to pipeline successful");
1389
+ preview->filter = filter;
1392
+ GST_WARNING ("Cannot change filter when pipeline is running");
1395
+ g_mutex_unlock (preview->processing_lock);
1399
Index: gst-plugins-good0.10/gst-libs/gst/basecamerabinsrc/gstcamerabinpreview.h
1304
1400
===================================================================
1306
+++ trunk/gst-libs/gst/basecamerabinsrc/gstcamerabinpreview.h
1401
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
1402
+++ gst-plugins-good0.10/gst-libs/gst/basecamerabinsrc/gstcamerabinpreview.h 2012-02-09 14:44:27.400710798 +0200
1310
1406
+ * Copyright (C) 2008 Nokia Corporation <multimedia@maemo.org>
11989
12153
+ * Boston, MA 02111-1307, USA.
11992
+ * SECTION:element-gstcamerabin2
11994
+ * The gstcamerabin2 element does FIXME stuff.
11996
+ * Note that camerabin2 is still UNSTABLE, EXPERIMENTAL and under heavy
12156
+ * SECTION:element-camerabin2
12158
+ * CameraBin2 is a high-level camera object that encapsulates gstreamer
12159
+ * elements, providing an API for controlling a digital camera.
12162
+ * Note that camerabin2 is still UNSTABLE and under
11997
12163
+ * development.
12166
+ * CameraBin2 has the following main features:
12172
+ * Capture pictures
12175
+ * Display a viewfinder
12178
+ * Post preview images for each capture (video and image)
12180
+ * </itemizedlist>
12183
+ * <title>Usage</title>
12185
+ * Camerabin2 can be created using gst_element_factory_make() just like
12186
+ * any other element. Video or image capture mode can be selected using
12187
+ * the #GstCameraBin2:mode property and the file to save the capture is
12188
+ * selected using #GstCameraBin2:location property.
12190
+ * After creating camerabin2, applications might want to do some
12191
+ * customization (there's a section about this below), then select
12192
+ * the desired mode and start capturing.
12194
+ * In image capture mode, just send a #GstCameraBin:start-capture and a
12195
+ * picture will be captured. When the picture is stored on the selected
12196
+ * location, a %GST_MESSAGE_ELEMENT named 'image-done' will be posted on
12199
+ * In video capture mode, send a #GstCameraBin2:start-capture to start
12200
+ * recording, then send a #GstCameraBin2:stop-capture to stop recording.
12201
+ * Note that both signals are asynchronous, so, calling
12202
+ * #GstCameraBin2:stop-capture doesn't guarantee that the video has been
12203
+ * properly finished yet. Applications should wait for the 'video-done'
12204
+ * message to be posted on the bus.
12206
+ * In both modes, if #GstCameraBin2:post-previews is %TRUE, a #GstBuffer
12207
+ * will be post to the #GstBus in a field named 'buffer', in a
12208
+ * 'preview-image' message of type %GST_MESSAGE_ELEMENT.
12213
+ * <title>Customization</title>
12215
+ * Camerabin2 provides various customization properties, allowing the user
12216
+ * to set custom filters, selecting the viewfinder sink and formats to
12217
+ * use to encode the captured images/videos.
12219
+ * #GstEncodingProfile<!-- -->s are used to tell camerabin2 which formats it
12220
+ * should encode the captures to, those should be set to
12221
+ * #GstCameraBin2:image-profile and #GstCameraBin2:video-profile. Default is
12222
+ * jpeg for images, and ogg (theora and vorbis) for video. If a profile without
12223
+ * an audio stream is set for video, audio will be disabled on recordings.
12225
+ * #GstCameraBin2:preview-caps can be used to select which format preview
12226
+ * images should be posted on the #GstBus. It has to be a raw video format.
12228
+ * Camerabin2 has a #GstCameraBin2:camera-source property so applications can
12229
+ * set their source that will provide buffers for the viewfinder and for
12230
+ * captures. This camera source is a special type of source that has 3 pads.
12231
+ * To use a 'regular' source with a single pad you should use
12232
+ * #GstWrapperCameraBinSource, it will adapt your source and provide 3 pads.
12234
+ * Applications can also select the desired viewfinder sink using
12235
+ * #GstCameraBin2:viewfinder-sink, it is also possible to select the audio
12236
+ * source using #GstCameraBin2:audio-source.
12238
+ * The viewfinder resolution can be configured using
12239
+ * #GstCameraBin2:viewfinder-caps, these #GstCaps should be a subset of
12240
+ * #GstCameraBin2:viewfinder-supported-caps.
12242
+ * To select the desired resolution for captures, camerabin2 provides
12243
+ * #GstCameraBin2:image-capture-caps and #GstCameraBin2:video-capture-caps,
12244
+ * these caps must be a subset of what the source can produce. The allowed
12245
+ * caps can be probed using #GstCameraBin2:image-capture-supported-caps and
12246
+ * #GstCameraBin2:video-capture-supported-caps. In an analogous way, there
12247
+ * are #GstCameraBin2:audio-capture-caps and
12248
+ * #GstCameraBin2:audio-capture-supported-caps.
12250
+ * Camerabin2 also allows applications to insert custom #GstElements on any
12251
+ * of its branches: video capture, image capture, viewfinder and preview.
12252
+ * Check #GstCameraBin2:video-filter, #GstCameraBin2:image-filter,
12253
+ * #GstCameraBin2:viewfinder-filter and #GstCameraBin2:preview-filter.
12258
+ * <title>Example launch line</title>
12260
+ * Unfortunatelly, camerabin2 can't be really used from gst-launch, as you need
12261
+ * to send signals to control it. The following pipeline might be able
12262
+ * to show the viewfinder using all the default elements.
12264
+ * gst-launch -v -m camerabin2
12029
12300
+#include <gst/basecamerabinsrc/gstbasecamerasrc.h>
12030
12301
+#include "gstcamerabin2.h"
12032
+#define GST_CAMERA_BIN_PROCESSING_INC(c) \
12302
+#include <gst/gst-i18n-plugin.h>
12303
+#include <gst/pbutils/pbutils.h>
12305
+#if GLIB_CHECK_VERSION(2,29,6)
12306
+#define gst_camerabin2_atomic_int_add g_atomic_int_add
12308
+#define gst_camerabin2_atomic_int_add g_atomic_int_exchange_and_add
12311
+#define GST_CAMERA_BIN2_PROCESSING_INC(c) \
12034
+ gint bef = g_atomic_int_exchange_and_add (&c->processing_counter, 1); \
12313
+ gint bef = gst_camerabin2_atomic_int_add (&c->processing_counter, 1); \
12035
12314
+ if (bef == 0) \
12036
12315
+ g_object_notify (G_OBJECT (c), "idle"); \
12037
12316
+ GST_DEBUG_OBJECT ((c), "Processing counter incremented to: %d", \
12038
12317
+ bef + 1); \
12041
+#define GST_CAMERA_BIN_PROCESSING_DEC(c) \
12320
+#define GST_CAMERA_BIN2_PROCESSING_DEC(c) \
12043
+ if (g_atomic_int_dec_and_test (&c->processing_counter)) \
12322
+ if (g_atomic_int_dec_and_test (&c->processing_counter)) { \
12044
12323
+ g_object_notify (G_OBJECT (c), "idle"); \
12324
+ GST_DEBUG_OBJECT ((c), "Camerabin now idle"); \
12045
12326
+ GST_DEBUG_OBJECT ((c), "Processing counter decremented"); \
12048
+#define GST_CAMERA_BIN_RESET_PROCESSING_COUNTER(c) \
12329
+#define GST_CAMERA_BIN2_RESET_PROCESSING_COUNTER(c) \
12050
12331
+ g_atomic_int_set (&c->processing_counter, 0); \
12051
12332
+ GST_DEBUG_OBJECT ((c), "Processing counter reset"); \
12112
12394
+ ********************************/
12114
12396
+static GstPipelineClass *parent_class;
12115
+static void gst_camera_bin_class_init (GstCameraBinClass * klass);
12397
+static void gst_camera_bin_class_init (GstCameraBin2Class * klass);
12116
12398
+static void gst_camera_bin_base_init (gpointer klass);
12117
+static void gst_camera_bin_init (GstCameraBin * camera);
12399
+static void gst_camera_bin_init (GstCameraBin2 * camera);
12118
12400
+static void gst_camera_bin_dispose (GObject * object);
12119
12401
+static void gst_camera_bin_finalize (GObject * object);
12121
12403
+static void gst_camera_bin_handle_message (GstBin * bin, GstMessage * message);
12404
+static gboolean gst_camera_bin_send_event (GstElement * element,
12405
+ GstEvent * event);
12407
+#define C_FLAGS(v) ((guint) v)
12408
+#define GST_TYPE_CAM_FLAGS (gst_cam_flags_get_type())
12410
+gst_cam_flags_get_type (void)
12412
+ static const GFlagsValue values[] = {
12413
+ {C_FLAGS (GST_CAM_FLAG_NO_AUDIO_CONVERSION), "Do not use audio conversion "
12414
+ "elements", "no-audio-conversion"},
12415
+ {C_FLAGS (GST_CAM_FLAG_NO_VIDEO_CONVERSION), "Do not use video conversion "
12416
+ "elements", "no-video-conversion"},
12417
+ {C_FLAGS (GST_CAM_FLAG_NO_VIEWFINDER_CONVERSION),
12418
+ "Do not use viewfinder conversion " "elements",
12419
+ "no-viewfinder-conversion"},
12420
+ {C_FLAGS (GST_CAM_FLAG_NO_IMAGE_CONVERSION), "Do not use image conversion "
12421
+ "elements", "no-image-conversion"},
12424
+ static volatile GType id = 0;
12426
+ if (g_once_init_enter ((gsize *) & id)) {
12429
+ _id = g_flags_register_static ("GstCamFlags", values);
12431
+ g_once_init_leave ((gsize *) & id, _id);
12124
+gst_camera_bin_get_type (void)
12438
+gst_camera_bin2_get_type (void)
12126
12440
+ static GType gst_camera_bin_type = 0;
12127
12441
+ static const GInterfaceInfo camerabin_tagsetter_info = {
12175
12489
+ gst_structure_new ("renegotiate", NULL));
12493
+gst_camera_bin_new_event_file_location (const gchar * location)
12495
+ return gst_event_new_custom (GST_EVENT_CUSTOM_DOWNSTREAM,
12496
+ gst_structure_new ("new-location", "location", G_TYPE_STRING, location,
12179
+gst_camera_bin_start_capture (GstCameraBin * camerabin)
12501
+gst_camera_bin_start_capture (GstCameraBin2 * camerabin)
12181
12503
+ const GstTagList *taglist;
12504
+ gint capture_index = camerabin->capture_index;
12505
+ gchar *location = NULL;
12183
12506
+ GST_DEBUG_OBJECT (camerabin, "Received start-capture");
12184
+ GST_CAMERA_BIN_PROCESSING_INC (camerabin);
12508
+ /* check that we have a valid location */
12509
+ if (camerabin->mode == MODE_VIDEO) {
12510
+ if (camerabin->location == NULL) {
12511
+ GST_ELEMENT_ERROR (camerabin, RESOURCE, OPEN_WRITE,
12512
+ (_("File location is set to NULL, please set it to a valid filename")), (NULL));
12516
+ g_mutex_lock (camerabin->video_capture_mutex);
12517
+ while (camerabin->video_state == GST_CAMERA_BIN_VIDEO_FINISHING) {
12518
+ g_cond_wait (camerabin->video_state_cond, camerabin->video_capture_mutex);
12520
+ if (camerabin->video_state != GST_CAMERA_BIN_VIDEO_IDLE) {
12521
+ GST_WARNING_OBJECT (camerabin, "Another video recording is ongoing"
12522
+ " (state %d), cannot start a new one", camerabin->video_state);
12523
+ g_mutex_unlock (camerabin->video_capture_mutex);
12526
+ camerabin->video_state = GST_CAMERA_BIN_VIDEO_STARTING;
12529
+ GST_CAMERA_BIN2_PROCESSING_INC (camerabin);
12531
+ if (camerabin->location)
12532
+ location = g_strdup_printf (camerabin->location, capture_index);
12534
+ if (camerabin->mode == MODE_VIDEO) {
12535
+ if (camerabin->audio_src) {
12536
+ GstClock *clock = gst_pipeline_get_clock (GST_PIPELINE_CAST (camerabin));
12538
+ gst_element_set_state (camerabin->audio_src, GST_STATE_PAUSED);
12540
+ gst_element_set_base_time (camerabin->audio_src,
12541
+ gst_element_get_base_time (GST_ELEMENT_CAST (camerabin)));
12543
+ gst_element_set_clock (camerabin->audio_src, clock);
12544
+ gst_object_unref (clock);
12548
+ /* store the next capture buffer filename */
12549
+ g_mutex_lock (camerabin->image_capture_mutex);
12550
+ camerabin->image_location_list =
12551
+ g_slist_append (camerabin->image_location_list, g_strdup (location));
12552
+ g_mutex_unlock (camerabin->image_capture_mutex);
12555
+ if (camerabin->post_previews) {
12556
+ /* Count processing of preview images too */
12557
+ GST_CAMERA_BIN2_PROCESSING_INC (camerabin);
12558
+ /* store the next preview filename */
12559
+ g_mutex_lock (camerabin->preview_list_mutex);
12560
+ camerabin->preview_location_list =
12561
+ g_slist_append (camerabin->preview_location_list, location);
12562
+ g_mutex_unlock (camerabin->preview_list_mutex);
12564
+ g_free (location);
12567
+ g_signal_emit_by_name (camerabin->src, "start-capture", NULL);
12568
+ if (camerabin->mode == MODE_VIDEO) {
12569
+ camerabin->audio_send_newseg = TRUE;
12570
+ if (camerabin->audio_src)
12571
+ gst_element_set_state (camerabin->audio_src, GST_STATE_PLAYING);
12573
+ camerabin->video_state = GST_CAMERA_BIN_VIDEO_RECORDING;
12574
+ g_mutex_unlock (camerabin->video_capture_mutex);
12578
+ * We have to push tags after start capture because the video elements
12579
+ * might be flushing from the previous capture and are reset only on the
12580
+ * notify from ready for capture going to FALSE
12186
12582
+ taglist = gst_tag_setter_get_tag_list (GST_TAG_SETTER (camerabin));
12583
+ GST_DEBUG_OBJECT (camerabin, "Have tags from application: %"
12584
+ GST_PTR_FORMAT, taglist);
12586
+ if (camerabin->mode == MODE_IMAGE) {
12587
+ /* Store image tags in a list and push them later, this prevents
12588
+ start_capture() from blocking in pad_push_event call */
12589
+ g_mutex_lock (camerabin->image_capture_mutex);
12590
+ camerabin->image_tags_list =
12591
+ g_slist_append (camerabin->image_tags_list,
12592
+ taglist ? gst_tag_list_copy (taglist) : NULL);
12593
+ g_mutex_unlock (camerabin->image_capture_mutex);
12594
+ } else if (taglist) {
12188
12595
+ GstPad *active_pad;
12190
+ GST_DEBUG_OBJECT (camerabin, "Pushing tags from application: %"
12191
+ GST_PTR_FORMAT, taglist);
12193
+ if (camerabin->mode == MODE_IMAGE) {
12194
+ active_pad = gst_element_get_static_pad (camerabin->src,
12195
+ GST_BASE_CAMERA_SRC_IMAGE_PAD_NAME);
12197
+ active_pad = gst_element_get_static_pad (camerabin->src,
12198
+ GST_BASE_CAMERA_SRC_VIDEO_PAD_NAME);
12597
+ active_pad = gst_element_get_static_pad (camerabin->src,
12598
+ GST_BASE_CAMERA_SRC_VIDEO_PAD_NAME);
12201
12599
+ gst_pad_push_event (active_pad,
12202
12600
+ gst_event_new_tag (gst_tag_list_copy (taglist)));
12203
12602
+ gst_object_unref (active_pad);
12206
+ if (camerabin->mode == MODE_VIDEO && camerabin->audio_src) {
12207
+ gst_element_set_state (camerabin->audio_src, GST_STATE_READY);
12208
+ /* need to reset eos status (pads could be flushing) */
12209
+ gst_element_set_state (camerabin->audio_queue, GST_STATE_READY);
12210
+ gst_element_set_state (camerabin->audio_convert, GST_STATE_READY);
12211
+ gst_element_set_state (camerabin->audio_capsfilter, GST_STATE_READY);
12212
+ gst_element_set_state (camerabin->audio_volume, GST_STATE_READY);
12214
+ gst_element_sync_state_with_parent (camerabin->audio_queue);
12215
+ gst_element_sync_state_with_parent (camerabin->audio_convert);
12216
+ gst_element_sync_state_with_parent (camerabin->audio_capsfilter);
12217
+ gst_element_sync_state_with_parent (camerabin->audio_volume);
12220
+ g_signal_emit_by_name (camerabin->src, "start-capture", NULL);
12221
+ if (camerabin->mode == MODE_VIDEO && camerabin->audio_src)
12222
+ gst_element_set_state (camerabin->audio_src, GST_STATE_PLAYING);
12605
+ GST_DEBUG_OBJECT (camerabin, "Start-capture end");
12226
+gst_camera_bin_stop_capture (GstCameraBin * camerabin)
12609
+gst_camera_bin_stop_capture (GstCameraBin2 * camerabin)
12228
12611
+ GST_DEBUG_OBJECT (camerabin, "Received stop-capture");
12229
+ if (camerabin->src)
12230
+ g_signal_emit_by_name (camerabin->src, "stop-capture", NULL);
12612
+ if (camerabin->mode == MODE_VIDEO) {
12613
+ g_mutex_lock (camerabin->video_capture_mutex);
12614
+ if (camerabin->video_state == GST_CAMERA_BIN_VIDEO_RECORDING) {
12615
+ if (camerabin->src)
12616
+ g_signal_emit_by_name (camerabin->src, "stop-capture", NULL);
12232
+ if (camerabin->mode == MODE_VIDEO && camerabin->audio_src) {
12233
+ gst_element_send_event (camerabin->audio_src, gst_event_new_eos ());
12618
+ camerabin->video_state = GST_CAMERA_BIN_VIDEO_FINISHING;
12619
+ if (camerabin->audio_src) {
12620
+ camerabin->audio_drop_eos = FALSE;
12621
+ gst_element_send_event (camerabin->audio_src, gst_event_new_eos ());
12624
+ g_mutex_unlock (camerabin->video_capture_mutex);
12238
+gst_camera_bin_change_mode (GstCameraBin * camerabin, gint mode)
12629
+gst_camera_bin_change_mode (GstCameraBin2 * camerabin, gint mode)
12240
12631
+ if (mode == camerabin->mode)
12253
12644
+gst_camera_bin_src_notify_readyforcapture (GObject * obj, GParamSpec * pspec,
12254
12645
+ gpointer user_data)
12256
+ GstCameraBin *camera = GST_CAMERA_BIN_CAST (user_data);
12647
+ GstCameraBin2 *camera = GST_CAMERA_BIN2_CAST (user_data);
12257
12648
+ gboolean ready;
12259
+ if (camera->mode == MODE_VIDEO) {
12260
+ g_object_get (camera->src, "ready-for-capture", &ready, NULL);
12650
+ g_object_get (camera->src, "ready-for-capture", &ready, NULL);
12652
+ gchar *location = NULL;
12264
+ /* a video recording is about to start, we reset the videobin to clear eos/flushing state
12265
+ * also need to clean the queue ! capsfilter before it */
12266
+ gst_element_set_state (camera->encodebin, GST_STATE_NULL);
12654
+ if (camera->mode == MODE_VIDEO) {
12655
+ /* a video recording is about to start, change the filesink location */
12267
12656
+ gst_element_set_state (camera->videosink, GST_STATE_NULL);
12268
+ gst_element_set_state (camera->videobin_queue, GST_STATE_NULL);
12269
+ gst_element_set_state (camera->videobin_capsfilter, GST_STATE_NULL);
12271
+ g_strdup_printf (camera->video_location, camera->video_index++);
12657
+ location = g_strdup_printf (camera->location, camera->capture_index);
12272
12658
+ GST_DEBUG_OBJECT (camera, "Switching videobin location to %s", location);
12273
12659
+ g_object_set (camera->videosink, "location", location, NULL);
12274
12660
+ g_free (location);
12275
+ gst_element_set_state (camera->encodebin, GST_STATE_PLAYING);
12276
+ gst_element_set_state (camera->videosink, GST_STATE_PLAYING);
12277
+ gst_element_set_state (camera->videobin_capsfilter, GST_STATE_PLAYING);
12278
+ gst_element_set_state (camera->videobin_queue, GST_STATE_PLAYING);
12661
+ if (gst_element_set_state (camera->videosink, GST_STATE_PLAYING) ==
12662
+ GST_STATE_CHANGE_FAILURE) {
12663
+ /* Resets the latest state change return, that would be a failure
12664
+ * and could cause problems in a camerabin2 state change */
12665
+ gst_element_set_state (camera->videosink, GST_STATE_NULL);
12669
+ camera->capture_index++;
12284
12674
+gst_camera_bin_dispose (GObject * object)
12286
+ GstCameraBin *camerabin = GST_CAMERA_BIN_CAST (object);
12676
+ GstCameraBin2 *camerabin = GST_CAMERA_BIN2_CAST (object);
12288
+ g_free (camerabin->image_location);
12289
+ g_free (camerabin->video_location);
12678
+ g_free (camerabin->location);
12679
+ g_mutex_free (camerabin->preview_list_mutex);
12680
+ g_mutex_free (camerabin->image_capture_mutex);
12681
+ g_mutex_free (camerabin->video_capture_mutex);
12682
+ g_cond_free (camerabin->video_state_cond);
12291
12684
+ if (camerabin->src_capture_notify_id)
12292
12685
+ g_signal_handler_disconnect (camerabin->src,
12317
12706
+ if (camerabin->viewfinderbin_capsfilter)
12318
12707
+ gst_object_unref (camerabin->viewfinderbin_capsfilter);
12320
+ if (camerabin->encodebin_signal_id)
12321
+ g_signal_handler_disconnect (camerabin->encodebin,
12322
+ camerabin->encodebin_signal_id);
12324
+ if (camerabin->videosink_probe) {
12325
+ GstPad *pad = gst_element_get_static_pad (camerabin->videosink, "sink");
12326
+ gst_pad_remove_data_probe (pad, camerabin->videosink_probe);
12327
+ gst_object_unref (pad);
12709
+ if (camerabin->video_encodebin_signal_id)
12710
+ g_signal_handler_disconnect (camerabin->video_encodebin,
12711
+ camerabin->video_encodebin_signal_id);
12330
12713
+ if (camerabin->videosink)
12331
12714
+ gst_object_unref (camerabin->videosink);
12332
+ if (camerabin->encodebin)
12333
+ gst_object_unref (camerabin->encodebin);
12334
+ if (camerabin->videobin_queue)
12335
+ gst_object_unref (camerabin->videobin_queue);
12715
+ if (camerabin->video_encodebin)
12716
+ gst_object_unref (camerabin->video_encodebin);
12336
12717
+ if (camerabin->videobin_capsfilter)
12337
12718
+ gst_object_unref (camerabin->videobin_capsfilter);
12339
+ if (camerabin->imagebin)
12340
+ gst_object_unref (camerabin->imagebin);
12341
+ if (camerabin->imagebin_queue)
12342
+ gst_object_unref (camerabin->imagebin_queue);
12720
+ if (camerabin->image_encodebin_signal_id)
12721
+ g_signal_handler_disconnect (camerabin->image_encodebin,
12722
+ camerabin->image_encodebin_signal_id);
12723
+ if (camerabin->imagesink)
12724
+ gst_object_unref (camerabin->imagesink);
12725
+ if (camerabin->image_encodebin)
12726
+ gst_object_unref (camerabin->image_encodebin);
12343
12727
+ if (camerabin->imagebin_capsfilter)
12344
12728
+ gst_object_unref (camerabin->imagebin_capsfilter);
12425
12816
+ g_param_spec_string ("location", "Location",
12426
12817
+ "Location to save the captured files. A %d might be used on the"
12427
12818
+ "filename as a placeholder for a numeric index of the capture."
12428
+ "Default for images is img_%d and vid_%d for videos",
12429
+ DEFAULT_IMG_LOCATION, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
12819
+ "Default is cap_%d",
12820
+ DEFAULT_LOCATION, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
12431
12822
+ g_object_class_install_property (object_class, PROP_CAMERA_SRC,
12432
+ g_param_spec_object ("camera-src", "Camera source",
12433
+ "The camera source element to be used",
12823
+ g_param_spec_object ("camera-source", "Camera source",
12824
+ "The camera source element to be used. It is only taken into use on"
12825
+ " the next null to ready transition",
12434
12826
+ GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
12436
12828
+ g_object_class_install_property (object_class, PROP_AUDIO_SRC,
12437
+ g_param_spec_object ("audio-src", "Audio source",
12438
+ "The audio source element to be used on video recordings",
12829
+ g_param_spec_object ("audio-source", "Audio source",
12830
+ "The audio source element to be used on video recordings. It is only"
12831
+ " taken into use on the next null to ready transition",
12439
12832
+ GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
12441
12834
+ g_object_class_install_property (object_class, PROP_MUTE_AUDIO,
12554
12954
+ * Review before stable
12555
+ * - We use a profile for video recording properties and here we have
12556
+ * elements for image capture. This is slightly inconsistent.
12557
12955
+ * - One problem with using encodebin for images here is how jifmux
12558
12956
+ * autoplugging works. We need to give it a higher rank and fix its
12559
12957
+ * caps (it has image/jpeg on sink and src pads). Preliminary tests
12560
12958
+ * show that jifmux is picked if image/jpeg is the caps of a container
12561
12959
+ * profile. So this could work.
12562
12960
+ * - There seems to be a problem with encodebin for images currently as
12563
+ * it autoplugs a videorate that ony starts outputing buffers after
12961
+ * it autoplugs a videorate that only starts outputing buffers after
12564
12962
+ * getting the 2nd buffer.
12566
+ g_object_class_install_property (object_class, PROP_IMAGE_CAPTURE_ENCODER,
12567
+ g_param_spec_object ("image-capture-encoder", "Image capture encoder",
12568
+ "The image encoder element to be used on image captures.",
12569
+ GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
12964
+ g_object_class_install_property (object_class, PROP_IMAGE_ENCODING_PROFILE,
12965
+ gst_param_spec_mini_object ("image-profile", "Image Profile",
12966
+ "The GstEncodingProfile to use for image captures.",
12967
+ GST_TYPE_ENCODING_PROFILE,
12968
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
12571
+ g_object_class_install_property (object_class, PROP_IMAGE_CAPTURE_MUXER,
12572
+ g_param_spec_object ("image-capture-muxer", "Image capture encoder",
12573
+ "The image encoder element to be used on image captures.",
12574
+ GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
12576
12971
+ g_object_class_install_property (object_class, PROP_IDLE,
12577
12972
+ g_param_spec_boolean ("idle", "Idle",
12603
13008
+ g_signal_new ("start-capture",
12604
13009
+ G_TYPE_FROM_CLASS (klass),
12605
13010
+ G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
12606
+ G_STRUCT_OFFSET (GstCameraBinClass, start_capture),
13011
+ G_STRUCT_OFFSET (GstCameraBin2Class, start_capture),
12607
13012
+ NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
12610
+ * GstCameraBin::capture-stop:
13015
+ * GstCameraBin2::capture-stop:
12611
13016
+ * @camera: the camera bin element
12613
13018
+ camerabin_signals[STOP_CAPTURE_SIGNAL] =
12614
13019
+ g_signal_new ("stop-capture",
12615
13020
+ G_TYPE_FROM_CLASS (klass),
12616
13021
+ G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
12617
+ G_STRUCT_OFFSET (GstCameraBinClass, stop_capture),
13022
+ G_STRUCT_OFFSET (GstCameraBin2Class, stop_capture),
12618
13023
+ NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
12622
+gst_camera_bin_init (GstCameraBin * camera)
13027
+gst_camera_bin_init (GstCameraBin2 * camera)
12624
13029
+ camera->post_previews = DEFAULT_POST_PREVIEWS;
12625
13030
+ camera->mode = DEFAULT_MODE;
12626
+ camera->video_location = g_strdup (DEFAULT_VID_LOCATION);
12627
+ camera->image_location = g_strdup (DEFAULT_IMG_LOCATION);
13031
+ camera->location = g_strdup (DEFAULT_LOCATION);
12628
13032
+ camera->viewfinderbin = gst_element_factory_make ("viewfinderbin", "vf-bin");
12629
+ camera->imagebin = gst_element_factory_make ("imagecapturebin", "imagebin");
12630
13033
+ camera->zoom = DEFAULT_ZOOM;
12631
13034
+ camera->max_zoom = MAX_ZOOM;
13035
+ camera->flags = DEFAULT_FLAGS;
13036
+ camera->preview_list_mutex = g_mutex_new ();
13037
+ camera->image_capture_mutex = g_mutex_new ();
13038
+ camera->video_capture_mutex = g_mutex_new ();
13039
+ camera->video_state_cond = g_cond_new ();
12633
13041
+ /* capsfilters are created here as we proxy their caps properties and
12634
13042
+ * this way we avoid having to store the caps while on NULL state to
13080
+gst_video_capture_bin_post_video_done (GstCameraBin2 * camera)
13084
+ msg = gst_message_new_element (GST_OBJECT_CAST (camera),
13085
+ gst_structure_new ("video-done", NULL));
13087
+ if (!gst_element_post_message (GST_ELEMENT_CAST (camera), msg))
13088
+ GST_WARNING_OBJECT (camera, "Failed to post video-done message");
13092
+gst_camera_bin_skip_next_preview (GstCameraBin2 * camerabin)
13096
+ g_mutex_lock (camerabin->preview_list_mutex);
13097
+ if (camerabin->preview_location_list) {
13098
+ location = camerabin->preview_location_list->data;
13099
+ GST_DEBUG_OBJECT (camerabin, "Skipping preview for %s", location);
13100
+ g_free (location);
13101
+ camerabin->preview_location_list =
13102
+ g_slist_delete_link (camerabin->preview_location_list,
13103
+ camerabin->preview_location_list);
13104
+ GST_CAMERA_BIN2_PROCESSING_DEC (camerabin);
13106
+ GST_WARNING_OBJECT (camerabin, "No previews to skip");
13108
+ g_mutex_unlock (camerabin->preview_list_mutex);
13112
+gst_camera_bin_video_reset_elements (gpointer u_data)
13114
+ GstCameraBin2 *camerabin = GST_CAMERA_BIN2_CAST (u_data);
13116
+ GST_DEBUG_OBJECT (camerabin, "Resetting video elements state");
13117
+ g_mutex_lock (camerabin->video_capture_mutex);
13119
+ /* reset element states to clear eos/flushing pads */
13120
+ gst_element_set_state (camerabin->video_encodebin, GST_STATE_READY);
13121
+ gst_element_set_state (camerabin->videobin_capsfilter, GST_STATE_READY);
13122
+ if (camerabin->video_filter) {
13123
+ gst_element_set_state (camerabin->video_filter, GST_STATE_READY);
13124
+ gst_element_sync_state_with_parent (camerabin->video_filter);
13126
+ gst_element_sync_state_with_parent (camerabin->videobin_capsfilter);
13127
+ gst_element_sync_state_with_parent (camerabin->video_encodebin);
13129
+ if (camerabin->audio_src) {
13130
+ gst_element_set_state (camerabin->audio_capsfilter, GST_STATE_READY);
13131
+ gst_element_set_state (camerabin->audio_volume, GST_STATE_READY);
13133
+ /* FIXME We need to set audiosrc to null to make it resync the ringbuffer
13134
+ * while bug https://bugzilla.gnome.org/show_bug.cgi?id=648359 isn't
13137
+ * Also, we don't reinit the audiosrc to keep audio devices from being open
13138
+ * and running until we really need them */
13139
+ gst_element_set_state (camerabin->audio_src, GST_STATE_NULL);
13141
+ if (camerabin->audio_filter) {
13142
+ gst_element_set_state (camerabin->audio_filter, GST_STATE_READY);
13143
+ gst_element_sync_state_with_parent (camerabin->audio_filter);
13146
+ gst_element_sync_state_with_parent (camerabin->audio_capsfilter);
13147
+ gst_element_sync_state_with_parent (camerabin->audio_volume);
13151
+ GST_DEBUG_OBJECT (camerabin, "Setting video state to idle");
13152
+ camerabin->video_state = GST_CAMERA_BIN_VIDEO_IDLE;
13153
+ g_cond_signal (camerabin->video_state_cond);
13154
+ g_mutex_unlock (camerabin->video_capture_mutex);
13156
+ gst_object_unref (camerabin);
12672
13161
+gst_camera_bin_handle_message (GstBin * bin, GstMessage * message)
13163
+ GstCameraBin2 *camerabin = GST_CAMERA_BIN2_CAST (bin);
13164
+ gboolean dec_counter = FALSE;
12674
13166
+ switch (GST_MESSAGE_TYPE (message)) {
12675
13167
+ case GST_MESSAGE_ELEMENT:{
12676
13168
+ const GstStructure *structure = gst_message_get_structure (message);
12677
13169
+ const gchar *filename;
12679
13171
+ if (gst_structure_has_name (structure, "GstMultiFileSink")) {
12680
+ GST_CAMERA_BIN_PROCESSING_DEC (GST_CAMERA_BIN_CAST (bin));
12681
13172
+ filename = gst_structure_get_string (structure, "filename");
13173
+ GST_DEBUG_OBJECT (bin, "Got file save message from multifilesink, "
13174
+ "image %s has been saved", filename);
12682
13175
+ if (filename) {
12683
+ gst_image_capture_bin_post_image_done (GST_CAMERA_BIN_CAST (bin),
13176
+ gst_image_capture_bin_post_image_done (GST_CAMERA_BIN2_CAST (bin),
13179
+ dec_counter = TRUE;
13180
+ } else if (gst_structure_has_name (structure, "preview-image")) {
13181
+ gchar *location = NULL;
13183
+ g_mutex_lock (camerabin->preview_list_mutex);
13184
+ if (camerabin->preview_location_list) {
13185
+ location = camerabin->preview_location_list->data;
13186
+ camerabin->preview_location_list =
13187
+ g_slist_delete_link (camerabin->preview_location_list,
13188
+ camerabin->preview_location_list);
13189
+ GST_DEBUG_OBJECT (camerabin, "Adding preview location to preview "
13190
+ "message '%s'", location);
13192
+ GST_WARNING_OBJECT (camerabin, "Unexpected preview message received, "
13193
+ "won't be able to put location field into the message. This can "
13194
+ "happen if the source is posting previews while camerabin2 is "
13195
+ "shutting down");
13197
+ g_mutex_unlock (camerabin->preview_list_mutex);
13200
+ GValue value = { 0 };
13201
+ g_value_init (&value, G_TYPE_STRING);
13202
+ g_value_take_string (&value, location);
13203
+ gst_structure_take_value ((GstStructure *) structure, "location",
13207
+ GST_LOG_OBJECT (bin, "received preview-image message");
13208
+ dec_counter = TRUE;
12693
13216
+ gst_message_parse_warning (message, &err, &debug);
12694
13217
+ if (err->domain == GST_RESOURCE_ERROR) {
12695
13218
+ /* some capturing failed */
12696
+ GST_CAMERA_BIN_PROCESSING_DEC (GST_CAMERA_BIN_CAST (bin));
13219
+ GST_WARNING_OBJECT (bin, "Capture failed, reason: %s - %s",
13220
+ err->message, debug);
13221
+ if (camerabin->post_previews) {
13222
+ gst_camera_bin_skip_next_preview (camerabin);
13224
+ dec_counter = TRUE;
13226
+ g_error_free (err);
12700
13230
+ case GST_MESSAGE_EOS:{
12701
13231
+ GstElement *src = GST_ELEMENT (GST_MESSAGE_SRC (message));
12702
+ if (src == GST_CAMERA_BIN_CAST (bin)->videosink) {
13232
+ if (src == GST_CAMERA_BIN2_CAST (bin)->videosink) {
13234
+ g_mutex_lock (camerabin->video_capture_mutex);
12703
13235
+ GST_DEBUG_OBJECT (bin, "EOS from video branch");
12704
+ GST_CAMERA_BIN_PROCESSING_DEC (GST_CAMERA_BIN_CAST (bin));
13236
+ g_assert (camerabin->video_state == GST_CAMERA_BIN_VIDEO_FINISHING);
13238
+ gst_video_capture_bin_post_video_done (GST_CAMERA_BIN2_CAST (bin));
13239
+ dec_counter = TRUE;
13241
+ if (!g_thread_create (gst_camera_bin_video_reset_elements,
13242
+ gst_object_ref (camerabin), FALSE, NULL)) {
13243
+ GST_WARNING_OBJECT (camerabin, "Failed to create thread to "
13244
+ "reset video elements' state, video recordings may not work "
13246
+ gst_object_unref (camerabin);
13247
+ camerabin->video_state = GST_CAMERA_BIN_VIDEO_IDLE;
13250
+ g_mutex_unlock (camerabin->video_capture_mutex);
12883
13456
+gst_camera_bin_src_notify_max_zoom_cb (GObject * self, GParamSpec * pspec,
12884
13457
+ gpointer user_data)
12886
+ GstCameraBin *camera = (GstCameraBin *) user_data;
13459
+ GstCameraBin2 *camera = (GstCameraBin2 *) user_data;
12888
13461
+ g_object_get (self, "max-zoom", &camera->max_zoom, NULL);
12889
13462
+ GST_DEBUG_OBJECT (camera, "Max zoom updated to %f", camera->max_zoom);
12890
13463
+ g_object_notify (G_OBJECT (camera), "max-zoom");
13467
+gst_camera_bin_src_notify_zoom_cb (GObject * self, GParamSpec * pspec,
13468
+ gpointer user_data)
13470
+ GstCameraBin2 *camera = (GstCameraBin2 *) user_data;
13472
+ g_object_get (self, "zoom", &camera->zoom, NULL);
13473
+ GST_DEBUG_OBJECT (camera, "Zoom updated to %f", camera->zoom);
13474
+ g_object_notify (G_OBJECT (camera), "zoom");
13478
+gst_camera_bin_image_src_buffer_probe (GstPad * pad, GstBuffer * buf,
13481
+ gboolean ret = TRUE;
13482
+ GstCameraBin2 *camerabin = data;
13484
+ gchar *location = NULL;
13486
+ GstTagList *tags;
13488
+ g_mutex_lock (camerabin->image_capture_mutex);
13490
+ /* Push pending image tags */
13491
+ if (camerabin->image_tags_list) {
13492
+ tags = camerabin->image_tags_list->data;
13493
+ camerabin->image_tags_list =
13494
+ g_slist_delete_link (camerabin->image_tags_list,
13495
+ camerabin->image_tags_list);
13496
+ GST_DEBUG_OBJECT (camerabin, "Pushing tags from application: %"
13497
+ GST_PTR_FORMAT, tags);
13499
+ peer = gst_pad_get_peer (pad);
13500
+ gst_pad_send_event (peer, gst_event_new_tag (tags));
13501
+ gst_object_unref (peer);
13504
+ GST_DEBUG_OBJECT (camerabin, "No tags from application to send");
13507
+ /* Push image location event */
13508
+ if (camerabin->image_location_list) {
13509
+ location = camerabin->image_location_list->data;
13510
+ camerabin->image_location_list =
13511
+ g_slist_delete_link (camerabin->image_location_list,
13512
+ camerabin->image_location_list);
13513
+ GST_DEBUG_OBJECT (camerabin, "Sending image location change to '%s'",
13516
+ GST_DEBUG_OBJECT (camerabin, "No filename location change to send");
13517
+ g_mutex_unlock (camerabin->image_capture_mutex);
13520
+ g_mutex_unlock (camerabin->image_capture_mutex);
13523
+ evt = gst_camera_bin_new_event_file_location (location);
13524
+ peer = gst_pad_get_peer (pad);
13525
+ gst_pad_send_event (peer, evt);
13526
+ gst_object_unref (peer);
13527
+ g_free (location);
13529
+ /* This means we don't have to encode the capture, it is used for
13530
+ * signaling the application just wants the preview */
13532
+ GST_CAMERA_BIN2_PROCESSING_DEC (camerabin);
13540
+gst_camera_bin_image_sink_event_probe (GstPad * pad, GstEvent * event,
13543
+ GstCameraBin2 *camerabin = data;
13545
+ switch (GST_EVENT_TYPE (event)) {
13546
+ case GST_EVENT_CUSTOM_DOWNSTREAM:{
13547
+ if (gst_event_has_name (event, "new-location")) {
13548
+ const GstStructure *structure = gst_event_get_structure (event);
13549
+ const gchar *filename = gst_structure_get_string (structure,
13552
+ gst_element_set_state (camerabin->imagesink, GST_STATE_NULL);
13553
+ GST_DEBUG_OBJECT (camerabin, "Setting filename to imagesink: %s",
13555
+ g_object_set (camerabin->imagesink, "location", filename, NULL);
13556
+ if (gst_element_set_state (camerabin->imagesink, GST_STATE_PLAYING) ==
13557
+ GST_STATE_CHANGE_FAILURE) {
13558
+ /* Resets the latest state change return, that would be a failure
13559
+ * and could cause problems in a camerabin2 state change */
13560
+ gst_element_set_state (camerabin->imagesink, GST_STATE_NULL);
13573
+gst_camera_bin_audio_src_data_probe (GstPad * pad, GstMiniObject * obj,
13576
+ GstCameraBin2 *camera = data;
13577
+ gboolean ret = TRUE;
13579
+ if (GST_IS_BUFFER (obj)) {
13580
+ if (G_UNLIKELY (camera->audio_send_newseg)) {
13581
+ GstBuffer *buf = GST_BUFFER_CAST (obj);
13582
+ GstClockTime ts = GST_BUFFER_TIMESTAMP (buf);
13585
+ if (!GST_CLOCK_TIME_IS_VALID (ts)) {
13589
+ peer = gst_pad_get_peer (pad);
13590
+ g_return_val_if_fail (peer != NULL, TRUE);
13592
+ gst_pad_send_event (peer, gst_event_new_new_segment (FALSE, 1.0,
13593
+ GST_FORMAT_TIME, ts, -1, 0));
13595
+ gst_object_unref (peer);
13597
+ camera->audio_send_newseg = FALSE;
13600
+ GstEvent *event = GST_EVENT_CAST (obj);
13601
+ if (GST_EVENT_TYPE (event) == GST_EVENT_EOS) {
13602
+ /* we only let an EOS pass when the user is stopping a capture */
13603
+ if (camera->audio_drop_eos) {
13606
+ camera->audio_drop_eos = TRUE;
13607
+ /* should already be false, but reinforce in case no buffers get
13609
+ camera->audio_send_newseg = FALSE;
13611
+ } else if (GST_EVENT_TYPE (event) == GST_EVENT_NEWSEGMENT) {
12894
13620
+ * gst_camera_bin_create_elements:
12895
+ * @param camera: the #GstCameraBin
13621
+ * @param camera: the #GstCameraBin2
12897
+ * Creates all elements inside #GstCameraBin
13623
+ * Creates all elements inside #GstCameraBin2
12899
13625
+ * Each of the pads on the camera source is linked as follows:
12900
13626
+ * .pad ! queue ! capsfilter ! correspondingbin
12903
13629
+ * the camera source pad.
12905
13631
+static gboolean
12906
+gst_camera_bin_create_elements (GstCameraBin * camera)
13632
+gst_camera_bin_create_elements (GstCameraBin2 * camera)
12908
13634
+ gboolean new_src = FALSE;
12909
13635
+ gboolean new_audio_src = FALSE;
12910
13636
+ gboolean has_audio;
12911
13637
+ gboolean profile_switched = FALSE;
13638
+ const gchar *missing_element_name;
13639
+ gint encbin_flags = 0;
12913
13641
+ if (!camera->elements_created) {
12914
+ /* TODO check that elements created in _init were really created */
12915
+ /* TODO add proper missing plugin error handling */
13642
+ /* Check that elements created in _init were really created */
13643
+ if (!(camera->audio_capsfilter && camera->videobin_capsfilter &&
13644
+ camera->imagebin_capsfilter && camera->viewfinderbin_capsfilter)) {
13645
+ missing_element_name = "capsfilter";
13646
+ goto missing_element;
12917
+ camera->encodebin = gst_element_factory_make ("encodebin", NULL);
12918
+ camera->encodebin_signal_id = g_signal_connect (camera->encodebin,
12919
+ "element-added", (GCallback) encodebin_element_added, camera);
13649
+ camera->video_encodebin =
13650
+ gst_element_factory_make ("encodebin", "video-encodebin");
13651
+ if (!camera->video_encodebin) {
13652
+ missing_element_name = "encodebin";
13653
+ goto missing_element;
13655
+ camera->video_encodebin_signal_id =
13656
+ g_signal_connect (camera->video_encodebin, "element-added",
13657
+ (GCallback) encodebin_element_added, camera);
12921
13659
+ camera->videosink =
12922
13660
+ gst_element_factory_make ("filesink", "videobin-filesink");
13661
+ if (!camera->videosink) {
13662
+ missing_element_name = "filesink";
13663
+ goto missing_element;
12923
13665
+ g_object_set (camera->videosink, "async", FALSE, NULL);
12925
13667
+ /* audio elements */
12926
+ camera->audio_queue = gst_element_factory_make ("queue", "audio-queue");
12927
+ camera->audio_convert = gst_element_factory_make ("audioconvert",
12928
+ "audio-convert");
13668
+ if (!camera->audio_volume) {
13669
+ missing_element_name = "volume";
13670
+ goto missing_element;
12930
13673
+ if (camera->video_profile == NULL) {
12931
13674
+ GstEncodingContainerProfile *prof;
12953
13696
+ gst_caps_unref (caps);
12955
13698
+ camera->video_profile = (GstEncodingProfile *) prof;
12956
+ camera->profile_switch = TRUE;
12959
+ camera->videobin_queue =
12960
+ gst_element_factory_make ("queue", "videobin-queue");
12961
+ camera->imagebin_queue =
12962
+ gst_element_factory_make ("queue", "imagebin-queue");
13699
+ camera->video_profile_switch = TRUE;
13702
+ camera->image_encodebin =
13703
+ gst_element_factory_make ("encodebin", "image-encodebin");
13704
+ if (!camera->image_encodebin) {
13705
+ missing_element_name = "encodebin";
13706
+ goto missing_element;
13708
+ /* durations have no meaning for image captures */
13709
+ g_object_set (camera->image_encodebin, "queue-time-max", (guint64) 0, NULL);
13711
+ camera->image_encodebin_signal_id =
13712
+ g_signal_connect (camera->image_encodebin, "element-added",
13713
+ (GCallback) encodebin_element_added, camera);
13715
+ camera->imagesink =
13716
+ gst_element_factory_make ("multifilesink", "imagebin-filesink");
13717
+ if (!camera->imagesink) {
13718
+ missing_element_name = "multifilesink";
13719
+ goto missing_element;
13721
+ g_object_set (camera->imagesink, "async", FALSE, "post-messages", TRUE,
13724
+ if (camera->image_profile == NULL) {
13725
+ GstEncodingContainerProfile *prof;
13726
+ GstEncodingVideoProfile *vprof;
13729
+ caps = gst_caps_new_simple ("image/jpeg", NULL);
13730
+ vprof = gst_encoding_video_profile_new (caps, NULL, NULL, 1);
13731
+ gst_encoding_video_profile_set_variableframerate (vprof, TRUE);
13733
+ prof = gst_encoding_container_profile_new ("jpeg", "jpeg container", caps,
13735
+ gst_encoding_container_profile_add_profile (prof,
13736
+ (GstEncodingProfile *) vprof);
13738
+ gst_caps_unref (caps);
13739
+ camera->image_profile = (GstEncodingProfile *) prof;
13740
+ camera->image_profile_switch = TRUE;
12963
13743
+ camera->viewfinderbin_queue =
12964
13744
+ gst_element_factory_make ("queue", "viewfinderbin-queue");
13745
+ if (!camera->viewfinderbin_queue) {
13746
+ missing_element_name = "queue";
13747
+ goto missing_element;
12966
13750
+ g_object_set (camera->viewfinderbin_queue, "leaky", 2, "silent", TRUE,
12968
+ g_object_set (camera->imagebin_queue, "max-size-time", (guint64) 0,
12969
+ "silent", TRUE, NULL);
12970
+ g_object_set (camera->videobin_queue, "silent", TRUE, NULL);
13751
+ "max-size-time", (guint64) 0, "max-size-bytes", (guint) 0,
13752
+ "max-size-buffers", (guint) 1, NULL);
12972
13754
+ gst_bin_add_many (GST_BIN_CAST (camera),
12973
+ gst_object_ref (camera->encodebin),
13755
+ gst_object_ref (camera->video_encodebin),
12974
13756
+ gst_object_ref (camera->videosink),
12975
+ gst_object_ref (camera->imagebin),
12976
+ gst_object_ref (camera->videobin_queue),
12977
+ gst_object_ref (camera->imagebin_queue),
13757
+ gst_object_ref (camera->image_encodebin),
13758
+ gst_object_ref (camera->imagesink),
12978
13759
+ gst_object_ref (camera->viewfinderbin_queue), NULL);
12980
+ /* Linking can be optimized TODO */
12981
+ gst_element_link_many (camera->videobin_queue, camera->videobin_capsfilter,
12983
+ gst_element_link (camera->encodebin, camera->videosink);
12985
+ gst_element_link_many (camera->imagebin_queue, camera->imagebin_capsfilter,
12986
+ camera->imagebin, NULL);
12987
+ gst_element_link_many (camera->viewfinderbin_queue,
12988
+ camera->viewfinderbin_capsfilter, camera->viewfinderbin, NULL);
13761
+ gst_element_link_pads_full (camera->video_encodebin, "src",
13762
+ camera->videosink, "sink", GST_PAD_LINK_CHECK_NOTHING);
13763
+ gst_element_link_pads_full (camera->image_encodebin, "src",
13764
+ camera->imagesink, "sink", GST_PAD_LINK_CHECK_NOTHING);
13765
+ gst_element_link_pads_full (camera->viewfinderbin_queue, "src",
13766
+ camera->viewfinderbin_capsfilter, "sink", GST_PAD_LINK_CHECK_CAPS);
13767
+ gst_element_link_pads_full (camera->viewfinderbin_capsfilter, "src",
13768
+ camera->viewfinderbin, "sink", GST_PAD_LINK_CHECK_CAPS);
13771
+ /* set an event probe to watch for custom location changes */
13774
+ srcpad = gst_element_get_static_pad (camera->image_encodebin, "src");
13776
+ gst_pad_add_event_probe (srcpad,
13777
+ (GCallback) gst_camera_bin_image_sink_event_probe, camera);
13779
+ gst_object_unref (srcpad);
12990
13783
+ * Video can't get into playing as its internal filesink will open
12991
13784
+ * a file for writing and leave it empty if unused.
12996
13789
+ * starting recording, so we should prepare the video bin.
12998
13791
+ gst_element_set_locked_state (camera->videosink, TRUE);
13792
+ gst_element_set_locked_state (camera->imagesink, TRUE);
13000
+ g_object_set (camera->videosink, "location", camera->video_location, NULL);
13001
+ g_object_set (camera->imagebin, "location", camera->image_location, NULL);
13794
+ g_object_set (camera->videosink, "location", camera->location, NULL);
13795
+ g_object_set (camera->imagesink, "location", camera->location, NULL);
13003
+ if (camera->profile_switch) {
13004
+ GST_DEBUG_OBJECT (camera, "Switching encodebin's profile");
13005
+ g_object_set (camera->encodebin, "profile", camera->video_profile, NULL);
13006
+ gst_camera_bin_link_encodebin (camera, camera->videobin_capsfilter,
13008
+ camera->profile_switch = FALSE;
13798
+ /* propagate the flags property by translating appropriate values
13799
+ * to GstEncFlags values */
13800
+ if (camera->flags & GST_CAM_FLAG_NO_AUDIO_CONVERSION)
13801
+ encbin_flags |= (1 << 0);
13802
+ if (camera->flags & GST_CAM_FLAG_NO_VIDEO_CONVERSION)
13803
+ encbin_flags |= (1 << 1);
13804
+ g_object_set (camera->video_encodebin, "flags", encbin_flags, NULL);
13806
+ /* image encodebin has only video branch so disable its conversion elements
13807
+ * appropriately */
13808
+ if (camera->flags & GST_CAM_FLAG_NO_IMAGE_CONVERSION)
13809
+ g_object_set (camera->image_encodebin, "flags", (1 << 1), NULL);
13811
+ g_object_set (camera->viewfinderbin, "disable-converters",
13812
+ camera->flags & GST_CAM_FLAG_NO_VIEWFINDER_CONVERSION ? TRUE : FALSE,
13815
+ if (camera->video_profile_switch) {
13816
+ GST_DEBUG_OBJECT (camera, "Switching video-encodebin's profile");
13817
+ g_object_set (camera->video_encodebin, "profile", camera->video_profile,
13819
+ if (GST_PAD_LINK_FAILED (gst_camera_bin_link_encodebin (camera,
13820
+ camera->video_encodebin, camera->videobin_capsfilter,
13824
+ camera->video_profile_switch = FALSE;
13010
13826
+ /* used to trigger relinking further down */
13011
13827
+ profile_switched = TRUE;
13830
+ if (camera->image_profile_switch) {
13831
+ GST_DEBUG_OBJECT (camera, "Switching image-encodebin's profile");
13832
+ g_object_set (camera->image_encodebin, "profile", camera->image_profile,
13834
+ if (GST_PAD_LINK_FAILED (gst_camera_bin_link_encodebin (camera,
13835
+ camera->image_encodebin, camera->imagebin_capsfilter,
13839
+ camera->image_profile_switch = FALSE;
13014
13842
+ /* check if we need to replace the camera src */
13015
13843
+ if (camera->src) {
13016
13844
+ if (camera->user_src && camera->user_src != camera->src) {
13045
13873
+ "preview-caps", camera->preview_caps, "preview-filter",
13046
13874
+ camera->preview_filter, NULL);
13876
+ g_signal_connect (G_OBJECT (camera->src), "notify::zoom",
13877
+ (GCallback) gst_camera_bin_src_notify_zoom_cb, camera);
13048
13878
+ g_object_set (camera->src, "zoom", camera->zoom, NULL);
13049
13879
+ g_signal_connect (G_OBJECT (camera->src), "notify::max-zoom",
13050
13880
+ (GCallback) gst_camera_bin_src_notify_max_zoom_cb, camera);
13052
13882
+ if (new_src) {
13883
+ GstPad *imgsrc = gst_element_get_static_pad (camera->src, "imgsrc");
13053
13885
+ gst_bin_add (GST_BIN_CAST (camera), gst_object_ref (camera->src));
13054
13886
+ camera->src_capture_notify_id = g_signal_connect (G_OBJECT (camera->src),
13055
13887
+ "notify::ready-for-capture",
13056
13888
+ G_CALLBACK (gst_camera_bin_src_notify_readyforcapture), camera);
13057
13889
+ gst_element_link_pads (camera->src, "vfsrc", camera->viewfinderbin_queue,
13059
+ gst_element_link_pads (camera->src, "imgsrc", camera->imagebin_queue,
13061
+ gst_element_link_pads (camera->src, "vidsrc", camera->videobin_queue,
13892
+ if (!gst_element_link_pads (camera->src, "imgsrc",
13893
+ camera->imagebin_capsfilter, "sink")) {
13894
+ GST_ERROR_OBJECT (camera,
13895
+ "Failed to link camera source's imgsrc pad to image bin capsfilter");
13898
+ if (!gst_element_link_pads (camera->src, "vidsrc",
13899
+ camera->videobin_capsfilter, "sink")) {
13900
+ GST_ERROR_OBJECT (camera,
13901
+ "Failed to link camera source's vidsrc pad to video bin capsfilter");
13905
+ gst_pad_add_buffer_probe (imgsrc,
13906
+ (GCallback) gst_camera_bin_image_src_buffer_probe, camera);
13907
+ gst_object_unref (imgsrc);
13065
13910
+ gst_camera_bin_check_and_replace_filter (camera, &camera->image_filter,
13066
+ camera->user_image_filter, camera->imagebin_queue,
13067
+ camera->imagebin_capsfilter);
13911
+ camera->user_image_filter, camera->src, camera->imagebin_capsfilter,
13068
13913
+ gst_camera_bin_check_and_replace_filter (camera, &camera->video_filter,
13069
+ camera->user_video_filter, camera->videobin_queue,
13070
+ camera->videobin_capsfilter);
13914
+ camera->user_video_filter, camera->src, camera->videobin_capsfilter,
13071
13916
+ gst_camera_bin_check_and_replace_filter (camera, &camera->viewfinder_filter,
13072
13917
+ camera->user_viewfinder_filter, camera->viewfinderbin_queue,
13073
+ camera->viewfinderbin_capsfilter);
13918
+ camera->viewfinderbin_capsfilter, NULL);
13075
13920
+ /* check if we need to replace the camera audio src */
13076
13921
+ has_audio = gst_camera_bin_video_profile_has_audio (camera);
13102
13949
+ if (new_audio_src) {
13952
+ if (g_object_class_find_property (G_OBJECT_GET_CLASS (camera->audio_src),
13953
+ "provide-clock")) {
13954
+ g_object_set (camera->audio_src, "provide-clock", FALSE, NULL);
13103
13956
+ gst_bin_add (GST_BIN_CAST (camera), gst_object_ref (camera->audio_src));
13104
+ gst_bin_add (GST_BIN_CAST (camera), gst_object_ref (camera->audio_queue));
13105
13957
+ gst_bin_add (GST_BIN_CAST (camera), gst_object_ref (camera->audio_volume));
13106
13958
+ gst_bin_add (GST_BIN_CAST (camera),
13107
13959
+ gst_object_ref (camera->audio_capsfilter));
13108
+ gst_bin_add (GST_BIN_CAST (camera), gst_object_ref (camera->audio_convert));
13110
+ gst_element_link_many (camera->audio_src, camera->audio_queue,
13111
+ camera->audio_volume,
13112
+ camera->audio_capsfilter, camera->audio_convert, NULL);
13961
+ gst_element_link_pads_full (camera->audio_src, "src",
13962
+ camera->audio_volume, "sink", GST_PAD_LINK_CHECK_CAPS);
13963
+ gst_element_link_pads_full (camera->audio_volume, "src",
13964
+ camera->audio_capsfilter, "sink", GST_PAD_LINK_CHECK_CAPS);
13966
+ srcpad = gst_element_get_static_pad (camera->audio_src, "src");
13968
+ /* 1) drop EOS for audiosrc elements that push them on state_changes
13969
+ * (basesrc does this)
13970
+ * 2) Fix newsegment events to have start time = first buffer ts */
13971
+ gst_pad_add_data_probe (srcpad,
13972
+ (GCallback) gst_camera_bin_audio_src_data_probe, camera);
13974
+ gst_object_unref (srcpad);
13977
+ gst_camera_bin_check_and_replace_filter (camera, &camera->audio_filter,
13978
+ camera->user_audio_filter, camera->audio_src, camera->audio_volume,
13115
13982
+ if ((profile_switched && has_audio) || new_audio_src) {
13116
+ gst_camera_bin_link_encodebin (camera, camera->audio_convert, AUDIO_PAD);
13983
+ if (GST_PAD_LINK_FAILED (gst_camera_bin_link_encodebin (camera,
13984
+ camera->video_encodebin, camera->audio_capsfilter,
13119
13990
+ camera->elements_created = TRUE;
13120
13991
+ return TRUE;
13994
+ gst_element_post_message (GST_ELEMENT_CAST (camera),
13995
+ gst_missing_element_message_new (GST_ELEMENT_CAST (camera),
13996
+ missing_element_name));
13997
+ GST_ELEMENT_ERROR (camera, CORE, MISSING_PLUGIN,
13998
+ (_("Missing element '%s' - check your GStreamer installation."),
13999
+ missing_element_name), (NULL));
14003
+ /* FIXME properly clean up */
14008
+_gst_tag_list_free_maybe (GstTagList * taglist)
14011
+ gst_tag_list_free (taglist);
13123
14014
+static GstStateChangeReturn
13124
14015
+gst_camera_bin_change_state (GstElement * element, GstStateChange trans)
13126
14017
+ GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
13127
+ GstCameraBin *camera = GST_CAMERA_BIN_CAST (element);
14018
+ GstCameraBin2 *camera = GST_CAMERA_BIN2_CAST (element);
13129
14021
+ switch (trans) {
13130
14022
+ case GST_STATE_CHANGE_NULL_TO_READY:
13135
14027
+ case GST_STATE_CHANGE_READY_TO_PAUSED:
13136
+ GST_CAMERA_BIN_RESET_PROCESSING_COUNTER (camera);
13142
+ ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, trans);
14028
+ GST_CAMERA_BIN2_RESET_PROCESSING_COUNTER (camera);
14029
+ camera->audio_drop_eos = TRUE;
14030
+ camera->audio_send_newseg = FALSE;
13145
14032
+ case GST_STATE_CHANGE_PAUSED_TO_READY:
13146
14033
+ if (GST_STATE (camera->videosink) >= GST_STATE_PAUSED)
13147
14034
+ gst_element_set_state (camera->videosink, GST_STATE_READY);
14035
+ if (GST_STATE (camera->imagesink) >= GST_STATE_PAUSED)
14036
+ gst_element_set_state (camera->imagesink, GST_STATE_READY);
14038
+ case GST_STATE_CHANGE_READY_TO_NULL:
14039
+ gst_element_set_state (camera->videosink, GST_STATE_NULL);
14040
+ gst_element_set_state (camera->imagesink, GST_STATE_NULL);
14046
+ ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, trans);
14049
+ case GST_STATE_CHANGE_PAUSED_TO_READY:
13148
14050
+ if (camera->audio_src && GST_STATE (camera->audio_src) >= GST_STATE_READY)
13149
14051
+ gst_element_set_state (camera->audio_src, GST_STATE_READY);
13151
14053
+ gst_tag_setter_reset_tags (GST_TAG_SETTER (camera));
13152
+ GST_CAMERA_BIN_RESET_PROCESSING_COUNTER (camera);
14054
+ GST_CAMERA_BIN2_RESET_PROCESSING_COUNTER (camera);
14055
+ camera->video_state = GST_CAMERA_BIN_VIDEO_IDLE;
14057
+ g_mutex_lock (camera->image_capture_mutex);
14058
+ g_slist_foreach (camera->image_location_list, (GFunc) g_free, NULL);
14059
+ g_slist_free (camera->image_location_list);
14060
+ camera->image_location_list = NULL;
14062
+ g_slist_foreach (camera->image_tags_list,
14063
+ (GFunc) _gst_tag_list_free_maybe, NULL);
14064
+ g_slist_free (camera->image_tags_list);
14065
+ camera->image_tags_list = NULL;
14066
+ g_mutex_unlock (camera->image_capture_mutex);
14068
+ g_mutex_lock (camera->preview_list_mutex);
14069
+ g_slist_foreach (camera->preview_location_list, (GFunc) g_free, NULL);
14070
+ g_slist_free (camera->preview_location_list);
14071
+ camera->preview_location_list = NULL;
14072
+ g_mutex_unlock (camera->preview_list_mutex);
13154
14074
+ /* explicitly set to READY as they might be outside of the bin */
13155
+ gst_element_set_state (camera->audio_queue, GST_STATE_READY);
13156
14075
+ gst_element_set_state (camera->audio_volume, GST_STATE_READY);
13157
14076
+ gst_element_set_state (camera->audio_capsfilter, GST_STATE_READY);
13158
+ gst_element_set_state (camera->audio_convert, GST_STATE_READY);
13160
14078
+ case GST_STATE_CHANGE_READY_TO_NULL:
13161
+ gst_element_set_state (camera->videosink, GST_STATE_NULL);
13162
14079
+ if (camera->audio_src)
13163
14080
+ gst_element_set_state (camera->audio_src, GST_STATE_NULL);
13165
14082
+ /* explicitly set to NULL as they might be outside of the bin */
13166
+ gst_element_set_state (camera->audio_queue, GST_STATE_NULL);
13167
14083
+ gst_element_set_state (camera->audio_volume, GST_STATE_NULL);
13168
14084
+ gst_element_set_state (camera->audio_capsfilter, GST_STATE_NULL);
13169
+ gst_element_set_state (camera->audio_convert, GST_STATE_NULL);
13176
14091
+ return ret;
14095
+gst_camera_bin_send_event (GstElement * element, GstEvent * event)
14097
+ GstCameraBin2 *camera = GST_CAMERA_BIN2_CAST (element);
14100
+ /* avoid losing our ref to send_event */
14101
+ gst_event_ref (event);
14103
+ res = GST_ELEMENT_CLASS (parent_class)->send_event (element, event);
14104
+ switch (GST_EVENT_TYPE (event)) {
14105
+ case GST_EVENT_EOS:
14107
+ GstState current;
14109
+ if (camera->videosink) {
14110
+ gst_element_get_state (camera->videosink, ¤t, NULL, 0);
14111
+ if (current <= GST_STATE_READY)
14112
+ gst_element_post_message (camera->videosink,
14113
+ gst_message_new_eos (GST_OBJECT (camera->videosink)));
14115
+ if (camera->imagesink) {
14116
+ gst_element_get_state (camera->imagesink, ¤t, NULL, 0);
14117
+ if (current <= GST_STATE_READY)
14118
+ gst_element_post_message (camera->imagesink,
14119
+ gst_message_new_eos (GST_OBJECT (camera->imagesink)));
14128
+ gst_event_unref (event);
13180
+gst_camera_bin_set_location (GstCameraBin * camera, const gchar * location)
14133
+gst_camera_bin_set_location (GstCameraBin2 * camera, const gchar * location)
13182
14135
+ GST_DEBUG_OBJECT (camera, "Setting mode %d location to %s", camera->mode,
13184
+ if (camera->mode == MODE_IMAGE) {
13185
+ if (camera->imagebin)
13186
+ g_object_set (camera->imagebin, "location", location, NULL);
13187
+ g_free (camera->image_location);
13188
+ camera->image_location = g_strdup (location);
13190
+ g_free (camera->video_location);
13191
+ camera->video_location = g_strdup (location);
14137
+ g_free (camera->location);
14138
+ camera->location = g_strdup (location);
13196
+gst_camera_bin_set_audio_src (GstCameraBin * camera, GstElement * src)
14142
+gst_camera_bin_set_audio_src (GstCameraBin2 * camera, GstElement * src)
13198
14144
+ GST_DEBUG_OBJECT (GST_OBJECT (camera),
13199
14145
+ "Setting audio source %" GST_PTR_FORMAT, src);
13481
14450
+ case PROP_AUDIO_CAPTURE_CAPS:{
13482
14451
+ GstCaps *caps = NULL;
13483
+ g_object_get (camera->audio_capsfilter, "caps", &caps, NULL);
14452
+ if (G_LIKELY (camera->audio_capsfilter)) {
14453
+ g_object_get (camera->audio_capsfilter, "caps", &caps, NULL);
14455
+ GST_WARNING ("Missing audio capsfilter");
13484
14457
+ gst_value_set_caps (value, caps);
13485
14458
+ gst_caps_unref (caps);
13488
14461
+ case PROP_IMAGE_CAPTURE_CAPS:{
13489
14462
+ GstCaps *caps = NULL;
13490
+ g_object_get (camera->imagebin_capsfilter, "caps", &caps, NULL);
14463
+ if (G_LIKELY (camera->imagebin_capsfilter)) {
14464
+ g_object_get (camera->imagebin_capsfilter, "caps", &caps, NULL);
14466
+ GST_WARNING ("Missing imagebin capsfilter");
13491
14468
+ gst_value_set_caps (value, caps);
13492
14469
+ gst_caps_unref (caps);
13495
14472
+ case PROP_VIDEO_CAPTURE_CAPS:{
13496
14473
+ GstCaps *caps = NULL;
13497
+ g_object_get (camera->videobin_capsfilter, "caps", &caps, NULL);
14474
+ if (G_LIKELY (camera->videobin_capsfilter)) {
14475
+ g_object_get (camera->videobin_capsfilter, "caps", &caps, NULL);
14477
+ GST_WARNING ("Missing imagebin capsfilter");
13498
14479
+ gst_value_set_caps (value, caps);
13499
14480
+ gst_caps_unref (caps);
13502
14483
+ case PROP_VIEWFINDER_CAPS:{
13503
14484
+ GstCaps *caps = NULL;
13504
+ g_object_get (camera->viewfinderbin_capsfilter, "caps", &caps, NULL);
14485
+ if (G_LIKELY (camera->viewfinderbin_capsfilter)) {
14486
+ g_object_get (camera->viewfinderbin_capsfilter, "caps", &caps, NULL);
14488
+ GST_WARNING ("Missing imagebin capsfilter");
13505
14490
+ gst_value_set_caps (value, caps);
13506
14491
+ gst_caps_unref (caps);
13603
14587
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
13604
14588
+ * Boston, MA 02111-1307, USA.
13606
+#ifndef _GST_CAMERA_BIN_H_
13607
+#define _GST_CAMERA_BIN_H_
14590
+#ifndef _GST_CAMERA_BIN2_H_
14591
+#define _GST_CAMERA_BIN2_H_
13609
14593
+#include <gst/gst.h>
13610
14594
+#include <gst/pbutils/encoding-profile.h>
13612
14596
+G_BEGIN_DECLS
13614
+#define GST_TYPE_CAMERA_BIN (gst_camera_bin_get_type())
13615
+#define GST_CAMERA_BIN(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_CAMERA_BIN,GstCameraBin))
13616
+#define GST_CAMERA_BIN_CAST(obj) ((GstCameraBin *) obj)
13617
+#define GST_CAMERA_BIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_CAMERA_BIN,GstCameraBinClass))
13618
+#define GST_IS_CAMERA_BIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_CAMERA_BIN))
13619
+#define GST_IS_CAMERA_BIN_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_CAMERA_BIN))
13621
+typedef struct _GstCameraBin GstCameraBin;
13622
+typedef struct _GstCameraBinClass GstCameraBinClass;
13624
+struct _GstCameraBin
14598
+#define GST_TYPE_CAMERA_BIN2 (gst_camera_bin2_get_type())
14599
+#define GST_CAMERA_BIN2(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_CAMERA_BIN2,GstCameraBin2))
14600
+#define GST_CAMERA_BIN2_CAST(obj) ((GstCameraBin2 *) obj)
14601
+#define GST_CAMERA_BIN2_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_CAMERA_BIN2,GstCameraBin2Class))
14602
+#define GST_IS_CAMERA_BIN2(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_CAMERA_BIN2))
14603
+#define GST_IS_CAMERA_BIN2_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_CAMERA_BIN2))
14607
+ /* matches GstEncFlags GST_ENC_FLAG_NO_AUDIO_CONVERSION in encodebin */
14608
+ GST_CAM_FLAG_NO_AUDIO_CONVERSION = (1 << 0),
14609
+ /* matches GstEncFlags GST_ENC_FLAG_NO_VIDEO_CONVERSION in encodebin */
14610
+ GST_CAM_FLAG_NO_VIDEO_CONVERSION = (1 << 1),
14611
+ /* maps to 'disable-converters' property in viewfinderbin */
14612
+ GST_CAM_FLAG_NO_VIEWFINDER_CONVERSION = (1 << 2),
14613
+ /* maps to GstEncFlags GST_ENC_FLAG_NO_VIDEO_CONVERSION in the image bin's
14615
+ GST_CAM_FLAG_NO_IMAGE_CONVERSION = (1 << 3)
14619
+typedef enum _GstCameraBinVideoState
14621
+ GST_CAMERA_BIN_VIDEO_IDLE=0,
14622
+ GST_CAMERA_BIN_VIDEO_STARTING=1,
14623
+ GST_CAMERA_BIN_VIDEO_RECORDING=2,
14624
+ GST_CAMERA_BIN_VIDEO_FINISHING=3
14625
+} GstCameraBinVideoState;
14627
+typedef struct _GstCameraBin2 GstCameraBin2;
14628
+typedef struct _GstCameraBin2Class GstCameraBin2Class;
14630
+struct _GstCameraBin2
13626
14632
+ GstPipeline pipeline;
13629
14635
+ GstElement *user_src;
13630
14636
+ gulong src_capture_notify_id;
13632
+ GstElement *encodebin;
13633
+ gulong encodebin_signal_id;
14638
+ GstElement *video_encodebin;
14639
+ gulong video_encodebin_signal_id;
13634
14640
+ GstElement *videosink;
13635
+ gulong videosink_probe;
13636
+ GstElement *videobin_queue;
13637
14641
+ GstElement *videobin_capsfilter;
13639
14643
+ GstElement *viewfinderbin;
13640
14644
+ GstElement *viewfinderbin_queue;
13641
14645
+ GstElement *viewfinderbin_capsfilter;
13643
+ GstElement *imagebin;
13644
+ GstElement *imagebin_queue;
14647
+ GstElement *image_encodebin;
14648
+ gulong image_encodebin_signal_id;
14649
+ GstElement *imagesink;
13645
14650
+ GstElement *imagebin_capsfilter;
13647
14652
+ GstElement *video_filter;
13648
14653
+ GstElement *image_filter;
13649
14654
+ GstElement *viewfinder_filter;
14655
+ GstElement *audio_filter;
13650
14656
+ GstElement *user_video_filter;
13651
14657
+ GstElement *user_image_filter;
13652
14658
+ GstElement *user_viewfinder_filter;
14659
+ GstElement *user_audio_filter;
13654
14661
+ GstElement *audio_src;
13655
14662
+ GstElement *user_audio_src;
13656
+ GstElement *audio_queue;
13657
14663
+ GstElement *audio_volume;
13658
14664
+ GstElement *audio_capsfilter;
13659
+ GstElement *audio_convert;
13661
14666
+ gint processing_counter; /* atomic int */
13663
+ /* Index of the auto incrementing file index for video recordings */
13664
+ gint video_index;
13666
+ gboolean profile_switch;
14668
+ /* Index of the auto incrementing file index for captures */
14669
+ gint capture_index;
14671
+ GMutex *image_capture_mutex;
14672
+ /* stores list of image locations to be pushed to the image sink
14673
+ * as file location change notifications, they are pushed before
14674
+ * each buffer capture */
14675
+ GSList *image_location_list;
14676
+ /* Store also tags and push them before each captured image */
14677
+ GSList *image_tags_list;
14680
+ * Similar to above, but used for giving names to previews
14682
+ * Need to protect with a mutex as this list is used when the
14683
+ * camera-source posts a preview image. As we have no control
14684
+ * on how the camera-source will behave (we can only tell how
14685
+ * it should), the preview location list might be used in an
14686
+ * inconsistent way.
14687
+ * One example is the camera-source posting a preview image after
14688
+ * camerabin2 was put to ready, when this preview list will be
14689
+ * freed and set to NULL. Concurrent access might lead to crashes in
14690
+ * this situation. (Concurrency from the state-change freeing the
14691
+ * list and the message handling function looking at preview names)
14693
+ GSList *preview_location_list;
14694
+ GMutex *preview_list_mutex;
14696
+ gboolean video_profile_switch;
14697
+ gboolean image_profile_switch;
14699
+ gboolean audio_drop_eos;
14700
+ gboolean audio_send_newseg;
14702
+ GMutex *video_capture_mutex;
14703
+ GCond *video_state_cond;
14704
+ GstCameraBinVideoState video_state;
13668
14706
+ /* properties */
13670
+ gchar *video_location;
13671
+ gchar *image_location;
13672
14709
+ gboolean post_previews;
13673
14710
+ GstCaps *preview_caps;
13674
14711
+ GstElement *preview_filter;
13675
14712
+ GstEncodingProfile *video_profile;
14713
+ GstEncodingProfile *image_profile;
13676
14714
+ gfloat zoom;
13677
14715
+ gfloat max_zoom;
14716
+ GstCamFlags flags;
13679
14718
+ gboolean elements_created;
13682
+struct _GstCameraBinClass
14721
+struct _GstCameraBin2Class
13684
14723
+ GstPipelineClass pipeline_class;
13686
14725
+ /* Action signals */
13687
+ void (*start_capture) (GstCameraBin * camera);
13688
+ void (*stop_capture) (GstCameraBin * camera);
14726
+ void (*start_capture) (GstCameraBin2 * camera);
14727
+ void (*stop_capture) (GstCameraBin2 * camera);
13691
+GType gst_camera_bin_get_type (void);
13692
+gboolean gst_camera_bin_plugin_init (GstPlugin * plugin);
14730
+GType gst_camera_bin2_get_type (void);
14731
+gboolean gst_camera_bin2_plugin_init (GstPlugin * plugin);
13697
Index: trunk/gst/camerabin2/gstimagecapturebin.c
14736
Index: gst-plugins-good0.10/gst/camerabin2/gstimagecapturebin.c
13698
14737
===================================================================
13700
+++ trunk/gst/camerabin2/gstimagecapturebin.c
14738
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
14739
+++ gst-plugins-good0.10/gst/camerabin2/gstimagecapturebin.c 2012-02-09 14:44:27.408711038 +0200
13701
14740
@@ -0,0 +1,352 @@
13702
14741
+/* GStreamer
13703
14742
+ * Copyright (C) 2010 Thiago Santos <thiago.sousa.santos@collabora.co.uk>
14324
15372
+ GstElement *csp = NULL;
14325
15373
+ GstElement *videoscale = NULL;
14326
+ GstPad *pad = NULL;
14327
+ gboolean added = FALSE;
15374
+ GstPad *firstpad = NULL;
15375
+ const gchar *missing_element_name;
15376
+ gboolean newsink = FALSE;
15377
+ gboolean updated_converters = FALSE;
14329
15379
+ GST_DEBUG_OBJECT (vfbin, "Creating internal elements");
14331
+ if (!vfbin->elements_created) {
14332
+ /* create elements */
14333
+ csp = gst_element_factory_make ("ffmpegcolorspace", "vfbin-csp");
14337
+ videoscale = gst_element_factory_make ("videoscale", "vfbin-videoscale");
14341
+ GST_DEBUG_OBJECT (vfbin, "Internal elements created, proceding to linking");
14343
+ /* add and link */
14344
+ gst_bin_add_many (GST_BIN_CAST (vfbin), csp, videoscale, NULL);
14346
+ if (!gst_element_link (csp, videoscale))
14349
+ /* add ghostpad */
14350
+ pad = gst_element_get_static_pad (csp, "sink");
14351
+ if (!gst_ghost_pad_set_target (GST_GHOST_PAD (vfbin->ghostpad), pad))
14353
+ gst_object_unref (pad);
14355
+ vfbin->elements_created = TRUE;
14356
+ GST_DEBUG_OBJECT (vfbin, "Elements succesfully created and linked");
15381
+ /* First check if we need to add/replace the internal sink */
14359
15382
+ if (vfbin->video_sink) {
14360
+ /* check if we need to replace the current one */
14361
15383
+ if (vfbin->user_video_sink && vfbin->video_sink != vfbin->user_video_sink) {
14362
15384
+ gst_bin_remove (GST_BIN_CAST (vfbin), vfbin->video_sink);
14363
15385
+ gst_object_unref (vfbin->video_sink);
14368
15390
+ if (!vfbin->video_sink) {
14369
15391
+ if (vfbin->user_video_sink)
14370
15392
+ vfbin->video_sink = gst_object_ref (vfbin->user_video_sink);
14372
15394
+ vfbin->video_sink = gst_element_factory_make ("autovideosink",
14373
15395
+ "vfbin-sink");
15396
+ if (!vfbin->video_sink) {
15397
+ missing_element_name = "autovideosink";
15398
+ goto missing_element;
14375
15402
+ gst_bin_add (GST_BIN_CAST (vfbin), gst_object_ref (vfbin->video_sink));
15406
+ /* check if we want add/remove the conversion elements */
15407
+ if (vfbin->elements_created && vfbin->disable_converters) {
15408
+ /* remove the elements, user doesn't want them */
15410
+ gst_ghost_pad_set_target (GST_GHOST_PAD (vfbin->ghostpad), NULL);
15411
+ csp = gst_bin_get_by_name (GST_BIN_CAST (vfbin), "vfbin-csp");
15412
+ videoscale = gst_bin_get_by_name (GST_BIN_CAST (vfbin), "vfbin-videoscale");
15414
+ gst_bin_remove (GST_BIN_CAST (vfbin), csp);
15415
+ gst_bin_remove (GST_BIN_CAST (vfbin), videoscale);
15417
+ gst_object_unref (csp);
15418
+ gst_object_unref (videoscale);
15420
+ updated_converters = TRUE;
15421
+ } else if (!vfbin->elements_created && !vfbin->disable_converters) {
15422
+ gst_ghost_pad_set_target (GST_GHOST_PAD (vfbin->ghostpad), NULL);
15424
+ /* add the elements, user wants them */
15425
+ csp = gst_element_factory_make ("ffmpegcolorspace", "vfbin-csp");
15427
+ missing_element_name = "ffmpegcolorspace";
15428
+ goto missing_element;
15430
+ gst_bin_add (GST_BIN_CAST (vfbin), csp);
15432
+ videoscale = gst_element_factory_make ("videoscale", "vfbin->videoscale");
15433
+ if (!videoscale) {
15434
+ missing_element_name = "videoscale";
15435
+ goto missing_element;
15437
+ gst_bin_add (GST_BIN_CAST (vfbin), videoscale);
15439
+ gst_element_link_pads_full (csp, "src", videoscale, "sink",
15440
+ GST_PAD_LINK_CHECK_NOTHING);
15442
+ vfbin->elements_created = TRUE;
15443
+ GST_DEBUG_OBJECT (vfbin, "Elements succesfully created and linked");
15445
+ updated_converters = TRUE;
15447
+ /* otherwise, just leave it as is */
15449
+ /* if sink was replaced -> link it to the internal converters */
15450
+ if (newsink && !vfbin->disable_converters) {
15451
+ gboolean unref = FALSE;
15452
+ if (!videoscale) {
14378
15453
+ videoscale = gst_bin_get_by_name (GST_BIN_CAST (vfbin),
14379
+ "vfbin-videoscale");
14381
+ if (!gst_element_link_pads (videoscale, "src", vfbin->video_sink, "sink")) {
14382
+ GST_WARNING_OBJECT (vfbin, "Failed to link the new sink");
15454
+ "vfbin-videscale");
15458
+ if (!gst_element_link_pads_full (videoscale, "src", vfbin->video_sink,
15459
+ "sink", GST_PAD_LINK_CHECK_CAPS)) {
15460
+ GST_ELEMENT_ERROR (vfbin, CORE, NEGOTIATION, (NULL),
15461
+ ("linking videoscale and viewfindersink failed"));
15465
+ gst_object_unref (videoscale);
15466
+ videoscale = NULL;
15469
+ /* Check if we need a new ghostpad target */
15470
+ if (updated_converters || (newsink && vfbin->disable_converters)) {
15471
+ if (vfbin->disable_converters) {
15472
+ firstpad = gst_element_get_static_pad (vfbin->video_sink, "sink");
15474
+ /* csp should always exist at this point */
15475
+ firstpad = gst_element_get_static_pad (csp, "sink");
15479
+ /* need to change the ghostpad target if firstpad is set */
15481
+ if (!gst_ghost_pad_set_target (GST_GHOST_PAD (vfbin->ghostpad), firstpad))
15483
+ gst_object_unref (firstpad);
14386
15487
+ return TRUE;
15490
+ gst_element_post_message (GST_ELEMENT_CAST (vfbin),
15491
+ gst_missing_element_message_new (GST_ELEMENT_CAST (vfbin),
15492
+ missing_element_name));
15493
+ GST_ELEMENT_ERROR (vfbin, CORE, MISSING_PLUGIN,
15494
+ (_("Missing element '%s' - check your GStreamer installation."),
15495
+ missing_element_name), (NULL));
14389
15499
+ GST_WARNING_OBJECT (vfbin, "Creating internal elements failed");
14391
+ gst_object_unref (pad);
14394
+ gst_object_unref (csp);
14396
+ gst_object_unref (videoscale);
14398
+ gst_bin_remove_many (GST_BIN_CAST (vfbin), csp, videoscale, NULL);
15501
+ gst_object_unref (firstpad);
14400
15502
+ return FALSE;
15054
+ /* hook-up the vf ghostpad */
15055
+ vf_pad = gst_element_get_static_pad (videoscale, "src");
15056
+ gst_ghost_pad_set_target (GST_GHOST_PAD (self->vfsrc), vf_pad);
15057
+ gst_object_unref (vf_pad);
15059
16195
+ gst_pad_set_active (self->vfsrc, TRUE);
15060
16196
+ gst_pad_set_active (self->imgsrc, TRUE); /* XXX ??? */
15061
16197
+ gst_pad_set_active (self->vidsrc, TRUE); /* XXX ??? */
16200
+ /* Do this even if pipeline is constructed */
16202
+ if (self->video_filter) {
16203
+ /* check if we need to replace the current one */
16204
+ if (self->video_filter != self->app_vid_filter) {
16205
+ gst_bin_remove (cbin, self->video_filter);
16206
+ gst_object_unref (self->video_filter);
16207
+ self->video_filter = NULL;
16208
+ filter_csp = gst_bin_get_by_name (cbin, "filter-colorspace");
16209
+ gst_bin_remove (cbin, filter_csp);
16210
+ gst_object_unref (filter_csp);
16211
+ filter_csp = NULL;
16215
+ if (!self->video_filter) {
16216
+ if (self->app_vid_filter) {
16217
+ self->video_filter = gst_object_ref (self->app_vid_filter);
16218
+ filter_csp = gst_element_factory_make ("ffmpegcolorspace",
16219
+ "filter-colorspace");
16220
+ gst_bin_add_many (cbin, self->video_filter, filter_csp, NULL);
16221
+ src_csp = gst_bin_get_by_name (cbin, "src-colorspace");
16222
+ capsfilter = gst_bin_get_by_name (cbin, "src-capsfilter");
16223
+ if (gst_pad_is_linked (gst_element_get_static_pad (src_csp, "src")))
16224
+ gst_element_unlink (src_csp, capsfilter);
16225
+ if (!gst_element_link_many (src_csp, self->video_filter, filter_csp,
16226
+ capsfilter, NULL))
15063
16230
+ ret = TRUE;
15064
16231
+ self->elements_created = TRUE;
15352
+gst_wrapper_camera_bin_src_get_allowed_input_caps (GstBaseCameraSrc * bcamsrc)
15354
+ GstWrapperCameraBinSrc *self = GST_WRAPPER_CAMERA_BIN_SRC (bcamsrc);
15355
+ GstCaps *caps = NULL;
15356
+ GstPad *pad = NULL, *peer_pad = NULL;
15358
+ GstElement *videosrc;
15360
+ videosrc = self->src_vid_src ? self->src_vid_src : self->app_vid_src;
15363
+ GST_WARNING_OBJECT (self, "no videosrc, can't get allowed caps");
15367
+ if (self->allowed_caps) {
15368
+ GST_DEBUG_OBJECT (self, "returning cached caps");
15372
+ pad = gst_element_get_static_pad (videosrc, "src");
15375
+ GST_WARNING_OBJECT (self, "no srcpad in videosrc");
15379
+ state = GST_STATE (videosrc);
15381
+ /* Make this function work also in NULL state */
15382
+ if (state == GST_STATE_NULL) {
15383
+ GST_DEBUG_OBJECT (self, "setting videosrc to ready temporarily");
15384
+ peer_pad = gst_pad_get_peer (pad);
15386
+ gst_pad_unlink (pad, peer_pad);
15388
+ /* Set videosrc to READY to open video device */
15389
+ gst_element_set_locked_state (videosrc, TRUE);
15390
+ gst_element_set_state (videosrc, GST_STATE_READY);
15393
+ self->allowed_caps = gst_pad_get_caps (pad);
15395
+ /* Restore state and re-link if necessary */
15396
+ if (state == GST_STATE_NULL) {
15397
+ GST_DEBUG_OBJECT (self, "restoring videosrc state %d", state);
15398
+ /* Reset videosrc to NULL state, some drivers seem to need this */
15399
+ gst_element_set_state (videosrc, GST_STATE_NULL);
15401
+ gst_pad_link (pad, peer_pad);
15402
+ gst_object_unref (peer_pad);
15404
+ gst_element_set_locked_state (videosrc, FALSE);
15407
+ gst_object_unref (pad);
15410
+ if (self->allowed_caps) {
15411
+ caps = gst_caps_copy (self->allowed_caps);
15413
+ GST_DEBUG_OBJECT (self, "allowed caps:%" GST_PTR_FORMAT, caps);
15419
16523
+ * update_aspect_filter:
15420
16524
+ * @self: camerasrc object