/* GStreamer
- * Copyright (C) <2005> Edgard Lima <edgard.lima@indt.org.br>
+ * Copyright (C) <2005> Edgard Lima <edgard.lima@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
*
* 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.
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
*/
#ifdef HAVE_CONFIG_H
#include <stdlib.h>
#include <string.h>
#include <gst/rtp/gstrtpbuffer.h>
+#include <gst/audio/audio.h>
#include "gstrtpspeexpay.h"
+#include "gstrtputils.h"
GST_DEBUG_CATEGORY_STATIC (rtpspeexpay_debug);
#define GST_CAT_DEFAULT (rtpspeexpay_debug)
static GstStateChangeReturn gst_rtp_speex_pay_change_state (GstElement *
element, GstStateChange transition);
-static gboolean gst_rtp_speex_pay_setcaps (GstBaseRTPPayload * payload,
+static gboolean gst_rtp_speex_pay_setcaps (GstRTPBasePayload * payload,
GstCaps * caps);
-static GstCaps *gst_rtp_speex_pay_getcaps (GstBaseRTPPayload * payload,
+static GstCaps *gst_rtp_speex_pay_getcaps (GstRTPBasePayload * payload,
GstPad * pad, GstCaps * filter);
-static GstFlowReturn gst_rtp_speex_pay_handle_buffer (GstBaseRTPPayload *
+static GstFlowReturn gst_rtp_speex_pay_handle_buffer (GstRTPBasePayload *
payload, GstBuffer * buffer);
#define gst_rtp_speex_pay_parent_class parent_class
-G_DEFINE_TYPE (GstRtpSPEEXPay, gst_rtp_speex_pay, GST_TYPE_BASE_RTP_PAYLOAD);
+G_DEFINE_TYPE (GstRtpSPEEXPay, gst_rtp_speex_pay, GST_TYPE_RTP_BASE_PAYLOAD);
static void
gst_rtp_speex_pay_class_init (GstRtpSPEEXPayClass * klass)
{
GstElementClass *gstelement_class;
- GstBaseRTPPayloadClass *gstbasertppayload_class;
+ GstRTPBasePayloadClass *gstrtpbasepayload_class;
gstelement_class = (GstElementClass *) klass;
- gstbasertppayload_class = (GstBaseRTPPayloadClass *) klass;
+ gstrtpbasepayload_class = (GstRTPBasePayloadClass *) klass;
gstelement_class->change_state = gst_rtp_speex_pay_change_state;
- gstbasertppayload_class->set_caps = gst_rtp_speex_pay_setcaps;
- gstbasertppayload_class->get_caps = gst_rtp_speex_pay_getcaps;
- gstbasertppayload_class->handle_buffer = gst_rtp_speex_pay_handle_buffer;
+ gstrtpbasepayload_class->set_caps = gst_rtp_speex_pay_setcaps;
+ gstrtpbasepayload_class->get_caps = gst_rtp_speex_pay_getcaps;
+ gstrtpbasepayload_class->handle_buffer = gst_rtp_speex_pay_handle_buffer;
- gst_element_class_add_pad_template (gstelement_class,
- gst_static_pad_template_get (&gst_rtp_speex_pay_sink_template));
- gst_element_class_add_pad_template (gstelement_class,
- gst_static_pad_template_get (&gst_rtp_speex_pay_src_template));
- gst_element_class_set_details_simple (gstelement_class, "RTP Speex payloader",
- "Codec/Payloader/Network/RTP",
+ gst_element_class_add_static_pad_template (gstelement_class,
+ &gst_rtp_speex_pay_sink_template);
+ gst_element_class_add_static_pad_template (gstelement_class,
+ &gst_rtp_speex_pay_src_template);
+ gst_element_class_set_static_metadata (gstelement_class,
+ "RTP Speex payloader", "Codec/Payloader/Network/RTP",
"Payload-encodes Speex audio into a RTP packet",
- "Edgard Lima <edgard.lima@indt.org.br>");
+ "Edgard Lima <edgard.lima@gmail.com>");
GST_DEBUG_CATEGORY_INIT (rtpspeexpay_debug, "rtpspeexpay", 0,
"Speex RTP Payloader");
static void
gst_rtp_speex_pay_init (GstRtpSPEEXPay * rtpspeexpay)
{
- GST_BASE_RTP_PAYLOAD (rtpspeexpay)->clock_rate = 8000;
- GST_BASE_RTP_PAYLOAD_PT (rtpspeexpay) = 110; /* Create String */
+ GST_RTP_BASE_PAYLOAD (rtpspeexpay)->clock_rate = 8000;
+ GST_RTP_BASE_PAYLOAD_PT (rtpspeexpay) = 110; /* Create String */
}
static gboolean
-gst_rtp_speex_pay_setcaps (GstBaseRTPPayload * payload, GstCaps * caps)
+gst_rtp_speex_pay_setcaps (GstRTPBasePayload * payload, GstCaps * caps)
{
/* don't configure yet, we wait for the ident packet */
return TRUE;
static GstCaps *
-gst_rtp_speex_pay_getcaps (GstBaseRTPPayload * payload, GstPad * pad,
+gst_rtp_speex_pay_getcaps (GstRTPBasePayload * payload, GstPad * pad,
GstCaps * filter)
{
GstCaps *otherpadcaps;
GstCaps *caps;
otherpadcaps = gst_pad_get_allowed_caps (payload->srcpad);
- caps = gst_caps_copy (gst_pad_get_pad_template_caps (pad));
+ caps = gst_pad_get_pad_template_caps (pad);
if (otherpadcaps) {
if (!gst_caps_is_empty (otherpadcaps)) {
- GstStructure *ps = gst_caps_get_structure (otherpadcaps, 0);
- GstStructure *s = gst_caps_get_structure (caps, 0);
+ GstStructure *ps;
+ GstStructure *s;
gint clock_rate;
+ ps = gst_caps_get_structure (otherpadcaps, 0);
+ caps = gst_caps_make_writable (caps);
+ s = gst_caps_get_structure (caps, 0);
+
if (gst_structure_get_int (ps, "clock-rate", &clock_rate)) {
gst_structure_fixate_field_nearest_int (s, "rate", clock_rate);
}
const guint8 * data, guint size)
{
guint32 version, header_size, rate, mode, nb_channels;
- GstBaseRTPPayload *payload;
+ GstRTPBasePayload *payload;
gchar *cstr;
gboolean res;
GST_DEBUG_OBJECT (rtpspeexpay, "rate %d, mode %d, nb_channels %d",
rate, mode, nb_channels);
- payload = GST_BASE_RTP_PAYLOAD (rtpspeexpay);
+ payload = GST_RTP_BASE_PAYLOAD (rtpspeexpay);
- gst_basertppayload_set_options (payload, "audio", FALSE, "SPEEX", rate);
+ gst_rtp_base_payload_set_options (payload, "audio", FALSE, "SPEEX", rate);
cstr = g_strdup_printf ("%d", nb_channels);
- res = gst_basertppayload_set_outcaps (payload, "encoding-params",
+ res = gst_rtp_base_payload_set_outcaps (payload, "encoding-params",
G_TYPE_STRING, cstr, NULL);
g_free (cstr);
}
static GstFlowReturn
-gst_rtp_speex_pay_handle_buffer (GstBaseRTPPayload * basepayload,
+gst_rtp_speex_pay_handle_buffer (GstRTPBasePayload * basepayload,
GstBuffer * buffer)
{
GstRtpSPEEXPay *rtpspeexpay;
- guint payload_len;
- gsize size;
+ GstMapInfo map;
GstBuffer *outbuf;
- guint8 *payload, *data;
GstClockTime timestamp, duration;
GstFlowReturn ret;
- GstRTPBuffer rtp;
rtpspeexpay = GST_RTP_SPEEX_PAY (basepayload);
- data = gst_buffer_map (buffer, &size, NULL, GST_MAP_READ);
+ gst_buffer_map (buffer, &map, GST_MAP_READ);
switch (rtpspeexpay->packet) {
case 0:
/* ident packet. We need to parse the headers to construct the RTP
* properties. */
- if (!gst_rtp_speex_pay_parse_ident (rtpspeexpay, data, size))
+ if (!gst_rtp_speex_pay_parse_ident (rtpspeexpay, map.data, map.size)) {
+ gst_buffer_unmap (buffer, &map);
goto parse_error;
+ }
ret = GST_FLOW_OK;
+ gst_buffer_unmap (buffer, &map);
goto done;
case 1:
/* comment packet, we ignore it */
ret = GST_FLOW_OK;
+ gst_buffer_unmap (buffer, &map);
goto done;
default:
/* other packets go in the payload */
break;
}
+ gst_buffer_unmap (buffer, &map);
if (GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_GAP)) {
ret = GST_FLOW_OK;
goto done;
}
- timestamp = GST_BUFFER_TIMESTAMP (buffer);
+ timestamp = GST_BUFFER_PTS (buffer);
duration = GST_BUFFER_DURATION (buffer);
/* FIXME, only one SPEEX frame per RTP packet for now */
- payload_len = size;
+ outbuf = gst_rtp_base_payload_allocate_output_buffer (basepayload, 0, 0, 0);
- outbuf = gst_rtp_buffer_new_allocate (payload_len, 0, 0);
/* FIXME, assert for now */
- g_assert (payload_len <= GST_BASE_RTP_PAYLOAD_MTU (rtpspeexpay));
+ g_assert (gst_buffer_get_size (buffer) <=
+ GST_RTP_BASE_PAYLOAD_MTU (rtpspeexpay));
/* copy timestamp and duration */
- GST_BUFFER_TIMESTAMP (outbuf) = timestamp;
+ GST_BUFFER_PTS (outbuf) = timestamp;
GST_BUFFER_DURATION (outbuf) = duration;
- gst_rtp_buffer_map (outbuf, GST_MAP_WRITE, &rtp);
- /* get payload */
- payload = gst_rtp_buffer_get_payload (&rtp);
-
- /* copy data in payload */
- memcpy (&payload[0], data, size);
+ gst_rtp_copy_audio_meta (basepayload, outbuf, buffer);
+ outbuf = gst_buffer_append (outbuf, buffer);
+ buffer = NULL;
- gst_rtp_buffer_unmap (&rtp);
-
- ret = gst_basertppayload_push (basepayload, outbuf);
+ ret = gst_rtp_base_payload_push (basepayload, outbuf);
done:
- gst_buffer_unmap (buffer, data, -1);
- gst_buffer_unref (buffer);
+ if (buffer)
+ gst_buffer_unref (buffer);
rtpspeexpay->packet++;
{
GST_ELEMENT_ERROR (rtpspeexpay, STREAM, DECODE, (NULL),
("Error parsing first identification packet."));
- gst_buffer_unmap (buffer, data, -1);
gst_buffer_unref (buffer);
return GST_FLOW_ERROR;
}