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