diff options
author | Moonchild <moonchild@palemoon.org> | 2019-11-03 11:20:08 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-11-03 11:20:08 +0100 |
commit | b7c6c779ee1d0100842822a1a9c63cd97d27644b (patch) | |
tree | cd6504982a432efda7dcd0b5208efde4c04847b1 /media/libcubeb/src/android/cubeb_media_library.h | |
parent | 21b3f6247403c06f85e1f45d219f87549862198f (diff) | |
parent | 22b35fa8e923d52a3fa785993c28c3e63cd1ee1e (diff) | |
download | UXP-b7c6c779ee1d0100842822a1a9c63cd97d27644b.tar UXP-b7c6c779ee1d0100842822a1a9c63cd97d27644b.tar.gz UXP-b7c6c779ee1d0100842822a1a9c63cd97d27644b.tar.lz UXP-b7c6c779ee1d0100842822a1a9c63cd97d27644b.tar.xz UXP-b7c6c779ee1d0100842822a1a9c63cd97d27644b.zip |
Merge pull request #1270 from g4jc/libcubeb
Update libcubeb
Diffstat (limited to 'media/libcubeb/src/android/cubeb_media_library.h')
-rw-r--r-- | media/libcubeb/src/android/cubeb_media_library.h | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/media/libcubeb/src/android/cubeb_media_library.h b/media/libcubeb/src/android/cubeb_media_library.h new file mode 100644 index 000000000..ab21b779d --- /dev/null +++ b/media/libcubeb/src/android/cubeb_media_library.h @@ -0,0 +1,62 @@ +#ifndef _CUBEB_MEDIA_LIBRARY_H_ +#define _CUBEB_MEDIA_LIBRARY_H_ + +struct media_lib { + void * libmedia; + int32_t (* get_output_latency)(uint32_t * latency, int stream_type); +}; + +typedef struct media_lib media_lib; + +media_lib * +cubeb_load_media_library() +{ + media_lib ml = {0}; + ml.libmedia = dlopen("libmedia.so", RTLD_LAZY); + if (!ml.libmedia) { + return NULL; + } + + // Get the latency, in ms, from AudioFlinger. First, try the most recent signature. + // status_t AudioSystem::getOutputLatency(uint32_t* latency, audio_stream_type_t streamType) + ml.get_output_latency = + dlsym(ml.libmedia, "_ZN7android11AudioSystem16getOutputLatencyEPj19audio_stream_type_t"); + if (!ml.get_output_latency) { + // In case of failure, try the signature from legacy version. + // status_t AudioSystem::getOutputLatency(uint32_t* latency, int streamType) + ml.get_output_latency = + dlsym(ml.libmedia, "_ZN7android11AudioSystem16getOutputLatencyEPji"); + if (!ml.get_output_latency) { + return NULL; + } + } + + media_lib * rv = NULL; + rv = calloc(1, sizeof(media_lib)); + assert(rv); + *rv = ml; + return rv; +} + +void +cubeb_close_media_library(media_lib * ml) +{ + dlclose(ml->libmedia); + ml->libmedia = NULL; + ml->get_output_latency = NULL; + free(ml); +} + +uint32_t +cubeb_get_output_latency_from_media_library(media_lib * ml) +{ + uint32_t latency = 0; + const int audio_stream_type_music = 3; + int32_t r = ml->get_output_latency(&latency, audio_stream_type_music); + if (r) { + return 0; + } + return latency; +} + +#endif // _CUBEB_MEDIA_LIBRARY_H_ |