mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-02 21:48:55 +00:00
sbc: Force LITTLE_ENDIAN instead of BYTE_ORDER for now
This commit is contained in:
parent
85874338ff
commit
e590dc56dc
3 changed files with 115 additions and 112 deletions
|
@ -49,7 +49,7 @@ GST_STATIC_PAD_TEMPLATE ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
|
|||
GST_STATIC_CAPS ("audio/x-raw-int, "
|
||||
"rate = (int) { 16000, 32000, 44100, 48000 }, "
|
||||
"channels = (int) [ 1, 2 ], "
|
||||
"endianness = (int) BYTE_ORDER, "
|
||||
"endianness = (int) LITTLE_ENDIAN, "
|
||||
"signed = (boolean) true, " "width = (int) 16, " "depth = (int) 16"));
|
||||
|
||||
static GstFlowReturn
|
||||
|
|
|
@ -72,7 +72,7 @@ GST_STATIC_PAD_TEMPLATE ("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
|
|||
GST_STATIC_CAPS ("audio/x-raw-int, "
|
||||
"rate = (int) { 16000, 32000, 44100, 48000 }, "
|
||||
"channels = (int) [ 1, 2 ], "
|
||||
"endianness = (int) BYTE_ORDER, "
|
||||
"endianness = (int) LITTLE_ENDIAN, "
|
||||
"signed = (boolean) true, " "width = (int) 16, " "depth = (int) 16"));
|
||||
|
||||
static GstStaticPadTemplate sbc_enc_src_factory =
|
||||
|
|
|
@ -29,166 +29,169 @@
|
|||
|
||||
#include "gstsbcparse.h"
|
||||
|
||||
GST_DEBUG_CATEGORY_STATIC(sbc_parse_debug);
|
||||
GST_DEBUG_CATEGORY_STATIC (sbc_parse_debug);
|
||||
#define GST_CAT_DEFAULT sbc_parse_debug
|
||||
|
||||
GST_BOILERPLATE(GstSbcParse, gst_sbc_parse, GstElement, GST_TYPE_ELEMENT);
|
||||
GST_BOILERPLATE (GstSbcParse, gst_sbc_parse, GstElement, GST_TYPE_ELEMENT);
|
||||
|
||||
static const GstElementDetails sbc_parse_details =
|
||||
GST_ELEMENT_DETAILS("Bluetooth SBC parser",
|
||||
"Codec/Parser/Audio",
|
||||
"Parse a SBC audio stream",
|
||||
"Marcel Holtmann <marcel@holtmann.org>");
|
||||
GST_ELEMENT_DETAILS ("Bluetooth SBC parser",
|
||||
"Codec/Parser/Audio",
|
||||
"Parse a SBC audio stream",
|
||||
"Marcel Holtmann <marcel@holtmann.org>");
|
||||
|
||||
static GstStaticPadTemplate sbc_parse_sink_factory =
|
||||
GST_STATIC_PAD_TEMPLATE("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
|
||||
GST_STATIC_CAPS("audio/x-sbc"));
|
||||
GST_STATIC_PAD_TEMPLATE ("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
|
||||
GST_STATIC_CAPS ("audio/x-sbc"));
|
||||
|
||||
static GstStaticPadTemplate sbc_parse_src_factory =
|
||||
GST_STATIC_PAD_TEMPLATE("src", GST_PAD_SRC, GST_PAD_ALWAYS,
|
||||
GST_STATIC_CAPS("audio/x-sbc, "
|
||||
"rate = (int) { 16000, 32000, 44100, 48000 }, "
|
||||
"channels = (int) [ 1, 2 ], "
|
||||
"mode = (string) { mono, dual, stereo, joint }, "
|
||||
"blocks = (int) { 4, 8, 12, 16 }, "
|
||||
"subbands = (int) { 4, 8 }, "
|
||||
"allocation = (string) { snr, loudness }"));
|
||||
GST_STATIC_PAD_TEMPLATE ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
|
||||
GST_STATIC_CAPS ("audio/x-sbc, "
|
||||
"rate = (int) { 16000, 32000, 44100, 48000 }, "
|
||||
"channels = (int) [ 1, 2 ], "
|
||||
"mode = (string) { mono, dual, stereo, joint }, "
|
||||
"blocks = (int) { 4, 8, 12, 16 }, "
|
||||
"subbands = (int) { 4, 8 }, "
|
||||
"allocation = (string) { snr, loudness }"));
|
||||
|
||||
static GstFlowReturn sbc_parse_chain(GstPad *pad, GstBuffer *buffer)
|
||||
static GstFlowReturn
|
||||
sbc_parse_chain (GstPad * pad, GstBuffer * buffer)
|
||||
{
|
||||
GstSbcParse *parse = GST_SBC_PARSE(gst_pad_get_parent(pad));
|
||||
GstFlowReturn res = GST_FLOW_OK;
|
||||
guint size, offset = 0;
|
||||
guint8 *data;
|
||||
GstClockTime timestamp;
|
||||
GstSbcParse *parse = GST_SBC_PARSE (gst_pad_get_parent (pad));
|
||||
GstFlowReturn res = GST_FLOW_OK;
|
||||
guint size, offset = 0;
|
||||
guint8 *data;
|
||||
GstClockTime timestamp;
|
||||
|
||||
timestamp = GST_BUFFER_TIMESTAMP(buffer);
|
||||
timestamp = GST_BUFFER_TIMESTAMP (buffer);
|
||||
|
||||
if (parse->buffer) {
|
||||
GstBuffer *temp = buffer;
|
||||
buffer = gst_buffer_span(parse->buffer, 0, buffer,
|
||||
GST_BUFFER_SIZE(parse->buffer) + GST_BUFFER_SIZE(buffer));
|
||||
gst_buffer_unref(temp);
|
||||
gst_buffer_unref(parse->buffer);
|
||||
parse->buffer = NULL;
|
||||
}
|
||||
if (parse->buffer) {
|
||||
GstBuffer *temp = buffer;
|
||||
buffer = gst_buffer_span (parse->buffer, 0, buffer,
|
||||
GST_BUFFER_SIZE (parse->buffer) + GST_BUFFER_SIZE (buffer));
|
||||
gst_buffer_unref (temp);
|
||||
gst_buffer_unref (parse->buffer);
|
||||
parse->buffer = NULL;
|
||||
}
|
||||
|
||||
data = GST_BUFFER_DATA(buffer);
|
||||
size = GST_BUFFER_SIZE(buffer);
|
||||
data = GST_BUFFER_DATA (buffer);
|
||||
size = GST_BUFFER_SIZE (buffer);
|
||||
|
||||
while (offset < size) {
|
||||
GstBuffer *output;
|
||||
GstPadTemplate *template;
|
||||
GstCaps *caps, *temp;
|
||||
int consumed;
|
||||
while (offset < size) {
|
||||
GstBuffer *output;
|
||||
GstPadTemplate *template;
|
||||
GstCaps *caps, *temp;
|
||||
int consumed;
|
||||
|
||||
consumed = sbc_parse(&parse->sbc, data + offset, size - offset);
|
||||
if (consumed <= 0)
|
||||
break;
|
||||
consumed = sbc_parse (&parse->sbc, data + offset, size - offset);
|
||||
if (consumed <= 0)
|
||||
break;
|
||||
|
||||
caps = gst_caps_new_simple("audio/x-sbc",
|
||||
"rate", G_TYPE_INT, parse->sbc.rate,
|
||||
"channels", G_TYPE_INT, parse->sbc.channels,
|
||||
NULL);
|
||||
caps = gst_caps_new_simple ("audio/x-sbc",
|
||||
"rate", G_TYPE_INT, parse->sbc.rate,
|
||||
"channels", G_TYPE_INT, parse->sbc.channels, NULL);
|
||||
|
||||
template = gst_static_pad_template_get(&sbc_parse_src_factory);
|
||||
template = gst_static_pad_template_get (&sbc_parse_src_factory);
|
||||
|
||||
temp = gst_caps_intersect(caps,
|
||||
gst_pad_template_get_caps(template));
|
||||
temp = gst_caps_intersect (caps, gst_pad_template_get_caps (template));
|
||||
|
||||
gst_caps_unref(caps);
|
||||
gst_caps_unref (caps);
|
||||
|
||||
res = gst_pad_alloc_buffer_and_set_caps(parse->srcpad,
|
||||
GST_BUFFER_OFFSET_NONE,
|
||||
consumed, temp, &output);
|
||||
res = gst_pad_alloc_buffer_and_set_caps (parse->srcpad,
|
||||
GST_BUFFER_OFFSET_NONE, consumed, temp, &output);
|
||||
|
||||
gst_caps_unref(temp);
|
||||
gst_caps_unref (temp);
|
||||
|
||||
if (res != GST_FLOW_OK)
|
||||
goto done;
|
||||
if (res != GST_FLOW_OK)
|
||||
goto done;
|
||||
|
||||
memcpy(GST_BUFFER_DATA(output), data + offset, consumed);
|
||||
memcpy (GST_BUFFER_DATA (output), data + offset, consumed);
|
||||
|
||||
res = gst_pad_push(parse->srcpad, output);
|
||||
if (res != GST_FLOW_OK)
|
||||
goto done;
|
||||
res = gst_pad_push (parse->srcpad, output);
|
||||
if (res != GST_FLOW_OK)
|
||||
goto done;
|
||||
|
||||
offset += consumed;
|
||||
}
|
||||
offset += consumed;
|
||||
}
|
||||
|
||||
if (offset < size)
|
||||
parse->buffer = gst_buffer_create_sub(buffer,
|
||||
offset, size - offset);
|
||||
if (offset < size)
|
||||
parse->buffer = gst_buffer_create_sub (buffer, offset, size - offset);
|
||||
|
||||
done:
|
||||
gst_buffer_unref(buffer);
|
||||
gst_object_unref(parse);
|
||||
gst_buffer_unref (buffer);
|
||||
gst_object_unref (parse);
|
||||
|
||||
return res;
|
||||
return res;
|
||||
}
|
||||
|
||||
static GstStateChangeReturn sbc_parse_change_state(GstElement *element,
|
||||
GstStateChange transition)
|
||||
static GstStateChangeReturn
|
||||
sbc_parse_change_state (GstElement * element, GstStateChange transition)
|
||||
{
|
||||
GstSbcParse *parse = GST_SBC_PARSE(element);
|
||||
GstSbcParse *parse = GST_SBC_PARSE (element);
|
||||
|
||||
switch (transition) {
|
||||
case GST_STATE_CHANGE_READY_TO_PAUSED:
|
||||
GST_DEBUG("Setup subband codec");
|
||||
if (parse->buffer) {
|
||||
gst_buffer_unref(parse->buffer);
|
||||
parse->buffer = NULL;
|
||||
}
|
||||
sbc_init(&parse->sbc, 0);
|
||||
break;
|
||||
switch (transition) {
|
||||
case GST_STATE_CHANGE_READY_TO_PAUSED:
|
||||
GST_DEBUG ("Setup subband codec");
|
||||
if (parse->buffer) {
|
||||
gst_buffer_unref (parse->buffer);
|
||||
parse->buffer = NULL;
|
||||
}
|
||||
sbc_init (&parse->sbc, 0);
|
||||
break;
|
||||
|
||||
case GST_STATE_CHANGE_PAUSED_TO_READY:
|
||||
GST_DEBUG("Finish subband codec");
|
||||
if (parse->buffer) {
|
||||
gst_buffer_unref(parse->buffer);
|
||||
parse->buffer = NULL;
|
||||
}
|
||||
sbc_finish(&parse->sbc);
|
||||
break;
|
||||
case GST_STATE_CHANGE_PAUSED_TO_READY:
|
||||
GST_DEBUG ("Finish subband codec");
|
||||
if (parse->buffer) {
|
||||
gst_buffer_unref (parse->buffer);
|
||||
parse->buffer = NULL;
|
||||
}
|
||||
sbc_finish (&parse->sbc);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return parent_class->change_state(element, transition);
|
||||
return parent_class->change_state (element, transition);
|
||||
}
|
||||
|
||||
static void gst_sbc_parse_base_init(gpointer g_class)
|
||||
static void
|
||||
gst_sbc_parse_base_init (gpointer g_class)
|
||||
{
|
||||
GstElementClass *element_class = GST_ELEMENT_CLASS(g_class);
|
||||
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
|
||||
|
||||
gst_element_class_add_pad_template(element_class,
|
||||
gst_static_pad_template_get(&sbc_parse_sink_factory));
|
||||
gst_element_class_add_pad_template (element_class,
|
||||
gst_static_pad_template_get (&sbc_parse_sink_factory));
|
||||
|
||||
gst_element_class_add_pad_template(element_class,
|
||||
gst_static_pad_template_get(&sbc_parse_src_factory));
|
||||
gst_element_class_add_pad_template (element_class,
|
||||
gst_static_pad_template_get (&sbc_parse_src_factory));
|
||||
|
||||
gst_element_class_set_details(element_class, &sbc_parse_details);
|
||||
gst_element_class_set_details (element_class, &sbc_parse_details);
|
||||
}
|
||||
|
||||
static void gst_sbc_parse_class_init(GstSbcParseClass *klass)
|
||||
static void
|
||||
gst_sbc_parse_class_init (GstSbcParseClass * klass)
|
||||
{
|
||||
GstElementClass *element_class = GST_ELEMENT_CLASS(klass);
|
||||
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
|
||||
|
||||
parent_class = g_type_class_peek_parent(klass);
|
||||
parent_class = g_type_class_peek_parent (klass);
|
||||
|
||||
element_class->change_state = GST_DEBUG_FUNCPTR(sbc_parse_change_state);
|
||||
element_class->change_state = GST_DEBUG_FUNCPTR (sbc_parse_change_state);
|
||||
|
||||
GST_DEBUG_CATEGORY_INIT(sbc_parse_debug, "sbcparse", 0,
|
||||
"SBC parsing element");
|
||||
GST_DEBUG_CATEGORY_INIT (sbc_parse_debug, "sbcparse", 0,
|
||||
"SBC parsing element");
|
||||
}
|
||||
|
||||
static void gst_sbc_parse_init(GstSbcParse *self, GstSbcParseClass *klass)
|
||||
static void
|
||||
gst_sbc_parse_init (GstSbcParse * self, GstSbcParseClass * klass)
|
||||
{
|
||||
self->sinkpad = gst_pad_new_from_static_template(&sbc_parse_sink_factory, "sink");
|
||||
gst_pad_set_chain_function(self->sinkpad, GST_DEBUG_FUNCPTR(sbc_parse_chain));
|
||||
gst_element_add_pad(GST_ELEMENT(self), self->sinkpad);
|
||||
self->sinkpad =
|
||||
gst_pad_new_from_static_template (&sbc_parse_sink_factory, "sink");
|
||||
gst_pad_set_chain_function (self->sinkpad,
|
||||
GST_DEBUG_FUNCPTR (sbc_parse_chain));
|
||||
gst_element_add_pad (GST_ELEMENT (self), self->sinkpad);
|
||||
|
||||
self->srcpad = gst_pad_new_from_static_template(&sbc_parse_src_factory, "src");
|
||||
gst_element_add_pad(GST_ELEMENT(self), self->srcpad);
|
||||
self->srcpad =
|
||||
gst_pad_new_from_static_template (&sbc_parse_src_factory, "src");
|
||||
gst_element_add_pad (GST_ELEMENT (self), self->srcpad);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue