summaryrefslogtreecommitdiff
path: root/libavcodec/libspeexenc.c
diff options
context:
space:
mode:
authorDmitry Samonenko <shreddingwork@gmail.com>2012-10-05 00:36:16 +0400
committerMartin Storsjö <martin@martin.st>2012-10-05 23:29:24 +0300
commit978d5bd2a7d803ed5ebfe29600811555db4f632b (patch)
tree8ca8dcfb51724765894b7822d5d293da4498e0c7 /libavcodec/libspeexenc.c
parent2f49e3da3320e49edb40713af503af0db5b3bba6 (diff)
downloadffmpeg-978d5bd2a7d803ed5ebfe29600811555db4f632b.tar.gz
libspeexenc: Add an option for enabling DTX
Discontinuous transmission is an addition to VAD/VBR operation, that allows to greatly reduce bitrate for silent chunks or stationary noises. Signed-off-by: Martin Storsjö <martin@martin.st>
Diffstat (limited to 'libavcodec/libspeexenc.c')
-rw-r--r--libavcodec/libspeexenc.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/libavcodec/libspeexenc.c b/libavcodec/libspeexenc.c
index 43f84dc5f4..5a5079b43c 100644
--- a/libavcodec/libspeexenc.c
+++ b/libavcodec/libspeexenc.c
@@ -85,6 +85,7 @@ typedef struct {
int cbr_quality; ///< CBR quality 0 to 10
int abr; ///< flag to enable ABR
int vad; ///< flag to enable VAD
+ int dtx; ///< flag to enable DTX
int pkt_frame_count; ///< frame count for the current packet
AudioFrameQueue afq; ///< frame queue
} LibSpeexEncContext;
@@ -120,6 +121,7 @@ static av_cold void print_enc_params(AVCodecContext *avctx,
av_log(avctx, AV_LOG_DEBUG, "packet size: %d\n",
avctx->frame_size * s->frames_per_packet);
av_log(avctx, AV_LOG_DEBUG, "voice activity detection: %d\n", s->vad);
+ av_log(avctx, AV_LOG_DEBUG, "discontinuous transmission: %d\n", s->dtx);
}
static av_cold int encode_init(AVCodecContext *avctx)
@@ -196,6 +198,13 @@ static av_cold int encode_init(AVCodecContext *avctx)
if (s->vad)
speex_encoder_ctl(s->enc_state, SPEEX_SET_VAD, &s->vad);
+ /* Activiting Discontinuous Transmission */
+ if (s->dtx) {
+ speex_encoder_ctl(s->enc_state, SPEEX_SET_DTX, &s->dtx);
+ if (!(s->abr || s->vad || s->header.vbr))
+ av_log(avctx, AV_LOG_WARNING, "DTX is not much of use without ABR, VAD or VBR\n");
+ }
+
/* set encoding complexity */
if (avctx->compression_level > FF_COMPRESSION_DEFAULT) {
complexity = av_clip(avctx->compression_level, 0, 10);
@@ -318,6 +327,7 @@ static const AVOption options[] = {
{ "cbr_quality", "Set quality value (0 to 10) for CBR", OFFSET(cbr_quality), AV_OPT_TYPE_INT, { .i64 = 8 }, 0, 10, AE },
{ "frames_per_packet", "Number of frames to encode in each packet", OFFSET(frames_per_packet), AV_OPT_TYPE_INT, { .i64 = 1 }, 1, 8, AE },
{ "vad", "Voice Activity Detection", OFFSET(vad), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, AE },
+ { "dtx", "Discontinuous Transmission", OFFSET(dtx), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, AE },
{ NULL },
};