Skip to content

Commit ebb82be

Browse files
committed
h
1 parent 8d83cbe commit ebb82be

File tree

1 file changed

+101
-21
lines changed

1 file changed

+101
-21
lines changed

app/src/main/cpp/NativeTrack.cpp

Lines changed: 101 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,11 @@ Java_org_akanework_gramophone_logic_utils_NativeTrack_set(
631631
/* maxRequiredSpeed = */ maxRequiredSpeed
632632
);
633633
} else if (android_get_device_api_level() >= 24) { // Android 7.x
634-
*(int32_t*)((uintptr_t)holder->track + 0x300) = selectedDeviceId;
634+
#ifdef __LP64__
635+
*(int32_t*)((uintptr_t)holder->track + 0x300) = selectedDeviceId; // TODO x86_64
636+
#else
637+
*(int32_t*)((uintptr_t)holder->track + 0x27c) = selectedDeviceId; // TODO x86
638+
#endif
635639
ret = ZN7android10AudioTrack3setE19audio_stream_type_tj14audio_format_tjm20audio_output_flags_tPFviPvS4_ES4_iRKNS_2spINS_7IMemoryEEEb15audio_session_tNS0_13transfer_typeEPK20audio_offload_info_tiiPK18audio_attributes_tbf(
636640
holder->track,
637641
/* streamType = */ streamType,
@@ -655,7 +659,11 @@ Java_org_akanework_gramophone_logic_utils_NativeTrack_set(
655659
/* maxRequiredSpeed = */ maxRequiredSpeed
656660
);
657661
} else if (android_get_device_api_level() >= 23) { // Android 6.0 (SDK 23)
658-
*(int32_t*)((uintptr_t)holder->track + 0x2e0) = selectedDeviceId;
662+
#ifdef __LP64__
663+
*(int32_t*)((uintptr_t)holder->track + 0x2e0) = selectedDeviceId; // TODO x86_64
664+
#else
665+
*(int32_t*)((uintptr_t)holder->track + 0x254) = selectedDeviceId; // TODO x86
666+
#endif
659667
if (maxRequiredSpeed > 1.0f) {
660668
if (trackFlags & 4 /* AUDIO_OUTPUT_FLAG_FAST */) {
661669
// if we're unlucky, the calculated frame count may be smaller than HAL frame count
@@ -702,8 +710,8 @@ Java_org_akanework_gramophone_logic_utils_NativeTrack_set(
702710
// calculating the minimum frame count like AudioTrack would in N
703711
// (where maxRequiredSpeed was added)
704712
minBufCount = afLatencyMs / ((1000 * afFrameCount) / afSampleRate);
705-
minFrameCount = (int32_t)((minBufCount < 2 ? 2 : minBufCount) *
706-
(sampleRate == afSampleRate ? afFrameCount : size_t((uint64_t)afFrameCount *
713+
minFrameCount = (int32_t)((double)(minBufCount < 2 ? 2 : minBufCount) *
714+
(double)(sampleRate == afSampleRate ? afFrameCount : (size_t)((uint64_t)afFrameCount *
707715
sampleRate / afSampleRate + 1 + 1))
708716
* (double)maxRequiredSpeed + 1 + 1);
709717
if (frameCount < minFrameCount) {
@@ -775,48 +783,122 @@ Java_org_akanework_gramophone_logic_utils_NativeTrack_getRealPtr(
775783
extern "C" JNIEXPORT jint JNICALL
776784
Java_org_akanework_gramophone_logic_utils_NativeTrack_flagsFromOffset(
777785
JNIEnv *, jobject, jlong ptr) {
778-
auto holder = (track_holder*) ptr;
786+
auto holder = (track_holder*) ptr; // TODO x86
787+
size_t extra;
779788
switch (android_get_device_api_level()) {
780789
case 27:
790+
#ifdef __LP64__
781791
return (int32_t)*(uint32_t*)((uintptr_t)holder->track + 0x338);
792+
#else
793+
return (int32_t)*(uint32_t*)((uintptr_t)holder->track + 0x2d8);
794+
#endif
782795
case 26:
796+
#ifdef __LP64__
783797
return (int32_t)*(uint32_t*)((uintptr_t)holder->track + 0x330);
798+
#else
799+
return (int32_t)*(uint32_t*)((uintptr_t)holder->track + 0x2d0);
800+
#endif
784801
case 25:
785802
case 24:
803+
#ifdef __LP64__
786804
return (int32_t)*(uint32_t*)((uintptr_t)holder->track + 0x2a0);
805+
#else
806+
return (int32_t)*(uint32_t*)((uintptr_t)holder->track + 0x248);
807+
#endif
787808
case 23:
809+
#ifdef __LP64__
788810
return (int32_t)*(uint32_t*)((uintptr_t)holder->track + 0x280);
789-
case 22: // TODO caf abi support
790-
// did caf pick https://github.com/LineageOS/android_frameworks_av/commit/65dfe71d2499c835400d6a71d17a9f3070a49463#diff-5277c03b566cc83f5f9842c3d0faa9ae47c135cf7da0f49331699401a5432965
791-
// or was that a CM idea? and how do we detect who's ifdefed?
792-
// same question for https://github.com/LineageOS/android_frameworks_av/commit/aa31cfab23de946abf7b52bfae3667110ba405ef
793-
// do we have to cover for both with and without either of these commits?
794-
case 21: // TODO caf abi support (https://github.com/LineageOS/android_frameworks_av/commit/8c6297e4a78a97cac2c9c4b855828dc06c356686#diff-5277c03b566cc83f5f9842c3d0faa9ae47c135cf7da0f49331699401a5432965)
795-
return (int32_t)*(uint32_t*)((uintptr_t)holder->track + 0x228);
811+
#else
812+
return (int32_t)*(uint32_t*)((uintptr_t)holder->track + 0x220);
813+
#endif
814+
case 22:
815+
extra =
816+
#ifdef __ARM_ARCH_7A__
817+
/* QCOM_DIRECTTRACK (BOARD_USES_LEGACY_ALSA_AUDIO), only for MSM8x60 in CM12.x */
818+
dlsym(libaudioclient_handle, "_ZN7android10AudioTrack6notifyEi") ? 0x20 /* 0x208 */ :
819+
#endif
820+
(dlsym(libaudioclient_handle, "_ZN7android10AudioTrack28initializeTrackOffloadParamsEv")
821+
#if defined(__LP64__)
822+
? 0x20 /* 0x248 */ : 0x0); // edge case: couldn't find any CM12.1 x86_64 build
823+
#else
824+
? 0x18 /* 0x200 */ : 0x0); // TODO is this valid for x86?
825+
#endif
826+
// cm12.1 x86 0x1f8
827+
break;
828+
case 21:
829+
extra =
830+
#ifdef __ARM_ARCH_7A__
831+
/* QCOM_DIRECTTRACK (BOARD_USES_LEGACY_ALSA_AUDIO), only for MSM8x60 in CM12.x */
832+
dlsym(libaudioclient_handle, "_ZN7android10AudioTrack6notifyEi") ? 0x8 /* 0x1f0 */ :
833+
#endif
834+
(0);
835+
break;
796836
default:
797837
return INT32_MAX;
798-
};
838+
}
839+
#ifdef __LP64__
840+
return (int32_t)*(uint32_t*)((uintptr_t)holder->track + 0x228 + extra);
841+
#else
842+
return (int32_t)*(uint32_t*)((uintptr_t)holder->track + 0x1e8 + extra);
843+
#endif
799844
}
800845

801846
extern "C" JNIEXPORT jint JNICALL
802847
Java_org_akanework_gramophone_logic_utils_NativeTrack_notificationFramesActFromOffset(
803848
JNIEnv *, jobject, jlong ptr) {
804-
auto holder = (track_holder*) ptr;
849+
auto holder = (track_holder*) ptr; // TODO x86
850+
size_t extra;
805851
switch (android_get_device_api_level()) {
806852
case 27:
807853
case 26:
854+
#ifdef __LP64__
808855
return (int32_t)*(uint32_t*)((uintptr_t)holder->track + 0x228);
856+
#else
857+
return (int32_t)*(uint32_t*)((uintptr_t)holder->track + 0x1dc);
858+
#endif
809859
case 25:
810860
case 24:
861+
#ifdef __LP64__
811862
return (int32_t)*(uint32_t*)((uintptr_t)holder->track + 0x220);
863+
#else
864+
return (int32_t)*(uint32_t*)((uintptr_t)holder->track + 0x1d4);
865+
#endif
812866
case 23:
867+
#ifdef __LP64__
813868
return (int32_t)*(uint32_t*)((uintptr_t)holder->track + 0x214);
814-
case 22: // TODO caf abi support (see above)
815-
case 21: // TODO caf abi support (see above)
816-
return (int32_t)*(uint32_t*)((uintptr_t)holder->track + 0x1ec);
869+
#else
870+
return (int32_t)*(uint32_t*)((uintptr_t)holder->track + 0x1c8);
871+
#endif
872+
case 22:
873+
extra =
874+
#ifdef __ARM_ARCH_7A__
875+
/* QCOM_DIRECTTRACK (BOARD_USES_LEGACY_ALSA_AUDIO), only for MSM8x60 in CM12.x */
876+
dlsym(libaudioclient_handle, "_ZN7android10AudioTrack6notifyEi") ? 0x1c /* 0x1c8 */ :
877+
#endif
878+
(dlsym(libaudioclient_handle, "_ZN7android10AudioTrack28initializeTrackOffloadParamsEv")
879+
#ifdef __LP64__
880+
? 0x20 /* 0x20c */ : 0x0); // edge case: couldn't find any CM12.1 x86_64 build
881+
#else
882+
? 0x14 /* 0x1c0 */ : 0x0); // TODO is this valid for x86?
883+
#endif
884+
// cm12.1 x86 0x1bc
885+
break;
886+
case 21:
887+
extra =
888+
#ifdef __ARM_ARCH_7A__
889+
/* QCOM_DIRECTTRACK (BOARD_USES_LEGACY_ALSA_AUDIO), only for MSM8x60 in CM12.x */
890+
dlsym(libaudioclient_handle, "_ZN7android10AudioTrack6notifyEi") ? 0x8 /* 0x1b4 */ :
891+
#endif
892+
(0);
893+
break;
817894
default:
818895
return INT32_MAX;
819-
};
896+
}
897+
#ifdef __LP64__
898+
return (int32_t)*(uint32_t*)((uintptr_t)holder->track + 0x1ec + extra);
899+
#else
900+
return (int32_t)*(uint32_t*)((uintptr_t)holder->track + 0x1ac + extra);
901+
#endif
820902
}
821903

822904
extern "C" JNIEXPORT void JNICALL
@@ -899,6 +981,4 @@ Java_org_akanework_gramophone_logic_utils_NativeTrack_00024Companion_isOffloadSu
899981
// TODO types
900982
// media::VolumeShaper::Status applyVolumeShaper(
901983
// const sp<media::VolumeShaper::Configuration>& configuration,
902-
// const sp<media::VolumeShaper::Operation>& operation);
903-
904-
// TODO getTimestamp is virtual on CAF L?
984+
// const sp<media::VolumeShaper::Operation>& operation);

0 commit comments

Comments
 (0)