mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-10-04 09:42:19 +00:00
camerabin: set camerabin default sources/sinks like in playbin2. Fixes #574434
This uses same approach like in playbin, namely checking for user defined element, auto{audio,video}{sink,src} and finally DEFAULT_{AUDIO,VIDEO}{SRC,SINK} defines from config.h.
This commit is contained in:
parent
c4190684c5
commit
52e314ef81
5 changed files with 91 additions and 50 deletions
|
@ -246,6 +246,9 @@ AG_GST_SET_ERROR_CXXFLAGS($GST_CVS)
|
||||||
dnl define correct level for debugging messages
|
dnl define correct level for debugging messages
|
||||||
AG_GST_SET_LEVEL_DEFAULT($GST_CVS)
|
AG_GST_SET_LEVEL_DEFAULT($GST_CVS)
|
||||||
|
|
||||||
|
dnl used in examples
|
||||||
|
AG_GST_DEFAULT_ELEMENTS
|
||||||
|
|
||||||
dnl *** plug-ins to include ***
|
dnl *** plug-ins to include ***
|
||||||
|
|
||||||
dnl these are all the gst plug-ins, compilable without additional libs
|
dnl these are all the gst plug-ins, compilable without additional libs
|
||||||
|
|
|
@ -117,7 +117,7 @@ gst_camerabin_try_add_element (GstBin * bin, GstElement * new_elem)
|
||||||
GstElement *
|
GstElement *
|
||||||
gst_camerabin_create_and_add_element (GstBin * bin, const gchar * elem_name)
|
gst_camerabin_create_and_add_element (GstBin * bin, const gchar * elem_name)
|
||||||
{
|
{
|
||||||
GstElement *new_elem = NULL;
|
GstElement *new_elem;
|
||||||
|
|
||||||
new_elem = gst_element_factory_make (elem_name, NULL);
|
new_elem = gst_element_factory_make (elem_name, NULL);
|
||||||
if (!new_elem) {
|
if (!new_elem) {
|
||||||
|
@ -130,6 +130,53 @@ gst_camerabin_create_and_add_element (GstBin * bin, const gchar * elem_name)
|
||||||
return new_elem;
|
return new_elem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* try to change the state of an element. This function returns the element when
|
||||||
|
* the state change could be performed. When this function returns NULL an error
|
||||||
|
* occured and the element is unreffed if @unref is TRUE. */
|
||||||
|
static GstElement *
|
||||||
|
try_element (GstElement * bin, GstElement * element, gboolean unref)
|
||||||
|
{
|
||||||
|
GstStateChangeReturn ret;
|
||||||
|
|
||||||
|
if (element) {
|
||||||
|
ret = gst_element_set_state (element, GST_STATE_READY);
|
||||||
|
if (ret == GST_STATE_CHANGE_FAILURE) {
|
||||||
|
GST_DEBUG_OBJECT (bin, "failed state change..");
|
||||||
|
gst_element_set_state (element, GST_STATE_NULL);
|
||||||
|
if (unref)
|
||||||
|
gst_object_unref (element);
|
||||||
|
element = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return element;
|
||||||
|
}
|
||||||
|
|
||||||
|
GstElement *
|
||||||
|
gst_camerabin_setup_default_element (GstBin * bin, GstElement * user_elem,
|
||||||
|
const gchar * auto_elem_name, const gchar * default_elem_name)
|
||||||
|
{
|
||||||
|
GstElement *elem;
|
||||||
|
|
||||||
|
if (user_elem) {
|
||||||
|
GST_DEBUG_OBJECT (bin, "trying configured element");
|
||||||
|
elem = try_element (bin, user_elem, FALSE);
|
||||||
|
} else {
|
||||||
|
/* only try fallback if no specific sink was chosen */
|
||||||
|
GST_DEBUG_OBJECT (bin, "trying %s", auto_elem_name);
|
||||||
|
elem = gst_element_factory_make (auto_elem_name, NULL);
|
||||||
|
elem = try_element (bin, elem, TRUE);
|
||||||
|
if (elem == NULL) {
|
||||||
|
/* if default sink from config.h is different then try it too */
|
||||||
|
if (strcmp (default_elem_name, auto_elem_name)) {
|
||||||
|
GST_DEBUG_OBJECT (bin, "trying %s", default_elem_name);
|
||||||
|
elem = gst_element_factory_make (default_elem_name, NULL);
|
||||||
|
elem = try_element (bin, elem, TRUE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return elem;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gst_camerabin_remove_elements_from_bin:
|
* gst_camerabin_remove_elements_from_bin:
|
||||||
* @bin: removes all elements from this bin
|
* @bin: removes all elements from this bin
|
||||||
|
|
|
@ -27,6 +27,8 @@ gboolean gst_camerabin_try_add_element (GstBin * bin, GstElement * new_elem);
|
||||||
gboolean gst_camerabin_add_element (GstBin * bin, GstElement * new_elem);
|
gboolean gst_camerabin_add_element (GstBin * bin, GstElement * new_elem);
|
||||||
GstElement *gst_camerabin_create_and_add_element (GstBin * bin, const gchar * elem_name);
|
GstElement *gst_camerabin_create_and_add_element (GstBin * bin, const gchar * elem_name);
|
||||||
|
|
||||||
|
GstElement * gst_camerabin_setup_default_element (GstBin * bin, GstElement *user_elem, const gchar *auto_elem_name, const gchar *default_elem_name);
|
||||||
|
|
||||||
void gst_camerabin_remove_elements_from_bin (GstBin * bin);
|
void gst_camerabin_remove_elements_from_bin (GstBin * bin);
|
||||||
|
|
||||||
gboolean gst_camerabin_drop_eos_probe (GstPad * pad, GstEvent * event, gpointer u_data);
|
gboolean gst_camerabin_drop_eos_probe (GstPad * pad, GstEvent * event, gpointer u_data);
|
||||||
|
|
|
@ -51,6 +51,9 @@
|
||||||
* includes
|
* includes
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
#include "config.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <gst/gst.h>
|
#include <gst/gst.h>
|
||||||
#include "camerabingeneral.h"
|
#include "camerabingeneral.h"
|
||||||
|
@ -63,7 +66,6 @@
|
||||||
|
|
||||||
/* internal element names */
|
/* internal element names */
|
||||||
|
|
||||||
#define DEFAULT_AUD_SRC "pulsesrc"
|
|
||||||
#define DEFAULT_AUD_ENC "vorbisenc"
|
#define DEFAULT_AUD_ENC "vorbisenc"
|
||||||
#define DEFAULT_VID_ENC "theoraenc"
|
#define DEFAULT_VID_ENC "theoraenc"
|
||||||
#define DEFAULT_MUX "oggmux"
|
#define DEFAULT_MUX "oggmux"
|
||||||
|
@ -616,13 +618,12 @@ gst_camerabin_video_create_elements (GstCameraBinVideo * vid)
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
/* Add user set or default audio source element */
|
/* Add user set or default audio source element */
|
||||||
if (vid->user_aud_src) {
|
if (!(vid->aud_src = gst_camerabin_setup_default_element (vidbin,
|
||||||
vid->aud_src = vid->user_aud_src;
|
vid->user_aud_src, "autoaudiosrc", DEFAULT_AUDIOSRC))) {
|
||||||
if (!gst_camerabin_add_element (vidbin, vid->aud_src)) {
|
vid->aud_src = NULL;
|
||||||
goto error;
|
goto error;
|
||||||
}
|
} else {
|
||||||
} else if (!(vid->aud_src =
|
if (!gst_camerabin_add_element (vidbin, vid->aud_src))
|
||||||
gst_camerabin_create_and_add_element (vidbin, DEFAULT_AUD_SRC))) {
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -226,12 +226,6 @@ static guint camerabin_signals[LAST_SIGNAL];
|
||||||
//#define USE_VIEWFINDER_COLOR_CONVERTER 1
|
//#define USE_VIEWFINDER_COLOR_CONVERTER 1
|
||||||
//#define USE_VIEWFINDER_SCALE 1
|
//#define USE_VIEWFINDER_SCALE 1
|
||||||
|
|
||||||
/* internal element names */
|
|
||||||
|
|
||||||
/* FIXME: Make sure this can work with autovideosrc and use that. */
|
|
||||||
#define DEFAULT_SRC_VID_SRC "v4l2src"
|
|
||||||
#define DEFAULT_VIEW_SINK "autovideosink"
|
|
||||||
|
|
||||||
/* message names */
|
/* message names */
|
||||||
#define PREVIEW_MESSAGE_NAME "preview-image"
|
#define PREVIEW_MESSAGE_NAME "preview-image"
|
||||||
#define IMG_CAPTURED_MESSAGE_NAME "image-captured"
|
#define IMG_CAPTURED_MESSAGE_NAME "image-captured"
|
||||||
|
@ -558,16 +552,15 @@ camerabin_create_src_elements (GstCameraBin * camera)
|
||||||
GstBin *cbin = GST_BIN (camera);
|
GstBin *cbin = GST_BIN (camera);
|
||||||
gchar *driver_name = NULL;
|
gchar *driver_name = NULL;
|
||||||
|
|
||||||
if (camera->user_vid_src) {
|
/* Add user set or default video src element */
|
||||||
camera->src_vid_src = camera->user_vid_src;
|
if (!(camera->src_vid_src = gst_camerabin_setup_default_element (cbin,
|
||||||
|
camera->user_vid_src, "autovideosrc", DEFAULT_VIDEOSRC))) {
|
||||||
if (!gst_camerabin_add_element (cbin, camera->src_vid_src)) {
|
|
||||||
camera->src_vid_src = NULL;
|
camera->src_vid_src = NULL;
|
||||||
goto done;
|
goto done;
|
||||||
}
|
} else {
|
||||||
} else if (!(camera->src_vid_src =
|
if (!gst_camerabin_add_element (cbin, camera->src_vid_src))
|
||||||
gst_camerabin_create_and_add_element (cbin, DEFAULT_SRC_VID_SRC)))
|
|
||||||
goto done;
|
goto done;
|
||||||
|
}
|
||||||
#ifdef USE_COLOR_CONVERTER
|
#ifdef USE_COLOR_CONVERTER
|
||||||
if (!gst_camerabin_create_and_add_element (cbin, "ffmpegcolorspace"))
|
if (!gst_camerabin_create_and_add_element (cbin, "ffmpegcolorspace"))
|
||||||
goto done;
|
goto done;
|
||||||
|
@ -646,10 +639,10 @@ static gboolean
|
||||||
camerabin_create_view_elements (GstCameraBin * camera)
|
camerabin_create_view_elements (GstCameraBin * camera)
|
||||||
{
|
{
|
||||||
const GList *pads;
|
const GList *pads;
|
||||||
|
GstBin *cbin = GST_BIN (camera);
|
||||||
|
|
||||||
if (!(camera->view_in_sel =
|
if (!(camera->view_in_sel =
|
||||||
gst_camerabin_create_and_add_element (GST_BIN (camera),
|
gst_camerabin_create_and_add_element (cbin, "input-selector"))) {
|
||||||
"input-selector"))) {
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -664,32 +657,28 @@ camerabin_create_view_elements (GstCameraBin * camera)
|
||||||
#ifdef USE_VIEWFINDER_CONVERTERS
|
#ifdef USE_VIEWFINDER_CONVERTERS
|
||||||
/* Add videoscale in case we need to downscale frame for view finder */
|
/* Add videoscale in case we need to downscale frame for view finder */
|
||||||
if (!(camera->view_scale =
|
if (!(camera->view_scale =
|
||||||
gst_camerabin_create_and_add_element (GST_BIN (camera),
|
gst_camerabin_create_and_add_element (cbin, "videoscale"))) {
|
||||||
"videoscale"))) {
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Add capsfilter to maintain aspect ratio while scaling */
|
/* Add capsfilter to maintain aspect ratio while scaling */
|
||||||
if (!(camera->aspect_filter =
|
if (!(camera->aspect_filter =
|
||||||
gst_camerabin_create_and_add_element (GST_BIN (camera),
|
gst_camerabin_create_and_add_element (cbin, "capsfilter"))) {
|
||||||
"capsfilter"))) {
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef USE_VIEWFINDER_COLOR_CONVERTER
|
#ifdef USE_VIEWFINDER_COLOR_CONVERTER
|
||||||
if (!gst_camerabin_create_and_add_element (GST_BIN (camera),
|
if (!gst_camerabin_create_and_add_element (cbin, "ffmpegcolorspace")) {
|
||||||
"ffmpegcolorspace")) {
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (camera->user_vf_sink) {
|
/* Add user set or default video sink element */
|
||||||
camera->view_sink = camera->user_vf_sink;
|
if (!(camera->view_sink = gst_camerabin_setup_default_element (cbin,
|
||||||
if (!gst_camerabin_add_element (GST_BIN (camera), camera->view_sink)) {
|
camera->user_vf_sink, "autovideosink", DEFAULT_VIDEOSINK))) {
|
||||||
|
camera->view_sink = NULL;
|
||||||
goto error;
|
goto error;
|
||||||
}
|
} else {
|
||||||
} else if (!(camera->view_sink =
|
if (!gst_camerabin_add_element (cbin, camera->view_sink))
|
||||||
gst_camerabin_create_and_add_element (GST_BIN (camera),
|
|
||||||
DEFAULT_VIEW_SINK))) {
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1652,8 +1641,7 @@ gst_camerabin_send_video_eos (GstCameraBin * camera)
|
||||||
gst_pad_send_event (videopad, gst_event_new_eos ());
|
gst_pad_send_event (videopad, gst_event_new_eos ());
|
||||||
gst_object_unref (videopad);
|
gst_object_unref (videopad);
|
||||||
camera->eos_handled = TRUE;
|
camera->eos_handled = TRUE;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
GST_INFO_OBJECT (camera, "dropping duplicate EOS");
|
GST_INFO_OBJECT (camera, "dropping duplicate EOS");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2472,41 +2460,41 @@ gst_camerabin_class_init (GstCameraBinClass * klass)
|
||||||
* GstCameraBin:vfsink:
|
* GstCameraBin:vfsink:
|
||||||
*
|
*
|
||||||
* Set up a sink element to render frames in view finder.
|
* Set up a sink element to render frames in view finder.
|
||||||
* By default "autovideosink" will be the sink element.
|
* By default "autovideosink" or DEFAULT_VIDEOSINK will be used.
|
||||||
* This property can only be set while #GstCameraBin is in NULL state.
|
* This property can only be set while #GstCameraBin is in NULL state.
|
||||||
* The ownership of the element will be taken by #GstCameraBin.
|
* The ownership of the element will be taken by #GstCameraBin.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
g_object_class_install_property (gobject_class, ARG_VF_SINK,
|
g_object_class_install_property (gobject_class, ARG_VF_SINK,
|
||||||
g_param_spec_object ("vfsink", "View finder sink",
|
g_param_spec_object ("vfsink", "View finder sink",
|
||||||
"View finder sink GStreamer element (default is " DEFAULT_VIEW_SINK
|
"View finder sink GStreamer element (NULL = default video sink)",
|
||||||
")", GST_TYPE_ELEMENT, G_PARAM_READWRITE));
|
GST_TYPE_ELEMENT, G_PARAM_READWRITE));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GstCameraBin:videosrc:
|
* GstCameraBin:videosrc:
|
||||||
*
|
*
|
||||||
* Set up a video source element.
|
* Set up a video source element.
|
||||||
* By default "v4l2src" will be the src element.
|
* By default "autovideosrc" or DEFAULT_VIDEOSRC will be used.
|
||||||
* This property can only be set while #GstCameraBin is in NULL state.
|
* This property can only be set while #GstCameraBin is in NULL state.
|
||||||
* The ownership of the element will be taken by #GstCameraBin.
|
* The ownership of the element will be taken by #GstCameraBin.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
g_object_class_install_property (gobject_class, ARG_VIDEO_SRC,
|
g_object_class_install_property (gobject_class, ARG_VIDEO_SRC,
|
||||||
g_param_spec_object ("videosrc", "Video source element",
|
g_param_spec_object ("videosrc", "Video source element",
|
||||||
"Video source GStreamer element (default is " DEFAULT_SRC_VID_SRC ")",
|
"Video source GStreamer element (NULL = default video src)",
|
||||||
GST_TYPE_ELEMENT, G_PARAM_READWRITE));
|
GST_TYPE_ELEMENT, G_PARAM_READWRITE));
|
||||||
/**
|
/**
|
||||||
* GstCameraBin:audiosrc:
|
* GstCameraBin:audiosrc:
|
||||||
*
|
*
|
||||||
* Set up an audio source element.
|
* Set up an audio source element.
|
||||||
* By default "pulsesrc" will be the source element.
|
* By default "autoaudiosrc" or DEFAULT_AUDIOSRC will be used.
|
||||||
* This property can only be set while #GstCameraBin is in NULL state.
|
* This property can only be set while #GstCameraBin is in NULL state.
|
||||||
* The ownership of the element will be taken by #GstCameraBin.
|
* The ownership of the element will be taken by #GstCameraBin.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
g_object_class_install_property (gobject_class, ARG_AUDIO_SRC,
|
g_object_class_install_property (gobject_class, ARG_AUDIO_SRC,
|
||||||
g_param_spec_object ("audiosrc", "Audio source element",
|
g_param_spec_object ("audiosrc", "Audio source element",
|
||||||
"Audio source GStreamer element (default is pulsesrc)",
|
"Audio source GStreamer element (NULL = default audio src)",
|
||||||
GST_TYPE_ELEMENT, G_PARAM_READWRITE));
|
GST_TYPE_ELEMENT, G_PARAM_READWRITE));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue