[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

11/04/2009 at 10:34AM PST, ID: 24871910 | Points: 500
[x]
Attachment Details

using pjsip and pjmedia to play wav file over telephone

Asked by csummer in Voice Over IP, IP Telephony, Chat / IM Software

Tags: pjsip, pjmedia, pjsua, sip, sound ports

im using pjsip to create a simple sip client. my problem arises when i try to use pjmedia to play an audio file over the phone.  the audio file plays fine in the computer's internal sound card through the speakers but it does not play out over the telephone line.  any help would be greatly appreciated in what i am missing...
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
pj_status_t stream_to_call(pjsua_call_id call_id)
{
		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;
		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);
		Sleep(100); 
		/* Create memory pool for our file player */
		pool = pj_pool_create( &cp.factory,     /* pool factory         */
		                        "wav",           /* pool name.           */
		                        4000,            /* init size            */
		                        4000,            /* increment size       */
		                        NULL             /* callback on error    */
		                        );
		
		  /* Create file media port from the WAV file */
		status = pjmedia_wav_player_port_create(  pool,     /* memory pool      */
								"C:/waves/16bit/test55.wav",  /* file to play     */
		                        20,       /* ptime.   WAS 20        */
		                        0,        /* flags            */
								0,        /* default buffer   */
								&file_port/* returned port    */
								);
		if (status != PJ_SUCCESS) 
		{
			app_perror(THIS_FILE, "Unable to use WAV file", status);
			return 1;
		} 
		status = pjmedia_snd_port_create_player(
			pool,
			-1,
			file_port->info.clock_rate,        /* clock rate.          */
			file_port->info.channel_count,     /* # of channels.       */
			file_port->info.samples_per_frame, /* samples per frame.   */
			file_port->info.bits_per_sample,   /* 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); 
}
 
Loading Advertisement...
20091111-EE-VQP-91 - Hierarchy / EE_QW_3_20080625