summaryrefslogtreecommitdiff
path: root/libavcodec/utils.c
diff options
context:
space:
mode:
authorJustin Ruggles <justin.ruggles@gmail.com>2011-04-19 18:50:20 -0400
committerJustin Ruggles <justin.ruggles@gmail.com>2011-04-27 12:57:42 -0400
commit8b00ab0113a8ca40429e0a06331be83996963a9e (patch)
tree37f89d8a6c6a35c9b1f8816e898d0f91e209f805 /libavcodec/utils.c
parent767848d7619ce43e00d1a13607a5cf2aa61d2d6e (diff)
Check AVCodec.supported_samplerates and AVCodec.channel_layouts in
avcodec_open(). If the encoder has a channel_layouts list and AVCodecContext.channel_layout is 0, then only print a warning and let the encoder decide how to handle it.
Diffstat (limited to 'libavcodec/utils.c')
-rw-r--r--libavcodec/utils.c28
1 files changed, 27 insertions, 1 deletions
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index 7e2847afb1..915fb31bc6 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -542,8 +542,9 @@ int attribute_align_arg avcodec_open(AVCodecContext *avctx, AVCodec *codec)
ret = AVERROR(EINVAL);
goto free_and_end;
}
- if (avctx->codec->sample_fmts && avctx->codec->encode) {
+ if (avctx->codec->encode) {
int i;
+ if (avctx->codec->sample_fmts) {
for (i = 0; avctx->codec->sample_fmts[i] != AV_SAMPLE_FMT_NONE; i++)
if (avctx->sample_fmt == avctx->codec->sample_fmts[i])
break;
@@ -552,6 +553,31 @@ int attribute_align_arg avcodec_open(AVCodecContext *avctx, AVCodec *codec)
ret = AVERROR(EINVAL);
goto free_and_end;
}
+ }
+ if (avctx->codec->supported_samplerates) {
+ for (i = 0; avctx->codec->supported_samplerates[i] != 0; i++)
+ if (avctx->sample_rate == avctx->codec->supported_samplerates[i])
+ break;
+ if (avctx->codec->supported_samplerates[i] == 0) {
+ av_log(avctx, AV_LOG_ERROR, "Specified sample_rate is not supported\n");
+ ret = AVERROR(EINVAL);
+ goto free_and_end;
+ }
+ }
+ if (avctx->codec->channel_layouts) {
+ if (!avctx->channel_layout) {
+ av_log(avctx, AV_LOG_WARNING, "channel_layout not specified\n");
+ } else {
+ for (i = 0; avctx->codec->channel_layouts[i] != 0; i++)
+ if (avctx->channel_layout == avctx->codec->channel_layouts[i])
+ break;
+ if (avctx->codec->channel_layouts[i] == 0) {
+ av_log(avctx, AV_LOG_ERROR, "Specified channel_layout is not supported\n");
+ ret = AVERROR(EINVAL);
+ goto free_and_end;
+ }
+ }
+ }
}
if(avctx->codec->init && !(avctx->active_thread_type&FF_THREAD_FRAME)){