Commit bd15866c authored by Ghislain MARY's avatar Ghislain MARY

Fix the getMinFrameCount problem.

On some devices the AudioTrack::getMinFrameCount() implementation is a
dummy one that does nothing. If we detect that this is the case, we now
perform the calculation as it is supposed to be done.
parent 913ea76f
...@@ -103,11 +103,6 @@ AudioSystemImpl::AudioSystemImpl(Library *lib) : ...@@ -103,11 +103,6 @@ AudioSystemImpl::AudioSystemImpl(Library *lib) :
bool AudioSystemImpl::init(Library *lib){ bool AudioSystemImpl::init(Library *lib){
AudioSystemImpl *impl=new AudioSystemImpl(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->mGetOutputSamplingRate.isFound()) goto fail;
if (!impl->mGetOutputFrameCount.isFound()) goto fail; if (!impl->mGetOutputFrameCount.isFound()) goto fail;
...@@ -117,25 +112,6 @@ bool AudioSystemImpl::init(Library *lib){ ...@@ -117,25 +112,6 @@ bool AudioSystemImpl::init(Library *lib){
if (!impl->mSetForceUse.isFound()) goto fail; if (!impl->mSetForceUse.isFound()) goto fail;
//if (!impl->mGetInput.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; sImpl=impl;
return true; return true;
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "mediastreamer2/mscommon.h" #include "mediastreamer2/mscommon.h"
#include "AudioTrack.h" #include "AudioTrack.h"
#include "AudioSystem.h"
namespace fake_android{ namespace fake_android{
...@@ -80,8 +81,28 @@ namespace fake_android{ ...@@ -80,8 +81,28 @@ namespace fake_android{
status_t AudioTrack::getMinFrameCount(int* frameCount, status_t AudioTrack::getMinFrameCount(int* frameCount,
audio_stream_type_t streamType, audio_stream_type_t streamType,
uint32_t sampleRate){ uint32_t sampleRate){
// Initialize frameCount to a magic value
*frameCount = 54321;
if (AudioTrackImpl::get()->mGetMinFrameCount.isFound()){ if (AudioTrackImpl::get()->mGetMinFrameCount.isFound()){
return AudioTrackImpl::get()->mGetMinFrameCount.invoke(frameCount,streamType,sampleRate); status_t ret = AudioTrackImpl::get()->mGetMinFrameCount.invoke(frameCount,streamType,sampleRate);
if ((ret == 0) && (*frameCount = 54321)) {
// If no error and the magic value has not been erased then the getMinFrameCount implementation
// is a dummy one. So perform the calculation manually as it is supposed to be implemented...
int afSampleRate;
if (AudioSystem::getOutputSamplingRate(&afSampleRate, streamType) != 0) return -1;
int afFrameCount;
if (AudioSystem::getOutputFrameCount(&afFrameCount, streamType) != 0) return -1;
uint32_t afLatency;
if (AudioSystem::getOutputLatency(&afLatency, streamType) != 0) return -1;
// Ensure that buffer depth covers at least audio hardware latency
uint32_t minBufCount = afLatency / ((1000 * afFrameCount) / afSampleRate);
if (minBufCount < 2) minBufCount = 2;
*frameCount = (sampleRate == 0) ? afFrameCount * minBufCount :
afFrameCount * minBufCount * sampleRate / afSampleRate;
}
return ret;
}else{ }else{
//this method didn't existed in 2.2 //this method didn't existed in 2.2
//Use hardcoded values instead (1024 frames at 8khz) //Use hardcoded values instead (1024 frames at 8khz)
......
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