summaryrefslogtreecommitdiffstats
path: root/sub
diff options
context:
space:
mode:
authorKacper Michajłow <kasper93@gmail.com>2023-10-21 04:55:41 +0200
committerDudemanguy <random342@airmail.cc>2023-11-05 17:36:17 +0000
commit174df99ffa53f1091589eaa4fa0c16cdd55a9326 (patch)
tree3a60d45615f18beed98a9b08267c28ed7e05dd5f /sub
parent3a8b107f6216b38a151d5ca1e9d4f2727e3418f5 (diff)
downloadmpv-174df99ffa53f1091589eaa4fa0c16cdd55a9326.tar.bz2
mpv-174df99ffa53f1091589eaa4fa0c16cdd55a9326.tar.xz
ALL: use new mp_thread abstraction
Diffstat (limited to 'sub')
-rw-r--r--sub/dec_sub.c55
-rw-r--r--sub/osd.c52
-rw-r--r--sub/osd_libass.c12
-rw-r--r--sub/osd_state.h4
4 files changed, 61 insertions, 62 deletions
diff --git a/sub/dec_sub.c b/sub/dec_sub.c
index 4f3a917e7a..9de37d7523 100644
--- a/sub/dec_sub.c
+++ b/sub/dec_sub.c
@@ -20,7 +20,6 @@
#include <string.h>
#include <math.h>
#include <assert.h>
-#include <pthread.h>
#include "demux/demux.h"
#include "sd.h"
@@ -43,7 +42,7 @@ static const struct sd_functions *const sd_list[] = {
};
struct dec_sub {
- pthread_mutex_t lock;
+ mp_mutex lock;
struct mp_log *log;
struct mpv_global *global;
@@ -126,7 +125,7 @@ void sub_destroy(struct dec_sub *sub)
sub->sd->driver->uninit(sub->sd);
}
talloc_free(sub->sd);
- pthread_mutex_destroy(&sub->lock);
+ mp_mutex_destroy(&sub->lock);
talloc_free(sub);
}
@@ -182,7 +181,7 @@ struct dec_sub *sub_create(struct mpv_global *global, struct track *track,
.end = MP_NOPTS_VALUE,
};
sub->opts = sub->opts_cache->opts;
- mpthread_mutex_init_recursive(&sub->lock);
+ mp_mutex_init_type(&sub->lock, MP_MUTEX_RECURSIVE);
sub->sd = init_decoder(sub);
if (sub->sd) {
@@ -227,15 +226,15 @@ static void update_segment(struct dec_sub *sub)
bool sub_can_preload(struct dec_sub *sub)
{
bool r;
- pthread_mutex_lock(&sub->lock);
+ mp_mutex_lock(&sub->lock);
r = sub->sd->driver->accept_packets_in_advance && !sub->preload_attempted;
- pthread_mutex_unlock(&sub->lock);
+ mp_mutex_unlock(&sub->lock);
return r;
}
void sub_preload(struct dec_sub *sub)
{
- pthread_mutex_lock(&sub->lock);
+ mp_mutex_lock(&sub->lock);
struct mp_dispatch_queue *demux_waiter = mp_dispatch_create(NULL);
demux_set_stream_wakeup_cb(sub->sh, wakeup_demux, demux_waiter);
@@ -258,7 +257,7 @@ void sub_preload(struct dec_sub *sub)
demux_set_stream_wakeup_cb(sub->sh, NULL, NULL);
talloc_free(demux_waiter);
- pthread_mutex_unlock(&sub->lock);
+ mp_mutex_unlock(&sub->lock);
}
static bool is_new_segment(struct dec_sub *sub, struct demux_packet *p)
@@ -273,7 +272,7 @@ static bool is_new_segment(struct dec_sub *sub, struct demux_packet *p)
bool sub_read_packets(struct dec_sub *sub, double video_pts, bool force)
{
bool r = true;
- pthread_mutex_lock(&sub->lock);
+ mp_mutex_lock(&sub->lock);
video_pts = pts_to_subtitle(sub, video_pts);
while (1) {
bool read_more = true;
@@ -331,7 +330,7 @@ bool sub_read_packets(struct dec_sub *sub, double video_pts, bool force)
if (!(sub->preload_attempted && sub->sd->preload_ok))
sub->sd->driver->decode(sub->sd, pkt);
}
- pthread_mutex_unlock(&sub->lock);
+ mp_mutex_unlock(&sub->lock);
return r;
}
@@ -339,19 +338,19 @@ bool sub_read_packets(struct dec_sub *sub, double video_pts, bool force)
// Used with UPDATE_SUB_HARD and UPDATE_SUB_FILT.
void sub_redecode_cached_packets(struct dec_sub *sub)
{
- pthread_mutex_lock(&sub->lock);
+ mp_mutex_lock(&sub->lock);
if (sub->cached_pkts[0])
sub->sd->driver->decode(sub->sd, sub->cached_pkts[0]);
if (sub->cached_pkts[1])
sub->sd->driver->decode(sub->sd, sub->cached_pkts[1]);
- pthread_mutex_unlock(&sub->lock);
+ mp_mutex_unlock(&sub->lock);
}
// Unref sub_bitmaps.rc to free the result. May return NULL.
struct sub_bitmaps *sub_get_bitmaps(struct dec_sub *sub, struct mp_osd_res dim,
int format, double pts)
{
- pthread_mutex_lock(&sub->lock);
+ mp_mutex_lock(&sub->lock);
pts = pts_to_subtitle(sub, pts);
@@ -364,14 +363,14 @@ struct sub_bitmaps *sub_get_bitmaps(struct dec_sub *sub, struct mp_osd_res dim,
sub->sd->driver->get_bitmaps)
res = sub->sd->driver->get_bitmaps(sub->sd, dim, format, pts);
- pthread_mutex_unlock(&sub->lock);
+ mp_mutex_unlock(&sub->lock);
return res;
}
// The returned string is talloc'ed.
char *sub_get_text(struct dec_sub *sub, double pts, enum sd_text_type type)
{
- pthread_mutex_lock(&sub->lock);
+ mp_mutex_lock(&sub->lock);
char *text = NULL;
pts = pts_to_subtitle(sub, pts);
@@ -381,7 +380,7 @@ char *sub_get_text(struct dec_sub *sub, double pts, enum sd_text_type type)
if (sub->sd->driver->get_text)
text = sub->sd->driver->get_text(sub->sd, pts, type);
- pthread_mutex_unlock(&sub->lock);
+ mp_mutex_unlock(&sub->lock);
return text;
}
@@ -396,7 +395,7 @@ char *sub_ass_get_extradata(struct dec_sub *sub)
struct sd_times sub_get_times(struct dec_sub *sub, double pts)
{
- pthread_mutex_lock(&sub->lock);
+ mp_mutex_lock(&sub->lock);
struct sd_times res = { .start = MP_NOPTS_VALUE, .end = MP_NOPTS_VALUE };
pts = pts_to_subtitle(sub, pts);
@@ -407,13 +406,13 @@ struct sd_times sub_get_times(struct dec_sub *sub, double pts)
if (sub->sd->driver->get_times)
res = sub->sd->driver->get_times(sub->sd, pts);
- pthread_mutex_unlock(&sub->lock);
+ mp_mutex_unlock(&sub->lock);
return res;
}
void sub_reset(struct dec_sub *sub)
{
- pthread_mutex_lock(&sub->lock);
+ mp_mutex_lock(&sub->lock);
if (sub->sd->driver->reset)
sub->sd->driver->reset(sub->sd);
sub->last_pkt_pts = MP_NOPTS_VALUE;
@@ -421,21 +420,21 @@ void sub_reset(struct dec_sub *sub)
TA_FREEP(&sub->cached_pkts[0]);
TA_FREEP(&sub->cached_pkts[1]);
TA_FREEP(&sub->new_segment);
- pthread_mutex_unlock(&sub->lock);
+ mp_mutex_unlock(&sub->lock);
}
void sub_select(struct dec_sub *sub, bool selected)
{
- pthread_mutex_lock(&sub->lock);
+ mp_mutex_lock(&sub->lock);
if (sub->sd->driver->select)
sub->sd->driver->select(sub->sd, selected);
- pthread_mutex_unlock(&sub->lock);
+ mp_mutex_unlock(&sub->lock);
}
int sub_control(struct dec_sub *sub, enum sd_ctrl cmd, void *arg)
{
int r = CONTROL_UNKNOWN;
- pthread_mutex_lock(&sub->lock);
+ mp_mutex_lock(&sub->lock);
bool propagate = false;
switch (cmd) {
case SD_CTRL_SET_VIDEO_DEF_FPS:
@@ -470,22 +469,22 @@ int sub_control(struct dec_sub *sub, enum sd_ctrl cmd, void *arg)
}
if (propagate && sub->sd->driver->control)
r = sub->sd->driver->control(sub->sd, cmd, arg);
- pthread_mutex_unlock(&sub->lock);
+ mp_mutex_unlock(&sub->lock);
return r;
}
void sub_set_recorder_sink(struct dec_sub *sub, struct mp_recorder_sink *sink)
{
- pthread_mutex_lock(&sub->lock);
+ mp_mutex_lock(&sub->lock);
sub->recorder_sink = sink;
- pthread_mutex_unlock(&sub->lock);
+ mp_mutex_unlock(&sub->lock);
}
void sub_set_play_dir(struct dec_sub *sub, int dir)
{
- pthread_mutex_lock(&sub->lock);
+ mp_mutex_lock(&sub->lock);
sub->play_dir = dir;
- pthread_mutex_unlock(&sub->lock);
+ mp_mutex_unlock(&sub->lock);
}
bool sub_is_primary_visible(struct dec_sub *sub)
diff --git a/sub/osd.c b/sub/osd.c
index 88baecb768..9d6926dcb6 100644
--- a/sub/osd.c
+++ b/sub/osd.c
@@ -129,7 +129,7 @@ struct osd_state *osd_create(struct mpv_global *global)
.force_video_pts = MP_NOPTS_VALUE,
.stats = stats_ctx_create(osd, global, "osd"),
};
- pthread_mutex_init(&osd->lock, NULL);
+ mp_mutex_init(&osd->lock);
osd->opts = osd->opts_cache->opts;
for (int n = 0; n < MAX_OSD_PARTS; n++) {
@@ -156,13 +156,13 @@ void osd_free(struct osd_state *osd)
return;
osd_destroy_backend(osd);
talloc_free(osd->objs[OSDTYPE_EXTERNAL2]->external2);
- pthread_mutex_destroy(&osd->lock);
+ mp_mutex_destroy(&osd->lock);
talloc_free(osd);
}
void osd_set_text(struct osd_state *osd, const char *text)
{
- pthread_mutex_lock(&osd->lock);
+ mp_mutex_lock(&osd->lock);
struct osd_object *osd_obj = osd->objs[OSDTYPE_OSD];
if (!text)
text = "";
@@ -172,32 +172,32 @@ void osd_set_text(struct osd_state *osd, const char *text)
osd_obj->osd_changed = true;
osd->want_redraw_notification = true;
}
- pthread_mutex_unlock(&osd->lock);
+ mp_mutex_unlock(&osd->lock);
}
void osd_set_sub(struct osd_state *osd, int index, struct dec_sub *dec_sub)
{
- pthread_mutex_lock(&osd->lock);
+ mp_mutex_lock(&osd->lock);
if (index >= 0 && index < 2) {
struct osd_object *obj = osd->objs[OSDTYPE_SUB + index];
obj->sub = dec_sub;
obj->vo_change_id += 1;
}
osd->want_redraw_notification = true;
- pthread_mutex_unlock(&osd->lock);
+ mp_mutex_unlock(&osd->lock);
}
bool osd_get_render_subs_in_filter(struct osd_state *osd)
{
- pthread_mutex_lock(&osd->lock);
+ mp_mutex_lock(&osd->lock);
bool r = osd->render_subs_in_filter;
- pthread_mutex_unlock(&osd->lock);
+ mp_mutex_unlock(&osd->lock);
return r;
}
void osd_set_render_subs_in_filter(struct osd_state *osd, bool s)
{
- pthread_mutex_lock(&osd->lock);
+ mp_mutex_lock(&osd->lock);
if (osd->render_subs_in_filter != s) {
osd->render_subs_in_filter = s;
@@ -207,7 +207,7 @@ void osd_set_render_subs_in_filter(struct osd_state *osd, bool s)
for (int n = 0; n < MAX_OSD_PARTS; n++)
osd->objs[n]->vo_change_id = change_id + 1;
}
- pthread_mutex_unlock(&osd->lock);
+ mp_mutex_unlock(&osd->lock);
}
void osd_set_force_video_pts(struct osd_state *osd, double video_pts)
@@ -222,7 +222,7 @@ double osd_get_force_video_pts(struct osd_state *osd)
void osd_set_progbar(struct osd_state *osd, struct osd_progbar_state *s)
{
- pthread_mutex_lock(&osd->lock);
+ mp_mutex_lock(&osd->lock);
struct osd_object *osd_obj = osd->objs[OSDTYPE_OSD];
osd_obj->progbar_state.type = s->type;
osd_obj->progbar_state.value = s->value;
@@ -234,18 +234,18 @@ void osd_set_progbar(struct osd_state *osd, struct osd_progbar_state *s)
}
osd_obj->osd_changed = true;
osd->want_redraw_notification = true;
- pthread_mutex_unlock(&osd->lock);
+ mp_mutex_unlock(&osd->lock);
}
void osd_set_external2(struct osd_state *osd, struct sub_bitmaps *imgs)
{
- pthread_mutex_lock(&osd->lock);
+ mp_mutex_lock(&osd->lock);
struct osd_object *obj = osd->objs[OSDTYPE_EXTERNAL2];
talloc_free(obj->external2);
obj->external2 = sub_bitmaps_copy(NULL, imgs);
obj->vo_change_id += 1;
osd->want_redraw_notification = true;
- pthread_mutex_unlock(&osd->lock);
+ mp_mutex_unlock(&osd->lock);
}
static void check_obj_resize(struct osd_state *osd, struct mp_osd_res res,
@@ -268,11 +268,11 @@ static void check_obj_resize(struct osd_state *osd, struct mp_osd_res res,
// Unnecessary for anything else.
void osd_resize(struct osd_state *osd, struct mp_osd_res res)
{
- pthread_mutex_lock(&osd->lock);
+ mp_mutex_lock(&osd->lock);
int types[] = {OSDTYPE_OSD, OSDTYPE_EXTERNAL, OSDTYPE_EXTERNAL2, -1};
for (int n = 0; types[n] >= 0; n++)
check_obj_resize(osd, res, osd->objs[types[n]]);
- pthread_mutex_unlock(&osd->lock);
+ mp_mutex_unlock(&osd->lock);
}
static struct sub_bitmaps *render_object(struct osd_state *osd,
@@ -326,7 +326,7 @@ struct sub_bitmap_list *osd_render(struct osd_state *osd, struct mp_osd_res res,
double video_pts, int draw_flags,
const bool formats[SUBBITMAP_COUNT])
{
- pthread_mutex_lock(&osd->lock);
+ mp_mutex_lock(&osd->lock);
struct sub_bitmap_list *list = talloc_zero(NULL, struct sub_bitmap_list);
list->change_id = 1;
@@ -383,7 +383,7 @@ struct sub_bitmap_list *osd_render(struct osd_state *osd, struct mp_osd_res res,
if (!(draw_flags & OSD_DRAW_SUB_FILTER))
osd->want_redraw_notification = false;
- pthread_mutex_unlock(&osd->lock);
+ mp_mutex_unlock(&osd->lock);
return list;
}
@@ -433,7 +433,7 @@ void osd_draw_on_image_p(struct osd_state *osd, struct mp_osd_res res,
return; // on OOM, skip
// Need to lock for the dumb osd->draw_cache thing.
- pthread_mutex_lock(&osd->lock);
+ mp_mutex_lock(&osd->lock);
if (!osd->draw_cache)
osd->draw_cache = mp_draw_sub_alloc(osd, osd->global);
@@ -446,7 +446,7 @@ void osd_draw_on_image_p(struct osd_state *osd, struct mp_osd_res res,
stats_time_end(osd->stats, "draw-bmp");
- pthread_mutex_unlock(&osd->lock);
+ mp_mutex_unlock(&osd->lock);
talloc_free(list);
}
@@ -466,29 +466,29 @@ struct mp_osd_res osd_res_from_image_params(const struct mp_image_params *p)
// Typically called to react to OSD style changes.
void osd_changed(struct osd_state *osd)
{
- pthread_mutex_lock(&osd->lock);
+ mp_mutex_lock(&osd->lock);
osd->objs[OSDTYPE_OSD]->osd_changed = true;
osd->want_redraw_notification = true;
// Done here for a lack of a better place.
m_config_cache_update(osd->opts_cache);
- pthread_mutex_unlock(&osd->lock);
+ mp_mutex_unlock(&osd->lock);
}
bool osd_query_and_reset_want_redraw(struct osd_state *osd)
{
- pthread_mutex_lock(&osd->lock);
+ mp_mutex_lock(&osd->lock);
bool r = osd->want_redraw_notification;
osd->want_redraw_notification = false;
- pthread_mutex_unlock(&osd->lock);
+ mp_mutex_unlock(&osd->lock);
return r;
}
struct mp_osd_res osd_get_vo_res(struct osd_state *osd)
{
- pthread_mutex_lock(&osd->lock);
+ mp_mutex_lock(&osd->lock);
// Any OSDTYPE is fine; but it mustn't be a subtitle one (can have lower res.)
struct mp_osd_res res = osd->objs[OSDTYPE_OSD]->vo_res;
- pthread_mutex_unlock(&osd->lock);
+ mp_mutex_unlock(&osd->lock);
return res;
}
diff --git a/sub/osd_libass.c b/sub/osd_libass.c
index d4c0b1107a..a3b19c96df 100644
--- a/sub/osd_libass.c
+++ b/sub/osd_libass.c
@@ -268,12 +268,12 @@ static void update_osd_text(struct osd_state *osd, struct osd_object *obj)
void osd_get_text_size(struct osd_state *osd, int *out_screen_h, int *out_font_h)
{
- pthread_mutex_lock(&osd->lock);
+ mp_mutex_lock(&osd->lock);
struct osd_object *obj = osd->objs[OSDTYPE_OSD];
ASS_Style *style = prepare_osd_ass(osd, obj);
*out_screen_h = obj->ass.track->PlayResY - style->MarginV;
*out_font_h = style->FontSize;
- pthread_mutex_unlock(&osd->lock);
+ mp_mutex_unlock(&osd->lock);
}
// align: -1 .. +1
@@ -534,7 +534,7 @@ static int cmp_zorder(const void *pa, const void *pb)
void osd_set_external(struct osd_state *osd, struct osd_external_ass *ov)
{
- pthread_mutex_lock(&osd->lock);
+ mp_mutex_lock(&osd->lock);
struct osd_object *obj = osd->objs[OSDTYPE_EXTERNAL];
bool zorder_changed = false;
int index = -1;
@@ -616,12 +616,12 @@ void osd_set_external(struct osd_state *osd, struct osd_external_ass *ov)
}
done:
- pthread_mutex_unlock(&osd->lock);
+ mp_mutex_unlock(&osd->lock);
}
void osd_set_external_remove_owner(struct osd_state *osd, void *owner)
{
- pthread_mutex_lock(&osd->lock);
+ mp_mutex_lock(&osd->lock);
struct osd_object *obj = osd->objs[OSDTYPE_EXTERNAL];
for (int n = obj->num_externals - 1; n >= 0; n--) {
struct osd_external *e = obj->externals[n];
@@ -632,7 +632,7 @@ void osd_set_external_remove_owner(struct osd_state *osd, void *owner)
osd->want_redraw_notification = true;
}
}
- pthread_mutex_unlock(&osd->lock);
+ mp_mutex_unlock(&osd->lock);
}
static void append_ass(struct ass_state *ass, struct mp_osd_res *res,
diff --git a/sub/osd_state.h b/sub/osd_state.h
index 79f7b902d8..9bb48f8153 100644
--- a/sub/osd_state.h
+++ b/sub/osd_state.h
@@ -1,10 +1,10 @@
#ifndef MP_OSD_STATE_H_
#define MP_OSD_STATE_H_
-#include <pthread.h>
#include <stdatomic.h>
#include "osd.h"
+#include "osdep/threads.h"
enum mp_osdtype {
OSDTYPE_SUB,
@@ -66,7 +66,7 @@ struct osd_external {
};
struct osd_state {
- pthread_mutex_t lock;
+ mp_mutex lock;
struct osd_object *objs[MAX_OSD_PARTS];