gst/rtp/: Fix speex (de)payloader. Fixes #358040.
Original commit message from CVS: * gst/rtp/gstrtpspeexdepay.c: (gst_rtp_speex_depay_class_init), (gst_rtp_speex_depay_get_mode), (gst_rtp_speex_depay_setcaps), (gst_rtp_speex_depay_process): * gst/rtp/gstrtpspeexpay.c: (gst_rtp_speex_pay_base_init), (gst_rtp_speex_pay_class_init), (gst_rtp_speex_pay_setcaps), (gst_rtp_speex_pay_parse_ident), (gst_rtp_speex_pay_handle_buffer), (gst_rtp_speex_pay_change_state): * gst/rtp/gstrtpspeexpay.h: Fix speex (de)payloader. Fixes #358040.
This commit is contained in:
parent
e7495dcfbb
commit
d3948d2323
12
ChangeLog
12
ChangeLog
@ -1,3 +1,15 @@
|
|||||||
|
2007-03-05 Wim Taymans <wim@fluendo.com>
|
||||||
|
|
||||||
|
* gst/rtp/gstrtpspeexdepay.c: (gst_rtp_speex_depay_class_init),
|
||||||
|
(gst_rtp_speex_depay_get_mode), (gst_rtp_speex_depay_setcaps),
|
||||||
|
(gst_rtp_speex_depay_process):
|
||||||
|
* gst/rtp/gstrtpspeexpay.c: (gst_rtp_speex_pay_base_init),
|
||||||
|
(gst_rtp_speex_pay_class_init), (gst_rtp_speex_pay_setcaps),
|
||||||
|
(gst_rtp_speex_pay_parse_ident), (gst_rtp_speex_pay_handle_buffer),
|
||||||
|
(gst_rtp_speex_pay_change_state):
|
||||||
|
* gst/rtp/gstrtpspeexpay.h:
|
||||||
|
Fix speex (de)payloader. Fixes #358040.
|
||||||
|
|
||||||
2007-03-05 Jan Schmidt <thaytan@mad.scientist.com>
|
2007-03-05 Jan Schmidt <thaytan@mad.scientist.com>
|
||||||
|
|
||||||
* ext/gconf/gstswitchsink.c: (gst_switch_sink_reset),
|
* ext/gconf/gstswitchsink.c: (gst_switch_sink_reset),
|
||||||
|
@ -94,8 +94,6 @@ gst_rtp_speex_depay_class_init (GstRtpSPEEXDepayClass * klass)
|
|||||||
gstelement_class = (GstElementClass *) klass;
|
gstelement_class = (GstElementClass *) klass;
|
||||||
gstbasertpdepayload_class = (GstBaseRTPDepayloadClass *) klass;
|
gstbasertpdepayload_class = (GstBaseRTPDepayloadClass *) klass;
|
||||||
|
|
||||||
parent_class = g_type_class_peek_parent (klass);
|
|
||||||
|
|
||||||
gstbasertpdepayload_class->process = gst_rtp_speex_depay_process;
|
gstbasertpdepayload_class->process = gst_rtp_speex_depay_process;
|
||||||
gstbasertpdepayload_class->set_caps = gst_rtp_speex_depay_setcaps;
|
gstbasertpdepayload_class->set_caps = gst_rtp_speex_depay_setcaps;
|
||||||
}
|
}
|
||||||
@ -107,37 +105,104 @@ gst_rtp_speex_depay_init (GstRtpSPEEXDepay * rtpspeexdepay,
|
|||||||
GST_BASE_RTP_DEPAYLOAD (rtpspeexdepay)->clock_rate = 8000;
|
GST_BASE_RTP_DEPAYLOAD (rtpspeexdepay)->clock_rate = 8000;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gint
|
||||||
|
gst_rtp_speex_depay_get_mode (gint rate)
|
||||||
|
{
|
||||||
|
if (rate > 25000)
|
||||||
|
return 2;
|
||||||
|
else if (rate > 12500)
|
||||||
|
return 1;
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* len 4 bytes LE,
|
||||||
|
* vendor string (len bytes),
|
||||||
|
* user_len 4 (0) bytes LE
|
||||||
|
*/
|
||||||
|
static const gchar gst_rtp_speex_comment[] =
|
||||||
|
"\045\0\0\0Depayloaded with GStreamer speexdepay\0\0\0\0";
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
gst_rtp_speex_depay_setcaps (GstBaseRTPDepayload * depayload, GstCaps * caps)
|
gst_rtp_speex_depay_setcaps (GstBaseRTPDepayload * depayload, GstCaps * caps)
|
||||||
{
|
{
|
||||||
GstCaps *srccaps;
|
GstStructure *structure;
|
||||||
gboolean ret;
|
GstRtpSPEEXDepay *rtpspeexdepay;
|
||||||
|
gint clock_rate, nb_channels;
|
||||||
|
GstBuffer *buf;
|
||||||
|
guint8 *data;
|
||||||
|
const gchar *params;
|
||||||
|
|
||||||
srccaps =
|
rtpspeexdepay = GST_RTP_SPEEX_DEPAY (depayload);
|
||||||
gst_static_pad_template_get_caps (&gst_rtp_speex_depay_src_template);
|
|
||||||
ret = gst_pad_set_caps (GST_BASE_RTP_DEPAYLOAD_SRCPAD (depayload), srccaps);
|
|
||||||
|
|
||||||
gst_caps_unref (srccaps);
|
structure = gst_caps_get_structure (caps, 0);
|
||||||
return ret;
|
|
||||||
|
gst_structure_get_int (structure, "clock-rate", &clock_rate);
|
||||||
|
depayload->clock_rate = clock_rate;
|
||||||
|
|
||||||
|
if (!(params = gst_structure_get_string (structure, "encoding-params")))
|
||||||
|
nb_channels = 1;
|
||||||
|
else {
|
||||||
|
nb_channels = atoi (params);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* construct minimal header and comment packet for the decoder */
|
||||||
|
buf = gst_buffer_new_and_alloc (80);
|
||||||
|
data = GST_BUFFER_DATA (buf);
|
||||||
|
memcpy (data, "Speex ", 8);
|
||||||
|
data += 8;
|
||||||
|
memcpy (data, "1.1.12", 7);
|
||||||
|
data += 20;
|
||||||
|
GST_WRITE_UINT32_LE (data, 1); /* version */
|
||||||
|
data += 4;
|
||||||
|
GST_WRITE_UINT32_LE (data, 80); /* header_size */
|
||||||
|
data += 4;
|
||||||
|
GST_WRITE_UINT32_LE (data, clock_rate); /* rate */
|
||||||
|
data += 4;
|
||||||
|
GST_WRITE_UINT32_LE (data, gst_rtp_speex_depay_get_mode (clock_rate)); /* mode */
|
||||||
|
data += 4;
|
||||||
|
GST_WRITE_UINT32_LE (data, 4); /* mode_bitstream_version */
|
||||||
|
data += 4;
|
||||||
|
GST_WRITE_UINT32_LE (data, nb_channels); /* nb_channels */
|
||||||
|
data += 4;
|
||||||
|
GST_WRITE_UINT32_LE (data, -1); /* bitrate */
|
||||||
|
data += 4;
|
||||||
|
GST_WRITE_UINT32_LE (data, 0xa0); /* frame_size */
|
||||||
|
data += 4;
|
||||||
|
GST_WRITE_UINT32_LE (data, 0); /* VBR */
|
||||||
|
data += 4;
|
||||||
|
GST_WRITE_UINT32_LE (data, 1); /* frames_per_packet */
|
||||||
|
data += 4;
|
||||||
|
GST_WRITE_UINT32_LE (data, 0); /* extra_headers */
|
||||||
|
data += 4;
|
||||||
|
GST_WRITE_UINT32_LE (data, 0); /* reserved1 */
|
||||||
|
data += 4;
|
||||||
|
GST_WRITE_UINT32_LE (data, 0); /* reserved2 */
|
||||||
|
|
||||||
|
gst_base_rtp_depayload_push (GST_BASE_RTP_DEPAYLOAD (rtpspeexdepay), buf);
|
||||||
|
|
||||||
|
buf = gst_buffer_new_and_alloc (sizeof (gst_rtp_speex_comment));
|
||||||
|
memcpy (GST_BUFFER_DATA (buf), gst_rtp_speex_comment,
|
||||||
|
sizeof (gst_rtp_speex_comment));
|
||||||
|
|
||||||
|
gst_base_rtp_depayload_push (GST_BASE_RTP_DEPAYLOAD (rtpspeexdepay), buf);
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static GstBuffer *
|
static GstBuffer *
|
||||||
gst_rtp_speex_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf)
|
gst_rtp_speex_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf)
|
||||||
{
|
{
|
||||||
GstBuffer *outbuf = NULL;
|
GstBuffer *outbuf = NULL;
|
||||||
gint payload_len;
|
|
||||||
guint8 *payload;
|
|
||||||
|
|
||||||
GST_DEBUG ("process : got %d bytes, mark %d ts %u seqn %d",
|
GST_DEBUG ("process : got %d bytes, mark %d ts %u seqn %d",
|
||||||
GST_BUFFER_SIZE (buf),
|
GST_BUFFER_SIZE (buf),
|
||||||
gst_rtp_buffer_get_marker (buf),
|
gst_rtp_buffer_get_marker (buf),
|
||||||
gst_rtp_buffer_get_timestamp (buf), gst_rtp_buffer_get_seq (buf));
|
gst_rtp_buffer_get_timestamp (buf), gst_rtp_buffer_get_seq (buf));
|
||||||
|
|
||||||
payload_len = gst_rtp_buffer_get_payload_len (buf);
|
/* nothing special to be done */
|
||||||
payload = gst_rtp_buffer_get_payload (buf);
|
outbuf = gst_rtp_buffer_get_payload_buffer (buf);
|
||||||
|
|
||||||
outbuf = gst_buffer_new_and_alloc (payload_len);
|
|
||||||
memcpy (GST_BUFFER_DATA (outbuf), payload, payload_len);
|
|
||||||
return outbuf;
|
return outbuf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,6 +27,9 @@
|
|||||||
|
|
||||||
#include "gstrtpspeexpay.h"
|
#include "gstrtpspeexpay.h"
|
||||||
|
|
||||||
|
GST_DEBUG_CATEGORY_STATIC (rtpspeexpay_debug);
|
||||||
|
#define GST_CAT_DEFAULT (rtpspeexpay_debug)
|
||||||
|
|
||||||
/* elementfactory information */
|
/* elementfactory information */
|
||||||
static const GstElementDetails gst_rtp_speex_pay_details =
|
static const GstElementDetails gst_rtp_speex_pay_details =
|
||||||
GST_ELEMENT_DETAILS ("RTP packet payloader",
|
GST_ELEMENT_DETAILS ("RTP packet payloader",
|
||||||
@ -48,11 +51,14 @@ GST_STATIC_PAD_TEMPLATE ("src",
|
|||||||
GST_STATIC_CAPS ("application/x-rtp, "
|
GST_STATIC_CAPS ("application/x-rtp, "
|
||||||
"media = (string) \"audio\", "
|
"media = (string) \"audio\", "
|
||||||
"payload = (int) " GST_RTP_PAYLOAD_DYNAMIC_STRING ", "
|
"payload = (int) " GST_RTP_PAYLOAD_DYNAMIC_STRING ", "
|
||||||
"clock-rate = (int) 8000, "
|
"clock-rate = (int) [ 6000, 48000 ], "
|
||||||
"encoding-name = (string) \"SPEEX\", "
|
"encoding-name = (string) \"SPEEX\", "
|
||||||
"encoding-params = (string) \"1\"")
|
"encoding-params = (string) \"1\"")
|
||||||
);
|
);
|
||||||
|
|
||||||
|
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 (GstBaseRTPPayload * payload,
|
||||||
GstCaps * caps);
|
GstCaps * caps);
|
||||||
static GstFlowReturn gst_rtp_speex_pay_handle_buffer (GstBaseRTPPayload *
|
static GstFlowReturn gst_rtp_speex_pay_handle_buffer (GstBaseRTPPayload *
|
||||||
@ -71,6 +77,9 @@ gst_rtp_speex_pay_base_init (gpointer klass)
|
|||||||
gst_element_class_add_pad_template (element_class,
|
gst_element_class_add_pad_template (element_class,
|
||||||
gst_static_pad_template_get (&gst_rtp_speex_pay_src_template));
|
gst_static_pad_template_get (&gst_rtp_speex_pay_src_template));
|
||||||
gst_element_class_set_details (element_class, &gst_rtp_speex_pay_details);
|
gst_element_class_set_details (element_class, &gst_rtp_speex_pay_details);
|
||||||
|
|
||||||
|
GST_DEBUG_CATEGORY_INIT (rtpspeexpay_debug, "rtpspeexpay", 0,
|
||||||
|
"Speex RTP Payloader");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -84,7 +93,7 @@ gst_rtp_speex_pay_class_init (GstRtpSPEEXPayClass * klass)
|
|||||||
gstelement_class = (GstElementClass *) klass;
|
gstelement_class = (GstElementClass *) klass;
|
||||||
gstbasertppayload_class = (GstBaseRTPPayloadClass *) klass;
|
gstbasertppayload_class = (GstBaseRTPPayloadClass *) klass;
|
||||||
|
|
||||||
parent_class = g_type_class_peek_parent (klass);
|
gstelement_class->change_state = gst_rtp_speex_pay_change_state;
|
||||||
|
|
||||||
gstbasertppayload_class->set_caps = gst_rtp_speex_pay_setcaps;
|
gstbasertppayload_class->set_caps = gst_rtp_speex_pay_setcaps;
|
||||||
gstbasertppayload_class->handle_buffer = gst_rtp_speex_pay_handle_buffer;
|
gstbasertppayload_class->handle_buffer = gst_rtp_speex_pay_handle_buffer;
|
||||||
@ -101,10 +110,95 @@ gst_rtp_speex_pay_init (GstRtpSPEEXPay * rtpspeexpay,
|
|||||||
static gboolean
|
static gboolean
|
||||||
gst_rtp_speex_pay_setcaps (GstBaseRTPPayload * payload, GstCaps * caps)
|
gst_rtp_speex_pay_setcaps (GstBaseRTPPayload * payload, GstCaps * caps)
|
||||||
{
|
{
|
||||||
gst_basertppayload_set_options (payload, "audio", FALSE, "speex", 8000);
|
/* don't configure yet, we wait for the ident packet */
|
||||||
gst_basertppayload_set_outcaps (payload, NULL);
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
gst_rtp_speex_pay_parse_ident (GstRtpSPEEXPay * rtpspeexpay,
|
||||||
|
const guint8 * data, guint size)
|
||||||
|
{
|
||||||
|
guint32 version, header_size, rate, mode, nb_channels;
|
||||||
|
GstBaseRTPPayload *payload;
|
||||||
|
gchar *cstr;
|
||||||
|
|
||||||
|
/* we need the header string (8), the version string (20), the version
|
||||||
|
* and the header length. */
|
||||||
|
if (size < 36)
|
||||||
|
goto too_small;
|
||||||
|
|
||||||
|
if (!g_str_has_prefix ((const gchar *) data, "Speex "))
|
||||||
|
goto wrong_header;
|
||||||
|
|
||||||
|
/* skip header and version string */
|
||||||
|
data += 28;
|
||||||
|
|
||||||
|
version = GST_READ_UINT32_LE (data);
|
||||||
|
if (version != 1)
|
||||||
|
goto wrong_version;
|
||||||
|
|
||||||
|
data += 4;
|
||||||
|
/* ensure sizes */
|
||||||
|
header_size = GST_READ_UINT32_LE (data);
|
||||||
|
if (header_size < 80)
|
||||||
|
goto header_too_small;
|
||||||
|
|
||||||
|
if (size < header_size)
|
||||||
|
goto payload_too_small;
|
||||||
|
|
||||||
|
data += 4;
|
||||||
|
rate = GST_READ_UINT32_LE (data);
|
||||||
|
data += 4;
|
||||||
|
mode = GST_READ_UINT32_LE (data);
|
||||||
|
data += 8;
|
||||||
|
nb_channels = GST_READ_UINT32_LE (data);
|
||||||
|
|
||||||
|
GST_DEBUG_OBJECT (rtpspeexpay, "rate %d, mode %d, nb_channels %d",
|
||||||
|
rate, mode, nb_channels);
|
||||||
|
|
||||||
|
payload = GST_BASE_RTP_PAYLOAD (rtpspeexpay);
|
||||||
|
|
||||||
|
gst_basertppayload_set_options (payload, "audio", FALSE, "SPEEX", rate);
|
||||||
|
cstr = g_strdup_printf ("%d", nb_channels);
|
||||||
|
gst_basertppayload_set_outcaps (payload, "encoding-params",
|
||||||
|
G_TYPE_STRING, cstr, NULL);
|
||||||
|
g_free (cstr);
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
|
/* ERRORS */
|
||||||
|
too_small:
|
||||||
|
{
|
||||||
|
GST_DEBUG_OBJECT (rtpspeexpay,
|
||||||
|
"ident packet too small, need at least 32 bytes");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
wrong_header:
|
||||||
|
{
|
||||||
|
GST_DEBUG_OBJECT (rtpspeexpay,
|
||||||
|
"ident packet does not start with \"Speex \"");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
wrong_version:
|
||||||
|
{
|
||||||
|
GST_DEBUG_OBJECT (rtpspeexpay, "can only handle version 1, have version %d",
|
||||||
|
version);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
header_too_small:
|
||||||
|
{
|
||||||
|
GST_DEBUG_OBJECT (rtpspeexpay,
|
||||||
|
"header size too small, need at least 80 bytes, " "got only %d",
|
||||||
|
header_size);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
payload_too_small:
|
||||||
|
{
|
||||||
|
GST_DEBUG_OBJECT (rtpspeexpay,
|
||||||
|
"payload too small, need at least %d bytes, got only %d", header_size,
|
||||||
|
size);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static GstFlowReturn
|
static GstFlowReturn
|
||||||
@ -121,6 +215,26 @@ gst_rtp_speex_pay_handle_buffer (GstBaseRTPPayload * basepayload,
|
|||||||
rtpspeexpay = GST_RTP_SPEEX_PAY (basepayload);
|
rtpspeexpay = GST_RTP_SPEEX_PAY (basepayload);
|
||||||
|
|
||||||
size = GST_BUFFER_SIZE (buffer);
|
size = GST_BUFFER_SIZE (buffer);
|
||||||
|
data = GST_BUFFER_DATA (buffer);
|
||||||
|
|
||||||
|
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))
|
||||||
|
goto parse_error;
|
||||||
|
|
||||||
|
ret = GST_FLOW_OK;
|
||||||
|
goto done;
|
||||||
|
case 1:
|
||||||
|
/* comment packet, we ignore it */
|
||||||
|
ret = GST_FLOW_OK;
|
||||||
|
goto done;
|
||||||
|
default:
|
||||||
|
/* other packets go in the payload */
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
timestamp = GST_BUFFER_TIMESTAMP (buffer);
|
timestamp = GST_BUFFER_TIMESTAMP (buffer);
|
||||||
|
|
||||||
/* FIXME, only one SPEEX frame per RTP packet for now */
|
/* FIXME, only one SPEEX frame per RTP packet for now */
|
||||||
@ -135,8 +249,6 @@ gst_rtp_speex_pay_handle_buffer (GstBaseRTPPayload * basepayload,
|
|||||||
/* get payload */
|
/* get payload */
|
||||||
payload = gst_rtp_buffer_get_payload (outbuf);
|
payload = gst_rtp_buffer_get_payload (outbuf);
|
||||||
|
|
||||||
data = GST_BUFFER_DATA (buffer);
|
|
||||||
|
|
||||||
/* copy data in payload */
|
/* copy data in payload */
|
||||||
memcpy (&payload[0], data, size);
|
memcpy (&payload[0], data, size);
|
||||||
|
|
||||||
@ -144,6 +256,46 @@ gst_rtp_speex_pay_handle_buffer (GstBaseRTPPayload * basepayload,
|
|||||||
|
|
||||||
ret = gst_basertppayload_push (basepayload, outbuf);
|
ret = gst_basertppayload_push (basepayload, outbuf);
|
||||||
|
|
||||||
|
done:
|
||||||
|
rtpspeexpay->packet++;
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
/* ERRORS */
|
||||||
|
parse_error:
|
||||||
|
{
|
||||||
|
GST_ELEMENT_ERROR (rtpspeexpay, STREAM, DECODE, (NULL),
|
||||||
|
("Error parsing first identification packet."));
|
||||||
|
return GST_FLOW_ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static GstStateChangeReturn
|
||||||
|
gst_rtp_speex_pay_change_state (GstElement * element, GstStateChange transition)
|
||||||
|
{
|
||||||
|
GstRtpSPEEXPay *rtpspeexpay;
|
||||||
|
GstStateChangeReturn ret;
|
||||||
|
|
||||||
|
rtpspeexpay = GST_RTP_SPEEX_PAY (element);
|
||||||
|
|
||||||
|
switch (transition) {
|
||||||
|
case GST_STATE_CHANGE_NULL_TO_READY:
|
||||||
|
break;
|
||||||
|
case GST_STATE_CHANGE_READY_TO_PAUSED:
|
||||||
|
rtpspeexpay->packet = 0;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
|
||||||
|
|
||||||
|
switch (transition) {
|
||||||
|
case GST_STATE_CHANGE_READY_TO_NULL:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,6 +38,8 @@ typedef struct _GstRtpSPEEXPayClass GstRtpSPEEXPayClass;
|
|||||||
struct _GstRtpSPEEXPay
|
struct _GstRtpSPEEXPay
|
||||||
{
|
{
|
||||||
GstBaseRTPPayload payload;
|
GstBaseRTPPayload payload;
|
||||||
|
|
||||||
|
guint64 packet;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _GstRtpSPEEXPayClass
|
struct _GstRtpSPEEXPayClass
|
||||||
|
Loading…
x
Reference in New Issue
Block a user