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
1313
1414 API changes, most recent first:
1515
16+2017-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+
1620 2017-04-xx - xxxxxxx - lavu 56.1.0 - spherical.h
1721 Add av_spherical_projection_name() and av_spherical_from_name().
1822
libavutil/hwcontext.c+13−1
@@ -455,6 +455,11 @@ int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, AVFrame *frame, int flags) · 454 unmodified lines
455455 // and map the frame immediately.
456456 AVFrame *src_frame;
457457
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+
458463 src_frame = av_frame_alloc();
459464 if (!src_frame)
460465 return AVERROR(ENOMEM);
@@ -464,7 +469,8 @@ int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, AVFrame *frame, int flags) · 3 unmodified lines
464469 if (ret < 0)
465470 return ret;
466471
467− ret = av_hwframe_map(frame, src_frame, 0);
472+ ret = av_hwframe_map(frame, src_frame,
473+ ctx->internal->source_allocation_map_flags);
468474 if (ret) {
469475 av_log(ctx, AV_LOG_ERROR, "Failed to map frame into derived "
470476 "frame context: %d.\n", ret);
@@ -816,6 +822,12 @@ int av_hwframe_ctx_create_derived(AVBufferRef **derived_frame_ctx, · 345 unmodified lines
816822 goto fail;
817823 }
818824
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+
819831 ret = AVERROR(ENOSYS);
820832 if (src->internal->hw_type->frames_derive_from)
821833 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
564564 * AVHWFramesContext on.
565565 * @param source_frame_ctx A reference to an existing AVHWFramesContext
566566 * 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.
568570 * @return Zero on success, negative AVERROR code on failure.
569571 */
570572 int av_hwframe_ctx_create_derived(AVBufferRef **derived_frame_ctx,
libavutil/hwcontext_internal.h+5−0
@@ -121,6 +121,11 @@ struct AVHWFramesInternal { · 120 unmodified lines
121121 * context it was derived from.
122122 */
123123 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;
124129 };
125130
126131 typedef struct HWMapDescriptor {
libavutil/version.h+1−1
@@ -55,7 +55,7 @@ · 54 unmodified lines
5555
5656 #define LIBAVUTIL_VERSION_MAJOR 56
5757 #define LIBAVUTIL_VERSION_MINOR 1
58−#define LIBAVUTIL_VERSION_MICRO 0
58+#define LIBAVUTIL_VERSION_MICRO 1
5959
6060 #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
6161 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