2009-02-08 03:27:30 +00: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 20:28:24 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2009-09-17 14:47:43 +00:00
|
|
|
#include <assert.h>
|
2009-09-18 13:27:55 +00:00
|
|
|
#include <stdbool.h>
|
2001-02-24 20:28:24 +00:00
|
|
|
|
|
|
|
#include <unistd.h>
|
2013-03-02 21:50:09 +00:00
|
|
|
|
2013-06-15 17:23:53 +00:00
|
|
|
#include <libavutil/common.h>
|
|
|
|
|
2013-03-02 21:50:09 +00:00
|
|
|
#include "talloc.h"
|
2001-02-24 20:28:24 +00:00
|
|
|
|
|
|
|
#include "config.h"
|
2013-03-02 21:50:09 +00:00
|
|
|
#include "osdep/timer.h"
|
2013-12-17 01:02:25 +00:00
|
|
|
#include "options/options.h"
|
2013-12-17 01:39:45 +00:00
|
|
|
#include "bstr/bstr.h"
|
2012-11-09 00:06:43 +00:00
|
|
|
#include "vo.h"
|
2007-02-17 20:58:55 +00:00
|
|
|
#include "aspect.h"
|
2013-12-17 00:23:09 +00:00
|
|
|
#include "input/input.h"
|
2013-12-17 01:02:25 +00:00
|
|
|
#include "options/m_config.h"
|
2013-12-17 01:39:45 +00: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 13:25:04 +00:00
|
|
|
#include "video/mp_image.h"
|
2012-11-09 00:06:43 +00:00
|
|
|
#include "video/vfcap.h"
|
2013-11-24 11:58:06 +00:00
|
|
|
#include "sub/osd.h"
|
2002-09-29 21:53:05 +00:00
|
|
|
|
2001-02-24 20:28:24 +00:00
|
|
|
//
|
|
|
|
// Externally visible list of all vo drivers
|
|
|
|
//
|
2008-04-03 03:25:41 +00:00
|
|
|
extern struct vo_driver video_out_x11;
|
2009-02-17 23:07:37 +00:00
|
|
|
extern struct vo_driver video_out_vdpau;
|
2008-04-03 03:25:41 +00:00
|
|
|
extern struct vo_driver video_out_xv;
|
2012-09-23 14:10:00 +00:00
|
|
|
extern struct vo_driver video_out_opengl;
|
2012-09-29 16:36:05 +00:00
|
|
|
extern struct vo_driver video_out_opengl_hq;
|
2012-09-23 14:10:00 +00:00
|
|
|
extern struct vo_driver video_out_opengl_old;
|
2008-04-03 03:25:41 +00:00
|
|
|
extern struct vo_driver video_out_null;
|
2012-08-06 15:52:17 +00:00
|
|
|
extern struct vo_driver video_out_image;
|
2012-09-14 15:51:26 +00:00
|
|
|
extern struct vo_driver video_out_lavc;
|
2008-04-03 03:25:41 +00:00
|
|
|
extern struct vo_driver video_out_caca;
|
2008-11-22 17:16:43 +00:00
|
|
|
extern struct vo_driver video_out_direct3d;
|
2011-11-04 07:39:20 +00:00
|
|
|
extern struct vo_driver video_out_direct3d_shaders;
|
2012-12-28 07:07:14 +00:00
|
|
|
extern struct vo_driver video_out_sdl;
|
2009-05-08 20:50:26 +00: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 12:01:30 +00:00
|
|
|
extern struct vo_driver video_out_vaapi;
|
2013-04-15 20:37:02 +00:00
|
|
|
extern struct vo_driver video_out_wayland;
|
2008-04-03 03:25:41 +00:00
|
|
|
|
|
|
|
const struct vo_driver *video_out_drivers[] =
|
2001-02-24 20:28:24 +00:00
|
|
|
{
|
2013-07-16 11:28:28 +00:00
|
|
|
#if HAVE_VDPAU
|
2013-02-06 21:29:21 +00:00
|
|
|
&video_out_vdpau,
|
|
|
|
#endif
|
2013-07-16 11:28:28 +00:00
|
|
|
#if HAVE_GL
|
2013-02-06 21:29:21 +00:00
|
|
|
&video_out_opengl,
|
|
|
|
#endif
|
2013-07-16 11:28:28 +00:00
|
|
|
#if HAVE_DIRECT3D
|
2011-11-04 07:39:20 +00:00
|
|
|
&video_out_direct3d_shaders,
|
2012-02-27 23:25:17 +00:00
|
|
|
&video_out_direct3d,
|
2008-11-18 13:18:55 +00:00
|
|
|
#endif
|
2013-07-16 11:28:28 +00:00
|
|
|
#if HAVE_COREVIDEO
|
2009-05-04 16:55:05 +00:00
|
|
|
&video_out_corevideo,
|
2005-05-05 00:17:27 +00:00
|
|
|
#endif
|
2013-07-16 11:28:28 +00:00
|
|
|
#if HAVE_XV
|
2009-09-18 21:25:36 +00:00
|
|
|
&video_out_xv,
|
|
|
|
#endif
|
2013-07-16 11:28:28 +00:00
|
|
|
#if HAVE_SDL2
|
2012-12-28 07:07:14 +00:00
|
|
|
&video_out_sdl,
|
|
|
|
#endif
|
2013-07-16 11:28:28 +00:00
|
|
|
#if HAVE_GL
|
2013-02-06 21:29:21 +00:00
|
|
|
&video_out_opengl_old,
|
|
|
|
#endif
|
2013-07-16 11:28:28 +00: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 12:01:30 +00:00
|
|
|
&video_out_vaapi,
|
|
|
|
#endif
|
2013-07-16 11:28:28 +00:00
|
|
|
#if HAVE_X11
|
2001-02-24 20:28:24 +00:00
|
|
|
&video_out_x11,
|
2004-10-04 19:36:12 +00:00
|
|
|
#endif
|
|
|
|
&video_out_null,
|
2008-12-20 11:49:00 +00:00
|
|
|
// should not be auto-selected
|
2012-08-06 15:52:17 +00:00
|
|
|
&video_out_image,
|
2013-07-16 11:28:28 +00:00
|
|
|
#if HAVE_CACA
|
2013-02-06 21:29:21 +00:00
|
|
|
&video_out_caca,
|
|
|
|
#endif
|
2013-07-16 11:28:28 +00:00
|
|
|
#if HAVE_ENCODING
|
2012-09-14 15:51:26 +00:00
|
|
|
&video_out_lavc,
|
2012-09-29 16:36:05 +00:00
|
|
|
#endif
|
2013-07-16 11:28:28 +00:00
|
|
|
#if HAVE_GL
|
2012-09-29 16:36:05 +00:00
|
|
|
&video_out_opengl_hq,
|
2013-04-15 20:37:02 +00:00
|
|
|
#endif
|
2013-07-16 11:28:28 +00:00
|
|
|
#if HAVE_WAYLAND
|
2013-04-15 20:37:02 +00:00
|
|
|
&video_out_wayland,
|
2004-10-23 22:43:19 +00:00
|
|
|
#endif
|
2001-02-24 20:28:24 +00:00
|
|
|
NULL
|
|
|
|
};
|
2002-05-13 13:15:40 +00:00
|
|
|
|
2013-07-21 19:17:48 +00: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 17:06:14 +00:00
|
|
|
.name = vo->name,
|
|
|
|
.description = vo->description,
|
2013-07-21 19:17:48 +00:00
|
|
|
.priv_size = vo->priv_size,
|
|
|
|
.priv_defaults = vo->priv_defaults,
|
|
|
|
.options = vo->options,
|
2013-07-21 20:03:53 +00:00
|
|
|
.hidden = vo->encode,
|
2013-07-21 19:17:48 +00: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 03:25:41 +00:00
|
|
|
|
2013-07-31 19:44:21 +00:00
|
|
|
static struct vo *vo_create(struct mpv_global *global,
|
2013-07-21 19:17:48 +00:00
|
|
|
struct input_ctx *input_ctx,
|
|
|
|
struct encode_lavc_context *encode_lavc_ctx,
|
|
|
|
char *name, char **args)
|
2008-04-03 03:25:41 +00:00
|
|
|
{
|
2013-07-31 19:44:21 +00:00
|
|
|
struct mp_log *log = mp_log_new(NULL, global->log, "vo");
|
2013-07-21 19:17:48 +00:00
|
|
|
struct m_obj_desc desc;
|
|
|
|
if (!m_obj_list_find(&desc, &vo_obj_list, bstr0(name))) {
|
2013-12-21 20:49:13 +00:00
|
|
|
mp_msg(log, MSGL_ERR, "Video output %s not found!\n", name);
|
2013-07-31 19:44:21 +00:00
|
|
|
talloc_free(log);
|
2013-07-21 19:17:48 +00:00
|
|
|
return NULL;
|
|
|
|
};
|
|
|
|
struct vo *vo = talloc_ptrtype(NULL, vo);
|
|
|
|
*vo = (struct vo) {
|
2013-07-31 19:44:21 +00:00
|
|
|
.log = mp_log_new(vo, log, name),
|
2013-07-21 19:17:48 +00:00
|
|
|
.driver = desc.p,
|
2013-07-31 19:44:21 +00:00
|
|
|
.opts = &global->opts->vo,
|
2013-12-21 16:51:20 +00:00
|
|
|
.global = global,
|
2013-07-21 19:17:48 +00:00
|
|
|
.encode_lavc_ctx = encode_lavc_ctx,
|
|
|
|
.input_ctx = input_ctx,
|
|
|
|
.event_fd = -1,
|
|
|
|
.registered_fd = -1,
|
2014-01-11 17:44:27 +00:00
|
|
|
.monitor_par = 1,
|
2013-12-10 18:32:52 +00:00
|
|
|
.next_pts = MP_NOPTS_VALUE,
|
|
|
|
.next_pts2 = MP_NOPTS_VALUE,
|
2013-07-21 19:17:48 +00:00
|
|
|
};
|
2014-01-21 23:26:01 +00:00
|
|
|
talloc_steal(vo, log);
|
2013-02-06 21:54:03 +00:00
|
|
|
if (vo->driver->encode != !!vo->encode_lavc_ctx)
|
2013-07-21 19:17:48 +00:00
|
|
|
goto error;
|
2013-12-21 18:45:42 +00:00
|
|
|
struct m_config *config = m_config_from_obj_desc(vo, vo->log, &desc);
|
2013-11-30 23:12:10 +00:00
|
|
|
if (m_config_apply_defaults(config, name, vo->opts->vo_defs) < 0)
|
|
|
|
goto error;
|
2013-07-22 20:52:42 +00:00
|
|
|
if (m_config_set_obj_params(config, args) < 0)
|
2013-07-21 19:17:48 +00:00
|
|
|
goto error;
|
2013-07-22 20:52:42 +00:00
|
|
|
vo->priv = config->optstruct;
|
|
|
|
if (vo->driver->preinit(vo))
|
2013-07-21 19:17:48 +00:00
|
|
|
goto error;
|
|
|
|
return vo;
|
|
|
|
error:
|
|
|
|
talloc_free(vo);
|
|
|
|
return NULL;
|
2008-04-03 03:25:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int vo_control(struct vo *vo, uint32_t request, void *data)
|
|
|
|
{
|
|
|
|
return vo->driver->control(vo, request, data);
|
|
|
|
}
|
|
|
|
|
2013-03-28 20:39:10 +00:00
|
|
|
void vo_queue_image(struct vo *vo, struct mp_image *mpi)
|
2009-09-18 13:27:55 +00:00
|
|
|
{
|
|
|
|
if (!vo->config_ok)
|
2013-03-28 20:39:10 +00:00
|
|
|
return;
|
2009-09-18 13:27:55 +00:00
|
|
|
if (vo->driver->buffer_frames) {
|
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 13:25:04 +00:00
|
|
|
vo->driver->draw_image(vo, mpi);
|
2013-03-28 20:39:10 +00:00
|
|
|
return;
|
2009-09-18 13:27:55 +00:00
|
|
|
}
|
|
|
|
vo->frame_loaded = true;
|
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 13:25:04 +00:00
|
|
|
vo->next_pts = mpi->pts;
|
2013-12-10 18:32:52 +00:00
|
|
|
vo->next_pts2 = MP_NOPTS_VALUE;
|
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 13:25:04 +00:00
|
|
|
assert(!vo->waiting_mpi);
|
|
|
|
vo->waiting_mpi = mp_image_new_ref(mpi);
|
2009-09-18 13:27:55 +00:00
|
|
|
}
|
|
|
|
|
2011-12-05 03:24:18 +00:00
|
|
|
int vo_redraw_frame(struct vo *vo)
|
|
|
|
{
|
video/out: always support redrawing VO window at any point
Before, a VO could easily refuse to respond to VOCTRL_REDRAW_FRAME,
which means the VO wouldn't redraw OSD and window contents, and the
player would appear frozen to the user. This was a bit stupid, and makes
dealing with some corner cases much harder (think of --keep-open, which
was hard to implement, because the VO gets into this state if there are
no new video frames after a seek reset).
Change this, and require VOs to always react to VOCTRL_REDRAW_FRAME.
There are two aspects of this: First, behavior after a (successful)
vo_reconfig() call, but before any video frame has been displayed.
Second, behavior after a vo_seek_reset().
For the first issue, we define that sending VOCTRL_REDRAW_FRAME after
vo_reconfig() should clear the window with black. This requires minor
changes to some VOs. In particular vaapi makes this horribly
complicated, because OSD rendering is bound to a video surface. We
create a black dummy surface for this purpose.
The second issue is much simpler and works already with most VOs: they
simply redraw whatever has been uploaded previously. The exception is
vdpau, which has a complicated mechanism to track and filter video
frames. The state associated with this mechanism is completely cleared
with vo_seek_reset(), so implementing this to work as expected is not
trivial. For now, we just clear the window with black.
2013-10-01 21:35:51 +00:00
|
|
|
if (!vo->config_ok)
|
2011-12-05 03:24:18 +00:00
|
|
|
return -1;
|
|
|
|
if (vo_control(vo, VOCTRL_REDRAW_FRAME, NULL) == true) {
|
2013-03-01 10:16:01 +00:00
|
|
|
vo->want_redraw = false;
|
2011-12-05 03:24:18 +00:00
|
|
|
vo->redrawing = true;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-03-01 10:16:01 +00:00
|
|
|
bool vo_get_want_redraw(struct vo *vo)
|
|
|
|
{
|
video/out: always support redrawing VO window at any point
Before, a VO could easily refuse to respond to VOCTRL_REDRAW_FRAME,
which means the VO wouldn't redraw OSD and window contents, and the
player would appear frozen to the user. This was a bit stupid, and makes
dealing with some corner cases much harder (think of --keep-open, which
was hard to implement, because the VO gets into this state if there are
no new video frames after a seek reset).
Change this, and require VOs to always react to VOCTRL_REDRAW_FRAME.
There are two aspects of this: First, behavior after a (successful)
vo_reconfig() call, but before any video frame has been displayed.
Second, behavior after a vo_seek_reset().
For the first issue, we define that sending VOCTRL_REDRAW_FRAME after
vo_reconfig() should clear the window with black. This requires minor
changes to some VOs. In particular vaapi makes this horribly
complicated, because OSD rendering is bound to a video surface. We
create a black dummy surface for this purpose.
The second issue is much simpler and works already with most VOs: they
simply redraw whatever has been uploaded previously. The exception is
vdpau, which has a complicated mechanism to track and filter video
frames. The state associated with this mechanism is completely cleared
with vo_seek_reset(), so implementing this to work as expected is not
trivial. For now, we just clear the window with black.
2013-10-01 21:35:51 +00:00
|
|
|
if (!vo->config_ok)
|
2013-03-01 10:16:01 +00:00
|
|
|
return false;
|
|
|
|
return vo->want_redraw;
|
|
|
|
}
|
|
|
|
|
2009-09-18 13:27:55 +00:00
|
|
|
int vo_get_buffered_frame(struct vo *vo, bool eof)
|
|
|
|
{
|
|
|
|
if (!vo->config_ok)
|
|
|
|
return -1;
|
|
|
|
if (vo->frame_loaded)
|
|
|
|
return 0;
|
|
|
|
if (!vo->driver->buffer_frames)
|
|
|
|
return -1;
|
|
|
|
vo->driver->get_buffered_frame(vo, eof);
|
|
|
|
return vo->frame_loaded ? 0 : -1;
|
|
|
|
}
|
|
|
|
|
2011-03-03 10:54:36 +00:00
|
|
|
void vo_skip_frame(struct vo *vo)
|
|
|
|
{
|
2011-12-04 16:10:17 +00:00
|
|
|
vo_control(vo, VOCTRL_SKIPFRAME, NULL);
|
2011-03-03 10:54:36 +00:00
|
|
|
vo->frame_loaded = false;
|
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 13:25:04 +00:00
|
|
|
mp_image_unrefp(&vo->waiting_mpi);
|
2011-03-03 10:54:36 +00:00
|
|
|
}
|
|
|
|
|
2011-12-04 16:10:17 +00:00
|
|
|
void vo_new_frame_imminent(struct vo *vo)
|
|
|
|
{
|
|
|
|
if (vo->driver->buffer_frames)
|
|
|
|
vo_control(vo, VOCTRL_NEWFRAME, NULL);
|
|
|
|
else {
|
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 13:25:04 +00:00
|
|
|
assert(vo->frame_loaded);
|
|
|
|
assert(vo->waiting_mpi);
|
|
|
|
assert(vo->waiting_mpi->pts == vo->next_pts);
|
|
|
|
vo->driver->draw_image(vo, vo->waiting_mpi);
|
|
|
|
mp_image_unrefp(&vo->waiting_mpi);
|
2011-12-04 16:10:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-23 22:53:58 +00:00
|
|
|
void vo_draw_osd(struct vo *vo, struct osd_state *osd)
|
2008-04-03 03:25:41 +00:00
|
|
|
{
|
2013-03-01 10:16:01 +00:00
|
|
|
if (vo->config_ok && vo->driver->draw_osd)
|
2012-10-21 13:54:22 +00:00
|
|
|
vo->driver->draw_osd(vo, osd);
|
2008-04-03 03:25:41 +00:00
|
|
|
}
|
|
|
|
|
2013-12-22 17:42:19 +00:00
|
|
|
void vo_flip_page(struct vo *vo, int64_t pts_us, int duration)
|
2008-04-03 03:25:41 +00:00
|
|
|
{
|
2008-04-18 03:28:47 +00:00
|
|
|
if (!vo->config_ok)
|
|
|
|
return;
|
2011-12-05 03:24:18 +00:00
|
|
|
if (!vo->redrawing) {
|
|
|
|
vo->frame_loaded = false;
|
|
|
|
vo->next_pts = MP_NOPTS_VALUE;
|
2013-12-10 18:32:52 +00:00
|
|
|
vo->next_pts2 = MP_NOPTS_VALUE;
|
2011-12-05 03:24:18 +00:00
|
|
|
}
|
2011-12-05 04:36:20 +00:00
|
|
|
vo->want_redraw = false;
|
2011-12-05 03:24:18 +00:00
|
|
|
vo->redrawing = false;
|
2009-11-15 02:39:22 +00:00
|
|
|
if (vo->driver->flip_page_timed)
|
|
|
|
vo->driver->flip_page_timed(vo, pts_us, duration);
|
|
|
|
else
|
|
|
|
vo->driver->flip_page(vo);
|
2012-02-28 01:17:25 +00:00
|
|
|
vo->hasframe = true;
|
2008-04-03 03:25:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void vo_check_events(struct vo *vo)
|
|
|
|
{
|
2010-12-14 19:58:47 +00:00
|
|
|
if (!vo->config_ok) {
|
|
|
|
if (vo->registered_fd != -1)
|
|
|
|
mp_input_rm_key_fd(vo->input_ctx, vo->registered_fd);
|
|
|
|
vo->registered_fd = -1;
|
2008-04-18 03:28:47 +00:00
|
|
|
return;
|
2010-12-14 19:58:47 +00:00
|
|
|
}
|
2013-05-15 16:17:18 +00:00
|
|
|
vo_control(vo, VOCTRL_CHECK_EVENTS, NULL);
|
2008-04-03 03:25:41 +00:00
|
|
|
}
|
|
|
|
|
2009-09-18 13:27:55 +00:00
|
|
|
void vo_seek_reset(struct vo *vo)
|
|
|
|
{
|
|
|
|
vo_control(vo, VOCTRL_RESET, NULL);
|
|
|
|
vo->frame_loaded = false;
|
2013-12-10 18:32:52 +00:00
|
|
|
vo->next_pts = MP_NOPTS_VALUE;
|
|
|
|
vo->next_pts2 = MP_NOPTS_VALUE;
|
2013-10-02 18:41:11 +00:00
|
|
|
vo->hasframe = false;
|
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 13:25:04 +00:00
|
|
|
mp_image_unrefp(&vo->waiting_mpi);
|
2009-09-18 13:27:55 +00:00
|
|
|
}
|
|
|
|
|
2008-04-03 03:25:41 +00:00
|
|
|
void vo_destroy(struct vo *vo)
|
|
|
|
{
|
2010-12-14 19:58:47 +00:00
|
|
|
if (vo->registered_fd != -1)
|
|
|
|
mp_input_rm_key_fd(vo->input_ctx, vo->registered_fd);
|
2013-08-11 18:09:06 +00:00
|
|
|
mp_image_unrefp(&vo->waiting_mpi);
|
2008-04-03 03:25:41 +00:00
|
|
|
vo->driver->uninit(vo);
|
2008-04-20 03:04:10 +00:00
|
|
|
talloc_free(vo);
|
2008-04-03 03:25:41 +00:00
|
|
|
}
|
|
|
|
|
2013-07-31 19:44:21 +00:00
|
|
|
struct vo *init_best_video_out(struct mpv_global *global,
|
2012-09-14 15:51:26 +00:00
|
|
|
struct input_ctx *input_ctx,
|
|
|
|
struct encode_lavc_context *encode_lavc_ctx)
|
2008-04-03 01:58:32 +00:00
|
|
|
{
|
2013-07-31 19:44:21 +00:00
|
|
|
struct m_obj_settings *vo_list = global->opts->vo.video_driver_list;
|
2002-09-29 21:53:05 +00:00
|
|
|
// first try the preferred drivers, with their optional subdevice param:
|
2013-07-21 19:17:48 +00: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 19:44:21 +00:00
|
|
|
struct vo *vo = vo_create(global, input_ctx, encode_lavc_ctx,
|
2013-07-21 19:17:48 +00:00
|
|
|
vo_list[n].name, vo_list[n].attribs);
|
|
|
|
if (vo)
|
|
|
|
return vo;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
autoprobe:
|
2002-09-29 21:53:05 +00:00
|
|
|
// now try the rest...
|
2013-07-21 19:17:48 +00:00
|
|
|
for (int i = 0; video_out_drivers[i]; i++) {
|
2013-07-31 19:44:21 +00:00
|
|
|
struct vo *vo = vo_create(global, input_ctx, encode_lavc_ctx,
|
2013-10-23 17:06:14 +00:00
|
|
|
(char *)video_out_drivers[i]->name, NULL);
|
2013-07-21 19:17:48 +00:00
|
|
|
if (vo)
|
|
|
|
return vo;
|
2002-09-29 21:53:05 +00:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-01-11 17:44:27 +00:00
|
|
|
static void calc_monitor_aspect(struct mp_vo_opts *opts, int scr_w, int scr_h,
|
|
|
|
float *pixelaspect, int *w, int *h)
|
|
|
|
{
|
|
|
|
*pixelaspect = 1.0 / opts->monitor_pixel_aspect;
|
|
|
|
|
|
|
|
if (scr_w > 0 && scr_h > 0 && opts->force_monitor_aspect)
|
|
|
|
*pixelaspect = opts->force_monitor_aspect * scr_h / scr_w;
|
|
|
|
|
|
|
|
if (*pixelaspect < 1) {
|
|
|
|
*h /= *pixelaspect;
|
|
|
|
} else {
|
|
|
|
*w *= *pixelaspect;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-23 09:56:36 +00:00
|
|
|
// Fit *w/*h into the size specified by geo.
|
|
|
|
static void apply_autofit(int *w, int *h, int scr_w, int scr_h,
|
|
|
|
struct m_geometry *geo, bool allow_upscale)
|
|
|
|
{
|
|
|
|
if (!geo->wh_valid)
|
|
|
|
return;
|
|
|
|
|
|
|
|
int dummy;
|
|
|
|
int n_w = *w, n_h = *h;
|
|
|
|
m_geometry_apply(&dummy, &dummy, &n_w, &n_h, scr_w, scr_h, geo);
|
|
|
|
|
|
|
|
if (!allow_upscale && *w <= n_w && *h <= n_h)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// If aspect mismatches, always make the window smaller than the fit box
|
|
|
|
double asp = (double)*w / *h;
|
|
|
|
double n_asp = (double)n_w / n_h;
|
|
|
|
if (n_asp <= asp) {
|
|
|
|
*w = n_w;
|
|
|
|
*h = n_w / asp;
|
|
|
|
} else {
|
|
|
|
*w = n_h * asp;
|
|
|
|
*h = n_h;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-22 12:28:31 +00:00
|
|
|
// Set window size (vo->dwidth/dheight) and position (vo->dx/dy) according to
|
|
|
|
// the video display size d_w/d_h.
|
|
|
|
// NOTE: currently, all GUI backends do their own handling of window geometry
|
|
|
|
// additional to this code. This is to deal with initial window placement,
|
|
|
|
// fullscreen handling, avoiding resize on config() with no size change,
|
|
|
|
// multi-monitor stuff, and possibly more.
|
|
|
|
static void determine_window_geometry(struct vo *vo, int d_w, int d_h)
|
|
|
|
{
|
2013-03-04 21:41:27 +00:00
|
|
|
struct mp_vo_opts *opts = vo->opts;
|
2013-01-22 12:28:31 +00:00
|
|
|
|
2013-03-04 21:41:27 +00:00
|
|
|
int scr_w = opts->screenwidth;
|
|
|
|
int scr_h = opts->screenheight;
|
2013-01-23 09:56:36 +00:00
|
|
|
|
2014-01-11 17:44:27 +00:00
|
|
|
MP_DBG(vo, "screen size: %dx%d\n", scr_w, scr_h);
|
|
|
|
|
|
|
|
calc_monitor_aspect(opts, scr_w, scr_h, &vo->monitor_par, &d_w, &d_h);
|
2013-01-22 12:28:31 +00:00
|
|
|
|
2013-03-04 21:41:27 +00:00
|
|
|
apply_autofit(&d_w, &d_h, scr_w, scr_h, &opts->autofit, true);
|
|
|
|
apply_autofit(&d_w, &d_h, scr_w, scr_h, &opts->autofit_larger, false);
|
2013-01-23 09:56:36 +00:00
|
|
|
|
2013-03-04 21:41:27 +00:00
|
|
|
vo->dx = (int)(opts->screenwidth - d_w) / 2;
|
|
|
|
vo->dy = (int)(opts->screenheight - d_h) / 2;
|
2013-01-23 09:56:36 +00:00
|
|
|
m_geometry_apply(&vo->dx, &vo->dy, &d_w, &d_h, scr_w, scr_h,
|
2013-03-04 21:41:27 +00:00
|
|
|
&opts->geometry);
|
2013-01-22 12:28:31 +00:00
|
|
|
|
2013-03-04 16:40:21 +00:00
|
|
|
vo->dx += vo->xinerama_x;
|
|
|
|
vo->dy += vo->xinerama_y;
|
2013-01-22 12:28:31 +00:00
|
|
|
vo->dwidth = d_w;
|
|
|
|
vo->dheight = d_h;
|
|
|
|
}
|
|
|
|
|
2010-12-14 19:58:47 +00:00
|
|
|
static int event_fd_callback(void *ctx, int fd)
|
|
|
|
{
|
|
|
|
struct vo *vo = ctx;
|
|
|
|
vo_check_events(vo);
|
2011-07-17 01:47:50 +00:00
|
|
|
return MP_INPUT_NOTHING;
|
2010-12-14 19:58:47 +00:00
|
|
|
}
|
|
|
|
|
2013-06-07 23:35:44 +00:00
|
|
|
int vo_reconfig(struct vo *vo, struct mp_image_params *params, int flags)
|
2008-04-03 01:58:32 +00:00
|
|
|
{
|
2013-06-07 23:35:44 +00:00
|
|
|
int d_width = params->d_w;
|
|
|
|
int d_height = params->d_h;
|
2007-02-17 20:58:55 +00:00
|
|
|
|
2008-04-03 03:25:41 +00:00
|
|
|
if (vo_control(vo, VOCTRL_UPDATE_SCREENINFO, NULL) == VO_TRUE) {
|
2013-06-07 23:35:44 +00:00
|
|
|
determine_window_geometry(vo, params->d_w, params->d_h);
|
2013-01-22 12:28:31 +00:00
|
|
|
d_width = vo->dwidth;
|
|
|
|
d_height = vo->dheight;
|
2008-04-03 01:58:32 +00:00
|
|
|
}
|
2013-06-07 23:35:44 +00:00
|
|
|
vo->dwidth = d_width;
|
|
|
|
vo->dheight = d_height;
|
2007-02-17 20:58:55 +00:00
|
|
|
|
2014-01-21 23:26:01 +00:00
|
|
|
talloc_free(vo->params);
|
2014-01-24 20:22:25 +00:00
|
|
|
vo->params = talloc_memdup(vo, params, sizeof(*params));
|
2014-01-21 23:26:01 +00:00
|
|
|
|
2014-01-24 20:22:25 +00:00
|
|
|
int ret = vo->driver->reconfig(vo, vo->params, flags);
|
|
|
|
vo->config_ok = ret >= 0;
|
2008-04-18 03:28:47 +00:00
|
|
|
vo->config_count += vo->config_ok;
|
2014-01-21 23:26:01 +00:00
|
|
|
if (!vo->config_ok) {
|
|
|
|
talloc_free(vo->params);
|
|
|
|
vo->params = NULL;
|
|
|
|
}
|
2010-12-14 19:58:47 +00:00
|
|
|
if (vo->registered_fd == -1 && vo->event_fd != -1 && vo->config_ok) {
|
2013-12-21 18:33:45 +00:00
|
|
|
mp_input_add_fd(vo->input_ctx, vo->event_fd, 1, NULL, event_fd_callback,
|
|
|
|
NULL, vo);
|
2010-12-14 19:58:47 +00:00
|
|
|
vo->registered_fd = vo->event_fd;
|
|
|
|
}
|
2011-12-04 16:10:17 +00:00
|
|
|
vo->frame_loaded = false;
|
|
|
|
vo->waiting_mpi = NULL;
|
2011-12-05 03:24:18 +00:00
|
|
|
vo->redrawing = false;
|
2012-02-28 01:17:25 +00:00
|
|
|
vo->hasframe = false;
|
2008-04-18 03:28:47 +00:00
|
|
|
return ret;
|
2007-02-17 20:58:55 +00:00
|
|
|
}
|
2002-09-29 21:53:05 +00:00
|
|
|
|
2008-12-20 11:52:11 +00: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.
|
|
|
|
*/
|
2010-04-23 10:22:44 +00:00
|
|
|
int lookup_keymap_table(const struct mp_keymap *map, int key) {
|
2008-12-20 11:52:11 +00:00
|
|
|
while (map->from && map->from != key) map++;
|
|
|
|
return map->to;
|
|
|
|
}
|
|
|
|
|
2014-01-21 23:26:01 +00: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)
|
|
|
|
{
|
|
|
|
mp_get_src_dst_rects(vo->log, vo->opts, vo->params, vo->dwidth, vo->dheight,
|
|
|
|
vo->monitor_par, out_src, out_dst, out_osd);
|
|
|
|
}
|
|
|
|
|
2011-12-06 19:23:54 +00: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 14:18:51 +00:00
|
|
|
if (!vo->window_title)
|
|
|
|
vo->window_title = talloc_strdup(vo, "");
|
2012-08-02 00:36:26 +00:00
|
|
|
return vo->window_title;
|
2011-12-06 19:23:54 +00:00
|
|
|
}
|
|
|
|
|
2010-04-25 16:13:57 +00: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 16:22:56 +00: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 00:13:30 +00:00
|
|
|
if (!vo->opts->enable_mouse_movements)
|
|
|
|
return;
|
2013-09-27 13:39:28 +00: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 16:13:57 +00:00
|
|
|
}
|