Commit 23940f14 authored by Justin Ruggles's avatar Justin Ruggles

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
parent 31769dad
......@@ -12,6 +12,11 @@ libavutil: 2009-03-08
API changes, most recent first:
2010-07-11 - r????? - lavc 52.83.0
Add AVCodecContext.lpc_type and Add AVCodecContext.lpc_passes fields.
Add AVLPCType enum.
Deprecate AVCodecContext.use_lpc.
2010-07-11 - r24185 - lavc 52.82.0 - avsubtitle_free()
Add a function for free the contents of a AVSubtitle generated by
avcodec_decode_subtitle.
......
......@@ -145,7 +145,8 @@ static void calc_predictor_params(AlacEncodeContext *s, int ch)
s->avctx->frame_size,
s->min_prediction_order,
s->max_prediction_order,
ALAC_MAX_LPC_PRECISION, coefs, shift, 1,
ALAC_MAX_LPC_PRECISION, coefs, shift,
AV_LPC_TYPE_LEVINSON, 0,
ORDER_METHOD_EST, ALAC_MAX_LPC_SHIFT, 1);
s->lpc[ch].lpc_order = opt_order;
......
......@@ -30,7 +30,7 @@
#include "libavutil/avutil.h"
#define LIBAVCODEC_VERSION_MAJOR 52
#define LIBAVCODEC_VERSION_MINOR 82
#define LIBAVCODEC_VERSION_MINOR 83
#define LIBAVCODEC_VERSION_MICRO 0
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
......@@ -526,6 +526,18 @@ enum AVChromaLocation{
AVCHROMA_LOC_NB , ///< Not part of ABI
};
/**
* LPC analysis type
*/
enum AVLPCType {
AV_LPC_TYPE_DEFAULT = -1, ///< use the codec default LPC type
AV_LPC_TYPE_NONE = 0, ///< do not use LPC prediction or use all zero coefficients
AV_LPC_TYPE_FIXED = 1, ///< fixed LPC coefficients
AV_LPC_TYPE_LEVINSON = 2, ///< Levinson-Durbin recursion
AV_LPC_TYPE_CHOLESKY = 3, ///< Cholesky factorization
AV_LPC_TYPE_NB , ///< Not part of ABI
};
typedef struct RcOverride{
int start_frame;
int end_frame;
......@@ -2413,12 +2425,15 @@ typedef struct AVCodecContext {
int compression_level;
#define FF_COMPRESSION_DEFAULT -1
#if LIBAVCODEC_VERSION_MAJOR < 53
/**
* Sets whether to use LPC mode - used by FLAC encoder.
* - encoding: Set by user.
* - decoding: unused
* @deprecated Deprecated in favor of lpc_type and lpc_passes.
*/
int use_lpc;
#endif
/**
* LPC coefficient precision - used by FLAC encoder
......@@ -2672,6 +2687,20 @@ typedef struct AVCodecContext {
float crf_max;
int log_level_offset;
/**
* Determines which LPC analysis algorithm to use.
* - encoding: Set by user
* - decoding: unused
*/
enum AVLPCType lpc_type;
/**
* Number of passes to use for Cholesky factorization during LPC analysis
* - encoding: Set by user
* - decoding: unused
*/
int lpc_passes;
} AVCodecContext;
/**
......
......@@ -44,7 +44,8 @@
typedef struct CompressionOptions {
int compression_level;
int block_time_ms;
int use_lpc;
enum AVLPCType lpc_type;
int lpc_passes;
int lpc_coeff_precision;
int min_prediction_order;
int max_prediction_order;
......@@ -208,7 +209,11 @@ static av_cold int flac_encode_init(AVCodecContext *avctx)
}
s->options.block_time_ms = ((int[]){ 27, 27, 27,105,105,105,105,105,105,105,105,105,105})[level];
s->options.use_lpc = ((int[]){ 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1})[level];
s->options.lpc_type = ((int[]){ AV_LPC_TYPE_FIXED, AV_LPC_TYPE_FIXED, AV_LPC_TYPE_FIXED,
AV_LPC_TYPE_LEVINSON, AV_LPC_TYPE_LEVINSON, AV_LPC_TYPE_LEVINSON,
AV_LPC_TYPE_LEVINSON, AV_LPC_TYPE_LEVINSON, AV_LPC_TYPE_LEVINSON,
AV_LPC_TYPE_LEVINSON, AV_LPC_TYPE_LEVINSON, AV_LPC_TYPE_LEVINSON,
AV_LPC_TYPE_LEVINSON})[level];
s->options.min_prediction_order= ((int[]){ 2, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1})[level];
s->options.max_prediction_order= ((int[]){ 3, 4, 4, 6, 8, 8, 8, 8, 12, 12, 12, 32, 32})[level];
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)
s->options.max_partition_order = ((int[]){ 2, 2, 3, 3, 3, 8, 8, 8, 8, 8, 8, 8, 8})[level];
/* set compression option overrides from AVCodecContext */
if(avctx->use_lpc >= 0) {
s->options.use_lpc = av_clip(avctx->use_lpc, 0, 11);
}
if(s->options.use_lpc == 1)
av_log(avctx, AV_LOG_DEBUG, " use lpc: Levinson-Durbin recursion with Welch window\n");
else if(s->options.use_lpc > 1)
av_log(avctx, AV_LOG_DEBUG, " use lpc: Cholesky factorization\n");
if(avctx->min_prediction_order >= 0) {
if(s->options.use_lpc) {
if(avctx->min_prediction_order < MIN_LPC_ORDER ||
avctx->min_prediction_order > MAX_LPC_ORDER) {
av_log(avctx, AV_LOG_ERROR, "invalid min prediction order: %d\n",
avctx->min_prediction_order);
#if LIBAVCODEC_VERSION_MAJOR < 53
/* for compatibility with deprecated AVCodecContext.use_lpc */
if (avctx->use_lpc == 0) {
s->options.lpc_type = AV_LPC_TYPE_FIXED;
} else if (avctx->use_lpc == 1) {
s->options.lpc_type = AV_LPC_TYPE_LEVINSON;
} else if (avctx->use_lpc > 1) {
s->options.lpc_type = AV_LPC_TYPE_CHOLESKY;
s->options.lpc_passes = avctx->use_lpc - 1;
}
#endif
if (avctx->lpc_type > AV_LPC_TYPE_DEFAULT) {
if (avctx->lpc_type > AV_LPC_TYPE_CHOLESKY) {
av_log(avctx, AV_LOG_ERROR, "unknown lpc type: %d\n", avctx->lpc_type);
return -1;
}
s->options.lpc_type = avctx->lpc_type;
if (s->options.lpc_type == AV_LPC_TYPE_CHOLESKY) {
if (avctx->lpc_passes < 0) {
// default number of passes for Cholesky
s->options.lpc_passes = 2;
} else if (avctx->lpc_passes == 0) {
av_log(avctx, AV_LOG_ERROR, "invalid number of lpc passes: %d\n",
avctx->lpc_passes);
return -1;
} else {
s->options.lpc_passes = avctx->lpc_passes;
}
} else {
}
}
switch (s->options.lpc_type) {
case AV_LPC_TYPE_NONE:
av_log(avctx, AV_LOG_DEBUG, " lpc type: None\n");
break;
case AV_LPC_TYPE_FIXED:
av_log(avctx, AV_LOG_DEBUG, " lpc type: Fixed pre-defined coefficients\n");
break;
case AV_LPC_TYPE_LEVINSON:
av_log(avctx, AV_LOG_DEBUG, " lpc type: Levinson-Durbin recursion with Welch window\n");
break;
case AV_LPC_TYPE_CHOLESKY:
av_log(avctx, AV_LOG_DEBUG, " lpc type: Cholesky factorization, %d pass%s\n",
s->options.lpc_passes, s->options.lpc_passes==1?"":"es");
break;
}
if (s->options.lpc_type == AV_LPC_TYPE_NONE) {
s->options.min_prediction_order = 0;
} else if (avctx->min_prediction_order >= 0) {
if (s->options.lpc_type == AV_LPC_TYPE_FIXED) {
if(avctx->min_prediction_order > MAX_FIXED_ORDER) {
av_log(avctx, AV_LOG_ERROR, "invalid min prediction order: %d\n",
avctx->min_prediction_order);
return -1;
}
} else if(avctx->min_prediction_order < MIN_LPC_ORDER ||
avctx->min_prediction_order > MAX_LPC_ORDER) {
av_log(avctx, AV_LOG_ERROR, "invalid min prediction order: %d\n",
avctx->min_prediction_order);
return -1;
}
s->options.min_prediction_order = avctx->min_prediction_order;
}
if(avctx->max_prediction_order >= 0) {
if(s->options.use_lpc) {
if(avctx->max_prediction_order < MIN_LPC_ORDER ||
avctx->max_prediction_order > MAX_LPC_ORDER) {
av_log(avctx, AV_LOG_ERROR, "invalid max prediction order: %d\n",
avctx->max_prediction_order);
return -1;
}
} else {
if (s->options.lpc_type == AV_LPC_TYPE_NONE) {
s->options.max_prediction_order = 0;
} else if (avctx->max_prediction_order >= 0) {
if (s->options.lpc_type == AV_LPC_TYPE_FIXED) {
if(avctx->max_prediction_order > MAX_FIXED_ORDER) {
av_log(avctx, AV_LOG_ERROR, "invalid max prediction order: %d\n",
avctx->max_prediction_order);
return -1;
}
} else if (avctx->max_prediction_order < MIN_LPC_ORDER ||
avctx->max_prediction_order > MAX_LPC_ORDER) {
av_log(avctx, AV_LOG_ERROR, "invalid max prediction order: %d\n",
avctx->max_prediction_order);
return -1;
}
s->options.max_prediction_order = avctx->max_prediction_order;
}
......@@ -754,7 +797,8 @@ static int encode_residual(FlacEncodeContext *ctx, int ch)
omethod = ctx->options.prediction_order_method;
/* FIXED */
if(!ctx->options.use_lpc || max_order == 0 || (n <= max_order)) {
if (ctx->options.lpc_type == AV_LPC_TYPE_NONE ||
ctx->options.lpc_type == AV_LPC_TYPE_FIXED || n <= max_order) {
uint32_t bits[MAX_FIXED_ORDER+1];
if(max_order > MAX_FIXED_ORDER) max_order = MAX_FIXED_ORDER;
opt_order = 0;
......@@ -780,8 +824,9 @@ static int encode_residual(FlacEncodeContext *ctx, int ch)
/* LPC */
opt_order = ff_lpc_calc_coefs(&ctx->dsp, smp, n, min_order, max_order,
precision, coefs, shift, ctx->options.use_lpc,
omethod, MAX_LPC_SHIFT, 0);
precision, coefs, shift, ctx->options.lpc_type,
ctx->options.lpc_passes, omethod,
MAX_LPC_SHIFT, 0);
if(omethod == ORDER_METHOD_2LEVEL ||
omethod == ORDER_METHOD_4LEVEL ||
......
......@@ -165,7 +165,8 @@ static int estimate_best_order(double *ref, int min_order, int max_order)
int ff_lpc_calc_coefs(DSPContext *s,
const int32_t *samples, int blocksize, int min_order,
int max_order, int precision,
int32_t coefs[][MAX_LPC_ORDER], int *shift, int use_lpc,
int32_t coefs[][MAX_LPC_ORDER], int *shift,
enum AVLPCType lpc_type, int lpc_passes,
int omethod, int max_shift, int zero_shift)
{
double autoc[MAX_LPC_ORDER+1];
......@@ -174,20 +175,21 @@ int ff_lpc_calc_coefs(DSPContext *s,
int i, j, pass;
int opt_order;
assert(max_order >= MIN_LPC_ORDER && max_order <= MAX_LPC_ORDER && use_lpc > 0);
assert(max_order >= MIN_LPC_ORDER && max_order <= MAX_LPC_ORDER &&
lpc_type > AV_LPC_TYPE_FIXED);
if(use_lpc == 1){
if (lpc_type == AV_LPC_TYPE_LEVINSON) {
s->lpc_compute_autocorr(samples, blocksize, max_order, autoc);
compute_lpc_coefs(autoc, max_order, &lpc[0][0], MAX_LPC_ORDER, 0, 1);
for(i=0; i<max_order; i++)
ref[i] = fabs(lpc[i][i]);
}else{
} else if (lpc_type == AV_LPC_TYPE_CHOLESKY) {
LLSModel m[2];
double var[MAX_LPC_ORDER+1], av_uninit(weight);
for(pass=0; pass<use_lpc-1; pass++){
for(pass=0; pass<lpc_passes; pass++){
av_init_lls(&m[pass&1], max_order);
weight=0;
......
......@@ -42,7 +42,8 @@
int ff_lpc_calc_coefs(DSPContext *s,
const int32_t *samples, int blocksize, int min_order,
int max_order, int precision,
int32_t coefs[][MAX_LPC_ORDER], int *shift, int use_lpc,
int32_t coefs[][MAX_LPC_ORDER], int *shift,
enum AVLPCType lpc_type, int lpc_passes,
int omethod, int max_shift, int zero_shift);
void ff_lpc_compute_autocorr(const int32_t *data, int len, int lag,
......
......@@ -382,7 +382,9 @@ static const AVOption options[]={
{"ivlc", "intra vlc table", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_INTRA_VLC, INT_MIN, INT_MAX, V|E, "flags2"},
{"b_sensitivity", "adjusts sensitivity of b_frame_strategy 1", OFFSET(b_sensitivity), FF_OPT_TYPE_INT, 40, 1, INT_MAX, V|E},
{"compression_level", NULL, OFFSET(compression_level), FF_OPT_TYPE_INT, FF_COMPRESSION_DEFAULT, INT_MIN, INT_MAX, V|A|E},
#if LIBAVCODEC_VERSION_MAJOR < 53
{"use_lpc", "sets whether to use LPC mode (FLAC)", OFFSET(use_lpc), FF_OPT_TYPE_INT, -1, INT_MIN, INT_MAX, A|E},
#endif
{"lpc_coeff_precision", "LPC coefficient precision (FLAC)", OFFSET(lpc_coeff_precision), FF_OPT_TYPE_INT, DEFAULT, 0, INT_MAX, A|E},
{"min_prediction_order", NULL, OFFSET(min_prediction_order), FF_OPT_TYPE_INT, -1, INT_MIN, INT_MAX, A|E},
{"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[]={
{"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"},
{"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},
{"log_level_offset", "set the log level offset", OFFSET(log_level_offset), FF_OPT_TYPE_INT, 0, INT_MIN, INT_MAX },
{"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},
{"none", NULL, 0, FF_OPT_TYPE_CONST, AV_LPC_TYPE_NONE, INT_MIN, INT_MAX, A|E, "lpc_type"},
{"fixed", NULL, 0, FF_OPT_TYPE_CONST, AV_LPC_TYPE_FIXED, INT_MIN, INT_MAX, A|E, "lpc_type"},
{"levinson", NULL, 0, FF_OPT_TYPE_CONST, AV_LPC_TYPE_LEVINSON, INT_MIN, INT_MAX, A|E, "lpc_type"},
{"cholesky", NULL, 0, FF_OPT_TYPE_CONST, AV_LPC_TYPE_CHOLESKY, INT_MIN, INT_MAX, A|E, "lpc_type"},
{"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},
{NULL},
};
......
......@@ -452,8 +452,8 @@ static int ra144_encode_frame(AVCodecContext *avctx, uint8_t *frame,
32)];
ff_lpc_calc_coefs(&ractx->dsp, lpc_data, NBLOCKS * BLOCKSIZE, LPC_ORDER,
LPC_ORDER, 16, lpc_coefs, shift, 1, ORDER_METHOD_EST, 12,
0);
LPC_ORDER, 16, lpc_coefs, shift, AV_LPC_TYPE_LEVINSON,
0, ORDER_METHOD_EST, 12, 0);
for (i = 0; i < LPC_ORDER; i++)
block_coefs[NBLOCKS - 1][i] = -(lpc_coefs[LPC_ORDER - 1][i] <<
(12 - shift[LPC_ORDER - 1]));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment