|
1 // Copyright (c) 2003-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 // Implements the avdtp media transport session |
|
15 // |
|
16 // |
|
17 |
|
18 /** |
|
19 @file |
|
20 @internalComponent |
|
21 */ |
|
22 |
|
23 #include <bluetooth/logger.h> |
|
24 #include "avdtpMediaSession.h" |
|
25 #include "avdtp.h" |
|
26 #include "avdtpsap.h" |
|
27 #include "avdtpStream.h" |
|
28 #include "avdtputil.h" |
|
29 #include "gavdpinterface.h" |
|
30 |
|
31 //#include <es_mbman.h> // for MBUF logging |
|
32 |
|
33 #ifdef __FLOG_ACTIVE |
|
34 _LIT8(KLogComponent, LOG_COMPONENT_AVDTP); |
|
35 #endif |
|
36 |
|
37 CMediaSession* CMediaSession::NewLC(CAvdtpProtocol& aProtocol, CAvdtpSAP& aSAP, CAVStream& aStream) |
|
38 { |
|
39 LOG_STATIC_FUNC |
|
40 CMediaSession* s = new (ELeave) CMediaSession(aProtocol, aSAP, aStream); |
|
41 CleanupStack::PushL(s); |
|
42 s->ConstructL(); |
|
43 return s; |
|
44 } |
|
45 |
|
46 CMediaSession* CMediaSession::NewL(CAvdtpProtocol& aProtocol, CAvdtpSAP& aSAP, CAVStream& aStream) |
|
47 { |
|
48 LOG_STATIC_FUNC |
|
49 CMediaSession* s = CMediaSession::NewLC(aProtocol, aSAP, aStream); |
|
50 CleanupStack::Pop(); |
|
51 return s; |
|
52 } |
|
53 |
|
54 CMediaSession::CMediaSession(CAvdtpProtocol& aProtocol, CAvdtpSAP& aSAP, CAVStream& aStream) |
|
55 : CUserPlaneTransportSession(aProtocol, aSAP, EMedia, aStream) |
|
56 { |
|
57 LOG_FUNC |
|
58 iNotifyMediaPacketDroppedFlag = EFalse; |
|
59 iPacketsLost = 0; |
|
60 } |
|
61 |
|
62 void CMediaSession::ConstructL() |
|
63 { |
|
64 LOG_FUNC |
|
65 CUserPlaneTransportSession::ConstructL(); |
|
66 |
|
67 // Balking is set to true. This allows the circular buffer to wrap |
|
68 // and overwrite the oldest data. |
|
69 User::LeaveIfError(iSendPool.Create(4, ETrue)); |
|
70 User::LeaveIfError(iReceivePool.Create(16, ETrue)); |
|
71 } |
|
72 |
|
73 TInt CMediaSession::DoActiveOpen() |
|
74 { |
|
75 LOG_FUNC |
|
76 __ASSERT_DEBUG(iStream, Panic(EAvdtpTransportSessionBaseNotCheckStream)); |
|
77 TInt ret = KErrGeneral; // may be OOM or notfound |
|
78 |
|
79 ret = iStream->AddSession(EMedia,*this,iTransportChannel); |
|
80 if (ret!=KErrNone) |
|
81 { |
|
82 // not erroring the stream, as it's not it's fault |
|
83 // and it may not exist anyway! |
|
84 iStream = NULL; |
|
85 iSAP.Error(ret); |
|
86 } |
|
87 return ret; |
|
88 } |
|
89 |
|
90 TInt CMediaSession::Send(RMBufChain& aData, TUint /*aOptions*/, TSockAddr* /*aAddr*/) |
|
91 { |
|
92 LOG_FUNC |
|
93 // if we get flow controlled should we *could* indicate to reporting session which could complete |
|
94 // an ioctl (for rtcp use) |
|
95 // if (iStream && iStream->CanSend(EMedia)) |
|
96 TInt requestedToSend = aData.Length(); |
|
97 TInt packetsLostThisSend = 0; // Packets lost during this send (if any) |
|
98 |
|
99 if (!iTransportChannelBlocked) |
|
100 { |
|
101 RMBufChain toSend; |
|
102 iSendPool.Remove(toSend); |
|
103 |
|
104 if (toSend.IsEmpty()) |
|
105 { |
|
106 toSend.Assign(aData); |
|
107 } |
|
108 else |
|
109 { |
|
110 iSendPool.Add(aData, packetsLostThisSend); |
|
111 iPacketsLost += packetsLostThisSend; |
|
112 } |
|
113 |
|
114 DoSend(toSend); |
|
115 } |
|
116 else |
|
117 { |
|
118 iSendPool.Add(aData, packetsLostThisSend); |
|
119 iPacketsLost += packetsLostThisSend; |
|
120 } |
|
121 |
|
122 // If client app has previous sent pack drop IOCTL it needs to be notified |
|
123 if (iNotifyMediaPacketDroppedFlag && iPacketsLost) |
|
124 { |
|
125 TPckgBuf<TInt> buf(iPacketsLost); |
|
126 iSAP.ServiceComplete(&buf); |
|
127 iNotifyMediaPacketDroppedFlag = EFalse; |
|
128 iPacketsLost = 0; |
|
129 } |
|
130 |
|
131 return requestedToSend; |
|
132 } |
|
133 |
|
134 // if pools become nicely generic then we could move this sending stuff to base class |
|
135 // and have sessions just configure the Tx, Rx pools |
|
136 void CMediaSession::DoSend(RMBufChain& aData) |
|
137 { |
|
138 LOG_FUNC |
|
139 if (iTransportChannel->SendPacket(EMedia, aData)==0) |
|
140 { |
|
141 // as media session, just free stale AV data (gets tricky putting stuff back on pool, and not really needed) |
|
142 // but mark TC as blokced so we can begin buffering in future |
|
143 aData.Free(); |
|
144 iTransportChannelBlocked = ETrue; |
|
145 } |
|
146 } |
|
147 |
|
148 |
|
149 void CMediaSession::CanSend() |
|
150 { |
|
151 LOG_FUNC |
|
152 // pluck off pool |
|
153 iTransportChannelBlocked = EFalse; |
|
154 //RDebug::Print(_L("MBuf free %d"), CMBufManager::Context()->__DbgGetBufSpace()); |
|
155 // something was placed on the send pool - remove it and send |
|
156 RMBufChain chain; |
|
157 |
|
158 do |
|
159 { |
|
160 iSendPool.Remove(chain); |
|
161 if (!chain.IsEmpty()) |
|
162 { |
|
163 DoSend(chain); |
|
164 } |
|
165 } |
|
166 while (!chain.IsEmpty()); |
|
167 } |
|
168 |
|
169 void CMediaSession::ReceivePacketLost() |
|
170 { |
|
171 // Increment the packet lost count. |
|
172 iPacketsLost++; |
|
173 |
|
174 // If client app has previous sent pack drop IOCTL it needs to be notified |
|
175 if (iNotifyMediaPacketDroppedFlag) |
|
176 { |
|
177 TPckgBuf<TInt> buf(iPacketsLost); |
|
178 iSAP.ServiceComplete(&buf); |
|
179 iNotifyMediaPacketDroppedFlag = EFalse; |
|
180 iPacketsLost = 0; |
|
181 } |
|
182 } |
|
183 |
|
184 TInt CMediaSession::GetOption(TUint aLevel, TUint aName, TDes8& aOption) const |
|
185 { |
|
186 LOG_FUNC |
|
187 TInt ret = KErrArgument; |
|
188 if (aLevel == KSolBtAVDTPMedia) |
|
189 { |
|
190 switch (aName) |
|
191 { |
|
192 case EAvdtpMediaGetMaximumPacketSize: |
|
193 { |
|
194 if (iTransportChannel) |
|
195 { |
|
196 TInt mtu; |
|
197 ret = iTransportChannel->MaxPacketSize(mtu); |
|
198 if (ret==KErrNone) |
|
199 { |
|
200 LOG1(_L("Media session transport channel MTU = %d"), mtu); |
|
201 TPckg<TInt> mtuBuf(mtu); |
|
202 aOption = mtuBuf; |
|
203 } |
|
204 } |
|
205 else |
|
206 { |
|
207 ret = KErrNotReady; |
|
208 } |
|
209 } |
|
210 break; |
|
211 case EAvdtpMediaGetMaximumReceivePacketSize: |
|
212 { |
|
213 if (iTransportChannel) |
|
214 { |
|
215 TInt mru; |
|
216 ret = iTransportChannel->MaxReceivePacketSize(mru); |
|
217 if (ret==KErrNone) |
|
218 { |
|
219 LOG1(_L("Media session transport channel MRU = %d"), mru); |
|
220 TPckg<TInt> mruBuf(mru); |
|
221 aOption = mruBuf; |
|
222 } |
|
223 } |
|
224 else |
|
225 { |
|
226 ret = KErrNotReady; |
|
227 } |
|
228 } |
|
229 break; |
|
230 default: |
|
231 ret = KErrNotSupported; |
|
232 } |
|
233 } |
|
234 |
|
235 return ret; |
|
236 } |
|
237 |
|
238 void CMediaSession::Ioctl(TUint aLevel, TUint aName, const TDesC8* /* aOption */) |
|
239 { |
|
240 LOG_FUNC |
|
241 TInt res; |
|
242 |
|
243 if (aLevel == KSolBtAVDTPMedia) |
|
244 { |
|
245 switch (aName) |
|
246 { |
|
247 case ENotifyAvdtpMediaPacketDropped: |
|
248 { |
|
249 iNotifyMediaPacketDroppedFlag= ETrue; |
|
250 res = KErrNone; |
|
251 break; |
|
252 } |
|
253 default: |
|
254 { |
|
255 res = KErrNotSupported; |
|
256 break; |
|
257 } |
|
258 } |
|
259 if (res!=KErrNone) |
|
260 { |
|
261 iSAP.Error(res); |
|
262 } |
|
263 } |
|
264 } |