Commit d2e6dd32 authored by Mark Thompson's avatar Mark Thompson

avconv: Generic device setup

Not yet enabled for any hwaccels.
parent b7487f4f
......@@ -8,7 +8,8 @@ PROGS += $(AVPROGS)
AVBASENAMES = avconv avplay avprobe
ALLAVPROGS = $(AVBASENAMES:%=%$(EXESUF))
OBJS-avconv += avtools/avconv_opt.o avtools/avconv_filter.o
OBJS-avconv += avtools/avconv_opt.o avtools/avconv_filter.o \
avtools/avconv_hw.o
OBJS-avconv-$(CONFIG_LIBMFX) += avtools/avconv_qsv.o
OBJS-avconv-$(CONFIG_VAAPI) += avtools/avconv_vaapi.o
OBJS-avconv-$(CONFIG_VDA) += avtools/avconv_vda.o
......
......@@ -1704,6 +1704,17 @@ 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) {
char errbuf[128];
av_strerror(ret, errbuf, sizeof(errbuf));
snprintf(error, error_len, "Device setup failed for "
"decoder on input stream #%d:%d : %s",
ist->file_index, ist->st->index, errbuf);
return ret;
}
if ((ret = avcodec_open2(ist->dec_ctx, codec, &ist->decoder_opts)) < 0) {
char errbuf[128];
if (ret == AVERROR_EXPERIMENTAL)
......@@ -2046,6 +2057,16 @@ static int init_output_stream(OutputStream *ost, char *error, int error_len)
ost->enc_ctx->hw_frames_ctx = av_buffer_ref(ost->filter->filter->inputs[0]->hw_frames_ctx);
if (!ost->enc_ctx->hw_frames_ctx)
return AVERROR(ENOMEM);
} else {
ret = hw_device_setup_for_encode(ost);
if (ret < 0) {
char errbuf[128];
av_strerror(ret, errbuf, sizeof(errbuf));
snprintf(error, error_len, "Device setup failed for "
"encoder on output stream #%d:%d : %s",
ost->file_index, ost->index, errbuf);
return ret;
}
}
if ((ret = avcodec_open2(ost->enc_ctx, codec, &ost->encoder_opts)) < 0) {
......@@ -2795,6 +2816,7 @@ static int transcode(void)
}
av_buffer_unref(&hw_device_ctx);
hw_device_free_all();
/* finished ! */
ret = 0;
......
......@@ -40,6 +40,7 @@
#include "libavutil/avutil.h"
#include "libavutil/dict.h"
#include "libavutil/fifo.h"
#include "libavutil/hwcontext.h"
#include "libavutil/pixfmt.h"
#include "libavutil/rational.h"
......@@ -63,8 +64,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 */
......@@ -510,4 +518,13 @@ int qsv_transcode_init(OutputStream *ost);
int vaapi_decode_init(AVCodecContext *avctx);
int vaapi_device_init(const char *device);
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 /* AVCONV_H */
This diff is collapsed.
......@@ -57,19 +57,24 @@
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", vda_init, HWACCEL_VDA, AV_PIX_FMT_VDA },
{ "vda", vda_init, HWACCEL_VDA, AV_PIX_FMT_VDA,
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
{ 0 },
};
......@@ -337,6 +342,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
......@@ -2741,5 +2761,8 @@ const OptionDef options[] = {
"set VAAPI hardware device (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