os/mm/mmlibs/mmfw/inc/mmf/server/mmfdatapath.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// source\server\mmfdatapath.h
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#ifndef MMFDATAPATH_H
sl@0
    19
#define MMFDATAPATH_H
sl@0
    20
sl@0
    21
#include <mmf/common/mmfcontroller.h>
sl@0
    22
#include <mmf/server/mmfdatasource.h>
sl@0
    23
#include <mmf/server/mmfdatasink.h>
sl@0
    24
#include <mmf/server/mmfcodec.h>
sl@0
    25
#include <mmf/server/mmfbuffer.h>
sl@0
    26
#include <mmf/common/mmfutilities.h>
sl@0
    27
#include <mmf/server/mmfformat.h>
sl@0
    28
#include <mmf/server/mmfsubthreadbase.h>
sl@0
    29
sl@0
    30
/**
sl@0
    31
 * @publishedAll
sl@0
    32
 * @deprecated
sl@0
    33
 *
sl@0
    34
 * Datapath general error code used when sending events to clients
sl@0
    35
 */
sl@0
    36
const TUid KMMFErrorCategoryDataPathGeneralError = {0x101F76DC};
sl@0
    37
sl@0
    38
sl@0
    39
sl@0
    40
/**
sl@0
    41
@publishedAll
sl@0
    42
@deprecated
sl@0
    43
sl@0
    44
Abstract utility class that moves data from a single data source to a single data sink, via a codec if required.
sl@0
    45
sl@0
    46
All functions are exported form the DLL and are virtual to allow plugins to define their own data paths.
sl@0
    47
*/
sl@0
    48
class CMMFDataPath : public CActive,
sl@0
    49
					 public MDataSink,
sl@0
    50
					 public MDataSource, 
sl@0
    51
					 public MAsyncEventHandler
