comparison flacenc.c @ 12302:2e28769c55a9 libavcodec

Move debug logging of compression options to a single function.
author jbr
date Fri, 30 Jul 2010 18:59:27 +0000
parents a2dfd6f9a580
children bf6a00442ed0
comparison
equal deleted inserted replaced
12301:a2dfd6f9a580 12302:2e28769c55a9
146 } 146 }
147 return blocksize; 147 return blocksize;
148 } 148 }
149 149
150 150
151 static av_cold void dprint_compression_options(FlacEncodeContext *s)
152 {
153 AVCodecContext *avctx = s->avctx;
154 CompressionOptions *opt = &s->options;
155
156 av_log(avctx, AV_LOG_DEBUG, " compression: %d\n", opt->compression_level);
157
158 switch (opt->lpc_type) {
159 case AV_LPC_TYPE_NONE:
160 av_log(avctx, AV_LOG_DEBUG, " lpc type: None\n");
161 break;
162 case AV_LPC_TYPE_FIXED:
163 av_log(avctx, AV_LOG_DEBUG, " lpc type: Fixed pre-defined coefficients\n");
164 break;
165 case AV_LPC_TYPE_LEVINSON:
166 av_log(avctx, AV_LOG_DEBUG, " lpc type: Levinson-Durbin recursion with Welch window\n");
167 break;
168 case AV_LPC_TYPE_CHOLESKY:
169 av_log(avctx, AV_LOG_DEBUG, " lpc type: Cholesky factorization, %d pass%s\n",
170 opt->lpc_passes, opt->lpc_passes == 1 ? "" : "es");
171 break;
172 }
173
174 av_log(avctx, AV_LOG_DEBUG, " prediction order: %d, %d\n",
175 opt->min_prediction_order, opt->max_prediction_order);
176
177 switch (opt->prediction_order_method) {
178 case ORDER_METHOD_EST:
179 av_log(avctx, AV_LOG_DEBUG, " order method: %s\n", "estimate");
180 break;
181 case ORDER_METHOD_2LEVEL:
182 av_log(avctx, AV_LOG_DEBUG, " order method: %s\n", "2-level");
183 break;
184 case ORDER_METHOD_4LEVEL:
185 av_log(avctx, AV_LOG_DEBUG, " order method: %s\n", "4-level");
186 break;
187 case ORDER_METHOD_8LEVEL:
188 av_log(avctx, AV_LOG_DEBUG, " order method: %s\n", "8-level");
189 break;
190 case ORDER_METHOD_SEARCH:
191 av_log(avctx, AV_LOG_DEBUG, " order method: %s\n", "full search");
192 break;
193 case ORDER_METHOD_LOG:
194 av_log(avctx, AV_LOG_DEBUG, " order method: %s\n", "log search");
195 break;
196 }
197
198
199 av_log(avctx, AV_LOG_DEBUG, " partition order: %d, %d\n",
200 opt->min_partition_order, opt->max_partition_order);
201
202 av_log(avctx, AV_LOG_DEBUG, " block size: %d\n", avctx->frame_size);
203
204 av_log(avctx, AV_LOG_DEBUG, " lpc precision: %d\n",
205 opt->lpc_coeff_precision);
206 }
207
208
151 static av_cold int flac_encode_init(AVCodecContext *avctx) 209 static av_cold int flac_encode_init(AVCodecContext *avctx)
152 { 210 {
153 int freq = avctx->sample_rate; 211 int freq = avctx->sample_rate;
154 int channels = avctx->channels; 212 int channels = avctx->channels;
155 FlacEncodeContext *s = avctx->priv_data; 213 FlacEncodeContext *s = avctx->priv_data;
198 /* set compression option defaults based on avctx->compression_level */ 256 /* set compression option defaults based on avctx->compression_level */
199 if (avctx->compression_level < 0) 257 if (avctx->compression_level < 0)
200 s->options.compression_level = 5; 258 s->options.compression_level = 5;
201 else 259 else
202 s->options.compression_level = avctx->compression_level; 260 s->options.compression_level = avctx->compression_level;
203 av_log(avctx, AV_LOG_DEBUG, " compression: %d\n", s->options.compression_level);
204 261
205 level = s->options.compression_level; 262 level = s->options.compression_level;
206 if (level > 12) { 263 if (level > 12) {
207 av_log(avctx, AV_LOG_ERROR, "invalid compression level: %d\n", 264 av_log(avctx, AV_LOG_ERROR, "invalid compression level: %d\n",
208 s->options.compression_level); 265 s->options.compression_level);
257 return -1; 314 return -1;
258 } else { 315 } else {
259 s->options.lpc_passes = avctx->lpc_passes; 316 s->options.lpc_passes = avctx->lpc_passes;
260 } 317 }
261 } 318 }
262 }
263 switch (s->options.lpc_type) {
264 case AV_LPC_TYPE_NONE:
265 av_log(avctx, AV_LOG_DEBUG, " lpc type: None\n");
266 break;
267 case AV_LPC_TYPE_FIXED:
268 av_log(avctx, AV_LOG_DEBUG, " lpc type: Fixed pre-defined coefficients\n");
269 break;
270 case AV_LPC_TYPE_LEVINSON:
271 av_log(avctx, AV_LOG_DEBUG, " lpc type: Levinson-Durbin recursion with Welch window\n");
272 break;
273 case AV_LPC_TYPE_CHOLESKY:
274 av_log(avctx, AV_LOG_DEBUG, " lpc type: Cholesky factorization, %d pass%s\n",
275 s->options.lpc_passes, s->options.lpc_passes==1?"":"es");
276 break;
277 } 319 }
278 320
279 if (s->options.lpc_type == AV_LPC_TYPE_NONE) { 321 if (s->options.lpc_type == AV_LPC_TYPE_NONE) {
280 s->options.min_prediction_order = 0; 322 s->options.min_prediction_order = 0;
281 } else if (avctx->min_prediction_order >= 0) { 323 } else if (avctx->min_prediction_order >= 0) {
313 if (s->options.max_prediction_order < s->options.min_prediction_order) { 355 if (s->options.max_prediction_order < s->options.min_prediction_order) {
314 av_log(avctx, AV_LOG_ERROR, "invalid prediction orders: min=%d max=%d\n", 356 av_log(avctx, AV_LOG_ERROR, "invalid prediction orders: min=%d max=%d\n",
315 s->options.min_prediction_order, s->options.max_prediction_order); 357 s->options.min_prediction_order, s->options.max_prediction_order);
316 return -1; 358 return -1;
317 } 359 }
318 av_log(avctx, AV_LOG_DEBUG, " prediction order: %d, %d\n",
319 s->options.min_prediction_order, s->options.max_prediction_order);
320 360
321 if (avctx->prediction_order_method >= 0) { 361 if (avctx->prediction_order_method >= 0) {
322 if (avctx->prediction_order_method > ORDER_METHOD_LOG) { 362 if (avctx->prediction_order_method > ORDER_METHOD_LOG) {
323 av_log(avctx, AV_LOG_ERROR, "invalid prediction order method: %d\n", 363 av_log(avctx, AV_LOG_ERROR, "invalid prediction order method: %d\n",
324 avctx->prediction_order_method); 364 avctx->prediction_order_method);
325 return -1; 365 return -1;
326 } 366 }
327 s->options.prediction_order_method = avctx->prediction_order_method; 367 s->options.prediction_order_method = avctx->prediction_order_method;
328 } 368 }
329 switch (s->options.prediction_order_method) {
330 case ORDER_METHOD_EST: av_log(avctx, AV_LOG_DEBUG, " order method: %s\n",
331 "estimate"); break;
332 case ORDER_METHOD_2LEVEL: av_log(avctx, AV_LOG_DEBUG, " order method: %s\n",
333 "2-level"); break;
334 case ORDER_METHOD_4LEVEL: av_log(avctx, AV_LOG_DEBUG, " order method: %s\n",
335 "4-level"); break;
336 case ORDER_METHOD_8LEVEL: av_log(avctx, AV_LOG_DEBUG, " order method: %s\n",
337 "8-level"); break;
338 case ORDER_METHOD_SEARCH: av_log(avctx, AV_LOG_DEBUG, " order method: %s\n",
339 "full search"); break;
340 case ORDER_METHOD_LOG: av_log(avctx, AV_LOG_DEBUG, " order method: %s\n",
341 "log search"); break;
342 }
343 369
344 if (avctx->min_partition_order >= 0) { 370 if (avctx->min_partition_order >= 0) {
345 if (avctx->min_partition_order > MAX_PARTITION_ORDER) { 371 if (avctx->min_partition_order > MAX_PARTITION_ORDER) {
346 av_log(avctx, AV_LOG_ERROR, "invalid min partition order: %d\n", 372 av_log(avctx, AV_LOG_ERROR, "invalid min partition order: %d\n",
347 avctx->min_partition_order); 373 avctx->min_partition_order);
360 if (s->options.max_partition_order < s->options.min_partition_order) { 386 if (s->options.max_partition_order < s->options.min_partition_order) {
361 av_log(avctx, AV_LOG_ERROR, "invalid partition orders: min=%d max=%d\n", 387 av_log(avctx, AV_LOG_ERROR, "invalid partition orders: min=%d max=%d\n",
362 s->options.min_partition_order, s->options.max_partition_order); 388 s->options.min_partition_order, s->options.max_partition_order);
363 return -1; 389 return -1;
364 } 390 }
365 av_log(avctx, AV_LOG_DEBUG, " partition order: %d, %d\n",
366 s->options.min_partition_order, s->options.max_partition_order);
367 391
368 if (avctx->frame_size > 0) { 392 if (avctx->frame_size > 0) {
369 if (avctx->frame_size < FLAC_MIN_BLOCKSIZE || 393 if (avctx->frame_size < FLAC_MIN_BLOCKSIZE ||
370 avctx->frame_size > FLAC_MAX_BLOCKSIZE) { 394 avctx->frame_size > FLAC_MAX_BLOCKSIZE) {
371 av_log(avctx, AV_LOG_ERROR, "invalid block size: %d\n", 395 av_log(avctx, AV_LOG_ERROR, "invalid block size: %d\n",
374 } 398 }
375 } else { 399 } else {
376 s->avctx->frame_size = select_blocksize(s->samplerate, s->options.block_time_ms); 400 s->avctx->frame_size = select_blocksize(s->samplerate, s->options.block_time_ms);
377 } 401 }
378 s->max_blocksize = s->avctx->frame_size; 402 s->max_blocksize = s->avctx->frame_size;
379 av_log(avctx, AV_LOG_DEBUG, " block size: %d\n", s->avctx->frame_size);
380 403
381 /* set LPC precision */ 404 /* set LPC precision */
382 if (avctx->lpc_coeff_precision > 0) { 405 if (avctx->lpc_coeff_precision > 0) {
383 if (avctx->lpc_coeff_precision > MAX_LPC_PRECISION) { 406 if (avctx->lpc_coeff_precision > MAX_LPC_PRECISION) {
384 av_log(avctx, AV_LOG_ERROR, "invalid lpc coeff precision: %d\n", 407 av_log(avctx, AV_LOG_ERROR, "invalid lpc coeff precision: %d\n",
388 s->options.lpc_coeff_precision = avctx->lpc_coeff_precision; 411 s->options.lpc_coeff_precision = avctx->lpc_coeff_precision;
389 } else { 412 } else {
390 /* default LPC precision */ 413 /* default LPC precision */
391 s->options.lpc_coeff_precision = 15; 414 s->options.lpc_coeff_precision = 15;
392 } 415 }
393 av_log(avctx, AV_LOG_DEBUG, " lpc precision: %d\n",
394 s->options.lpc_coeff_precision);
395 416
396 /* set maximum encoded frame size in verbatim mode */ 417 /* set maximum encoded frame size in verbatim mode */
397 s->max_framesize = ff_flac_get_max_frame_size(s->avctx->frame_size, 418 s->max_framesize = ff_flac_get_max_frame_size(s->avctx->frame_size,
398 s->channels, 16); 419 s->channels, 16);
399 420
415 436
416 avctx->coded_frame = avcodec_alloc_frame(); 437 avctx->coded_frame = avcodec_alloc_frame();
417 if (!avctx->coded_frame) 438 if (!avctx->coded_frame)
418 return AVERROR(ENOMEM); 439 return AVERROR(ENOMEM);
419 avctx->coded_frame->key_frame = 1; 440 avctx->coded_frame->key_frame = 1;
441
442 dprint_compression_options(s);
420 443
421 return 0; 444 return 0;
422 } 445 }
423 446
424 447