History

Add AVCodecContext.lpc_type and Add AVCodecContext.lpc_passes fields. Add AVLPCType enum. Deprecate AVCodecContext.use_lpc.

Originally committed as revision 24199 to svn://svn.ffmpeg.org/ffmpeg/trunk

Justin Ruggles committed 16 years ago

Commit 23940f11 parent 31769da8 files · +130 −39Browse files

Showing the changes to libavcodec (7 of 8 files). Show all

Unified · Split

7 files
  1. libavcodec/alacenc.c +2 −1
  2. libavcodec/avcodec.h +30 −1
  3. libavcodec/flacenc.c +74 −29
  4. libavcodec/lpc.c +7 −5
  5. libavcodec/lpc.h +2 −1
  6. libavcodec/options.c +8 −0
  7. libavcodec/ra144enc.c +2 −2
libavcodec/alacenc.c+2−1
@@ -145,7 +145,8 @@ static void calc_predictor_params(AlacEncodeContext *s, int ch) · 144 unmodified lines
145145 s->avctx->frame_size,
146146 s->min_prediction_order,
147147 s->max_prediction_order,
148− ALAC_MAX_LPC_PRECISION, coefs, shift, 1,
148+ ALAC_MAX_LPC_PRECISION, coefs, shift,
149+ AV_LPC_TYPE_LEVINSON, 0,
149150 ORDER_METHOD_EST, ALAC_MAX_LPC_SHIFT, 1);
150151
151152 s->lpc[ch].lpc_order = opt_order;
libavcodec/avcodec.h+30−1
@@ -30,7 +30,7 @@ · 29 unmodified lines
3030 #include "libavutil/avutil.h"
3131
3232 #define LIBAVCODEC_VERSION_MAJOR 52
33−#define LIBAVCODEC_VERSION_MINOR 82
33+#define LIBAVCODEC_VERSION_MINOR 83
3434 #define LIBAVCODEC_VERSION_MICRO 0
3535
3636 #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
@@ -526,6 +526,18 @@ enum AVChromaLocation{ · 489 unmodified lines
526526 AVCHROMA_LOC_NB , ///< Not part of ABI
527527 };
528528
529+/**
530+ * LPC analysis type
531+ */
532+enum AVLPCType {
533+ AV_LPC_TYPE_DEFAULT = -1, ///< use the codec default LPC type
534+ AV_LPC_TYPE_NONE = 0, ///< do not use LPC prediction or use all zero coefficients
535+ AV_LPC_TYPE_FIXED = 1, ///< fixed LPC coefficients
536+ AV_LPC_TYPE_LEVINSON = 2, ///< Levinson-Durbin recursion
537+ AV_LPC_TYPE_CHOLESKY = 3, ///< Cholesky factorization
538+ AV_LPC_TYPE_NB , ///< Not part of ABI
539+};
540+
529541 typedef struct RcOverride{
530542 int start_frame;
531543 int end_frame;
@@ -2413,12 +2425,15 @@ typedef struct AVCodecContext { · 1881 unmodified lines
24132425 int compression_level;
24142426 #define FF_COMPRESSION_DEFAULT -1
24152427
2428+#if LIBAVCODEC_VERSION_MAJOR < 53
24162429 /**
24172430 * Sets whether to use LPC mode - used by FLAC encoder.
24182431 * - encoding: Set by user.
24192432 * - decoding: unused
2433+ * @deprecated Deprecated in favor of lpc_type and lpc_passes.
24202434 */
24212435 int use_lpc;
2436+#endif
24222437
24232438 /**
24242439 * LPC coefficient precision - used by FLAC encoder
@@ -2672,6 +2687,20 @@ typedef struct AVCodecContext { · 247 unmodified lines
26722687 float crf_max;
26732688
26742689 int log_level_offset;
2690+
2691+ /**
2692+ * Determines which LPC analysis algorithm to use.
2693+ * - encoding: Set by user
2694+ * - decoding: unused
2695+ */
2696+ enum AVLPCType lpc_type;
2697+
2698+ /**
2699+ * Number of passes to use for Cholesky factorization during LPC analysis
2700+ * - encoding: Set by user
2701+ * - decoding: unused
2702+ */
2703+ int lpc_passes;
26752704 } AVCodecContext;
26762705
26772706 /**
libavcodec/flacenc.c+74−29
@@ -44,7 +44,8 @@ · 43 unmodified lines
4444 typedef struct CompressionOptions {
4545 int compression_level;
4646 int block_time_ms;
47− int use_lpc;
47+ enum AVLPCType lpc_type;
48+ int lpc_passes;
4849 int lpc_coeff_precision;
4950 int min_prediction_order;
5051 int max_prediction_order;
@@ -208,7 +209,11 @@ static av_cold int flac_encode_init(AVCodecContext *avctx) · 157 unmodified lines
208209 }
209210
210211 s->options.block_time_ms = ((int[]){ 27, 27, 27,105,105,105,105,105,105,105,105,105,105})[level];
211− s->options.use_lpc = ((int[]){ 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1})[level];
212+ s->options.lpc_type = ((int[]){ AV_LPC_TYPE_FIXED, AV_LPC_TYPE_FIXED, AV_LPC_TYPE_FIXED,
213+ AV_LPC_TYPE_LEVINSON, AV_LPC_TYPE_LEVINSON, AV_LPC_TYPE_LEVINSON,
214+ AV_LPC_TYPE_LEVINSON, AV_LPC_TYPE_LEVINSON, AV_LPC_TYPE_LEVINSON,
215+ AV_LPC_TYPE_LEVINSON, AV_LPC_TYPE_LEVINSON, AV_LPC_TYPE_LEVINSON,
216+ AV_LPC_TYPE_LEVINSON})[level];
212217 s->options.min_prediction_order= ((int[]){ 2, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1})[level];
213218 s->options.max_prediction_order= ((int[]){ 3, 4, 4, 6, 8, 8, 8, 8, 12, 12, 12, 32, 32})[level];
214219 s->options.prediction_order_method = ((int[]){ ORDER_METHOD_EST, ORDER_METHOD_EST, ORDER_METHOD_EST,
@@ -220,45 +225,83 @@ static av_cold int flac_encode_init(AVCodecContext *avctx) · 5 unmodified lines
220225 s->options.max_partition_order = ((int[]){ 2, 2, 3, 3, 3, 8, 8, 8, 8, 8, 8, 8, 8})[level];
221226
222227 /* set compression option overrides from AVCodecContext */
223− if(avctx->use_lpc >= 0) {
224− s->options.use_lpc = av_clip(avctx->use_lpc, 0, 11);
225− }
226− if(s->options.use_lpc == 1)
227− av_log(avctx, AV_LOG_DEBUG, " use lpc: Levinson-Durbin recursion with Welch window\n");
228− else if(s->options.use_lpc > 1)
229− av_log(avctx, AV_LOG_DEBUG, " use lpc: Cholesky factorization\n");
230−
231− if(avctx->min_prediction_order >= 0) {
232− if(s->options.use_lpc) {
233− if(avctx->min_prediction_order < MIN_LPC_ORDER ||
234− avctx->min_prediction_order > MAX_LPC_ORDER) {
235− av_log(avctx, AV_LOG_ERROR, "invalid min prediction order: %d\n",
236− avctx->min_prediction_order);
228+#if LIBAVCODEC_VERSION_MAJOR < 53
229+ /* for compatibility with deprecated AVCodecContext.use_lpc */
230+ if (avctx->use_lpc == 0) {
231+ s->options.lpc_type = AV_LPC_TYPE_FIXED;
232+ } else if (avctx->use_lpc == 1) {
233+ s->options.lpc_type = AV_LPC_TYPE_LEVINSON;
234+ } else if (avctx->use_lpc > 1) {
235+ s->options.lpc_type = AV_LPC_TYPE_CHOLESKY;
236+ s->options.lpc_passes = avctx->use_lpc - 1;
237+ }
238+#endif
239+ if (avctx->lpc_type > AV_LPC_TYPE_DEFAULT) {
240+ if (avctx->lpc_type > AV_LPC_TYPE_CHOLESKY) {
241+ av_log(avctx, AV_LOG_ERROR, "unknown lpc type: %d\n", avctx->lpc_type);
242+ return -1;
243+ }
244+ s->options.lpc_type = avctx->lpc_type;
245+ if (s->options.lpc_type == AV_LPC_TYPE_CHOLESKY) {
246+ if (avctx->lpc_passes < 0) {
247+ // default number of passes for Cholesky
248+ s->options.lpc_passes = 2;
249+ } else if (avctx->lpc_passes == 0) {
250+ av_log(avctx, AV_LOG_ERROR, "invalid number of lpc passes: %d\n",
251+ avctx->lpc_passes);
237252 return -1;
253+ } else {
254+ s->options.lpc_passes = avctx->lpc_passes;
238255 }
239− } else {
256+ }
257+ }
258+ switch (s->options.lpc_type) {
259+ case AV_LPC_TYPE_NONE:
260+ av_log(avctx, AV_LOG_DEBUG, " lpc type: None\n");
261+ break;
262+ case AV_LPC_TYPE_FIXED:
263+ av_log(avctx, AV_LOG_DEBUG, " lpc type: Fixed pre-defined coefficients\n");
264+ break;
265+ case AV_LPC_TYPE_LEVINSON:
266+ av_log(avctx, AV_LOG_DEBUG, " lpc type: Levinson-Durbin recursion with Welch window\n");
267+ break;
268+ case AV_LPC_TYPE_CHOLESKY:
269+ av_log(avctx, AV_LOG_DEBUG, " lpc type: Cholesky factorization, %d pass%s\n",
270+ s->options.lpc_passes, s->options.lpc_passes==1?"":"es");
271+ break;
272+ }
273+
274+ if (s->options.lpc_type == AV_LPC_TYPE_NONE) {
275+ s->options.min_prediction_order = 0;
276+ } else if (avctx->min_prediction_order >= 0) {
277+ if (s->options.lpc_type == AV_LPC_TYPE_FIXED) {
240278 if(avctx->min_prediction_order > MAX_FIXED_ORDER) {
241279 av_log(avctx, AV_LOG_ERROR, "invalid min prediction order: %d\n",
242280 avctx->min_prediction_order);
243281 return -1;
244282 }
283+ } else if(avctx->min_prediction_order < MIN_LPC_ORDER ||
284+ avctx->min_prediction_order > MAX_LPC_ORDER) {
285+ av_log(avctx, AV_LOG_ERROR, "invalid min prediction order: %d\n",
286+ avctx->min_prediction_order);
287+ return -1;
245288 }
246289 s->options.min_prediction_order = avctx->min_prediction_order;
247290 }
248− if(avctx->max_prediction_order >= 0) {
249− if(s->options.use_lpc) {
250− if(avctx->max_prediction_order < MIN_LPC_ORDER ||
251− avctx->max_prediction_order > MAX_LPC_ORDER) {
252− av_log(avctx, AV_LOG_ERROR, "invalid max prediction order: %d\n",
253− avctx->max_prediction_order);
254− return -1;
255− }
256− } else {
291+ if (s->options.lpc_type == AV_LPC_TYPE_NONE) {
292+ s->options.max_prediction_order = 0;
293+ } else if (avctx->max_prediction_order >= 0) {
294+ if (s->options.lpc_type == AV_LPC_TYPE_FIXED) {
257295 if(avctx->max_prediction_order > MAX_FIXED_ORDER) {
258296 av_log(avctx, AV_LOG_ERROR, "invalid max prediction order: %d\n",
259297 avctx->max_prediction_order);
260298 return -1;
261299 }
300+ } else if (avctx->max_prediction_order < MIN_LPC_ORDER ||
301+ avctx->max_prediction_order > MAX_LPC_ORDER) {
302+ av_log(avctx, AV_LOG_ERROR, "invalid max prediction order: %d\n",
303+ avctx->max_prediction_order);
304+ return -1;
262305 }
263306 s->options.max_prediction_order = avctx->max_prediction_order;
264307 }
@@ -754,7 +797,8 @@ static int encode_residual(FlacEncodeContext *ctx, int ch) · 489 unmodified lines
754797 omethod = ctx->options.prediction_order_method;
755798
756799 /* FIXED */
757− if(!ctx->options.use_lpc || max_order == 0 || (n <= max_order)) {
800+ if (ctx->options.lpc_type == AV_LPC_TYPE_NONE ||
801+ ctx->options.lpc_type == AV_LPC_TYPE_FIXED || n <= max_order) {
758802 uint32_t bits[MAX_FIXED_ORDER+1];
759803 if(max_order > MAX_FIXED_ORDER) max_order = MAX_FIXED_ORDER;
760804 opt_order = 0;
@@ -780,8 +824,9 @@ static int encode_residual(FlacEncodeContext *ctx, int ch) · 19 unmodified lines
780824
781825 /* LPC */
782826 opt_order = ff_lpc_calc_coefs(&ctx->dsp, smp, n, min_order, max_order,
783− precision, coefs, shift, ctx->options.use_lpc,
784− omethod, MAX_LPC_SHIFT, 0);
827+ precision, coefs, shift, ctx->options.lpc_type,
828+ ctx->options.lpc_passes, omethod,
829+ MAX_LPC_SHIFT, 0);
785830
786831 if(omethod == ORDER_METHOD_2LEVEL ||
787832 omethod == ORDER_METHOD_4LEVEL ||
libavcodec/lpc.c+7−5
@@ -165,7 +165,8 @@ static int estimate_best_order(double *ref, int min_order, int max_order) · 164 unmodified lines
165165 int ff_lpc_calc_coefs(DSPContext *s,
166166 const int32_t *samples, int blocksize, int min_order,
167167 int max_order, int precision,
168− int32_t coefs[][MAX_LPC_ORDER], int *shift, int use_lpc,
168+ int32_t coefs[][MAX_LPC_ORDER], int *shift,
169+ enum AVLPCType lpc_type, int lpc_passes,
169170 int omethod, int max_shift, int zero_shift)
170171 {
171172 double autoc[MAX_LPC_ORDER+1];
@@ -174,20 +175,21 @@ int ff_lpc_calc_coefs(DSPContext *s, · 2 unmodified lines
174175 int i, j, pass;
175176 int opt_order;
176177
177− assert(max_order >= MIN_LPC_ORDER && max_order <= MAX_LPC_ORDER && use_lpc > 0);
178+ assert(max_order >= MIN_LPC_ORDER && max_order <= MAX_LPC_ORDER &&
179+ lpc_type > AV_LPC_TYPE_FIXED);
178180
179− if(use_lpc == 1){
181+ if (lpc_type == AV_LPC_TYPE_LEVINSON) {
180182 s->lpc_compute_autocorr(samples, blocksize, max_order, autoc);
181183
182184 compute_lpc_coefs(autoc, max_order, &lpc[0][0], MAX_LPC_ORDER, 0, 1);
183185
184186 for(i=0; i<max_order; i++)
185187 ref[i] = fabs(lpc[i][i]);
186− }else{
188+ } else if (lpc_type == AV_LPC_TYPE_CHOLESKY) {
187189 LLSModel m[2];
188190 double var[MAX_LPC_ORDER+1], av_uninit(weight);
189191
190− for(pass=0; pass<use_lpc-1; pass++){
192+ for(pass=0; pass<lpc_passes; pass++){
191193 av_init_lls(&m[pass&1], max_order);
192194
193195 weight=0;
libavcodec/lpc.h+2−1
@@ -42,7 +42,8 @@ · 41 unmodified lines
4242 int ff_lpc_calc_coefs(DSPContext *s,
4343 const int32_t *samples, int blocksize, int min_order,
4444 int max_order, int precision,
45− int32_t coefs[][MAX_LPC_ORDER], int *shift, int use_lpc,
45+ int32_t coefs[][MAX_LPC_ORDER], int *shift,
46+ enum AVLPCType lpc_type, int lpc_passes,
4647 int omethod, int max_shift, int zero_shift);
4748
4849 void ff_lpc_compute_autocorr(const int32_t *data, int len, int lag,
libavcodec/options.c+8−0
@@ -382,7 +382,9 @@ static const AVOption options[]={ · 381 unmodified lines
382382 {"ivlc", "intra vlc table", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_INTRA_VLC, INT_MIN, INT_MAX, V|E, "flags2"},
383383 {"b_sensitivity", "adjusts sensitivity of b_frame_strategy 1", OFFSET(b_sensitivity), FF_OPT_TYPE_INT, 40, 1, INT_MAX, V|E},
384384 {"compression_level", NULL, OFFSET(compression_level), FF_OPT_TYPE_INT, FF_COMPRESSION_DEFAULT, INT_MIN, INT_MAX, V|A|E},
385+#if LIBAVCODEC_VERSION_MAJOR < 53
385386 {"use_lpc", "sets whether to use LPC mode (FLAC)", OFFSET(use_lpc), FF_OPT_TYPE_INT, -1, INT_MIN, INT_MAX, A|E},
387+#endif
386388 {"lpc_coeff_precision", "LPC coefficient precision (FLAC)", OFFSET(lpc_coeff_precision), FF_OPT_TYPE_INT, DEFAULT, 0, INT_MAX, A|E},
387389 {"min_prediction_order", NULL, OFFSET(min_prediction_order), FF_OPT_TYPE_INT, -1, INT_MIN, INT_MAX, A|E},
388390 {"max_prediction_order", NULL, OFFSET(max_prediction_order), FF_OPT_TYPE_INT, -1, INT_MIN, INT_MAX, A|E},
@@ -417,6 +419,12 @@ static const AVOption options[]={ · 28 unmodified lines
417419 {"intra_refresh", "use periodic insertion of intra blocks instead of keyframes", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_INTRA_REFRESH, INT_MIN, INT_MAX, V|E, "flags2"},
418420 {"crf_max", "in crf mode, prevents vbv from lowering quality beyond this point", OFFSET(crf_max), FF_OPT_TYPE_FLOAT, DEFAULT, 0, 51, V|E},
419421 {"log_level_offset", "set the log level offset", OFFSET(log_level_offset), FF_OPT_TYPE_INT, 0, INT_MIN, INT_MAX },
422+{"lpc_type", "specify LPC algorithm", OFFSET(lpc_type), FF_OPT_TYPE_INT, AV_LPC_TYPE_DEFAULT, AV_LPC_TYPE_DEFAULT, AV_LPC_TYPE_NB-1, A|E},
423+{"none", NULL, 0, FF_OPT_TYPE_CONST, AV_LPC_TYPE_NONE, INT_MIN, INT_MAX, A|E, "lpc_type"},
424+{"fixed", NULL, 0, FF_OPT_TYPE_CONST, AV_LPC_TYPE_FIXED, INT_MIN, INT_MAX, A|E, "lpc_type"},
425+{"levinson", NULL, 0, FF_OPT_TYPE_CONST, AV_LPC_TYPE_LEVINSON, INT_MIN, INT_MAX, A|E, "lpc_type"},
426+{"cholesky", NULL, 0, FF_OPT_TYPE_CONST, AV_LPC_TYPE_CHOLESKY, INT_MIN, INT_MAX, A|E, "lpc_type"},
427+{"lpc_passes", "number of passes to use for Cholesky factorization during LPC analysis", OFFSET(lpc_passes), FF_OPT_TYPE_INT, -1, INT_MIN, INT_MAX, A|E},
420428 {NULL},
421429 };
422430
libavcodec/ra144enc.c+2−2
@@ -452,8 +452,8 @@ static int ra144_encode_frame(AVCodecContext *avctx, uint8_t *frame, · 451 unmodified lines
452452 32)];
453453
454454 ff_lpc_calc_coefs(&ractx->dsp, lpc_data, NBLOCKS * BLOCKSIZE, LPC_ORDER,
455− LPC_ORDER, 16, lpc_coefs, shift, 1, ORDER_METHOD_EST, 12,
456− 0);
455+ LPC_ORDER, 16, lpc_coefs, shift, AV_LPC_TYPE_LEVINSON,
456+ 0, ORDER_METHOD_EST, 12, 0);
457457 for (i = 0; i < LPC_ORDER; i++)
458458 block_coefs[NBLOCKS - 1][i] = -(lpc_coefs[LPC_ORDER - 1][i] <<
459459 (12 - shift[LPC_ORDER - 1]));

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