2014-04-29 13:07:21 +00:00
|
|
|
/*
|
|
|
|
* This file is part of mpv.
|
|
|
|
*
|
2016-05-27 15:01:36 +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-04-29 13:07:21 +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
|
2016-05-27 15:01:36 +00:00
|
|
|
* GNU Lesser General Public License for more details.
|
2014-04-29 13:07:21 +00:00
|
|
|
*
|
2016-05-27 15:01:36 +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-04-29 13:07:21 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <inttypes.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
#include "common/common.h"
|
|
|
|
#include "common/msg.h"
|
|
|
|
#include "options/m_option.h"
|
|
|
|
|
|
|
|
#include "video/img_format.h"
|
|
|
|
#include "video/mp_image.h"
|
|
|
|
#include "video/hwdec.h"
|
|
|
|
#include "video/vdpau.h"
|
|
|
|
#include "video/vdpau_mixer.h"
|
|
|
|
#include "vf.h"
|
2016-05-27 15:01:36 +00:00
|
|
|
#include "refqueue.h"
|
2014-04-29 13:07:21 +00:00
|
|
|
|
|
|
|
// Note: this filter does no actual filtering; it merely sets appropriate
|
|
|
|
// flags on vdpau images (mp_vdpau_mixer_frame) to do the appropriate
|
|
|
|
// processing on the final rendering process in the VO.
|
|
|
|
|
|
|
|
struct vf_priv_s {
|
|
|
|
struct mp_vdpau_ctx *ctx;
|
2016-05-27 15:01:36 +00:00
|
|
|
struct mp_refqueue *queue;
|
2014-04-29 13:07:21 +00:00
|
|
|
|
2014-04-29 13:16:06 +00:00
|
|
|
int def_deintmode;
|
|
|
|
int deint_enabled;
|
2015-07-08 13:14:38 +00:00
|
|
|
int interlaced_only;
|
2014-04-29 13:07:21 +00:00
|
|
|
struct mp_vdpau_mixer_opts opts;
|
|
|
|
};
|
|
|
|
|
2016-05-27 15:01:36 +00:00
|
|
|
static int filter_ext(struct vf_instance *vf, struct mp_image *mpi)
|
2014-04-29 13:07:21 +00:00
|
|
|
{
|
|
|
|
struct vf_priv_s *p = vf->priv;
|
|
|
|
|
2016-05-27 15:01:36 +00:00
|
|
|
if (p->opts.deint >= 2) {
|
|
|
|
mp_refqueue_set_refs(p->queue, 1, 1); // 2 past fields, 1 future field
|
|
|
|
} else {
|
|
|
|
mp_refqueue_set_refs(p->queue, 0, 0);
|
|
|
|
}
|
|
|
|
mp_refqueue_set_mode(p->queue,
|
|
|
|
(p->deint_enabled ? MP_MODE_DEINT : 0) |
|
|
|
|
(p->interlaced_only ? MP_MODE_INTERLACED_ONLY : 0) |
|
|
|
|
(p->opts.deint >= 2 ? MP_MODE_OUTPUT_FIELDS : 0));
|
|
|
|
|
|
|
|
if (mpi) {
|
|
|
|
struct mp_image *new = mp_vdpau_upload_video_surface(p->ctx, mpi);
|
|
|
|
talloc_free(mpi);
|
|
|
|
if (!new)
|
|
|
|
return -1;
|
|
|
|
mpi = new;
|
|
|
|
|
|
|
|
if (mp_vdpau_mixed_frame_get(mpi)) {
|
|
|
|
MP_ERR(vf, "Can't apply vdpaupp filter multiple times.\n");
|
|
|
|
vf_add_output_frame(vf, mpi);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mp_refqueue_add_input(p->queue, mpi);
|
|
|
|
return 0;
|
|
|
|
}
|
2014-04-29 13:07:21 +00:00
|
|
|
|
2014-05-25 14:01:33 +00:00
|
|
|
static VdpVideoSurface ref_field(struct vf_priv_s *p,
|
2014-04-29 13:07:21 +00:00
|
|
|
struct mp_vdpau_mixer_frame *frame, int pos)
|
|
|
|
{
|
2016-05-27 15:01:36 +00:00
|
|
|
struct mp_image *mpi = mp_image_new_ref(mp_refqueue_get_field(p->queue, pos));
|
video: introduce failure path for image allocations
Until now, failure to allocate image data resulted in a crash (i.e.
abort() was called). This was intentional, because it's pretty silly to
degrade playback, and in almost all situations, the OOM will probably
kill you anyway. (And then there's the standard Linux overcommit
behavior, which also will kill you at some point.)
But I changed my opinion, so here we go. This change does not affect
_all_ memory allocations, just image data. Now in most failure cases,
the output will just be skipped. For video filters, this coincidentally
means that failure is treated as EOF (because the playback core assumes
EOF if nothing comes out of the video filter chain). In other
situations, output might be in some way degraded, like skipping frames,
not scaling OSD, and such.
Functions whose return values changed semantics:
mp_image_alloc
mp_image_new_copy
mp_image_new_ref
mp_image_make_writeable
mp_image_setrefp
mp_image_to_av_frame_and_unref
mp_image_from_av_frame
mp_image_new_external_ref
mp_image_new_custom_ref
mp_image_pool_make_writeable
mp_image_pool_get
mp_image_pool_new_copy
mp_vdpau_mixed_frame_create
vf_alloc_out_image
vf_make_out_image_writeable
glGetWindowScreenshot
2014-06-17 20:43:43 +00:00
|
|
|
if (!mpi)
|
|
|
|
return VDP_INVALID_HANDLE;
|
2014-04-29 13:07:21 +00:00
|
|
|
talloc_steal(frame, mpi);
|
|
|
|
return (uintptr_t)mpi->planes[3];
|
|
|
|
}
|
|
|
|
|
2016-05-27 15:01:36 +00:00
|
|
|
static int filter_out(struct vf_instance *vf)
|
2014-04-29 13:07:21 +00:00
|
|
|
{
|
|
|
|
struct vf_priv_s *p = vf->priv;
|
|
|
|
|
2016-05-27 15:01:36 +00:00
|
|
|
if (!mp_refqueue_has_output(p->queue))
|
|
|
|
return 0;
|
2014-04-29 13:07:21 +00:00
|
|
|
|
2016-05-27 15:01:36 +00:00
|
|
|
struct mp_image *mpi =
|
|
|
|
mp_vdpau_mixed_frame_create(mp_refqueue_get_field(p->queue, 0));
|
video: introduce failure path for image allocations
Until now, failure to allocate image data resulted in a crash (i.e.
abort() was called). This was intentional, because it's pretty silly to
degrade playback, and in almost all situations, the OOM will probably
kill you anyway. (And then there's the standard Linux overcommit
behavior, which also will kill you at some point.)
But I changed my opinion, so here we go. This change does not affect
_all_ memory allocations, just image data. Now in most failure cases,
the output will just be skipped. For video filters, this coincidentally
means that failure is treated as EOF (because the playback core assumes
EOF if nothing comes out of the video filter chain). In other
situations, output might be in some way degraded, like skipping frames,
not scaling OSD, and such.
Functions whose return values changed semantics:
mp_image_alloc
mp_image_new_copy
mp_image_new_ref
mp_image_make_writeable
mp_image_setrefp
mp_image_to_av_frame_and_unref
mp_image_from_av_frame
mp_image_new_external_ref
mp_image_new_custom_ref
mp_image_pool_make_writeable
mp_image_pool_get
mp_image_pool_new_copy
mp_vdpau_mixed_frame_create
vf_alloc_out_image
vf_make_out_image_writeable
glGetWindowScreenshot
2014-06-17 20:43:43 +00:00
|
|
|
if (!mpi)
|
2016-05-27 15:01:36 +00:00
|
|
|
return -1; // OOM
|
2014-04-29 13:07:21 +00:00
|
|
|
struct mp_vdpau_mixer_frame *frame = mp_vdpau_mixed_frame_get(mpi);
|
|
|
|
|
2016-05-27 15:01:36 +00:00
|
|
|
if (!mp_refqueue_should_deint(p->queue)) {
|
|
|
|
frame->field = VDP_VIDEO_MIXER_PICTURE_STRUCTURE_FRAME;
|
|
|
|
} else if (mp_refqueue_is_top_field(p->queue)) {
|
|
|
|
frame->field = VDP_VIDEO_MIXER_PICTURE_STRUCTURE_TOP_FIELD;
|
|
|
|
} else {
|
|
|
|
frame->field = VDP_VIDEO_MIXER_PICTURE_STRUCTURE_BOTTOM_FIELD;
|
2014-04-29 13:07:21 +00:00
|
|
|
}
|
|
|
|
|
2016-05-27 15:01:36 +00:00
|
|
|
frame->future[0] = ref_field(p, frame, 1);
|
|
|
|
frame->current = ref_field(p, frame, 0);
|
|
|
|
frame->past[0] = ref_field(p, frame, -1);
|
|
|
|
frame->past[1] = ref_field(p, frame, -2);
|
2014-04-29 13:07:21 +00:00
|
|
|
|
|
|
|
frame->opts = p->opts;
|
|
|
|
|
|
|
|
mpi->planes[3] = (void *)(uintptr_t)frame->current;
|
|
|
|
|
2016-05-27 15:01:36 +00:00
|
|
|
mp_refqueue_next_field(p->queue);
|
2014-04-29 13:07:21 +00:00
|
|
|
|
|
|
|
vf_add_output_frame(vf, mpi);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int reconfig(struct vf_instance *vf, struct mp_image_params *in,
|
|
|
|
struct mp_image_params *out)
|
|
|
|
{
|
2016-05-27 15:01:36 +00:00
|
|
|
struct vf_priv_s *p = vf->priv;
|
|
|
|
mp_refqueue_flush(p->queue);
|
2014-04-29 13:07:21 +00:00
|
|
|
*out = *in;
|
|
|
|
out->imgfmt = IMGFMT_VDPAU;
|
2016-06-19 17:58:40 +00:00
|
|
|
out->hw_subfmt = 0;
|
2014-04-29 13:07:21 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int query_format(struct vf_instance *vf, unsigned int fmt)
|
|
|
|
{
|
2014-04-29 13:10:57 +00:00
|
|
|
if (fmt == IMGFMT_VDPAU || mp_vdpau_get_format(fmt, NULL, NULL))
|
2014-04-29 13:07:21 +00:00
|
|
|
return vf_next_query_format(vf, IMGFMT_VDPAU);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int control(vf_instance_t *vf, int request, void *data)
|
|
|
|
{
|
2014-04-29 13:16:06 +00:00
|
|
|
struct vf_priv_s *p = vf->priv;
|
|
|
|
|
2014-04-29 13:07:21 +00:00
|
|
|
switch (request) {
|
|
|
|
case VFCTRL_SEEK_RESET:
|
2016-05-27 15:01:36 +00:00
|
|
|
mp_refqueue_flush(p->queue);
|
2014-04-29 13:07:21 +00:00
|
|
|
return CONTROL_OK;
|
2014-04-29 13:16:06 +00:00
|
|
|
case VFCTRL_GET_DEINTERLACE:
|
|
|
|
*(int *)data = !!p->deint_enabled;
|
|
|
|
return true;
|
|
|
|
case VFCTRL_SET_DEINTERLACE:
|
|
|
|
p->deint_enabled = !!*(int *)data;
|
|
|
|
p->opts.deint = p->deint_enabled ? p->def_deintmode : 0;
|
|
|
|
return true;
|
2014-04-29 13:07:21 +00:00
|
|
|
}
|
|
|
|
return CONTROL_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void uninit(struct vf_instance *vf)
|
|
|
|
{
|
2016-05-27 15:01:36 +00:00
|
|
|
struct vf_priv_s *p = vf->priv;
|
|
|
|
|
|
|
|
mp_refqueue_free(p->queue);
|
2014-04-29 13:07:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int vf_open(vf_instance_t *vf)
|
|
|
|
{
|
|
|
|
struct vf_priv_s *p = vf->priv;
|
|
|
|
|
|
|
|
vf->reconfig = reconfig;
|
|
|
|
vf->filter_ext = filter_ext;
|
2016-05-27 15:01:36 +00:00
|
|
|
vf->filter_out = filter_out;
|
2014-04-29 13:07:21 +00:00
|
|
|
vf->query_format = query_format;
|
|
|
|
vf->control = control;
|
|
|
|
vf->uninit = uninit;
|
|
|
|
|
2016-05-27 15:01:36 +00:00
|
|
|
p->queue = mp_refqueue_alloc();
|
|
|
|
|
2016-05-09 17:42:03 +00:00
|
|
|
p->ctx = hwdec_devices_load(vf->hwdec_devs, HWDEC_VDPAU);
|
2014-04-29 13:07:21 +00:00
|
|
|
if (!p->ctx)
|
|
|
|
return 0;
|
|
|
|
|
2014-04-29 13:16:06 +00:00
|
|
|
p->def_deintmode = p->opts.deint;
|
|
|
|
if (!p->deint_enabled)
|
|
|
|
p->opts.deint = 0;
|
|
|
|
|
2014-04-29 13:07:21 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define OPT_BASE_STRUCT struct vf_priv_s
|
|
|
|
static const m_option_t vf_opts_fields[] = {
|
2014-04-29 13:16:06 +00:00
|
|
|
OPT_CHOICE("deint-mode", opts.deint, 0,
|
|
|
|
({"first-field", 1},
|
2014-04-29 13:07:21 +00:00
|
|
|
{"bob", 2},
|
|
|
|
{"temporal", 3},
|
|
|
|
{"temporal-spatial", 4}),
|
|
|
|
OPTDEF_INT(3)),
|
2014-04-29 13:16:06 +00:00
|
|
|
OPT_FLAG("deint", deint_enabled, 0),
|
2014-04-29 13:07:21 +00:00
|
|
|
OPT_FLAG("chroma-deint", opts.chroma_deint, 0, OPTDEF_INT(1)),
|
|
|
|
OPT_FLAG("pullup", opts.pullup, 0),
|
|
|
|
OPT_FLOATRANGE("denoise", opts.denoise, 0, 0, 1),
|
|
|
|
OPT_FLOATRANGE("sharpen", opts.sharpen, 0, -1, 1),
|
|
|
|
OPT_INTRANGE("hqscaling", opts.hqscaling, 0, 0, 9),
|
2015-07-08 13:14:38 +00:00
|
|
|
OPT_FLAG("interlaced-only", interlaced_only, 0, OPTDEF_INT(1)),
|
2014-04-29 13:07:21 +00:00
|
|
|
{0}
|
|
|
|
};
|
|
|
|
|
|
|
|
const vf_info_t vf_info_vdpaupp = {
|
|
|
|
.description = "vdpau postprocessing",
|
|
|
|
.name = "vdpaupp",
|
|
|
|
.open = vf_open,
|
|
|
|
.priv_size = sizeof(struct vf_priv_s),
|
|
|
|
.options = vf_opts_fields,
|
|
|
|
};
|