tizen 2.0 init
[framework/multimedia/gst-plugins-good0.10.git] / gst / rtp / gstrtpmp2tdepay.c
1 /* GStreamer
2  * Copyright (C) <2005> Wim Taymans <wim.taymans@gmail.com>
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 #ifdef HAVE_CONFIG_H
21 #  include "config.h"
22 #endif
23
24 #include <gst/rtp/gstrtpbuffer.h>
25
26 #include <string.h>
27 #include "gstrtpmp2tdepay.h"
28
29 /* RtpMP2TDepay signals and args */
30 enum
31 {
32   /* FILL ME */
33   LAST_SIGNAL
34 };
35
36 #define DEFAULT_SKIP_FIRST_BYTES        0
37
38 enum
39 {
40   PROP_0,
41   PROP_SKIP_FIRST_BYTES
42 };
43
44 static GstStaticPadTemplate gst_rtp_mp2t_depay_src_template =
45 GST_STATIC_PAD_TEMPLATE ("src",
46     GST_PAD_SRC,
47     GST_PAD_ALWAYS,
48     GST_STATIC_CAPS ("video/mpegts,"
49         "packetsize=(int)188," "systemstream=(boolean)true")
50     );
51
52 static GstStaticPadTemplate gst_rtp_mp2t_depay_sink_template =
53     GST_STATIC_PAD_TEMPLATE ("sink",
54     GST_PAD_SINK,
55     GST_PAD_ALWAYS,
56     GST_STATIC_CAPS ("application/x-rtp, "
57         "media = (string) \"video\", "
58         "payload = (int) " GST_RTP_PAYLOAD_DYNAMIC_STRING ", "
59         "clock-rate = (int) [1, MAX ], " "encoding-name = (string) \"MP2T-ES\";"
60         /* All optional parameters
61          *
62          * "profile-level-id=[1,MAX]"
63          * "config=" 
64          */
65         "application/x-rtp, "
66         "media = (string) \"video\", "
67         "payload = (int) " GST_RTP_PAYLOAD_MP2T_STRING ", "
68         "clock-rate = (int) [1, MAX ]")
69     );
70
71 GST_BOILERPLATE (GstRtpMP2TDepay, gst_rtp_mp2t_depay, GstBaseRTPDepayload,
72     GST_TYPE_BASE_RTP_DEPAYLOAD);
73
74 static gboolean gst_rtp_mp2t_depay_setcaps (GstBaseRTPDepayload * depayload,
75     GstCaps * caps);
76 static GstBuffer *gst_rtp_mp2t_depay_process (GstBaseRTPDepayload * depayload,
77     GstBuffer * buf);
78
79 static void gst_rtp_mp2t_depay_set_property (GObject * object, guint prop_id,
80     const GValue * value, GParamSpec * pspec);
81 static void gst_rtp_mp2t_depay_get_property (GObject * object, guint prop_id,
82     GValue * value, GParamSpec * pspec);
83
84 static void
85 gst_rtp_mp2t_depay_base_init (gpointer klass)
86 {
87   GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
88
89   gst_element_class_add_static_pad_template (element_class,
90       &gst_rtp_mp2t_depay_src_template);
91   gst_element_class_add_static_pad_template (element_class,
92       &gst_rtp_mp2t_depay_sink_template);
93
94   gst_element_class_set_details_simple (element_class,
95       "RTP MPEG Transport Stream depayloader", "Codec/Depayloader/Network/RTP",
96       "Extracts MPEG2 TS from RTP packets (RFC 2250)",
97       "Wim Taymans <wim.taymans@gmail.com>, "
98       "Thijs Vermeir <thijs.vermeir@barco.com>");
99 }
100
101 static void
102 gst_rtp_mp2t_depay_class_init (GstRtpMP2TDepayClass * klass)
103 {
104   GObjectClass *gobject_class;
105   GstBaseRTPDepayloadClass *gstbasertpdepayload_class;
106
107   gobject_class = (GObjectClass *) klass;
108
109   gstbasertpdepayload_class = (GstBaseRTPDepayloadClass *) klass;
110
111   gstbasertpdepayload_class->process = gst_rtp_mp2t_depay_process;
112   gstbasertpdepayload_class->set_caps = gst_rtp_mp2t_depay_setcaps;
113
114   gobject_class->set_property = gst_rtp_mp2t_depay_set_property;
115   gobject_class->get_property = gst_rtp_mp2t_depay_get_property;
116
117   g_object_class_install_property (gobject_class, PROP_SKIP_FIRST_BYTES,
118       g_param_spec_uint ("skip-first-bytes",
119           "Skip first bytes",
120           "The amount of bytes that need to be skipped at the beginning of the payload",
121           0, G_MAXUINT, 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
122
123 }
124
125 static void
126 gst_rtp_mp2t_depay_init (GstRtpMP2TDepay * rtpmp2tdepay,
127     GstRtpMP2TDepayClass * klass)
128 {
129   rtpmp2tdepay->skip_first_bytes = DEFAULT_SKIP_FIRST_BYTES;
130 }
131
132 static gboolean
133 gst_rtp_mp2t_depay_setcaps (GstBaseRTPDepayload * depayload, GstCaps * caps)
134 {
135   GstCaps *srccaps;
136   GstStructure *structure;
137   gint clock_rate;
138   gboolean res;
139
140   structure = gst_caps_get_structure (caps, 0);
141   if (!gst_structure_get_int (structure, "clock-rate", &clock_rate))
142     clock_rate = 90000;         /* default */
143   depayload->clock_rate = clock_rate;
144
145   srccaps = gst_caps_new_simple ("video/mpegts",
146       "packetsize", G_TYPE_INT, 188,
147       "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
148   res = gst_pad_set_caps (GST_BASE_RTP_DEPAYLOAD_SRCPAD (depayload), srccaps);
149   gst_caps_unref (srccaps);
150
151   return res;
152 }
153
154 static GstBuffer *
155 gst_rtp_mp2t_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf)
156 {
157   GstRtpMP2TDepay *rtpmp2tdepay;
158   GstBuffer *outbuf;
159   gint payload_len;
160
161   rtpmp2tdepay = GST_RTP_MP2T_DEPAY (depayload);
162
163   payload_len = gst_rtp_buffer_get_payload_len (buf);
164
165   if (G_UNLIKELY (payload_len <= rtpmp2tdepay->skip_first_bytes))
166     goto empty_packet;
167
168   outbuf =
169       gst_rtp_buffer_get_payload_subbuffer (buf, rtpmp2tdepay->skip_first_bytes,
170       -1);
171
172   if (outbuf)
173     GST_DEBUG ("gst_rtp_mp2t_depay_chain: pushing buffer of size %d",
174         GST_BUFFER_SIZE (outbuf));
175
176   return outbuf;
177
178   /* ERRORS */
179 empty_packet:
180   {
181     GST_ELEMENT_WARNING (rtpmp2tdepay, STREAM, DECODE,
182         (NULL), ("Packet was empty"));
183     return NULL;
184   }
185 }
186
187 static void
188 gst_rtp_mp2t_depay_set_property (GObject * object, guint prop_id,
189     const GValue * value, GParamSpec * pspec)
190 {
191   GstRtpMP2TDepay *rtpmp2tdepay;
192
193   rtpmp2tdepay = GST_RTP_MP2T_DEPAY (object);
194
195   switch (prop_id) {
196     case PROP_SKIP_FIRST_BYTES:
197       rtpmp2tdepay->skip_first_bytes = g_value_get_uint (value);
198       break;
199     default:
200       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
201       break;
202   }
203 }
204
205 static void
206 gst_rtp_mp2t_depay_get_property (GObject * object, guint prop_id,
207     GValue * value, GParamSpec * pspec)
208 {
209   GstRtpMP2TDepay *rtpmp2tdepay;
210
211   rtpmp2tdepay = GST_RTP_MP2T_DEPAY (object);
212
213   switch (prop_id) {
214     case PROP_SKIP_FIRST_BYTES:
215       g_value_set_uint (value, rtpmp2tdepay->skip_first_bytes);
216       break;
217     default:
218       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
219       break;
220   }
221 }
222
223 gboolean
224 gst_rtp_mp2t_depay_plugin_init (GstPlugin * plugin)
225 {
226   return gst_element_register (plugin, "rtpmp2tdepay",
227       GST_RANK_SECONDARY, GST_TYPE_RTP_MP2T_DEPAY);
228 }