Skip to content

Commit 352c208

Browse files
committed
remove segfault feature again
1 parent bed35b0 commit 352c208

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

app/src/main/cpp/NativeTrack.cpp

+16-8
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ static ZN7android10AudioTrackC1Ev_t ZN7android10AudioTrackC1Ev = nullptr;
3535
typedef void(*ZN7android7RefBase12weakref_type7decWeakEPKv_t)(void* thisptr, void* id);
3636
static ZN7android7RefBase12weakref_type7decWeakEPKv_t ZN7android7RefBase12weakref_type7decWeakEPKv = nullptr;
3737
typedef int32_t(*ZN7android10AudioTrack3setE19audio_stream_type_tj14audio_format_t20audio_channel_mask_tm20audio_output_flags_tRKNS_2wpINS0_19IAudioTrackCallbackEEEiRKNS_2spINS_7IMemoryEEEb15audio_session_tNS0_13transfer_typeEPK20audio_offload_info_tRKNS_7content22AttributionSourceStateEPK18audio_attributes_tbfi_t)
38-
(void* thisptr, int32_t streamType, uint32_t sampleRate, uint32_t format, uint32_t channelMask, size_t frameCount /* = 0 */, uint32_t flags /* = 0 */, fake_wp callback /* = nullptr */, int32_t notificationFrames /* = 0 */, fake_sp sharedMemory /* = nullptr */, bool threadCanCallJava /* = false */, int32_t audioSessionId /* = 0 */, transfer_type transferType /* = TRANSFER_DEFAULT */, void* offloadInfo /* = nullptr */, void* attributionSource, void* attributes /* = nullptr */, bool doNotReconnect /* = false */, float maxRequiredSpeed /* = 1.0f */, int selectedDeviceId /* = 0 */);
38+
(void* thisptr, int32_t streamType, uint32_t sampleRate, uint32_t format, uint32_t channelMask, size_t frameCount /* = 0 */, uint32_t flags /* = 0 */, fake_wp& callback /* = nullptr */, int32_t notificationFrames /* = 0 */, fake_sp& sharedMemory /* = nullptr */, bool threadCanCallJava /* = false */, int32_t audioSessionId /* = 0 */, transfer_type transferType /* = TRANSFER_DEFAULT */, void* offloadInfo /* = nullptr */, int& attributionSource, void* attributes /* = nullptr */, bool doNotReconnect /* = false */, float maxRequiredSpeed /* = 1.0f */, int selectedDeviceId /* = 0 */);
3939
static ZN7android10AudioTrack3setE19audio_stream_type_tj14audio_format_t20audio_channel_mask_tm20audio_output_flags_tRKNS_2wpINS0_19IAudioTrackCallbackEEEiRKNS_2spINS_7IMemoryEEEb15audio_session_tNS0_13transfer_typeEPK20audio_offload_info_tRKNS_7content22AttributionSourceStateEPK18audio_attributes_tbfi_t ZN7android10AudioTrack3setE19audio_stream_type_tj14audio_format_t20audio_channel_mask_tm20audio_output_flags_tRKNS_2wpINS0_19IAudioTrackCallbackEEEiRKNS_2spINS_7IMemoryEEEb15audio_session_tNS0_13transfer_typeEPK20audio_offload_info_tRKNS_7content22AttributionSourceStateEPK18audio_attributes_tbfi = nullptr;
4040

