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>
This commit is contained in:
parent
6c9db40205
commit
00663de3b7
@ -127,6 +127,7 @@ int avpriv_unlock_avformat(void);
|
|||||||
* ensure the output packet data is large enough, whether provided by the user
|
* ensure the output packet data is large enough, whether provided by the user
|
||||||
* or allocated in this function.
|
* or allocated in this function.
|
||||||
*
|
*
|
||||||
|
* @param avctx the AVCodecContext of the encoder
|
||||||
* @param avpkt the AVPacket
|
* @param avpkt the AVPacket
|
||||||
* If avpkt->data is already set, avpkt->size is checked
|
* If avpkt->data is already set, avpkt->size is checked
|
||||||
* to ensure it is large enough.
|
* to ensure it is large enough.
|
||||||
@ -136,6 +137,8 @@ int avpriv_unlock_avformat(void);
|
|||||||
* @param size the minimum required packet size
|
* @param size the minimum required packet size
|
||||||
* @return 0 on success, negative error code on failure
|
* @return 0 on success, negative error code on failure
|
||||||
*/
|
*/
|
||||||
|
int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int size);
|
||||||
|
|
||||||
int ff_alloc_packet(AVPacket *avpkt, int size);
|
int ff_alloc_packet(AVPacket *avpkt, int size);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -939,26 +939,38 @@ free_and_end:
|
|||||||
goto 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);
|
return AVERROR(EINVAL);
|
||||||
|
}
|
||||||
|
|
||||||
if (avpkt->data) {
|
if (avpkt->data) {
|
||||||
void *destruct = avpkt->destruct;
|
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);
|
return AVERROR(EINVAL);
|
||||||
|
}
|
||||||
|
|
||||||
av_init_packet(avpkt);
|
av_init_packet(avpkt);
|
||||||
avpkt->destruct = destruct;
|
avpkt->destruct = destruct;
|
||||||
avpkt->size = size;
|
avpkt->size = size;
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} 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,
|
int attribute_align_arg avcodec_encode_audio2(AVCodecContext *avctx,
|
||||||
AVPacket *avpkt,
|
AVPacket *avpkt,
|
||||||
const AVFrame *frame,
|
const AVFrame *frame,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user