Changeset 361 for pjproject/trunk/pjsip-apps/src/samples/confsample.c
- Timestamp:
- Mar 24, 2006 8:44:27 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip-apps/src/samples/confsample.c
r352 r361 19 19 20 20 #include <pjmedia.h> 21 #include <pjlib-util.h> /* pj_getopt */ 22 #include <pjlib.h> 23 24 #include <stdlib.h> /* atoi() */ 25 #include <stdio.h> 26 27 #include "util.h" 28 29 /* For logging purpose. */ 30 #define THIS_FILE "confsample.c" 31 32 33 /* Shall we put recorder in the conference */ 34 #define RECORDER 1 35 21 36 22 37 static const char *desc = … … 31 46 " USAGE: \n" 32 47 " \n" 33 " confsample [file1.wav] [file2.wav] ... \n" 34 " \n" 35 " where: \n" 48 " confsample [options] [file1.wav] [file2.wav] ... \n" 49 " \n" 50 " options: \n" 51 SND_USAGE 52 " \n" 36 53 " fileN.wav are optional WAV files to be connected to the conference \n" 37 54 " bridge. The WAV files MUST have single channel (mono) and 16 bit PCM \n" … … 46 63 " to slot starting from number one in the bridge. The WAV files can have \n" 47 64 " arbitrary sampling rate; the bridge will convert it to its clock rate. \n" 48 " However, the files MUST have a single audio channel only (i.e. mono). \n"; 49 50 #include <pjmedia.h> 51 #include <pjlib.h> 52 53 #include <stdlib.h> /* atoi() */ 54 #include <stdio.h> 55 56 57 /* For logging purpose. */ 58 #define THIS_FILE "confsample.c" 59 60 /* Constants */ 61 #define CLOCK_RATE 44100 62 #define NSAMPLES (CLOCK_RATE * 20 / 1000) 63 #define NCHANNELS 1 64 #define NBITS 16 65 " However, the files MUST have a single audio channel only (i.e. mono). \n"; 66 65 67 66 68 … … 74 76 /* Display VU meter */ 75 77 static void monitor_level(pjmedia_conf *conf, int slot, int dir, int dur); 76 77 78 /* Util to display the error message for the specified error code */79 static int app_perror( const char *sender, const char *title,80 pj_status_t status)81 {82 char errmsg[PJ_ERR_MSG_SIZE];83 84 pj_strerror(status, errmsg, sizeof(errmsg));85 86 printf("%s: %s [code=%d]\n", title, errmsg, status);87 return 1;88 }89 78 90 79 … … 124 113 int main(int argc, char *argv[]) 125 114 { 115 int dev_id = -1; 116 int clock_rate = CLOCK_RATE; 117 int channel_count = NCHANNELS; 118 int samples_per_frame = NSAMPLES; 119 int bits_per_sample = NBITS; 120 126 121 pj_caching_pool cp; 127 122 pjmedia_endpt *med_endpt; … … 131 126 int i, port_count, file_count; 132 127 pjmedia_port **file_port; /* Array of file ports */ 128 pjmedia_port *rec_port = NULL; /* Wav writer port */ 133 129 134 130 char tmp[10]; 135 131 pj_status_t status; 136 137 138 /* Just in case user needs help */139 if (argc > 1 && (*argv[1]=='-' || *argv[1]=='/' || *argv[1]=='?')) {140 usage();141 return 1;142 }143 132 144 133 … … 146 135 status = pj_init(); 147 136 PJ_ASSERT_RETURN(status == PJ_SUCCESS, 1); 137 138 /* Get command line options. */ 139 if (get_snd_options(THIS_FILE, argc, argv, &dev_id, &clock_rate, 140 &channel_count, &samples_per_frame, &bits_per_sample)) 141 { 142 usage(); 143 return 1; 144 } 148 145 149 146 /* Must create a pool factory before we can allocate any memory. */ … … 166 163 167 164 168 file_count = argc -1;169 port_count = file_count + 1 ;165 file_count = argc - pj_optind; 166 port_count = file_count + 1 + RECORDER; 170 167 171 168 /* Create the conference bridge. … … 175 172 status = pjmedia_conf_create( pool, /* pool to use */ 176 173 port_count,/* number of ports */ 177 CLOCK_RATE,/* sampling rate */178 NCHANNELS,/* # of channels. */179 NSAMPLES, /* samples per frame */180 NBITS, /* bits per sample */174 clock_rate, 175 channel_count, 176 samples_per_frame, 177 bits_per_sample, 181 178 0, /* options */ 182 179 &conf /* result */ … … 187 184 } 188 185 186 #if RECORDER 187 status = pjmedia_file_writer_port_create( pool, "confrecord.wav", 188 clock_rate, channel_count, 189 samples_per_frame, 190 bits_per_sample, 0, 0, NULL, 191 &rec_port); 192 if (status != PJ_SUCCESS) { 193 app_perror(THIS_FILE, "Unable to create WAV writer", status); 194 return 1; 195 } 196 197 pjmedia_conf_add_port(conf, pool, rec_port, NULL, NULL); 198 #endif 199 189 200 190 201 /* Create file ports. */ … … 194 205 195 206 /* Load the WAV file to file port. */ 196 status = pjmedia_file_player_port_create( pool, /* pool. */ 197 argv[i+1],/* filename */ 198 0, /* flags */ 199 0, /* buf size */ 200 NULL, /* user data */ 201 &file_port[i] /* result */ 202 ); 207 status = pjmedia_file_player_port_create( 208 pool, /* pool. */ 209 argv[i+pj_optind], /* filename */ 210 0, /* flags */ 211 0, /* buf size */ 212 NULL, /* user data */ 213 &file_port[i] /* result */ 214 ); 203 215 if (status != PJ_SUCCESS) { 204 216 char title[80]; 205 pj_ansi_sprintf(title, "Unable to use %s", argv[i+ 1]);217 pj_ansi_sprintf(title, "Unable to use %s", argv[i+pj_optind]); 206 218 app_perror(THIS_FILE, title, status); 207 219 usage(); … … 214 226 file_port[i], /* port to connect */ 215 227 NULL, /* Use port's name */ 216 NULL /* ptr to receive slot #*/228 NULL /* ptr for slot # */ 217 229 ); 218 230 if (status != PJ_SUCCESS) { … … 229 241 */ 230 242 243 244 /* Dump memory usage */ 245 dump_pool_usage(THIS_FILE, &cp); 231 246 232 247 /* Sleep to allow log messages to flush */ … … 421 436 } 422 437 438 /* Destroy recorder port */ 439 if (rec_port) 440 pjmedia_port_destroy(rec_port); 441 423 442 /* Release application pool */ 424 443 pj_pool_release( pool ); … … 484 503 " Name : %.*s\n" 485 504 " Sampling rate : %d Hz\n" 505 " Samples per frame : %d\n" 486 506 " Frame time : %d ms\n" 487 507 " Signal level adjustment : tx=%d, rx=%d\n" … … 492 512 port_info->name.ptr, 493 513 port_info->clock_rate, 514 port_info->samples_per_frame, 494 515 port_info->samples_per_frame*1000/port_info->clock_rate, 495 516 port_info->tx_adj_level,
Note: See TracChangeset
for help on using the changeset viewer.