mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-29 10:38:27 +00:00
sbc: Make sbc codec to write directly in application buffers and so avoiding memcpys.
This commit is contained in:
parent
6f87580cfa
commit
97fcf537cd
2 changed files with 24 additions and 19 deletions
|
@ -57,10 +57,11 @@ sbc_dec_chain (GstPad * pad, GstBuffer * buffer)
|
||||||
{
|
{
|
||||||
GstSbcDec *dec = GST_SBC_DEC (gst_pad_get_parent (pad));
|
GstSbcDec *dec = GST_SBC_DEC (gst_pad_get_parent (pad));
|
||||||
GstFlowReturn res = GST_FLOW_OK;
|
GstFlowReturn res = GST_FLOW_OK;
|
||||||
guint size, offset = 0;
|
guint size, codesize, offset = 0;
|
||||||
guint8 *data;
|
guint8 *data;
|
||||||
GstClockTime timestamp;
|
GstClockTime timestamp;
|
||||||
|
|
||||||
|
codesize = sbc_get_codesize (&dec->sbc);
|
||||||
timestamp = GST_BUFFER_TIMESTAMP (buffer);
|
timestamp = GST_BUFFER_TIMESTAMP (buffer);
|
||||||
|
|
||||||
if (dec->buffer) {
|
if (dec->buffer) {
|
||||||
|
@ -81,10 +82,6 @@ sbc_dec_chain (GstPad * pad, GstBuffer * buffer)
|
||||||
GstCaps *caps, *temp;
|
GstCaps *caps, *temp;
|
||||||
int consumed;
|
int consumed;
|
||||||
|
|
||||||
consumed = sbc_decode (&dec->sbc, data + offset, size - offset);
|
|
||||||
if (consumed <= 0)
|
|
||||||
break;
|
|
||||||
|
|
||||||
caps = gst_caps_new_simple ("audio/x-raw-int",
|
caps = gst_caps_new_simple ("audio/x-raw-int",
|
||||||
"rate", G_TYPE_INT, dec->sbc.rate,
|
"rate", G_TYPE_INT, dec->sbc.rate,
|
||||||
"channels", G_TYPE_INT, dec->sbc.channels, NULL);
|
"channels", G_TYPE_INT, dec->sbc.channels, NULL);
|
||||||
|
@ -96,14 +93,19 @@ sbc_dec_chain (GstPad * pad, GstBuffer * buffer)
|
||||||
gst_caps_unref (caps);
|
gst_caps_unref (caps);
|
||||||
|
|
||||||
res = gst_pad_alloc_buffer_and_set_caps (dec->srcpad,
|
res = gst_pad_alloc_buffer_and_set_caps (dec->srcpad,
|
||||||
GST_BUFFER_OFFSET_NONE, dec->sbc.len, temp, &output);
|
GST_BUFFER_OFFSET_NONE, codesize, temp, &output);
|
||||||
|
|
||||||
gst_caps_unref (temp);
|
gst_caps_unref (temp);
|
||||||
|
|
||||||
if (res != GST_FLOW_OK)
|
if (res != GST_FLOW_OK)
|
||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
memcpy (GST_BUFFER_DATA (output), dec->sbc.data, dec->sbc.len);
|
consumed = sbc_decode (&dec->sbc, data + offset, size - offset,
|
||||||
|
GST_BUFFER_DATA (output), codesize, NULL);
|
||||||
|
if (consumed <= 0)
|
||||||
|
break;
|
||||||
|
|
||||||
|
GST_BUFFER_TIMESTAMP (output) = GST_BUFFER_TIMESTAMP (buffer);
|
||||||
|
|
||||||
res = gst_pad_push (dec->srcpad, output);
|
res = gst_pad_push (dec->srcpad, output);
|
||||||
if (res != GST_FLOW_OK)
|
if (res != GST_FLOW_OK)
|
||||||
|
|
|
@ -136,10 +136,11 @@ sbc_enc_generate_srcpad_caps (GstSbcEnc * enc, GstCaps * caps)
|
||||||
enc->sbc.rate = rate;
|
enc->sbc.rate = rate;
|
||||||
enc->sbc.channels = channels;
|
enc->sbc.channels = channels;
|
||||||
|
|
||||||
if (enc->mode == 0)
|
if (enc->mode == CFG_MODE_AUTO)
|
||||||
enc->sbc.joint = CFG_MODE_JOINT_STEREO;
|
enc->mode = CFG_MODE_JOINT_STEREO;
|
||||||
else
|
|
||||||
enc->sbc.joint = enc->mode;
|
if (enc->mode == CFG_MODE_MONO || enc->mode == CFG_MODE_JOINT_STEREO)
|
||||||
|
enc->sbc.joint = 1;
|
||||||
|
|
||||||
enc->sbc.blocks = enc->blocks;
|
enc->sbc.blocks = enc->blocks;
|
||||||
enc->sbc.subbands = enc->subbands;
|
enc->sbc.subbands = enc->subbands;
|
||||||
|
@ -252,8 +253,10 @@ sbc_enc_chain (GstPad * pad, GstBuffer * buffer)
|
||||||
GstSbcEnc *enc = GST_SBC_ENC (gst_pad_get_parent (pad));
|
GstSbcEnc *enc = GST_SBC_ENC (gst_pad_get_parent (pad));
|
||||||
GstAdapter *adapter = enc->adapter;
|
GstAdapter *adapter = enc->adapter;
|
||||||
GstFlowReturn res = GST_FLOW_OK;
|
GstFlowReturn res = GST_FLOW_OK;
|
||||||
gint codesize = enc->sbc.subbands * enc->sbc.blocks * enc->sbc.channels * 2;
|
gint codesize, frame_len;
|
||||||
|
|
||||||
|
codesize = sbc_get_codesize (&enc->sbc);
|
||||||
|
frame_len = sbc_get_frame_length (&enc->sbc);
|
||||||
gst_adapter_push (adapter, buffer);
|
gst_adapter_push (adapter, buffer);
|
||||||
|
|
||||||
while (gst_adapter_available (adapter) >= codesize && res == GST_FLOW_OK) {
|
while (gst_adapter_available (adapter) >= codesize && res == GST_FLOW_OK) {
|
||||||
|
@ -262,19 +265,20 @@ sbc_enc_chain (GstPad * pad, GstBuffer * buffer)
|
||||||
const guint8 *data;
|
const guint8 *data;
|
||||||
int consumed;
|
int consumed;
|
||||||
|
|
||||||
|
caps = GST_PAD_CAPS (enc->srcpad);
|
||||||
|
|
||||||
|
res = gst_pad_alloc_buffer_and_set_caps (enc->srcpad,
|
||||||
|
GST_BUFFER_OFFSET_NONE, frame_len, caps, &output);
|
||||||
|
|
||||||
data = gst_adapter_peek (adapter, codesize);
|
data = gst_adapter_peek (adapter, codesize);
|
||||||
consumed = sbc_encode (&enc->sbc, (gpointer) data, codesize);
|
consumed = sbc_encode (&enc->sbc, (gpointer) data, codesize,
|
||||||
|
GST_BUFFER_DATA (output), frame_len, NULL);
|
||||||
if (consumed <= 0) {
|
if (consumed <= 0) {
|
||||||
GST_ERROR ("comsumed < 0, codesize: %d", codesize);
|
GST_ERROR ("comsumed < 0, codesize: %d", codesize);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
gst_adapter_flush (adapter, consumed);
|
gst_adapter_flush (adapter, consumed);
|
||||||
|
|
||||||
caps = GST_PAD_CAPS (enc->srcpad);
|
|
||||||
|
|
||||||
res = gst_pad_alloc_buffer_and_set_caps (enc->srcpad,
|
|
||||||
GST_BUFFER_OFFSET_NONE, enc->sbc.len, caps, &output);
|
|
||||||
|
|
||||||
if (res != GST_FLOW_OK)
|
if (res != GST_FLOW_OK)
|
||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
|
@ -285,7 +289,6 @@ sbc_enc_chain (GstPad * pad, GstBuffer * buffer)
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy (GST_BUFFER_DATA (output), enc->sbc.data, enc->sbc.len);
|
|
||||||
GST_BUFFER_TIMESTAMP (output) = GST_BUFFER_TIMESTAMP (buffer);
|
GST_BUFFER_TIMESTAMP (output) = GST_BUFFER_TIMESTAMP (buffer);
|
||||||
|
|
||||||
res = gst_pad_push (enc->srcpad, output);
|
res = gst_pad_push (enc->srcpad, output);
|
||||||
|
|
Loading…
Reference in a new issue