[PJSip] simpleua + record audio file

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi

I am newbie to PJSip and use below program from pjsip-app/samples/ i.e.
simpleua program.

In this, program I have added function to record file in wav format. I have
highlighted the things which I added in this simpleua.c file

Here, I am attached whole C code for your reference and whatever changes i
have done shown in bold character over here. mainly changes in
 call_on_media_update() file.



#include <pjsip.h>
#include <pjmedia.h>
#include <pjmedia-codec.h>
#include <pjsip_ua.h>
#include <pjsip_simple.h>
#include <pjlib-util.h>
#include <pjlib.h>

...
pj_pool_t *pool;

pjmedia_port *media_port;

...

int main(int argc, char *argv[])
{

...
/* Loop until one call is completed */
for (;!g_complete;) {
pj_time_val timeout = {0, 10};
pjsip_endpt_handle_events(g_endpt, &timeout);
}

/* On exit, dump current memory usage: */
dump_pool_usage(THIS_FILE, &cp);

*/* Destroy sound device */
status = pjmedia_snd_port_destroy( g_snd_rec );

/* Destroy file port */
status = pjmedia_port_destroy( media_port );
PJ_ASSERT_RETURN(status == PJ_SUCCESS, 1);

/* Destroy media endpoint. */
pjmedia_endpt_destroy( g_med_endpt );

/* Destroy pool factory */
pj_caching_pool_destroy( &cp );

/* Shutdown PJLIB */
pj_shutdown();
*

return 0;
}

static void call_on_state_changed( pjsip_inv_session *inv, pjsip_event *e)
{
....
}

static void call_on_forked(pjsip_inv_session *inv, pjsip_event *e)
{
....
}

static pj_bool_t on_rx_request( pjsip_rx_data *rdata )
{
....
}

static void call_on_media_update( pjsip_inv_session *inv,
pj_status_t status)
{
pjmedia_session_info sess_info;
const pjmedia_sdp_session *local_sdp;
const pjmedia_sdp_session *remote_sdp;

if (status != PJ_SUCCESS) {

app_perror(THIS_FILE, "SDP negotiation has failed", status);

/* Here we should disconnect call if we're not in the middle
* of initializing an UAS dialog and if this is not a re-INVITE.
*/
return;
}

/* Get local and remote SDP.
* We need both SDPs to create a media session.
*/
status = pjmedia_sdp_neg_get_active_local(inv->neg, &local_sdp);

status = pjmedia_sdp_neg_get_active_remote(inv->neg, &remote_sdp);

status = pjmedia_session_info_from_sdp(inv->dlg->pool, g_med_endpt, 1,
&sess_info, local_sdp, remote_sdp);

if (status != PJ_SUCCESS) {
app_perror( THIS_FILE, "Unable to create media session", status);
return;
}

status = pjmedia_session_create( g_med_endpt, &sess_info, &g_med_transport,
NULL, &g_med_session );
if (status != PJ_SUCCESS) {
app_perror( THIS_FILE, "Unable to create media session", status);
return;
}


pjmedia_session_get_port(g_med_session, 0, &media_port);


/* Create a sound Player device and connect the media port to the
* sound device.
*/
*/* ----------------------------------------------------------------- PUT IN
COMMENT
status = pjmedia_snd_port_create_player(
inv->pool, * pool *
-1, * sound dev id *
48000, * clock rate *
media_port->info.channel_count, * channel count *
media_port->info.samples_per_frame, * samples per frame *
media_port->info.bits_per_sample, * bits per sample *
0, * options *
&g_snd_player);
if (status != PJ_SUCCESS) {
app_perror( THIS_FILE, "Unable to create sound player", status);
PJ_LOG(3,(THIS_FILE, "%d %d %d %d",
media_port->info.clock_rate, * clock rate *
media_port->info.channel_count, * channel count *
media_port->info.samples_per_frame, * samples per frame*
media_port->info.bits_per_sample * bits per sample *
));
return;
}
* *status = pjmedia_snd_port_connect(g_snd_player, media_port);
*/
/* Create WAVE file writer port. */
status = pjmedia_wav_writer_port_create( inv->pool, "recording.wav",
48000, /* clock rate */
2, /* channel count */
media_port->info.samples_per_frame, /* samples per frame*/
media_port->info.bits_per_sample, /* bits per sample */
0, 0,
&media_port);
if (status != PJ_SUCCESS) {
app_perror(THIS_FILE, "Unable to open WAV file for writing", status);
return;
}
*
/* Create a sound recorder device and connect the media port to the
* sound device.
*/

*status = pjmedia_snd_port_create_rec(
inv->pool, /* pool */
-1, /* sound dev id */
48000, /* clock rate */
2, /* channel count */
media_port->info.samples_per_frame, /* samples per frame*/
media_port->info.bits_per_sample, /* bits per sample */
0, /* options */
&g_snd_rec);
if (status != PJ_SUCCESS) {
app_perror( THIS_FILE, "Unable to create sound recorder", status);
return;
}

status = pjmedia_snd_port_connect(g_snd_rec, media_port);
* /* Done with media. */

}

-- 
Regards,

Chandrakant Solanki
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.pjsip.org/pipermail/pjsip_lists.pjsip.org/attachments/20101029/4f34f151/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: simpleua.c
Type: application/octet-stream
Size: 20128 bytes
Desc: not available
URL: <http://lists.pjsip.org/pipermail/pjsip_lists.pjsip.org/attachments/20101029/4f34f151/attachment-0001.c>


[Index of Archives]     [Asterisk Users]     [Asterisk App Development]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [Linux API]
  Powered by Linux