Commit 06043cc0 authored by Mark Thompson's avatar Mark Thompson

ffmpeg: Generic device setup

Not yet enabled for any hwaccels.

(cherry picked from commit d2e6dd32)
(cherry picked from commit 9203aac2)
parent 0b1794a4
...@@ -31,7 +31,7 @@ ALLAVPROGS_G = $(AVBASENAMES:%=%$(PROGSSUF)_g$(EXESUF)) ...@@ -31,7 +31,7 @@ ALLAVPROGS_G = $(AVBASENAMES:%=%$(PROGSSUF)_g$(EXESUF))
$(foreach prog,$(AVBASENAMES),$(eval OBJS-$(prog) += cmdutils.o)) $(foreach prog,$(AVBASENAMES),$(eval OBJS-$(prog) += cmdutils.o))
$(foreach prog,$(AVBASENAMES),$(eval OBJS-$(prog)-$(CONFIG_OPENCL) += cmdutils_opencl.o)) $(foreach prog,$(AVBASENAMES),$(eval OBJS-$(prog)-$(CONFIG_OPENCL) += cmdutils_opencl.o))
OBJS-ffmpeg += ffmpeg_opt.o ffmpeg_filter.o OBJS-ffmpeg += ffmpeg_opt.o ffmpeg_filter.o ffmpeg_hw.o
OBJS-ffmpeg-$(CONFIG_VIDEOTOOLBOX) += ffmpeg_videotoolbox.o OBJS-ffmpeg-$(CONFIG_VIDEOTOOLBOX) += ffmpeg_videotoolbox.o
OBJS-ffmpeg-$(CONFIG_LIBMFX) += ffmpeg_qsv.o OBJS-ffmpeg-$(CONFIG_LIBMFX) += ffmpeg_qsv.o
OBJS-ffmpeg-$(CONFIG_VAAPI) += ffmpeg_vaapi.o OBJS-ffmpeg-$(CONFIG_VAAPI) += ffmpeg_vaapi.o
......
...@@ -2884,6 +2884,15 @@ static int init_input_stream(int ist_index, char *error, int error_len) ...@@ -2884,6 +2884,15 @@ static int init_input_stream(int ist_index, char *error, int error_len)
if (!av_dict_get(ist->decoder_opts, "threads", NULL, 0)) if (!av_dict_get(ist->decoder_opts, "threads", NULL, 0))
av_dict_set(&ist->decoder_opts, "threads", "auto", 0); av_dict_set(&ist->decoder_opts, "threads", "auto", 0);
ret = hw_device_setup_for_decode(ist);
if (ret < 0) {
snprintf(error, error_len, "Device setup failed for "
"decoder on input stream #%d:%d : %s",
ist->file_index, ist->st->index, av_err2str(ret));
return ret;
}
if ((ret = avcodec_open2(ist->dec_ctx, codec, &ist->decoder_opts)) < 0) { if ((ret = avcodec_open2(ist->dec_ctx, codec, &ist->decoder_opts)) < 0) {
if (ret == AVERROR_EXPERIMENTAL) if (ret == AVERROR_EXPERIMENTAL)
abort_codec_experimental(codec, 0); abort_codec_experimental(codec, 0);
...@@ -3441,6 +3450,14 @@ static int init_output_stream(OutputStream *ost, char *error, int error_len) ...@@ -3441,6 +3450,14 @@ static int init_output_stream(OutputStream *ost, char *error, int error_len)
ost->enc_ctx->hw_frames_ctx = av_buffer_ref(av_buffersink_get_hw_frames_ctx(ost->filter->filter)); ost->enc_ctx->hw_frames_ctx = av_buffer_ref(av_buffersink_get_hw_frames_ctx(ost->filter->filter));
if (!ost->enc_ctx->hw_frames_ctx) if (!ost->enc_ctx->hw_frames_ctx)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
} else {
ret = hw_device_setup_for_encode(ost);
if (ret < 0) {
snprintf(error, error_len, "Device setup failed for "
"encoder on output stream #%d:%d : %s",
ost->file_index, ost->index, av_err2str(ret));
return ret;
}
} }
if ((ret = avcodec_open2(ost->enc_ctx, codec, &ost->encoder_opts)) < 0) { if ((ret = avcodec_open2(ost->enc_ctx, codec, &ost->encoder_opts)) < 0) {
...@@ -4643,6 +4660,7 @@ static int transcode(void) ...@@ -4643,6 +4660,7 @@ static int transcode(void)
} }
av_buffer_unref(&hw_device_ctx); av_buffer_unref(&hw_device_ctx);
hw_device_free_all();
/* finished ! */ /* finished ! */
ret = 0; ret = 0;
......
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
#include "libavutil/dict.h" #include "libavutil/dict.h"
#include "libavutil/eval.h" #include "libavutil/eval.h"
#include "libavutil/fifo.h" #include "libavutil/fifo.h"
#include "libavutil/hwcontext.h"
#include "libavutil/pixfmt.h" #include "libavutil/pixfmt.h"
#include "libavutil/rational.h" #include "libavutil/rational.h"
#include "libavutil/threadmessage.h" #include "libavutil/threadmessage.h"
...@@ -74,8 +75,15 @@ typedef struct HWAccel { ...@@ -74,8 +75,15 @@ typedef struct HWAccel {
int (*init)(AVCodecContext *s); int (*init)(AVCodecContext *s);
enum HWAccelID id; enum HWAccelID id;
enum AVPixelFormat pix_fmt; enum AVPixelFormat pix_fmt;
enum AVHWDeviceType device_type;
} HWAccel; } HWAccel;
typedef struct HWDevice {
char *name;
enum AVHWDeviceType type;
AVBufferRef *device_ref;
} HWDevice;
/* select an input stream for an output stream */ /* select an input stream for an output stream */
typedef struct StreamMap { typedef struct StreamMap {
int disabled; /* 1 is this mapping is disabled by a negative map */ int disabled; /* 1 is this mapping is disabled by a negative map */
...@@ -661,4 +669,13 @@ int vaapi_decode_init(AVCodecContext *avctx); ...@@ -661,4 +669,13 @@ int vaapi_decode_init(AVCodecContext *avctx);
int vaapi_device_init(const char *device); int vaapi_device_init(const char *device);
int cuvid_init(AVCodecContext *s); int cuvid_init(AVCodecContext *s);
HWDevice *hw_device_get_by_name(const char *name);
int hw_device_init_from_string(const char *arg, HWDevice **dev);
void hw_device_free_all(void);
int hw_device_setup_for_decode(InputStream *ist);
int hw_device_setup_for_encode(OutputStream *ost);
int hwaccel_decode_init(AVCodecContext *avctx);
#endif /* FFMPEG_H */ #endif /* FFMPEG_H */
This diff is collapsed.
...@@ -67,25 +67,32 @@ ...@@ -67,25 +67,32 @@
const HWAccel hwaccels[] = { const HWAccel hwaccels[] = {
#if HAVE_VDPAU_X11 #if HAVE_VDPAU_X11
{ "vdpau", vdpau_init, HWACCEL_VDPAU, AV_PIX_FMT_VDPAU }, { "vdpau", vdpau_init, HWACCEL_VDPAU, AV_PIX_FMT_VDPAU,
AV_HWDEVICE_TYPE_NONE },
#endif #endif
#if HAVE_DXVA2_LIB #if HAVE_DXVA2_LIB
{ "dxva2", dxva2_init, HWACCEL_DXVA2, AV_PIX_FMT_DXVA2_VLD }, { "dxva2", dxva2_init, HWACCEL_DXVA2, AV_PIX_FMT_DXVA2_VLD,
AV_HWDEVICE_TYPE_NONE },
#endif #endif
#if CONFIG_VDA #if CONFIG_VDA
{ "vda", videotoolbox_init, HWACCEL_VDA, AV_PIX_FMT_VDA }, { "vda", videotoolbox_init, HWACCEL_VDA, AV_PIX_FMT_VDA,
AV_HWDEVICE_TYPE_NONE },
#endif #endif
#if CONFIG_VIDEOTOOLBOX #if CONFIG_VIDEOTOOLBOX
{ "videotoolbox", videotoolbox_init, HWACCEL_VIDEOTOOLBOX, AV_PIX_FMT_VIDEOTOOLBOX }, { "videotoolbox", videotoolbox_init, HWACCEL_VIDEOTOOLBOX, AV_PIX_FMT_VIDEOTOOLBOX,
AV_HWDEVICE_TYPE_NONE },
#endif #endif
#if CONFIG_LIBMFX #if CONFIG_LIBMFX
{ "qsv", qsv_init, HWACCEL_QSV, AV_PIX_FMT_QSV }, { "qsv", qsv_init, HWACCEL_QSV, AV_PIX_FMT_QSV,
AV_HWDEVICE_TYPE_NONE },
#endif #endif
#if CONFIG_VAAPI #if CONFIG_VAAPI
{ "vaapi", vaapi_decode_init, HWACCEL_VAAPI, AV_PIX_FMT_VAAPI }, { "vaapi", vaapi_decode_init, HWACCEL_VAAPI, AV_PIX_FMT_VAAPI,
AV_HWDEVICE_TYPE_NONE },
#endif #endif
#if CONFIG_CUVID #if CONFIG_CUVID
{ "cuvid", cuvid_init, HWACCEL_CUVID, AV_PIX_FMT_CUDA }, { "cuvid", cuvid_init, HWACCEL_CUVID, AV_PIX_FMT_CUDA,
AV_HWDEVICE_TYPE_NONE },
#endif #endif
{ 0 }, { 0 },
}; };
...@@ -463,6 +470,21 @@ static int opt_vaapi_device(void *optctx, const char *opt, const char *arg) ...@@ -463,6 +470,21 @@ static int opt_vaapi_device(void *optctx, const char *opt, const char *arg)
} }
#endif #endif
static int opt_init_hw_device(void *optctx, const char *opt, const char *arg)
{
if (!strcmp(arg, "list")) {
enum AVHWDeviceType type = AV_HWDEVICE_TYPE_NONE;
printf("Supported hardware device types:\n");
while ((type = av_hwdevice_iterate_types(type)) !=
AV_HWDEVICE_TYPE_NONE)
printf("%s\n", av_hwdevice_get_type_name(type));
printf("\n");
exit_program(0);
} else {
return hw_device_init_from_string(arg, NULL);
}
}
/** /**
* Parse a metadata specifier passed as 'arg' parameter. * Parse a metadata specifier passed as 'arg' parameter.
* @param arg metadata string to parse * @param arg metadata string to parse
...@@ -3674,5 +3696,8 @@ const OptionDef options[] = { ...@@ -3674,5 +3696,8 @@ const OptionDef options[] = {
"set QSV hardware device (DirectX adapter index, DRM path or X11 display name)", "device"}, "set QSV hardware device (DirectX adapter index, DRM path or X11 display name)", "device"},
#endif #endif
{ "init_hw_device", HAS_ARG | OPT_EXPERT, { .func_arg = opt_init_hw_device },
"initialise hardware device", "args" },
{ NULL, }, { NULL, },
}; };
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment