blob: 31a3108d2124c967635b410a2acb5d9404b392d4 [file] [log] [blame]
Wim Taymans8f0079c2008-08-05 13:54:18 +00001/* GStreamer
2 * Copyright (C) <2008> 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
Tim-Philipp Müller230cf412012-11-04 00:07:18 +000016 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
Wim Taymans8f0079c2008-08-05 13:54:18 +000018 */
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 "gstrtpmp1sdepay.h"
Sebastian Drögeb1089fb2015-08-04 20:59:17 +030028#include "gstrtputils.h"
Wim Taymans8f0079c2008-08-05 13:54:18 +000029
Wim Taymans8f0079c2008-08-05 13:54:18 +000030/* RtpMP1SDepay signals and args */
31enum
32{
33 /* FILL ME */
34 LAST_SIGNAL
35};
36
37enum
38{
39 PROP_0,
40 PROP_LAST
41};
42
43static GstStaticPadTemplate gst_rtp_mp1s_depay_src_template =
44GST_STATIC_PAD_TEMPLATE ("src",
45 GST_PAD_SRC,
46 GST_PAD_ALWAYS,
47 GST_STATIC_CAPS ("video/mpeg,systemstream=(boolean)true")
48 );
49
50/* The spec says video/MP1S but I have seen streams with other/MP1S so we will
51 * allow them both */
52static GstStaticPadTemplate gst_rtp_mp1s_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) \"other\", "
Wim Taymans8f0079c2008-08-05 13:54:18 +000058 "clock-rate = (int) [1, MAX ], " "encoding-name = (string) \"MP1S\";"
59 "application/x-rtp, "
60 "media = (string) \"video\", "
Wim Taymans8f0079c2008-08-05 13:54:18 +000061 "clock-rate = (int) [1, MAX ], " "encoding-name = (string) \"MP1S\"")
62 );
63
Mark Nauwelaertseb82a502011-07-10 21:50:19 +020064G_DEFINE_TYPE (GstRtpMP1SDepay, gst_rtp_mp1s_depay,
Wim Taymans249d0082011-11-11 12:25:01 +010065 GST_TYPE_RTP_BASE_DEPAYLOAD);
Wim Taymans8f0079c2008-08-05 13:54:18 +000066
Wim Taymans249d0082011-11-11 12:25:01 +010067static gboolean gst_rtp_mp1s_depay_setcaps (GstRTPBaseDepayload * depayload,
Wim Taymans8f0079c2008-08-05 13:54:18 +000068 GstCaps * caps);
Wim Taymans249d0082011-11-11 12:25:01 +010069static GstBuffer *gst_rtp_mp1s_depay_process (GstRTPBaseDepayload * depayload,
Tim-Philipp Müller6717c862015-07-12 14:27:15 +010070 GstRTPBuffer * rtp);
Wim Taymans8f0079c2008-08-05 13:54:18 +000071
Wim Taymans8f0079c2008-08-05 13:54:18 +000072static void
Mark Nauwelaertseb82a502011-07-10 21:50:19 +020073gst_rtp_mp1s_depay_class_init (GstRtpMP1SDepayClass * klass)
Wim Taymans8f0079c2008-08-05 13:54:18 +000074{
Mark Nauwelaertseb82a502011-07-10 21:50:19 +020075 GstElementClass *gstelement_class;
Wim Taymans249d0082011-11-11 12:25:01 +010076 GstRTPBaseDepayloadClass *gstrtpbasedepayload_class;
Wim Taymans8f0079c2008-08-05 13:54:18 +000077
Mark Nauwelaertseb82a502011-07-10 21:50:19 +020078 gstelement_class = (GstElementClass *) klass;
Wim Taymans249d0082011-11-11 12:25:01 +010079 gstrtpbasedepayload_class = (GstRTPBaseDepayloadClass *) klass;
Mark Nauwelaertseb82a502011-07-10 21:50:19 +020080
Tim-Philipp Müller6717c862015-07-12 14:27:15 +010081 gstrtpbasedepayload_class->process_rtp_packet = gst_rtp_mp1s_depay_process;
Wim Taymans249d0082011-11-11 12:25:01 +010082 gstrtpbasedepayload_class->set_caps = gst_rtp_mp1s_depay_setcaps;
Mark Nauwelaertseb82a502011-07-10 21:50:19 +020083
Vineeth TM10713092016-03-04 10:30:12 +090084 gst_element_class_add_static_pad_template (gstelement_class,
85 &gst_rtp_mp1s_depay_src_template);
86 gst_element_class_add_static_pad_template (gstelement_class,
87 &gst_rtp_mp1s_depay_sink_template);
Wim Taymans8f0079c2008-08-05 13:54:18 +000088
Tim-Philipp Müllere09ae572012-04-10 00:51:41 +010089 gst_element_class_set_static_metadata (gstelement_class,
Wim Taymansf4155f32010-12-21 16:58:47 +010090 "RTP MPEG1 System Stream depayloader", "Codec/Depayloader/Network/RTP",
Benjamin Ottecccfeaa2010-03-18 14:31:35 +010091 "Extracts MPEG1 System Streams from RTP packets (RFC 3555)",
92 "Wim Taymans <wim.taymans@gmail.com>");
Wim Taymans8f0079c2008-08-05 13:54:18 +000093}
94
95static void
Mark Nauwelaertseb82a502011-07-10 21:50:19 +020096gst_rtp_mp1s_depay_init (GstRtpMP1SDepay * rtpmp1sdepay)
Wim Taymans8f0079c2008-08-05 13:54:18 +000097{
98}
99
100static gboolean
Wim Taymans249d0082011-11-11 12:25:01 +0100101gst_rtp_mp1s_depay_setcaps (GstRTPBaseDepayload * depayload, GstCaps * caps)
Wim Taymans8f0079c2008-08-05 13:54:18 +0000102{
103 GstCaps *srccaps;
104 GstStructure *structure;
Wim Taymans2428a1c2008-10-27 11:03:53 +0000105 gint clock_rate;
106 gboolean res;
Wim Taymans8f0079c2008-08-05 13:54:18 +0000107
Wim Taymans8f0079c2008-08-05 13:54:18 +0000108 structure = gst_caps_get_structure (caps, 0);
Wim Taymans2428a1c2008-10-27 11:03:53 +0000109 if (!gst_structure_get_int (structure, "clock-rate", &clock_rate))
110 clock_rate = 90000; /* default */
Wim Taymans8f0079c2008-08-05 13:54:18 +0000111 depayload->clock_rate = clock_rate;
112
113 srccaps = gst_caps_new_simple ("video/mpeg",
114 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
Wim Taymans249d0082011-11-11 12:25:01 +0100115 res = gst_pad_set_caps (GST_RTP_BASE_DEPAYLOAD_SRCPAD (depayload), srccaps);
Wim Taymans8f0079c2008-08-05 13:54:18 +0000116 gst_caps_unref (srccaps);
117
Wim Taymans2428a1c2008-10-27 11:03:53 +0000118 return res;
Wim Taymans8f0079c2008-08-05 13:54:18 +0000119}
120
121static GstBuffer *
Tim-Philipp Müller6717c862015-07-12 14:27:15 +0100122gst_rtp_mp1s_depay_process (GstRTPBaseDepayload * depayload, GstRTPBuffer * rtp)
Wim Taymans8f0079c2008-08-05 13:54:18 +0000123{
Wim Taymans8f0079c2008-08-05 13:54:18 +0000124 GstBuffer *outbuf;
Wim Taymans8f0079c2008-08-05 13:54:18 +0000125
Tim-Philipp Müller6717c862015-07-12 14:27:15 +0100126 outbuf = gst_rtp_buffer_get_payload_buffer (rtp);
Wim Taymans8f0079c2008-08-05 13:54:18 +0000127
Sebastian Drögeb1089fb2015-08-04 20:59:17 +0300128 if (outbuf) {
Matej Knopp1e5dd9e2011-11-21 20:31:31 +0100129 GST_DEBUG ("gst_rtp_mp1s_depay_chain: pushing buffer of size %"
130 G_GSIZE_FORMAT, gst_buffer_get_size (outbuf));
Wim Taymans8f0079c2008-08-05 13:54:18 +0000131
Sebastian Drögeb1089fb2015-08-04 20:59:17 +0300132 gst_rtp_drop_meta (GST_ELEMENT_CAST (depayload), outbuf, 0);
133 }
134
Wim Taymans8f0079c2008-08-05 13:54:18 +0000135 return outbuf;
Wim Taymans8f0079c2008-08-05 13:54:18 +0000136}
137
Wim Taymans8f0079c2008-08-05 13:54:18 +0000138gboolean
139gst_rtp_mp1s_depay_plugin_init (GstPlugin * plugin)
140{
141 return gst_element_register (plugin, "rtpmp1sdepay",
Wim Taymansf357e092010-12-21 16:49:28 +0100142 GST_RANK_SECONDARY, GST_TYPE_RTP_MP1S_DEPAY);
Wim Taymans8f0079c2008-08-05 13:54:18 +0000143}