epoc32/include/mmf/server/mmfdatasource.h
author William Roberts <williamr@symbian.org>
Tue, 16 Mar 2010 16:12:26 +0000
branchSymbian2
changeset 2 2fe1408b6811
parent 0 061f57f2323e
child 4 837f303aceeb
permissions -rw-r--r--
Final list of Symbian^2 public API header files
williamr@2
     1
// Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies).
williamr@2
     2
// All rights reserved.
williamr@2
     3
// This component and the accompanying materials are made available
williamr@2
     4
// under the terms of the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
williamr@2
     5
// which accompanies this distribution, and is available
williamr@2
     6
// at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
williamr@2
     7
//
williamr@2
     8
// Initial Contributors:
williamr@2
     9
// Nokia Corporation - initial contribution.
williamr@2
    10
//
williamr@2
    11
// Contributors:
williamr@2
    12
//
williamr@2
    13
// Description:
williamr@2
    14
// include\mmf\Server\mmfdatasource.h
williamr@2
    15
// 
williamr@2
    16
//
williamr@2
    17
williamr@2
    18
#ifndef __MMF_SERVER_DATASOURCE_H__
williamr@2
    19
#define __MMF_SERVER_DATASOURCE_H__
williamr@2
    20
williamr@2
    21
#include <e32base.h>
williamr@2
    22
#include <mmf/server/mmfdatasourcesink.hrh>
williamr@2
    23
#include <mmf/common/mmfutilities.h>
williamr@2
    24
#include <ecom/ecom.h>
williamr@2
    25
#include <mmf/common/mmfbase.h>
williamr@2
    26
#include <mmf/common/mmfcontrollerframework.h>
williamr@2
    27
williamr@2
    28
//
williamr@2
    29
// MDataSource mixim
williamr@2
    30
//
williamr@2
    31
williamr@2
    32
class CMMFBuffer;
williamr@2
    33
class MDataSink;
williamr@2
    34
class MAsyncEventHandler;
williamr@2
    35
williamr@2
    36
/**
williamr@2
    37
@publishedAll
williamr@2
    38
@released
williamr@2
    39
williamr@2
    40
Abstract class representing a data source.
williamr@2
    41
*/
williamr@2
    42
