|
1 // Copyright (c) 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". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 /** |
|
17 @file |
|
18 @internalTechnology |
|
19 */ |
|
20 |
|
21 #include <bluetooth/a2dpoptimisation.h> |
|
22 #include <bluetooth/a2dpoptimisationparams.h> |
|
23 |
|
24 #include <bluetooth/hciserverclient.h> |
|
25 #include <bluetooth/hci/hciipc.h> |
|
26 #include <bluetooth/logger.h> |
|
27 |
|
28 #ifdef __FLOG_ACTIVE |
|
29 _LIT8(KLogComponent, LOG_COMPONENT_A2DP_OPTIMISER); |
|
30 #endif |
|
31 |
|
32 EXPORT_C RA2dpOptimiser::RA2dpOptimiser() |
|
33 : iHCIServerSession(NULL) |
|
34 { |
|
35 } |
|
36 |
|
37 /** |
|
38 Opens the handle to the A2DP Optimisation interface. |
|
39 |
|
40 @return KErrNone if successful, otherwise a standard Symbian error code |
|
41 */ |
|
42 EXPORT_C TInt RA2dpOptimiser::Open() |
|
43 { |
|
44 LOG_FUNC |
|
45 __ASSERT_ALWAYS(!iHCIServerSession, PANIC(KA2dpOptimiserUtilsPanic, EHandleIsAlreadyOpen)); |
|
46 |
|
47 TInt err = KErrNoMemory; |
|
48 iHCIServerSession = new RHCIServerSession; |
|
49 if(iHCIServerSession) |
|
50 { |
|
51 err = iHCIServerSession->Open(KHCIA2dpOptimserManagerUid); |
|
52 if(err != KErrNone) |
|
53 { |
|
54 delete iHCIServerSession; |
|
55 iHCIServerSession = NULL; |
|
56 } |
|
57 } |
|
58 return err; |
|
59 } |
|
60 |
|
61 /** |
|
62 Closes the handle to the A2DP Optimisation interface. |
|
63 |
|
64 Note that it is safe to call this multiple times. |
|
65 */ |
|
66 EXPORT_C void RA2dpOptimiser::Close() |
|
67 { |
|
68 LOG_FUNC |
|
69 if(iHCIServerSession) |
|
70 { |
|
71 iHCIServerSession->Close(); |
|
72 delete iHCIServerSession; |
|
73 iHCIServerSession = NULL; |
|
74 } |
|
75 } |
|
76 |
|
77 /** |
|
78 Attempt to optimise the ACL for A2DP streaming. |
|
79 |
|
80 This method should return immediately without waiting for confirmation of optimisation |
|
81 from the hardware as it will be called directly before streaming is required. This |
|
82 method can also be called multiple times without having to remove the optimisation to |
|
83 allow for changing streaming parameters. |
|
84 |
|
85 The Peak Bandwidth argument is for the octets of A2DP data only, i.e. the overhead |
|
86 of additional headers, L2CAP for example, should not be considered by the caller of this |
|
87 method. |
|
88 |
|
89 @param aBDAddr Address of the remote device recieving audio stream |
|
90 @param aPeakBandwidth Peak Bandwidth of audio stream in octets per second |
|
91 @param aAccessLatency Access Latency of audio stream in microseconds |
|
92 */ |
|
93 EXPORT_C void RA2dpOptimiser::OptimiseAclForAudioStreaming(const TBTDevAddr& aBDAddr, TUint aPeakBandwidth, TUint aAccessLatency) |
|
94 { |
|
95 LOG_FUNC |
|
96 __ASSERT_ALWAYS(iHCIServerSession, PANIC(KA2dpOptimiserUtilsPanic, EApiUsedWhenHandleIsNotOpen)); |
|
97 |
|
98 TPckgBuf<TA2dpOptimisationParams> args(TA2dpOptimisationParams(aBDAddr, aPeakBandwidth, aAccessLatency)); |
|
99 static_cast<void>(iHCIServerSession->SendSync(EHCIA2dpOptimiseAcl, &args, NULL, 0)); |
|
100 } |
|
101 |
|
102 |
|
103 /** |
|
104 Attempt to remove any A2DP optimisation that was previously set using |
|
105 OptimiseAclForAudioStreaming(). |
|
106 |
|
107 @param aBDAddr Address of the remote device recieving audio stream |
|
108 */ |
|
109 EXPORT_C void RA2dpOptimiser::RemoveAclOptimisation(const TBTDevAddr& aBDAddr) |
|
110 { |
|
111 LOG_FUNC |
|
112 __ASSERT_ALWAYS(iHCIServerSession, PANIC(KA2dpOptimiserUtilsPanic, EApiUsedWhenHandleIsNotOpen)); |
|
113 |
|
114 TPckgBuf<TBTDevAddr> addrBuf(aBDAddr); |
|
115 static_cast<void>(iHCIServerSession->SendSync(EHCIA2dpRemoveAclOptimisation, &addrBuf, NULL, 0)); |
|
116 } |
|
117 |
|
118 // |
|
119 // TA2dpOptimisationParams |
|
120 // |
|
121 EXPORT_C TA2dpOptimisationParams::TA2dpOptimisationParams(const TBTDevAddr& aBDAddr, TUint aPeakBandwidth, TUint aAccessLatency) |
|
122 : iBDAddr(aBDAddr), iPeakBandwidth(aPeakBandwidth), iAccessLatency(aAccessLatency) |
|
123 { |
|
124 LOG_FUNC |
|
125 } |
|
126 |
|
127 EXPORT_C TA2dpOptimisationParams::TA2dpOptimisationParams() |
|
128 : iBDAddr(), iPeakBandwidth(0), iAccessLatency(0) |
|
129 { |
|
130 LOG_FUNC |
|
131 } |
|
132 |
|
133 EXPORT_C TBTDevAddr TA2dpOptimisationParams::RemoteDeviceAddress() const |
|
134 { |
|
135 LOG_FUNC |
|
136 return iBDAddr; |
|
137 } |
|
138 |
|
139 EXPORT_C TUint TA2dpOptimisationParams::PeakBandwidth() const |
|
140 { |
|
141 LOG_FUNC |
|
142 return iPeakBandwidth; |
|
143 } |
|
144 |
|
145 EXPORT_C TUint TA2dpOptimisationParams::AccessLatency() const |
|
146 { |
|
147 LOG_FUNC |
|
148 return iAccessLatency; |
|
149 } |
|
150 |