gstrtpilbcdepay.c 6.78 KB
Newer Older
1
/* GStreamer
2
 * Copyright (C) <2006> Philippe Khalaf <burger@speedy.org>
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#ifdef HAVE_CONFIG_H
#  include "config.h"
#endif

#include <string.h>
25
#include <stdlib.h>
26
27
28
29
#include <gst/rtp/gstrtpbuffer.h>
#include "gstrtpilbcdepay.h"

/* elementfactory information */
30
static const GstElementDetails gst_rtp_ilbc_depay_details =
31
GST_ELEMENT_DETAILS ("RTP iLBC packet depayloader",
Wim Taymans's avatar
Wim Taymans committed
32
    "Codec/Depayloader/Network",
33
34
35
36
37
38
39
40
41
42
    "Extracts iLBC audio from RTP packets",
    "Philippe Kalaf <philippe.kalaf@collabora.co.uk>");

/* RtpiLBCDepay signals and args */
enum
{
  /* FILL ME */
  LAST_SIGNAL
};

43
44
#define DEFAULT_MODE GST_ILBC_MODE_30

45
46
enum
{
47
48
  PROP_0,
  PROP_MODE
49
50
};

51
/* FIXME, mode should be string because it is a parameter in SDP fmtp */
52
53
54
55
56
57
static GstStaticPadTemplate gst_rtp_ilbc_depay_sink_template =
GST_STATIC_PAD_TEMPLATE ("sink",
    GST_PAD_SINK,
    GST_PAD_ALWAYS,
    GST_STATIC_CAPS ("application/x-rtp, "
        "media = (string) \"audio\", "
58
        "payload = (int) " GST_RTP_PAYLOAD_DYNAMIC_STRING ", "
59
        "clock-rate = (int) 8000, "
60
61
        "encoding-name = (string) \"ILBC\", "
        "mode = (string) { \"20\", \"30\" }")
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
    );

static GstStaticPadTemplate gst_rtp_ilbc_depay_src_template =
GST_STATIC_PAD_TEMPLATE ("src",
    GST_PAD_SRC,
    GST_PAD_ALWAYS,
    GST_STATIC_CAPS ("audio/x-iLBC, " "mode = (int) { 20, 30 }")
    );

static void gst_ilbc_depay_set_property (GObject * object,
    guint prop_id, const GValue * value, GParamSpec * pspec);
static void gst_ilbc_depay_get_property (GObject * object,
    guint prop_id, GValue * value, GParamSpec * pspec);

static GstBuffer *gst_rtp_ilbc_depay_process (GstBaseRTPDepayload * depayload,
    GstBuffer * buf);
static gboolean gst_rtp_ilbc_depay_setcaps (GstBaseRTPDepayload * depayload,
    GstCaps * caps);

GST_BOILERPLATE (GstRTPiLBCDepay, gst_rtp_ilbc_depay, GstBaseRTPDepayload,
    GST_TYPE_BASE_RTP_DEPAYLOAD);

#define GST_TYPE_ILBC_MODE (gst_ilbc_mode_get_type())
static GType
gst_ilbc_mode_get_type (void)
{
  static GType ilbc_mode_type = 0;
89
  static const GEnumValue ilbc_modes[] = {
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
    {GST_ILBC_MODE_20, "20ms frames", "20ms"},
    {GST_ILBC_MODE_30, "30ms frames", "30ms"},
    {0, NULL, NULL},
  };

  if (!ilbc_mode_type) {
    ilbc_mode_type = g_enum_register_static ("iLBCMode", ilbc_modes);
  }
  return ilbc_mode_type;
}

static void
gst_rtp_ilbc_depay_base_init (gpointer klass)
{
  GstElementClass *element_class = GST_ELEMENT_CLASS (klass);

  gst_element_class_add_pad_template (element_class,
      gst_static_pad_template_get (&gst_rtp_ilbc_depay_src_template));
  gst_element_class_add_pad_template (element_class,
      gst_static_pad_template_get (&gst_rtp_ilbc_depay_sink_template));
  gst_element_class_set_details (element_class, &gst_rtp_ilbc_depay_details);
}

