|
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: Implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include "MCEConstants.h" |
|
21 #include "TCmdAddAudioStream.h" |
|
22 #include "CTcMCEContext.h" |
|
23 |
|
24 #include <badesca.h> |
|
25 #include <MceInSession.h> |
|
26 #include <MCEAudioStream.h> |
|
27 #include <MCEMicSource.h> |
|
28 #include <MceRtpSink.h> |
|
29 #include <MceRtpSource.h> |
|
30 #include <MCESpeakerSink.h> |
|
31 #include <MCEAudioCodec.h> |
|
32 #include <MCEAMRCodec.h> |
|
33 |
|
34 #include <mcefilesource.h> |
|
35 void TCmdAddAudioStream::ExecuteL() |
|
36 { |
|
37 |
|
38 // ---------- Setup -------------------------------------------------------- |
|
39 |
|
40 // Get session |
|
41 CMceSession* session = reinterpret_cast<CMceSession*> |
|
42 (GetObjectForIdL(KSessionId, ETrue)); |
|
43 |
|
44 // Get existing stream |
|
45 CMceMediaStream* mainStream = reinterpret_cast<CMceMediaStream*> |
|
46 (GetObjectForIdL(KStreamId, EFalse)); |
|
47 |
|
48 TBool suppressRtcp = ExtractBooleanL( KParamSuppressRtcp, EFalse ); |
|
49 |
|
50 //source path for audiofile |
|
51 TPtrC8 pathAudioFile = ExtractTextL( KParamAudioFileSource, EFalse ); |
|
52 |
|
53 //get path for media file sink |
|
54 TPtrC8 mediaFileSink = ExtractTextL( KParamMediaFileSink, EFalse ); |
|
55 // ---------- Execution ---------------------------------------------------- |
|
56 |
|
57 CMceAudioStream* audioStream = CMceAudioStream::NewLC(); |
|
58 |
|
59 |
|
60 // Add source |
|
61 TPtrC8 source = ExtractTextL( KParamSource, EFalse ); |
|
62 if (source == KValueSourceRTP ) |
|
63 { |
|
64 CMceRtpSource* rtpSource = CMceRtpSource::NewLC(); |
|
65 audioStream->SetSourceL(rtpSource); |
|
66 CleanupStack::Pop(rtpSource); |
|
67 } |
|
68 else if (source == KValueSourceMic ) |
|
69 { |
|
70 CMceMicSource* mic = CMceMicSource::NewLC(); |
|
71 audioStream->SetSourceL(mic); |
|
72 CleanupStack::Pop(mic); |
|
73 } |
|
74 else if (pathAudioFile.Compare( KNullDesC8 ) != 0) |
|
75 { |
|
76 // If source path was defined use the file audio specified in path |
|
77 iSessionHelper.SetMediaFileSourceL( iContext.MCEManager(), *audioStream, pathAudioFile ); |
|
78 } |
|
79 else |
|
80 { |
|
81 if( mediaFileSink.Compare( KNullDesC8 ) == 0 ) |
|
82 User::Leave( KErrNotSupported ); |
|
83 } |
|
84 |
|
85 |
|
86 // Add sinks |
|
87 CDesC8Array* sinks = ExtractArrayL( KParamSinks, EFalse ); |
|
88 |
|
89 if ( sinks ) |
|
90 { |
|
91 CleanupStack::PushL( sinks ); |
|
92 for ( TInt i = 0; i < sinks->Count(); i++ ) |
|
93 { |
|
94 if ( (*sinks)[i] == KValueSinkRTP ) |
|
95 { |
|
96 //CMceRtpSink* rtpSink = CMceRtpSink::NewLC(); |
|
97 //enable all RtpSink with RTCP |
|
98 CMceRtpSink* rtpSink = CMceRtpSink::NewL(suppressRtcp); |
|
99 CleanupStack::PushL(rtpSink); |
|
100 audioStream->AddSinkL(rtpSink); |
|
101 CleanupStack::Pop(rtpSink); |
|
102 } |
|
103 else if ( (*sinks)[i] == KValueSinkSpeaker ) |
|
104 { |
|
105 CMceSpeakerSink* speaker = CMceSpeakerSink::NewLC(); |
|
106 audioStream->AddSinkL(speaker); |
|
107 CleanupStack::Pop(speaker); |
|
108 } |
|
109 else if ( (*sinks)[i] == KValueSinkFile ) |
|
110 { |
|
111 const RPointerArray<CMceMediaStream>& streams = session->Streams(); |
|
112 for ( TInt i = 0; i < streams.Count(); ++i ) |
|
113 { |
|
114 CMceMediaStream* tmpStream; |
|
115 tmpStream = streams[i]; |
|
116 if ( tmpStream->Type() == KMceAudio ) |
|
117 { |
|
118 //use the same source which was used for outgoing audio stream |
|
119 if( tmpStream->Source()->Type() != KMceRTPSource ) |
|
120 { |
|
121 audioStream->SetSourceL( tmpStream->Source() ); |
|
122 } |
|
123 else |
|
124 { |
|
125 if(tmpStream->BoundStream()) |
|
126 if( tmpStream->BoundStreamL().Source()->Type() != KMceRTPSource ) |
|
127 audioStream->SetSourceL(tmpStream->BoundStreamL().Source()); |
|
128 } |
|
129 break; |
|
130 } |
|
131 } |
|
132 if( mediaFileSink.Compare( KNullDesC8 ) != 0 ) |
|
133 { |
|
134 iSessionHelper.SetMediaFileSinkL(*audioStream, mediaFileSink); |
|
135 } |
|
136 else |
|
137 { |
|
138 iSessionHelper.SetMediaFileSinkL(*audioStream, TPtrC8( KTestAudioFileName )); |
|
139 } |
|
140 session->AddStreamL(audioStream); |
|
141 } |
|
142 else |
|
143 { |
|
144 User::Leave( KErrNotSupported ); |
|
145 } |
|
146 } |
|
147 CleanupStack::PopAndDestroy( sinks ); |
|
148 } |
|
149 |
|
150 |
|
151 // Modify codecs |
|
152 CDesC8Array* codecs = ExtractArrayL( KParamCodecs, EFalse ); |
|
153 |
|
154 if ( codecs ) |
|
155 { |
|
156 CleanupStack::PushL( codecs ); |
|
157 if ( codecs->Count() > 0) |
|
158 { |
|
159 const RPointerArray<CMceAudioCodec>& streamCodecs = |
|
160 audioStream->Codecs(); |
|
161 |
|
162 if ( (*codecs)[0] == KValueCodecNone ) |
|
163 { |
|
164 // Remove all codecs from stream |
|
165 for (TInt i = 0; i < streamCodecs.Count(); i++ ) |
|
166 { |
|
167 // No implementation yet in MMCE |
|
168 audioStream->RemoveCodecL( *(streamCodecs[i]) ); |
|
169 } |
|
170 } |
|
171 |
|
172 if ( (*codecs)[0] != KValueCodecNone && |
|
173 (*codecs)[0] != KValueCodecAll ) |
|
174 { |
|
175 for (TInt i = 0; i < codecs->Count(); i++ ) |
|
176 { |
|
177 audioStream->AddCodecL( |
|
178 GetAudioCodecCloneL( (*codecs)[i] ) ); |
|
179 } |
|
180 |
|
181 } |
|
182 } |
|
183 CleanupStack::PopAndDestroy( codecs ); |
|
184 } |
|
185 |
|
186 // Add streams |
|
187 if (mainStream) |
|
188 { |
|
189 mainStream->BindL( audioStream ); |
|
190 //if there are no codecs in the stream already, all the codecs will be |
|
191 //added to stream by mce. |
|
192 //Note: streams needs to be bound before adding stream to session |
|
193 session->AddStreamL( mainStream ); |
|
194 } |
|
195 else |
|
196 { |
|
197 //NOOP |
|
198 } |
|
199 |
|
200 CleanupStack::Pop( audioStream ); |
|
201 |
|
202 // ---------- Response creation -------------------------------------------- |
|
203 |
|
204 AddIdResponseL(KSessionId, session); // uses CleanupStack internally |
|
205 AddIdResponseL(KStreamId, *audioStream); |
|
206 |
|
207 } |
|
208 |
|
209 TBool TCmdAddAudioStream::Match( const TTcIdentifier& aId ) |
|
210 { |
|
211 return TTcMceCommandBase::Match( aId, _L8("AddAudioStream") ); |
|
212 } |
|
213 |
|
214 TTcCommandBase* TCmdAddAudioStream::CreateL( MTcTestContext& aContext ) |
|
215 { |
|
216 return new( ELeave ) TCmdAddAudioStream( aContext ); |
|
217 } |
|
218 |
|
219 |
|
220 CMceAudioCodec* TCmdAddAudioStream::GetAudioCodecCloneL( const TDesC8& aParamCodecName ) |
|
221 { |
|
222 |
|
223 const RPointerArray<const CMceAudioCodec>& managerAudioCodecs = |
|
224 iContext.MCEManager().SupportedAudioCodecs(); |
|
225 for ( TInt i = 0; i < managerAudioCodecs.Count(); i++ ) |
|
226 { |
|
227 const CMceAudioCodec* managerAudioCodec = managerAudioCodecs[i]; |
|
228 |
|
229 if ( managerAudioCodec->SdpName() == aParamCodecName ) |
|
230 { |
|
231 return managerAudioCodec->CloneL(); |
|
232 } |
|
233 |
|
234 } |
|
235 |
|
236 // If the requested codec is not supported |
|
237 User::Leave( KErrNotSupported ); |
|
238 return NULL; // To keep compiler happy |
|
239 } |