class MDataSource
williamr@2
    43
	{
williamr@2
    44
public:
williamr@2
    45
	static inline MDataSource* NewSourceL( TUid aImplementationUid,  const TDesC8& aInitData ) ;
williamr@2
    46
williamr@2
    47
	/**
williamr@2
    48
	Destructor.
williamr@2
    49
	*/
williamr@2
    50
	virtual ~MDataSource() {REComSession::DestroyedImplementation(iDtor_ID_Key);};
williamr@2
    51
williamr@2
    52
	/**
williamr@2
    53
	Returns the UID identifying the type of data source.
williamr@2
    54
williamr@2
    55
	@return	The UID identifying the type of data source.
williamr@2
    56
	*/
williamr@2
    57
	virtual TUid DataSourceType() const {return iDataSourceType;};
williamr@2
    58
williamr@2
    59
	/**
williamr@2
    60
	Returns the data type as a fourCC code of the data source.
williamr@2
    61
williamr@2
    62
	This is a pure virtual function that each derrived class must implement.
williamr@2
    63
williamr@2
    64
	@param  aMediaId
williamr@2
    65
	        This identifies the type of media eg. audio or video and the stream ID.
williamr@2
    66
	        This parameter is required in cases where the source can supply data
williamr@2
    67
	        of more than one media type and/or multiple streams of data.
williamr@2
    68
williamr@2
    69
	@return The fourCC code identifying the source datatype for the specified aMediaId.
williamr@2
    70
	*/
williamr@2
    71
	virtual TFourCC SourceDataTypeCode(TMediaId aMediaId) = 0;
williamr@2
    72
williamr@2
    73
	inline virtual TInt SetSourceDataTypeCode(TFourCC aSourceFourCC, TMediaId aMediaId);
williamr@2
    74
williamr@2
    75
	/**
williamr@2
    76
	Function called by a MDataSink to request the data source to fill aBuffer with data.
williamr@2
    77
williamr@2
    78
	This is a pure virtual function that each derived class must implement.
williamr@2
    79
	This method is used when a data source is passively waiting for requests from a consumer ie. a data sink
williamr@2
    80
	to fill a buffer. The data source must call the BufferFilledL member on aConsumer when it has filled
williamr@2
    81
	the buffer with data. The data source can either make this callback synchronously or asynchronously.
williamr@2
    82
williamr@2
    83
	The format should read the frame number of the buffer via the buffer's CMMFBuffer::FrameNumber()
williamr@2
    84
	function. From this, the format should be able to determine the actual position of the data on
williamr@2
    85
	the data source. The technique here depends on the nature of the format. For a linear audio
williamr@2
    86
	format, the position can be obtained by a simple calculation of the frame size, the header size
williamr@2
    87
	and where appropriate the datatype.
williamr@2
    88
williamr@2
    89
	For non-linear formats, either an index table of frame number and location will need to be
williamr@2
    90
	created in the NewL() or some form of approximating algorithm will be required. Some formats
williamr@2
    91
	have an index table as part of the format eg. AVI. If no random access is required then no index
williamr@2
    92
	table is required, the format can keep track of the current read position and increment it on
williamr@2
    93
	each access, and reset it if the frame number is reset to 0 or 1. Given that for non-linear
williamr@2
    94
	ie. variable bit rate formats, the size of the data read may vary from frame to frame, then the
williamr@2
    95
	format should either set the request size of the buffer for the required frame or call the
williamr@2
    96
	source's ReadBufferL() (either CMMFClip::ReadBufferL(), CMMFDescriptor ::ReadBufferL() or
williamr@2
    97
	CMMFFile::ReadBufferL()) function that takes the aLength parameter.
williamr@2
    98
williamr@2
    99
	It is the responsibility of the format decode to determine the size and position of the source
williamr@2
   100
	data for each frame. For linear audio formats, the format decode should fill the buffer up to
williamr@2
   101
	its maximum length. For multimedia formats e.g. mp4, AVI etc, the format decode is effectively
williamr@2
   102
	acting as a demultiplexor, and must obtain the appropriate data from the source depending on
williamr@2
   103
	the aMediaId.
williamr@2
   104
williamr@2
   105
	@param  aBuffer
williamr@2
   106
	        The buffer that needs filling with data.
williamr@2
   107
	@param  aConsumer
williamr@2
   108
	        The data sink that consumes the data. The data source needs this to make the BufferFilledL
williamr@2
   109
	        callback on aConsumer when the data source has completed filling the aBuffer.
williamr@2
   110
	@param  aMediaId
williamr@2
   111
	        This identifies the type of media eg. audio or video and the stream ID.
williamr@2
   112
	        This parameter is required in cases where the source can supply data
williamr@2
   113
	        of more than one media type and/or multiple strams of data eg. a multimedia file.
williamr@2
   114
	*/
williamr@2
   115
	virtual void FillBufferL(CMMFBuffer* aBuffer, MDataSink* aConsumer,TMediaId aMediaId)=0;
williamr@2
   116
williamr@2
   117
	/**
williamr@2
   118
	Function called by a data sink to pass back an emptied buffer to the source.
williamr@2
   119
williamr@2
   120
	This is a pure virtual function that each derived class must implement.
williamr@2
   121
	This method is used as the callback when the data source actively requests a consumer ie. a data
williamr@2
   122
	sink to empty a buffer by calling the data sinks EmptyBufferL.
williamr@2
   123
	When the data source gets this callback it knows that the buffer has been emptied and can be
williamr@2
   124
	reused.
williamr@2
   125
williamr@2
   126
	@param  aBuffer
williamr@2
   127
	        The buffer that has been emptied by a data sink and is now available for reuse.
williamr@2
   128
	*/
williamr@2
   129
	virtual void BufferEmptiedL(CMMFBuffer* aBuffer)=0;
williamr@2
   130
williamr@2
   131
	/**
williamr@2
   132
	@deprecated
williamr@2
   133
williamr@2
   134
	Function to indicate whether the data source can create a buffer.
williamr@2
   135
williamr@2
   136
	This is a pure virtual function that each derived class must implement.
williamr@2
   137
williamr@2
   138
	@return	A boolean indicating if the data source can create a buffer. ETrue if it can otherwise
williamr@2
   139
	        EFalse.
williamr@2
   140
	*/
williamr@2
   141
	virtual TBool CanCreateSourceBuffer()=0;
williamr@2
   142
williamr@2
   143
	/**
williamr@2
   144
	@deprecated
williamr@2
   145
williamr@2
   146
	Returns a buffer created by the data source
williamr@2
   147
williamr@2
   148
	This is a pure virtual function that each derived class must implement.
williamr@2
   149
williamr@2
   150
	@param	aMediaId
williamr@2
   151
	        This identifies the type of media eg. audio or video and the stream ID.
williamr@2
   152
	        This parameter is required in cases where the source can supply data
williamr@2
   153
	        of more than one media type and/or multiple strams of data eg a multimedia file.
williamr@2
   154
	@param  aReference
williamr@2
   155
	        This must be written to by the method to indicate whether the created buffer is
williamr@2
   156
	        a 'reference' buffer.  A 'reference' buffer is a buffer that is owned by the source
williamr@2
   157
	        and should be used in preference to the sink buffer provided the sink buffer
williamr@2
   158
	        is also not a reference buffer.
williamr@2
   159
williamr@2
   160
	@return	A pointer to the created buffer.
williamr@2
   161
	*/
williamr@2
   162
	virtual CMMFBuffer* CreateSourceBufferL(TMediaId aMediaId, TBool &aReference) = 0;
williamr@2
   163
williamr@2
   164
	inline virtual CMMFBuffer* CreateSourceBufferL(TMediaId aMediaId, CMMFBuffer& aSinkBuffer, TBool &aReference);
williamr@2
   165
williamr@2
   166
	inline virtual TInt SourceThreadLogon(MAsyncEventHandler& aEventHandler);
williamr@2
   167
williamr@2
   168
	/**
williamr@2
   169
	Function to 'logoff' the data source from the same thread that source supplies data in.
williamr@2
   170
williamr@2
   171
	This method may be required as the thread that the data source is deleted in may not be
williamr@2
   172
	the same thread that the data transfer took place in.  Therefore any thread specific
williamr@2
   173
	releasing of resources needs to be performed in the SourceThreadLogoff rather than in the
williamr@2
   174
	destructor.
williamr@2
   175
williamr@2
   176
	This is a virtual function that a derrived data source can implement if any thread specific
williamr@2
   177
	releasing of resources is required.
williamr@2
   178
	*/
williamr@2
   179
	virtual void SourceThreadLogoff() {};
williamr@2
   180
williamr@2
   181
	inline virtual void NegotiateSourceL(MDataSink& aDataSink); //called if source setup depends on sink
williamr@2
   182
williamr@2
   183
	/**
williamr@2
   184
	Indicates whether the data source supports sample rate conversion.
williamr@2
   185
williamr@2
   186
	This is a virtual function that a derived class can implement.
williamr@2
   187
williamr@2
   188
	@return	A boolean indicating if the data source can perform a sample rate conversion. ETrue if 
williamr@2
   189
	        it can otherwise EFalse.
williamr@2
   190
	*/
williamr@2
   191
	virtual TBool SourceSampleConvert() {return EFalse;};
williamr@2
   192
	
williamr@2
   193
	/**
williamr@2
   194
	Function to 'prime' the data source.
williamr@2
   195
	
williamr@2
   196
	This is a virtual function that a derrived data source can implement if
williamr@2
   197
	any data source specific 'priming' is required.
williamr@2
   198
	*/
williamr@2
   199
	virtual void SourcePrimeL() {};
williamr@2
   200
	
williamr@2
   201
	/**
williamr@2
   202
	Function to 'play' the data source.
williamr@2
   203
williamr@2
   204
	This is a virtual function that a derrived data source can implement if
williamr@2
   205
	any data source specific action is required prior to 'playing' ie. the start of data transfer.
williamr@2
   206
	*/
williamr@2
   207
	virtual void SourcePlayL() {};
williamr@2
   208
williamr@2
   209
	/**
williamr@2
   210
	Function to 'pause' the data source.
williamr@2
   211
williamr@2
   212
	This is a virtual function that a derrived data source can implement if
williamr@2
   213
	any data source specific action is required to 'pause'
williamr@2
   214
	*/
williamr@2
   215
	virtual void SourcePauseL() {};
williamr@2
   216
williamr@2
   217
	/**
williamr@2
   218
	Function to 'stop' the data source.
williamr@2
   219
williamr@2
   220
	This is a virtual function that a derrived data source can implement if
williamr@2
   221
	any data source specific action is required to 'stop'.
williamr@2
   222
	*/
williamr@2
   223
	virtual void SourceStopL() {};
williamr@2
   224
williamr@2
   225
	inline virtual void SetSourcePrioritySettings(const TMMFPrioritySettings& aPrioritySettings);
williamr@2
   226
williamr@2
   227
	/**
williamr@2
   228
	Function to call a source specific custom command.
williamr@2
   229
williamr@2
   230
	This is a virtual function that a derrived data source can implement if
williamr@2
   231
	it implements any custom commands.
williamr@2
   232
williamr@2
   233
	@param  aMessage
williamr@2
   234
	        The message specifying the custom command.
williamr@2
   235
	*/
williamr@2
   236
	virtual void SourceCustomCommand(TMMFMessage& aMessage) {aMessage.Complete(KErrNotSupported);};
williamr@2
   237
protected:
williamr@2
   238
williamr@2
   239
	/**
williamr@2
   240
	Performs any source construction dependant on the source construction
williamr@2
   241
	initialisation data aInitData.
williamr@2
   242
williamr@2
   243
	This is a pure virtual function that a derrived data source must implement
williamr@2
   244
williamr@2
   245
	@param  aInitData
williamr@2
   246
	        The source specific initialisation data required for source construction.
williamr@2
   247
	*/
williamr@2
   248
	virtual void ConstructSourceL(  const TDesC8& aInitData ) = 0 ;
williamr@2
   249
williamr@2
   250
	/**
williamr@2
   251
	Protected constructor.
williamr@2
   252
	*/
williamr@2
   253
	MDataSource(TUid aType): iDataSourceType(aType) {}
williamr@2
   254
private:
williamr@2
   255
	TUid iDataSourceType;
williamr@2
   256
	TUid iDtor_ID_Key;
williamr@2
   257
williamr@2
   258
	};
