vtprotocolplugins/VideoSource/inc/CVSDataSourceImp.h
changeset 0 ed9695c8bcbe
equal deleted inserted replaced
-1:000000000000 0:ed9695c8bcbe
       
     1 /*
       
     2 * Copyright (c) 2006 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:  Video Source subsystem.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef CVSDATASOURCEIMP_H
       
    20 #define CVSDATASOURCEIMP_H
       
    21 
       
    22 //  INCLUDE FILES
       
    23 
       
    24 #include "CApiVideoSource.h"
       
    25 
       
    26 // FORWARD DECLARATIONS
       
    27 
       
    28 class CVSDataSourceImp;
       
    29 class CVSMMFDataBuffer;
       
    30 
       
    31 // CLASS DECLARATION
       
    32 
       
    33 /**
       
    34 *  Active Object that handles switch of active provider for data source.
       
    35 *
       
    36 *  @lib videosource.lib
       
    37 */
       
    38 class CVSProviderSwitchAO : public CActive
       
    39     {
       
    40     public: // Constructors and destructor
       
    41 
       
    42         /**
       
    43         * Leave safe static constructor.
       
    44         * @param "aDataSourceImp" Pointer to VSDataSourceImp instance.
       
    45         */
       
    46         static CVSProviderSwitchAO* NewL( CVSDataSourceImp* aDataSourceImp );
       
    47 
       
    48         /**
       
    49         * Destructor.
       
    50         */
       
    51         ~CVSProviderSwitchAO();
       
    52 
       
    53     public: // New functions
       
    54 
       
    55         /**
       
    56         * Adds this instance to calling thread's active scheduler.
       
    57         * @param "aEventHandler" Reference to asynchronous event handler. This
       
    58         * will be given to provider that will be switched as active provider
       
    59         * in SourceThreadLogon() call.
       
    60         * @return Possible error code.
       
    61         */
       
    62         TInt ThreadLogon( MAsyncEventHandler& aEventHandler );
       
    63 
       
    64         /**
       
    65         * Removes this instance from calling thread's active scheduler.
       
    66         */
       
    67         void ThreadLogoff();
       
    68 
       
    69         /**
       
    70         * Initializes provider switch.
       
    71         * @param "aNewProvider" Pointer to CVSDataProvider instance that will
       
    72         * be set as active provider.
       
    73         */
       
    74         void InitiateProviderSwitch( CVSDataProvider* aNewProvider );
       
    75 
       
    76         /**
       
    77         * Return reference to event handler.
       
    78         */
       
    79         inline MAsyncEventHandler& EventHandler() { return *iEventHandler; }
       
    80 
       
    81         /**
       
    82         * Return pointer to new provider.
       
    83         */
       
    84         inline CVSDataProvider*& NewDataProvider() { return iNewProvider; }
       
    85 
       
    86     public: // Functions from base classes
       
    87 
       
    88     protected:  // New functions
       
    89 
       
    90     protected:  // Functions from base classes
       
    91 
       
    92     private:    // New functions
       
    93 
       
    94         /**
       
    95         * Constructor.
       
    96         * @param "aDataSourceImp" Pointer to VSDataSourceImp instance.
       
    97         */
       
    98         CVSProviderSwitchAO( CVSDataSourceImp* aDataSourceImp );
       
    99 
       
   100         /**
       
   101         * Leave safe construtor
       
   102         */
       
   103         void ConstructL();
       
   104 
       
   105     private:    // Functions from base classes
       
   106 
       
   107         /**
       
   108         * From CActive. See CActive for description.
       
   109         */
       
   110         void RunL();
       
   111 
       
   112         /**
       
   113         * From CActive. See CActive for description.
       
   114         */
       
   115         void DoCancel();
       
   116 
       
   117     private:    // New functions
       
   118 
       
   119         /**
       
   120         * Signals this active object with given error code.
       
   121         * @param "aError" Error code with which active object will be signalled.
       
   122         */
       
   123         void Signal( TInt aError );
       
   124 
       
   125     public: // Data
       
   126 
       
   127     protected:  // Data
       
   128 
       
   129     private:    // Data
       
   130 
       
   131         // Pointer to data source implementation.
       
   132         CVSDataSourceImp* iDataSourceImp; // not owned
       
   133 
       
   134         // Pointer to data provider that will be switched.
       
   135         CVSDataProvider* iNewProvider; // not owned
       
   136 
       
   137         // Id of thread whose active scheduler this instance is added into.
       
   138         TThreadId iThreadId;
       
   139 
       
   140         // Pointer to async handler that will be given to the new provider in
       
   141         // SourceThreadLogon() call.
       
   142         MAsyncEventHandler* iEventHandler; // not owned
       
   143 
       
   144         // Critical section for switch handling
       
   145         RCriticalSection iSwitchCs;
       
   146 
       
   147     };
       
   148 
       
   149 /**
       
   150 *  Data source observer active object. This AO is needed because we want to
       
   151 *  call vsProviderSwitchDone() callback
       
   152 *  in correct thread context.
       
   153 *
       
   154 *  @lib videosource.lib
       
   155 */
       
   156 class CVSDataSourceObserverAO : public CActive
       
   157     {
       
   158     public: // Constructors and destructor
       
   159 
       
   160         /**
       
   161         * Constructor.
       
   162         */
       
   163         CVSDataSourceObserverAO();
       
   164 
       
   165         /**
       
   166         * Destructor.
       
   167         */
       
   168         ~CVSDataSourceObserverAO();
       
   169 
       
   170     public: // New functions
       
   171 
       
   172         /**
       
   173         * This method is called when CVSProviderSwitchAO has completed provider
       
   174         * switching.
       
   175         * @param "aObserver" Observer that will signalled when RunL() is called.
       
   176         * @param "aOldProvider" Pointer to provider that was active before the
       
   177         * provider switch was done.
       
   178         */
       
   179         void vsProviderSwitchDone(
       
   180             MVSDataSourceObserver& aObserver,
       
   181             CVSDataProvider* aOldProvider );
       
   182 
       
   183     public: // Functions from base classes
       
   184 
       
   185     protected:  // New functions
       
   186 
       
   187     protected:  // Functions from base classes
       
   188 
       
   189     private:    // New functions
       
   190 
       
   191     private:    // Functions from base classes
       
   192 
       
   193         /**
       
   194         * From CActive. See CActive for description.
       
   195         */
       
   196         void RunL();
       
   197 
       
   198         /**
       
   199         * From CActive. See CActive for description.
       
   200         */
       
   201         void DoCancel();
       
   202 
       
   203     private:    // New functions
       
   204 
       
   205         /**
       
   206         * Signals this active object with given error code.
       
   207         * @param "aError" Error code with which active object will be signalled.
       
   208         */
       
   209         void Signal( TInt aError );
       
   210 
       
   211     public: // Data
       
   212 
       
   213     protected:  // Data
       
   214 
       
   215     private:    // Data
       
   216 
       
   217         // Data source observer pointer
       
   218         MVSDataSourceObserver* iObserver; // not owned
       
   219 
       
   220         // Previous active provider
       
   221         CVSDataProvider* iOldProvider; // not owned
       
   222 
       
   223         // Thread Id whose active scheduler this instance is added into
       
   224         TThreadId iThreadId;
       
   225     };
       
   226 
       
   227 
       
   228 
       
   229 /**
       
   230 *  Internal implementation of data source. This class is inherited from
       
   231 *  public data source interface. Some of the implemented MVTVideoSource,
       
   232 *  MVTVideoInput calls are forwarded to active data provider,
       
   233 *  some are processed here.
       
   234 *
       
   235 *  @lib videosource.lib
       
   236 */
       
   237 class CVSDataSourceImp : public CVSDataSource
       
   238     {
       
   239     public: // Constructors and destructor
       
   240 
       
   241         /**
       
   242         * Static factory function to create instance of this class.
       
   243         * @exception Can leave with one of the system wide error codes.
       
   244         * @return Pointer to new instance.
       
   245         */
       
   246         static CVSDataSourceImp* NewSourceL();
       
   247 
       
   248     public: // New functions
       
   249 
       
   250     public: // Functions from base classes
       
   251 
       
   252         /**
       
   253         * Switch active provider for source.
       
   254         * @param "aNewProvider" Pointer to provider instance.
       
   255         * @exception Can leave with one of the system wide error codes.
       
   256         */
       
   257         void SwitchDataProviderL( CVSDataProvider* aNewProvider );
       
   258 
       
   259         /**
       
   260         * @see CVSDataSource::PauseSending
       
   261         */
       
   262         void PauseSending();
       
   263 
       
   264         /**
       
   265         * @see CVSDataSource::ResumeSending
       
   266         */
       
   267         void ResumeSending();
       
   268 
       
   269     public: // Constructors and destructor
       
   270 
       
   271         /**
       
   272         * Destructor.
       
   273         */
       
   274         ~CVSDataSourceImp();
       
   275 
       
   276     public: // Functions from base classes
       
   277 
       
   278         /**
       
   279         * From MVTVideoSource / MDataSource. See MDataSource for description.
       
   280         */
       
   281         virtual void FillBufferL(
       
   282             CMMFBuffer* aBuffer,
       
   283             MVTVideoSink* aConsumer,
       
   284             TMediaId aMediaId );
       
   285 
       
   286         /**
       
   287         * From MVTVideoSource / MDataSource. See MDataSource for description.
       
   288         */
       
   289         void BufferEmptiedL( CMMFBuffer* aBuffer );
       
   290 
       
   291         /**
       
   292         * From MVTVideoSource / MDataSource. See MDataSource for description.
       
   293         */
       
   294         virtual TBool CanCreateSourceBuffer();
       
   295 
       
   296         /**
       
   297         * From MVTVideoSource / MDataSource. See MDataSource for description.
       
   298         */
       
   299         virtual CMMFBuffer* CreateSourceBufferL(
       
   300             TMediaId aMediaId,
       
   301             TBool &aReference );
       
   302 
       
   303         /**
       
   304         * From MVTVideoSource / MDataSource. See MDataSource for description.
       
   305         */
       
   306         virtual CMMFBuffer* CreateSourceBufferL(
       
   307             TMediaId aMediaId,
       
   308             CMMFBuffer& aSinkBuffer,
       
   309             TBool &aReference );
       
   310 
       
   311         /**
       
   312         * From MVTVideoSource / MDataSource. See MDataSource for description.
       
   313         */
       
   314         virtual TInt SourceThreadLogon( MAsyncEventHandler& aEventHandler );
       
   315 
       
   316         /**
       
   317         * From MVTVideoSource / MDataSource. See MDataSource for description.
       
   318         */
       
   319         virtual void SourceThreadLogoff();
       
   320 
       
   321         /**
       
   322         * From MVTVideoSource / MDataSource. See MDataSource for description.
       
   323         */
       
   324         virtual TInt SourcePrimeL();
       
   325 
       
   326         /**
       
   327         * From MVTVideoSource / MDataSource. See MDataSource for description.
       
   328         */
       
   329         virtual TInt SourcePlayL();
       
   330 
       
   331         /**
       
   332         * From MVTVideoSource / MDataSource. See MDataSource for description.
       
   333         */
       
   334         virtual TInt SourcePauseL();
       
   335 
       
   336         /**
       
   337         * From MVTVideoSource / MDataSource. See MDataSource for description.
       
   338         */
       
   339         virtual TInt SourceStopL();
       
   340 
       
   341     protected:  // New functions
       
   342 
       
   343     protected:  // Functions from base classes
       
   344 
       
   345         /**
       
   346         * From MDataSource. See MDataSource for description.
       
   347         */
       
   348         virtual void ConstructSourceL(const TDesC8& aInitData);
       
   349 
       
   350     public: // Functions from base classes
       
   351 
       
   352         
       
   353         virtual const RArray<TDesC8* >& GetMultimediaTypesL() const;
       
   354 
       
   355 
       
   356 
       
   357     public: // Functions from base classes
       
   358 
       
   359         /**
       
   360         * From MVTVideoInput. See MVTVideoInput for description.
       
   361         */
       
   362         virtual void SetFormatL( const TDesC8& aFormat );
       
   363 
       
   364         /**
       
   365         * From MVTVideoInput. See MVTVideoInput for description.
       
   366         */
       
   367         virtual void SetFrameRateL( TReal32 aFrameRate );
       
   368 
       
   369         /**
       
   370         * From MVTVideoInput. See MVTVideoInput for description.
       
   371         */
       
   372         virtual void SetVideoFrameSizeL( const TSize& aSize );
       
   373 
       
   374         /**
       
   375         * From MVTVideoInput. See MVTVideoInput for description.
       
   376         */
       
   377         virtual void GetVideoFrameSizeL( TSize& aSize ) const;
       
   378         
       
   379     private:    // New functions
       
   380 
       
   381         /**
       
   382         * Starts provider switching. Switching must be done in correct thread
       
   383         * context.
       
   384         * @param "aNewProvider" Pointer to provider that will be switched as
       
   385         * active.
       
   386         * @param "aEventHandler" Reference to asynchronous event handler.
       
   387         * @exception Can leave with one of the system wide error codes.
       
   388         */
       
   389         void DoProviderSwitchL(
       
   390             CVSDataProvider* aNewProvider,
       
   391             MAsyncEventHandler& aEventHandler );
       
   392 
       
   393         /**
       
   394         * Test if provider switch operation is ongoing.
       
   395         * @return ETrue if provider switch operation was suspended because
       
   396         * buffers were not free.
       
   397         */
       
   398         inline TBool SwitchPending() { return iSwitchPending; };
       
   399 
       
   400         /**
       
   401         * Notifies provider observer about error occurred in provider switch.
       
   402         * @param "aError" Standard Symbian error code
       
   403         */
       
   404         void ProviderSwitchError( TInt aError );
       
   405 
       
   406     private:    // Constructors and destructor
       
   407 
       
   408         /**
       
   409         * Constructor.
       
   410         */
       
   411         CVSDataSourceImp();
       
   412 
       
   413     private:    // Functions from base classes
       
   414 
       
   415         /**
       
   416         * From MVSBufferPool. See MVSBufferPool for description.
       
   417         */
       
   418         virtual CVSMMFDataBuffer* GetBufferL( TBool aRemove );
       
   419 
       
   420         /**
       
   421         * From MVSBufferPool. See MVSBufferPool for description.
       
   422         */
       
   423         virtual void FreeBufferL( CVSMMFDataBuffer* aBuffer );
       
   424 
       
   425     private:    // New functions
       
   426 
       
   427         /**
       
   428         * Add buffer to free buffer pool without locking queue cs.
       
   429         * @return One of the system wide error codes or KErrNone if no error
       
   430         * happens.
       
   431         * @param "aBuffer" A pointer to buffer to add to free buffer pool.
       
   432         * If buffer pointer is found from active buffer pool it is first
       
   433         * removed from there.
       
   434         */
       
   435         TInt FreeBufferNoWait( CVSMMFDataBuffer* aBuffer );
       
   436 
       
   437     public: // Data
       
   438 
       
   439     protected:  // Data
       
   440 
       
   441     private:    // Data
       
   442 
       
   443         // Data source state
       
   444         enum TDataSourceState
       
   445             {
       
   446             EStopped,
       
   447             EPrimed,
       
   448             EPlaying
       
   449             };
       
   450 
       
   451         // Data source method call flags
       
   452         enum TCallFlags
       
   453             {
       
   454             // SetVideoFrameSizeL() was called
       
   455             ESetSizeCalled = ( 1 << 0 ),
       
   456 
       
   457             // SetFrameRateL() was called
       
   458             ESetFrameRateCalled = ( 1 << 1 ),
       
   459 
       
   460             // SetFormatL() was called
       
   461             ESetFormatCalled = ( 1 << 2 )
       
   462             };
       
   463 
       
   464         // Data source state
       
   465         TDataSourceState iDSState;
       
   466 
       
   467         // Call flags
       
   468         TUint32 iCallFlags;
       
   469 
       
   470 
       
   471         // Provider switch AO pointer
       
   472         CVSProviderSwitchAO* iProviderSwitchAO;
       
   473 
       
   474         // Data source observer AO pointer
       
   475         CVSDataSourceObserverAO* iDataSourceObserverAO; // owned
       
   476 
       
   477         // Format heap descriptor pointer
       
   478         HBufC8* iFormat; // owned
       
   479 
       
   480         // Frame rate
       
   481         TReal32 iFrameRate;
       
   482 
       
   483         // Frame size
       
   484         TSize iSize;
       
   485 
       
   486         // SourceThreadLogon() called flag
       
   487         TBool iThreadLogonCalled;
       
   488 
       
   489         // Array to return in response to GetMultimediaTypesL call
       
   490         // (supported video frame formats).
       
   491         RArray<TDesC8*> iProtoMimeTypes;
       
   492 
       
   493         // Video frame formats supported by all providers.
       
   494         CDesC8Array* iSupportedVideoFormats;
       
   495 
       
   496         // Video frame sizes for each format supported by all providers
       
   497         class TVSFrameSize
       
   498             {
       
   499             public:
       
   500                 TPtrC8  iFormat;    // Primary key, 1st field
       
   501                 TSize   iSize;
       
   502             };
       
   503         RArray<TVSFrameSize> iSupportedVideoSizes;
       
   504 
       
   505         // Video frame rates for each format and frame size supported by all
       
   506         // providers.
       
   507         class TVSFrameRate
       
   508             {
       
   509             public:
       
   510                 TPtrC8  iFormat;    // Primary key, 1st field
       
   511                 TSize   iSize;      // Primary key, 2nd field
       
   512                 TReal32 iRate;
       
   513             };
       
   514 
       
   515         RArray<TVSFrameRate> iSupportedFrameRates;
       
   516 
       
   517     private:    // Data
       
   518 
       
   519         // Needs to be friend
       
   520         friend class CVSProviderSwitchAO;
       
   521 
       
   522         // MIME type holder
       
   523         TBuf8<128> iYuv420PlanarDesc;
       
   524 
       
   525     private:    // Data
       
   526 
       
   527         // Critical section for queue handling
       
   528         RCriticalSection iQueueCs;
       
   529 
       
   530         // Critical section for queue handling
       
   531         RCriticalSection iPauseCs;
       
   532 
       
   533         // Queue for buffers that are free for use
       
   534         RPointerArray<CVSMMFDataBuffer> iFreeQueue;
       
   535 
       
   536         // Queue for buffers that are being used by the Protocol
       
   537         RPointerArray<CVSMMFDataBuffer> iActiveQueue;
       
   538 
       
   539         // All buffers allocated by CreateSourceBufferL()
       
   540         RPointerArray<CVSMMFDataBuffer> iAllocatedBuffers;
       
   541 
       
   542         // Number of buffer requests by CreateSourceBufferL()
       
   543         TInt iRequestedBufferCount;
       
   544 
       
   545         // Set to ETrue when protocol is initializing (From
       
   546         // SourceThreadLogon to SourcePlayL)
       
   547         TBool iProtoInitOngoing;
       
   548 
       
   549         // Set to ETrue if provider switch operation was suspended because
       
   550         // protocol was initializing
       
   551         TBool iProviderSwitchRequestDuringProtoInit;
       
   552 
       
   553         // Temporary save pointer, not owned
       
   554         CVSDataProvider* iNewProvider;
       
   555 
       
   556         // Critical section for synchronizing access to
       
   557         // iProviderSwitchRequestDuringProtoInit and iProtoInitOngoing
       
   558         RCriticalSection iProtoInitCS;
       
   559 
       
   560         // Set to ETrue during DoProviderSwitchL
       
   561         TBool iSwitchOngoing;
       
   562 
       
   563         // Set to ETrue when DoProviderSwitchL is needed
       
   564         TBool iSwitchPending;
       
   565 
       
   566         // Set to ETrue when video sending is paused to Protocol
       
   567         // Guarded by: iPauseCs
       
   568         TBool iSendingPaused;
       
   569 
       
   570         // If true then FBS was started during SourceThreadLogon() and
       
   571         // thus should be stopped in SourceThreadLogoff()
       
   572         TBool iFbsStarted;
       
   573     };
       
   574 
       
   575 #endif      // CVSDATASOURCEIMP_H
       
   576 
       
   577 // End of File