2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
3 * Copyright (C) <2005> Zeeshan Ali <zeenix@gmail.com>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
26 #include <gst/rtp/gstrtpbuffer.h>
27 #include "gstrtpgsmdepay.h"
29 GST_DEBUG_CATEGORY_STATIC (rtpgsmdepay_debug);
30 #define GST_CAT_DEFAULT (rtpgsmdepay_debug)
32 /* RTPGSMDepay signals and args */
39 static GstStaticPadTemplate gst_rtp_gsm_depay_src_template =
40 GST_STATIC_PAD_TEMPLATE ("src",
43 GST_STATIC_CAPS ("audio/x-gsm, " "rate = (int) 8000, " "channels = 1")
46 static GstStaticPadTemplate gst_rtp_gsm_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) 8000, " "encoding-name = (string) \"GSM\";"
55 "media = (string) \"audio\", "
56 "payload = (int) " GST_RTP_PAYLOAD_GSM_STRING ", "
57 "clock-rate = (int) 8000")
60 static GstBuffer *gst_rtp_gsm_depay_process (GstBaseRTPDepayload * _depayload,
62 static gboolean gst_rtp_gsm_depay_setcaps (GstBaseRTPDepayload * _depayload,
65 #define gst_rtp_gsm_depay_parent_class parent_class
66 G_DEFINE_TYPE (GstRTPGSMDepay, gst_rtp_gsm_depay, GST_TYPE_BASE_RTP_DEPAYLOAD);
69 gst_rtp_gsm_depay_class_init (GstRTPGSMDepayClass * klass)
71 GstElementClass *gstelement_class;
72 GstBaseRTPDepayloadClass *gstbasertp_depayload_class;
74 gstelement_class = (GstElementClass *) klass;
75 gstbasertp_depayload_class = (GstBaseRTPDepayloadClass *) klass;
77 gst_element_class_add_pad_template (gstelement_class,
78 gst_static_pad_template_get (&gst_rtp_gsm_depay_src_template));
79 gst_element_class_add_pad_template (gstelement_class,
80 gst_static_pad_template_get (&gst_rtp_gsm_depay_sink_template));
82 gst_element_class_set_details_simple (gstelement_class, "RTP GSM depayloader",
83 "Codec/Depayloader/Network/RTP",
84 "Extracts GSM audio from RTP packets", "Zeeshan Ali <zeenix@gmail.com>");
86 gstbasertp_depayload_class->process = gst_rtp_gsm_depay_process;
87 gstbasertp_depayload_class->set_caps = gst_rtp_gsm_depay_setcaps;
89 GST_DEBUG_CATEGORY_INIT (rtpgsmdepay_debug, "rtpgsmdepay", 0,
90 "GSM Audio RTP Depayloader");
94 gst_rtp_gsm_depay_init (GstRTPGSMDepay * rtpgsmdepay)
99 gst_rtp_gsm_depay_setcaps (GstBaseRTPDepayload * depayload, GstCaps * caps)
103 GstStructure *structure;
106 structure = gst_caps_get_structure (caps, 0);
108 if (!gst_structure_get_int (structure, "clock-rate", &clock_rate))
109 clock_rate = 8000; /* default */
110 depayload->clock_rate = clock_rate;
112 srccaps = gst_caps_new_simple ("audio/x-gsm",
113 "channels", G_TYPE_INT, 1, "rate", G_TYPE_INT, clock_rate, NULL);
114 ret = gst_pad_set_caps (GST_BASE_RTP_DEPAYLOAD_SRCPAD (depayload), srccaps);
115 gst_caps_unref (srccaps);
121 gst_rtp_gsm_depay_process (GstBaseRTPDepayload * _depayload, GstBuffer * buf)
123 GstBuffer *outbuf = NULL;
125 GstRTPBuffer rtp = { NULL };
127 gst_rtp_buffer_map (buf, GST_MAP_READ, &rtp);
129 marker = gst_rtp_buffer_get_marker (&rtp);
131 GST_DEBUG ("process : got %d bytes, mark %d ts %u seqn %d",
132 gst_buffer_get_size (buf), marker,
133 gst_rtp_buffer_get_timestamp (&rtp), gst_rtp_buffer_get_seq (&rtp));
135 outbuf = gst_rtp_buffer_get_payload_buffer (&rtp);
137 gst_rtp_buffer_unmap (&rtp);
140 /* mark start of talkspurt with DISCONT */
141 GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_DISCONT);
148 gst_rtp_gsm_depay_plugin_init (GstPlugin * plugin)
150 return gst_element_register (plugin, "rtpgsmdepay",
151 GST_RANK_SECONDARY, GST_TYPE_RTP_GSM_DEPAY);