Commit 58d0af57 authored by Ghislain MARY's avatar Ghislain MARY

Check AudioSystem characteristics when loading native Android sound module.

It permits to fallback to the old sound module if the characteristics
returned by Android are not correct.
parent b1e1f3fc
......@@ -31,6 +31,22 @@ status_t AudioSystem::getOutputSamplingRate(int *rate, int streamType){
return AudioSystemImpl::get()->mGetOutputSamplingRate.invoke(rate,streamType);
}
status_t AudioSystem::getOutputFrameCount(int *frameCount, audio_stream_type_t streamType) {
return AudioSystemImpl::get()->mGetOutputFrameCount.invoke(frameCount, streamType);
}
status_t AudioSystem::getOutputFrameCount(int *frameCount, int streamType) {
return AudioSystemImpl::get()->mGetOutputFrameCount.invoke(frameCount, streamType);
}
status_t AudioSystem::getOutputLatency(uint32_t *latency, audio_stream_type_t streamType) {
return AudioSystemImpl::get()->mGetOutputLatency.invoke(latency, streamType);
}
status_t AudioSystem::getOutputLatency(uint32_t *latency, int streamType) {
return AudioSystemImpl::get()->mGetOutputLatency.invoke(latency, streamType);
}
status_t AudioSystem::setParameters(audio_io_handle_t ioHandle, const String8& keyValuePairs){
return AudioSystemImpl::get()->mSetParameters.invoke(ioHandle,keyValuePairs);
}
......@@ -48,19 +64,61 @@ audio_io_handle_t AudioSystem::getInput(audio_source_t inputSource,
AudioSystemImpl::AudioSystemImpl(Library *lib) :
// By default, try to load Android 2.3 symbols
mGetOutputSamplingRate(lib,"_ZN7android11AudioSystem21getOutputSamplingRateEPii"),
mGetOutputFrameCount(lib, "_ZN7android11AudioSystem19getOutputFrameCountEPii"),
mGetOutputLatency(lib, "_ZN7android11AudioSystem16getOutputLatencyEPji"),
mSetParameters(lib,"_ZN7android11AudioSystem13setParametersEiRKNS_7String8E"){
//mGetInput(lib,"_ZN7android11AudioSystem8getInputEijjjNS0_18audio_in_acousticsE"){
// Try some Android 4.1 symbols if not found
if (!mGetOutputSamplingRate.isFound()) {
mGetOutputSamplingRate.load(lib, "_ZN7android11AudioSystem21getOutputSamplingRateEPi19audio_stream_type_t");
}
if (!mGetOutputFrameCount.isFound()) {
mGetOutputFrameCount.load(lib, "_ZN7android11AudioSystem19getOutputFrameCountEPi19audio_stream_type_t");
}
if (!mGetOutputLatency.isFound()) {
mGetOutputLatency.load(lib, "_ZN7android11AudioSystem16getOutputLatencyEPj19audio_stream_type_t");
}
}
bool AudioSystemImpl::init(Library *lib){
AudioSystemImpl *impl=new AudioSystemImpl(lib);
int samplingRate;
int frameCount;
uint32_t latency;
status_t err;
bool buggyAndroid = false;
if (!impl->mGetOutputSamplingRate.isFound()) goto fail;
if (!impl->mGetOutputFrameCount.isFound()) goto fail;
if (!impl->mGetOutputLatency.isFound()) goto fail;
if (!impl->mSetParameters.isFound()) goto fail;
//if (!impl->mGetInput.isFound()) goto fail;
err = impl->mGetOutputSamplingRate.invoke(&samplingRate, AUDIO_STREAM_VOICE_CALL);
if (err == 0) err = impl->mGetOutputFrameCount.invoke(&frameCount, AUDIO_STREAM_VOICE_CALL);
if (err == 0) err = impl->mGetOutputLatency.invoke(&latency, AUDIO_STREAM_VOICE_CALL);
if (err == 0) {
ms_message("AUDIO_STREAM_VOICE_CALL characteristics: SamplingRate=%d, FrameCount=%d, Latency=%u", samplingRate, frameCount, latency);
} else {
ms_error("Unable to get AUDIO_STREAM_VOICE_CALL characteristics");
}
if ((frameCount > 8192) || (latency > 200)) buggyAndroid = true;
err = impl->mGetOutputSamplingRate.invoke(&samplingRate, AUDIO_STREAM_DEFAULT);
if (err == 0) err = impl->mGetOutputFrameCount.invoke(&frameCount, AUDIO_STREAM_DEFAULT);
if (err == 0) err = impl->mGetOutputLatency.invoke(&latency, AUDIO_STREAM_DEFAULT);
if (err == 0) {
ms_message("AUDIO_STREAM_DEFAULT characteristics: SamplingRate=%d, FrameCount=%d, Latency=%u", samplingRate, frameCount, latency);
} else {
ms_error("Unable to get AUDIO_STREAM_DEFAULT characteristics");
}
if (buggyAndroid) goto fail;
sImpl=impl;
return true;
fail:
delete impl;
return false;
......
......@@ -107,6 +107,9 @@ public:
// DEPRECATED
static status_t getOutputFrameCount(int* frameCount, int stream = AUDIO_STREAM_DEFAULT);
// DEPRECATED
static status_t getOutputLatency(uint32_t* latency, int stream = AUDIO_STREAM_DEFAULT);
static bool routedToA2dpOutput(audio_stream_type_t streamType);
static status_t getInputBufferSize(uint32_t sampleRate, audio_format_t format, int channelCount,
......@@ -246,6 +249,8 @@ public:
return sImpl;
}
Function2<status_t,int*,int> mGetOutputSamplingRate;
Function2<status_t, int *, int> mGetOutputFrameCount;
Function2<status_t, uint32_t *, int> mGetOutputLatency;
Function2<status_t,audio_io_handle_t,const String8 &> mSetParameters;
//Function6<audio_io_handle_t,audio_source_t,uint32_t,audio_format_t,uint32_t,audio_in_acoustics_t,int> mGetInput;
private:
......
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