mmserv/voipaudioservices/VoIPServer/inc/VoIPServerThread.h
changeset 0 71ca22bcf22a
child 38 9e9fc5ab059f
equal deleted inserted replaced
-1:000000000000 0:71ca22bcf22a
       
     1 /*
       
     2  * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3  * All rights reserved.
       
     4  * This component and the accompanying materials are made available
       
     5  * under the terms of "Eclipse Public License v1.0"
       
     6  * which accompanies this distribution, and is available
       
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8  *
       
     9  * Initial Contributors:
       
    10  * Nokia Corporation - initial contribution.
       
    11  *
       
    12  * Contributors:
       
    13  *
       
    14  * Description:  VoIP Audio Services - Uplink stream API
       
    15  *               Defines uplink and downlink thread objects.
       
    16  *
       
    17  */
       
    18 
       
    19 #ifndef __VOIPAUDIOSERVERTHREAD_H
       
    20 #define __VOIPAUDIOSERVERTHREAD_H
       
    21 
       
    22 #include <e32msgqueue.h>
       
    23 #include <sounddevice.h>
       
    24 #include "JitterBufferObserver.h"
       
    25 #include "JitterBuffer.h"
       
    26 #include "VoIPAudioClientServer.h"
       
    27 #include "VoIPQueueHandlerSrv.h"
       
    28 #include "VoIPSharedData.h"
       
    29 
       
    30 // FORWARD DECLARATIONS
       
    31 class CAudioOutput;
       
    32 class CErrorConcealmentIntfc;
       
    33 class CSpeechEncoderConfig;
       
    34 class CG711DecoderIntfc;
       
    35 class CG729DecoderIntfc;
       
    36 class CIlbcDecoderIntfc;
       
    37 class CG711EncoderIntfc;
       
    38 class CG729EncoderIntfc;
       
    39 class CIlbcEncoderIntfc;
       
    40 class CQueueHandlerSrv;
       
    41 
       
    42 // -----------------------------------------------------------------------------
       
    43 //  Class Name:  CVoIPThreadBase
       
    44 //
       
    45 //  Base abstract class for creating VoIP uplink and downlink threads.
       
    46 // -----------------------------------------------------------------------------
       
    47 class CVoIPThreadBase : public CBase,
       
    48                         public MDevSoundObserver,
       
    49                         public MQueueHandlerObserverSrv
       
    50     {
       
    51 public:
       
    52     enum TStreamState
       
    53         {
       
    54         ENotReady,  // not initialized
       
    55         EReady,     // initialized and ready for streaming
       
    56         EStreaming  // active streaming
       
    57         };
       
    58 
       
    59 public:
       
    60     virtual ~CVoIPThreadBase();
       
    61 
       
    62     // From MQueueHandlerObserverSrv
       
    63     virtual void Event(TInt aEventType, TInt aError) = 0;
       
    64 
       
    65 protected:
       
    66     virtual void SetCodecCiL() = 0;
       
    67     virtual void Start() = 0;
       
    68     virtual void Stop() = 0;
       
    69 
       
    70     void InitThreadL();
       
    71     void InitDevSoundL(const TMMFState aDevSoundState, const TInt aPriority,
       
    72             const TInt aPreference);
       
    73     void InitMsgQueuesL(const TDesC& aBufferQ, const TDesC& aComQ);
       
    74     TInt DoChunk(const TDesC& aChunkName, const TInt aChunkLen,
       
    75             const TInt aChunkMaxLen);
       
    76     TInt DetermineMaxBufferLen(TVoIPCodecSettings::TG711FrameRate
       
    77             aG711FrameRate = TVoIPCodecSettings::E20MS);
       
    78 
       
    79     // From MDevSoundObserver
       
    80     virtual void InitializeComplete(TInt aError) = 0;
       
    81     virtual void BufferToBeEmptied(CMMFBuffer* /*aBuffer*/) {}
       
    82     virtual void RecordError(TInt /*aError*/) {}
       
    83     virtual void BufferToBeFilled(CMMFBuffer* /*aBuffer*/) {}
       
    84     virtual void PlayError(TInt /*aError*/) {}
       
    85     virtual void ToneFinished(TInt /*aError*/) {}
       
    86     virtual void ConvertError(TInt /*aError*/) {}
       
    87     virtual void DeviceMessage(TUid /*aMessageType*/, const TDesC8& /*aMsg*/) {}
       
    88     virtual void SendEventToClient(const TMMFEvent& /*aEvent*/) {}
       
    89 
       
    90 protected:
       
    91 
       
    92     CActiveScheduler* iActiveScheduler;
       
    93     TStreamState iStatus;
       
    94     CMMFDevSound* iDevSound;
       
    95 
       
    96     RMsgQueue<TVoIPMsgBuf> iMsgQueue; // ITC back to client
       
    97     RMsgQueue<TVoIPMsgBuf> iMsgComQueue; // ITC with this thread
       
    98     CQueueHandlerSrv* iMsgQComHandler; // commands from main thread
       
    99     TVoIPMsgBuf iMsgBuffer;
       
   100     CMMFDataBuffer* iDevSoundBufPtr;
       
   101     RChunk iChunk;
       
   102     TUint32 iCodecID;
       
   103     TInt iBufLen;
       
   104     TInt iMaxBufLen;
       
   105 
       
   106     CVoIPFormatIntfc::TG711CodecMode iG711CodecMode;
       
   107     CVoIPFormatIntfc::TILBCCodecMode iILBCCodecMode;
       
   108 
       
   109     };
       
   110 
       
   111 // -----------------------------------------------------------------------------
       
   112 //  Class Name:  CVoIPDownlinkThread
       
   113 //
       
   114 //  Class handling VoIP downlink in a separate thread.
       
   115 // -----------------------------------------------------------------------------
       
   116 class CVoIPDownlinkThread : public CVoIPThreadBase,
       
   117                             public MJitterBufferObserver
       
   118     {
       
   119 public:
       
   120     static TInt ThreadFunction(TAny* aData);
       
   121     virtual ~CVoIPDownlinkThread();
       
   122 
       
   123 private:
       
   124 
       
   125     static CVoIPDownlinkThread* NewL(TSharedData& aData);
       
   126     CVoIPDownlinkThread(TSharedData& aData);
       
   127     void ConstructL();
       
   128 
       
   129     void SetCodecCiL();
       
   130     void Start();
       
   131     void Stop();
       
   132 
       
   133     void BufferFilled();
       
   134     void SetVolume();
       
   135     void GetVolume();
       
   136     void SetAudioDeviceL();
       
   137     void GetAudioDeviceL();
       
   138 
       
   139     // For CIs
       
   140     void SetIlbcCodecMode();
       
   141     void GetIlbcCodecMode();
       
   142     void SetG711CodecMode();
       
   143     void GetG711CodecMode();
       
   144     void FrameModeRqrdForEC();
       
   145     void SetFrameMode();
       
   146     void GetFrameMode();
       
   147     void ConcealErrorForNextBuffer();
       
   148     void SetCng();
       
   149     void GetCng();
       
   150     void SetPlc();
       
   151     void GetPlc();
       
   152     void BadLsfNextBuffer();
       
   153 
       
   154     // For Jitter Buffer
       
   155     /**
       
   156      * ?description
       
   157      * @since S60 v5.0
       
   158      * @param  none
       
   159      * @return void
       
   160      */
       
   161     void ConfigureJitterBufferL();
       
   162 
       
   163     /**
       
   164      * ?description
       
   165      * @since S60 v5.0
       
   166      * @param none
       
   167      * @return void
       
   168      */
       
   169     void ResetJitterBuffer();
       
   170 
       
   171     /**
       
   172      * ?description
       
   173      * @since S60 v5.0
       
   174      * @param none
       
   175      * @return void
       
   176      */
       
   177     void JBDelayDown();
       
   178 
       
   179     /**
       
   180      * ?description
       
   181      * @since S60 v5.0
       
   182      * @param none
       
   183      * @return void
       
   184      */
       
   185     void JBDelayUp();
       
   186 
       
   187     void SendCmd(TUserCommand aCmd, TInt aError = KErrNone);
       
   188 
       
   189     // From MDevSoundObserver
       
   190     virtual void InitializeComplete(TInt aError);
       
   191     virtual void BufferToBeFilled(CMMFBuffer* aBuffer);
       
   192     virtual void PlayError(TInt aError);
       
   193 
       
   194     // From MQueueHandlerObserverSrv
       
   195     virtual void Event(TInt aEventType, TInt aError);
       
   196 
       
   197     // From MJitterBufferObserver
       
   198     virtual void EventJB(TInt aEventType, TInt aError = KErrNone);
       
   199 
       
   200 private:
       
   201 
       
   202     TSharedData& iShared;
       
   203     TBool iFrameMode;
       
   204     TBool iPlc;
       
   205     CAudioOutput* iAudioOutput;
       
   206     CErrorConcealmentIntfc* iErrConcealmentIntfc;
       
   207     CG711DecoderIntfc* iG711DecoderIntfc;
       
   208     CG729DecoderIntfc* iG729DecoderIntfc;
       
   209     CIlbcDecoderIntfc* iIlbcDecoderIntfc;
       
   210 
       
   211     CVoIPJitterBuffer* iJitterBuffer;
       
   212     CMMFDataBuffer* iAddJBuffer;
       
   213     CMMFDataBuffer* iGetJBuffer;
       
   214 
       
   215 #ifdef _DEBUG
       
   216     TInt iSamplesPlayedCount;
       
   217 #endif
       
   218 
       
   219     };
       
   220 
       
   221 // -----------------------------------------------------------------------------
       
   222 //  Class Name:  CVoIPUplinkThread
       
   223 //
       
   224 //  Class handling VoIP uplink in a separate thread.
       
   225 // -----------------------------------------------------------------------------
       
   226 class CVoIPUplinkThread : public CVoIPThreadBase
       
   227     {
       
   228 public:
       
   229 
       
   230     static TInt ThreadFunction(TAny* aData);
       
   231     virtual ~CVoIPUplinkThread();
       
   232 
       
   233 private:
       
   234 
       
   235     static CVoIPUplinkThread* NewL(TSharedData& aData);
       
   236     CVoIPUplinkThread(TSharedData& aData);
       
   237     void ConstructL();
       
   238 
       
   239     void SetCodecCiL();
       
   240     void Start();
       
   241     void Stop();
       
   242 
       
   243     void BufferEmptied();
       
   244     void SetGain();
       
   245     void GetGain();
       
   246 
       
   247     // For CIs
       
   248     void SetIlbcCodecMode();
       
   249     void GetIlbcCodecMode();
       
   250     void SetG711CodecMode();
       
   251     void GetG711CodecMode();
       
   252     void GetSupportedBitrates();
       
   253     void SetBitrate();
       
   254     void GetBitrate();
       
   255     void SetVad();
       
   256     void GetVad();
       
   257 
       
   258     void SendCmd(TUserCommand aCmd, TInt aError = KErrNone);
       
   259 
       
   260     // From MDevSoundObserver
       
   261     virtual void InitializeComplete(TInt aError);
       
   262     virtual void BufferToBeEmptied(CMMFBuffer* /*aBuffer*/);
       
   263     virtual void RecordError(TInt /*aError*/);
       
   264 
       
   265     // From MQueueHandlerObserverSrv
       
   266     virtual void Event(TInt aEventType, TInt aError);
       
   267 
       
   268 private:
       
   269 
       
   270     TSharedData& iShared;
       
   271     TBool iVad;
       
   272 
       
   273     CSpeechEncoderConfig* iSpeechEncoderConfig;
       
   274     CG711EncoderIntfc* iG711EncoderIntfc;
       
   275     CG729EncoderIntfc* iG729EncoderIntfc;
       
   276     CIlbcEncoderIntfc* iIlbcEncoderIntfc;
       
   277 
       
   278 #ifdef _DEBUG
       
   279     TInt iSamplesRecCount;
       
   280 #endif
       
   281 
       
   282     };
       
   283 
       
   284 #endif  // __VOIPAUDIOSERVERTHREAD_H
       
   285 
       
   286 // End of file