os/mm/devsound/sounddevbt/src/A2dpBlueTooth/client/A2dpBTHeadsetAudioIfClient.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2005-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
//
sl@0
    15
sl@0
    16
#include <bttypes.h>
sl@0
    17
#include <s32mem.h>	// RDesReadStream
sl@0
    18
sl@0
    19
#include "A2dpBTHeadsetAudioIfClient.h"
sl@0
    20
#include "A2dpBTHeadsetAudioIfClientServer.h"
sl@0
    21
#include "A2dpBTHeadsetAudioIfServerStart.h"
sl@0
    22
#include "MMFBtRoutingSoundDevice.h"
sl@0
    23
sl@0
    24
const TInt KBluetoothAddressBufferLength = 32;
sl@0
    25
sl@0
    26
EXPORT_C RA2dpBTHeadsetAudioInterface::RA2dpBTHeadsetAudioInterface()
sl@0
    27
	{
sl@0
    28
	}
sl@0
    29
sl@0
    30
EXPORT_C TInt RA2dpBTHeadsetAudioInterface::Connect()
sl@0
    31
	{
sl@0
    32
	TRAPD(err, iBufAddr = HBufC::NewL(KBluetoothAddressBufferLength));
sl@0
    33
	if (err)
sl@0
    34
		{
sl@0
    35
		delete iBufAddr;
sl@0
    36
		iBufAddr = NULL;
sl@0
    37
		return err;
sl@0
    38
		}
sl@0
    39
sl@0
    40
	TRAP(err, iPckgBuf = new(ELeave)TPckgBuf<TBTDevAddr>);
sl@0
    41
	if (err)
sl@0
    42
		{
sl@0
    43
		delete iPckgBuf;
sl@0
    44
		iPckgBuf = NULL;
sl@0
    45
		return err;
sl@0
    46
		}
sl@0
    47
sl@0
    48
	TVersion version(KBTAudioServerMajorVersionNumber,
sl@0
    49
					KBTAudioServerMinorVersionNumber,
sl@0
    50
					KBTAudioServerBuildVersionNumber);
sl@0
    51
	// Assume the server is already running and attempt to create a session	
sl@0
    52
	return CreateSession(KA2DPAudioServerName, version);
sl@0
    53
	}
sl@0
    54
sl@0
    55
EXPORT_C void RA2dpBTHeadsetAudioInterface::Close()
sl@0
    56
	{
sl@0
    57
	// Call the base class
sl@0
    58
	RMmfSessionBase::Close();
sl@0
    59
	
sl@0
    60
	delete iPckgBuf;
sl@0
    61
	iPckgBuf = NULL;
sl@0
    62
	
sl@0
    63
	delete iBufAddr;
sl@0
    64
	iBufAddr = NULL;
sl@0
    65
	}
sl@0
    66
sl@0
    67
EXPORT_C void RA2dpBTHeadsetAudioInterface::Initialize(const TBTDevAddr& aRemoteAddress,
sl@0
    68
														TRequestStatus& aStatus)
sl@0
    69
	{
sl@0
    70
	if (iPckgBuf)
sl@0
    71
		{
sl@0
    72
		(*iPckgBuf)() = aRemoteAddress;
sl@0
    73
		SendReceiveResult(EBTAudioServerInitialize, *iPckgBuf, aStatus);
sl@0
    74
		}
sl@0
    75
	else
sl@0
    76
		{
sl@0
    77
		// iPckgBuf not created => Connect() wasn't called or the returned error code was ignored.
sl@0
    78
		TRequestStatus* status = &aStatus;
sl@0
    79
		User::RequestComplete(status, KErrDisconnected);
sl@0
    80
		}
sl@0
    81
	}
sl@0
    82
sl@0
    83
EXPORT_C void RA2dpBTHeadsetAudioInterface::CancelInitialize()
sl@0
    84
	{
sl@0
    85
	SendReceive(EBTAudioServerCancelInitialize);
sl@0
    86
	}
sl@0
    87
sl@0
    88
