rtpvrawpay: Add missing break
[platform/upstream/gst-plugins-good.git] / gst / rtp / gstrtpmpadepay.c
1 /* GStreamer
2  * Copyright (C) <2005> 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 "gstrtpmpadepay.h"
28
29 GST_DEBUG_CATEGORY_STATIC (rtpmpadepay_debug);
30 #define GST_CAT_DEFAULT (rtpmpadepay_debug)
31
32 static GstStaticPadTemplate gst_rtp_mpa_depay_src_template =
33 GST_STATIC_PAD_TEMPLATE ("src",
34     GST_PAD_SRC,
35     GST_PAD_ALWAYS,
36     GST_STATIC_CAPS ("audio/mpeg, " "mpegversion = (int) 1")
37     );
38
39 static GstStaticPadTemplate gst_rtp_mpa_depay_sink_template =
40     GST_STATIC_PAD_TEMPLATE ("sink",
41     GST_PAD_SINK,
42     GST_PAD_ALWAYS,
43     GST_STATIC_CAPS ("application/x-rtp, "
44         "media = (string) \"audio\", "
45         "clock-rate = (int) 90000, " "encoding-name = (string) \"MPA\";"
46         "application/x-rtp, "
47         "media = (string) \"audio\", "
48         "payload = (int) " GST_RTP_PAYLOAD_MPA_STRING ", "
49         "clock-rate = (int) 90000")
50     );
51
52 #define gst_rtp_mpa_depay_parent_class parent_class
53 G_DEFINE_TYPE (GstRtpMPADepay, gst_rtp_mpa_depay, GST_TYPE_RTP_BASE_DEPAYLOAD);
54
55 static gboolean gst_rtp_mpa_depay_setcaps (GstRTPBaseDepayload * depayload,
56     GstCaps * caps);
57 static GstBuffer *gst_rtp_mpa_depay_process (GstRTPBaseDepayload * depayload,
58     GstBuffer * buf);
59
60 static void
61 gst_rtp_mpa_depay_class_init (GstRtpMPADepayClass * klass)
62 {
63   GstElementClass *gstelement_class;
64   GstRTPBaseDepayloadClass *gstrtpbasedepayload_class;
65
66   GST_DEBUG_CATEGORY_INIT (rtpmpadepay_debug, "rtpmpadepay", 0,
67       "MPEG Audio RTP Depayloader");
68
69   gstelement_class = (GstElementClass *) klass;
70   gstrtpbasedepayload_class = (GstRTPBaseDepayloadClass *) klass;
71
72   gst_element_class_add_pad_template (gstelement_class,
73       gst_static_pad_template_get (&gst_rtp_mpa_depay_src_template));
74   gst_element_class_add_pad_template (gstelement_class,
75       gst_static_pad_template_get (&gst_rtp_mpa_depay_sink_template));
76
77   gst_element_class_set_static_metadata (gstelement_class,
78       "RTP MPEG audio depayloader", "Codec/Depayloader/Network/RTP",
79       "Extracts MPEG audio from RTP packets (RFC 2038)",
80       "Wim Taymans <wim.taymans@gmail.com>");
81
82   gstrtpbasedepayload_class->set_caps = gst_rtp_mpa_depay_setcaps;
83   gstrtpbasedepayload_class->process = gst_rtp_mpa_depay_process;
84 }
85
86 static void
87 gst_rtp_mpa_depay_init (GstRtpMPADepay * rtpmpadepay)
88 {
89 }
90
91 static gboolean
92 gst_rtp_mpa_depay_setcaps (GstRTPBaseDepayload * depayload, GstCaps * caps)
93 {
94   GstStructure *structure;
95   GstCaps *outcaps;
96   gint clock_rate;
97   gboolean res;
98
99   structure = gst_caps_get_structure (caps, 0);
100
101   if (!gst_structure_get_int (structure, "clock-rate", &clock_rate))
102     clock_rate = 90000;
103   depayload->clock_rate = clock_rate;
104
105   outcaps =
106       gst_caps_new_simple ("audio/mpeg", "mpegversion", G_TYPE_INT, 1, NULL);
107   res = gst_pad_set_caps (depayload->srcpad, outcaps);
108   gst_caps_unref (outcaps);
109
110   return res;
111 }
112
113 static GstBuffer *
114 gst_rtp_mpa_depay_process (GstRTPBaseDepayload * depayload, GstBuffer * buf)
115 {
116   GstRtpMPADepay *rtpmpadepay;
117   GstBuffer *outbuf;
118   GstRTPBuffer rtp = { NULL };
119   gint payload_len;
120 #if 0
121   guint8 *payload;
122   guint16 frag_offset;
123 #endif
124   gboolean marker;
125
126   rtpmpadepay = GST_RTP_MPA_DEPAY (depayload);
127
128   gst_rtp_buffer_map (buf, GST_MAP_READ, &rtp);
129
130   payload_len = gst_rtp_buffer_get_payload_len (&rtp);
131
132   if (payload_len <= 4)
133     goto empty_packet;
134
135 #if 0
136   payload = gst_rtp_buffer_get_payload (&rtp);
137   /* strip off header
138    *
139    *  0                   1                   2                   3
140    *  0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
141    * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
142    * |             MBZ               |          Frag_offset          |
143    * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
144    */
145   frag_offset = (payload[2] << 8) | payload[3];
146 #endif
147
148   /* subbuffer skipping the 4 header bytes */
149   outbuf = gst_rtp_buffer_get_payload_subbuffer (&rtp, 4, -1);
150   marker = gst_rtp_buffer_get_marker (&rtp);
151
152   if (marker) {
153     /* mark start of talkspurt with RESYNC */
154     GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_RESYNC);
155   }
156   GST_DEBUG_OBJECT (rtpmpadepay,
157       "gst_rtp_mpa_depay_chain: pushing buffer of size %" G_GSIZE_FORMAT "",
158       gst_buffer_get_size (outbuf));
159
160   gst_rtp_buffer_unmap (&rtp);
161
162   /* FIXME, we can push half mpeg frames when they are split over multiple
163    * RTP packets */
164   return outbuf;
165
166   /* ERRORS */
167 empty_packet:
168   {
169     GST_ELEMENT_WARNING (rtpmpadepay, STREAM, DECODE,
170         ("Empty Payload."), (NULL));
171     gst_rtp_buffer_unmap (&rtp);
172     return NULL;
173   }
174 }
175
176 gboolean
177 gst_rtp_mpa_depay_plugin_init (GstPlugin * plugin)
178 {
179   return gst_element_register (plugin, "rtpmpadepay",
180       GST_RANK_SECONDARY, GST_TYPE_RTP_MPA_DEPAY);
181 }