os/mm/devsound/sounddevbt/src/A2dpBlueTooth/client/A2dpBTHeadsetAudioIfClient.cpp
Update contrib.
1 // Copyright (c) 2005-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.
17 #include <s32mem.h> // RDesReadStream
19 #include "A2dpBTHeadsetAudioIfClient.h"
20 #include "A2dpBTHeadsetAudioIfClientServer.h"
21 #include "A2dpBTHeadsetAudioIfServerStart.h"
22 #include "MMFBtRoutingSoundDevice.h"
24 const TInt KBluetoothAddressBufferLength = 32;
26 EXPORT_C RA2dpBTHeadsetAudioInterface::RA2dpBTHeadsetAudioInterface()
30 EXPORT_C TInt RA2dpBTHeadsetAudioInterface::Connect()
32 TRAPD(err, iBufAddr = HBufC::NewL(KBluetoothAddressBufferLength));
40 TRAP(err, iPckgBuf = new(ELeave)TPckgBuf<TBTDevAddr>);
48 TVersion version(KBTAudioServerMajorVersionNumber,
49 KBTAudioServerMinorVersionNumber,
50 KBTAudioServerBuildVersionNumber);
51 // Assume the server is already running and attempt to create a session
52 return CreateSession(KA2DPAudioServerName, version);
55 EXPORT_C void RA2dpBTHeadsetAudioInterface::Close()
57 // Call the base class
58 RMmfSessionBase::Close();
67 EXPORT_C void RA2dpBTHeadsetAudioInterface::Initialize(const TBTDevAddr& aRemoteAddress,
68 TRequestStatus& aStatus)
72 (*iPckgBuf)() = aRemoteAddress;
73 SendReceiveResult(EBTAudioServerInitialize, *iPckgBuf, aStatus);
77 // iPckgBuf not created => Connect() wasn't called or the returned error code was ignored.
78 TRequestStatus* status = &aStatus;
79 User::RequestComplete(status, KErrDisconnected);
83 EXPORT_C void RA2dpBTHeadsetAudioInterface::CancelInitialize()
85 SendReceive(EBTAudioServerCancelInitialize);
88 EXPORT_C void RA2dpBTHeadsetAudioInterface::GetSupportedDataTypesL(RArray<TFourCC>& aSupportedDataTypes) const
90 aSupportedDataTypes.Reset();
91 TPckgBuf<TInt> numberOfElementsPckg;
92 TInt err = SendReceiveResult(EBTAudioServerGetSupportedDataTypes, numberOfElementsPckg);
93 User::LeaveIfError(err);
95 HBufC8* buf = HBufC8::NewLC(numberOfElementsPckg() * sizeof(TFourCC));
96 TPtr8 ptr = buf->Des();
97 err = SendReceiveResult(EBTAudioServerCopyFourCCArrayData, ptr);
98 User::LeaveIfError(err);
100 RDesReadStream stream(ptr);
101 CleanupClosePushL(stream);
103 for (TInt i = 0; i < numberOfElementsPckg(); i++)
105 err = aSupportedDataTypes.Append(stream.ReadInt32L());
107 {//note we don't destroy array because we don't own it
108 //but we do reset it as it is incomplete
109 aSupportedDataTypes.Reset();
113 CleanupStack::PopAndDestroy(2, buf);
116 EXPORT_C void RA2dpBTHeadsetAudioInterface::GetSupportedSampleRatesL(RArray<TUint>& aSupportedDiscreteRates,
117 RArray<TRange>& aSupportedRateRanges) const
119 aSupportedDiscreteRates.Reset();
120 TPckgBuf<TRatesArrayElements> numberOfElementsPckg;
122 TInt err = SendReceiveResult(EBTAudioServerGetSupportedSampleRates, numberOfElementsPckg);
123 User::LeaveIfError(err);
125 HBufC8* buf = HBufC8::NewLC(numberOfElementsPckg().iDiscrete * sizeof(TUint));
126 TPtr8 ptr = buf->Des();
127 err = SendReceiveResult(EBTAudioServerGetSupportedSampleRatesDiscrete, ptr);
128 User::LeaveIfError(err);
130 RDesReadStream stream(ptr);
131 CleanupClosePushL(stream);
133 // Populate the discrete rates array
134 for (TInt i = 0; i < numberOfElementsPckg().iDiscrete; i++)
136 err = aSupportedDiscreteRates.Append(stream.ReadInt32L());
138 {//note we don't destroy array because we don't own it
139 //but we do reset it as it is incomplete
140 aSupportedDiscreteRates.Reset();
145 ptr.SetLength(0); //clear out exiting data
146 // Get the rates range array (# of elements and the elements themselves)
147 buf = buf->ReAllocL(numberOfElementsPckg().iRange * sizeof(TRange));
151 err = SendReceiveResult(EBTAudioServerGetSupportedSampleRatesRange, ptr);
152 User::LeaveIfError(err);
154 for (TInt i = 0; i < numberOfElementsPckg().iRange; i++)
156 range.iLow = stream.ReadInt32L();
157 range.iHigh = stream.ReadInt32L();
158 err = aSupportedRateRanges.Append(range);
161 aSupportedRateRanges.Reset();
166 CleanupStack::PopAndDestroy(2, buf);//stream, buf
169 EXPORT_C void RA2dpBTHeadsetAudioInterface::GetSupportedChannelsL(RArray<TUint>& aSupportedChannels,
170 TMMFStereoSupport& aStereoSupport) const
173 aSupportedChannels.Reset();
174 TChannelsSupport channelsSupport;
175 channelsSupport.iElementCount = 0;
176 channelsSupport.iSupport = EMMFNone;
177 TPckgBuf<TChannelsSupport> channelsSupportPckg(channelsSupport);
179 TInt err = SendReceiveResult(EBTAudioServerGetSupportedChannels, channelsSupportPckg);
180 User::LeaveIfError(err);
182 aStereoSupport = channelsSupportPckg().iSupport;
183 HBufC8* buf = HBufC8::NewLC(channelsSupportPckg().iElementCount * sizeof(TUint));
184 TPtr8 ptr = buf->Des();
185 err = SendReceiveResult(EBTAudioServerCopyChannelsArrayData, ptr);
186 User::LeaveIfError(err);
188 RDesReadStream stream(ptr);
189 CleanupClosePushL(stream);
191 // Populate the stereo support array
192 for (TInt i = 0; i < channelsSupportPckg().iElementCount; i++)
194 err = aSupportedChannels.Append(stream.ReadInt32L());
196 {//note we don't destroy array because we don't own it
197 //but we do reset it as it is incomplete
198 aSupportedChannels.Reset();
202 CleanupStack::PopAndDestroy(2, buf); //stream, buf
205 EXPORT_C TInt RA2dpBTHeadsetAudioInterface::SetDataType(const TFourCC& aDataType)
207 TPckgBuf<TFourCC> dataTypePckg(aDataType);
208 return SendReceiveResult(EBTAudioServerSetDataType, dataTypePckg);
211 EXPORT_C TInt RA2dpBTHeadsetAudioInterface::SetSampleRate(TUint aSampleRate)
213 TPckgBuf<TUint> sampleRatePckg(aSampleRate);
214 return SendReceiveResult(EBTAudioServerSetSampleRate, sampleRatePckg);
217 EXPORT_C TInt RA2dpBTHeadsetAudioInterface::SetChannels(TUint aChannels,
218 TMMFStereoSupport aStereoSupport)
220 TChannelsSupport channelsSupport;
221 channelsSupport.iElementCount = aChannels;
222 channelsSupport.iSupport = aStereoSupport;
223 TPckgBuf<TChannelsSupport> pckgBuf(channelsSupport);
224 return SendReceiveResult(EBTAudioServerSetChannels, pckgBuf);
227 EXPORT_C void RA2dpBTHeadsetAudioInterface::OpenDevice(TRequestStatus& aStatus)
229 aStatus = KRequestPending;
230 SendReceive(EBTAudioServerOpenDevice, aStatus);
233 EXPORT_C void RA2dpBTHeadsetAudioInterface::CancelOpenDevice()
235 SendReceive(EBTAudioServerCancelOpenDevice);
238 EXPORT_C void RA2dpBTHeadsetAudioInterface::CloseDevice(TRequestStatus& aStatus)
240 aStatus = KRequestPending;
241 SendReceive(EBTAudioServerCloseDevice, aStatus);
244 EXPORT_C TUint RA2dpBTHeadsetAudioInterface::Volume() const
247 TPckgBuf<TUint> volumePckg(volume);
248 SendReceiveResult(EBTAudioServerVolume, volumePckg);
252 EXPORT_C TInt RA2dpBTHeadsetAudioInterface::SetVolume(TUint aVolume)
254 TPckgBuf<TUint> volumePckg(aVolume);
255 return SendReceiveResult(EBTAudioServerSetVolume, volumePckg);
258 EXPORT_C void RA2dpBTHeadsetAudioInterface::PlayData(const TDesC8& aData, TRequestStatus& aStatus)
260 aStatus = KRequestPending;
261 SendReceive(EBTAudioServerPlayData, aData, aStatus);
264 EXPORT_C void RA2dpBTHeadsetAudioInterface::CancelPlayData()
266 SendReceive(EBTAudioServerCancelPlayData);
269 EXPORT_C void RA2dpBTHeadsetAudioInterface::FlushBuffer()
271 SendReceive(EBTAudioServerFlushBuffer);
274 EXPORT_C TUint RA2dpBTHeadsetAudioInterface::BytesPlayed() const
277 TPckgBuf<TUint> bytesPlayedPckg(bytes);
278 SendReceive(EBTAudioServerBytesPlayed, bytesPlayedPckg);
279 return bytesPlayedPckg();
282 EXPORT_C void RA2dpBTHeadsetAudioInterface::ResetBytesPlayed()
284 SendReceive(EBTAudioServerResetBytesPlayed);
287 EXPORT_C void RA2dpBTHeadsetAudioInterface::PauseBuffer()
289 SendReceive(EBTAudioServerPauseBuffer);
292 EXPORT_C void RA2dpBTHeadsetAudioInterface::ResumePlaying()
294 SendReceive(EBTAudioServerResumePlaying);
297 EXPORT_C void RA2dpBTHeadsetAudioInterface::NotifyError(TRequestStatus& aStatus)
299 aStatus = KRequestPending;
300 SendReceive(EBTAudioServerNotifyError, aStatus);
303 EXPORT_C void RA2dpBTHeadsetAudioInterface::CancelNotifyError()
305 SendReceive(EBTAudioServerCancelNotifyError);