EXPORT_C void RA2dpBTHeadsetAudioInterface::GetSupportedDataTypesL(RArray<TFourCC>& aSupportedDataTypes) const
sl@0
    89
	{
sl@0
    90
	aSupportedDataTypes.Reset();
sl@0
    91
	TPckgBuf<TInt> numberOfElementsPckg;
sl@0
    92
	TInt err = SendReceiveResult(EBTAudioServerGetSupportedDataTypes, numberOfElementsPckg);
sl@0
    93
	User::LeaveIfError(err);
sl@0
    94
sl@0
    95
	HBufC8* buf = HBufC8::NewLC(numberOfElementsPckg() * sizeof(TFourCC));
sl@0
    96
	TPtr8 ptr = buf->Des();
sl@0
    97
	err = SendReceiveResult(EBTAudioServerCopyFourCCArrayData, ptr);
sl@0
    98
	User::LeaveIfError(err);
sl@0
    99
sl@0
   100
	RDesReadStream stream(ptr);
sl@0
   101
	CleanupClosePushL(stream);
sl@0
   102
	
sl@0
   103
	for (TInt i = 0; i < numberOfElementsPckg(); i++)
sl@0
   104
		{
sl@0
   105
		err = aSupportedDataTypes.Append(stream.ReadInt32L());
sl@0
   106
		if (err)
sl@0
   107
			{//note we don't destroy array because we don't own it
sl@0
   108
			//but we do reset it as it is incomplete
sl@0
   109
			aSupportedDataTypes.Reset();
sl@0
   110
			User::Leave(err);
sl@0
   111
			}
sl@0
   112
		}
sl@0
   113
	CleanupStack::PopAndDestroy(2, buf);
sl@0
   114
	}
sl@0
   115
	
sl@0
   116
EXPORT_C void RA2dpBTHeadsetAudioInterface::GetSupportedSampleRatesL(RArray<TUint>& aSupportedDiscreteRates,
sl@0
   117
																	RArray<TRange>& aSupportedRateRanges) const
sl@0
   118
	{
sl@0
   119
	aSupportedDiscreteRates.Reset();
sl@0
   120
	TPckgBuf<TRatesArrayElements> numberOfElementsPckg;
sl@0
   121
	
sl@0
   122
	TInt err = SendReceiveResult(EBTAudioServerGetSupportedSampleRates, numberOfElementsPckg);
sl@0
   123
	User::LeaveIfError(err);
sl@0
   124
	
sl@0
   125
	HBufC8* buf = HBufC8::NewLC(numberOfElementsPckg().iDiscrete * sizeof(TUint));
sl@0
   126
	TPtr8 ptr = buf->Des();
sl@0
   127
	err = SendReceiveResult(EBTAudioServerGetSupportedSampleRatesDiscrete, ptr);
sl@0
   128
	User::LeaveIfError(err);
sl@0
   129
	
sl@0
   130
	RDesReadStream stream(ptr);
sl@0
   131
	CleanupClosePushL(stream);
sl@0
   132
sl@0
   133
	// Populate the discrete rates array
sl@0
   134
	for (TInt i = 0; i < numberOfElementsPckg().iDiscrete; i++)
sl@0
   135
		{
sl@0
   136
		err = aSupportedDiscreteRates.Append(stream.ReadInt32L());
sl@0
   137
		if (err)
sl@0
   138
			{//note we don't destroy array because we don't own it
sl@0
   139
			//but we do reset it as it is incomplete
sl@0
   140
			aSupportedDiscreteRates.Reset();
sl@0
   141
			User::Leave(err);
sl@0
   142
			}
sl@0
   143
		}
sl@0
   144
		
sl@0
   145
	ptr.SetLength(0); //clear out exiting data	
sl@0
   146
	// Get the rates range array (# of elements and the elements themselves)
sl@0
   147
	buf = buf->ReAllocL(numberOfElementsPckg().iRange * sizeof(TRange));
sl@0
   148
	ptr = buf->Des();
sl@0
   149
	stream.Close();
sl@0
   150
	stream.Open(ptr);
sl@0
   151
	err = SendReceiveResult(EBTAudioServerGetSupportedSampleRatesRange, ptr);
sl@0
   152
	User::LeaveIfError(err);
sl@0
   153
	TRange range;
sl@0
   154
	for (TInt i = 0; i < numberOfElementsPckg().iRange; i++)
sl@0
   155
		{
sl@0
   156
		range.iLow = stream.ReadInt32L();
sl@0
   157
		range.iHigh = stream.ReadInt32L();					
sl@0
   158
		err = aSupportedRateRanges.Append(range);
sl@0
   159
		if (err)
sl@0
   160
			{
sl@0
   161
			aSupportedRateRanges.Reset();
sl@0
   162
			User::Leave(err);
sl@0
   163
			}
sl@0
   164
		}
sl@0
   165
		
sl@0
   166
	CleanupStack::PopAndDestroy(2, buf);//stream, buf		
sl@0
   167
	}
