I'm working on a call recorder app using MediaRecorder VOICE_CALL audio source, In some marshmallow devices it's crashing, then I changed source to MIC here incoming voice is not getting recorded. Due to this java limitation now I'm working on native android code to record voice call. I'm managed to record the audio using native-audio recorder for call recorder. Problem is in native code also it's recording one side voice only,incoming voice is not getting recorded. Then I tried the voice communication preset configuration, its not recording. Below is the preset configuration code.
const SLInterfaceID id[2] = { SL_IID_ANDROIDSIMPLEBUFFERQUEUE,SL_IID_ANDROIDCONFIGURATION};
const SLboolean req[2] = { SL_BOOLEAN_TRUE,SL_BOOLEAN_TRUE};
result = (*engineEngine)->CreateAudioRecorder(engineEngine, &recorderObject, &audioSrc,
&audioSnk, 2, id, req);
SLAndroidConfigurationItf inputConfig;
result = (*recorderObject)->GetInterface(recorderObject,
SL_IID_ANDROIDCONFIGURATION,
&inputConfig);
if (SL_RESULT_SUCCESS == result) {
SLuint32 presetValue =SL_ANDROID_RECORDING_PRESET_VOICE_COMMUNICATION ;
(*inputConfig)->SetConfiguration(inputConfig,
SL_ANDROID_KEY_RECORDING_PRESET,
&presetValue,
sizeof(SLuint32));
__android_log_print(ANDROID_LOG_DEBUG, "LOG_TAG", "\n Native PCM Conf Success\n");
} else{
__android_log_print(ANDROID_LOG_DEBUG, "LOG_TAG", "\n Native PCM Conf Error %d\n",result);
}
After adding preset configuration I'm getting system error when start recording the voice call :
E/AudioRecord: Could not get audio input for record source 7, sample rate 16000, format 0x1, channel mask 0x10, session 925, flags 0
E/libOpenSLES: android_audioRecorder_realize(0x559548c350) error creating AudioRecord object; status -22
W/libOpenSLES: Leaving Object::Realize (SL_RESULT_CONTENT_UNSUPPORTED)
check documentation and set correct sampling rate, format and mask. Channel mask might be stereo or mono. I am not sure how you are getting status -22 error, but Realize error is very clear, as per documentation
SL_RESULT_CONTENT_UNSUPPORTED if a format is not supported (e.g. sample rate too high)
Look at NDK sample to clarify your parameter setup
来源:https://stackoverflow.com/questions/45593065/how-to-configure-opensl-to-record-voice-call