Exemplo n.º 1
0
// helper for creating call-media-player
static void create_player(pjsua_call_id call_id)
{
	// get call infos
	pjsua_call_info ci; 
	pjsua_call_get_info(call_id, &ci);
	
	pj_str_t name;
	pj_status_t status = PJ_ENOTFOUND;
	
	log_message("Creating player ... ");
	
	// create player for playback media		
	if (app_cfg.wav_file) {
		status = pjsua_player_create(pj_cstr(&name, app_cfg.wav_file), 0, &play_id);
	} else {
		status = pjsua_player_create(pj_cstr(&name, app_cfg.tts_file), 0, &play_id);
	}
	if (status != PJ_SUCCESS) error_exit("Error playing sound-playback", status);
		
	// connect active call to media player
	pjsua_conf_connect(pjsua_player_get_conf_port(play_id), ci.conf_slot);
	
	// get media port (play_port) from play_id
    status = pjsua_player_get_port(play_id, &play_port);
	if (status != PJ_SUCCESS) error_exit("Error getting sound player port", status);
	
	// register media finished callback	
    status = pjmedia_wav_player_set_eof_cb(play_port, NULL, &on_media_finished);
	if (status != PJ_SUCCESS) error_exit("Error adding sound-playback callback", status);
	
	log_message("Done.\n");
}
Exemplo n.º 2
0
int dll_playWav(char* wavFile, int callId)
{
       pj_status_t status;

       /* Infos Player */
       pjsua_player_id player_id;            // Ident. for the player
       pjmedia_port *media_port;           // Struct. media_port
       pjsua_conf_port_id conf_port;       // Conference port for the player
 
       /* Infos Call Session */
       pjsua_call_info call_info;

       /********************************************
       / 1- Check if Call exists and is active
       ********************************************/

       // Get call_info from callId
       pjsua_call_get_info(callId, &call_info);

       if (call_info.media_status != PJSUA_CALL_MEDIA_ACTIVE)
               return -1;

       /********************************************
       / 2- Load the WAV File - Create the player
       ********************************************/
       status = pjsua_player_create(&pj_str(wavFile), PJMEDIA_FILE_NO_LOOP, &player_id);

       /********************************************
       / 3- Register the Callback C++ Function "on_wavplayerEof_callback"
       ********************************************/

       if (status == PJ_SUCCESS)
       {
               // Get media_port from player_id
               status = pjsua_player_get_port(player_id, &media_port);
       }
 
       if (status == PJ_SUCCESS)
       {
               // Prepare argument for Callback
               wavplayerEof_Data* args = (wavplayerEof_Data*)malloc(sizeof(wavplayerEof_Data));
               args->playerId = player_id;
               args->callId = callId;     

               // Register the Callback, launched when the End of the Wave File is reached
               status = pjmedia_wav_player_set_eof_cb(media_port, args, &on_wavplayerEof_callback);
       }
 
       /********************************************
       / 4- Stream the file to the Call Session
       ********************************************/

       // Get conf_port from player_id
       if (status == PJ_SUCCESS)
               conf_port = pjsua_player_get_conf_port(player_id);

 
       // one way connect conf_port (wav player) to call_info.conf_slot (call)
       if ((status == PJ_SUCCESS)&&(conf_port != PJSUA_INVALID_ID)&&(call_info.conf_slot != 0))        // test if conf_port valid, and if conf_slot != soundcard
       {
               status = pjsua_conf_connect(conf_port, call_info.conf_slot);
       }

       PJ_LOG(3,(THIS_FILE,"Wav Play, status %d",status));

       if (status != PJ_SUCCESS)
               return -1;

       return player_id;
}