|
1 /* |
|
2 * Copyright (c) 2006 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 // INCLUDE FILES |
|
21 #include "mccvideosourcekeyretriever.h" |
|
22 #include "mccinternalcodecs.h" |
|
23 #include "mccinternaldef.h" |
|
24 #include "mccinternalevents.h" |
|
25 #include "mccvideosourceimpl.h" |
|
26 #include "mccvideosourcesinklogs.h" |
|
27 #include "mccperiodicrunner.h" |
|
28 |
|
29 // ============================ MEMBER FUNCTIONS =============================== |
|
30 |
|
31 // ----------------------------------------------------------------------------- |
|
32 // CMccVideoSourceConfigKeyRetriever::NewLC |
|
33 // ----------------------------------------------------------------------------- |
|
34 // |
|
35 CMccVideoSourceConfigKeyRetriever* CMccVideoSourceConfigKeyRetriever::NewLC( |
|
36 MMccCameraHandler& aCameraHandler ) |
|
37 { |
|
38 CMccVideoSourceConfigKeyRetriever* self = |
|
39 new ( ELeave ) CMccVideoSourceConfigKeyRetriever( aCameraHandler ); |
|
40 CleanupStack::PushL( self ); |
|
41 self->ConstructL(); |
|
42 return self; |
|
43 } |
|
44 |
|
45 // ----------------------------------------------------------------------------- |
|
46 // CMccVideoSourceConfigKeyRetriever::~CMccVideoSourceConfigKeyRetriever |
|
47 // ----------------------------------------------------------------------------- |
|
48 // |
|
49 CMccVideoSourceConfigKeyRetriever::~CMccVideoSourceConfigKeyRetriever() |
|
50 { |
|
51 __V_SOURCESINK_CONTROLL( |
|
52 "CMccVideoSourceConfigKeyRetriever::~CMccVideoSourceConfigKeyRetriever" ) |
|
53 |
|
54 delete iGuardTimer; |
|
55 |
|
56 StopWaiting(); |
|
57 |
|
58 delete iWait; |
|
59 |
|
60 delete iSource; |
|
61 |
|
62 delete iBuffer; |
|
63 |
|
64 __V_SOURCESINK_CONTROLL( |
|
65 "CMccVideoSourceConfigKeyRetriever::~CMccVideoSourceConfigKeyRetriever, exit" ) |
|
66 } |
|
67 |
|
68 // ----------------------------------------------------------------------------- |
|
69 // CMccVideoSourceConfigKeyRetriever::RetrieveL |
|
70 // ----------------------------------------------------------------------------- |
|
71 // |
|
72 void CMccVideoSourceConfigKeyRetriever::RetrieveL( |
|
73 const TMccCodecInfo& aVideoCodec, |
|
74 TDes8& aConfigKey ) |
|
75 { |
|
76 __V_SOURCESINK_CONTROLL( "CMccVideoSourceConfigKeyRetriever::RetrieveL" ) |
|
77 |
|
78 __ASSERT_ALWAYS( aVideoCodec.iSdpName.CompareF( KAVCSdpName ) == 0, |
|
79 User::Leave( KErrNotSupported ) ); |
|
80 |
|
81 delete iBuffer; |
|
82 iBuffer = NULL; |
|
83 iBuffer = CMMFDataBuffer::NewL( aVideoCodec.iFrameSize ); |
|
84 |
|
85 delete iSource; |
|
86 iSource = NULL; |
|
87 iSource = CMccVideoSourceImpl::NewL( 0, NULL, ETrue ); |
|
88 |
|
89 iFailed = EFalse; |
|
90 |
|
91 iSource->SourceThreadLogon( *this ); |
|
92 iSource->SetCameraHandler( iCameraHandler ); |
|
93 iSource->SetVideoCodecL( aVideoCodec ); |
|
94 iSource->SourcePrimeL( EFalse ); |
|
95 |
|
96 if ( !iSource->HasConfigKey() && !iFailed ) |
|
97 { |
|
98 __V_SOURCESINK_CONTROLL( "Start waiting for key" ) |
|
99 |
|
100 // Start also guard timer to prevent possible eternal jam |
|
101 StartGuardTimer(); |
|
102 |
|
103 iWait->Start(); |
|
104 |
|
105 __V_SOURCESINK_CONTROLL( "Waiting completed" ) |
|
106 StopGuardTimer(); |
|
107 } |
|
108 |
|
109 __ASSERT_ALWAYS( !iFailed, User::Leave( KErrNotFound ) ); |
|
110 |
|
111 iSource->GetConfigKeyL( aVideoCodec, aConfigKey, EFalse ); |
|
112 |
|
113 __V_SOURCESINK_CONTROLL( "CMccVideoSourceConfigKeyRetriever::RetrieveL, exit" ) |
|
114 } |
|
115 |
|
116 // ----------------------------------------------------------------------------- |
|
117 // CMccVideoSourceConfigKeyRetriever::SendEventToClient |
|
118 // ----------------------------------------------------------------------------- |
|
119 // |
|
120 TInt CMccVideoSourceConfigKeyRetriever::SendEventToClient( const TMMFEvent& aEvent ) |
|
121 { |
|
122 __V_SOURCESINK_CONTROLL( "CMccVideoSourceConfigKeyRetriever::SendEventToClient" ) |
|
123 |
|
124 TInt error( KErrNone ); |
|
125 TMccEvent* mccEventPtr = NULL; |
|
126 if ( IS_MCC_EVENT( aEvent ) ) |
|
127 { |
|
128 mccEventPtr = |
|
129 reinterpret_cast<const TMccInternalEvent&>( aEvent ).iMccEvent; |
|
130 } |
|
131 |
|
132 if ( mccEventPtr ) |
|
133 { |
|
134 TRAP( error, HandleEventL( *mccEventPtr ) ); |
|
135 if ( error != KErrNone ) |
|
136 { |
|
137 HandleError(); |
|
138 } |
|
139 } |
|
140 |
|
141 __V_SOURCESINK_CONTROLL( "CMccVideoSourceConfigKeyRetriever::SendEventToClient, exit" ) |
|
142 |
|
143 return error; |
|
144 } |
|
145 |
|
146 // ----------------------------------------------------------------------------- |
|
147 // CMccVideoSourceConfigKeyRetriever::SinkDataTypeCode |
|
148 // ----------------------------------------------------------------------------- |
|
149 // |
|
150 TFourCC CMccVideoSourceConfigKeyRetriever::SinkDataTypeCode( TMediaId /*aMediaId*/ ) |
|
151 { |
|
152 return TFourCC( 0 ); |
|
153 } |
|
154 |
|
155 // ----------------------------------------------------------------------------- |
|
156 // CMccVideoSourceConfigKeyRetriever::EmptyBufferL |
|
157 // ----------------------------------------------------------------------------- |
|
158 // |
|
159 void CMccVideoSourceConfigKeyRetriever::EmptyBufferL( |
|
160 CMMFBuffer* /*aBuffer*/, MDataSource* /*aSupplier*/, TMediaId /*aMediaId*/ ) |
|
161 { |
|
162 } |
|
163 |
|
164 // ----------------------------------------------------------------------------- |
|
165 // CMccVideoSourceConfigKeyRetriever::BufferFilledL |
|
166 // ----------------------------------------------------------------------------- |
|
167 // |
|
168 void CMccVideoSourceConfigKeyRetriever::BufferFilledL( CMMFBuffer* /*aBuffer*/ ) |
|
169 { |
|
170 __V_SOURCESINK_CONTROLL( "CMccVideoSourceConfigKeyRetriever::BufferFilledL" ) |
|
171 |
|
172 // First buffer was received from mediarecorder, config info should be now |
|
173 // available. |
|
174 StopWaiting(); |
|
175 } |
|
176 |
|
177 // ----------------------------------------------------------------------------- |
|
178 // CMccVideoSourceConfigKeyRetriever::CanCreateSinkBuffer |
|
179 // ----------------------------------------------------------------------------- |
|
180 // |
|
181 TBool CMccVideoSourceConfigKeyRetriever::CanCreateSinkBuffer() |
|
182 { |
|
183 return EFalse; |
|
184 } |
|
185 |
|
186 // ----------------------------------------------------------------------------- |
|
187 // CMccVideoSourceConfigKeyRetriever::CreateSinkBufferL |
|
188 // ----------------------------------------------------------------------------- |
|
189 // |
|
190 CMMFBuffer* CMccVideoSourceConfigKeyRetriever::CreateSinkBufferL( |
|
191 TMediaId /*aMediaId*/, TBool& /*aReference*/ ) |
|
192 { |
|
193 return NULL; |
|
194 } |
|
195 |
|
196 // ----------------------------------------------------------------------------- |
|
197 // CMccVideoSourceConfigKeyRetriever::ConstructSinkL |
|
198 // ----------------------------------------------------------------------------- |
|
199 // |
|
200 void CMccVideoSourceConfigKeyRetriever::ConstructSinkL( const TDesC8& /*aInitData*/ ) |
|
201 { |
|
202 } |
|
203 |
|
204 |
|
205 // ----------------------------------------------------------------------------- |
|
206 // CMccVideoSourceConfigKeyRetriever::ConstructL |
|
207 // ----------------------------------------------------------------------------- |
|
208 // |
|
209 void CMccVideoSourceConfigKeyRetriever::ConstructL() |
|
210 { |
|
211 __V_SOURCESINK_CONTROLL( "CMccVideoSourceConfigKeyRetriever::ConstructL" ) |
|
212 |
|
213 iWait = new ( ELeave ) CActiveSchedulerWait; |
|
214 |
|
215 iGuardTimer = CMccPeriodicRunner::NewL(); |
|
216 |
|
217 __V_SOURCESINK_CONTROLL( "CMccVideoSourceConfigKeyRetriever::ConstructL, exit" ) |
|
218 } |
|
219 |
|
220 // ----------------------------------------------------------------------------- |
|
221 // CMccVideoSourceConfigKeyRetriever::ConstructL |
|
222 // ----------------------------------------------------------------------------- |
|
223 // |
|
224 CMccVideoSourceConfigKeyRetriever::CMccVideoSourceConfigKeyRetriever( |
|
225 MMccCameraHandler& aCameraHandler ) : |
|
226 MDataSink( KNullUid ), |
|
227 iCameraHandler( aCameraHandler ), |
|
228 iGuardTimerTimeout( KMccKeyRetrieveGuardTimeoutMicrosecs ) |
|
229 { |
|
230 } |
|
231 |
|
232 // ----------------------------------------------------------------------------- |
|
233 // CMccVideoSourceConfigKeyRetriever::HandleEventL |
|
234 // ----------------------------------------------------------------------------- |
|
235 // |
|
236 void CMccVideoSourceConfigKeyRetriever::HandleEventL( TMccEvent& aEvent ) |
|
237 { |
|
238 __V_SOURCESINK_CONTROLL( "CMccVideoSourceConfigKeyRetriever::HandleEventL" ) |
|
239 |
|
240 if ( aEvent.iEventType == KMccStreamError || aEvent.iErrorCode != KErrNone ) |
|
241 { |
|
242 User::Leave( KErrNotReady ); |
|
243 } |
|
244 else if ( aEvent.iEventType == KMccStreamPrepared ) |
|
245 { |
|
246 __V_SOURCESINK_CONTROLL( "Prepared" ) |
|
247 |
|
248 // Start recording, first buffer received from mediarecorder |
|
249 // should contain config info |
|
250 iSource->FillBufferL( iBuffer, this, KUidMediaTypeVideo ); |
|
251 iSource->SourcePlayL(); |
|
252 } |
|
253 else if ( aEvent.iEventType == KMccStreamStarted ) |
|
254 { |
|
255 __V_SOURCESINK_CONTROLL( "Started" ) |
|
256 } |
|
257 else |
|
258 { |
|
259 // NOP |
|
260 } |
|
261 |
|
262 __V_SOURCESINK_CONTROLL( "CMccVideoSourceConfigKeyRetriever::HandleEventL, exit" ) |
|
263 } |
|
264 |
|
265 // ----------------------------------------------------------------------------- |
|
266 // CMccVideoSourceConfigKeyRetriever::HandleError |
|
267 // ----------------------------------------------------------------------------- |
|
268 // |
|
269 void CMccVideoSourceConfigKeyRetriever::HandleError() |
|
270 { |
|
271 __V_SOURCESINK_CONTROLL( "CMccVideoSourceConfigKeyRetriever::HandleError" ) |
|
272 |
|
273 iFailed = ETrue; |
|
274 StopWaiting(); |
|
275 } |
|
276 |
|
277 // ----------------------------------------------------------------------------- |
|
278 // CMccVideoSourceConfigKeyRetriever::StopWaiting |
|
279 // ----------------------------------------------------------------------------- |
|
280 // |
|
281 void CMccVideoSourceConfigKeyRetriever::StopWaiting() |
|
282 { |
|
283 if ( iWait && iWait->IsStarted() ) |
|
284 { |
|
285 __V_SOURCESINK_CONTROLL( "CMccVideoSourceConfigKeyRetriever::StopWaiting" ) |
|
286 iWait->AsyncStop(); |
|
287 } |
|
288 } |
|
289 |
|
290 // ----------------------------------------------------------------------------- |
|
291 // CMccVideoSourceConfigKeyRetriever::StartGuardTimer |
|
292 // ----------------------------------------------------------------------------- |
|
293 // |
|
294 void CMccVideoSourceConfigKeyRetriever::StartGuardTimer() |
|
295 { |
|
296 __V_SOURCESINK_CONTROLL( "CMccVideoSourceConfigKeyRetriever::StartGuardTimer" ) |
|
297 |
|
298 iGuardTimer->Start( |
|
299 iGuardTimerTimeout, TCallBack( GuardTimerExpired, this ) ); |
|
300 } |
|
301 |
|
302 // ----------------------------------------------------------------------------- |
|
303 // CMccVideoSourceConfigKeyRetriever::StopGuardTimer |
|
304 // ----------------------------------------------------------------------------- |
|
305 // |
|
306 void CMccVideoSourceConfigKeyRetriever::StopGuardTimer() |
|
307 { |
|
308 __V_SOURCESINK_CONTROLL( "CMccVideoSourceConfigKeyRetriever::StopGuardTimer" ) |
|
309 |
|
310 iGuardTimer->Stop(); |
|
311 } |
|
312 |
|
313 // ----------------------------------------------------------------------------- |
|
314 // CMccVideoSourceConfigKeyRetriever::GuardTimerExpired |
|
315 // ----------------------------------------------------------------------------- |
|
316 // |
|
317 TInt CMccVideoSourceConfigKeyRetriever::GuardTimerExpired( TAny* aObject ) |
|
318 { |
|
319 __V_SOURCESINK_CONTROLL( "CMccVideoSourceConfigKeyRetriever::GuardTimerExpired" ) |
|
320 |
|
321 CMccVideoSourceConfigKeyRetriever* self = |
|
322 static_cast<CMccVideoSourceConfigKeyRetriever*>( aObject ); |
|
323 if ( self ) |
|
324 { |
|
325 self->StopWaiting(); |
|
326 } |
|
327 |
|
328 __V_SOURCESINK_CONTROLL( "CMccVideoSourceConfigKeyRetriever::GuardTimerExpired, exit" ) |
|
329 |
|
330 return KErrNone; |
|
331 } |
|
332 |
|
333 // End of file |
|
334 |