1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
/*
* This file is part of mpv.
*
* 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.
*
* 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
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with mpv. If not, see <http://www.gnu.org/licenses/>.
*/
#include <assert.h>
#include "video/vdpau.h"
#include "video/vdpau_mixer.h"
#include "vf.h"
// This filter will read back decoded frames that have been decoded by vdpau
// so they can be post-processed by regular filters. As vdpau is still doing
// the decoding, a vdpau compatible vo must always be used.
//
// NB: This filter assumes the video surface will have a 420 chroma type and
// can always be read back in NV12 format. This is a safe assumption at the
// time of writing, but may not always remain true.
struct vf_priv_s {
struct mp_vdpau_ctx *ctx;
};
static int filter_ext(struct vf_instance *vf, struct mp_image *mpi)
{
VdpStatus vdp_st;
struct vf_priv_s *p = vf->priv;
struct mp_vdpau_ctx *ctx = p->ctx;
struct vdp_functions *vdp = &ctx->vdp;
if (!mpi) {
return 0;
}
// Pass-through anything that's not been decoded by VDPAU
if (mpi->imgfmt != IMGFMT_VDPAU) {
vf_add_output_frame(vf, mpi);
return 0;
}
if (mp_vdpau_mixed_frame_get(mpi)) {
MP_ERR(vf, "Can't apply vdpaurb filter after vdpaupp filter.\n");
mp_image_unrefp(&mpi);
return -1;
}
struct mp_image *out = vf_alloc_out_image(vf);
if (!out) {
mp_image_unrefp(&mpi);
return -1;
}
mp_image_copy_attributes(out, mpi);
VdpVideoSurface surface = (uintptr_t)mpi->planes[3];
assert(surface > 0);
vdp_st = vdp->video_surface_get_bits_y_cb_cr(surface,
VDP_YCBCR_FORMAT_NV12,
(void * const *)out->planes,
out->stride);
CHECK_VDP_WARNING(vf, "Error when calling vdp_output_surface_get_bits_y_cb_cr");
vf_add_output_frame(vf, out);
mp_image_unrefp(&mpi);
return 0;
}
static int reconfig(struct vf_instance *vf, struct mp_image_params *in,
struct mp_image_params *out)
{
*out = *in;
if (in->imgfmt == IMGFMT_VDPAU) {
out->imgfmt = IMGFMT_NV12;
}
return 0;
}
static int query_format(struct vf_instance *vf, unsigned int fmt)
{
return vf_next_query_format(vf, fmt == IMGFMT_VDPAU ? IMGFMT_NV12 : fmt);
}
static int vf_open(vf_instance_t *vf)
{
struct vf_priv_s *p = vf->priv;
vf->filter_ext = filter_ext;
vf->filter = NULL;
vf->reconfig = reconfig;
vf->query_format = query_format;
if (!vf->hwdec) {
return 0;
}
hwdec_request_api(vf->hwdec, "vdpau");
p->ctx = vf->hwdec->hwctx ? vf->hwdec->hwctx->vdpau_ctx : NULL;
if (!p->ctx) {
return 0;
}
return 1;
}
const vf_info_t vf_info_vdpaurb = {
.description = "vdpau readback",
.name = "vdpaurb",
.open = vf_open,
.priv_size = sizeof(struct vf_priv_s),
};
|