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., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
24 #include <gst/rtp/gstrtpbuffer.h>
27 #include "gstrtpac3depay.h"
29 GST_DEBUG_CATEGORY_STATIC (rtpac3depay_debug);
30 #define GST_CAT_DEFAULT (rtpac3depay_debug)
32 /* elementfactory information */
33 static const GstElementDetails gst_rtp_ac3depay_details =
34 GST_ELEMENT_DETAILS ("RTP AC3 depayloader",
35 "Codec/Depayloader/Network",
36 "Extracts AC3 audio from RTP packets (RFC 4184)",
37 "Wim Taymans <wim.taymans@gmail.com>");
39 static GstStaticPadTemplate gst_rtp_ac3_depay_src_template =
40 GST_STATIC_PAD_TEMPLATE ("src",
43 GST_STATIC_CAPS ("audio/ac3")
46 static GstStaticPadTemplate gst_rtp_ac3_depay_sink_template =
47 GST_STATIC_PAD_TEMPLATE ("sink",
50 GST_STATIC_CAPS ("application/x-rtp, "
51 "media = (string) \"audio\", "
52 "payload = (int) " GST_RTP_PAYLOAD_DYNAMIC_STRING ", "
53 "clock-rate = (int) { 32000, 44100, 48000 }, "
54 "encoding-name = (string) \"AC3\"")
57 GST_BOILERPLATE (GstRtpAC3Depay, gst_rtp_ac3_depay, GstBaseRTPDepayload,
58 GST_TYPE_BASE_RTP_DEPAYLOAD);
60 static gboolean gst_rtp_ac3_depay_setcaps (GstBaseRTPDepayload * depayload,
62 static GstBuffer *gst_rtp_ac3_depay_process (GstBaseRTPDepayload * depayload,
66 gst_rtp_ac3_depay_base_init (gpointer klass)
68 GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
70 gst_element_class_add_pad_template (element_class,
71 gst_static_pad_template_get (&gst_rtp_ac3_depay_src_template));
72 gst_element_class_add_pad_template (element_class,
73 gst_static_pad_template_get (&gst_rtp_ac3_depay_sink_template));
75 gst_element_class_set_details (element_class, &gst_rtp_ac3depay_details);
79 gst_rtp_ac3_depay_class_init (GstRtpAC3DepayClass * klass)
81 GstBaseRTPDepayloadClass *gstbasertpdepayload_class;
83 gstbasertpdepayload_class = (GstBaseRTPDepayloadClass *) klass;
85 gstbasertpdepayload_class->set_caps = gst_rtp_ac3_depay_setcaps;
86 gstbasertpdepayload_class->process = gst_rtp_ac3_depay_process;
88 GST_DEBUG_CATEGORY_INIT (rtpac3depay_debug, "rtpac3depay", 0,
89 "MPEG Audio RTP Depayloader");
93 gst_rtp_ac3_depay_init (GstRtpAC3Depay * rtpac3depay,
94 GstRtpAC3DepayClass * klass)
96 /* needed because of GST_BOILERPLATE */
100 gst_rtp_ac3_depay_setcaps (GstBaseRTPDepayload * depayload, GstCaps * caps)
102 GstStructure *structure;
107 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;
113 srccaps = gst_caps_new_simple ("audio/ac3", NULL);
114 res = gst_pad_set_caps (depayload->srcpad, srccaps);
115 gst_caps_unref (srccaps);
126 static const struct frmsize_s frmsizecod_tbl[] = {
131 {48, {96, 104, 144}},
132 {48, {96, 105, 144}},
133 {56, {112, 121, 168}},
134 {56, {112, 122, 168}},
135 {64, {128, 139, 192}},
136 {64, {128, 140, 192}},
137 {80, {160, 174, 240}},
138 {80, {160, 175, 240}},
139 {96, {192, 208, 288}},
140 {96, {192, 209, 288}},
141 {112, {224, 243, 336}},
142 {112, {224, 244, 336}},
143 {128, {256, 278, 384}},
144 {128, {256, 279, 384}},
145 {160, {320, 348, 480}},
146 {160, {320, 349, 480}},
147 {192, {384, 417, 576}},
148 {192, {384, 418, 576}},
149 {224, {448, 487, 672}},
150 {224, {448, 488, 672}},
151 {256, {512, 557, 768}},
152 {256, {512, 558, 768}},
153 {320, {640, 696, 960}},
154 {320, {640, 697, 960}},
155 {384, {768, 835, 1152}},
156 {384, {768, 836, 1152}},
157 {448, {896, 975, 1344}},
158 {448, {896, 976, 1344}},
159 {512, {1024, 1114, 1536}},
160 {512, {1024, 1115, 1536}},
161 {576, {1152, 1253, 1728}},
162 {576, {1152, 1254, 1728}},
163 {640, {1280, 1393, 1920}},
164 {640, {1280, 1394, 1920}}
168 gst_rtp_ac3_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf)
170 GstRtpAC3Depay *rtpac3depay;
173 rtpac3depay = GST_RTP_AC3_DEPAY (depayload);
179 if (gst_rtp_buffer_get_payload_len (buf) < 2)
182 payload = gst_rtp_buffer_get_payload (buf);
187 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
188 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
190 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
192 FT = payload[0] & 0x3;
195 GST_DEBUG_OBJECT (rtpac3depay, "FT: %d, NF: %d", FT, NF);
197 /* We don't bother with fragmented packets yet */
198 outbuf = gst_rtp_buffer_get_payload_subbuffer (buf, 2, -1);
200 GST_DEBUG_OBJECT (rtpac3depay, "pushing buffer of size %d",
201 GST_BUFFER_SIZE (outbuf));
211 GST_ELEMENT_WARNING (rtpac3depay, STREAM, DECODE,
212 ("Empty Payload."), (NULL));
218 gst_rtp_ac3_depay_plugin_init (GstPlugin * plugin)
220 return gst_element_register (plugin, "rtpac3depay",
221 GST_RANK_MARGINAL, GST_TYPE_RTP_AC3_DEPAY);