1 /* GStreamer
2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
3 * Copyright (C) <2005> Zeeshan Ali <zeenix@gmail.com>
4 *
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.
9 *
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.
14 *
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., 51 Franklin St, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 */
20
21 #ifdef HAVE_CONFIG_H
22 # include "config.h"
23 #endif
24
25 #include <string.h>
26 #include <gst/rtp/gstrtpbuffer.h>
27 #include <gst/audio/audio.h>
28 #include "gstrtpgsmdepay.h"
29 #include "gstrtputils.h"
30
31 GST_DEBUG_CATEGORY_STATIC (rtpgsmdepay_debug);
32 #define GST_CAT_DEFAULT (rtpgsmdepay_debug)
33
34 /* RTPGSMDepay signals and args */
35 enum
36 {
37 /* FILL ME */
38 LAST_SIGNAL
39 };
40
41 static GstStaticPadTemplate gst_rtp_gsm_depay_src_template =
42 GST_STATIC_PAD_TEMPLATE ("src",
43 GST_PAD_SRC,
44 GST_PAD_ALWAYS,
45 GST_STATIC_CAPS ("audio/x-gsm, " "rate = (int) 8000, " "channels = 1")
46 );
47
48 static GstStaticPadTemplate gst_rtp_gsm_depay_sink_template =
49 GST_STATIC_PAD_TEMPLATE ("sink",
50 GST_PAD_SINK,
51 GST_PAD_ALWAYS,
52 GST_STATIC_CAPS ("application/x-rtp, "
53 "media = (string) \"audio\", "
54 "clock-rate = (int) 8000, " "encoding-name = (string) \"GSM\";"
55 "application/x-rtp, "
56 "media = (string) \"audio\", "
57 "payload = (int) " GST_RTP_PAYLOAD_GSM_STRING ", "
58 "clock-rate = (int) 8000")
59 );
60
61 static GstBuffer *gst_rtp_gsm_depay_process (GstRTPBaseDepayload * _depayload,
62 GstRTPBuffer * rtp);
63 static gboolean gst_rtp_gsm_depay_setcaps (GstRTPBaseDepayload * _depayload,
64 GstCaps * caps);
65
66 #define gst_rtp_gsm_depay_parent_class parent_class
67 G_DEFINE_TYPE (GstRTPGSMDepay, gst_rtp_gsm_depay, GST_TYPE_RTP_BASE_DEPAYLOAD);
68
69 static void
gst_rtp_gsm_depay_class_init(GstRTPGSMDepayClass * klass)70 gst_rtp_gsm_depay_class_init (GstRTPGSMDepayClass * klass)
71 {
72 GstElementClass *gstelement_class;
73 GstRTPBaseDepayloadClass *gstrtpbase_depayload_class;
74
75 gstelement_class = (GstElementClass *) klass;
76 gstrtpbase_depayload_class = (GstRTPBaseDepayloadClass *) klass;
77
78 gst_element_class_add_static_pad_template (gstelement_class,
79 &gst_rtp_gsm_depay_src_template);
80 gst_element_class_add_static_pad_template (gstelement_class,
81 &gst_rtp_gsm_depay_sink_template);
82
83 gst_element_class_set_static_metadata (gstelement_class,
84 "RTP GSM depayloader", "Codec/Depayloader/Network/RTP",
85 "Extracts GSM audio from RTP packets", "Zeeshan Ali <zeenix@gmail.com>");
86
87 gstrtpbase_depayload_class->process_rtp_packet = gst_rtp_gsm_depay_process;
88 gstrtpbase_depayload_class->set_caps = gst_rtp_gsm_depay_setcaps;
89
90 GST_DEBUG_CATEGORY_INIT (rtpgsmdepay_debug, "rtpgsmdepay", 0,
91 "GSM Audio RTP Depayloader");
92 }
93
94 static void
gst_rtp_gsm_depay_init(GstRTPGSMDepay * rtpgsmdepay)95 gst_rtp_gsm_depay_init (GstRTPGSMDepay * rtpgsmdepay)
96 {
97 }
98
99 static gboolean
gst_rtp_gsm_depay_setcaps(GstRTPBaseDepayload * depayload,GstCaps * caps)100 gst_rtp_gsm_depay_setcaps (GstRTPBaseDepayload * depayload, GstCaps * caps)
101 {
102 GstCaps *srccaps;
103 gboolean ret;
104 GstStructure *structure;
105 gint clock_rate;
106
107 structure = gst_caps_get_structure (caps, 0);
108
109 if (!gst_structure_get_int (structure, "clock-rate", &clock_rate))
110 clock_rate = 8000; /* default */
111 depayload->clock_rate = clock_rate;
112
113 srccaps = gst_caps_new_simple ("audio/x-gsm",
114 "channels", G_TYPE_INT, 1, "rate", G_TYPE_INT, clock_rate, NULL);
115 ret = gst_pad_set_caps (GST_RTP_BASE_DEPAYLOAD_SRCPAD (depayload), srccaps);
116 gst_caps_unref (srccaps);
117
118 return ret;
119 }
120
121 static GstBuffer *
gst_rtp_gsm_depay_process(GstRTPBaseDepayload * depayload,GstRTPBuffer * rtp)122 gst_rtp_gsm_depay_process (GstRTPBaseDepayload * depayload, GstRTPBuffer * rtp)
123 {
124 GstBuffer *outbuf = NULL;
125 gboolean marker;
126
127 marker = gst_rtp_buffer_get_marker (rtp);
128
129 GST_DEBUG ("process : got %" G_GSIZE_FORMAT " bytes, mark %d ts %u seqn %d",
130 gst_buffer_get_size (rtp->buffer), marker,
131 gst_rtp_buffer_get_timestamp (rtp), gst_rtp_buffer_get_seq (rtp));
132
133 outbuf = gst_rtp_buffer_get_payload_buffer (rtp);
134
135 if (marker && outbuf) {
136 /* mark start of talkspurt with RESYNC */
137 GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_RESYNC);
138 }
139
140 if (outbuf) {
141 gst_rtp_drop_non_audio_meta (depayload, outbuf);
142 }
143
144 return outbuf;
145 }
146
147 gboolean
gst_rtp_gsm_depay_plugin_init(GstPlugin * plugin)148 gst_rtp_gsm_depay_plugin_init (GstPlugin * plugin)
149 {
150 return gst_element_register (plugin, "rtpgsmdepay",
151 GST_RANK_SECONDARY, GST_TYPE_RTP_GSM_DEPAY);
152 }
153