diff options
author | Luiz Augusto von Dentz <luiz.dentz@openbossa.org> | 2007-11-12 18:15:59 +0000 |
---|---|---|
committer | Luiz Augusto von Dentz <luiz.dentz@openbossa.org> | 2007-11-12 18:15:59 +0000 |
commit | 397d6c2b3bc7661f978c1777442d33fd86ada21e (patch) | |
tree | 7ac2b0d3768715896e286eab291dccfde333cfb8 /audio | |
parent | f89c7796c7882c65e829e5203a79606c3d1d63b0 (diff) |
Make sbc codec to write directly in application buffers and so avoiding memcpys.
Diffstat (limited to 'audio')
-rw-r--r-- | audio/gstsbcdec.c | 17 | ||||
-rw-r--r-- | audio/gstsbcenc.c | 30 | ||||
-rw-r--r-- | audio/pcm_bluetooth.c | 24 |
3 files changed, 39 insertions, 32 deletions
diff --git a/audio/gstsbcdec.c b/audio/gstsbcdec.c index 98504d4d..a60c3e69 100644 --- a/audio/gstsbcdec.c +++ b/audio/gstsbcdec.c @@ -58,10 +58,11 @@ static GstFlowReturn sbc_dec_chain(GstPad *pad, GstBuffer *buffer) { GstSbcDec *dec = GST_SBC_DEC(gst_pad_get_parent(pad)); GstFlowReturn res = GST_FLOW_OK; - guint size, offset = 0; + guint size, codesize, offset = 0; guint8 *data; GstClockTime timestamp; + codesize = sbc_get_codesize(&dec->sbc); timestamp = GST_BUFFER_TIMESTAMP(buffer); if (dec->buffer) { @@ -82,10 +83,6 @@ static GstFlowReturn sbc_dec_chain(GstPad *pad, GstBuffer *buffer) GstCaps *caps, *temp; int consumed; - consumed = sbc_decode(&dec->sbc, data + offset, size - offset); - if (consumed <= 0) - break; - caps = gst_caps_new_simple("audio/x-raw-int", "rate", G_TYPE_INT, dec->sbc.rate, "channels", G_TYPE_INT, dec->sbc.channels, @@ -100,14 +97,20 @@ static GstFlowReturn sbc_dec_chain(GstPad *pad, GstBuffer *buffer) res = gst_pad_alloc_buffer_and_set_caps(dec->srcpad, GST_BUFFER_OFFSET_NONE, - dec->sbc.len, temp, &output); + codesize, temp, &output); gst_caps_unref(temp); if (res != GST_FLOW_OK) 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); if (res != GST_FLOW_OK) diff --git a/audio/gstsbcenc.c b/audio/gstsbcenc.c index 0e9daed1..e1c480a0 100644 --- a/audio/gstsbcenc.c +++ b/audio/gstsbcenc.c @@ -134,10 +134,11 @@ static GstCaps* sbc_enc_generate_srcpad_caps(GstSbcEnc *enc, GstCaps *caps) enc->sbc.rate = rate; enc->sbc.channels = channels; - if (enc->mode == 0) - enc->sbc.joint = CFG_MODE_JOINT_STEREO; - else - enc->sbc.joint = enc->mode; + if (enc->mode == CFG_MODE_AUTO) + enc->mode = CFG_MODE_JOINT_STEREO; + + if (enc->mode == CFG_MODE_MONO || enc->mode == CFG_MODE_JOINT_STEREO) + enc->sbc.joint = 1; enc->sbc.blocks = enc->blocks; enc->sbc.subbands = enc->subbands; @@ -247,8 +248,10 @@ static GstFlowReturn sbc_enc_chain(GstPad *pad, GstBuffer *buffer) GstSbcEnc *enc = GST_SBC_ENC(gst_pad_get_parent(pad)); GstAdapter *adapter = enc->adapter; 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); while (gst_adapter_available(adapter) >= codesize && res == GST_FLOW_OK) { @@ -257,20 +260,22 @@ static GstFlowReturn sbc_enc_chain(GstPad *pad, GstBuffer *buffer) const guint8 *data; 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); - 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) { GST_ERROR ("comsumed < 0, codesize: %d", codesize); break; } 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) goto done; @@ -282,7 +287,6 @@ static GstFlowReturn sbc_enc_chain(GstPad *pad, GstBuffer *buffer) goto done; } - memcpy(GST_BUFFER_DATA(output), enc->sbc.data, enc->sbc.len); GST_BUFFER_TIMESTAMP(output) = GST_BUFFER_TIMESTAMP(buffer); res = gst_pad_push(enc->srcpad, output); diff --git a/audio/pcm_bluetooth.c b/audio/pcm_bluetooth.c index 89ce8965..04eabf24 100644 --- a/audio/pcm_bluetooth.c +++ b/audio/pcm_bluetooth.c @@ -666,7 +666,7 @@ static snd_pcm_sframes_t bluetooth_a2dp_write(snd_pcm_ioplug_t *io, struct bluetooth_a2dp *a2dp = &data->a2dp; snd_pcm_sframes_t ret = 0; snd_pcm_uframes_t frames_to_read, frames_left = size; - int frame_size, encoded; + int frame_size, encoded, written; uint8_t *buff; DBG("areas->step=%u areas->first=%u offset=%lu size=%lu", @@ -728,30 +728,30 @@ static snd_pcm_sframes_t bluetooth_a2dp_write(snd_pcm_ioplug_t *io, } /* Enough data to encode (sbc wants 1k blocks) */ - encoded = sbc_encode(&(a2dp->sbc), data->buffer, a2dp->codesize); + encoded = sbc_encode(&(a2dp->sbc), data->buffer, a2dp->codesize, + a2dp->buffer, sizeof(a2dp->buffer), + &written); if (encoded <= 0) { DBG("Encoding error %d", encoded); goto done; } data->count -= encoded; + a2dp->count += written; + a2dp->frame_count++; + a2dp->samples += encoded / frame_size; + a2dp->nsamples += encoded / frame_size; - DBG("encoded=%d a2dp.sbc.len=%d count=%d", encoded, - a2dp->sbc.len, a2dp->count); + DBG("encoded=%d written=%d count=%d", encoded, + written, a2dp->count); - /* Send previously encoded buffer */ - if (a2dp->count + a2dp->sbc.len >= data->cfg.pkt_len) { + /* No space left for another frame then send */ + if (a2dp->count + written >= data->cfg.pkt_len) { avdtp_write(data); DBG("sending packet %d, count %d, pkt_len %u", c, old_count, data->cfg.pkt_len); } - memcpy(a2dp->buffer + a2dp->count, a2dp->sbc.data, a2dp->sbc.len); - a2dp->count += a2dp->sbc.len; - a2dp->frame_count++; - a2dp->samples += encoded / frame_size; - a2dp->nsamples += encoded / frame_size; - ret += frames_to_read; frames_left -= frames_to_read; } |