Coverage Report

Created: 2026-06-13 07:01

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/mpv/player/osd.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 <stddef.h>
19
#include <stdbool.h>
20
#include <inttypes.h>
21
#include <math.h>
22
#include <limits.h>
23
#include <assert.h>
24
25
#include "mpv_talloc.h"
26
27
#include "common/msg.h"
28
#include "common/msg_control.h"
29
#include "options/options.h"
30
#include "common/common.h"
31
#include "options/m_property.h"
32
#include "filters/f_decoder_wrapper.h"
33
#include "common/encode.h"
34
35
#include "osdep/terminal.h"
36
#include "osdep/timer.h"
37
38
#include "demux/demux.h"
39
#include "stream/stream.h"
40
#include "sub/osd.h"
41
42
#include "video/out/vo.h"
43
44
#include "core.h"
45
#include "command.h"
46
47
449
#define saddf(var, ...) (*(var) = talloc_asprintf_append((*var), __VA_ARGS__))
48
49
// append time in the hh:mm:ss format (plus fractions if wanted)
50
static void sadd_hhmmssff(char **buf, double time, bool fractions)
51
191
{
52
191
    char *s = mp_format_time(time, fractions);
53
191
    *buf = talloc_strdup_append(*buf, s);
54
191
    talloc_free(s);
55
191
}
56
57
92
static void sadd_percentage(char **buf, double ratio) {
58
92
    if (ratio >= 0)
59
89
        *buf = talloc_asprintf_append(*buf, " (%.f%%)", ratio * 100);
60
92
}
61
62
static char *join_lines(void *ta_ctx, char **parts, int num_parts)
63
5.85k
{
64
5.85k
    char *res = talloc_strdup(ta_ctx, "");
65
5.93k
    for (int n = 0; n < num_parts; n++)
66
86
        res = talloc_asprintf_append(res, "%s%s", n ? "\n" : "", parts[n]);
67
5.85k
    return res;
68
5.85k
}
69
70
static bool term_osd_empty(char *text)
71
23.4k
{
72
23.4k
    return !text || !text[0] || !strcmp(text, TERM_MSG_0);
73
23.4k
}
74
75
static void term_osd_update(struct MPContext *mpctx)
76
505k
{
77
505k
    int num_parts = 0;
78
505k
    char *parts[4] = {0};
79
80
505k
    if (!mpctx->opts->use_terminal)
81
499k
        return;
82
83
5.85k
    if (!term_osd_empty(mpctx->term_osd_subs[0]))
84
0
        parts[num_parts++] = mpctx->term_osd_subs[0];
85
5.85k
    if (!term_osd_empty(mpctx->term_osd_subs[1]))
86
0
        parts[num_parts++] = mpctx->term_osd_subs[1];
87
5.85k
    if (!term_osd_empty(mpctx->term_osd_text))
88
0
        parts[num_parts++] = mpctx->term_osd_text;
89
5.85k
    if (!term_osd_empty(mpctx->term_osd_status))
90
86
        parts[num_parts++] = mpctx->term_osd_status;
91
92
5.85k
    char *s = join_lines(mpctx, parts, num_parts);
93
94
5.85k
    if (strcmp(mpctx->term_osd_contents, s) == 0 &&
95
5.76k
        mp_msg_has_status_line(mpctx->global))
96
0
    {
97
0
        talloc_free(s);
98
5.85k
    } else {
99
5.85k
        talloc_free(mpctx->term_osd_contents);
100
5.85k
        mpctx->term_osd_contents = s;
101
5.85k
        mp_msg(mpctx->statusline, MSGL_STATUS, "%s", s);
102
5.85k
    }
103
5.85k
}
104
105
static void term_osd_update_title(struct MPContext *mpctx)
106
505k
{
107
505k
    if (!mpctx->opts->use_terminal)
108
499k
        return;
109
110
5.85k
    char *s = mp_property_expand_escaped_string(mpctx, mpctx->opts->term_title);
111
5.85k
    bstr title = bstr0(s);
112
5.85k
    mp_msg_sanitize(&title, false);
113
5.85k
    if (bstr_equals(title, bstr0(mpctx->term_osd_title))) {
114
5.82k
        talloc_free(s);
115
5.82k
        return;
116
5.82k
    }
117
118
22
    mp_msg_set_term_title(mpctx->statusline, s);
119
22
    mpctx->term_osd_title = talloc_steal(mpctx, s);
120
22
}
121
122
void term_osd_clear_subs(struct MPContext *mpctx)
123
467k
{
124
467k
    term_osd_set_subs(mpctx, NULL, 0);
125
467k
    term_osd_set_subs(mpctx, NULL, 1);
126
467k
}
127
128
void term_osd_set_subs(struct MPContext *mpctx, const char *text, int order)
129
936k
{
130
936k
    if (mpctx->video_out || !text || !mpctx->opts->subs_shared->sub_visibility[order])
131
936k
        text = ""; // disable
132
936k
    if (strcmp(mpctx->term_osd_subs[order] ? mpctx->term_osd_subs[order] : "", text) == 0)
133
936k
        return;
134
12
    talloc_replace(mpctx, mpctx->term_osd_subs[order], text);
135
12
    term_osd_update(mpctx);
136
12
}
137
138
static void term_osd_set_text_lazy(struct MPContext *mpctx, const char *text)
139
505k
{
140
505k
    bool video_osd = mpctx->video_out && mpctx->opts->video_osd;
141
505k
    if ((video_osd && mpctx->opts->term_osd != 1) || !text)
142
505k
        text = ""; // disable
143
505k
    talloc_replace(mpctx, mpctx->term_osd_text, text);
144
505k
}
145
146
static void term_osd_set_status_lazy(struct MPContext *mpctx, const char *text)
147
4.68k
{
148
4.68k
    talloc_replace(mpctx, mpctx->term_osd_status, text);
149
4.68k
}
150
151
static void add_term_osd_bar(struct MPContext *mpctx, char **line, int width)
152
0
{
153
0
    struct MPOpts *opts = mpctx->opts;
154
155
0
    if (width < 5)
156
0
        return;
157
158
0
    int pos = get_current_pos_ratio(mpctx, false) * (width - 3);
159
0
    pos = MPCLAMP(pos, 0, width - 3);
160
161
0
    bstr chars = bstr0(opts->term_osd_bar_chars);
162
0
    bstr parts[5];
163
0
    for (int n = 0; n < 5; n++)
164
0
        parts[n] = bstr_split_utf8(chars, &chars);
165
166
0
    saddf(line, "\r%.*s", BSTR_P(parts[0]));
167
0
    for (int n = 0; n < pos; n++)
168
0
        saddf(line, "%.*s", BSTR_P(parts[1]));
169
0
    saddf(line, "%.*s", BSTR_P(parts[2]));
170
0
    for (int n = 0; n < width - 3 - pos; n++)
171
0
        saddf(line, "%.*s", BSTR_P(parts[3]));
172
0
    saddf(line, "%.*s", BSTR_P(parts[4]));
173
0
}
174
175
static bool is_busy(struct MPContext *mpctx)
176
579
{
177
579
    return !mpctx->restart_complete && mp_time_sec() - mpctx->start_timestamp > 0.3;
178
579
}
179
180
static char *get_term_status_msg(struct MPContext *mpctx)
181
86
{
182
86
    struct MPOpts *opts = mpctx->opts;
183
184
86
    if (opts->status_msg)
185
0
        return mp_property_expand_escaped_string(mpctx, opts->status_msg);
186
187
86
    char *line = NULL;
188
189
    // Playback status
190
86
    if (is_busy(mpctx)) {
191
0
        saddf(&line, "(...) ");
192
86
    } else if (mpctx->paused_for_cache && !opts->pause) {
193
0
        saddf(&line, "(Buffering) ");
194
86
    } else if (mpctx->paused) {
195
0
        saddf(&line, "(Paused) ");
196
0
    }
197
198
86
    if (mpctx->ao_chain)
199
86
        saddf(&line, "A");
200
86
    if (mpctx->vo_chain)
201
86
        saddf(&line, "V");
202
86
    saddf(&line, ": ");
203
204
    // Playback position
205
86
    sadd_hhmmssff(&line, get_playback_time(mpctx), opts->osd_fractions);
206
86
    saddf(&line, " / ");
207
86
    sadd_hhmmssff(&line, get_time_length(mpctx), opts->osd_fractions);
208
209
86
    sadd_percentage(&line, get_current_pos_ratio(mpctx, false));
210
211
    // other
212
86
    if (opts->playback_speed != 1)
213
0
        saddf(&line, " x%4.2f", opts->playback_speed);
214
215
    // A-V sync
216
86
    if (mpctx->ao_chain && mpctx->vo_chain && !mpctx->vo_chain->is_sparse) {
217
86
        saddf(&line, " A-V:%7.3f", mpctx->last_av_difference);
218
86
        if (fabs(mpctx->total_avsync_change) > 0.05)
219
0
            saddf(&line, " ct:%7.3f", mpctx->total_avsync_change);
220
86
    }
221
222
86
    double position = get_current_pos_ratio(mpctx, true);
223
86
    char lavcbuf[80];
224
86
    if (encode_lavc_getstatus(mpctx->encode_lavc_ctx, lavcbuf, sizeof(lavcbuf),
225
86
            position) >= 0)
226
0
    {
227
        // encoding stats
228
0
        saddf(&line, " %s", lavcbuf);
229
86
    } else {
230
        // VO stats
231
86
        if (mpctx->vo_chain) {
232
86
            if (mpctx->display_sync_active) {
233
0
                char *r = mp_property_expand_string(mpctx,
234
0
                                            "${?vsync-ratio:${>vsync-ratio}}");
235
0
                if (r[0]) {
236
0
                    saddf(&line, " DS: %s/%"PRId64, r,
237
0
                          vo_get_delayed_count(mpctx->video_out));
238
0
                }
239
0
                talloc_free(r);
240
0
            }
241
86
            int64_t c = vo_get_drop_count(mpctx->video_out);
242
86
            struct mp_decoder_wrapper *dec = mpctx->vo_chain->track
243
86
                                        ? mpctx->vo_chain->track->dec : NULL;
244
86
            int dropped_frames =
245
86
                dec ? mp_decoder_wrapper_get_frames_dropped(dec) : 0;
246
86
            if (c > 0 || dropped_frames > 0) {
247
0
                saddf(&line, " Dropped: %"PRId64, c);
248
0
                if (dropped_frames)
249
0
                    saddf(&line, "/%d", dropped_frames);
250
0
            }
251
86
        }
252
86
    }
253
254
86
    if (mpctx->demuxer && demux_is_network_cached(mpctx->demuxer)) {
255
0
        saddf(&line, " Cache: ");
256
257
0
        struct demux_reader_state s;
258
0
        demux_get_reader_state(mpctx->demuxer, &s);
259
260
0
        if (s.ts_info.duration < 0) {
261
0
            saddf(&line, "???");
262
0
        } else if (s.ts_info.duration < 10) {
263
0
            saddf(&line, "%2.1fs", s.ts_info.duration);
264
0
        } else {
265
0
            saddf(&line, "%2ds", (int)s.ts_info.duration);
266
0
        }
267
0
        int64_t cache_size = s.fw_bytes;
268
0
        if (cache_size > 0) {
269
0
            if (cache_size >= 1024 * 1024) {
270
0
                saddf(&line, "/%lldMB", (long long)(cache_size / 1024 / 1024));
271
0
            } else {
272
0
                saddf(&line, "/%lldKB", (long long)(cache_size / 1024));
273
0
            }
274
0
        }
275
0
    }
276
277
86
    return line;
278
86
}
279
280
static void term_osd_print_status_lazy(struct MPContext *mpctx)
281
505k
{
282
505k
    struct MPOpts *opts = mpctx->opts;
283
284
505k
    term_osd_update_title(mpctx);
285
505k
    update_window_title(mpctx, false);
286
505k
    update_vo_playback_state(mpctx);
287
288
505k
    if (!opts->use_terminal)
289
499k
        return;
290
291
5.85k
    if (opts->quiet || !mpctx->playback_initialized || !mpctx->playing_msg_shown)
292
5.76k
    {
293
5.76k
        if (!mpctx->playing)
294
4.60k
            term_osd_set_status_lazy(mpctx, "");
295
5.76k
        return;
296
5.76k
    }
297
298
86
    char *line = get_term_status_msg(mpctx);
299
300
86
    if (opts->term_osd_bar) {
301
0
        saddf(&line, "\n");
302
0
        int w = 80, h = 24;
303
0
        terminal_get_size(&w, &h);
304
0
        add_term_osd_bar(mpctx, &line, w);
305
0
    }
306
307
86
    term_osd_set_status_lazy(mpctx, line);
308
86
    talloc_free(line);
309
86
}
310
311
MP_PRINTF_ATTRIBUTE(4, 0)
312
static bool set_osd_msg_va(struct MPContext *mpctx, int level, int time,
313
                           const char *fmt, va_list ap)
