1 // Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // include\mmf\server\mmfdatasink.h
18 #ifndef __MMF_SERVER_DATASINK_H__
19 #define __MMF_SERVER_DATASINK_H__
22 #include <mmf/server/mmfdatasourcesink.hrh>
23 #include <mmf/common/mmfutilities.h>
24 #include <ecom/ecom.h>
25 #include <mmf/common/mmfbase.h>
26 #include <mmf/common/mmfcontrollerframework.h>
36 class MAsyncEventHandler;
42 Abstract class representing a data sink.
48 static inline MDataSink* NewSinkL( TUid aImplementationUid, const TDesC8& aInitData ) ;
53 virtual ~MDataSink() {REComSession::DestroyedImplementation(iDtor_ID_Key);};
56 Returns the UID identifying the type of data sink.
58 @return The UID identifying the type of data sink
60 virtual TUid DataSinkType() const {return iDataSinkType;};
63 Returns the data type as a fourCC code of the data sink.
65 This is a pure virtual function that each derrived class must implement.
68 This identifies the type of media eg. audio or video and the stream ID.
69 This parameter is required in cases where the sink can accept data
70 of more than one media type and/or multiple streams of data.
72 @return The fourCC code identifying the sink datatype for the specified aMediaId.
74 virtual TFourCC SinkDataTypeCode(TMediaId aMediaId) = 0;
76 inline virtual TInt SetSinkDataTypeCode(TFourCC aSinkFourCC, TMediaId aMediaId);
79 Method called by a MDataSource to request the data sink to empty aBuffer of data.
81 This is a pure virtual function that each derived class must implement.
82 This method is used when a data sink is passively waiting for requests from a supplier ie.
83 a data source to empty a buffer. The data sink must call the BufferEmptiedL member on aSupplier
84 when it has emptied the buffer of it's data. The data sink can either make this callback
85 synchronously or asynchronously.
88 The full buffer that needs emptying of it's data.
90 The data source that supplied the data. The data sink needs this to make the
91 BufferEmptiedL callback on aSupplier to indicate to the data source that the data sink
92 has finished with the buffer.
94 This identifies the type of media eg. audio or video and the stream ID.
95 This parameter is required in cases where the source can supply data
96 of more than one media type and/or multiple streams of data.
98 virtual void EmptyBufferL(CMMFBuffer* aBuffer, MDataSource* aSupplier, TMediaId aMediaId)=0;
101 Function called by a data source to pass back a filled buffer to the sink.
103 This is a pure virtual function that each derived class must implement.
104 This method is used as the callback when the data sink actively requests a supplier ie. a
105 data source to fill a buffer by calling the data sources FillBufferL. When the data sink gets
106 this callback it knows that the buffer has been filled and is ready to be emptied.
109 The buffer that has been filled by a data source and is now available for processing.
111 virtual void BufferFilledL(CMMFBuffer* aBuffer)=0;
116 Function to indicate whether the data sink can create a buffer.
118 This is a pure virtual function that each derived class must implement.
120 @return A boolean indicating if the data sink can create a buffer. ETrue if it can otherwise
123 virtual TBool CanCreateSinkBuffer()=0;
126 Returns a buffer created by the data sink.
128 This is a pure virtual function that each derived class must implement.
131 This identifies the type of media eg. audio or video and the stream ID.
132 This parameter is required in cases where the source can supply data
133 of more than one media type and/or multiple streams of data.
136 This must be written to by the method to indicate whether the created buffer is
137 a 'reference' buffer. A 'reference' buffer is a buffer that is owned by the sink
138 and should be used in preference to the source buffer provided the source buffer
139 is also not a reference buffer.
141 @return The created buffer.
143 virtual CMMFBuffer* CreateSinkBufferL(TMediaId aMediaId, TBool &aReference)=0;
145 inline virtual TInt SinkThreadLogon(MAsyncEventHandler& aEventHandler);
148 Function to 'logoff' the data sink from the same thread that sink consumes data in.
150 This method may be required as the thread that the data sink is deleted in may not be
151 the same thread that the data transfer took place in. Therefore any thread specific
152 releasing of resources needs to be performed in the SinkThreadLogoff rather than in the
155 This is a virtual function that a derrived data sink can implement if any thread specific
156 releasing of resources is required.
158 virtual void SinkThreadLogoff() {};
160 inline virtual void NegotiateL(MDataSource& aDataSource);
163 Function to 'prime' the data sink.
165 This is a virtual function that a derrived data sink can implement if
166 any data sink specific 'priming' is required.
168 virtual void SinkPrimeL() {};
171 Function 'play' the data sink.
173 This is a virtual function that a derrived data sink can implement if
174 any data sink specific action is required prior to 'playing' ie. the start of data transfer.
176 virtual void SinkPlayL() {};
179 Function to 'pause' the data sink.
181 This is a virtual function that a derrived data sink can implement if
182 any data sink specific action is required to 'pause'.
184 virtual void SinkPauseL() {};
187 Function to 'stop' the data sink.
189 This is a virtual function that a derrived data sink can implement if
190 any data sink specific action is required to 'stop'
192 virtual void SinkStopL() {};
194 inline virtual void SetSinkPrioritySettings(const TMMFPrioritySettings& aPrioritySettings);
197 Calls a sink specific custom command.
199 This is a virtual function that a derrived data sink can implement if
200 it implements any custom commands.
203 The message specifying the custom command.
205 virtual void SinkCustomCommand(TMMFMessage& aMessage) {aMessage.Complete(KErrNotSupported);};
209 Performs any sink construction dependant on the sink construction
210 initialisation data aInitData.
212 This is a pure virtual function that a derrived data sink must implement
215 The sink specific initialisation data required for sink construction.
217 virtual void ConstructSinkL( const TDesC8& aInitData ) = 0;
220 Protected constructor.
225 MDataSink(TUid aType): iDataSinkType(aType) {}
233 Instantiates a new data sink.
235 @param aImplementationUid
236 The UID identifying the data sink to be instantiated.
238 The sink specific initialisation data required for sink construction.
240 @return A pointer to the instantiated data sink.
242 inline MDataSink* MDataSink::NewSinkL( TUid aImplementationUid, const TDesC8& aInitData )
244 MDataSink* retPtr = REINTERPRET_CAST( MDataSink*, REComSession::CreateImplementationL( aImplementationUid,
245 _FOFF(MDataSink, iDtor_ID_Key) ) ) ;
246 CleanupDeletePushL(retPtr);
247 retPtr->ConstructSinkL( aInitData ) ;
249 CleanupStack::Pop(retPtr);
254 Sets the data type as a fourCC code for the data sink.
256 This is a virtual function that each derived class can implement if the data sink supports
257 the ability to have its data type set.
260 This specifies the data type as a fourCC code to set the sink to.
262 This identifies the type of media eg. audio or video and the stream ID.
263 This parameter is required in cases where the source can supply data
264 of more than one media type and/or multiple streams of data.
266 @return KErrNone if successful, KErrNotSupported if the sink does not support having
267 it's data type set, otherwise a system wide error code.
269 inline TInt MDataSink::SetSinkDataTypeCode(TFourCC /*aSinkFourCC*/, TMediaId /*aMediaId*/)
271 return KErrNotSupported;
275 Function to 'logon' the data sink to the same thread that sink will be consuming data in.
277 This method may be required as the thread that the data sink was created in is not always
278 the same thread that the data transfer will take place in. Therefore any thread specific
279 initialisation needs to be performed in the SinkThreadLogon rather than in the creation
282 This is a virtual function that a derrived data sink can implement if any thread specific
283 initialisation is required and/or the data sink can create any asynchronous events.
286 This is an MAsyncEventHandler to handle asynchronous events that occur during the
287 transfer of multimedia data. The event handler must be in the same thread as the data
288 transfer thread - hence the reason it is passed in the SinkThreadLogon as opposed to
291 @return An error code indicating if the function call was successful. KErrNone on success, otherwise
292 another of the system-wide error codes.
294 inline TInt MDataSink::SinkThreadLogon(MAsyncEventHandler& /*aEventHandler*/)
302 Allows the data sink to negotiate with a data source.
304 This method is required in cases where the settings of data sink are dependant on those of a
305 data source. This is a virtual function that a derrived data sink can implement.
308 The data source whose settings can affect the data sink.
310 inline void MDataSink::NegotiateL(MDataSource& /*aDataSource*/)
315 Sets the sink priority settings.
317 This is a virtual function that a derrived data sink can implement if
318 a priority mechanism is required to arbitrate between multiple clients
319 trying to access the same resource.
321 @param aPrioritySettings
322 The sink priority settings.
325 inline void MDataSink::SetSinkPrioritySettings(const TMMFPrioritySettings& /*aPrioritySettings*/)
330 This function is used by TCleanupItem objects to perform
331 a SinkStopL() when leaving functions exist, ususally between SinkPrimeL-SinkStopL pairs.
334 The data sink to be stopped.
336 inline static void DoDataSinkStop(TAny* aSink)
338 MDataSink* sink = STATIC_CAST(MDataSink*, aSink);
339 // we don't want this function to leave because no leaving functions are supposed
340 // to be used as argument to the TCleanupItem objects. Hence we catch the error but
341 // we do nothing with it.
342 TRAP_IGNORE(sink->SinkStopL());
346 This method is used by TCleanupItem objects to perform a SinkThreadLogoff().
349 The data sink to be logged off.
351 inline static void DoDataSinkThreadLogoff(TAny* aSink)
353 MDataSink* sink = STATIC_CAST(MDataSink*, aSink);
354 sink->SinkThreadLogoff();