williamr@2
   259
williamr@2
   260
/**
williamr@2
   261
Instantiates a data source.
williamr@2
   262
williamr@2
   263
@param  aImplementationUid
williamr@2
   264
        The UID identifying the data source to be instantiated.
williamr@2
   265
@param  aInitData
williamr@2
   266
        The source specific initialisation data required for source construction.
williamr@2
   267
williamr@2
   268
@return	The instantiated data source.
williamr@2
   269
*/
williamr@2
   270
inline MDataSource* MDataSource::NewSourceL( TUid aImplementationUid, const TDesC8& aInitData )
williamr@2
   271
	{
williamr@2
   272
	MDataSource* retPtr = REINTERPRET_CAST( MDataSource*, REComSession::CreateImplementationL( aImplementationUid,
williamr@2
   273
																			_FOFF(MDataSource, iDtor_ID_Key) ) ) ;
williamr@2
   274
	CleanupDeletePushL(retPtr);
williamr@2
   275
	retPtr->ConstructSourceL( aInitData ) ;
williamr@2
   276
williamr@2
   277
	CleanupStack::Pop(retPtr);
williamr@2
   278
	return retPtr ;
williamr@2
   279
	}
williamr@2
   280
williamr@2
   281
/**
williamr@2
   282
Sets the data type as a fourCC code for the data source.
williamr@2
   283
williamr@2
   284
This is a virtual function that each derived class can implement if the data source supports
williamr@2
   285
the ability to have its data type set.
williamr@2
   286
williamr@2
   287
@param  aSourceFourCC
williamr@2
   288
        This specifies the data type as a fourCC code to set the source to.
williamr@2
   289
@param  aMediaId
williamr@2
   290
        This identifies the type of media eg. audio or video and the stream ID.
williamr@2
   291
        This parameter is required in cases where the source can supply data
williamr@2
   292
        of more than one media type and/or multiple strams of data eg a multimedia file.
williamr@2
   293
williamr@2
   294
@return	KErrNone if successful, KErrNotSupported if the source does not support having
williamr@2
   295
        it's data type set, otherwise a system wide error code.
williamr@2
   296
*/
williamr@2
   297