314
0
{
315
0
    if (level > mpctx->opts->osd_level)
316
0
        return false;
317
318
0
    talloc_free(mpctx->osd_msg_text);
319
0
    mpctx->osd_msg_text = talloc_vasprintf(mpctx, fmt, ap);
320
0
    mpctx->osd_show_pos = false;
321
0
    mpctx->osd_msg_next_duration = time / 1000.0;
322
0
    mpctx->osd_force_update = true;
323
0
    mp_wakeup_core(mpctx);
324
0
    if (mpctx->osd_msg_next_duration <= 0)
325
0
        mpctx->osd_msg_visible = mp_time_sec();
326
0
    return true;
327
0
}
328
329
bool set_osd_msg(struct MPContext *mpctx, int level, int time,
330
                 const char *fmt, ...)
331
0
{
332
0
    va_list ap;
333
0
    va_start(ap, fmt);
334
0
    bool r = set_osd_msg_va(mpctx, level, time, fmt, ap);
335
0
    va_end(ap);
336
0
    return r;
337
0
}
338
339
// type: mp_osd_font_codepoints, ASCII, or OSD_BAR_*
340
void set_osd_bar(struct MPContext *mpctx, int type,
341
                 double min, double max, double neutral, double val)
342
0
{
343
0
    struct MPOpts *opts = mpctx->opts;
344
0
    bool video_osd = mpctx->video_out && mpctx->opts->video_osd;
345
0
    if (opts->osd_level < 1 || !opts->osd_bar_visible || !video_osd)
346
0
        return;
347
348
0
    mpctx->osd_visible = mp_time_sec() + opts->osd_duration / 1000.0;
349
0
    mpctx->osd_progbar.type = type;
350
0
    mpctx->osd_progbar.value = (val - min) / (max - min);
351
0
    mpctx->osd_progbar.num_stops = 0;
352
0
    if (neutral > min && neutral < max) {
353
0
        float pos = (neutral - min) / (max - min);
354
0
        MP_TARRAY_APPEND(mpctx, mpctx->osd_progbar.stops,
355
0
                         mpctx->osd_progbar.num_stops, pos);
356
0
    }
357
0
    osd_set_progbar(mpctx->osd, &mpctx->osd_progbar);
358
0
    mp_wakeup_core(mpctx);
359
0
}
360
361
// Update a currently displayed bar of the same type, without resetting the
362
// timer.
363
static void update_osd_bar(struct MPContext *mpctx, int type,
364
                           double min, double max, double val)
