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., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
24 #include <gst/rtp/gstrtpbuffer.h>
27 #include "gstrtpelements.h"
28 #include "gstrtpmp2tdepay.h"
29 #include "gstrtputils.h"
31 /* RtpMP2TDepay signals and args */
38 #define DEFAULT_SKIP_FIRST_BYTES 0
46 static GstStaticPadTemplate gst_rtp_mp2t_depay_src_template =
47 GST_STATIC_PAD_TEMPLATE ("src",
50 GST_STATIC_CAPS ("video/mpegts,"
51 "packetsize=(int)188," "systemstream=(boolean)true")
54 static GstStaticPadTemplate gst_rtp_mp2t_depay_sink_template =
55 GST_STATIC_PAD_TEMPLATE ("sink",
58 GST_STATIC_CAPS ("application/x-rtp, "
59 "media = (string) \"video\", "
60 "clock-rate = (int) [1, MAX ], "
61 "encoding-name = (string) { MP2T, MP2T-ES } ;"
62 /* All optional parameters
64 * "profile-level-id=[1,MAX]"
68 "media = (string) \"video\", "
69 "payload = (int) " GST_RTP_PAYLOAD_MP2T_STRING ", "
70 "clock-rate = (int) [1, MAX ]")
73 G_DEFINE_TYPE (GstRtpMP2TDepay, gst_rtp_mp2t_depay,
74 GST_TYPE_RTP_BASE_DEPAYLOAD);
75 GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (rtpmp2tdepay, "rtpmp2tdepay",
76 GST_RANK_SECONDARY, GST_TYPE_RTP_MP2T_DEPAY, rtp_element_init (plugin));
78 static gboolean gst_rtp_mp2t_depay_setcaps (GstRTPBaseDepayload * depayload,
80 static GstBuffer *gst_rtp_mp2t_depay_process (GstRTPBaseDepayload * depayload,
83 static void gst_rtp_mp2t_depay_set_property (GObject * object, guint prop_id,
84 const GValue * value, GParamSpec * pspec);
85 static void gst_rtp_mp2t_depay_get_property (GObject * object, guint prop_id,
86 GValue * value, GParamSpec * pspec);
89 gst_rtp_mp2t_depay_class_init (GstRtpMP2TDepayClass * klass)
91 GObjectClass *gobject_class;
92 GstElementClass *gstelement_class;
93 GstRTPBaseDepayloadClass *gstrtpbasedepayload_class;
95 gobject_class = (GObjectClass *) klass;
96 gstelement_class = (GstElementClass *) klass;
97 gstrtpbasedepayload_class = (GstRTPBaseDepayloadClass *) klass;
99 gstrtpbasedepayload_class->process_rtp_packet = gst_rtp_mp2t_depay_process;
100 gstrtpbasedepayload_class->set_caps = gst_rtp_mp2t_depay_setcaps;
102 gobject_class->set_property = gst_rtp_mp2t_depay_set_property;
103 gobject_class->get_property = gst_rtp_mp2t_depay_get_property;
105 gst_element_class_add_static_pad_template (gstelement_class,
106 &gst_rtp_mp2t_depay_src_template);
107 gst_element_class_add_static_pad_template (gstelement_class,
108 &gst_rtp_mp2t_depay_sink_template);
110 gst_element_class_set_static_metadata (gstelement_class,
111 "RTP MPEG Transport Stream depayloader", "Codec/Depayloader/Network/RTP",
112 "Extracts MPEG2 TS from RTP packets (RFC 2250)",
113 "Wim Taymans <wim.taymans@gmail.com>, "
114 "Thijs Vermeir <thijs.vermeir@barco.com>");
116 g_object_class_install_property (gobject_class, PROP_SKIP_FIRST_BYTES,
117 g_param_spec_uint ("skip-first-bytes",
119 "The amount of bytes that need to be skipped at the beginning of the payload",
120 0, G_MAXUINT, 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
125 gst_rtp_mp2t_depay_init (GstRtpMP2TDepay * rtpmp2tdepay)
127 rtpmp2tdepay->skip_first_bytes = DEFAULT_SKIP_FIRST_BYTES;
131 gst_rtp_mp2t_depay_setcaps (GstRTPBaseDepayload * depayload, GstCaps * caps)
134 GstStructure *structure;
138 structure = gst_caps_get_structure (caps, 0);
139 if (!gst_structure_get_int (structure, "clock-rate", &clock_rate))
140 clock_rate = 90000; /* default */
141 depayload->clock_rate = clock_rate;
143 srccaps = gst_caps_new_simple ("video/mpegts",
144 "packetsize", G_TYPE_INT, 188,
145 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
146 res = gst_pad_set_caps (GST_RTP_BASE_DEPAYLOAD_SRCPAD (depayload), srccaps);
147 gst_caps_unref (srccaps);
153 gst_rtp_mp2t_depay_process (GstRTPBaseDepayload * depayload, GstRTPBuffer * rtp)
155 GstRtpMP2TDepay *rtpmp2tdepay;
157 gint payload_len, leftover;
159 rtpmp2tdepay = GST_RTP_MP2T_DEPAY (depayload);
161 payload_len = gst_rtp_buffer_get_payload_len (rtp);
163 if (G_UNLIKELY (payload_len <= rtpmp2tdepay->skip_first_bytes))
166 payload_len -= rtpmp2tdepay->skip_first_bytes;
170 * 2. Encapsulation of MPEG System and Transport Streams
172 * For MPEG2 Transport Streams the RTP payload will contain an integral
173 * number of MPEG transport packets.
175 leftover = payload_len % 188;
176 if (G_UNLIKELY (leftover)) {
177 GST_WARNING ("We don't have an integral number of buffers (leftover: %d)",
180 payload_len -= leftover;
184 gst_rtp_buffer_get_payload_subbuffer (rtp,
185 rtpmp2tdepay->skip_first_bytes, payload_len);
188 GST_DEBUG ("gst_rtp_mp2t_depay_chain: pushing buffer of size %"
189 G_GSIZE_FORMAT, gst_buffer_get_size (outbuf));
191 gst_rtp_drop_meta (GST_ELEMENT_CAST (depayload), outbuf, 0);
199 GST_ELEMENT_WARNING (rtpmp2tdepay, STREAM, DECODE,
200 (NULL), ("Packet was empty"));
206 gst_rtp_mp2t_depay_set_property (GObject * object, guint prop_id,
207 const GValue * value, GParamSpec * pspec)
209 GstRtpMP2TDepay *rtpmp2tdepay;
211 rtpmp2tdepay = GST_RTP_MP2T_DEPAY (object);
214 case PROP_SKIP_FIRST_BYTES:
215 rtpmp2tdepay->skip_first_bytes = g_value_get_uint (value);
218 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
224 gst_rtp_mp2t_depay_get_property (GObject * object, guint prop_id,
225 GValue * value, GParamSpec * pspec)
227 GstRtpMP2TDepay *rtpmp2tdepay;
229 rtpmp2tdepay = GST_RTP_MP2T_DEPAY (object);
232 case PROP_SKIP_FIRST_BYTES:
233 g_value_set_uint (value, rtpmp2tdepay->skip_first_bytes);
236 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);