mirror of
https://github.com/nyanmisaka/ffmpeg-rockchip.git
synced 2025-10-15 13:21:09 +08:00
avcodec/decode: Extend ff_hwaccel_frame_priv_alloc()'s task
All usages of ff_hwaccel_frame_priv_alloc() have the same pattern: Check for whether a hwaccel is in use; check whether it needs private frame-specific data; allocate the AVBuffer and set it. This commit modifies ff_hwaccel_frame_priv_alloc() to perform this task on its own. (It also seems that the H.264 decoder did not perform proper cleanup in case the buffer could not be allocated. This has been changed.) Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
@@ -1788,24 +1788,36 @@ int ff_copy_palette(void *dst, const AVPacket *src, void *logctx)
|
||||
return 0;
|
||||
}
|
||||
|
||||
AVBufferRef *ff_hwaccel_frame_priv_alloc(AVCodecContext *avctx,
|
||||
const AVHWAccel *hwaccel)
|
||||
int ff_hwaccel_frame_priv_alloc(AVCodecContext *avctx, void **hwaccel_picture_private,
|
||||
AVBufferRef **hwaccel_priv_buf)
|
||||
{
|
||||
const AVHWAccel *hwaccel = avctx->hwaccel;
|
||||
AVBufferRef *ref;
|
||||
AVHWFramesContext *frames_ctx = (AVHWFramesContext *)avctx->hw_frames_ctx->data;
|
||||
uint8_t *data = av_mallocz(hwaccel->frame_priv_data_size);
|
||||
AVHWFramesContext *frames_ctx;
|
||||
uint8_t *data;
|
||||
|
||||
if (!hwaccel || !hwaccel->frame_priv_data_size)
|
||||
return 0;
|
||||
|
||||
av_assert0(!*hwaccel_picture_private);
|
||||
data = av_mallocz(hwaccel->frame_priv_data_size);
|
||||
if (!data)
|
||||
return NULL;
|
||||
return AVERROR(ENOMEM);
|
||||
|
||||
frames_ctx = (AVHWFramesContext *)avctx->hw_frames_ctx->data;
|
||||
|
||||
ref = av_buffer_create(data, hwaccel->frame_priv_data_size,
|
||||
hwaccel->free_frame_priv,
|
||||
frames_ctx->device_ctx, 0);
|
||||
if (!ref) {
|
||||
av_free(data);
|
||||
return NULL;
|
||||
return AVERROR(ENOMEM);
|
||||
}
|
||||
|
||||
return ref;
|
||||
*hwaccel_priv_buf = ref;
|
||||
*hwaccel_picture_private = ref->data;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ff_decode_flush_buffers(AVCodecContext *avctx)
|
||||
|
Reference in New Issue
Block a user