diff options
author | Reimar Döffinger <Reimar.Doeffinger@gmx.de> | 2016-02-26 18:38:19 +0100 |
---|---|---|
committer | Reimar Döffinger <Reimar.Doeffinger@gmx.de> | 2016-02-28 13:33:14 +0100 |
commit | 4dd4d535313016cf934a187ba8f46e51b583cfb9 (patch) | |
tree | 9cc4cf77a540f13782400a73b0020637a54e72ba /libavcodec/utils.c | |
parent | 45fa03b1f9b0475df666f7592f250c37763b7d64 (diff) | |
download | ffmpeg-streaming-4dd4d535313016cf934a187ba8f46e51b583cfb9.zip ffmpeg-streaming-4dd4d535313016cf934a187ba8f46e51b583cfb9.tar.gz |
Document and validate AVFrame plane pointers.
Check that the required plane pointers and only
those are set up.
Currently does not enforce anything for the palette
pointer of pseudopal formats as I am unsure about the
requirements.
Signed-off-by: Reimar Döffinger <Reimar.Doeffinger@gmx.de>
Diffstat (limited to 'libavcodec/utils.c')
-rw-r--r-- | libavcodec/utils.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/libavcodec/utils.c b/libavcodec/utils.c index 5791ffa..b1ba51e 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -853,6 +853,30 @@ int ff_decode_frame_props(AVCodecContext *avctx, AVFrame *frame) return ff_init_buffer_info(avctx, frame); } +static void validate_avframe_allocation(AVCodecContext *avctx, AVFrame *frame) +{ + if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) { + int i; + int num_planes = av_pix_fmt_count_planes(frame->format); + const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format); + int flags = desc ? desc->flags : 0; + if (num_planes == 1 && (flags & AV_PIX_FMT_FLAG_PAL)) + num_planes = 2; + for (i = 0; i < num_planes; i++) { + av_assert0(frame->data[i]); + } + // For now do not enforce anything for palette of pseudopal formats + if (num_planes == 1 && (flags & AV_PIX_FMT_FLAG_PSEUDOPAL)) + num_planes = 2; + // For formats without data like hwaccel allow unused pointers to be non-NULL. + for (i = num_planes; num_planes > 0 && i < FF_ARRAY_ELEMS(frame->data); i++) { + if (frame->data[i]) + av_log(avctx, AV_LOG_ERROR, "Buffer returned by get_buffer2() did not zero unused plane pointers\n"); + frame->data[i] = NULL; + } + } +} + static int get_buffer_internal(AVCodecContext *avctx, AVFrame *frame, int flags) { const AVHWAccel *hwaccel = avctx->hwaccel; @@ -889,6 +913,8 @@ static int get_buffer_internal(AVCodecContext *avctx, AVFrame *frame, int flags) avctx->sw_pix_fmt = avctx->pix_fmt; ret = avctx->get_buffer2(avctx, frame, flags); + if (ret >= 0) + validate_avframe_allocation(avctx, frame); end: if (avctx->codec_type == AVMEDIA_TYPE_VIDEO && !override_dimensions) { |