~ubuntu-branches/ubuntu/lucid/gst-plugins-farsight/lucid

« back to all changes in this revision

Viewing changes to gst/rtppayloads/gstrtpcnpayload.c

  • Committer: Bazaar Package Importer
  • Author(s): Sjoerd Simons, Simon McVittie, Sjoerd Simons
  • Date: 2008-06-05 16:39:48 UTC
  • mfrom: (1.3.1 upstream) (2.1.4 gutsy)
  • Revision ID: james.westby@ubuntu.com-20080605163948-ev3yvy6ehlqq7dbw
Tags: 0.12.8-1
[ Simon McVittie ]
* Use my debian.org address in Uploaders
* Wrap Uploaders, Build-Depends

[ Sjoerd Simons ]
* New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Farsight
 
2
 * Copyright (C) 2007 Nokia Corporation
 
3
 * Copyright (C) 2007 Collabora Ltd
 
4
 *  @author: Olivier Crete <olivier.crete@collabora.co.uk>
 
5
 *
 
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.
 
10
 *
 
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.
 
15
 *
 
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.
 
20
 */
 
21
 
 
22
#ifdef HAVE_CONFIG_H
 
23
#  include "config.h"
 
24
#endif
 
25
 
 
26
#include <stdlib.h>
 
27
#include <string.h>
 
28
#include <gst/rtp/gstrtpbuffer.h>
 
29
 
 
30
#include "gstrtpcnpayload.h"
 
31
 
 
32
#ifndef GST_RTP_PAYLOAD_CN_STRING
 
33
#define GST_RTP_PAYLOAD_CN_STRING "13"
 
34
#endif
 
35
 
 
36
#ifndef GST_RTP_PAYLOAD_CN
 
37
#define GST_RTP_PAYLOAD_CN 13
 
38
#endif
 
39
 
 
40
GST_DEBUG_CATEGORY (rtpcnpayload_debug);
 
41
#define GST_CAT_DEFAULT (rtpcnpayload_debug)
 
42
 
 
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>"
 
49
};
 
50
 
 
51
static GstStaticPadTemplate gst_rtpcnpayload_sink_template =
 
52
GST_STATIC_PAD_TEMPLATE ("sink",
 
53
    GST_PAD_SINK,
 
54
    GST_PAD_ALWAYS,
 
55
    GST_STATIC_CAPS ("audio/CN, "
 
56
                     "rate = (int) [ 1, MAX ]")
 
57
    );
 
58
 
 
59
static GstStaticPadTemplate gst_rtpcnpayload_src_template =
 
60
GST_STATIC_PAD_TEMPLATE ("src",
 
61
    GST_PAD_SRC,
 
62
    GST_PAD_ALWAYS,
 
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\"; " 
 
68
        "application/x-rtp, "
 
69
        "media = (string) \"audio\", "
 
70
        "payload = (int) " GST_RTP_PAYLOAD_DYNAMIC_STRING ", "
 
71
        "clock-rate = (int) [ 1, MAX ], "
 
72
        "encoding-name = (string) \"CN\" ")
 
73
    );
 
74
 
 
75
GST_BOILERPLATE (GstRTPCNPayload, gst_rtpcnpayload, GstBaseRTPPayload,
 
76
    GST_TYPE_BASE_RTP_PAYLOAD);
 
77
 
 
78
 
 
79
static gboolean gst_rtpcnpayload_setcaps (GstBaseRTPPayload * payload,
 
80
    GstCaps * caps);
 
81
static GstFlowReturn gst_rtpcnpayload_handle_buffer (GstBaseRTPPayload * payload,
 
82
    GstBuffer * buffer);
 
83
 
 
84
static void
 
85
gst_rtpcnpayload_base_init (gpointer klass)
 
86
{
 
87
  GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
 
88
 
 
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);
 
94
}
 
95
 
 
96
static void
 
97
gst_rtpcnpayload_class_init (GstRTPCNPayloadClass * klass)
 
98
{
 
99
  GObjectClass *gobject_class;
 
100
  GstElementClass *gstelement_class;
 
101
  GstBaseRTPPayloadClass *gstbasertppayload_class;
 
102
 
 
103
  gobject_class = (GObjectClass *) klass;
 
104
  gstelement_class = (GstElementClass *) klass;
 
105
  gstbasertppayload_class = (GstBaseRTPPayloadClass *) klass;
 
106
 
 
107
  parent_class = g_type_class_ref (GST_TYPE_BASE_RTP_PAYLOAD);
 
108
 
 
109
  gstbasertppayload_class->set_caps = gst_rtpcnpayload_setcaps;
 
110
  gstbasertppayload_class->handle_buffer = gst_rtpcnpayload_handle_buffer;
 
111
 
 
112
  GST_DEBUG_CATEGORY_INIT (rtpcnpayload_debug, "rtpcnpay", 0, "CN RTP Payloader");
 
113
}
 
114
 
 
115
static void
 
116
gst_rtpcnpayload_init (GstRTPCNPayload * cnpayload, 
 
117
    GstRTPCNPayloadClass * class)
 
118
{
 
119
  GstBaseRTPPayload * payload = GST_BASE_RTP_PAYLOAD (cnpayload);
 
120
 
 
121
  payload->pt = GST_RTP_PAYLOAD_CN;
 
122
}
 
123
 
 
124
static gboolean
 
125
gst_rtpcnpayload_setcaps (GstBaseRTPPayload * payload, GstCaps * caps)
 
126
{
 
127
  GstRTPCNPayload *cnpayload;
 
128
  GstStructure *structure;
 
129
  gint rate;
 
130
 
 
131
  cnpayload = GST_RTPCNPAYLOAD (payload);
 
132
 
 
133
  structure = gst_caps_get_structure (caps, 0);
 
134
 
 
135
  if (!gst_structure_get_int (structure, "rate", &rate))
 
136
    rate = 8000;
 
137
  
 
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);
 
141
    return FALSE;
 
142
  }
 
143
 
 
144
  gst_basertppayload_set_options (payload, "audio", 
 
145
      payload->pt != GST_RTP_PAYLOAD_CN , "CN", rate);
 
146
  
 
147
  gst_basertppayload_set_outcaps (payload, NULL);
 
148
 
 
149
  return TRUE;
 
150
}
 
151
 
 
152
/* Get a CN frame... move it in a rtp buffer... ship it!
 
153
 */
 
154
static GstFlowReturn
 
155
gst_rtpcnpayload_handle_buffer (GstBaseRTPPayload * basepayload,
 
156
    GstBuffer * buffer)
 
157
{
 
158
  GstBuffer *outbuf;
 
159
  GstFlowReturn ret = GST_FLOW_OK;
 
160
 
 
161
  outbuf =  gst_rtp_buffer_new_allocate (GST_BUFFER_SIZE (buffer), 0, 0);
 
162
 
 
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);
 
167
 
 
168
  memcpy(gst_rtp_buffer_get_payload(outbuf), GST_BUFFER_DATA(buffer), 
 
169
      GST_BUFFER_SIZE (buffer));
 
170
 
 
171
  
 
172
  ret = gst_basertppayload_push (basepayload, outbuf);
 
173
  gst_buffer_unref (buffer);
 
174
  return ret;
 
175
}
 
176
 
 
177
gboolean
 
178
gst_rtpcnpayload_plugin_init (GstPlugin * plugin)
 
179
{
 
180
  return gst_element_register (plugin, "rtpcnpay",
 
181
      GST_RANK_NONE, GST_TYPE_RTPCNPAYLOAD);
 
182
}