2 * Copyright (C) <2007> Wim Taymans <wim.taymans@gmail.com>
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.
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.
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.
21 * SECTION:element-rtpac3depay
22 * @see_also: rtpac3pay
24 * Extract AC3 audio from RTP packets according to RFC 4184.
25 * For detailed information see: http://www.rfc-editor.org/rfc/rfc4184.txt
28 * <title>Example pipeline</title>
30 * gst-launch-1.0 udpsrc caps='application/x-rtp, media=(string)audio, clock-rate=(int)44100, encoding-name=(string)AC3, payload=(int)96' ! rtpac3depay ! a52dec ! pulsesink
31 * ]| This example pipeline will depayload and decode an RTP AC3 stream. Refer to
32 * the rtpac3pay example to create the RTP stream.
35 * Last reviewed on 2013-04-25 (1.1.0)
42 #include <gst/rtp/gstrtpbuffer.h>
45 #include "gstrtpac3depay.h"
47 GST_DEBUG_CATEGORY_STATIC (rtpac3depay_debug);
48 #define GST_CAT_DEFAULT (rtpac3depay_debug)
50 static GstStaticPadTemplate gst_rtp_ac3_depay_src_template =
51 GST_STATIC_PAD_TEMPLATE ("src",
54 GST_STATIC_CAPS ("audio/ac3")
57 static GstStaticPadTemplate gst_rtp_ac3_depay_sink_template =
58 GST_STATIC_PAD_TEMPLATE ("sink",
61 GST_STATIC_CAPS ("application/x-rtp, "
62 "media = (string) \"audio\", "
63 "clock-rate = (int) { 32000, 44100, 48000 }, "
64 "encoding-name = (string) \"AC3\"")
67 G_DEFINE_TYPE (GstRtpAC3Depay, gst_rtp_ac3_depay, GST_TYPE_RTP_BASE_DEPAYLOAD);
69 static gboolean gst_rtp_ac3_depay_setcaps (GstRTPBaseDepayload * depayload,
71 static GstBuffer *gst_rtp_ac3_depay_process (GstRTPBaseDepayload * depayload,
75 gst_rtp_ac3_depay_class_init (GstRtpAC3DepayClass * klass)
77 GstElementClass *gstelement_class;
78 GstRTPBaseDepayloadClass *gstrtpbasedepayload_class;
80 gstelement_class = (GstElementClass *) klass;
81 gstrtpbasedepayload_class = (GstRTPBaseDepayloadClass *) klass;
83 gst_element_class_add_pad_template (gstelement_class,
84 gst_static_pad_template_get (&gst_rtp_ac3_depay_src_template));
85 gst_element_class_add_pad_template (gstelement_class,
86 gst_static_pad_template_get (&gst_rtp_ac3_depay_sink_template));
88 gst_element_class_set_static_metadata (gstelement_class,
89 "RTP AC3 depayloader", "Codec/Depayloader/Network/RTP",
90 "Extracts AC3 audio from RTP packets (RFC 4184)",
91 "Wim Taymans <wim.taymans@gmail.com>");
93 gstrtpbasedepayload_class->set_caps = gst_rtp_ac3_depay_setcaps;
94 gstrtpbasedepayload_class->process = gst_rtp_ac3_depay_process;
96 GST_DEBUG_CATEGORY_INIT (rtpac3depay_debug, "rtpac3depay", 0,
97 "AC3 Audio RTP Depayloader");
101 gst_rtp_ac3_depay_init (GstRtpAC3Depay * rtpac3depay)
103 /* needed because of G_DEFINE_TYPE */
107 gst_rtp_ac3_depay_setcaps (GstRTPBaseDepayload * depayload, GstCaps * caps)
109 GstStructure *structure;
114 structure = gst_caps_get_structure (caps, 0);
116 if (!gst_structure_get_int (structure, "clock-rate", &clock_rate))
117 clock_rate = 90000; /* default */
118 depayload->clock_rate = clock_rate;
120 srccaps = gst_caps_new_empty_simple ("audio/ac3");
121 res = gst_pad_set_caps (depayload->srcpad, srccaps);
122 gst_caps_unref (srccaps);
133 static const struct frmsize_s frmsizecod_tbl[] = {
138 {48, {96, 104, 144}},
139 {48, {96, 105, 144}},
140 {56, {112, 121, 168}},
141 {56, {112, 122, 168}},
142 {64, {128, 139, 192}},
143 {64, {128, 140, 192}},
144 {80, {160, 174, 240}},
145 {80, {160, 175, 240}},
146 {96, {192, 208, 288}},
147 {96, {192, 209, 288}},
148 {112, {224, 243, 336}},
149 {112, {224, 244, 336}},
150 {128, {256, 278, 384}},
151 {128, {256, 279, 384}},
152 {160, {320, 348, 480}},
153 {160, {320, 349, 480}},
154 {192, {384, 417, 576}},
155 {192, {384, 418, 576}},
156 {224, {448, 487, 672}},
157 {224, {448, 488, 672}},
158 {256, {512, 557, 768}},
159 {256, {512, 558, 768}},
160 {320, {640, 696, 960}},
161 {320, {640, 697, 960}},
162 {384, {768, 835, 1152}},
163 {384, {768, 836, 1152}},
164 {448, {896, 975, 1344}},
165 {448, {896, 976, 1344}},
166 {512, {1024, 1114, 1536}},
167 {512, {1024, 1115, 1536}},
168 {576, {1152, 1253, 1728}},
169 {576, {1152, 1254, 1728}},
170 {640, {1280, 1393, 1920}},
171 {640, {1280, 1394, 1920}}
175 gst_rtp_ac3_depay_process (GstRTPBaseDepayload * depayload, GstBuffer * buf)
177 GstRtpAC3Depay *rtpac3depay;
179 GstRTPBuffer rtp = { NULL, };
183 rtpac3depay = GST_RTP_AC3_DEPAY (depayload);
185 gst_rtp_buffer_map (buf, GST_MAP_READ, &rtp);
187 if (gst_rtp_buffer_get_payload_len (&rtp) < 2)
190 payload = gst_rtp_buffer_get_payload (&rtp);
195 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
196 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
198 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
200 FT = payload[0] & 0x3;
203 GST_DEBUG_OBJECT (rtpac3depay, "FT: %d, NF: %d", FT, NF);
205 /* We don't bother with fragmented packets yet */
206 outbuf = gst_rtp_buffer_get_payload_subbuffer (&rtp, 2, -1);
208 gst_rtp_buffer_unmap (&rtp);
211 GST_DEBUG_OBJECT (rtpac3depay, "pushing buffer of size %" G_GSIZE_FORMAT,
212 gst_buffer_get_size (outbuf));
219 GST_ELEMENT_WARNING (rtpac3depay, STREAM, DECODE,
220 ("Empty Payload."), (NULL));
221 gst_rtp_buffer_unmap (&rtp);
227 gst_rtp_ac3_depay_plugin_init (GstPlugin * plugin)
229 return gst_element_register (plugin, "rtpac3depay",
230 GST_RANK_SECONDARY, GST_TYPE_RTP_AC3_DEPAY);