Update contrib.
1 // Copyright (c) 2006-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.
19 #include "sounddevicebody.h"
20 #include <a3f/mmfdevsoundcustominterfaceextensions.h>
21 #include <mmf/plugin/mmfdevsoundcustominterface.hrh>
22 #include <mm/mmpluginutils.h>
25 * Default Constructor.
27 CMMFDevSound::CBody::CBody()
34 * Deletes all objects and releases all resource owned by this
37 CMMFDevSound::CBody::~CBody()
39 // Clear the array of custom interfaces
40 TInt numIfs = iCustomInterfaceArray.Count();
41 for (TInt i = 0; i < numIfs; i++)
43 if(iCustomInterfaceArray[i].iInterface)
45 iCustomInterfaceArray[i].iInterface->Release();
48 iCustomInterfaceArray.Reset();
49 iCustomInterfaceArray.Close();
51 // Delete the MUX utility
56 iDevSoundProxy->Close();
57 delete iDevSoundProxy;
60 // Delete the CI extension
63 iCIExtension->Release();
68 * Constructs, and returns a pointer to, a new CMMFDevSound::CBody object.
72 CMMFDevSound::CBody* CMMFDevSound::CBody::NewL()
74 CBody* self = new (ELeave) CBody;
75 CleanupStack::PushL(self);
77 CleanupStack::Pop(self);
82 * Second phase constructor.
84 void CMMFDevSound::CBody::ConstructL()
86 // all these data properties should be NULL, but add ASSERTs to verify.
87 ASSERT(!iDevSoundProxy);
88 iDevSoundProxy = new (ELeave) RMMFDevSoundProxy();
89 TInt err = iDevSoundProxy->Open();
90 User::LeaveIfError(err);
92 User::LeaveIfError(iDevSoundProxy->PostOpen());
94 // create Custom Interface MUX utility
95 iMuxUtility = CMMFDevSoundCIMuxUtility::NewL(this);
97 // Create Custom Interface extension
98 RImplInfoPtrArray pluginArray;
99 CleanupResetAndDestroyPushL(pluginArray);
100 TUid interfaceUid = {KUidDevSoundCIClientExtension};
101 REComSession::ListImplementationsL(interfaceUid, pluginArray);
103 if (pluginArray.Count() > 0)
105 // One or more exists - use the 1st one found
106 iCIExtension = static_cast<MDevSoundCIClientExtension*>
107 (REComSession::CreateImplementationL(pluginArray[0]->ImplementationUid(), destructorKey));
109 CleanupStack::PopAndDestroy(&pluginArray);
112 // Extension exists. Complete the setup
113 iCIExtension->PassDestructorKey(destructorKey);
114 User::LeaveIfError(iCIExtension->Setup(*iDevSoundProxy));
119 * CMMFDevSound::InitializeL
121 * Initializes CMMFDevSound object. On completion of Initialization will
122 * call InitializeComplete() on aDevSoundObserver.
126 * @param MDevSoundObserver&
127 * A reference to the DevSound Observer instance.
130 * A mode for which this object will be used.
132 void CMMFDevSound::CBody::InitializeL(MDevSoundObserver& aDevSoundObserver,
137 ASSERT(iDevSoundProxy);
138 iDevSoundProxy->InitializeL(aDevSoundObserver, aMode, *this);
142 * CMMFDevSound::InitializeL
144 * Initializes CMMFDevSound object with hardware device with hardware
145 * device's FourCC code. On completion of Initialization will call
146 * InitializeComplete() on aDevSoundObserver.
150 * @param MDevSoundObserver&
151 * A reference to the DevSound Observer instance.
154 * CMMFHwDevice implementation FourCC.
157 * A mode for which this object will be used.
160 void CMMFDevSound::CBody::InitializeL(MDevSoundObserver& aDevSoundObserver,
161 TFourCC aDesiredFourCC,
164 ASSERT(iDevSoundProxy);
165 iDevSoundProxy->InitializeL(aDevSoundObserver, aDesiredFourCC, aMode, *this);
169 * CMMFDevSound::CBody::CustomInterface
171 * Returns custom interface proxy object created by Proxy Custom Interface
175 * UID of the custom interface object to be started.
178 * Pointer to the Interface Returned by the DevSoundProxy member.
180 TAny* CMMFDevSound::CBody::CustomInterface(TUid aInterfaceId)
182 // check if this UID refers to CancelInitialize()
183 if (aInterfaceId == KMmfUidDevSoundCancelInitializeCustomInterface)
185 MMMFDevSoundCancelInitialize* result = this;
189 // check if this UID refers to EmptyBuffers()
190 if (aInterfaceId == KMmfUidDevSoundEmptyBuffersCustomInterface)
192 MMMFDevSoundEmptyBuffers* result = this;
196 if (aInterfaceId == KMmfUidDevSoundAudioResourceCustomInterface)
198 MAutoPauseResumeSupport* result = this;
202 if (aInterfaceId == KMmfUidDevSoundTimePlayedCustomInterface)
204 MMMFDevSoundTimePlayed* result = this;
208 if (aInterfaceId == KMmfUidDevSoundQueryIgnoresUnderflowCustomInterface)
210 MMMFDevSoundQueryIgnoresUnderflow* result = this;
214 if (aInterfaceId == KMmfUidDevSoundAudioClientThreadInfoCustomInterface)
216 MAudioClientThreadInfo* result = this;
220 if (aInterfaceId == KMmfUidDevSoundTruePauseCustomInterface)
222 MMMFDevSoundTruePause* result = this;
226 // first check if we already have resolved a custom interface of this type
227 TInt index = FindCustomInterface(aInterfaceId);
229 MMMFDevSoundCustomInterfaceMuxPlugin* ptr = NULL;
231 // if we found the interface, take a copy of this instead
232 if (index != KNullHandle)
234 // check our index is valid
235 ptr = iCustomInterfaceArray[index-1].iInterface;
238 return ptr->CustomInterface(aInterfaceId);
243 // else try and instantiate a plugin tunnelling
244 // pair to support this Custom Interface
245 TRAPD(err, ptr = iMuxUtility->CreateCustomInterfaceMuxL(aInterfaceId));
247 if (ptr && (err == KErrNone))
249 TMMFDevSoundCustomInterfaceData data;
250 data.iInterface = ptr;
251 data.iId = aInterfaceId;
253 // attempt to open remote demux
254 // this will store a handle in the mux plugin if successful
255 // and also return it here - invalid handle = -1
256 data.iHandle = ptr->OpenInterface(aInterfaceId);
258 // if the handle is greater than zero then we know we have
259 // successfully opened the interface
260 if (data.iHandle > KNullHandle)
262 // append this to the current interface list
264 err = iCustomInterfaceArray.Append(data);
267 // return the custom interface on the ptr
268 return ptr->CustomInterface(aInterfaceId);
272 // no memory or other problem so shut down interface
280 // CI Extension exists, see if it supports the interface
282 TInt err = iCIExtension->CustomInterfaceExtension(aInterfaceId, interface);
288 // No Mux/DeMux support & no support from CI Extension, if here
289 // So, its not supported
293 TInt CMMFDevSound::CBody::FindCustomInterface(TUid aInterfaceId)
295 TInt index = KNullHandle;
296 TInt count = iCustomInterfaceArray.Count();
297 for (TInt i = 0; i < count; i++)
299 if (iCustomInterfaceArray[i].iId == aInterfaceId)
301 index = i+1; // use index+1 as the handle, so 0 is undefined/not-found
309 void CMMFDevSound::CBody::CloseCustomInterface(TInt aIndex)
311 TInt count = iCustomInterfaceArray.Count();
312 for (TInt i = 0; i < count; i++)
314 if(iCustomInterfaceArray[i].iHandle == aIndex)
316 iCustomInterfaceArray[i].iInterface->Release();
317 iCustomInterfaceArray.Remove(i);
323 TInt CMMFDevSound::CBody::GetTimePlayed(TTimeIntervalMicroSeconds& aTime)
325 return iDevSoundProxy->GetTimePlayed(aTime);
328 TBool CMMFDevSound::CBody::QueryIgnoresUnderflow()
333 TInt CMMFDevSound::CBody::SetClientThreadInfo(TThreadId aTid)
335 return iDevSoundProxy->SetClientThreadInfo(aTid);