[FFmpeg-devel] [PATCH 1/6] lavc: Add device context field to AVCodecContext
Mark Thompson
sw at jkqxz.net
Wed Jan 18 00:28:43 EET 2017
For use by codec implementations which require a device to operation
but will allocate frames internally.
---
The following patches make use of it for qsv. Is this definition appropriate to solve the issues with cuvid device setup as well?
doc/APIchanges | 3 +++
libavcodec/avcodec.h | 38 ++++++++++++++++++++++++++++++++++++--
libavcodec/utils.c | 1 +
libavcodec/version.h | 2 +-
4 files changed, 41 insertions(+), 3 deletions(-)
diff --git a/doc/APIchanges b/doc/APIchanges
index c0ed711..d1d9a14 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.74.100- avcodec.h
+ Add AVCodecContext.hw_device_ctx.
+
2017-01-12 - xxxxxxx - lavfi 6.69.100- buffersink.h
Add av_buffersink_get_*() functions.
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 4d26d14..9758bb8 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -3532,8 +3532,13 @@ 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.
+ * or output (decoding) frames which will be used by a hardware codec.
+ *
+ * It can be set by the user if they wish to supply the frames used, or it
+ * can be set automatically by libavcodec for decoding when get_format()
+ * indicates that it should output hardware frames.
+ *
+ * If set by the user:
*
* - decoding: This field should be set by the caller from the get_format()
* callback. The previous reference (if any) will always be
@@ -3550,6 +3555,20 @@ typedef struct AVCodecContext {
* AVCodecContext.pix_fmt.
*
* This field should be set before avcodec_open2() is called.
+ *
+ * If set by libavcodec:
+ *
+ * - decoding: The hw_device_ctx field should be set by the user before
+ * calling avcodec_open2(). If at some later point a hardware
+ * pixel format is selected by get_format(), then a new
+ * AVHWFramesContext will be created by the decoder and put
+ * in this field.
+ *
+ * It will be valid when get_buffer2() is called (which must
+ * then return a buffer from the given context).
+ *
+ * - encoding: Unused. In this case the user must not supply hardware
+ * frames to the encoder.
*/
AVBufferRef *hw_frames_ctx;
@@ -3583,6 +3602,21 @@ 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 only be used if either the codec device does not require
+ * hardware frames or any that are used are allocated internally by
+ * libavcodec. If the frames may be supplied by the user, then
+ * hw_frames_ctx must be used instead.
+ *
+ * If a device is to be supplied, this field should be set before
+ * avcodec_open2() is called.
+ */
+ 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 1263306..0d1f87e 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -3060,6 +3060,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 b0dd46d..33b3bcb 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 73
+#define LIBAVCODEC_VERSION_MINOR 74
#define LIBAVCODEC_VERSION_MICRO 100
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
--
2.7.4
More information about the ffmpeg-devel
mailing list