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