summaryrefslogtreecommitdiff
path: root/recipes-multimedia/gstreamer/gstreamer1.0-plugins-bad/0005-camerabin-Add-one-property-to-set-sink-element-for-v.patch
blob: 14291e9b6469fe97de926857edbef582f3d97643 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
From 74ba87e4a54c7f39e8ee58bff16c47f1f0baad14 Mon Sep 17 00:00:00 2001
From: Song Bing <b06498@freescale.com>
Date: Fri, 13 Mar 2015 17:31:29 +0800
Subject: [PATCH 05/26] camerabin: Add one property to set sink element for
 video recording pipeline

Add one property to set sink element for video recording. Default is
filesink.

https://bugzilla.gnome.org/show_bug.cgi?id=744508

Upstream-Status: Inappropriate [i.MX specific]
---
 gst/camerabin2/gstcamerabin2.c | 73 +++++++++++++++++++++++++++++++++++-------
 gst/camerabin2/gstcamerabin2.h |  1 +
 2 files changed, 63 insertions(+), 11 deletions(-)

diff --git a/gst/camerabin2/gstcamerabin2.c b/gst/camerabin2/gstcamerabin2.c
index 0e4a3c7..6549bcb 100644
--- a/gst/camerabin2/gstcamerabin2.c
+++ b/gst/camerabin2/gstcamerabin2.c
@@ -203,6 +203,7 @@ enum
   PROP_MUTE_AUDIO,
   PROP_AUDIO_CAPTURE_SUPPORTED_CAPS,
   PROP_AUDIO_CAPTURE_CAPS,
+  PROP_VIDEO_SINK,
   PROP_ZOOM,
   PROP_MAX_ZOOM,
   PROP_IMAGE_ENCODING_PROFILE,
