2009-02-08 04:27:30 +01:00
|
|
|
/*
|
|
|
|
* libvo common functions, variables used by many/all drivers.
|
|
|
|
*
|
|
|
|
* This file is part of MPlayer.
|
|
|
|
*
|
|
|
|
* MPlayer is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* MPlayer is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
2001-02-24 21:28:24 +01:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2009-09-17 16:47:43 +02:00
|
|
|
#include <assert.h>
|
2009-09-18 15:27:55 +02:00
|
|
|
#include <stdbool.h>
|
2001-02-24 21:28:24 +01:00
|
|
|
|
|
|
|
#include <unistd.h>
|
2013-03-02 22:50:09 +01:00
|
|
|
|
2013-06-15 19:23:53 +02:00
|
|
|
#include <libavutil/common.h>
|
|
|
|
|
2013-03-02 22:50:09 +01:00
|
|
|
#include "talloc.h"
|
2001-02-24 21:28:24 +01:00
|
|
|
|
|
|
|
#include "config.h"
|
2013-03-02 22:50:09 +01:00
|
|
|
#include "osdep/timer.h"
|
2013-12-17 02:02:25 +01:00
|
|
|
#include "options/options.h"
|
2013-12-17 02:39:45 +01:00
|
|
|
#include "bstr/bstr.h"
|
2012-11-09 01:06:43 +01:00
|
|
|
#include "vo.h"
|
2007-02-17 21:58:55 +01:00
|
|
|
#include "aspect.h"
|
2013-12-17 01:23:09 +01:00
|
|
|
#include "input/input.h"
|
2013-12-17 02:02:25 +01:00
|
|
|
#include "options/m_config.h"
|
2013-12-17 02:39:45 +01:00
|
|
|
#include "common/msg.h"
|
|
|
|
#include "common/global.h"
|
video/filter: change filter API, use refcounting, remove filter DR
Change the entire filter API to use reference counted images instead
of vf_get_image().
Remove filter "direct rendering". This was useful for vf_expand and (in
rare cases) vf_sub: DR allowed these filters to pass a cropped image to
the filters before them. Then, on filtering, the image was "uncropped",
so that black bars could be added around the image without copying. This
means that in some cases, vf_expand will be slower (-vf gradfun,expand
for example).
Note that another form of DR used for in-place filters has been replaced
by simpler logic. Instead of trying to do DR, filters can check if the
image is writeable (with mp_image_is_writeable()), and do true in-place
if that's the case. This affects filters like vf_gradfun and vf_sub.
Everything has to support strides now. If something doesn't, making a
copy of the image data is required.
2012-11-05 14:25:04 +01:00
|
|
|
#include "video/mp_image.h"
|
2012-11-09 01:06:43 +01:00
|
|
|
#include "video/vfcap.h"
|
2013-11-24 12:58:06 +01:00
|
|
|
#include "sub/osd.h"
|
2002-09-29 23:53:05 +02:00
|
|
|
|
2001-02-24 21:28:24 +01:00
|
|
|
//
|
|
|
|
// Externally visible list of all vo drivers
|
|
|
|
//
|
2008-04-03 05:25:41 +02:00
|
|
|
extern struct vo_driver video_out_x11;
|
2009-02-18 00:07:37 +01:00
|
|
|
extern struct vo_driver video_out_vdpau;
|
2008-04-03 05:25:41 +02:00
|
|
|
extern struct vo_driver video_out_xv;
|
2012-09-23 16:10:00 +02:00
|
|
|
extern struct vo_driver video_out_opengl;
|
2012-09-29 18:36:05 +02:00
|
|
|
extern struct vo_driver video_out_opengl_hq;
|
2012-09-23 16:10:00 +02:00
|
|
|
extern struct vo_driver video_out_opengl_old;
|
2008-04-03 05:25:41 +02:00
|
|
|
extern struct vo_driver video_out_null;
|
2012-08-06 17:52:17 +02:00
|
|
|
extern struct vo_driver video_out_image;
|
2012-09-14 17:51:26 +02:00
|
|
|
extern struct vo_driver video_out_lavc;
|
2008-04-03 05:25:41 +02:00
|
|
|
extern struct vo_driver video_out_caca;
|
2008-11-22 18:16:43 +01:00
|
|
|
extern struct vo_driver video_out_direct3d;
|
2011-11-04 08:39:20 +01:00
|
|
|
extern struct vo_driver video_out_direct3d_shaders;
|
2012-12-28 08:07:14 +01:00
|
|
|
extern struct vo_driver video_out_sdl;
|
2009-05-08 22:50:26 +02:00
|
|
|
extern struct vo_driver video_out_corevideo;
|
video: add vaapi decode and output support
This is based on the MPlayer VA API patches. To be exact it's based on
a very stripped down version of commit f1ad459a263f8537f6c from
git://gitorious.org/vaapi/mplayer.git.
This doesn't contain useless things like benchmarking hacks and the
demo code for GLX interop. Also, unlike in the original patch, decoding
and video output are split into separate source files (the separation
between decoding and display also makes pixel format hacks unnecessary).
On the other hand, some features not present in the original patch were
added, like screenshot support.
VA API is rather bad for actual video output. Dealing with older libva
versions or the completely broken vdpau backend doesn't help. OSD is
low quality and should be rather slow. In some cases, only either OSD
or subtitles can be shown at the same time (because OSD is drawn first,
OSD is prefered).
Also, libva can't decide whether it accepts straight or premultiplied
alpha for OSD sub-pictures: the vdpau backend seems to assume
premultiplied, while a native vaapi driver uses straight. So I picked
straight alpha. It doesn't matter much, because the blending code for
straight alpha I added to img_convert.c is probably buggy, and ASS
subtitles might be blended incorrectly.
Really good video output with VA API would probably use OpenGL and the
GL interop features, but at this point you might just use vo_opengl.
(Patches for making HW decoding with vo_opengl have a chance of being
accepted.)
Despite these issues, decoding seems to work ok. I still got tearing
on the Intel system I tested (Intel(R) Core(TM) i3-2350M). It was also
tested with the vdpau vaapi wrapper on a nvidia system; however this
was rather broken. (Fortunately, there is no reason to use mpv's VAAPI
support over native VDPAU.)
2013-08-09 14:01:30 +02:00
|
|
|
extern struct vo_driver video_out_vaapi;
|
2013-04-15 22:37:02 +02:00
|
|
|
extern struct vo_driver video_out_wayland;
|
2008-04-03 05:25:41 +02:00
|
|
|
|
|
|
|
const struct vo_driver *video_out_drivers[] =
|
2001-02-24 21:28:24 +01:00
|
|
|
{
|
2013-07-16 13:28:28 +02:00
|
|
|
#if HAVE_VDPAU
|
2013-02-06 22:29:21 +01:00
|
|
|
&video_out_vdpau,
|
|
|
|
#endif
|
2013-07-16 13:28:28 +02:00
|
|
|
#if HAVE_GL
|
2013-02-06 22:29:21 +01:00
|
|
|
&video_out_opengl,
|
|
|
|
#endif
|
2013-07-16 13:28:28 +02:00
|
|
|
#if HAVE_DIRECT3D
|
2011-11-04 08:39:20 +01:00
|
|
|
&video_out_direct3d_shaders,
|
2012-02-28 00:25:17 +01:00
|
|
|
&video_out_direct3d,
|
2008-11-18 14:18:55 +01:00
|
|
|
#endif
|
2013-07-16 13:28:28 +02:00
|
|
|
#if HAVE_COREVIDEO
|
2009-05-04 18:55:05 +02:00
|
|
|
&video_out_corevideo,
|
2005-05-05 02:17:27 +02:00
|
|
|
#endif
|
2013-07-16 13:28:28 +02:00
|
|
|
#if HAVE_XV
|
2009-09-18 23:25:36 +02:00
|
|
|
&video_out_xv,
|
|
|
|
#endif
|
2013-07-16 13:28:28 +02:00
|
|
|
#if HAVE_SDL2
|
2012-12-28 08:07:14 +01:00
|
|
|
&video_out_sdl,
|
|
|
|
#endif
|
2013-07-16 13:28:28 +02:00
|
|
|
#if HAVE_GL
|
2013-02-06 22:29:21 +01:00
|
|
|
&video_out_opengl_old,
|
|
|
|
#endif
|
2013-07-16 13:28:28 +02:00
|
|
|
#if HAVE_VAAPI
|
video: add vaapi decode and output support
This is based on the MPlayer VA API patches. To be exact it's based on
a very stripped down version of commit f1ad459a263f8537f6c from
git://gitorious.org/vaapi/mplayer.git.
This doesn't contain useless things like benchmarking hacks and the
demo code for GLX interop. Also, unlike in the original patch, decoding
and video output are split into separate source files (the separation
between decoding and display also makes pixel format hacks unnecessary).
On the other hand, some features not present in the original patch were
added, like screenshot support.
VA API is rather bad for actual video output. Dealing with older libva
versions or the completely broken vdpau backend doesn't help. OSD is
low quality and should be rather slow. In some cases, only either OSD
or subtitles can be shown at the same time (because OSD is drawn first,
OSD is prefered).
Also, libva can't decide whether it accepts straight or premultiplied
alpha for OSD sub-pictures: the vdpau backend seems to assume
premultiplied, while a native vaapi driver uses straight. So I picked
straight alpha. It doesn't matter much, because the blending code for
straight alpha I added to img_convert.c is probably buggy, and ASS
subtitles might be blended incorrectly.
Really good video output with VA API would probably use OpenGL and the
GL interop features, but at this point you might just use vo_opengl.
(Patches for making HW decoding with vo_opengl have a chance of being
accepted.)
Despite these issues, decoding seems to work ok. I still got tearing
on the Intel system I tested (Intel(R) Core(TM) i3-2350M). It was also
tested with the vdpau vaapi wrapper on a nvidia system; however this
was rather broken. (Fortunately, there is no reason to use mpv's VAAPI
support over native VDPAU.)
2013-08-09 14:01:30 +02:00
|
|
|
&video_out_vaapi,
|
|
|
|
#endif
|
2013-07-16 13:28:28 +02:00
|
|
|
#if HAVE_X11
|
2001-02-24 21:28:24 +01:00
|
|
|
&video_out_x11,
|
2004-10-04 21:36:12 +02:00
|
|
|
#endif
|
|
|
|
&video_out_null,
|
2008-12-20 12:49:00 +01:00
|
|
|
// should not be auto-selected
|
2012-08-06 17:52:17 +02:00
|
|
|
&video_out_image,
|
2013-07-16 13:28:28 +02:00
|
|
|
#if HAVE_CACA
|
2013-02-06 22:29:21 +01:00
|
|
|
&video_out_caca,
|
|
|
|
#endif
|
2013-07-16 13:28:28 +02:00
|
|
|
#if HAVE_ENCODING
|
2012-09-14 17:51:26 +02:00
|
|
|
&video_out_lavc,
|
2012-09-29 18:36:05 +02:00
|
|
|
#endif
|
2013-07-16 13:28:28 +02:00
|
|
|
#if HAVE_GL
|
2012-09-29 18:36:05 +02:00
|
|
|
&video_out_opengl_hq,
|
2013-04-15 22:37:02 +02:00
|
|
|
#endif
|
2013-07-16 13:28:28 +02:00
|
|
|
#if HAVE_WAYLAND
|
2013-04-15 22:37:02 +02:00
|
|
|
&video_out_wayland,
|
2004-10-24 00:43:19 +02:00
|
|
|
#endif
|
2001-02-24 21:28:24 +01:00
|
|
|
NULL
|
|
|
|
};
|
2002-05-13 15:15:40 +02:00
|
|
|
|
2014-04-29 15:19:03 +02:00
|
|
|
static void forget_frames(struct vo *vo);
|
|
|
|
|
2013-07-21 21:17:48 +02:00
|
|
|
static bool get_desc(struct m_obj_desc *dst, int index)
|
|
|
|
{
|
|
|
|
if (index >= MP_ARRAY_SIZE(video_out_drivers) - 1)
|
|
|
|
return false;
|
|
|
|
const struct vo_driver *vo = video_out_drivers[index];
|
|
|
|
*dst = (struct m_obj_desc) {
|
2013-10-23 19:06:14 +02:00
|
|
|
.name = vo->name,
|
|
|
|
.description = vo->description,
|
2013-07-21 21:17:48 +02:00
|
|
|
.priv_size = vo->priv_size,
|
|
|
|
.priv_defaults = vo->priv_defaults,
|
|
|
|
.options = vo->options,
|
2013-07-21 22:03:53 +02:00
|
|
|
.hidden = vo->encode,
|
2013-07-21 21:17:48 +02:00
|
|
|
.p = vo,
|
|
|
|
};
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// For the vo option
|
|
|
|
const struct m_obj_list vo_obj_list = {
|
|
|
|
.get_desc = get_desc,
|
|
|
|
.description = "video outputs",
|
|
|
|
.aliases = {
|
|
|
|
{"gl", "opengl"},
|
|
|
|
{"gl3", "opengl-hq"},
|
|
|
|
{0}
|
|
|
|
},
|
|
|
|
.allow_unknown_entries = true,
|
|
|
|
.allow_trailer = true,
|
|
|
|
};
|
2008-04-03 05:25:41 +02:00
|
|
|
|
2014-04-22 21:06:23 +02:00
|
|
|
static int event_fd_callback(void *ctx, int fd)
|
|
|
|
{
|
|
|
|
struct vo *vo = ctx;
|
|
|
|
vo_check_events(vo);
|
|
|
|
return MP_INPUT_NOTHING;
|
|
|
|
}
|
|
|
|
|
2013-07-31 21:44:21 +02:00
|
|
|
static struct vo *vo_create(struct mpv_global *global,
|
2013-07-21 21:17:48 +02:00
|
|
|
struct input_ctx *input_ctx,
|
|
|
|
struct encode_lavc_context *encode_lavc_ctx,
|
|
|
|
char *name, char **args)
|
2008-04-03 05:25:41 +02:00
|
|
|
{
|
2013-07-31 21:44:21 +02:00
|
|
|
struct mp_log *log = mp_log_new(NULL, global->log, "vo");
|
2013-07-21 21:17:48 +02:00
|
|
|
struct m_obj_desc desc;
|
|
|
|
if (!m_obj_list_find(&desc, &vo_obj_list, bstr0(name))) {
|
2013-12-21 21:49:13 +01:00
|
|
|
mp_msg(log, MSGL_ERR, "Video output %s not found!\n", name);
|
2013-07-31 21:44:21 +02:00
|
|
|
talloc_free(log);
|
2013-07-21 21:17:48 +02:00
|
|
|
return NULL;
|
|
|
|
};
|
|
|
|
struct vo *vo = talloc_ptrtype(NULL, vo);
|
|
|
|
*vo = (struct vo) {
|
2013-07-31 21:44:21 +02:00
|
|
|
.log = mp_log_new(vo, log, name),
|
2013-07-21 21:17:48 +02:00
|
|
|
.driver = desc.p,
|
2013-07-31 21:44:21 +02:00
|
|
|
.opts = &global->opts->vo,
|
2013-12-21 17:51:20 +01:00
|
|
|
.global = global,
|
2013-07-21 21:17:48 +02:00
|
|
|
.encode_lavc_ctx = encode_lavc_ctx,
|
|
|
|
.input_ctx = input_ctx,
|
|
|
|
.event_fd = -1,
|
2014-01-11 18:44:27 +01:00
|
|
|
.monitor_par = 1,
|
2014-04-29 15:19:03 +02:00
|
|
|
.max_video_queue = 1,
|
2013-07-21 21:17:48 +02:00
|
|
|
};
|
2014-01-22 00:26:01 +01:00
|
|
|
talloc_steal(vo, log);
|
2013-02-06 22:54:03 +01:00
|
|
|
if (vo->driver->encode != !!vo->encode_lavc_ctx)
|
2013-07-21 21:17:48 +02:00
|
|
|
goto error;
|
2013-12-21 19:45:42 +01:00
|
|
|
struct m_config *config = m_config_from_obj_desc(vo, vo->log, &desc);
|
2013-12-01 00:12:10 +01:00
|
|
|
if (m_config_apply_defaults(config, name, vo->opts->vo_defs) < 0)
|
|
|
|
goto error;
|
2013-07-22 22:52:42 +02:00
|
|
|
if (m_config_set_obj_params(config, args) < 0)
|
2013-07-21 21:17:48 +02:00
|
|
|
goto error;
|
2013-07-22 22:52:42 +02:00
|
|
|
vo->priv = config->optstruct;
|
|
|
|
if (vo->driver->preinit(vo))
|
2013-07-21 21:17:48 +02:00
|
|
|
goto error;
|
2014-04-22 21:06:23 +02:00
|
|
|
if (vo->event_fd != -1) {
|
|
|
|
mp_input_add_fd(vo->input_ctx, vo->event_fd, 1, NULL, event_fd_callback,
|
|
|
|
NULL, vo);
|
|
|
|
}
|
2013-07-21 21:17:48 +02:00
|
|
|
return vo;
|
|
|
|
error:
|
|
|
|
talloc_free(vo);
|
|
|
|
return NULL;
|
2008-04-03 05:25:41 +02:00
|
|
|
}
|
|
|
|
|
2013-07-31 21:44:21 +02:00
|
|
|
struct vo *init_best_video_out(struct mpv_global *global,
|
2012-09-14 17:51:26 +02:00
|
|
|
struct input_ctx *input_ctx,
|
|
|
|
struct encode_lavc_context *encode_lavc_ctx)
|
2008-04-03 03:58:32 +02:00
|
|
|
{
|
2013-07-31 21:44:21 +02:00
|
|
|
struct m_obj_settings *vo_list = global->opts->vo.video_driver_list;
|
2002-09-29 23:53:05 +02:00
|
|
|
// first try the preferred drivers, with their optional subdevice param:
|
2013-07-21 21:17:48 +02:00
|
|
|
if (vo_list && vo_list[0].name) {
|
|
|
|
for (int n = 0; vo_list[n].name; n++) {
|
|
|
|
// Something like "-vo name," allows fallback to autoprobing.
|
|
|
|
if (strlen(vo_list[n].name) == 0)
|
|
|
|
goto autoprobe;
|
2013-07-31 21:44:21 +02:00
|
|
|
struct vo *vo = vo_create(global, input_ctx, encode_lavc_ctx,
|
2013-07-21 21:17:48 +02:00
|
|
|
vo_list[n].name, vo_list[n].attribs);
|
|
|
|
if (vo)
|
|
|
|
return vo;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
autoprobe:
|
2002-09-29 23:53:05 +02:00
|
|
|
// now try the rest...
|
2013-07-21 21:17:48 +02:00
|
|
|
for (int i = 0; video_out_drivers[i]; i++) {
|
2013-07-31 21:44:21 +02:00
|
|
|
struct vo *vo = vo_create(global, input_ctx, encode_lavc_ctx,
|
2013-10-23 19:06:14 +02:00
|
|
|
(char *)video_out_drivers[i]->name, NULL);
|
2013-07-21 21:17:48 +02:00
|
|
|
if (vo)
|
|
|
|
return vo;
|
2002-09-29 23:53:05 +02:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-04-22 21:03:52 +02:00
|
|
|
void vo_destroy(struct vo *vo)
|
|
|
|
{
|
2014-04-22 21:06:23 +02:00
|
|
|
if (vo->event_fd != -1)
|
|
|
|
mp_input_rm_key_fd(vo->input_ctx, vo->event_fd);
|
2014-04-29 15:19:03 +02:00
|
|
|
forget_frames(vo);
|
2014-04-22 21:03:52 +02:00
|
|
|
vo->driver->uninit(vo);
|
|
|
|
talloc_free(vo);
|
|
|
|
}
|
|
|
|
|
2014-04-21 22:53:51 +02:00
|
|
|
static void check_vo_caps(struct vo *vo)
|
|
|
|
{
|
|
|
|
int rot = vo->params->rotate;
|
|
|
|
if (rot) {
|
|
|
|
bool ok = rot % 90 ? false : (vo->driver->caps & VO_CAP_ROTATE90);
|
|
|
|
if (!ok) {
|
|
|
|
MP_WARN(vo, "Video is flagged as rotated by %d degrees, but the "
|
|
|
|
"video output does not support this.\n", rot);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-08 01:35:44 +02:00
|
|
|
int vo_reconfig(struct vo *vo, struct mp_image_params *params, int flags)
|
2008-04-03 03:58:32 +02:00
|
|
|
{
|
2014-05-06 20:22:32 +02:00
|
|
|
vo->dwidth = params->d_w;
|
|
|
|
vo->dheight = params->d_h;
|
2007-02-17 21:58:55 +01:00
|
|
|
|
2014-01-22 00:26:01 +01:00
|
|
|
talloc_free(vo->params);
|
2014-01-24 21:22:25 +01:00
|
|
|
vo->params = talloc_memdup(vo, params, sizeof(*params));
|
2014-01-22 00:26:01 +01:00
|
|
|
|
2014-01-24 21:22:25 +01:00
|
|
|
int ret = vo->driver->reconfig(vo, vo->params, flags);
|
|
|
|
vo->config_ok = ret >= 0;
|
2014-04-21 22:53:51 +02:00
|
|
|
if (vo->config_ok) {
|
|
|
|
check_vo_caps(vo);
|
|
|
|
} else {
|
2014-01-22 00:26:01 +01:00
|
|
|
talloc_free(vo->params);
|
|
|
|
vo->params = NULL;
|
|
|
|
}
|
2014-04-29 15:19:03 +02:00
|
|
|
forget_frames(vo);
|
2012-02-28 02:17:25 +01:00
|
|
|
vo->hasframe = false;
|
2008-04-18 05:28:47 +02:00
|
|
|
return ret;
|
2007-02-17 21:58:55 +01:00
|
|
|
}
|
2002-09-29 23:53:05 +02:00
|
|
|
|
2014-04-22 21:03:52 +02:00
|
|
|
int vo_control(struct vo *vo, uint32_t request, void *data)
|
|
|
|
{
|
|
|
|
return vo->driver->control(vo, request, data);
|
|
|
|
}
|
|
|
|
|
2014-04-29 15:19:03 +02:00
|
|
|
static void forget_frames(struct vo *vo)
|
|
|
|
{
|
|
|
|
for (int n = 0; n < vo->num_video_queue; n++)
|
|
|
|
talloc_free(vo->video_queue[n]);
|
|
|
|
vo->num_video_queue = 0;
|
|
|
|
}
|
|
|
|
|
2014-04-22 21:03:52 +02:00
|
|
|
void vo_queue_image(struct vo *vo, struct mp_image *mpi)
|
|
|
|
{
|
2014-04-29 15:19:03 +02:00
|
|
|
assert(mpi);
|
2014-04-22 21:03:52 +02:00
|
|
|
if (!vo->config_ok)
|
|
|
|
return;
|
2014-05-01 14:29:43 +02:00
|
|
|
assert(mp_image_params_equals(vo->params, &mpi->params));
|
2014-04-29 15:19:03 +02:00
|
|
|
mpi = mp_image_new_ref(mpi);
|
|
|
|
if (vo->driver->filter_image)
|
|
|
|
mpi = vo->driver->filter_image(vo, mpi);
|
|
|
|
if (!mpi) {
|
|
|
|
MP_ERR(vo, "Could not upload image.\n");
|
2014-04-22 21:03:52 +02:00
|
|
|
return;
|
|
|
|
}
|
2014-04-29 15:19:03 +02:00
|
|
|
assert(vo->max_video_queue <= VO_MAX_QUEUE);
|
|
|
|
assert(vo->num_video_queue < vo->max_video_queue);
|
|
|
|
vo->video_queue[vo->num_video_queue++] = mpi;
|
2014-05-01 23:53:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Return whether vo_queue_image() should be called.
|
|
|
|
bool vo_needs_new_image(struct vo *vo)
|
|
|
|
{
|
2014-05-22 09:28:39 +02:00
|
|
|
return vo->config_ok && vo->num_video_queue < vo->max_video_queue;
|
2014-05-01 23:53:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Return whether a frame can be displayed.
|
|
|
|
// eof==true: return true if at least one frame is queued
|
|
|
|
// eof==false: return true if "enough" frames are queued
|
|
|
|
bool vo_has_next_frame(struct vo *vo, bool eof)
|
|
|
|
{
|
|
|
|
// Normally, buffer 1 image ahead, except if the queue is limited to less
|
|
|
|
// than 2 entries, or if EOF is reached and there aren't enough images left.
|
|
|
|
return eof ? vo->num_video_queue : vo->num_video_queue == vo->max_video_queue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return the PTS of a future frame (where index==0 is the next frame)
|
|
|
|
double vo_get_next_pts(struct vo *vo, int index)
|
|
|
|
{
|
|
|
|
if (index < 0 || index >= vo->num_video_queue)
|
|
|
|
return MP_NOPTS_VALUE;
|
|
|
|
return vo->video_queue[index]->pts;
|
2014-04-22 21:03:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int vo_redraw_frame(struct vo *vo)
|
|
|
|
{
|
2014-05-22 09:28:39 +02:00
|
|
|
if (vo->config_ok && vo_control(vo, VOCTRL_REDRAW_FRAME, NULL) == true) {
|
2014-04-22 21:03:52 +02:00
|
|
|
vo->want_redraw = false;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool vo_get_want_redraw(struct vo *vo)
|
|
|
|
{
|
2014-05-22 09:28:39 +02:00
|
|
|
return vo->config_ok && vo->want_redraw;
|
2014-04-22 21:03:52 +02:00
|
|
|
}
|
|
|
|
|
2014-04-29 15:19:03 +02:00
|
|
|
// Remove vo->video_queue[0]
|
|
|
|
static void shift_queue(struct vo *vo)
|
|
|
|
{
|
|
|
|
if (!vo->num_video_queue)
|
|
|
|
return;
|
|
|
|
talloc_free(vo->video_queue[0]);
|
|
|
|
vo->num_video_queue--;
|
|
|
|
for (int n = 0; n < vo->num_video_queue; n++)
|
|
|
|
vo->video_queue[n] = vo->video_queue[n + 1];
|
|
|
|
}
|
|
|
|
|
2014-04-22 21:03:52 +02:00
|
|
|
void vo_new_frame_imminent(struct vo *vo)
|
|
|
|
{
|
2014-04-29 15:19:03 +02:00
|
|
|
assert(vo->num_video_queue > 0);
|
|
|
|
vo->driver->draw_image(vo, vo->video_queue[0]);
|
|
|
|
shift_queue(vo);
|
2014-04-22 21:03:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void vo_draw_osd(struct vo *vo, struct osd_state *osd)
|
|
|
|
{
|
|
|
|
if (vo->config_ok && vo->driver->draw_osd)
|
|
|
|
vo->driver->draw_osd(vo, osd);
|
|
|
|
}
|
|
|
|
|
|
|
|
void vo_flip_page(struct vo *vo, int64_t pts_us, int duration)
|
|
|
|
{
|
|
|
|
if (!vo->config_ok)
|
|
|
|
return;
|
|
|
|
vo->want_redraw = false;
|
|
|
|
if (vo->driver->flip_page_timed)
|
|
|
|
vo->driver->flip_page_timed(vo, pts_us, duration);
|
|
|
|
else
|
|
|
|
vo->driver->flip_page(vo);
|
|
|
|
vo->hasframe = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void vo_check_events(struct vo *vo)
|
|
|
|
{
|
2014-05-22 09:28:28 +02:00
|
|
|
vo_control(vo, VOCTRL_CHECK_EVENTS, NULL);
|
2014-04-22 21:03:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void vo_seek_reset(struct vo *vo)
|
|
|
|
{
|
|
|
|
vo_control(vo, VOCTRL_RESET, NULL);
|
2014-04-29 15:19:03 +02:00
|
|
|
forget_frames(vo);
|
2014-04-22 21:03:52 +02:00
|
|
|
vo->hasframe = false;
|
2008-12-20 12:52:11 +01:00
|
|
|
}
|
|
|
|
|
2014-01-22 00:26:01 +01:00
|
|
|
// Calculate the appropriate source and destination rectangle to
|
|
|
|
// get a correctly scaled picture, including pan-scan.
|
|
|
|
// out_src: visible part of the video
|
|
|
|
// out_dst: area of screen covered by the video source rectangle
|
|
|
|
// out_osd: OSD size, OSD margins, etc.
|
|
|
|
void vo_get_src_dst_rects(struct vo *vo, struct mp_rect *out_src,
|
|
|
|
struct mp_rect *out_dst, struct mp_osd_res *out_osd)
|
|
|
|
{
|
2014-05-06 01:04:51 +02:00
|
|
|
if (!vo->params)
|
2014-05-06 00:33:59 +02:00
|
|
|
return;
|
2014-04-20 21:36:56 +02:00
|
|
|
mp_get_src_dst_rects(vo->log, vo->opts, vo->driver->caps, vo->params,
|
|
|
|
vo->dwidth, vo->dheight, vo->monitor_par,
|
|
|
|
out_src, out_dst, out_osd);
|
2014-01-22 00:26:01 +01:00
|
|
|
}
|
|
|
|
|
2011-12-06 20:23:54 +01:00
|
|
|
// Return the window title the VO should set. Always returns a null terminated
|
|
|
|
// string. The string is valid until frontend code is invoked again. Copy it if
|
|
|
|
// you need to keep the string for an extended period of time.
|
|
|
|
const char *vo_get_window_title(struct vo *vo)
|
|
|
|
{
|
2012-08-16 16:18:51 +02:00
|
|
|
if (!vo->window_title)
|
|
|
|
vo->window_title = talloc_strdup(vo, "");
|
2012-08-02 02:36:26 +02:00
|
|
|
return vo->window_title;
|
2011-12-06 20:23:54 +01:00
|
|
|
}
|
|
|
|
|
2010-04-25 18:13:57 +02:00
|
|
|
/**
|
|
|
|
* Generates a mouse movement message if those are enable and sends it
|
|
|
|
* to the "main" MPlayer.
|
|
|
|
*
|
|
|
|
* \param posx new x position of mouse
|
|
|
|
* \param posy new y position of mouse
|
|
|
|
*/
|
2010-04-26 18:22:56 +02:00
|
|
|
void vo_mouse_movement(struct vo *vo, int posx, int posy)
|
|
|
|
{
|
input: handle mouse movement differently
Before this commit, mouse movement events emitted a special command
("set_mouse_pos"), which was specially handled in command.c. This was
once special-cased to the dvdnav and menu code, and did nothing after
libmenu and dvdnav were removed.
Change it so that mouse movement triggers a pseudo-key ("MOUSE_MOVE"),
which then can be bound to an arbitrary command. The mouse position is
now managed in input.c. A command which actually needs the mouse
position can use either mp_input_get_mouse_pos() or mp_get_osd_mouse_pos()
to query it. The former returns raw window-space coordinates, while the
latter returns coordinates transformed to OSD- space. (Both are the same
for most VOs, except vo_xv and vo_x11, which can't render OSD in
window-space. These require extra code for mapping mouse position.)
As of this commit, there is still nothing that uses mouse movement, so
MOUSE_MOVE is mapped to "ignore" to silence warnings when moving the
mouse (much like MOUSE_BTN0).
Extend the concept of input sections. Allow multiple sections to be
active at once, and organize them as stack. Bindings from the top of
the stack are preferred to lower ones.
Each section has a mouse input section associated, inside which mouse
events are associated with the bindings. If the mouse pointer is
outside of a section's mouse area, mouse events will be dispatched to
an input section lower on the stack of active sections. This is intended
for scripting, which is to be added later. Two scripts could occupy
different areas of the screen without conflicting with each other. (If
it turns out that this mechanism is useless, we'll just remove it
again.)
2013-04-26 02:13:30 +02:00
|
|
|
if (!vo->opts->enable_mouse_movements)
|
|
|
|
return;
|
2013-09-27 15:39:28 +02:00
|
|
|
float p[2] = {posx, posy};
|
|
|
|
vo_control(vo, VOCTRL_WINDOW_TO_OSD_COORDS, p);
|
|
|
|
mp_input_set_mouse_pos(vo->input_ctx, p[0], p[1]);
|
2010-04-25 18:13:57 +02:00
|
|
|
}
|
2014-04-22 21:03:52 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief lookup an integer in a table, table must have 0 as the last key
|
|
|
|
* \param key key to search for
|
|
|
|
* \result translation corresponding to key or "to" value of last mapping
|
|
|
|
* if not found.
|
|
|
|
*/
|
|
|
|
int lookup_keymap_table(const struct mp_keymap *map, int key)
|
|
|
|
{
|
|
|
|
while (map->from && map->from != key)
|
|
|
|
map++;
|
|
|
|
return map->to;
|
|
|
|
}
|