|
1 /* |
|
2 * Copyright (c) 2010 Ixonos Plc. |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the "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 * Ixonos Plc |
|
14 * |
|
15 * Description: |
|
16 * Implementation for size estimate. |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 // Include Files |
|
22 |
|
23 #include "SizeEstimate.h" |
|
24 #include "movieprocessorimpl.h" |
|
25 #include "AudSong.h" |
|
26 #include "VedMovieImp.h" |
|
27 #include "VedVideoClipInfoImp.h" |
|
28 #include "VedVideoClipGenerator.h" |
|
29 #include "vedaudiosettings.h" |
|
30 |
|
31 |
|
32 |
|
33 // An assertion macro wrapper to clean up the code a bit |
|
34 #define VPASSERT(x) __ASSERT_DEBUG(x, User::Panic(_L("CSizeEstimate"), CMovieProcessorImpl::EInvalidInternalState)) |
|
35 |
|
36 #ifdef _DEBUG |
|
37 #include <e32svr.h> |
|
38 #define PRINT(x) RDebug::Print x; |
|
39 #else |
|
40 #define PRINT(x) |
|
41 #endif |
|
42 |
|
43 |
|
44 // ================= MEMBER FUNCTIONS ======================= |
|
45 |
|
46 // ----------------------------------------------------------------------------- |
|
47 // CSizeEstimate::NewL |
|
48 // Two-phased constructor. |
|
49 // ----------------------------------------------------------------------------- |
|
50 // |
|
51 CSizeEstimate* CSizeEstimate::NewL(CMovieProcessorImpl* aProcessor) |
|
52 { |
|
53 CSizeEstimate* self = NewLC(aProcessor); |
|
54 CleanupStack::Pop(self); |
|
55 return self; |
|
56 } |
|
57 |
|
58 CSizeEstimate* CSizeEstimate::NewLC(CMovieProcessorImpl* aProcessor) |
|
59 { |
|
60 CSizeEstimate* self = new (ELeave) CSizeEstimate(aProcessor); |
|
61 CleanupStack::PushL(self); |
|
62 self->ConstructL(); |
|
63 return self; |
|
64 } |
|
65 |
|
66 // ----------------------------------------------------------------------------- |
|
67 // CSizeEstimate::CSizeEstimate |
|
68 // C++ default constructor can NOT contain any code, that |
|
69 // might leave. |
|
70 // ----------------------------------------------------------------------------- |
|
71 // |
|
72 CSizeEstimate::CSizeEstimate(CMovieProcessorImpl* aProcessor) |
|
73 { |
|
74 iProcessor = aProcessor; |
|
75 } |
|
76 |
|
77 // ----------------------------------------------------------------------------- |
|
78 // CSizeEstimate::~CSizeEstimate |
|
79 // Destructor. |
|
80 // ----------------------------------------------------------------------------- |
|
81 // |
|
82 CSizeEstimate::~CSizeEstimate() |
|
83 { |
|
84 } |
|
85 |
|
86 // ----------------------------------------------------------------------------- |
|
87 // CSizeEstimate::ConstructL |
|
88 // Symbian 2nd phase constructor can leave. |
|
89 // ----------------------------------------------------------------------------- |
|
90 // |
|
91 void CSizeEstimate::ConstructL() |
|
92 { |
|
93 } |
|
94 |
|
95 // ----------------------------------------------------------------------------- |
|
96 // CSizeEstimate::GetMovieSizeEstimateL |
|
97 // Calculates file size estimate |
|
98 // (other items were commented in a header). |
|
99 // ----------------------------------------------------------------------------- |
|
100 // |
|
101 TInt CSizeEstimate::GetMovieSizeEstimateL(const CVedMovie* aMovie, TInt& aFileSize) |
|
102 { |
|
103 TInt i = 0; |
|
104 TInt j = 0; |
|
105 |
|
106 TInt videoDataSize = 0; |
|
107 TInt audioDataSize = 0; |
|
108 TInt video3gpSize = 0; |
|
109 TInt audio3gpSize = 0; |
|
110 TInt numberOfVideoFrames = 0; |
|
111 |
|
112 const CVedMovieImp* movie = reinterpret_cast<const CVedMovieImp *>(aMovie); |
|
113 |
|
114 TInt movieBitrate = movie->VideoStandardBitrate(); |
|
115 if (movieBitrate < KSELowBitrateLimit) |
|
116 { |
|
117 // Adjust low bit rates to slightly higher |
|
118 movieBitrate += KSELowBitrateIncrement; |
|
119 } |
|
120 |
|
121 TInt numberOfVideoClips = movie->VideoClipCount(); |
|
122 |
|
123 // Calculate video data size from all clips |
|
124 for (i = 0; i < numberOfVideoClips; i++) |
|
125 { |
|
126 CVedVideoClip* vedClip = movie->VideoClip(i); |
|
127 TInt videoClipSize = 0; |
|
128 |
|
129 // Get the number of video frames in the clip |
|
130 TInt videoFramesInClip = 0; |
|
131 if (vedClip->Info()->Class() == EVedVideoClipClassGenerated) |
|
132 { |
|
133 videoFramesInClip = vedClip->Info()->Generator()->VideoFrameCount(); |
|
134 } |
|
135 else |
|
136 { |
|
137 videoFramesInClip = vedClip->Info()->VideoFrameCount(); |
|
138 } |
|
139 |
|
140 if (videoFramesInClip <= 0) |
|
141 { |
|
142 // No video frames in clip, check next one |
|
143 continue; |
|
144 } |
|
145 |
|
146 if (vedClip->Info()->Class() == EVedVideoClipClassGenerated) |
|
147 { |
|
148 TInt startTransitionFrames = 0; |
|
149 TInt endTransitionFrames = 0; |
|
150 |
|
151 // Get the number of transition frames in the clip |
|
152 GetTransitionFrames(movie, i, startTransitionFrames, endTransitionFrames); |
|
153 |
|
154 // Calculate the size of the transition frames and add to video clip size |
|
155 TInt transitionLength = (TInt) (1000000.0 / (TReal) movie->MaximumFramerate()) * (startTransitionFrames + endTransitionFrames); |
|
156 videoClipSize += (transitionLength * movieBitrate) / 8 / 1000000; |
|
157 |
|
158 // Calculate the size of the non-transition frames and add to video clip size |
|
159 TInt nonTransitionFrames = videoFramesInClip - startTransitionFrames - endTransitionFrames; |
|
160 |
|
161 if (nonTransitionFrames > 0) |
|
162 { |
|
163 // The first one is intra and the rest are inter frames |
|
164 videoClipSize += GetGeneratedFrameSize(movie, ETrue); |
|
165 videoClipSize += GetGeneratedFrameSize(movie, EFalse) * (nonTransitionFrames - 1); |
|
166 } |
|
167 |
|
168 // Add clip size to video data size |
|
169 videoDataSize += videoClipSize; |
|
170 numberOfVideoFrames += videoFramesInClip; |
|
171 |
|
172 // All done for this clip, go to next one |
|
173 continue; |
|
174 } |
|
175 |
|
176 // Calculate the frame rate of the source clip |
|
177 TReal videoClipFramerate = 1.0; |
|
178 if (vedClip->Info()->Duration().Int64() != 0) |
|
179 { |
|
180 videoClipFramerate = (TReal) videoFramesInClip * 1000000.0 / |
|
181 I64REAL(vedClip->Info()->Duration().Int64()); |
|
182 } |
|
183 |
|
184 if (vedClip->Info()->Resolution() == movie->Resolution() && |
|
185 vedClip->Info()->VideoType() == movie->VideoType() && |
|
186 videoClipFramerate < (TReal) movie->MaximumFramerate() + 0.2) |
|
187 { |
|
188 // Clip is not transcoded => calculate the clip size using the frame sizes of the original clip |
|
189 TInt64 frameTime = 0; |
|
190 TInt64 videoClipCutInTime = vedClip->CutInTime().Int64(); |
|
191 TInt64 videoClipCutOutTime = vedClip->CutOutTime().Int64(); |
|
192 |
|
193 for (j = 0; j < videoFramesInClip; j++) |
|
194 { |
|
195 frameTime = vedClip->Info()->VideoFrameStartTimeL(j).Int64(); |
|
196 |
|
197 if (frameTime < videoClipCutInTime) |
|
198 { |
|
199 continue; // Frame is before cut in position => check next one |
|
200 } |
|
201 else if (frameTime >= videoClipCutOutTime) |
|
202 { |
|
203 break; // Cut out position reached => no need to check frames anymore |
|
204 } |
|
205 |
|
206 // Add frame size to video clip size |
|
207 videoClipSize += vedClip->Info()->VideoFrameSizeL(j); |
|
208 numberOfVideoFrames++; |
|
209 } |
|
210 |
|
211 // Check if color effect is in use |
|
212 if (vedClip->ColorEffect() != EVedColorEffectNone) |
|
213 { |
|
214 // Color tone effects decreases the size of the frames slightly |
|
215 videoClipSize -= (TInt) ((TReal) videoClipSize * KSEBWReductionFactor); |
|
216 } |
|
217 } |
|
218 else // Clip is transcoded |
|
219 { |
|
220 TInt estimatedBitrate = movieBitrate; |
|
221 |
|
222 // If we are transcoding a low quality clip to high quality (e.g. QCIF to VGA) |
|
223 if (movieBitrate >= KSEHighBitrateLimit && |
|
224 movie->Resolution().iWidth > vedClip->Info()->Resolution().iWidth * 3 && |
|
225 videoClipFramerate < (TReal) movie->MaximumFramerate() * 0.5 + 0.2) |
|
226 { |
|
227 // Halve the estimated bit rate if the source frame rate is |
|
228 // roughly less than half of the maximum frame rate |
|
229 estimatedBitrate = estimatedBitrate >> 1; |
|
230 } |
|
231 |
|
232 // Clip frame rate can be decreased if necessary but not increased |
|
233 TReal estimatedFramerate = Min(videoClipFramerate, (TReal) movie->MaximumFramerate()); |
|
234 |
|
235 // Calculate the clip length |
|
236 TInt64 videoClipLength = vedClip->CutOutTime().Int64() - vedClip->CutInTime().Int64(); |
|
237 |
|
238 // Calculate clip size |
|
239 videoClipSize = I64INT((videoClipLength * (TInt64) estimatedBitrate) / 8 / 1000000); |
|
240 |
|
241 // Calculate the number of frames included between cut in and cut out |
|
242 numberOfVideoFrames += (TInt) (I64REAL(videoClipLength * estimatedFramerate) / 1000000.0); |
|
243 } |
|
244 |
|
245 // Add clip size to video data size |
|
246 videoDataSize += videoClipSize; |
|
247 } |
|
248 |
|
249 // Calculate video 3gp size |
|
250 video3gpSize = GetVideo3gpSizePerFrame(numberOfVideoFrames) * numberOfVideoFrames; |
|
251 |
|
252 // Check if there's any audio |
|
253 if (movie->AudioType() != EVedAudioTypeNoAudio) |
|
254 { |
|
255 // Calculate audio data size |
|
256 CAudSong* song = ((CVedMovieImp*)aMovie)->Song(); |
|
257 audioDataSize = song->GetFrameSizeEstimateL(TTimeIntervalMicroSeconds(0), movie->Duration()); |
|
258 |
|
259 if (audioDataSize > 0) |
|
260 { |
|
261 // Calculate audio 3gp size |
|
262 TReal numberOfAudioFrames = I64REAL(aMovie->Duration().Int64() / song->GetFrameDurationMicro()); |
|
263 TReal numberOfAudioSamples = numberOfAudioFrames / (TReal) iProcessor->GetAudioFramesInSample(); |
|
264 |
|
265 audio3gpSize = (TInt) (GetAudio3gpSizePerSample(numberOfAudioSamples) * numberOfAudioSamples); |
|
266 } |
|
267 } |
|
268 |
|
269 // Calculate final estimated file size |
|
270 aFileSize = videoDataSize + audioDataSize + video3gpSize + audio3gpSize + KSEFixedSize; |
|
271 return KErrNone; |
|
272 } |
|
273 |
|
274 |
|
275 // ----------------------------------------------------------------------------- |
|
276 // CSizeEstimate::GetMovieSizeEstimateForMMSL |
|
277 // Calculates file size estimate for MMS use |
|
278 // (other items were commented in a header). |
|
279 // ----------------------------------------------------------------------------- |
|
280 // |
|
281 TInt CSizeEstimate::GetMovieSizeEstimateForMMSL(const CVedMovie* aMovie, TInt aTargetSize, |
|
282 TTimeIntervalMicroSeconds aStartTime, |
|
283 TTimeIntervalMicroSeconds& aEndTime) |
|
284 { |
|
285 TInt i = 0; |
|
286 TInt j = 0; |
|
287 |
|
288 TInt videoDataSize = 0; |
|
289 TInt audioDataSize = 0; |
|
290 TInt video3gpSize = 0; |
|
291 TInt audio3gpSize = 0; |
|
292 TInt numberOfVideoFrames = 0; |
|
293 TReal numberOfAudioSamples = 0.0; |
|
294 TInt64 currentTime = aStartTime.Int64(); |
|
295 |
|
296 CVedVideoClip* vedClip = 0; |
|
297 CAudSong* song = ((CVedMovieImp*)aMovie)->Song(); |
|
298 const CVedMovieImp* movie = reinterpret_cast<const CVedMovieImp *>(aMovie); |
|
299 |
|
300 TReal audioDurationToSamplesFactor = 1.0 / (I64REAL(song->GetFrameDurationMicro()) * (TReal) iProcessor->GetAudioFramesInSample()); |
|
301 |
|
302 TInt movieBitrate = movie->VideoStandardBitrate(); |
|
303 if (movieBitrate < KSELowBitrateLimit) |
|
304 { |
|
305 // Adjust low bit rates to slightly higher |
|
306 movieBitrate += KSELowBitrateIncrement; |
|
307 } |
|
308 |
|
309 TInt numberOfVideoClips = movie->VideoClipCount(); |
|
310 |
|
311 // Find first clip included in the output |
|
312 TInt startClipNumber = 0; |
|
313 for (i = 1; i < numberOfVideoClips; i++, startClipNumber++) |
|
314 { |
|
315 vedClip = movie->VideoClip(i); |
|
316 |
|
317 if (aStartTime < vedClip->StartTime()) |
|
318 { |
|
319 break; |
|
320 } |
|
321 } |
|
322 |
|
323 // Go through all the clips |
|
324 for (i = startClipNumber; i < numberOfVideoClips; i++) |
|
325 { |
|
326 vedClip = movie->VideoClip(i); |
|
327 |
|
328 // Get the number of video frames in the clip |
|
329 TInt videoFramesInClip = 0; |
|
330 if (vedClip->Info()->Class() == EVedVideoClipClassGenerated) |
|
331 { |
|
332 videoFramesInClip = vedClip->Info()->Generator()->VideoFrameCount(); |
|
333 } |
|
334 else |
|
335 { |
|
336 videoFramesInClip = vedClip->Info()->VideoFrameCount(); |
|
337 } |
|
338 |
|
339 if (videoFramesInClip <= 0) |
|
340 { |
|
341 // No video frames in clip, check next clip |
|
342 continue; |
|
343 } |
|
344 |
|
345 // Calculate the frame rate of the source clip |
|
346 TReal videoClipFramerate = 1.0; |
|
347 if (vedClip->Info()->Duration().Int64() != 0) |
|
348 { |
|
349 videoClipFramerate = (TReal) videoFramesInClip * 1000000.0 / |
|
350 I64REAL(vedClip->Info()->Duration().Int64()); |
|
351 } |
|
352 |
|
353 TInt videoFrameSize = 0; |
|
354 TInt64 frameTime = 0; |
|
355 TInt64 frameDuration = 0; |
|
356 TInt64 videoClipCutInTime = vedClip->CutInTime().Int64(); |
|
357 TInt64 videoClipCutOutTime = vedClip->CutOutTime().Int64(); |
|
358 currentTime = vedClip->StartTime().Int64(); |
|
359 |
|
360 TInt startTransitionFrames = 0; |
|
361 TInt endTransitionFrames = 0; |
|
362 |
|
363 // Check if clip needs to be transcoded |
|
364 TBool clipIsTranscoded = EFalse; |
|
365 if (vedClip->Info()->Class() == EVedVideoClipClassFile) |
|
366 { |
|
367 if (!(vedClip->Info()->Resolution() == movie->Resolution() && |
|
368 vedClip->Info()->VideoType() == movie->VideoType() && |
|
369 videoClipFramerate < (TReal) movie->MaximumFramerate() + 0.2)) |
|
370 { |
|
371 clipIsTranscoded = ETrue; |
|
372 } |
|
373 } |
|
374 else |
|
375 { |
|
376 // Get the number of transition frames in the clip |
|
377 GetTransitionFrames(movie, i, startTransitionFrames, endTransitionFrames); |
|
378 } |
|
379 |
|
380 TInt estimatedBitrate = movieBitrate; |
|
381 |
|
382 // If we are transcoding a low quality clip to high quality (e.g. QCIF to VGA) |
|
383 if (movieBitrate >= KSEHighBitrateLimit && |
|
384 movie->Resolution().iWidth > vedClip->Info()->Resolution().iWidth * 3 && |
|
385 videoClipFramerate < (TReal) movie->MaximumFramerate() * 0.5 + 0.2) |
|
386 { |
|
387 // Halve the estimated bit rate if the source frame rate is |
|
388 // roughly less than half of the maximum frame rate |
|
389 estimatedBitrate = estimatedBitrate >> 1; |
|
390 } |
|
391 |
|
392 if (i == startClipNumber) |
|
393 { |
|
394 // We need to adjust the cut in time for the first clip since the client |
|
395 // requested to get the size estimate starting from this position |
|
396 videoClipCutInTime = aStartTime.Int64() - vedClip->StartTime().Int64(); |
|
397 |
|
398 // Initialize the current time to this position |
|
399 currentTime = aStartTime.Int64(); |
|
400 } |
|
401 |
|
402 // Estimate the size on every frame |
|
403 for (j = 0; j < videoFramesInClip; j++) |
|
404 { |
|
405 // Get frame start time and duration |
|
406 if (vedClip->Info()->Class() == EVedVideoClipClassFile) |
|
407 { |
|
408 frameTime = vedClip->Info()->VideoFrameStartTimeL(j).Int64(); |
|
409 frameDuration = vedClip->Info()->VideoFrameDurationL(j).Int64(); |
|
410 } |
|
411 else |
|
412 { |
|
413 frameTime = vedClip->Info()->Generator()->VideoFrameStartTime(j).Int64(); |
|
414 frameDuration = vedClip->Info()->Generator()->VideoFrameDuration(j).Int64(); |
|
415 } |
|
416 |
|
417 if (frameTime < videoClipCutInTime) |
|
418 { |
|
419 continue; // Frame is before cut in position => check next one |
|
420 } |
|
421 else if (frameTime >= videoClipCutOutTime) |
|
422 { |
|
423 break; // Cut out position reached => no need to check frames anymore |
|
424 } |
|
425 |
|
426 // Check that duration is valid |
|
427 if ((frameDuration <= 0) || (frameDuration > KSEMaxFrameDuration)) |
|
428 { |
|
429 // Calculate frame duration from the frame rate |
|
430 frameDuration = (TInt64) (1000000.0 / videoClipFramerate); |
|
431 } |
|
432 |
|
433 // Check for slow motion |
|
434 if (vedClip->Speed() != KVedNormalSpeed) |
|
435 { |
|
436 frameDuration = (frameDuration * KVedNormalSpeed) / vedClip->Speed(); |
|
437 } |
|
438 |
|
439 if (clipIsTranscoded) |
|
440 { |
|
441 // Clip is transcoded so calculate frame size from estimated bit rate |
|
442 videoFrameSize = I64INT((frameDuration * estimatedBitrate) / 8 / 1000000); |
|
443 } |
|
444 else |
|
445 { |
|
446 if (vedClip->Info()->Class() == EVedVideoClipClassGenerated) |
|
447 { |
|
448 // Check if the frame is a transition frame |
|
449 if (j < (startTransitionFrames - 1) || |
|
450 j > (videoFramesInClip - endTransitionFrames)) |
|
451 { |
|
452 // Frame is encoded so calculate frame size from movie bit rate |
|
453 videoFrameSize = I64INT((frameDuration * movieBitrate) / 8 / 1000000); |
|
454 } |
|
455 else |
|
456 { |
|
457 // Frame is intra if it's the first one in the clip |
|
458 // or if it's right after or before transition |
|
459 TBool isIntra = j == 0 || j == (startTransitionFrames - 1) || j == (videoFramesInClip - endTransitionFrames); |
|
460 videoFrameSize = GetGeneratedFrameSize(movie, isIntra); |
|
461 } |
|
462 } |
|
463 else |
|
464 { |
|
465 // Get frame size from the original clip |
|
466 videoFrameSize = vedClip->Info()->VideoFrameSizeL(j); |
|
467 |
|
468 // Check if color effect is in use |
|
469 if (vedClip->ColorEffect() != EVedColorEffectNone) |
|
470 { |
|
471 // Color tone effects decreases the size of the frame slightly |
|
472 videoFrameSize -= (TInt) ((TReal) videoFrameSize * KSEBWReductionFactor); |
|
473 } |
|
474 } |
|
475 } |
|
476 |
|
477 // Calculate video data size |
|
478 videoDataSize += videoFrameSize; |
|
479 |
|
480 // Calculate video 3gp size |
|
481 numberOfVideoFrames++; |
|
482 video3gpSize = GetVideo3gpSizePerFrame(numberOfVideoFrames) * numberOfVideoFrames; |
|
483 |
|
484 if (movie->AudioType() != EVedAudioTypeNoAudio) |
|
485 { |
|
486 // Calculate audio data size |
|
487 audioDataSize += song->GetFrameSizeEstimateL(currentTime, currentTime + frameDuration); |
|
488 |
|
489 if (audioDataSize > 0) |
|
490 { |
|
491 // Calculate audio 3gp size |
|
492 numberOfAudioSamples += I64REAL(frameDuration) * audioDurationToSamplesFactor; |
|
493 audio3gpSize = (TInt) (GetAudio3gpSizePerSample(numberOfAudioSamples) * numberOfAudioSamples); |
|
494 } |
|
495 } |
|
496 |
|
497 // Check if target size is reached |
|
498 if (videoDataSize + audioDataSize + video3gpSize + audio3gpSize + KSEFixedSize >= aTargetSize) |
|
499 { |
|
500 aEndTime = currentTime; |
|
501 |
|
502 // Make sure we didn't overflow the end time |
|
503 if (aEndTime > movie->Duration()) |
|
504 { |
|
505 aEndTime = movie->Duration(); |
|
506 } |
|
507 |
|
508 return KErrNone; |
|
509 } |
|
510 |
|
511 // Increase time to the next frame |
|
512 currentTime += frameDuration; |
|
513 } |
|
514 } |
|
515 |
|
516 // Check if audio is longer than video |
|
517 TInt64 remainingAudioDuration = 0; |
|
518 |
|
519 if (numberOfVideoClips > 0) |
|
520 { |
|
521 remainingAudioDuration = movie->Duration().Int64() - |
|
522 movie->VideoClip(numberOfVideoClips - 1)->EndTime().Int64(); |
|
523 |
|
524 // Adjust current time to the end of the last clip |
|
525 currentTime = movie->VideoClip(numberOfVideoClips - 1)->EndTime().Int64(); |
|
526 } |
|
527 else |
|
528 { |
|
529 remainingAudioDuration = aMovie->Duration().Int64(); |
|
530 } |
|
531 |
|
532 if (remainingAudioDuration > 0) |
|
533 { |
|
534 // Estimate how many black frames are inserted |
|
535 TInt frameDuration = KSEBlackFrameDuration; |
|
536 TInt blackVideoFrames = (TInt) (remainingAudioDuration / frameDuration) + 1; |
|
537 |
|
538 for (j = 0; j < blackVideoFrames; j++) |
|
539 { |
|
540 // Calculate video data size |
|
541 TBool isIntra = j == 0; |
|
542 videoDataSize += GetBlackFrameSize(movie, isIntra); |
|
543 |
|
544 // Calculate video 3gp size |
|
545 numberOfVideoFrames++; |
|
546 video3gpSize = GetVideo3gpSizePerFrame(numberOfVideoFrames) * numberOfVideoFrames; |
|
547 |
|
548 // Calculate audio data size |
|
549 audioDataSize += song->GetFrameSizeEstimateL(currentTime, currentTime + frameDuration); |
|
550 |
|
551 // Calculate audio 3gp size |
|
552 numberOfAudioSamples += (TReal) frameDuration * audioDurationToSamplesFactor; |
|
553 audio3gpSize = (TInt) (GetAudio3gpSizePerSample(numberOfAudioSamples) * numberOfAudioSamples); |
|
554 |
|
555 // Check if target size is reached |
|
556 if (videoDataSize + audioDataSize + video3gpSize + audio3gpSize + KSEFixedSize >= aTargetSize) |
|
557 { |
|
558 aEndTime = currentTime; |
|
559 |
|
560 // Make sure we didn't overflow the end time |
|
561 if (aEndTime > movie->Duration()) |
|
562 { |
|
563 aEndTime = movie->Duration(); |
|
564 } |
|
565 |
|
566 return KErrNone; |
|
567 } |
|
568 |
|
569 currentTime += frameDuration; |
|
570 } |
|
571 } |
|
572 |
|
573 // Target size not reached till end of movie |
|
574 aEndTime = movie->Duration(); |
|
575 |
|
576 return KErrNone; |
|
577 } |
|
578 |
|
579 // ----------------------------------------------------------------------------- |
|
580 // CSizeEstimate::GetTransitionFrames |
|
581 // Returns the number of start and end transition frames in given clip |
|
582 // (other items were commented in a header). |
|
583 // ----------------------------------------------------------------------------- |
|
584 // |
|
585 void CSizeEstimate::GetTransitionFrames(const CVedMovieImp *aMovie, TInt aIndex, |
|
586 TInt& aStartTransitionFrames, TInt& aEndTransitionFrames) |
|
587 { |
|
588 aStartTransitionFrames = 0; |
|
589 aEndTransitionFrames = 0; |
|
590 |
|
591 CVedVideoClip* vedClip = aMovie->VideoClip(aIndex); |
|
592 |
|
593 // Get the number of video frames in the clip |
|
594 TInt videoFramesInClip = 0; |
|
595 if (vedClip->Info()->Class() == EVedVideoClipClassGenerated) |
|
596 { |
|
597 videoFramesInClip = vedClip->Info()->Generator()->VideoFrameCount(); |
|
598 } |
|
599 else |
|
600 { |
|
601 videoFramesInClip = vedClip->Info()->VideoFrameCount(); |
|
602 } |
|
603 |
|
604 // Calculate the amount of start transition frames in the clip |
|
605 if (aIndex == 0) |
|
606 { |
|
607 // First clip in the movie so check movie start transition |
|
608 if (aMovie->StartTransitionEffect() != EVedStartTransitionEffectNone) |
|
609 { |
|
610 aStartTransitionFrames = KSEFadeTransitionFrames; // Fade from |
|
611 } |
|
612 } |
|
613 else if (aMovie->MiddleTransitionEffect(aIndex - 1) != EVedMiddleTransitionEffectNone) |
|
614 { |
|
615 // Check if the previous clip has a middle transition |
|
616 if (aMovie->MiddleTransitionEffect(aIndex - 1) == EVedMiddleTransitionEffectDipToBlack || |
|
617 aMovie->MiddleTransitionEffect(aIndex - 1) == EVedMiddleTransitionEffectDipToWhite) |
|
618 { |
|
619 aStartTransitionFrames = KSEFadeTransitionFrames; // Dip |
|
620 } |
|
621 else |
|
622 { |
|
623 aStartTransitionFrames = KSEWipeTransitionFrames; // Wipe / crossfade |
|
624 } |
|
625 } |
|
626 |
|
627 // Calculate the amount of end transition frames in the clip |
|
628 if (aIndex == aMovie->VideoClipCount() - 1) |
|
629 { |
|
630 // Last clip in the movie so check movie end transition |
|
631 if (aMovie->EndTransitionEffect() != EVedEndTransitionEffectNone) |
|
632 { |
|
633 aEndTransitionFrames = KSEFadeTransitionFrames; // Fade to |
|
634 } |
|
635 } |
|
636 else if (aMovie->MiddleTransitionEffect(aIndex) != EVedMiddleTransitionEffectNone) |
|
637 { |
|
638 // Check if this clip has a middle transition |
|
639 if (aMovie->MiddleTransitionEffect(aIndex) == EVedMiddleTransitionEffectDipToBlack || |
|
640 aMovie->MiddleTransitionEffect(aIndex) == EVedMiddleTransitionEffectDipToWhite) |
|
641 { |
|
642 aEndTransitionFrames = KSEFadeTransitionFrames; // Dip |
|
643 } |
|
644 else |
|
645 { |
|
646 aEndTransitionFrames = KSEWipeTransitionFrames; // Wipe / crossfade |
|
647 } |
|
648 } |
|
649 |
|
650 // Check that the number of transition frames does not overflow |
|
651 if (aStartTransitionFrames > videoFramesInClip) |
|
652 { |
|
653 aStartTransitionFrames = videoFramesInClip; |
|
654 } |
|
655 if (aEndTransitionFrames > videoFramesInClip - aStartTransitionFrames) |
|
656 { |
|
657 aEndTransitionFrames = videoFramesInClip - aStartTransitionFrames; |
|
658 } |
|
659 } |
|
660 |
|
661 // ----------------------------------------------------------------------------- |
|
662 // CSizeEstimate::GetGeneratedFrameSize |
|
663 // Estimates the average generated frame size |
|
664 // (other items were commented in a header). |
|
665 // ----------------------------------------------------------------------------- |
|
666 // |
|
667 TInt CSizeEstimate::GetGeneratedFrameSize(const CVedMovieImp *aMovie, TBool aIntra) |
|
668 { |
|
669 TInt frameFactor = 0; |
|
670 |
|
671 // Estimate the frame factor based on codec type |
|
672 if (aMovie->VideoType() == EVedVideoTypeMPEG4SimpleProfile) |
|
673 { |
|
674 // MPEG-4 |
|
675 frameFactor = aIntra ? KSEGeneratedIFrameFactorMPEG4 : KSEGeneratedPFrameFactorMPEG4; |
|
676 } |
|
677 else if (aMovie->VideoType() == EVedVideoTypeAVCBaselineProfile) |
|
678 { |
|
679 // H.264 |
|
680 frameFactor = aIntra ? KSEGeneratedIFrameFactorH264 : KSEGeneratedPFrameFactorH264; |
|
681 } |
|
682 else |
|
683 { |
|
684 // H.263 |
|
685 frameFactor = aIntra ? KSEGeneratedIFrameFactorH263 : KSEGeneratedPFrameFactorH263; |
|
686 } |
|
687 |
|
688 // Estimate frame size based on movie resolution and frame factor |
|
689 return (aMovie->Resolution().iWidth * frameFactor) >> 3; // Convert bits to bytes |
|
690 } |
|
691 |
|
692 // ----------------------------------------------------------------------------- |
|
693 // CSizeEstimate::GetBlackFrameSize |
|
694 // Estimates the average black frame size |
|
695 // (other items were commented in a header). |
|
696 // ----------------------------------------------------------------------------- |
|
697 // |
|
698 TInt CSizeEstimate::GetBlackFrameSize(const CVedMovieImp *aMovie, TBool aIntra) |
|
699 { |
|
700 TInt frameFactor = aIntra ? KSEBlackIFrameFactor : KSEBlackPFrameFactor; |
|
701 |
|
702 return (aMovie->Resolution().iWidth * frameFactor) >> 3; // Convert bits to bytes |
|
703 } |
|
704 |
|
705 // ----------------------------------------------------------------------------- |
|
706 // CSizeEstimate::GetVideo3gpSizePerFrame |
|
707 // Returns the 3gp size for video based on number of video frames |
|
708 // (other items were commented in a header). |
|
709 // ----------------------------------------------------------------------------- |
|
710 // |
|
711 TInt CSizeEstimate::GetVideo3gpSizePerFrame(TInt aNumberOfVideoFrames) |
|
712 { |
|
713 TInt video3gpSize = KSEVideo3gpSizePerFrame6; |
|
714 |
|
715 if (aNumberOfVideoFrames < KSEVideo3gpFramesLimit1) video3gpSize = KSEVideo3gpSizePerFrame1; |
|
716 else if (aNumberOfVideoFrames < KSEVideo3gpFramesLimit2) video3gpSize = KSEVideo3gpSizePerFrame2; |
|
717 else if (aNumberOfVideoFrames < KSEVideo3gpFramesLimit3) video3gpSize = KSEVideo3gpSizePerFrame3; |
|
718 else if (aNumberOfVideoFrames < KSEVideo3gpFramesLimit4) video3gpSize = KSEVideo3gpSizePerFrame4; |
|
719 else if (aNumberOfVideoFrames < KSEVideo3gpFramesLimit5) video3gpSize = KSEVideo3gpSizePerFrame5; |
|
720 |
|
721 return video3gpSize; |
|
722 } |
|
723 |
|
724 // ----------------------------------------------------------------------------- |
|
725 // CSizeEstimate::GetAudio3gpSizePerSample |
|
726 // Returns the 3gp size for audio based on number of audio samples |
|
727 // (other items were commented in a header). |
|
728 // ----------------------------------------------------------------------------- |
|
729 // |
|
730 TReal CSizeEstimate::GetAudio3gpSizePerSample(TReal aNumberOfAudioSamples) |
|
731 { |
|
732 TReal audio3gpSize = KSEAudio3gpSizePerSample8; |
|
733 |
|
734 if (aNumberOfAudioSamples < KSEAudio3gpSamplesLimit1) audio3gpSize = KSEAudio3gpSizePerSample1; |
|
735 else if (aNumberOfAudioSamples < KSEAudio3gpSamplesLimit2) audio3gpSize = KSEAudio3gpSizePerSample2; |
|
736 else if (aNumberOfAudioSamples < KSEAudio3gpSamplesLimit3) audio3gpSize = KSEAudio3gpSizePerSample3; |
|
737 else if (aNumberOfAudioSamples < KSEAudio3gpSamplesLimit4) audio3gpSize = KSEAudio3gpSizePerSample4; |
|
738 else if (aNumberOfAudioSamples < KSEAudio3gpSamplesLimit5) audio3gpSize = KSEAudio3gpSizePerSample5; |
|
739 else if (aNumberOfAudioSamples < KSEAudio3gpSamplesLimit6) audio3gpSize = KSEAudio3gpSizePerSample6; |
|
740 else if (aNumberOfAudioSamples < KSEAudio3gpSamplesLimit7) audio3gpSize = KSEAudio3gpSizePerSample7; |
|
741 |
|
742 return audio3gpSize; |
|
743 } |
|
744 |
|
745 |
|
746 // End of File |
|
747 |