camerabin2: implement viewfinderbin::video-sink property to override default video output

This commit is contained in:
André Dieb Martins 2010-12-10 12:08:48 -03:00 committed by Thiago Santos
parent 80ff930012
commit 7c47fc497f
5 changed files with 100 additions and 9 deletions

View file

@ -192,6 +192,8 @@ gst_camera_bin_dispose (GObject * object)
{ {
GstCameraBin *camerabin = GST_CAMERA_BIN_CAST (object); GstCameraBin *camerabin = GST_CAMERA_BIN_CAST (object);
gst_object_unref (camerabin->vf_bin);
g_free (camerabin->img_location); g_free (camerabin->img_location);
g_free (camerabin->vid_location); g_free (camerabin->vid_location);
@ -299,6 +301,9 @@ gst_camera_bin_init (GstCameraBin * camerabin)
camerabin->mode = DEFAULT_MODE; camerabin->mode = DEFAULT_MODE;
camerabin->vid_location = g_strdup (DEFAULT_VID_LOCATION); camerabin->vid_location = g_strdup (DEFAULT_VID_LOCATION);
camerabin->img_location = g_strdup (DEFAULT_IMG_LOCATION); camerabin->img_location = g_strdup (DEFAULT_IMG_LOCATION);
camerabin->vf_bin = gst_element_factory_make ("viewfinderbin", "vf-bin");
gst_bin_add (GST_BIN (camerabin), gst_object_ref (camerabin->vf_bin));
} }
/** /**
@ -319,7 +324,6 @@ gst_camera_bin_create_elements (GstCameraBin * camera)
GstElement *src; GstElement *src;
GstElement *vid; GstElement *vid;
GstElement *img; GstElement *img;
GstElement *vf;
GstElement *vid_queue; GstElement *vid_queue;
GstElement *img_queue; GstElement *img_queue;
GstElement *vf_queue; GstElement *vf_queue;
@ -333,7 +337,6 @@ gst_camera_bin_create_elements (GstCameraBin * camera)
src = gst_element_factory_make ("v4l2camerasrc", "camerasrc"); src = gst_element_factory_make ("v4l2camerasrc", "camerasrc");
vid = gst_element_factory_make ("videorecordingbin", "video-rec-bin"); vid = gst_element_factory_make ("videorecordingbin", "video-rec-bin");
img = gst_element_factory_make ("imagecapturebin", "image-cap-bin"); img = gst_element_factory_make ("imagecapturebin", "image-cap-bin");
vf = gst_element_factory_make ("viewfinderbin", "vf-bin");
camera->src = gst_object_ref (src); camera->src = gst_object_ref (src);
camera->vidbin = gst_object_ref (vid); camera->vidbin = gst_object_ref (vid);
@ -347,13 +350,14 @@ gst_camera_bin_create_elements (GstCameraBin * camera)
img_capsfilter = gst_element_factory_make ("capsfilter", "image-capsfilter"); img_capsfilter = gst_element_factory_make ("capsfilter", "image-capsfilter");
vf_capsfilter = gst_element_factory_make ("capsfilter", "vf-capsfilter"); vf_capsfilter = gst_element_factory_make ("capsfilter", "vf-capsfilter");
gst_bin_add_many (GST_BIN_CAST (camera), src, vid, img, vf, vid_queue, gst_bin_add_many (GST_BIN_CAST (camera), src, vid, img,
img_queue, vf_queue, vid_capsfilter, img_capsfilter, vf_capsfilter, NULL); vid_queue, img_queue, vf_queue, vid_capsfilter, img_capsfilter,
vf_capsfilter, NULL);
/* Linking can be optimized TODO */ /* Linking can be optimized TODO */
gst_element_link_many (vid_queue, vid_capsfilter, vid, NULL); gst_element_link_many (vid_queue, vid_capsfilter, vid, NULL);
gst_element_link_many (img_queue, img_capsfilter, img, NULL); gst_element_link_many (img_queue, img_capsfilter, img, NULL);
gst_element_link_many (vf_queue, vf_capsfilter, vf, NULL); gst_element_link_many (vf_queue, vf_capsfilter, camera->vf_bin, NULL);
gst_element_link_pads (src, "vfsrc", vf_queue, "sink"); gst_element_link_pads (src, "vfsrc", vf_queue, "sink");
gst_element_link_pads (src, "imgsrc", img_queue, "sink"); gst_element_link_pads (src, "imgsrc", img_queue, "sink");
gst_element_link_pads (src, "vidsrc", vid_queue, "sink"); gst_element_link_pads (src, "vidsrc", vid_queue, "sink");

View file

@ -44,6 +44,8 @@ struct _GstCameraBin
GstElement *vid_queue; GstElement *vid_queue;
GstElement *vid_capsfilter; GstElement *vid_capsfilter;
GstElement *vf_bin;
GstElement *imgbin; GstElement *imgbin;
gint vid_index; gint vid_index;

View file

