History

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

DTX, discontinuous transmission, allows emitting frames with comfort noise when no voice is detected in the input audio.

Martin Storsjö committed 15 years ago

Commit 651b2761 parent 3dd82af2 files · +26 −2Browse files

Unified · Split

2 files
  1. libavcodec/libopencore-amr.c +14 −1
  2. libavcodec/libvo-amrwbenc.c +12 −1
libavcodec/libopencore-amr.c+14−1
@@ -21,6 +21,7 @@ · 20 unmodified lines
2121
2222 #include "avcodec.h"
2323 #include "libavutil/avstring.h"
24+#include "libavutil/opt.h"
2425
2526 static void amr_decode_fix_avctx(AVCodecContext *avctx)
2627 {
@@ -77,13 +78,24 @@ static int get_bitrate_mode(int bitrate, void *log_ctx) · 50 unmodified lines
7778 }
7879
7980 typedef struct AMRContext {
81+ AVClass *av_class;
8082 int frame_count;
8183 void *dec_state;
8284 void *enc_state;
8385 int enc_bitrate;
8486 int enc_mode;
87+ int enc_dtx;
8588 } AMRContext;
8689
90+static const AVOption options[] = {
91+ { "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 },
92+ { NULL }
93+};
94+
95+static const AVClass class = {
96+ "libopencore_amrnb", av_default_item_name, options, LIBAVUTIL_VERSION_INT
97+};
98+
8799 static av_cold int amr_nb_decode_init(AVCodecContext *avctx)
88100 {
89101 AMRContext *s = avctx->priv_data;
@@ -176,7 +188,7 @@ static av_cold int amr_nb_encode_init(AVCodecContext *avctx) · 86 unmodified lines
176188 avctx->frame_size = 160;
177189 avctx->coded_frame = avcodec_alloc_frame();
178190
179− s->enc_state = Encoder_Interface_init(0);
191+ s->enc_state = Encoder_Interface_init(s->enc_dtx);
180192 if (!s->enc_state) {
181193 av_log(avctx, AV_LOG_ERROR, "Encoder_Interface_init error\n");
182194 return -1;
@@ -228,6 +240,7 @@ AVCodec ff_libopencore_amrnb_encoder = { · 45 unmodified lines
228240 NULL,
229241 .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE},
230242 .long_name = NULL_IF_CONFIG_SMALL("OpenCORE Adaptive Multi-Rate (AMR) Narrow-Band"),
243+ .priv_class = &class,
231244 };
232245
233246 #endif
libavcodec/libvo-amrwbenc.c+12−1
@@ -23,14 +23,25 @@ · 22 unmodified lines
2323
2424 #include "avcodec.h"
2525 #include "libavutil/avstring.h"
26+#include "libavutil/opt.h"
2627
2728 typedef struct AMRWBContext {
29+ AVClass *av_class;
2830 void *state;
2931 int mode;
3032 int last_bitrate;
3133 int allow_dtx;
3234 } AMRWBContext;
3335
36+static const AVOption options[] = {
37+ { "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 },
38+ { NULL }
39+};
40+
41+static const AVClass class = {
42+ "libvo_amrwbenc", av_default_item_name, options, LIBAVUTIL_VERSION_INT
43+};
44+
3445 static int get_wb_bitrate_mode(int bitrate, void *log_ctx)
3546 {
3647 /* make the correspondance between bitrate and mode */
@@ -78,7 +89,6 @@ static av_cold int amr_wb_encode_init(AVCodecContext *avctx) · 41 unmodified lines
7889 avctx->coded_frame = avcodec_alloc_frame();
7990
8091 s->state = E_IF_init();
81− s->allow_dtx = 0;
8292
8393 return 0;
8494 }
@@ -119,5 +129,6 @@ AVCodec ff_libvo_amrwbenc_encoder = { · 34 unmodified lines
119129 .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE},
120130 .long_name = NULL_IF_CONFIG_SMALL("Android VisualOn Adaptive Multi-Rate "
121131 "(AMR) Wide-Band"),
132+ .priv_class = &class,
122133 };
123134

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t