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 "clock-rate = (int) [1, MAX ], " "encoding-name = (string) \"MP2T-ES\""
64 /* All optional parameters
66 * "profile-level-id=[1,MAX]"
72 GST_BOILERPLATE (GstRtpMP2TDepay, gst_rtp_mp2t_depay, GstBaseRTPDepayload,
73 GST_TYPE_BASE_RTP_DEPAYLOAD);
75 static gboolean gst_rtp_mp2t_depay_setcaps (GstBaseRTPDepayload * depayload,
77 static GstBuffer *gst_rtp_mp2t_depay_process (GstBaseRTPDepayload * depayload,
80 static void gst_rtp_mp2t_depay_set_property (GObject * object, guint prop_id,
81 const GValue * value, GParamSpec * pspec);
82 static void gst_rtp_mp2t_depay_get_property (GObject * object, guint prop_id,
83 GValue * value, GParamSpec * pspec);
85 static GstStateChangeReturn gst_rtp_mp2t_depay_change_state (GstElement *
86 element, GstStateChange transition);
90 gst_rtp_mp2t_depay_base_init (gpointer klass)
92 GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
94 gst_element_class_add_pad_template (element_class,
95 gst_static_pad_template_get (&gst_rtp_mp2t_depay_src_template));
96 gst_element_class_add_pad_template (element_class,
97 gst_static_pad_template_get (&gst_rtp_mp2t_depay_sink_template));
99 gst_element_class_set_details (element_class, &gst_rtp_mp2tdepay_details);
103 gst_rtp_mp2t_depay_class_init (GstRtpMP2TDepayClass * klass)
105 GObjectClass *gobject_class;
106 GstElementClass *gstelement_class;
107 GstBaseRTPDepayloadClass *gstbasertpdepayload_class;
109 gobject_class = (GObjectClass *) klass;
110 gstelement_class = (GstElementClass *) klass;
112 gstbasertpdepayload_class = (GstBaseRTPDepayloadClass *) klass;
114 parent_class = g_type_class_peek_parent (klass);
116 gstbasertpdepayload_class->process = gst_rtp_mp2t_depay_process;
117 gstbasertpdepayload_class->set_caps = gst_rtp_mp2t_depay_setcaps;
119 gobject_class->set_property = gst_rtp_mp2t_depay_set_property;
120 gobject_class->get_property = gst_rtp_mp2t_depay_get_property;
122 gstelement_class->change_state = gst_rtp_mp2t_depay_change_state;
126 gst_rtp_mp2t_depay_init (GstRtpMP2TDepay * rtpmp2tdepay,
127 GstRtpMP2TDepayClass * klass)
132 gst_rtp_mp2t_depay_setcaps (GstBaseRTPDepayload * depayload, GstCaps * caps)
135 GstStructure *structure;
136 GstRtpMP2TDepay *rtpmp2tdepay;
138 gint clock_rate = 90000; /* default */
140 rtpmp2tdepay = GST_RTP_MP2T_DEPAY (depayload);
142 structure = gst_caps_get_structure (caps, 0);
144 if (gst_structure_has_field (structure, "clock-rate")) {
145 gst_structure_get_int (structure, "clock-rate", &clock_rate);
148 depayload->clock_rate = clock_rate;
150 srccaps = gst_caps_new_simple ("video/mpegts",
151 "systemstream", G_TYPE_BOOLEAN, TRUE,
152 "packetsize", G_TYPE_INT, 188, NULL);
158 gst_rtp_mp2t_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf)
160 GstRtpMP2TDepay *rtpmp2tdepay;
166 rtpmp2tdepay = GST_RTP_MP2T_DEPAY (depayload);
168 if (!gst_rtp_buffer_validate (buf))
171 payload_len = gst_rtp_buffer_get_payload_len (buf);
172 payload = gst_rtp_buffer_get_payload (buf);
174 timestamp = gst_rtp_buffer_get_timestamp (buf);
176 outbuf = gst_buffer_new_and_alloc (payload_len);
177 memcpy (GST_BUFFER_DATA (outbuf), payload, payload_len);
179 gst_buffer_set_caps (outbuf, GST_PAD_CAPS (depayload->srcpad));
180 GST_BUFFER_TIMESTAMP (outbuf) =
181 gst_util_uint64_scale_int (timestamp, GST_SECOND, depayload->clock_rate);
183 GST_DEBUG ("gst_rtp_mp2t_depay_chain: pushing buffer of size %d",
184 GST_BUFFER_SIZE (outbuf));
190 GST_ELEMENT_WARNING (rtpmp2tdepay, STREAM, DECODE,
191 ("Packet did not validate"), (NULL));
197 gst_rtp_mp2t_depay_set_property (GObject * object, guint prop_id,
198 const GValue * value, GParamSpec * pspec)
200 GstRtpMP2TDepay *rtpmp2tdepay;
202 rtpmp2tdepay = GST_RTP_MP2T_DEPAY (object);
206 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
212 gst_rtp_mp2t_depay_get_property (GObject * object, guint prop_id,
213 GValue * value, GParamSpec * pspec)
215 GstRtpMP2TDepay *rtpmp2tdepay;
217 rtpmp2tdepay = GST_RTP_MP2T_DEPAY (object);
221 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
226 static GstStateChangeReturn
227 gst_rtp_mp2t_depay_change_state (GstElement * element,
228 GstStateChange transition)
230 GstRtpMP2TDepay *rtpmp2tdepay;
231 GstStateChangeReturn ret;
233 rtpmp2tdepay = GST_RTP_MP2T_DEPAY (element);
235 switch (transition) {
236 case GST_STATE_CHANGE_NULL_TO_READY:
238 case GST_STATE_CHANGE_READY_TO_PAUSED:
244 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
246 switch (transition) {
247 case GST_STATE_CHANGE_READY_TO_NULL:
256 gst_rtp_mp2t_depay_plugin_init (GstPlugin * plugin)
258 return gst_element_register (plugin, "rtpmp2tdepay",
259 GST_RANK_MARGINAL, GST_TYPE_RTP_MP2T_DEPAY);