autodetect: use a common baseclass

This makes the actual elements super simple. We're using the ELEMENT_FLAG to
configure source/sink and a string for the Audio/Video type.
This commit is contained in:
Stefan Sauer 2014-02-19 21:55:52 +01:00
parent 62f5a27416
commit bf6a2f9afd
10 changed files with 506 additions and 1326 deletions

View file

@ -39,35 +39,25 @@
#include "config.h"
#endif
#include <string.h>
#include "gstautoaudiosink.h"
#include "gstautodetect.h"
#define DEFAULT_TS_OFFSET 0
#define DEFAULT_SYNC TRUE
/* Properties */
enum
{
PROP_0,
PROP_CAPS,
PROP_TS_OFFSET,
PROP_SYNC,
};
static GstStateChangeReturn
gst_auto_audio_sink_change_state (GstElement * element,
GstStateChange transition);
static void gst_auto_audio_sink_dispose (GstAutoAudioSink * sink);
static void gst_auto_audio_sink_clear_kid (GstAutoAudioSink * sink);
static void gst_auto_audio_sink_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec);
static void gst_auto_audio_sink_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec);
static void gst_auto_audio_sink_configure (GstAutoDetect * autodetect,
GstElement * kid);
#define gst_auto_audio_sink_parent_class parent_class
G_DEFINE_TYPE (GstAutoAudioSink, gst_auto_audio_sink, GST_TYPE_BIN);
G_DEFINE_TYPE (GstAutoAudioSink, gst_auto_audio_sink, GST_TYPE_AUTO_DETECT);
static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_SINK,
@ -77,318 +67,45 @@ static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink",
static void
gst_auto_audio_sink_class_init (GstAutoAudioSinkClass * klass)
{
GObjectClass *gobject_class;
GstElementClass *eklass;
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
GstElementClass *eklass = GST_ELEMENT_CLASS (klass);
GstAutoDetectClass *aklass = GST_AUTO_DETECT_CLASS (klass);
gobject_class = G_OBJECT_CLASS (klass);
eklass = GST_ELEMENT_CLASS (klass);
gobject_class->dispose = (GObjectFinalizeFunc) gst_auto_audio_sink_dispose;
gobject_class->set_property = gst_auto_audio_sink_set_property;
gobject_class->get_property = gst_auto_audio_sink_get_property;
eklass->change_state = GST_DEBUG_FUNCPTR (gst_auto_audio_sink_change_state);
/**
* GstAutoAudioSink:filter-caps:
*
* This property will filter out candidate sinks that can handle the specified
* caps. By default only audio sinks that support raw floating point and
* integer audio are selected.
*
* This property can only be set before the element goes to the READY state.
*/
g_object_class_install_property (gobject_class, PROP_CAPS,
g_param_spec_boxed ("filter-caps", "Filter caps",
"Filter sink candidates using these caps.", GST_TYPE_CAPS,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
aklass->configure = gst_auto_audio_sink_configure;
g_object_class_install_property (gobject_class, PROP_TS_OFFSET,
g_param_spec_int64 ("ts-offset", "TS Offset",
"Timestamp offset in nanoseconds", G_MININT64, G_MAXINT64,
DEFAULT_TS_OFFSET, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class, PROP_SYNC,
g_param_spec_boolean ("sync", "Sync",
"Sync on the clock", DEFAULT_SYNC,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
gst_element_class_add_pad_template (eklass,
gst_static_pad_template_get (&sink_template));
gst_element_class_set_static_metadata (eklass, "Auto audio sink",
"Sink/Audio",
"Wrapper audio sink for automatically detected audio sink",
"Jan Schmidt <thaytan@noraisin.net>");
}
static void
gst_auto_audio_sink_dispose (GstAutoAudioSink * sink)
{
gst_auto_audio_sink_clear_kid (sink);
if (sink->filter_caps)
gst_caps_unref (sink->filter_caps);
sink->filter_caps = NULL;
G_OBJECT_CLASS (parent_class)->dispose ((GObject *) sink);
}
static void
gst_auto_audio_sink_clear_kid (GstAutoAudioSink * sink)
{
if (sink->kid) {
gst_element_set_state (sink->kid, GST_STATE_NULL);
gst_bin_remove (GST_BIN (sink), sink->kid);
sink->kid = NULL;
/* Don't lose the SINK flag */
GST_OBJECT_FLAG_SET (sink, GST_ELEMENT_FLAG_SINK);
}
}
/*
* Hack to make initial linking work; ideally, this'd work even when
* no target has been assigned to the ghostpad yet.
*/
static void
gst_auto_audio_sink_reset (GstAutoAudioSink * sink)
{
GstPad *targetpad;
gst_auto_audio_sink_clear_kid (sink);
/* fakesink placeholder */
sink->kid = gst_element_factory_make ("fakesink", "tempsink");
gst_bin_add (GST_BIN (sink), sink->kid);
/* pad */
targetpad = gst_element_get_static_pad (sink->kid, "sink");
gst_ghost_pad_set_target (GST_GHOST_PAD (sink->pad), targetpad);
gst_object_unref (targetpad);
}
static GstStaticCaps raw_caps = GST_STATIC_CAPS ("audio/x-raw");
static void
gst_auto_audio_sink_init (GstAutoAudioSink * sink)
{
sink->pad = gst_ghost_pad_new_no_target ("sink", GST_PAD_SINK);
gst_element_add_pad (GST_ELEMENT (sink), sink->pad);
GstAutoDetect *autodetect = GST_AUTO_DETECT (sink);
gst_auto_audio_sink_reset (sink);
autodetect->media_klass = "Audio";
autodetect->flag = GST_ELEMENT_FLAG_SINK;
/* set the default raw audio caps */
sink->filter_caps = gst_static_caps_get (&raw_caps);
sink->ts_offset = DEFAULT_TS_OFFSET;
sink->sync = DEFAULT_SYNC;
/* mark as sink */
GST_OBJECT_FLAG_SET (sink, GST_ELEMENT_FLAG_SINK);
}
static gboolean
gst_auto_audio_sink_factory_filter (GstPluginFeature * feature, gpointer data)
static void
gst_auto_audio_sink_configure (GstAutoDetect * autodetect, GstElement * kid)
{
guint rank;
const gchar *klass;
GstAutoAudioSink *self = GST_AUTO_AUDIO_SINK (autodetect);
/* we only care about element factories */
if (!GST_IS_ELEMENT_FACTORY (feature))
return FALSE;
/* audio sinks */
klass = gst_element_factory_get_metadata (GST_ELEMENT_FACTORY (feature),
GST_ELEMENT_METADATA_KLASS);
if (!(strstr (klass, "Sink") && strstr (klass, "Audio")))
return FALSE;
/* only select elements with autoplugging rank */
rank = gst_plugin_feature_get_rank (feature);
if (rank < GST_RANK_MARGINAL)
return FALSE;
return TRUE;
}
static GstElement *
gst_auto_audio_sink_find_best (GstAutoAudioSink * sink)
{
GList *list, *item;
GstElement *choice = NULL;
GstMessage *message = NULL;
GSList *errors = NULL;
GstBus *bus = gst_bus_new ();
GstPad *el_pad = NULL;
GstCaps *el_caps = NULL;
gboolean no_match = TRUE;
list = gst_registry_feature_filter (gst_registry_get (),
(GstPluginFeatureFilter) gst_auto_audio_sink_factory_filter, FALSE, sink);
list =
g_list_sort (list, (GCompareFunc) gst_plugin_feature_rank_compare_func);
/* We don't treat sound server sinks special. Our policy is that sound
* server sinks that have a rank must not auto-spawn a daemon under any
* circumstances, so there's nothing for us to worry about here */
GST_LOG_OBJECT (sink, "Trying to find usable audio devices ...");
for (item = list; item != NULL; item = item->next) {
GstElementFactory *f = GST_ELEMENT_FACTORY (item->data);
GstElement *el;
if ((el = gst_auto_create_element_with_pretty_name (GST_ELEMENT_CAST (sink),
f, "sink"))) {
GstStateChangeReturn ret;
GST_DEBUG_OBJECT (sink, "Testing %s", GST_OBJECT_NAME (f));
/* If autoaudiosink has been provided with filter caps,
* accept only sinks that match with the filter caps */
if (sink->filter_caps) {
el_pad = gst_element_get_static_pad (GST_ELEMENT (el), "sink");
el_caps = gst_pad_query_caps (el_pad, NULL);
gst_object_unref (el_pad);
GST_DEBUG_OBJECT (sink,
"Checking caps: %" GST_PTR_FORMAT " vs. %" GST_PTR_FORMAT,
sink->filter_caps, el_caps);
no_match = !gst_caps_can_intersect (sink->filter_caps, el_caps);
gst_caps_unref (el_caps);
if (no_match) {
GST_DEBUG_OBJECT (sink, "Incompatible caps");
gst_object_unref (el);
continue;
} else {
GST_DEBUG_OBJECT (sink, "Found compatible caps");
}
}
gst_element_set_bus (el, bus);
ret = gst_element_set_state (el, GST_STATE_READY);
if (ret == GST_STATE_CHANGE_SUCCESS) {
GST_DEBUG_OBJECT (sink, "This worked!");
choice = el;
break;
}
/* collect all error messages */
while ((message = gst_bus_pop_filtered (bus, GST_MESSAGE_ERROR))) {
GST_DEBUG_OBJECT (sink, "error message %" GST_PTR_FORMAT, message);
errors = g_slist_append (errors, message);
}
gst_element_set_state (el, GST_STATE_NULL);
gst_object_unref (el);
}
}
GST_DEBUG_OBJECT (sink, "done trying");
if (!choice) {
if (errors) {
/* FIXME: we forward the first error for now; but later on it might make
* sense to actually analyse them */
gst_message_ref (GST_MESSAGE (errors->data));
GST_DEBUG_OBJECT (sink, "reposting message %p", errors->data);
gst_element_post_message (GST_ELEMENT (sink), GST_MESSAGE (errors->data));
} else {
/* send warning message to application and use a fakesink */
GST_ELEMENT_WARNING (sink, RESOURCE, NOT_FOUND, (NULL),
("Failed to find a usable audio sink"));
choice = gst_element_factory_make ("fakesink", "fake-audio-sink");
if (g_object_class_find_property (G_OBJECT_GET_CLASS (choice), "sync"))
g_object_set (choice, "sync", TRUE, NULL);
gst_element_set_state (choice, GST_STATE_READY);
}
}
gst_object_unref (bus);
gst_plugin_feature_list_free (list);
g_slist_foreach (errors, (GFunc) gst_mini_object_unref, NULL);
g_slist_free (errors);
return choice;
}
static gboolean
gst_auto_audio_sink_detect (GstAutoAudioSink * sink)
{
GstElement *esink;
GstPad *targetpad;
gst_auto_audio_sink_clear_kid (sink);
/* find element */
GST_DEBUG_OBJECT (sink, "Creating new kid");
if (!(esink = gst_auto_audio_sink_find_best (sink)))
goto no_sink;
g_object_set (G_OBJECT (esink), "ts-offset", sink->ts_offset, NULL);
g_object_set (G_OBJECT (esink), "sync", sink->sync, NULL);
sink->kid = esink;
/* Ensure the child is brought up to the right state to match the parent
* although it's currently always in READY and
* we're always doing NULL->READY. */
if (GST_STATE (sink->kid) < GST_STATE (sink))
gst_element_set_state (sink->kid, GST_STATE (sink));
gst_bin_add (GST_BIN (sink), esink);
/* attach ghost pad */
GST_DEBUG_OBJECT (sink, "Re-assigning ghostpad");
targetpad = gst_element_get_static_pad (sink->kid, "sink");
if (!gst_ghost_pad_set_target (GST_GHOST_PAD (sink->pad), targetpad))
goto target_failed;
gst_object_unref (targetpad);
GST_DEBUG_OBJECT (sink, "done changing auto audio sink");
return TRUE;
/* ERRORS */
no_sink:
{
GST_ELEMENT_ERROR (sink, LIBRARY, INIT, (NULL),
("Failed to find a supported audio sink"));
return FALSE;
}
target_failed:
{
GST_ELEMENT_ERROR (sink, LIBRARY, INIT, (NULL),
("Failed to set target pad"));
gst_object_unref (targetpad);
return FALSE;
}
}
static GstStateChangeReturn
gst_auto_audio_sink_change_state (GstElement * element,
GstStateChange transition)
{
GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
GstAutoAudioSink *sink = GST_AUTO_AUDIO_SINK (element);
switch (transition) {
case GST_STATE_CHANGE_NULL_TO_READY:
if (!gst_auto_audio_sink_detect (sink))
return GST_STATE_CHANGE_FAILURE;
break;
default:
break;
}
ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
if (ret == GST_STATE_CHANGE_FAILURE)
return ret;
switch (transition) {
case GST_STATE_CHANGE_READY_TO_NULL:
gst_auto_audio_sink_reset (sink);
break;
default:
break;
}
return ret;
g_object_set (G_OBJECT (kid), "ts-offset", self->ts_offset, NULL);
}
static void
@ -396,22 +113,13 @@ gst_auto_audio_sink_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec)
{
GstAutoAudioSink *sink = GST_AUTO_AUDIO_SINK (object);
GstAutoDetect *autodetect = (GstAutoDetect *) sink;
switch (prop_id) {
case PROP_CAPS:
if (sink->filter_caps)
gst_caps_unref (sink->filter_caps);
sink->filter_caps = gst_caps_copy (gst_value_get_caps (value));
break;
case PROP_TS_OFFSET:
sink->ts_offset = g_value_get_int64 (value);
if (sink->kid)
g_object_set_property (G_OBJECT (sink->kid), pspec->name, value);
break;
case PROP_SYNC:
sink->sync = g_value_get_boolean (value);
if (sink->kid)
g_object_set_property (G_OBJECT (sink->kid), pspec->name, value);
if (autodetect->kid)
g_object_set_property (G_OBJECT (autodetect->kid), pspec->name, value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@ -426,16 +134,9 @@ gst_auto_audio_sink_get_property (GObject * object, guint prop_id,
GstAutoAudioSink *sink = GST_AUTO_AUDIO_SINK (object);
switch (prop_id) {
case PROP_CAPS:{
gst_value_set_caps (value, sink->filter_caps);
break;
}
case PROP_TS_OFFSET:
g_value_set_int64 (value, sink->ts_offset);
break;
case PROP_SYNC:
g_value_set_boolean (value, sink->sync);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;

View file

@ -21,6 +21,7 @@
#define __GST_AUTO_AUDIO_SINK_H__
#include <gst/gst.h>
#include "gstautodetect.h"
G_BEGIN_DECLS
@ -38,18 +39,13 @@ G_BEGIN_DECLS
(G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_AUTO_AUDIO_SINK))
typedef struct _GstAutoAudioSink {
GstBin parent;
GstAutoDetect parent;
/* explicit pointers to stuff used */
GstPad *pad;
GstElement *kid;
GstCaps *filter_caps;
GstClockTimeDiff ts_offset;
gboolean sync;
} GstAutoAudioSink;
typedef struct _GstAutoAudioSinkClass {
GstBinClass parent_class;
GstAutoDetectClass parent_class;
} GstAutoAudioSinkClass;
GType gst_auto_audio_sink_get_type (void);

View file

@ -40,30 +40,9 @@
#include "config.h"
#endif
#include <string.h>
#include "gstautoaudiosrc.h"
#include "gstautodetect.h"
/* Properties */
enum
{
PROP_0,
PROP_CAPS,
};
static GstStateChangeReturn
gst_auto_audio_src_change_state (GstElement * element,
GstStateChange transition);
static void gst_auto_audio_src_dispose (GstAutoAudioSrc * src);
static void gst_auto_audio_src_clear_kid (GstAutoAudioSrc * src);
static void gst_auto_audio_src_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec);
static void gst_auto_audio_src_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec);
#define gst_auto_audio_src_parent_class parent_class
G_DEFINE_TYPE (GstAutoAudioSrc, gst_auto_audio_src, GST_TYPE_BIN);
G_DEFINE_TYPE (GstAutoAudioSrc, gst_auto_audio_src, GST_TYPE_AUTO_DETECT);
static GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC,
@ -73,35 +52,10 @@ static GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE ("src",
static void
gst_auto_audio_src_class_init (GstAutoAudioSrcClass * klass)
{
GObjectClass *gobject_class;
GstElementClass *eklass;
gobject_class = G_OBJECT_CLASS (klass);
eklass = GST_ELEMENT_CLASS (klass);
gobject_class->dispose = (GObjectFinalizeFunc) gst_auto_audio_src_dispose;
gobject_class->set_property = gst_auto_audio_src_set_property;
gobject_class->get_property = gst_auto_audio_src_get_property;
eklass->change_state = GST_DEBUG_FUNCPTR (gst_auto_audio_src_change_state);
/**
* GstAutoAudioSrc:filter-caps:
*
* This property will filter out candidate sinks that can handle the specified
* caps. By default only audio sinks that support raw floating point and
* integer audio are selected.
*
* This property can only be set before the element goes to the READY state.
*/
g_object_class_install_property (gobject_class, PROP_CAPS,
g_param_spec_boxed ("filter-caps", "Filter caps",
"Filter sink candidates using these caps.", GST_TYPE_CAPS,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
GstElementClass *eklass = GST_ELEMENT_CLASS (klass);
gst_element_class_add_pad_template (eklass,
gst_static_pad_template_get (&src_template));
gst_element_class_set_static_metadata (eklass, "Auto audio source",
"Source/Audio",
"Wrapper audio source for automatically detected audio source",
@ -109,302 +63,11 @@ gst_auto_audio_src_class_init (GstAutoAudioSrcClass * klass)
"Stefan Kost <ensonic@users.sf.net>");
}
static void
gst_auto_audio_src_dispose (GstAutoAudioSrc * src)
{
gst_auto_audio_src_clear_kid (src);
if (src->filter_caps)
gst_caps_unref (src->filter_caps);
src->filter_caps = NULL;
G_OBJECT_CLASS (parent_class)->dispose ((GObject *) src);
}
static void
gst_auto_audio_src_clear_kid (GstAutoAudioSrc * src)
{
if (src->kid) {
gst_element_set_state (src->kid, GST_STATE_NULL);
gst_bin_remove (GST_BIN (src), src->kid);
src->kid = NULL;
/* Don't lose SOURCE flag */
GST_OBJECT_FLAG_SET (src, GST_ELEMENT_FLAG_SOURCE);
}
}
/*
* Hack to make initial linking work; ideally, this'd work even when
* no target has been assigned to the ghostpad yet.
*/
static void
gst_auto_audio_src_reset (GstAutoAudioSrc * src)
{
GstPad *targetpad;
gst_auto_audio_src_clear_kid (src);
/* fakesink placeholder */
src->kid = gst_element_factory_make ("fakesrc", "tempsrc");
gst_bin_add (GST_BIN (src), src->kid);
/* pad */
targetpad = gst_element_get_static_pad (src->kid, "src");
gst_ghost_pad_set_target (GST_GHOST_PAD (src->pad), targetpad);
gst_object_unref (targetpad);
}
static GstStaticCaps raw_caps = GST_STATIC_CAPS ("audio/x-raw");
static void
gst_auto_audio_src_init (GstAutoAudioSrc * src)
{
src->pad = gst_ghost_pad_new_no_target ("src", GST_PAD_SRC);
gst_element_add_pad (GST_ELEMENT (src), src->pad);
GstAutoDetect *autodetect = GST_AUTO_DETECT (src);
gst_auto_audio_src_reset (src);
/* set the default raw audio caps */
src->filter_caps = gst_static_caps_get (&raw_caps);
/* mark as source */
GST_OBJECT_FLAG_SET (src, GST_ELEMENT_FLAG_SOURCE);
}
static gboolean
gst_auto_audio_src_factory_filter (GstPluginFeature * feature, gpointer data)
{
guint rank;
const gchar *klass;
/* we only care about element factories */
if (!GST_IS_ELEMENT_FACTORY (feature))
return FALSE;
/* audio sinks */
klass = gst_element_factory_get_metadata (GST_ELEMENT_FACTORY (feature),
GST_ELEMENT_METADATA_KLASS);
if (!(strstr (klass, "Source") && strstr (klass, "Audio")))
return FALSE;
/* only select elements with autoplugging rank */
rank = gst_plugin_feature_get_rank (feature);
if (rank < GST_RANK_MARGINAL)
return FALSE;
return TRUE;
}
static GstElement *
gst_auto_audio_src_find_best (GstAutoAudioSrc * src)
{
GList *list, *item;
GstElement *choice = NULL;
GstMessage *message = NULL;
GSList *errors = NULL;
GstBus *bus = gst_bus_new ();
GstPad *el_pad = NULL;
GstCaps *el_caps = NULL;
gboolean no_match = TRUE;
list = gst_registry_feature_filter (gst_registry_get (),
(GstPluginFeatureFilter) gst_auto_audio_src_factory_filter, FALSE, src);
list =
g_list_sort (list, (GCompareFunc) gst_plugin_feature_rank_compare_func);
/* We don't treat sound server sources special. Our policy is that sound
* server sources that have a rank must not auto-spawn a daemon under any
* circumstances, so there's nothing for us to worry about here */
GST_LOG_OBJECT (src, "Trying to find usable audio devices ...");
for (item = list; item != NULL; item = item->next) {
GstElementFactory *f = GST_ELEMENT_FACTORY (item->data);
GstElement *el;
if ((el = gst_auto_create_element_with_pretty_name (GST_ELEMENT_CAST (src),
f, "src"))) {
GstStateChangeReturn ret;
GST_DEBUG_OBJECT (src, "Testing %s", GST_OBJECT_NAME (f));
/* If autoAudioSrc has been provided with filter caps,
* accept only sources that match with the filter caps */
if (src->filter_caps) {
el_pad = gst_element_get_static_pad (GST_ELEMENT (el), "src");
el_caps = gst_pad_query_caps (el_pad, NULL);
gst_object_unref (el_pad);
GST_DEBUG_OBJECT (src,
"Checking caps: %" GST_PTR_FORMAT " vs. %" GST_PTR_FORMAT,
src->filter_caps, el_caps);
no_match = !gst_caps_can_intersect (src->filter_caps, el_caps);
gst_caps_unref (el_caps);
if (no_match) {
GST_DEBUG_OBJECT (src, "Incompatible caps");
gst_object_unref (el);
continue;
} else {
GST_DEBUG_OBJECT (src, "Found compatible caps");
}
}
gst_element_set_bus (el, bus);
ret = gst_element_set_state (el, GST_STATE_READY);
if (ret == GST_STATE_CHANGE_SUCCESS) {
GST_DEBUG_OBJECT (src, "This worked!");
choice = el;
break;
}
/* collect all error messages */
while ((message = gst_bus_pop_filtered (bus, GST_MESSAGE_ERROR))) {
GST_DEBUG_OBJECT (src, "error message %" GST_PTR_FORMAT, message);
errors = g_slist_append (errors, message);
}
gst_element_set_state (el, GST_STATE_NULL);
gst_object_unref (el);
}
}
GST_DEBUG_OBJECT (src, "done trying");
if (!choice) {
if (errors) {
/* FIXME: we forward the first error for now; but later on it might make
* sense to actually analyse them */
gst_message_ref (GST_MESSAGE (errors->data));
GST_DEBUG_OBJECT (src, "reposting message %p", errors->data);
gst_element_post_message (GST_ELEMENT (src), GST_MESSAGE (errors->data));
} else {
/* send warning message to application and use a fakesrc */
GST_ELEMENT_WARNING (src, RESOURCE, NOT_FOUND, (NULL),
("Failed to find a usable audio source"));
choice = gst_element_factory_make ("fakesrc", "fake-audio-src");
if (g_object_class_find_property (G_OBJECT_GET_CLASS (choice), "sync"))
g_object_set (choice, "sync", TRUE, NULL);
gst_element_set_state (choice, GST_STATE_READY);
}
}
gst_object_unref (bus);
gst_plugin_feature_list_free (list);
g_slist_foreach (errors, (GFunc) gst_mini_object_unref, NULL);
g_slist_free (errors);
return choice;
}
static gboolean
gst_auto_audio_src_detect (GstAutoAudioSrc * src)
{
GstElement *esrc;
GstPad *targetpad;
gst_auto_audio_src_clear_kid (src);
/* find element */
GST_DEBUG_OBJECT (src, "Creating new kid");
if (!(esrc = gst_auto_audio_src_find_best (src)))
goto no_src;
src->kid = esrc;
/* Ensure the child is brought up to the right state to match the parent
* although it's currently always in READY and
* we're always doing NULL->READY. */
if (GST_STATE (src->kid) < GST_STATE (src))
gst_element_set_state (src->kid, GST_STATE (src));
gst_bin_add (GST_BIN (src), esrc);
/* attach ghost pad */
GST_DEBUG_OBJECT (src, "Re-assigning ghostpad");
targetpad = gst_element_get_static_pad (src->kid, "src");
if (!gst_ghost_pad_set_target (GST_GHOST_PAD (src->pad), targetpad))
goto target_failed;
gst_object_unref (targetpad);
GST_DEBUG_OBJECT (src, "done changing auto audio source");
return TRUE;
/* ERRORS */
no_src:
{
GST_ELEMENT_ERROR (src, LIBRARY, INIT, (NULL),
("Failed to find a supported audio source"));
return FALSE;
}
target_failed:
{
GST_ELEMENT_ERROR (src, LIBRARY, INIT, (NULL),
("Failed to set target pad"));
gst_object_unref (targetpad);
return FALSE;
}
}
static GstStateChangeReturn
gst_auto_audio_src_change_state (GstElement * element,
GstStateChange transition)
{
GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
GstAutoAudioSrc *src = GST_AUTO_AUDIO_SRC (element);
switch (transition) {
case GST_STATE_CHANGE_NULL_TO_READY:
if (!gst_auto_audio_src_detect (src))
return GST_STATE_CHANGE_FAILURE;
break;
default:
break;
}
ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
if (ret == GST_STATE_CHANGE_FAILURE)
return ret;
switch (transition) {
case GST_STATE_CHANGE_READY_TO_NULL:
gst_auto_audio_src_reset (src);
break;
default:
break;
}
return ret;
}
static void
gst_auto_audio_src_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec)
{
GstAutoAudioSrc *src = GST_AUTO_AUDIO_SRC (object);
switch (prop_id) {
case PROP_CAPS:
if (src->filter_caps)
gst_caps_unref (src->filter_caps);
src->filter_caps = gst_caps_copy (gst_value_get_caps (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gst_auto_audio_src_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec)
{
GstAutoAudioSrc *src = GST_AUTO_AUDIO_SRC (object);
switch (prop_id) {
case PROP_CAPS:{
gst_value_set_caps (value, src->filter_caps);
break;
}
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
autodetect->media_klass = "Audio";
autodetect->flag = GST_ELEMENT_FLAG_SOURCE;
}

View file

@ -22,6 +22,7 @@
#define __GST_AUTO_AUDIO_SRC_H__
#include <gst/gst.h>
#include "gstautodetect.h"
G_BEGIN_DECLS
@ -39,16 +40,11 @@ G_BEGIN_DECLS
(G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_AUTO_AUDIO_SRC))
typedef struct _GstAutoAudioSrc {
GstBin parent;
/* explicit pointers to stuff used */
GstPad *pad;
GstElement *kid;
GstCaps *filter_caps;
GstAutoDetect parent;
} GstAutoAudioSrc;
typedef struct _GstAutoAudioSrcClass {
GstBinClass parent_class;
GstAutoDetectClass parent_class;
} GstAutoAudioSrcClass;
GType gst_auto_audio_src_get_type (void);

View file

@ -21,6 +21,7 @@
#include "config.h"
#endif
#include <stdio.h>
#include <string.h>
#include <gst/gst.h>
@ -33,20 +34,203 @@
GST_DEBUG_CATEGORY (autodetect_debug);
GstElement *
gst_auto_create_element_with_pretty_name (GstElement * autodetect,
GstElementFactory * factory, const gchar * suffix)
#define DEFAULT_SYNC TRUE
/* Properties */
enum
{
PROP_0,
PROP_CAPS,
PROP_SYNC,
};
static GstStateChangeReturn gst_auto_detect_change_state (GstElement * element,
GstStateChange transition);
static void gst_auto_detect_constructed (GObject * object);
static void gst_auto_detect_dispose (GObject * self);
static void gst_auto_detect_clear_kid (GstAutoDetect * self);
static void gst_auto_detect_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec);
static void gst_auto_detect_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec);
#define gst_auto_detect_parent_class parent_class
G_DEFINE_ABSTRACT_TYPE (GstAutoDetect, gst_auto_detect, GST_TYPE_BIN);
static void
gst_auto_detect_class_init (GstAutoDetectClass * klass)
{
GObjectClass *gobject_class;
GstElementClass *eklass;
gobject_class = G_OBJECT_CLASS (klass);
eklass = GST_ELEMENT_CLASS (klass);
gobject_class->constructed = gst_auto_detect_constructed;
gobject_class->dispose = gst_auto_detect_dispose;
gobject_class->set_property = gst_auto_detect_set_property;
gobject_class->get_property = gst_auto_detect_get_property;
eklass->change_state = GST_DEBUG_FUNCPTR (gst_auto_detect_change_state);
/**
* GstAutoDetect:filter-caps:
*
* This property will filter out candidate sinks that can handle the specified
* caps. By default only elements that support uncompressed data are selected.
*
* This property can only be set before the element goes to the READY state.
*/
g_object_class_install_property (gobject_class, PROP_CAPS,
g_param_spec_boxed ("filter-caps", "Filter caps",
"Filter sink candidates using these caps.", GST_TYPE_CAPS,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class, PROP_SYNC,
g_param_spec_boolean ("sync", "Sync",
"Sync on the clock", DEFAULT_SYNC,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
}
static void
gst_auto_detect_dispose (GObject * object)
{
GstAutoDetect *self = GST_AUTO_DETECT (object);
gst_auto_detect_clear_kid (self);
if (self->filter_caps)
gst_caps_unref (self->filter_caps);
self->filter_caps = NULL;
G_OBJECT_CLASS (parent_class)->dispose ((GObject *) self);
}
static void
gst_auto_detect_clear_kid (GstAutoDetect * self)
{
if (self->kid) {
gst_element_set_state (self->kid, GST_STATE_NULL);
gst_bin_remove (GST_BIN (self), self->kid);
self->kid = NULL;
/* Don't lose the element type flag */
GST_OBJECT_FLAG_SET (self, self->flag);
}
}
static GstElement *
gst_auto_detect_create_fake_element (GstAutoDetect * self)
{
GstElement *fake;
gchar dummy_factory[10], dummy_name[20];
sprintf (dummy_factory, "fake%s", self->type_klass_lc);
sprintf (dummy_name, "fake-%s-%s", self->media_klass_lc, self->type_klass_lc);
fake = gst_element_factory_make (dummy_factory, dummy_name);
g_object_set (fake, "sync", self->sync, NULL);
return fake;
}
static gboolean
gst_auto_detect_attach_ghost_pad (GstAutoDetect * self)
{
GstPad *target = gst_element_get_static_pad (self->kid, self->type_klass_lc);
gboolean res = gst_ghost_pad_set_target (GST_GHOST_PAD (self->pad), target);
gst_object_unref (target);
return res;
}
/* Hack to make initial linking work; ideally, this'd work even when
* no target has been assigned to the ghostpad yet. */
static void
gst_auto_detect_reset (GstAutoDetect * self)
{
gst_auto_detect_clear_kid (self);
/* placeholder element */
self->kid = gst_auto_detect_create_fake_element (self);
gst_bin_add (GST_BIN (self), self->kid);
gst_auto_detect_attach_ghost_pad (self);
}
static GstStaticCaps raw_audio_caps = GST_STATIC_CAPS ("audio/x-raw");
static GstStaticCaps raw_video_caps = GST_STATIC_CAPS ("video/x-raw");
static void
gst_auto_detect_init (GstAutoDetect * self)
{
self->sync = DEFAULT_SYNC;
}
static void
gst_auto_detect_constructed (GObject * object)
{
GstAutoDetect *self = GST_AUTO_DETECT (object);
gboolean is_audio;
if (G_OBJECT_CLASS (parent_class)->constructed)
G_OBJECT_CLASS (parent_class)->constructed (object);
is_audio = !g_strcmp0 (self->media_klass, "Audio");
self->type_klass = (self->flag == GST_ELEMENT_FLAG_SINK) ? "Sink" : "Source";
self->type_klass_lc = (self->flag == GST_ELEMENT_FLAG_SINK) ? "sink" : "src";
self->media_klass_lc = is_audio ? "audio" : "video";
/* set the default raw caps */
self->filter_caps = gst_static_caps_get (is_audio ? &raw_audio_caps :
&raw_video_caps);
self->pad = gst_ghost_pad_new_no_target (self->type_klass_lc,
(self->flag == GST_ELEMENT_FLAG_SINK) ? GST_PAD_SINK : GST_PAD_SRC);
gst_element_add_pad (GST_ELEMENT (self), self->pad);
gst_auto_detect_reset (self);
/* mark element type */
GST_OBJECT_FLAG_SET (self, self->flag);
}
static gboolean
gst_auto_detect_factory_filter (GstPluginFeature * feature, gpointer data)
{
GstAutoDetect *self = (GstAutoDetect *) data;
guint rank;
const gchar *klass;
/* we only care about element factories */
if (!GST_IS_ELEMENT_FACTORY (feature))
return FALSE;
/* audio sinks */
klass = gst_element_factory_get_metadata (GST_ELEMENT_FACTORY (feature),
GST_ELEMENT_METADATA_KLASS);
if (!(strstr (klass, self->type_klass) && strstr (klass, self->media_klass)))
return FALSE;
/* only select elements with autoplugging rank */
rank = gst_plugin_feature_get_rank (feature);
if (rank < GST_RANK_MARGINAL)
return FALSE;
return TRUE;
}
static GstElement *
create_element_with_pretty_name (GstAutoDetect * self,
GstElementFactory * factory)
{
GstElement *element;
gchar *name, *marker;
marker = g_strdup (GST_OBJECT_NAME (factory));
if (g_str_has_suffix (marker, suffix))
if (g_str_has_suffix (marker, self->type_klass_lc))
marker[strlen (marker) - 4] = '\0';
if (g_str_has_prefix (marker, "gst"))
memmove (marker, marker + 3, strlen (marker + 3) + 1);
name = g_strdup_printf ("%s-actual-%s-%s", GST_OBJECT_NAME (autodetect),
suffix, marker);
name = g_strdup_printf ("%s-actual-%s-%s", GST_OBJECT_NAME (self),
self->type_klass_lc, marker);
g_free (marker);
element = gst_element_factory_create (factory, name);
@ -55,7 +239,226 @@ gst_auto_create_element_with_pretty_name (GstElement * autodetect,
return element;
}
static GstElement *
gst_auto_detect_find_best (GstAutoDetect * self)
{
GList *list, *item;
GstElement *choice = NULL;
GstMessage *message = NULL;
GSList *errors = NULL;
GstBus *bus = gst_bus_new ();
GstPad *el_pad = NULL;
GstCaps *el_caps = NULL;
gboolean no_match = TRUE;
/* We don't treat sound server sinks special. Our policy is that sound
* server sinks that have a rank must not auto-spawn a daemon under any
* circumstances, so there's nothing for us to worry about here */
list = gst_registry_feature_filter (gst_registry_get (),
(GstPluginFeatureFilter) gst_auto_detect_factory_filter, FALSE, self);
list =
g_list_sort (list, (GCompareFunc) gst_plugin_feature_rank_compare_func);
GST_LOG_OBJECT (self, "Trying to find usable %s elements ...",
self->media_klass_lc);
for (item = list; item != NULL; item = item->next) {
GstElementFactory *f = GST_ELEMENT_FACTORY (item->data);
GstElement *el;
if ((el = create_element_with_pretty_name (self, f))) {
GstStateChangeReturn ret;
GST_DEBUG_OBJECT (self, "Testing %s", GST_OBJECT_NAME (f));
/* If autodetect has been provided with filter caps,
* accept only elements that match with the filter caps */
if (self->filter_caps) {
el_pad = gst_element_get_static_pad (el, self->type_klass_lc);
el_caps = gst_pad_query_caps (el_pad, NULL);
gst_object_unref (el_pad);
GST_DEBUG_OBJECT (self,
"Checking caps: %" GST_PTR_FORMAT " vs. %" GST_PTR_FORMAT,
self->filter_caps, el_caps);
no_match = !gst_caps_can_intersect (self->filter_caps, el_caps);
gst_caps_unref (el_caps);
if (no_match) {
GST_DEBUG_OBJECT (self, "Incompatible caps");
gst_object_unref (el);
continue;
} else {
GST_DEBUG_OBJECT (self, "Found compatible caps");
}
}
gst_element_set_bus (el, bus);
ret = gst_element_set_state (el, GST_STATE_READY);
if (ret == GST_STATE_CHANGE_SUCCESS) {
GST_DEBUG_OBJECT (self, "This worked!");
choice = el;
break;
}
/* collect all error messages */
while ((message = gst_bus_pop_filtered (bus, GST_MESSAGE_ERROR))) {
GST_DEBUG_OBJECT (self, "error message %" GST_PTR_FORMAT, message);
errors = g_slist_append (errors, message);
}
gst_element_set_state (el, GST_STATE_NULL);
gst_object_unref (el);
}
}
GST_DEBUG_OBJECT (self, "done trying");
if (!choice) {
if (errors) {
/* FIXME: we forward the first error for now; but later on it might make
* sense to actually analyse them */
message = gst_message_ref (GST_MESSAGE (errors->data));
GST_DEBUG_OBJECT (self, "reposting message %p", message);
gst_element_post_message (GST_ELEMENT_CAST (self), message);
} else {
/* send warning message to application and use a fakesrc */
GST_ELEMENT_WARNING (self, RESOURCE, NOT_FOUND, (NULL),
("Failed to find a usable %s %s", self->media_klass_lc,
self->type_klass_lc));
choice = gst_auto_detect_create_fake_element (self);
gst_element_set_state (choice, GST_STATE_READY);
}
}
gst_object_unref (bus);
gst_plugin_feature_list_free (list);
g_slist_foreach (errors, (GFunc) gst_mini_object_unref, NULL);
g_slist_free (errors);
return choice;
}
static gboolean
gst_auto_detect_detect (GstAutoDetect * self)
{
GstElement *kid;
GstAutoDetectClass *klass = GST_AUTO_DETECT_GET_CLASS (self);
gst_auto_detect_clear_kid (self);
/* find element */
GST_DEBUG_OBJECT (self, "Creating new kid");
if (!(kid = gst_auto_detect_find_best (self)))
goto no_sink;
g_object_set (G_OBJECT (kid), "sync", self->sync, NULL);
if (klass->configure) {
klass->configure (self, kid);
}
self->kid = kid;
/* Ensure the child is brought up to the right state to match the parent.
* Although it's currently always in READY and we're always doing NULL->READY.
*/
if (GST_STATE (self->kid) < GST_STATE (self))
gst_element_set_state (self->kid, GST_STATE (self));
gst_bin_add (GST_BIN (self), kid);
/* attach ghost pad */
GST_DEBUG_OBJECT (self, "Re-assigning ghostpad");
if (!gst_auto_detect_attach_ghost_pad (self))
goto target_failed;
GST_DEBUG_OBJECT (self, "done changing auto %s %s", self->media_klass_lc,
self->type_klass_lc);
return TRUE;
/* ERRORS */
no_sink:
{
GST_ELEMENT_ERROR (self, LIBRARY, INIT, (NULL),
("Failed to find a supported audio sink"));
return FALSE;
}
target_failed:
{
GST_ELEMENT_ERROR (self, LIBRARY, INIT, (NULL),
("Failed to set target pad"));
return FALSE;
}
}
static GstStateChangeReturn
gst_auto_detect_change_state (GstElement * element, GstStateChange transition)
{
GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
GstAutoDetect *sink = GST_AUTO_DETECT (element);
switch (transition) {
case GST_STATE_CHANGE_NULL_TO_READY:
if (!gst_auto_detect_detect (sink))
return GST_STATE_CHANGE_FAILURE;
break;
default:
break;
}
ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
if (ret == GST_STATE_CHANGE_FAILURE)
return ret;
switch (transition) {
case GST_STATE_CHANGE_READY_TO_NULL:
gst_auto_detect_reset (sink);
break;
default:
break;
}
return ret;
}
static void
gst_auto_detect_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec)
{
GstAutoDetect *self = GST_AUTO_DETECT (object);
switch (prop_id) {
case PROP_CAPS:
if (self->filter_caps)
gst_caps_unref (self->filter_caps);
self->filter_caps = gst_caps_copy (gst_value_get_caps (value));
break;
case PROP_SYNC:
self->sync = g_value_get_boolean (value);
if (self->kid)
g_object_set_property (G_OBJECT (self->kid), pspec->name, value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gst_auto_detect_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec)
{
GstAutoDetect *self = GST_AUTO_DETECT (object);
switch (prop_id) {
case PROP_CAPS:
gst_value_set_caps (value, self->filter_caps);
break;
case PROP_SYNC:
g_value_set_boolean (value, self->sync);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static gboolean
plugin_init (GstPlugin * plugin)

View file

@ -20,11 +20,52 @@
#ifndef __GST_AUTO_DETECT_H__
#define __GST_AUTO_DETECT_H__
G_BEGIN_DECLS
GST_DEBUG_CATEGORY_EXTERN (autodetect_debug);
#define GST_CAT_DEFAULT autodetect_debug
GstElement * gst_auto_create_element_with_pretty_name (
GstElement * autodetect, GstElementFactory * factory, const gchar *suffix);
#define GST_TYPE_AUTO_DETECT (gst_auto_detect_get_type ())
#define GST_AUTO_DETECT(obj) \
(G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_AUTO_DETECT, GstAutoDetect))
#define GST_AUTO_DETECT_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_AUTO_DETECT, GstAutoDetectClass))
#define GST_IS_AUTO_DETECT(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_AUTO_DETECT))
#define GST_IS_AUTO_DETECT_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_AUTO_DETECT))
#define GST_AUTO_DETECT_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_AUTO_DETECT, GstAutoDetectClass))
typedef struct _GstAutoDetect {
GstBin parent;
/* configuration for subclasses */
const gchar *media_klass; /* Audio/Video/... */
GstElementFlags flag; /* GST_ELEMENT_FLAG_{SINK/SOURCE} */
/* explicit pointers to stuff used */
GstPad *pad;
GstCaps *filter_caps;
gboolean sync;
/* < private > */
GstElement *kid;
const gchar *type_klass; /* Source/Sink */
const gchar *media_klass_lc, *type_klass_lc; /* lower case versions */
} GstAutoDetect;
typedef struct _GstAutoDetectClass {
GstBinClass parent_class;
/*< public >*/
/* virtual methods for subclasses */
void (*configure)(GstAutoDetect *self, GstElement *kid);
} GstAutoDetectClass;
GType gst_auto_detect_get_type (void);
G_END_DECLS
#endif /* __GST_AUTO_DETECT_H__ */

View file

@ -39,36 +39,25 @@
#include "config.h"
#endif
#include <string.h>
#include "gstautovideosink.h"
#include "gstautodetect.h"
#define DEFAULT_TS_OFFSET 0
#define DEFAULT_SYNC TRUE
/* Properties */
enum
{
PROP_0,
PROP_CAPS,
PROP_TS_OFFSET,
PROP_SYNC,
};
static GstStateChangeReturn
gst_auto_video_sink_change_state (GstElement * element,
GstStateChange transition);
static void gst_auto_video_sink_dispose (GstAutoVideoSink * sink);
static void gst_auto_video_sink_clear_kid (GstAutoVideoSink * sink);
static void gst_auto_video_sink_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec);
static void gst_auto_video_sink_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec);
static void gst_auto_video_sink_configure (GstAutoDetect * autodetect,
GstElement * kid);
#define gst_auto_video_sink_parent_class parent_class
G_DEFINE_TYPE (GstAutoVideoSink, gst_auto_video_sink, GST_TYPE_BIN);
G_DEFINE_TYPE (GstAutoVideoSink, gst_auto_video_sink, GST_TYPE_AUTO_DETECT);
static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_SINK,
@ -78,39 +67,20 @@ static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink",
static void
gst_auto_video_sink_class_init (GstAutoVideoSinkClass * klass)
{
GObjectClass *gobject_class;
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
GstElementClass *eklass = GST_ELEMENT_CLASS (klass);
GstAutoDetectClass *aklass = GST_AUTO_DETECT_CLASS (klass);
gobject_class = G_OBJECT_CLASS (klass);
gobject_class->dispose = (GObjectFinalizeFunc) gst_auto_video_sink_dispose;
gobject_class->set_property = gst_auto_video_sink_set_property;
gobject_class->get_property = gst_auto_video_sink_get_property;
eklass->change_state = GST_DEBUG_FUNCPTR (gst_auto_video_sink_change_state);
/**
* GstAutoVideoSink:filter-caps:
*
* This property will filter out candidate sinks that can handle the specified
* caps. By default only video sinks that support raw rgb and yuv video
* are selected.
*
* This property can only be set before the element goes to the READY state.
*/
g_object_class_install_property (gobject_class, PROP_CAPS,
g_param_spec_boxed ("filter-caps", "Filter caps",
"Filter sink candidates using these caps.", GST_TYPE_CAPS,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
aklass->configure = gst_auto_video_sink_configure;
g_object_class_install_property (gobject_class, PROP_TS_OFFSET,
g_param_spec_int64 ("ts-offset", "TS Offset",
"Timestamp offset in nanoseconds", G_MININT64, G_MAXINT64,
DEFAULT_TS_OFFSET, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class, PROP_SYNC,
g_param_spec_boolean ("sync", "Sync",
"Sync on the clock", DEFAULT_SYNC,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
gst_element_class_add_pad_template (eklass,
gst_static_pad_template_get (&sink_template));
gst_element_class_set_static_metadata (eklass, "Auto video sink",
@ -119,264 +89,23 @@ gst_auto_video_sink_class_init (GstAutoVideoSinkClass * klass)
"Jan Schmidt <thaytan@noraisin.net>");
}
static void
gst_auto_video_sink_dispose (GstAutoVideoSink * sink)
{
gst_auto_video_sink_clear_kid (sink);
if (sink->filter_caps)
gst_caps_unref (sink->filter_caps);
sink->filter_caps = NULL;
G_OBJECT_CLASS (parent_class)->dispose ((GObject *) sink);
}
static void
gst_auto_video_sink_clear_kid (GstAutoVideoSink * sink)
{
if (sink->kid) {
gst_element_set_state (sink->kid, GST_STATE_NULL);
gst_bin_remove (GST_BIN (sink), sink->kid);
sink->kid = NULL;
/* Don't lose the SINK flag */
GST_OBJECT_FLAG_SET (sink, GST_ELEMENT_FLAG_SINK);
}
}
/*
* Hack to make initial linking work; ideally, this'd work even when
* no target has been assigned to the ghostpad yet.
*/
static void
gst_auto_video_sink_reset (GstAutoVideoSink * sink)
{
GstPad *targetpad;
/* Remove any existing element */
gst_auto_video_sink_clear_kid (sink);
/* fakesink placeholder */
sink->kid = gst_element_factory_make ("fakesink", "tempsink");
gst_bin_add (GST_BIN (sink), sink->kid);
/* pad, setting this target should always work */
targetpad = gst_element_get_static_pad (sink->kid, "sink");
gst_ghost_pad_set_target (GST_GHOST_PAD (sink->pad), targetpad);
gst_object_unref (targetpad);
}
static GstStaticCaps raw_caps = GST_STATIC_CAPS ("video/x-raw");
static void
gst_auto_video_sink_init (GstAutoVideoSink * sink)
{
sink->pad = gst_ghost_pad_new_no_target ("sink", GST_PAD_SINK);
gst_element_add_pad (GST_ELEMENT (sink), sink->pad);
GstAutoDetect *autodetect = GST_AUTO_DETECT (sink);
gst_auto_video_sink_reset (sink);
autodetect->media_klass = "Video";
autodetect->flag = GST_ELEMENT_FLAG_SINK;
/* set the default raw video caps */
sink->filter_caps = gst_static_caps_get (&raw_caps);
sink->ts_offset = DEFAULT_TS_OFFSET;
sink->sync = DEFAULT_SYNC;
/* mark as sink */
GST_OBJECT_FLAG_SET (sink, GST_ELEMENT_FLAG_SINK);
}
static gboolean
gst_auto_video_sink_factory_filter (GstPluginFeature * feature, gpointer data)
static void
gst_auto_video_sink_configure (GstAutoDetect * autodetect, GstElement * kid)
{
guint rank;
const gchar *klass;
GstAutoVideoSink *self = GST_AUTO_VIDEO_SINK (autodetect);
/* we only care about element factories */
if (!GST_IS_ELEMENT_FACTORY (feature))
return FALSE;
/* video sinks */
klass = gst_element_factory_get_metadata (GST_ELEMENT_FACTORY (feature),
GST_ELEMENT_METADATA_KLASS);
if (!(strstr (klass, "Sink") && strstr (klass, "Video")))
return FALSE;
/* only select elements with autoplugging rank */
rank = gst_plugin_feature_get_rank (feature);
if (rank < GST_RANK_MARGINAL)
return FALSE;
return TRUE;
}
static GstElement *
gst_auto_video_sink_find_best (GstAutoVideoSink * sink)
{
GList *list, *item;
GstElement *choice = NULL;
GstMessage *message = NULL;
GSList *errors = NULL;
GstBus *bus = gst_bus_new ();
GstPad *el_pad = NULL;
GstCaps *el_caps = NULL;
gboolean no_match = TRUE;
list = gst_registry_feature_filter (gst_registry_get (),
(GstPluginFeatureFilter) gst_auto_video_sink_factory_filter, FALSE, sink);
list =
g_list_sort (list, (GCompareFunc) gst_plugin_feature_rank_compare_func);
GST_LOG_OBJECT (sink, "Trying to find usable video devices ...");
for (item = list; item != NULL; item = item->next) {
GstElementFactory *f = GST_ELEMENT_FACTORY (item->data);
GstElement *el;
if ((el = gst_auto_create_element_with_pretty_name (GST_ELEMENT_CAST (sink),
f, "sink"))) {
GstStateChangeReturn ret;
GST_DEBUG_OBJECT (sink, "Testing %s", GST_OBJECT_NAME (f));
/* If autovideosink has been provided with filter caps,
* accept only sinks that match with the filter caps */
if (sink->filter_caps) {
el_pad = gst_element_get_static_pad (GST_ELEMENT (el), "sink");
el_caps = gst_pad_query_caps (el_pad, NULL);
gst_object_unref (el_pad);
GST_DEBUG_OBJECT (sink,
"Checking caps: %" GST_PTR_FORMAT " vs. %" GST_PTR_FORMAT,
sink->filter_caps, el_caps);
no_match = !gst_caps_can_intersect (sink->filter_caps, el_caps);
gst_caps_unref (el_caps);
if (no_match) {
GST_DEBUG_OBJECT (sink, "Incompatible caps");
gst_object_unref (el);
continue;
} else {
GST_DEBUG_OBJECT (sink, "Found compatible caps");
}
}
gst_element_set_bus (el, bus);
ret = gst_element_set_state (el, GST_STATE_READY);
if (ret == GST_STATE_CHANGE_SUCCESS) {
GST_DEBUG_OBJECT (sink, "This worked!");
choice = el;
break;
}
/* collect all error messages */
while ((message = gst_bus_pop_filtered (bus, GST_MESSAGE_ERROR))) {
GST_DEBUG_OBJECT (sink, "error message %" GST_PTR_FORMAT, message);
errors = g_slist_append (errors, message);
}
gst_element_set_state (el, GST_STATE_NULL);
gst_object_unref (el);
}
}
GST_DEBUG_OBJECT (sink, "done trying");
if (!choice) {
if (errors) {
/* FIXME: we forward the first error for now; but later on it might make
* sense to actually analyse them */
gst_message_ref (GST_MESSAGE (errors->data));
GST_DEBUG_OBJECT (sink, "reposting message %p", errors->data);
gst_element_post_message (GST_ELEMENT (sink), GST_MESSAGE (errors->data));
} else {
/* send warning message to application and use a fakesink */
GST_ELEMENT_WARNING (sink, RESOURCE, NOT_FOUND, (NULL),
("Failed to find a usable video sink"));
choice = gst_element_factory_make ("fakesink", "fake-video-sink");
if (g_object_class_find_property (G_OBJECT_GET_CLASS (choice), "sync"))
g_object_set (choice, "sync", TRUE, NULL);
gst_element_set_state (choice, GST_STATE_READY);
}
}
gst_object_unref (bus);
gst_plugin_feature_list_free (list);
g_slist_foreach (errors, (GFunc) gst_mini_object_unref, NULL);
g_slist_free (errors);
return choice;
}
static gboolean
gst_auto_video_sink_detect (GstAutoVideoSink * sink)
{
GstElement *esink;
GstPad *targetpad;
gst_auto_video_sink_clear_kid (sink);
/* find element */
GST_DEBUG_OBJECT (sink, "Creating new kid");
if (!(esink = gst_auto_video_sink_find_best (sink)))
goto no_sink;
g_object_set (G_OBJECT (esink), "ts-offset", sink->ts_offset, NULL);
g_object_set (G_OBJECT (esink), "sync", sink->sync, NULL);
sink->kid = esink;
gst_bin_add (GST_BIN (sink), esink);
/* attach ghost pad */
GST_DEBUG_OBJECT (sink, "Re-assigning ghostpad");
targetpad = gst_element_get_static_pad (sink->kid, "sink");
if (!gst_ghost_pad_set_target (GST_GHOST_PAD (sink->pad), targetpad))
goto target_failed;
gst_object_unref (targetpad);
GST_DEBUG_OBJECT (sink, "done changing auto video sink");
return TRUE;
/* ERRORS */
no_sink:
{
GST_ELEMENT_ERROR (sink, LIBRARY, INIT, (NULL),
("Failed to find a supported video sink"));
return FALSE;
}
target_failed:
{
GST_ELEMENT_ERROR (sink, LIBRARY, INIT, (NULL),
("Failed to set target pad"));
gst_object_unref (targetpad);
return FALSE;
}
}
static GstStateChangeReturn
gst_auto_video_sink_change_state (GstElement * element,
GstStateChange transition)
{
GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
GstAutoVideoSink *sink = GST_AUTO_VIDEO_SINK (element);
switch (transition) {
case GST_STATE_CHANGE_NULL_TO_READY:
if (!gst_auto_video_sink_detect (sink))
return GST_STATE_CHANGE_FAILURE;
break;
default:
break;
}
ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
switch (transition) {
case GST_STATE_CHANGE_READY_TO_NULL:
gst_auto_video_sink_reset (sink);
break;
default:
break;
}
return ret;
g_object_set (G_OBJECT (kid), "ts-offset", self->ts_offset, NULL);
}
static void
@ -384,22 +113,13 @@ gst_auto_video_sink_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec)
{
GstAutoVideoSink *sink = GST_AUTO_VIDEO_SINK (object);
GstAutoDetect *autodetect = (GstAutoDetect *) sink;
switch (prop_id) {
case PROP_CAPS:
if (sink->filter_caps)
gst_caps_unref (sink->filter_caps);
sink->filter_caps = gst_caps_copy (gst_value_get_caps (value));
break;
case PROP_TS_OFFSET:
sink->ts_offset = g_value_get_int64 (value);
if (sink->kid)
g_object_set_property (G_OBJECT (sink->kid), pspec->name, value);
break;
case PROP_SYNC:
sink->sync = g_value_get_boolean (value);
if (sink->kid)
g_object_set_property (G_OBJECT (sink->kid), pspec->name, value);
if (autodetect->kid)
g_object_set_property (G_OBJECT (autodetect->kid), pspec->name, value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@ -414,16 +134,9 @@ gst_auto_video_sink_get_property (GObject * object, guint prop_id,
GstAutoVideoSink *sink = GST_AUTO_VIDEO_SINK (object);
switch (prop_id) {
case PROP_CAPS:{
gst_value_set_caps (value, sink->filter_caps);
break;
}
case PROP_TS_OFFSET:
g_value_set_int64 (value, sink->ts_offset);
break;
case PROP_SYNC:
g_value_set_boolean (value, sink->sync);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;

View file

@ -21,6 +21,7 @@
#define __GST_AUTO_VIDEO_SINK_H__
#include <gst/gst.h>
#include "gstautodetect.h"
G_BEGIN_DECLS
@ -38,18 +39,13 @@ G_BEGIN_DECLS
(G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_AUTO_VIDEO_SINK))
typedef struct _GstAutoVideoSink {
GstBin parent;
GstAutoDetect parent;
/* explicit pointers to stuff used */
GstPad *pad;
GstElement *kid;
GstCaps *filter_caps;
GstClockTimeDiff ts_offset;
gboolean sync;
} GstAutoVideoSink;
typedef struct _GstAutoVideoSinkClass {
GstBinClass parent_class;
GstAutoDetectClass parent_class;
} GstAutoVideoSinkClass;
GType gst_auto_video_sink_get_type (void);

View file

@ -40,31 +40,9 @@
#include "config.h"
#endif
#include <string.h>
#include "gstautovideosrc.h"
#include "gstautodetect.h"
/* Properties */
enum
{
PROP_0,
PROP_CAPS,
};
static GstStateChangeReturn
gst_auto_video_src_change_state (GstElement * element,
GstStateChange transition);
static void gst_auto_video_src_dispose (GstAutoVideoSrc * src);
static void gst_auto_video_src_clear_kid (GstAutoVideoSrc * src);
static void gst_auto_video_src_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec);
static void gst_auto_video_src_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec);
#define gst_auto_video_src_parent_class parent_class
G_DEFINE_TYPE (GstAutoVideoSrc, gst_auto_video_src, GST_TYPE_BIN);
G_DEFINE_TYPE (GstAutoVideoSrc, gst_auto_video_src, GST_TYPE_AUTO_DETECT);
static GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC,
@ -74,30 +52,8 @@ static GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE ("src",
static void
gst_auto_video_src_class_init (GstAutoVideoSrcClass * klass)
{
GObjectClass *gobject_class;
GstElementClass *eklass = GST_ELEMENT_CLASS (klass);
gobject_class = G_OBJECT_CLASS (klass);
gobject_class->dispose = (GObjectFinalizeFunc) gst_auto_video_src_dispose;
gobject_class->set_property = gst_auto_video_src_set_property;
gobject_class->get_property = gst_auto_video_src_get_property;
eklass->change_state = GST_DEBUG_FUNCPTR (gst_auto_video_src_change_state);
/**
* GstAutoVideoSrc:filter-caps:
*
* This property will filter out candidate sources that can handle the specified
* caps. By default only video sources that support raw rgb and yuv video
* are selected.
*
* This property can only be set before the element goes to the READY state.
*/
g_object_class_install_property (gobject_class, PROP_CAPS,
g_param_spec_boxed ("filter-caps", "Filter caps",
"Filter src candidates using these caps.", GST_TYPE_CAPS,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
gst_element_class_add_pad_template (eklass,
gst_static_pad_template_get (&src_template));
gst_element_class_set_static_metadata (eklass, "Auto video source",
@ -107,292 +63,11 @@ gst_auto_video_src_class_init (GstAutoVideoSrcClass * klass)
"Stefan Kost <ensonic@users.sf.net>");
}
static void
gst_auto_video_src_dispose (GstAutoVideoSrc * src)
{
gst_auto_video_src_clear_kid (src);
if (src->filter_caps)
gst_caps_unref (src->filter_caps);
src->filter_caps = NULL;
G_OBJECT_CLASS (parent_class)->dispose ((GObject *) src);
}
static void
gst_auto_video_src_clear_kid (GstAutoVideoSrc * src)
{
if (src->kid) {
gst_element_set_state (src->kid, GST_STATE_NULL);
gst_bin_remove (GST_BIN (src), src->kid);
src->kid = NULL;
/* Don't loose SOURCE flag */
GST_OBJECT_FLAG_SET (src, GST_ELEMENT_FLAG_SOURCE);
}
}
/*
* Hack to make initial linking work; ideally, this'd work even when
* no target has been assigned to the ghostpad yet.
*/
static void
gst_auto_video_src_reset (GstAutoVideoSrc * src)
{
GstPad *targetpad;
/* Remove any existing element */
gst_auto_video_src_clear_kid (src);
/* fakesrc placeholder */
src->kid = gst_element_factory_make ("fakesrc", "tempsrc");
gst_bin_add (GST_BIN (src), src->kid);
/* pad */
targetpad = gst_element_get_static_pad (src->kid, "src");
gst_ghost_pad_set_target (GST_GHOST_PAD (src->pad), targetpad);
gst_object_unref (targetpad);
}
static GstStaticCaps raw_caps = GST_STATIC_CAPS ("video/x-raw");
static void
gst_auto_video_src_init (GstAutoVideoSrc * src)
{
src->pad = gst_ghost_pad_new_no_target ("src", GST_PAD_SRC);
gst_element_add_pad (GST_ELEMENT (src), src->pad);
GstAutoDetect *autodetect = GST_AUTO_DETECT (src);
gst_auto_video_src_reset (src);
/* set the default raw video caps */
src->filter_caps = gst_static_caps_get (&raw_caps);
/* mark as source */
GST_OBJECT_FLAG_SET (src, GST_ELEMENT_FLAG_SOURCE);
}
static gboolean
gst_auto_video_src_factory_filter (GstPluginFeature * feature, gpointer data)
{
guint rank;
const gchar *klass;
/* we only care about element factories */
if (!GST_IS_ELEMENT_FACTORY (feature))
return FALSE;
/* video sources */
klass = gst_element_factory_get_metadata (GST_ELEMENT_FACTORY (feature),
GST_ELEMENT_METADATA_KLASS);
if (!(strstr (klass, "Source") && strstr (klass, "Video")))
return FALSE;
/* only select elements with autoplugging rank */
rank = gst_plugin_feature_get_rank (feature);
if (rank < GST_RANK_MARGINAL)
return FALSE;
return TRUE;
}
static GstElement *
gst_auto_video_src_find_best (GstAutoVideoSrc * src)
{
GList *list, *item;
GstElement *choice = NULL;
GstMessage *message = NULL;
GSList *errors = NULL;
GstBus *bus = gst_bus_new ();
GstPad *el_pad = NULL;
GstCaps *el_caps = NULL;
gboolean no_match = TRUE;
list = gst_registry_feature_filter (gst_registry_get (),
(GstPluginFeatureFilter) gst_auto_video_src_factory_filter, FALSE, src);
list =
g_list_sort (list, (GCompareFunc) gst_plugin_feature_rank_compare_func);
GST_LOG_OBJECT (src, "Trying to find usable video devices ...");
for (item = list; item != NULL; item = item->next) {
GstElementFactory *f = GST_ELEMENT_FACTORY (item->data);
GstElement *el;
if ((el = gst_auto_create_element_with_pretty_name (GST_ELEMENT_CAST (src),
f, "src"))) {
GstStateChangeReturn ret;
GST_DEBUG_OBJECT (src, "Testing %s", GST_OBJECT_NAME (f));
/* If AutoVideoSrc has been provided with filter caps,
* accept only sources that match with the filter caps */
if (src->filter_caps) {
el_pad = gst_element_get_static_pad (GST_ELEMENT (el), "src");
el_caps = gst_pad_query_caps (el_pad, NULL);
gst_object_unref (el_pad);
GST_DEBUG_OBJECT (src,
"Checking caps: %" GST_PTR_FORMAT " vs. %" GST_PTR_FORMAT,
src->filter_caps, el_caps);
no_match = !gst_caps_can_intersect (src->filter_caps, el_caps);
gst_caps_unref (el_caps);
if (no_match) {
GST_DEBUG_OBJECT (src, "Incompatible caps");
gst_object_unref (el);
continue;
} else {
GST_DEBUG_OBJECT (src, "Found compatible caps");
}
}
gst_element_set_bus (el, bus);
ret = gst_element_set_state (el, GST_STATE_READY);
if (ret == GST_STATE_CHANGE_SUCCESS) {
GST_DEBUG_OBJECT (src, "This worked!");
choice = el;
break;
}
/* collect all error messages */
while ((message = gst_bus_pop_filtered (bus, GST_MESSAGE_ERROR))) {
GST_DEBUG_OBJECT (src, "error message %" GST_PTR_FORMAT, message);
errors = g_slist_append (errors, message);
}
gst_element_set_state (el, GST_STATE_NULL);
gst_object_unref (el);
}
}
GST_DEBUG_OBJECT (src, "done trying");
if (!choice) {
if (errors) {
/* FIXME: we forward the first error for now; but later on it might make
* sense to actually analyse them */
gst_message_ref (GST_MESSAGE (errors->data));
GST_DEBUG_OBJECT (src, "reposting message %p", errors->data);
gst_element_post_message (GST_ELEMENT (src), GST_MESSAGE (errors->data));
} else {
/* send warning message to application and use a fakesrc */
GST_ELEMENT_WARNING (src, RESOURCE, NOT_FOUND, (NULL),
("Failed to find a usable video source"));
choice = gst_element_factory_make ("fakesrc", "fake-video-src");
if (g_object_class_find_property (G_OBJECT_GET_CLASS (choice), "sync"))
g_object_set (choice, "sync", TRUE, NULL);
gst_element_set_state (choice, GST_STATE_READY);
}
}
gst_object_unref (bus);
gst_plugin_feature_list_free (list);
g_slist_foreach (errors, (GFunc) gst_mini_object_unref, NULL);
g_slist_free (errors);
return choice;
}
static gboolean
gst_auto_video_src_detect (GstAutoVideoSrc * src)
{
GstElement *esrc;
GstPad *targetpad;
gst_auto_video_src_clear_kid (src);
/* find element */
GST_DEBUG_OBJECT (src, "Creating new kid");
if (!(esrc = gst_auto_video_src_find_best (src)))
goto no_src;
src->kid = esrc;
gst_bin_add (GST_BIN (src), esrc);
/* attach ghost pad */
GST_DEBUG_OBJECT (src, "Re-assigning ghostpad");
targetpad = gst_element_get_static_pad (src->kid, "src");
if (!gst_ghost_pad_set_target (GST_GHOST_PAD (src->pad), targetpad))
goto target_failed;
gst_object_unref (targetpad);
GST_DEBUG_OBJECT (src, "done changing auto video source");
return TRUE;
/* ERRORS */
no_src:
{
GST_ELEMENT_ERROR (src, LIBRARY, INIT, (NULL),
("Failed to find a supported video source"));
return FALSE;
}
target_failed:
{
GST_ELEMENT_ERROR (src, LIBRARY, INIT, (NULL),
("Failed to set target pad"));
gst_object_unref (targetpad);
return FALSE;
}
}
static GstStateChangeReturn
gst_auto_video_src_change_state (GstElement * element,
GstStateChange transition)
{
GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
GstAutoVideoSrc *src = GST_AUTO_VIDEO_SRC (element);
switch (transition) {
case GST_STATE_CHANGE_NULL_TO_READY:
if (!gst_auto_video_src_detect (src))
return GST_STATE_CHANGE_FAILURE;
break;
default:
break;
}
ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
switch (transition) {
case GST_STATE_CHANGE_READY_TO_NULL:
gst_auto_video_src_reset (src);
break;
default:
break;
}
return ret;
}
static void
gst_auto_video_src_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec)
{
GstAutoVideoSrc *src = GST_AUTO_VIDEO_SRC (object);
switch (prop_id) {
case PROP_CAPS:
if (src->filter_caps)
gst_caps_unref (src->filter_caps);
src->filter_caps = gst_caps_copy (gst_value_get_caps (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gst_auto_video_src_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec)
{
GstAutoVideoSrc *src = GST_AUTO_VIDEO_SRC (object);
switch (prop_id) {
case PROP_CAPS:{
gst_value_set_caps (value, src->filter_caps);
break;
}
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
autodetect->media_klass = "Video";
autodetect->flag = GST_ELEMENT_FLAG_SOURCE;
}

View file

@ -22,6 +22,7 @@
#define __GST_AUTO_VIDEO_SRC_H__
#include <gst/gst.h>
#include "gstautodetect.h"
G_BEGIN_DECLS
@ -39,16 +40,11 @@ G_BEGIN_DECLS
(G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_AUTO_VIDEO_SRC))
typedef struct _GstAutoVideoSrc {
GstBin parent;
/* explicit pointers to stuff used */
GstPad *pad;
GstElement *kid;
GstCaps *filter_caps;
GstAutoDetect parent;
} GstAutoVideoSrc;
typedef struct _GstAutoVideoSrcClass {
GstBinClass parent_class;
GstAutoDetectClass parent_class;
} GstAutoVideoSrcClass;
GType gst_auto_video_src_get_type (void);