summaryrefslogtreecommitdiffstats
path: root/audio/out
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2016-09-16 14:23:54 +0200
committerwm4 <wm4@nowhere>2016-09-16 14:37:48 +0200
commitb8ade7c99b830ee9870040bcfc1f2c3d3a64d172 (patch)
tree48df8031d90be4e6e1f9c9c4045a72e21c33862c /audio/out
parentf845f64c2abe4361084b4bc07f5f1ea5dd43ec9f (diff)
downloadmpv-b8ade7c99b830ee9870040bcfc1f2c3d3a64d172.tar.bz2
mpv-b8ade7c99b830ee9870040bcfc1f2c3d3a64d172.tar.xz
player, ao, vo: don't call mp_input_wakeup() directly
Currently, calling mp_input_wakeup() will wake up the core thread (also called the playloop). This seems odd, but currently the core indeed calls mp_input_wait() when it has nothing more to do. It's done this way because MPlayer used input_ctx as central "mainloop". This is probably going to change. Remove direct calls to this function, and replace it with mp_wakeup_core() calls. ao and vo are changed to use opaque callbacks and not use input_ctx for this purpose. Other code already uses opaque callbacks, or has legitimate reasons to use input_ctx directly (such as sending actual user input).
Diffstat (limited to 'audio/out')
-rw-r--r--audio/out/ao.c44
-rw-r--r--audio/out/ao.h5
-rw-r--r--audio/out/internal.h3
-rw-r--r--audio/out/pull.c2
-rw-r--r--audio/out/push.c4
5 files changed, 35 insertions, 23 deletions
diff --git a/audio/out/ao.c b/audio/out/ao.c
index cd2b9e8089..15c0f8139e 100644
--- a/audio/out/ao.c
+++ b/audio/out/ao.c
@@ -28,7 +28,6 @@
#include "audio/format.h"
#include "audio/audio.h"
-#include "input/input.h"
#include "options/options.h"
#include "options/m_config.h"
#include "common/msg.h"
@@ -127,8 +126,11 @@ const struct m_obj_list ao_obj_list = {
};
static struct ao *ao_alloc(bool probing, struct mpv_global *global,
- struct input_ctx *input_ctx, char *name, char **args)
+ void (*wakeup_cb)(void *ctx), void *wakeup_ctx,
+ char *name, char **args)
{
+ assert(wakeup_cb);
+
struct MPOpts *opts = global->opts;
struct mp_log *log = mp_log_new(NULL, global->log, "ao");
struct m_obj_desc desc;
@@ -143,7 +145,8 @@ static struct ao *ao_alloc(bool probing, struct mpv_global *global,
.driver = desc.p,
.probing = probing,
.global = global,
- .input_ctx = input_ctx,
+ .wakeup_cb = wakeup_cb,
+ .wakeup_ctx = wakeup_ctx,
.log = mp_log_new(ao, log, name),
.def_buffer = opts->audio_buffer,
.client_name = talloc_strdup(ao, opts->audio_client_name),
@@ -161,12 +164,12 @@ error:
}
static struct ao *ao_init(bool probing, struct mpv_global *global,
- struct input_ctx *input_ctx,
+ void (*wakeup_cb)(void *ctx), void *wakeup_ctx,
struct encode_lavc_context *encode_lavc_ctx, int flags,
int samplerate, int format, struct mp_chmap channels,
char *dev, char *name, char **args)
{
- struct ao *ao = ao_alloc(probing, global, input_ctx, name, args);
+ struct ao *ao = ao_alloc(probing, global, wakeup_cb, wakeup_ctx, name, args);
if (!ao)
return NULL;
ao->samplerate = samplerate;
@@ -197,8 +200,9 @@ static struct ao *ao_init(bool probing, struct mpv_global *global,
snprintf(redirect, sizeof(redirect), "%s", ao->redirect);
snprintf(rdevice, sizeof(rdevice), "%s", ao->device ? ao->device : "");
talloc_free(ao);
- return ao_init(probing, global, input_ctx, encode_lavc_ctx, flags,
- samplerate, format, channels, rdevice, redirect, NULL);
+ return ao_init(probing, global, wakeup_cb, wakeup_ctx,
+ encode_lavc_ctx, flags, samplerate, format, channels,
+ rdevice, redirect, NULL);
}
goto fail;
}
@@ -248,7 +252,7 @@ static void split_ao_device(void *tmp, char *opt, char **out_ao, char **out_dev)
struct ao *ao_init_best(struct mpv_global *global,
int init_flags,
- struct input_ctx *input_ctx,
+ void (*wakeup_cb)(void *ctx), void *wakeup_ctx,
struct encode_lavc_context *encode_lavc_ctx,
int samplerate, int format, struct mp_chmap channels)
{
@@ -304,8 +308,8 @@ struct ao *ao_init_best(struct mpv_global *global,
dev = pref_dev;
mp_verbose(log, "Using preferred device '%s'\n", dev);
}
- ao = ao_init(probing, global, input_ctx, encode_lavc_ctx, init_flags,
- samplerate, format, channels, dev,
+ ao = ao_init(probing, global, wakeup_cb, wakeup_ctx, encode_lavc_ctx,
+ init_flags, samplerate, format, channels, dev,
entry->name, entry->attribs);
if (ao)
break;
@@ -409,8 +413,7 @@ int ao_query_and_reset_events(struct ao *ao, int events)
static void ao_add_events(struct ao *ao, int events)
{
atomic_fetch_or(&ao->events_, events);
- if (ao->input_ctx)
- mp_input_wakeup(ao->input_ctx);
+ ao->wakeup_cb(ao->wakeup_ctx);
}
// Request that the player core destroys and recreates the AO. Fully thread-safe.
@@ -494,7 +497,8 @@ bool ao_untimed(struct ao *ao)
struct ao_hotplug {
struct mpv_global *global;
- struct input_ctx *input_ctx;
+ void (*wakeup_cb)(void *ctx);
+ void *wakeup_ctx;
// A single AO instance is used to listen to hotplug events. It wouldn't
// make much sense to allow multiple AO drivers; all sane platforms have
// a single such audio API.
@@ -506,12 +510,14 @@ struct ao_hotplug {
};
struct ao_hotplug *ao_hotplug_create(struct mpv_global *global,
- struct input_ctx *input_ctx)
+ void (*wakeup_cb)(void *ctx),
+ void *wakeup_ctx)
{
struct ao_hotplug *hp = talloc_ptrtype(NULL, hp);
*hp = (struct ao_hotplug){
.global = global,
- .input_ctx = input_ctx,
+ .wakeup_cb = wakeup_cb,
+ .wakeup_ctx = wakeup_ctx,
.needs_update = true,
};
return hp;
@@ -564,7 +570,7 @@ struct ao_device_list *ao_hotplug_get_device_list(struct ao_hotplug *hp)
if (d == &audio_out_null)
break; // don't add unsafe/special entries
- struct ao *ao = ao_alloc(true, hp->global, hp->input_ctx,
+ struct ao *ao = ao_alloc(true, hp->global, hp->wakeup_cb, hp->wakeup_ctx,
(char *)d->name, NULL);
if (!ao)
continue;
@@ -605,9 +611,13 @@ void ao_hotplug_destroy(struct ao_hotplug *hp)
talloc_free(hp);
}
+static void dummy_wakeup(void *ctx)
+{
+}
+
void ao_print_devices(struct mpv_global *global, struct mp_log *log)
{
- struct ao_hotplug *hp = ao_hotplug_create(global, NULL);
+ struct ao_hotplug *hp = ao_hotplug_create(global, dummy_wakeup, NULL);
struct ao_device_list *list = ao_hotplug_get_device_list(hp);
mp_info(log, "List of detected audio devices:\n");
for (int n = 0; n < list->num_devices; n++) {
diff --git a/audio/out/ao.h b/audio/out/ao.h
index fe09e2750a..4a4d433c2b 100644
--- a/audio/out/ao.h
+++ b/audio/out/ao.h
@@ -85,7 +85,7 @@ struct mp_audio;
struct ao *ao_init_best(struct mpv_global *global,
int init_flags,
- struct input_ctx *input_ctx,
+ void (*wakeup_cb)(void *ctx), void *wakeup_ctx,
struct encode_lavc_context *encode_lavc_ctx,
int samplerate, int format, struct mp_chmap channels);
void ao_uninit(struct ao *ao);
@@ -108,7 +108,8 @@ void ao_hotplug_event(struct ao *ao);
struct ao_hotplug;
struct ao_hotplug *ao_hotplug_create(struct mpv_global *global,
- struct input_ctx *input_ctx);
+ void (*wakeup_cb)(void *ctx),
+ void *wakeup_ctx);
void ao_hotplug_destroy(struct ao_hotplug *hp);
bool ao_hotplug_check_update(struct ao_hotplug *hp);
const char *ao_hotplug_get_detected_device(struct ao_hotplug *hp);
diff --git a/audio/out/internal.h b/audio/out/internal.h
index 319881b194..3ddc1becb9 100644
--- a/audio/out/internal.h
+++ b/audio/out/internal.h
@@ -42,7 +42,8 @@ struct ao {
void *priv;
struct mpv_global *global;
struct encode_lavc_context *encode_lavc_ctx;
- struct input_ctx *input_ctx;
+ void (*wakeup_cb)(void *ctx);
+ void *wakeup_ctx;
struct mp_log *log; // Using e.g. "[ao/coreaudio]" as prefix
int init_flags; // AO_INIT_* flags
bool stream_silence; // if audio inactive, just play silence
diff --git a/audio/out/pull.c b/audio/out/pull.c
index 5dd6525fc8..44f6ab3355 100644
--- a/audio/out/pull.c
+++ b/audio/out/pull.c
@@ -151,7 +151,7 @@ int ao_read_data(struct ao *ao, void **data, int samples, int64_t out_time_us)
end:
if (need_wakeup)
- mp_input_wakeup_nolock(ao->input_ctx);
+ ao->wakeup_cb(ao->wakeup_ctx);
// pad with silence (underflow/paused/eof)
for (int n = 0; n < ao->num_planes; n++)
diff --git a/audio/out/push.c b/audio/out/push.c
index 406b0da790..623ee6827a 100644
--- a/audio/out/push.c
+++ b/audio/out/push.c
@@ -305,7 +305,7 @@ static void ao_play_data(struct ao *ao)
bool more = needed >= (r == space ? ao->device_buffer / 4 : 1) && !stuck &&
!(flags & AOPLAY_FINAL_CHUNK);
if (more)
- mp_input_wakeup(ao->input_ctx); // request more data
+ ao->wakeup_cb(ao->wakeup_ctx); // request more data
MP_TRACE(ao, "in=%d flags=%d space=%d r=%d wa/pl=%d/%d needed=%d more=%d\n",
max, flags, space, r, p->wait_on_ao, p->still_playing, needed, more);
}
@@ -347,7 +347,7 @@ static void *playthread(void *arg)
}
if (was_playing && !p->still_playing)
- mp_input_wakeup(ao->input_ctx);
+ ao->wakeup_cb(ao->wakeup_ctx);
pthread_cond_signal(&p->wakeup); // for draining
if (p->still_playing && timeout > 0) {