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 "gstrtpmp1sdepay.h"
28 #include "gstrtputils.h"
29 
30 /* RtpMP1SDepay signals and args */
31 enum
32 {
33   /* FILL ME */
34   LAST_SIGNAL
35 };
36 
37 enum
38 {
39   PROP_0,
40   PROP_LAST
41 };
42 
43 static GstStaticPadTemplate gst_rtp_mp1s_depay_src_template =
44 GST_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 */
52 static 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\", "
58         "clock-rate = (int) [1, MAX ], " "encoding-name = (string) \"MP1S\";"
59         "application/x-rtp, "
60         "media = (string) \"video\", "
61         "clock-rate = (int) [1, MAX ], " "encoding-name = (string) \"MP1S\"")
62     );
63 
64 G_DEFINE_TYPE (GstRtpMP1SDepay, gst_rtp_mp1s_depay,
65     GST_TYPE_RTP_BASE_DEPAYLOAD);
66 
67 static gboolean gst_rtp_mp1s_depay_setcaps (GstRTPBaseDepayload * depayload,
68     GstCaps * caps);
69 static GstBuffer *gst_rtp_mp1s_depay_process (GstRTPBaseDepayload * depayload,
70     GstRTPBuffer * rtp);
71 
72 static void
gst_rtp_mp1s_depay_class_init(GstRtpMP1SDepayClass * klass)73 gst_rtp_mp1s_depay_class_init (GstRtpMP1SDepayClass * klass)
74 {
75   GstElementClass *gstelement_class;
76   GstRTPBaseDepayloadClass *gstrtpbasedepayload_class;
77 
78   gstelement_class = (GstElementClass *) klass;
79   gstrtpbasedepayload_class = (GstRTPBaseDepayloadClass *) klass;
80 
81   gstrtpbasedepayload_class->process_rtp_packet = gst_rtp_mp1s_depay_process;
82   gstrtpbasedepayload_class->set_caps = gst_rtp_mp1s_depay_setcaps;
83 
84   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);
88 
89   gst_element_class_set_static_metadata (gstelement_class,
90       "RTP MPEG1 System Stream depayloader", "Codec/Depayloader/Network/RTP",
91       "Extracts MPEG1 System Streams from RTP packets (RFC 3555)",
92       "Wim Taymans <wim.taymans@gmail.com>");
93 }
94 
95 static void
gst_rtp_mp1s_depay_init(GstRtpMP1SDepay * rtpmp1sdepay)96 gst_rtp_mp1s_depay_init (GstRtpMP1SDepay * rtpmp1sdepay)
97 {
98 }
99 
100 static gboolean
gst_rtp_mp1s_depay_setcaps(GstRTPBaseDepayload * depayload,GstCaps * caps)101 gst_rtp_mp1s_depay_setcaps (GstRTPBaseDepayload * depayload, GstCaps * caps)
102 {
103   GstCaps *srccaps;
104   GstStructure *structure;
105   gint clock_rate;
106   gboolean res;
107 
108   structure = gst_caps_get_structure (caps, 0);
109   if (!gst_structure_get_int (structure, "clock-rate", &clock_rate))
110     clock_rate = 90000;         /* default */
111   depayload->clock_rate = clock_rate;
112 
113   srccaps = gst_caps_new_simple ("video/mpeg",
114       "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
115   res = gst_pad_set_caps (GST_RTP_BASE_DEPAYLOAD_SRCPAD (depayload), srccaps);
116   gst_caps_unref (srccaps);
117 
118   return res;
119 }
120 
121 static GstBuffer *
gst_rtp_mp1s_depay_process(GstRTPBaseDepayload * depayload,GstRTPBuffer * rtp)122 gst_rtp_mp1s_depay_process (GstRTPBaseDepayload * depayload, GstRTPBuffer * rtp)
123 {
124   GstBuffer *outbuf;
125 
126   outbuf = gst_rtp_buffer_get_payload_buffer (rtp);
127 
128   if (outbuf) {
129     GST_DEBUG ("gst_rtp_mp1s_depay_chain: pushing buffer of size %"
130         G_GSIZE_FORMAT, gst_buffer_get_size (outbuf));
131 
132     gst_rtp_drop_meta (GST_ELEMENT_CAST (depayload), outbuf, 0);
133   }
134 
135   return outbuf;
136 }
137 
138 gboolean
gst_rtp_mp1s_depay_plugin_init(GstPlugin * plugin)139 gst_rtp_mp1s_depay_plugin_init (GstPlugin * plugin)
140 {
141   return gst_element_register (plugin, "rtpmp1sdepay",
142       GST_RANK_SECONDARY, GST_TYPE_RTP_MP1S_DEPAY);
143 }
144