1 /* |
|
2 * Copyright (c) 2007 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 the License "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: Class that reads packets from a .rtp clip for testing purposes.* |
|
15 */ |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "CCRNullSource.h" |
|
22 #include <ipvideo/CRtpClipHandler.h> |
|
23 #include "CCRPacketBuffer.h" |
|
24 #include "CRtpTimer.h" |
|
25 #include "videoserviceutilsLogger.h" |
|
26 |
|
27 // CONSTANTS |
|
28 const TInt KGroupsCountPoint( 0 ); |
|
29 const TInt KBufferThesholdCount( 20 ); |
|
30 |
|
31 // ============================ MEMBER FUNCTIONS =============================== |
|
32 |
|
33 // ----------------------------------------------------------------------------- |
|
34 // CCRNullSource::NewL |
|
35 // Two-phased constructor. |
|
36 // ----------------------------------------------------------------------------- |
|
37 // |
|
38 CCRNullSource* CCRNullSource::NewL( |
|
39 const TDesC& aClipName, |
|
40 MCRStreamObserver& aSessionObs, |
|
41 CCRStreamingSession& aOwningSession ) |
|
42 { |
|
43 CCRNullSource* self = new( ELeave ) |
|
44 CCRNullSource( aSessionObs, aOwningSession ); |
|
45 CleanupStack::PushL( self ); |
|
46 self->ConstructL( aClipName ); |
|
47 CleanupStack::Pop(); |
|
48 return self; |
|
49 } |
|
50 |
|
51 // ----------------------------------------------------------------------------- |
|
52 // CCRNullSource::CCRNullSource |
|
53 // C++ default constructor can NOT contain any code, that might leave. |
|
54 // ----------------------------------------------------------------------------- |
|
55 // |
|
56 CCRNullSource::CCRNullSource( |
|
57 MCRStreamObserver& aSessionObs, |
|
58 CCRStreamingSession& aOwningSession ) |
|
59 : CCRPacketSourceBase( aOwningSession, CCRStreamingSession::ECRNullSourceId ), |
|
60 iSessionObs( aSessionObs ), |
|
61 iGroupTime( KMaxTUint ) |
|
62 { |
|
63 // None |
|
64 } |
|
65 |
|
66 // ----------------------------------------------------------------------------- |
|
67 // CCRNullSource::ConstructL |
|
68 // Symbian 2nd phase constructor can leave. |
|
69 // ----------------------------------------------------------------------------- |
|
70 // |
|
71 void CCRNullSource::ConstructL( const TDesC& aClipName ) |
|
72 { |
|
73 LOG1( "CCRNullSource::ConstructL() in, aClipName: %S", &aClipName ); |
|
74 |
|
75 iClipHandler = CRtpClipHandler::NewL(); |
|
76 iClipHandler->RegisterReadObserver( this ); |
|
77 |
|
78 // Start playback |
|
79 SCRRtpPlayParams params; |
|
80 params.iFileName = aClipName; |
|
81 iClipHandler->StartPlayBackL( params ); |
|
82 |
|
83 LOG( "CCRNullSource::ConstructL() out" ); |
|
84 } |
|
85 |
|
86 // ----------------------------------------------------------------------------- |
|
87 // CCRNullSource::~CCRNullSource |
|
88 // Destructor. |
|
89 // ----------------------------------------------------------------------------- |
|
90 // |
|
91 CCRNullSource::~CCRNullSource() |
|
92 { |
|
93 LOG( "CCRNullSource::~CCRNullSource()" ); |
|
94 |
|
95 if ( iClipHandler ) |
|
96 { |
|
97 iClipHandler->StopPlayBack( KErrNone, 0 ); |
|
98 } |
|
99 |
|
100 delete iClipHandler; iClipHandler = NULL; |
|
101 delete iFlowTimer; |
|
102 delete iSdp; |
|
103 } |
|
104 |
|
105 // ----------------------------------------------------------------------------- |
|
106 // CCRNullSource::GetSdp |
|
107 // ----------------------------------------------------------------------------- |
|
108 // |
|
109 TInt CCRNullSource::GetSdp( TPtrC8& aSdp ) |
|
110 { |
|
111 if ( iSdp ) |
|
112 { |
|
113 aSdp.Set( iSdp->Des() ); |
|
114 return KErrNone; |
|
115 } |
|
116 |
|
117 return KErrNotReady; |
|
118 } |
|
119 |
|
120 // ----------------------------------------------------------------------------- |
|
121 // CCRNullSource::SetBuffer |
|
122 // ----------------------------------------------------------------------------- |
|
123 // |
|
124 void CCRNullSource::SetBuffer( CCRPacketBuffer* aBuffer ) |
|
125 { |
|
126 iBuffer = aBuffer; |
|
127 iBuffer->ContinousStream( EFalse ); |
|
128 iBuffer->MoreComing( EFalse ); |
|
129 } |
|
130 |
|
131 // ----------------------------------------------------------------------------- |
|
132 // CCRNullSource::PostActionL |
|
133 // ----------------------------------------------------------------------------- |
|
134 // |
|
135 void CCRNullSource::PostActionL() |
|
136 { |
|
137 LOG( "CCRNullSource::PostActionL(), SDP will be handled !" ); |
|
138 |
|
139 // SDP |
|
140 iSdp = iClipHandler->GetClipSdpL(); |
|
141 |
|
142 // Notify that SDP available |
|
143 iSessionObs.StatusChanged( MCRPacketSource::ERtpStateSdpAvailable ); |
|
144 delete iSdp; iSdp = NULL; |
|
145 } |
|
146 |
|
147 // ----------------------------------------------------------------------------- |
|
148 // CCRNullSource::Restore |
|
149 // ----------------------------------------------------------------------------- |
|
150 // |
|
151 void CCRNullSource::Restore() |
|
152 { |
|
153 delete iFlowTimer; iFlowTimer = NULL; |
|
154 const TInt err( NextClipGroup() ); |
|
155 if ( err ) |
|
156 { |
|
157 LOG1( "CCRNullSource::Restore(), NextClipGroup() err: %d", err ); |
|
158 iSessionObs.StatusChanged( MCRPacketSource::ERtpStateClosing ); |
|
159 } |
|
160 } |
|
161 |
|
162 // ----------------------------------------------------------------------------- |
|
163 // CCRNullSource::Play |
|
164 // |
|
165 // ----------------------------------------------------------------------------- |
|
166 // |
|
167 TInt CCRNullSource::Play( const TReal& aStartPos, const TReal& aEndPos ) |
|
168 { |
|
169 LOG2( "CCRNullSource::Play(), aStartPos: %f, aEndPos: %f", |
|
170 aStartPos, aEndPos ); |
|
171 |
|
172 if ( aStartPos == KRealZero && aEndPos == KRealZero ) |
|
173 { |
|
174 Restore(); |
|
175 } |
|
176 |
|
177 return KErrNone; |
|
178 } |
|
179 |
|
180 |
|
181 // ----------------------------------------------------------------------------- |
|
182 // CCRNullSource::Stop |
|
183 // ----------------------------------------------------------------------------- |
|
184 // |
|
185 TInt CCRNullSource::Stop() |
|
186 { |
|
187 iClipHandler->StopPlayBack( KErrNone, 0 ); |
|
188 return KErrNone; |
|
189 } |
|
190 |
|
191 // ----------------------------------------------------------------------------- |
|
192 // CCRNullSource::GetPosition |
|
193 // |
|
194 // ----------------------------------------------------------------------------- |
|
195 // |
|
196 TInt CCRNullSource::GetPosition( TInt64& aPosition, TInt64& aDuration ) |
|
197 { |
|
198 if ( iBuffer ) |
|
199 { |
|
200 if ( iGroupTime != KMaxTUint ) |
|
201 { |
|
202 aPosition += TInt64( iGroupTime ) * KSiKilo; |
|
203 } |
|
204 |
|
205 aDuration = TInt64( iClipHandler->GetCurrentLength() ) * KSiKilo; |
|
206 #ifdef CR_ALL_LOGS |
|
207 LOG2( "CCRNullSource::GetPosition(), aPosition: %u, aDuration: %u", |
|
208 ( TUint )( aPosition / KSiKilo ), ( TUint )( aDuration / KSiKilo ) ); |
|
209 #endif // CR_ALL_LOGS |
|
210 return KErrNone; |
|
211 } |
|
212 |
|
213 return KErrCompletion; |
|
214 } |
|
215 |
|
216 // ----------------------------------------------------------------------------- |
|
217 // CCRNullSource::GroupReadedL |
|
218 // Adds packets to the buffer when finished asyncronous group reading. |
|
219 // ----------------------------------------------------------------------------- |
|
220 // |
|
221 void CCRNullSource::GroupReadedL( |
|
222 const TDesC8& aGroup, |
|
223 const TUint aGroupTime, |
|
224 const TBool aLastGroup ) |
|
225 { |
|
226 // Group time |
|
227 if ( iGroupTime == KMaxTUint ) |
|
228 { |
|
229 iGroupTime = aGroupTime; |
|
230 } |
|
231 |
|
232 // Data valid? |
|
233 TInt point( KGroupsCountPoint + KPacketsCountBytes ); |
|
234 const TInt total( aGroup.Length() ); |
|
235 if ( point > total ) |
|
236 { |
|
237 LOG( "CCRNullSource::GroupReadedL(), No Packets Total Count !" ); |
|
238 User::Leave( KErrCorrupt ); |
|
239 } |
|
240 |
|
241 // Packets total count (PTC) |
|
242 const TInt totalCount( CRtpUtil::GetValueL( |
|
243 aGroup.Mid( KGroupsCountPoint, KPacketsCountBytes ) ) ); |
|
244 if ( totalCount > 0 ) |
|
245 { |
|
246 iBuffer->ContinousStream( ETrue ); |
|
247 } |
|
248 |
|
249 // Loop all packets |
|
250 for ( TInt i( 0 ); i < totalCount; i++ ) |
|
251 { |
|
252 // Corrupted? |
|
253 if ( ( point + KPacketSizeBytesLen ) > total ) |
|
254 { |
|
255 LOG( "CCRNullSource::GroupReadedL(), No Packets Size !" ); |
|
256 User::Leave( KErrCorrupt ); |
|
257 } |
|
258 |
|
259 // Packet total Size (PTS) |
|
260 TInt packetSize( CRtpUtil::GetValueL( |
|
261 aGroup.Mid( point, KPacketSizeBytesLen ) ) ); |
|
262 // Corrupted? |
|
263 if ( packetSize <= 0 || ( point + packetSize ) > total ) |
|
264 { |
|
265 LOG( "CCRNullSource::GroupReadedL(), No Packets Payload !" ); |
|
266 User::Leave( KErrCorrupt ); |
|
267 } |
|
268 |
|
269 // Packet type |
|
270 point += KPacketSizeBytesLen; |
|
271 const MRtpFileWriteObserver::TRtpType type( |
|
272 ( MRtpFileWriteObserver::TRtpType )( aGroup[point] ) ); |
|
273 point += KPacketTypeBytesLen; |
|
274 packetSize -= ( KPacketSizeBytesLen + KPacketTypeBytesLen ); |
|
275 |
|
276 // Insert packet to the buffer |
|
277 const TPtrC8 packet( aGroup.Mid( point, packetSize ) ); |
|
278 |
|
279 #ifdef CR_ALL_LOGS |
|
280 const TUint8* pointer( &packet[2] ); |
|
281 TInt seq( BigEndian::Get16( pointer ) ); |
|
282 LOG3( "CCRNullSource::GroupReadedL(), type: %d, packet: %d, seq: %d", |
|
283 type, packet.Length(), seq ); |
|
284 //RFileLogger::WriteFormat( _L( "livetv" ), _L( "play.log" ), EFileLoggingModeAppend, |
|
285 // _L( "GroupReadedL(), type: %d, packet: %d, seq: %d" ), type, packet.Length(), seq ); |
|
286 #endif // CR_ALL_LOGS |
|
287 |
|
288 MCRPacketSource::TCRPacketStreamId stream( MCRPacketSource::EStreamIdCount ); |
|
289 if ( TypeToStream( type, stream ) ) |
|
290 { |
|
291 // Last packet in group? |
|
292 if ( i >= ( totalCount - 1 ) ) |
|
293 { |
|
294 iBuffer->ContinousStream( EFalse ); |
|
295 if ( aLastGroup && stream != MCRPacketSource::EStreamEndTag ) |
|
296 { |
|
297 LOG( "CCRNullSource::GroupReadedL(), Misses last group from clip !" ); |
|
298 stream = MCRPacketSource::EStreamEndTag; |
|
299 } |
|
300 } |
|
301 |
|
302 // Packet to buffer |
|
303 iBuffer->AddPacket( stream, packet ); |
|
304 } |
|
305 |
|
306 point+= packetSize; |
|
307 } |
|
308 |
|
309 if ( !iFlowTimer ) |
|
310 { |
|
311 iFlowTimer = CRtpTimer::NewL( *this ); |
|
312 iFlowTimer->After( KNormalRecGroupLength * KSiKilo ); |
|
313 } |
|
314 } |
|
315 |
|
316 // ----------------------------------------------------------------------------- |
|
317 // CCRNullSource::ReadStatus |
|
318 // ----------------------------------------------------------------------------- |
|
319 // |
|
320 void CCRNullSource::ReadStatus( TInt aStatus ) |
|
321 { |
|
322 LOG1( "CCRNullSource::ReadStatus(), aStatus: %d", aStatus ); |
|
323 |
|
324 switch ( aStatus ) |
|
325 { |
|
326 case MRtpFileReadObserver::ERtpTimeShifTEnd: |
|
327 break; |
|
328 |
|
329 default: |
|
330 iSessionObs.StatusChanged( MCRPacketSource::ERtpStateClosing ); |
|
331 break; |
|
332 } |
|
333 } |
|
334 |
|
335 // ----------------------------------------------------------------------------- |
|
336 // CCRNullSource::TimerEventL |
|
337 // Internal timer call this when triggered. |
|
338 // ----------------------------------------------------------------------------- |
|
339 // |
|
340 void CCRNullSource::TimerEventL() |
|
341 { |
|
342 User::LeaveIfError( NextClipGroup() ); |
|
343 delete iFlowTimer; iFlowTimer = NULL; |
|
344 } |
|
345 |
|
346 // ----------------------------------------------------------------------------- |
|
347 // CCRNullSource::TimerError |
|
348 // Internal timer call this when TimerEventL() leaves. |
|
349 // ----------------------------------------------------------------------------- |
|
350 // |
|
351 void CCRNullSource::TimerError( const TInt aError ) |
|
352 { |
|
353 LOG1( "CCRNullSource::TimerError(), TimerEventL() leaved: %d", aError ); |
|
354 ( void )aError; // Prevent compiler warning |
|
355 |
|
356 delete iFlowTimer; iFlowTimer = NULL; |
|
357 iSessionObs.StatusChanged( MCRPacketSource::ERtpStateClosing ); |
|
358 } |
|
359 |
|
360 // ----------------------------------------------------------------------------- |
|
361 // CCRNullSource::NextClipGroup |
|
362 // ----------------------------------------------------------------------------- |
|
363 // |
|
364 TInt CCRNullSource::NextClipGroup() |
|
365 { |
|
366 if ( iBuffer && iClipHandler ) |
|
367 { |
|
368 if ( iBuffer->PacketsMinCount() < KBufferThesholdCount ) |
|
369 { |
|
370 TRAPD( err, iClipHandler->NextClipGroupL() ); |
|
371 return err; |
|
372 } |
|
373 |
|
374 return KErrNone; |
|
375 } |
|
376 |
|
377 return KErrNotReady; |
|
378 } |
|
379 |
|
380 // ----------------------------------------------------------------------------- |
|
381 // CCRNullSource::TypeToStream |
|
382 // ----------------------------------------------------------------------------- |
|
383 // |
|
384 TBool CCRNullSource::TypeToStream( |
|
385 const MRtpFileWriteObserver::TRtpType& aType, |
|
386 MCRPacketSource::TCRPacketStreamId& aStream ) |
|
387 { |
|
388 switch ( aType ) |
|
389 { |
|
390 case MRtpFileWriteObserver::ERtpAudio: |
|
391 aStream = MCRPacketSource::EAudioStream; |
|
392 break; |
|
393 |
|
394 case MRtpFileWriteObserver::ERtcpAudio: |
|
395 aStream = MCRPacketSource::EAudioControlStream; |
|
396 break; |
|
397 |
|
398 case MRtpFileWriteObserver::ERtpVideo: |
|
399 aStream = MCRPacketSource::EVideoStream; |
|
400 break; |
|
401 |
|
402 case MRtpFileWriteObserver::ERtcpVideo: |
|
403 aStream = MCRPacketSource::EVideoControlStream; |
|
404 break; |
|
405 |
|
406 case MRtpFileWriteObserver::ERtpSubTitle: |
|
407 aStream = MCRPacketSource::ESubTitleStream; |
|
408 break; |
|
409 |
|
410 case MRtpFileWriteObserver::ERtcpSubTitle: |
|
411 aStream = MCRPacketSource::ESubTitleControlStream; |
|
412 break; |
|
413 |
|
414 case MRtpFileWriteObserver::ERtpClipPause: |
|
415 LOG( "CCRNullSource::TypeToStream(), ERtpClipPause" ); |
|
416 aStream = MCRPacketSource::EDisContinousStream; |
|
417 break; |
|
418 |
|
419 case MRtpFileWriteObserver::ERtpClipEnd: |
|
420 LOG( "CCRNullSource::TypeToStream(), ERtpClipEnd" ); |
|
421 aStream = MCRPacketSource::EStreamEndTag; |
|
422 break; |
|
423 |
|
424 default: |
|
425 LOG1( "CCRNullSource::TypeToStream(), Default case, aType: %d", |
|
426 aType ); |
|
427 return EFalse; |
|
428 } |
|
429 |
|
430 return ETrue; |
|
431 } |
|
432 |
|
433 // End of File |
|