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
1515
1616 API changes, most recent first:
1717
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+
1822 2017-06-14 - xxxxxxx - lavc 57.99.100 - avcodec.h
1923 Add AV_HWACCEL_FLAG_ALLOW_PROFILE_MISMATCH.
2024
libavutil/hwcontext.c+13−1
@@ -458,6 +458,11 @@ int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, AVFrame *frame, int flags) · 457 unmodified lines
458458 // and map the frame immediately.
459459 AVFrame *src_frame;
460460
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+
461466 src_frame = av_frame_alloc();
462467 if (!src_frame)
463468 return AVERROR(ENOMEM);
@@ -467,7 +472,8 @@ int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, AVFrame *frame, int flags) · 3 unmodified lines
467472 if (ret < 0)
468473 return ret;
469474
470− ret = av_hwframe_map(frame, src_frame, 0);
475+ ret = av_hwframe_map(frame, src_frame,
476+ ctx->internal->source_allocation_map_flags);
471477 if (ret) {
472478 av_log(ctx, AV_LOG_ERROR, "Failed to map frame into derived "
473479 "frame context: %d.\n", ret);
@@ -819,6 +825,12 @@ int av_hwframe_ctx_create_derived(AVBufferRef **derived_frame_ctx, · 345 unmodified lines
819825 goto fail;
820826 }
821827
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+
822834 ret = AVERROR(ENOSYS);
823835 if (src->internal->hw_type->frames_derive_from)
824836 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
566566 * AVHWFramesContext on.
567567 * @param source_frame_ctx A reference to an existing AVHWFramesContext
568568 * 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.
570572 * @return Zero on success, negative AVERROR code on failure.
571573 */
572574 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
@@ -80,7 +80,7 @@ · 79 unmodified lines
8080
8181
8282 #define LIBAVUTIL_VERSION_MAJOR 55
83−#define LIBAVUTIL_VERSION_MINOR 65
83+#define LIBAVUTIL_VERSION_MINOR 66
8484 #define LIBAVUTIL_VERSION_MICRO 100
8585
8686 #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