|
1 /* |
|
2 * Copyright (c) 2008 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDES |
|
20 #include <f32file.h> |
|
21 #include <BAUTILS.H> |
|
22 |
|
23 #include "CIptvTestVideoCreator.h" |
|
24 #include "VCXTestLog.h" |
|
25 |
|
26 // ----------------------------------------------------------------------------- |
|
27 // NewL |
|
28 // ----------------------------------------------------------------------------- |
|
29 // |
|
30 EXPORT_C CIptvTestVideoCreator* CIptvTestVideoCreator::NewL() |
|
31 { |
|
32 CIptvTestVideoCreator* self; |
|
33 self = new (ELeave) CIptvTestVideoCreator(); |
|
34 CleanupStack::PushL(self); |
|
35 self->ConstructL(); |
|
36 CleanupStack::Pop(self); |
|
37 return self; |
|
38 } |
|
39 |
|
40 // ----------------------------------------------------------------------------- |
|
41 // CIptvTestVideoCreator |
|
42 // ----------------------------------------------------------------------------- |
|
43 // |
|
44 EXPORT_C CIptvTestVideoCreator::~CIptvTestVideoCreator() |
|
45 { |
|
46 delete iFileMan; |
|
47 iFileMan = NULL; |
|
48 iFs.Close(); |
|
49 } |
|
50 |
|
51 // ----------------------------------------------------------------------------- |
|
52 // CIptvTestVideoCreator |
|
53 // ----------------------------------------------------------------------------- |
|
54 // |
|
55 EXPORT_C CIptvTestVideoCreator::CIptvTestVideoCreator() |
|
56 { |
|
57 |
|
58 } |
|
59 |
|
60 // ----------------------------------------------------------------------------- |
|
61 // ConstructL |
|
62 // ----------------------------------------------------------------------------- |
|
63 // |
|
64 EXPORT_C void CIptvTestVideoCreator::ConstructL() |
|
65 { |
|
66 User::LeaveIfError( iFs.Connect() ); |
|
67 iFileMan = CFileMan::NewL( iFs ); |
|
68 } |
|
69 |
|
70 // ----------------------------------------------------------------------------- |
|
71 // CreateVideoL |
|
72 // ----------------------------------------------------------------------------- |
|
73 // |
|
74 EXPORT_C void CIptvTestVideoCreator::CreateVideoL(CIptvTestVideoCreator::TIptvTestVideoType aVideoType, TDesC& aFileName, TInt aSize) |
|
75 { |
|
76 VCXLOGLO1(">>>CIptvTestVideoCreator::CreateVideoL"); |
|
77 |
|
78 // Resolve source filename |
|
79 TBuf<256> srcFileName; |
|
80 |
|
81 GetVideoFile( srcFileName, aVideoType, _L("C") ); |
|
82 if( !BaflUtils::FileExists(iFs, srcFileName) ) |
|
83 { |
|
84 VCXLOGLO2("CIptvTestVideoCreator:: %S does not exist.", &srcFileName); |
|
85 GetVideoFile( srcFileName, aVideoType, _L("E") ); |
|
86 if( !BaflUtils::FileExists(iFs, srcFileName) ) |
|
87 { |
|
88 VCXLOGLO2("CIptvTestVideoCreator:: %S does not exist.", &srcFileName); |
|
89 VCXLOGLO2("CIptvTestVideoCreator:: test video file %S missing! PANIC.", &srcFileName); |
|
90 User::Panic(_L("Video files missing!"), KErrNotFound); |
|
91 } |
|
92 } |
|
93 |
|
94 BaflUtils::EnsurePathExistsL( iFs, aFileName.Left( aFileName.LocateReverse('\\') ) ); |
|
95 |
|
96 BaflUtils::DeleteFile( iFs, aFileName ); |
|
97 |
|
98 VCXLOGLO2("CIptvTestVideoCreator:: aSize = %d", aSize); |
|
99 |
|
100 TInt64 wantedSize( 0 ); |
|
101 |
|
102 // Check the size |
|
103 if( aSize == KVcxTestLargeFile3GB ) { |
|
104 wantedSize = 3000000000; |
|
105 } |
|
106 else { |
|
107 wantedSize = aSize; |
|
108 } |
|
109 |
|
110 //wantedSize = wantedSize == 0 ? wantedSize -1 : wantedSize; |
|
111 |
|
112 VCXLOGLO2("CIptvTestVideoCreator:: Wanted file size: %Ld", wantedSize); |
|
113 |
|
114 // Read source file into memory, won't work on huge files. |
|
115 RFile64 srcFile; |
|
116 VCXLOGLO2("CIptvTestVideoCreator:: Opening %S", &srcFileName); |
|
117 User::LeaveIfError( srcFile.Open( iFs, srcFileName, EFileRead ) ); |
|
118 CleanupClosePushL( srcFile ); |
|
119 |
|
120 TInt64 srcSize(0); |
|
121 VCXLOGLO2("CIptvTestVideoCreator:: Getting size of %S", &srcFileName); |
|
122 User::LeaveIfError( srcFile.Size( srcSize ) ); |
|
123 |
|
124 HBufC8* data = HBufC8::NewL( srcSize ); |
|
125 TPtr8 ptr( data->Des() ); |
|
126 srcFile.Read( ptr, srcSize ); |
|
127 CleanupStack::PopAndDestroy( &srcFile ); |
|
128 |
|
129 CleanupStack::PushL( data ); |
|
130 |
|
131 // Write new file. |
|
132 RFile64 dstFile; |
|
133 VCXLOGLO1("CIptvTestVideoCreator:: Replace"); |
|
134 User::LeaveIfError( dstFile.Replace( iFs, aFileName, EFileWrite ) ); |
|
135 CleanupClosePushL(dstFile); |
|
136 |
|
137 if( wantedSize <= srcSize ) |
|
138 { |
|
139 if( wantedSize == -1 ) |
|
140 { |
|
141 VCXLOGLO2("CIptvTestVideoCreator:: Writing %Ld", srcSize); |
|
142 User::LeaveIfError( dstFile.Write( *data, srcSize ) ); |
|
143 } |
|
144 else |
|
145 { |
|
146 VCXLOGLO2("CIptvTestVideoCreator:: Writing %Ld", wantedSize); |
|
147 User::LeaveIfError( dstFile.Write( *data, wantedSize ) ); |
|
148 } |
|
149 } |
|
150 else |
|
151 { |
|
152 VCXLOGLO2("CIptvTestVideoCreator:: Writing %Ld", srcSize); |
|
153 User::LeaveIfError( dstFile.Write( *data, srcSize ) ); |
|
154 |
|
155 const TInt KIptvTest200Kilos = 1024*200; |
|
156 HBufC8* buff = HBufC8::NewL( KIptvTest200Kilos ); |
|
157 buff->Des().SetLength( KIptvTest200Kilos ); |
|
158 CleanupStack::PushL( buff ); |
|
159 TInt64 bytesToWrite = wantedSize - srcSize; |
|
160 while( bytesToWrite > 0 ) |
|
161 { |
|
162 if( bytesToWrite >= KIptvTest200Kilos ) |
|
163 { |
|
164 bytesToWrite -= KIptvTest200Kilos; |
|
165 User::LeaveIfError( dstFile.Write( *buff ) ); |
|
166 } |
|
167 else |
|
168 { |
|
169 User::LeaveIfError( dstFile.Write( *buff, bytesToWrite ) ); |
|
170 bytesToWrite = 0; |
|
171 } |
|
172 } |
|
173 CleanupStack::PopAndDestroy( buff ); |
|
174 } |
|
175 |
|
176 CleanupStack::PopAndDestroy( &dstFile ); |
|
177 CleanupStack::PopAndDestroy( data ); |
|
178 |
|
179 VCXLOGLO1("<<<CIptvTestVideoCreator::CreateVideoL"); |
|
180 } |
|
181 |
|
182 |
|
183 // ----------------------------------------------------------------------------- |
|
184 // CreateVideosL |
|
185 // ----------------------------------------------------------------------------- |
|
186 // |
|
187 EXPORT_C void CIptvTestVideoCreator::CreateVideosL(CIptvTestVideoCreator::TIptvTestVideoType aVideoType, TDesC& aFileName, TInt aCount, RPointerArray<HBufC>& aFileArray ) |
|
188 { |
|
189 VCXLOGLO1(">>>CIptvTestVideoCreator::CreateVideosL"); |
|
190 |
|
191 // Resolve source filename |
|
192 TBuf<256> srcFileName; |
|
193 |
|
194 GetVideoFile( srcFileName, aVideoType, _L("C") ); |
|
195 |
|
196 if( !BaflUtils::FileExists(iFs, srcFileName) ) |
|
197 { |
|
198 VCXLOGLO2("CIptvTestVideoCreator:: %S does not exist.", &srcFileName); |
|
199 GetVideoFile( srcFileName, aVideoType, _L("E") ); |
|
200 if( !BaflUtils::FileExists(iFs, srcFileName) ) |
|
201 { |
|
202 VCXLOGLO2("CIptvTestVideoCreator:: %S does not exist.", &srcFileName); |
|
203 VCXLOGLO2("CIptvTestVideoCreator:: test video file %S missing! PANIC.", &srcFileName); |
|
204 // Comment next line if you want dummy files to be created. They won't be recognized by MDS. |
|
205 User::Panic(_L("Video files missing!"), KErrNotFound); |
|
206 } |
|
207 } |
|
208 |
|
209 TBool fileExists = BaflUtils::FileExists(iFs, srcFileName); |
|
210 |
|
211 HBufC* newFileName = HBufC::NewL( 256 ); |
|
212 CleanupStack::PushL( newFileName ); |
|
213 |
|
214 newFileName->Des().Copy( aFileName.Left( aFileName.LocateReverse('\\') ) ); |
|
215 BaflUtils::EnsurePathExistsL(iFs, *newFileName); |
|
216 |
|
217 TInt dotPos = aFileName.LocateReverse('.'); |
|
218 |
|
219 for( TInt i = 0; i < aCount; i++ ) |
|
220 { |
|
221 newFileName->Des().Copy( aFileName.Left( dotPos ) ); |
|
222 newFileName->Des().Append( _L("_") ); |
|
223 newFileName->Des().AppendNum( i ); |
|
224 newFileName->Des().Append( aFileName.Right( aFileName.Length() - dotPos ) ); |
|
225 |
|
226 HBufC* fileForClient = newFileName->Des().AllocL(); |
|
227 aFileArray.Append( fileForClient ); |
|
228 |
|
229 if( fileExists ) |
|
230 { |
|
231 User::LeaveIfError( iFileMan->Copy(srcFileName, *newFileName) ); |
|
232 VCXLOGLO2("CIptvTestVideoCreator:: copy file: '%S'", newFileName); |
|
233 } |
|
234 else |
|
235 { |
|
236 VCXLOGLO2("CIptvTestVideoCreator:: new fake file: '%S'", newFileName); |
|
237 RFile file; |
|
238 CleanupClosePushL(file); |
|
239 User::LeaveIfError( file.Replace(iFs, *newFileName, EFileWrite) ); |
|
240 User::LeaveIfError( file.SetSize( 1024*10 ) ); |
|
241 CleanupStack::PopAndDestroy( &file ); |
|
242 } |
|
243 User::After( 100000 ); // Wait tenth of a second. |
|
244 } |
|
245 |
|
246 CleanupStack::PopAndDestroy( newFileName ); |
|
247 |
|
248 VCXLOGLO1("<<<CIptvTestVideoCreator::CreateVideosL"); |
|
249 } |
|
250 |
|
251 // ----------------------------------------------------------------------------- |
|
252 // GetVideoFile |
|
253 // ----------------------------------------------------------------------------- |
|
254 // |
|
255 EXPORT_C void CIptvTestVideoCreator::GetVideoFile( TDes& aFileName, CIptvTestVideoCreator::TIptvTestVideoType aVideoType, const TDesC& aDrive ) |
|
256 { |
|
257 VCXLOGLO1(">>>CIptvTestVideoCreator::GetVideoFile"); |
|
258 aFileName.Copy( aDrive ); |
|
259 |
|
260 _LIT(KIptvTestVideoBasePath, ":\\testing\\data\\"); |
|
261 |
|
262 aFileName.Append( KIptvTestVideoBasePath ); |
|
263 |
|
264 VCXLOGLO2("CIptvTestVideoCreator::GetVideoFile -- using %S", &aFileName); |
|
265 |
|
266 switch (aVideoType) |
|
267 { |
|
268 case CIptvTestVideoCreator::IptvTestVideo3Gp: |
|
269 { |
|
270 aFileName.Append( _L("video_3gp.xxx") ); |
|
271 } |
|
272 break; |
|
273 |
|
274 case CIptvTestVideoCreator::IptvTestVideo3Gp2: |
|
275 { |
|
276 aFileName.Append( _L("video_3gp2.xxx") ); |
|
277 } |
|
278 break; |
|
279 |
|
280 case CIptvTestVideoCreator::IptvTestVideoMp2: |
|
281 { |
|
282 aFileName.Append( _L("video_mp2.xxx") ); |
|
283 } |
|
284 break; |
|
285 |
|
286 case CIptvTestVideoCreator::IptvTestVideoMpeg1: |
|
287 { |
|
288 aFileName.Append( _L("video_mpeg1.xxx") ); |
|
289 } |
|
290 break; |
|
291 |
|
292 case CIptvTestVideoCreator::IptvTestVideoMpeg2: |
|
293 { |
|
294 aFileName.Append( _L("video_mpeg2.xxx") ); |
|
295 } |
|
296 break; |
|
297 |
|
298 case CIptvTestVideoCreator::IptvTestVideoSuperVideoCd: |
|
299 { |
|
300 aFileName.Append( _L("video_supervideocd.xxx") ); |
|
301 } |
|
302 break; |
|
303 |
|
304 case CIptvTestVideoCreator::IptvTestVideoMp3: |
|
305 { |
|
306 aFileName.Append( _L("video_mp3.xxx") ); |
|
307 } |
|
308 break; |
|
309 |
|
310 case CIptvTestVideoCreator::IptvTestVideoAppleMpeg: |
|
311 { |
|
312 aFileName.Append( _L("video_applempeg.xxx") ); |
|
313 } |
|
314 break; |
|
315 |
|
316 case CIptvTestVideoCreator::IptvTestVideoMpeg4: |
|
317 { |
|
318 aFileName.Append( _L("video_mpeg4.xxx") ); |
|
319 } |
|
320 break; |
|
321 |
|
322 case CIptvTestVideoCreator::IptvTestVideoMpegAvc: |
|
323 { |
|
324 aFileName.Append( _L("video_mpegavc.xxx") ); |
|
325 } |
|
326 break; |
|
327 |
|
328 case CIptvTestVideoCreator::IptvTestVideoQuicktime: |
|
329 { |
|
330 aFileName.Append( _L("video_quicktime.xxx") ); |
|
331 } |
|
332 break; |
|
333 |
|
334 case CIptvTestVideoCreator::IptvTestVideoRealVideo: |
|
335 { |
|
336 aFileName.Append( _L("video_realvideo.xxx") ); |
|
337 } |
|
338 break; |
|
339 |
|
340 case CIptvTestVideoCreator::IptvTestVideoAvi: |
|
341 { |
|
342 aFileName.Append( _L("video_avi.xxx") ); |
|
343 } |
|
344 break; |
|
345 |
|
346 case CIptvTestVideoCreator::IptvTestVideoWmv: |
|
347 { |
|
348 aFileName.Append( _L("video_wmv.xxx") ); |
|
349 } |
|
350 break; |
|
351 |
|
352 case CIptvTestVideoCreator::IptvTestVideoAviAC3: |
|
353 { |
|
354 aFileName.Append( _L("video_aviac3.xxx") ); |
|
355 } |
|
356 break; |
|
357 default: |
|
358 User::Panic(_L("IptvMyVideosApiTest: Unknown video type!"), KErrCorrupt); |
|
359 } |
|
360 VCXLOGLO1("<<<CIptvTestVideoCreator::GetVideoFile"); |
|
361 } |
|
362 |
|
363 // End of File |