Originally committed as revision 24199 to svn://svn.ffmpeg.org/ffmpeg/trunk
Showing the changes to libavcodec (7 of 8 files). Show all
Unified · Split
| @@ -145,7 +145,8 @@ static void calc_predictor_params(AlacEncodeContext *s, int ch) · 144 unmodified lines | ||
| 145 | 145 | s->avctx->frame_size, |
| 146 | 146 | s->min_prediction_order, |
| 147 | 147 | 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, | |
| 149 | 150 | ORDER_METHOD_EST, ALAC_MAX_LPC_SHIFT, 1); |
| 150 | 151 | |
| 151 | 152 | s->lpc[ch].lpc_order = opt_order; |
| @@ -30,7 +30,7 @@ · 29 unmodified lines | ||
| 30 | 30 | #include "libavutil/avutil.h" |
| 31 | 31 | |
| 32 | 32 | #define LIBAVCODEC_VERSION_MAJOR 52 |
| 33 | −#define LIBAVCODEC_VERSION_MINOR 82 | |
| 33 | +#define LIBAVCODEC_VERSION_MINOR 83 | |
| 34 | 34 | #define LIBAVCODEC_VERSION_MICRO 0 |
| 35 | 35 | |
| 36 | 36 | #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ |
| @@ -526,6 +526,18 @@ enum AVChromaLocation{ · 489 unmodified lines | ||
| 526 | 526 | AVCHROMA_LOC_NB , ///< Not part of ABI |
| 527 | 527 | }; |
| 528 | 528 | |
| 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 | + | |
| 529 | 541 | typedef struct RcOverride{ |
| 530 | 542 | int start_frame; |
| 531 | 543 | int end_frame; |
| @@ -2413,12 +2425,15 @@ typedef struct AVCodecContext { · 1881 unmodified lines | ||
| 2413 | 2425 | int compression_level; |
| 2414 | 2426 | #define FF_COMPRESSION_DEFAULT -1 |
| 2415 | 2427 | |
| 2428 | +#if LIBAVCODEC_VERSION_MAJOR < 53 | |
| 2416 | 2429 | /** |
| 2417 | 2430 | * Sets whether to use LPC mode - used by FLAC encoder. |
| 2418 | 2431 | * - encoding: Set by user. |
| 2419 | 2432 | * - decoding: unused |
| 2433 | + * @deprecated Deprecated in favor of lpc_type and lpc_passes. | |
| 2420 | 2434 | */ |
| 2421 | 2435 | int use_lpc; |
| 2436 | +#endif | |
| 2422 | 2437 | |
| 2423 | 2438 | /** |
| 2424 | 2439 | * LPC coefficient precision - used by FLAC encoder |
| @@ -2672,6 +2687,20 @@ typedef struct AVCodecContext { · 247 unmodified lines | ||
| 2672 | 2687 | float crf_max; |
| 2673 | 2688 | |
| 2674 | 2689 | 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; | |
| 2675 | 2704 | } AVCodecContext; |
| 2676 | 2705 | |
| 2677 | 2706 | /** |
| @@ -44,7 +44,8 @@ · 43 unmodified lines | ||
| 44 | 44 | typedef struct CompressionOptions { |
| 45 | 45 | int compression_level; |
| 46 | 46 | int block_time_ms; |
| 47 | − int use_lpc; | |
| 47 | + enum AVLPCType lpc_type; | |
| 48 | + int lpc_passes; | |
| 48 | 49 | int lpc_coeff_precision; |
| 49 | 50 | int min_prediction_order; |
| 50 | 51 | int max_prediction_order; |
| @@ -208,7 +209,11 @@ static av_cold int flac_encode_init(AVCodecContext *avctx) · 157 unmodified lines | ||
| 208 | 209 | } |
| 209 | 210 | |
| 210 | 211 | 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]; | |
| 212 | 217 | s->options.min_prediction_order= ((int[]){ 2, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1})[level]; |
| 213 | 218 | s->options.max_prediction_order= ((int[]){ 3, 4, 4, 6, 8, 8, 8, 8, 12, 12, 12, 32, 32})[level]; |
| 214 | 219 | 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 | ||
| 220 | 225 | s->options.max_partition_order = ((int[]){ 2, 2, 3, 3, 3, 8, 8, 8, 8, 8, 8, 8, 8})[level]; |
| 221 | 226 | |
| 222 | 227 | /* 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); | |
| 237 | 252 | return -1; |
| 253 | + } else { | |
| 254 | + s->options.lpc_passes = avctx->lpc_passes; | |
| 238 | 255 | } |
| 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) { | |
| 240 | 278 | if(avctx->min_prediction_order > MAX_FIXED_ORDER) { |
| 241 | 279 | av_log(avctx, AV_LOG_ERROR, "invalid min prediction order: %d\n", |
| 242 | 280 | avctx->min_prediction_order); |
| 243 | 281 | return -1; |
| 244 | 282 | } |
| 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; | |
| 245 | 288 | } |
| 246 | 289 | s->options.min_prediction_order = avctx->min_prediction_order; |
| 247 | 290 | } |
| 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) { | |
| 257 | 295 | if(avctx->max_prediction_order > MAX_FIXED_ORDER) { |
| 258 | 296 | av_log(avctx, AV_LOG_ERROR, "invalid max prediction order: %d\n", |
| 259 | 297 | avctx->max_prediction_order); |
| 260 | 298 | return -1; |
| 261 | 299 | } |
| 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; | |
| 262 | 305 | } |
| 263 | 306 | s->options.max_prediction_order = avctx->max_prediction_order; |
| 264 | 307 | } |
| @@ -754,7 +797,8 @@ static int encode_residual(FlacEncodeContext *ctx, int ch) · 489 unmodified lines | ||
| 754 | 797 | omethod = ctx->options.prediction_order_method; |
| 755 | 798 | |
| 756 | 799 | /* 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) { | |
| 758 | 802 | uint32_t bits[MAX_FIXED_ORDER+1]; |
| 759 | 803 | if(max_order > MAX_FIXED_ORDER) max_order = MAX_FIXED_ORDER; |
| 760 | 804 | opt_order = 0; |
| @@ -780,8 +824,9 @@ static int encode_residual(FlacEncodeContext *ctx, int ch) · 19 unmodified lines | ||
| 780 | 824 | |
| 781 | 825 | /* LPC */ |
| 782 | 826 | 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); | |
| 785 | 830 | |
| 786 | 831 | if(omethod == ORDER_METHOD_2LEVEL || |
| 787 | 832 | omethod == ORDER_METHOD_4LEVEL || |
| @@ -165,7 +165,8 @@ static int estimate_best_order(double *ref, int min_order, int max_order) · 164 unmodified lines | ||
| 165 | 165 | int ff_lpc_calc_coefs(DSPContext *s, |
| 166 | 166 | const int32_t *samples, int blocksize, int min_order, |
| 167 | 167 | 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, | |
| 169 | 170 | int omethod, int max_shift, int zero_shift) |
| 170 | 171 | { |
| 171 | 172 | double autoc[MAX_LPC_ORDER+1]; |
| @@ -174,20 +175,21 @@ int ff_lpc_calc_coefs(DSPContext *s, · 2 unmodified lines | ||
| 174 | 175 | int i, j, pass; |
| 175 | 176 | int opt_order; |
| 176 | 177 | |
| 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); | |
| 178 | 180 | |
| 179 | − if(use_lpc == 1){ | |
| 181 | + if (lpc_type == AV_LPC_TYPE_LEVINSON) { | |
| 180 | 182 | s->lpc_compute_autocorr(samples, blocksize, max_order, autoc); |
| 181 | 183 | |
| 182 | 184 | compute_lpc_coefs(autoc, max_order, &lpc[0][0], MAX_LPC_ORDER, 0, 1); |
| 183 | 185 | |
| 184 | 186 | for(i=0; i<max_order; i++) |
| 185 | 187 | ref[i] = fabs(lpc[i][i]); |
| 186 | − }else{ | |
| 188 | + } else if (lpc_type == AV_LPC_TYPE_CHOLESKY) { | |
| 187 | 189 | LLSModel m[2]; |
| 188 | 190 | double var[MAX_LPC_ORDER+1], av_uninit(weight); |
| 189 | 191 | |
| 190 | − for(pass=0; pass<use_lpc-1; pass++){ | |
| 192 | + for(pass=0; pass<lpc_passes; pass++){ | |
| 191 | 193 | av_init_lls(&m[pass&1], max_order); |
| 192 | 194 | |
| 193 | 195 | weight=0; |
| @@ -42,7 +42,8 @@ · 41 unmodified lines | ||
| 42 | 42 | int ff_lpc_calc_coefs(DSPContext *s, |
| 43 | 43 | const int32_t *samples, int blocksize, int min_order, |
| 44 | 44 | 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, | |
| 46 | 47 | int omethod, int max_shift, int zero_shift); |
| 47 | 48 | |
| 48 | 49 | void ff_lpc_compute_autocorr(const int32_t *data, int len, int lag, |
| @@ -382,7 +382,9 @@ static const AVOption options[]={ · 381 unmodified lines | ||
| 382 | 382 | {"ivlc", "intra vlc table", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_INTRA_VLC, INT_MIN, INT_MAX, V|E, "flags2"}, |
| 383 | 383 | {"b_sensitivity", "adjusts sensitivity of b_frame_strategy 1", OFFSET(b_sensitivity), FF_OPT_TYPE_INT, 40, 1, INT_MAX, V|E}, |
| 384 | 384 | {"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 | |
| 385 | 386 | {"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 | |
| 386 | 388 | {"lpc_coeff_precision", "LPC coefficient precision (FLAC)", OFFSET(lpc_coeff_precision), FF_OPT_TYPE_INT, DEFAULT, 0, INT_MAX, A|E}, |
| 387 | 389 | {"min_prediction_order", NULL, OFFSET(min_prediction_order), FF_OPT_TYPE_INT, -1, INT_MIN, INT_MAX, A|E}, |
| 388 | 390 | {"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 | ||
| 417 | 419 | {"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"}, |
| 418 | 420 | {"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}, |
| 419 | 421 | {"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}, | |
| 420 | 428 | {NULL}, |
| 421 | 429 | }; |
| 422 | 430 | |
| @@ -452,8 +452,8 @@ static int ra144_encode_frame(AVCodecContext *avctx, uint8_t *frame, · 451 unmodified lines | ||
| 452 | 452 | 32)]; |
| 453 | 453 | |
| 454 | 454 | 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); | |
| 457 | 457 | for (i = 0; i < LPC_ORDER; i++) |
| 458 | 458 | block_coefs[NBLOCKS - 1][i] = -(lpc_coefs[LPC_ORDER - 1][i] << |
| 459 | 459 | (12 - shift[LPC_ORDER - 1])); |