Commit 63aef125 authored by Ghislain MARY's avatar Ghislain MARY

Fix channel mask on tablets with 3.x versions of Android.

Get the android SDK version from JNI instead of guessing it from the symbols found in libmedia.so.
parent 13d3df5a
......@@ -38,18 +38,6 @@ namespace fake_android{
int sessionId ){
mThis=new uint8_t[512];
mImpl=AudioTrackImpl::get();
/* HACK for Froyo and Gingerbread */
/* This is needed because the enum values have changed between Gingerbread and ICS */
if (mImpl->mBeforeICS) {
ms_message("Android version older than ICS, apply audio channel hack for AudioTrack");
if ((channelMask & AUDIO_CHANNEL_OUT_MONO) == AUDIO_CHANNEL_OUT_MONO) {
channelMask = 0x4;
} else if ((channelMask & AUDIO_CHANNEL_OUT_STEREO) == AUDIO_CHANNEL_OUT_STEREO) {
channelMask = 0x4|0x8;
}
}
mImpl->mCtor.invoke(mThis,streamType,sampleRate,format,channelMask,frameCount,flags,cbf,user,notificationFrames,sessionId);
}
......@@ -130,8 +118,7 @@ namespace fake_android{
mFlush(lib,"_ZN7android10AudioTrack5flushEv"),
mGetMinFrameCount(lib,"_ZN7android10AudioTrack16getMinFrameCountEPiij"),
mLatency(lib,"_ZNK7android10AudioTrack7latencyEv"),
mGetPosition(lib,"_ZN7android10AudioTrack11getPositionEPj"),
mBeforeICS(false)
mGetPosition(lib,"_ZN7android10AudioTrack11getPositionEPj")
{
// Try some Android 2.2 symbols if not found
if (!mCtor.isFound()) {
......@@ -142,12 +129,6 @@ namespace fake_android{
if (!mGetMinFrameCount.isFound()) {
mGetMinFrameCount.load(lib,"_ZN7android10AudioTrack16getMinFrameCountEPi19audio_stream_type_tj");
}
// Dummy symbol loading to detect the Android version, this function did not exist before ICS,
Function0<uint32_t> getFrameRate(lib,"_ZN7android10AudioTrack9setLoop_lEjji");
if (!getFrameRate.isFound()) {
mBeforeICS = true;
}
}
bool AudioTrackImpl::init(Library *lib){
......@@ -171,4 +152,4 @@ namespace fake_android{
}//end of namespace
\ No newline at end of file
}//end of namespace
......@@ -431,7 +431,6 @@ public:
Function3<status_t,int*,audio_stream_type_t,int> mGetMinFrameCount;
Function1<uint32_t,void*> mLatency;
Function2<status_t,void*,uint32_t*> mGetPosition;
bool mBeforeICS;
private:
AudioTrackImpl(Library *lib);
static AudioTrackImpl *sImpl;
......
......@@ -219,6 +219,17 @@ static void android_snd_card_detect(MSSndCardManager *m){
}
static int sdk_version = 0;
static void android_native_snd_card_init(MSSndCard *card) {
/* Get Android SDK version. */
JNIEnv *jni_env = ms_get_jni_env();
jclass version_class = jni_env->FindClass("android/os/Build$VERSION");
jfieldID fid = jni_env->GetStaticFieldID(version_class, "SDK_INT", "I");
sdk_version = jni_env->GetStaticIntField(version_class, fid);
ms_message("SDK version [%i] detected", sdk_version);
}
static void android_native_snd_card_uninit(MSSndCard *card){
delete static_cast<AndroidNativeSndCardData*>(card->data);
......@@ -227,7 +238,7 @@ static void android_native_snd_card_uninit(MSSndCard *card){
MSSndCardDesc android_native_snd_card_desc={
"libmedia",
android_snd_card_detect,
NULL,
android_native_snd_card_init,
NULL,
NULL,
NULL,
......@@ -552,6 +563,20 @@ static void android_snd_write_cb(int event, void *user, void * p_info){
}else ms_error("Untracked event %i",event);
}
static int channel_mask_for_audio_track(int nchannels) {
int channel_mask;
channel_mask = audio_channel_out_mask_from_count(nchannels);
if (sdk_version < 14) {
ms_message("Android version older than ICS, apply audio channel hack for AudioTrack");
if ((channel_mask & AUDIO_CHANNEL_OUT_MONO) == AUDIO_CHANNEL_OUT_MONO) {
channel_mask = 0x4;
} else if ((channel_mask & AUDIO_CHANNEL_OUT_STEREO) == AUDIO_CHANNEL_OUT_STEREO) {
channel_mask = 0x4|0x8;
}
}
return channel_mask;
}
static void android_snd_write_preprocess(MSFilter *obj){
AndroidSndWriteData *ad=(AndroidSndWriteData*)obj->data;
int play_buf_size;
......@@ -571,7 +596,7 @@ static void android_snd_write_preprocess(MSFilter *obj){
ad->tr=new AudioTrack(ad->stype,
ad->rate,
AUDIO_FORMAT_PCM_16_BIT,
audio_channel_out_mask_from_count(ad->nchannels),
channel_mask_for_audio_track(ad->nchannels),
play_buf_size,
AUDIO_OUTPUT_FLAG_NONE, // AUDIO_OUTPUT_FLAG_NONE,
android_snd_write_cb, ad,notify_frames,0);
......
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