ALL: use new mp_thread abstraction

This commit is contained in:
Kacper Michajłow
2023-10-21 04:55:41 +02:00
committed by Dudemanguy
parent 3a8b107f62
commit 174df99ffa
81 changed files with 1255 additions and 1302 deletions

View File

@@ -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)