2
* Copyright (C) 2007 Nokia Corporation
3
* Copyright (C) 2007 Collabora Ltd
4
* @author: Olivier Crete <olivier.crete@collabora.co.uk>
6
* This library is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU Library General Public
8
* License as published by the Free Software Foundation; either
9
* version 2 of the License, or (at your option) any later version.
11
* This library is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
* Library General Public License for more details.
16
* You should have received a copy of the GNU Library General Public
17
* License along with this library; if not, write to the
18
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19
* Boston, MA 02111-1307, USA.
28
#include <gst/rtp/gstrtpbuffer.h>
30
#include "gstrtpcnpayload.h"
32
#ifndef GST_RTP_PAYLOAD_CN_STRING
33
#define GST_RTP_PAYLOAD_CN_STRING "13"
36
#ifndef GST_RTP_PAYLOAD_CN
37
#define GST_RTP_PAYLOAD_CN 13
40
GST_DEBUG_CATEGORY (rtpcnpayload_debug);
41
#define GST_CAT_DEFAULT (rtpcnpayload_debug)
43
/* Elementfactory information */
44
static GstElementDetails gst_rtpcnpayload_details = {
45
"RTP Confort Noise Payloader",
46
"Codec/Payloader/Network",
47
"Payloads CN into RTP packets",
48
"Olivier Crete <olivier.crete@collabora.co.uk>"
51
static GstStaticPadTemplate gst_rtpcnpayload_sink_template =
52
GST_STATIC_PAD_TEMPLATE ("sink",
55
GST_STATIC_CAPS ("audio/CN, "
56
"rate = (int) [ 1, MAX ]")
59
static GstStaticPadTemplate gst_rtpcnpayload_src_template =
60
GST_STATIC_PAD_TEMPLATE ("src",
63
GST_STATIC_CAPS ("application/x-rtp, "
64
"media = (string) \"audio\", "
65
"payload = (int) " GST_RTP_PAYLOAD_CN_STRING ", "
66
"clock-rate = (int) 8000, "
67
"encoding-name = (string) \"CN\"; "
69
"media = (string) \"audio\", "
70
"payload = (int) " GST_RTP_PAYLOAD_DYNAMIC_STRING ", "
71
"clock-rate = (int) [ 1, MAX ], "
72
"encoding-name = (string) \"CN\" ")
75
GST_BOILERPLATE (GstRTPCNPayload, gst_rtpcnpayload, GstBaseRTPPayload,
76
GST_TYPE_BASE_RTP_PAYLOAD);
79
static gboolean gst_rtpcnpayload_setcaps (GstBaseRTPPayload * payload,
81
static GstFlowReturn gst_rtpcnpayload_handle_buffer (GstBaseRTPPayload * payload,
85
gst_rtpcnpayload_base_init (gpointer klass)
87
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
89
gst_element_class_add_pad_template (element_class,
90
gst_static_pad_template_get (&gst_rtpcnpayload_sink_template));
91
gst_element_class_add_pad_template (element_class,
92
gst_static_pad_template_get (&gst_rtpcnpayload_src_template));
93
gst_element_class_set_details (element_class, &gst_rtpcnpayload_details);
97
gst_rtpcnpayload_class_init (GstRTPCNPayloadClass * klass)
99
GObjectClass *gobject_class;
100
GstElementClass *gstelement_class;
101
GstBaseRTPPayloadClass *gstbasertppayload_class;
103
gobject_class = (GObjectClass *) klass;
104
gstelement_class = (GstElementClass *) klass;
105
gstbasertppayload_class = (GstBaseRTPPayloadClass *) klass;
107
parent_class = g_type_class_ref (GST_TYPE_BASE_RTP_PAYLOAD);
109
gstbasertppayload_class->set_caps = gst_rtpcnpayload_setcaps;
110
gstbasertppayload_class->handle_buffer = gst_rtpcnpayload_handle_buffer;
112
GST_DEBUG_CATEGORY_INIT (rtpcnpayload_debug, "rtpcnpay", 0, "CN RTP Payloader");
116
gst_rtpcnpayload_init (GstRTPCNPayload * cnpayload,
117
GstRTPCNPayloadClass * class)
119
GstBaseRTPPayload * payload = GST_BASE_RTP_PAYLOAD (cnpayload);
121
payload->pt = GST_RTP_PAYLOAD_CN;
125
gst_rtpcnpayload_setcaps (GstBaseRTPPayload * payload, GstCaps * caps)
127
GstRTPCNPayload *cnpayload;
128
GstStructure *structure;
131
cnpayload = GST_RTPCNPAYLOAD (payload);
133
structure = gst_caps_get_structure (caps, 0);
135
if (!gst_structure_get_int (structure, "rate", &rate))
138
if (payload->pt == GST_RTP_PAYLOAD_CN && rate != 8000) {
139
GST_WARNING_OBJECT (cnpayload,
140
"Trying to set PT 13 with non-8000 rate (%d\n)", rate);
144
gst_basertppayload_set_options (payload, "audio",
145
payload->pt != GST_RTP_PAYLOAD_CN , "CN", rate);
147
gst_basertppayload_set_outcaps (payload, NULL);
152
/* Get a CN frame... move it in a rtp buffer... ship it!
155
gst_rtpcnpayload_handle_buffer (GstBaseRTPPayload * basepayload,
159
GstFlowReturn ret = GST_FLOW_OK;
161
outbuf = gst_rtp_buffer_new_allocate (GST_BUFFER_SIZE (buffer), 0, 0);
163
GST_BUFFER_TIMESTAMP (outbuf) = GST_BUFFER_TIMESTAMP (buffer);
164
GST_BUFFER_DURATION (outbuf) = GST_BUFFER_DURATION (buffer);
165
GST_BUFFER_FLAGS (outbuf) = GST_BUFFER_FLAGS (buffer) &
166
(GST_BUFFER_FLAG_DISCONT | GST_BUFFER_FLAG_DELTA_UNIT);
168
memcpy(gst_rtp_buffer_get_payload(outbuf), GST_BUFFER_DATA(buffer),
169
GST_BUFFER_SIZE (buffer));
172
ret = gst_basertppayload_push (basepayload, outbuf);
173
gst_buffer_unref (buffer);
178
gst_rtpcnpayload_plugin_init (GstPlugin * plugin)
180
return gst_element_register (plugin, "rtpcnpay",
181
GST_RANK_NONE, GST_TYPE_RTPCNPAYLOAD);