@@ -342,7 +343,7 @@ gst_camera_bin_start_capture (GstCameraBin2 * camerabin)
 
   /* check that we have a valid location */
   if (camerabin->mode == MODE_VIDEO) {
-    if (camerabin->location == NULL) {
+    if (camerabin->location == NULL && !camerabin->user_video_sink) {
       GST_ELEMENT_ERROR (camerabin, RESOURCE, OPEN_WRITE,
           (_("File location is set to NULL, please set it to a valid filename")), (NULL));
       return;
@@ -477,10 +478,13 @@ gst_camera_bin_src_notify_readyforcapture (GObject * obj, GParamSpec * pspec,
     if (camera->mode == MODE_VIDEO) {
       /* a video recording is about to start, change the filesink location */
       gst_element_set_state (camera->videosink, GST_STATE_NULL);
-      location = g_strdup_printf (camera->location, camera->capture_index);
-      GST_DEBUG_OBJECT (camera, "Switching videobin location to %s", location);
-      g_object_set (camera->videosink, "location", location, NULL);
-      g_free (location);
+      /* shouldn't set location for user_video_sink */
+      if (!camera->user_video_sink) {
+        location = g_strdup_printf (camera->location, camera->capture_index);
+        GST_DEBUG_OBJECT (camera, "Switching videobin location to %s", location);
+        g_object_set (camera->videosink, "location", location, NULL);
+        g_free (location);
+      }
       if (gst_element_set_state (camera->videosink, GST_STATE_PLAYING) ==
           GST_STATE_CHANGE_FAILURE) {
         /* Resets the latest state change return, that would be a failure
@@ -535,6 +539,8 @@ gst_camera_bin_dispose (GObject * object)
 
   if (camerabin->videosink)
     gst_object_unref (camerabin->videosink);
+  if (camerabin->user_video_sink)
+    gst_object_unref (camerabin->user_video_sink);
   if (camerabin->video_encodebin)
     gst_object_unref (camerabin->video_encodebin);
   if (camerabin->videobin_capsfilter)
@@ -655,6 +661,12 @@ gst_camera_bin_class_init (GstCameraBin2Class * klass)
           " taken into use on the next null to ready transition",
           GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
 
+  g_object_class_install_property (object_class, PROP_VIDEO_SINK,
+      g_param_spec_object ("video-sink", "Video sink",
+          "The video sink element to be used on video recordings. It is only"
+          " taken into use on the next null to ready transition",
+          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 "
@@ -1519,13 +1531,30 @@ gst_camera_bin_create_elements (GstCameraBin2 * camera)
         g_signal_connect (camera->video_encodebin, "element-added",
         (GCallback) encodebin_element_added, camera);
 
-    camera->videosink =
-        gst_element_factory_make ("filesink", "videobin-filesink");
+    /* check if we need to replace the videosink */
+    if (camera->videosink) {
+      if (camera->user_video_sink && camera->user_video_sink != camera->videosink) {
+        gst_bin_remove (GST_BIN_CAST (camera), camera->videosink);
+        gst_object_unref (camera->videosink);
+        camera->videosink = NULL;
+      }
+    }
+
     if (!camera->videosink) {
-      missing_element_name = "filesink";
-      goto missing_element;
+      if (camera->user_video_sink) {
+        camera->videosink = gst_object_ref (camera->user_video_sink);
+      } else {
+        camera->videosink =
+          gst_element_factory_make ("filesink", "videobin-filesink");
+        if (!camera->videosink) {
+          missing_element_name = "filesink";
+          goto missing_element;
+        }
+        g_object_set (camera->videosink, "async", FALSE, NULL);
+      }
     }
-    g_object_set (camera->videosink, "async", FALSE, NULL);
+
+    g_assert (camera->videosink != NULL);
 
     /* audio elements */
     if (!camera->audio_volume) {
@@ -1648,7 +1677,9 @@ gst_camera_bin_create_elements (GstCameraBin2 * camera)
     gst_element_set_locked_state (camera->videosink, TRUE);
     gst_element_set_locked_state (camera->imagesink, TRUE);
 
-    g_object_set (camera->videosink, "location", camera->location, NULL);
+    if (!camera->user_video_sink) {
+      g_object_set (camera->videosink, "location", camera->location, NULL);
+    }
     g_object_set (camera->imagesink, "location", camera->location, NULL);
   }
 
@@ -2014,6 +2045,20 @@ gst_camera_bin_set_audio_src (GstCameraBin2 * camera, GstElement * src)
 }
 
 static void
+gst_camera_bin_set_video_sink (GstCameraBin2 * camera, GstElement * sink)
+{
+  GST_DEBUG_OBJECT (GST_OBJECT (camera),
+      "Setting video sink %" GST_PTR_FORMAT, sink);
+
+  if (camera->user_video_sink)
+    g_object_unref (camera->user_video_sink);
+
+  if (sink)
+    g_object_ref (sink);
+  camera->user_video_sink = sink;
+}
+
+static void
 gst_camera_bin_set_camera_src (GstCameraBin2 * camera, GstElement * src)
 {
   GST_DEBUG_OBJECT (GST_OBJECT (camera),
@@ -2046,6 +2091,9 @@ gst_camera_bin_set_property (GObject * object, guint prop_id,
     case PROP_AUDIO_SRC:
       gst_camera_bin_set_audio_src (camera, g_value_get_object (value));
       break;
+    case PROP_VIDEO_SINK:
+      gst_camera_bin_set_video_sink (camera, g_value_get_object (value));
+      break;
     case PROP_MUTE_AUDIO:
       g_object_set (camera->audio_volume, "mute", g_value_get_boolean (value),
           NULL);
@@ -2229,6 +2277,9 @@ gst_camera_bin_get_property (GObject * object, guint prop_id,
     case PROP_AUDIO_SRC:
       g_value_set_object (value, camera->user_audio_src);
       break;
+    case PROP_VIDEO_SINK:
+      g_value_set_object (value, camera->user_video_sink);
+      break;
     case PROP_MUTE_AUDIO:{
       gboolean mute;
 
diff --git a/gst/camerabin2/gstcamerabin2.h b/gst/camerabin2/gstcamerabin2.h
index ba55a7e..9e090b6 100644
--- a/gst/camerabin2/gstcamerabin2.h
+++ b/gst/camerabin2/gstcamerabin2.h
@@ -71,6 +71,7 @@ struct _GstCameraBin2
   GstElement *video_encodebin;
   gulong video_encodebin_signal_id;
   GstElement *videosink;
+  GstElement *user_video_sink;
   GstElement *videobin_capsfilter;
 
   GstElement *viewfinderbin;
-- 
1.9.1