Call recording with OpenSL

后端 未结 2 1694
不知归路
不知归路 2020-12-29 17:03

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.

And this is the main part of

2条回答
  •  忘掉有多难
    2020-12-29 17:23

    You need to use ndk. Here are examples of the functions that need to be done.

    Load libmedia.so and libutils.so

    int load(JNIEnv *env, jobject thiz) {
        void *handleLibMedia;
        void *handleLibUtils;
        int result = -1;
        lspr func = NULL;
    
        pthread_t newthread = (pthread_t) thiz;
    
        handleLibMedia = dlopen("libmedia.so", RTLD_NOW | RTLD_GLOBAL);
        if (handleLibMedia != NULL) {
            func = dlsym(handleLibMedia, "_ZN7android11AudioSystem13setParametersEiRKNS_7String8E");
            if (func != NULL) {
                result = 0;
            }
            audioSetParameters = (lasp) func;
        } else {
            result = -1;
        }
    
        handleLibUtils = dlopen("libutils.so", RTLD_NOW | RTLD_GLOBAL);
        if (handleLibUtils != NULL) {
            fstr = dlsym(handleLibUtils, "_ZN7android7String8C2EPKc");
            if (fstr == NULL) {
                result = -1;
            }
        } else {
            result = -1;
        }
    
        cmd = CM_D;
    
        int resultTh = pthread_create(&newthread, NULL, taskAudioSetParam, NULL);
    
        return result;}
    

    Function setParameters

    int setParam(jint i, jint as) {
    pthread_mutex_lock(&mt);
    
    audioSession = (int) (as + 1);
    
    kvp = "input_source=4";
    kvps = toString8(kvp);
    
    cmd = (int) i;
    
    pthread_cond_signal(&cnd);
    pthread_mutex_unlock(&mt);
    
    return 0;}
    

    Task AudioSetParameters

    void *taskAudioSetParam(void *threadid) {
        while (1) {
            pthread_mutex_lock(&mt);
            if (cmd == CM_D) {
                pthread_cond_wait(&cnd, &mt);
            } else if (audioSetParameters != NULL) {
                 audioSetParameters(audioSession, kvps);
            }
            pthread_mutex_unlock(&mt);
        }
    }
    

    There is a library and an example of use https://github.com/ViktorDegtyarev/CallRecLib

提交回复
热议问题