Changeset 4790 for pjproject


Ignore:
Timestamp:
Mar 11, 2014 7:03:22 AM (10 years ago)
Author:
riza
Message:

Re #1742 (misc): Add input file checking on pjsua2_demo

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip-apps/src/samples/pjsua2_demo.cpp

    r4708 r4790  
    2222#include <pj/file_access.h> 
    2323 
     24#define THIS_FILE       "pjsua2_demo.cpp" 
     25 
    2426using namespace pj; 
    2527 
     
    105107} 
    106108 
    107 static void mainProg1() throw(Error) 
    108 { 
    109     Endpoint ep; 
    110  
    111     // Create library 
    112     ep.libCreate(); 
    113  
     109static void mainProg1(Endpoint &ep) throw(Error) 
     110{ 
    114111    // Init library 
    115112    EpConfig ep_cfg; 
     
    154151} 
    155152 
    156 void mainProg2() throw(Error) 
    157 { 
    158     Endpoint ep; 
    159  
    160     // Create library 
    161     ep.libCreate(); 
    162  
     153static void mainProg2() throw(Error) 
     154{ 
    163155    string json_str; 
    164  
    165156    { 
    166157        EpConfig epCfg; 
     
    203194        pj_file_delete("jsontest.js"); 
    204195    } 
    205  
    206     ep.libDestroy(); 
    207 } 
    208  
    209  
    210 void mainProg3() throw(Error) 
    211 { 
    212     Endpoint ep; 
    213  
    214     // Create library 
    215     ep.libCreate(); 
     196} 
     197 
     198 
     199static void mainProg3(Endpoint &ep) throw(Error) 
     200{ 
     201    const char *paths[] = { "../../../../tests/pjsua/wavs/input.16.wav", 
     202                            "../../tests/pjsua/wavs/input.16.wav", 
     203                            "input.16.wav"}; 
     204    unsigned i; 
     205    const char *filename = NULL; 
    216206 
    217207    // Init library 
     
    219209    ep.libInit( ep_cfg ); 
    220210 
     211    for (i=0; i<PJ_ARRAY_SIZE(paths); ++i) { 
     212       if (pj_file_exists(paths[i])) { 
     213          filename = paths[i]; 
     214          break; 
     215       } 
     216    } 
     217 
     218    if (!filename) { 
     219        PJSUA2_RAISE_ERROR3(PJ_ENOTFOUND, "mainProg3()", 
     220                           "Could not locate input.16.wav"); 
     221    } 
     222 
    221223    // Start library 
    222224    ep.libStart(); 
     
    226228    { 
    227229        AudioMediaPlayer amp; 
    228         amp.createPlayer("../../tests/pjsua/wavs/input.16.wav"); 
     230        amp.createPlayer(filename); 
    229231 
    230232        AudioMediaRecorder amr; 
     
    236238        pj_thread_sleep(5000); 
    237239    } 
    238  
    239     ep.libDestroy(); 
    240 } 
    241  
    242  
    243 void mainProg() throw(Error) 
    244 { 
    245     Endpoint ep; 
    246  
    247     // Create library 
    248     ep.libCreate(); 
    249  
     240} 
     241 
     242 
     243static void mainProg() throw(Error) 
     244{ 
    250245    string json_str; 
    251246 
     
    295290        std::cout << json_str << std::endl << std::endl; 
    296291    } 
    297  
    298     ep.libDestroy(); 
    299292} 
    300293 
     
    302295{ 
    303296    int ret = 0; 
    304  
    305     /* Test endpoint instantiation and destruction without libCreate(), 
    306      * libInit() etc. 
    307      */ 
    308     { 
    309         Endpoint ep; 
    310     } 
     297    Endpoint ep; 
    311298 
    312299    try { 
    313         mainProg3(); 
    314         std::cout << "Success" << std::endl; 
     300        ep.libCreate(); 
     301 
     302        mainProg3(ep); 
     303        ret = PJ_SUCCESS; 
    315304    } catch (Error & err) { 
    316305        std::cout << "Exception: " << err.info() << std::endl; 
     
    318307    } 
    319308 
     309    try { 
     310        ep.libDestroy(); 
     311    } catch(Error &err) { 
     312        std::cout << "Exception: " << err.info() << std::endl; 
     313        ret = 1; 
     314    } 
     315 
     316    if (ret == PJ_SUCCESS) { 
     317        std::cout << "Success" << std::endl; 
     318    } else { 
     319        std::cout << "Error Found" << std::endl; 
     320    } 
     321 
    320322    return ret; 
    321323} 
Note: See TracChangeset for help on using the changeset viewer.