sl@0
   168
	
sl@0
   169
EXPORT_C void RA2dpBTHeadsetAudioInterface::GetSupportedChannelsL(RArray<TUint>& aSupportedChannels,
sl@0
   170
																TMMFStereoSupport& aStereoSupport) const
sl@0
   171
sl@0
   172
	{
sl@0
   173
	aSupportedChannels.Reset();
sl@0
   174
	TChannelsSupport channelsSupport;
sl@0
   175
	channelsSupport.iElementCount = 0;
sl@0
   176
	channelsSupport.iSupport = EMMFNone;
sl@0
   177
	TPckgBuf<TChannelsSupport> channelsSupportPckg(channelsSupport);
sl@0
   178
	
sl@0
   179
	TInt err = SendReceiveResult(EBTAudioServerGetSupportedChannels, channelsSupportPckg);
sl@0
   180
	User::LeaveIfError(err);
sl@0
   181
sl@0
   182
	aStereoSupport = channelsSupportPckg().iSupport;
sl@0
   183
	HBufC8* buf = HBufC8::NewLC(channelsSupportPckg().iElementCount * sizeof(TUint));
sl@0
   184
	TPtr8 ptr = buf->Des();
sl@0
   185
	err = SendReceiveResult(EBTAudioServerCopyChannelsArrayData, ptr);
sl@0
   186
	User::LeaveIfError(err);
sl@0
   187
	
sl@0
   188
	RDesReadStream stream(ptr);
sl@0
   189
	CleanupClosePushL(stream);
sl@0
   190
sl@0
   191
	// Populate the stereo support array
sl@0
   192
	for (TInt i = 0; i < channelsSupportPckg().iElementCount; i++)
sl@0
   193
		{
sl@0
   194
		err = aSupportedChannels.Append(stream.ReadInt32L());
sl@0
   195
		if (err)
sl@0
   196
			{//note we don't destroy array because we don't own it
sl@0
   197
			//but we do reset it as it is incomplete
sl@0
   198
			aSupportedChannels.Reset();
sl@0
   199
			User::Leave(err);
sl@0
   200
			}
sl@0
   201
		}		
sl@0
   202
	CleanupStack::PopAndDestroy(2, buf); //stream, buf
sl@0
   203
	}
sl@0
   204
sl@0
   205
EXPORT_C TInt RA2dpBTHeadsetAudioInterface::SetDataType(const TFourCC& aDataType)
sl@0
   206
	{
sl@0
   207
	TPckgBuf<TFourCC> dataTypePckg(aDataType);
sl@0
   208
	return SendReceiveResult(EBTAudioServerSetDataType, dataTypePckg);
sl@0
   209
	}
sl@0
   210
	
sl@0
   211
EXPORT_C TInt RA2dpBTHeadsetAudioInterface::SetSampleRate(TUint aSampleRate)
sl@0
   212
	{
sl@0
   213
	TPckgBuf<TUint> sampleRatePckg(aSampleRate);
sl@0
   214
	return SendReceiveResult(EBTAudioServerSetSampleRate, sampleRatePckg);
sl@0
   215
	}
sl@0
   216
sl@0
   217
EXPORT_C TInt RA2dpBTHeadsetAudioInterface::SetChannels(TUint aChannels,
sl@0
   218
														TMMFStereoSupport aStereoSupport)
sl@0
   219
	{
sl@0
   220
	TChannelsSupport channelsSupport;
sl@0
   221
	channelsSupport.iElementCount = aChannels;
sl@0
   222
	channelsSupport.iSupport = aStereoSupport;
sl@0
   223
	TPckgBuf<TChannelsSupport> pckgBuf(channelsSupport);
sl@0
   224
	return SendReceiveResult(EBTAudioServerSetChannels, pckgBuf);
sl@0
   225
	}
sl@0
   226
	
sl@0
   227
EXPORT_C void RA2dpBTHeadsetAudioInterface::OpenDevice(TRequestStatus& aStatus)
sl@0
   228
	{
sl@0
   229
	aStatus = KRequestPending;
sl@0
   230
	SendReceive(EBTAudioServerOpenDevice, aStatus);
sl@0
   231
	}