inline TInt MDataSource::SetSourceDataTypeCode(TFourCC /*aSourceFourCC*/, TMediaId /*aMediaId*/)
williamr@2
   298
{
williamr@2
   299
	return KErrNotSupported;
williamr@2
   300
}
williamr@2
   301
williamr@2
   302
/**
williamr@2
   303
@deprecated
williamr@2
   304
williamr@2
   305
Returns a buffer created by the data source.
williamr@2
   306
williamr@2
   307
This is a virtual function that a derived class can implement.
williamr@2
   308
This can be used in preference to the above CreateSourceBufferL method in cases where
williamr@2
   309
the source buffer creation has a dependancy on the sink buffer.
williamr@2
   310
williamr@2
   311
@param  aMediaId
williamr@2
   312
        This identifies the type of media eg. audio or video and the stream ID.
williamr@2
   313
        This parameter is required in cases where the source can supply data
williamr@2
   314
        of more than one media type and/or multiple strams of data eg a multimedia file
williamr@2
   315
@param  aSinkBuffer
williamr@2
   316
        The sink buffer the nature of which may influence the creation of the source buffer.
williamr@2
   317
@param  aReference
williamr@2
   318
        This must be written to by the method to indicate whether the created buffer is
williamr@2
   319
        a 'reference' buffer.  A 'reference' buffer is a buffer that is owned by the source
williamr@2
   320
        and should be used in preference to the sink buffer provided the sink buffer is not a
williamr@2
   321
        reference buffer.
williamr@2
   322
williamr@2
   323
@return A pointer to the created buffer.
williamr@2
   324
*/
williamr@2
   325
