| 1 |
#ifndef _CUBEB_OUTPUT_LATENCY_H_ |
| 2 |
#define _CUBEB_OUTPUT_LATENCY_H_ |
| 3 |
|
| 4 |
#include "../cubeb-jni.h" |
| 5 |
#include "cubeb_media_library.h" |
| 6 |
#include <stdbool.h> |
| 7 |
|
| 8 |
struct output_latency_function { |
| 9 |
media_lib * from_lib; |
| 10 |
cubeb_jni * from_jni; |
| 11 |
int version; |
| 12 |
}; |
| 13 |
|
| 14 |
typedef struct output_latency_function output_latency_function; |
| 15 |
|
| 16 |
const int ANDROID_JELLY_BEAN_MR1_4_2 = 17; |
| 17 |
|
| 18 |
output_latency_function * |
| 19 |
cubeb_output_latency_load_method(int version) |
| 20 |
{ |
| 21 |
output_latency_function * ol = NULL; |
| 22 |
ol = (output_latency_function *)calloc(1, sizeof(output_latency_function)); |
| 23 |
|
| 24 |
ol->version = version; |
| 25 |
|
| 26 |
if (ol->version > ANDROID_JELLY_BEAN_MR1_4_2) { |
| 27 |
ol->from_jni = cubeb_jni_init(); |
| 28 |
return ol; |
| 29 |
} |
| 30 |
|
| 31 |
ol->from_lib = cubeb_load_media_library(); |
| 32 |
return ol; |
| 33 |
} |
| 34 |
|
| 35 |
bool |
| 36 |
cubeb_output_latency_method_is_loaded(output_latency_function * ol) |
| 37 |
{ |
| 38 |
assert(ol); |
| 39 |
if (ol->version > ANDROID_JELLY_BEAN_MR1_4_2) { |
| 40 |
return !!ol->from_jni; |
| 41 |
} |
| 42 |
|
| 43 |
return !!ol->from_lib; |
| 44 |
} |
| 45 |
|
| 46 |
void |
| 47 |
cubeb_output_latency_unload_method(output_latency_function * ol) |
| 48 |
{ |
| 49 |
if (!ol) { |
| 50 |
return; |
| 51 |
} |
| 52 |
|
| 53 |
if (ol->version > ANDROID_JELLY_BEAN_MR1_4_2 && ol->from_jni) { |
| 54 |
cubeb_jni_destroy(ol->from_jni); |
| 55 |
} |
| 56 |
|
| 57 |
if (ol->version <= ANDROID_JELLY_BEAN_MR1_4_2 && ol->from_lib) { |
| 58 |
cubeb_close_media_library(ol->from_lib); |
| 59 |
} |
| 60 |
|
| 61 |
free(ol); |
| 62 |
} |
| 63 |
|
| 64 |
extern "C" { |
| 65 |
|
| 66 |
uint32_t |
| 67 |
cubeb_get_output_latency(output_latency_function * ol) |
| 68 |
{ |
| 69 |
assert(cubeb_output_latency_method_is_loaded(ol)); |
| 70 |
|
| 71 |
if (ol->version > ANDROID_JELLY_BEAN_MR1_4_2) { |
| 72 |
return cubeb_get_output_latency_from_jni(ol->from_jni); |
| 73 |
} |
| 74 |
|
| 75 |
return cubeb_get_output_latency_from_media_library(ol->from_lib); |
| 76 |
} |
| 77 |
} |
| 78 |
|
| 79 |
#endif // _CUBEB_OUTPUT_LATENCY_H_ |