os/mm/mmlibs/mmfw/inc/mmf/server/mmfdatasink.h
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
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\mmfdatasink.h
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#ifndef __MMF_SERVER_DATASINK_H__
sl@0
    19
#define __MMF_SERVER_DATASINK_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
// MDataSink mixim
sl@0
    30
//
sl@0
    31
sl@0
    32
class TFourCC;
sl@0
    33
class TMediaId;
sl@0
    34
class CMMFBuffer;
sl@0
    35
class MDataSource;
sl@0
    36
class MAsyncEventHandler;
sl@0
    37
sl@0
    38
/**
sl@0
    39
@publishedAll
sl@0
    40
@released
sl@0
    41
sl@0
    42
Abstract class representing a data sink.
sl@0
    43
*/
sl@0
    44
class MDataSink
sl@0
    45
	{
sl@0
    46
public:
sl@0
    47
sl@0
    48
	static inline MDataSink* NewSinkL( TUid aImplementationUid,  const TDesC8& aInitData ) ;
sl@0
    49
sl@0
    50
	/**
sl@0
    51
	Destructor.
sl@0
    52
	*/
sl@0
    53
	virtual ~MDataSink() {REComSession::DestroyedImplementation(iDtor_ID_Key);};
sl@0
    54
sl@0
    55
	/**
sl@0
    56
	Returns the UID identifying the type of data sink.
sl@0
    57
sl@0
    58
	@return The UID identifying the type of data sink
sl@0
    59
	*/
sl@0
    60
	virtual TUid DataSinkType() const {return iDataSinkType;};
sl@0
    61
sl@0
    62
	/**
sl@0
    63
	Returns the data type as a fourCC code of the data sink.
sl@0
    64
sl@0
    65
	This is a pure virtual function that each derrived class must implement.
sl@0
    66
sl@0
    67
	@param  aMediaId
sl@0
    68
	        This identifies the type of media eg. audio or video and the stream ID.
sl@0
    69
	        This parameter is required in cases where the sink can accept data
sl@0
    70
	        of more than one media type and/or multiple streams of data.
sl@0
    71
sl@0
    72
	@return The fourCC code identifying the sink datatype for the specified aMediaId.
sl@0
    73
	*/
sl@0
    74
	virtual TFourCC SinkDataTypeCode(TMediaId aMediaId) = 0;
sl@0
    75
sl@0
    76
	inline virtual TInt SetSinkDataTypeCode(TFourCC aSinkFourCC, TMediaId aMediaId);
sl@0
    77
sl@0
    78
	/**
sl@0
    79
	Method called by a MDataSource to request the data sink to empty aBuffer of data.
sl@0
    80
sl@0
    81
	This is a pure virtual function that each derived class must implement.
sl@0
    82
	This method is used when a data sink is passively waiting for requests from a supplier ie.
sl@0
    83
	a data source to empty a buffer. The data sink must call the BufferEmptiedL member on aSupplier 
sl@0
    84
	when it has emptied	the buffer of it's data. The data sink can either make this callback 
sl@0
    85
	synchronously or asynchronously.
sl@0
    86
sl@0
    87
	@param  aBuffer
sl@0
    88
	        The full buffer that needs emptying of it's data.
sl@0
    89
	@param  aSupplier
sl@0
    90
	        The data source that supplied the data. The data sink needs this to make the 
sl@0
    91
	        BufferEmptiedL callback on aSupplier to indicate to the data source that the data sink
sl@0
    92
	        has finished with the buffer.
sl@0
    93
	@param  aMediaId
sl@0
    94
	        This identifies the type of media eg. audio or video and the stream ID.
sl@0
    95
	        This parameter is required in cases where the source can supply data
sl@0
    96
	        of more than one media type and/or multiple streams of data.
sl@0
    97
	*/
sl@0
    98
	virtual void EmptyBufferL(CMMFBuffer* aBuffer, MDataSource* aSupplier, TMediaId aMediaId)=0;
sl@0
    99
sl@0
   100
	/**
sl@0
   101
	Function called by a data source to pass back a filled buffer to the sink.
sl@0
   102
sl@0
   103
	This is a pure virtual function that each derived class must implement.
sl@0
   104
	This method is used as the callback when the data sink actively requests a supplier ie. a
sl@0
   105
	data source	to fill a buffer by calling the data sources FillBufferL. When the data sink gets
sl@0
   106
	this callback it knows that the buffer has been filled and is ready to be emptied.
sl@0
   107
sl@0
   108
	@param  aBuffer
sl@0
   109
	        The buffer that has been filled by a data source and is now available for processing.
sl@0
   110
	*/
sl@0
   111
	virtual void BufferFilledL(CMMFBuffer* aBuffer)=0;
sl@0
   112
	
sl@0
   113
	/**
sl@0
   114
	@deprecated
sl@0
   115
sl@0
   116
	Function to indicate whether the data sink can create a buffer.
sl@0
   117
sl@0
   118
	This is a pure virtual function that each derived class must implement.
sl@0
   119
sl@0
   120
	@return	A boolean indicating if the data sink can create a buffer. ETrue if it can otherwise 
sl@0
   121
	        EFalse.
sl@0
   122
	*/
sl@0
   123
	virtual TBool CanCreateSinkBuffer()=0;
sl@0
   124
	
sl@0
   125
	/**
sl@0
   126
	Returns a buffer created by the data sink.
sl@0
   127
sl@0
   128
	This is a pure virtual function that each derived class must implement.
sl@0
   129
sl@0
   130
	@param  aMediaId
sl@0
   131
	        This identifies the type of media eg. audio or video and the stream ID.
sl@0
   132
	        This parameter is required in cases where the source can supply data
sl@0
   133
	        of more than one media type and/or multiple streams of data.
sl@0
   134
sl@0
   135
	@param  aReference
sl@0
   136
	        This must be written to by the method to indicate whether the created buffer is
sl@0
   137
	        a 'reference' buffer.  A 'reference' buffer is a buffer that is owned by the sink
sl@0
   138
	        and should be used in preference to the source buffer provided the source buffer
sl@0
   139
	        is also not a reference buffer.
sl@0
   140
sl@0
   141
	@return	The created buffer.
sl@0
   142
	*/
sl@0
   143
	virtual CMMFBuffer* CreateSinkBufferL(TMediaId aMediaId, TBool &aReference)=0;
sl@0
   144
sl@0
   145
	inline virtual TInt SinkThreadLogon(MAsyncEventHandler& aEventHandler);
sl@0
   146
sl@0
   147
	/**
sl@0
   148
	Function to 'logoff' the data sink from the same thread that sink consumes data in.
sl@0
   149
sl@0
   150
	This method may be required as the thread that the data sink is deleted in may not be
sl@0
   151
	the same thread that the data transfer took place in.  Therefore any thread specific
sl@0
   152
	releasing of resources needs to be performed in the SinkThreadLogoff rather than in the
sl@0
   153
	destructor.
sl@0
   154
sl@0
   155
	This is a virtual function that a derrived data sink can implement if any thread specific
sl@0
   156
	releasing of resources is required.
sl@0
   157
	*/
sl@0
   158
	virtual void SinkThreadLogoff() {};
sl@0
   159
sl@0
   160
	inline virtual void NegotiateL(MDataSource& aDataSource);
sl@0
   161
sl@0
   162
	/**
sl@0
   163
	Function to 'prime' the data sink.
sl@0
   164
sl@0
   165
	This is a virtual function that a derrived data sink can implement if
sl@0
   166
	any data sink specific 'priming' is required.
sl@0
   167
	*/
sl@0
   168
	virtual void SinkPrimeL() {};
sl@0
   169
sl@0
   170
	/**
sl@0
   171
	Function 'play' the data sink.
sl@0
   172
sl@0
   173
	This is a virtual function that a derrived data sink can implement if
sl@0
   174
	any data sink specific action is required prior to 'playing' ie. the start of data transfer.
sl@0
   175
	*/
sl@0
   176
	virtual void SinkPlayL() {};
sl@0
   177
sl@0
   178
	/**
sl@0
   179
	Function to 'pause' the data sink.
sl@0
   180
sl@0
   181
	This is a virtual function that a derrived data sink can implement if
sl@0
   182
	any data sink specific action is required to 'pause'.
sl@0
   183
	*/
sl@0
   184
	virtual void SinkPauseL() {};
sl@0
   185
sl@0
   186
	/**
sl@0
   187
	Function to 'stop' the data sink.
sl@0
   188
sl@0
   189
	This is a virtual function that a derrived data sink can implement if
sl@0
   190
	any data sink specific action is required to 'stop'
sl@0
   191
	*/
sl@0
   192
	virtual void SinkStopL() {};
sl@0
   193
sl@0
   194
	inline virtual void SetSinkPrioritySettings(const TMMFPrioritySettings& aPrioritySettings);
sl@0
   195
sl@0
   196
	/**
sl@0
   197
	Calls a sink specific custom command.
sl@0
   198
sl@0
   199
	This is a virtual function that a derrived data sink can implement if
sl@0
   200
	it implements any custom commands.
sl@0
   201
sl@0
   202
	@param  aMessage
sl@0
   203
	        The message specifying the custom command.
sl@0
   204
	*/
sl@0
   205
	virtual void SinkCustomCommand(TMMFMessage& aMessage) {aMessage.Complete(KErrNotSupported);};
sl@0
   206
	
sl@0
   207
protected:
sl@0
   208
	/**
sl@0
   209
	Performs any sink construction dependant on the sink construction
sl@0
   210
	initialisation data aInitData.
sl@0
   211
sl@0
   212
	This is a pure virtual function that a derrived data sink must implement
sl@0
   213
sl@0
   214
	@param  aInitData
sl@0
   215
	        The sink specific initialisation data required for sink construction.
sl@0
   216
	*/
sl@0
   217
	virtual void ConstructSinkL( const TDesC8& aInitData ) = 0;
sl@0
   218
sl@0
   219
	/**
sl@0
   220
	Protected constructor.
sl@0
   221
sl@0
   222
	@param  aType
sl@0
   223
	        The source type UID.
sl@0
   224
	*/
sl@0
   225
	MDataSink(TUid aType): iDataSinkType(aType),iDtor_ID_Key(TUid::Null()) {}
sl@0
   226
	
sl@0
   227
private:
sl@0
   228
	TUid iDataSinkType;
sl@0
   229
	TUid iDtor_ID_Key;
sl@0
   230
	};
