hythmbox-2.98/plugins/fmradio/rb-fm-radio-gst-src.c

No issues found

  1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
  2  *
  3  *  Copyright (C) 2007  James Henstridge <james@jamesh.id.au>
  4  *
  5  *  This program is free software; you can redistribute it and/or modify
  6  *  it under the terms of the GNU General Public License as published by
  7  *  the Free Software Foundation; either version 2 of the License, or
  8  *  (at your option) any later version.
  9  *
 10  *  The Rhythmbox authors hereby grant permission for non-GPL compatible
 11  *  GStreamer plugins to be used and distributed together with GStreamer
 12  *  and Rhythmbox. This permission is above and beyond the permissions granted
 13  *  by the GPL license by which Rhythmbox is covered. If you modify this code
 14  *  you may extend this exception to your version of the code, but you are not
 15  *  obligated to do so. If you do not wish to do so, delete this exception
 16  *  statement from your version.
 17  *
 18  *  This program is distributed in the hope that it will be useful,
 19  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 20  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 21  *  GNU General Public License for more details.
 22  *
 23  *  You should have received a copy of the GNU General Public License
 24  *  along with this program; if not, write to the Free Software
 25  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA.
 26  *
 27  */
 28 
 29 #include "config.h"
 30 
 31 #include <string.h>
 32 
 33 #include "rb-debug.h"
 34 
 35 #include <gst/gst.h>
 36 
 37 #define RB_TYPE_FM_RADIO_SRC (rb_fm_radio_src_get_type())
 38 #define RB_FM_RADIO_SRC(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),RB_TYPE_FM_RADIO_SRC,RBFMRadioSrc))
 39 #define RB_FM_RADIO_SRC_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),RB_TYPE_FM_RADIO_SRC,RBFMRadioSrcClass))
 40 #define RB_IS_LASTFM_SRC(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),RB_TYPE_FM_RADIO_SRC))
 41 #define RB_IS_LASTFM_SRC_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE((klass),RB_TYPE_FM_RADIO_SRC))
 42 
 43 typedef struct _RBFMRadioSrc RBFMRadioSrc;
 44 typedef struct _RBFMRadioSrcClass RBFMRadioSrcClass;
 45 
 46 struct _RBFMRadioSrc
 47 {
 48 	GstBin parent;
 49 
 50 	GstElement *audiotestsrc;
 51 	GstPad *ghostpad;
 52 };
 53 
 54 struct _RBFMRadioSrcClass
 55 {
 56 	GstBinClass parent_class;
 57 };
 58 
 59 static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
 60 	GST_PAD_SRC,
 61 	GST_PAD_ALWAYS,
 62 	GST_STATIC_CAPS_ANY);
 63 
 64 static GstElementDetails rb_fm_radio_src_details =
 65 GST_ELEMENT_DETAILS ("RB Silence Source",
 66 	"Source/File",
 67 	"Outputs buffers of silence",
 68 	"James Henstridge <james@jamesh.id.au>");
 69 
 70 GType rb_fm_radio_src_get_type (void);
 71 static void rb_fm_radio_src_uri_handler_init (gpointer g_iface,
 72 					      gpointer iface_data);
 73 
 74 static void
 75 _do_init (GType fmradio_src_type)
 76 {
 77 	static const GInterfaceInfo urihandler_info = {
 78 		rb_fm_radio_src_uri_handler_init,
 79 		NULL,
 80 		NULL
 81 	};
 82 
 83 	g_type_add_interface_static (fmradio_src_type, GST_TYPE_URI_HANDLER,
 84 				     &urihandler_info);
 85 }
 86 
 87 GST_BOILERPLATE_FULL (RBFMRadioSrc, rb_fm_radio_src,
 88 		      GstBin, GST_TYPE_BIN, _do_init);
 89 
 90 static void
 91 rb_fm_radio_src_base_init (gpointer g_class)
 92 {
 93 	GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
 94 	gst_element_class_add_pad_template (element_class,
 95 		gst_static_pad_template_get (&srctemplate));
 96 	gst_element_class_set_details (element_class, &rb_fm_radio_src_details);
 97 }
 98 
 99 static void
