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-04-27 11:49:47 +00:00
|
|
|
extern const struct gl_hwdec_driver gl_hwdec_d3d11egl;
|
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-05-11 12:37:03 +00:00
|
|
|
#if HAVE_D3D_HWACCEL
|
2016-03-08 03:53:24 +00:00
|
|
|
#if HAVE_EGL_ANGLE
|
2016-04-27 11:49:47 +00:00
|
|
|
&gl_hwdec_d3d11egl,
|
2016-03-08 03:53:24 +00:00
|
|
|
&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,
|
2016-05-09 17:42:03 +00:00
|
|
|
struct mp_hwdec_devices *devs,
|
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,
|
2016-05-09 17:42:03 +00:00
|
|
|
.devs = devs,
|
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-05-09 17:42:03 +00:00
|
|
|
struct gl_hwdec *gl_hwdec_load_api(struct mp_log *log, GL *gl,
|
|
|
|
struct mpv_global *g,
|
|
|
|
struct mp_hwdec_devices *devs,
|
|
|
|
enum hwdec_type api)
|
2014-12-03 20:54:04 +00:00
|
|
|
{
|
2016-05-11 14:18:58 +00:00
|
|
|
bool is_auto = HWDEC_IS_AUTO(api);
|
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-05-09 17:42:03 +00:00
|
|
|
if (is_auto || api == drv->api) {
|
|
|
|
struct gl_hwdec *r = load_hwdec_driver(log, gl, g, devs, drv, is_auto);
|
2014-12-03 20:54:04 +00:00
|
|
|
if (r)
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void gl_hwdec_uninit(struct gl_hwdec *hwdec)
|
|
|
|
{
|
|
|
|
if (hwdec)
|
|
|
|
hwdec->driver->destroy(hwdec);
|
|
|
|
talloc_free(hwdec);
|
|
|
|
}
|