[FFmpeg-cvslog] hwcontext: Improve allocation in derived contexts

2017-10-30 Thread Mark Thompson
ffmpeg | branch: master | Mark Thompson  | Sat Mar  4 23:57:40 
2017 +| [c5714b51aad41fef56dddac1d542e7fc6b984627] | committer: Mark 
Thompson

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.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=c5714b51aad41fef56dddac1d542e7fc6b984627
---

 doc/APIchanges |  4 
 libavutil/hwcontext.c  | 14 +-
 libavutil/hwcontext.h  |  4 +++-
 libavutil/hwcontext_internal.h |  5 +
 libavutil/version.h|  2 +-
 5 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 34d788a706..a251c4ca82 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -13,6 +13,10 @@ libavutil: 2017-03-23
 
 API changes, most recent first:
 
+2017-04-30 - xxx - lavu 56.1.1 - hwcontext.h
+  av_hwframe_ctx_create_derived() now takes some AV_HWFRAME_MAP_* combination
+  as its flags argument (which was previously unused).
+
 2017-04-xx - xxx - lavu 56.1.0 - spherical.h
   Add av_spherical_projection_name() and av_spherical_from_name().
 
diff --git a/libavutil/hwcontext.c b/libavutil/hwcontext.c
index a6d88421d8..360b01205c 100644
--- a/libavutil/hwcontext.c
+++ b/libavutil/hwcontext.c
@@ -455,6 +455,11 @@ int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, 
AVFrame *frame, int flags)
 // and map the frame immediately.
 AVFrame *src_frame;
 
+frame->format = ctx->format;
+frame->hw_frames_ctx = av_buffer_ref(hwframe_ref);
+if (!frame->hw_frames_ctx)
+return AVERROR(ENOMEM);
+
 src_frame = av_frame_alloc();
 if (!src_frame)
 return AVERROR(ENOMEM);
@@ -464,7 +469,8 @@ int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, AVFrame 
*frame, int flags)
 if (ret < 0)
 return ret;
 
-ret = av_hwframe_map(frame, src_frame, 0);
+ret = av_hwframe_map(frame, src_frame,
+ ctx->internal->source_allocation_map_flags);
 if (ret) {
 av_log(ctx, AV_LOG_ERROR, "Failed to map frame into derived "
"frame context: %d.\n", ret);
@@ -816,6 +822,12 @@ int av_hwframe_ctx_create_derived(AVBufferRef 
**derived_frame_ctx,
 goto fail;
 }
 
+dst->internal->source_allocation_map_flags =
+flags & (AV_HWFRAME_MAP_READ  |
+ AV_HWFRAME_MAP_WRITE |
+ AV_HWFRAME_MAP_OVERWRITE |
+ AV_HWFRAME_MAP_DIRECT);
+
 ret = AVERROR(ENOSYS);
 if (src->internal->hw_type->frames_derive_from)
 ret = src->internal->hw_type->frames_derive_from(dst, src, flags);
diff --git a/libavutil/hwcontext.h b/libavutil/hwcontext.h
index 889e30365e..eaf40c46f1 100644
--- a/libavutil/hwcontext.h
+++ b/libavutil/hwcontext.h
@@ -564,7 +564,9 @@ int av_hwframe_map(AVFrame *dst, const AVFrame *src, int 
flags);
  *   AVHWFramesContext on.
  * @param source_frame_ctx   A reference to an existing AVHWFramesContext
  *   which will be mapped to the derived context.
- * @param flags  Currently unused; should be set to zero.
+ * @param flags  Some combination of AV_HWFRAME_MAP_* flags, defining the
+ *   mapping parameters to apply to frames which are allocated
+ *   in the derived device.
  * @return   Zero on success, negative AVERROR code on failure.
  */
 int av_hwframe_ctx_create_derived(AVBufferRef **derived_frame_ctx,
diff --git a/libavutil/hwcontext_internal.h b/libavutil/hwcontext_internal.h
index 87b32e191e..7cf6cb07c7 100644
--- a/libavutil/hwcontext_internal.h
+++ b/libavutil/hwcontext_internal.h
@@ -121,6 +121,11 @@ struct AVHWFramesInternal {
  * context it was derived from.
  */
 AVBufferRef *source_frames;
+/**
+ * Flags to apply to the mapping from the source to the derived
+ * frame context when trying to allocate in the derived context.
+ */
+int source_allocation_map_flags;
 };
 
 typedef struct HWMapDescriptor {
diff --git a/libavutil/version.h b/libavutil/version.h
index fd72ff431d..7779755870 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -55,7 +55,7 @@
 
 #define LIBAVUTIL_VERSION_MAJOR 56
 #define LIBAVUTIL_VERSION_MINOR  1
-#define LIBAVUTIL_VERSION_MICRO  0
+#define LIBAVUTIL_VERSION_MICRO  1
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
LIBAVUTIL_VERSION_MINOR, \

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog


[FFmpeg-cvslog] hwcontext: Improve allocation in derived contexts

2017-06-14 Thread Mark Thompson
ffmpeg | branch: master | Mark Thompson  | Sat Mar  4 23:57:40 
2017 +| [d59c6a3aebc20cc64cb7a46401cb55f02f4cbe09] | committer: Mark 
Thompson

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)

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=d59c6a3aebc20cc64cb7a46401cb55f02f4cbe09
---

 doc/APIchanges |  4 
 libavutil/hwcontext.c  | 14 +-
 libavutil/hwcontext.h  |  4 +++-
 libavutil/hwcontext_internal.h |  5 +
 libavutil/version.h|  2 +-
 5 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index cedffbf428..5dca6b3e51 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -15,6 +15,10 @@ libavutil: 2015-08-28
 
 API changes, most recent first:
 
+2017-06-14 - xxx - lavu 55.66.100 - hwcontext.h
+  av_hwframe_ctx_create_derived() now takes some AV_HWFRAME_MAP_* combination
+  as its flags argument (which was previously unused).
+
 2017-06-14 - xxx - lavc 57.99.100 - avcodec.h
   Add AV_HWACCEL_FLAG_ALLOW_PROFILE_MISMATCH.
 
diff --git a/libavutil/hwcontext.c b/libavutil/hwcontext.c
index ed09c49f2d..5a22194716 100644
--- a/libavutil/hwcontext.c
+++ b/libavutil/hwcontext.c
@@ -458,6 +458,11 @@ int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, 
AVFrame *frame, int flags)
 // and map the frame immediately.
 AVFrame *src_frame;
 
+frame->format = ctx->format;
+frame->hw_frames_ctx = av_buffer_ref(hwframe_ref);
+if (!frame->hw_frames_ctx)
+return AVERROR(ENOMEM);
+
 src_frame = av_frame_alloc();
 if (!src_frame)
 return AVERROR(ENOMEM);
@@ -467,7 +472,8 @@ int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, AVFrame 
*frame, int flags)
 if (ret < 0)
 return ret;
 
