From a82abf01b16983b97036a5e0e11e70d188970256 Mon Sep 17 00:00:00 2001 From: Benny Prijono Date: Fri, 24 Mar 2006 20:44:27 +0000 Subject: Added more samples: WAV recorder, resample, etc., and also moved some common functions to util.h git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@361 74dad513-b988-da41-8d7b-12977e46ad98 --- pjsip-apps/src/samples/confsample.c | 127 +++++++++++++++++++++--------------- 1 file changed, 74 insertions(+), 53 deletions(-) (limited to 'pjsip-apps/src/samples/confsample.c') diff --git a/pjsip-apps/src/samples/confsample.c b/pjsip-apps/src/samples/confsample.c index bf786d65..843b99fa 100644 --- a/pjsip-apps/src/samples/confsample.c +++ b/pjsip-apps/src/samples/confsample.c @@ -18,6 +18,21 @@ */ #include +#include /* pj_getopt */ +#include + +#include /* atoi() */ +#include + +#include "util.h" + +/* For logging purpose. */ +#define THIS_FILE "confsample.c" + + +/* Shall we put recorder in the conference */ +#define RECORDER 1 + static const char *desc = " FILE: \n" @@ -30,9 +45,11 @@ static const char *desc = " \n" " USAGE: \n" " \n" - " confsample [file1.wav] [file2.wav] ... \n" + " confsample [options] [file1.wav] [file2.wav] ... \n" + " \n" + " options: \n" + SND_USAGE " \n" - " where: \n" " fileN.wav are optional WAV files to be connected to the conference \n" " bridge. The WAV files MUST have single channel (mono) and 16 bit PCM \n" " samples. It can have arbitrary sampling rate. \n" @@ -45,24 +62,9 @@ static const char *desc = " If WAV files are specified, the WAV file player ports will be connected \n" " to slot starting from number one in the bridge. The WAV files can have \n" " arbitrary sampling rate; the bridge will convert it to its clock rate. \n" - " However, the files MUST have a single audio channel only (i.e. mono). \n"; - -#include -#include - -#include /* atoi() */ -#include + " However, the files MUST have a single audio channel only (i.e. mono). \n"; -/* For logging purpose. */ -#define THIS_FILE "confsample.c" - -/* Constants */ -#define CLOCK_RATE 44100 -#define NSAMPLES (CLOCK_RATE * 20 / 1000) -#define NCHANNELS 1 -#define NBITS 16 - /* * Prototypes: @@ -75,19 +77,6 @@ static void conf_list(pjmedia_conf *conf, pj_bool_t detail); static void monitor_level(pjmedia_conf *conf, int slot, int dir, int dur); -/* Util to display the error message for the specified error code */ -static int app_perror( const char *sender, const char *title, - pj_status_t status) -{ - char errmsg[PJ_ERR_MSG_SIZE]; - - pj_strerror(status, errmsg, sizeof(errmsg)); - - printf("%s: %s [code=%d]\n", title, errmsg, status); - return 1; -} - - /* Show usage */ static void usage(void) { @@ -123,6 +112,12 @@ static pj_bool_t input(const char *title, char *buf, pj_size_t len) */ int main(int argc, char *argv[]) { + int dev_id = -1; + int clock_rate = CLOCK_RATE; + int channel_count = NCHANNELS; + int samples_per_frame = NSAMPLES; + int bits_per_sample = NBITS; + pj_caching_pool cp; pjmedia_endpt *med_endpt; pj_pool_t *pool; @@ -130,22 +125,24 @@ int main(int argc, char *argv[]) int i, port_count, file_count; pjmedia_port **file_port; /* Array of file ports */ + pjmedia_port *rec_port = NULL; /* Wav writer port */ char tmp[10]; pj_status_t status; - /* Just in case user needs help */ - if (argc > 1 && (*argv[1]=='-' || *argv[1]=='/' || *argv[1]=='?')) { - usage(); - return 1; - } - - /* Must init PJLIB first: */ status = pj_init(); PJ_ASSERT_RETURN(status == PJ_SUCCESS, 1); + /* Get command line options. */ + if (get_snd_options(THIS_FILE, argc, argv, &dev_id, &clock_rate, + &channel_count, &samples_per_frame, &bits_per_sample)) + { + usage(); + return 1; + } + /* Must create a pool factory before we can allocate any memory. */ pj_caching_pool_init(&cp, &pj_pool_factory_default_policy, 0); @@ -165,8 +162,8 @@ int main(int argc, char *argv[]) ); - file_count = argc-1; - port_count = file_count + 1; + file_count = argc - pj_optind; + port_count = file_count + 1 + RECORDER; /* Create the conference bridge. * With default options (zero), the bridge will create an instance of @@ -174,10 +171,10 @@ int main(int argc, char *argv[]) */ status = pjmedia_conf_create( pool, /* pool to use */ port_count,/* number of ports */ - CLOCK_RATE,/* sampling rate */ - NCHANNELS,/* # of channels. */ - NSAMPLES, /* samples per frame */ - NBITS, /* bits per sample */ + clock_rate, + channel_count, + samples_per_frame, + bits_per_sample, 0, /* options */ &conf /* result */ ); @@ -186,6 +183,20 @@ int main(int argc, char *argv[]) return 1; } +#if RECORDER + status = pjmedia_file_writer_port_create( pool, "confrecord.wav", + clock_rate, channel_count, + samples_per_frame, + bits_per_sample, 0, 0, NULL, + &rec_port); + if (status != PJ_SUCCESS) { + app_perror(THIS_FILE, "Unable to create WAV writer", status); + return 1; + } + + pjmedia_conf_add_port(conf, pool, rec_port, NULL, NULL); +#endif + /* Create file ports. */ file_port = pj_pool_alloc(pool, file_count * sizeof(pjmedia_port*)); @@ -193,16 +204,17 @@ int main(int argc, char *argv[]) for (i=0; iname.slen, port_info->name.ptr, port_info->clock_rate, + port_info->samples_per_frame, port_info->samples_per_frame*1000/port_info->clock_rate, port_info->tx_adj_level, port_info->rx_adj_level, -- cgit v1.2.3