@ -44,7 +44,8 @@ GST_DEBUG_CATEGORY_STATIC (gst_viewfinder_bin_debug);
enum enum
{ {
PROP_0 PROP_0,
PROP_VIDEO_SINK,
}; };
/* pad templates */ /* pad templates */
@ -59,6 +60,15 @@ static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink",
GST_BOILERPLATE (GstViewfinderBin, gst_viewfinder_bin, GstBin, GST_TYPE_BIN); GST_BOILERPLATE (GstViewfinderBin, gst_viewfinder_bin, GstBin, GST_TYPE_BIN);
static void gst_viewfinder_bin_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * spec);
static void gst_viewfinder_bin_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * spec);
static void
gst_viewfinder_bin_set_video_sink (GstViewfinderBin * vfbin, GstElement * sink);
/* Element class functions */ /* Element class functions */
static GstStateChangeReturn static GstStateChangeReturn
gst_viewfinder_bin_change_state (GstElement * element, GstStateChange trans); gst_viewfinder_bin_change_state (GstElement * element, GstStateChange trans);
@ -79,12 +89,22 @@ gst_viewfinder_bin_base_init (gpointer g_class)
static void static void
gst_viewfinder_bin_class_init (GstViewfinderBinClass * klass) gst_viewfinder_bin_class_init (GstViewfinderBinClass * klass)
{ {
GObjectClass *gobject_klass;
GstElementClass *element_class; GstElementClass *element_class;
gobject_klass = (GObjectClass *) klass;
element_class = GST_ELEMENT_CLASS (klass); element_class = GST_ELEMENT_CLASS (klass);
element_class->change_state = element_class->change_state =
GST_DEBUG_FUNCPTR (gst_viewfinder_bin_change_state); GST_DEBUG_FUNCPTR (gst_viewfinder_bin_change_state);
gobject_klass->set_property = gst_viewfinder_bin_set_property;
gobject_klass->get_property = gst_viewfinder_bin_get_property;
g_object_class_install_property (gobject_klass, PROP_VIDEO_SINK,
g_param_spec_object ("video-sink", "Video Sink",
"the video output element to use (NULL = default)",
GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
} }
static void static void
@ -95,6 +115,8 @@ gst_viewfinder_bin_init (GstViewfinderBin * viewfinderbin,
gst_static_pad_template_get (&sink_template)); gst_static_pad_template_get (&sink_template));
gst_element_add_pad (GST_ELEMENT_CAST (viewfinderbin), gst_element_add_pad (GST_ELEMENT_CAST (viewfinderbin),
viewfinderbin->ghostpad); viewfinderbin->ghostpad);
viewfinderbin->video_sink = NULL;
} }
static gboolean static gboolean
@ -120,9 +142,13 @@ gst_viewfinder_bin_create_elements (GstViewfinderBin * vfbin)
if (!videoscale) if (!videoscale)
goto error; goto error;
sink = gst_element_factory_make ("autovideosink", "vfbin-sink"); if (vfbin->video_sink) {
if (!sink) sink = vfbin->video_sink;
goto error; } else {
sink = gst_element_factory_make ("autovideosink", "vfbin-sink");
if (!sink)
goto error;
}
GST_DEBUG_OBJECT (vfbin, "Internal elements created, proceding to linking"); GST_DEBUG_OBJECT (vfbin, "Internal elements created, proceding to linking");
@ -186,6 +212,56 @@ gst_viewfinder_bin_change_state (GstElement * element, GstStateChange trans)
return ret; return ret;
} }
static void
gst_viewfinder_bin_set_video_sink (GstViewfinderBin * vfbin, GstElement * sink)
{
GST_INFO_OBJECT (vfbin, "Setting video sink to %" GST_PTR_FORMAT, sink);
if (vfbin->video_sink != sink) {
if (sink)
gst_object_ref_sink (sink);
if (vfbin->video_sink)
gst_object_unref (vfbin->video_sink);
vfbin->video_sink = sink;
}
GST_LOG_OBJECT (vfbin, "Video sink is now %" GST_PTR_FORMAT, sink);
}
static void
gst_viewfinder_bin_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec)
{
GstViewfinderBin *vfbin = GST_VIEWFINDER_BIN_CAST (object);
switch (prop_id) {
case PROP_VIDEO_SINK:
gst_viewfinder_bin_set_video_sink (vfbin, g_value_get_object (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gst_viewfinder_bin_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec)
{
GstViewfinderBin *vfbin = GST_VIEWFINDER_BIN_CAST (object);
switch (prop_id) {
case PROP_VIDEO_SINK:
g_value_take_object (value, vfbin->video_sink);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
gboolean gboolean
gst_viewfinder_bin_plugin_init (GstPlugin * plugin) gst_viewfinder_bin_plugin_init (GstPlugin * plugin)
{ {

View file

@ -39,6 +39,8 @@ struct _GstViewfinderBin
GstPad *ghostpad; GstPad *ghostpad;
GstElement *video_sink;
gboolean elements_created; gboolean elements_created;
}; };

View file

@ -117,12 +117,19 @@ static void
setup (void) setup (void)
{ {
GstBus *bus; GstBus *bus;
GstElement *vfbin;
GstElement *fakevideosink;
GST_INFO ("init"); GST_INFO ("init");
main_loop = g_main_loop_new (NULL, TRUE); main_loop = g_main_loop_new (NULL, TRUE);
camera = gst_check_setup_element ("camerabin2"); camera = gst_check_setup_element ("camerabin2");
fakevideosink = gst_check_setup_element ("fakesink");
vfbin = gst_bin_get_by_name (GST_BIN (camera), "vf-bin");
g_object_set (G_OBJECT (vfbin), "video-sink", fakevideosink, NULL);
gst_object_unref (vfbin);
bus = gst_pipeline_get_bus (GST_PIPELINE (camera)); bus = gst_pipeline_get_bus (GST_PIPELINE (camera));
gst_bus_add_watch (bus, (GstBusFunc) capture_bus_cb, main_loop); gst_bus_add_watch (bus, (GstBusFunc) capture_bus_cb, main_loop);