sl@0
   232
sl@0
   233
EXPORT_C void RA2dpBTHeadsetAudioInterface::CancelOpenDevice()
sl@0
   234
	{
sl@0
   235
	SendReceive(EBTAudioServerCancelOpenDevice);
sl@0
   236
	}
sl@0
   237
	
sl@0
   238
EXPORT_C void RA2dpBTHeadsetAudioInterface::CloseDevice(TRequestStatus& aStatus)
sl@0
   239
	{
sl@0
   240
	aStatus = KRequestPending;
sl@0
   241
	SendReceive(EBTAudioServerCloseDevice, aStatus);
sl@0
   242
	}
sl@0
   243
	
sl@0
   244
EXPORT_C TUint RA2dpBTHeadsetAudioInterface::Volume() const
sl@0
   245
	{
sl@0
   246
	TUint volume = 0;
sl@0
   247
	TPckgBuf<TUint> volumePckg(volume);
sl@0
   248
	SendReceiveResult(EBTAudioServerVolume, volumePckg);
sl@0
   249
	return volumePckg();
sl@0
   250
	}
sl@0
   251
sl@0
   252
EXPORT_C TInt RA2dpBTHeadsetAudioInterface::SetVolume(TUint aVolume)
sl@0
   253
	{
sl@0
   254
	TPckgBuf<TUint> volumePckg(aVolume);
sl@0
   255
	return SendReceiveResult(EBTAudioServerSetVolume, volumePckg);
sl@0
   256
	}
sl@0
   257
sl@0
   258
EXPORT_C void RA2dpBTHeadsetAudioInterface::PlayData(const TDesC8& aData, TRequestStatus& aStatus)
sl@0
   259
	{
sl@0
   260
	aStatus = KRequestPending;
sl@0
   261
	SendReceive(EBTAudioServerPlayData, aData, aStatus);
sl@0
   262
	}
sl@0
   263
sl@0
   264
EXPORT_C void RA2dpBTHeadsetAudioInterface::CancelPlayData()
sl@0
   265
	{
sl@0
   266
	SendReceive(EBTAudioServerCancelPlayData);
sl@0
   267
	}
sl@0
   268
sl@0
   269
EXPORT_C void RA2dpBTHeadsetAudioInterface::FlushBuffer()
sl@0
   270
	{
sl@0
   271
	SendReceive(EBTAudioServerFlushBuffer);
sl@0
   272
	}
sl@0
   273
sl@0
   274
EXPORT_C TUint RA2dpBTHeadsetAudioInterface::BytesPlayed() const
sl@0
   275
	{
sl@0
   276
	TUint bytes = 0;
sl@0
   277
	TPckgBuf<TUint> bytesPlayedPckg(bytes);
sl@0
   278
	SendReceive(EBTAudioServerBytesPlayed, bytesPlayedPckg);
sl@0
   279
	return bytesPlayedPckg();
sl@0
   280
	}
sl@0
   281
sl@0
   282
EXPORT_C void RA2dpBTHeadsetAudioInterface::ResetBytesPlayed()
sl@0
   283
	{
sl@0
   284
	SendReceive(EBTAudioServerResetBytesPlayed);
sl@0
   285
	}
sl@0
   286
sl@0
   287
EXPORT_C void RA2dpBTHeadsetAudioInterface::PauseBuffer()
sl@0
   288
	{
sl@0
   289
	SendReceive(EBTAudioServerPauseBuffer);
sl@0
   290
	}
sl@0
   291
sl@0
   292
EXPORT_C void RA2dpBTHeadsetAudioInterface::ResumePlaying()
sl@0
   293
	{
sl@0
   294
	SendReceive(EBTAudioServerResumePlaying);
sl@0
   295
	}
sl@0
   296
sl@0
   297
EXPORT_C void RA2dpBTHeadsetAudioInterface::NotifyError(TRequestStatus& aStatus)
sl@0
   298
	{
sl@0
   299
	aStatus = KRequestPending;
sl@0
   300
	SendReceive(EBTAudioServerNotifyError, aStatus);
sl@0
   301
	}
sl@0
   302
sl@0
   303
EXPORT_C void RA2dpBTHeadsetAudioInterface::CancelNotifyError()
sl@0
   304
	{
sl@0
   305
	SendReceive(EBTAudioServerCancelNotifyError);
sl@0
   306
	}
sl@0
   307
sl@0
   308