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.

Mark Thompson committed 9 years ago

Commit c5714b51 parent e1c5d565 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
@@ -13,6 +13,10 @@ libavutil: 2017-03-23 · 12 unmodified lines
13 13
14API changes, most recent first:14API changes, most recent first:
15 15
162017-04-30 - xxxxxxx - lavu 56.1.1 - hwcontext.h
17 av_hwframe_ctx_create_derived() now takes some AV_HWFRAME_MAP_* combination
18 as its flags argument (which was previously unused).
19
162017-04-xx - xxxxxxx - lavu 56.1.0 - spherical.h202017-04-xx - xxxxxxx - lavu 56.1.0 - spherical.h
17 Add av_spherical_projection_name() and av_spherical_from_name().21 Add av_spherical_projection_name() and av_spherical_from_name().
18 22
libavutil/hwcontext.c+13−1
@@ -455,6 +455,11 @@ int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, AVFrame *frame, int flags) · 454 unmodified lines
455 // and map the frame immediately.455 // and map the frame immediately.
456 AVFrame *src_frame;456 AVFrame *src_frame;
457 457
458 frame->format = ctx->format;
459 frame->hw_frames_ctx = av_buffer_ref(hwframe_ref);
460 if (!frame->hw_frames_ctx)
461 return AVERROR(ENOMEM);
462
458 src_frame = av_frame_alloc();463 src_frame = av_frame_alloc();
459 if (!src_frame)464 if (!src_frame)
460 return AVERROR(ENOMEM);465 return AVERROR(ENOMEM);
@@ -464,7 +469,8 @@ int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, AVFrame *frame, int flags) · 3 unmodified lines
464 if (ret < 0)469 if (ret < 0)
465 return ret;470 return ret;
466 471
467 ret = av_hwframe_map(frame, src_frame, 0);472 ret = av_hwframe_map(frame, src_frame,
473 ctx->internal->source_allocation_map_flags);
468 if (ret) {474 if (ret) {
469 av_log(ctx, AV_LOG_ERROR, "Failed to map frame into derived "475 av_log(ctx, AV_LOG_ERROR, "Failed to map frame into derived "
470 "frame context: %d.\n", ret);476 "frame context: %d.\n", ret);
@@ -816,6 +822,12 @@ int av_hwframe_ctx_create_derived(AVBufferRef **derived_frame_ctx, · 345 unmodified lines
816 goto fail;822 goto fail;
817 }823 }
818 824
825 dst->internal->source_allocation_map_flags =
826 flags & (AV_HWFRAME_MAP_READ |
827 AV_HWFRAME_MAP_WRITE |
828 AV_HWFRAME_MAP_OVERWRITE |
829 AV_HWFRAME_MAP_DIRECT);
830
819 ret = AVERROR(ENOSYS);831 ret = AVERROR(ENOSYS);
820 if (src->internal->hw_type->frames_derive_from)832 if (src->internal->hw_type->frames_derive_from)
821 ret = src->internal->hw_type->frames_derive_from(dst, src, flags);833 ret = src->internal->hw_type->frames_derive_from(dst, src, flags);
libavutil/hwcontext.h+3−1
@@ -564,7 +564,9 @@ int av_hwframe_map(AVFrame *dst, const AVFrame *src, int flags); · 563 unmodified lines
564 * AVHWFramesContext on.564 * AVHWFramesContext on.
565 * @param source_frame_ctx A reference to an existing AVHWFramesContext565 * @param source_frame_ctx A reference to an existing AVHWFramesContext
566 * which will be mapped to the derived context.566 * which will be mapped to the derived context.
567 * @param flags Currently unused; should be set to zero.567 * @param flags Some combination of AV_HWFRAME_MAP_* flags, defining the
568 * mapping parameters to apply to frames which are allocated
569 * in the derived device.
568 * @return Zero on success, negative AVERROR code on failure.570 * @return Zero on success, negative AVERROR code on failure.
569 */571 */
570int av_hwframe_ctx_create_derived(AVBufferRef **derived_frame_ctx,572int 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
@@ -55,7 +55,7 @@ · 54 unmodified lines
55 55
56#define LIBAVUTIL_VERSION_MAJOR 5656#define LIBAVUTIL_VERSION_MAJOR 56
57#define LIBAVUTIL_VERSION_MINOR 157#define LIBAVUTIL_VERSION_MINOR 1
58#define LIBAVUTIL_VERSION_MICRO 058#define LIBAVUTIL_VERSION_MICRO 1
59 59
60#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \60#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
61 LIBAVUTIL_VERSION_MINOR, \61 LIBAVUTIL_VERSION_MINOR, \

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