|
1 /* |
|
2 * Copyright (c) 2005 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 #include "mcepreparingstreams.h" |
|
22 #include "mcecomsession.h" |
|
23 #include "mcesdpsession.h" |
|
24 #include "mcesrvstream.h" |
|
25 #include "mceevents.h" |
|
26 #include "mcemmlogs.h" |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 // ----------------------------------------------------------------------------- |
|
32 // TMcePreparingStreams::TMcePreparingStreams |
|
33 // ----------------------------------------------------------------------------- |
|
34 // |
|
35 TMcePreparingStreams::TMcePreparingStreams ( |
|
36 CMceComSession& aSession, |
|
37 TMceNegotiationRole aRole, |
|
38 TMceSrvStreamIterator::TDirection aDirection ) |
|
39 : TMceMediaState( aSession ), |
|
40 iIterator( TMceSrvStreamIterator( aSession.MccStreams(), aDirection ) ) |
|
41 { |
|
42 SetRole( aRole ); |
|
43 } |
|
44 |
|
45 |
|
46 |
|
47 // ----------------------------------------------------------------------------- |
|
48 // TMcePreparingStreams::MccLinkCreatedL |
|
49 // ----------------------------------------------------------------------------- |
|
50 // |
|
51 void TMcePreparingStreams::MccLinkCreatedL( TMceMccComEvent& aEvent ) |
|
52 { |
|
53 MCEMM_DEBUG("TMcePreparingStreams::MccLinkCreatedL(), Entry "); |
|
54 |
|
55 CMceSrvStream::EventReceived( iSession.MccStreams(), aEvent ); |
|
56 CMceSrvStream* stream = NULL; |
|
57 |
|
58 iIterator.Reset(); |
|
59 |
|
60 //try to find first stream, which is in state 'greater or equal' than link created |
|
61 //if no stream => all streams are in state link created |
|
62 //=> links are created |
|
63 if ( !iIterator.Next( stream, CMceSrvStream::ECreatingLink, |
|
64 TMceSrvStreamIterator::ExactMatch ) ) |
|
65 { |
|
66 PrepareStreamsL(); |
|
67 } |
|
68 else |
|
69 { |
|
70 MCEMM_DEBUG("TMcePreparingStreams::MccLinkCreatedL(): \ |
|
71 waiting links to be created"); |
|
72 //just wait |
|
73 } |
|
74 |
|
75 MCEMM_DEBUG("TMcePreparingStreams::MccLinkCreatedL(), Exit "); |
|
76 } |
|
77 |
|
78 |
|
79 // ----------------------------------------------------------------------------- |
|
80 // TMcePreparingStreams::MccMediaPreparedL |
|
81 // ----------------------------------------------------------------------------- |
|
82 // |
|
83 void TMcePreparingStreams::MccMediaPreparedL( TMceMccComEvent& aEvent ) |
|
84 { |
|
85 MCEMM_DEBUG("TMcePreparingStreams::MccMediaPreparedL(), Entry "); |
|
86 |
|
87 CMceSrvStream::EventReceived( iSession.MccStreams(), aEvent ); |
|
88 CMceSrvStream* stream = NULL; |
|
89 |
|
90 iIterator.Reset(); |
|
91 |
|
92 //try to find first stream, which is in state 'greater or equal' than prepared |
|
93 //if no stream => all streams are in state prepared or stopped (or started, paused) |
|
94 //=> streams are prepared |
|
95 if ( !iIterator.Next( stream, CMceSrvStream::EPreparing, |
|
96 TMceSrvStreamIterator::ExactMatch ) ) |
|
97 { |
|
98 StreamsPreparedL(); |
|
99 } |
|
100 else |
|
101 { |
|
102 MCEMM_DEBUG("TMcePreparingStreams::MccMediaPreparedL(): \ |
|
103 waiting streams to be prepared"); |
|
104 //just wait |
|
105 } |
|
106 |
|
107 MCEMM_DEBUG("TMcePreparingStreams::MccMediaPreparedL(), Exit "); |
|
108 } |
|
109 |
|
110 |
|
111 // ----------------------------------------------------------------------------- |
|
112 // TMcePreparingStreams::MccMediaStartedL |
|
113 // ----------------------------------------------------------------------------- |
|
114 // |
|
115 void TMcePreparingStreams::MccMediaStartedL( TMceMccComEvent& aEvent ) |
|
116 { |
|
117 MCEMM_DEBUG("TMcePreparingStreams::MccMediaStartedL(), Entry "); |
|
118 |
|
119 CMceSrvStream::EventReceived( iSession.MccStreams(), aEvent ); |
|
120 |
|
121 CMceSrvStream* stream = NULL; |
|
122 |
|
123 iIterator.Reset(); |
|
124 |
|
125 //try to find first stream, which is in state 'greater or equal' than stopped |
|
126 //if no stream => all streams are in state stopped, started or paused |
|
127 if ( !iIterator.Next( stream, CMceSrvStream::EStarting, |
|
128 TMceSrvStreamIterator::ExactMatch ) ) |
|
129 { |
|
130 StreamsStartedL(); |
|
131 } |
|
132 else |
|
133 { |
|
134 MCEMM_DEBUG("TMcePreparingStreams::MccMediaStartedL(): \ |
|
135 waiting streams to be started"); |
|
136 //just wait |
|
137 } |
|
138 |
|
139 MCEMM_DEBUG("TMcePreparingStreams::MccMediaStartedL(), Exit "); |
|
140 } |
|
141 |
|
142 // ----------------------------------------------------------------------------- |
|
143 // TMcePreparingStreams::MccMediaPausedL |
|
144 // ----------------------------------------------------------------------------- |
|
145 // |
|
146 void TMcePreparingStreams::MccMediaPausedL( TMceMccComEvent& aEvent ) |
|
147 { |
|
148 MCEMM_DEBUG("TMcePreparingStreams::MccMediaPausedL(), Entry "); |
|
149 |
|
150 MccMediaStartedL( aEvent ); |
|
151 |
|
152 MCEMM_DEBUG("TMcePreparingStreams::MccMediaPausedL(), Exit "); |
|
153 } |
|
154 |
|
155 |
|
156 // ----------------------------------------------------------------------------- |
|
157 // TMcePreparingStreams::MccMediaResumedL |
|
158 // ----------------------------------------------------------------------------- |
|
159 // |
|
160 void TMcePreparingStreams::MccMediaResumedL( TMceMccComEvent& aEvent ) |
|
161 { |
|
162 MCEMM_DEBUG("TMcePreparingStreams::MccMediaResumedL(), Entry "); |
|
163 |
|
164 MccMediaStartedL( aEvent ); |
|
165 |
|
166 MCEMM_DEBUG("TMcePreparingStreams::MccMediaResumedL(), Exit "); |
|
167 } |
|
168 |
|
169 |
|
170 // ----------------------------------------------------------------------------- |
|
171 // TMcePreparingStreams::PrepareStreamsL |
|
172 // ----------------------------------------------------------------------------- |
|
173 // |
|
174 |
|
175 void TMcePreparingStreams::PrepareStreamsL() |
|
176 { |
|
177 MCEMM_DEBUG("TMcePreparingStreams::PrepareStreamsL(), Entry "); |
|
178 |
|
179 CMceSrvStream* stream = NULL; |
|
180 TBool wait = EFalse; |
|
181 |
|
182 iIterator.Reset(); |
|
183 while( iIterator.Next( stream, CMceSrvStream::ECreated ) ) |
|
184 { |
|
185 MCEMM_DEBUG_STREAM( "TMcePreparingStreams::PrepareStreamsL(): \ |
|
186 create link", *stream ); |
|
187 iSession.SdpSession().Manager().CreateMccLinkL( *stream ); |
|
188 wait = !wait ? stream->State() != CMceSrvStream::ELinkCreated : wait; |
|
189 } |
|
190 |
|
191 if ( !wait ) |
|
192 { |
|
193 |
|
194 iIterator.Reset(); |
|
195 wait = EFalse; |
|
196 while( iIterator.Next( stream, CMceSrvStream::ELinkCreated ) ) |
|
197 { |
|
198 MCEMM_DEBUG_STREAM( "TMcePreparingStreams::PrepareStreamsL(): \ |
|
199 create stream", *stream ); |
|
200 iSession.SdpSession().Manager().CreateMccStreamL( *stream, iRole ); |
|
201 } |
|
202 |
|
203 iIterator.Reset(); |
|
204 wait = EFalse; |
|
205 while( iIterator.Next( stream, CMceSrvStream::ELinkCreated ) ) |
|
206 { |
|
207 MCEMM_DEBUG_STREAM( "TMcePreparingStreams::PrepareStreamsL(): \ |
|
208 prepare stream", *stream ); |
|
209 iSession.SdpSession().Manager().PrepareMccStreamL( *stream, iRole ); |
|
210 wait = !wait ? stream->State() != CMceSrvStream::EPrepared : wait; |
|
211 } |
|
212 |
|
213 if (!wait) |
|
214 { |
|
215 MCEMM_DEBUG("TMcePreparingStreams::PrepareStreamsL(): streams prepared"); |
|
216 StreamsPreparedL(); |
|
217 } |
|
218 |
|
219 } |
|
220 |
|
221 MCEMM_DEBUG("TMcePreparingStreams::PrepareStreamsL(), Exit "); |
|
222 |
|
223 } |
|
224 |
|
225 |
|
226 // ----------------------------------------------------------------------------- |
|
227 // TMcePreparingStreams::StartStreamsL |
|
228 // ----------------------------------------------------------------------------- |
|
229 // |
|
230 void TMcePreparingStreams::StartStreamsL( TBool aUpdateRemoteAddress ) |
|
231 { |
|
232 MCEMM_DEBUG( "TMcePreparingStreams::StartStreamsL(), Entry" ) |
|
233 |
|
234 // Hardware does not necessarily support two simulataneous mic users so |
|
235 // it is more safe to do pausing of old send stream before starting the |
|
236 // new one. This can be achieved by traversing streams in reverse order |
|
237 // as they are in priority order and new send stream has higher priority. |
|
238 // |
|
239 RPointerArray<CMceSrvStream>& origStreams = iSession.MccStreams(); |
|
240 RPointerArray<CMceSrvStream> reverseOrderStream; |
|
241 CleanupClosePushL( reverseOrderStream ); |
|
242 TInt lastIndex( origStreams.Count() - 1 ); |
|
243 for ( TInt i = lastIndex; i >= 0; i-- ) |
|
244 { |
|
245 reverseOrderStream.AppendL( origStreams[ i ] ); |
|
246 } |
|
247 |
|
248 TMceSrvStreamIterator reversedIterator( reverseOrderStream, |
|
249 iIterator.Direction() ); |
|
250 |
|
251 TBool wait = EFalse; |
|
252 CMceSrvStream* stream = NULL; |
|
253 |
|
254 while( reversedIterator.Next( stream, CMceSrvStream::EPrepared, |
|
255 TMceSrvStreamIterator::GreaterOrEqualMatch ) ) |
|
256 { |
|
257 const CMceSrvStream::TState state = stream->State(); |
|
258 |
|
259 if ( state == CMceSrvStream::EPrepared && |
|
260 stream->Codec().iIsEnabled ) |
|
261 { |
|
262 MCEMM_DEBUG_STREAM( "TMcePreparingStreams::StartStreamsL() start stream", |
|
263 *stream ) |
|
264 |
|
265 iSession.SdpSession().Manager().StartMccStreamL( *stream ); |
|
266 wait = !wait ? stream->State() == CMceSrvStream::EStarting : wait; |
|
267 } |
|
268 else if ( aUpdateRemoteAddress ) |
|
269 { |
|
270 MCEMM_DEBUG( "TMcePreparingStreams::StartStreamsL() remote address update" ) |
|
271 iSession.SdpSession().Manager().SetRemoteAddressL( *stream ); |
|
272 } |
|
273 else |
|
274 { |
|
275 // NOP |
|
276 } |
|
277 |
|
278 MCEMM_DEBUG_STREAM( "TMcePreparingStreams::StartStreamsL() synchronize stream", |
|
279 *stream ) |
|
280 |
|
281 iSession.SdpSession().Manager().SynchronizeMccStreamL( *stream, iRole ); |
|
282 } |
|
283 |
|
284 if ( !wait ) |
|
285 { |
|
286 MCEMM_DEBUG( "TMcePreparingStreams::StartStreamsL(): streams started" ) |
|
287 StreamsStartedL(); |
|
288 } |
|
289 |
|
290 CleanupStack::PopAndDestroy( &reverseOrderStream ); |
|
291 |
|
292 MCEMM_DEBUG( "TMcePreparingStreams::StartStreamsL(), Exit" ) |
|
293 } |
|
294 |