aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec
diff options
context:
space:
mode:
authorJustin Ruggles <justin.ruggles@gmail.com>2010-07-11 16:56:20 +0000
committerJustin Ruggles <justin.ruggles@gmail.com>2010-07-11 16:56:20 +0000
commit23940f1405d4c19df69b1fa77c319e9f114c8ef7 (patch)
tree1f98802573d8e6c7ff8f0467bca1a05171d5fe7d /libavcodec
parent31769dad7d182983e2943d519201c24e9cea6f3e (diff)
downloadffmpeg-23940f1405d4c19df69b1fa77c319e9f114c8ef7.tar.gz
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
Diffstat (limited to 'libavcodec')
-rw-r--r--libavcodec/alacenc.c3
-rw-r--r--libavcodec/avcodec.h31
-rw-r--r--libavcodec/flacenc.c103
-rw-r--r--libavcodec/lpc.c12
-rw-r--r--libavcodec/lpc.h3
-rw-r--r--libavcodec/options.c8
-rw-r--r--libavcodec/ra144enc.c4
7 files changed, 125 insertions, 39 deletions
diff --git a/libavcodec/alacenc.c b/libavcodec/alacenc.c
index 0876633cbd..ee6acc0715 100644
--- a/libavcodec/alacenc.c
+++ b/libavcodec/alacenc.c
@@ -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;
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 475d9b5f03..48666f9970 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -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;
/**
diff --git a/libavcodec/flacenc.c b/libavcodec/flacenc.c
index fa05b7d4ee..d87d5d7c21 100644
--- a/libavcodec/flacenc.c
+++ b/libavcodec/flacenc.c
@@ -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 ||
diff --git a/libavcodec/lpc.c b/libavcodec/lpc.c
index 41d5e19255..112a78d4b9 100644
--- a/libavcodec/lpc.c
+++ b/libavcodec/lpc.c
@@ -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;
diff --git a/libavcodec/lpc.h b/libavcodec/lpc.h
index a5b6f2ebb1..1c595f6b9a 100644
--- a/libavcodec/lpc.h
+++ b/libavcodec/lpc.h
@@ -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,
diff --git a/libavcodec/options.c b/libavcodec/options.c
index 75856f699f..d20a643fa4 100644
--- a/libavcodec/options.c
+++ b/libavcodec/options.c
@@ -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},
};
diff --git a/libavcodec/ra144enc.c b/libavcodec/ra144enc.c
index 7886602477..9e2cf36c2d 100644
--- a/libavcodec/ra144enc.c
+++ b/libavcodec/ra144enc.c
@@ -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]));