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))
$(foreach prog,$(AVBASENAMES),$(eval OBJS-$(prog) += cmdutils.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_LIBMFX) += ffmpeg_qsv.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)
if (!av_dict_get(ist->decoder_opts, "threads", NULL, 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 == AVERROR_EXPERIMENTAL)
abort_codec_experimental(codec, 0);
......@@ -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));
if (!ost->enc_ctx->hw_frames_ctx)
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) {
......@@ -4643,6 +4660,7 @@ static int transcode(void)
}
av_buffer_unref(&hw_device_ctx);
hw_device_free_all();
/* finished ! */
ret = 0;
......
......@@ -42,6 +42,7 @@
#include "libavutil/dict.h"
#include "libavutil/eval.h"
#include "libavutil/fifo.h"
#include "libavutil/hwcontext.h"
#include "libavutil/pixfmt.h"
#include "libavutil/rational.h"
#include "libavutil/threadmessage.h"
......@@ -74,8 +75,15 @@ typedef struct HWAccel {
int (*init)(AVCodecContext *s);
enum HWAccelID id;
enum AVPixelFormat pix_fmt;
enum AVHWDeviceType device_type;
} HWAccel;
typedef struct HWDevice {
char *name;
enum AVHWDeviceType type;
AVBufferRef *device_ref;
} HWDevice;
/* select an input stream for an output stream */
typedef struct StreamMap {
int disabled; /* 1 is this mapping is disabled by a negative map */
......@@ -661,4 +669,13 @@ int vaapi_decode_init(AVCodecContext *avctx);
int vaapi_device_init(const char *device);
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 */
This diff is collapsed.
......@@ -67,25 +67,32 @@
const HWAccel hwaccels[] = {
#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
#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
#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
#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
#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
#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
#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
{ 0 },
};
......@@ -463,6 +470,21 @@ static int opt_vaapi_device(void *optctx, const char *opt, const char *arg)
}
#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.
* @param arg metadata string to parse
......@@ -3674,5 +3696,8 @@ const OptionDef options[] = {
"set QSV hardware device (DirectX adapter index, DRM path or X11 display name)", "device"},
#endif
{ "init_hw_device", HAS_ARG | OPT_EXPERT, { .func_arg = opt_init_hw_device },
"initialise hardware device", "args" },
{ 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