summaryrefslogtreecommitdiff
path: root/libavutil/hwcontext.c
diff options
context:
space:
mode:
authorMark Thompson <sw@jkqxz.net>2017-03-04 23:57:40 +0000
committerMark Thompson <sw@jkqxz.net>2017-06-14 22:27:32 +0100
commitd59c6a3aebc20cc64cb7a46401cb55f02f4cbe09 (patch)
tree93d7c8e3cb688736da2b691f14546d86530ac4d4 /libavutil/hwcontext.c
parenta97fb14418fd621defec1ea5cd387953407b180d (diff)
hwcontext: Improve allocation in derived contexts
Use the flags argument of av_hwframe_ctx_create_derived() to pass the mapping flags which will be used on allocation. Also, set the format and hardware context on the allocated frame automatically - the user should not be required to do this themselves. (cherry picked from commit c5714b51aad41fef56dddac1d542e7fc6b984627)
Diffstat (limited to 'libavutil/hwcontext.c')
-rw-r--r--libavutil/hwcontext.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/libavutil/hwcontext.c b/libavutil/hwcontext.c
index ed09c49f2d..5a22194716 100644
--- a/libavutil/hwcontext.c
+++ b/libavutil/hwcontext.c
@@ -458,6 +458,11 @@ int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, AVFrame *frame, int flags)
// and map the frame immediately.
AVFrame *src_frame;
+ frame->format = ctx->format;
+ frame->hw_frames_ctx = av_buffer_ref(hwframe_ref);
+ if (!frame->hw_frames_ctx)
+ return AVERROR(ENOMEM);
+
src_frame = av_frame_alloc();
if (!src_frame)
return AVERROR(ENOMEM);
@@ -467,7 +472,8 @@ int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, AVFrame *frame, int flags)
if (ret < 0)
return ret;
- ret = av_hwframe_map(frame, src_frame, 0);
+ ret = av_hwframe_map(frame, src_frame,
+ ctx->internal->source_allocation_map_flags);
if (ret) {
av_log(ctx, AV_LOG_ERROR, "Failed to map frame into derived "
"frame context: %d.\n", ret);
@@ -819,6 +825,12 @@ int av_hwframe_ctx_create_derived(AVBufferRef **derived_frame_ctx,
goto fail;
}
+ dst->internal->source_allocation_map_flags =
+ flags & (AV_HWFRAME_MAP_READ |
+ AV_HWFRAME_MAP_WRITE |
+ AV_HWFRAME_MAP_OVERWRITE |
+ AV_HWFRAME_MAP_DIRECT);
+
ret = AVERROR(ENOSYS);
if (src->internal->hw_type->frames_derive_from)
ret = src->internal->hw_type->frames_derive_from(dst, src, flags);