1 /* 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
16 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
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 "gstrtpelements.h"
28 #include "gstrtpmp1sdepay.h"
29 #include "gstrtputils.h"
30
31 /* RtpMP1SDepay signals and args */
32 enum
33 {
34 /* FILL ME */
35 LAST_SIGNAL
36 };
37
38 enum
39 {
40 PROP_0,
41 PROP_LAST
42 };
43
44 static GstStaticPadTemplate gst_rtp_mp1s_depay_src_template =
45 GST_STATIC_PAD_TEMPLATE ("src",
46 GST_PAD_SRC,
47 GST_PAD_ALWAYS,
48 GST_STATIC_CAPS ("video/mpeg,systemstream=(boolean)true")
49 );
50
51 /* The spec says video/MP1S but I have seen streams with other/MP1S so we will
52 * allow them both */
53 static GstStaticPadTemplate gst_rtp_mp1s_depay_sink_template =
54 GST_STATIC_PAD_TEMPLATE ("sink",
55 GST_PAD_SINK,
56 GST_PAD_ALWAYS,
57 GST_STATIC_CAPS ("application/x-rtp, "
58 "media = (string) \"other\", "
59 "clock-rate = (int) [1, MAX ], " "encoding-name = (string) \"MP1S\";"
60 "application/x-rtp, "
61 "media = (string) \"video\", "
62 "clock-rate = (int) [1, MAX ], " "encoding-name = (string) \"MP1S\"")
63 );
64
65 G_DEFINE_TYPE (GstRtpMP1SDepay, gst_rtp_mp1s_depay,
66 GST_TYPE_RTP_BASE_DEPAYLOAD);
67 GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (rtpmp1sdepay, "rtpmp1sdepay",
68 GST_RANK_SECONDARY, GST_TYPE_RTP_MP1S_DEPAY, rtp_element_init (plugin));
69
70 static gboolean gst_rtp_mp1s_depay_setcaps (GstRTPBaseDepayload * depayload,
71 GstCaps * caps);
72 static GstBuffer *gst_rtp_mp1s_depay_process (GstRTPBaseDepayload * depayload,
73 GstRTPBuffer * rtp);
74
75 static void
gst_rtp_mp1s_depay_class_init(GstRtpMP1SDepayClass * klass)76 gst_rtp_mp1s_depay_class_init (GstRtpMP1SDepayClass * klass)
77 {
78 GstElementClass *gstelement_class;
79 GstRTPBaseDepayloadClass *gstrtpbasedepayload_class;
80
81 gstelement_class = (GstElementClass *) klass;
82 gstrtpbasedepayload_class = (GstRTPBaseDepayloadClass *) klass;
83
84 gstrtpbasedepayload_class->process_rtp_packet = gst_rtp_mp1s_depay_process;
85 gstrtpbasedepayload_class->set_caps = gst_rtp_mp1s_depay_setcaps;
86
87 gst_element_class_add_static_pad_template (gstelement_class,
88 &gst_rtp_mp1s_depay_src_template);
89 gst_element_class_add_static_pad_template (gstelement_class,
90 &gst_rtp_mp1s_depay_sink_template);
91
92 gst_element_class_set_static_metadata (gstelement_class,
93 "RTP MPEG1 System Stream depayloader", "Codec/Depayloader/Network/RTP",
94 "Extracts MPEG1 System Streams from RTP packets (RFC 3555)",
95 "Wim Taymans <wim.taymans@gmail.com>");
96 }
97
98 static void
gst_rtp_mp1s_depay_init(GstRtpMP1SDepay * rtpmp1sdepay)99 gst_rtp_mp1s_depay_init (GstRtpMP1SDepay * rtpmp1sdepay)
100 {
101 }
102
103 static gboolean
gst_rtp_mp1s_depay_setcaps(GstRTPBaseDepayload * depayload,GstCaps * caps)104 gst_rtp_mp1s_depay_setcaps (GstRTPBaseDepayload * depayload, GstCaps * caps)
105 {
106 GstCaps *srccaps;
107 GstStructure *structure;
108 gint clock_rate;
109 gboolean res;
110
111 structure = gst_caps_get_structure (caps, 0);
112 if (!gst_structure_get_int (structure, "clock-rate", &clock_rate))
113 clock_rate = 90000; /* default */
114 depayload->clock_rate = clock_rate;
115
116 srccaps = gst_caps_new_simple ("video/mpeg",
117 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
118 res = gst_pad_set_caps (GST_RTP_BASE_DEPAYLOAD_SRCPAD (depayload), srccaps);
119 gst_caps_unref (srccaps);
120
121 return res;
122 }
123
124 static GstBuffer *
gst_rtp_mp1s_depay_process(GstRTPBaseDepayload * depayload,GstRTPBuffer * rtp)125 gst_rtp_mp1s_depay_process (GstRTPBaseDepayload * depayload, GstRTPBuffer * rtp)
126 {
127 GstBuffer *outbuf;
128
129 outbuf = gst_rtp_buffer_get_payload_buffer (rtp);
130
131 if (outbuf) {
132 GST_DEBUG ("gst_rtp_mp1s_depay_chain: pushing buffer of size %"
133 G_GSIZE_FORMAT, gst_buffer_get_size (outbuf));
134
135 gst_rtp_drop_meta (GST_ELEMENT_CAST (depayload), outbuf, 0);
136 }
137
138 return outbuf;
139 }
140