365
0
{
366
0
    if (mpctx->osd_progbar.type != type)
367
0
        return;
368
369
0
    float new_value = (val - min) / (max - min);
370
0
    if (new_value != mpctx->osd_progbar.value) {
371
0
        mpctx->osd_progbar.value = new_value;
372
0
        osd_set_progbar(mpctx->osd, &mpctx->osd_progbar);
373
0
    }
374
0
}
375
376
void set_osd_bar_chapters(struct MPContext *mpctx, int type)
377
486k
{
378
486k
    if (mpctx->osd_progbar.type != type)
379
486k
        return;
380
381
0
    mpctx->osd_progbar.num_stops = 0;
382
0
    double len = get_time_length(mpctx);
383
0
    if (len > 0) {
384
        // Always render the loop points, even if they're incomplete.
385
0
        double ab[2];
386
0
        bool valid = get_ab_loop_times(mpctx, ab);
387
0
        for (int n = 0; n < 2; n++) {
388
0
            if (ab[n] != MP_NOPTS_VALUE) {
389
0
                MP_TARRAY_APPEND(mpctx, mpctx->osd_progbar.stops,
390
0
                                 mpctx->osd_progbar.num_stops, ab[n] / len);
391
0
            }
392
0
        }
393
0
        if (!valid) {
394
0
            int num = get_chapter_count(mpctx);
395
0
            for (int n = 0; n < num; n++) {
396
0
                double time = chapter_start_time(mpctx, n);
397
0
                if (time >= 0) {
398
0
                    float pos = time / len;
399
0
                    MP_TARRAY_APPEND(mpctx, mpctx->osd_progbar.stops,
400
0
                                     mpctx->osd_progbar.num_stops, pos);
401
0
                }
402
0
            }
403
0
        }
404
0
    }
405
0
    osd_set_progbar(mpctx->osd, &mpctx->osd_progbar);
406
0
    mp_wakeup_core(mpctx);
407
0
}
408
409
// osd_function is the symbol appearing in the video status, such as OSD_PLAY
410
void set_osd_function(struct MPContext *mpctx, int osd_function)
411
0
{
412
0
    struct MPOpts *opts = mpctx->opts;
413
414
0
    mpctx->osd_function = osd_function;
415
0
    mpctx->osd_function_visible = mp_time_sec() + opts->osd_duration / 1000.0;
416
0
    mpctx->osd_force_update = true;
417
0
    mp_wakeup_core(mpctx);
418
0
}
419
420
void get_current_osd_sym(struct MPContext *mpctx, char *buf, size_t buf_size)
421
493
{
422
493
    int sym = mpctx->osd_function;
423
493
    if (!sym) {
424
493
        if (is_busy(mpctx) || (mpctx->paused_for_cache && !mpctx->opts->pause)) {
425
365
            sym = OSD_CLOCK;
426
365
        } else if (mpctx->paused || mpctx->step_frames) {
427
0
            sym = OSD_PAUSE;
428
128
        } else if (mpctx->play_dir < 0 ) {
429
0
            sym = OSD_REV;
430
128
        } else {
431
128
            sym = OSD_PLAY;
432
128
        }
433
493
    }
434
493
    osd_get_function_sym(buf, buf_size, sym);
435
493
}
436
437
static void sadd_osd_status(char **buffer, struct MPContext *mpctx, int level)
438
81.4k
{
439
81.4k
    mp_assert(level >= 0 && level <= 3);
440
81.4k
    if (level == 0)
441
8
        return;
442
81.4k
    char *msg = mpctx->opts->osd_msg[level - 1];
443
444
81.4k
    if (msg && msg[0]) {
445
12.2k
        char *text = mp_property_expand_escaped_string(mpctx, msg);
446
12.2k
        *buffer = talloc_strdup_append(*buffer, text);
447
12.2k
        talloc_free(text);
448
69.2k
    } else if (level >= 2) {
449
13
        bool fractions = mpctx->opts->osd_fractions;
450
13
        char sym[10];
451
13
        get_current_osd_sym(mpctx, sym, sizeof(sym));
452
13
        saddf(buffer, "%s ", sym);
453
13
        char *custom_msg = mpctx->opts->osd_status_msg;
454
13
        if (custom_msg && level == 3) {
455
0
            char *text = mp_property_expand_escaped_string(mpctx, custom_msg);
456
0
            *buffer = talloc_strdup_append(*buffer, text);
457
0
            talloc_free(text);
458
13
        } else {
459
13
            sadd_hhmmssff(buffer, get_playback_time(mpctx), fractions);
460
13
            if (level == 3) {
461
6
                saddf(buffer, " / ");
462
6
                sadd_hhmmssff(buffer, get_time_length(mpctx), fractions);
463
6
                sadd_percentage(buffer, get_current_pos_ratio(mpctx, false));
464
6
            }
465
13
        }
466
13
    }
467
81.4k
}
468
469
// OSD messages initiated by seeking commands are added lazily with this
470
// function, because multiple successive seek commands can be coalesced.
471
static void add_seek_osd_messages(struct MPContext *mpctx)
472
505k
{
473
505k
    if (mpctx->add_osd_seek_info & OSD_SEEK_INFO_BAR) {
474
0
        double pos = get_current_pos_ratio(mpctx, false);
475
0
        set_osd_bar(mpctx, OSD_BAR_SEEK, 0, 1, 0, MPCLAMP(pos, 0, 1));
476
0
        set_osd_bar_chapters(mpctx, OSD_BAR_SEEK);
477
0
    }
478
505k
    if (mpctx->add_osd_seek_info & OSD_SEEK_INFO_TEXT) {
479
        // Never in term-osd mode
480
0
        bool video_osd = mpctx->video_out && mpctx->opts->video_osd;
481
0
        if (video_osd && mpctx->opts->term_osd != 1) {
482
0
            if (set_osd_msg(mpctx, 1, mpctx->opts->osd_duration, ""))
483
0
                mpctx->osd_show_pos = true;
484
0
        }
485
0
    }
486
505k
    if (mpctx->add_osd_seek_info & OSD_SEEK_INFO_CHAPTER_TEXT) {
487
0
        char *chapter = chapter_display_name(mpctx, get_current_chapter(mpctx));
488
0
        set_osd_msg(mpctx, 1, mpctx->opts->osd_duration,
489
0
                     "Chapter: %s", chapter);
490
0
        talloc_free(chapter);
491
0
    }
492
505k
    if (mpctx->add_osd_seek_info & OSD_SEEK_INFO_CURRENT_FILE) {
493
0
        if (mpctx->filename) {
494
0
            set_osd_msg(mpctx, 1, mpctx->opts->osd_duration, "%s",
495
0
                        mpctx->filename);
496
0
        }
497
0
    }
498
505k
    mpctx->add_osd_seek_info = 0;
499
505k
}
500
501
// Update the OSD text (both on VO and terminal status line).
502
void update_osd_msg(struct MPContext *mpctx)
503
2.04M
{
504
2.04M
    struct MPOpts *opts = mpctx->opts;
505
2.04M
    struct osd_state *osd = mpctx->osd;
506
507
2.04M
    double now = mp_time_sec();
508
509
2.04M
    if (!mpctx->osd_force_update) {
510
        // Assume nothing is going on at all.
511
1.69M
        if (!mpctx->osd_idle_update)
512
157k
            return;
513
514
1.53M
        double delay = 0.050; // update the OSD at most this often
515
1.53M
        double diff = now - mpctx->osd_last_update;
516
1.53M
        if (diff < delay) {
517
1.37M
            mp_set_timeout(mpctx, delay - diff);
518
1.37M
            return;
519
1.37M
        }
520
1.53M
    }
521
505k
    mpctx->osd_force_update = false;
522
505k
    mpctx->osd_idle_update = false;
523
505k
    mpctx->osd_last_update = now;
524
525
505k
    if (mpctx->osd_visible) {
526
0
        double sleep = mpctx->osd_visible - now;
527
0
        if (sleep > 0) {
528
0
            mp_set_timeout(mpctx, sleep);
529
0
            mpctx->osd_idle_update = true;
530
0
        } else {
531
0
            mpctx->osd_visible = 0;
532
0
            mpctx->osd_progbar.type = -1; // disable
533
0
            osd_set_progbar(mpctx->osd, &mpctx->osd_progbar);
534
0
        }
535
0
    }
536
537
505k
    if (mpctx->osd_function_visible) {
538
0
        double sleep = mpctx->osd_function_visible - now;
539
0
        if (sleep > 0) {
540
0
            mp_set_timeout(mpctx, sleep);
541
0
            mpctx->osd_idle_update = true;
542
0
        } else {
543
0
            mpctx->osd_function_visible = 0;
544
0
            mpctx->osd_function = 0;
545
0
        }
546
0
    }
547
548
505k
    if (mpctx->osd_msg_next_duration > 0) {
549
        // This is done to avoid cutting the OSD message short if slow commands
550
        // are executed between setting the OSD message and showing it.
551
0
        mpctx->osd_msg_visible = now + mpctx->osd_msg_next_duration;
552
0
        mpctx->osd_msg_next_duration = 0;
553
0
    }
554
555
505k
    if (mpctx->osd_msg_visible) {
556
0
        double sleep = mpctx->osd_msg_visible - now;
557
0
        if (sleep > 0) {
558
0
            mp_set_timeout(mpctx, sleep);
559
0
            mpctx->osd_idle_update = true;
560
0
        } else {
561
0
            talloc_free(mpctx->osd_msg_text);
562
0
            mpctx->osd_msg_text = NULL;
563
0
            mpctx->osd_msg_visible = 0;
564
0
            mpctx->osd_show_pos = false;
565
0
        }
566
0
    }
567
568
505k
    add_seek_osd_messages(mpctx);
569
570
505k
    if (mpctx->osd_progbar.type == OSD_BAR_SEEK) {
571
0
        double pos = get_current_pos_ratio(mpctx, false);
572
0
        update_osd_bar(mpctx, OSD_BAR_SEEK, 0, 1, MPCLAMP(pos, 0, 1));
573
0
    }
574
575
505k
    term_osd_set_text_lazy(mpctx, mpctx->osd_msg_text);
576
505k
    term_osd_print_status_lazy(mpctx);
577
505k
    term_osd_update(mpctx);
578
579
505k
    if (!opts->video_osd)
580
424k
        return;
581
582
81.4k
    int osd_level = opts->osd_level;
583
81.4k
    if (mpctx->osd_show_pos)
584
0
        osd_level = 3;
585
586
81.4k
    char *text = NULL;
587
81.4k
    sadd_osd_status(&text, mpctx, osd_level);
588
81.4k
    if (mpctx->osd_msg_text && mpctx->osd_msg_text[0]) {
589
0
        text = talloc_asprintf_append(text, "%s%s", text ? "\n" : "",
590
0
                                      mpctx->osd_msg_text);
591
0
    }
592
81.4k
    osd_set_text(osd, text);
593
81.4k
    talloc_free(text);
594
81.4k
}