2015-05-28 19:56:13 +00:00
|
|
|
/*
|
|
|
|
* This file is part of mpv.
|
|
|
|
*
|
Relicense some non-MPlayer source files to LGPL 2.1 or later
This covers source files which were added in mplayer2 and mpv times
only, and where all code is covered by LGPL relicensing agreements.
There are probably more files to which this applies, but I'm being
conservative here.
A file named ao_sdl.c exists in MPlayer too, but the mpv one is a
complete rewrite, and was added some time after the original ao_sdl.c
was removed. The same applies to vo_sdl.c, for which the SDL2 API is
radically different in addition (MPlayer supports SDL 1.2 only).
common.c contains only code written by me. But common.h is a strange
case: although it originally was named mp_common.h and exists in MPlayer
too, by now it contains only definitions written by uau and me. The
exceptions are the CONTROL_ defines - thus not changing the license of
common.h yet.
codec_tags.c contained once large tables generated from MPlayer's
codecs.conf, but all of these tables were removed.
From demux_playlist.c I'm removing a code fragment from someone who was
not asked; this probably could be done later (see commit 15dccc37).
misc.c is a bit complicated to reason about (it was split off mplayer.c
and thus contains random functions out of this file), but actually all
functions have been added post-MPlayer. Except get_relative_time(),
which was written by uau, but looks similar to 3 different versions of
something similar in each of the Unix/win32/OSX timer source files. I'm
not sure what that means in regards to copyright, so I've just moved it
into another still-GPL source file for now.
screenshot.c once had some minor parts of MPlayer's vf_screenshot.c, but
they're all gone.
2016-01-19 17:36:06 +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.
|
2015-05-28 19:56:13 +00:00
|
|
|
*
|
|
|
|
* mpv 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
|
Relicense some non-MPlayer source files to LGPL 2.1 or later
This covers source files which were added in mplayer2 and mpv times
only, and where all code is covered by LGPL relicensing agreements.
There are probably more files to which this applies, but I'm being
conservative here.
A file named ao_sdl.c exists in MPlayer too, but the mpv one is a
complete rewrite, and was added some time after the original ao_sdl.c
was removed. The same applies to vo_sdl.c, for which the SDL2 API is
radically different in addition (MPlayer supports SDL 1.2 only).
common.c contains only code written by me. But common.h is a strange
case: although it originally was named mp_common.h and exists in MPlayer
too, by now it contains only definitions written by uau and me. The
exceptions are the CONTROL_ defines - thus not changing the license of
common.h yet.
codec_tags.c contained once large tables generated from MPlayer's
codecs.conf, but all of these tables were removed.
From demux_playlist.c I'm removing a code fragment from someone who was
not asked; this probably could be done later (see commit 15dccc37).
misc.c is a bit complicated to reason about (it was split off mplayer.c
and thus contains random functions out of this file), but actually all
functions have been added post-MPlayer. Except get_relative_time(),
which was written by uau, but looks similar to 3 different versions of
something similar in each of the Unix/win32/OSX timer source files. I'm
not sure what that means in regards to copyright, so I've just moved it
into another still-GPL source file for now.
screenshot.c once had some minor parts of MPlayer's vf_screenshot.c, but
they're all gone.
2016-01-19 17:36:06 +00:00
|
|
|
* GNU Lesser General Public License for more details.
|
2015-05-28 19:56:13 +00:00
|
|
|
*
|
Relicense some non-MPlayer source files to LGPL 2.1 or later
This covers source files which were added in mplayer2 and mpv times
only, and where all code is covered by LGPL relicensing agreements.
There are probably more files to which this applies, but I'm being
conservative here.
A file named ao_sdl.c exists in MPlayer too, but the mpv one is a
complete rewrite, and was added some time after the original ao_sdl.c
was removed. The same applies to vo_sdl.c, for which the SDL2 API is
radically different in addition (MPlayer supports SDL 1.2 only).
common.c contains only code written by me. But common.h is a strange
case: although it originally was named mp_common.h and exists in MPlayer
too, by now it contains only definitions written by uau and me. The
exceptions are the CONTROL_ defines - thus not changing the license of
common.h yet.
codec_tags.c contained once large tables generated from MPlayer's
codecs.conf, but all of these tables were removed.
From demux_playlist.c I'm removing a code fragment from someone who was
not asked; this probably could be done later (see commit 15dccc37).
misc.c is a bit complicated to reason about (it was split off mplayer.c
and thus contains random functions out of this file), but actually all
functions have been added post-MPlayer. Except get_relative_time(),
which was written by uau, but looks similar to 3 different versions of
something similar in each of the Unix/win32/OSX timer source files. I'm
not sure what that means in regards to copyright, so I've just moved it
into another still-GPL source file for now.
screenshot.c once had some minor parts of MPlayer's vf_screenshot.c, but
they're all gone.
2016-01-19 17:36:06 +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/>.
|
2015-05-28 19:56:13 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <libavcodec/avcodec.h>
|
|
|
|
#include <libavcodec/vdpau.h>
|
|
|
|
#include <libavutil/common.h>
|
|
|
|
|
|
|
|
#include "lavc.h"
|
|
|
|
#include "common/common.h"
|
|
|
|
#include "video/vdpau.h"
|
|
|
|
#include "video/hwdec.h"
|
|
|
|
|
|
|
|
struct priv {
|
|
|
|
struct mp_log *log;
|
|
|
|
struct mp_vdpau_ctx *mpvdp;
|
|
|
|
uint64_t preemption_counter;
|
|
|
|
};
|
|
|
|
|
2015-08-19 19:33:18 +00:00
|
|
|
static int init_decoder(struct lavc_ctx *ctx, int w, int h)
|
2015-05-28 19:56:13 +00:00
|
|
|
{
|
|
|
|
struct priv *p = ctx->hwdec_priv;
|
|
|
|
|
|
|
|
// During preemption, pretend everything is ok.
|
|
|
|
if (mp_vdpau_handle_preemption(p->mpvdp, &p->preemption_counter) < 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return av_vdpau_bind_context(ctx->avctx, p->mpvdp->vdp_device,
|
|
|
|
p->mpvdp->get_proc_address,
|
|
|
|
AV_HWACCEL_FLAG_IGNORE_LEVEL |
|
|
|
|
AV_HWACCEL_FLAG_ALLOW_HIGH_DEPTH);
|
|
|
|
}
|
|
|
|
|
2015-08-19 19:33:18 +00:00
|
|
|
static struct mp_image *allocate_image(struct lavc_ctx *ctx, int w, int h)
|
2015-05-28 19:56:13 +00:00
|
|
|
{
|
|
|
|
struct priv *p = ctx->hwdec_priv;
|
|
|
|
|
|
|
|
// In case of preemption, reinit the decoder. Setting hwdec_request_reinit
|
|
|
|
// will cause init_decoder() to be called again.
|
|
|
|
if (mp_vdpau_handle_preemption(p->mpvdp, &p->preemption_counter) == 0)
|
|
|
|
ctx->hwdec_request_reinit = true;
|
|
|
|
|
|
|
|
VdpChromaType chroma = 0;
|
|
|
|
uint32_t s_w = w, s_h = h;
|
|
|
|
if (av_vdpau_get_surface_parameters(ctx->avctx, &chroma, &s_w, &s_h) < 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return mp_vdpau_get_video_surface(p->mpvdp, chroma, s_w, s_h);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void uninit(struct lavc_ctx *ctx)
|
|
|
|
{
|
|
|
|
struct priv *p = ctx->hwdec_priv;
|
|
|
|
|
|
|
|
talloc_free(p);
|
|
|
|
|
|
|
|
av_freep(&ctx->avctx->hwaccel_context);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int init(struct lavc_ctx *ctx)
|
|
|
|
{
|
|
|
|
struct priv *p = talloc_ptrtype(NULL, p);
|
|
|
|
*p = (struct priv) {
|
|
|
|
.log = mp_log_new(p, ctx->log, "vdpau"),
|
|
|
|
.mpvdp = ctx->hwdec_info->hwctx->vdpau_ctx,
|
|
|
|
};
|
|
|
|
ctx->hwdec_priv = p;
|
|
|
|
|
vdpau: force driver to report preemption early
Another fix for the crazy and insane nvidia preemption behavior.
This time, the situation is that we are using vo_opengl with vdpau
interop, and that vdpau got preempted in the background while mpv was
sitting idly. This can be e.g. reproduced by using:
--force-window=immediate --idle --hwdec=vdpau
and switching VTs. Then after switching back, load a video file.
This will not let mp_vdpau_handle_preemption() perform preemption
recovery, simply because it will do so only once vdp_decoder_create()
has been called. There are some other API calls which trigger
preemption, but many don't.
Due to the way the libavcodec API works, vdp_decoder_create() is way too
late. It does so when get_format returns. It notices creating the
decoder fails, and continues calling get_format without the vdpau
format. We could perhaps force it to reinit again (by adding a call to
vdpau.c, that checks for preemption, and sets hwdec_request_reinit), but
this seems too much of a mess.
Solve it by calling API in mp_vdpau_handle_preemption() that empirically
does trigger preemption: output_surface_put_bits_native(). This call is
useless, and in fact should be doing nothing (empty update VdpRect).
There's the slight chance that in theory it will slow down operation,
but in practice it's bound to be harmless. It's the likely cheapest and
simplest API call I've found that can trigger the fallback this way.
(The driver is closed source, so it was up to trial & error.)
Also, when initializing decoding, allow initial preemption recovery,
which is needed to pass the test mention above.
2016-01-25 15:42:54 +00:00
|
|
|
mp_vdpau_handle_preemption(p->mpvdp, &p->preemption_counter);
|
2015-05-28 19:56:13 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int probe(struct vd_lavc_hwdec *hwdec, struct mp_hwdec_info *info,
|
2016-04-07 15:48:00 +00:00
|
|
|
const char *codec)
|
2015-05-28 19:56:13 +00:00
|
|
|
{
|
|
|
|
hwdec_request_api(info, "vdpau");
|
|
|
|
if (!info || !info->hwctx || !info->hwctx->vdpau_ctx)
|
|
|
|
return HWDEC_ERR_NO_CTX;
|
|
|
|
if (mp_vdpau_guess_if_emulated(info->hwctx->vdpau_ctx))
|
|
|
|
return HWDEC_ERR_EMULATED;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
const struct vd_lavc_hwdec mp_vd_lavc_vdpau = {
|
|
|
|
.type = HWDEC_VDPAU,
|
|
|
|
.image_format = IMGFMT_VDPAU,
|
|
|
|
.probe = probe,
|
|
|
|
.init = init,
|
|
|
|
.uninit = uninit,
|
|
|
|
.init_decoder = init_decoder,
|
|
|
|
.allocate_image = allocate_image,
|
|
|
|
};
|