sl@0
   231
sl@0
   232
/**
sl@0
   233
Instantiates a new data sink.
sl@0
   234
sl@0
   235
@param  aImplementationUid
sl@0
   236
        The UID identifying the data sink to be instantiated.
sl@0
   237
@param  aInitData
sl@0
   238
        The sink specific initialisation data required for sink construction.
sl@0
   239
sl@0
   240
@return	A pointer to the instantiated data sink.
sl@0
   241
*/
sl@0
   242
inline MDataSink* MDataSink::NewSinkL( TUid aImplementationUid,  const TDesC8& aInitData )
sl@0
   243
	{
sl@0
   244
	MDataSink* retPtr = REINTERPRET_CAST( MDataSink*, REComSession::CreateImplementationL( aImplementationUid,
sl@0
   245
																			_FOFF(MDataSink, iDtor_ID_Key) ) ) ;
sl@0
   246
	CleanupDeletePushL(retPtr);
sl@0
   247
	retPtr->ConstructSinkL( aInitData ) ;
sl@0
   248
sl@0
   249
	CleanupStack::Pop(retPtr);
sl@0
   250
	return retPtr ;
sl@0
   251
	}
sl@0
   252
sl@0
   253
/**
sl@0
   254
Sets the data type as a fourCC code for the data sink.
sl@0
   255
sl@0
   256
This is a virtual function that each derived class can implement if the data sink supports
sl@0
   257
the ability to have its data type set.
sl@0
   258
sl@0
   259
@param  aSinkFourCC
sl@0
   260
        This specifies the data type as a fourCC code to set the sink to.
sl@0
   261
@param  aMediaId
sl@0
   262
        This identifies the type of media eg. audio or video and the stream ID.
sl@0
   263
        This parameter is required in cases where the source can supply data
sl@0
   264
        of more than one media type and/or multiple streams of data.
sl@0
   265
sl@0
   266
@return	KErrNone if successful, KErrNotSupported if the sink does not support having
sl@0
   267
        it's data type set, otherwise a system wide error code.
sl@0
   268
*/
sl@0
   269
