1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/mm/devsound/a3fdevsound/src/mmfdevsound/sounddevicebody.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,337 @@
1.4 +// Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// INCLUDE FILES
1.18 +//
1.19 +
1.20 +
1.21 +
1.22 +#include "sounddevicebody.h"
1.23 +#include <a3f/mmfdevsoundcustominterfaceextensions.h>
1.24 +#include <mmf/plugin/mmfdevsoundcustominterface.hrh>
1.25 +#include <mm/mmpluginutils.h>
1.26 +
1.27 +/*
1.28 + * Default Constructor.
1.29 + */
1.30 +CMMFDevSound::CBody::CBody()
1.31 + {
1.32 + }
1.33 +
1.34 +/*
1.35 + * Destructor.
1.36 + *
1.37 + * Deletes all objects and releases all resource owned by this
1.38 + * instance.
1.39 + */
1.40 +CMMFDevSound::CBody::~CBody()
1.41 + {
1.42 + // Clear the array of custom interfaces
1.43 + TInt numIfs = iCustomInterfaceArray.Count();
1.44 + for (TInt i = 0; i < numIfs; i++)
1.45 + {
1.46 + if(iCustomInterfaceArray[i].iInterface)
1.47 + {
1.48 + iCustomInterfaceArray[i].iInterface->Release();
1.49 + }
1.50 + }
1.51 + iCustomInterfaceArray.Reset();
1.52 + iCustomInterfaceArray.Close();
1.53 +
1.54 + // Delete the MUX utility
1.55 + delete iMuxUtility;
1.56 +
1.57 + if (iDevSoundProxy)
1.58 + {
1.59 + iDevSoundProxy->Close();
1.60 + delete iDevSoundProxy;
1.61 + }
1.62 +
1.63 + // Delete the CI extension
1.64 + if (iCIExtension)
1.65 + {
1.66 + iCIExtension->Release();
1.67 + }
1.68 + }
1.69 +
1.70 +/*
1.71 + * Constructs, and returns a pointer to, a new CMMFDevSound::CBody object.
1.72 + *
1.73 + * Leaves on failure.
1.74 + */
1.75 +CMMFDevSound::CBody* CMMFDevSound::CBody::NewL()
1.76 + {
1.77 + CBody* self = new (ELeave) CBody;
1.78 + CleanupStack::PushL(self);
1.79 + self->ConstructL();
1.80 + CleanupStack::Pop(self);
1.81 + return self;
1.82 + }
1.83 +
1.84 +/*
1.85 + * Second phase constructor.
1.86 + */
1.87 +void CMMFDevSound::CBody::ConstructL()
1.88 + {
1.89 + // all these data properties should be NULL, but add ASSERTs to verify.
1.90 + ASSERT(!iDevSoundProxy);
1.91 + iDevSoundProxy = new (ELeave) RMMFDevSoundProxy();
1.92 + TInt err = iDevSoundProxy->Open();
1.93 + User::LeaveIfError(err);
1.94 +
1.95 + User::LeaveIfError(iDevSoundProxy->PostOpen());
1.96 +
1.97 + // create Custom Interface MUX utility
1.98 + iMuxUtility = CMMFDevSoundCIMuxUtility::NewL(this);
1.99 +
1.100 + // Create Custom Interface extension
1.101 + RImplInfoPtrArray pluginArray;
1.102 + CleanupResetAndDestroyPushL(pluginArray);
1.103 + TUid interfaceUid = {KUidDevSoundCIClientExtension};
1.104 + REComSession::ListImplementationsL(interfaceUid, pluginArray);
1.105 + TUid destructorKey;
1.106 + if (pluginArray.Count() > 0)
1.107 + {
1.108 + // One or more exists - use the 1st one found
1.109 + iCIExtension = static_cast<MDevSoundCIClientExtension*>
1.110 + (REComSession::CreateImplementationL(pluginArray[0]->ImplementationUid(), destructorKey));
1.111 + }
1.112 + CleanupStack::PopAndDestroy(&pluginArray);
1.113 + if (iCIExtension)
1.114 + {
1.115 + // Extension exists. Complete the setup
1.116 + iCIExtension->PassDestructorKey(destructorKey);
1.117 + User::LeaveIfError(iCIExtension->Setup(*iDevSoundProxy));
1.118 + }
1.119 + }
1.120 +
1.121 +/*
1.122 + * CMMFDevSound::InitializeL
1.123 + *
1.124 + * Initializes CMMFDevSound object. On completion of Initialization will
1.125 + * call InitializeComplete() on aDevSoundObserver.
1.126 + *
1.127 + * Leaves on failure.
1.128 + *
1.129 + * @param MDevSoundObserver&
1.130 + * A reference to the DevSound Observer instance.
1.131 + *
1.132 + * @param TMMFState
1.133 + * A mode for which this object will be used.
1.134 + */
1.135 +void CMMFDevSound::CBody::InitializeL(MDevSoundObserver& aDevSoundObserver,
1.136 + TMMFState aMode)
1.137 +
1.138 + {
1.139 +
1.140 + ASSERT(iDevSoundProxy);
1.141 + iDevSoundProxy->InitializeL(aDevSoundObserver, aMode, *this);
1.142 + }
1.143 +
1.144 +/*
1.145 + * CMMFDevSound::InitializeL
1.146 + *
1.147 + * Initializes CMMFDevSound object with hardware device with hardware
1.148 + * device's FourCC code. On completion of Initialization will call
1.149 + * InitializeComplete() on aDevSoundObserver.
1.150 + *
1.151 + * Leaves on failure.
1.152 + *
1.153 + * @param MDevSoundObserver&
1.154 + * A reference to the DevSound Observer instance.
1.155 + *
1.156 + * @param TFourCC
1.157 + * CMMFHwDevice implementation FourCC.
1.158 + *
1.159 + * @param TMMFState
1.160 + * A mode for which this object will be used.
1.161 + *
1.162 + */
1.163 +void CMMFDevSound::CBody::InitializeL(MDevSoundObserver& aDevSoundObserver,
1.164 + TFourCC aDesiredFourCC,
1.165 + TMMFState aMode)
1.166 + {
1.167 + ASSERT(iDevSoundProxy);
1.168 + iDevSoundProxy->InitializeL(aDevSoundObserver, aDesiredFourCC, aMode, *this);
1.169 + }
1.170 +
1.171 +/**
1.172 + * CMMFDevSound::CBody::CustomInterface
1.173 + *
1.174 + * Returns custom interface proxy object created by Proxy Custom Interface
1.175 + * Utility.
1.176 + *
1.177 + * @param TUid
1.178 + * UID of the custom interface object to be started.
1.179 + *
1.180 + * @return TAny*
1.181 + * Pointer to the Interface Returned by the DevSoundProxy member.
1.182 + */
1.183 +TAny* CMMFDevSound::CBody::CustomInterface(TUid aInterfaceId)
1.184 + {
1.185 + // check if this UID refers to CancelInitialize()
1.186 + if (aInterfaceId == KMmfUidDevSoundCancelInitializeCustomInterface)
1.187 + {
1.188 + MMMFDevSoundCancelInitialize* result = this;
1.189 + return result;
1.190 + }
1.191 +
1.192 + // check if this UID refers to EmptyBuffers()
1.193 + if (aInterfaceId == KMmfUidDevSoundEmptyBuffersCustomInterface)
1.194 + {
1.195 + MMMFDevSoundEmptyBuffers* result = this;
1.196 + return result;
1.197 + }
1.198 +
1.199 + if (aInterfaceId == KMmfUidDevSoundAudioResourceCustomInterface)
1.200 + {
1.201 + MAutoPauseResumeSupport* result = this;
1.202 + return result;
1.203 + }
1.204 +
1.205 + if (aInterfaceId == KMmfUidDevSoundTimePlayedCustomInterface)
1.206 + {
1.207 + MMMFDevSoundTimePlayed* result = this;
1.208 + return result;
1.209 + }
1.210 +
1.211 + if (aInterfaceId == KMmfUidDevSoundQueryIgnoresUnderflowCustomInterface)
1.212 + {
1.213 + MMMFDevSoundQueryIgnoresUnderflow* result = this;
1.214 + return result;
1.215 + }
1.216 +
1.217 + if (aInterfaceId == KMmfUidDevSoundAudioClientThreadInfoCustomInterface)
1.218 + {
1.219 + MAudioClientThreadInfo* result = this;
1.220 + return result;
1.221 + }
1.222 +
1.223 + if (aInterfaceId == KMmfUidDevSoundTruePauseCustomInterface)
1.224 + {
1.225 + MMMFDevSoundTruePause* result = this;
1.226 + return result;
1.227 + }
1.228 +
1.229 + // first check if we already have resolved a custom interface of this type
1.230 + TInt index = FindCustomInterface(aInterfaceId);
1.231 +
1.232 + MMMFDevSoundCustomInterfaceMuxPlugin* ptr = NULL;
1.233 +
1.234 + // if we found the interface, take a copy of this instead
1.235 + if (index != KNullHandle)
1.236 + {
1.237 + // check our index is valid
1.238 + ptr = iCustomInterfaceArray[index-1].iInterface;
1.239 + if (ptr)
1.240 + {
1.241 + return ptr->CustomInterface(aInterfaceId);
1.242 + }
1.243 + }
1.244 + else
1.245 + {
1.246 + // else try and instantiate a plugin tunnelling
1.247 + // pair to support this Custom Interface
1.248 + TRAPD(err, ptr = iMuxUtility->CreateCustomInterfaceMuxL(aInterfaceId));
1.249 +
1.250 + if (ptr && (err == KErrNone))
1.251 + {
1.252 + TMMFDevSoundCustomInterfaceData data;
1.253 + data.iInterface = ptr;
1.254 + data.iId = aInterfaceId;
1.255 +
1.256 + // attempt to open remote demux
1.257 + // this will store a handle in the mux plugin if successful
1.258 + // and also return it here - invalid handle = -1
1.259 + data.iHandle = ptr->OpenInterface(aInterfaceId);
1.260 +
1.261 + // if the handle is greater than zero then we know we have
1.262 + // successfully opened the interface
1.263 + if (data.iHandle > KNullHandle)
1.264 + {
1.265 + // append this to the current interface list
1.266 + TInt err = KErrNone;
1.267 + err = iCustomInterfaceArray.Append(data);
1.268 + if (err == KErrNone)
1.269 + {
1.270 + // return the custom interface on the ptr
1.271 + return ptr->CustomInterface(aInterfaceId);
1.272 + }
1.273 + }
1.274 +
1.275 + // no memory or other problem so shut down interface
1.276 + ptr->Release();
1.277 + ptr = NULL;
1.278 + }
1.279 + }
1.280 +
1.281 + if (iCIExtension)
1.282 + {
1.283 + // CI Extension exists, see if it supports the interface
1.284 + TAny* interface;
1.285 + TInt err = iCIExtension->CustomInterfaceExtension(aInterfaceId, interface);
1.286 + if (err == KErrNone)
1.287 + {
1.288 + return interface;
1.289 + }
1.290 + }
1.291 + // No Mux/DeMux support & no support from CI Extension, if here
1.292 + // So, its not supported
1.293 + return NULL;
1.294 + }
1.295 +
1.296 +TInt CMMFDevSound::CBody::FindCustomInterface(TUid aInterfaceId)
1.297 + {
1.298 + TInt index = KNullHandle;
1.299 + TInt count = iCustomInterfaceArray.Count();
1.300 + for (TInt i = 0; i < count; i++)
1.301 + {
1.302 + if (iCustomInterfaceArray[i].iId == aInterfaceId)
1.303 + {
1.304 + index = i+1; // use index+1 as the handle, so 0 is undefined/not-found
1.305 + break;
1.306 + }
1.307 + }
1.308 +
1.309 + return index;
1.310 + }
1.311 +
1.312 +void CMMFDevSound::CBody::CloseCustomInterface(TInt aIndex)
1.313 + {
1.314 + TInt count = iCustomInterfaceArray.Count();
1.315 + for (TInt i = 0; i < count; i++)
1.316 + {
1.317 + if(iCustomInterfaceArray[i].iHandle == aIndex)
1.318 + {
1.319 + iCustomInterfaceArray[i].iInterface->Release();
1.320 + iCustomInterfaceArray.Remove(i);
1.321 + break;
1.322 + }
1.323 + }
1.324 + }
1.325 +
1.326 +TInt CMMFDevSound::CBody::GetTimePlayed(TTimeIntervalMicroSeconds& aTime)
1.327 + {
1.328 + return iDevSoundProxy->GetTimePlayed(aTime);
1.329 + }
1.330 +
1.331 +TBool CMMFDevSound::CBody::QueryIgnoresUnderflow()
1.332 + {
1.333 + return ETrue;
1.334 + }
1.335 +
1.336 +TInt CMMFDevSound::CBody::SetClientThreadInfo(TThreadId aTid)
1.337 + {
1.338 + return iDevSoundProxy->SetClientThreadInfo(aTid);
1.339 + }
1.340 +// End of File