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