mirror of
https://git.ffmpeg.org/ffmpeg.git
synced 2026-01-06 14:15:29 +01:00
avcodec/decode: add a flags parameter to ff_reget_buffer()
Some decoders may not need a writable buffer in some specific cases, but only a reference to the existing buffer with updated frame properties instead, for the purpose of returning duplicate frames. For this, the FF_REGET_BUFFER_FLAG_READONLY flag is added, which will prevent potential allocations and buffer copies when they are not needed. Signed-off-by: James Almer <jamrial@gmail.com>
This commit is contained in:
@@ -1970,7 +1970,7 @@ int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int reget_buffer_internal(AVCodecContext *avctx, AVFrame *frame)
|
||||
static int reget_buffer_internal(AVCodecContext *avctx, AVFrame *frame, int flags)
|
||||
{
|
||||
AVFrame *tmp;
|
||||
int ret;
|
||||
@@ -1986,7 +1986,7 @@ static int reget_buffer_internal(AVCodecContext *avctx, AVFrame *frame)
|
||||
if (!frame->data[0])
|
||||
return ff_get_buffer(avctx, frame, AV_GET_BUFFER_FLAG_REF);
|
||||
|
||||
if (av_frame_is_writable(frame))
|
||||
if ((flags & FF_REGET_BUFFER_FLAG_READONLY) || av_frame_is_writable(frame))
|
||||
return ff_decode_frame_props(avctx, frame);
|
||||
|
||||
tmp = av_frame_alloc();
|
||||
@@ -2007,9 +2007,9 @@ static int reget_buffer_internal(AVCodecContext *avctx, AVFrame *frame)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ff_reget_buffer(AVCodecContext *avctx, AVFrame *frame)
|
||||
int ff_reget_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
|
||||
{
|
||||
int ret = reget_buffer_internal(avctx, frame);
|
||||
int ret = reget_buffer_internal(avctx, frame, flags);
|
||||
if (ret < 0)
|
||||
av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
|
||||
return ret;
|
||||
|
||||
Reference in New Issue
Block a user