4141
class MyCallback : public virtual android::AudioTrack::IAudioTrackCallback {
@@ -99,15 +99,15 @@ extern "C" JNIEXPORT jlong JNICALL
9999
Java_org_akanework_gramophone_logic_utils_NativeTrack_create(
100100
JNIEnv *env, jobject, jobject parcel) {
101101
auto theTrack = ::operator new(AUDIO_TRACK_SIZE);
102-
memset(theTrack, 0xdeadbeef, AUDIO_TRACK_SIZE);
102+
memset(theTrack, (unsigned char)0xde, AUDIO_TRACK_SIZE);
103103
auto holder = new track_holder();
104-
if (parcel != nullptr) { // implies SDK >= 31
104+
if (true || parcel != nullptr) { // implies SDK >= 31
105105
// I'm too cool to call AttributionSourceState ctor before using it.
106106
auto myParcel = ZN7android19parcelForJavaObjectEP7_JNIEnvP8_jobject(env, parcel);
107107
if (myParcel == nullptr) {
108108
ALOGE("myParcel is NULL");
109109
::operator delete(theTrack);
110-
return NULL;
110+
return 0;
111111
}
112112
auto ats = ::operator new(ATTRIBUTION_SOURCE_SIZE);
113113
memset(ats, 0, ATTRIBUTION_SOURCE_SIZE);
@@ -130,7 +130,9 @@ Java_org_akanework_gramophone_logic_utils_NativeTrack_doSet(
130130
JNIEnv *, jobject, jlong ptr) {
131131
auto holder = (track_holder*) ptr;
132132
auto refs = holder->callback->createWeak(holder);
133-
ALOGE("calling set on %p", holder->track);
133+
ALOGE("calling set on %p with ats %p", holder->track, holder->ats);
134+
fake_wp callback = { .thePtr = nullptr };
135+
fake_sp sharedMemory = { .thePtr = nullptr };
134136
auto ret = ZN7android10AudioTrack3setE19audio_stream_type_tj14audio_format_t20audio_channel_mask_tm20audio_output_flags_tRKNS_2wpINS0_19IAudioTrackCallbackEEEiRKNS_2spINS_7IMemoryEEEb15audio_session_tNS0_13transfer_typeEPK20audio_offload_info_tRKNS_7content22AttributionSourceStateEPK18audio_attributes_tbfi(
135137
holder->track,
136138
/* streamType = */ 3 /* AUDIO_STREAM_MUSIC */,
@@ -139,14 +141,14 @@ Java_org_akanework_gramophone_logic_utils_NativeTrack_doSet(
139141
/* channelMask = */ 1,
140142
/* frameCount = */ 0 /* default */,
141143
/* flags = */ 0 /* AUDIO_OUTPUT_FLAG_NONE */,
142-
/* callback = */ { .thePtr = nullptr }, // TODO add back ptr/refs
144+
/* callback = */ callback, // TODO add back ptr/refs
143145
/* notificationFrames = */ 0 /* default */,
144-
/* sharedBuffer = */ { .thePtr = nullptr },
146+
/* sharedBuffer = */ sharedMemory,
145147
/* threadCanCallJava = */ true,
146148
/* sessionId = */ 0 /* default */,
147149
/* transferType = */ TRANSFER_SYNC,
148150
/* offloadInfo = */ nullptr,
149-
/* attributionSource = */ holder->ats,
151+
/* attributionSource = */ *((int*)holder->ats),
150152
/* pAttributes = */ nullptr,
151153
/* doNotReconnect = */ true, // for emulating DIRECT track developer UX
152154
/* maxRequiredSpeed = */ 1.0f,
@@ -160,6 +162,12 @@ Java_org_akanework_gramophone_logic_utils_NativeTrack_doSet(
160162
return ret;
161163
}
162164

165+
extern "C" JNIEXPORT jlong JNICALL
166+
Java_org_akanework_gramophone_logic_utils_NativeTrack_getRealPtr(
167+
JNIEnv *, jobject, jlong ptr) {
168+
return (intptr_t)((track_holder*)ptr)->track;
169+
}
170+
163171
extern "C" JNIEXPORT void JNICALL
164172
Java_org_akanework_gramophone_logic_utils_NativeTrack_dtor(
165173
JNIEnv *, jobject, jlong ptr) {

app/src/main/kotlin/org/akanework/gramophone/logic/utils/AfFormatTracker.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ data class AudioTrackInfo(
4343
}
4444
}
4545

46-
@UnstableApi
46+
@OptIn(UnstableApi::class)
4747
class AfFormatTracker(
4848
private val context: Context, private val playbackHandler: Handler,
4949
private val handler: Handler
@@ -571,7 +571,7 @@ class AfFormatTracker(
571571
}.also { Log.d(TRACE_TAG, "native dump/getAudioTrackPtr is done: $it") }
572572
}
573573

574-
private external fun dumpInternal(@Suppress("unused") audioTrackPtr: Long): String
574+
/*private*/ external fun dumpInternal(@Suppress("unused") audioTrackPtr: Long): String
575575

576576
@SuppressLint("PrivateApi") // only used below U, stable private API
577577
private fun getAfService(): IBinder? {

app/src/main/kotlin/org/akanework/gramophone/logic/utils/NativeTrack.kt

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package org.akanework.gramophone.logic.utils
33
import android.content.Context
44
import android.os.Build
55
import android.os.Parcel
6+
import android.util.Log
67

78
class NativeTrack(context: Context) {
89
val ptr: Long
@@ -41,9 +42,11 @@ class NativeTrack(context: Context) {
4142
private external fun initDlsym(): Boolean
4243
private external fun create(@Suppress("unused") parcel: Parcel?): Long
4344
private external fun doSet(@Suppress("unused") ptr: Long): Int
45+
private external fun getRealPtr(@Suppress("unused") ptr: Long): Long
4446
private external fun dtor(@Suppress("unused") ptr: Long): Unit
4547
fun set(): Boolean {
4648
doSet(ptr)
49+
Log.e("hi", "dump:${AfFormatTracker.dumpInternal(getRealPtr(ptr))}")
4750
return myState == State.ALIVE
4851
}
4952

0 commit comments

Comments
 (0)