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
21 21
22#include "avcodec.h"22#include "avcodec.h"
23#include "libavutil/avstring.h"23#include "libavutil/avstring.h"
24#include "libavutil/opt.h"
24 25
25static void amr_decode_fix_avctx(AVCodecContext *avctx)26static void amr_decode_fix_avctx(AVCodecContext *avctx)
26{27{
@@ -77,13 +78,24 @@ static int get_bitrate_mode(int bitrate, void *log_ctx) · 50 unmodified lines
77}78}
78 79
79typedef struct AMRContext {80typedef struct AMRContext {
81 AVClass *av_class;
80 int frame_count;82 int frame_count;
81 void *dec_state;83 void *dec_state;
82 void *enc_state;84 void *enc_state;
83 int enc_bitrate;85 int enc_bitrate;
84 int enc_mode;86 int enc_mode;
87 int enc_dtx;
85} AMRContext;88} AMRContext;
86 89
90static 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
95static const AVClass class = {
96 "libopencore_amrnb", av_default_item_name, options, LIBAVUTIL_VERSION_INT
97};
98
87static av_cold int amr_nb_decode_init(AVCodecContext *avctx)99static av_cold int amr_nb_decode_init(AVCodecContext *avctx)
88{100{
89 AMRContext *s = avctx->priv_data;101 AMRContext *s = avctx->priv_data;
@@ -176,7 +188,7 @@ static av_cold int amr_nb_encode_init(AVCodecContext *avctx) · 86 unmodified lines
176 avctx->frame_size = 160;188 avctx->frame_size = 160;
177 avctx->coded_frame = avcodec_alloc_frame();189 avctx->coded_frame = avcodec_alloc_frame();
178 190
179 s->enc_state = Encoder_Interface_init(0);191 s->enc_state = Encoder_Interface_init(s->enc_dtx);
180 if (!s->enc_state) {192 if (!s->enc_state) {
181 av_log(avctx, AV_LOG_ERROR, "Encoder_Interface_init error\n");193 av_log(avctx, AV_LOG_ERROR, "Encoder_Interface_init error\n");
182 return -1;194 return -1;
@@ -228,6 +240,7 @@ AVCodec ff_libopencore_amrnb_encoder = { · 45 unmodified lines
228 NULL,240 NULL,
229 .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE},241 .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE},
230 .long_name = NULL_IF_CONFIG_SMALL("OpenCORE Adaptive Multi-Rate (AMR) Narrow-Band"),242 .long_name = NULL_IF_CONFIG_SMALL("OpenCORE Adaptive Multi-Rate (AMR) Narrow-Band"),
243 .priv_class = &class,
231};244};
232 245
233#endif246#endif
libavcodec/libvo-amrwbenc.c+12−1
@@ -23,14 +23,25 @@ · 22 unmodified lines
23 23
24#include "avcodec.h"24#include "avcodec.h"
25#include "libavutil/avstring.h"25#include "libavutil/avstring.h"
26#include "libavutil/opt.h"
26 27
27typedef struct AMRWBContext {28typedef struct AMRWBContext {
29 AVClass *av_class;
28 void *state;30 void *state;
29 int mode;31 int mode;
30 int last_bitrate;32 int last_bitrate;
31 int allow_dtx;33 int allow_dtx;
32} AMRWBContext;34} AMRWBContext;
33 35
36static 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
41static const AVClass class = {
42 "libvo_amrwbenc", av_default_item_name, options, LIBAVUTIL_VERSION_INT
43};
44
34static int get_wb_bitrate_mode(int bitrate, void *log_ctx)45static int get_wb_bitrate_mode(int bitrate, void *log_ctx)
35{46{
36 /* make the correspondance between bitrate and mode */47 /* make the correspondance between bitrate and mode */
@@ -78,7 +89,6 @@ static av_cold int amr_wb_encode_init(AVCodecContext *avctx) · 41 unmodified lines
78 avctx->coded_frame = avcodec_alloc_frame();89 avctx->coded_frame = avcodec_alloc_frame();
79 90
80 s->state = E_IF_init();91 s->state = E_IF_init();
81 s->allow_dtx = 0;
82 92
83 return 0;93 return 0;
84}94}
@@ -119,5 +129,6 @@ AVCodec ff_libvo_amrwbenc_encoder = { · 34 unmodified lines
119 .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE},129 .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE},
120 .long_name = NULL_IF_CONFIG_SMALL("Android VisualOn Adaptive Multi-Rate "130 .long_name = NULL_IF_CONFIG_SMALL("Android VisualOn Adaptive Multi-Rate "
121 "(AMR) Wide-Band"),131 "(AMR) Wide-Band"),
132 .priv_class = &class,
122};133};
123 134

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