mirror of https://github.com/mpv-player/mpv
sub/osd: use atomic for osd_state.force_video_pts
this field is used only in a special vo draining edge case. switching to an atomic reduces osd->lock contention between the mpv core (in write_video) and vo threads which are managing osd rendering manually (such as vo_rpi). Signed-off-by: Aman Karmani <aman@tmm1.net>
This commit is contained in:
parent
76b9254b8b
commit
fb7b66ecf1
16
sub/osd.c
16
sub/osd.c
|
@ -124,7 +124,7 @@ struct osd_state *osd_create(struct mpv_global *global)
|
|||
.opts_cache = m_config_cache_alloc(osd, global, &mp_osd_render_sub_opts),
|
||||
.global = global,
|
||||
.log = mp_log_new(osd, global->log, "osd"),
|
||||
.force_video_pts = MP_NOPTS_VALUE,
|
||||
.force_video_pts = ATOMIC_VAR_INIT(MP_NOPTS_VALUE),
|
||||
.stats = stats_ctx_create(osd, global, "osd"),
|
||||
};
|
||||
pthread_mutex_init(&osd->lock, NULL);
|
||||
|
@ -210,17 +210,12 @@ void osd_set_render_subs_in_filter(struct osd_state *osd, bool s)
|
|||
|
||||
void osd_set_force_video_pts(struct osd_state *osd, double video_pts)
|
||||
{
|
||||
pthread_mutex_lock(&osd->lock);
|
||||
osd->force_video_pts = video_pts;
|
||||
pthread_mutex_unlock(&osd->lock);
|
||||
atomic_store(&osd->force_video_pts, video_pts);
|
||||
}
|
||||
|
||||
double osd_get_force_video_pts(struct osd_state *osd)
|
||||
{
|
||||
pthread_mutex_lock(&osd->lock);
|
||||
double pts = osd->force_video_pts;
|
||||
pthread_mutex_unlock(&osd->lock);
|
||||
return pts;
|
||||
return atomic_load(&osd->force_video_pts);
|
||||
}
|
||||
|
||||
void osd_set_progbar(struct osd_state *osd, struct osd_progbar_state *s)
|
||||
|
@ -335,8 +330,9 @@ struct sub_bitmap_list *osd_render(struct osd_state *osd, struct mp_osd_res res,
|
|||
list->w = res.w;
|
||||
list->h = res.h;
|
||||
|
||||
if (osd->force_video_pts != MP_NOPTS_VALUE)
|
||||
video_pts = osd->force_video_pts;
|
||||
double force_video_pts = atomic_load(&osd->force_video_pts);
|
||||
if (force_video_pts != MP_NOPTS_VALUE)
|
||||
video_pts = force_video_pts;
|
||||
|
||||
if (draw_flags & OSD_DRAW_SUB_FILTER)
|
||||
draw_flags |= OSD_DRAW_SUB_ONLY;
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include <pthread.h>
|
||||
|
||||
#include "osdep/atomic.h"
|
||||
#include "osd.h"
|
||||
|
||||
enum mp_osdtype {
|
||||
|
@ -70,7 +71,7 @@ struct osd_state {
|
|||
struct osd_object *objs[MAX_OSD_PARTS];
|
||||
|
||||
bool render_subs_in_filter;
|
||||
double force_video_pts;
|
||||
mp_atomic_double force_video_pts;
|
||||
|
||||
bool want_redraw;
|
||||
bool want_redraw_notification;
|
||||
|
|
Loading…
Reference in New Issue