Hi Saul, If the variables (of pjmedia ports) are local, it is impossible to access them to stop the ring. Furthermore, the caching pool will produce leak (not release-able). And I think it is more efficient and easier to maintain only single instance of pjmedia_endpt and pjmedia_snd_port for the whole application (perhaps also the wav player port). So yes, (member of) global variables should be better. Regards, nanang On 23/03/2008, Sa?l Ibarra <saghul at gmail.com> wrote: > Hi! > > I've been playing around with pjsip for several days and i'm trying to > make my own 'hello world' softphone to learn how to use the library :) > > Now i'm a little stuck getting incoming call ringtone to work. I've > done the following: > > I've defined the incoming call callback, and inside that function, I > call another function: ring(); > > ring() basically does nearly the same as playfile.c sample, but I > paste the code just in case: > > static void ring(void) > { > 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; > > /* Para poder asignar memoria din?micamente tenemos que crear > una 'pool factory' */ > pj_caching_pool_init(&cp, &pj_pool_factory_default_policy, 0); > > /* Inicializamos el endpoint */ > status = pjmedia_endpt_create(&cp.factory, NULL, 1, &med_endpt); > if (status != PJ_SUCCESS) > return; > > /* Creamos un pool de memoria para el reproductor */ > pool = pj_pool_create( &cp.factory, /* pool factory */ > "wavplayer", /* pool name. */ > 4000, /* init size */ > 4000, /* increment size */ > NULL /* callback on error */ > ); > > /* Creamos el media port del fichero wav */ > status = pjmedia_wav_player_port_create(pool, /* > memory pool */ > RINGTONE, /* > file to play */ > 20, /* > ptime. */ > 0, /* > flags */ > 0, /* > default buffer */ > &file_port /* > returned port */ > ); > > if (status != PJ_SUCCESS) { > printf("No se puede usar ese archivo WAV: %s\n", status); > return; > } > > /* Creamos el puerto para el reproductor de sonido */ > status = pjmedia_snd_port_create_player( > pool, /* pool */ > -1, /* use default dev. */ > 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) { > printf("No se pudo abrir el dispositivo de audio: > %s\n", status); > } > > /* Conectamos el puerto del fichero a la tarjeta de sonido. La > reproducci?n comenzar? inmediatamente. */ > status = pjmedia_snd_port_connect( snd_port, file_port); > if (status != PJ_SUCCESS) { > printf("Error conectando el puerto de audio: %s\n", status); > return; > } > > > Now, when I get an incoming call, the file starts plying and it loops > infinitely, which is OK, BUT, I want the file to stop plying when I > type 'answer' at the main loop prompt. > > The issue is: how can I access the sound port again? Shoul I use > global variables? or open another thread and when I type 'answer' > return there and do my stuff? > > I hope my explanation is fine :) Sorry for the long mail. > > > Thanks in advance for any help. > > -- > Sa?l -- "Nunca subestimes el ancho de banda de un cami?n lleno de disketes." > ---------------------------------------------------------------- > http://www.saghul.net/ > > _______________________________________________ > Visit our blog: http://blog.pjsip.org > > pjsip mailing list > pjsip at lists.pjsip.org > http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org >