sl@0
    52
	{ 
sl@0
    53
public:
sl@0
    54
sl@0
    55
	//CMMFDataPath constructor if codec Uid is not already known by CMMFController
sl@0
    56
	//and there is no data path ambiguity - ie only one data path is possible
sl@0
    57
	IMPORT_C static CMMFDataPath* NewL(MAsyncEventHandler& aEventHandler); 
sl@0
    58
sl@0
    59
	//CMMFDataPath constructor if codec Uid is not already known by CMMFController
sl@0
    60
	//and there is ambiguity ie more than one possible data path TMediaId used to select path 
sl@0
    61
	IMPORT_C static CMMFDataPath* NewL(TMediaId aMediaId, MAsyncEventHandler& aEventHandler); 
sl@0
    62
sl@0
    63
	//CMMFDataPath constructor if codec Uid is already known by CMMFController
sl@0
    64
	//and there is no data path ambiguity - ie only one data path is possible
sl@0
    65
	IMPORT_C static CMMFDataPath* NewL(TUid aCodecUid, MAsyncEventHandler& aEventHandler); 
sl@0
    66
sl@0
    67
	//CMMFDataPath constructor if codec Uid is already known by CMMFController
sl@0
    68
	//and there is ambiguity ie more than one possible data path TMediaId used to select path 
sl@0
    69
	IMPORT_C static CMMFDataPath* NewL(TUid aCodecUid, TMediaId aMediaId, MAsyncEventHandler& aEventHandler);
sl@0
    70
sl@0
    71
	IMPORT_C virtual ~CMMFDataPath();
sl@0
    72
sl@0
    73
	// Called when source and sink needs to be de-referenced
sl@0
    74
	IMPORT_C virtual void ResetL();
sl@0
    75
sl@0
    76
	//from MDataSink - CMMFData path is a sink to its MDataSource
sl@0
    77
	IMPORT_C virtual void EmptyBufferL(CMMFBuffer* aBuffer, MDataSource* aSupplier, TMediaId aMediaId); //only required for an active push MDataSource requesting a buffer empty - not implemented
sl@0
    78
	IMPORT_C virtual void BufferFilledL(CMMFBuffer* aBuffer); //called by the CMMFDataPath's MDataSource when it has filled the buffer
sl@0
    79
	IMPORT_C virtual TBool CanCreateSinkBuffer(); //from both MDataSource & MDataSink?
sl@0
    80
	IMPORT_C virtual CMMFBuffer* CreateSinkBufferL(TMediaId aMediaId); //CMMFDataPath can't create buffers
sl@0
    81
	IMPORT_C virtual CMMFBuffer* CreateSinkBufferL(TMediaId aMediaId, TBool &aReference); //CMMFDataPath can't create buffers
sl@0
    82
sl@0
    83
	IMPORT_C virtual TFourCC SinkDataTypeCode(TMediaId aMediaId);
sl@0
    84
sl@0
    85
	//from MDataSource
sl@0
    86
	IMPORT_C virtual void FillBufferL(CMMFBuffer* aBuffer, MDataSink* aConsumer, TMediaId aMediaId); //only required for an active pull MDataSink requesting buffer fill - not implementated
sl@0
    87
	IMPORT_C virtual void BufferEmptiedL(CMMFBuffer* aBuffer);//called by the CMMFDataPath's MDataSink when it has emptied the buffer
sl@0
    88
	IMPORT_C virtual TBool CanCreateSourceBuffer(); //from both MDataSource & MDataSink?
sl@0
    89
	IMPORT_C virtual CMMFBuffer* CreateSourceBufferL(TMediaId aMediaId); //CMMFDataPath can't create buffers
sl@0
    90
	IMPORT_C virtual CMMFBuffer* CreateSourceBufferL(TMediaId aMediaId, TBool &aReference); //CMMFDataPath can't create buffers
sl@0
    91
	IMPORT_C virtual TFourCC SourceDataTypeCode(TMediaId aMediaId);
sl@0
    92
sl@0
    93
	IMPORT_C virtual void AddDataSourceL(MDataSource* aSource);
sl@0
    94
	IMPORT_C virtual void AddDataSinkL(MDataSink* aSink);
sl@0
    95
sl@0
    96
	//could derive these from a mixin eg MMMFControle later for active MDataSource/Sinks
sl@0
    97
	IMPORT_C virtual void PrimeL();
sl@0
    98
	IMPORT_C virtual void PlayL();
sl@0
    99
	IMPORT_C virtual void Pause();
sl@0
   100
	IMPORT_C virtual void Stop();
sl@0
   101
sl@0
   102
	IMPORT_C virtual TTimeIntervalMicroSeconds Position() const;
sl@0
   103
	IMPORT_C virtual void SetPositionL(const TTimeIntervalMicroSeconds& aPosition);
sl@0
   104
sl@0
   105
	// Play Window.
sl@0
   106
	IMPORT_C virtual void SetPlayWindowL( const TTimeIntervalMicroSeconds& aStart, const TTimeIntervalMicroSeconds& aEnd ) ;
sl@0
   107
	IMPORT_C virtual void ClearPlayWindowL() ;
sl@0
   108
sl@0
   109
	//State
sl@0
   110
	IMPORT_C virtual TInt State();
sl@0
   111
sl@0
   112
	//CActive implementations
sl@0
   113
	IMPORT_C void RunL();
sl@0
   114
	IMPORT_C void DoCancel();
sl@0
   115
	IMPORT_C TInt RunError(TInt aError);
sl@0
   116
sl@0
   117
	//error handling
sl@0
   118
	IMPORT_C TInt DoSendEventToClient(TUid aEventType, TInt aErrorCode);
sl@0
   119
sl@0
   120
	IMPORT_C TInt SetBlockLength(TUint aBlockLength);
sl@0
   121
	/**
sl@0
   122
	
sl@0
   123
	Indicates the state of the data path.
sl@0
   124
sl@0
   125
	Mimics typical MultiMedia behaviour of stopped, primed and playing
sl@0
   126
	*/
sl@0
   127
	enum TDataPathState
sl@0
   128
		{
sl@0
   129
		/** Stopped.
sl@0
   130
		*/
sl@0
   131
		EStopped,
sl@0
   132
		/** Primed.
sl@0
   133
		*/
sl@0
   134
		EPrimed,
sl@0
   135
		/** Playing.
sl@0
   136
		*/
sl@0
   137
		EPlaying,
sl@0
   138
		/** Recording.
sl@0
   139
		*/
sl@0
   140
		ERecording,
sl@0
   141
		/** Converting.
sl@0
   142
		*/
sl@0
   143
		EConverting
sl@0
   144
		};
sl@0
   145
sl@0
   146
	/**
sl@0
   147
	@internalComponent
sl@0
   148
	*/
sl@0
   149
	class CCompleteCallback : public CActive
sl@0
   150
		{
sl@0
   151
	public:
sl@0
   152
		CCompleteCallback(CMMFDataPath& aDataPath, TBool aWaitForSink);
sl@0
   153
		~CCompleteCallback();
sl@0
   154
sl@0
   155
		void SignalDataPathComplete(TInt aDataPathError);
sl@0
   156
		void SignalSinkComplete(TInt aSinkError);
sl@0
   157
		TRequestStatus& ActiveStatus();
sl@0
   158
sl@0
   159
		void DoCancel();
sl@0
   160
	private:
sl@0
   161
		void RunL();
sl@0
   162
		CMMFDataPath& iDataPath;
sl@0
   163
		TBool iDataPathComplete;
sl@0
   164
		TBool iSinkComplete;
sl@0
   165
		TBool iWaitForSink;
sl@0
   166
sl@0
   167
		TInt iSinkError;
sl@0
   168
		TInt iDataPathError;
sl@0
   169
		};
sl@0
   170
	friend class CCompleteCallback;
sl@0
   171
	friend class CMMFDataPath2;
sl@0
   172
protected:
sl@0
   173
sl@0
   174
	/**
sl@0
   175
	Indicates the transfer state.
sl@0
   176
	
sl@0
   177
	Buffers maybe be filled, emptied, or have "one" shot initialisatings performed upon them.
sl@0
   178
	
sl@0
   179
	TTransferState is used within the datapath RunL which drives databuffer exchange.
sl@0
   180
	*/
sl@0
   181
	enum TTransferState
sl@0
   182
		{
sl@0
   183
		/** Waiting on a BufferEmptied callback from sink
sl@0
   184
		*/
sl@0
   185
		EWaitSink,
sl@0
   186
		/** Waiting on a BufferFilled callback from source
sl@0
   187
		*/
sl@0
   188
		EWaitSource,
sl@0
   189
		/** Initialize the sink.
sl@0
   190
		*/
sl@0
   191
		EInitializeSink,
sl@0
   192
		/** Initialize the source.
sl@0
   193
		*/
sl@0
   194
		EInitializeSource,
sl@0
   195
		/** Source buffer does not contain data.
sl@0
   196
		*/
sl@0
   197
		ENeedSourceData,
sl@0
   198
		/** Sink buffer does not contain data.
sl@0
   199
		*/
sl@0
   200
		ENeedSinkData,
sl@0
   201
		/** There is more source data to send to the sink and need to match sink and source.
sl@0
   202
		*/
sl@0
   203
		ENeedToMatchSourceToSink,
sl@0
   204
		/** Outstanding data to send to sink.
sl@0
   205
		*/
sl@0
   206
		ESendDataToSink,
sl@0
   207
		/** End of data.
sl@0
   208
		*/
sl@0
   209
		EEndOfData //indicates that the datapath has transferred all the data to the sink
sl@0
   210
		};
sl@0
   211
sl@0
   212
sl@0
   213
sl@0
   214
sl@0
   215
protected:
sl@0
   216
	CMMFDataPath(TMediaId aMediaId, MAsyncEventHandler& aEventHandler) : 
sl@0
   217
		CActive(EPriorityStandard), MDataSink(KUidMmfDataPath), MDataSource(KUidMmfDataPath),
sl@0
   218
		iEventHandler(aEventHandler), iMediaId(aMediaId), iState(EStopped) 
sl@0
   219
			{CActiveScheduler::Add(this);};
sl@0
   220
sl@0
   221
	IMPORT_C void ConstructL(TUid aCodecUid = KNullUid);
sl@0
   222
	IMPORT_C virtual void ConstructSourceL( const TDesC8& aInitData ) ;
sl@0
   223
	IMPORT_C virtual void ConstructSinkL( const TDesC8& aInitData ) ;
sl@0
   224
	IMPORT_C virtual void EndOfData();
sl@0
   225
sl@0
   226
	//These methods use API on DevSound to determine how many samples have been played/recorded
sl@0
   227
	//and thereby determine the real position.
sl@0
   228
	TTimeIntervalMicroSeconds CalculateAudioOutputPosition() const;
sl@0
   229
	TTimeIntervalMicroSeconds CalculateAudioInputPosition() const;
sl@0
   230
sl@0
   231
	//These methods determine the position of either the input or the output.
sl@0
   232
	//The position may come from a format or from an audio input/output depending on 
sl@0
   233
	//the operation the datapath is doing (Playing (output), Recording & Converting (input))
sl@0
   234
	TTimeIntervalMicroSeconds OutputPosition() const;
sl@0
   235
	TTimeIntervalMicroSeconds InputPosition() const;
sl@0
   236
sl@0
   237
sl@0
   238
	//Determines what buffers are required (see TNeedBuffer)
sl@0
   239
	//May leave KErrNotSupported if source/sinks can't supply the necessary buffers
sl@0
   240
	TInt DetermineBuffersToUseL(void) const; 
sl@0
   241
sl@0
   242
	//Determines how many samples have been played by DevSound
sl@0
   243
	TInt AudioSamplesPlayed() const;
sl@0
   244
sl@0
   245
	//Determines how many samples have been recorded by DevSound
sl@0
   246
	TInt AudioSamplesRecorded() const;
sl@0
   247
sl@0
   248
sl@0
   249
private:
sl@0
   250
	void ChangeDataPathTransferState(TTransferState aNewDataPathTransferState);
sl@0
   251
	void CreateDataPathL(MDataSource* aSource, MDataSink* aSink);
sl@0
   252
	
sl@0
   253
	void InitializeSinkL();
sl@0
   254
	void InitializeSourceL();
sl@0
   255
	void FillSourceBufferL();
sl@0
   256
	void FillSinkBufferL();
sl@0
   257
	void EmptySinkBufferL();
sl@0
   258
	void DoCleanupBuffers();
sl@0
   259
	void ObtainSyncBuffersL(); //tries to obtain synchronous data buffers from src/snk
sl@0
   260
sl@0
   261
	TTimeIntervalMicroSeconds Duration() const;
sl@0
   262
sl@0
   263
	void DoStopL();
sl@0
   264
	void DoPauseL();
sl@0
   265
	void DoEndOfDataL();
sl@0
   266
sl@0
   267
	IMPORT_C TInt SendEventToClient(const TMMFEvent& aEvent);
sl@0
   268
sl@0
   269
	void SetBuffersAvailable();
sl@0
   270
	void ResetRefBuffers();
sl@0
   271
sl@0
   272
	
sl@0
   273
sl@0
   274
protected:
sl@0
   275
	/**
sl@0
   276
    Event handler.
sl@0
   277
	*/
sl@0
   278
	MAsyncEventHandler& iEventHandler;
sl@0
   279
sl@0
   280
	/** 
sl@0
   281
	The source of data to which the CMMFDataPath is a MDataSink for.
sl@0
   282
	*/
sl@0
   283
	MDataSource* iDataSource;
sl@0
   284
	/** 
sl@0
   285
	The sink of data for which the CMMFDataPath is a MDataSource for
sl@0
   286
	*/
sl@0
   287
	MDataSink* iDataSink;
sl@0
   288
	/** 
sl@0
   289
	Set to true when the sink is able to accept data. EFalse otherwise.
sl@0
   290
	*/
sl@0
   291
	TBool iSinkCanReceive;
sl@0
   292
	/**
sl@0
   293
	The sink's data type. Same as the codec input data type.
sl@0
   294
	*/
sl@0
   295
	TFourCC iSinkFourCC;
sl@0
   296
	/** 
sl@0
   297
	The source's data type. Same as the codec output data type.
sl@0
   298
	*/
sl@0
   299
	TFourCC iSourceFourCC;
sl@0
   300
	/** 
sl@0
   301
	Identifies which media type and stream within MDataSource.
sl@0
   302
	*/
sl@0
   303
	TMediaId iMediaId;
sl@0
   304
	/** 
sl@0
   305
	Codec in use. Null Codec is signified by == NULL
sl@0
   306
	*/
sl@0
   307
	CMMFCodec* iCodec;
sl@0
   308
sl@0
   309
	/**
sl@0
   310
    Result of processing the codec.
sl@0
   311
	*/
sl@0
   312
	TCodecProcessResult iCodecProcessResult;
sl@0
   313
sl@0
   314
	/**
sl@0
   315
	Set to ETrue when the data path has a source and a sink and can send data from the source to the sink.
sl@0
   316
	*/
sl@0
   317
	TBool iDataPathCreated;
sl@0
   318
	
sl@0
   319
	/**
sl@0
   320
	Current data path state. 
sl@0
   321
	@see TDataPathState	
sl@0
   322
	*/
sl@0
   323
	TDataPathState iState;
sl@0
   324
sl@0
   325
	/**
sl@0
   326
    Current transfer state.
sl@0
   327
	@see TTransferState
sl@0
   328
	*/
sl@0
   329
	TTransferState iTransferState;
sl@0
   330
sl@0
   331
	/**
sl@0
   332
	Set to true if data path has to use a supplied codec in its construction.
sl@0
   333
	*/
sl@0
   334
	TBool iUseSuppliedCodecUid;
sl@0
   335
sl@0
   336
	/** 
sl@0
   337
	This is set to point to whichever sink buffer is in use.
sl@0
   338
	*/
sl@0
   339
	CMMFBuffer* iSinkBuffer;
sl@0
   340
sl@0
   341
	/**
sl@0
   342
	This is the pointer to whichever source buffer is in use
sl@0
   343
	*/
sl@0
   344
	CMMFBuffer* iSourceBuffer;
sl@0
   345
sl@0
   346
	/**
sl@0
   347
	The source's position in terms of frames or some other time fixed parameter.
sl@0
   348
	*/
sl@0
   349
	TUint iCurrentSourceFrameNumber;
sl@0
   350
sl@0
   351
	/**
sl@0
   352
	The sink's position in terms of frames or some other time fixed parameter.
sl@0
   353
	*/
sl@0
   354
	TUint iCurrentSinkFrameNumber;
sl@0
   355
sl@0
   356
	/**
sl@0
   357
	Indicates that all data has been obtained from the source (ETrue if there is no more source data).
sl@0
   358
	*/
sl@0
   359
	TBool iNoMoreSourceData;
sl@0
   360
sl@0
   361
	/** 
sl@0
   362
	Indicates that all data has been sent to the sink.
sl@0
   363
	*/
sl@0
   364
	TBool iAllDataSentToSink;
sl@0
   365
sl@0
   366
	/** 
sl@0
   367
	Datapath completed because of an error; usually KErrNone.
sl@0
   368
	*/
sl@0
   369
	TUint iDataPathCompletedErrorCode;
sl@0
   370
sl@0
   371
	/**
sl@0
   372
	Start position of the play window.
sl@0
   373
	*/
sl@0
   374
	TTimeIntervalMicroSeconds iPlayWindowStartPosition ;
sl@0
   375
	
sl@0
   376
	/**
sl@0
   377
	End position of the play window.
sl@0
   378
	*/
sl@0
   379
	TTimeIntervalMicroSeconds iPlayWindowEndPosition ;
sl@0
   380
sl@0
   381
	/**	
sl@0
   382
	The position audio will start playing from.
sl@0
   383
	When stopping, this is set to iPlayWindowStartPosition.
sl@0
   384
	When pausing, this is set to the current position.
sl@0
   385
	*/
sl@0
   386
	TTimeIntervalMicroSeconds iStartPosition;
sl@0
   387
sl@0
   388
	/**	
sl@0
   389
	This value can be used to obtain the duration of the source when playing or converting.
sl@0
   390
	This is an optimisation as this value will not change if we are playing or converting.
sl@0
   391
	*/
sl@0
   392
	TTimeIntervalMicroSeconds iCachedSourceDuration;
sl@0
   393
sl@0
   394
sl@0
   395
	/** 
sl@0
   396
	ETrue if the source buffer is reference to object owned by someone else.
sl@0
   397
	*/
sl@0
   398
	TBool iSrcBufRef;
sl@0
   399
sl@0
   400
	/**
sl@0
   401
	ETrue if sink buffer is reference to object owned by someone else
sl@0
   402
	*/
sl@0
   403
	TBool iSnkBufRef;
sl@0
   404
sl@0
   405
	/**
sl@0
   406
	Indicates asynchrous buffers from AudioInput.
sl@0
   407
	*/
sl@0
   408
	TBool iObtainingAsyncSourceBuffer;
sl@0
   409
sl@0
   410
	/**
sl@0
   411
	Indicates asynchrous buffers from AudioOutput.
sl@0
   412
	*/
sl@0
   413
	TBool iObtainingAsyncSinkBuffer;
sl@0
   414
sl@0
   415
	/** 
sl@0
   416
	Indicates DoPauseL() has been called.
sl@0
   417
	*/
sl@0
   418
	TBool iPauseCalled;
sl@0
   419
sl@0
   420
	/**	
sl@0
   421
	Flag to indicate that a buffer is with the source.
sl@0
   422
sl@0
   423
	This is necessary as it is imperrative that when a buffer is with the source, it must
sl@0
   424
	not be referenced in any way. The reason for this is that it is not mandated that sources
sl@0
   425
	maintain buffer references. For example, it is valid for DevSound to return recorded data in a
sl@0
   426
	different buffer to the one supplied to it.
sl@0
   427
    */
sl@0
   428
	TBool iSourceBufferWithSource;
sl@0
   429
sl@0
   430
	/**
sl@0
   431
	Flag to indicate that a buffer is with the sink.
sl@0
   432
sl@0
   433
	This are necessary as it is imperrative that when a buffer is with the sink, it must
sl@0
   434
	not be referenced in any way. The reason for this is that it is not mandated that sinks
sl@0
   435
	maintain buffer references. For example, it is valid for DevSound to request more audio data in a
sl@0
   436
	different buffer to the one supplied to it.
sl@0
   437
	*/
sl@0
   438
	TBool iSinkBufferWithSink;
sl@0
   439
sl@0
   440
sl@0
   441
	/** 
sl@0
   442
	Holds the number of samples played on audio output at a point where we
sl@0
   443
	want to reference play duration from.
sl@0
   444
	*/
sl@0
   445
	TInt iReferenceAudioSamplesPlayed;
sl@0
   446
sl@0
   447
	/** 
sl@0
   448
	Holds the number of samples recorded from audio input at a point where we
sl@0
   449
	want to reference record duration from.
sl@0
   450
	*/
sl@0
   451
	TInt iReferenceAudioSamplesRecorded;
sl@0
   452
sl@0
   453
	/** 
sl@0
   454
	Pointer to internal callback completion class
sl@0
   455
	*/
sl@0
   456
	CCompleteCallback * iCompleteCallback;
sl@0
   457
sl@0
   458
	/**
sl@0
   459
	This indicates what buffers are required in order to operate.
sl@0
   460
	If a real Codec is in use, buffers are required from both source and sink,
sl@0
   461
	else only one is required and source is preferred.
sl@0
   462
	*/
sl@0
   463
	enum TNeedBuffer
sl@0
   464
		{
sl@0
   465
		/** No buffers needed.
sl@0
   466
		*/
sl@0
   467
		ENoBuffers = 0x0,
sl@0
   468
		/** Sink buffer needed.
sl@0
   469
		*/
sl@0
   470
		ENeedSinkBuffer = 0x01,
sl@0
   471
		/** Source buffer needed.
sl@0
   472
		*/
sl@0
   473
		ENeedSourceBuffer = 0x10
sl@0
   474
		};
sl@0
   475
sl@0
   476
	/** Holds the outcome of the call to DetermineBuffersToUseL
sl@0
   477
	*/
sl@0
   478
	TInt iBuffersToUse;
sl@0
   479
	};
sl@0
   480
sl@0
   481
#endif
sl@0
   482