|
1 /* |
|
2 * Copyright (c) 2007-2009 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: VoIP Audio Services |
|
15 * Implements uplink thread object. |
|
16 * |
|
17 */ |
|
18 |
|
19 #include <IlbcEncoderIntfc.h> |
|
20 #include <G711EncoderIntfc.h> |
|
21 #include <G729EncoderIntfc.h> |
|
22 #include <SpeechEncoderConfig.h> |
|
23 #include "debugtracemacros.h" |
|
24 #include "VoIPSharedData.h" |
|
25 #include "VoIPServerThread.h" |
|
26 |
|
27 // ----------------------------------------------------------------------------- |
|
28 // CVoIPUplinkThread::CVoIPUplinkThread |
|
29 // Standard Constructor |
|
30 // ----------------------------------------------------------------------------- |
|
31 // |
|
32 CVoIPUplinkThread::CVoIPUplinkThread(TSharedData& aData) : |
|
33 iShared(aData) |
|
34 { |
|
35 } |
|
36 |
|
37 // ----------------------------------------------------------------------------- |
|
38 // CVoIPUplinkThread::~CVoIPUplinkThread |
|
39 // Standard Constructor |
|
40 // ----------------------------------------------------------------------------- |
|
41 // |
|
42 CVoIPUplinkThread::~CVoIPUplinkThread() |
|
43 { |
|
44 TRACE_PRN_FN_ENT; |
|
45 |
|
46 Stop(); |
|
47 delete iSpeechEncoderConfig; |
|
48 delete iG711EncoderIntfc; |
|
49 delete iG729EncoderIntfc; |
|
50 delete iIlbcEncoderIntfc; |
|
51 |
|
52 TRACE_PRN_FN_EXT; |
|
53 } |
|
54 |
|
55 // ----------------------------------------------------------------------------- |
|
56 // CVoIPUplinkThread::NewL |
|
57 // Symbian two-phase constructor |
|
58 // ----------------------------------------------------------------------------- |
|
59 // |
|
60 CVoIPUplinkThread* CVoIPUplinkThread::NewL(TSharedData& aData) |
|
61 { |
|
62 CVoIPUplinkThread* self = new (ELeave) CVoIPUplinkThread(aData); |
|
63 CleanupStack::PushL(self); |
|
64 self->ConstructL(); |
|
65 CleanupStack::Pop(self); |
|
66 return self; |
|
67 } |
|
68 |
|
69 // ----------------------------------------------------------------------------- |
|
70 // CVoIPUplinkThread::ConstructL |
|
71 // Part two of Symbian two phase construction |
|
72 // ----------------------------------------------------------------------------- |
|
73 // |
|
74 void CVoIPUplinkThread::ConstructL() |
|
75 { |
|
76 TRACE_PRN_FN_ENT; |
|
77 |
|
78 InitThreadL(); |
|
79 iCodecID = iShared.iCodecSettings.iFourCC; |
|
80 InitMsgQueuesL(KUpLinkQueue, KUpLinkThreadComQueue); |
|
81 |
|
82 iShared.iMutex.Wait(); |
|
83 TRAPD(err, InitDevSoundL(EMMFStateRecording, iShared.iPriority, |
|
84 iShared.iPreference)); |
|
85 iShared.iMutex.Signal(); |
|
86 |
|
87 if (err != KErrNone) |
|
88 { |
|
89 SendCmd(ECmdDnLinkError, err); |
|
90 } |
|
91 iMaxBufLen = DetermineMaxBufferLen(); |
|
92 |
|
93 // Client must set these before querying! |
|
94 iG711CodecMode = CVoIPFormatIntfc::EG711ALaw; |
|
95 iILBCCodecMode = CVoIPFormatIntfc::EiLBC20mSecFrame; |
|
96 |
|
97 TRACE_PRN_FN_EXT; |
|
98 } |
|
99 |
|
100 // ----------------------------------------------------------------------------- |
|
101 // CVoIPUplinkThread::ThreadFunction |
|
102 // Thread Startup function |
|
103 // ----------------------------------------------------------------------------- |
|
104 // |
|
105 TInt CVoIPUplinkThread::ThreadFunction(TAny* aData) |
|
106 { |
|
107 // get a pointer to the shared data object |
|
108 TSharedData& shared = *((TSharedData*) aData); |
|
109 |
|
110 // we can set the sync flag here |
|
111 shared.iMutex.Wait(); |
|
112 |
|
113 // create a cleanup stack |
|
114 CTrapCleanup* cleanupStack = CTrapCleanup::New(); |
|
115 |
|
116 if (!cleanupStack) |
|
117 { |
|
118 return KErrNoMemory; |
|
119 } |
|
120 |
|
121 CVoIPUplinkThread* thread = 0; |
|
122 TRAPD(err, thread = CVoIPUplinkThread::NewL(shared)); |
|
123 if (err != KErrNone) |
|
124 { |
|
125 return err; |
|
126 } |
|
127 |
|
128 shared.iMutex.Signal(); |
|
129 |
|
130 // if we're still here, active scheduler has been constructed |
|
131 // start wait loop which runs until it's time to end the thread |
|
132 CActiveScheduler::Start(); |
|
133 |
|
134 // Termination cleanup |
|
135 delete thread; |
|
136 delete cleanupStack; |
|
137 |
|
138 TRACE_PRN_N(_L("CVoIPUplinkThread::ThreadFunction : Thread CLOSED")); |
|
139 return KErrNone; |
|
140 } |
|
141 |
|
142 // ----------------------------------------------------------------------------- |
|
143 // CVoIPUplinkThread::Start |
|
144 // |
|
145 // ----------------------------------------------------------------------------- |
|
146 // |
|
147 void CVoIPUplinkThread::Start() |
|
148 { |
|
149 TRACE_PRN_FN_ENT; |
|
150 |
|
151 TInt err = KErrNotReady; |
|
152 |
|
153 if (iStatus == EReady) |
|
154 { |
|
155 TRAP(err, iDevSound->RecordInitL()); |
|
156 TRACE_PRN_IF_ERR(err); |
|
157 |
|
158 if (err != KErrNone) |
|
159 { |
|
160 SendCmd(ECmdUpLinkError, err); |
|
161 iStatus = EReady; |
|
162 } |
|
163 #ifdef _DEBUG |
|
164 else |
|
165 { |
|
166 iSamplesRecCount = 0; |
|
167 } |
|
168 #endif |
|
169 } |
|
170 |
|
171 TRACE_PRN_FN_EXT; |
|
172 } |
|
173 |
|
174 // ----------------------------------------------------------------------------- |
|
175 // CVoIPUplinkThread::Stop |
|
176 // |
|
177 // ----------------------------------------------------------------------------- |
|
178 // |
|
179 void CVoIPUplinkThread::Stop() |
|
180 { |
|
181 TRACE_PRN_FN_ENT; |
|
182 |
|
183 if (iStatus == EStreaming) |
|
184 { |
|
185 iDevSound->Stop(); |
|
186 iStatus = EReady; |
|
187 } |
|
188 |
|
189 TRACE_PRN_FN_EXT; |
|
190 } |
|
191 |
|
192 // ----------------------------------------------------------------------------- |
|
193 // CVoIPUplinkThread::InitializeComplete |
|
194 // A callback from the DevSound indicating completion of the initialization. |
|
195 // It will send config data to the D/S and configure the encoder via CI. |
|
196 // If everything goes well, the state of the thread is set EReady. |
|
197 // The initialization completion message is sent back to the main thread. |
|
198 // ----------------------------------------------------------------------------- |
|
199 // |
|
200 void CVoIPUplinkThread::InitializeComplete(TInt aError) |
|
201 { |
|
202 TRACE_PRN_FN_ENT; |
|
203 |
|
204 TInt err = aError; |
|
205 |
|
206 if (err == KErrNone) |
|
207 { |
|
208 TMMFCapabilities conf; |
|
209 conf = iDevSound->Config(); |
|
210 conf.iRate = EMMFSampleRate8000Hz; |
|
211 conf.iChannels = EMMFMono; |
|
212 TRAP(err, iDevSound->SetConfigL(conf)); |
|
213 if (err == KErrNone) |
|
214 { |
|
215 // We are ready to stream even in case of later CI setting failure |
|
216 iStatus = EReady; |
|
217 TInt gain = iDevSound->MaxGain(); |
|
218 iShared.iMutex.Wait(); |
|
219 iShared.iMaxGain = gain; |
|
220 iShared.iMutex.Signal(); |
|
221 } |
|
222 |
|
223 // Init Custom Interface API to the Encoder |
|
224 TRAPD(err0, SetCodecCiL()); |
|
225 if (err0 != KErrNone) |
|
226 { |
|
227 // DEBUG only |
|
228 // Can ignore error - the encoder is not fully configured but |
|
229 // can still run in the default mode. |
|
230 TRACE_PRN_IF_ERR(err0); |
|
231 } |
|
232 } |
|
233 |
|
234 // Notify the main thread |
|
235 SendCmd(ECmdUplinkInitComplete, err); |
|
236 |
|
237 TRACE_PRN_IF_ERR(err); |
|
238 TRACE_PRN_FN_EXT; |
|
239 } |
|
240 |
|
241 // ----------------------------------------------------------------------------- |
|
242 // CVoIPUplinkThread::BufferToBeEmptied |
|
243 // From MDevSoundObserver |
|
244 // ----------------------------------------------------------------------------- |
|
245 // |
|
246 void CVoIPUplinkThread::BufferToBeEmptied(CMMFBuffer* aBuffer) |
|
247 { |
|
248 // TRACE_PRN_N1(_L("SAMPLES-RECORDED [%d]"), iSamplesRecCount++); |
|
249 |
|
250 iDevSoundBufPtr = static_cast<CMMFDataBuffer*> (aBuffer); |
|
251 TDes8& data = iDevSoundBufPtr->Data(); |
|
252 |
|
253 #ifndef __WINSCW__ |
|
254 iBufLen = iDevSoundBufPtr->BufferSize(); |
|
255 #else //__WINSCW__ |
|
256 // Buffer size is always 4kB in WINS (PCM). Since we are testing stub |
|
257 // adaptaions of all other supported codecs, and WINS playback is not |
|
258 // supported anyway, we can throw away generated frames and use only |
|
259 // up to the max length of other codecs just to keep the loopback alive. |
|
260 iBufLen = iMaxBufLen; |
|
261 data.SetLength(iBufLen); |
|
262 #endif //__WINSCW__ |
|
263 |
|
264 TRACE_PRN_N1(_L("VoIP->UPL: BTBE->LEN [%d]"), iBufLen); |
|
265 |
|
266 // Adjust/create RChunk if necessary |
|
267 TInt err = DoChunk(KChunkUPL, iBufLen, iMaxBufLen); |
|
268 |
|
269 if (err != KErrNone) |
|
270 { |
|
271 Stop(); |
|
272 iMsgBuffer.iStatus = err; |
|
273 } |
|
274 else |
|
275 { |
|
276 // Pass buffer parameters to the client |
|
277 iMsgBuffer.iStatus = iChunk.Handle(); |
|
278 iMsgBuffer.iInt = iBufLen; |
|
279 |
|
280 // Copy data over to RChunk |
|
281 TPtr8 dataPtr(iChunk.Base(), iBufLen, iMaxBufLen); |
|
282 dataPtr = data; |
|
283 iStatus = EStreaming; |
|
284 } |
|
285 |
|
286 // Notify client there is buffer ready to be emptied |
|
287 iMsgBuffer.iRequest = ECmdEmptyBuffer; |
|
288 iMsgQueue.Send(iMsgBuffer); |
|
289 } |
|
290 |
|
291 // ----------------------------------------------------------------------------- |
|
292 // CVoIPUplinkThread::BufferEmptied |
|
293 // |
|
294 // ----------------------------------------------------------------------------- |
|
295 // |
|
296 void CVoIPUplinkThread::BufferEmptied() |
|
297 { |
|
298 // TRACE_PRN_N(_L("VoIP->UPL: BE")); |
|
299 |
|
300 iDevSound->RecordData(); |
|
301 } |
|
302 |
|
303 // ----------------------------------------------------------------------------- |
|
304 // CVoIPUplinkThread::RecordError |
|
305 // From MDevSoundObserver |
|
306 // Recording error is send to the main thread. |
|
307 // The state of recorder is rolled back to EReady. |
|
308 // ----------------------------------------------------------------------------- |
|
309 // |
|
310 void CVoIPUplinkThread::RecordError(TInt aError) |
|
311 { |
|
312 TRACE_PRN_IF_ERR(aError); |
|
313 |
|
314 #ifdef _DEBUG |
|
315 iSamplesRecCount = 0; |
|
316 #endif |
|
317 iStatus = EReady; |
|
318 SendCmd(ECmdUpLinkError, aError); |
|
319 } |
|
320 |
|
321 // --------------------------------------------------------------------------- |
|
322 // CVoIPUplinkThread::SetCodecCiL |
|
323 // |
|
324 // --------------------------------------------------------------------------- |
|
325 // |
|
326 void CVoIPUplinkThread::SetCodecCiL() |
|
327 { |
|
328 TRACE_PRN_FN_ENT; |
|
329 |
|
330 switch (iCodecID) |
|
331 { |
|
332 case KMccFourCCIdG711: |
|
333 { |
|
334 if (!iG711EncoderIntfc) |
|
335 { |
|
336 iG711EncoderIntfc = CG711EncoderIntfc::NewL(*iDevSound); |
|
337 } |
|
338 break; |
|
339 } |
|
340 case KMccFourCCIdG729: |
|
341 { |
|
342 if (!iG729EncoderIntfc) |
|
343 { |
|
344 iG729EncoderIntfc = CG729EncoderIntfc::NewL(*iDevSound); |
|
345 } |
|
346 break; |
|
347 } |
|
348 case KMccFourCCIdILBC: |
|
349 { |
|
350 if (!iIlbcEncoderIntfc) |
|
351 { |
|
352 iIlbcEncoderIntfc = CIlbcEncoderIntfc::NewL(*iDevSound); |
|
353 } |
|
354 break; |
|
355 } |
|
356 default: |
|
357 { |
|
358 break; |
|
359 } |
|
360 } |
|
361 |
|
362 if (!iSpeechEncoderConfig && iCodecID != KMMFFourCCCodePCM16) |
|
363 { |
|
364 iSpeechEncoderConfig = CSpeechEncoderConfig::NewL(*iDevSound); |
|
365 } |
|
366 |
|
367 TRACE_PRN_FN_EXT; |
|
368 } |
|
369 |
|
370 // ----------------------------------------------------------------------------- |
|
371 // CVoIPUplinkThread::SetGain |
|
372 // |
|
373 // ----------------------------------------------------------------------------- |
|
374 // |
|
375 void CVoIPUplinkThread::SetGain() |
|
376 { |
|
377 iShared.iMutex.Wait(); |
|
378 TInt gain = iShared.iInt; |
|
379 iShared.iMutex.Signal(); |
|
380 iDevSound->SetGain(gain); |
|
381 TRACE_PRN_N1(_L("VoIP->UPL: SetGain [%d]"), gain); |
|
382 } |
|
383 |
|
384 // ----------------------------------------------------------------------------- |
|
385 // CVoIPUplinkThread::GetGain |
|
386 // |
|
387 // ----------------------------------------------------------------------------- |
|
388 // |
|
389 void CVoIPUplinkThread::GetGain() |
|
390 { |
|
391 TInt gain = iDevSound->Gain(); |
|
392 iShared.iMutex.Wait(); |
|
393 iShared.iInt = gain; |
|
394 iShared.iMutex.Signal(); |
|
395 SendCmd(ECmdGetGainComplete); |
|
396 } |
|
397 |
|
398 // ----------------------------------------------------------------------------- |
|
399 // CVoIPUplinkThread::SetIlbcCodecMode |
|
400 // |
|
401 // ----------------------------------------------------------------------------- |
|
402 // |
|
403 void CVoIPUplinkThread::SetIlbcCodecMode() |
|
404 { |
|
405 TInt err = KErrNotSupported; |
|
406 |
|
407 if (iStatus == EReady) |
|
408 { |
|
409 iShared.iMutex.Wait(); |
|
410 iILBCCodecMode = iShared.iCodecSettings.iILBCCodecMode; |
|
411 iShared.iMutex.Signal(); |
|
412 |
|
413 if (iIlbcEncoderIntfc && iCodecID == KMccFourCCIdILBC) |
|
414 { |
|
415 if (iILBCCodecMode == CVoIPFormatIntfc::EiLBC20mSecFrame) |
|
416 { |
|
417 err = iIlbcEncoderIntfc->SetEncoderMode( |
|
418 CIlbcEncoderIntfc::E20msFrame); |
|
419 TRACE_PRN_0( |
|
420 _L("VoIP->CVoIPUplinkThread[0x%x]::SetIlbcCodecMode [20ms Frame]")); |
|
421 } |
|
422 else |
|
423 { |
|
424 if (iILBCCodecMode == CVoIPFormatIntfc::EiLBC30mSecFrame) |
|
425 { |
|
426 err = iIlbcEncoderIntfc->SetEncoderMode( |
|
427 CIlbcEncoderIntfc::E30msFrame); |
|
428 TRACE_PRN_0( |
|
429 _L("VoIP->CVoIPUplinkThread[0x%x]::SetIlbcCodecMode [30ms Frame]")); |
|
430 } |
|
431 } |
|
432 } |
|
433 } |
|
434 |
|
435 if (err != KErrNone) |
|
436 { |
|
437 SendCmd(ECmdUpLinkError, err); |
|
438 } |
|
439 |
|
440 TRACE_PRN_IF_ERR(err); |
|
441 } |
|
442 |
|
443 // ----------------------------------------------------------------------------- |
|
444 // CVoIPUplinkThread::GetIlbcCodecMode |
|
445 // |
|
446 // ----------------------------------------------------------------------------- |
|
447 // |
|
448 void CVoIPUplinkThread::GetIlbcCodecMode() |
|
449 { |
|
450 // not available through CIs -> return local value |
|
451 iShared.iMutex.Wait(); |
|
452 iShared.iCodecSettings.iILBCCodecMode = iILBCCodecMode; |
|
453 iShared.iMutex.Signal(); |
|
454 SendCmd(ECmdGetIlbcCodecModeComplete); |
|
455 } |
|
456 |
|
457 // ----------------------------------------------------------------------------- |
|
458 // CVoIPUplinkThread::SetG711CodecMode |
|
459 // |
|
460 // ----------------------------------------------------------------------------- |
|
461 // |
|
462 void CVoIPUplinkThread::SetG711CodecMode() |
|
463 { |
|
464 TInt err = KErrNotSupported; |
|
465 |
|
466 if (iStatus == EReady) |
|
467 { |
|
468 iShared.iMutex.Wait(); |
|
469 iG711CodecMode = iShared.iCodecSettings.iG711CodecMode; |
|
470 iShared.iMutex.Signal(); |
|
471 |
|
472 if (iG711EncoderIntfc && iCodecID == KMccFourCCIdG711) |
|
473 { |
|
474 if (iG711CodecMode == CVoIPFormatIntfc::EG711ALaw) |
|
475 { |
|
476 err = iG711EncoderIntfc->SetEncoderMode( |
|
477 CG711EncoderIntfc::EEncALaw); |
|
478 TRACE_PRN_0( |
|
479 _L("VoIP->CVoIPUplinkThread[0x%x]::SetG711CodecMode [ALaw]")); |
|
480 } |
|
481 else |
|
482 { |
|
483 if (iG711CodecMode == CVoIPFormatIntfc::EG711uLaw) |
|
484 { |
|
485 err = iG711EncoderIntfc->SetEncoderMode( |
|
486 CG711EncoderIntfc::EEncULaw); |
|
487 TRACE_PRN_0( |
|
488 _L("VoIP->CVoIPUplinkThread[0x%x]::SetG711CodecMode [uLaw]")); |
|
489 } |
|
490 } |
|
491 } |
|
492 } |
|
493 |
|
494 if (err != KErrNone) |
|
495 { |
|
496 SendCmd(ECmdUpLinkError, err); |
|
497 } |
|
498 |
|
499 TRACE_PRN_IF_ERR(err); |
|
500 } |
|
501 |
|
502 // ----------------------------------------------------------------------------- |
|
503 // CVoIPUplinkThread::GetG711CodecMode |
|
504 // |
|
505 // ----------------------------------------------------------------------------- |
|
506 // |
|
507 void CVoIPUplinkThread::GetG711CodecMode() |
|
508 { |
|
509 // not available through CIs -> return local value |
|
510 iShared.iMutex.Wait(); |
|
511 iShared.iCodecSettings.iG711CodecMode = iG711CodecMode; |
|
512 iShared.iMutex.Signal(); |
|
513 SendCmd(ECmdGetG711CodecModeComplete); |
|
514 } |
|
515 |
|
516 // ----------------------------------------------------------------------------- |
|
517 // CVoIPUplinkThread::GetSupportedBitrates |
|
518 // |
|
519 // ----------------------------------------------------------------------------- |
|
520 // |
|
521 void CVoIPUplinkThread::GetSupportedBitrates() |
|
522 { |
|
523 TInt err = KErrNotSupported; |
|
524 |
|
525 if (iSpeechEncoderConfig) |
|
526 { |
|
527 RArray<TUint> bitrates; |
|
528 err = iSpeechEncoderConfig->GetSupportedBitrates(bitrates); |
|
529 iShared.iMutex.Wait(); |
|
530 iShared.iCodecSettings.iArrBitrates = bitrates; |
|
531 iShared.iMutex.Signal(); |
|
532 } |
|
533 |
|
534 SendCmd(ECmdGetSupportedBitratesComplete, err); |
|
535 TRACE_PRN_IF_ERR(err); |
|
536 } |
|
537 |
|
538 // ----------------------------------------------------------------------------- |
|
539 // CVoIPUplinkThread::SetBitrate |
|
540 // |
|
541 // ----------------------------------------------------------------------------- |
|
542 // |
|
543 void CVoIPUplinkThread::SetBitrate() |
|
544 { |
|
545 TInt err = KErrNotSupported; |
|
546 iShared.iMutex.Wait(); |
|
547 TUint bitrate = iShared.iCodecSettings.iBitrate; |
|
548 iShared.iMutex.Signal(); |
|
549 |
|
550 if (iSpeechEncoderConfig) |
|
551 { |
|
552 err = iSpeechEncoderConfig->SetBitrate(bitrate); |
|
553 TRACE_PRN_N1(_L("VoIP->UPL: SetBitrate [%d]"), bitrate); |
|
554 } |
|
555 |
|
556 if (err != KErrNone) |
|
557 { |
|
558 SendCmd(ECmdUpLinkError, err); |
|
559 } |
|
560 |
|
561 TRACE_PRN_IF_ERR(err); |
|
562 } |
|
563 |
|
564 // ----------------------------------------------------------------------------- |
|
565 // CVoIPUplinkThread::GetBitrate |
|
566 // |
|
567 // ----------------------------------------------------------------------------- |
|
568 // |
|
569 void CVoIPUplinkThread::GetBitrate() |
|
570 { |
|
571 TInt err = KErrNotSupported; |
|
572 TUint bitrate = 0; |
|
573 |
|
574 if (iSpeechEncoderConfig) |
|
575 { |
|
576 err = iSpeechEncoderConfig->GetBitrate(bitrate); |
|
577 } |
|
578 |
|
579 iShared.iMutex.Wait(); |
|
580 iShared.iCodecSettings.iBitrate = bitrate; |
|
581 iShared.iMutex.Signal(); |
|
582 SendCmd(ECmdGetBitrateComplete, err); |
|
583 TRACE_PRN_IF_ERR(err); |
|
584 } |
|
585 |
|
586 // ----------------------------------------------------------------------------- |
|
587 // CVoIPUplinkThread::SetVad |
|
588 // |
|
589 // ----------------------------------------------------------------------------- |
|
590 // |
|
591 void CVoIPUplinkThread::SetVad() |
|
592 { |
|
593 TInt err = KErrNotSupported; |
|
594 iShared.iMutex.Wait(); |
|
595 TBool vad = iShared.iCodecSettings.iVad; |
|
596 iShared.iMutex.Signal(); |
|
597 |
|
598 switch (iCodecID) |
|
599 { |
|
600 case KMccFourCCIdG711: |
|
601 { |
|
602 if (iG711EncoderIntfc) |
|
603 { |
|
604 err = iG711EncoderIntfc->SetVadMode(vad); |
|
605 } |
|
606 break; |
|
607 } |
|
608 case KMccFourCCIdG729: |
|
609 { |
|
610 if (iG729EncoderIntfc) |
|
611 { |
|
612 err = iG729EncoderIntfc->SetVadMode(vad); |
|
613 } |
|
614 break; |
|
615 } |
|
616 case KMccFourCCIdILBC: |
|
617 { |
|
618 if (iIlbcEncoderIntfc) |
|
619 { |
|
620 err = iIlbcEncoderIntfc->SetVadMode(vad); |
|
621 } |
|
622 break; |
|
623 } |
|
624 case KMccFourCCIdAMRNB: |
|
625 { |
|
626 if (iSpeechEncoderConfig) |
|
627 { |
|
628 err = iSpeechEncoderConfig->SetVadMode(vad); |
|
629 } |
|
630 break; |
|
631 } |
|
632 default: |
|
633 { |
|
634 break; //KErrNotSupported |
|
635 } |
|
636 } |
|
637 |
|
638 if (err != KErrNone) |
|
639 { |
|
640 SendCmd(ECmdUpLinkError, err); |
|
641 } |
|
642 |
|
643 TRACE_PRN_IF_ERR(err); |
|
644 } |
|
645 |
|
646 // ----------------------------------------------------------------------------- |
|
647 // CVoIPUplinkThread::GetVad |
|
648 // |
|
649 // ----------------------------------------------------------------------------- |
|
650 // |
|
651 void CVoIPUplinkThread::GetVad() |
|
652 { |
|
653 TInt err = KErrNotSupported; |
|
654 TBool vad = EFalse; |
|
655 |
|
656 switch (iCodecID) |
|
657 { |
|
658 case KMccFourCCIdG711: |
|
659 { |
|
660 if (iG711EncoderIntfc) |
|
661 { |
|
662 err = iG711EncoderIntfc->GetVadMode(vad); |
|
663 } |
|
664 break; |
|
665 } |
|
666 case KMccFourCCIdG729: |
|
667 { |
|
668 if (iG729EncoderIntfc) |
|
669 { |
|
670 err = iG729EncoderIntfc->GetVadMode(vad); |
|
671 } |
|
672 break; |
|
673 } |
|
674 case KMccFourCCIdILBC: |
|
675 { |
|
676 if (iIlbcEncoderIntfc) |
|
677 { |
|
678 err = iIlbcEncoderIntfc->GetVadMode(vad); |
|
679 } |
|
680 break; |
|
681 } |
|
682 case KMccFourCCIdAMRNB: |
|
683 { |
|
684 if (iSpeechEncoderConfig) |
|
685 { |
|
686 err = iSpeechEncoderConfig->GetVadMode(vad); |
|
687 } |
|
688 break; |
|
689 } |
|
690 default: |
|
691 { |
|
692 break; //KErrNotSupported |
|
693 } |
|
694 } |
|
695 |
|
696 iShared.iMutex.Wait(); |
|
697 iShared.iCodecSettings.iVad = vad; |
|
698 iShared.iMutex.Signal(); |
|
699 SendCmd(ECmdGetVadComplete, err); |
|
700 TRACE_PRN_IF_ERR(err); |
|
701 } |
|
702 |
|
703 // ----------------------------------------------------------------------------- |
|
704 // CVoIPUplinkThread::SendCmd |
|
705 // Completes active object's request and sets shared data command value to |
|
706 // one of the user requested commands. |
|
707 // ----------------------------------------------------------------------------- |
|
708 // |
|
709 void CVoIPUplinkThread::SendCmd(TUserCommand aCmd, TInt aError) |
|
710 { |
|
711 iShared.iMutex.Wait(); |
|
712 |
|
713 iShared.iCmd = aCmd; |
|
714 TRequestStatus* status = iShared.iMnThreadStatus; |
|
715 |
|
716 if (status) |
|
717 { |
|
718 if (status->Int() == KRequestPending) |
|
719 { |
|
720 RThread t; |
|
721 TInt err = t.Open(iShared.iMainThreadID); |
|
722 if (err == KErrNone) |
|
723 { |
|
724 t.RequestComplete(status, aError); |
|
725 } |
|
726 } |
|
727 } |
|
728 |
|
729 iShared.iMutex.Signal(); |
|
730 } |
|
731 |
|
732 // ----------------------------------------------------------------------------- |
|
733 // CVoIPUplinkThread |
|
734 // From MQueueHandlerObserverSrv |
|
735 // ----------------------------------------------------------------------------- |
|
736 // |
|
737 void CVoIPUplinkThread::Event(TInt aEventType, TInt /*aError*/) |
|
738 { |
|
739 switch (aEventType) |
|
740 { |
|
741 case ECmdStartUplink: |
|
742 { |
|
743 Start(); |
|
744 break; |
|
745 } |
|
746 case ECmdStopUplink: |
|
747 { |
|
748 if (iStatus == EStreaming) |
|
749 { |
|
750 Stop(); |
|
751 } |
|
752 break; |
|
753 } |
|
754 case ECmdBufferEmptied: |
|
755 { |
|
756 BufferEmptied(); |
|
757 break; |
|
758 } |
|
759 case ECmdGetGain: |
|
760 { |
|
761 GetGain(); |
|
762 break; |
|
763 } |
|
764 case ECmdSetGain: |
|
765 { |
|
766 SetGain(); |
|
767 break; |
|
768 } |
|
769 case ECmdSetIlbcCodecMode: |
|
770 { |
|
771 SetIlbcCodecMode(); |
|
772 break; |
|
773 } |
|
774 case ECmdGetIlbcCodecMode: |
|
775 { |
|
776 GetIlbcCodecMode(); |
|
777 break; |
|
778 } |
|
779 case ECmdSetG711CodecMode: |
|
780 { |
|
781 SetG711CodecMode(); |
|
782 break; |
|
783 } |
|
784 case ECmdGetG711CodecMode: |
|
785 { |
|
786 GetG711CodecMode(); |
|
787 break; |
|
788 } |
|
789 case ECmdGetSupportedBitrates: |
|
790 { |
|
791 GetSupportedBitrates(); |
|
792 break; |
|
793 } |
|
794 case ECmdSetBitrate: |
|
795 { |
|
796 SetBitrate(); |
|
797 break; |
|
798 } |
|
799 case ECmdGetBitrate: |
|
800 { |
|
801 GetBitrate(); |
|
802 break; |
|
803 } |
|
804 case ECmdSetVad: |
|
805 { |
|
806 SetVad(); |
|
807 break; |
|
808 } |
|
809 case ECmdGetVad: |
|
810 { |
|
811 GetVad(); |
|
812 break; |
|
813 } |
|
814 case ECmdTerminateThread: |
|
815 default: |
|
816 { |
|
817 if (iStatus == EStreaming) |
|
818 { |
|
819 Stop(); |
|
820 } |
|
821 // if unknown exception is raised, just exit this thread |
|
822 CActiveScheduler::Stop(); |
|
823 break; |
|
824 } |
|
825 } |
|
826 } |
|
827 |
|
828 // End of file |