Coverage Report

Created: 2026-11-30 06:48

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/mpv/player/clipboard/clipboard-vo.c
Line
Count
Source
1
/*
2
 * This file is part of mpv.
3
 *
4
 * mpv is free software; you can redistribute it and/or
5
 * modify it under the terms of the GNU Lesser General Public
6
 * License as published by the Free Software Foundation; either
7
 * version 2.1 of the License, or (at your option) any later version.
8
 *
9
 * mpv is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU Lesser General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU Lesser General Public
15
 * License along with mpv.  If not, see <http://www.gnu.org/licenses/>.
16
 */
17
18
#include "common/common.h"
19
#include "clipboard.h"
20
#include "player/core.h"
21
#include "video/out/vo.h"
22
23
struct clipboard_vo_priv {
24
    struct MPContext *mpctx;
25
    struct mp_log *log;
26
};
27
28
static int init(struct clipboard_ctx *cl, struct clipboard_init_params *params)
29
301k
{
30
301k
    struct clipboard_vo_priv *priv = talloc_ptrtype(cl, priv);
31
301k
    priv->mpctx = params->mpctx;
32
301k
    priv->log = mp_log_new(priv, cl->log, "vo"),
33
301k
    cl->priv = priv;
34
301k
    return CLIPBOARD_SUCCESS;
35
301k
}
36
37
static int get_data(struct clipboard_ctx *cl, struct clipboard_access_params *params,
38
                    struct clipboard_data *out, void *talloc_ctx)
39
589
{
40
589
    struct clipboard_vo_priv *priv = cl->priv;
41
589
    struct vo *vo = priv->mpctx->video_out;
42
589
    struct voctrl_clipboard vc = {
43
589
        .data = *out,
44
589
        .params = *params,
45
589
        .talloc_ctx = talloc_ctx,
46
589
    };
47
48
589
    if (!vo)
49
0
        return CLIPBOARD_UNAVAILABLE;
50
589
    int ret = vo_control(vo, VOCTRL_GET_CLIPBOARD, &vc);
51
589
    switch (ret) {
52
0
    case VO_TRUE:
53
0
        *out = vc.data;
54
0
        return CLIPBOARD_SUCCESS;
55
0
    case VO_NOTAVAIL:
56
589
    case VO_NOTIMPL:
57
589
        MP_VERBOSE(priv, "VO does not support getting clipboard in the requested format.\n");
58
589
        return CLIPBOARD_UNAVAILABLE;
59
0
    default:
60
0
        MP_WARN(priv, "Failed getting VO clipboard.\n");
61
0
        return CLIPBOARD_FAILED;
62
589
    }
63
589
}
64
65
static int set_data(struct clipboard_ctx *cl, struct clipboard_access_params *params,
66
                    struct clipboard_data *data)
67
0
{
68
0
    struct clipboard_vo_priv *priv = cl->priv;
69
0
    struct vo *vo = priv->mpctx->video_out;
70
0
    struct voctrl_clipboard vc = {
71
0
        .data = *data,
72
0
        .params = *params,
73
0
    };
74
75
0
    if (!vo)
76
0
        return CLIPBOARD_UNAVAILABLE;
77
0
    int ret = vo_control(vo, VOCTRL_SET_CLIPBOARD, &vc);
78
0
    switch (ret) {
79
0
    case VO_TRUE:
80
0
        return CLIPBOARD_SUCCESS;
81
0
    case VO_NOTAVAIL:
82
0
    case VO_NOTIMPL:
83
0
        MP_VERBOSE(priv, "VO does not support setting clipboard in the requested format.\n");
84
0
        return CLIPBOARD_UNAVAILABLE;
85
0
    default:
86
0
        MP_WARN(priv, "Failed setting VO clipboard.\n");
87
0
        return CLIPBOARD_FAILED;
88
0
    }
89
0
}
90
91
const struct clipboard_backend clipboard_backend_vo = {
92
    .name = "vo",
93
    .desc = "VO clipboard",
94
    .init = init,
95
    .get_data = get_data,
96
    .set_data = set_data,
97
};