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

Initial sources of APS-direct.

Location:
pjproject/branches/projects/aps-direct
Files:
1 added
17 edited

Legend:

Unmodified
Added
Removed
  • pjproject/branches/projects/aps-direct/build.symbian/bld.inf

    r2174 r2434  
    1 #define SND_USE_NULL    0 
    2 #define SND_USE_APS     0 
    3  
    41prj_platforms 
    52winscw 
     
    2623 
    2724/* Sound device impl */ 
    28 #if SND_USE_NULL 
    29         null_audio.mmp 
    30 #elif SND_USE_APS 
    31         symbian_audio_aps.mmp 
    32 #else 
    33         symbian_audio.mmp 
    34 #endif 
     25symbian_audio.mmp 
    3526 
    3627/* Applications */ 
  • pjproject/branches/projects/aps-direct/build.symbian/pjmedia.mmp

    r2262 r2434  
    4141SOURCE          codec.c 
    4242SOURCE          conference.c 
     43SOURCE          conf_switch.c 
    4344SOURCE          echo_common.c 
    4445SOURCE          echo_port.c 
  • pjproject/branches/projects/aps-direct/build.symbian/symbian_audio.mmp

    r1965 r2434  
    2525 
    2626OPTION          CW -lang c++ 
    27  
    28 // 
    29 // GCCE optimization setting 
    30 // 
    3127OPTION          GCCE -O2 -fno-unit-at-a-time 
    3228 
     
    3430MACRO           PJ_SYMBIAN=1 
    3531 
     32SOURCE          nullsound.c 
    3633SOURCE          symbian_sound.cpp 
     34SOURCE          symbian_sound_aps.cpp 
    3735 
    3836SYSTEMINCLUDE   ..\pjlib\include 
     
    4139SYSTEMINCLUDE   \epoc32\include 
    4240SYSTEMINCLUDE   \epoc32\include\libc 
     41SYSTEMINCLUDE   \epoc32\include\mmf\server  
     42SYSTEMINCLUDE   \epoc32\include\mmf\common  
     43SYSTEMINCLUDE   \epoc32\include\mda\common  
    4344 
    4445SYSTEMINCLUDE   \epoc32\include\mmf\plugin  
  • pjproject/branches/projects/aps-direct/build.symbian/symbian_ua.mmp

    r2384 r2434  
    1 #define SND_USE_NULL    0 
    2 #define SND_USE_APS     0 
     1#define SND_USE_APS     1 
     2#define SND_USE_VAS     0 
    33 
    4 TARGET          symbian_ua.exe 
    5 TARGETTYPE      exe 
    6 UID             0x0 0xA000000D 
     4TARGET                  symbian_ua.exe 
     5TARGETTYPE              exe 
     6UID                     0x0 0xA000000D 
    77 
    8 SOURCEPATH      ..\pjsip-apps\src\symbian_ua 
     8SOURCEPATH              ..\pjsip-apps\src\symbian_ua 
    99 
    10 MACRO           PJ_M_I386=1 
    11 MACRO           PJ_SYMBIAN=1 
     10MACRO                   PJ_M_I386=1 
     11MACRO                   PJ_SYMBIAN=1 
    1212 
    1313// Source files 
    1414 
    15 SOURCE  ua.cpp 
    16 SOURCE  main_symbian.cpp 
     15SOURCE                  ua.cpp 
     16SOURCE                  main_symbian.cpp 
    1717 
    18 DOCUMENT ua.h 
     18DOCUMENT                ua.h 
    1919 
    20 START RESOURCE  symbian_ua_reg.rss 
     20START RESOURCE          symbian_ua_reg.rss 
    2121        TARGETPATH      \private\10003a3f\apps 
    2222END 
    2323 
    24 SYSTEMINCLUDE   ..\pjlib\include 
    25 SYSTEMINCLUDE   ..\pjlib-util\include 
    26 SYSTEMINCLUDE   ..\pjnath\include 
    27 SYSTEMINCLUDE   ..\pjmedia\include 
    28 SYSTEMINCLUDE   ..\pjsip\include 
     24SYSTEMINCLUDE           ..\pjlib\include 
     25SYSTEMINCLUDE           ..\pjlib-util\include 
     26SYSTEMINCLUDE           ..\pjnath\include 
     27SYSTEMINCLUDE           ..\pjmedia\include 
     28SYSTEMINCLUDE           ..\pjsip\include 
    2929 
    30 SYSTEMINCLUDE   \epoc32\include 
    31 SYSTEMINCLUDE   \epoc32\include\libc 
     30SYSTEMINCLUDE           \epoc32\include 
     31SYSTEMINCLUDE           \epoc32\include\libc 
    3232 
    33 STATICLIBRARY   pjsua_lib.lib pjsip_ua.lib 
    34 STATICLIBRARY   pjsip_simple.lib pjsip.lib pjsdp.lib pjmedia.lib 
    35 STATICLIBRARY   pjnath.lib pjlib_util.lib pjlib.lib 
    36 STATICLIBRARY   libsrtp.lib 
    37 STATICLIBRARY   libgsmcodec.lib libspeexcodec.lib 
     33STATICLIBRARY           pjsua_lib.lib pjsip_ua.lib 
     34STATICLIBRARY           pjsip_simple.lib pjsip.lib pjsdp.lib pjmedia.lib 
     35STATICLIBRARY           pjnath.lib pjlib_util.lib pjlib.lib 
     36STATICLIBRARY           libsrtp.lib 
     37STATICLIBRARY           libgsmcodec.lib libspeexcodec.lib 
     38STATICLIBRARY           symbian_audio.lib 
    3839 
    39 #if SND_USE_NULL 
    40     STATICLIBRARY       null_audio.lib 
    41     CAPABILITY          NetworkServices LocalServices ReadUserData WriteUserData UserEnvironment  
    42 #elif SND_USE_APS 
    43     STATICLIBRARY       symbian_audio_aps.lib 
    44     LIBRARY             APSSession2.lib 
    45     CAPABILITY          NetworkServices LocalServices ReadUserData WriteUserData UserEnvironment MultimediaDD 
    46     MACRO               PJMEDIA_SYM_SND_USE_APS=1 
     40#if SND_USE_APS 
     41        LIBRARY         APSSession2.lib 
     42        CAPABILITY      NetworkServices LocalServices ReadUserData WriteUserData UserEnvironment MultimediaDD 
     43#elif SND_USE_VAS 
     44//      LIBRARY          
     45        CAPABILITY      NetworkServices LocalServices ReadUserData WriteUserData UserEnvironment MultimediaDD 
    4746#else 
    48     STATICLIBRARY       symbian_audio.lib 
    49     LIBRARY             mediaclientaudiostream.lib 
    50     LIBRARY             mediaclientaudioinputstream.lib 
    51     CAPABILITY          NetworkServices LocalServices ReadUserData WriteUserData UserEnvironment  
     47        LIBRARY         mediaclientaudiostream.lib 
     48        LIBRARY         mediaclientaudioinputstream.lib 
     49        CAPABILITY      NetworkServices LocalServices ReadUserData WriteUserData UserEnvironment 
    5250#endif 
    5351 
     
    5654#endif 
    5755 
    58 LIBRARY         esock.lib insock.lib charconv.lib euser.lib estlib.lib commdb.lib apengine.lib  
     56LIBRARY                 esock.lib insock.lib charconv.lib euser.lib estlib.lib commdb.lib apengine.lib  
    5957 
    6058// The default 8KB seems to be insufficient with all bells and 
  • pjproject/branches/projects/aps-direct/build.symbian/symsndtest.mmp

    r2257 r2434  
    1 #define SND_USE_NULL    0 
    2 #define SND_USE_APS     0 
     1#define SND_USE_APS     1 
     2#define SND_USE_VAS     0 
    33 
    4 TARGET          symsndtest.exe 
    5 TARGETTYPE      exe 
    6 UID             0x0 0xA000000E 
     4TARGET                  symsndtest.exe 
     5TARGETTYPE              exe 
     6UID                     0x0 0xA000000E 
    77 
    8 SOURCEPATH      ..\pjsip-apps\src\symsndtest 
     8SOURCEPATH              ..\pjsip-apps\src\symsndtest 
    99 
    10 MACRO           PJ_M_I386=1 
    11 MACRO           PJ_SYMBIAN=1 
     10MACRO                   PJ_M_I386=1 
     11MACRO                   PJ_SYMBIAN=1 
    1212 
    1313// Test files 
    1414 
    15 SOURCE  app_main.cpp 
    16 SOURCE  main_symbian.cpp 
     15SOURCE                  app_main.cpp 
     16SOURCE                  main_symbian.cpp 
    1717 
    18 START RESOURCE  symsndtest_reg.rss 
     18START RESOURCE          symsndtest_reg.rss 
    1919        TARGETPATH      \private\10003a3f\apps 
    2020END 
    2121 
    22 SYSTEMINCLUDE   ..\pjlib\include 
    23 SYSTEMINCLUDE   ..\pjmedia\include 
     22SYSTEMINCLUDE           ..\pjlib\include 
     23SYSTEMINCLUDE           ..\pjmedia\include 
    2424 
    25 SYSTEMINCLUDE   \epoc32\include 
    26 SYSTEMINCLUDE   \epoc32\include\libc 
     25SYSTEMINCLUDE           \epoc32\include 
     26SYSTEMINCLUDE           \epoc32\include\libc 
    2727 
    28 LIBRARY         charconv.lib euser.lib estlib.lib 
    29 LIBRARY         esock.lib insock.lib 
    30 STATICLIBRARY   pjlib.lib pjmedia.lib 
     28LIBRARY                 charconv.lib euser.lib estlib.lib 
     29LIBRARY                 esock.lib insock.lib 
     30STATICLIBRARY           pjlib.lib pjmedia.lib 
     31STATICLIBRARY           symbian_audio.lib 
    3132 
    32 #if SND_USE_NULL 
    33     STATICLIBRARY       null_audio.lib 
    34     CAPABILITY          NetworkServices LocalServices ReadUserData WriteUserData UserEnvironment  
    35 #elif SND_USE_APS 
    36     SOURCEPATH                              ..\pjmedia\src\pjmedia  
    37     SOURCE                                  symbian_sound_aps.cpp  
    38  
    39     SYSTEMINCLUDE                           \epoc32\include\mmf\server  
    40     SYSTEMINCLUDE                           \epoc32\include\mmf\common  
    41     SYSTEMINCLUDE                           \epoc32\include\mda\common  
    42  
    43     //STATICLIBRARY     symbian_audio_aps.lib 
    44     LIBRARY             APSSession2.lib 
    45     CAPABILITY          NetworkServices LocalServices ReadUserData WriteUserData UserEnvironment MultimediaDD 
     33#if SND_USE_APS 
     34        LIBRARY         APSSession2.lib 
     35        CAPABILITY      NetworkServices LocalServices ReadUserData WriteUserData UserEnvironment MultimediaDD 
     36#elif SND_USE_VAS 
     37//      LIBRARY          
     38        CAPABILITY      NetworkServices LocalServices ReadUserData WriteUserData UserEnvironment MultimediaDD 
    4639#else 
    47     STATICLIBRARY       symbian_audio.lib 
    48     LIBRARY             mediaclientaudiostream.lib 
    49     LIBRARY             mediaclientaudioinputstream.lib 
    50     CAPABILITY          NetworkServices LocalServices ReadUserData WriteUserData UserEnvironment  
     40        LIBRARY         mediaclientaudiostream.lib 
     41        LIBRARY         mediaclientaudioinputstream.lib 
     42        CAPABILITY      NetworkServices LocalServices ReadUserData WriteUserData UserEnvironment 
    5143#endif 
    5244 
  • pjproject/branches/projects/aps-direct/pjmedia/build/pjmedia.vcproj

    r2430 r2434  
    9696                </Configuration> 
    9797                <Configuration 
    98                         Name="Release|Windows Mobile 6 Standard SDK (ARMV4I)" 
    99                         OutputDirectory="output\$(ProjectName)-$(PlatformName)-$(ConfigurationName)" 
    100                         IntermediateDirectory="$(OutDir)" 
    101                         ConfigurationType="4" 
    102                         CharacterSet="1" 
    103                         > 
    104                         <Tool 
    105                                 Name="VCPreBuildEventTool" 
    106                         /> 
    107                         <Tool 
    108                                 Name="VCCustomBuildTool" 
    109                         /> 
    110                         <Tool 
    111                                 Name="VCXMLDataGeneratorTool" 
    112                         /> 
    113                         <Tool 
    114                                 Name="VCWebServiceProxyGeneratorTool" 
    115                         /> 
    116                         <Tool 
    117                                 Name="VCMIDLTool" 
    118                         /> 
    119                         <Tool 
    120                                 Name="VCCLCompilerTool" 
    121                                 ExecutionBucket="7" 
    122                                 Optimization="2" 
    123                                 FavorSizeOrSpeed="2" 
    124                                 AdditionalIncludeDirectories="../include,../../pjlib/include,../../pjlib-util/include,../../pjnath/include,../../third_party/portaudio/include,../../third_party/speex/include,../../third_party/build/srtp,../../third_party/srtp/include,../../third_party/srtp/crypto/include;../.." 
    125                                 PreprocessorDefinitions="NDEBUG;_WIN32_WCE=$(CEVER);UNDER_CE;$(PLATFORMDEFINES);WINCE;$(ARCHFAM);$(_ARCHFAM_);SMARTPHONE2003_UI_MODEL;SMARTPHONE2003_UI_MODEL" 
    126                                 ExceptionHandling="0" 
    127                                 RuntimeLibrary="0" 
    128                                 WarningLevel="3" 
    129                                 DebugInformationFormat="0" 
    130                                 CompileAs="0" 
    131                         /> 
    132                         <Tool 
    133                                 Name="VCManagedResourceCompilerTool" 
    134                         /> 
    135                         <Tool 
    136                                 Name="VCResourceCompilerTool" 
    137                         /> 
    138                         <Tool 
    139                                 Name="VCPreLinkEventTool" 
    140                         /> 
    141                         <Tool 
    142                                 Name="VCLibrarianTool" 
    143                                 AdditionalOptions="" 
    144                         /> 
    145                         <Tool 
    146                                 Name="VCALinkTool" 
    147                         /> 
    148                         <Tool 
    149                                 Name="VCXDCMakeTool" 
    150                         /> 
    151                         <Tool 
    152                                 Name="VCBscMakeTool" 
    153                         /> 
    154                         <Tool 
    155                                 Name="VCCodeSignTool" 
    156                         /> 
    157                         <Tool 
    158                                 Name="VCPostBuildEventTool" 
    159                         /> 
    160                         <DeploymentTool 
    161                                 ForceDirty="-1" 
    162                                 RemoteDirectory="" 
    163                                 RegisterOutput="0" 
    164                                 AdditionalFiles="" 
    165                         /> 
    166                         <DebuggerTool 
    167                         /> 
    168                 </Configuration> 
    169                 <Configuration 
    17098                        Name="Debug|Win32" 
    17199                        OutputDirectory=".\output\pjmedia-i386-win32-vc8-debug" 
     
    244172                </Configuration> 
    245173                <Configuration 
     174                        Name="Release|Windows Mobile 6 Standard SDK (ARMV4I)" 
     175                        OutputDirectory="output\$(ProjectName)-$(PlatformName)-$(ConfigurationName)" 
     176                        IntermediateDirectory="$(OutDir)" 
     177                        ConfigurationType="4" 
     178                        CharacterSet="1" 
     179                        > 
     180                        <Tool 
     181                                Name="VCPreBuildEventTool" 
     182                        /> 
     183                        <Tool 
     184                                Name="VCCustomBuildTool" 
     185                        /> 
     186                        <Tool 
     187                                Name="VCXMLDataGeneratorTool" 
     188                        /> 
     189                        <Tool 
     190                                Name="VCWebServiceProxyGeneratorTool" 
     191                        /> 
     192                        <Tool 
     193                                Name="VCMIDLTool" 
     194                        /> 
     195                        <Tool 
     196                                Name="VCCLCompilerTool" 
     197                                ExecutionBucket="7" 
     198                                Optimization="2" 
     199                                FavorSizeOrSpeed="2" 
     200                                AdditionalIncludeDirectories="../include,../../pjlib/include,../../pjlib-util/include,../../pjnath/include,../../third_party/portaudio/include,../../third_party/speex/include,../../third_party/build/srtp,../../third_party/srtp/include,../../third_party/srtp/crypto/include;../.." 
     201                                PreprocessorDefinitions="NDEBUG;_WIN32_WCE=$(CEVER);UNDER_CE;$(PLATFORMDEFINES);WINCE;$(ARCHFAM);$(_ARCHFAM_);SMARTPHONE2003_UI_MODEL;SMARTPHONE2003_UI_MODEL" 
     202                                ExceptionHandling="0" 
     203                                RuntimeLibrary="0" 
     204                                WarningLevel="3" 
     205                                DebugInformationFormat="0" 
     206                                CompileAs="0" 
     207                        /> 
     208                        <Tool 
     209                                Name="VCManagedResourceCompilerTool" 
     210                        /> 
     211                        <Tool 
     212                                Name="VCResourceCompilerTool" 
     213                        /> 
     214                        <Tool 
     215                                Name="VCPreLinkEventTool" 
     216                        /> 
     217                        <Tool 
     218                                Name="VCLibrarianTool" 
     219                                AdditionalOptions="" 
     220                        /> 
     221                        <Tool 
     222                                Name="VCALinkTool" 
     223                        /> 
     224                        <Tool 
     225                                Name="VCXDCMakeTool" 
     226                        /> 
     227                        <Tool 
     228                                Name="VCBscMakeTool" 
     229                        /> 
     230                        <Tool 
     231                                Name="VCCodeSignTool" 
     232                        /> 
     233                        <Tool 
     234                                Name="VCPostBuildEventTool" 
     235                        /> 
     236                        <DeploymentTool 
     237                                ForceDirty="-1" 
     238                                RemoteDirectory="" 
     239                                RegisterOutput="0" 
     240                                AdditionalFiles="" 
     241                        /> 
     242                        <DebuggerTool 
     243                        /> 
     244                </Configuration> 
     245                <Configuration 
    246246                        Name="Debug|Windows Mobile 6 Standard SDK (ARMV4I)" 
    247247                        OutputDirectory="output\$(ProjectName)-$(PlatformName)-$(ConfigurationName)" 
     
    435435                        </File> 
    436436                        <File 
     437                                RelativePath="..\src\pjmedia\conf_switch.c" 
     438                                > 
     439                        </File> 
     440                        <File 
    437441                                RelativePath="..\src\pjmedia\conference.c" 
    438442                                > 
  • pjproject/branches/projects/aps-direct/pjmedia/include/pjmedia-codec/config.h

    r2394 r2434  
    195195#endif 
    196196 
     197/** 
     198 * Enable Passthrough codecs. 
     199 * 
     200 * Default: 0 
     201 */ 
     202#ifndef PJMEDIA_HAS_PASSTHROUGH_CODECS 
     203#   define PJMEDIA_HAS_PASSTHROUGH_CODECS       0 
     204#endif 
    197205 
    198206#endif  /* __PJMEDIA_CODEC_CONFIG_H__ */ 
  • pjproject/branches/projects/aps-direct/pjmedia/include/pjmedia/conference.h

    r2394 r2434  
    5757    unsigned            slot;               /**< Slot number.               */ 
    5858    pj_str_t            name;               /**< Port name.                 */ 
     59    pjmedia_fourcc      format;             /**< Format (FourCC identifier) */ 
    5960    pjmedia_port_op     tx_setting;         /**< Transmit settings.         */ 
    6061    pjmedia_port_op     rx_setting;         /**< Receive settings.          */ 
  • pjproject/branches/projects/aps-direct/pjmedia/include/pjmedia/config.h

    r2394 r2434  
    4545#endif 
    4646 
     47/** 
     48 * Specify whether we prefer to use audio switch board rather than  
     49 * conference bridge. 
     50 * 
     51 * Audio switch board is a kind of simplified version of conference  
     52 * bridge, but not really the subset of conference bridge. It has  
     53 * stricter rules on audio routing among the pjmedia ports and has 
     54 * no audio mixing capability. The power of it is it could work with 
     55 * encoded audio frames where conference brigde couldn't. 
     56 * 
     57 * Default: 0 
     58 */ 
     59#ifndef PJMEDIA_CONF_USE_SWITCH_BOARD 
     60#   define PJMEDIA_CONF_USE_SWITCH_BOARD    0 
     61#endif 
     62 
    4763/* 
    4864 * Types of sound stream backends. 
     
    6076/** Constant for Win32 MME sound backend. */ 
    6177#define PJMEDIA_SOUND_WIN32_MME_SOUND       3 
     78 
     79/** Constant for Symbian Multimedia Audio Stream backend. */ 
     80#define PJMEDIA_SOUND_SYMB_MDA_SOUND        4 
     81 
     82/** Constant for Symbian APS backend. */ 
     83#define PJMEDIA_SOUND_SYMB_APS_SOUND        5 
     84 
     85/** Constant for Symbian VAS backend. */ 
     86#define PJMEDIA_SOUND_SYMB_VAS_SOUND        6 
     87 
    6288 
    6389/** When this is set, pjmedia will not provide any sound device backend.  
  • pjproject/branches/projects/aps-direct/pjmedia/include/pjmedia/port.h

    r2394 r2434  
    2626 */ 
    2727#include <pjmedia/types.h> 
     28#include <pj/assert.h> 
    2829#include <pj/os.h> 
    2930 
     
    212213    pj_bool_t       need_info;          /**< Need info on connect?          */ 
    213214    unsigned        pt;                 /**< Payload type (can be dynamic). */ 
     215    pjmedia_fourcc  format;             /**< Format (FourCC identifier)     */ 
    214216    pj_str_t        encoding_name;      /**< Encoding name.                 */ 
    215217    unsigned        clock_rate;         /**< Sampling rate.                 */ 
     
    227229{ 
    228230    PJMEDIA_FRAME_TYPE_NONE,        /**< No frame.              */ 
    229     PJMEDIA_FRAME_TYPE_AUDIO        /**< Normal audio frame.    */ 
     231    PJMEDIA_FRAME_TYPE_AUDIO,       /**< Normal audio frame.    */ 
     232    PJMEDIA_FRAME_TYPE_EXTENDED     /**< Extended audio frame.  */ 
    230233 
    231234} pjmedia_frame_type; 
     
    250253 
    251254/** 
     255 * The pjmedia_frame_ext is used to carry a more complex audio frames than 
     256 * the typical PCM audio frames, and it is signaled by setting the "type" 
     257 * field of a pjmedia_frame to PJMEDIA_FRAME_TYPE_EXTENDED. With this set, 
     258 * application may typecast pjmedia_frame to pjmedia_frame_ext. 
     259 * 
     260 * This structure may contain more than one audio frames, which subsequently 
     261 * will be called subframes in this structure. The subframes section 
     262 * immediately follows the end of this structure, and each subframe is 
     263 * represented by pjmedia_frame_ext_subframe structure. Every next 
     264 * subframe immediately follows the previous subframe, and all subframes 
     265 * are byte-aligned although its payload may not be byte-aligned. 
     266 */ 
     267typedef struct pjmedia_frame_ext { 
     268    pjmedia_frame   base;           /**< Base frame info */ 
     269    pj_uint16_t     samples_cnt;    /**< Number of samples in this frame */ 
     270    pj_uint16_t     subframe_cnt;   /**< Number of (sub)frames in this frame */ 
     271 
     272    /* Zero or more (sub)frames follows immediately after this, 
     273     * each will be represented by pjmedia_frame_ext_subframe 
     274     */ 
     275} pjmedia_frame_ext; 
     276 
     277/** 
     278 * This structure represents the individual subframes in the 
     279 * pjmedia_frame_ext structure. 
     280 */ 
     281typedef struct pjmedia_frame_ext_subframe { 
     282    pj_uint16_t     bitlen;         /**< Number of bits in the data */ 
     283    pj_uint8_t      data[1];        /**< Start of encoded data */ 
     284} pjmedia_frame_ext_subframe; 
     285 
     286 
     287/* Append one subframe to the frame_ext */ 
     288PJ_INLINE(void) pjmedia_frame_ext_append_subframe(pjmedia_frame_ext *frm, 
     289                                                  const void *src, 
     290                                                  pj_uint16_t bitlen, 
     291                                                  pj_uint16_t samples_cnt) 
     292{ 
     293    pj_uint8_t *p; 
     294    unsigned i, tmp; 
     295 
     296    p = (pj_uint8_t*)frm + sizeof(pjmedia_frame_ext); 
     297    for (i = 0; i < frm->subframe_cnt; ++i) { 
     298        pjmedia_frame_ext_subframe *fsub; 
     299        fsub = (pjmedia_frame_ext_subframe*) p; 
     300        p += fsub->bitlen / 8; 
     301        if (fsub->bitlen % 8) 
     302            ++p; 
     303    } 
     304 
     305    tmp = bitlen / 8; 
     306    if (bitlen % 8) ++tmp; 
     307    pj_memcpy(p, &bitlen, sizeof(bitlen)); 
     308    pj_memcpy(p + sizeof(bitlen), src, tmp); 
     309    frm->subframe_cnt++; 
     310    frm->samples_cnt = frm->samples_cnt + samples_cnt; 
     311} 
     312 
     313/* Get the pointer and length of the n-th subframe */ 
     314PJ_INLINE(pjmedia_frame_ext_subframe*)  
     315          pjmedia_frame_ext_get_subframe(const pjmedia_frame_ext *frm, 
     316                                         unsigned n) 
     317{ 
     318    pj_uint8_t *p; 
     319    unsigned i; 
     320    pjmedia_frame_ext_subframe *tmp; 
     321 
     322    pj_assert(n < frm->subframe_cnt); 
     323 
     324    p = (pj_uint8_t*)frm + sizeof(pjmedia_frame_ext); 
     325    for (i = 0; i < n; ++i) {    
     326        tmp = (pjmedia_frame_ext_subframe*) p; 
     327        p += tmp->bitlen / 8; 
     328        if (tmp->bitlen % 8) 
     329            ++p; 
     330    } 
     331     
     332    tmp = (pjmedia_frame_ext_subframe*) p; 
     333    return tmp; 
     334} 
     335         
     336/** 
    252337 * Port interface. 
    253338 */ 
  • pjproject/branches/projects/aps-direct/pjmedia/include/pjmedia/symbian_sound_aps.h

    r2394 r2434  
    3232 
    3333/** 
     34 * Declaration of APS sound setting.   
     35 */ 
     36typedef struct pjmedia_snd_aps_setting 
     37{ 
     38    pjmedia_fourcc      format;   /**< Format (FourCC ID).      */  
     39    pj_uint32_t         bitrate;  /**< Bitrate (bps).           */ 
     40    pj_uint32_t         mode;     /**< Mode, currently only used  
     41                                       for specifying iLBC mode, 
     42                                       20ms or 30ms frame size. */ 
     43    pj_bool_t           plc;      /**< PLC enabled/disabled.    */ 
     44    pj_bool_t           vad;      /**< VAD enabled/disabled.    */ 
     45    pj_bool_t           cng;      /**< CNG enabled/disabled.    */ 
     46    pj_bool_t           loudspk;  /**< Audio routed to loudspeaker.*/ 
     47     
     48} pjmedia_snd_aps_setting; 
     49 
     50 
     51/** 
    3452 * Activate/deactivate loudspeaker, when loudspeaker is inactive, audio 
    3553 * will be routed to earpiece. 
     
    4866 
    4967 
     68/** 
     69 * Set a codec and its settings to be used on the next sound device session. 
     70 * 
     71 * @param setting       APS sound device setting, see @pjmedia_snd_aps_setting. 
     72 * 
     73 * @return              PJ_SUCCESS on success. 
     74 */ 
     75PJ_DECL(pj_status_t) pjmedia_snd_aps_modify_setting( 
     76                                    const pjmedia_snd_aps_setting *setting); 
     77 
     78 
    5079PJ_END_DECL 
    5180 
  • pjproject/branches/projects/aps-direct/pjmedia/include/pjmedia/types.h

    r2394 r2434  
    4848 */ 
    4949 
    50 /**  
    51  * Top most media type.  
     50/** 
     51 * Top most media type. 
    5252 */ 
    5353typedef enum pjmedia_type 
     
    6262    PJMEDIA_TYPE_VIDEO = 2, 
    6363 
    64     /** Unknown media type, in this case the name will be specified in  
     64    /** Unknown media type, in this case the name will be specified in 
    6565     *  encoding_name. 
    6666     */ 
     
    7373 
    7474 
    75 /**  
    76  * Media transport protocol.  
     75/** 
     76 * Media transport protocol. 
    7777 */ 
    7878typedef enum pjmedia_tp_proto 
     
    9393 
    9494 
    95 /**  
    96  * Media direction.  
     95/** 
     96 * Media direction. 
    9797 */ 
    9898typedef enum pjmedia_dir 
     
    139139 
    140140 
    141 /**  
    142  * Opague declaration of media endpoint.  
     141/** 
     142 * Opaque declaration of media endpoint. 
    143143 */ 
    144144typedef struct pjmedia_endpt pjmedia_endpt; 
     
    151151 
    152152 
    153 /**  
     153/** 
    154154 * Media socket info is used to describe the underlying sockets 
    155155 * to be used as media transport. 
     
    179179} pjmedia_sock_info; 
    180180 
     181/** 
     182 * Declaration of FourCC type. 
     183 */ 
     184typedef union pjmedia_fourcc { 
     185   pj_uint32_t  u32; 
     186   char         c[4]; 
     187} pjmedia_fourcc; 
     188 
     189 
     190/** 
     191 * FourCC packing macro. 
     192 */ 
     193#define PJMEDIA_FOURCC_PACK(C1, C2, C3, C4) ( C1<<24 | C2<<16 | C3<<8 | C4 ) 
     194 
     195/** 
     196 * FourCC identifier definitions. 
     197 */ 
     198#define PJMEDIA_FOURCC_L16      PJMEDIA_FOURCC_PACK(' ', 'L', '1', '6') 
     199#define PJMEDIA_FOURCC_G711A    PJMEDIA_FOURCC_PACK('G', '7', '1', '1') 
     200#define PJMEDIA_FOURCC_G711U    PJMEDIA_FOURCC_PACK('U', 'L', 'A', 'W') 
     201#define PJMEDIA_FOURCC_AMR      PJMEDIA_FOURCC_PACK(' ', 'A', 'M', 'R') 
     202#define PJMEDIA_FOURCC_G729     PJMEDIA_FOURCC_PACK('G', '7', '2', '9') 
     203#define PJMEDIA_FOURCC_ILBC     PJMEDIA_FOURCC_PACK('i', 'L', 'B', 'C') 
     204 
    181205 
    182206/** 
    183207 * This is a general purpose function set PCM samples to zero. 
    184  * Since this function is needed by many parts of the library,  
     208 * Since this function is needed by many parts of the library, 
    185209 * by putting this functionality in one place, it enables some. 
    186210 * clever people to optimize this function. 
     
    206230/** 
    207231 * This is a general purpose function to copy samples from/to buffers with 
    208  * equal size. Since this function is needed by many parts of the library,  
     232 * equal size. Since this function is needed by many parts of the library, 
    209233 * by putting this functionality in one place, it enables some. 
    210234 * clever people to optimize this function. 
     
    221245    unsigned i; 
    222246    count >>= 1; 
    223     for (i=0; i<count; ++i)  
     247    for (i=0; i<count; ++i) 
    224248        ((pj_int32_t*)dst)[i] = ((pj_int32_t*)src)[i]; 
    225249#endif 
     
    229253/** 
    230254 * This is a general purpose function to copy samples from/to buffers with 
    231  * equal size. Since this function is needed by many parts of the library,  
     255 * equal size. Since this function is needed by many parts of the library, 
    232256 * by putting this functionality in one place, it enables some. 
    233257 * clever people to optimize this function. 
     
    244268    unsigned i; 
    245269    count >>= 1; 
    246     for (i=0; i<count; ++i)  
     270    for (i=0; i<count; ++i) 
    247271        ((pj_int32_t*)dst)[i] = ((pj_int32_t*)src)[i]; 
    248272#endif 
  • pjproject/branches/projects/aps-direct/pjmedia/src/pjmedia/conference.c

    r2394 r2434  
    3434#include <pj/string.h> 
    3535 
     36#if !defined(PJMEDIA_CONF_USE_SWITCH_BOARD) || PJMEDIA_CONF_USE_SWITCH_BOARD==0 
    3637 
    3738/* CONF_DEBUG enables detailed operation of the conference bridge. 
     
    19881989} 
    19891990 
     1991#endif 
  • pjproject/branches/projects/aps-direct/pjmedia/src/pjmedia/symbian_sound.cpp

    r2394 r2434  
    2424#include <pj/os.h> 
    2525 
     26#if PJMEDIA_SOUND_IMPLEMENTATION == PJMEDIA_SOUND_SYMB_MDA_SOUND 
    2627 
    2728/* 
     
    943944    return PJ_SUCCESS; 
    944945} 
     946 
     947#endif 
  • pjproject/branches/projects/aps-direct/pjmedia/src/pjmedia/symbian_sound_aps.cpp

    r2418 r2434  
    1818 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA  
    1919 */ 
     20#include <pjmedia/symbian_sound_aps.h> 
    2021#include <pjmedia/sound.h> 
    2122#include <pjmedia/alaw_ulaw.h> 
     
    2627#include <pj/os.h> 
    2728 
     29#if PJMEDIA_SOUND_IMPLEMENTATION == PJMEDIA_SOUND_SYMB_APS_SOUND 
     30 
    2831#include <e32msgqueue.h> 
    2932#include <sounddevice.h> 
     
    4649#endif 
    4750 
    48 static pjmedia_snd_dev_info symbian_snd_dev_info =  
     51static pjmedia_snd_dev_info symbian_snd_dev_info = 
    4952{ 
    5053    "Symbian Sound Device (APS)", 
     
    5760extern TPtrC                APP_UID; 
    5861 
    59 /* Default setting for loudspeaker */ 
    60 static pj_bool_t act_loudspeaker = PJ_FALSE; 
     62/* Default setting */ 
     63static pjmedia_snd_aps_setting def_setting; 
     64 
     65/* APS G.711 frame length */ 
     66static pj_uint8_t aps_g711_frame_len; 
     67 
     68/* Pool factory */ 
     69static pj_pool_factory *snd_pool_factory; 
    6170 
    6271/* Forward declaration of CPjAudioEngine */ 
    6372class CPjAudioEngine; 
    6473 
    65 /*  
    66  * PJMEDIA Sound Stream instance  
     74/* 
     75 * PJMEDIA Sound Stream instance 
    6776 */ 
    6877struct pjmedia_snd_stream 
    6978{ 
    7079    // Pool 
    71     pj_pool_t                   *pool; 
     80    pj_pool_t           *pool; 
    7281 
    7382    // Common settings. 
    74     pjmedia_dir                  dir; 
    75     unsigned                     clock_rate; 
    76     unsigned                     channel_count; 
    77     unsigned                     samples_per_frame; 
     83    pjmedia_dir          dir; 
     84    unsigned             clock_rate; 
     85    unsigned             channel_count; 
     86    unsigned             samples_per_frame; 
     87    pjmedia_snd_rec_cb   rec_cb; 
     88    pjmedia_snd_play_cb  play_cb; 
     89    void                *user_data; 
    7890 
    7991    // Audio engine 
    80     CPjAudioEngine              *engine; 
     92    CPjAudioEngine      *engine; 
     93 
     94    pj_timestamp         ts_play; 
     95    pj_timestamp         ts_rec; 
     96 
     97    pj_int16_t          *play_buf; 
     98    pj_uint16_t          play_buf_len; 
     99    pj_uint16_t          play_buf_start; 
     100    pj_int16_t          *rec_buf; 
     101    pj_uint16_t          rec_buf_len; 
    81102}; 
    82  
    83 static pj_pool_factory *snd_pool_factory; 
    84103 
    85104 
     
    87106 * Utility: print sound device error 
    88107 */ 
    89 static void snd_perror(const char *title, TInt rc)  
     108static void snd_perror(const char *title, TInt rc) 
    90109{ 
    91110    PJ_LOG(1,(THIS_FILE, "%s (error code=%d)", title, rc)); 
    92111} 
    93   
     112 
    94113////////////////////////////////////////////////////////////////////////////// 
    95114// 
    96115 
     116typedef void(*PjAudioCallback)(TAPSCommBuffer &buf, void *user_data); 
     117 
    97118/** 
    98119 * Abstract class for handler of callbacks from APS client. 
     
    101122{ 
    102123public: 
     124    MQueueHandlerObserver(PjAudioCallback RecCb_, PjAudioCallback PlayCb_, 
     125                          void *UserData_) 
     126    : RecCb(RecCb_), PlayCb(PlayCb_), UserData(UserData_) 
     127    {} 
     128 
    103129    virtual void InputStreamInitialized(const TInt aStatus) = 0; 
    104130    virtual void OutputStreamInitialized(const TInt aStatus) = 0; 
    105131    virtual void NotifyError(const TInt aError) = 0; 
    106132 
    107     virtual void RecCb(TAPSCommBuffer &buffer) = 0; 
    108     virtual void PlayCb(TAPSCommBuffer &buffer) = 0; 
     133public: 
     134    PjAudioCallback RecCb; 
     135    PjAudioCallback PlayCb; 
     136    void *UserData; 
    109137}; 
    110138 
     
    133161    }; 
    134162 
    135     static CQueueHandler* NewL(MQueueHandlerObserver* aObserver,  
    136                                RMsgQueue<TAPSCommBuffer>* aQ,  
     163    static CQueueHandler* NewL(MQueueHandlerObserver* aObserver, 
     164                               RMsgQueue<TAPSCommBuffer>* aQ, 
     165                               RMsgQueue<TAPSCommBuffer>* aWriteQ, 
    137166                               TQueueHandlerType aType) 
    138167    { 
    139         CQueueHandler* self = new (ELeave) CQueueHandler(aObserver, aQ, aType); 
     168        CQueueHandler* self = new (ELeave) CQueueHandler(aObserver, aQ, aWriteQ, 
     169                                                         aType); 
    140170        CleanupStack::PushL(self); 
    141171        self->ConstructL(); 
     
    155185private: 
    156186    // Constructor 
    157     CQueueHandler(MQueueHandlerObserver* aObserver,  
    158                   RMsgQueue<TAPSCommBuffer>* aQ,  
    159                   TQueueHandlerType aType)  
     187    CQueueHandler(MQueueHandlerObserver* aObserver, 
     188                  RMsgQueue<TAPSCommBuffer>* aQ, 
     189                  RMsgQueue<TAPSCommBuffer>* aWriteQ, 
     190                  TQueueHandlerType aType) 
    160191        : CActive(CActive::EPriorityHigh), 
    161           iQ(aQ), iObserver(aObserver), iType(aType) 
     192          iQ(aQ), iWriteQ(aWriteQ), iObserver(aObserver), iType(aType) 
    162193    { 
    163194        CActiveScheduler::Add(this); 
     
    178209            iObserver->NotifyError(iStatus.Int()); 
    179210            return; 
    180         }     
     211        } 
    181212 
    182213        TAPSCommBuffer buffer; 
     
    191222        case ERecordQueue: 
    192223            if (buffer.iCommand == EAPSRecordData) { 
    193                 iObserver->RecCb(buffer); 
     224                iObserver->RecCb(buffer, iObserver->UserData); 
     225            } else { 
     226                iObserver->NotifyError(buffer.iStatus); 
    194227            } 
    195228            break; 
     
    200233                case EAPSPlayData: 
    201234                    if (buffer.iStatus == KErrUnderflow) { 
    202                         iObserver->PlayCb(buffer); 
     235                        iObserver->PlayCb(buffer, iObserver->UserData); 
     236                        iWriteQ->Send(buffer); 
    203237                    } 
    204238                    break; 
     
    225259                // sent from the APS main thread through EPlayCommQueue 
    226260                case EAPSRecorderInitialize: 
    227                     if (buffer.iStatus == KErrNone) { 
    228                         iObserver->InputStreamInitialized(buffer.iStatus); 
    229                         break; 
    230                     } 
    231261                case EAPSRecordData: 
     262                default: 
    232263                    iObserver->NotifyError(buffer.iStatus); 
    233                     break; 
    234                 default: 
    235264                    break; 
    236265            } 
     
    246275    } 
    247276 
     277    TInt RunError(TInt) { 
     278        return 0; 
     279    } 
     280 
    248281    // Data 
    249282    RMsgQueue<TAPSCommBuffer>   *iQ;   // (not owned) 
     283    RMsgQueue<TAPSCommBuffer>   *iWriteQ;   // (not owned) 
    250284    MQueueHandlerObserver       *iObserver; // (not owned) 
    251285    TQueueHandlerType            iType; 
    252286}; 
    253287 
     288/* 
     289 * Audio setting for CPjAudioEngine. 
     290 */ 
     291class CPjAudioSetting 
     292{ 
     293public: 
     294    TFourCC              fourcc; 
     295    TAPSCodecMode        mode; 
     296    TBool                plc; 
     297    TBool                vad; 
     298    TBool                cng; 
     299    TBool                loudspk; 
     300}; 
    254301 
    255302/* 
     
    269316 
    270317    static CPjAudioEngine *NewL(pjmedia_snd_stream *parent_strm, 
    271                                 pjmedia_snd_rec_cb rec_cb, 
    272                                 pjmedia_snd_play_cb play_cb, 
    273                                 void *user_data); 
     318                                PjAudioCallback rec_cb, 
     319                                PjAudioCallback play_cb, 
     320                                void *user_data, 
     321                                const CPjAudioSetting &setting); 
    274322 
    275323    TInt StartL(); 
     
    280328private: 
    281329    CPjAudioEngine(pjmedia_snd_stream *parent_strm, 
    282                    pjmedia_snd_rec_cb rec_cb, 
    283                    pjmedia_snd_play_cb play_cb, 
    284                    void *user_data); 
     330                   PjAudioCallback rec_cb, 
     331                   PjAudioCallback play_cb, 
     332                   void *user_data, 
     333                   const CPjAudioSetting &setting); 
    285334    void ConstructL(); 
    286      
     335 
    287336    TInt InitPlayL(); 
    288337    TInt InitRecL(); 
    289338    TInt StartStreamL(); 
    290      
     339 
    291340    // Inherited from MQueueHandlerObserver 
    292341    virtual void InputStreamInitialized(const TInt aStatus); 
     
    294343    virtual void NotifyError(const TInt aError); 
    295344 
    296     virtual void RecCb(TAPSCommBuffer &buffer); 
    297     virtual void PlayCb(TAPSCommBuffer &buffer); 
    298  
    299345    State                        state_; 
    300346    pjmedia_snd_stream          *parentStrm_; 
    301     pjmedia_snd_rec_cb           recCb_; 
    302     pjmedia_snd_play_cb          playCb_; 
    303     void                        *userData_; 
    304     pj_uint32_t                  TsPlay_; 
    305     pj_uint32_t                  TsRec_; 
     347    CPjAudioSetting              setting_; 
    306348 
    307349    RAPSSession                  iSession; 
    308     TAPSInitSettings             iSettings; 
     350    TAPSInitSettings             iPlaySettings; 
     351    TAPSInitSettings             iRecSettings; 
     352 
    309353    RMsgQueue<TAPSCommBuffer>    iReadQ; 
    310354    RMsgQueue<TAPSCommBuffer>    iReadCommQ; 
     
    315359    CQueueHandler               *iRecCommHandler; 
    316360    CQueueHandler               *iRecHandler; 
    317      
    318     static pj_uint8_t            aps_samples_per_frame; 
    319      
    320     pj_int16_t                  *play_buf; 
    321     pj_uint16_t                  play_buf_len; 
    322     pj_uint16_t                  play_buf_start; 
    323     pj_int16_t                  *rec_buf; 
    324     pj_uint16_t                  rec_buf_len; 
    325361}; 
    326362 
    327363 
    328 pj_uint8_t CPjAudioEngine::aps_samples_per_frame = 0; 
    329  
    330  
    331364CPjAudioEngine* CPjAudioEngine::NewL(pjmedia_snd_stream *parent_strm, 
    332                                      pjmedia_snd_rec_cb rec_cb, 
    333                                      pjmedia_snd_play_cb play_cb, 
    334                                      void *user_data) 
     365                                     PjAudioCallback rec_cb, 
     366                                     PjAudioCallback play_cb, 
     367                                     void *user_data, 
     368                                     const CPjAudioSetting &setting) 
    335369{ 
    336370    CPjAudioEngine* self = new (ELeave) CPjAudioEngine(parent_strm, 
    337371                                                       rec_cb, play_cb, 
    338                                                        user_data); 
     372                                                       user_data, 
     373                                                       setting); 
    339374    CleanupStack::PushL(self); 
    340375    self->ConstructL(); 
     
    344379 
    345380CPjAudioEngine::CPjAudioEngine(pjmedia_snd_stream *parent_strm, 
    346                                pjmedia_snd_rec_cb rec_cb, 
    347                                pjmedia_snd_play_cb play_cb, 
    348                                void *user_data)  
    349       : state_(STATE_NULL), 
     381                               PjAudioCallback rec_cb, 
     382                               PjAudioCallback play_cb, 
     383                               void *user_data, 
     384                               const CPjAudioSetting &setting) 
     385      : MQueueHandlerObserver(rec_cb, play_cb, user_data), 
     386        state_(STATE_NULL), 
    350387        parentStrm_(parent_strm), 
    351         recCb_(rec_cb), 
    352         playCb_(play_cb), 
    353         userData_(user_data), 
     388        setting_(setting), 
    354389        iPlayCommHandler(0), 
    355390        iRecCommHandler(0), 
     
    362397    Stop(); 
    363398 
     399    delete iRecHandler; 
    364400    delete iPlayCommHandler; 
    365     iPlayCommHandler = NULL; 
    366401    delete iRecCommHandler; 
    367     iRecCommHandler = NULL; 
     402 
     403    // On some devices, immediate closing after stopping may cause APS server 
     404    // panic KERN-EXEC 0, so let's wait for sometime before really closing 
     405    // the client session. 
     406    TTime start, now; 
     407    enum { APS_CLOSE_WAIT_TIME = 200 }; 
     408    start.UniversalTime(); 
     409    now.UniversalTime(); 
     410    while (now.MicroSecondsFrom(start) < APS_CLOSE_WAIT_TIME * 1000) { 
     411        pj_symbianos_poll(-1, APS_CLOSE_WAIT_TIME); 
     412        now.UniversalTime(); 
     413    } 
    368414 
    369415    iSession.Close(); 
     
    384430        return 0; 
    385431 
    386     TInt err = iSession.InitializePlayer(iSettings); 
     432    TInt err = iSession.InitializePlayer(iPlaySettings); 
    387433    if (err != KErrNone) { 
    388434        snd_perror("Failed to initialize player", err); 
     
    391437 
    392438    // Open message queues for the output stream 
    393     TBuf<128> buf2 = iSettings.iGlobal; 
     439    TBuf<128> buf2 = iPlaySettings.iGlobal; 
    394440    buf2.Append(_L("PlayQueue")); 
    395     TBuf<128> buf3 = iSettings.iGlobal; 
     441    TBuf<128> buf3 = iPlaySettings.iGlobal; 
    396442    buf3.Append(_L("PlayCommQueue")); 
    397443 
     
    402448 
    403449    // Construct message queue handler 
    404     iPlayCommHandler = CQueueHandler::NewL(this, 
    405                                            &iWriteCommQ, 
     450    iPlayCommHandler = CQueueHandler::NewL(this, &iWriteCommQ, &iWriteQ, 
    406451                                           CQueueHandler::EPlayCommQueue); 
    407452 
     
    418463 
    419464    // Initialize input stream device 
    420     TInt err = iSession.InitializeRecorder(iSettings); 
    421     if (err != KErrNone) { 
     465    TInt err = iSession.InitializeRecorder(iRecSettings); 
     466    if (err != KErrNone && err != KErrAlreadyExists) { 
    422467        snd_perror("Failed to initialize recorder", err); 
    423468        return err; 
    424469    } 
    425470 
    426     TBuf<128> buf1 = iSettings.iGlobal; 
     471    TBuf<128> buf1 = iRecSettings.iGlobal; 
    427472    buf1.Append(_L("RecordQueue")); 
    428     TBuf<128> buf4 = iSettings.iGlobal; 
     473    TBuf<128> buf4 = iRecSettings.iGlobal; 
    429474    buf4.Append(_L("RecordCommQueue")); 
    430475 
     
    437482 
    438483    // Construct message queue handlers 
    439     iRecCommHandler = CQueueHandler::NewL(this, 
    440                                           &iReadCommQ, 
     484    iRecHandler = CQueueHandler::NewL(this, &iReadQ, NULL, 
     485                                      CQueueHandler::ERecordQueue); 
     486    iRecCommHandler = CQueueHandler::NewL(this, &iReadCommQ, NULL, 
    441487                                          CQueueHandler::ERecordCommQueue); 
    442488 
    443489    // Start observing APS callbacks from on input stream message queue 
     490    iRecHandler->Start(); 
    444491    iRecCommHandler->Start(); 
    445      
     492 
    446493    return 0; 
    447494} 
     
    449496TInt CPjAudioEngine::StartL() 
    450497{ 
    451     TInt err = iSession.Connect(); 
    452     if (err != KErrNone && err != KErrAlreadyExists) 
    453         return err; 
    454  
    455498    if (state_ == STATE_READY) 
    456499        return StartStreamL(); 
    457500 
    458     // Even if only capturer are opened, playback thread of APS Server need  
     501    // Even if only capturer are opened, playback thread of APS Server need 
    459502    // to be run(?). Since some messages will be delivered via play comm queue. 
    460503    return InitPlayL(); 
     
    463506void CPjAudioEngine::Stop() 
    464507{ 
    465     iSession.Stop(); 
    466  
    467     delete iRecHandler; 
    468     iRecHandler = NULL; 
    469  
    470     state_ = STATE_READY; 
     508    if (state_ == STATE_STREAMING) { 
     509        iSession.Stop(); 
     510        state_ = STATE_READY; 
     511        TRACE_((THIS_FILE, "Streaming stopped")); 
     512    } 
    471513} 
    472514 
    473515void CPjAudioEngine::ConstructL() 
    474516{ 
    475     iSettings.iFourCC               = TFourCC(KMCPFourCCIdG711); 
    476     iSettings.iGlobal               = APP_UID; 
    477     iSettings.iPriority             = TMdaPriority(100); 
    478     iSettings.iPreference           = TMdaPriorityPreference(0x05210001); 
    479     iSettings.iSettings.iChannels   = EMMFMono; 
    480     iSettings.iSettings.iSampleRate = EMMFSampleRate8000Hz; 
    481     iSettings.iSettings.iVolume     = 0; 
    482      
    483     /* play_buf size is samples per frame of parent stream. */ 
    484     play_buf = (pj_int16_t*)pj_pool_alloc(parentStrm_->pool,  
    485                                           parentStrm_->samples_per_frame << 1); 
    486     play_buf_len = 0; 
    487     play_buf_start = 0; 
    488      
    489     /* rec_buf size is samples per frame of parent stream. */ 
    490     rec_buf  = (pj_int16_t*)pj_pool_alloc(parentStrm_->pool,  
    491                                           parentStrm_->samples_per_frame << 1); 
    492     rec_buf_len = 0; 
     517    // Recorder settings 
     518    iRecSettings.iFourCC                = setting_.fourcc; 
     519    iRecSettings.iGlobal                = APP_UID; 
     520    iRecSettings.iPriority              = TMdaPriority(100); 
     521    iRecSettings.iPreference            = TMdaPriorityPreference(0x05210001); 
     522    iRecSettings.iSettings.iChannels    = EMMFMono; 
     523    iRecSettings.iSettings.iSampleRate  = EMMFSampleRate8000Hz; 
     524 
     525    // Player settings 
     526    iPlaySettings.iFourCC               = setting_.fourcc; 
     527    iPlaySettings.iGlobal               = APP_UID; 
     528    iPlaySettings.iPriority             = TMdaPriority(100); 
     529    iPlaySettings.iPreference           = TMdaPriorityPreference(0x05220001); 
     530    iPlaySettings.iSettings.iChannels   = EMMFMono; 
     531    iPlaySettings.iSettings.iSampleRate = EMMFSampleRate8000Hz; 
     532    iPlaySettings.iSettings.iVolume     = 0; 
     533 
     534    User::LeaveIfError(iSession.Connect()); 
    493535} 
    494536 
     
    498540        return 0; 
    499541 
    500     iSession.SetCng(EFalse); 
    501     iSession.SetVadMode(EFalse); 
    502     iSession.SetPlc(EFalse); 
    503     iSession.SetEncoderMode(EULawOr30ms); 
    504     iSession.SetDecoderMode(EULawOr30ms); 
    505     iSession.ActivateLoudspeaker(act_loudspeaker); 
    506  
    507     // Not only playback 
    508     if (parentStrm_->dir != PJMEDIA_DIR_PLAYBACK) { 
    509         iRecHandler = CQueueHandler::NewL(this, &iReadQ,  
    510                                           CQueueHandler::ERecordQueue); 
    511         iRecHandler->Start(); 
    512         iSession.Read(); 
    513         TRACE_((THIS_FILE, "APS recorder started")); 
    514     } 
     542    iSession.SetCng(setting_.cng); 
     543    iSession.SetVadMode(setting_.vad); 
     544    iSession.SetPlc(setting_.plc); 
     545    iSession.SetEncoderMode(setting_.mode); 
     546    iSession.SetDecoderMode(setting_.mode); 
     547    iSession.ActivateLoudspeaker(setting_.loudspk); 
    515548 
    516549    // Not only capture 
    517550    if (parentStrm_->dir != PJMEDIA_DIR_CAPTURE) { 
    518551        iSession.Write(); 
    519         TRACE_((THIS_FILE, "APS player started")); 
     552        TRACE_((THIS_FILE, "Player streaming started")); 
     553    } 
     554 
     555    // Not only playback 
     556    if (parentStrm_->dir != PJMEDIA_DIR_PLAYBACK) { 
     557        iSession.Read(); 
     558        TRACE_((THIS_FILE, "Recorder streaming started")); 
    520559    } 
    521560 
     
    557596} 
    558597 
    559 void CPjAudioEngine::RecCb(TAPSCommBuffer &buffer) 
    560 { 
    561     pj_assert(buffer.iBuffer[0] == 1 && buffer.iBuffer[1] == 0); 
    562  
    563     /* Detect the recorder G.711 frame size, player frame size will follow  
    564      * this recorder frame size.  
    565      */ 
    566     if (CPjAudioEngine::aps_samples_per_frame == 0) { 
    567         CPjAudioEngine::aps_samples_per_frame = buffer.iBuffer.Length() < 160? 
    568                                                  80 : 160; 
    569         TRACE_((THIS_FILE, "Detected APS G.711 frame size = %u samples",  
    570                 CPjAudioEngine::aps_samples_per_frame)); 
    571     } 
    572  
    573     /* Decode APS buffer (coded in G.711) and put the PCM result into rec_buf. 
    574      * Whenever rec_buf is full, call parent stream callback.   
    575      */  
    576     unsigned dec_len = 0; 
    577  
    578     while (dec_len < CPjAudioEngine::aps_samples_per_frame) { 
    579         unsigned tmp; 
    580  
    581         tmp = PJ_MIN(parentStrm_->samples_per_frame - rec_buf_len,  
    582                      CPjAudioEngine::aps_samples_per_frame - dec_len); 
    583         pjmedia_ulaw_decode(&rec_buf[rec_buf_len],  
    584                             buffer.iBuffer.Ptr() + 2 + dec_len,  
    585                             tmp); 
    586         rec_buf_len += tmp; 
    587         dec_len += tmp; 
    588          
    589         pj_assert(rec_buf_len <= parentStrm_->samples_per_frame); 
    590          
    591         if (rec_buf_len == parentStrm_->samples_per_frame) { 
    592             recCb_(userData_, 0, rec_buf, rec_buf_len << 1); 
    593             rec_buf_len = 0; 
    594         } 
    595     } 
    596 } 
    597  
    598 void CPjAudioEngine::PlayCb(TAPSCommBuffer &buffer) 
    599 { 
    600     buffer.iCommand = CQueueHandler::EAPSPlayData; 
    601     buffer.iStatus = 0; 
    602     buffer.iBuffer.Zero(); 
    603     buffer.iBuffer.Append(1); 
    604     buffer.iBuffer.Append(0); 
    605  
    606     /* Send 10ms silence frame if frame size hasn't been known. */ 
    607     if (CPjAudioEngine::aps_samples_per_frame == 0) { 
    608         pjmedia_zero_samples(play_buf, 80); 
    609         pjmedia_ulaw_encode((pj_uint8_t*)play_buf, play_buf, 80); 
    610         buffer.iBuffer.Append((TUint8*)play_buf, 80); 
    611         iWriteQ.Send(buffer); 
    612         return; 
    613     } 
    614      
    615     unsigned enc_len = 0; 
    616      
    617     /* Call parent stream callback to get PCM samples to play, 
    618      * encode the PCM samples into G.711 and put it into APS buffer.  
    619      */ 
    620     while (enc_len < CPjAudioEngine::aps_samples_per_frame) { 
    621         if (play_buf_len == 0) { 
    622             playCb_(userData_, 0, play_buf, parentStrm_->samples_per_frame<<1); 
    623             play_buf_len = parentStrm_->samples_per_frame; 
    624             play_buf_start = 0; 
    625         } 
    626          
    627         unsigned tmp; 
    628          
    629         tmp = PJ_MIN(play_buf_len,  
    630                      CPjAudioEngine::aps_samples_per_frame - enc_len); 
    631         pjmedia_ulaw_encode((pj_uint8_t*)&play_buf[play_buf_start],  
    632                             &play_buf[play_buf_start],  
    633                             tmp); 
    634         buffer.iBuffer.Append((TUint8*)&play_buf[play_buf_start], tmp); 
    635         enc_len += tmp; 
    636         play_buf_len -= tmp; 
    637         play_buf_start += tmp; 
    638     } 
    639  
    640     iWriteQ.Send(buffer); 
    641 } 
    642  
    643598// 
    644599// End of inherited from MQueueHandlerObserver 
     
    650605    if (state_ == STATE_READY || state_ == STATE_STREAMING) { 
    651606        iSession.ActivateLoudspeaker(active); 
     607        TRACE_((THIS_FILE, "Loudspeaker on/off: %d", active)); 
    652608        return KErrNone; 
    653609    } 
     
    658614 
    659615 
     616static void RecCbPcm(TAPSCommBuffer &buf, void *user_data) 
     617{ 
     618    pjmedia_snd_stream *strm = (pjmedia_snd_stream*) user_data; 
     619 
     620    pj_assert(buf.iBuffer[0] == 1 && buf.iBuffer[1] == 0); 
     621 
     622    /* Detect the recorder G.711 frame size, player frame size will follow 
     623     * this recorder frame size. 
     624     */ 
     625    if (aps_g711_frame_len == 0) { 
     626        aps_g711_frame_len = buf.iBuffer.Length() < 160? 80 : 160; 
     627        TRACE_((THIS_FILE, "Detected APS G.711 frame size = %u samples", 
     628                aps_g711_frame_len)); 
     629    } 
     630 
     631    /* Decode APS buffer (coded in G.711) and put the PCM result into rec_buf. 
     632     * Whenever rec_buf is full, call parent stream callback. 
     633     */ 
     634    unsigned dec_len = 0; 
     635 
     636    while (dec_len < aps_g711_frame_len) { 
     637        unsigned tmp; 
     638 
     639        tmp = PJ_MIN(strm->samples_per_frame - strm->rec_buf_len, 
     640                     aps_g711_frame_len - dec_len); 
     641        pjmedia_ulaw_decode(&strm->rec_buf[strm->rec_buf_len], 
     642                            buf.iBuffer.Ptr() + 2 + dec_len, 
     643                            tmp); 
     644        strm->rec_buf_len += tmp; 
     645        dec_len += tmp; 
     646 
     647        pj_assert(strm->rec_buf_len <= strm->samples_per_frame); 
     648 
     649        if (strm->rec_buf_len == strm->samples_per_frame) { 
     650            strm->rec_cb(strm->user_data, 0, strm->rec_buf, 
     651                         strm->rec_buf_len << 1); 
     652            strm->rec_buf_len = 0; 
     653        } 
     654    } 
     655} 
     656 
     657static void PlayCbPcm(TAPSCommBuffer &buf, void *user_data) 
     658{ 
     659    pjmedia_snd_stream *strm = (pjmedia_snd_stream*) user_data; 
     660    unsigned g711_frame_len = aps_g711_frame_len; 
     661 
     662    buf.iCommand = CQueueHandler::EAPSPlayData; 
     663    buf.iStatus = 0; 
     664    buf.iBuffer.Zero(); 
     665    buf.iBuffer.Append(1); 
     666    buf.iBuffer.Append(0); 
     667 
     668    /* Assume frame size is 10ms if frame size hasn't been known. */ 
     669    if (g711_frame_len == 0) 
     670        g711_frame_len = 80; 
     671 
     672    /* Call parent stream callback to get PCM samples to play, 
     673     * encode the PCM samples into G.711 and put it into APS buffer. 
     674     */ 
     675    unsigned enc_len = 0; 
     676    while (enc_len < g711_frame_len) { 
     677        if (strm->play_buf_len == 0) { 
     678            strm->play_cb(strm->user_data, 0, strm->play_buf, 
     679                          strm->samples_per_frame<<1); 
     680            strm->play_buf_len = strm->samples_per_frame; 
     681            strm->play_buf_start = 0; 
     682        } 
     683 
     684        unsigned tmp; 
     685 
     686        tmp = PJ_MIN(strm->play_buf_len, g711_frame_len - enc_len); 
     687        pjmedia_ulaw_encode((pj_uint8_t*)&strm->play_buf[strm->play_buf_start], 
     688                            &strm->play_buf[strm->play_buf_start], 
     689                            tmp); 
     690        buf.iBuffer.Append((TUint8*)&strm->play_buf[strm->play_buf_start], tmp); 
     691        enc_len += tmp; 
     692        strm->play_buf_len -= tmp; 
     693        strm->play_buf_start += tmp; 
     694    } 
     695} 
     696 
     697static void RecCb(TAPSCommBuffer &buf, void *user_data) 
     698{ 
     699} 
     700 
     701static void PlayCb(TAPSCommBuffer &buf, void *user_data) 
     702{ 
     703} 
     704 
    660705/* 
    661706 * Initialize sound subsystem. 
     
    664709{ 
    665710    snd_pool_factory = factory; 
     711 
     712    def_setting.format.u32 = PJMEDIA_FOURCC_L16; 
     713    def_setting.mode = 0; 
     714    def_setting.bitrate = 128000; 
     715    def_setting.plc = PJ_FALSE; 
     716    def_setting.vad = PJ_FALSE; 
     717    def_setting.cng = PJ_FALSE; 
     718    def_setting.loudspk = PJ_FALSE; 
     719 
    666720    return PJ_SUCCESS; 
    667721} 
     
    701755    pj_pool_t *pool; 
    702756    pjmedia_snd_stream *strm; 
     757    CPjAudioSetting setting; 
     758    PjAudioCallback aps_rec_cb; 
     759    PjAudioCallback aps_play_cb; 
    703760 
    704761    PJ_ASSERT_RETURN(p_snd_strm, PJ_EINVAL); 
    705     PJ_ASSERT_RETURN(clock_rate == 8000 && channel_count == 1 &&  
     762    PJ_ASSERT_RETURN(clock_rate == 8000 && channel_count == 1 && 
    706763                     bits_per_sample == 16, PJ_ENOTSUP); 
    707764    PJ_ASSERT_RETURN((dir == PJMEDIA_DIR_CAPTURE_PLAYBACK && rec_cb && play_cb) 
     
    710767                     PJ_EINVAL); 
    711768 
    712     pool = pj_pool_create(snd_pool_factory, POOL_NAME, POOL_SIZE, POOL_INC,  
     769    pool = pj_pool_create(snd_pool_factory, POOL_NAME, POOL_SIZE, POOL_INC, 
    713770                          NULL); 
    714771    if (!pool) 
    715772        return PJ_ENOMEM; 
    716773 
    717     strm = (pjmedia_snd_stream*) pj_pool_zalloc(pool,  
     774    strm = (pjmedia_snd_stream*) pj_pool_zalloc(pool, 
    718775                                                sizeof(pjmedia_snd_stream)); 
    719776    strm->dir = dir; 
     
    723780    strm->samples_per_frame = samples_per_frame; 
    724781 
     782    /* Set audio engine settings. */ 
     783    if (def_setting.format.u32 == PJMEDIA_FOURCC_G711U || 
     784        def_setting.format.u32 == PJMEDIA_FOURCC_L16) 
     785    { 
     786        setting.fourcc = TFourCC(KMCPFourCCIdG711); 
     787    } else { 
     788        setting.fourcc = TFourCC(def_setting.format.u32); 
     789    } 
     790 
     791    if (def_setting.format.u32 == PJMEDIA_FOURCC_AMR) 
     792    { 
     793        setting.mode = (TAPSCodecMode)def_setting.bitrate; 
     794    } else if (def_setting.format.u32 == PJMEDIA_FOURCC_G711U || 
     795               def_setting.format.u32 == PJMEDIA_FOURCC_L16   || 
     796              (def_setting.format.u32 == PJMEDIA_FOURCC_ILBC  && 
     797               def_setting.mode == 30)) 
     798    { 
     799        setting.mode = EULawOr30ms; 
     800    } else { 
     801        setting.mode = EALawOr20ms; 
     802    } 
     803 
     804    setting.vad = def_setting.vad; 
     805    setting.plc = def_setting.plc; 
     806    setting.cng = def_setting.cng; 
     807    setting.loudspk = def_setting.loudspk; 
     808 
     809    if (def_setting.format.u32 == PJMEDIA_FOURCC_AMR || 
     810        def_setting.format.u32 == PJMEDIA_FOURCC_G711A || 
     811        def_setting.format.u32 == PJMEDIA_FOURCC_G711U || 
     812        def_setting.format.u32 == PJMEDIA_FOURCC_G729 || 
     813        def_setting.format.u32 == PJMEDIA_FOURCC_ILBC) 
     814    { 
     815        aps_play_cb = &PlayCb; 
     816        aps_rec_cb  = &RecCb; 
     817    } else { 
     818        aps_play_cb = &PlayCbPcm; 
     819        aps_rec_cb  = &RecCbPcm; 
     820    } 
     821 
    725822    // Create the audio engine. 
    726     TRAPD(err, strm->engine = CPjAudioEngine::NewL(strm, rec_cb, play_cb,  
    727                                                    user_data)); 
     823    TRAPD(err, strm->engine = CPjAudioEngine::NewL(strm, 
     824                                                   aps_rec_cb, aps_play_cb, 
     825                                                   strm, setting)); 
    728826    if (err != KErrNone) { 
    729         pj_pool_release(pool);   
     827        pj_pool_release(pool); 
    730828        return PJ_RETURN_OS_ERROR(err); 
    731829    } 
     830 
     831    strm->rec_cb = rec_cb; 
     832    strm->play_cb = play_cb; 
     833    strm->user_data = user_data; 
     834 
     835    /* play_buf size is samples per frame. */ 
     836    strm->play_buf = (pj_int16_t*)pj_pool_alloc(pool, samples_per_frame << 1); 
     837    strm->play_buf_len = 0; 
     838    strm->play_buf_start = 0; 
     839 
     840    /* rec_buf size is samples per frame. */ 
     841    strm->rec_buf  = (pj_int16_t*)pj_pool_alloc(pool, samples_per_frame << 1); 
     842    strm->rec_buf_len = 0; 
    732843 
    733844    // Done. 
     
    753864    PJ_ASSERT_RETURN(index == 0, PJ_EINVAL); 
    754865 
    755     return sound_open(PJMEDIA_DIR_CAPTURE, clock_rate, channel_count,  
     866    return sound_open(PJMEDIA_DIR_CAPTURE, clock_rate, channel_count, 
    756867                      samples_per_frame, bits_per_sample, rec_cb, NULL, 
    757868                      user_data, p_snd_strm); 
     
    770881    PJ_ASSERT_RETURN(index == 0, PJ_EINVAL); 
    771882 
    772     return sound_open(PJMEDIA_DIR_PLAYBACK, clock_rate, channel_count,  
     883    return sound_open(PJMEDIA_DIR_PLAYBACK, clock_rate, channel_count, 
    773884                      samples_per_frame, bits_per_sample, NULL, play_cb, 
    774885                      user_data, p_snd_strm); 
     
    790901    PJ_ASSERT_RETURN(play_id == 0 && rec_id == 0, PJ_EINVAL); 
    791902 
    792     return sound_open(PJMEDIA_DIR_CAPTURE_PLAYBACK, clock_rate, channel_count,  
     903    return sound_open(PJMEDIA_DIR_CAPTURE_PLAYBACK, clock_rate, channel_count, 
    793904                      samples_per_frame, bits_per_sample, rec_cb, play_cb, 
    794905                      user_data, p_snd_strm); 
     
    822933{ 
    823934    PJ_ASSERT_RETURN(stream != NULL, PJ_EINVAL); 
    824      
     935 
    825936    if (stream->engine) { 
    826937        TInt err = stream->engine->StartL(); 
     
    828939            return PJ_RETURN_OS_ERROR(err); 
    829940    } 
    830          
     941 
    831942    return PJ_SUCCESS; 
    832943} 
     
    836947{ 
    837948    PJ_ASSERT_RETURN(stream != NULL, PJ_EINVAL); 
    838      
     949 
    839950    if (stream->engine) { 
    840951        stream->engine->Stop(); 
    841952    } 
    842      
     953 
    843954    return PJ_SUCCESS; 
    844955} 
     
    848959{ 
    849960    pj_pool_t *pool; 
    850      
     961 
    851962    PJ_ASSERT_RETURN(stream != NULL, PJ_EINVAL); 
    852      
    853     if (stream->engine) { 
    854         delete stream->engine; 
    855         stream->engine = NULL; 
    856     } 
     963 
     964    delete stream->engine; 
     965    stream->engine = NULL; 
    857966 
    858967    pool = stream->pool; 
    859     if (pool) {  
     968    if (pool) { 
    860969        stream->pool = NULL; 
    861970        pj_pool_release(pool); 
    862971    } 
    863      
     972 
    864973    return PJ_SUCCESS; 
    865974} 
     
    876985 * Set sound latency. 
    877986 */ 
    878 PJ_DEF(pj_status_t) pjmedia_snd_set_latency(unsigned input_latency,  
     987PJ_DEF(pj_status_t) pjmedia_snd_set_latency(unsigned input_latency, 
    879988                                            unsigned output_latency) 
    880989{ 
     
    890999 */ 
    8911000PJ_DEF(pj_status_t) pjmedia_snd_aps_activate_loudspeaker( 
    892                                         pjmedia_snd_stream *stream,  
     1001                                        pjmedia_snd_stream *stream, 
    8931002                                        pj_bool_t active) 
    8941003{ 
    8951004    if (stream == NULL) { 
    896         act_loudspeaker = active; 
     1005        def_setting.loudspk = active; 
    8971006    } else { 
    8981007        if (stream->engine == NULL) 
     
    9061015    return PJ_SUCCESS; 
    9071016} 
     1017 
     1018/** 
     1019 * Set a codec and its settings to be used on the next sound device session. 
     1020 */ 
     1021PJ_DEF(pj_status_t) pjmedia_snd_aps_modify_setting( 
     1022                                    const pjmedia_snd_aps_setting *setting) 
     1023{ 
     1024    PJ_ASSERT_RETURN(setting, PJ_EINVAL); 
     1025 
     1026    def_setting = *setting; 
     1027 
     1028    return PJ_SUCCESS; 
     1029} 
     1030 
     1031#endif // PJMEDIA_SOUND_IMPLEMENTATION == PJMEDIA_SOUND_SYMB_APS_SOUND 
  • 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; 
  • pjproject/branches/projects/aps-direct/pjsip-apps/src/symsndtest/main_symbian.cpp

    r2394 r2434  
    3030 
    3131// Needed by APS 
    32 TPtrC APP_UID = _L("A000000D"); 
     32TPtrC APP_UID = _L("A000000E"); 
    3333 
    3434int app_main(); 
    3535 
    36  
    37 //////////////////////////////////////////////////////////////////////////// 
    38 class MyTask : public CActive 
    39 { 
    40 public: 
    41     static MyTask *NewL(CActiveSchedulerWait *asw); 
    42     ~MyTask(); 
    43     void Start(); 
    44  
    45 protected: 
    46     MyTask(CActiveSchedulerWait *asw); 
    47     void ConstructL(); 
    48     virtual void RunL(); 
    49     virtual void DoCancel(); 
    50  
    51 private: 
    52     RTimer timer_; 
    53     CActiveSchedulerWait *asw_; 
    54 }; 
    55  
    56 MyTask::MyTask(CActiveSchedulerWait *asw) 
    57 : CActive(EPriorityNormal), asw_(asw) 
    58 { 
    59 } 
    60  
    61 MyTask::~MyTask()  
    62 { 
    63     timer_.Close(); 
    64 } 
    65  
    66 void MyTask::ConstructL() 
    67 { 
    68     timer_.CreateLocal(); 
    69     CActiveScheduler::Add(this); 
    70 } 
    71  
    72 MyTask *MyTask::NewL(CActiveSchedulerWait *asw) 
    73 { 
    74     MyTask *self = new (ELeave) MyTask(asw); 
    75     CleanupStack::PushL(self); 
    76  
    77     self->ConstructL(); 
    78  
    79     CleanupStack::Pop(self); 
    80     return self; 
    81 } 
    82  
    83 void MyTask::Start() 
    84 { 
    85     timer_.After(iStatus, 0); 
    86     SetActive(); 
    87 } 
    88  
    89 void MyTask::RunL() 
    90 { 
    91     int rc = app_main(); 
    92     asw_->AsyncStop(); 
    93 } 
    94  
    95 void MyTask::DoCancel() 
    96 { 
    97  
    98 } 
    9936 
    10037//////////////////////////////////////////////////////////////////////////// 
     
    10643    CActiveScheduler::Install(scheduler); 
    10744 
    108     CActiveSchedulerWait *asw = new CActiveSchedulerWait; 
    109     CleanupStack::PushL(asw); 
    110      
    111     MyTask *task = MyTask::NewL(asw); 
    112     task->Start(); 
     45    app_main(); 
    11346 
    114     asw->Start(); 
    115      
    116     delete task; 
    117      
    118     CleanupStack::Pop(asw); 
    119     delete asw; 
    120      
    12147    CActiveScheduler::Install(NULL); 
    12248    CleanupStack::Pop(scheduler); 
     
    14369    TRAPD(startError, DoStartL()); 
    14470 
    145     console->Printf(_L("[press any key to close]\n")); 
    146     console->Getch(); 
    147      
     71    //console->Printf(_L("[press any key to close]\n")); 
     72    //console->Getch(); 
     73 
    14874    delete console; 
    14975    delete cleanup; 
    15076 
    151     CloseSTDLIB();  
     77    CloseSTDLIB(); 
    15278 
    15379    // Mark end of heap usage, detect memory leaks 
Note: See TracChangeset for help on using the changeset viewer.