diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2012-03-22 03:55:21 +0100 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2012-03-22 19:03:18 +0100 |
commit | 00663de3b752fc3bdd47d4516ad2fcc720722782 (patch) | |
tree | 989cf29bf63f92b0e37c26351f1bafced378ad1e /libavcodec/utils.c | |
parent | 6c9db40205d5c0cf40c13bf34c0a1c39a310de50 (diff) | |
download | ffmpeg-00663de3b752fc3bdd47d4516ad2fcc720722782.tar.gz |
lavc: add ff_alloc_packet2().
This contains a AVCodecContext thus allowing us to prevent the
error message duplication
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavcodec/utils.c')
-rw-r--r-- | libavcodec/utils.c | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/libavcodec/utils.c b/libavcodec/utils.c index b5570aac6e..929376ecc5 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -939,26 +939,38 @@ free_and_end: goto end; } -int ff_alloc_packet(AVPacket *avpkt, int size) +int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int size) { - if (size > INT_MAX - FF_INPUT_BUFFER_PADDING_SIZE) + if (size < 0 || avpkt->size < 0 || size > INT_MAX - FF_INPUT_BUFFER_PADDING_SIZE) { + av_log(avctx, AV_LOG_ERROR, "Size %d invalid\n", size); return AVERROR(EINVAL); + } if (avpkt->data) { void *destruct = avpkt->destruct; - if (avpkt->size < size) + if (avpkt->size < size) { + av_log(avctx, AV_LOG_ERROR, "User packet is too small (%d < %d)\n", avpkt->size, size); return AVERROR(EINVAL); + } av_init_packet(avpkt); avpkt->destruct = destruct; avpkt->size = size; return 0; } else { - return av_new_packet(avpkt, size); + int ret = av_new_packet(avpkt, size); + if (ret < 0) + av_log(avctx, AV_LOG_ERROR, "Failed to allocate packet of size %d\n", size); + return ret; } } +int ff_alloc_packet(AVPacket *avpkt, int size) +{ + return ff_alloc_packet2(NULL, avpkt, size); +} + int attribute_align_arg avcodec_encode_audio2(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, |