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)
Unified · Split
| @@ -15,6 +15,10 @@ libavutil: 2015-08-28 · 14 unmodified lines | ||
| 15 | 15 | |
| 16 | 16 | API changes, most recent first: |
| 17 | 17 | |
| 18 | +2017-06-14 - xxxxxxx - lavu 55.66.100 - hwcontext.h | |
| 19 | + av_hwframe_ctx_create_derived() now takes some AV_HWFRAME_MAP_* combination | |
| 20 | + as its flags argument (which was previously unused). | |
| 21 | + | |
| 18 | 22 | 2017-06-14 - xxxxxxx - lavc 57.99.100 - avcodec.h |
| 19 | 23 | Add AV_HWACCEL_FLAG_ALLOW_PROFILE_MISMATCH. |
| 20 | 24 | |
| @@ -458,6 +458,11 @@ int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, AVFrame *frame, int flags) · 457 unmodified lines | ||
| 458 | 458 | // and map the frame immediately. |
| 459 | 459 | AVFrame *src_frame; |
| 460 | 460 | |
| 461 | + frame->format = ctx->format; | |
| 462 | + frame->hw_frames_ctx = av_buffer_ref(hwframe_ref); | |
| 463 | + if (!frame->hw_frames_ctx) | |
| 464 | + return AVERROR(ENOMEM); | |
| 465 | + | |
| 461 | 466 | src_frame = av_frame_alloc(); |
| 462 | 467 | if (!src_frame) |
| 463 | 468 | return AVERROR(ENOMEM); |
| @@ -467,7 +472,8 @@ int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, AVFrame *frame, int flags) · 3 unmodified lines | ||
| 467 | 472 | if (ret < 0) |
| 468 | 473 | return ret; |
| 469 | 474 | |
| 470 | − ret = av_hwframe_map(frame, src_frame, 0); | |
| 475 | + ret = av_hwframe_map(frame, src_frame, | |
| 476 | + ctx->internal->source_allocation_map_flags); | |
| 471 | 477 | if (ret) { |
| 472 | 478 | av_log(ctx, AV_LOG_ERROR, "Failed to map frame into derived " |
| 473 | 479 | "frame context: %d.\n", ret); |
| @@ -819,6 +825,12 @@ int av_hwframe_ctx_create_derived(AVBufferRef **derived_frame_ctx, · 345 unmodified lines | ||
| 819 | 825 | goto fail; |
| 820 | 826 | } |
| 821 | 827 | |
| 828 | + dst->internal->source_allocation_map_flags = | |
| 829 | + flags & (AV_HWFRAME_MAP_READ | | |
| 830 | + AV_HWFRAME_MAP_WRITE | | |
| 831 | + AV_HWFRAME_MAP_OVERWRITE | | |
| 832 | + AV_HWFRAME_MAP_DIRECT); | |
| 833 | + | |
| 822 | 834 | ret = AVERROR(ENOSYS); |
| 823 | 835 | if (src->internal->hw_type->frames_derive_from) |
| 824 | 836 | ret = src->internal->hw_type->frames_derive_from(dst, src, flags); |
| @@ -566,7 +566,9 @@ int av_hwframe_map(AVFrame *dst, const AVFrame *src, int flags); · 565 unmodified lines | ||
| 566 | 566 | * AVHWFramesContext on. |
| 567 | 567 | * @param source_frame_ctx A reference to an existing AVHWFramesContext |
| 568 | 568 | * which will be mapped to the derived context. |
| 569 | − * @param flags Currently unused; should be set to zero. | |
| 569 | + * @param flags Some combination of AV_HWFRAME_MAP_* flags, defining the | |
| 570 | + * mapping parameters to apply to frames which are allocated | |
| 571 | + * in the derived device. | |
| 570 | 572 | * @return Zero on success, negative AVERROR code on failure. |
| 571 | 573 | */ |
| 572 | 574 | int av_hwframe_ctx_create_derived(AVBufferRef **derived_frame_ctx, |
| @@ -121,6 +121,11 @@ struct AVHWFramesInternal { · 120 unmodified lines | ||
| 121 | 121 | * context it was derived from. |
| 122 | 122 | */ |
| 123 | 123 | AVBufferRef *source_frames; |
| 124 | + /** | |
| 125 | + * Flags to apply to the mapping from the source to the derived | |
| 126 | + * frame context when trying to allocate in the derived context. | |
| 127 | + */ | |
| 128 | + int source_allocation_map_flags; | |
| 124 | 129 | }; |
| 125 | 130 | |
| 126 | 131 | typedef struct HWMapDescriptor { |
| @@ -80,7 +80,7 @@ · 79 unmodified lines | ||
| 80 | 80 | |
| 81 | 81 | |
| 82 | 82 | #define LIBAVUTIL_VERSION_MAJOR 55 |
| 83 | −#define LIBAVUTIL_VERSION_MINOR 65 | |
| 83 | +#define LIBAVUTIL_VERSION_MINOR 66 | |
| 84 | 84 | #define LIBAVUTIL_VERSION_MICRO 100 |
| 85 | 85 | |
| 86 | 86 | #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ |