Commit 9e28e003 authored by Nicolas George's avatar Nicolas George

lavc/flacenc: improve error return.

Use meaningful error codes and add log messages.
parent 11ab2c25
...@@ -248,8 +248,11 @@ static av_cold int flac_encode_init(AVCodecContext *avctx) ...@@ -248,8 +248,11 @@ static av_cold int flac_encode_init(AVCodecContext *avctx)
break; break;
} }
if (channels < 1 || channels > FLAC_MAX_CHANNELS) if (channels < 1 || channels > FLAC_MAX_CHANNELS) {
return -1; av_log(avctx, AV_LOG_ERROR, "%d channels not supported (max %d)\n",
channels, FLAC_MAX_CHANNELS);
return AVERROR(EINVAL);
}
s->channels = channels; s->channels = channels;
/* find samplerate in table */ /* find samplerate in table */
...@@ -275,7 +278,8 @@ static av_cold int flac_encode_init(AVCodecContext *avctx) ...@@ -275,7 +278,8 @@ static av_cold int flac_encode_init(AVCodecContext *avctx)
s->sr_code[0] = 13; s->sr_code[0] = 13;
s->sr_code[1] = freq; s->sr_code[1] = freq;
} else { } else {
return -1; av_log(avctx, AV_LOG_ERROR, "%d Hz not supported\n", freq);
return AVERROR(EINVAL);
} }
s->samplerate = freq; s->samplerate = freq;
} }
...@@ -290,7 +294,7 @@ static av_cold int flac_encode_init(AVCodecContext *avctx) ...@@ -290,7 +294,7 @@ static av_cold int flac_encode_init(AVCodecContext *avctx)
if (level > 12) { if (level > 12) {
av_log(avctx, AV_LOG_ERROR, "invalid compression level: %d\n", av_log(avctx, AV_LOG_ERROR, "invalid compression level: %d\n",
s->options.compression_level); s->options.compression_level);
return -1; return AVERROR(EINVAL);
} }
s->options.block_time_ms = ((int[]){ 27, 27, 27,105,105,105,105,105,105,105,105,105,105})[level]; s->options.block_time_ms = ((int[]){ 27, 27, 27,105,105,105,105,105,105,105,105,105,105})[level];
...@@ -329,13 +333,13 @@ static av_cold int flac_encode_init(AVCodecContext *avctx) ...@@ -329,13 +333,13 @@ static av_cold int flac_encode_init(AVCodecContext *avctx)
if (avctx->min_prediction_order > MAX_FIXED_ORDER) { if (avctx->min_prediction_order > MAX_FIXED_ORDER) {
av_log(avctx, AV_LOG_ERROR, "invalid min prediction order: %d\n", av_log(avctx, AV_LOG_ERROR, "invalid min prediction order: %d\n",
avctx->min_prediction_order); avctx->min_prediction_order);
return -1; return AVERROR(EINVAL);
} }
} else if (avctx->min_prediction_order < MIN_LPC_ORDER || } else if (avctx->min_prediction_order < MIN_LPC_ORDER ||
avctx->min_prediction_order > MAX_LPC_ORDER) { avctx->min_prediction_order > MAX_LPC_ORDER) {
av_log(avctx, AV_LOG_ERROR, "invalid min prediction order: %d\n", av_log(avctx, AV_LOG_ERROR, "invalid min prediction order: %d\n",
avctx->min_prediction_order); avctx->min_prediction_order);
return -1; return AVERROR(EINVAL);
} }
s->options.min_prediction_order = avctx->min_prediction_order; s->options.min_prediction_order = avctx->min_prediction_order;
} }
...@@ -346,20 +350,20 @@ static av_cold int flac_encode_init(AVCodecContext *avctx) ...@@ -346,20 +350,20 @@ static av_cold int flac_encode_init(AVCodecContext *avctx)
if (avctx->max_prediction_order > MAX_FIXED_ORDER) { if (avctx->max_prediction_order > MAX_FIXED_ORDER) {
av_log(avctx, AV_LOG_ERROR, "invalid max prediction order: %d\n", av_log(avctx, AV_LOG_ERROR, "invalid max prediction order: %d\n",
avctx->max_prediction_order); avctx->max_prediction_order);
return -1; return AVERROR(EINVAL);
} }
} else if (avctx->max_prediction_order < MIN_LPC_ORDER || } else if (avctx->max_prediction_order < MIN_LPC_ORDER ||
avctx->max_prediction_order > MAX_LPC_ORDER) { avctx->max_prediction_order > MAX_LPC_ORDER) {
av_log(avctx, AV_LOG_ERROR, "invalid max prediction order: %d\n", av_log(avctx, AV_LOG_ERROR, "invalid max prediction order: %d\n",
avctx->max_prediction_order); avctx->max_prediction_order);
return -1; return AVERROR(EINVAL);
} }
s->options.max_prediction_order = avctx->max_prediction_order; s->options.max_prediction_order = avctx->max_prediction_order;
} }
if (s->options.max_prediction_order < s->options.min_prediction_order) { if (s->options.max_prediction_order < s->options.min_prediction_order) {
av_log(avctx, AV_LOG_ERROR, "invalid prediction orders: min=%d max=%d\n", av_log(avctx, AV_LOG_ERROR, "invalid prediction orders: min=%d max=%d\n",
s->options.min_prediction_order, s->options.max_prediction_order); s->options.min_prediction_order, s->options.max_prediction_order);
return -1; return AVERROR(EINVAL);
} }
if (avctx->frame_size > 0) { if (avctx->frame_size > 0) {
...@@ -367,7 +371,7 @@ static av_cold int flac_encode_init(AVCodecContext *avctx) ...@@ -367,7 +371,7 @@ static av_cold int flac_encode_init(AVCodecContext *avctx)
avctx->frame_size > FLAC_MAX_BLOCKSIZE) { avctx->frame_size > FLAC_MAX_BLOCKSIZE) {
av_log(avctx, AV_LOG_ERROR, "invalid block size: %d\n", av_log(avctx, AV_LOG_ERROR, "invalid block size: %d\n",
avctx->frame_size); avctx->frame_size);
return -1; return AVERROR(EINVAL);
} }
} else { } else {
s->avctx->frame_size = select_blocksize(s->samplerate, s->options.block_time_ms); s->avctx->frame_size = select_blocksize(s->samplerate, s->options.block_time_ms);
......
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