Cannot connect pjmedia_ports through pjsua_conf

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

 



(...again, sorry if this is a repost - I think the mailing list had a problem
with "gmail" vs. "googlemail" in my address. This is the last time, I
promise!)



Hi there, I was wondering if somebody could shed some light on this
for me, as I'm obviously doing something very wrong!

Basically, I'm trying to set up pjsua, add some pjmedia_ports to it
and connect them to each other. Originally I wanted to route a wav
player port through to a stream (just for testing purposes at this
point), but couldn't get that to work, so I concocted the following
example, which is a wav player to a wav recorder. It takes two file
names as arguments, and plays the first file through the pjsua_conf to
the second file. The lines that are commented out are me doing this
through a pjmedia_master_port, which works just fine, but when I try
and do it through pjsua's conference bridge, it seems to play
something through to the destination wav file (i.e. the size of the
file on my system gets larger) but when I try and play it, it doesn't
play anything (and takes no time to play it - aplay just returns
immediately, it doesn't "play" a few seconds of silence or anything).

Anyway, here's the code - I hope someone can help me figure out what I
should do that's different!


#include <strings.h>
#include <stdio.h>

#include <pjlib.h>
#include <pjmedia.h>
#include <pjsua-lib/pjsua.h>


#define CLOCK_SPKR                44100
#define MONO                      1
#define STEREO                    2
#define SAMPLES_PER_FRAME(CK,CH)  (CH * (CK * 20 / 1000))
#define BITS_PER_SAMPLE           16


#define CHECK(X)                                  \
                       status = (X);                         \
                       if (status != PJ_SUCCESS) {           \
                               printf("error: " #X "\n");        \
                               return 1;                         \
                       }

int main(int argc, char *argv[])
{
       if (argc != 3)
       {
               printf("Usage: %s in-file.wav out-file.wav\n", argv[0]);
               return 1;
       }


       pj_status_t status;

       pj_pool_t *pool;


       /* initiation */

       CHECK( pjsua_create() );
       CHECK( pjsua_init(NULL, NULL, NULL) );
       CHECK( pjsua_set_null_snd_dev() );
       CHECK( pjsua_start() );
       pool = pjsua_pool_create("pool", 0x1000, 0x1000);


       /* wav player */

       pjmedia_port       *player_port;

       unsigned int wav_ptime = SAMPLES_PER_FRAME(CLOCK_SPKR,MONO) * 1000 /
CLOCK_SPKR;
       CHECK( pjmedia_wav_player_port_create(
                       pool,
                       argv[1],
                       wav_ptime,
                       0,
                       -1,
                       &player_port) );


       /* wav recorder */

       pjmedia_port       *recorder_port;

       CHECK( pjmedia_wav_writer_port_create(
                       pool,
                       argv[2],
                       CLOCK_SPKR,
                       MONO,
                       SAMPLES_PER_FRAME(CLOCK_SPKR,MONO),
                       BITS_PER_SAMPLE,
                       0,
                       0,
                       &recorder_port) );


       /* add to conf port and connect */

       pjsua_conf_port_id  recorder_id;
       pjsua_conf_port_id  player_id;

       CHECK( pjsua_conf_add_port(
                       pool,
                       player_port,
                       &player_id) );

       CHECK( pjsua_conf_add_port(
                       pool,
                       recorder_port,
                       &recorder_id) );

       CHECK( pjsua_conf_connect(
                       player_id,
                       recorder_id) );

       /* use these lines and comment-out above to use
          master port instead */
//      pjmedia_master_port *master_port;
//      CHECK( pjmedia_master_port_create(
//         pool, player_port, recorder_port, 0, &master_port));
//      CHECK( pjmedia_master_port_start(master_port) );


       printf("*** Waiting for user input ***\n");

       getchar();

//      CHECK( pjmedia_master_port_destroy(master_port, PJ_TRUE) );
       CHECK( pjsua_destroy() );

       return 0;
}



[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