100 rb_fm_radio_src_init (RBFMRadioSrc *src, RBFMRadioSrcClass *klass)
101 {
102 	GstPad *pad;
103 
104 	rb_debug ("creating rb silence src element");
105 
106 	src->audiotestsrc = gst_element_factory_make ("audiotestsrc", NULL);
107 	gst_bin_add (GST_BIN (src), src->audiotestsrc);
108 	gst_object_ref (src->audiotestsrc);
109 
110 	/* set the audiotestsrc to generate silence (wave type 4) */
111 	g_object_set (src->audiotestsrc,
112 		      "wave", 4,
113 		      NULL);
114 
115 	pad = gst_element_get_static_pad (src->audiotestsrc, "src");
116 	src->ghostpad = gst_ghost_pad_new ("src", pad);
117 	gst_element_add_pad (GST_ELEMENT (src), src->ghostpad);
118 	gst_object_ref (src->ghostpad);
119 	gst_object_unref (pad);
120 	
121 }
122 
123 static void
124 rb_fm_radio_src_finalize (GObject *object)
125 {
126 	RBFMRadioSrc *src = RB_FM_RADIO_SRC (object);
127 
128 	if (src->ghostpad)
129 		gst_object_unref (src->ghostpad);
130 	if (src->audiotestsrc)
131 		gst_object_unref (src->audiotestsrc);
132 
133 	G_OBJECT_CLASS (parent_class)->finalize (object);
134 }
135 
136 static void
137 rb_fm_radio_src_class_init (RBFMRadioSrcClass *klass)
138 {
139 	GObjectClass *object_class;
140 
141 	object_class = G_OBJECT_CLASS (klass);
142 	object_class->finalize = rb_fm_radio_src_finalize;
143 }
144 
145 
146 /* URI handler interface */
147 
148 static guint
149 rb_fm_radio_src_uri_get_type (void)
150 {
151 	return GST_URI_SRC;
152 }
153 
154 static gchar **
155 rb_fm_radio_src_uri_get_protocols (void)
156 {
157 	static gchar *protocols[] = {"xrbsilence", NULL};
158 	return protocols;
159 }
160 
161 static const gchar *
162 rb_fm_radio_src_uri_get_uri (GstURIHandler *handler)
163 {
164 	return "xrbsilence:///";
165 }
166 
167 static gboolean
168 rb_fm_radio_src_uri_set_uri (GstURIHandler *handler,
169 			   const gchar *uri)
170 {
171 	if (g_str_has_prefix (uri, "xrbsilence://") == FALSE)
172 		return FALSE;
173 
174 	return TRUE;
175 }
176 
177 static void
178 rb_fm_radio_src_uri_handler_init (gpointer g_iface,
179 				gpointer iface_data)
180 {
181 	GstURIHandlerInterface *iface = (GstURIHandlerInterface *) g_iface;
182 
183 	iface->get_type = rb_fm_radio_src_uri_get_type;
184 	iface->get_protocols = rb_fm_radio_src_uri_get_protocols;
185 	iface->get_uri = rb_fm_radio_src_uri_get_uri;
186 	iface->set_uri = rb_fm_radio_src_uri_set_uri;
187 }
188 
189 static gboolean
190 plugin_init (GstPlugin *plugin)
191 {
192 	gboolean ret = gst_element_register (plugin, "rbsilencesrc", GST_RANK_PRIMARY, RB_TYPE_FM_RADIO_SRC);
193 	return ret;
194 }
195 
196 GST_PLUGIN_DEFINE_STATIC (GST_VERSION_MAJOR,
197 			  GST_VERSION_MINOR,
198 			  "rbsilencesrc",
199 			  "element to output silence",
200 			  plugin_init,
201 			  VERSION,
202 			  "GPL",
203 			  PACKAGE,
204 			  "");