DTX, discontinuous transmission, allows emitting frames with
comfort noise when no voice is detected in the input audio.
Signed-off-by: Martin Storsjö <martin@martin.st>
... | ... |
@@ -21,6 +21,7 @@ |
21 | 21 |
|
22 | 22 |
#include "avcodec.h" |
23 | 23 |
#include "libavutil/avstring.h" |
24 |
+#include "libavutil/opt.h" |
|
24 | 25 |
|
25 | 26 |
static void amr_decode_fix_avctx(AVCodecContext *avctx) |
26 | 27 |
{ |
... | ... |
@@ -77,13 +78,24 @@ static int get_bitrate_mode(int bitrate, void *log_ctx) |
77 | 77 |
} |
78 | 78 |
|
79 | 79 |
typedef struct AMRContext { |
80 |
+ AVClass *av_class; |
|
80 | 81 |
int frame_count; |
81 | 82 |
void *dec_state; |
82 | 83 |
void *enc_state; |
83 | 84 |
int enc_bitrate; |
84 | 85 |
int enc_mode; |
86 |
+ int enc_dtx; |
|
85 | 87 |
} AMRContext; |
86 | 88 |
|
89 |
+static const AVOption options[] = { |
|
90 |
+ { "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 }, |
|
91 |
+ { NULL } |
|
92 |
+}; |
|
93 |
+ |
|
94 |
+static const AVClass class = { |
|
95 |
+ "libopencore_amrnb", av_default_item_name, options, LIBAVUTIL_VERSION_INT |
|
96 |
+}; |
|
97 |
+ |
|
87 | 98 |
static av_cold int amr_nb_decode_init(AVCodecContext *avctx) |
88 | 99 |
{ |
89 | 100 |
AMRContext *s = avctx->priv_data; |
... | ... |
@@ -176,7 +188,7 @@ static av_cold int amr_nb_encode_init(AVCodecContext *avctx) |
176 | 176 |
avctx->frame_size = 160; |
177 | 177 |
avctx->coded_frame = avcodec_alloc_frame(); |
178 | 178 |
|
179 |
- s->enc_state = Encoder_Interface_init(0); |
|
179 |
+ s->enc_state = Encoder_Interface_init(s->enc_dtx); |
|
180 | 180 |
if (!s->enc_state) { |
181 | 181 |
av_log(avctx, AV_LOG_ERROR, "Encoder_Interface_init error\n"); |
182 | 182 |
return -1; |
... | ... |
@@ -228,6 +240,7 @@ AVCodec ff_libopencore_amrnb_encoder = { |
228 | 228 |
NULL, |
229 | 229 |
.sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE}, |
230 | 230 |
.long_name = NULL_IF_CONFIG_SMALL("OpenCORE Adaptive Multi-Rate (AMR) Narrow-Band"), |
231 |
+ .priv_class = &class, |
|
231 | 232 |
}; |
232 | 233 |
|
233 | 234 |
#endif |
... | ... |
@@ -23,14 +23,25 @@ |
23 | 23 |
|
24 | 24 |
#include "avcodec.h" |
25 | 25 |
#include "libavutil/avstring.h" |
26 |
+#include "libavutil/opt.h" |
|
26 | 27 |
|
27 | 28 |
typedef struct AMRWBContext { |
29 |
+ AVClass *av_class; |
|
28 | 30 |
void *state; |
29 | 31 |
int mode; |
30 | 32 |
int last_bitrate; |
31 | 33 |
int allow_dtx; |
32 | 34 |
} AMRWBContext; |
33 | 35 |
|
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 |
+ |
|
34 | 45 |
static int get_wb_bitrate_mode(int bitrate, void *log_ctx) |
35 | 46 |
{ |
36 | 47 |
/* make the correspondance between bitrate and mode */ |
... | ... |
@@ -78,7 +89,6 @@ static av_cold int amr_wb_encode_init(AVCodecContext *avctx) |
78 | 78 |
avctx->coded_frame = avcodec_alloc_frame(); |
79 | 79 |
|
80 | 80 |
s->state = E_IF_init(); |
81 |
- s->allow_dtx = 0; |
|
82 | 81 |
|
83 | 82 |
return 0; |
84 | 83 |
} |
... | ... |
@@ -119,5 +129,6 @@ AVCodec ff_libvo_amrwbenc_encoder = { |
119 | 119 |
.sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE}, |
120 | 120 |
.long_name = NULL_IF_CONFIG_SMALL("Android VisualOn Adaptive Multi-Rate " |
121 | 121 |
"(AMR) Wide-Band"), |
122 |
+ .priv_class = &class, |
|
122 | 123 |
}; |
123 | 124 |
|