-ret = av_hwframe_map(frame, src_frame, 0);
+ret = av_hwframe_map(frame, src_frame,
+ ctx->internal->source_allocation_map_flags);
 if (ret) {
 av_log(ctx, AV_LOG_ERROR, "Failed to map frame into derived "
"frame context: %d.\n", ret);
@@ -819,6 +825,12 @@ int av_hwframe_ctx_create_derived(AVBufferRef 
**derived_frame_ctx,
 goto fail;
 }
 
+dst->internal->source_allocation_map_flags =
+flags & (AV_HWFRAME_MAP_READ  |
+ AV_HWFRAME_MAP_WRITE |
+ AV_HWFRAME_MAP_OVERWRITE |
+ AV_HWFRAME_MAP_DIRECT);
+
 ret = AVERROR(ENOSYS);
 if (src->internal->hw_type->frames_derive_from)
 ret = src->internal->hw_type->frames_derive_from(dst, src, flags);
diff --git a/libavutil/hwcontext.h b/libavutil/hwcontext.h
index 37e8831f6b..edf12cc631 100644
--- a/libavutil/hwcontext.h
+++ b/libavutil/hwcontext.h
@@ -566,7 +566,9 @@ int av_hwframe_map(AVFrame *dst, const AVFrame *src, int 
flags);
  *   AVHWFramesContext on.
  * @param source_frame_ctx   A reference to an existing AVHWFramesContext
  *   which will be mapped to the derived context.
- * @param flags  Currently unused; should be set to zero.
+ * @param flags  Some combination of AV_HWFRAME_MAP_* flags, defining the
+ *   mapping parameters to apply to frames which are allocated
+ *   in the derived device.
  * @return   Zero on success, negative AVERROR code on failure.
  */
 int av_hwframe_ctx_create_derived(AVBufferRef **derived_frame_ctx,
diff --git a/libavutil/hwcontext_internal.h b/libavutil/hwcontext_internal.h
index 0a0c4e86ce..68f78c0a1f 100644
--- a/libavutil/hwcontext_internal.h
+++ b/libavutil/hwcontext_internal.h
@@ -121,6 +121,11 @@ struct AVHWFramesInternal {
  * context it was derived from.
  */
 AVBufferRef *source_frames;
+/**
+ * Flags to apply to the mapping from the source to the derived
+ * frame context when trying to allocate in the derived context.
+ */
+int source_allocation_map_flags;
 };
 
 typedef struct HWMapDescriptor {
diff --git a/libavutil/version.h b/libavutil/version.h
index 322b683cf4..308d16f95b 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -80,7 +80,7 @@
 
 
 #define LIBAVUTIL_VERSION_MAJOR  55
-#define LIBAVUTIL_VERSION_MINOR  65
+#define LIBAVUTIL_VERSION_MINOR  66
 #define LIBAVUTIL_VERSION_MICRO 100
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog