Changeset 361


Ignore:
Timestamp:
Mar 24, 2006 8:44:27 PM (18 years ago)
Author:
bennylp
Message:

Added more samples: WAV recorder, resample, etc., and also moved some common functions to util.h

Location:
pjproject/trunk/pjsip-apps
Files:
2 added
10 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip-apps/build/Samples-vc.mak

    r344 r361  
    4040SAMPLES = $(BINDIR)\simpleua.exe $(BINDIR)\playfile.exe $(BINDIR)\playsine.exe \ 
    4141          $(BINDIR)\confsample.exe $(BINDIR)\sndinfo.exe \ 
    42           $(BINDIR)\level.exe 
     42          $(BINDIR)\level.exe $(BINDIR)\recfile.exe  \ 
     43          $(BINDIR)\resampleplay.exe 
     44 
    4345 
    4446all: $(OBJDIR) $(SAMPLES) 
    4547 
    46 $(SAMPLES): $(SRCDIR)\$(@B).c $(LIBS) Samples-vc.mak 
     48$(SAMPLES): $(SRCDIR)\$(@B).c $(LIBS) $(SRCDIR)\util.h Samples-vc.mak 
    4749        cl -nologo -c $(SRCDIR)\$(@B).c /Fo$(OBJDIR)\$(@B).obj $(CFLAGS)  
    4850        cl /nologo $(OBJDIR)\$(@B).obj /Fe$@ /Fm$(OBJDIR)\$(@B).map $(LDFLAGS) 
  • pjproject/trunk/pjsip-apps/build/Samples.mak

    r346 r361  
    3939BINDIR := ../bin/samples 
    4040 
    41 SAMPLES := simpleua playfile playsine confsample sndinfo level 
     41SAMPLES := simpleua playfile playsine confsample sndinfo level recfile resampleplay 
    4242 
    4343EXES := $(foreach file, $(SAMPLES), $(BINDIR)/$(file)-$(MACHINE_NAME)-$(OS_NAME)-$(CC_NAME)$(HOST_EXE)) 
  • pjproject/trunk/pjsip-apps/build/sample_debug.dsp

    r336 r361  
    5151LINK32=link.exe 
    5252# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 
    53 # ADD LINK32 ole32.lib user32.lib dsound.lib dxguid.lib netapi32.lib mswsock.lib ws2_32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:"../bin/samples/debug_vc6.exe" 
     53# ADD LINK32 ole32.lib user32.lib dsound.lib dxguid.lib netapi32.lib mswsock.lib ws2_32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:"../bin/samples/sampledebug_vc6.exe" 
    5454 
    5555!ELSEIF  "$(CFG)" == "sample_debug - Win32 Debug" 
     
    6767# PROP Target_Dir "" 
    6868# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c 
    69 # ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "../../pjsip/include" /I "../../pjlib/include" /I "../../pjlib-util/include" /I "../../pjmedia/include" /D PJ_WIN32=1 /D PJ_M_I386=1 /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /FR /YX /FD /GZ /c 
     69# ADD CPP /nologo /MTd /W4 /Gm /GX /ZI /Od /I "../../pjsip/include" /I "../../pjlib/include" /I "../../pjlib-util/include" /I "../../pjmedia/include" /D PJ_WIN32=1 /D PJ_M_I386=1 /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /FR /YX /FD /GZ /c 
    7070# ADD BASE RSC /l 0x409 /d "_DEBUG" 
    7171# ADD RSC /l 0x409 /d "_DEBUG" 
     
    7575LINK32=link.exe 
    7676# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept 
    77 # ADD LINK32 ole32.lib user32.lib dsound.lib dxguid.lib netapi32.lib mswsock.lib ws2_32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:"../bin/samples/debug_vc6d.exe" /pdbtype:sept 
     77# ADD LINK32 ole32.lib user32.lib dsound.lib dxguid.lib netapi32.lib mswsock.lib ws2_32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:"../bin/samples/sampledebug_vc6d.exe" /pdbtype:sept 
    7878 
    7979!ENDIF  
  • pjproject/trunk/pjsip-apps/build/samples.dsp

    r350 r361  
    103103# Begin Source File 
    104104 
     105SOURCE=..\src\samples\recfile.c 
     106# End Source File 
     107# Begin Source File 
     108 
     109SOURCE=..\src\samples\resampleplay.c 
     110# End Source File 
     111# Begin Source File 
     112 
    105113SOURCE=..\src\samples\simpleua.c 
    106114# End Source File 
  • pjproject/trunk/pjsip-apps/src/pjsip-perf/main.c

    r350 r361  
    1818 */ 
    1919#include "pjsip_perf.h" 
    20 #include <pjsua-lib/getopt.h> 
    2120#include <stdlib.h>             /* atoi */ 
    2221 
  • pjproject/trunk/pjsip-apps/src/samples/confsample.c

    r352 r361  
    1919 
    2020#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 
    2136 
    2237static const char *desc =  
     
    3146 " USAGE:                                                                   \n" 
    3247 "                                                                          \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" 
    3653 "  fileN.wav are optional WAV files to be connected to the conference      \n" 
    3754 "  bridge. The WAV files MUST have single channel (mono) and 16 bit PCM    \n" 
     
    4663 "  to slot starting from number one in the bridge. The WAV files can have  \n" 
    4764 "  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 
    6567 
    6668  
     
    7476/* Display VU meter */ 
    7577static 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 } 
    8978 
    9079 
     
    124113int main(int argc, char *argv[]) 
    125114{ 
     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 
    126121    pj_caching_pool cp; 
    127122    pjmedia_endpt *med_endpt; 
     
    131126    int i, port_count, file_count; 
    132127    pjmedia_port **file_port;   /* Array of file ports */ 
     128    pjmedia_port *rec_port = NULL;  /* Wav writer port */ 
    133129 
    134130    char tmp[10]; 
    135131    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     } 
    143132 
    144133 
     
    146135    status = pj_init(); 
    147136    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    } 
    148145 
    149146    /* Must create a pool factory before we can allocate any memory. */ 
     
    166163 
    167164 
    168     file_count = argc-1; 
    169     port_count = file_count + 1; 
     165    file_count = argc - pj_optind; 
     166    port_count = file_count + 1 + RECORDER; 
    170167 
    171168    /* Create the conference bridge.  
     
    175172    status = pjmedia_conf_create( pool,     /* pool to use          */ 
    176173                                  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, 
    181178                                  0,        /* options              */ 
    182179                                  &conf     /* result               */ 
     
    187184    } 
    188185 
     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 
    189200 
    190201    /* Create file ports. */ 
     
    194205 
    195206        /* 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                        ); 
    203215        if (status != PJ_SUCCESS) { 
    204216            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]); 
    206218            app_perror(THIS_FILE, title, status); 
    207219            usage(); 
     
    214226                                        file_port[i],   /* port to connect  */ 
    215227                                        NULL,           /* Use port's name  */ 
    216                                         NULL            /* ptr to receive slot # */ 
     228                                        NULL            /* ptr for slot #  */ 
    217229                                        ); 
    218230        if (status != PJ_SUCCESS) { 
     
    229241     */ 
    230242 
     243 
     244    /* Dump memory usage */ 
     245    dump_pool_usage(THIS_FILE, &cp); 
    231246 
    232247    /* Sleep to allow log messages to flush */ 
     
    421436    } 
    422437 
     438    /* Destroy recorder port */ 
     439    if (rec_port) 
     440        pjmedia_port_destroy(rec_port); 
     441 
    423442    /* Release application pool */ 
    424443    pj_pool_release( pool ); 
     
    484503                   "  Name                    : %.*s\n" 
    485504                   "  Sampling rate           : %d Hz\n" 
     505                   "  Samples per frame       : %d\n" 
    486506                   "  Frame time              : %d ms\n" 
    487507                   "  Signal level adjustment : tx=%d, rx=%d\n" 
     
    492512                   port_info->name.ptr, 
    493513                   port_info->clock_rate, 
     514                   port_info->samples_per_frame, 
    494515                   port_info->samples_per_frame*1000/port_info->clock_rate, 
    495516                   port_info->tx_adj_level, 
  • pjproject/trunk/pjsip-apps/src/samples/debug.c

    r336 r361  
    2828 *  #include "playfile.c" 
    2929 */ 
    30 #include "confsample.c" 
     30#include "resampleplay.c" 
    3131 
  • pjproject/trunk/pjsip-apps/src/samples/playfile.c

    r350 r361  
    1919 
    2020#include <pjmedia.h> 
     21#include <pjlib-util.h> 
     22#include <pjlib.h> 
     23#include <stdio.h> 
     24#include <stdlib.h> 
     25 
     26#include "util.h" 
     27 
    2128 
    2229/* 
     
    3441 */ 
    3542 
    36 #include <pjmedia.h> 
    37 #include <pjlib.h> 
    38  
    39 #include <stdio.h> 
    4043 
    4144/* For logging purpose. */ 
     
    4346 
    4447 
    45 /* Util to display the error message for the specified error code  */ 
    46 static int app_perror( const char *sender, const char *title,  
    47                        pj_status_t status) 
    48 { 
    49     char errmsg[PJ_ERR_MSG_SIZE]; 
    50  
    51     pj_strerror(status, errmsg, sizeof(errmsg)); 
    52  
    53     printf("%s: %s [code=%d]\n", title, errmsg, status); 
    54     return 1; 
    55 } 
     48static const char *desc =  
     49" FILE                                                              \n" 
     50"                                                                   \n" 
     51"  playfile.c                                                       \n" 
     52"                                                                   \n" 
     53" PURPOSE                                                           \n" 
     54"                                                                   \n" 
     55"  Demonstrate how to play a WAV file.                              \n" 
     56"                                                                   \n" 
     57" USAGE                                                             \n" 
     58"                                                                   \n" 
     59"  playfile FILE.WAV                                                \n" 
     60"                                                                   \n" 
     61"  The WAV file could have mono or stereo channels with arbitrary   \n" 
     62"  sampling rate, but MUST contain uncompressed (i.e. 16bit) PCM.   \n"; 
    5663 
    5764 
     
    6976    pj_status_t status; 
    7077 
    71  
    72     /* Verify cmd line arguments. */ 
    73     if (argc != 2) { 
    74         puts(""); 
    75         puts("Usage: "); 
    76         puts("  playfile <wav-file>"); 
    77         puts(""); 
    78         puts("The WAV file could have mono or stereo channels with arbitrary"); 
    79         puts("sampling rate, but MUST contain uncompressed (i.e. 16bit) PCM."); 
    80         return 0; 
    81     } 
    8278 
    8379    /* Must init PJLIB first: */ 
  • pjproject/trunk/pjsip-apps/src/samples/simpleua.c

    r350 r361  
    6262#define THIS_FILE   "simpleua.c" 
    6363 
     64#include "util.h" 
    6465 
    6566/* 
     
    125126 
    126127 
    127 /*  
    128  * Util to display the error message for the specified error code   
    129  */ 
    130 static int app_perror( const char *sender, const char *title,  
    131                        pj_status_t status) 
    132 { 
    133     char errmsg[PJ_ERR_MSG_SIZE]; 
    134  
    135     pj_strerror(status, errmsg, sizeof(errmsg)); 
    136  
    137     PJ_LOG(1,(sender, "%s: %s [code=%d]", title, errmsg, status)); 
    138     return 1; 
    139 } 
    140  
    141128 
    142129/* 
     
    416403    } 
    417404 
    418     /* On exit, dump memory usage: */ 
    419     { 
    420         pj_pool_t   *p; 
    421         unsigned     total_alloc = 0; 
    422         unsigned     total_used = 0; 
    423  
    424         /* Accumulate memory usage in active list. */ 
    425         p = cp.used_list.next; 
    426         while (p != (pj_pool_t*) &cp.used_list) { 
    427             total_alloc += pj_pool_get_capacity(p); 
    428             total_used += pj_pool_get_used_size(p); 
    429             p = p->next; 
    430         } 
    431  
    432         printf("Total pool memory allocated=%d KB, used=%d KB\n", 
    433                 total_alloc / 1000, 
    434                 total_used / 1000); 
    435     } 
     405    /* On exit, dump current memory usage: */ 
     406    dump_pool_usage(THIS_FILE, &cp); 
    436407 
    437408    return 0; 
  • pjproject/trunk/pjsip-apps/src/samples/util.h

    r328 r361  
    1  
    2 /* Include all PJSIP core headers. */ 
    3 #include <pjsip.h> 
    4  
    5 /* Include all PJMEDIA headers. */ 
    6 #include <pjmedia.h> 
    7  
    8 /* Include all PJMEDIA-CODEC headers. */ 
    9 #include <pjmedia-codec.h> 
    10  
    11 /* Include all PJSIP-UA headers */ 
    12 #include <pjsip_ua.h> 
    13  
    14 /* Include all PJSIP-SIMPLE headers */ 
    15 #include <pjsip_simple.h> 
    16  
    17 /* Include all PJLIB-UTIL headers. */ 
    18 #include <pjlib-util.h> 
    19  
    20 /* Include all PJLIB headers. */ 
    21 #include <pjlib.h> 
    221 
    232 
    24 /* Global endpoint instance. */ 
    25 static pjsip_endpoint *g_endpt; 
    26  
    27 /* Global caching pool factory. */ 
    28 static pj_caching_pool cp; 
    29  
    30 /* Global media endpoint. */ 
    31 static pjmedia_endpt *g_med_endpt; 
    32  
    33 /*  
    34  * Show error. 
    35  */ 
     3/* Util to display the error message for the specified error code  */ 
    364static int app_perror( const char *sender, const char *title,  
    375                       pj_status_t status) 
     
    419    pj_strerror(status, errmsg, sizeof(errmsg)); 
    4210 
    43     PJ_LOG(1,(sender, "%s: %s [code=%d]", title, errmsg, status)); 
     11    PJ_LOG(3,(sender, "%s: %s [code=%d]", title, errmsg, status)); 
    4412    return 1; 
    4513} 
    4614 
     15 
     16 
     17/* Constants */ 
     18#define CLOCK_RATE      44100 
     19#define NSAMPLES        (CLOCK_RATE * 20 / 1000) 
     20#define NCHANNELS       1 
     21#define NBITS           16 
     22 
    4723/* 
    48  * Perform the very basic initialization: 
    49  *  - init PJLIB. 
    50  *  - init memory pool 
    51  *  - create SIP endpoint instance. 
     24 * Common sound options. 
    5225 */ 
    53 static pj_status_t util_init(void) 
     26#define SND_USAGE   \ 
     27"  -d, --dev=NUM        Sound device use device id NUM (default=-1)      \n"\ 
     28"  -r, --rate=HZ        Set clock rate in samples per sec (default=44100)\n"\ 
     29"  -c, --channel=NUM    Set # of channels (default=1 for mono).          \n"\ 
     30"  -f, --frame=NUM      Set # of samples per frame (default equival 20ms)\n"\ 
     31"  -b, --bit=NUM        Set # of bits per sample (default=16)            \n" 
     32 
     33 
     34/* 
     35 * This utility function parses the command line and look for 
     36 * common sound options. 
     37 */ 
     38static pj_status_t get_snd_options( const char *app_name, 
     39                                    int argc,  
     40                                    char *argv[], 
     41                                    int *dev_id, 
     42                                    int *clock_rate, 
     43                                    int *channel_count, 
     44                                    int *samples_per_frame, 
     45                                    int *bits_per_sample) 
    5446{ 
    55     pj_status_t status; 
     47    struct pj_getopt_option long_options[] = { 
     48        { "dev",        1, 0, 'd' }, 
     49        { "rate",       1, 0, 'r' }, 
     50        { "channel",    1, 0, 'c' }, 
     51        { "frame",      1, 0, 'f' }, 
     52        { "bit",        1, 0, 'b' }, 
     53        { NULL, 0, 0, 0 }, 
     54    }; 
     55    int c; 
     56    int option_index; 
     57    long val; 
     58    char *err; 
    5659 
    57     /* Init PJLIB */ 
    58     status = pj_init(); 
    59     if (status != PJ_SUCCESS) { 
    60         app_perror(THIS_FILE, "pj_init() error", status); 
    61         return status; 
     60    *samples_per_frame = 0; 
     61 
     62    pj_optind = 0; 
     63    while((c=pj_getopt_long(argc,argv, "d:r:c:f:b:",  
     64                            long_options, &option_index))!=-1)  
     65    { 
     66 
     67        switch (c) { 
     68        case 'd': 
     69            /* device */ 
     70            val = strtol(pj_optarg, &err, 10); 
     71            if (*err) { 
     72                PJ_LOG(3,(app_name, "Error: invalid value for device id")); 
     73                return PJ_EINVAL; 
     74            } 
     75            *dev_id = val; 
     76            break; 
     77 
     78        case 'r': 
     79            /* rate */ 
     80            val = strtol(pj_optarg, &err, 10); 
     81            if (*err) { 
     82                PJ_LOG(3,(app_name, "Error: invalid value for clock rate")); 
     83                return PJ_EINVAL; 
     84            } 
     85            *clock_rate = val; 
     86            break; 
     87 
     88        case 'c': 
     89            /* channel count */ 
     90            val = strtol(pj_optarg, &err, 10); 
     91            if (*err) { 
     92                PJ_LOG(3,(app_name, "Error: invalid channel count")); 
     93                return PJ_EINVAL; 
     94            } 
     95            *channel_count = val; 
     96            break; 
     97 
     98        case 'f': 
     99            /* frame count/samples per frame */ 
     100            val = strtol(pj_optarg, &err, 10); 
     101            if (*err) { 
     102                PJ_LOG(3,(app_name, "Error: invalid samples per frame")); 
     103                return PJ_EINVAL; 
     104            } 
     105            *samples_per_frame = val; 
     106            break; 
     107 
     108        case 'b': 
     109            /* bit per sample */ 
     110            val = strtol(pj_optarg, &err, 10); 
     111            if (*err) { 
     112                PJ_LOG(3,(app_name, "Error: invalid samples bits per sample")); 
     113                return PJ_EINVAL; 
     114            } 
     115            *bits_per_sample = val; 
     116            break; 
     117 
     118        default: 
     119            /* Unknown options */ 
     120            PJ_LOG(3,(app_name, "Error: unknown options '%c'", pj_optopt)); 
     121            return PJ_EINVAL; 
     122        } 
     123 
    62124    } 
    63125 
    64     /* Init PJLIB-UTIL: */ 
    65     status = pjlib_util_init(); 
    66     if (status != PJ_SUCCESS) { 
    67         app_perror(THIS_FILE, "pjlib_util_init() error", status); 
    68         return status; 
     126    if (*samples_per_frame == 0) { 
     127        *samples_per_frame = *clock_rate * *channel_count * 20 / 1000; 
    69128    } 
    70129 
    71     /* Init memory pool: */ 
     130    return 0; 
     131} 
    72132 
    73     /* Init caching pool. */ 
    74     pj_caching_pool_init(&cp, &pj_pool_factory_default_policy, 0); 
    75133 
    76     /* Create global endpoint: */ 
     134/* Dump memory pool usage. */ 
     135static void dump_pool_usage( const char *app_name, pj_caching_pool *cp ) 
     136{ 
     137    pj_pool_t   *p; 
     138    unsigned     total_alloc = 0; 
     139    unsigned     total_used = 0; 
    77140 
    78     { 
    79         const pj_str_t *hostname; 
    80         const char *endpt_name; 
    81  
    82         /* Endpoint MUST be assigned a globally unique name. 
    83          * The name will be used as the hostname in Warning header. 
    84          */ 
    85  
    86         /* For this implementation, we'll use hostname for simplicity */ 
    87         hostname = pj_gethostname(); 
    88         endpt_name = hostname->ptr; 
    89  
    90         /* Create the endpoint: */ 
    91  
    92         status = pjsip_endpt_create(&cp.factory, endpt_name,  
    93                                     &g_endpt); 
    94         if (status != PJ_SUCCESS) { 
    95             app_perror(THIS_FILE, "Unable to create SIP endpoint", status); 
    96             return status; 
    97         } 
     141    /* Accumulate memory usage in active list. */ 
     142    p = cp->used_list.next; 
     143    while (p != (pj_pool_t*) &cp->used_list) { 
     144        total_alloc += pj_pool_get_capacity(p); 
     145        total_used += pj_pool_get_used_size(p); 
     146        p = p->next; 
    98147    } 
    99148 
    100     return PJ_SUCCESS; 
     149    PJ_LOG(3, (app_name, "Total pool memory allocated=%d KB, used=%d KB", 
     150               total_alloc / 1000, 
     151               total_used / 1000)); 
    101152} 
    102  
    103 /* 
    104  * Add UDP transport to endpoint. 
    105  */ 
    106 static pj_status_t util_add_udp_transport(int port) 
    107 { 
    108     pj_sockaddr_in addr; 
    109     pj_status_t status; 
    110      
    111     addr.sin_family = PJ_AF_INET; 
    112     addr.sin_addr.s_addr = 0; 
    113     addr.sin_port = port; 
    114  
    115     status = pjsip_udp_transport_start( g_endpt, &addr, NULL, 1, NULL); 
    116     if (status != PJ_SUCCESS) { 
    117         app_perror(THIS_FILE, "Unable to start UDP transport", status); 
    118         return status; 
    119     } 
    120  
    121     return status; 
    122 } 
    123  
Note: See TracChangeset for help on using the changeset viewer.