Mercurial > libavcodec.hg
comparison flacenc.c @ 12139:e59926e2c50c libavcodec
Add AVCodecContext.lpc_type and Add AVCodecContext.lpc_passes fields.
Add AVLPCType enum.
Deprecate AVCodecContext.use_lpc.
author | jbr |
---|---|
date | Sun, 11 Jul 2010 16:56:20 +0000 |
parents | 8b28e74de2c0 |
children | dde20597f15e |
comparison
equal
deleted
inserted
replaced
12138:41f078d6869d | 12139:e59926e2c50c |
---|---|
42 #define MAX_RICE_PARAM 14 | 42 #define MAX_RICE_PARAM 14 |
43 | 43 |
44 typedef struct CompressionOptions { | 44 typedef struct CompressionOptions { |
45 int compression_level; | 45 int compression_level; |
46 int block_time_ms; | 46 int block_time_ms; |
47 int use_lpc; | 47 enum AVLPCType lpc_type; |
48 int lpc_passes; | |
48 int lpc_coeff_precision; | 49 int lpc_coeff_precision; |
49 int min_prediction_order; | 50 int min_prediction_order; |
50 int max_prediction_order; | 51 int max_prediction_order; |
51 int prediction_order_method; | 52 int prediction_order_method; |
52 int min_partition_order; | 53 int min_partition_order; |
206 s->options.compression_level); | 207 s->options.compression_level); |
207 return -1; | 208 return -1; |
208 } | 209 } |
209 | 210 |
210 s->options.block_time_ms = ((int[]){ 27, 27, 27,105,105,105,105,105,105,105,105,105,105})[level]; | 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 s->options.min_prediction_order= ((int[]){ 2, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1})[level]; | 217 s->options.min_prediction_order= ((int[]){ 2, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1})[level]; |
213 s->options.max_prediction_order= ((int[]){ 3, 4, 4, 6, 8, 8, 8, 8, 12, 12, 12, 32, 32})[level]; | 218 s->options.max_prediction_order= ((int[]){ 3, 4, 4, 6, 8, 8, 8, 8, 12, 12, 12, 32, 32})[level]; |
214 s->options.prediction_order_method = ((int[]){ ORDER_METHOD_EST, ORDER_METHOD_EST, ORDER_METHOD_EST, | 219 s->options.prediction_order_method = ((int[]){ ORDER_METHOD_EST, ORDER_METHOD_EST, ORDER_METHOD_EST, |
215 ORDER_METHOD_EST, ORDER_METHOD_EST, ORDER_METHOD_EST, | 220 ORDER_METHOD_EST, ORDER_METHOD_EST, ORDER_METHOD_EST, |
216 ORDER_METHOD_4LEVEL, ORDER_METHOD_LOG, ORDER_METHOD_4LEVEL, | 221 ORDER_METHOD_4LEVEL, ORDER_METHOD_LOG, ORDER_METHOD_4LEVEL, |
218 ORDER_METHOD_SEARCH})[level]; | 223 ORDER_METHOD_SEARCH})[level]; |
219 s->options.min_partition_order = ((int[]){ 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0})[level]; | 224 s->options.min_partition_order = ((int[]){ 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0})[level]; |
220 s->options.max_partition_order = ((int[]){ 2, 2, 3, 3, 3, 8, 8, 8, 8, 8, 8, 8, 8})[level]; | 225 s->options.max_partition_order = ((int[]){ 2, 2, 3, 3, 3, 8, 8, 8, 8, 8, 8, 8, 8})[level]; |
221 | 226 |
222 /* set compression option overrides from AVCodecContext */ | 227 /* set compression option overrides from AVCodecContext */ |
223 if(avctx->use_lpc >= 0) { | 228 #if LIBAVCODEC_VERSION_MAJOR < 53 |
224 s->options.use_lpc = av_clip(avctx->use_lpc, 0, 11); | 229 /* for compatibility with deprecated AVCodecContext.use_lpc */ |
225 } | 230 if (avctx->use_lpc == 0) { |
226 if(s->options.use_lpc == 1) | 231 s->options.lpc_type = AV_LPC_TYPE_FIXED; |
227 av_log(avctx, AV_LOG_DEBUG, " use lpc: Levinson-Durbin recursion with Welch window\n"); | 232 } else if (avctx->use_lpc == 1) { |
228 else if(s->options.use_lpc > 1) | 233 s->options.lpc_type = AV_LPC_TYPE_LEVINSON; |
229 av_log(avctx, AV_LOG_DEBUG, " use lpc: Cholesky factorization\n"); | 234 } else if (avctx->use_lpc > 1) { |
230 | 235 s->options.lpc_type = AV_LPC_TYPE_CHOLESKY; |
231 if(avctx->min_prediction_order >= 0) { | 236 s->options.lpc_passes = avctx->use_lpc - 1; |
232 if(s->options.use_lpc) { | 237 } |
233 if(avctx->min_prediction_order < MIN_LPC_ORDER || | 238 #endif |
234 avctx->min_prediction_order > MAX_LPC_ORDER) { | 239 if (avctx->lpc_type > AV_LPC_TYPE_DEFAULT) { |
235 av_log(avctx, AV_LOG_ERROR, "invalid min prediction order: %d\n", | 240 if (avctx->lpc_type > AV_LPC_TYPE_CHOLESKY) { |
236 avctx->min_prediction_order); | 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 return -1; | 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 if(avctx->min_prediction_order > MAX_FIXED_ORDER) { | 278 if(avctx->min_prediction_order > MAX_FIXED_ORDER) { |
241 av_log(avctx, AV_LOG_ERROR, "invalid min prediction order: %d\n", | 279 av_log(avctx, AV_LOG_ERROR, "invalid min prediction order: %d\n", |
242 avctx->min_prediction_order); | 280 avctx->min_prediction_order); |
243 return -1; | 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 s->options.min_prediction_order = avctx->min_prediction_order; | 289 s->options.min_prediction_order = avctx->min_prediction_order; |
247 } | 290 } |
248 if(avctx->max_prediction_order >= 0) { | 291 if (s->options.lpc_type == AV_LPC_TYPE_NONE) { |
249 if(s->options.use_lpc) { | 292 s->options.max_prediction_order = 0; |
250 if(avctx->max_prediction_order < MIN_LPC_ORDER || | 293 } else if (avctx->max_prediction_order >= 0) { |
251 avctx->max_prediction_order > MAX_LPC_ORDER) { | 294 if (s->options.lpc_type == AV_LPC_TYPE_FIXED) { |
252 av_log(avctx, AV_LOG_ERROR, "invalid max prediction order: %d\n", | |
253 avctx->max_prediction_order); | |
254 return -1; | |
255 } | |
256 } else { | |
257 if(avctx->max_prediction_order > MAX_FIXED_ORDER) { | 295 if(avctx->max_prediction_order > MAX_FIXED_ORDER) { |
258 av_log(avctx, AV_LOG_ERROR, "invalid max prediction order: %d\n", | 296 av_log(avctx, AV_LOG_ERROR, "invalid max prediction order: %d\n", |
259 avctx->max_prediction_order); | 297 avctx->max_prediction_order); |
260 return -1; | 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 s->options.max_prediction_order = avctx->max_prediction_order; | 306 s->options.max_prediction_order = avctx->max_prediction_order; |
264 } | 307 } |
265 if(s->options.max_prediction_order < s->options.min_prediction_order) { | 308 if(s->options.max_prediction_order < s->options.min_prediction_order) { |
266 av_log(avctx, AV_LOG_ERROR, "invalid prediction orders: min=%d max=%d\n", | 309 av_log(avctx, AV_LOG_ERROR, "invalid prediction orders: min=%d max=%d\n", |
752 max_porder = ctx->options.max_partition_order; | 795 max_porder = ctx->options.max_partition_order; |
753 precision = ctx->options.lpc_coeff_precision; | 796 precision = ctx->options.lpc_coeff_precision; |
754 omethod = ctx->options.prediction_order_method; | 797 omethod = ctx->options.prediction_order_method; |
755 | 798 |
756 /* FIXED */ | 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 uint32_t bits[MAX_FIXED_ORDER+1]; | 802 uint32_t bits[MAX_FIXED_ORDER+1]; |
759 if(max_order > MAX_FIXED_ORDER) max_order = MAX_FIXED_ORDER; | 803 if(max_order > MAX_FIXED_ORDER) max_order = MAX_FIXED_ORDER; |
760 opt_order = 0; | 804 opt_order = 0; |
761 bits[0] = UINT32_MAX; | 805 bits[0] = UINT32_MAX; |
762 for(i=min_order; i<=max_order; i++) { | 806 for(i=min_order; i<=max_order; i++) { |
778 return bits[sub->order]; | 822 return bits[sub->order]; |
779 } | 823 } |
780 | 824 |
781 /* LPC */ | 825 /* LPC */ |
782 opt_order = ff_lpc_calc_coefs(&ctx->dsp, smp, n, min_order, max_order, | 826 opt_order = ff_lpc_calc_coefs(&ctx->dsp, smp, n, min_order, max_order, |
783 precision, coefs, shift, ctx->options.use_lpc, | 827 precision, coefs, shift, ctx->options.lpc_type, |
784 omethod, MAX_LPC_SHIFT, 0); | 828 ctx->options.lpc_passes, omethod, |
829 MAX_LPC_SHIFT, 0); | |
785 | 830 |
786 if(omethod == ORDER_METHOD_2LEVEL || | 831 if(omethod == ORDER_METHOD_2LEVEL || |
787 omethod == ORDER_METHOD_4LEVEL || | 832 omethod == ORDER_METHOD_4LEVEL || |
788 omethod == ORDER_METHOD_8LEVEL) { | 833 omethod == ORDER_METHOD_8LEVEL) { |
789 int levels = 1 << omethod; | 834 int levels = 1 << omethod; |