2 * Copyright (C) <2005> Wim Taymans <wim.taymans@gmail.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 MPEG Transport Stream depayloader",
32 "Codec/Depayloader/Network",
33 "Extracts MPEG2 TS from RTP packets (RFC 2250)",
34 "Wim Taymans <wim.taymans@gmail.com>\n"
35 "Thijs Vermeir <thijs.vermeir@barco.com>");
37 /* RtpMP2TDepay signals and args */
44 #define DEFAULT_SKIP_FIRST_BYTES 0
52 static GstStaticPadTemplate gst_rtp_mp2t_depay_src_template =
53 GST_STATIC_PAD_TEMPLATE ("src",
56 GST_STATIC_CAPS ("video/mpegts,"
57 "packetsize=(int)188," "systemstream=(boolean)true")
60 static GstStaticPadTemplate gst_rtp_mp2t_depay_sink_template =
61 GST_STATIC_PAD_TEMPLATE ("sink",
64 GST_STATIC_CAPS ("application/x-rtp, "
65 "media = (string) \"video\", "
66 "payload = (int) " GST_RTP_PAYLOAD_DYNAMIC_STRING ", "
67 "clock-rate = (int) [1, MAX ], " "encoding-name = (string) \"MP2T-ES\";"
68 /* All optional parameters
70 * "profile-level-id=[1,MAX]"
74 "media = (string) \"video\", "
75 "payload = (int) " GST_RTP_PAYLOAD_MP2T_STRING ", "
76 "clock-rate = (int) [1, MAX ]")
79 GST_BOILERPLATE (GstRtpMP2TDepay, gst_rtp_mp2t_depay, GstBaseRTPDepayload,
80 GST_TYPE_BASE_RTP_DEPAYLOAD);
82 static gboolean gst_rtp_mp2t_depay_setcaps (GstBaseRTPDepayload * depayload,
84 static GstBuffer *gst_rtp_mp2t_depay_process (GstBaseRTPDepayload * depayload,
87 static void gst_rtp_mp2t_depay_set_property (GObject * object, guint prop_id,
88 const GValue * value, GParamSpec * pspec);
89 static void gst_rtp_mp2t_depay_get_property (GObject * object, guint prop_id,
90 GValue * value, GParamSpec * pspec);
93 gst_rtp_mp2t_depay_base_init (gpointer klass)
95 GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
97 gst_element_class_add_pad_template (element_class,
98 gst_static_pad_template_get (&gst_rtp_mp2t_depay_src_template));
99 gst_element_class_add_pad_template (element_class,
100 gst_static_pad_template_get (&gst_rtp_mp2t_depay_sink_template));
102 gst_element_class_set_details (element_class, &gst_rtp_mp2tdepay_details);
106 gst_rtp_mp2t_depay_class_init (GstRtpMP2TDepayClass * klass)
108 GObjectClass *gobject_class;
109 GstBaseRTPDepayloadClass *gstbasertpdepayload_class;
111 gobject_class = (GObjectClass *) klass;
113 gstbasertpdepayload_class = (GstBaseRTPDepayloadClass *) klass;
115 parent_class = g_type_class_peek_parent (klass);
117 gstbasertpdepayload_class->process = gst_rtp_mp2t_depay_process;
118 gstbasertpdepayload_class->set_caps = gst_rtp_mp2t_depay_setcaps;
120 gobject_class->set_property = gst_rtp_mp2t_depay_set_property;
121 gobject_class->get_property = gst_rtp_mp2t_depay_get_property;
123 g_object_class_install_property (gobject_class, PROP_SKIP_FIRST_BYTES,
124 g_param_spec_uint ("skip-first-bytes",
126 "The amount of bytes that need to be skipped at the beginning of the payload",
127 0, G_MAXUINT, 0, G_PARAM_READWRITE));
132 gst_rtp_mp2t_depay_init (GstRtpMP2TDepay * rtpmp2tdepay,
133 GstRtpMP2TDepayClass * klass)
135 rtpmp2tdepay->skip_first_bytes = DEFAULT_SKIP_FIRST_BYTES;
139 gst_rtp_mp2t_depay_setcaps (GstBaseRTPDepayload * depayload, GstCaps * caps)
142 GstStructure *structure;
143 GstRtpMP2TDepay *rtpmp2tdepay;
147 rtpmp2tdepay = GST_RTP_MP2T_DEPAY (depayload);
149 structure = gst_caps_get_structure (caps, 0);
150 if (!gst_structure_get_int (structure, "clock-rate", &clock_rate))
151 clock_rate = 90000; /* default */
152 depayload->clock_rate = clock_rate;
154 srccaps = gst_caps_new_simple ("video/mpegts",
155 "packetsize", G_TYPE_INT, 188,
156 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
157 res = gst_pad_set_caps (GST_BASE_RTP_DEPAYLOAD_SRCPAD (depayload), srccaps);
158 gst_caps_unref (srccaps);
164 gst_rtp_mp2t_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf)
166 GstRtpMP2TDepay *rtpmp2tdepay;
170 rtpmp2tdepay = GST_RTP_MP2T_DEPAY (depayload);
172 payload_len = gst_rtp_buffer_get_payload_len (buf);
174 if (G_UNLIKELY (payload_len <= rtpmp2tdepay->skip_first_bytes))
178 gst_rtp_buffer_get_payload_subbuffer (buf, rtpmp2tdepay->skip_first_bytes,
181 GST_DEBUG ("gst_rtp_mp2t_depay_chain: pushing buffer of size %d",
182 GST_BUFFER_SIZE (outbuf));
189 GST_ELEMENT_WARNING (rtpmp2tdepay, STREAM, DECODE,
190 (NULL), ("Packet was empty"));
196 gst_rtp_mp2t_depay_set_property (GObject * object, guint prop_id,
197 const GValue * value, GParamSpec * pspec)
199 GstRtpMP2TDepay *rtpmp2tdepay;
201 rtpmp2tdepay = GST_RTP_MP2T_DEPAY (object);
204 case PROP_SKIP_FIRST_BYTES:
205 rtpmp2tdepay->skip_first_bytes = g_value_get_uint (value);
208 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
214 gst_rtp_mp2t_depay_get_property (GObject * object, guint prop_id,
215 GValue * value, GParamSpec * pspec)
217 GstRtpMP2TDepay *rtpmp2tdepay;
219 rtpmp2tdepay = GST_RTP_MP2T_DEPAY (object);
222 case PROP_SKIP_FIRST_BYTES:
223 g_value_set_uint (value, rtpmp2tdepay->skip_first_bytes);
226 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
232 gst_rtp_mp2t_depay_plugin_init (GstPlugin * plugin)
234 return gst_element_register (plugin, "rtpmp2tdepay",
235 GST_RANK_MARGINAL, GST_TYPE_RTP_MP2T_DEPAY);