os/mm/devsound/sounddevbt/src/A2dpBlueTooth/client/A2dpBTHeadsetAudioIfClient.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/mm/devsound/sounddevbt/src/A2dpBlueTooth/client/A2dpBTHeadsetAudioIfClient.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,308 @@
     1.4 +// Copyright (c) 2005-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 +//
    1.18 +
    1.19 +#include <bttypes.h>
    1.20 +#include <s32mem.h>	// RDesReadStream
    1.21 +
    1.22 +#include "A2dpBTHeadsetAudioIfClient.h"
    1.23 +#include "A2dpBTHeadsetAudioIfClientServer.h"
    1.24 +#include "A2dpBTHeadsetAudioIfServerStart.h"
    1.25 +#include "MMFBtRoutingSoundDevice.h"
    1.26 +
    1.27 +const TInt KBluetoothAddressBufferLength = 32;
    1.28 +
    1.29 +EXPORT_C RA2dpBTHeadsetAudioInterface::RA2dpBTHeadsetAudioInterface()
    1.30 +	{
    1.31 +	}
    1.32 +
    1.33 +EXPORT_C TInt RA2dpBTHeadsetAudioInterface::Connect()
    1.34 +	{
    1.35 +	TRAPD(err, iBufAddr = HBufC::NewL(KBluetoothAddressBufferLength));
    1.36 +	if (err)
    1.37 +		{
    1.38 +		delete iBufAddr;
    1.39 +		iBufAddr = NULL;
    1.40 +		return err;
    1.41 +		}
    1.42 +
    1.43 +	TRAP(err, iPckgBuf = new(ELeave)TPckgBuf<TBTDevAddr>);
    1.44 +	if (err)
    1.45 +		{
    1.46 +		delete iPckgBuf;
    1.47 +		iPckgBuf = NULL;
    1.48 +		return err;
    1.49 +		}
    1.50 +
    1.51 +	TVersion version(KBTAudioServerMajorVersionNumber,
    1.52 +					KBTAudioServerMinorVersionNumber,
    1.53 +					KBTAudioServerBuildVersionNumber);
    1.54 +	// Assume the server is already running and attempt to create a session	
    1.55 +	return CreateSession(KA2DPAudioServerName, version);
    1.56 +	}
    1.57 +
    1.58 +EXPORT_C void RA2dpBTHeadsetAudioInterface::Close()
    1.59 +	{
    1.60 +	// Call the base class
    1.61 +	RMmfSessionBase::Close();
    1.62 +	
    1.63 +	delete iPckgBuf;
    1.64 +	iPckgBuf = NULL;
    1.65 +	
    1.66 +	delete iBufAddr;
    1.67 +	iBufAddr = NULL;
    1.68 +	}
    1.69 +
    1.70 +EXPORT_C void RA2dpBTHeadsetAudioInterface::Initialize(const TBTDevAddr& aRemoteAddress,
    1.71 +														TRequestStatus& aStatus)
    1.72 +	{
    1.73 +	if (iPckgBuf)
    1.74 +		{
    1.75 +		(*iPckgBuf)() = aRemoteAddress;
    1.76 +		SendReceiveResult(EBTAudioServerInitialize, *iPckgBuf, aStatus);
    1.77 +		}
    1.78 +	else
    1.79 +		{
    1.80 +		// iPckgBuf not created => Connect() wasn't called or the returned error code was ignored.
    1.81 +		TRequestStatus* status = &aStatus;
    1.82 +		User::RequestComplete(status, KErrDisconnected);
    1.83 +		}
    1.84 +	}
    1.85 +
    1.86 +EXPORT_C void RA2dpBTHeadsetAudioInterface::CancelInitialize()
    1.87 +	{
    1.88 +	SendReceive(EBTAudioServerCancelInitialize);
    1.89 +	}
    1.90 +
    1.91 +EXPORT_C void RA2dpBTHeadsetAudioInterface::GetSupportedDataTypesL(RArray<TFourCC>& aSupportedDataTypes) const
    1.92 +	{
    1.93 +	aSupportedDataTypes.Reset();
    1.94 +	TPckgBuf<TInt> numberOfElementsPckg;
    1.95 +	TInt err = SendReceiveResult(EBTAudioServerGetSupportedDataTypes, numberOfElementsPckg);
    1.96 +	User::LeaveIfError(err);
    1.97 +
    1.98 +	HBufC8* buf = HBufC8::NewLC(numberOfElementsPckg() * sizeof(TFourCC));
    1.99 +	TPtr8 ptr = buf->Des();
   1.100 +	err = SendReceiveResult(EBTAudioServerCopyFourCCArrayData, ptr);
   1.101 +	User::LeaveIfError(err);
   1.102 +
   1.103 +	RDesReadStream stream(ptr);
   1.104 +	CleanupClosePushL(stream);
   1.105 +	
   1.106 +	for (TInt i = 0; i < numberOfElementsPckg(); i++)
   1.107 +		{
   1.108 +		err = aSupportedDataTypes.Append(stream.ReadInt32L());
   1.109 +		if (err)
   1.110 +			{//note we don't destroy array because we don't own it
   1.111 +			//but we do reset it as it is incomplete
   1.112 +			aSupportedDataTypes.Reset();
   1.113 +			User::Leave(err);
   1.114 +			}
   1.115 +		}
   1.116 +	CleanupStack::PopAndDestroy(2, buf);
   1.117 +	}
   1.118 +	
   1.119 +EXPORT_C void RA2dpBTHeadsetAudioInterface::GetSupportedSampleRatesL(RArray<TUint>& aSupportedDiscreteRates,
   1.120 +																	RArray<TRange>& aSupportedRateRanges) const
   1.121 +	{
   1.122 +	aSupportedDiscreteRates.Reset();
   1.123 +	TPckgBuf<TRatesArrayElements> numberOfElementsPckg;
   1.124 +	
   1.125 +	TInt err = SendReceiveResult(EBTAudioServerGetSupportedSampleRates, numberOfElementsPckg);
   1.126 +	User::LeaveIfError(err);
   1.127 +	
   1.128 +	HBufC8* buf = HBufC8::NewLC(numberOfElementsPckg().iDiscrete * sizeof(TUint));
   1.129 +	TPtr8 ptr = buf->Des();
   1.130 +	err = SendReceiveResult(EBTAudioServerGetSupportedSampleRatesDiscrete, ptr);
   1.131 +	User::LeaveIfError(err);
   1.132 +	
   1.133 +	RDesReadStream stream(ptr);
   1.134 +	CleanupClosePushL(stream);
   1.135 +
   1.136 +	// Populate the discrete rates array
   1.137 +	for (TInt i = 0; i < numberOfElementsPckg().iDiscrete; i++)
   1.138 +		{
   1.139 +		err = aSupportedDiscreteRates.Append(stream.ReadInt32L());
   1.140 +		if (err)
   1.141 +			{//note we don't destroy array because we don't own it
   1.142 +			//but we do reset it as it is incomplete
   1.143 +			aSupportedDiscreteRates.Reset();
   1.144 +			User::Leave(err);
   1.145 +			}
   1.146 +		}
   1.147 +		
   1.148 +	ptr.SetLength(0); //clear out exiting data	
   1.149 +	// Get the rates range array (# of elements and the elements themselves)
   1.150 +	buf = buf->ReAllocL(numberOfElementsPckg().iRange * sizeof(TRange));
   1.151 +	ptr = buf->Des();
   1.152 +	stream.Close();
   1.153 +	stream.Open(ptr);
   1.154 +	err = SendReceiveResult(EBTAudioServerGetSupportedSampleRatesRange, ptr);
   1.155 +	User::LeaveIfError(err);
   1.156 +	TRange range;
   1.157 +	for (TInt i = 0; i < numberOfElementsPckg().iRange; i++)
   1.158 +		{
   1.159 +		range.iLow = stream.ReadInt32L();
   1.160 +		range.iHigh = stream.ReadInt32L();					
   1.161 +		err = aSupportedRateRanges.Append(range);
   1.162 +		if (err)
   1.163 +			{
   1.164 +			aSupportedRateRanges.Reset();
   1.165 +			User::Leave(err);
   1.166 +			}
   1.167 +		}
   1.168 +		
   1.169 +	CleanupStack::PopAndDestroy(2, buf);//stream, buf		
   1.170 +	}
   1.171 +	
   1.172 +EXPORT_C void RA2dpBTHeadsetAudioInterface::GetSupportedChannelsL(RArray<TUint>& aSupportedChannels,
   1.173 +																TMMFStereoSupport& aStereoSupport) const
   1.174 +
   1.175 +	{
   1.176 +	aSupportedChannels.Reset();
   1.177 +	TChannelsSupport channelsSupport;
   1.178 +	channelsSupport.iElementCount = 0;
   1.179 +	channelsSupport.iSupport = EMMFNone;
   1.180 +	TPckgBuf<TChannelsSupport> channelsSupportPckg(channelsSupport);
   1.181 +	
   1.182 +	TInt err = SendReceiveResult(EBTAudioServerGetSupportedChannels, channelsSupportPckg);
   1.183 +	User::LeaveIfError(err);
   1.184 +
   1.185 +	aStereoSupport = channelsSupportPckg().iSupport;
   1.186 +	HBufC8* buf = HBufC8::NewLC(channelsSupportPckg().iElementCount * sizeof(TUint));
   1.187 +	TPtr8 ptr = buf->Des();
   1.188 +	err = SendReceiveResult(EBTAudioServerCopyChannelsArrayData, ptr);
   1.189 +	User::LeaveIfError(err);
   1.190 +	
   1.191 +	RDesReadStream stream(ptr);
   1.192 +	CleanupClosePushL(stream);
   1.193 +
   1.194 +	// Populate the stereo support array
   1.195 +	for (TInt i = 0; i < channelsSupportPckg().iElementCount; i++)
   1.196 +		{
   1.197 +		err = aSupportedChannels.Append(stream.ReadInt32L());
   1.198 +		if (err)
   1.199 +			{//note we don't destroy array because we don't own it
   1.200 +			//but we do reset it as it is incomplete
   1.201 +			aSupportedChannels.Reset();
   1.202 +			User::Leave(err);
   1.203 +			}
   1.204 +		}		
   1.205 +	CleanupStack::PopAndDestroy(2, buf); //stream, buf
   1.206 +	}
   1.207 +
   1.208 +EXPORT_C TInt RA2dpBTHeadsetAudioInterface::SetDataType(const TFourCC& aDataType)
   1.209 +	{
   1.210 +	TPckgBuf<TFourCC> dataTypePckg(aDataType);
   1.211 +	return SendReceiveResult(EBTAudioServerSetDataType, dataTypePckg);
   1.212 +	}
   1.213 +	
   1.214 +EXPORT_C TInt RA2dpBTHeadsetAudioInterface::SetSampleRate(TUint aSampleRate)
   1.215 +	{
   1.216 +	TPckgBuf<TUint> sampleRatePckg(aSampleRate);
   1.217 +	return SendReceiveResult(EBTAudioServerSetSampleRate, sampleRatePckg);
   1.218 +	}
   1.219 +
   1.220 +EXPORT_C TInt RA2dpBTHeadsetAudioInterface::SetChannels(TUint aChannels,
   1.221 +														TMMFStereoSupport aStereoSupport)
   1.222 +	{
   1.223 +	TChannelsSupport channelsSupport;
   1.224 +	channelsSupport.iElementCount = aChannels;
   1.225 +	channelsSupport.iSupport = aStereoSupport;
   1.226 +	TPckgBuf<TChannelsSupport> pckgBuf(channelsSupport);
   1.227 +	return SendReceiveResult(EBTAudioServerSetChannels, pckgBuf);
   1.228 +	}
   1.229 +	
   1.230 +EXPORT_C void RA2dpBTHeadsetAudioInterface::OpenDevice(TRequestStatus& aStatus)
   1.231 +	{
   1.232 +	aStatus = KRequestPending;
   1.233 +	SendReceive(EBTAudioServerOpenDevice, aStatus);
   1.234 +	}
   1.235 +
   1.236 +EXPORT_C void RA2dpBTHeadsetAudioInterface::CancelOpenDevice()
   1.237 +	{
   1.238 +	SendReceive(EBTAudioServerCancelOpenDevice);
   1.239 +	}
   1.240 +	
   1.241 +EXPORT_C void RA2dpBTHeadsetAudioInterface::CloseDevice(TRequestStatus& aStatus)
   1.242 +	{
   1.243 +	aStatus = KRequestPending;
   1.244 +	SendReceive(EBTAudioServerCloseDevice, aStatus);
   1.245 +	}
   1.246 +	
   1.247 +EXPORT_C TUint RA2dpBTHeadsetAudioInterface::Volume() const
   1.248 +	{
   1.249 +	TUint volume = 0;
   1.250 +	TPckgBuf<TUint> volumePckg(volume);
   1.251 +	SendReceiveResult(EBTAudioServerVolume, volumePckg);
   1.252 +	return volumePckg();
   1.253 +	}
   1.254 +
   1.255 +EXPORT_C TInt RA2dpBTHeadsetAudioInterface::SetVolume(TUint aVolume)
   1.256 +	{
   1.257 +	TPckgBuf<TUint> volumePckg(aVolume);
   1.258 +	return SendReceiveResult(EBTAudioServerSetVolume, volumePckg);
   1.259 +	}
   1.260 +
   1.261 +EXPORT_C void RA2dpBTHeadsetAudioInterface::PlayData(const TDesC8& aData, TRequestStatus& aStatus)
   1.262 +	{
   1.263 +	aStatus = KRequestPending;
   1.264 +	SendReceive(EBTAudioServerPlayData, aData, aStatus);
   1.265 +	}
   1.266 +
   1.267 +EXPORT_C void RA2dpBTHeadsetAudioInterface::CancelPlayData()
   1.268 +	{
   1.269 +	SendReceive(EBTAudioServerCancelPlayData);
   1.270 +	}
   1.271 +
   1.272 +EXPORT_C void RA2dpBTHeadsetAudioInterface::FlushBuffer()
   1.273 +	{
   1.274 +	SendReceive(EBTAudioServerFlushBuffer);
   1.275 +	}
   1.276 +
   1.277 +EXPORT_C TUint RA2dpBTHeadsetAudioInterface::BytesPlayed() const
   1.278 +	{
   1.279 +	TUint bytes = 0;
   1.280 +	TPckgBuf<TUint> bytesPlayedPckg(bytes);
   1.281 +	SendReceive(EBTAudioServerBytesPlayed, bytesPlayedPckg);
   1.282 +	return bytesPlayedPckg();
   1.283 +	}
   1.284 +
   1.285 +EXPORT_C void RA2dpBTHeadsetAudioInterface::ResetBytesPlayed()
   1.286 +	{
   1.287 +	SendReceive(EBTAudioServerResetBytesPlayed);
   1.288 +	}
   1.289 +
   1.290 +EXPORT_C void RA2dpBTHeadsetAudioInterface::PauseBuffer()
   1.291 +	{
   1.292 +	SendReceive(EBTAudioServerPauseBuffer);
   1.293 +	}
   1.294 +
   1.295 +EXPORT_C void RA2dpBTHeadsetAudioInterface::ResumePlaying()
   1.296 +	{
   1.297 +	SendReceive(EBTAudioServerResumePlaying);
   1.298 +	}
   1.299 +
   1.300 +EXPORT_C void RA2dpBTHeadsetAudioInterface::NotifyError(TRequestStatus& aStatus)
   1.301 +	{
   1.302 +	aStatus = KRequestPending;
   1.303 +	SendReceive(EBTAudioServerNotifyError, aStatus);
   1.304 +	}
   1.305 +
   1.306 +EXPORT_C void RA2dpBTHeadsetAudioInterface::CancelNotifyError()
   1.307 +	{
   1.308 +	SendReceive(EBTAudioServerCancelNotifyError);
   1.309 +	}
   1.310 +
   1.311 +