speexenc: Use speex intern silence detection

Speex has build in silence detection. If speex_encode_int returns 0,
than there is silence and sample do not need to be transmitted.
This work only if vbr=1 and dtx=1 optionas are enabled.
So if we get 0, we add GAP flag to the sample.
This commit is contained in:
Alexey Fisher 2011-04-08 11:11:58 +02:00 committed by Sebastian Dröge
parent 547c97f590
commit 0016ceaa2b

View file

@ -901,7 +901,7 @@ gst_speex_enc_encode (GstSpeexEnc * enc, gboolean flush)
while (gst_adapter_available (enc->adapter) >= bytes) {
gint16 *data;
gint outsize, written;
gint outsize, written, dtx_ret;
GstBuffer *outbuf;
data = (gint16 *) gst_adapter_take (enc->adapter, bytes);
@ -913,7 +913,7 @@ gst_speex_enc_encode (GstSpeexEnc * enc, gboolean flush)
if (enc->channels == 2) {
speex_encode_stereo_int (data, frame_size, &enc->bits);
}
speex_encode_int (enc->state, data, &enc->bits);
dtx_ret = speex_encode_int (enc->state, data, &enc->bits);
g_free (data);
@ -937,6 +937,9 @@ gst_speex_enc_encode (GstSpeexEnc * enc, gboolean flush)
g_assert (written == outsize);
speex_bits_reset (&enc->bits);
if (!dtx_ret)
GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_GAP);
GST_BUFFER_TIMESTAMP (outbuf) = enc->start_ts +
gst_util_uint64_scale_int ((enc->frameno_out -
enc->nframes) * frame_size - enc->lookahead, GST_SECOND, enc->rate);