Ignore:
Timestamp:
Apr 7, 2010 1:21:31 PM (14 years ago)
Author:
nanang
Message:

More ticket #1055:

  • Added APS codecs detection.
  • Minor updates in symsndtest:
    • added log of supported extended audio formats.
    • changed libraries order in symsndtest.mmp, this fixes linking error on S60 3rd MR SDK.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjmedia/src/pjmedia-audiodev/symb_aps_dev.cpp

    r3134 r3135  
    12941294    af->dev_info.output_count = 1; 
    12951295 
    1296     af->dev_info.ext_fmt_cnt = 5; 
    1297  
    1298     af->dev_info.ext_fmt[0].id = PJMEDIA_FORMAT_AMR; 
    1299     af->dev_info.ext_fmt[0].bitrate = 7400; 
    1300     af->dev_info.ext_fmt[0].vad = PJ_TRUE; 
    1301  
    1302     af->dev_info.ext_fmt[1].id = PJMEDIA_FORMAT_G729; 
    1303     af->dev_info.ext_fmt[1].bitrate = 8000; 
    1304     af->dev_info.ext_fmt[1].vad = PJ_FALSE; 
    1305  
    1306     af->dev_info.ext_fmt[2].id = PJMEDIA_FORMAT_ILBC; 
    1307     af->dev_info.ext_fmt[2].bitrate = 13333; 
    1308     af->dev_info.ext_fmt[2].vad = PJ_TRUE; 
    1309  
    1310     af->dev_info.ext_fmt[3].id = PJMEDIA_FORMAT_PCMU; 
    1311     af->dev_info.ext_fmt[3].bitrate = 64000; 
    1312     af->dev_info.ext_fmt[3].vad = PJ_FALSE; 
    1313  
    1314     af->dev_info.ext_fmt[4].id = PJMEDIA_FORMAT_PCMA; 
    1315     af->dev_info.ext_fmt[4].bitrate = 64000; 
    1316     af->dev_info.ext_fmt[4].vad = PJ_FALSE; 
     1296    /* Enumerate codecs by trying to initialize each codec and examining 
     1297     * the error code. Consider the following: 
     1298     * - not possible to reinitialize the same APS session with  
     1299     *   different settings, 
     1300     * - closing APS session and trying to immediately reconnect may fail, 
     1301     *   clients should wait ~5s before attempting to reconnect. 
     1302     */ 
     1303 
     1304    unsigned i, fmt_cnt = 0; 
     1305    pj_bool_t g711_supported = PJ_FALSE; 
     1306 
     1307    /* Do not change the order! */ 
     1308    TFourCC fourcc[] = { 
     1309        TFourCC(KMCPFourCCIdAMRNB), 
     1310        TFourCC(KMCPFourCCIdG711), 
     1311        TFourCC(KMCPFourCCIdG729), 
     1312        TFourCC(KMCPFourCCIdILBC) 
     1313    }; 
     1314 
     1315    for (i = 0; i < PJ_ARRAY_SIZE(fourcc); ++i) { 
     1316        pj_bool_t supported = PJ_FALSE; 
     1317        unsigned retry_cnt = 0; 
     1318        enum { MAX_RETRY = 3 };  
     1319 
     1320#if (PJMEDIA_AUDIO_DEV_SYMB_APS_DETECTS_CODEC == 0) 
     1321        /* Codec detection is disabled */ 
     1322        supported = PJ_TRUE; 
     1323#elif (PJMEDIA_AUDIO_DEV_SYMB_APS_DETECTS_CODEC == 1) 
     1324        /* Minimal codec detection, AMR-NB and G.711 only */ 
     1325        if (i > 1) { 
     1326            /* If G.711 has been checked, skip G.729 and iLBC checks */ 
     1327            retry_cnt = MAX_RETRY; 
     1328            supported = g711_supported; 
     1329        } 
     1330#endif 
     1331         
     1332        while (!supported && ++retry_cnt <= MAX_RETRY) { 
     1333            RAPSSession iSession; 
     1334            TAPSInitSettings iPlaySettings; 
     1335            TAPSInitSettings iRecSettings; 
     1336            TInt err; 
     1337 
     1338            // Recorder settings 
     1339            iRecSettings.iGlobal                = APP_UID; 
     1340            iRecSettings.iPriority              = TMdaPriority(100); 
     1341            iRecSettings.iPreference            = TMdaPriorityPreference(0x05210001); 
     1342            iRecSettings.iSettings.iChannels    = EMMFMono; 
     1343            iRecSettings.iSettings.iSampleRate  = EMMFSampleRate8000Hz; 
     1344 
     1345            // Player settings 
     1346            iPlaySettings.iGlobal               = APP_UID; 
     1347            iPlaySettings.iPriority             = TMdaPriority(100); 
     1348            iPlaySettings.iPreference           = TMdaPriorityPreference(0x05220001); 
     1349            iPlaySettings.iSettings.iChannels   = EMMFMono; 
     1350            iPlaySettings.iSettings.iSampleRate = EMMFSampleRate8000Hz; 
     1351 
     1352            iRecSettings.iFourCC = iPlaySettings.iFourCC = fourcc[i]; 
     1353 
     1354            err = iSession.Connect(); 
     1355            if (err == KErrNone) 
     1356                err = iSession.InitializePlayer(iPlaySettings); 
     1357            if (err == KErrNone) 
     1358                err = iSession.InitializeRecorder(iRecSettings); 
     1359            iSession.Close(); 
     1360 
     1361            if (err == KErrNone) { 
     1362                /* All fine, stop retyring */ 
     1363                supported = PJ_TRUE; 
     1364            }  else if (err == KErrAlreadyExists && retry_cnt < MAX_RETRY) { 
     1365                /* Seems that the previous session is still arround, 
     1366                 * let's wait before retrying. 
     1367                 */ 
     1368                enum { RETRY_WAIT = 3000 }; /* in msecs */ 
     1369                TTime start, now; 
     1370                 
     1371                start.UniversalTime(); 
     1372                do { 
     1373                    pj_symbianos_poll(-1, RETRY_WAIT); 
     1374                    now.UniversalTime(); 
     1375                } while (now.MicroSecondsFrom(start) < RETRY_WAIT * 1000); 
     1376            } else { 
     1377                /* Seems that this format is not supported */ 
     1378                retry_cnt = MAX_RETRY; 
     1379            } 
     1380        } 
     1381 
     1382        if (supported) { 
     1383            switch(i) { 
     1384            case 0: /* AMRNB */ 
     1385                af->dev_info.ext_fmt[fmt_cnt].id = PJMEDIA_FORMAT_AMR; 
     1386                af->dev_info.ext_fmt[fmt_cnt].bitrate = 7400; 
     1387                af->dev_info.ext_fmt[fmt_cnt].vad = PJ_TRUE; 
     1388                ++fmt_cnt; 
     1389                break; 
     1390            case 1: /* G.711 */ 
     1391                af->dev_info.ext_fmt[fmt_cnt].id = PJMEDIA_FORMAT_PCMU; 
     1392                af->dev_info.ext_fmt[fmt_cnt].bitrate = 64000; 
     1393                af->dev_info.ext_fmt[fmt_cnt].vad = PJ_FALSE; 
     1394                ++fmt_cnt; 
     1395                af->dev_info.ext_fmt[fmt_cnt].id = PJMEDIA_FORMAT_PCMA; 
     1396                af->dev_info.ext_fmt[fmt_cnt].bitrate = 64000; 
     1397                af->dev_info.ext_fmt[fmt_cnt].vad = PJ_FALSE; 
     1398                ++fmt_cnt; 
     1399                g711_supported = PJ_TRUE; 
     1400                break; 
     1401            case 2: /* G.729 */ 
     1402                af->dev_info.ext_fmt[fmt_cnt].id = PJMEDIA_FORMAT_G729; 
     1403                af->dev_info.ext_fmt[fmt_cnt].bitrate = 8000; 
     1404                af->dev_info.ext_fmt[fmt_cnt].vad = PJ_FALSE; 
     1405                ++fmt_cnt; 
     1406                break; 
     1407            case 3: /* iLBC */ 
     1408                af->dev_info.ext_fmt[fmt_cnt].id = PJMEDIA_FORMAT_ILBC; 
     1409                af->dev_info.ext_fmt[fmt_cnt].bitrate = 13333; 
     1410                af->dev_info.ext_fmt[fmt_cnt].vad = PJ_TRUE; 
     1411                ++fmt_cnt; 
     1412                break; 
     1413            } 
     1414        } 
     1415    } 
    13171416     
     1417    af->dev_info.ext_fmt_cnt = fmt_cnt; 
     1418 
    13181419    PJ_LOG(4, (THIS_FILE, "APS initialized")); 
    13191420 
Note: See TracChangeset for help on using the changeset viewer.