Commit Graph

18 Commits

Author SHA1 Message Date
sfan5 8f96169117 ao_opensles: fix delayed audio
This was forgotten in commit 5a8c48fde2
when the number of buffers was reduced to 1.
2019-09-02 00:38:05 +03:00
Tom Yan 6c2d6a3046 ao_opensles: set numBuffers to 8
Apparently some Android builds/forks require this for Bluetooth
audio to work as they unexpectedly accept fast flag for it.

Shouldn't cause any side-effect (e.g. buffer requirement increased
when on wired audio). It's a hardcoded default in the upstream
AAudio implementation anyway.

Ref.:
https://android.googlesource.com/platform/frameworks/av/+/android-8.0.0_r1/media/libaaudio/src/legacy/AudioStreamTrack.cpp#109
https://android.googlesource.com/platform/frameworks/wilhelm/+/android-8.0.0_r1/src/android/AudioPlayer_to_android.cpp#1680
https://android.googlesource.com/platform/frameworks/av/+/android-8.0.0_r1/media/libaudioclient/AudioTrack.cpp#488
2018-08-13 19:10:10 +02:00
Tom Yan e1bd5288b7 ao_opensles: rework the heuristic of buffer/enqueue size setting
ao->device_buffer will only affect the enqueue size if the latter
is not specified. In other word, its intended purpose will solely
be setting/guarding the soft buffer size.

This guarantees that the soft buffer size will be consistent no
matter a specific enqueue size is set or not. (In the past it
would drop to the default of the generic audio-buffer option.)

opensles-frames-per-buffer has been renamed to opensles-frames-per
-enqueue, as it was never purposed to set the soft buffer size. It
will only make sure the size is never smaller than itself, just as
before.

opensles-buffer-size-in-ms is introduced to allow easy tuning of
the relative (i.e. in time) soft buffer size (and enqueue size,
unless the aforementioned option is set). As "device buffer" never
really made sense in this AO, this option OVERRIDES audio-buffer
whenever its value (including the default) is larger than 0.

Setting opensl-buffer-size-in-ms to 1 allows you to equate the soft
buffer size to the absolute enqueue size set with opensl-frames-per
-enqueue conveniently (unless it is less than 1ms).

When both are set to 0, audio-buffer will be the ultimate fallback.
If audio-buffer is also 0, the AO errors out.
2018-08-05 17:52:01 +02:00
Tom Yan 8baad91e7b ao_opensles: allow s32 and float output
OpenSLES (and its AudioTrack backend) in Android can take 32-bit
fixed and floating point input since Android L (API 21).
2018-08-05 17:51:45 +02:00
Tom Yan b0951d71f8 ao_opensles: let cfg_frames_per_buffer accept buffer size up to 0.5s at 192kHz 2018-04-05 04:35:49 +03:00
Tom Yan e3b3e28deb ao_opensles: remove useless cfg_sample_rate
We should always use the ao-neutral --audio-samplerate option.
2018-04-05 04:35:49 +03:00
Tom Yan 14b429de8d ao_opensles: bump device buffer size to 250ms
Although half (non-fast track on sink rate) or one-third (non-fast track not on sink rate) of the buffer size of the created AudioTrack instance as the SL Enqueue buffer size is basically enough for dropout-free playback, only using the full size can avoid stutter upon (re)start of playback.

Here are the various buffer sizes on different track/sink rate when on Bluetooth audio on Android O:

aptX @ 48kHz:
Sink rate: 48000 Hz
44100 Hz: 10632 frames (241.09 ms)
48000 Hz: 11544 frames (240.50 ms)
88200 Hz: 21216 frames (240.54 ms)
96000 Hz: 23088 frames (240.50 ms)
176400 Hz: 42384 frames (240.27 ms)
192000 Hz: 46128 frames (240.25 ms)

SBC/AAC/aptX @ 44.1kHz:
Sink rate: 44100 Hz
44100 Hz: 10776 frames (244.35 ms)
48000 Hz: 11748 frames (244.75 ms)
88200 Hz: 21552 frames (244.35 ms)
96000 Hz: 23448 frames (244.25 ms)
176400 Hz: 43056 frames (244.08 ms)
192000 Hz: 46848 frames (244.00 ms)

The above results were produced with the following code:

import android.media.AudioAttributes;
import android.media.AudioFormat;
import android.media.AudioTrack;

