Commit b8bf1d43 authored by Simon Morlat's avatar Simon Morlat
Browse files

fix android sound system on motoG

parent 6469e3d2
......@@ -127,7 +127,7 @@ void AudioRecord::readBuffer(const void *p_info, Buffer *buffer){
}
bool AudioRecord::isRefCounted()const{
return mImpl->mApiVersion>=19;
return mImpl->mUseRefcount;
}
void AudioRecord::destroy()const{
......@@ -172,16 +172,16 @@ bool AudioRecordImpl::init(Library *lib){
}
sImpl=impl;
if (impl->mApiVersion>=19){
ms_message("AudioRecord needs refcounting.");
/*
AudioRecord *test=new AudioRecord();
ptrdiff_t offset=findRefbaseOffset(test->mThis,sObjSize);
if (offset==-1){
offset=0;
//dumpMemory(test->getRealThis(),AudioRecordImpl::sObjSize);
if (findRefbaseOffset(test->getRealThis(),AudioRecordImpl::sObjSize)>(ptrdiff_t)sizeof(void*)){
ms_message("AudioRecord does not need refcounting despite it is 4.4");
impl->mUseRefcount=false;
}else{
ms_message("AudioRecord needs refcounting.");
impl->mUseRefcount=true;
}
impl->mRefBaseOffset=offset;
ms_message("AudioRecord's offset for RefBase is %i",offset);
*/
sp<AudioRecord> st(test);
}
return true;
}
......@@ -201,6 +201,7 @@ AudioRecordImpl::AudioRecordImpl(Library *lib) :
mGetSessionId(lib,"_ZNK7android11AudioRecord12getSessionIdEv")
{
mApiVersion=0;
mUseRefcount=false;
mRefBaseOffset=0;
if (!mCtor.isFound()){
// Try some Android 2.2 symbols if not found
......
......@@ -404,6 +404,7 @@ public:
//Function1<audio_io_handle_t,void*> mGetInput;
ptrdiff_t mRefBaseOffset;
int mApiVersion;
bool mUseRefcount;
static const size_t sObjSize=512;
private:
AudioRecordImpl(Library *lib);
......
......@@ -221,6 +221,10 @@ void RefBase::decStrong(const void* id) const{
}
}
int32_t RefBase::getStrongCount() const{
return mImpl->mGetStrongCount.invoke(getRealThis());
}
ptrdiff_t findRefbaseOffset(void *obj, size_t size){
uint8_t *base_vptr=(uint8_t*)*(void **)obj;
const long vptrMemRange=0x1000000;
......@@ -231,7 +235,7 @@ ptrdiff_t findRefbaseOffset(void *obj, size_t size){
ms_warning("findRefbaseOffset(): no base vptr");
}
ms_message("base_vptr is %p for obj %p",base_vptr, obj);
for (i=0;i<size;i+=sizeof(void*)){
for (i=(size/sizeof(void*))*sizeof(void*);i>0;i-=sizeof(void*)){
uint8_t *ptr= ((uint8_t*)obj) + i;
uint8_t *candidate=(uint8_t*)*(void**)ptr;
if (i!=0 && labs((ptrdiff_t)(candidate-base_vptr))<vptrMemRange){
......
......@@ -148,7 +148,7 @@ namespace fake_android{
}
bool AudioTrack::isRefCounted()const{
return mImpl->mSdkVersion >= 19;
return mImpl->mUseRefCount;
}
void AudioTrack::destroy()const{
......@@ -173,6 +173,7 @@ namespace fake_android{
{
mRefBaseOffset=0;
mSdkVersion=0;
mUseRefCount=false;
// Try some Android 2.2 symbols if not found
if (!mCtor.isFound()) {
mCtor.load(lib,"_ZN7android10AudioTrackC1EijiiijPFviPvS1_ES1_i");
......@@ -238,16 +239,18 @@ namespace fake_android{
if (!fail){
sImpl=impl;
if (impl->mSdkVersion>=19){
ms_message("AudioTrack needs refcounting.");
/*
impl->mUseRefCount=true;
AudioTrack *test=new AudioTrack();
ptrdiff_t offset=findRefbaseOffset(test->mThis,sObjSize);
if (offset==-1){
offset=0;
//dumpMemory(test->getRealThis(),AudioTrackImpl::sObjSize);
ptrdiff_t offset=findRefbaseOffset(test->getRealThis(),AudioTrackImpl::sObjSize);
if (offset>(ptrdiff_t)sizeof(void*)){
ms_message("AudioTrack uses virtual RefBase despite it is 4.4");
impl->mRefBaseOffset=offset;
}else{
ms_message("AudioTrack needs refcounting.");
}
impl->mRefBaseOffset=offset;
ms_message("Found offset [%i] for RefBase in AudioTrack",offset);
*/
sp<AudioTrack> st(test);
}
return true;
}else{
......@@ -257,7 +260,4 @@ namespace fake_android{
}
AudioTrackImpl * AudioTrackImpl::sImpl=NULL;
}//end of namespace
......@@ -473,6 +473,7 @@ public:
Function2<status_t,void*,uint32_t*> mGetPosition;
int mSdkVersion;
ptrdiff_t mRefBaseOffset;
bool mUseRefCount;
static const int sObjSize=512;
private:
AudioTrackImpl(Library *lib);
......
......@@ -248,11 +248,11 @@ static void android_snd_card_detect(MSSndCardManager *m){
if (libmedia && libutils){
/*perform initializations in order rather than in a if statement so that all missing symbols are shown in logs*/
string8_loaded=String8Impl::init(libutils);
refbase_loaded=RefBaseImpl::init(libutils);
audio_record_loaded=AudioRecordImpl::init(libmedia);
audio_track_loaded=AudioTrackImpl::init(libmedia);
audio_system_loaded=AudioSystemImpl::init(libmedia);
string8_loaded=String8Impl::init(libutils);
refbase_loaded=RefBaseImpl::init(libutils);
}
if (audio_record_loaded && audio_track_loaded && audio_system_loaded && string8_loaded && refbase_loaded){
ms_message("Native android sound support available.");
......
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