Ignore:
Timestamp:
Jan 28, 2009 6:03:12 PM (15 years ago)
Author:
nanang
Message:

Initial sources of APS-direct.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/branches/projects/aps-direct/pjsip-apps/src/symsndtest/app_main.cpp

    r2394 r2434  
    5050 
    5151    PJ_UNUSED_ARG(level); 
    52      
     52 
    5353    pj_ansi_to_unicode(buf, len, buf16, PJ_ARRAY_SIZE(buf16)); 
    5454 
     
    5858 
    5959/* perror util */ 
    60 static void app_perror(const char *title, pj_status_t status)  
    61 { 
    62     char errmsg[PJ_ERR_MSG_SIZE];        
     60static void app_perror(const char *title, pj_status_t status) 
     61{ 
     62    char errmsg[PJ_ERR_MSG_SIZE]; 
    6363    pj_strerror(status, errmsg, sizeof(errmsg)); 
    6464    PJ_LOG(1,(THIS_FILE, "Error: %s: %s", title, errmsg)); 
     
    6666 
    6767/* Application init */ 
    68 static pj_status_t app_init()  
     68static pj_status_t app_init() 
    6969{ 
    7070    unsigned i, count; 
    7171    pj_status_t status; 
    72     
     72 
    7373    /* Redirect log */ 
    7474    pj_log_set_log_func((void (*)(int,const char*,int)) &log_writer); 
    7575    pj_log_set_decor(PJ_LOG_HAS_NEWLINE); 
    7676    pj_log_set_level(3); 
    77      
     77 
    7878    /* Init pjlib */ 
    7979    status = pj_init(); 
     
    8484 
    8585    pj_caching_pool_init(&cp, NULL, 0); 
    86      
     86 
    8787    /* Init sound subsystem */ 
    8888    status = pjmedia_snd_init(&cp.factory); 
     
    9393        return status; 
    9494    } 
    95      
     95 
    9696    count = pjmedia_snd_get_dev_count(); 
    9797    PJ_LOG(3,(THIS_FILE, "Device count: %d", count)); 
    9898    for (i=0; i<count; ++i) { 
    9999        const pjmedia_snd_dev_info *info; 
    100          
     100 
    101101        info = pjmedia_snd_get_dev_info(i); 
    102102        PJ_LOG(3, (THIS_FILE, "%d: %s %d/%d %dHz", 
    103103                   i, info->name, info->input_count, info->output_count, 
    104                    info->default_samples_per_sec));      
     104                   info->default_samples_per_sec)); 
    105105    } 
    106106 
     
    115115 
    116116    /* Init delay buffer */ 
    117     status = pjmedia_delay_buf_create(pool, THIS_FILE, CLOCK_RATE,  
    118                                       SAMPLES_PER_FRAME, CHANNEL_COUNT,  
     117    status = pjmedia_delay_buf_create(pool, THIS_FILE, CLOCK_RATE, 
     118                                      SAMPLES_PER_FRAME, CHANNEL_COUNT, 
    119119                                      0, 0, &delaybuf); 
    120120    if (status != PJ_SUCCESS) { 
     
    124124        //return status; 
    125125    } 
    126      
     126 
    127127    return PJ_SUCCESS; 
    128128} 
     
    130130 
    131131/* Sound capture callback */ 
    132 static pj_status_t rec_cb(void *user_data,  
     132static pj_status_t rec_cb(void *user_data, 
    133133                          pj_uint32_t timestamp, 
    134134                          void *input, 
    135                           unsigned size)  
     135                          unsigned size) 
    136136{ 
    137137    PJ_UNUSED_ARG(user_data); 
     
    154154                           pj_uint32_t timestamp, 
    155155                           void *output, 
    156                            unsigned size)  
     156                           unsigned size) 
    157157{ 
    158158    PJ_UNUSED_ARG(user_data); 
    159159    PJ_UNUSED_ARG(timestamp); 
    160160    PJ_UNUSED_ARG(size); 
    161      
     161 
    162162    pjmedia_delay_buf_get(delaybuf, (pj_int16_t*)output); 
    163      
     163 
    164164    ++play_cnt; 
    165     return PJ_SUCCESS;   
     165    return PJ_SUCCESS; 
    166166} 
    167167 
    168168/* Start sound */ 
    169 static pj_status_t snd_start(unsigned flag)  
     169static pj_status_t snd_start(unsigned flag) 
    170170{ 
    171171    pj_status_t status; 
    172      
     172 
    173173    if (strm != NULL) { 
    174174        app_perror("snd already open", PJ_EINVALIDOP); 
    175175        return PJ_EINVALIDOP; 
    176176    } 
    177      
     177 
    178178    if (flag==PJMEDIA_DIR_CAPTURE_PLAYBACK) 
    179179        status = pjmedia_snd_open(-1, -1, CLOCK_RATE, CHANNEL_COUNT, 
     
    188188                                         SAMPLES_PER_FRAME, BITS_PER_SAMPLE, 
    189189                                         &play_cb, NULL, &strm); 
    190                           
     190 
    191191    if (status != PJ_SUCCESS) { 
    192192        app_perror("snd open", status); 
     
    211211 
    212212/* Stop sound */ 
    213 static pj_status_t snd_stop()  
     213static pj_status_t snd_stop() 
    214214{ 
    215215    pj_time_val now; 
    216216    pj_status_t status; 
    217      
     217 
    218218    if (strm == NULL) { 
    219219        app_perror("snd not open", PJ_EINVALIDOP); 
    220220        return PJ_EINVALIDOP; 
    221221    } 
    222      
     222 
     223    status = pjmedia_snd_stream_stop(strm); 
     224    if (status != PJ_SUCCESS) { 
     225        app_perror("snd failed to stop", status); 
     226    } 
    223227    status = pjmedia_snd_stream_close(strm); 
    224228    strm = NULL; 
    225      
     229 
    226230    pj_gettimeofday(&now); 
    227231    PJ_TIME_VAL_SUB(now, t_start); 
     
    235239 
    236240/* Shutdown application */ 
    237 static void app_fini()  
     241static void app_fini() 
    238242{ 
    239243    if (strm) 
    240244        snd_stop(); 
    241      
     245 
    242246    pjmedia_snd_deinit(); 
    243247    pjmedia_delay_buf_destroy(delaybuf); 
     
    254258#include <e32base.h> 
    255259 
    256 class ConsoleUI : public CActive  
     260class ConsoleUI : public CActive 
    257261{ 
    258262public: 
    259     ConsoleUI(CActiveSchedulerWait *asw, CConsoleBase *con); 
     263    ConsoleUI(CConsoleBase *con); 
    260264 
    261265    // Run console UI 
     
    264268    // Stop 
    265269    void Stop(); 
    266      
     270 
    267271protected: 
    268272    // Cancel asynchronous read. 
     
    271275    // Implementation: called when read has completed. 
    272276    void RunL(); 
    273      
     277 
    274278private: 
    275     CActiveSchedulerWait *asw_; 
    276279    CConsoleBase *con_; 
    277280}; 
    278281 
    279282 
    280 ConsoleUI::ConsoleUI(CActiveSchedulerWait *asw, CConsoleBase *con)  
    281 : CActive(EPriorityHigh), asw_(asw), con_(con) 
     283ConsoleUI::ConsoleUI(CConsoleBase *con) 
     284: CActive(EPriorityUserInput), con_(con) 
    282285{ 
    283286    CActiveScheduler::Add(this); 
     
    285288 
    286289// Run console UI 
    287 void ConsoleUI::Run()  
     290void ConsoleUI::Run() 
    288291{ 
    289292    con_->Read(iStatus); 
     
    292295 
    293296// Stop console UI 
    294 void ConsoleUI::Stop()  
     297void ConsoleUI::Stop() 
    295298{ 
    296299    DoCancel(); 
     
    298301 
    299302// Cancel asynchronous read. 
    300 void ConsoleUI::DoCancel()  
     303void ConsoleUI::DoCancel() 
    301304{ 
    302305    con_->ReadCancel(); 
    303306} 
    304307 
    305 static void PrintMenu()  
     308static void PrintMenu() 
    306309{ 
    307310    PJ_LOG(3, (THIS_FILE, "\n\n" 
     
    315318 
    316319// Implementation: called when read has completed. 
    317 void ConsoleUI::RunL()  
     320void ConsoleUI::RunL() 
    318321{ 
    319322    TKeyCode kc = con_->KeyCode(); 
    320323    pj_bool_t reschedule = PJ_TRUE; 
    321      
     324 
    322325    switch (kc) { 
    323326    case 'w': 
    324             asw_->AsyncStop(); 
     327            snd_stop(); 
     328            CActiveScheduler::Stop(); 
    325329            reschedule = PJ_FALSE; 
    326330            break; 
     
    344348 
    345349    PrintMenu(); 
    346      
     350 
    347351    if (reschedule) 
    348352        Run(); 
     
    351355 
    352356//////////////////////////////////////////////////////////////////////////// 
    353 int app_main()  
     357int app_main() 
    354358{ 
    355359    if (app_init() != PJ_SUCCESS) 
    356360        return -1; 
    357      
     361 
    358362    // Run the UI 
    359     CActiveSchedulerWait *asw = new CActiveSchedulerWait; 
    360     ConsoleUI *con = new ConsoleUI(asw, console); 
    361      
     363    ConsoleUI *con = new ConsoleUI(console); 
     364 
    362365    con->Run(); 
    363      
     366 
    364367    PrintMenu(); 
    365     asw->Start(); 
    366      
     368    CActiveScheduler::Start(); 
     369 
    367370    delete con; 
    368     delete asw; 
    369      
     371 
    370372    app_fini(); 
    371373    return 0; 
Note: See TracChangeset for help on using the changeset viewer.