summaryrefslogtreecommitdiffstats
path: root/video/out/gpu
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2017-12-01 05:05:00 +0100
committerwm4 <wm4@nowhere>2017-12-01 05:57:01 +0100
commit91586c35924ff8bd54eab549e7326d6cf2868b46 (patch)
treeb76152da6a15dd1afcb8d7db396d47195d5b6427 /video/out/gpu
parent2cf58362932be56645b16942ef3985eb2d0af65f (diff)
downloadmpv-91586c35924ff8bd54eab549e7326d6cf2868b46.tar.bz2
mpv-91586c35924ff8bd54eab549e7326d6cf2868b46.tar.xz
vo_gpu: make it possible to load multiple hwdec interop drivers
Make the VO<->decoder interface capable of supporting multiple hwdec APIs at once. The main gain is that this simplifies autoprobing a lot. Before this change, it could happen that the VO loaded the "wrong" hwdec API, and the decoder was stuck with the choice (breaking hw decoding). With the change applied, the VO simply loads all available APIs, so autoprobing trickery is left entirely to the decoder. In the past, we were quite careful about not accidentally loading the wrong interop drivers. This was in part to make sure autoprobing works, but also because libva had this obnoxious bug of dumping garbage to stderr when using the API. libva was fixed, so this is not a problem anymore. The --opengl-hwdec-interop option is changed in various ways (again...), and renamed to --gpu-hwdec-interop. It does not have much use anymore, other than debugging. It's notable that the order in the hwdec interop array ra_hwdec_drivers[] still matters if multiple drivers support the same image formats, so the option can explicitly force one, if that should ever be necessary, or more likely, for debugging. One example are the ra_hwdec_d3d11egl and ra_hwdec_d3d11eglrgb drivers, which both support d3d11 input. vo_gpu now always loads the interop lazily by default, but when it does, it loads them all. vo_opengl_cb now always loads them when the GL context handle is initialized. I don't expect that this causes any problems. It's now possible to do things like changing between vdpau and nvdec decoding at runtime. This is also preparation for cleaning up vd_lavc.c hwdec autoprobing. It's another reason why hwdec_devices_request_all() does not take a hwdec type anymore.
Diffstat (limited to 'video/out/gpu')
-rw-r--r--video/out/gpu/hwdec.c81
-rw-r--r--video/out/gpu/hwdec.h16
-rw-r--r--video/out/gpu/video.c103
-rw-r--r--video/out/gpu/video.h7
4 files changed, 109 insertions, 98 deletions
diff --git a/video/out/gpu/hwdec.c b/video/out/gpu/hwdec.c
index 12f4dd7f64..4661e875bf 100644
--- a/video/out/gpu/hwdec.c
+++ b/video/out/gpu/hwdec.c
@@ -40,7 +40,7 @@ extern const struct ra_hwdec_driver ra_hwdec_cuda_nvdec;
extern const struct ra_hwdec_driver ra_hwdec_rpi_overlay;
extern const struct ra_hwdec_driver ra_hwdec_drmprime_drm;
-static const struct ra_hwdec_driver *const mpgl_hwdec_drivers[] = {
+const struct ra_hwdec_driver *const ra_hwdec_drivers[] = {
#if HAVE_VAAPI_EGL
&ra_hwdec_vaegl,
#endif
@@ -76,11 +76,11 @@ static const struct ra_hwdec_driver *const mpgl_hwdec_drivers[] = {
NULL
};
-static struct ra_hwdec *load_hwdec_driver(struct mp_log *log, struct ra *ra,
- struct mpv_global *global,
- struct mp_hwdec_devices *devs,
- const struct ra_hwdec_driver *drv,
- bool is_auto)
+struct ra_hwdec *ra_hwdec_load_driver(struct ra *ra, struct mp_log *log,
+ struct mpv_global *global,
+ struct mp_hwdec_devices *devs,
+ const struct ra_hwdec_driver *drv,
+ bool is_auto)
{
struct ra_hwdec *hwdec = talloc(NULL, struct ra_hwdec);
*hwdec = (struct ra_hwdec) {
@@ -101,81 +101,30 @@ static struct ra_hwdec *load_hwdec_driver(struct mp_log *log, struct ra *ra,
return hwdec;
}
-struct ra_hwdec *ra_hwdec_load_api(struct mp_log *log, struct ra *ra,
- struct mpv_global *g,
- struct mp_hwdec_devices *devs,
- enum hwdec_type api)
-{
- bool is_auto = HWDEC_IS_AUTO(api);
- for (int n = 0; mpgl_hwdec_drivers[n]; n++) {
- const struct ra_hwdec_driver *drv = mpgl_hwdec_drivers[n];
- if ((is_auto || api == drv->api) && !drv->testing_only) {
- struct ra_hwdec *r = load_hwdec_driver(log, ra, g, devs, drv, is_auto);
- if (r)
- return r;
- }
- }
- return NULL;
-}
-
-// Load by option name.
-struct ra_hwdec *ra_hwdec_load(struct mp_log *log, struct ra *ra,
- struct mpv_global *g,
- struct mp_hwdec_devices *devs,
- const char *name)
-{
- int g_hwdec_api;
- mp_read_option_raw(g, "hwdec", &m_option_type_choice, &g_hwdec_api);
- if (!name || !name[0])
- name = m_opt_choice_str(mp_hwdec_names, g_hwdec_api);
-
- int api_id = HWDEC_NONE;
- for (int n = 0; mp_hwdec_names[n].name; n++) {
- if (name && strcmp(mp_hwdec_names[n].name, name) == 0)
- api_id = mp_hwdec_names[n].value;
- }
-
- for (int n = 0; mpgl_hwdec_drivers[n]; n++) {
- const struct ra_hwdec_driver *drv = mpgl_hwdec_drivers[n];
- if (name && strcmp(drv->name, name) == 0) {
- struct ra_hwdec *r = load_hwdec_driver(log, ra, g, devs, drv, false);
- if (r)
- return r;
- }
- }
-
- return ra_hwdec_load_api(log, ra, g, devs, api_id);
-}
-
int ra_hwdec_validate_opt(struct mp_log *log, const m_option_t *opt,
struct bstr name, struct bstr param)
{
bool help = bstr_equals0(param, "help");
if (help)
mp_info(log, "Available hwdecs:\n");
- for (int n = 0; mpgl_hwdec_drivers[n]; n++) {
- const struct ra_hwdec_driver *drv = mpgl_hwdec_drivers[n];
- const char *api_name = m_opt_choice_str(mp_hwdec_names, drv->api);
+ for (int n = 0; ra_hwdec_drivers[n]; n++) {
+ const struct ra_hwdec_driver *drv = ra_hwdec_drivers[n];
if (help) {
- mp_info(log, " %s [%s]\n", drv->name, api_name);
- } else if (bstr_equals0(param, drv->name) ||
- bstr_equals0(param, api_name))
- {
+ mp_info(log, " %s\n", drv->name);
+ } else if (bstr_equals0(param, drv->name)) {
return 1;
}
}
if (help) {
- mp_info(log, " auto (loads best)\n"
- " (other --hwdec values)\n"
- "Setting an empty string means use --hwdec.\n");
+ mp_info(log, " auto (behavior depends on context)\n"
+ " no (do not load any and block loading on demand)\n");
return M_OPT_EXIT;
}
if (!param.len)
return 1; // "" is treated specially
- for (int n = 0; mp_hwdec_names[n].name; n++) {
- if (bstr_equals0(param, mp_hwdec_names[n].name))
- return 1;
- }
+ if (bstr_equals0(param, "all") || bstr_equals0(param, "auto") ||
+ bstr_equals0(param, "no"))
+ return 1;
mp_fatal(log, "No hwdec backend named '%.*s' found!\n", BSTR_P(param));
return M_OPT_INVALID;
}
diff --git a/video/out/gpu/hwdec.h b/video/out/gpu/hwdec.h
index 20bbaae9eb..0ff6056bfd 100644
--- a/video/out/gpu/hwdec.h
+++ b/video/out/gpu/hwdec.h
@@ -104,15 +104,13 @@ struct ra_hwdec_driver {
struct mp_rect *src, struct mp_rect *dst, bool newframe);
};
-struct ra_hwdec *ra_hwdec_load_api(struct mp_log *log, struct ra *ra,
- struct mpv_global *g,
- struct mp_hwdec_devices *devs,
- enum hwdec_type api);
-
-struct ra_hwdec *ra_hwdec_load(struct mp_log *log, struct ra *ra,
- struct mpv_global *g,
- struct mp_hwdec_devices *devs,
- const char *name);
+extern const struct ra_hwdec_driver *const ra_hwdec_drivers[];
+
+struct ra_hwdec *ra_hwdec_load_driver(struct ra *ra, struct mp_log *log,
+ struct mpv_global *global,
+ struct mp_hwdec_devices *devs,
+ const struct ra_hwdec_driver *drv,
+ bool is_auto);
int ra_hwdec_validate_opt(struct mp_log *log, const m_option_t *opt,
struct bstr name, struct bstr param);
diff --git a/video/out/gpu/video.c b/video/out/gpu/video.c
index 4cdf20dfae..29af4b92b1 100644
--- a/video/out/gpu/video.c
+++ b/video/out/gpu/video.c
@@ -277,8 +277,12 @@ struct gl_video {
struct cached_file *files;
int num_files;
- struct ra_hwdec *hwdec;
+ bool hwdec_interop_loading_done;
+ struct ra_hwdec **hwdecs;
+ int num_hwdecs;
+
struct ra_hwdec_mapper *hwdec_mapper;
+ struct ra_hwdec *hwdec_overlay;
bool hwdec_active;
bool dsi_warned;
@@ -401,6 +405,10 @@ const struct m_sub_options gl_video_conf = {
OPT_INTRANGE("gpu-tex-pad-y", tex_pad_y, 0, 0, 4096),
OPT_SUBSTRUCT("", icc_opts, mp_icc_conf, 0),
OPT_STRING("gpu-shader-cache-dir", shader_cache_dir, 0),
+ OPT_STRING_VALIDATE("gpu-hwdec-interop", hwdec_interop, 0,
+ ra_hwdec_validate_opt),
+ OPT_REPLACED("opengl-hwdec-interop", "gpu-hwdec-interop"),
+ OPT_REPLACED("hwdec-preload", "opengl-hwdec-interop"),
OPT_REPLACED("hdr-tone-mapping", "tone-mapping"),
OPT_REPLACED("opengl-shaders", "glsl-shaders"),
OPT_REPLACED("opengl-shader", "glsl-shader"),
@@ -803,18 +811,27 @@ static void init_video(struct gl_video *p)
{
p->use_integer_conversion = false;
- if (p->hwdec && ra_hwdec_test_format(p->hwdec, p->image_params.imgfmt)) {
- if (p->hwdec->driver->overlay_frame) {
+ struct ra_hwdec *hwdec = NULL;
+ for (int n = 0; n < p->num_hwdecs; n++) {
+ if (ra_hwdec_test_format(p->hwdecs[n], p->image_params.imgfmt)) {
+ hwdec = p->hwdecs[n];
+ break;
+ }
+ }
+
+ if (hwdec) {
+ if (hwdec->driver->overlay_frame) {
MP_WARN(p, "Using HW-overlay mode. No GL filtering is performed "
"on the video!\n");
+ p->hwdec_overlay = hwdec;
} else {
- p->hwdec_mapper = ra_hwdec_mapper_create(p->hwdec, &p->image_params);
+ p->hwdec_mapper = ra_hwdec_mapper_create(hwdec, &p->image_params);
if (!p->hwdec_mapper)
MP_ERR(p, "Initializing texture for hardware decoding failed.\n");
}
if (p->hwdec_mapper)
p->image_params = p->hwdec_mapper->dst_params;
- const char **exts = p->hwdec->glsl_extensions;
+ const char **exts = hwdec->glsl_extensions;
for (int n = 0; exts && exts[n]; n++)
gl_sc_enable_extension(p->sc, (char *)exts[n]);
p->hwdec_active = true;
@@ -957,8 +974,8 @@ static void unref_current_image(struct gl_video *p)
// lead to flickering artifacts.
static void unmap_overlay(struct gl_video *p)
{
- if (p->hwdec_active && p->hwdec->driver->overlay_frame)
- p->hwdec->driver->overlay_frame(p->hwdec, NULL, NULL, NULL, true);
+ if (p->hwdec_overlay)
+ p->hwdec_overlay->driver->overlay_frame(p->hwdec_overlay, NULL, NULL, NULL, true);
}
static void uninit_video(struct gl_video *p)
@@ -981,6 +998,7 @@ static void uninit_video(struct gl_video *p)
p->real_image_params = (struct mp_image_params){0};
p->image_params = p->real_image_params;
p->hwdec_active = false;
+ p->hwdec_overlay = NULL;
ra_hwdec_mapper_free(&p->hwdec_mapper);
}
@@ -3005,15 +3023,15 @@ void gl_video_render_frame(struct gl_video *p, struct vo_frame *frame,
p->ra->fns->clear(p->ra, fbo.tex, color, &target_rc);
}
- if (p->hwdec_active && p->hwdec->driver->overlay_frame) {
+ if (p->hwdec_overlay) {
if (has_frame) {
- float *color = p->hwdec->overlay_colorkey;
+ float *color = p->hwdec_overlay->overlay_colorkey;
p->ra->fns->clear(p->ra, fbo.tex, color, &p->dst_rect);
}
- p->hwdec->driver->overlay_frame(p->hwdec, frame->current,
- &p->src_rect, &p->dst_rect,
- frame->frame_id != p->image.id);
+ p->hwdec_overlay->driver->overlay_frame(p->hwdec_overlay, frame->current,
+ &p->src_rect, &p->dst_rect,
+ frame->frame_id != p->image.id);
if (frame->current)
p->osd_pts = frame->current->pts;
@@ -3507,6 +3525,10 @@ void gl_video_uninit(struct gl_video *p)
uninit_video(p);
+ for (int n = 0; n < p->num_hwdecs; n++)
+ ra_hwdec_uninit(p->hwdecs[n]);
+ p->num_hwdecs = 0;
+
gl_sc_destroy(p->sc);
ra_tex_free(p->ra, &p->lut_3d_texture);
@@ -3561,8 +3583,10 @@ bool gl_video_check_format(struct gl_video *p, int mp_format)
if (ra_get_imgfmt_desc(p->ra, mp_format, &desc) &&
is_imgfmt_desc_supported(p, &desc))
return true;
- if (p->hwdec && ra_hwdec_test_format(p->hwdec, mp_format))
- return true;
+ for (int n = 0; n < p->num_hwdecs; n++) {
+ if (ra_hwdec_test_format(p->hwdecs[n], mp_format))
+ return true;
+ }
return false;
}
@@ -3782,13 +3806,6 @@ void gl_video_set_ambient_lux(struct gl_video *p, int lux)
}
}
-void gl_video_set_hwdec(struct gl_video *p, struct ra_hwdec *hwdec)
-{
- unref_current_image(p);
- ra_hwdec_mapper_free(&p->hwdec_mapper);
- p->hwdec = hwdec;
-}
-
static void *gl_video_dr_alloc_buffer(struct gl_video *p, size_t size)
{
struct ra_buf_params params = {
@@ -3845,3 +3862,47 @@ struct mp_image *gl_video_get_image(struct gl_video *p, int imgfmt, int w, int h
gl_video_dr_free_buffer(p, ptr);
return res;
}
+
+static void load_add_hwdec(struct gl_video *p, struct mp_hwdec_devices *devs,
+ const struct ra_hwdec_driver *drv, bool is_auto)
+{
+ struct ra_hwdec *hwdec =
+ ra_hwdec_load_driver(p->ra, p->log, p->global, devs, drv, is_auto);
+ if (hwdec)
+ MP_TARRAY_APPEND(p, p->hwdecs, p->num_hwdecs, hwdec);
+}
+
+void gl_video_load_hwdecs(struct gl_video *p, struct mp_hwdec_devices *devs,
+ bool load_all_by_default)
+{
+ char *type = p->opts.hwdec_interop;
+ if (!type || !type[0] || strcmp(type, "auto") == 0) {
+ if (!load_all_by_default)
+ return;
+ type = "all";
+ }
+ if (strcmp(type, "no") == 0) {
+ // do nothing, just block further loading
+ } else if (strcmp(type, "all") == 0) {
+ for (int n = 0; ra_hwdec_drivers[n]; n++)
+ load_add_hwdec(p, devs, ra_hwdec_drivers[n], true);
+ } else {
+ for (int n = 0; ra_hwdec_drivers[n]; n++) {
+ const struct ra_hwdec_driver *drv = ra_hwdec_drivers[n];
+ if (strcmp(type, drv->name) == 0) {
+ load_add_hwdec(p, devs, drv, false);
+ break;
+ }
+ }
+ }
+ p->hwdec_interop_loading_done = true;
+}
+
+void gl_video_load_hwdecs_all(struct gl_video *p, struct mp_hwdec_devices *devs)
+{
+ if (!p->hwdec_interop_loading_done) {
+ for (int n = 0; ra_hwdec_drivers[n]; n++)
+ load_add_hwdec(p, devs, ra_hwdec_drivers[n], true);
+ p->hwdec_interop_loading_done = true;
+ }
+}
diff --git a/video/out/gpu/video.h b/video/out/gpu/video.h
index b87390f4d1..78f8828f99 100644
--- a/video/out/gpu/video.h
+++ b/video/out/gpu/video.h
@@ -139,6 +139,7 @@ struct gl_video_opts {
struct mp_icc_opts *icc_opts;
int early_flush;
char *shader_cache_dir;
+ char *hwdec_interop;
};
extern const struct m_sub_options gl_video_conf;
@@ -176,8 +177,10 @@ struct mp_colorspace gl_video_get_output_colorspace(struct gl_video *p);
void gl_video_reset(struct gl_video *p);
bool gl_video_showing_interpolated_frame(struct gl_video *p);
-struct ra_hwdec;
-void gl_video_set_hwdec(struct gl_video *p, struct ra_hwdec *hwdec);
+struct mp_hwdec_devices;
+void gl_video_load_hwdecs(struct gl_video *p, struct mp_hwdec_devices *devs,
+ bool load_all_by_default);
+void gl_video_load_hwdecs_all(struct gl_video *p, struct mp_hwdec_devices *devs);
struct vo;
void gl_video_configure_queue(struct gl_video *p, struct vo *vo);