|
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: Implementation of the Common Recording Engine RTP file base class.* |
|
15 */ |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <ipvideo/CRtpFileBase.h> |
|
22 #include "videoserviceutilsLogger.h" |
|
23 |
|
24 // CONSTANTS |
|
25 const TInt KFirstIntegerPoint( 0 ); |
|
26 const TInt KSecondIntegerPoint( KFirstIntegerPoint + KIntegerBytes ); |
|
27 const TInt KThirdIntegerPoint( KSecondIntegerPoint + KIntegerBytes ); |
|
28 const TInt KFourthIntegerPoint( KThirdIntegerPoint + KIntegerBytes ); |
|
29 const TInt KSeekArrayGranularity( 20 ); |
|
30 |
|
31 // ============================ MEMBER FUNCTIONS =============================== |
|
32 |
|
33 // ----------------------------------------------------------------------------- |
|
34 // CRtpFileBase::CRtpFileBase |
|
35 // C++ default constructor can NOT contain any code, that might leave. |
|
36 // ----------------------------------------------------------------------------- |
|
37 // |
|
38 CRtpFileBase::CRtpFileBase() |
|
39 : CActive( CActive::EPriorityStandard ), |
|
40 iMode( EModeNone ), |
|
41 iThisGroup( KErrNotFound ), |
|
42 iGroupsTotalCount( KErrNotFound ), |
|
43 iFirstSeekAddr( KErrNotFound ), |
|
44 iLastSeekAddr( KErrNotFound ), |
|
45 iGroupTotalLen( KErrNotFound ), |
|
46 iNextGroupPoint( KErrNotFound ), |
|
47 iPrevGroupPoint( KErrNotFound ), |
|
48 iGroupTime( 0 ), |
|
49 iSeekHeaderPoint( KErrNotFound ), |
|
50 iDataPtr( 0, 0 ) |
|
51 { |
|
52 CActiveScheduler::Add( this ); |
|
53 } |
|
54 |
|
55 // ----------------------------------------------------------------------------- |
|
56 // CRtpFileBase::ConstructL |
|
57 // Symbian 2nd phase constructor can leave. |
|
58 // ----------------------------------------------------------------------------- |
|
59 // |
|
60 void CRtpFileBase::ConstructL() |
|
61 { |
|
62 LOG( "CRtpFileBase::ConstructL()" ); |
|
63 |
|
64 iSeekArray = new( ELeave ) CArrayFixFlat<SSeek>( KSeekArrayGranularity ); |
|
65 } |
|
66 |
|
67 // ----------------------------------------------------------------------------- |
|
68 // Destructor |
|
69 // |
|
70 // ----------------------------------------------------------------------------- |
|
71 // |
|
72 CRtpFileBase::~CRtpFileBase() |
|
73 { |
|
74 LOG( "CRtpFileBase::~CRtpFileBase()" ); |
|
75 // Do not call Cancel here, it will cause crashes (DoCancel of inherited |
|
76 // class is never called, instead it jumps to foobar address) |
|
77 iFile.Close(); |
|
78 iFs.Close(); |
|
79 delete iCurrentPath; |
|
80 delete iSeekArray; |
|
81 } |
|
82 |
|
83 // ----------------------------------------------------------------------------- |
|
84 // CRtpFileBase::DeleteTimeShiftFiles |
|
85 // Deletes files used during time shift mode. |
|
86 // ----------------------------------------------------------------------------- |
|
87 // |
|
88 void CRtpFileBase::DeleteTimeShiftFiles( RArray<STimeShiftSeek>& aShiftSeek ) |
|
89 { |
|
90 LOG1( "CRtpFileBase::DeleteTimeShiftFiles(), count: %d", aShiftSeek.Count() ); |
|
91 |
|
92 TInt index( KErrNotFound ); |
|
93 const TInt count( aShiftSeek.Count() ); |
|
94 for ( TInt i( 0 ); i < count; i++ ) |
|
95 { |
|
96 if ( aShiftSeek[i].iNameIndex != index ) |
|
97 { |
|
98 TPath clipPath( KDvrTimeShiftFile ); |
|
99 index = aShiftSeek[i].iNameIndex; |
|
100 clipPath.AppendNum( index ); |
|
101 iFs.Delete( clipPath ); |
|
102 LOG1( "CRtpFileBase::DeleteTimeShiftFiles(), deleted: %S", &clipPath ); |
|
103 } |
|
104 } |
|
105 |
|
106 aShiftSeek.Reset(); |
|
107 } |
|
108 |
|
109 // ----------------------------------------------------------------------------- |
|
110 // CRtpFileBase::WriteSeekHeaderL |
|
111 // Writes seek header of all groups. |
|
112 // ----------------------------------------------------------------------------- |
|
113 // |
|
114 void CRtpFileBase::WriteSeekHeaderL() |
|
115 { |
|
116 User::LeaveIfError( iSeekHeaderPoint ); |
|
117 |
|
118 HBufC8* data = HBufC8::NewLC( KSeekHeaderBytes ); |
|
119 TPtr8 ptr( data->Des() ); |
|
120 |
|
121 HBufC8* bytes = CRtpUtil::MakeBytesLC( iGroupsTotalCount ); |
|
122 ptr.Copy( bytes->Des() ); |
|
123 CleanupStack::PopAndDestroy( bytes ); |
|
124 |
|
125 bytes = CRtpUtil::MakeBytesLC( iFirstSeekAddr ); |
|
126 ptr.Append( bytes->Des() ); |
|
127 CleanupStack::PopAndDestroy( bytes ); |
|
128 |
|
129 bytes = CRtpUtil::MakeBytesLC( iLastSeekAddr ); |
|
130 ptr.Append( bytes->Des() ); |
|
131 CleanupStack::PopAndDestroy( bytes ); |
|
132 |
|
133 User::LeaveIfError( iFile.Write( iSeekHeaderPoint, ptr, KSeekHeaderBytes ) ); |
|
134 CleanupStack::PopAndDestroy( data ); |
|
135 } |
|
136 |
|
137 // ----------------------------------------------------------------------------- |
|
138 // CRtpFileBase::ReadSeekHeaderL |
|
139 // Readss seek header of all groups. |
|
140 // ----------------------------------------------------------------------------- |
|
141 // |
|
142 void CRtpFileBase::ReadSeekHeaderL() |
|
143 { |
|
144 User::LeaveIfError( iSeekHeaderPoint ); |
|
145 |
|
146 HBufC8* bytes = HBufC8::NewLC( KSeekHeaderBytes ); |
|
147 TPtr8 ptr( bytes->Des() ); |
|
148 User::LeaveIfError( iFile.Read( iSeekHeaderPoint, ptr, KSeekHeaderBytes ) ); |
|
149 if ( ptr.Length() < KSeekHeaderBytes ) |
|
150 { |
|
151 LOG( "CRtpFileBase::ReadSeekHeaderL(), Seek Header Corrupted" ); |
|
152 User::Leave( KErrCorrupt ); |
|
153 } |
|
154 |
|
155 iGroupsTotalCount = CRtpUtil::GetValueL( ptr.Mid( KFirstIntegerPoint, |
|
156 KIntegerBytes ) ); |
|
157 User::LeaveIfError( iGroupsTotalCount ); |
|
158 iFirstSeekAddr = CRtpUtil::GetValueL( ptr.Mid( KSecondIntegerPoint, |
|
159 KIntegerBytes ) ); |
|
160 User::LeaveIfError( iFirstSeekAddr ); |
|
161 iLastSeekAddr = CRtpUtil::GetValueL( ptr.Mid( KThirdIntegerPoint, |
|
162 KIntegerBytes ) ); |
|
163 User::LeaveIfError( iLastSeekAddr ); |
|
164 CleanupStack::PopAndDestroy( bytes ); |
|
165 } |
|
166 |
|
167 // ----------------------------------------------------------------------------- |
|
168 // CRtpFileBase::ReadGroupHeaderL |
|
169 // Reads group header. |
|
170 // ----------------------------------------------------------------------------- |
|
171 // |
|
172 void CRtpFileBase::ReadGroupHeaderL() |
|
173 { |
|
174 User::LeaveIfError( iThisGroup ); |
|
175 |
|
176 HBufC8* bytes = HBufC8::NewLC( KGroupHeaderBytes ); |
|
177 TPtr8 ptr( bytes->Des() ); |
|
178 |
|
179 User::LeaveIfError( iFile.Read( iThisGroup, ptr, KGroupHeaderBytes ) ); |
|
180 UpdateGroupHeaderVariablesL( ptr ); |
|
181 |
|
182 CleanupStack::PopAndDestroy( bytes ); |
|
183 } |
|
184 |
|
185 // ----------------------------------------------------------------------------- |
|
186 // CRtpFileBase::UpdateGroupHeaderVariablesL |
|
187 // Updates group header variables from readed data. |
|
188 // ----------------------------------------------------------------------------- |
|
189 // |
|
190 void CRtpFileBase::UpdateGroupHeaderVariablesL( const TDesC8& aDataPtr ) |
|
191 { |
|
192 if ( aDataPtr.Length() < KGroupHeaderBytes ) |
|
193 { |
|
194 LOG( "CRtpFileBase::UpdateGroupHeaderVariablesL(), Group Header Corrupted" ); |
|
195 User::Leave( KErrCorrupt ); |
|
196 } |
|
197 |
|
198 iGroupTotalLen = CRtpUtil::GetValueL( aDataPtr.Mid( KFirstIntegerPoint , |
|
199 KIntegerBytes ) ); |
|
200 User::LeaveIfError( iGroupTotalLen ); |
|
201 iNextGroupPoint = CRtpUtil::GetValueL( aDataPtr.Mid( KSecondIntegerPoint, |
|
202 KIntegerBytes ) ); |
|
203 User::LeaveIfError( iNextGroupPoint ); |
|
204 iPrevGroupPoint = CRtpUtil::GetValueL( aDataPtr.Mid( KThirdIntegerPoint, |
|
205 KIntegerBytes ) ); |
|
206 User::LeaveIfError( iPrevGroupPoint ); |
|
207 iGroupTime = CRtpUtil::GetValueL( aDataPtr.Mid( KFourthIntegerPoint, |
|
208 KIntegerBytes ) ); |
|
209 User::LeaveIfError( iGroupTime ); |
|
210 } |
|
211 |
|
212 // ----------------------------------------------------------------------------- |
|
213 // CRtpFileBase::AppendSeekArrayL |
|
214 // Appends one item to seek array. |
|
215 // ----------------------------------------------------------------------------- |
|
216 // |
|
217 void CRtpFileBase::AppendSeekArrayL( const TUint aTime, const TInt aPoint ) |
|
218 { |
|
219 #ifdef CR_ALL_LOGS |
|
220 LOG2( "CRtpFileBase::AppendSeekArrayL(), aTime: %u, aPoint: %d", |
|
221 aTime, aPoint ); |
|
222 #endif // CR_ALL_LOGS |
|
223 |
|
224 SSeek seek; |
|
225 seek.iTime = aTime; |
|
226 seek.iPoint = aPoint; |
|
227 iSeekArray->AppendL( seek ); |
|
228 } |
|
229 |
|
230 // ----------------------------------------------------------------------------- |
|
231 // CRtpFileBase::SaveSeekArrayL |
|
232 // |
|
233 // ----------------------------------------------------------------------------- |
|
234 // |
|
235 void CRtpFileBase::SaveSeekArrayL() |
|
236 { |
|
237 LOG1( "CRtpFileBase::SaveSeekArrayL(), count: %d", iSeekArray->Count() ); |
|
238 |
|
239 const TInt len( KIntegerBytes + iSeekArray->Count() * 2 * KIntegerBytes ); |
|
240 HBufC8* data = HBufC8::NewLC( len ); |
|
241 TPtr8 ptr( data->Des() ); |
|
242 |
|
243 // Total count |
|
244 HBufC8* bytes = CRtpUtil::MakeBytesLC( iSeekArray->Count() ); |
|
245 ptr.Copy( bytes->Des() ); |
|
246 CleanupStack::PopAndDestroy( bytes ); |
|
247 |
|
248 for ( TInt i( 0 ); i < iSeekArray->Count(); i++ ) |
|
249 { |
|
250 // Time |
|
251 bytes = CRtpUtil::MakeBytesLC( iSeekArray->At( i ).iTime ); |
|
252 ptr.Append( bytes->Des() ); |
|
253 CleanupStack::PopAndDestroy( bytes ); |
|
254 |
|
255 // Point |
|
256 bytes = CRtpUtil::MakeBytesLC( iSeekArray->At( i ).iPoint ); |
|
257 ptr.Append( bytes->Des() ); |
|
258 CleanupStack::PopAndDestroy( bytes ); |
|
259 |
|
260 #ifdef CR_ALL_LOGS |
|
261 LOG3( "CRtpFileBase::SaveSeekArrayL(), ind: %d, time: %u, point: %d", |
|
262 i, iSeekArray->At( i ).iTime, iSeekArray->At( i ).iPoint ); |
|
263 #endif // CR_ALL_LOGS |
|
264 } |
|
265 |
|
266 User::LeaveIfError( iFile.Write( iNextGroupPoint, ptr, len ) ); |
|
267 CleanupStack::PopAndDestroy( data ); |
|
268 } |
|
269 |
|
270 // ----------------------------------------------------------------------------- |
|
271 // CRtpFileBase::ReadSeekArrayL |
|
272 // |
|
273 // ----------------------------------------------------------------------------- |
|
274 // |
|
275 TBool CRtpFileBase::ReadSeekArrayL( const TInt aPoint ) |
|
276 { |
|
277 User::LeaveIfError( aPoint ); |
|
278 HBufC8* bytes = HBufC8::NewLC( KIntegerBytes ); |
|
279 TPtr8 ptr( bytes->Des() ); |
|
280 |
|
281 // Verify read point |
|
282 TInt size( KErrNotFound ); |
|
283 iFile.Size( size ); |
|
284 User::LeaveIfError( ( aPoint > ( size - KIntegerBytes ) ) * KErrCorrupt ); |
|
285 |
|
286 // Total count |
|
287 User::LeaveIfError( iFile.Read( aPoint, ptr, KIntegerBytes ) ); |
|
288 const TInt count( CRtpUtil::GetValueL( ptr ) ); |
|
289 CleanupStack::PopAndDestroy( bytes ); |
|
290 LOG1( "CRtpFileBase::ReadSeekArrayL(), count: %d", count ); |
|
291 |
|
292 // Any point stored? |
|
293 if ( count > 0 ) |
|
294 { |
|
295 // Read array from clip |
|
296 User::LeaveIfError( ( count > ( KMaxTInt / 2 / KIntegerBytes ) ) * KErrCorrupt ); |
|
297 const TInt len( count * 2 * KIntegerBytes ); |
|
298 HBufC8* data = HBufC8::NewLC( len ); |
|
299 ptr.Set( data->Des() ); |
|
300 User::LeaveIfError( iFile.Read( aPoint + KIntegerBytes, ptr, len ) ); |
|
301 |
|
302 // Set seek array |
|
303 for ( TInt i( 0 ); i < count; i++ ) |
|
304 { |
|
305 const TInt next( i * 2 * KIntegerBytes ); |
|
306 if ( ptr.Length() < ( next + ( 2 * KIntegerBytes ) ) ) |
|
307 { |
|
308 LOG( "CRtpFileBase::ReadSeekArrayL(), Seek Array Corrupted" ); |
|
309 User::Leave( KErrCorrupt ); |
|
310 } |
|
311 |
|
312 // Time |
|
313 TUint time( CRtpUtil::GetValueL( ptr.Mid( next, KIntegerBytes ) ) ); |
|
314 // Point |
|
315 TInt point( CRtpUtil::GetValueL( ptr.Mid( next + KIntegerBytes, |
|
316 KIntegerBytes ) ) ); |
|
317 User::LeaveIfError( point ); |
|
318 AppendSeekArrayL( time, point ); |
|
319 #ifdef CR_ALL_LOGS |
|
320 LOG3( "CRtpFileBase::ReadSeekArrayL(), ind: %d, time: %u, point: %d", |
|
321 i, time, point ); |
|
322 #endif // CR_ALL_LOGS |
|
323 } |
|
324 |
|
325 CleanupStack::PopAndDestroy( data ); |
|
326 } |
|
327 |
|
328 return ( count > 0 ); |
|
329 } |
|
330 |
|
331 // ----------------------------------------------------------------------------- |
|
332 // CRtpFileBase::LogVariables |
|
333 // ----------------------------------------------------------------------------- |
|
334 // |
|
335 void CRtpFileBase::LogVariables( const TDesC& aMethod ) |
|
336 { |
|
337 #ifdef CR_ALL_LOGS |
|
338 LOG1( "CRtpFileBase::LogVariables(), Method: %S", &aMethod ); |
|
339 LOG1( "CRtpFileBase::LogVariables(), iMode : %d", iMode ); |
|
340 LOG1( "CRtpFileBase::LogVariables(), GTC : %d", iGroupsTotalCount ); |
|
341 LOG1( "CRtpFileBase::LogVariables(), FSA : %d", iFirstSeekAddr ); |
|
342 LOG1( "CRtpFileBase::LogVariables(), LSA : %d", iLastSeekAddr ); |
|
343 LOG1( "CRtpFileBase::LogVariables(), This : %d", iThisGroup ); |
|
344 LOG1( "CRtpFileBase::LogVariables(), GTL : %d", iGroupTotalLen ); |
|
345 LOG1( "CRtpFileBase::LogVariables(), NGP : %d", iNextGroupPoint ); |
|
346 LOG1( "CRtpFileBase::LogVariables(), PGP : %d", iPrevGroupPoint ); |
|
347 LOG1( "CRtpFileBase::LogVariables(), GTime : %u", iGroupTime ); |
|
348 #else // CR_ALL_LOGS |
|
349 ( void )aMethod; |
|
350 #endif // CR_ALL_LOGS |
|
351 } |
|
352 |
|
353 // End of File |
|
354 |