inline TInt MDataSink::SetSinkDataTypeCode(TFourCC /*aSinkFourCC*/, TMediaId /*aMediaId*/)
sl@0
   270
{
sl@0
   271
	return KErrNotSupported;
sl@0
   272
}
sl@0
   273
sl@0
   274
/**
sl@0
   275
Function to 'logon' the data sink to the same thread that sink will be consuming data in.
sl@0
   276
sl@0
   277
This method may be required as the thread that the data sink was created in is not always
sl@0
   278
the same thread that the data transfer will take place in.  Therefore any thread specific
sl@0
   279
initialisation needs to be performed in the SinkThreadLogon rather than in the creation
sl@0
   280
of the data sink.
sl@0
   281
sl@0
   282
This is a virtual function that a derrived data sink can implement if any thread specific
sl@0
   283
initialisation is required and/or the data sink can create any asynchronous events.
sl@0
   284
sl@0
   285
@param  aEventHandler
sl@0
   286
        This is an MAsyncEventHandler to handle asynchronous events that occur during the
sl@0
   287
        transfer of multimedia data. The event handler must be in the same thread as the data
sl@0
   288
        transfer thread - hence the reason it is passed in the SinkThreadLogon as opposed to
sl@0
   289
        say the constructor.
sl@0
   290
sl@0
   291
@return An error code indicating if the function call was successful. KErrNone on success, otherwise
sl@0
   292
        another of the system-wide error codes.
sl@0
   293
*/
sl@0
   294
