2

现在我可以在 pjsip 中录制我自己的声音或说传出(通过麦克风),但我只需要录制通过扬声器传输的传入音频。这是我以 .wav 格式录制传出语音的代码。请帮我完成这项任务。感谢进阶。

-(int)startRecordAudio 
{
    pj_caching_pool cp;
    pjmedia_endpt *med_endpt;
    pj_pool_t *pool;
    pjmedia_port *file_port;
    pjmedia_snd_port *snd_port;
    char tmp[10];

    pj_status_t status;

    /* Must init PJLIB first: */
    status = pj_init();
    PJ_ASSERT_RETURN(status == PJ_SUCCESS, 1);

    /* Must create a pool factory before we can allocate any memory. */
    pj_caching_pool_init(&cp, &pj_pool_factory_default_policy, 0);
    status = pjmedia_endpt_create(&cp.factory, NULL, 1, &med_endpt);
    PJ_ASSERT_RETURN(status == PJ_SUCCESS, 1);

    /* Create memory pool for our file player */
    pool = pj_pool_create(&cp.factory,    /* pool factory       */
                          "app",          /* pool name.     */
                          4000,           /* init size      */
                          4000,           /* increment size     */
                          NULL            /* callback on error    */
                          );

    /* Create WAVE file writer port. */
    NSString* documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,   NSUserDomainMask, YES) objectAtIndex:0];
    NSString* foofile = [documentsPath stringByAppendingPathComponent:@"output.wav"];

    status = pjmedia_wav_writer_port_create(pool,
                                            [foofile cStringUsingEncoding:NSUTF8StringEncoding],
                                            CLOCK_RATE,
                                            NCHANNELS,
                                            SAMPLES_PER_FRAME,
                                            BITS_PER_SAMPLE,
                                            0, 0,
                                            &file_port);

    if (status != PJ_SUCCESS) {
        NSLog(@"Unable to write file");
        return 1;
    }

    /* Create sound player port. */
    status = pjmedia_snd_port_create_rec(pool,       /* pool         */
                                         -1,         /* use default dev.        */
                                         PJMEDIA_PIA_SRATE(&file_port->info),/* clock rate.     */
                                         PJMEDIA_PIA_CCNT(&file_port->info),/* # of channels.       */
                                         PJMEDIA_PIA_SPF(&file_port->info), /* samples per frame.   */
                                         PJMEDIA_PIA_BITS(&file_port->info),/* bits per sample.     */
                                         0,      /* options      */
                                         &snd_port       /* returned port       */
                                         );

    if (status != PJ_SUCCESS) {
      //  app_perror(THIS_FILE, "Unable to open sound device", status);
        return 1;
    }

    /* Connect file port to the sound player.
     * Stream playing will commence immediately.
     */

    status = pjmedia_snd_port_connect( snd_port, file_port);
    PJ_ASSERT_RETURN(status == PJ_SUCCESS, 1);

    /* Sleep to allow log messages to flush */
    pj_thread_sleep(10);

    if (fgets(tmp, sizeof(tmp), stdin) == NULL) {
        puts("EOF while reading stdin, will quit now..");
    }

    return 0;
} 
4

1 回答 1

0

你不需要做太多。在调用媒体状态检查调用活动和连接跟随是在 Java 中,但函数调用是完全相同的。

if (call_media_status == pjsua_call_media_status.PJSUA_CALL_MEDIA_ACTIVE ||
                call_media_status == pjsua_call_media_status.PJSUA_CALL_MEDIA_REMOTE_HOLD) {
    int callConfSlot = call_info.getConf_slot();
    int status = pjsua.pjsua_recorder_create(pjsua.pj_str_copy("/storage/sdcard0/test.wav"), 0, null, 0, 0, ids);
    if (status != pjsuaConstants.PJ_SUCCESS) {
        App.logd("NOT SUCCESSFULL IN RECORDING=" + status);    
    } else {
        App.logd("Scccuessfull in recording");
        int recordPort = pjsua.pjsua_recorder_get_conf_port(ids[0]);
        pjsua.conf_connect(callConfSlot, recordPort);
        pjsua.conf_connect(0, recordPort);//this line includes microphone
    }}
于 2015-10-06T11:41:57.320 回答