| 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 |
#ifdef HAVE_CONFIG_H |
| 31 |
#include "config.h" |
| 32 |
#endif |
| 33 |
|
| 34 |
#include <string.h> |
| 35 |
|
| 36 |
#include <glib.h> |
| 37 |
#include <gst/basecamerabinsrc/gstbasecamerasrc.h> |
| 38 |
#include <glib/gi18n-lib.h> |
| 39 |
|
| 40 |
#include "camerabingeneral.h" |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
gboolean |
| 54 |
gst_camerabin_add_element (GstBin * bin, GstElement * new_elem) |
| 55 |
{ |
| 56 |
return gst_camerabin_add_element_full (bin, NULL, new_elem, NULL); |
| 57 |
} |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
gboolean |
| 74 |
gst_camerabin_add_element_full (GstBin * bin, const gchar * srcpad, |
| 75 |
GstElement * new_elem, const gchar * dstpad) |
| 76 |
{ |
| 77 |
gboolean ret; |
| 78 |
|
| 79 |
g_return_val_if_fail (bin, FALSE); |
| 80 |
g_return_val_if_fail (new_elem, FALSE); |
| 81 |
|
| 82 |
ret = gst_camerabin_try_add_element (bin, srcpad, new_elem, dstpad); |
| 83 |
|
| 84 |
if (!ret) { |
| 85 |
gchar *elem_name = gst_element_get_name (new_elem); |
| 86 |
GST_ELEMENT_ERROR (bin, CORE, NEGOTIATION, (NULL), |
| 87 |
("linking %s failed", elem_name)); |
| 88 |
g_free (elem_name); |
| 89 |
gst_object_unref (new_elem); |
| 90 |
} |
| 91 |
|
| 92 |
return ret; |
| 93 |
} |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
gboolean |
| 109 |
gst_camerabin_try_add_element (GstBin * bin, const gchar * srcpad, |
| 110 |
GstElement * new_elem, const gchar * dstpad) |
| 111 |
{ |
| 112 |
GstPad *bin_pad; |
| 113 |
GstElement *bin_elem; |
| 114 |
gboolean ret = TRUE; |
| 115 |
|
| 116 |
g_return_val_if_fail (bin, FALSE); |
| 117 |
g_return_val_if_fail (new_elem, FALSE); |
| 118 |
|
| 119 |
|
| 120 |
bin_pad = gst_bin_find_unlinked_pad (bin, GST_PAD_SRC); |
| 121 |
|
| 122 |
gst_bin_add (GST_BIN (bin), new_elem); |
| 123 |
|
| 124 |
if (bin_pad) { |
| 125 |
GST_DEBUG_OBJECT (bin, "linking %s to %s:%s", GST_OBJECT_NAME (new_elem), |
| 126 |
GST_DEBUG_PAD_NAME (bin_pad)); |
| 127 |
bin_elem = gst_pad_get_parent_element (bin_pad); |
| 128 |
gst_object_unref (bin_pad); |
| 129 |
if (!gst_element_link_pads_full (bin_elem, srcpad, new_elem, dstpad, |
| 130 |
GST_PAD_LINK_CHECK_CAPS)) { |
| 131 |
gst_object_ref (new_elem); |
| 132 |
gst_bin_remove (bin, new_elem); |
| 133 |
ret = FALSE; |
| 134 |
} |
| 135 |
gst_object_unref (bin_elem); |
| 136 |
} else { |
| 137 |
GST_INFO_OBJECT (bin, "no unlinked source pad in bin"); |
| 138 |
} |
| 139 |
|
| 140 |
return ret; |
| 141 |
} |
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
GstElement * |
| 156 |
gst_camerabin_create_and_add_element (GstBin * bin, const gchar * elem_name, |
| 157 |
const gchar * instance_name) |
| 158 |
{ |
| 159 |
GstElement *new_elem; |
| 160 |
|
| 161 |
g_return_val_if_fail (bin, FALSE); |
| 162 |
g_return_val_if_fail (elem_name, FALSE); |
| 163 |
|
| 164 |
new_elem = gst_element_factory_make (elem_name, instance_name); |
| 165 |
if (!new_elem) { |
| 166 |
GST_ELEMENT_ERROR (bin, CORE, MISSING_PLUGIN, |
| 167 |
(_("Missing element '%s' - check your GStreamer installation."), |
| 168 |
elem_name), (NULL)); |
| 169 |
} else if (!gst_camerabin_add_element (bin, new_elem)) { |
| 170 |
new_elem = NULL; |
| 171 |
} |
| 172 |
|
| 173 |
return new_elem; |
| 174 |
} |
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
static GstElement * |
| 180 |
try_element (GstElement * bin, GstElement * element) |
| 181 |
{ |
| 182 |
GstStateChangeReturn ret; |
| 183 |
|
| 184 |
if (element) { |
| 185 |
ret = gst_element_set_state (element, GST_STATE_READY); |
| 186 |
if (ret == GST_STATE_CHANGE_FAILURE) { |
| 187 |
GST_DEBUG_OBJECT (bin, "failed state change.."); |
| 188 |
gst_element_set_state (element, GST_STATE_NULL); |
| 189 |
gst_object_unref (element); |
| 190 |
element = NULL; |
| 191 |
} |
| 192 |
} |
| 193 |
return element; |
| 194 |
} |
| 195 |
|
| 196 |
GstElement * |
| 197 |
gst_camerabin_setup_default_element (GstBin * bin, GstElement * user_elem, |
| 198 |
const gchar * auto_elem_name, const gchar * default_elem_name, |
| 199 |
const gchar * instance_name) |
| 200 |
{ |
| 201 |
GstElement *elem; |
| 202 |
|
| 203 |
if (user_elem) { |
| 204 |
GST_DEBUG_OBJECT (bin, "trying configured element"); |
| 205 |
elem = try_element (GST_ELEMENT_CAST (bin), gst_object_ref (user_elem)); |
| 206 |
} else { |
| 207 |
|
| 208 |
GST_DEBUG_OBJECT (bin, "trying %s", auto_elem_name); |
| 209 |
elem = gst_element_factory_make (auto_elem_name, instance_name); |
| 210 |
elem = try_element (GST_ELEMENT_CAST (bin), elem); |
| 211 |
if (elem == NULL) { |
| 212 |
|
| 213 |
if (strcmp (default_elem_name, auto_elem_name)) { |
| 214 |
GST_DEBUG_OBJECT (bin, "trying %s", default_elem_name); |
| 215 |
elem = gst_element_factory_make (default_elem_name, instance_name); |
| 216 |
elem = try_element (GST_ELEMENT_CAST (bin), elem); |
| 217 |
} |
| 218 |
} |
| 219 |
} |
| 220 |
return elem; |
| 221 |
} |
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
void |
| 230 |
gst_camerabin_remove_elements_from_bin (GstBin * bin) |
| 231 |
{ |
| 232 |
GstIterator *iter = NULL; |
| 233 |
GValue value = { 0 }; |
| 234 |
GstElement *elem = NULL; |
| 235 |
gboolean done = FALSE; |
| 236 |
|
| 237 |
iter = gst_bin_iterate_elements (bin); |
| 238 |
while (!done) { |
| 239 |
switch (gst_iterator_next (iter, &value)) { |
| 240 |
case GST_ITERATOR_OK: |
| 241 |
elem = (GstElement *) g_value_get_object (&value); |
| 242 |
gst_bin_remove (bin, elem); |
| 243 |
gst_element_set_state (GST_ELEMENT (elem), GST_STATE_NULL); |
| 244 |
|
| 245 |
g_value_unset (&value); |
| 246 |
break; |
| 247 |
case GST_ITERATOR_RESYNC: |
| 248 |
gst_iterator_resync (iter); |
| 249 |
break; |
| 250 |
case GST_ITERATOR_ERROR: |
| 251 |
GST_WARNING_OBJECT (bin, "error in iterating elements"); |
| 252 |
done = TRUE; |
| 253 |
break; |
| 254 |
case GST_ITERATOR_DONE: |
| 255 |
done = TRUE; |
| 256 |
break; |
| 257 |
} |
| 258 |
} |
| 259 |
gst_iterator_free (iter); |
| 260 |
} |