inline TInt MDataSink::SinkThreadLogon(MAsyncEventHandler& /*aEventHandler*/)
sl@0
   295
{
sl@0
   296
	return KErrNone;
sl@0
   297
}
sl@0
   298
sl@0
   299
/**
sl@0
   300
@deprecated
sl@0
   301
sl@0
   302
Allows the data sink to negotiate with a data source.
sl@0
   303
sl@0
   304
This method is required in cases where the settings of data sink are dependant on those of a
sl@0
   305
data source. This is a virtual function that a derrived data sink can implement.
sl@0
   306
sl@0
   307
@param  aDataSource
sl@0
   308
        The data source whose settings can affect the data sink.
sl@0
   309
*/
sl@0
   310
inline void MDataSink::NegotiateL(MDataSource& /*aDataSource*/)
sl@0
   311
{
sl@0
   312
}
sl@0
   313
sl@0
   314
/**
sl@0
   315
Sets the sink priority settings.
sl@0
   316
sl@0
   317
This is a virtual function that a derrived data sink can implement if
sl@0
   318
a priority mechanism is required to arbitrate between multiple clients
sl@0
   319
trying to access the same resource.
sl@0
   320
sl@0
   321
@param  aPrioritySettings
sl@0
   322
        The sink priority settings.
sl@0
   323
sl@0
   324
*/
sl@0
   325
inline void MDataSink::SetSinkPrioritySettings(const TMMFPrioritySettings& /*aPrioritySettings*/)
sl@0
   326
{
sl@0
   327
}
sl@0
   328
sl@0
   329
/**
sl@0
   330
This function is used by TCleanupItem objects to perform
sl@0
   331
a SinkStopL() when leaving functions exist, ususally between SinkPrimeL-SinkStopL pairs.
sl@0
   332
sl@0
   333
@param  aSink
sl@0
   334
        The data sink to be stopped.
sl@0
   335
*/
sl@0
   336
inline static void DoDataSinkStop(TAny* aSink)
sl@0
   337
	{
sl@0
   338
	MDataSink* sink = STATIC_CAST(MDataSink*, aSink);
sl@0
   339
	// we don't want this function to leave because no leaving functions are supposed
sl@0
   340
	// to be used as argument to the TCleanupItem objects. Hence we catch the error but
sl@0
   341
	// we do nothing with it.
sl@0
   342
	TRAP_IGNORE(sink->SinkStopL());
sl@0
   343
	}
sl@0
   344
sl@0
   345
/**
sl@0
   346
This method is used by TCleanupItem objects to perform a SinkThreadLogoff().
sl@0
   347
sl@0
   348
@param  aSink
sl@0
   349
        The data sink to be logged off.
sl@0
   350
*/
sl@0
   351
inline static void DoDataSinkThreadLogoff(TAny* aSink)
sl@0
   352
	{
sl@0
   353
	MDataSink* sink = STATIC_CAST(MDataSink*, aSink);
sl@0
   354
	sink->SinkThreadLogoff();
sl@0
   355
	}
sl@0
   356
sl@0
   357
sl@0
   358
#endif