History

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)

Mark Thompson committed 9 years ago

Commit d59c6a31 parent a97fb145 files · +26 −3Browse files

Unified · Split

5 files
  1. doc/APIchanges +4 −0
  2. libavutil/hwcontext.c +13 −1
  3. libavutil/hwcontext.h +3 −1
  4. libavutil/hwcontext_internal.h +5 −0
  5. libavutil/version.h +1 −1
doc/APIchanges+4−0
@@ -15,6 +15,10 @@ libavutil: 2015-08-28 · 14 unmodified lines
15 15
16API changes, most recent first:16API changes, most recent first:
17 17
182017-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
182017-06-14 - xxxxxxx - lavc 57.99.100 - avcodec.h222017-06-14 - xxxxxxx - lavc 57.99.100 - avcodec.h
19 Add AV_HWACCEL_FLAG_ALLOW_PROFILE_MISMATCH.23 Add AV_HWACCEL_FLAG_ALLOW_PROFILE_MISMATCH.
20 24
libavutil/hwcontext.c+13−1
@@ -458,6 +458,11 @@ int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, AVFrame *frame, int flags) · 457 unmodified lines
458 // and map the frame immediately.458 // and map the frame immediately.
459 AVFrame *src_frame;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 src_frame = av_frame_alloc();466 src_frame = av_frame_alloc();
462 if (!src_frame)467 if (!src_frame)
463 return AVERROR(ENOMEM);468 return AVERROR(ENOMEM);
@@ -467,7 +472,8 @@ int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, AVFrame *frame, int flags) · 3 unmodified lines
467 if (ret < 0)472 if (ret < 0)
468 return ret;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 if (ret) {477 if (ret) {
472 av_log(ctx, AV_LOG_ERROR, "Failed to map frame into derived "478 av_log(ctx, AV_LOG_ERROR, "Failed to map frame into derived "
473 "frame context: %d.\n", ret);479 "frame context: %d.\n", ret);
@@ -819,6 +825,12 @@ int av_hwframe_ctx_create_derived(AVBufferRef **derived_frame_ctx, · 345 unmodified lines
819 goto fail;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 ret = AVERROR(ENOSYS);834 ret = AVERROR(ENOSYS);
823 if (src->internal->hw_type->frames_derive_from)835 if (src->internal->hw_type->frames_derive_from)
824 ret = src->internal->hw_type->frames_derive_from(dst, src, flags);836 ret = src->internal->hw_type->frames_derive_from(dst, src, flags);
libavutil/hwcontext.h+3−1
@@ -566,7 +566,9 @@ int av_hwframe_map(AVFrame *dst, const AVFrame *src, int flags); · 565 unmodified lines
566 * AVHWFramesContext on.566 * AVHWFramesContext on.
567 * @param source_frame_ctx A reference to an existing AVHWFramesContext567 * @param source_frame_ctx A reference to an existing AVHWFramesContext
568 * which will be mapped to the derived context.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 * @return Zero on success, negative AVERROR code on failure.572 * @return Zero on success, negative AVERROR code on failure.
571 */573 */
572int av_hwframe_ctx_create_derived(AVBufferRef **derived_frame_ctx,574int av_hwframe_ctx_create_derived(AVBufferRef **derived_frame_ctx,
libavutil/hwcontext_internal.h+5−0
@@ -121,6 +121,11 @@ struct AVHWFramesInternal { · 120 unmodified lines
121 * context it was derived from.121 * context it was derived from.
122 */122 */
123 AVBufferRef *source_frames;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
126typedef struct HWMapDescriptor {131typedef struct HWMapDescriptor {
libavutil/version.h+1−1
@@ -80,7 +80,7 @@ · 79 unmodified lines
80 80
81 81
82#define LIBAVUTIL_VERSION_MAJOR 5582#define LIBAVUTIL_VERSION_MAJOR 55
83#define LIBAVUTIL_VERSION_MINOR 6583#define LIBAVUTIL_VERSION_MINOR 66
84#define LIBAVUTIL_VERSION_MICRO 10084#define LIBAVUTIL_VERSION_MICRO 100
85 85
86#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \86#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t