问题描述
自从我的 Galaxy S5 中的棒棒糖更新以来,我尝试修复我的应用程序中的通话录音.作为基础,我从这里使用谷歌示例项目:示例.
I try to fix call recording in my app since lolipop update in my Galaxy S5. As a base I am using google sample project from here: Sample.
这是代码的主要部分:
SLresult result;
sampleInfo_ = *sampleFormat;
SLAndroidDataFormat_PCM_EX format_pcm;
ConvertToSLSampleFormat(&format_pcm, &sampleInfo_);
gFp = fopen("/storage/emulated/0/file.pcm", "w");
// configure audio source
SLDataLocator_IODevice loc_dev = {SL_DATALOCATOR_IODEVICE, SL_IODEVICE_AUDIOINPUT,
SL_DEFAULTDEVICEID_AUDIOINPUT, NULL};
SLDataSource audioSrc = {&loc_dev, NULL};
// configure audio sink
SLDataLocator_AndroidSimpleBufferQueue loc_bq = {
SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE,
DEVICE_SHADOW_BUFFER_QUEUE_LEN};
SLDataSink audioSnk = {&loc_bq, &format_pcm};
// create audio recorder
// (requires the RECORD_AUDIO permission)
const SLInterfaceID id[2] = {SL_IID_ANDROIDSIMPLEBUFFERQUEUE,
SL_IID_ANDROIDCONFIGURATION};
const SLboolean req[2] = {SL_BOOLEAN_FALSE, SL_BOOLEAN_FALSE};
result = (*slEngine)->CreateAudioRecorder(slEngine,
&recObjectItf_,
&audioSrc,
&audioSnk,
2,
id, req);
SLASSERT(result);
// Configure the voice recognition preset which has no
// signal processing for lower latency.
SLAndroidConfigurationItf inputConfig;
result = (*recObjectItf_)->GetInterface(recObjectItf_,
SL_IID_ANDROIDCONFIGURATION,
&inputConfig);
SLuint32 presetValue = SL_ANDROID_RECORDING_PRESET_VOICE_COMMUNICATION;
result = (*inputConfig)->SetConfiguration(inputConfig,
SL_ANDROID_KEY_RECORDING_PRESET,
&presetValue,
sizeof(SLint32));
SLASSERT(result);
result = (*recObjectItf_)->Realize(recObjectItf_, SL_BOOLEAN_FALSE);
SLASSERT(result);
result = (*recObjectItf_)->GetInterface(recObjectItf_, SL_IID_RECORD, &recItf_);
SLASSERT(result);
result = (*recObjectItf_)->GetInterface(recObjectItf_, SL_IID_ANDROIDSIMPLEBUFFERQUEUE,
&recBufQueueItf_);
SLASSERT(result);
result = (*recBufQueueItf_)->RegisterCallback(recBufQueueItf_, bqRecorderCallback, this);
SLASSERT(result);
devShadowQueue_ = new AudioQueue(DEVICE_SHADOW_BUFFER_QUEUE_LEN);
assert(devShadowQueue_);
这是我的问题,这段代码没有记录通话的另一端,在输出文件中我只能听到麦克风的声音.我尝试更改参数但结果相同.有人知道我做错了什么吗?
And here is my problem this code do not record other side of the call, in output file I can only hear voice from microphone. I tried changing parameters but with same result. Anyone know what I am doing wrong?
推荐答案
我找到了修复 Galaxy S5 通话录音的解决方案.
I found the solution to fix Galaxy S5 call recording.
主要是调用这个:status_t AudioSystem::setParameters(audio_io_handle_t ioHandle, const String8& keyValuePairs)
在调用开始时循环.
Main thing is to call this:status_t AudioSystem::setParameters(audio_io_handle_t ioHandle, const String8& keyValuePairs)
in the loop when the call is started.
首先得到想要的函数:
open_media = dlopen("/system/lib/libmedia.so", RTLD_LAZY);
set_parameters = (int (*)(int, void *)) dlsym(open_media,
"_ZN7android11AudioSystem13setParametersEiRKNS_7String8E");
接下来我们需要 audio_io_handle_t
和 String8&
对象:
Next we need audio_io_handle_t
and String8&
object:
audio_io_handle_t
- 是audio session id加1,你可以从AudioRecord.getAudioSessionId
String8&
这个比较难:
audio_io_handle_t
- is audio session id increased by 1, You can get it fromAudioRecord.getAudioSessionId
String8&
this is more difficult:
//First inicialize function
create_string = (void (*)(void *, const char *)) dlsym(open_util,
"_ZN7android7String8C2EPKc");
//next call this function to convert string to required object
create_string(&str8, str);
当我们拥有所有需要的部分时,我们可以调用 setParameters 函数:
When we have all needed parts we can call setParameters function:
//remember to call this in loop when recording is starting
set_parameters(id + 1, &str8);
变量声明的样子:
int (*set_parameters)(int, void *);
void (*create_string)(void *, const char *);
void *str8 = 0;
const char *str = "input_source=4";
@ChanchalShelar
@ChanchalShelar
@Peter @AkshatVajpayee
@Peter @AkshatVajpayee
这是我的 .cpp 文件的外观:
This is how my .cpp file looks:
void *open_media;
void *open_util;
int (*set_parameters)(int, void *);
void (*create_string)(void *, const char *);
void *str8 = 0;
const char *str = "input_source=4";
extern "C" {
JNIEXPORT bool JNICALL
Java_com_sample_NativeAudio_init(JNIEnv *env, jclass);
JNIEXPORT int JNICALL
Java_com_sample_NativeAudio_setParameters(JNIEnv *env, jclass, int id);
}
void get_string8() {
create_string = (void (*)(void *, const char *)) dlsym(open_util, "_ZN7android7String8C2EPKc");
if (!create_string) {
LOGD("There is no create_string function");
} else {
LOGD("create_string function OK");
}
create_string(&str8, str);
if (!str8) {
LOGD("Filed to create str8");
} else {
LOGD("create str8 success");
}
}
JNIEXPORT int JNICALL Java_com_sample_NativeAudio_setParameters(JNIEnv *env,
jclass type, int id) {
if (set_parameters) {
return set_parameters(id + 1, &str8);
}
return 0;
}
JNIEXPORT bool JNICALL Java_com_sample_NativeAudio_init(JNIEnv *env, jclass type) {
open_util = dlopen("/system/lib/libutils.so", RTLD_LAZY);
if (open_util) {
get_string8();
} else {
return false;
}
open_media = dlopen("/system/lib/libmedia.so", RTLD_LAZY);
if (open_media) {
set_parameters = (int (*)(int, void *)) dlsym(open_media,
"_ZN7android11AudioSystem13setParametersEiRKNS_7String8E");
} else {
return false;
}
return true;
}
这篇关于使用 OpenSL 进行通话录音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!