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
23 * @see_also: rtpac3pay
25 * Extract AC3 audio from RTP packets according to RFC 4184.
26 * For detailed information see: http://www.rfc-editor.org/rfc/rfc4184.txt
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.
40 #include <gst/rtp/gstrtpbuffer.h>
41 #include <gst/audio/audio.h>
44 #include "gstrtpelements.h"
45 #include "gstrtpac3depay.h"
46 #include "gstrtputils.h"
48 GST_DEBUG_CATEGORY_STATIC (rtpac3depay_debug);
49 #define GST_CAT_DEFAULT (rtpac3depay_debug)
51 static GstStaticPadTemplate gst_rtp_ac3_depay_src_template =
52 GST_STATIC_PAD_TEMPLATE ("src",
55 GST_STATIC_CAPS ("audio/ac3")
58 static GstStaticPadTemplate gst_rtp_ac3_depay_sink_template =
59 GST_STATIC_PAD_TEMPLATE ("sink",
62 GST_STATIC_CAPS ("application/x-rtp, "
63 "media = (string) \"audio\", "
64 "clock-rate = (int) { 32000, 44100, 48000 }, "
65 "encoding-name = (string) \"AC3\"")
68 G_DEFINE_TYPE (GstRtpAC3Depay, gst_rtp_ac3_depay, GST_TYPE_RTP_BASE_DEPAYLOAD);
69 GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (rtpac3depay, "rtpac3depay",
70 GST_RANK_SECONDARY, GST_TYPE_RTP_AC3_DEPAY, rtp_element_init (plugin));
72 static gboolean gst_rtp_ac3_depay_setcaps (GstRTPBaseDepayload * depayload,
74 static GstBuffer *gst_rtp_ac3_depay_process (GstRTPBaseDepayload * depayload,
78 gst_rtp_ac3_depay_class_init (GstRtpAC3DepayClass * klass)
80 GstElementClass *gstelement_class;
81 GstRTPBaseDepayloadClass *gstrtpbasedepayload_class;
83 gstelement_class = (GstElementClass *) klass;
84 gstrtpbasedepayload_class = (GstRTPBaseDepayloadClass *) klass;
86 gst_element_class_add_static_pad_template (gstelement_class,
87 &gst_rtp_ac3_depay_src_template);
88 gst_element_class_add_static_pad_template (gstelement_class,
89 &gst_rtp_ac3_depay_sink_template);
91 gst_element_class_set_static_metadata (gstelement_class,
92 "RTP AC3 depayloader", "Codec/Depayloader/Network/RTP",
93 "Extracts AC3 audio from RTP packets (RFC 4184)",
94 "Wim Taymans <wim.taymans@gmail.com>");
96 gstrtpbasedepayload_class->set_caps = gst_rtp_ac3_depay_setcaps;
97 gstrtpbasedepayload_class->process_rtp_packet = gst_rtp_ac3_depay_process;
99 GST_DEBUG_CATEGORY_INIT (rtpac3depay_debug, "rtpac3depay", 0,
100 "AC3 Audio RTP Depayloader");
104 gst_rtp_ac3_depay_init (GstRtpAC3Depay * rtpac3depay)
106 /* needed because of G_DEFINE_TYPE */
110 gst_rtp_ac3_depay_setcaps (GstRTPBaseDepayload * depayload, GstCaps * caps)
112 GstStructure *structure;
117 structure = gst_caps_get_structure (caps, 0);
119 if (!gst_structure_get_int (structure, "clock-rate", &clock_rate))
120 clock_rate = 90000; /* default */
121 depayload->clock_rate = clock_rate;
123 srccaps = gst_caps_new_empty_simple ("audio/ac3");
124 res = gst_pad_set_caps (depayload->srcpad, srccaps);
125 gst_caps_unref (srccaps);
131 gst_rtp_ac3_depay_process (GstRTPBaseDepayload * depayload, GstRTPBuffer * rtp)
133 GstRtpAC3Depay *rtpac3depay;
138 rtpac3depay = GST_RTP_AC3_DEPAY (depayload);
140 if (gst_rtp_buffer_get_payload_len (rtp) < 2)
143 payload = gst_rtp_buffer_get_payload (rtp);
148 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
149 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
151 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
153 FT = payload[0] & 0x3;
156 GST_DEBUG_OBJECT (rtpac3depay, "FT: %d, NF: %d", FT, NF);
158 /* We don't bother with fragmented packets yet */
159 outbuf = gst_rtp_buffer_get_payload_subbuffer (rtp, 2, -1);
162 gst_rtp_drop_non_audio_meta (rtpac3depay, outbuf);
163 GST_DEBUG_OBJECT (rtpac3depay, "pushing buffer of size %" G_GSIZE_FORMAT,
164 gst_buffer_get_size (outbuf));
172 GST_ELEMENT_WARNING (rtpac3depay, STREAM, DECODE,
173 ("Empty Payload."), (NULL));