From b83bdd1d17cc90b4d8cd2a32321cd7c5cc306422 Mon Sep 17 00:00:00 2001 From: wm4 Date: Mon, 25 May 2020 01:53:41 +0200 Subject: audio: merge pull/push ring buffer glue code This is preparation to further cleanups (and eventually actual improvements) of the audio output code. AOs are split into two classes: pull and push. Pull AOs let an audio callback of the native audio API read from a ring buffer. Push AOs expose a function that works similar to write(), and for which we start a "feeder" thread. It seems making this split was beneficial, because of the different data flow, and emulating the one or other in the AOs directly would have created code duplication (all the "pull" AOs had their own ring buffer implementation before it was cleaned up). Unfortunately, both types had completely separate implementations (in pull.c and push.c). The idea was that little can be shared anyway. But that's very annoying now, because I want to change the API between AO and player. This commit attempts to merge them. I've moved everything from push.c to pull.c, the trivial entrypoints from ao.c to pull.c, and attempted to reconcile the differences. It's a mess, but at least there's only one ring buffer within the AO code now. Everything should work mostly the same. Pull AOs now always copy the audio data under a lock; before this commit, all ring buffer access was lock-free (except for the decoder wakeup callback, which acquired a mutex). In theory, this is "bad", and people obsessed with lock-free stuff will hate me, but in practice probably won't matter. The planned change will probably remove this copying-under-lock again, but who knows when this will happen. One change for the push AOs now makes it drop audio, where before only a warning was logged. This is only in case of AOs or drivers which exhibit unexpected (and now unsupported) behavior. This is a risky change. Although it's completely trivial conceptually, there are too many special cases. In addition, I barely tested it, and I've messed with it in a half-motivated state over a longer time, barely making any progress, and finishing it under a rush when I already should have been asleep. Most things seem to work, and I made superficial tests with alsa, sdl, and encode mode. This should cover most things, but there are a lot of tricky things that received no coverage. All this text means you should be prepared to roll back to an older commit and report your problem. --- wscript_build.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'wscript_build.py') diff --git a/wscript_build.py b/wscript_build.py index 34398c10cd..1c7a681a77 100644 --- a/wscript_build.py +++ b/wscript_build.py @@ -262,8 +262,7 @@ def build(ctx): ( "audio/out/ao_wasapi.c", "wasapi" ), ( "audio/out/ao_wasapi_changenotify.c", "wasapi" ), ( "audio/out/ao_wasapi_utils.c", "wasapi" ), - ( "audio/out/pull.c" ), - ( "audio/out/push.c" ), + ( "audio/out/buffer.c" ), ## Core ( "common/av_common.c" ), -- cgit v1.2.3