|
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 // USER |
|
20 #include "musenglivesession.h" |
|
21 #include "musunittesting.h" |
|
22 #include "musengmceutils.h" |
|
23 #include "musenglogger.h" |
|
24 #include "mussessionproperties.h" |
|
25 #include "musenglivevideoplayer.h" |
|
26 |
|
27 // SYSTEM |
|
28 #include <lcsessionobserver.h> |
|
29 #include <mcemanager.h> |
|
30 #include <mcecamerasource.h> |
|
31 #include <mcevideostream.h> |
|
32 #include <mcertpsink.h> |
|
33 #include <mcedisplaysink.h> |
|
34 #include <mcefilesink.h> |
|
35 #include <mcesession.h> |
|
36 #include <mcevideocodec.h> |
|
37 #include <mceh263codec.h> |
|
38 #include <mceavccodec.h> |
|
39 |
|
40 |
|
41 // ----------------------------------------------------------------------------- |
|
42 // |
|
43 // ----------------------------------------------------------------------------- |
|
44 // |
|
45 CMusEngLiveSession* CMusEngLiveSession::NewL() |
|
46 { |
|
47 CMusEngLiveSession* self = new( ELeave )CMusEngLiveSession(); |
|
48 CleanupStack::PushL( self ); |
|
49 self->ConstructL(); |
|
50 CleanupStack::Pop( self ); |
|
51 return self; |
|
52 } |
|
53 |
|
54 // ----------------------------------------------------------------------------- |
|
55 // |
|
56 // ----------------------------------------------------------------------------- |
|
57 // |
|
58 CMusEngLiveSession::CMusEngLiveSession() |
|
59 : CMusEngMceOutSession() |
|
60 { |
|
61 } |
|
62 |
|
63 // ----------------------------------------------------------------------------- |
|
64 // |
|
65 // ----------------------------------------------------------------------------- |
|
66 // |
|
67 void CMusEngLiveSession::ConstructL() |
|
68 { |
|
69 MUS_LOG( "mus: [ENGINE] -> CMusEngLiveSession::ConstructL()" ) |
|
70 |
|
71 iCameraHandler.ReadCameraUsageKeyL(); |
|
72 CMusEngMceOutSession::ConstructL(); |
|
73 |
|
74 iLiveVideoPlayer = |
|
75 CMusEngLiveVideoPlayer::NewL( *this, iCameraHandler, *this ); |
|
76 |
|
77 MUS_LOG( "mus: [ENGINE] <- CMusEngLiveSession::ConstructL()" ) |
|
78 } |
|
79 |
|
80 // ----------------------------------------------------------------------------- |
|
81 // |
|
82 // ----------------------------------------------------------------------------- |
|
83 // |
|
84 CMusEngLiveSession::~CMusEngLiveSession() |
|
85 { |
|
86 MUS_LOG( "mus: [ENGINE] -> CMusEngLiveSession::~CMusEngLiveSession()" ) |
|
87 delete iLiveVideoPlayer; |
|
88 MUS_LOG( "mus: [ENGINE] <- CMusEngLiveSession::~CMusEngLiveSession()" ) |
|
89 } |
|
90 |
|
91 // ----------------------------------------------------------------------------- |
|
92 // From MLcSession |
|
93 // ----------------------------------------------------------------------------- |
|
94 // |
|
95 MLcVideoPlayer* CMusEngLiveSession::LocalVideoPlayer() |
|
96 { |
|
97 return iLiveVideoPlayer; |
|
98 } |
|
99 |
|
100 // ----------------------------------------------------------------------------- |
|
101 // |
|
102 // ----------------------------------------------------------------------------- |
|
103 // |
|
104 void CMusEngLiveSession::CompleteSessionStructureL( |
|
105 CMceStreamBundle& /*aLocalBundle*/ ) |
|
106 { |
|
107 MUS_LOG( "mus: [ENGINE] -> CMusEngLiveSession::CompleteSessionStructureL()" ) |
|
108 |
|
109 __ASSERT_ALWAYS( iSession, User::Leave( KErrNotReady ) ); |
|
110 |
|
111 iCameraHandler.SetSession( iSession ); |
|
112 |
|
113 // Create outgoing video stream |
|
114 CMceVideoStream* videoStream = CMceVideoStream::NewLC(); |
|
115 |
|
116 CMceRtpSink* rtpsink = CMceRtpSink::NewLC(); |
|
117 videoStream->AddSinkL( rtpsink ); |
|
118 CleanupStack::Pop( rtpsink ); |
|
119 |
|
120 CMceCameraSource* camera = CMceCameraSource::NewLC( *iManager ); |
|
121 camera->DisableL(); // Start session in pause mode. |
|
122 |
|
123 iCameraHandler.InitializeL( *camera ); |
|
124 |
|
125 videoStream->SetSourceL( camera ); |
|
126 CleanupStack::Pop( camera ); |
|
127 |
|
128 iSession->AddStreamL( videoStream ); |
|
129 CleanupStack::Pop( videoStream ); |
|
130 |
|
131 // Construct recording stream if needed |
|
132 if ( iLiveVideoPlayer->LcFileName().Length() > 0 ) |
|
133 { |
|
134 CMceVideoStream* streamForRecording = CMceVideoStream::NewLC(); |
|
135 |
|
136 CMceFileSink* fileSink = |
|
137 CMceFileSink::NewLC( iLiveVideoPlayer->LcFileName() ); |
|
138 fileSink->DisableL(); // Start in not recording mode |
|
139 streamForRecording->AddSinkL( fileSink ); |
|
140 CleanupStack::Pop( fileSink ); |
|
141 |
|
142 streamForRecording->SetSourceL( camera ); |
|
143 iSession->AddStreamL( streamForRecording ); |
|
144 CleanupStack::Pop( streamForRecording ); |
|
145 } |
|
146 |
|
147 iLiveVideoPlayer->SetMceSession( iSession ); |
|
148 |
|
149 MUS_LOG( "mus: [ENGINE] <- CMusEngLiveSession::CompleteSessionStructureL()" ) |
|
150 } |
|
151 |
|
152 // ----------------------------------------------------------------------------- |
|
153 // Sets video codec attributes |
|
154 // ----------------------------------------------------------------------------- |
|
155 // |
|
156 void CMusEngLiveSession::AdjustVideoCodecL( CMceVideoCodec& aVideoCodec, |
|
157 TMceSourceType aSourceType ) |
|
158 { |
|
159 MUS_LOG( "mus: [ENGINE] -> CMusEngLiveSession::AdjustVideoCodecL()" ) |
|
160 |
|
161 CMusEngMceOutSession::AdjustVideoCodecL( aVideoCodec, aSourceType ); |
|
162 |
|
163 // Starting with 80Kbps will give better quality than starting with |
|
164 // 64kbps.And if network behaves bad than anyhow we will drop down or |
|
165 // if network is good guy than we climp up to 128. |
|
166 // Esp in operator variance. No constant defined in MCE so defining |
|
167 // one here. |
|
168 const TInt KMushInitialBitrate = 80000; |
|
169 MUS_LOG1( "mus: [ENGINE] - Intial bit rate set to %d",KMushInitialBitrate); |
|
170 User::LeaveIfError( aVideoCodec.SetBitrate( KMushInitialBitrate ) ); |
|
171 |
|
172 if ( aVideoCodec.SdpName() == KMceSDPNameH263() || |
|
173 aVideoCodec.SdpName() == KMceSDPNameH2632000() ) |
|
174 { |
|
175 // Set H.263 codec to allow all bitrates, set maximum to level 45 and |
|
176 // start using level 10 and let the rate control raise it if possible |
|
177 // Label:H263 |
|
178 User::LeaveIfError( aVideoCodec.SetAllowedBitrates( |
|
179 KMceAllowedH263BitrateAll ) ); |
|
180 aVideoCodec.SetMaxBitrateL( KMceH263Level45Bitrate ); |
|
181 } |
|
182 else if ( aVideoCodec.SdpName() == KMceSDPNameH264() ) |
|
183 { |
|
184 User::LeaveIfError( aVideoCodec.SetAllowedBitrates( |
|
185 KMceAvcCodecProfileIdBaseline | |
|
186 KMceAvcCodecProfileIopConstraintSet | |
|
187 KMceAvcBitrateLevel1b ) ); |
|
188 } |
|
189 else |
|
190 { |
|
191 // NOP |
|
192 } |
|
193 |
|
194 MUS_LOG( "mus: [ENGINE] <- CMusEngLiveSession::AdjustVideoCodecL()" ) |
|
195 } |
|
196 |
|
197 // ----------------------------------------------------------------------------- |
|
198 // |
|
199 // ----------------------------------------------------------------------------- |
|
200 // |
|
201 void CMusEngLiveSession::AdjustAudioCodecL( CMceAudioCodec& aAudioCodec ) |
|
202 { |
|
203 MUS_LOG( "mus: [ENGINE] -> CMusEngLiveSession::AdjustAudioCodecL()" ) |
|
204 |
|
205 CMusEngMceOutSession::AdjustAudioCodecL( aAudioCodec ); |
|
206 |
|
207 MUS_LOG( "mus: [ENGINE] <- CMusEngLiveSession::AdjustAudioCodecL()" ) |
|
208 } |
|
209 |
|
210 // ----------------------------------------------------------------------------- |
|
211 // |
|
212 // ----------------------------------------------------------------------------- |
|
213 // |
|
214 void CMusEngLiveSession::DoCodecSelectionL( CMceVideoStream& aVideoStream ) |
|
215 { |
|
216 MUS_LOG( "mus: [ENGINE] -> CMusEngLiveSession::DoCodecSelectionL()" ) |
|
217 |
|
218 CMusEngMceSession::DoCodecSelectionL( aVideoStream ); |
|
219 |
|
220 if ( iVideoCodecList && !IsH264Supported() ) |
|
221 { |
|
222 // We know that recipient doesn't support AVC, so we do not offer it |
|
223 const RPointerArray<CMceVideoCodec>& codecs = aVideoStream.Codecs(); |
|
224 |
|
225 for ( TInt codecIndex = 0; codecIndex < codecs.Count(); ++codecIndex ) |
|
226 { |
|
227 if ( codecs[codecIndex]->SdpName() == KMceSDPNameH264() ) |
|
228 { |
|
229 aVideoStream.RemoveCodecL( *codecs[codecIndex] ); |
|
230 // Since succesfull removal of a codec has changed the |
|
231 // indexing, we have to reset the index |
|
232 codecIndex = 0; |
|
233 } |
|
234 } |
|
235 } |
|
236 |
|
237 MUS_LOG( "mus: [ENGINE] <- CMusEngLiveSession::DoCodecSelectionL()" ) |
|
238 } |
|
239 |
|
240 // ----------------------------------------------------------------------------- |
|
241 // |
|
242 // ----------------------------------------------------------------------------- |
|
243 // |
|
244 void CMusEngLiveSession::StreamStateChanged( CMceMediaStream& aStream, |
|
245 CMceMediaSink& aSink ) |
|
246 { |
|
247 MUS_LOG( "mus: [ENGINE] -> CMusEngLiveSession::StreamStateChanged( sink )" ) |
|
248 |
|
249 if ( !iSession ) |
|
250 { |
|
251 return; |
|
252 } |
|
253 |
|
254 MUS_ENG_LOG_STREAM_STATE( aStream ) |
|
255 |
|
256 CMceVideoStream* recordingStream = |
|
257 MusEngMceUtils::GetRecordingStream( *iSession ); |
|
258 |
|
259 if ( recordingStream && |
|
260 recordingStream == &aStream && |
|
261 aStream.State() == CMceMediaStream::ENoResources && |
|
262 aSink.IsEnabled() == EFalse ) |
|
263 { |
|
264 InformObserverAboutSessionFailure( MLcSession::EDiskFull ); |
|
265 } |
|
266 else |
|
267 { |
|
268 // Cannot handle, forward to a base class |
|
269 CMusEngMceSession::StreamStateChanged( aStream, aSink ); |
|
270 } |
|
271 |
|
272 MUS_LOG( "mus: [ENGINE] <- CMusEngLiveSession::StreamStateChanged( sink )" ) |
|
273 } |