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 static GstStaticPadTemplate gst_rtp_ac3_depay_src_template =
33 GST_STATIC_PAD_TEMPLATE ("src",
36 GST_STATIC_CAPS ("audio/ac3")
39 static GstStaticPadTemplate gst_rtp_ac3_depay_sink_template =
40 GST_STATIC_PAD_TEMPLATE ("sink",
43 GST_STATIC_CAPS ("application/x-rtp, "
44 "media = (string) \"audio\", "
45 "payload = (int) " GST_RTP_PAYLOAD_DYNAMIC_STRING ", "
46 "clock-rate = (int) { 32000, 44100, 48000 }, "
47 "encoding-name = (string) \"AC3\"")
50 G_DEFINE_TYPE (GstRtpAC3Depay, gst_rtp_ac3_depay, GST_TYPE_BASE_RTP_DEPAYLOAD);
52 static gboolean gst_rtp_ac3_depay_setcaps (GstBaseRTPDepayload * depayload,
54 static GstBuffer *gst_rtp_ac3_depay_process (GstBaseRTPDepayload * depayload,
58 gst_rtp_ac3_depay_class_init (GstRtpAC3DepayClass * klass)
60 GstElementClass *gstelement_class;
61 GstBaseRTPDepayloadClass *gstbasertpdepayload_class;
63 gstelement_class = (GstElementClass *) klass;
64 gstbasertpdepayload_class = (GstBaseRTPDepayloadClass *) klass;
66 gst_element_class_add_pad_template (gstelement_class,
67 gst_static_pad_template_get (&gst_rtp_ac3_depay_src_template));
68 gst_element_class_add_pad_template (gstelement_class,
69 gst_static_pad_template_get (&gst_rtp_ac3_depay_sink_template));
71 gst_element_class_set_details_simple (gstelement_class, "RTP AC3 depayloader",
72 "Codec/Depayloader/Network/RTP",
73 "Extracts AC3 audio from RTP packets (RFC 4184)",
74 "Wim Taymans <wim.taymans@gmail.com>");
76 gstbasertpdepayload_class->set_caps = gst_rtp_ac3_depay_setcaps;
77 gstbasertpdepayload_class->process = gst_rtp_ac3_depay_process;
79 GST_DEBUG_CATEGORY_INIT (rtpac3depay_debug, "rtpac3depay", 0,
80 "AC3 Audio RTP Depayloader");
84 gst_rtp_ac3_depay_init (GstRtpAC3Depay * rtpac3depay)
86 /* needed because of G_DEFINE_TYPE */
90 gst_rtp_ac3_depay_setcaps (GstBaseRTPDepayload * depayload, GstCaps * caps)
92 GstStructure *structure;
97 structure = gst_caps_get_structure (caps, 0);
99 if (!gst_structure_get_int (structure, "clock-rate", &clock_rate))
100 clock_rate = 90000; /* default */
101 depayload->clock_rate = clock_rate;
103 srccaps = gst_caps_new_simple ("audio/ac3", NULL);
104 res = gst_pad_set_caps (depayload->srcpad, srccaps);
105 gst_caps_unref (srccaps);
116 static const struct frmsize_s frmsizecod_tbl[] = {
121 {48, {96, 104, 144}},
122 {48, {96, 105, 144}},
123 {56, {112, 121, 168}},
124 {56, {112, 122, 168}},
125 {64, {128, 139, 192}},
126 {64, {128, 140, 192}},
127 {80, {160, 174, 240}},
128 {80, {160, 175, 240}},
129 {96, {192, 208, 288}},
130 {96, {192, 209, 288}},
131 {112, {224, 243, 336}},
132 {112, {224, 244, 336}},
133 {128, {256, 278, 384}},
134 {128, {256, 279, 384}},
135 {160, {320, 348, 480}},
136 {160, {320, 349, 480}},
137 {192, {384, 417, 576}},
138 {192, {384, 418, 576}},
139 {224, {448, 487, 672}},
140 {224, {448, 488, 672}},
141 {256, {512, 557, 768}},
142 {256, {512, 558, 768}},
143 {320, {640, 696, 960}},
144 {320, {640, 697, 960}},
145 {384, {768, 835, 1152}},
146 {384, {768, 836, 1152}},
147 {448, {896, 975, 1344}},
148 {448, {896, 976, 1344}},
149 {512, {1024, 1114, 1536}},
150 {512, {1024, 1115, 1536}},
151 {576, {1152, 1253, 1728}},
152 {576, {1152, 1254, 1728}},
153 {640, {1280, 1393, 1920}},
154 {640, {1280, 1394, 1920}}
158 gst_rtp_ac3_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf)
160 GstRtpAC3Depay *rtpac3depay;
162 GstRTPBuffer rtp = { NULL, };
166 rtpac3depay = GST_RTP_AC3_DEPAY (depayload);
168 gst_rtp_buffer_map (buf, GST_MAP_READ, &rtp);
170 if (gst_rtp_buffer_get_payload_len (&rtp) < 2)
173 payload = gst_rtp_buffer_get_payload (&rtp);
178 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
179 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
181 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
183 FT = payload[0] & 0x3;
186 GST_DEBUG_OBJECT (rtpac3depay, "FT: %d, NF: %d", FT, NF);
188 /* We don't bother with fragmented packets yet */
189 outbuf = gst_rtp_buffer_get_payload_subbuffer (&rtp, 2, -1);
191 gst_rtp_buffer_unmap (&rtp);
194 GST_DEBUG_OBJECT (rtpac3depay, "pushing buffer of size %d",
195 gst_buffer_get_size (outbuf));
202 GST_ELEMENT_WARNING (rtpac3depay, STREAM, DECODE,
203 ("Empty Payload."), (NULL));
204 gst_rtp_buffer_unmap (&rtp);
210 gst_rtp_ac3_depay_plugin_init (GstPlugin * plugin)
212 return gst_element_register (plugin, "rtpac3depay",
213 GST_RANK_SECONDARY, GST_TYPE_RTP_AC3_DEPAY);