class AudioInfo {
    public static void main(String[] args) {
	int nosr = AudioTrack.getNativeOutputSampleRate(3);
	System.out.printf("Sink rate: %d Hz\n", nosr);

	int[] rates = {44100,48000,88200,96000,176400,192000};
	for (int rate: rates) {
	    AudioAttributes aa = new AudioAttributes.Builder().setFlags(256).build();
	    AudioFormat af = new AudioFormat.Builder().setSampleRate(rate).build();
	    AudioTrack at = new AudioTrack(aa, af, 4, 1, 0);
	    int sr = at.getSampleRate();
	    int bs = at.getBufferSizeInFrames();
	    float ms = bs * (float) 1000 / sr;
	    at.release();
	    System.out.printf("%d Hz: %d frames (%.2f ms)\n", sr, bs, ms);
	}
    }
}

Therefore bumping the device buffer size to 250ms.
2018-04-05 04:35:49 +03:00
Tom Yan 5a8c48fde2 ao_opensles: do one buffer only
Doing two buffers causes stutters upon (re)start of playback on Android O for all kinds of sinks.
2018-04-05 04:35:49 +03:00
Jan Ekström 59a04562b1 ao_opensles: re-flow interface/configuration retrieval
This manages to make the code more readable. Thanks to
MakeGho@IRCnet for the snippet on which this was based.
2018-03-24 03:43:57 +02:00
Aman Gupta aaa076b631 ao_opensles: fix audio sync using device latency extension 2018-03-23 01:00:01 +02:00
tomty89 013a8f75f3 ao_opensles: bump device buffer size to 200ms
While the soft buffer size is already by default 200ms, it is not enough to guarantee dropout-free playback on Bluetooth audio. Bumping the device buffer size to the same value seems to suffice.
2018-03-07 01:40:05 +02:00
tomty89 0a9ab1b076 ao_opensles: remove set_play_state()
Set play state to playing in init() instead. We no longer touch the play state afterwards.
2018-03-07 01:40:05 +02:00
tomty89 ba68e570de ao_opensles: clear buffer queue in reset()
Avoid resume() from causing SL_RESULT_BUFFER_INSUFFICIENT ("Failed to Enqueue: 7" when seek or resume from pause).
2018-03-07 01:40:05 +02:00
wm4 d36ff64b29 audio: fix annyoing af_get_best_sample_formats() definition
The af_get_best_sample_formats() function had an argument of
int[AF_FORMAT_COUNT], which is slightly incorrect, because it's 0
terminated and should in theory have AF_FORMAT_COUNT+1 entries. It won't
actually write this many formats (since some formats are fundamentally
incompatible), but it still feels annoying and incorrect. So fix it, and
require that callers pass an AF_FORMAT_COUNT+1 array.

Note that the array size has no meaning in C function arguments (just
another issue with C static arrays being weird and stupid), so get rid
of it completely.

Not changing the af_lavcac3enc use, since that is rewritten in another
branch anyway.
2018-01-25 20:18:32 -08:00
wm4 1a2319f3e4 options: remove deprecated sub-option handling for --vo and --ao
Long planned. Leads to some sanity.

There still are some rather gross things. Especially g_groups is ugly,
and a hack that can hopefully be removed. (There is a plan for it, but
whether it's implemented depends on how much energy is left.)
2016-11-25 21:17:25 +01:00
wm4 69283bc0f8 options: deprecate suboptions for the remaining AO/VOs 2016-09-05 21:26:39 +02:00
Josh de Kock 4aa017e301 ao_opensles: remove 32bit audio
It's unsupported by android, and can cause problems when trying to play 32bit audio. Removing 32bit fixes it by forcing 16 bit or 8 bit audio.
2016-05-22 14:31:37 +02:00
Ilya Zhuravlev 72aea5a12b ao: initial OpenSL ES support
OpenSL ES is used on Android. At the moment only stereo output is
supported. Two options are supported: 'frames-per-buffer' and
'sample-rate'. To get better latency the user of libmpv should pass
values obtained from AudioManager.getProperty(PROPERTY_OUTPUT_FRAMES_PER_BUFFER)
and AudioManager.getProperty(PROPERTY_OUTPUT_SAMPLE_RATE).
2016-02-27 00:00:36 +01:00