inline CMMFBuffer* MDataSource::CreateSourceBufferL(TMediaId aMediaId, CMMFBuffer& /*aSinkBuffer*/, TBool &aReference)
williamr@2
   326
{
williamr@2
   327
	return CreateSourceBufferL(aMediaId, aReference);
williamr@2
   328
}
williamr@2
   329
williamr@2
   330
/**
williamr@2
   331
Function to 'logon' the data source to the same thread that source will be supplying data in.
williamr@2
   332
williamr@2
   333
This method may be required as the thread that the data source was created in is not always
williamr@2
   334
the same thread that the data transfer will take place in.  Therefore any thread specific
williamr@2
   335
initialisation needs to be performed in the SourceThreadLogon rather than in the creation
williamr@2
   336
of the data source.
williamr@2
   337
williamr@2
   338
This is a virtual function that a derrived data source can implement if any thread specific
williamr@2
   339
initialisation is required and/or the data source can create any asynchronous events.
williamr@2
   340
williamr@2
   341
@param  aEventHandler
williamr@2
   342
        This is an MAsyncEventHandler to handle asynchronous events that occur during the
williamr@2
   343
        transfer of multimedia data.  The event handler must be in the same thread as the data transfer
williamr@2
   344
        thread. Hence the reason it is passed in the SourceThreadLogon as opposed to say the constructor.
williamr@2
   345
williamr@2
   346
@return An error code indicating if the function call was successful. KErrNone on success, otherwise
williamr@2
   347
        another of the system-wide error codes.
williamr@2
   348
*/
williamr@2
   349
