2014-12-03 20:54:04 +00:00
|
|
|
/*
|
2015-04-13 07:36:54 +00:00
|
|
|
* This file is part of mpv.
|
2014-12-03 20:54:04 +00:00
|
|
|
*
|
2016-01-19 17:36:34 +00:00
|
|
|
* mpv is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2014-12-03 20:54:04 +00:00
|
|
|
*
|
2015-04-13 07:36:54 +00:00
|
|
|
* mpv is distributed in the hope that it will be useful,
|
2014-12-03 20:54:04 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2016-01-19 17:36:34 +00:00
|
|
|
* GNU Lesser General Public License for more details.
|
2014-12-03 20:54:04 +00:00
|
|
|
*
|
2016-01-19 17:36:34 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with mpv. If not, see <http://www.gnu.org/licenses/>.
|
2014-12-03 20:54:04 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "common/common.h"
|
|
|
|
#include "common/msg.h"
|
2015-08-29 02:12:56 +00:00
|
|
|
#include "hwdec.h"
|
2014-12-03 20:54:04 +00:00
|
|
|
|
2015-09-24 22:20:57 +00:00
|
|
|
extern const struct gl_hwdec_driver gl_hwdec_vaegl;
|
2014-12-03 20:54:04 +00:00
|
|
|
extern const struct gl_hwdec_driver gl_hwdec_vaglx;
|
2015-07-11 15:21:39 +00:00
|
|
|
extern const struct gl_hwdec_driver gl_hwdec_videotoolbox;
|
2014-12-03 20:54:04 +00:00
|
|
|
extern const struct gl_hwdec_driver gl_hwdec_vdpau;
|
2016-03-08 03:53:24 +00:00
|
|
|
extern const struct gl_hwdec_driver gl_hwdec_dxva2egl;
|
2016-02-14 11:46:17 +00:00
|
|
|
extern const struct gl_hwdec_driver gl_hwdec_dxva2gldx;
|
2015-07-03 14:37:01 +00:00
|
|
|
extern const struct gl_hwdec_driver gl_hwdec_dxva2;
|
2014-12-03 20:54:04 +00:00
|
|
|
|
|
|
|
static const struct gl_hwdec_driver *const mpgl_hwdec_drivers[] = {
|
2015-09-27 18:09:10 +00:00
|
|
|
#if HAVE_VAAPI_EGL
|
2015-09-24 22:20:57 +00:00
|
|
|
&gl_hwdec_vaegl,
|
|
|
|
#endif
|
2014-12-03 20:54:04 +00:00
|
|
|
#if HAVE_VAAPI_GLX
|
|
|
|
&gl_hwdec_vaglx,
|
|
|
|
#endif
|
|
|
|
#if HAVE_VDPAU_GL_X11
|
|
|
|
&gl_hwdec_vdpau,
|
2014-12-09 16:47:02 +00:00
|
|
|
#endif
|
2015-09-28 19:55:23 +00:00
|
|
|
#if HAVE_VIDEOTOOLBOX_GL
|
2015-08-17 21:49:07 +00:00
|
|
|
&gl_hwdec_videotoolbox,
|
2015-07-03 14:37:01 +00:00
|
|
|
#endif
|
2016-02-17 18:17:52 +00:00
|
|
|
#if HAVE_DXVA2_HWACCEL
|
2016-03-08 03:53:24 +00:00
|
|
|
#if HAVE_EGL_ANGLE
|
|
|
|
&gl_hwdec_dxva2egl,
|
|
|
|
#endif
|
2016-02-17 18:17:52 +00:00
|
|
|
#if HAVE_GL_DXINTEROP
|
2016-02-14 11:46:17 +00:00
|
|
|
&gl_hwdec_dxva2gldx,
|
|
|
|
#endif
|
2015-07-03 14:37:01 +00:00
|
|
|
&gl_hwdec_dxva2,
|
2014-12-03 20:54:04 +00:00
|
|
|
#endif
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct gl_hwdec *load_hwdec_driver(struct mp_log *log, GL *gl,
|
2015-11-17 20:07:41 +00:00
|
|
|
struct mpv_global *global,
|
2014-12-03 20:54:04 +00:00
|
|
|
const struct gl_hwdec_driver *drv,
|
2014-12-09 16:47:02 +00:00
|
|
|
bool is_auto)
|
2014-12-03 20:54:04 +00:00
|
|
|
{
|
|
|
|
struct gl_hwdec *hwdec = talloc(NULL, struct gl_hwdec);
|
|
|
|
*hwdec = (struct gl_hwdec) {
|
|
|
|
.driver = drv,
|
2016-02-01 19:02:52 +00:00
|
|
|
.log = mp_log_new(hwdec, log, drv->name),
|
2015-11-17 20:07:41 +00:00
|
|
|
.global = global,
|
2014-12-03 20:54:04 +00:00
|
|
|
.gl = gl,
|
|
|
|
.gl_texture_target = GL_TEXTURE_2D,
|
2015-11-09 10:58:38 +00:00
|
|
|
.probing = is_auto,
|
2014-12-03 20:54:04 +00:00
|
|
|
};
|
2016-02-01 19:02:52 +00:00
|
|
|
mp_verbose(log, "Loading hwdec driver '%s'\n", drv->name);
|
2014-12-03 20:54:04 +00:00
|
|
|
if (hwdec->driver->create(hwdec) < 0) {
|
|
|
|
talloc_free(hwdec);
|
2015-07-03 13:12:42 +00:00
|
|
|
mp_verbose(log, "Loading failed.\n");
|
2014-12-03 20:54:04 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return hwdec;
|
|
|
|
}
|
|
|
|
|
2016-02-01 19:02:52 +00:00
|
|
|
struct gl_hwdec *gl_hwdec_load_api_id(struct mp_log *log, GL *gl,
|
|
|
|
struct mpv_global *g, int id)
|
2014-12-03 20:54:04 +00:00
|
|
|
{
|
2016-02-01 19:02:52 +00:00
|
|
|
bool is_auto = id == HWDEC_AUTO;
|
2014-12-03 20:54:04 +00:00
|
|
|
for (int n = 0; mpgl_hwdec_drivers[n]; n++) {
|
|
|
|
const struct gl_hwdec_driver *drv = mpgl_hwdec_drivers[n];
|
2016-02-01 19:02:52 +00:00
|
|
|
if (is_auto || id == drv->api) {
|
2015-11-17 20:07:41 +00:00
|
|
|
struct gl_hwdec *r = load_hwdec_driver(log, gl, g, drv, is_auto);
|
2014-12-03 20:54:04 +00:00
|
|
|
if (r)
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-02-01 19:02:52 +00:00
|
|
|
// Like gl_hwdec_load_api_id(), but use option names.
|
|
|
|
struct gl_hwdec *gl_hwdec_load_api(struct mp_log *log, GL *gl,
|
|
|
|
struct mpv_global *g, const char *api_name)
|
2015-07-07 12:53:58 +00:00
|
|
|
{
|
2016-02-01 19:02:52 +00:00
|
|
|
int id = HWDEC_NONE;
|
|
|
|
for (const struct m_opt_choice_alternatives *c = mp_hwdec_names; c->name; c++)
|
|
|
|
{
|
|
|
|
if (strcmp(c->name, api_name) == 0)
|
|
|
|
id = c->value;
|
|
|
|
}
|
|
|
|
return gl_hwdec_load_api_id(log, gl, g, id);
|
2015-07-07 12:53:58 +00:00
|
|
|
}
|
|
|
|
|
2014-12-03 20:54:04 +00:00
|
|
|
void gl_hwdec_uninit(struct gl_hwdec *hwdec)
|
|
|
|
{
|
|
|
|
if (hwdec)
|
|
|
|
hwdec->driver->destroy(hwdec);
|
|
|
|
talloc_free(hwdec);
|
|
|
|
}
|