Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support f32 when using the OpenSLES backend and compiling against older Android SDK #758

Merged
merged 9 commits into from
Aug 25, 2023
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ endif()
set(CMAKE_C_STANDARD 99)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

if(USE_SANITIZERS)
if(NOT COMMAND add_sanitizers)
Expand Down Expand Up @@ -277,7 +278,7 @@ endif()
check_include_files(SLES/OpenSLES.h USE_OPENSL)
if(USE_OPENSL)
target_sources(cubeb PRIVATE
src/cubeb_opensl.c
src/cubeb_opensl.cpp
src/cubeb-jni.cpp)
target_compile_definitions(cubeb PRIVATE USE_OPENSL)
target_link_libraries(cubeb PRIVATE OpenSLES)
Expand Down
5 changes: 4 additions & 1 deletion src/android/cubeb-output-latency.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ output_latency_function *
cubeb_output_latency_load_method(int version)
{
output_latency_function * ol = NULL;
ol = calloc(1, sizeof(output_latency_function));
ol = (output_latency_function *)calloc(1, sizeof(output_latency_function));

ol->version = version;

Expand Down Expand Up @@ -61,6 +61,8 @@ cubeb_output_latency_unload_method(output_latency_function * ol)
free(ol);
}

extern "C" {

uint32_t
cubeb_get_output_latency(output_latency_function * ol)
{
Expand All @@ -72,5 +74,6 @@ cubeb_get_output_latency(output_latency_function * ol)

return cubeb_get_output_latency_from_media_library(ol->from_lib);
}
}

#endif // _CUBEB_OUTPUT_LATENCY_H_
24 changes: 15 additions & 9 deletions src/android/cubeb_media_library.h
Original file line number Diff line number Diff line change
@@ -1,40 +1,46 @@
#include <cassert>
#include <cstdint>
#include <dlfcn.h>
#include <stdlib.h>
#ifndef _CUBEB_MEDIA_LIBRARY_H_
#define _CUBEB_MEDIA_LIBRARY_H_

typedef int32_t (*get_output_latency_ptr)(uint32_t * latency, int stream_type);

struct media_lib {
void * libmedia;
int32_t (*get_output_latency)(uint32_t * latency, int stream_type);
get_output_latency_ptr get_output_latency;
};

typedef struct media_lib media_lib;

media_lib *
cubeb_load_media_library()
{
media_lib ml = {0};
media_lib ml = {};
ml.libmedia = dlopen("libmedia.so", RTLD_LAZY);
if (!ml.libmedia) {
return NULL;
return nullptr;
}

// 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.get_output_latency = (get_output_latency_ptr)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");
ml.get_output_latency = (get_output_latency_ptr)dlsym(
ml.libmedia, "_ZN7android11AudioSystem16getOutputLatencyEPji");
if (!ml.get_output_latency) {
return NULL;
return nullptr;
}
}

media_lib * rv = NULL;
rv = calloc(1, sizeof(media_lib));
media_lib * rv = nullptr;
rv = (media_lib *)calloc(1, sizeof(media_lib));
assert(rv);
*rv = ml;
return rv;
Expand Down
8 changes: 8 additions & 0 deletions src/cubeb-jni.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,19 @@

typedef struct cubeb_jni cubeb_jni;

#ifdef __cplusplus
extern "C" {
#endif

cubeb_jni *
cubeb_jni_init();
int
cubeb_get_output_latency_from_jni(cubeb_jni * cubeb_jni_ptr);
void
cubeb_jni_destroy(cubeb_jni * cubeb_jni_ptr);

#ifdef __cplusplus
};
#endif

#endif // _CUBEB_JNI_H_
Loading