Skip to content

Commit

Permalink
avformat: add ff_alloc_extradata() helper
Browse files Browse the repository at this point in the history
Signed-off-by: Paul B Mahol <[email protected]>
  • Loading branch information
richardpl committed Oct 13, 2013
1 parent fe448cd commit 3fd7983
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
9 changes: 9 additions & 0 deletions libavformat/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -361,4 +361,13 @@ AVRational ff_choose_timebase(AVFormatContext *s, AVStream *st, int min_precissi
*/
void ff_generate_avci_extradata(AVStream *st);

/**
* Allocate extradata with additional FF_INPUT_BUFFER_PADDING_SIZE at end
* which is always set to 0.
*
* @param size size of extradata
* @return 0 if OK, AVERROR_xxx on error
*/
int ff_alloc_extradata(AVCodecContext *avctx, int size);

#endif /* AVFORMAT_INTERNAL_H */
20 changes: 20 additions & 0 deletions libavformat/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -2678,6 +2678,26 @@ int av_find_stream_info(AVFormatContext *ic)
}
#endif

int ff_alloc_extradata(AVCodecContext *avctx, int size)
{
int ret;

if (size < 0 || size >= INT32_MAX - FF_INPUT_BUFFER_PADDING_SIZE) {
avctx->extradata_size = 0;
return AVERROR(EINVAL);
}
avctx->extradata = av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE);
if (avctx->extradata) {
memset(avctx->extradata + size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
avctx->extradata_size = size;
ret = 0;
} else {
avctx->extradata_size = 0;
ret = AVERROR(ENOMEM);
}
return ret;
}

int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
{
int i, count, ret = 0, j;
Expand Down

0 comments on commit 3fd7983

Please sign in to comment.