Coverage Report

Created: 2025-06-12 07:21

/src/mpv/video/out/vo_null.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * based on video_out_null.c from mpeg2dec
3
 *
4
 * Copyright (C) Aaron Holtzman - June 2000
5
 *
6
 * This file is part of mpv.
7
 *
8
 * mpv is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU Lesser General Public
10
 * License as published by the Free Software Foundation; either
11
 * version 2.1 of the License, or (at your option) any later version.
12
 *
13
 * mpv is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU Lesser General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Lesser General Public
19
 * License along with mpv.  If not, see <http://www.gnu.org/licenses/>.
20
 */
21
22
#include <stdlib.h>
23
#include "common/msg.h"
24
#include "vo.h"
25
#include "video/mp_image.h"
26
#include "osdep/timer.h"
27
#include "options/m_option.h"
28
29
struct priv {
30
    int64_t last_vsync;
31
32
    double cfg_fps;
33
};
34
35
static bool draw_frame(struct vo *vo, struct vo_frame *frame)
36
5.38M
{
37
5.38M
    return VO_TRUE;
38
5.38M
}
39
40
static void flip_page(struct vo *vo)
41
5.38M
{
42
5.38M
    struct priv *p = vo->priv;
43
5.38M
    if (p->cfg_fps) {
44
0
        int64_t ft = 1e9 / p->cfg_fps;
45
0
        int64_t prev_vsync = mp_time_ns() / ft;
46
0
        int64_t target_time = (prev_vsync + 1) * ft;
47
0
        for (;;) {
48
0
            int64_t now = mp_time_ns();
49
0
            if (now >= target_time)
50
0
                break;
51
0
            mp_sleep_ns(target_time - now);
52
0
        }
53
0
    }
54
5.38M
}
55
56
static int query_format(struct vo *vo, int format)
57
87.4M
{
58
87.4M
    return 1;
59
87.4M
}
60
61
static int reconfig(struct vo *vo, struct mp_image_params *params)
62
43.9k
{
63
43.9k
    return 0;
64
43.9k
}
65
66
static void uninit(struct vo *vo)
67
61.3k
{
68
61.3k
}
69
70
static int preinit(struct vo *vo)
71
61.3k
{
72
61.3k
    return 0;
73
61.3k
}
74
75
static int control(struct vo *vo, uint32_t request, void *data)
76
7.03M
{
77
7.03M
    struct priv *p = vo->priv;
78
7.03M
    switch (request) {
79
61.3k
    case VOCTRL_GET_DISPLAY_FPS:
80
61.3k
        if (!p->cfg_fps)
81
61.3k
            break;
82
0
        *(double *)data = p->cfg_fps;
83
0
        return VO_TRUE;
84
7.03M
    }
85
7.03M
    return VO_NOTIMPL;
86
7.03M
}
87
88
#define OPT_BASE_STRUCT struct priv
89
const struct vo_driver video_out_null = {
90
    .description = "Null video output",
91
    .name = "null",
92
    .preinit = preinit,
93
    .query_format = query_format,
94
    .reconfig = reconfig,
95
    .control = control,
96
    .draw_frame = draw_frame,
97
    .flip_page = flip_page,
98
    .uninit = uninit,
99
    .priv_size = sizeof(struct priv),
100
    .options = (const struct m_option[]) {
101
        {"fps", OPT_DOUBLE(cfg_fps), M_RANGE(0, 10000)},
102
        {0},
103
    },
104
    .options_prefix = "vo-null",
105
};