Index: audio/gstsbcenc.c =================================================================== RCS file: /cvsroot/bluez/utils/audio/gstsbcenc.c,v retrieving revision 1.13 diff -u -3 -p -u -r1.13 gstsbcenc.c --- audio/gstsbcenc.c 21 Nov 2007 20:24:11 -0000 1.13 +++ audio/gstsbcenc.c 23 Nov 2007 12:58:11 -0000 @@ -345,23 +345,11 @@ gboolean gst_sbc_enc_fill_sbc_params(Gst enc->sbc.bitpool = bitpool; enc->mode = enc->sbc.joint = gst_sbc_get_mode_int(mode); enc->allocation = enc->sbc.allocation = gst_sbc_get_allocation_mode_int(allocation); - - return TRUE; -} - -static gboolean gst_sbc_enc_change_caps(GstSbcEnc *enc, GstCaps *caps) -{ - GST_INFO_OBJECT(enc, "Changing srcpad caps (renegotiation)"); - - if (!gst_pad_accept_caps(enc->srcpad, caps)) { - GST_WARNING_OBJECT(enc, "Src pad refused caps"); - return FALSE; - } - - if (!gst_sbc_enc_fill_sbc_params(enc, caps)) { - GST_ERROR_OBJECT(enc, "couldn't get sbc parameters from caps"); - return FALSE; - } + enc->codesize = sbc_get_codesize(&enc->sbc); + enc->frame_length = sbc_get_frame_length(&enc->sbc); + enc->frame_duration = sbc_get_frame_duration(&enc->sbc); + GST_DEBUG("codesize: %d, frame_length: %d, frame_duration: %d", + enc->codesize, enc->frame_length, enc->frame_duration); return TRUE; } @@ -371,45 +359,36 @@ static GstFlowReturn sbc_enc_chain(GstPa GstSbcEnc *enc = GST_SBC_ENC(gst_pad_get_parent(pad)); GstAdapter *adapter = enc->adapter; GstFlowReturn res = GST_FLOW_OK; - 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) { + while (gst_adapter_available(adapter) >= enc->codesize && + res == GST_FLOW_OK) { GstBuffer *output; GstCaps *caps; 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); + enc->frame_length, caps, + &output); + if (res != GST_FLOW_OK) + goto done; - data = gst_adapter_peek(adapter, codesize); - consumed = sbc_encode(&enc->sbc, (gpointer) data, codesize, - GST_BUFFER_DATA(output), frame_len, - NULL); + data = gst_adapter_peek(adapter, enc->codesize); + consumed = sbc_encode(&enc->sbc, (gpointer) data, + enc->codesize, + GST_BUFFER_DATA(output), + GST_BUFFER_SIZE(output), NULL); if (consumed <= 0) { - GST_ERROR ("comsumed < 0, codesize: %d", codesize); + GST_ERROR ("comsumed < 0, codesize: %d", + enc->codesize); break; } gst_adapter_flush(adapter, consumed); - if (res != GST_FLOW_OK) - goto done; - - if (!gst_caps_is_equal(caps, GST_BUFFER_CAPS(output))) - if (!gst_sbc_enc_change_caps(enc, - GST_BUFFER_CAPS(output))) { - res = GST_FLOW_ERROR; - GST_ERROR_OBJECT(enc, "couldn't renegotiate caps"); - goto done; - } - GST_BUFFER_TIMESTAMP(output) = GST_BUFFER_TIMESTAMP(buffer); res = gst_pad_push(enc->srcpad, output); Index: audio/gstsbcenc.h =================================================================== RCS file: /cvsroot/bluez/utils/audio/gstsbcenc.h,v retrieving revision 1.6 diff -u -3 -p -u -r1.6 gstsbcenc.h --- audio/gstsbcenc.h 21 Nov 2007 20:24:11 -0000 1.6 +++ audio/gstsbcenc.h 23 Nov 2007 12:58:11 -0000 @@ -55,6 +55,9 @@ struct _GstSbcEnc { gint blocks; gint allocation; gint subbands; + gint codesize; + gint frame_length; + gint frame_duration; sbc_t sbc; }; Index: sbc/sbc.c =================================================================== RCS file: /cvsroot/bluez/utils/sbc/sbc.c,v retrieving revision 1.24 diff -u -3 -p -u -r1.24 sbc.c --- sbc/sbc.c 13 Nov 2007 20:59:17 -0000 1.24 +++ sbc/sbc.c 23 Nov 2007 12:58:11 -0000 @@ -1404,6 +1404,11 @@ int sbc_get_frame_length(sbc_t *sbc) return ret; } +int sbc_get_frame_duration(sbc_t *sbc) +{ + return (1.0f * sbc->blocks * sbc->subbands / sbc->rate) * 1000000; +} + int sbc_get_codesize(sbc_t *sbc) { return sbc->subbands * sbc->blocks * sbc->channels * 2; Index: sbc/sbc.h =================================================================== RCS file: /cvsroot/bluez/utils/sbc/sbc.h,v retrieving revision 1.8 diff -u -3 -p -u -r1.8 sbc.h --- sbc/sbc.h 13 Nov 2007 20:04:12 -0000 1.8 +++ sbc/sbc.h 23 Nov 2007 12:58:11 -0000 @@ -57,6 +57,7 @@ int sbc_decode(sbc_t *sbc, void *input, int sbc_encode(sbc_t *sbc, void *input, int input_len, void *output, int output_len, int *written); int sbc_get_frame_length(sbc_t *sbc); +int sbc_get_frame_duration(sbc_t *sbc); int sbc_get_codesize(sbc_t *sbc); void sbc_finish(sbc_t *sbc);