codecparser: mpeg4 type error
[profile/ivi/gst-plugins-bad.git] / gst / sdi / gstsdimux.c
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 GST_BOILERPLATE (GstSdiMux, gst_sdi_mux, GstElement, GST_TYPE_ELEMENT);
105
106 static void
107 gst_sdi_mux_base_init (gpointer g_class)
108 {
109   GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
110
111   gst_element_class_add_static_pad_template (element_class,
112       &gst_sdi_mux_src_template);
113   gst_element_class_add_static_pad_template (element_class,
114       &gst_sdi_mux_sink_template);
115
116   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 }
121
122 static void
123 gst_sdi_mux_class_init (GstSdiMuxClass * klass)
124 {
125   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
126   GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
127
128   gobject_class->set_property = gst_sdi_mux_set_property;
129   gobject_class->get_property = gst_sdi_mux_get_property;
130   gobject_class->dispose = gst_sdi_mux_dispose;
131   gobject_class->finalize = gst_sdi_mux_finalize;
132   element_class->request_new_pad =
133       GST_DEBUG_FUNCPTR (gst_sdi_mux_request_new_pad);
134   element_class->release_pad = GST_DEBUG_FUNCPTR (gst_sdi_mux_release_pad);
135   element_class->change_state = GST_DEBUG_FUNCPTR (gst_sdi_mux_change_state);
136   element_class->get_query_types =
137       GST_DEBUG_FUNCPTR (gst_sdi_mux_get_query_types);
138   element_class->query = GST_DEBUG_FUNCPTR (gst_sdi_mux_query);
139
140 }
141
142 static void
143 gst_sdi_mux_init (GstSdiMux * sdimux, GstSdiMuxClass * sdimux_class)
144 {
145
146   sdimux->sinkpad =
147       gst_pad_new_from_static_template (&gst_sdi_mux_sink_template, "sink");
148   gst_pad_set_event_function (sdimux->sinkpad,
149       GST_DEBUG_FUNCPTR (gst_sdi_mux_sink_event));
150   gst_pad_set_chain_function (sdimux->sinkpad,
151       GST_DEBUG_FUNCPTR (gst_sdi_mux_chain));
152   gst_element_add_pad (GST_ELEMENT (sdimux), sdimux->sinkpad);
153
154   sdimux->srcpad = gst_pad_new_from_static_template (&gst_sdi_mux_src_template,
155       "src");
156   gst_pad_set_event_function (sdimux->srcpad,
157       GST_DEBUG_FUNCPTR (gst_sdi_mux_src_event));
158   gst_element_add_pad (GST_ELEMENT (sdimux), sdimux->srcpad);
159
160 }
161
162 void
163 gst_sdi_mux_set_property (GObject * object, guint property_id,
164     const GValue * value, GParamSpec * pspec)
165 {
166   g_return_if_fail (GST_IS_SDI_MUX (object));
167
168   switch (property_id) {
169     default:
170       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
171       break;
172   }
173 }
174
175 void
176 gst_sdi_mux_get_property (GObject * object, guint property_id,
177     GValue * value, GParamSpec * pspec)
178 {
179   g_return_if_fail (GST_IS_SDI_MUX (object));
180
181   switch (property_id) {
182     default:
183       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
184       break;
185   }
186 }
187
188 void
189 gst_sdi_mux_dispose (GObject * object)
190 {
191   g_return_if_fail (GST_IS_SDI_MUX (object));
192
193   /* clean up as possible.  may be called multiple times */
194
195   G_OBJECT_CLASS (parent_class)->dispose (object);
196 }
197
198 void
199 gst_sdi_mux_finalize (GObject * object)
200 {
201   g_return_if_fail (GST_IS_SDI_MUX (object));
202
203   /* clean up object here */
204
205   G_OBJECT_CLASS (parent_class)->finalize (object);
206 }
207
208
209
210 static GstPad *
211 gst_sdi_mux_request_new_pad (GstElement * element, GstPadTemplate * templ,
212     const gchar * name)
213 {
214
215   return NULL;
216 }
217
218 static void
219 gst_sdi_mux_release_pad (GstElement * element, GstPad * pad)
220 {
221
222 }
223
224 static GstStateChangeReturn
225 gst_sdi_mux_change_state (GstElement * element, GstStateChange transition)
226 {
227
228   return GST_STATE_CHANGE_SUCCESS;
229 }
230
231 static const GstQueryType *
232 gst_sdi_mux_get_query_types (GstElement * element)
233 {
234
235   return NULL;
236 }
237
238 static gboolean
239 gst_sdi_mux_query (GstElement * element, GstQuery * query)
240 {
241
242   return FALSE;
243 }
244
245 static GstFlowReturn
246 gst_sdi_mux_chain (GstPad * pad, GstBuffer * buffer)
247 {
248   GstSdiMux *sdimux;
249
250   sdimux = GST_SDI_MUX (gst_pad_get_parent (pad));
251
252   GST_DEBUG_OBJECT (sdimux, "chain");
253
254
255   gst_object_unref (sdimux);
256   return GST_FLOW_OK;
257 }
258
259 static gboolean
260 gst_sdi_mux_sink_event (GstPad * pad, GstEvent * event)
261 {
262   gboolean res;
263   GstSdiMux *sdimux;
264
265   sdimux = GST_SDI_MUX (gst_pad_get_parent (pad));
266
267   GST_DEBUG_OBJECT (sdimux, "event");
268
269   switch (GST_EVENT_TYPE (event)) {
270     case GST_EVENT_FLUSH_START:
271       res = gst_pad_push_event (sdimux->srcpad, event);
272       break;
273     case GST_EVENT_FLUSH_STOP:
274       res = gst_pad_push_event (sdimux->srcpad, event);
275       break;
276     case GST_EVENT_NEWSEGMENT:
277       res = gst_pad_push_event (sdimux->srcpad, event);
278       break;
279     case GST_EVENT_EOS:
280       res = gst_pad_push_event (sdimux->srcpad, event);
281       break;
282     default:
283       res = gst_pad_push_event (sdimux->srcpad, event);
284       break;
285   }
286
287   gst_object_unref (sdimux);
288   return res;
289 }
290
291 static gboolean
292 gst_sdi_mux_src_event (GstPad * pad, GstEvent * event)
293 {
294   gboolean res;
295   GstSdiMux *sdimux;
296
297   sdimux = GST_SDI_MUX (gst_pad_get_parent (pad));
298
299   GST_DEBUG_OBJECT (sdimux, "event");
300
301   switch (GST_EVENT_TYPE (event)) {
302     case GST_EVENT_SEEK:
303       res = gst_pad_push_event (sdimux->sinkpad, event);
304       break;
305     default:
306       res = gst_pad_push_event (sdimux->sinkpad, event);
307       break;
308   }
309
310   gst_object_unref (sdimux);
311   return res;
312 }