• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* GStreamer
2  * (c) 2005 Ronald S. Bultje <rbultje@ronald.bitfreak.net>
3  * (c) 2006 Jan Schmidt <thaytan@noraisin.net>
4  * (c) 2008 Stefan Kost <ensonic@users.sf.net>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the
18  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  */
21 
22 /**
23  * SECTION:element-autovideosrc
24  * @title: autovideosrc
25  * @see_also: autoaudiosrc, v4l2src, v4lsrc
26  *
27  * autovideosrc is a video src that automatically detects an appropriate
28  * video source to use.  It does so by scanning the registry for all elements
29  * that have "Source" and "Video" in the class field
30  * of their element information, and also have a non-zero autoplugging rank.
31  *
32  * ## Example launch line
33  * |[
34  * gst-launch-1.0 -v -m autovideosrc ! xvimagesink
35  * ]|
36  *
37  */
38 
39 #ifdef HAVE_CONFIG_H
40 #include "config.h"
41 #endif
42 
43 #include "gstautodetectelements.h"
44 #include "gstautodetect.h"
45 #include "gstautovideosrc.h"
46 
47 G_DEFINE_TYPE (GstAutoVideoSrc, gst_auto_video_src, GST_TYPE_AUTO_DETECT);
48 GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (autovideosrc, "autovideosrc",
49     GST_RANK_NONE, GST_TYPE_AUTO_VIDEO_SRC, autodetect_element_init (plugin));
50 
51 static GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE ("src",
52     GST_PAD_SRC,
53     GST_PAD_ALWAYS,
54     GST_STATIC_CAPS_ANY);
55 
56 static GstElement *
gst_auto_video_src_create_fake_element(GstAutoDetect * autodetect)57 gst_auto_video_src_create_fake_element (GstAutoDetect * autodetect)
58 {
59   GstElement *fake;
60 
61   fake = gst_element_factory_make ("videotestsrc", "fake-auto-video-src");
62   if (fake != NULL) {
63     g_object_set (fake, "is-live", TRUE, NULL);
64   } else {
65     GST_ELEMENT_ERROR (autodetect, RESOURCE, NOT_FOUND,
66         ("Failed to find usable video source element."),
67         ("Failed to find a usable video source and couldn't create a video"
68             "testsrc as fallback either, check your GStreamer installation."));
69     /* This will error out with not-negotiated.. */
70     fake = gst_element_factory_make ("fakesrc", "fake-auto-video-src");
71   }
72   return fake;
73 }
74 
75 static void
gst_auto_video_src_class_init(GstAutoVideoSrcClass * klass)76 gst_auto_video_src_class_init (GstAutoVideoSrcClass * klass)
77 {
78   GstAutoDetectClass *autoclass = GST_AUTO_DETECT_CLASS (klass);
79   GstElementClass *eklass = GST_ELEMENT_CLASS (klass);
80 
81   gst_element_class_add_static_pad_template (eklass, &src_template);
82   gst_element_class_set_static_metadata (eklass, "Auto video source",
83       "Source/Video",
84       "Wrapper video source for automatically detected video source",
85       "Jan Schmidt <thaytan@noraisin.net>, "
86       "Stefan Kost <ensonic@users.sf.net>");
87 
88   autoclass->create_fake_element = gst_auto_video_src_create_fake_element;
89 }
90 
91 static void
gst_auto_video_src_init(GstAutoVideoSrc * src)92 gst_auto_video_src_init (GstAutoVideoSrc * src)
93 {
94   GstAutoDetect *autodetect = GST_AUTO_DETECT (src);
95 
96   autodetect->media_klass = "Video";
97   autodetect->flag = GST_ELEMENT_FLAG_SOURCE;
98 }
99