static void
gst_rtp_ilbc_depay_class_init (GstRTPiLBCDepayClass * klass)
{
  GObjectClass *gobject_class;
  GstElementClass *gstelement_class;
  GstBaseRTPDepayloadClass *gstbasertpdepayload_class;

  gobject_class = (GObjectClass *) klass;
  gstelement_class = (GstElementClass *) klass;
  gstbasertpdepayload_class = (GstBaseRTPDepayloadClass *) klass;

  gobject_class->set_property = gst_ilbc_depay_set_property;
  gobject_class->get_property = gst_ilbc_depay_get_property;

127
128
129
130
  /* FIXME, mode is in the caps */
  g_object_class_install_property (gobject_class, PROP_MODE,
      g_param_spec_enum ("mode", "Mode", "iLBC frame mode",
          GST_TYPE_ILBC_MODE, DEFAULT_MODE, G_PARAM_READWRITE));
131
132
133
134
135
136
137
138
139
140
141
142
143

  gstbasertpdepayload_class->process = gst_rtp_ilbc_depay_process;
  gstbasertpdepayload_class->set_caps = gst_rtp_ilbc_depay_setcaps;
}

static void
gst_rtp_ilbc_depay_init (GstRTPiLBCDepay * rtpilbcdepay,
    GstRTPiLBCDepayClass * klass)
{
  GstBaseRTPDepayload *depayload;

  depayload = GST_BASE_RTP_DEPAYLOAD (rtpilbcdepay);

144
145
  /* Set default mode */
  rtpilbcdepay->mode = DEFAULT_MODE;
146
147
148
149
150
151
152
153
}

static gboolean
gst_rtp_ilbc_depay_setcaps (GstBaseRTPDepayload * depayload, GstCaps * caps)
{
  GstRTPiLBCDepay *rtpilbcdepay = GST_RTP_ILBC_DEPAY (depayload);
  GstCaps *srccaps;
  GstStructure *structure;
154
  const gchar *mode_str = NULL;
155
  gint mode;
156
157
  gboolean ret;

158
159
160
  structure = gst_caps_get_structure (caps, 0);

  mode = rtpilbcdepay->mode;
161
162
163
164
165
166
167
168
169

  /* parse mode, if we can */
  mode_str = gst_structure_get_string (structure, "mode");
  if (mode_str) {
    mode = strtol (mode_str, NULL, 10);
    if (mode != 20 && mode != 30)
      mode = rtpilbcdepay->mode;
  }

170
  rtpilbcdepay->mode = mode;
171

172
173
  srccaps = gst_caps_new_simple ("audio/x-iLBC",
      "mode", G_TYPE_INT, rtpilbcdepay->mode, NULL);
174
  ret = gst_pad_set_caps (GST_BASE_RTP_DEPAYLOAD_SRCPAD (depayload), srccaps);
Stefan Kost's avatar
Stefan Kost committed
175

176
  GST_DEBUG ("set caps on source: %" GST_PTR_FORMAT " (ret=%d)", srccaps, ret);
177
  gst_caps_unref (srccaps);
178
179
180
181

  /* always fixed clock rate of 8000 */
  depayload->clock_rate = 8000;

182
183
184
185
186
187
  return ret;
}

static GstBuffer *
gst_rtp_ilbc_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf)
{
188
  GstBuffer *outbuf;
189
190
191
192
193
194

  GST_DEBUG ("process : got %d bytes, mark %d ts %u seqn %d",
      GST_BUFFER_SIZE (buf),
      gst_rtp_buffer_get_marker (buf),
      gst_rtp_buffer_get_timestamp (buf), gst_rtp_buffer_get_seq (buf));

195
  outbuf = gst_rtp_buffer_get_payload_buffer (buf);
196
197
198
199
200
201
202
203
204
205
206

  return outbuf;
}

static void
gst_ilbc_depay_set_property (GObject * object,
    guint prop_id, const GValue * value, GParamSpec * pspec)
{
  GstRTPiLBCDepay *rtpilbcdepay = GST_RTP_ILBC_DEPAY (object);

  switch (prop_id) {
207
    case PROP_MODE:
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
      rtpilbcdepay->mode = g_value_get_enum (value);
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
  }
}

static void
gst_ilbc_depay_get_property (GObject * object,
    guint prop_id, GValue * value, GParamSpec * pspec)
{
  GstRTPiLBCDepay *rtpilbcdepay = GST_RTP_ILBC_DEPAY (object);

  switch (prop_id) {
223
    case PROP_MODE:
224
225
226
227
228
229
230
231
232
233
234
235
      g_value_set_enum (value, rtpilbcdepay->mode);
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
  }
}

gboolean
gst_rtp_ilbc_depay_plugin_init (GstPlugin * plugin)
{
  return gst_element_register (plugin, "rtpilbcdepay",
Wim Taymans's avatar
Wim Taymans committed
236
      GST_RANK_MARGINAL, GST_TYPE_RTP_ILBC_DEPAY);
237
}