2013-07-03 5 views
1

지금 내 자신의 목소리를 녹음하거나 pjsip으로 나가는 (마이크를 통해) 말을 할 수 있지만 스피커를 통해 전송되는 들어오는 오디오 만 녹음해야합니다. 여기에 나가는 음성을 .wav 형식으로 녹음하는 코드가 있습니다. 이 작업을 도와주세요. Adv에 감사드립니다.들어오는 오디오 녹음 PJSIP

-(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; 
} 

답변

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 
    }}