inline TInt MDataSource::SourceThreadLogon(MAsyncEventHandler& /*aEventHandler*/)
williamr@2
   350
{
williamr@2
   351
	return KErrNone;
williamr@2
   352
}
williamr@2
   353
williamr@2
   354
/**
williamr@2
   355
Function to allow the data source to negotiate with a data sink
williamr@2
   356
williamr@2
   357
This method is required in cases where the settings of data source are dependant on those of a
williamr@2
   358
data sink. This is a virtual function that a derrived data source can implement.
williamr@2
   359
williamr@2
   360
@param  aDataSink
williamr@2
   361
        The data sink whose settings can affect the data source.
williamr@2
   362
*/
williamr@2
   363
inline void MDataSource::NegotiateSourceL(MDataSink& /*aDataSink*/)
williamr@2
   364
{
williamr@2
   365
}
williamr@2
   366
williamr@2
   367
/**
williamr@2
   368
Function to set the source priority settings.
williamr@2
   369
williamr@2
   370
This is a virtual function that a derrived data source can implement if
williamr@2
   371
a priority mechanism is required to arbitrate between multiple clients
williamr@2
   372
trying to access the same resource.
williamr@2
   373
williamr@2
   374
@param  aPrioritySettings
williamr@2
   375
        The source priority settings.
williamr@2
   376
williamr@2
   377
@capability MultimediaDD
williamr@2
   378
            A process requesting or using this method that has MultimediaDD capability will
williamr@2
   379
			always have precedence over a process that does not have MultimediaDD.
williamr@2
   380
*/
williamr@2
   381
inline void MDataSource::SetSourcePrioritySettings(const TMMFPrioritySettings& /*aPrioritySettings*/)
williamr@2
   382
{
williamr@2
   383
}
williamr@2
   384
williamr@2
   385
/**
williamr@2
   386
This function is used by TCleanupItem objects to perform
williamr@2
   387
a SourceStopL() when leaving functions exist, ususally between SourcePrimeL-SourceStopL pairs.
williamr@2
   388
williamr@2
   389
@param  aSource
williamr@2
   390
        The data source to be stopped.
williamr@2
   391
*/
williamr@2
   392
inline static void DoDataSourceStop(TAny* aSource)
williamr@2
   393
	{
williamr@2
   394
	MDataSource* source = STATIC_CAST(MDataSource*, aSource);
williamr@2
   395
	// we don't want this function to leave because no leaving functions are supposed
williamr@2
   396
	// to be used as argument to the TCleanupItem objects. Hence we catch the error but
williamr@2
   397
	// we do nothing with it.
williamr@2
   398
	TRAP_IGNORE(source->SourceStopL());
williamr@2
   399
	}
williamr@2
   400
williamr@2
   401
/**
williamr@2
   402
This method is used by TCleanupItem objects to perform a SourceThreadLogoff().
williamr@2
   403
williamr@2
   404
@param  aSource
williamr@2
   405
        The data source to be logged off.
williamr@2
   406
*/
williamr@2
   407
inline static void DoDataSourceThreadLogoff(TAny* aSource)
williamr@2
   408
	{
williamr@2
   409
	MDataSource* source = STATIC_CAST(MDataSource*, aSource);
williamr@2
   410
	source->SourceThreadLogoff();
williamr@2
   411
	}
williamr@2
   412
williamr@2
   413
#endif