[FFmpeg-cvslog] hwcontext: Add frame context mapping for nontrivial contexts

Mark Thompson git at videolan.org
Mon Oct 30 23:02:41 EET 2017


ffmpeg | branch: master | Mark Thompson <sw at jkqxz.net> | Sat Mar  4 23:57:39 2017 +0000| [27978155bc661eec9f22bcf82c9cfc099cff4365] | committer: Mark Thompson

hwcontext: Add frame context mapping for nontrivial contexts

Some frames contexts are not usable without additional format-specific
state in hwctx.  This change adds new functions frames_derive_from and
frames_derive_to to initialise this state appropriately when deriving
a frames context which will require it to be set.

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

 libavutil/hwcontext.c          | 9 ++++++++-
 libavutil/hwcontext_internal.h | 5 +++++
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/libavutil/hwcontext.c b/libavutil/hwcontext.c
index ff9fe99aba..a6d88421d8 100644
--- a/libavutil/hwcontext.c
+++ b/libavutil/hwcontext.c
@@ -816,7 +816,14 @@ int av_hwframe_ctx_create_derived(AVBufferRef **derived_frame_ctx,
         goto fail;
     }
 
-    ret = av_hwframe_ctx_init(dst_ref);
+    ret = AVERROR(ENOSYS);
+    if (src->internal->hw_type->frames_derive_from)
+        ret = src->internal->hw_type->frames_derive_from(dst, src, flags);
+    if (ret == AVERROR(ENOSYS) &&
+        dst->internal->hw_type->frames_derive_to)
+        ret = dst->internal->hw_type->frames_derive_to(dst, src, flags);
+    if (ret == AVERROR(ENOSYS))
+        ret = 0;
     if (ret)
         goto fail;
 
diff --git a/libavutil/hwcontext_internal.h b/libavutil/hwcontext_internal.h
index 66f54142e8..87b32e191e 100644
--- a/libavutil/hwcontext_internal.h
+++ b/libavutil/hwcontext_internal.h
@@ -92,6 +92,11 @@ typedef struct HWContextType {
                                const AVFrame *src, int flags);
     int              (*map_from)(AVHWFramesContext *ctx, AVFrame *dst,
                                  const AVFrame *src, int flags);
+
+    int              (*frames_derive_to)(AVHWFramesContext *dst_ctx,
+                                         AVHWFramesContext *src_ctx, int flags);
+    int              (*frames_derive_from)(AVHWFramesContext *dst_ctx,
+                                           AVHWFramesContext *src_ctx, int flags);
 } HWContextType;
 
 struct AVHWDeviceInternal {



More information about the ffmpeg-cvslog mailing list