6ca6a9bd43cb2623a6ce22aa7cfaded01e7a7ef4
[platform/upstream/gst-plugins-good.git] / gst / rtp / gstrtpmp1sdepay.c
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., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, 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
29 /* elementfactory information */
30 static const GstElementDetails gst_rtp_mp1sdepay_details =
31 GST_ELEMENT_DETAILS ("RTP MPEG1 System Stream depayloader",
32     "Codec/Depayloader/Network",
33     "Extracts MPEG1 System Streams from RTP packets (RFC 3555)",
34     "Wim Taymans <wim.taymans@gmail.com>");
35
36 /* RtpMP1SDepay signals and args */
37 enum
38 {
39   /* FILL ME */
40   LAST_SIGNAL
41 };
42
43 enum
44 {
45   PROP_0,
46   PROP_LAST
47 };
48
49 static GstStaticPadTemplate gst_rtp_mp1s_depay_src_template =
50 GST_STATIC_PAD_TEMPLATE ("src",
51     GST_PAD_SRC,
52     GST_PAD_ALWAYS,
53     GST_STATIC_CAPS ("video/mpeg,systemstream=(boolean)true")
54     );
55
56 /* The spec says video/MP1S but I have seen streams with other/MP1S so we will
57  * allow them both */
58 static GstStaticPadTemplate gst_rtp_mp1s_depay_sink_template =
59     GST_STATIC_PAD_TEMPLATE ("sink",
60     GST_PAD_SINK,
61     GST_PAD_ALWAYS,
62     GST_STATIC_CAPS ("application/x-rtp, "
63         "media = (string) \"other\", "
64         "payload = (int) " GST_RTP_PAYLOAD_DYNAMIC_STRING ", "
65         "clock-rate = (int) [1, MAX ], " "encoding-name = (string) \"MP1S\";"
66         "application/x-rtp, "
67         "media = (string) \"video\", "
68         "payload = (int) " GST_RTP_PAYLOAD_DYNAMIC_STRING ", "
69         "clock-rate = (int) [1, MAX ], " "encoding-name = (string) \"MP1S\"")
70     );
71
72 GST_BOILERPLATE (GstRtpMP1SDepay, gst_rtp_mp1s_depay, GstBaseRTPDepayload,
73     GST_TYPE_BASE_RTP_DEPAYLOAD);
74
75 static gboolean gst_rtp_mp1s_depay_setcaps (GstBaseRTPDepayload * depayload,
76     GstCaps * caps);
77 static GstBuffer *gst_rtp_mp1s_depay_process (GstBaseRTPDepayload * depayload,
78     GstBuffer * buf);
79
80 static void
81 gst_rtp_mp1s_depay_base_init (gpointer klass)
82 {
83   GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
84
85   gst_element_class_add_pad_template (element_class,
86       gst_static_pad_template_get (&gst_rtp_mp1s_depay_src_template));
87   gst_element_class_add_pad_template (element_class,
88       gst_static_pad_template_get (&gst_rtp_mp1s_depay_sink_template));
89
90   gst_element_class_set_details (element_class, &gst_rtp_mp1sdepay_details);
91 }
92
93 static void
94 gst_rtp_mp1s_depay_class_init (GstRtpMP1SDepayClass * klass)
95 {
96   GstBaseRTPDepayloadClass *gstbasertpdepayload_class;
97
98   gstbasertpdepayload_class = (GstBaseRTPDepayloadClass *) klass;
99
100   parent_class = g_type_class_peek_parent (klass);
101
102   gstbasertpdepayload_class->process = gst_rtp_mp1s_depay_process;
103   gstbasertpdepayload_class->set_caps = gst_rtp_mp1s_depay_setcaps;
104
105 }
106
107 static void
108 gst_rtp_mp1s_depay_init (GstRtpMP1SDepay * rtpmp1sdepay,
109     GstRtpMP1SDepayClass * klass)
110 {
111 }
112
113 static gboolean
114 gst_rtp_mp1s_depay_setcaps (GstBaseRTPDepayload * depayload, GstCaps * caps)
115 {
116   GstCaps *srccaps;
117   GstStructure *structure;
118   GstRtpMP1SDepay *rtpmp1sdepay;
119   gint clock_rate;
120   gboolean res;
121
122   rtpmp1sdepay = GST_RTP_MP1S_DEPAY (depayload);
123
124   structure = gst_caps_get_structure (caps, 0);
125   if (!gst_structure_get_int (structure, "clock-rate", &clock_rate))
126     clock_rate = 90000;         /* default */
127   depayload->clock_rate = clock_rate;
128
129   srccaps = gst_caps_new_simple ("video/mpeg",
130       "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
131   res = gst_pad_set_caps (GST_BASE_RTP_DEPAYLOAD_SRCPAD (depayload), srccaps);
132   gst_caps_unref (srccaps);
133
134   return res;
135 }
136
137 static GstBuffer *
138 gst_rtp_mp1s_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf)
139 {
140   GstRtpMP1SDepay *rtpmp1sdepay;
141   GstBuffer *outbuf;
142
143   rtpmp1sdepay = GST_RTP_MP1S_DEPAY (depayload);
144
145   outbuf = gst_rtp_buffer_get_payload_buffer (buf);
146
147   GST_DEBUG ("gst_rtp_mp1s_depay_chain: pushing buffer of size %d",
148       GST_BUFFER_SIZE (outbuf));
149
150   return outbuf;
151 }
152
153 gboolean
154 gst_rtp_mp1s_depay_plugin_init (GstPlugin * plugin)
155 {
156   return gst_element_register (plugin, "rtpmp1sdepay",
157       GST_RANK_MARGINAL, GST_TYPE_RTP_MP1S_DEPAY);
158 }