Branch data Line data Source code
1 : : /* GStreamer
2 : : * Copyright (C) 2010 David Schleef <ds@schleef.org>
3 : : *
4 : : * This library is free software; you can redistribute it and/or
5 : : * modify it under the terms of the GNU Library General Public
6 : : * License as published by the Free Software Foundation; either
7 : : * version 2 of the License, or (at your option) any later version.
8 : : *
9 : : * This library is distributed in the hope that it will be useful,
10 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 : : * Library General Public License for more details.
13 : : *
14 : : * You should have received a copy of the GNU Library General Public
15 : : * License along with this library; if not, write to the
16 : : * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 : : * Boston, MA 02111-1307, USA.
18 : : */
19 : : /**
20 : : * SECTION:element-gstsdimux
21 : : *
22 : : * The gstsdimux element does FIXME stuff.
23 : : *
24 : : * <refsect2>
25 : : * <title>Example launch line</title>
26 : : * |[
27 : : * gst-launch -v fakesrc ! gstsdimux ! FIXME ! fakesink
28 : : * ]|
29 : : * FIXME Describe what the pipeline does.
30 : : * </refsect2>
31 : : */
32 : :
33 : : #ifdef HAVE_CONFIG_H
34 : : #include "config.h"
35 : : #endif
36 : :
37 : : #include <gst/gst.h>
38 : : #include <gst/gst.h>
39 : : #include "gstsdimux.h"
40 : :
41 : : /* prototypes */
42 : :
43 : :
44 : : static void gst_sdi_mux_set_property (GObject * object,
45 : : guint property_id, const GValue * value, GParamSpec * pspec);
46 : : static void gst_sdi_mux_get_property (GObject * object,
47 : : guint property_id, GValue * value, GParamSpec * pspec);
48 : : static void gst_sdi_mux_dispose (GObject * object);
49 : : static void gst_sdi_mux_finalize (GObject * object);
50 : :
51 : : static GstPad *gst_sdi_mux_request_new_pad (GstElement * element,
52 : : GstPadTemplate * templ, const gchar * name);
53 : : static void gst_sdi_mux_release_pad (GstElement * element, GstPad * pad);
54 : : static GstStateChangeReturn
55 : : gst_sdi_mux_change_state (GstElement * element, GstStateChange transition);
56 : : static const GstQueryType *gst_sdi_mux_get_query_types (GstElement * element);
57 : : static gboolean gst_sdi_mux_query (GstElement * element, GstQuery * query);
58 : : static GstFlowReturn gst_sdi_mux_chain (GstPad * pad, GstBuffer * buffer);
59 : : static gboolean gst_sdi_mux_sink_event (GstPad * pad, GstEvent * event);
60 : : static gboolean gst_sdi_mux_src_event (GstPad * pad, GstEvent * event);
61 : :
62 : : enum
63 : : {
64 : : PROP_0
65 : : };
66 : :
67 : : /* pad templates */
68 : :
69 : : #define GST_VIDEO_CAPS_NTSC(fourcc) \
70 : : "video/x-raw-yuv,format=(fourcc)" fourcc ",width=720,height=480," \
71 : : "framerate=30000/1001,interlaced=TRUE,pixel-aspect-ratio=10/11," \
72 : : "chroma-site=mpeg2,color-matrix=sdtv"
73 : : #define GST_VIDEO_CAPS_NTSC_WIDE(fourcc) \
74 : : "video/x-raw-yuv,format=(fourcc)" fourcc ",width=720,height=480," \
75 : : "framerate=30000/1001,interlaced=TRUE,pixel-aspect-ratio=40/33," \
76 : : "chroma-site=mpeg2,color-matrix=sdtv"
77 : : #define GST_VIDEO_CAPS_PAL(fourcc) \
78 : : "video/x-raw-yuv,format=(fourcc)" fourcc ",width=720,height=576," \
79 : : "framerate=25/1,interlaced=TRUE,pixel-aspect-ratio=12/11," \
80 : : "chroma-site=mpeg2,color-matrix=sdtv"
81 : : #define GST_VIDEO_CAPS_PAL_WIDE(fourcc) \
82 : : "video/x-raw-yuv,format=(fourcc)" fourcc ",width=720,height=576," \
83 : : "framerate=25/1,interlaced=TRUE,pixel-aspect-ratio=16/11," \
84 : : "chroma-site=mpeg2,color-matrix=sdtv"
85 : :
86 : : static GstStaticPadTemplate gst_sdi_mux_sink_template =
87 : : GST_STATIC_PAD_TEMPLATE ("sink",
88 : : GST_PAD_SINK,
89 : : GST_PAD_ALWAYS,
90 : : GST_STATIC_CAPS (GST_VIDEO_CAPS_NTSC ("{UYVY,v210}") ";"
91 : : GST_VIDEO_CAPS_PAL ("{UYVY,v210}"))
92 : : );
93 : :
94 : : static GstStaticPadTemplate gst_sdi_mux_src_template =
95 : : GST_STATIC_PAD_TEMPLATE ("src",
96 : : GST_PAD_SRC,
97 : : GST_PAD_ALWAYS,
98 : : GST_STATIC_CAPS
99 : : ("application/x-raw-sdi,rate=270,format=(fourcc){UYVY,v210}")
100 : : );
101 : :
102 : : /* class initialization */
103 : :
104 [ + + ]: 29 : GST_BOILERPLATE (GstSdiMux, gst_sdi_mux, GstElement, GST_TYPE_ELEMENT);
105 : :
106 : : static void
107 : 6 : gst_sdi_mux_base_init (gpointer g_class)
108 : : {
109 : 6 : GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
110 : :
111 : 6 : gst_element_class_add_pad_template (element_class,
112 : : gst_static_pad_template_get (&gst_sdi_mux_src_template));
113 : 6 : gst_element_class_add_pad_template (element_class,
114 : : gst_static_pad_template_get (&gst_sdi_mux_sink_template));
115 : :
116 : 6 : gst_element_class_set_details_simple (element_class, "SDI Muxer",
117 : : "Muxer",
118 : : "Multiplex raw audio and video into SDI",
119 : : "David Schleef <ds@schleef.org>");
120 : 6 : }
121 : :
122 : : static void
123 : 6 : gst_sdi_mux_class_init (GstSdiMuxClass * klass)
124 : : {
125 : 6 : GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
126 : 6 : GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
127 : :
128 : 6 : gobject_class->set_property = gst_sdi_mux_set_property;
129 : 6 : gobject_class->get_property = gst_sdi_mux_get_property;
130 : 6 : gobject_class->dispose = gst_sdi_mux_dispose;
131 : 6 : gobject_class->finalize = gst_sdi_mux_finalize;
132 : 6 : element_class->request_new_pad =
133 : 6 : GST_DEBUG_FUNCPTR (gst_sdi_mux_request_new_pad);
134 : 6 : element_class->release_pad = GST_DEBUG_FUNCPTR (gst_sdi_mux_release_pad);
135 : 6 : element_class->change_state = GST_DEBUG_FUNCPTR (gst_sdi_mux_change_state);
136 : 6 : element_class->get_query_types =
137 : 6 : GST_DEBUG_FUNCPTR (gst_sdi_mux_get_query_types);
138 : 6 : element_class->query = GST_DEBUG_FUNCPTR (gst_sdi_mux_query);
139 : :
140 : 6 : }
141 : :
142 : : static void
143 : 4 : gst_sdi_mux_init (GstSdiMux * sdimux, GstSdiMuxClass * sdimux_class)
144 : : {
145 : :
146 : 4 : sdimux->sinkpad =
147 : 4 : gst_pad_new_from_static_template (&gst_sdi_mux_sink_template, "sink");
148 : 4 : gst_pad_set_event_function (sdimux->sinkpad,
149 : 4 : GST_DEBUG_FUNCPTR (gst_sdi_mux_sink_event));
150 : 4 : gst_pad_set_chain_function (sdimux->sinkpad,
151 : 4 : GST_DEBUG_FUNCPTR (gst_sdi_mux_chain));
152 : 4 : gst_element_add_pad (GST_ELEMENT (sdimux), sdimux->sinkpad);
153 : :
154 : 4 : sdimux->srcpad = gst_pad_new_from_static_template (&gst_sdi_mux_src_template,
155 : : "src");
156 : 4 : gst_pad_set_event_function (sdimux->srcpad,
157 : 4 : GST_DEBUG_FUNCPTR (gst_sdi_mux_src_event));
158 : 4 : gst_element_add_pad (GST_ELEMENT (sdimux), sdimux->srcpad);
159 : :
160 : 4 : }
161 : :
162 : : void
163 : 0 : gst_sdi_mux_set_property (GObject * object, guint property_id,
164 : : const GValue * value, GParamSpec * pspec)
165 : : {
166 : : GstSdiMux *sdimux;
167 : :
168 [ # # ][ # # ]: 0 : g_return_if_fail (GST_IS_SDI_MUX (object));
[ # # ][ # # ]
169 : 0 : sdimux = GST_SDI_MUX (object);
170 : :
171 : : switch (property_id) {
172 : : default:
173 : 0 : G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
174 : 0 : break;
175 : : }
176 : : }
177 : :
178 : : void
179 : 0 : gst_sdi_mux_get_property (GObject * object, guint property_id,
180 : : GValue * value, GParamSpec * pspec)
181 : : {
182 : : GstSdiMux *sdimux;
183 : :
184 [ # # ][ # # ]: 0 : g_return_if_fail (GST_IS_SDI_MUX (object));
[ # # ][ # # ]
185 : 0 : sdimux = GST_SDI_MUX (object);
186 : :
187 : : switch (property_id) {
188 : : default:
189 : 0 : G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
190 : 0 : break;
191 : : }
192 : : }
193 : :
194 : : void
195 : 4 : gst_sdi_mux_dispose (GObject * object)
196 : : {
197 : : GstSdiMux *sdimux;
198 : :
199 [ - + ][ + - ]: 8 : g_return_if_fail (GST_IS_SDI_MUX (object));
[ + - ][ - + ]
200 : 4 : sdimux = GST_SDI_MUX (object);
201 : :
202 : : /* clean up as possible. may be called multiple times */
203 : :
204 : 4 : G_OBJECT_CLASS (parent_class)->dispose (object);
205 : : }
206 : :
207 : : void
208 : 4 : gst_sdi_mux_finalize (GObject * object)
209 : : {
210 : : GstSdiMux *sdimux;
211 : :
212 [ - + ][ + - ]: 8 : g_return_if_fail (GST_IS_SDI_MUX (object));
[ + - ][ - + ]
213 : 4 : sdimux = GST_SDI_MUX (object);
214 : :
215 : : /* clean up object here */
216 : :
217 : 4 : G_OBJECT_CLASS (parent_class)->finalize (object);
218 : : }
219 : :
220 : :
221 : :
222 : : static GstPad *
223 : 0 : gst_sdi_mux_request_new_pad (GstElement * element, GstPadTemplate * templ,
224 : : const gchar * name)
225 : : {
226 : :
227 : 0 : return NULL;
228 : : }
229 : :
230 : : static void
231 : 0 : gst_sdi_mux_release_pad (GstElement * element, GstPad * pad)
232 : : {
233 : :
234 : 0 : }
235 : :
236 : : static GstStateChangeReturn
237 : 34 : gst_sdi_mux_change_state (GstElement * element, GstStateChange transition)
238 : : {
239 : :
240 : 34 : return GST_STATE_CHANGE_SUCCESS;
241 : : }
242 : :
243 : : static const GstQueryType *
244 : 0 : gst_sdi_mux_get_query_types (GstElement * element)
245 : : {
246 : :
247 : 0 : return NULL;
248 : : }
249 : :
250 : : static gboolean
251 : 0 : gst_sdi_mux_query (GstElement * element, GstQuery * query)
252 : : {
253 : :
254 : 0 : return FALSE;
255 : : }
256 : :
257 : : static GstFlowReturn
258 : 0 : gst_sdi_mux_chain (GstPad * pad, GstBuffer * buffer)
259 : : {
260 : : GstSdiMux *sdimux;
261 : :
262 : 0 : sdimux = GST_SDI_MUX (gst_pad_get_parent (pad));
263 : :
264 [ # # ]: 0 : GST_DEBUG_OBJECT (sdimux, "chain");
265 : :
266 : :
267 : 0 : gst_object_unref (sdimux);
268 : 0 : return GST_FLOW_OK;
269 : : }
270 : :
271 : : static gboolean
272 : 0 : gst_sdi_mux_sink_event (GstPad * pad, GstEvent * event)
273 : : {
274 : : gboolean res;
275 : : GstSdiMux *sdimux;
276 : :
277 : 0 : sdimux = GST_SDI_MUX (gst_pad_get_parent (pad));
278 : :
279 [ # # ]: 0 : GST_DEBUG_OBJECT (sdimux, "event");
280 : :
281 [ # # # # : 0 : switch (GST_EVENT_TYPE (event)) {
# ]
282 : : case GST_EVENT_FLUSH_START:
283 : 0 : res = gst_pad_push_event (sdimux->srcpad, event);
284 : 0 : break;
285 : : case GST_EVENT_FLUSH_STOP:
286 : 0 : res = gst_pad_push_event (sdimux->srcpad, event);
287 : 0 : break;
288 : : case GST_EVENT_NEWSEGMENT:
289 : 0 : res = gst_pad_push_event (sdimux->srcpad, event);
290 : 0 : break;
291 : : case GST_EVENT_EOS:
292 : 0 : res = gst_pad_push_event (sdimux->srcpad, event);
293 : 0 : break;
294 : : default:
295 : 0 : res = gst_pad_push_event (sdimux->srcpad, event);
296 : 0 : break;
297 : : }
298 : :
299 : 0 : gst_object_unref (sdimux);
300 : 0 : return TRUE;
301 : : }
302 : :
303 : : static gboolean
304 : 0 : gst_sdi_mux_src_event (GstPad * pad, GstEvent * event)
305 : : {
306 : : gboolean res;
307 : : GstSdiMux *sdimux;
308 : :
309 : 0 : sdimux = GST_SDI_MUX (gst_pad_get_parent (pad));
310 : :
311 [ # # ]: 0 : GST_DEBUG_OBJECT (sdimux, "event");
312 : :
313 [ # # ]: 0 : switch (GST_EVENT_TYPE (event)) {
314 : : case GST_EVENT_SEEK:
315 : 0 : res = gst_pad_push_event (sdimux->sinkpad, event);
316 : 0 : break;
317 : : default:
318 : 0 : res = gst_pad_push_event (sdimux->sinkpad, event);
319 : 0 : break;
320 : : }
321 : :
322 : 0 : gst_object_unref (sdimux);
323 : 0 : return TRUE;
324 : : }
|