Changeset 1641


Ignore:
Timestamp:
Dec 28, 2007 6:55:02 PM (16 years ago)
Author:
bennylp
Message:

Ticket #435: Fixed and tested audio on Symbian device

Location:
pjproject/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjlib/include/pj/config_site_sample.h

    r1576 r1641  
    7777#   define PJSIP_MAX_DIALOG_COUNT       31 
    7878#   define PJSUA_MAX_CALLS              31 
    79      
     79 
     80#       define PJMEDIA_SOUND_BUFFER_COUNT 12 
     81 
    8082#endif 
    8183 
  • pjproject/trunk/pjmedia/src/pjmedia/symbian_sound.cpp

    r1428 r1641  
    6565 
    6666    // Common settings. 
     67    pjmedia_dir                  dir; 
    6768    unsigned                     clock_rate; 
    6869    unsigned                     channel_count; 
     
    163164    pj_uint32_t              timeStamp_; 
    164165 
     166    // cache variable 
     167    // to avoid calculating frame length repeatedly 
     168    TInt                          frameLen_; 
     169     
     170    // in some SymbianOS (e.g: OSv9.1), sometimes recorded size != requested framesize 
     171    // so let's provide a buffer to make sure the rec callback returns framesize as requested. 
     172    TUint8                   *frameRecBuf_; 
     173    TInt                          frameRecBufLen_; 
     174 
    165175    CPjAudioInputEngine(pjmedia_snd_stream *parent_strm, 
    166176                        pjmedia_snd_rec_cb rec_cb, 
     
    180190                                         pjmedia_snd_rec_cb rec_cb, 
    181191                                         void *user_data) 
    182     : state_(STATE_INACTIVE), parentStrm_(parent_strm), recCb_(rec_cb),  
     192    : state_(STATE_INACTIVE), parentStrm_(parent_strm),  
     193      recCb_(rec_cb), userData_(user_data),  
    183194      iInputStream_(NULL), iStreamBuffer_(NULL), iFramePtr_(0, 0), 
    184       userData_(user_data), lastError_(KErrNone), timeStamp_(0) 
     195      lastError_(KErrNone), timeStamp_(0), 
     196      frameLen_(parent_strm->samples_per_frame * parent_strm->channel_count * BYTES_PER_SAMPLE), 
     197      frameRecBuf_(NULL), frameRecBufLen_(0) 
    185198{ 
    186199} 
     
    189202{ 
    190203    Stop(); 
     204 
    191205    delete iStreamBuffer_; 
    192206    iStreamBuffer_ = NULL; 
     207     
     208    delete [] frameRecBuf_; 
     209    frameRecBuf_ = NULL; 
     210    frameRecBufLen_ = 0; 
    193211} 
    194212 
    195213void CPjAudioInputEngine::ConstructL() 
    196214{ 
    197     iStreamBuffer_ = HBufC8::NewL(parentStrm_->samples_per_frame * 
    198                                   parentStrm_->channel_count *  
    199                                   BYTES_PER_SAMPLE); 
     215    iStreamBuffer_ = HBufC8::NewL(frameLen_); 
     216    CleanupStack::PushL(iStreamBuffer_); 
     217 
     218    frameRecBuf_ = new TUint8[frameLen_*2]; 
     219    CleanupStack::PushL(frameRecBuf_); 
    200220} 
    201221 
     
    217237{ 
    218238    CPjAudioInputEngine *self = NewLC(parent, rec_cb, user_data); 
     239    CleanupStack::Pop(self->frameRecBuf_); 
     240    CleanupStack::Pop(self->iStreamBuffer_); 
    219241    CleanupStack::Pop(self); 
    220242    return self; 
     
    290312TPtr8 & CPjAudioInputEngine::GetFrame()  
    291313{ 
    292     TInt l = parentStrm_->samples_per_frame * 
    293              parentStrm_->channel_count *  
    294              BYTES_PER_SAMPLE; 
    295     iStreamBuffer_->Des().FillZ(l); 
    296     iFramePtr_.Set((TUint8*)(iStreamBuffer_->Ptr()), l, l); 
     314    //iStreamBuffer_->Des().FillZ(frameLen_); 
     315    iFramePtr_.Set((TUint8*)(iStreamBuffer_->Ptr()), frameLen_, frameLen_); 
    297316    return iFramePtr_; 
    298317} 
     
    327346    } 
    328347 
    329     // Call the callback. 
    330     recCb_(userData_, timeStamp_, (void*)aBuffer.Ptr(), aBuffer.Size()); 
    331  
    332     // Increment timestamp. 
    333     timeStamp_ += (aBuffer.Size() * BYTES_PER_SAMPLE); 
     348    if (frameRecBufLen_ || aBuffer.Size() < frameLen_) { 
     349                pj_memcpy(frameRecBuf_ + frameRecBufLen_, (void*) aBuffer.Ptr(), aBuffer.Size()); 
     350                frameRecBufLen_ += aBuffer.Size(); 
     351    } 
     352 
     353    if (frameRecBufLen_) { 
     354        while (frameRecBufLen_ >= frameLen_) { 
     355                // Call the callback. 
     356                    recCb_(userData_, timeStamp_, frameRecBuf_, frameLen_); 
     357                    // Increment timestamp. 
     358                    timeStamp_ += parentStrm_->samples_per_frame; 
     359 
     360                    frameRecBufLen_ -= frameLen_; 
     361                    pj_memmove(frameRecBuf_, frameRecBuf_+frameLen_, frameRecBufLen_); 
     362        } 
     363    } else { 
     364        // Call the callback. 
     365            recCb_(userData_, timeStamp_, (void*) aBuffer.Ptr(), aBuffer.Size()); 
     366            // Increment timestamp. 
     367            timeStamp_ += parentStrm_->samples_per_frame; 
     368    } 
    334369 
    335370    // Record next frame 
     
    526561                                            iSettings.iChannels); 
    527562 
    528         // set volume to 1/4th of stream max volume 
    529         iOutputStream_->SetVolume(iOutputStream_->MaxVolume()/4); 
     563        // set volume to 1/2th of stream max volume 
     564        iOutputStream_->SetVolume(iOutputStream_->MaxVolume()/2); 
    530565         
    531566        // set stream priority to normal and time sensitive 
     
    629664{ 
    630665    /* Always return the default sound device */ 
     666    if (index == (unsigned)-1) 
     667        index = 0; 
     668 
    631669    PJ_ASSERT_RETURN(index==0, NULL); 
    632670    return &symbian_snd_dev_info; 
     
    663701    strm = (pjmedia_snd_stream*) pj_pool_zalloc(pool,  
    664702                                                sizeof(pjmedia_snd_stream)); 
     703    strm->dir = PJMEDIA_DIR_CAPTURE; 
    665704    strm->pool = pool; 
    666705    strm->clock_rate = clock_rate; 
     
    677716    if (err != KErrNone) { 
    678717        pj_pool_release(pool); 
    679         return PJ_RETURN_OS_ERROR(err); 
    680     } 
    681  
     718        return PJ_RETURN_OS_ERROR(err); 
     719    } 
    682720 
    683721    // Done. 
     
    711749    strm = (pjmedia_snd_stream*) pj_pool_zalloc(pool,  
    712750                                                sizeof(pjmedia_snd_stream)); 
     751    strm->dir = PJMEDIA_DIR_PLAYBACK;     
    713752    strm->pool = pool; 
    714753    strm->clock_rate = clock_rate; 
     
    762801    strm = (pjmedia_snd_stream*) pj_pool_zalloc(pool,  
    763802                                                sizeof(pjmedia_snd_stream)); 
     803    strm->dir = PJMEDIA_DIR_CAPTURE_PLAYBACK; 
    764804    strm->pool = pool; 
    765805    strm->clock_rate = clock_rate; 
     
    795835} 
    796836 
     837/* 
     838 * Get stream info. 
     839 */ 
     840PJ_DEF(pj_status_t) pjmedia_snd_stream_get_info(pjmedia_snd_stream *strm, 
     841                                                pjmedia_snd_stream_info *pi) 
     842{ 
     843    PJ_ASSERT_RETURN(strm && pi, PJ_EINVAL); 
     844 
     845    pj_bzero(pi, sizeof(*pi)); 
     846    pi->dir = strm->dir; 
     847    pi->play_id = 0; 
     848    pi->rec_id = 0; 
     849    pi->clock_rate = strm->clock_rate; 
     850    pi->channel_count = strm->channel_count; 
     851    pi->samples_per_frame = strm->samples_per_frame; 
     852    pi->bits_per_sample = BYTES_PER_SAMPLE * 8; 
     853    pi->rec_latency = 0; 
     854    pi->play_latency = 0; 
     855 
     856    return PJ_SUCCESS; 
     857} 
     858 
    797859 
    798860PJ_DEF(pj_status_t) pjmedia_snd_stream_start(pjmedia_snd_stream *stream) 
  • pjproject/trunk/pjsip-apps/src/symbian_ua/ua.cpp

    r1606 r1641  
    3232// Destination URI (to make call, or to subscribe presence) 
    3333// 
    34 #define SIP_DST_URI     "sip:192.168.0.7:5061" 
     34#define SIP_DST_URI     "sip:192.168.0.11:5060" 
    3535 
    3636// 
     
    5858// 
    5959// STUN server 
    60 #if 1 
     60#if 0 
    6161        // Use this to have the STUN server resolved normally 
    6262#   define STUN_DOMAIN  NULL 
     
    7575// Use ICE? 
    7676// 
    77 #define USE_ICE         1 
     77#define USE_ICE         0 
    7878 
    7979 
     
    321321    med_cfg.has_ioqueue = PJ_FALSE; 
    322322    med_cfg.clock_rate = 8000; 
     323    med_cfg.audio_frame_ptime = 40; 
    323324    med_cfg.ec_tail_len = 0; 
    324325    med_cfg.enable_ice = USE_ICE; 
     
    453454            "  D    Dump states detail\n" 
    454455            "  P    Dump pool factory\n" 
     456            "  l    Start loopback audio device\n" 
     457            "  L    Stop loopback audio device\n" 
    455458            "  m    Call " SIP_DST_URI "\n" 
    456459            "  a    Answer call\n" 
     
    482485            pj_pool_factory_dump(pjsua_get_pool_factory(), PJ_TRUE); 
    483486            break; 
     487    case 'l': 
     488                pjsua_conf_connect(0, 0); 
     489            break; 
     490    case 'L': 
     491                pjsua_conf_disconnect(0, 0); 
     492            break; 
    484493    case 'm': 
    485494            if (g_call_id != PJSUA_INVALID_ID) { 
  • pjproject/trunk/pjsip-apps/src/symsndtest/app_main.cpp

    r1428 r1641  
    2929#define CHANNEL_COUNT           1 
    3030#define PTIME                   100 
    31 #define SAMPLES_PER_FRAME       (2048) 
     31#define SAMPLES_PER_FRAME       (80) 
    3232#define BITS_PER_SAMPLE         16 
    33  
     33#define LOOPBACK_BUFF_COUNT 100 
    3434 
    3535extern CConsoleBase* console; 
     
    4040static pj_time_val t_start; 
    4141 
     42 
     43static pj_int16_t buff_loopback[SAMPLES_PER_FRAME*LOOPBACK_BUFF_COUNT]; 
     44static pj_uint32_t pointer_w, pointer_r; 
    4245 
    4346/* Logging callback */ 
     
    7174    pj_log_set_log_func((void (*)(int,const char*,int)) &log_writer); 
    7275    pj_log_set_decor(PJ_LOG_HAS_NEWLINE); 
     76    pj_log_set_level(5); 
    7377     
    7478    /* Init pjlib */ 
     
    115119    PJ_UNUSED_ARG(input); 
    116120    PJ_UNUSED_ARG(size); 
     121 
     122    pj_memcpy(&buff_loopback[pointer_w*SAMPLES_PER_FRAME], input, size); 
     123 
     124    if (size != SAMPLES_PER_FRAME*2) { 
     125                PJ_LOG(3, (THIS_FILE, "Size captured = %u", 
     126                           size)); 
     127                pj_bzero(&buff_loopback[pointer_w*SAMPLES_PER_FRAME]+size/2, SAMPLES_PER_FRAME*2 - size); 
     128    } 
     129 
     130    if (++pointer_w >= LOOPBACK_BUFF_COUNT) { 
     131        pointer_w = 0; 
     132    } 
    117133     
    118134    ++rec_cnt; 
     
    129145    PJ_UNUSED_ARG(timestamp); 
    130146     
    131     pj_bzero(output, size); 
     147    //pj_bzero(output, size); 
     148    pj_memcpy(output, &buff_loopback[pointer_r*SAMPLES_PER_FRAME], SAMPLES_PER_FRAME*2); 
     149 
     150    if (++pointer_r >= LOOPBACK_BUFF_COUNT) { 
     151        pointer_r = 0; 
     152    } 
    132153     
    133154    ++play_cnt; 
     
    174195    } 
    175196 
     197    pointer_w = LOOPBACK_BUFF_COUNT/2; 
     198    pointer_r = 0; 
     199     
    176200    return PJ_SUCCESS; 
    177201} 
     
    298322    case 'p': 
    299323        snd_start(PJMEDIA_DIR_PLAYBACK); 
    300         break; 
     324    break; 
    301325    case 'c': 
    302326        snd_stop(); 
Note: See TracChangeset for help on using the changeset viewer.