libopencore-amr, libvo-amrwbenc: Allow enabling DTX via private AVOptions

Message ID 1302721752-88444-1-git-send-email-martin@martin.st
State Committed
Headers show

Commit Message

Martin Storsjö April 13, 2011, 7:09 p.m.
DTX, discontinuous transmission, allows emitting frames with
comfort noise when no voice is detected in the input audio.
---
 libavcodec/libopencore-amr.c |   15 ++++++++++++++-
 libavcodec/libvo-amrwbenc.c  |   13 ++++++++++++-
 2 files changed, 26 insertions(+), 2 deletions(-)

Comments

Ronald Bultje April 13, 2011, 7:39 p.m. | #1
Hi,

On Wed, Apr 13, 2011 at 3:09 PM, Martin Storsjö <martin@martin.st> wrote:
> DTX, discontinuous transmission, allows emitting frames with
> comfort noise when no voice is detected in the input audio.
> ---
>  libavcodec/libopencore-amr.c |   15 ++++++++++++++-
>  libavcodec/libvo-amrwbenc.c  |   13 ++++++++++++-
>  2 files changed, 26 insertions(+), 2 deletions(-)

Looks OK to me, assuming tested and it works with ffmpeg-the-application.

Ronald
Martin Storsjö April 13, 2011, 9:23 p.m. | #2
On Wed, 13 Apr 2011, Ronald S. Bultje wrote:

> On Wed, Apr 13, 2011 at 3:09 PM, Martin Storsjö <martin@martin.st> wrote:
> > DTX, discontinuous transmission, allows emitting frames with
> > comfort noise when no voice is detected in the input audio.
> > ---
> >  libavcodec/libopencore-amr.c |   15 ++++++++++++++-
> >  libavcodec/libvo-amrwbenc.c  |   13 ++++++++++++-
> >  2 files changed, 26 insertions(+), 2 deletions(-)
> 
> Looks OK to me, assuming tested and it works with ffmpeg-the-application.

Yes, tested via that, will queue after the other libopencore-amr bitrate 
patches (it's written on top of those).

// Martin

Patch

diff --git a/libavcodec/libopencore-amr.c b/libavcodec/libopencore-amr.c
index c8b3a2c..cf8bdbb 100644
--- a/libavcodec/libopencore-amr.c
+++ b/libavcodec/libopencore-amr.c
@@ -21,6 +21,7 @@ 
 
 #include "avcodec.h"
 #include "libavutil/avstring.h"
+#include "libavutil/opt.h"
 
 static void amr_decode_fix_avctx(AVCodecContext *avctx)
 {
@@ -77,13 +78,24 @@  static int get_bitrate_mode(int bitrate, void *log_ctx)
 }
 
 typedef struct AMRContext {
+    AVClass *av_class;
     int   frame_count;
     void *dec_state;
     void *enc_state;
     int   enc_bitrate;
     int   enc_mode;
+    int   enc_dtx;
 } AMRContext;
 
+static const AVOption options[] = {
+    { "dtx", "Allow DTX (generate comfort noise)", offsetof(AMRContext, enc_dtx), FF_OPT_TYPE_INT, 0, 0, 1, AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM },
+    { NULL }
+};
+
+static const AVClass class = {
+    "libopencore_amrnb", av_default_item_name, options, LIBAVUTIL_VERSION_INT
+};
+
 static av_cold int amr_nb_decode_init(AVCodecContext *avctx)
 {
     AMRContext *s  = avctx->priv_data;
@@ -176,7 +188,7 @@  static av_cold int amr_nb_encode_init(AVCodecContext *avctx)
     avctx->frame_size  = 160;
     avctx->coded_frame = avcodec_alloc_frame();
 
-    s->enc_state = Encoder_Interface_init(0);
+    s->enc_state = Encoder_Interface_init(s->enc_dtx);
     if (!s->enc_state) {
         av_log(avctx, AV_LOG_ERROR, "Encoder_Interface_init error\n");
         return -1;
@@ -228,6 +240,7 @@  AVCodec ff_libopencore_amrnb_encoder = {
     NULL,
     .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE},
     .long_name = NULL_IF_CONFIG_SMALL("OpenCORE Adaptive Multi-Rate (AMR) Narrow-Band"),
+    .priv_class = &class,
 };
 
 #endif
diff --git a/libavcodec/libvo-amrwbenc.c b/libavcodec/libvo-amrwbenc.c
index 64f19b9..ccd2c72 100644
--- a/libavcodec/libvo-amrwbenc.c
+++ b/libavcodec/libvo-amrwbenc.c
@@ -23,14 +23,25 @@ 
 
 #include "avcodec.h"
 #include "libavutil/avstring.h"
+#include "libavutil/opt.h"
 
 typedef struct AMRWBContext {
+    AVClass *av_class;
     void  *state;
     int    mode;
     int    last_bitrate;
     int    allow_dtx;
 } AMRWBContext;
 
+static const AVOption options[] = {
+    { "dtx", "Allow DTX (generate comfort noise)", offsetof(AMRWBContext, allow_dtx), FF_OPT_TYPE_INT, 0, 0, 1, AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM },
+    { NULL }
+};
+
+static const AVClass class = {
+    "libvo_amrwbenc", av_default_item_name, options, LIBAVUTIL_VERSION_INT
+};
+
 static int get_wb_bitrate_mode(int bitrate, void *log_ctx)
 {
     /* make the correspondance between bitrate and mode */
@@ -78,7 +89,6 @@  static av_cold int amr_wb_encode_init(AVCodecContext *avctx)
     avctx->coded_frame = avcodec_alloc_frame();
 
     s->state     = E_IF_init();
-    s->allow_dtx = 0;
 
     return 0;
 }
@@ -119,5 +129,6 @@  AVCodec ff_libvo_amrwbenc_encoder = {
     .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE},
     .long_name = NULL_IF_CONFIG_SMALL("VisualOn libvo-amrwbenc Adaptive Multi-Rate "
                                       "(AMR) Wide-Band"),
+    .priv_class = &class,
 };