2 * Copyright (C) <2005> Wim Taymans <wim@fluendo.com>
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.
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.
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.
24 #include <gst/rtp/gstrtpbuffer.h>
27 #include "gstrtpmp2tdepay.h"
29 /* elementfactory information */
30 static const GstElementDetails gst_rtp_mp2tdepay_details =
31 GST_ELEMENT_DETAILS ("RTP packet depayloader",
32 "Codec/Depayloader/Network",
33 "Extracts MPEG2 TS from RTP packets (RFC 2250)",
34 "Wim Taymans <wim@fluendo.com>");
36 /* RtpMP2TDepay signals and args */
49 static GstStaticPadTemplate gst_rtp_mp2t_depay_src_template =
50 GST_STATIC_PAD_TEMPLATE ("src",
53 GST_STATIC_CAPS ("video/mpegts,"
54 "packetsize=(int)188," "systemstream=(boolean)true")
57 static GstStaticPadTemplate gst_rtp_mp2t_depay_sink_template =
58 GST_STATIC_PAD_TEMPLATE ("sink",
61 GST_STATIC_CAPS ("application/x-rtp, "
62 "media = (string) \"video\", "
63 "payload = (int) " GST_RTP_PAYLOAD_DYNAMIC_STRING ", "
64 "clock-rate = (int) [1, MAX ], " "encoding-name = (string) \"MP2T-ES\";"
65 /* All optional parameters
67 * "profile-level-id=[1,MAX]"
71 "media = (string) \"video\", "
72 "payload = (int) " GST_RTP_PAYLOAD_MP2T_STRING ", "
73 "clock-rate = (int) [1, MAX ]")
76 GST_BOILERPLATE (GstRtpMP2TDepay, gst_rtp_mp2t_depay, GstBaseRTPDepayload,
77 GST_TYPE_BASE_RTP_DEPAYLOAD);
79 static gboolean gst_rtp_mp2t_depay_setcaps (GstBaseRTPDepayload * depayload,
81 static GstBuffer *gst_rtp_mp2t_depay_process (GstBaseRTPDepayload * depayload,
84 static void gst_rtp_mp2t_depay_set_property (GObject * object, guint prop_id,
85 const GValue * value, GParamSpec * pspec);
86 static void gst_rtp_mp2t_depay_get_property (GObject * object, guint prop_id,
87 GValue * value, GParamSpec * pspec);
89 static GstStateChangeReturn gst_rtp_mp2t_depay_change_state (GstElement *
90 element, GstStateChange transition);
94 gst_rtp_mp2t_depay_base_init (gpointer klass)
96 GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
98 gst_element_class_add_pad_template (element_class,
99 gst_static_pad_template_get (&gst_rtp_mp2t_depay_src_template));
100 gst_element_class_add_pad_template (element_class,
101 gst_static_pad_template_get (&gst_rtp_mp2t_depay_sink_template));
103 gst_element_class_set_details (element_class, &gst_rtp_mp2tdepay_details);
107 gst_rtp_mp2t_depay_class_init (GstRtpMP2TDepayClass * klass)
109 GObjectClass *gobject_class;
110 GstElementClass *gstelement_class;
111 GstBaseRTPDepayloadClass *gstbasertpdepayload_class;
113 gobject_class = (GObjectClass *) klass;
114 gstelement_class = (GstElementClass *) klass;
116 gstbasertpdepayload_class = (GstBaseRTPDepayloadClass *) klass;
118 parent_class = g_type_class_peek_parent (klass);
120 gstbasertpdepayload_class->process = gst_rtp_mp2t_depay_process;
121 gstbasertpdepayload_class->set_caps = gst_rtp_mp2t_depay_setcaps;
123 gobject_class->set_property = gst_rtp_mp2t_depay_set_property;
124 gobject_class->get_property = gst_rtp_mp2t_depay_get_property;
126 gstelement_class->change_state = gst_rtp_mp2t_depay_change_state;
130 gst_rtp_mp2t_depay_init (GstRtpMP2TDepay * rtpmp2tdepay,
131 GstRtpMP2TDepayClass * klass)
136 gst_rtp_mp2t_depay_setcaps (GstBaseRTPDepayload * depayload, GstCaps * caps)
139 GstStructure *structure;
140 GstRtpMP2TDepay *rtpmp2tdepay;
142 gint clock_rate = 90000; /* default */
144 rtpmp2tdepay = GST_RTP_MP2T_DEPAY (depayload);
146 structure = gst_caps_get_structure (caps, 0);
148 if (gst_structure_has_field (structure, "clock-rate")) {
149 gst_structure_get_int (structure, "clock-rate", &clock_rate);
152 depayload->clock_rate = clock_rate;
154 srccaps = gst_caps_new_simple ("video/mpegts",
155 "systemstream", G_TYPE_BOOLEAN, TRUE,
156 "packetsize", G_TYPE_INT, 188, NULL);
162 gst_rtp_mp2t_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf)
164 GstRtpMP2TDepay *rtpmp2tdepay;
170 rtpmp2tdepay = GST_RTP_MP2T_DEPAY (depayload);
172 if (!gst_rtp_buffer_validate (buf))
175 payload_len = gst_rtp_buffer_get_payload_len (buf);
176 payload = gst_rtp_buffer_get_payload (buf);
178 timestamp = gst_rtp_buffer_get_timestamp (buf);
180 outbuf = gst_buffer_new_and_alloc (payload_len);
181 memcpy (GST_BUFFER_DATA (outbuf), payload, payload_len);
183 gst_buffer_set_caps (outbuf, GST_PAD_CAPS (depayload->srcpad));
184 GST_BUFFER_TIMESTAMP (outbuf) =
185 gst_util_uint64_scale_int (timestamp, GST_SECOND, depayload->clock_rate);
187 GST_DEBUG ("gst_rtp_mp2t_depay_chain: pushing buffer of size %d",
188 GST_BUFFER_SIZE (outbuf));
194 GST_ELEMENT_WARNING (rtpmp2tdepay, STREAM, DECODE,
195 ("Packet did not validate"), (NULL));
201 gst_rtp_mp2t_depay_set_property (GObject * object, guint prop_id,
202 const GValue * value, GParamSpec * pspec)
204 GstRtpMP2TDepay *rtpmp2tdepay;
206 rtpmp2tdepay = GST_RTP_MP2T_DEPAY (object);
210 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
216 gst_rtp_mp2t_depay_get_property (GObject * object, guint prop_id,
217 GValue * value, GParamSpec * pspec)
219 GstRtpMP2TDepay *rtpmp2tdepay;
221 rtpmp2tdepay = GST_RTP_MP2T_DEPAY (object);
225 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
230 static GstStateChangeReturn
231 gst_rtp_mp2t_depay_change_state (GstElement * element,
232 GstStateChange transition)
234 GstRtpMP2TDepay *rtpmp2tdepay;
235 GstStateChangeReturn ret;
237 rtpmp2tdepay = GST_RTP_MP2T_DEPAY (element);
239 switch (transition) {
240 case GST_STATE_CHANGE_NULL_TO_READY:
242 case GST_STATE_CHANGE_READY_TO_PAUSED:
248 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
250 switch (transition) {
251 case GST_STATE_CHANGE_READY_TO_NULL:
260 gst_rtp_mp2t_depay_plugin_init (GstPlugin * plugin)
262 return gst_element_register (plugin, "rtpmp2tdepay",
263 GST_RANK_MARGINAL, GST_TYPE_RTP_MP2T_DEPAY);