quiet / org.quietmodem.Quiet

Quiet for Android - TCP over sound
1.43k stars 125 forks source link

failed to initialize opensl recorder, opensl error code=0009 #14

Closed canhenrik closed 6 years ago

canhenrik commented 6 years ago

Hey, i am trying to setup the quietshare app on android 4.0.4 and i got everything working except the receiver on the phone gives me the mentioned error. The code was build without any problems. Any idea, what i have to change to get the receiver working? Thanks in advance and thanks for this great project!

brian-armstrong commented 6 years ago

Are you running in the default emulator by any chance? It doesn't support the microphone

canhenrik commented 6 years ago

no, im running it on my phone (samsung galaxy gt-s7562). The message pops up in the app itself. I can still transmit. Receive just doesnt work and it shows the error message.

canhenrik commented 6 years ago

Here is the logcat, i hope that helps:

01-04 20:26:52.000: E/AudioHardwareMSM7X27A(113): More than one instance of recording not supported 01-04 20:26:52.000: V/AudioHardwareMSM7X27A(113): AudioStreamInMSM72xx destructor 01-04 20:26:52.000: V/AudioPolicyManagerBase(113): getInput() failed opening input: samplingRate 44100, format 1, channels 12 01-04 20:26:52.000: E/AudioRecord(16513): Could not get audio input for record source 1 01-04 20:26:52.000: E/libOpenSLES(16513): android_audioRecorder_realize(0x33f238) error creating AudioRecord object

canhenrik commented 6 years ago

when running the app for the first time, the receiver works fine. But it seems that the closing of the receiver does not really work when the spinner is used. In the FrameReceiverObservable.java the unsubscribe method does'nt really close the receiver, because the first error i get when changing something in the spinner is the above mentioned error, that only one recording instance is supported. Any idea on how to fix this?

brian-armstrong commented 6 years ago

Sorry, what codebase is this? There is no FrameReceiverObservable.java in this repo.

canhenrik commented 6 years ago

sorry, i meant the BaseFrameReceiver.java. The close method there is called from the quietshare app in FrameReceiverObservable.java and it doesnt seem to really close the recorder, at least on my phone.

brian-armstrong commented 6 years ago

It looks like there's some sort of destructor that runs just after that. Is it possible that you're creating a new receiver before the old one has been destroyed?

brian-armstrong commented 6 years ago

My best guess otherwise is that this happens because Quiet only destroys/deallocates one of the objects on gc, which may never happen. It's possible this destroy has to be moved up to close time.

canhenrik commented 6 years ago

I fixed the issue by changing the close() method in BaseFrameReceiver.java to: public void close() { this.nativeClose(); nativeFree();//added to avoid complication with multiple receiver instances on Android 4.0.4 } Thank's for your help and again thanks for this great project!

brian-armstrong commented 6 years ago

I'm glad that fixed it for you. I'm not sure I want to make that change to the repo. Ideally, users could close the receiver but then continue receiving any frames out of it that are still in the queue. It seems like the right fix will entail having close deallocate the recorder, but not the quiet receiver.

canhenrik commented 6 years ago

I found a better solution by adding the following code to _nativeClose(): JNIEXPORT void JNICALL Java_org_quietmodem_Quiet_BaseFrameReceiver_nativeClose( JNIEnv env, jobject This) { jvm_pointer j_dec = (env)->GetLongField(env, This, cache.decoder.ptr); quiet_android_decoder dec = (quiet_android_decoder )recover_pointer(j_dec); android_decoder_terminate(dec); //destroy recorder completely!! Error in android 4.0.4 multiple recorder instances! added the following lines: if (dec->recorder) { quiet_opensl_destroy_recorder(dec->recorder); }; } it works fine now!