[FFmpeg-devel] [PATCH] libspeexenc: option for DTX feature

Dmitry Samonenko shreddingwork at gmail.com
Thu Oct 4 22:57:05 CEST 2012


-------------- next part --------------
>From b6261fa43c3ff27b8e0d5fd8dc03740764ee483d Mon Sep 17 00:00:00 2001
From: Dmitry Samonenko <shreddingwork at gmail.com>
Date: Fri, 5 Oct 2012 00:36:16 +0400
Subject: [PATCH 1/2] 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.
---
 libavcodec/libspeexenc.c |   13 ++++++++++++-
 1 files changed, 12 insertions(+), 1 deletions(-)

diff --git a/libavcodec/libspeexenc.c b/libavcodec/libspeexenc.c
index 7c93a32..3d91634 100644
--- a/libavcodec/libspeexenc.c
+++ b/libavcodec/libspeexenc.c
@@ -75,7 +75,7 @@
 #include "internal.h"
 #include "audio_frame_queue.h"
 
-/* TODO: Think about converting abr, vad, dtx (still to come) and such flags to a bit field */
+/* TODO: Think about converting abr, vad, dtx and such flags to a bit field */
 typedef struct {
     AVClass *class;             ///< AVClass for private options
     SpeexBits bits;             ///< libspeex bitwriter context
@@ -86,6 +86,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;
@@ -121,6 +122,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)
@@ -197,6 +199,14 @@ 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);
@@ -317,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 },
 };
 
-- 
1.7.4.4

-------------- next part --------------
>From 0dcd27aea1fcd5e22fd3dddd44787a5200176d08 Mon Sep 17 00:00:00 2001
From: Dmitry Samonenko <shreddingwork at gmail.com>
Date: Fri, 5 Oct 2012 00:42:31 +0400
Subject: [PATCH 2/2] libspeexenc: Updated commentary to reflect recent changes

---
 libavcodec/libspeexenc.c |   17 +++++++++++++++++
 1 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/libavcodec/libspeexenc.c b/libavcodec/libspeexenc.c
index 3d91634..b7b7213 100644
--- a/libavcodec/libspeexenc.c
+++ b/libavcodec/libspeexenc.c
@@ -62,6 +62,23 @@
  *     sometimes desirable to use multiple frames-per-packet to reduce the
  *     amount of container overhead.  This can be done by setting the
  *     'frames_per_packet' option to a value 1 to 8.
+ *
+ * 
+ * Optional features
+ * Speex encoder supports several optional features, which can be useful
+ * for some conditions.
+ *
+ * Voice Activity Detection
+ *     When enabled, voice activity detection detects whether the audio
+ *     being encoded is speech or silence/background noise. VAD is always
+ *     implicitly activated when encoding in VBR, so the option is only useful
+ *     in non-VBR operation. In this case, Speex detects non-speech periods and
+ *     encodes them with just enough bits to reproduce the background noise.
+ *
+ * Discontinuous Transmission (DTX)
+ *     DTX is an addition to VAD/VBR operation, that allows to stop transmitting
+ *     completely when the background noise is stationary.
+ *     In file-based operation only 5 bits are used for such frames.
  */
 
 #include <speex/speex.h>
-- 
1.7.4.4



More information about the ffmpeg-devel mailing list