diff options
author | Paul Adenot <[email protected]> | 2020-10-29 15:28:22 +0100 |
---|---|---|
committer | Paul Adenot <[email protected]> | 2020-11-02 15:37:29 +0000 |
commit | 3fe4d25c047134e395d016d35826b667e5200d30 (patch) | |
tree | 2e3b132039d984bffc3e4e4a6c0ec677643157a4 | |
parent | e479f4268d63a183463c438feba1645a38e46049 (diff) | |
download | cubeb-3fe4d25c047134e395d016d35826b667e5200d30.tar.gz cubeb-3fe4d25c047134e395d016d35826b667e5200d30.zip |
Make the low-latency/powersave policy choice dynamic, based on latency.
This adds a new file that shares the value between the two non-obsolete
android backend.
-rw-r--r-- | src/cubeb_aaudio.cpp | 15 | ||||
-rw-r--r-- | src/cubeb_android.h | 17 | ||||
-rw-r--r-- | src/cubeb_opensl.c | 6 |
3 files changed, 26 insertions, 12 deletions
diff --git a/src/cubeb_aaudio.cpp b/src/cubeb_aaudio.cpp index 27a6752..ca1da93 100644 --- a/src/cubeb_aaudio.cpp +++ b/src/cubeb_aaudio.cpp @@ -20,6 +20,7 @@ #include "cubeb-internal.h" #include "cubeb_resampler.h" #include "cubeb_log.h" +#include "cubeb_android.h" #ifdef DISABLE_LIBAAUDIO_DLOPEN #define WRAP(x) x @@ -821,13 +822,13 @@ aaudio_stream_init_impl( WRAP(AAudioStreamBuilder_setSharingMode)(sb, AAUDIO_SHARING_MODE_EXCLUSIVE); #endif -#ifdef CUBEB_AAUDIO_LOW_LATENCY - LOG("AAudio setting low latency mode for stream"); - WRAP(AAudioStreamBuilder_setPerformanceMode)(sb, AAUDIO_PERFORMANCE_MODE_LOW_LATENCY); -#elif defined(CUBEB_AAUDIO_POWER_SAVING) - LOG("AAudio setting power saving mode for stream"); - WRAP(AAudioStreamBuilder_setPerformanceMode)(sb, AAUDIO_PERFORMANCE_MODE_POWER_SAVING); -#endif + if (latency_frames <= POWERSAVE_LATENCY_FRAMES_THRESHOLD) { + LOG("AAudio setting low latency mode for stream"); + WRAP(AAudioStreamBuilder_setPerformanceMode)(sb, AAUDIO_PERFORMANCE_MODE_LOW_LATENCY); + } else { + LOG("AAudio setting power saving mode for stream"); + WRAP(AAudioStreamBuilder_setPerformanceMode)(sb, AAUDIO_PERFORMANCE_MODE_POWER_SAVING); + } unsigned frame_size; diff --git a/src/cubeb_android.h b/src/cubeb_android.h new file mode 100644 index 0000000..c21a941 --- /dev/null +++ b/src/cubeb_android.h @@ -0,0 +1,17 @@ +#ifndef CUBEB_ANDROID_H +#define CUBEB_ANDROID_H + +#ifdef __cplusplus +extern "C" { +#endif +// If the latency requested is above this threshold, this stream is considered +// intended for playback (vs. real-time). Tell Android it should favor saving +// power over performance or latency. +// This is around 100ms at 44100 or 48000 +const uint16_t POWERSAVE_LATENCY_FRAMES_THRESHOLD = 4000; + +#ifdef __cplusplus +}; +#endif + +#endif // CUBEB_ANDROID_H diff --git a/src/cubeb_opensl.c b/src/cubeb_opensl.c index f34ab7a..8e6dfb1 100644 --- a/src/cubeb_opensl.c +++ b/src/cubeb_opensl.c @@ -27,6 +27,7 @@ #include "cubeb-sles.h" #include "cubeb_array_queue.h" #include "android/cubeb-output-latency.h" +#include "cubeb_android.h" #if defined(__ANDROID__) #ifdef LOG @@ -65,11 +66,6 @@ #define DEFAULT_SAMPLE_RATE 48000 #define DEFAULT_NUM_OF_FRAMES 480 -// If the latency requested is above this threshold, this stream is considered -// intended for playback (vs. real-time). Tell Android it should favor saving -// power over performance or latency. -// This is around 100ms at 44100 or 48000 -#define POWERSAVE_LATENCY_FRAMES_THRESHOLD 4000 static struct cubeb_ops const opensl_ops; |