Commit 6a70456f authored by Sylvain Berfini's avatar Sylvain Berfini
Browse files

Using MSList instead of array at runtime to lookup sound device description +...

Using MSList instead of array at runtime to lookup sound device description + added method to manually add a sound device description
parent 7c585a7f
......@@ -279,6 +279,11 @@ MS2_PUBLIC void ms_set_cpu_count(unsigned int c);
MS2_PUBLIC unsigned int ms_get_cpu_count();
/**
* Adds a new entry in the SoundDeviceDescription table
*/
MS2_PUBLIC void ms_sound_device_description_add(const char *manufacturer, const char *model, const char *platform, unsigned int flags, int delay, int recommended_rate);
/** @} */
#ifdef __cplusplus
......
......@@ -23,16 +23,28 @@ import android.content.Context;
import android.media.AudioManager;
import android.os.Build;
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
public class MediastreamerAndroidContext {
private native void setDeviceFavoriteSampleRate(int samplerate);
private native void setDeviceFavoriteBufferSize(int bufferSize);
private native void addSoundDeviceDescription(String manufacturer, String model, String platform, int flags, int delay, int recommended_rate);
private MediastreamerAndroidContext() {
}
private static MediastreamerAndroidContext instance;
private static MediastreamerAndroidContext getInstance() {
if (instance == null)
instance = new MediastreamerAndroidContext();
return instance;
}
public static void addSoundDeviceDesc(String manufacturer, String model, String platform, int flags, int delay, int recommended_rate) {
getInstance().addSoundDeviceDescription(manufacturer, model, platform, flags, delay, recommended_rate);
}
@TargetApi(Build.VERSION_CODES.KITKAT)
public static void setContext(Object c) {
if (c == null)
return;
......@@ -40,18 +52,18 @@ public class MediastreamerAndroidContext {
Context context = (Context)c;
int bufferSize = 64;
int sampleRate = 44100;
MediastreamerAndroidContext mac = new MediastreamerAndroidContext();
MediastreamerAndroidContext mac = getInstance();
// When using the OpenSLES sound card, the system is capable of giving us the best values to use for the buffer size and the sample rate
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
{
AudioManager audiomanager = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
String bufferProperty = audiomanager.getProperty(AudioManager.PROPERTY_OUTPUT_FRAMES_PER_BUFFER);
bufferSize = parseInt(bufferProperty, bufferSize);
String sampleRateProperty = audiomanager.getProperty(AudioManager.PROPERTY_OUTPUT_SAMPLE_RATE);
sampleRate = parseInt(sampleRateProperty, sampleRate);
Log.i("Setting buffer size to " + bufferSize + " and sample rate to " + sampleRate + " for OpenSLES MS sound card.");
mac.setDeviceFavoriteSampleRate(sampleRate);
mac.setDeviceFavoriteBufferSize(bufferSize);
AudioManager audiomanager = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
String bufferProperty = audiomanager.getProperty(AudioManager.PROPERTY_OUTPUT_FRAMES_PER_BUFFER);
bufferSize = parseInt(bufferProperty, bufferSize);
String sampleRateProperty = audiomanager.getProperty(AudioManager.PROPERTY_OUTPUT_SAMPLE_RATE);
sampleRate = parseInt(sampleRateProperty, sampleRate);
Log.i("Setting buffer size to " + bufferSize + " and sample rate to " + sampleRate + " for OpenSLES MS sound card.");
mac.setDeviceFavoriteSampleRate(sampleRate);
mac.setDeviceFavoriteBufferSize(bufferSize);
} else {
Log.i("Android < 4.4 detected, android context not used.");
}
......
......@@ -115,6 +115,18 @@ static SoundDeviceDescription devices[]={
static SoundDeviceDescription undefined={"Generic", "Generic", "Generic", 0, 250, 0};
JNIEXPORT void JNICALL Java_org_linphone_mediastream_MediastreamerAndroidContext_addSoundDeviceDescription(JNIEnv* env, jobject thiz, jstring jmanufacturer, jstring jmodel, jstring jplatform, jint flags, jint delay, jint rate) {
const char *manufacturer = jmanufacturer ? (*env)->GetStringUTFChars(env, jmanufacturer, NULL) : NULL;
const char *model = jmodel ? (*env)->GetStringUTFChars(env, jmodel, NULL) : NULL;
const char *platform = jplatform ? (*env)->GetStringUTFChars(env, jplatform, NULL) : NULL;
ms_sound_device_description_add(manufacturer, model, platform, flags, delay, rate);
(*env)->ReleaseStringUTFChars(env, jmanufacturer, manufacturer);
(*env)->ReleaseStringUTFChars(env, jmodel, model);
(*env)->ReleaseStringUTFChars(env, jplatform, platform);
}
#else
static SoundDeviceDescription devices[]={
......@@ -125,10 +137,21 @@ static SoundDeviceDescription undefined={"Generic", "Generic", "Generic", 0, 0,
#endif
static SoundDeviceDescription *lookup_by_model(const char *manufacturer, const char* model){
SoundDeviceDescription *d=&devices[0];
while (d->manufacturer!=NULL) {
if (strcasecmp(d->manufacturer,manufacturer)==0 && strcmp(d->model,model)==0){
static MSList *sound_device_descriptions;
static SoundDeviceDescription *lookup_by_model(const char *manufacturer, const char* model) {
MSList *list = sound_device_descriptions;
SoundDeviceDescription *d;
for(; list != NULL; list = list->next) {
d = (SoundDeviceDescription*) list->data;
if (strcasecmp(d->manufacturer, manufacturer) == 0 && strcmp(d->model, model) == 0) {
return d;
}
}
d = &devices[0];
while (d->manufacturer != NULL) {
if (strcasecmp(d->manufacturer, manufacturer) == 0 && strcmp(d->model, model) == 0) {
return d;
}
d++;
......@@ -136,10 +159,19 @@ static SoundDeviceDescription *lookup_by_model(const char *manufacturer, const c
return NULL;
}
static SoundDeviceDescription *lookup_by_platform(const char *platform){
SoundDeviceDescription *d=&devices[0];
while (d->manufacturer!=NULL){
if (strcmp(d->platform,platform)==0){
static SoundDeviceDescription *lookup_by_platform(const char *platform) {
MSList *list = sound_device_descriptions;
SoundDeviceDescription *d;
for(; list != NULL; list = list->next) {
d = (SoundDeviceDescription*) list->data;
if (strcmp(d->platform, platform) == 0) {
return d;
}
}
d = &devices[0];
while (d->manufacturer != NULL) {
if (strcmp(d->platform, platform) == 0) {
return d;
}
d++;
......@@ -147,6 +179,18 @@ static SoundDeviceDescription *lookup_by_platform(const char *platform){
return NULL;
}
void ms_sound_device_description_add(const char *manufacturer, const char *model, const char *platform, unsigned int flags, int delay, int recommended_rate) {
SoundDeviceDescription *new_sound_device_description = ms_new(SoundDeviceDescription, 1);
new_sound_device_description->manufacturer = ms_strdup(manufacturer);
new_sound_device_description->model = ms_strdup(model);
new_sound_device_description->platform = ms_strdup(platform);
new_sound_device_description->flags = flags;
new_sound_device_description->delay = delay;
new_sound_device_description->recommended_rate = recommended_rate;
sound_device_descriptions = ms_list_append(sound_device_descriptions, new_sound_device_description);
}
#ifndef PROV_VALUE_MAX
#define PROP_VALUE_MAX 256
#endif
......
......@@ -47,7 +47,6 @@ extern "C"{
/*obtain information regarding sound system of current device*/
SoundDeviceDescription * sound_device_description_get(void);
#ifdef __cplusplus
}
#endif
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment