[FFmpeg-devel] [PATCH] lavc: Add device context field to AVCodecContext

Mark Thompson sw at jkqxz.net
Thu Feb 9 02:28:09 EET 2017


For use by codec implementations which can allocate frames internally.
---
This seems to have reached agreement in libav.  If there are no more comments here, I will commit this to both tines soon.

Thanks,

- Mark


 doc/APIchanges       |  3 +++
 libavcodec/avcodec.h | 24 +++++++++++++++++++++++-
 libavcodec/utils.c   |  1 +
 libavcodec/version.h |  2 +-
 4 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 8bca71ef36..f7cf79e960 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -15,6 +15,9 @@ libavutil:     2015-08-28
 
 API changes, most recent first:
 
+2017-xx-xx - xxxxxxx - lavc 57.76.100 - avcodec.h
+  Add AVCodecContext.hw_device_ctx.
+
 2017-01-31 - xxxxxxx - lavu 55.46.100 / 55.20.0 - cpu.h
   Add AV_CPU_FLAG_SSSE3SLOW.
 
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 1e681e989b..3fc69ecc53 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -3533,7 +3533,8 @@ typedef struct AVCodecContext {
     /**
      * A reference to the AVHWFramesContext describing the input (for encoding)
      * or output (decoding) frames. The reference is set by the caller and
-     * afterwards owned (and freed) by libavcodec.
+     * afterwards owned (and freed) by libavcodec - it should never be read by
+     * the caller after being set.
      *
      * - decoding: This field should be set by the caller from the get_format()
      *             callback. The previous reference (if any) will always be
@@ -3583,6 +3584,27 @@ typedef struct AVCodecContext {
      */
     int64_t max_pixels;
 
+    /**
+     * A reference to the AVHWDeviceContext describing the device which will
+     * be used by a hardware encoder/decoder.  The reference is set by the
+     * caller and afterwards owned (and freed) by libavcodec.
+     *
+     * This should be used if either the codec device does not require
+     * hardware frames or any that are used are to be allocated internally by
+     * libavcodec.  If the user wishes to supply any of the frames used as
+     * encoder input or decoder output then hw_frames_ctx should be used
+     * instead.  When hw_frames_ctx is set in get_format() for a decoder, this
+     * field will be ignored while decoding the associated stream segment, but
+     * may again be used on a following one after another get_format() call.
+     *
+     * For both encoders and decoders this field should be set before
+     * avcodec_open2() is called and must not be written to thereafter.
+     *
+     * Note that some decoders may require this field to be set initially in
+     * order to support hw_frames_ctx at all - in that case, all frames
+     * contexts used must be created on the same device.
+     */
+    AVBufferRef *hw_device_ctx;
 } AVCodecContext;
 
 AVRational av_codec_get_pkt_timebase         (const AVCodecContext *avctx);
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index 4ae752ff2f..43e0365033 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -3065,6 +3065,7 @@ av_cold int avcodec_close(AVCodecContext *avctx)
     avctx->nb_coded_side_data = 0;
 
     av_buffer_unref(&avctx->hw_frames_ctx);
+    av_buffer_unref(&avctx->hw_device_ctx);
 
     if (avctx->priv_data && avctx->codec && avctx->codec->priv_class)
         av_opt_free(avctx->priv_data);
diff --git a/libavcodec/version.h b/libavcodec/version.h
index c038e4b093..82a89f9c42 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -28,7 +28,7 @@
 #include "libavutil/version.h"
 
 #define LIBAVCODEC_VERSION_MAJOR  57
-#define LIBAVCODEC_VERSION_MINOR  75
+#define LIBAVCODEC_VERSION_MINOR  76
 #define LIBAVCODEC_VERSION_MICRO 100
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
-- 
2.11.0



More information about the ffmpeg-devel mailing list