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 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 #include "VedVideoClip.h" |
|
23 #include "VedMovieImp.h" |
|
24 #include "VedVideoClipInfoGeneratedImp.h" |
|
25 #include "VedVideoClipInfoImp.h" |
|
26 #include "AudClip.h" |
|
27 #include "AudObservers.h" |
|
28 |
|
29 CVedVideoClip* CVedVideoClip::NewL(CVedMovieImp* aMovie, const TDesC& aFileName, |
|
30 TInt aIndex, CAudClip* aAudioClip, |
|
31 MVedVideoClipInfoObserver& aObserver) |
|
32 { |
|
33 CVedVideoClip* self = new (ELeave) CVedVideoClip(aMovie, aAudioClip); |
|
34 CleanupStack::PushL(self); |
|
35 self->ConstructL(aFileName, aIndex, aObserver); |
|
36 CleanupStack::Pop(self); |
|
37 return self; |
|
38 } |
|
39 |
|
40 |
|
41 CVedVideoClip* CVedVideoClip::NewL(CVedMovieImp* aMovie, CVedVideoClipGenerator& aGenerator, |
|
42 TInt aIndex, MVedVideoClipInfoObserver& aObserver, TBool aIsOwnedByVideoClip) |
|
43 { |
|
44 CVedVideoClip* self = new (ELeave) CVedVideoClip(aMovie, NULL /*CAudClip*/); |
|
45 CleanupStack::PushL(self); |
|
46 self->ConstructL(aGenerator, aIndex, aObserver, aIsOwnedByVideoClip); |
|
47 CleanupStack::Pop(self); |
|
48 return self; |
|
49 } |
|
50 |
|
51 CVedVideoClip* CVedVideoClip::NewL(CVedMovieImp* aMovie, RFile* aFileHandle, |
|
52 TInt aIndex, CAudClip* aAudioClip, |
|
53 MVedVideoClipInfoObserver& aObserver) |
|
54 { |
|
55 CVedVideoClip* self = new (ELeave) CVedVideoClip(aMovie, aAudioClip); |
|
56 CleanupStack::PushL(self); |
|
57 self->ConstructL(aFileHandle, aIndex, aObserver); |
|
58 CleanupStack::Pop(self); |
|
59 return self; |
|
60 } |
|
61 |
|
62 |
|
63 CVedVideoClip::CVedVideoClip(CVedMovieImp* aMovie, CAudClip* aAudioClip) |
|
64 : iMovie(aMovie), iSpeed(KVedNormalSpeed), iColorEffect(EVedColorEffectNone), |
|
65 iCutInTime(0), iAudClip(aAudioClip) |
|
66 { |
|
67 } |
|
68 |
|
69 |
|
70 void CVedVideoClip::ConstructL(const TDesC& aFileName, TInt aIndex, |
|
71 MVedVideoClipInfoObserver& aObserver) |
|
72 { |
|
73 __ASSERT_ALWAYS(aIndex >= 0, |
|
74 TVedPanic::Panic(TVedPanic::EVideoClipIllegalIndex)); |
|
75 __ASSERT_ALWAYS(aIndex <= iMovie->VideoClipCount(), |
|
76 TVedPanic::Panic(TVedPanic::EVideoClipIllegalIndex)); |
|
77 iIndex = aIndex; |
|
78 |
|
79 if (iMovie->iFs) // lock file against writing |
|
80 { |
|
81 |
|
82 TInt error = iLockFile.Open(*iMovie->iFs, aFileName, EFileShareReadersOnly | EFileStream | EFileRead); |
|
83 |
|
84 if (error != KErrNone) |
|
85 { |
|
86 User::LeaveIfError(iLockFile.Open(*iMovie->iFs, aFileName, |
|
87 EFileShareAny | EFileStream | EFileRead)); |
|
88 } |
|
89 iLockFileOpened = ETrue; |
|
90 } |
|
91 |
|
92 if (iAudClip) |
|
93 { |
|
94 iInfo = CVedVideoClipInfoImp::NewL(iAudClip->Info(), aFileName, aObserver); |
|
95 } |
|
96 else |
|
97 { |
|
98 iInfo = CVedVideoClipInfoImp::NewL(NULL, aFileName, aObserver); |
|
99 } |
|
100 } |
|
101 |
|
102 |
|
103 void CVedVideoClip::ConstructL(CVedVideoClipGenerator& aGenerator, TInt aIndex, |
|
104 MVedVideoClipInfoObserver& aObserver, TBool aIsOwnedByVideoClip) |
|
105 { |
|
106 __ASSERT_ALWAYS(aIndex >= 0, |
|
107 TVedPanic::Panic(TVedPanic::EVideoClipIllegalIndex)); |
|
108 __ASSERT_ALWAYS(aIndex <= iMovie->VideoClipCount(), |
|
109 TVedPanic::Panic(TVedPanic::EVideoClipIllegalIndex)); |
|
110 iIndex = aIndex; |
|
111 |
|
112 iInfo = new (ELeave) CVedVideoClipInfoGeneratedImp(aGenerator, aIsOwnedByVideoClip); |
|
113 ((CVedVideoClipInfoGeneratedImp*) iInfo)->ConstructL(aObserver); |
|
114 } |
|
115 |
|
116 |
|
117 void CVedVideoClip::ConstructL(RFile* aFileHandle, TInt aIndex, |
|
118 MVedVideoClipInfoObserver& aObserver) |
|
119 { |
|
120 __ASSERT_ALWAYS(aIndex >= 0, |
|
121 TVedPanic::Panic(TVedPanic::EVideoClipIllegalIndex)); |
|
122 __ASSERT_ALWAYS(aIndex <= iMovie->VideoClipCount(), |
|
123 TVedPanic::Panic(TVedPanic::EVideoClipIllegalIndex)); |
|
124 iIndex = aIndex; |
|
125 |
|
126 if (iAudClip) |
|
127 { |
|
128 iInfo = CVedVideoClipInfoImp::NewL(iAudClip->Info(), aFileHandle, aObserver); |
|
129 } |
|
130 else |
|
131 { |
|
132 iInfo = CVedVideoClipInfoImp::NewL(NULL, aFileHandle, aObserver); |
|
133 } |
|
134 } |
|
135 |
|
136 |
|
137 CVedVideoClip::~CVedVideoClip() |
|
138 { |
|
139 delete iInfo; |
|
140 |
|
141 if (iLockFileOpened) |
|
142 iLockFile.Close(); |
|
143 |
|
144 } |
|
145 |
|
146 |
|
147 void CVedVideoClip::SetIndex(TInt aIndex) |
|
148 { |
|
149 __ASSERT_ALWAYS(aIndex >= 0, |
|
150 TVedPanic::Panic(TVedPanic::EVideoClipIllegalIndex)); |
|
151 __ASSERT_ALWAYS(aIndex < iMovie->VideoClipCount(), |
|
152 TVedPanic::Panic(TVedPanic::EVideoClipIllegalIndex)); |
|
153 |
|
154 if (aIndex != iIndex) |
|
155 { |
|
156 TInt oldIndex = iIndex; |
|
157 iIndex = aIndex; |
|
158 |
|
159 iMovie->iVideoClipArray.Remove(oldIndex); |
|
160 TInt err = iMovie->iVideoClipArray.Insert(this, iIndex); |
|
161 __ASSERT_DEBUG(err == KErrNone, |
|
162 TVedPanic::Panic(TVedPanic::EInternal)); |
|
163 |
|
164 if (oldIndex < iIndex) |
|
165 { |
|
166 CVedVideoClip* clip = iMovie->iVideoClipArray[oldIndex]; |
|
167 clip->iIndex = oldIndex; |
|
168 iMovie->RecalculateVideoClipTimings(clip); |
|
169 } |
|
170 else |
|
171 { |
|
172 iMovie->RecalculateVideoClipTimings(this); |
|
173 } |
|
174 |
|
175 iMovie->FireVideoClipIndicesChanged(iMovie, oldIndex, iIndex); |
|
176 } |
|
177 } |
|
178 |
|
179 |
|
180 void CVedVideoClip::SetSpeed(TInt aSpeed) |
|
181 { |
|
182 __ASSERT_ALWAYS((aSpeed >= KVedMinSpeed) && (aSpeed <= KVedMaxSpeed), |
|
183 TVedPanic::Panic(TVedPanic::EVideoClipIllegalSpeed)); |
|
184 |
|
185 if (aSpeed != KVedNormalSpeed ) |
|
186 { |
|
187 // slow motion, mute the audio track |
|
188 if (iAudClip) |
|
189 { |
|
190 iAudClip->SetMuting(ETrue); |
|
191 iMovie->FireVideoClipAudioSettingsChanged(iMovie, this); |
|
192 } |
|
193 } |
|
194 else |
|
195 { |
|
196 // normal speed |
|
197 if ( !iUserMuted ) |
|
198 { |
|
199 // unmute the audio track unless user has muted the clip |
|
200 if (iAudClip) |
|
201 { |
|
202 iAudClip->SetMuting(EFalse); |
|
203 iMovie->FireVideoClipAudioSettingsChanged(iMovie, this); |
|
204 } |
|
205 } |
|
206 } |
|
207 |
|
208 if (aSpeed != iSpeed) |
|
209 { |
|
210 iSpeed = aSpeed; |
|
211 iMovie->RecalculateVideoClipTimings(this); |
|
212 iMovie->FireVideoClipTimingsChanged(iMovie, this); |
|
213 } |
|
214 } |
|
215 |
|
216 |
|
217 void CVedVideoClip::SetColorEffect(TVedColorEffect aColorEffect) |
|
218 { |
|
219 __ASSERT_ALWAYS((aColorEffect >= EVedColorEffectNone) |
|
220 && (aColorEffect < EVedColorEffectLast), |
|
221 TVedPanic::Panic(TVedPanic::EVideoClipIllegalColorEffect)); |
|
222 |
|
223 if (aColorEffect != iColorEffect) |
|
224 { |
|
225 iColorEffect = aColorEffect; |
|
226 iMovie->FireVideoClipColorEffectChanged(iMovie, this); |
|
227 } |
|
228 } |
|
229 |
|
230 TRgb CVedVideoClip::ColorTone() const |
|
231 { |
|
232 return iColorTone; |
|
233 } |
|
234 |
|
235 void CVedVideoClip::SetColorTone(TRgb aColorTone) |
|
236 { |
|
237 if (aColorTone != iColorTone) |
|
238 { |
|
239 // any checks needed? |
|
240 iColorTone = aColorTone; |
|
241 // reuses the observer callback from color effect, since essentially it is about the same thing |
|
242 iMovie->FireVideoClipColorEffectChanged(iMovie, this); |
|
243 } |
|
244 } |
|
245 |
|
246 void CVedVideoClip::SetMuted(TBool aMuted) |
|
247 { |
|
248 if (!iAudClip) |
|
249 { |
|
250 return; |
|
251 } |
|
252 iUserMuted = aMuted; // store the mute-value (true/false) to be able to differentiate user and automatic mute |
|
253 iAudClip->SetMuting(aMuted); |
|
254 iMovie->FireVideoClipAudioSettingsChanged(iMovie, this); |
|
255 } |
|
256 |
|
257 TInt CVedVideoClip::InsertDynamicLevelMarkL(const TVedDynamicLevelMark& aMark) |
|
258 { |
|
259 __ASSERT_ALWAYS(aMark.iTime.Int64() >= 0, |
|
260 TVedPanic::Panic(TVedPanic::EIllegalDynamicLevelMark)); |
|
261 __ASSERT_ALWAYS(aMark.iTime.Int64() <= CutOutTime().Int64(), |
|
262 TVedPanic::Panic(TVedPanic::EIllegalDynamicLevelMark)); |
|
263 |
|
264 if ( iAudClip ) |
|
265 { |
|
266 return iAudClip->InsertDynamicLevelMarkL(TAudDynamicLevelMark(aMark.iTime, aMark.iLevel)); |
|
267 } |
|
268 else |
|
269 { |
|
270 User::Leave(KErrNotFound); |
|
271 return -1;//to make compiler happy |
|
272 } |
|
273 } |
|
274 |
|
275 TBool CVedVideoClip::RemoveDynamicLevelMark(TInt aIndex) |
|
276 { |
|
277 __ASSERT_ALWAYS(aIndex >= 0, |
|
278 TVedPanic::Panic(TVedPanic::EIllegalDynamicLevelMarkIndex)); |
|
279 __ASSERT_ALWAYS(aIndex < DynamicLevelMarkCount(), |
|
280 TVedPanic::Panic(TVedPanic::EIllegalDynamicLevelMarkIndex)); |
|
281 if ( iAudClip ) |
|
282 { |
|
283 return iAudClip->RemoveDynamicLevelMark(aIndex); |
|
284 } |
|
285 else |
|
286 { |
|
287 return EFalse; |
|
288 } |
|
289 } |
|
290 |
|
291 TVedDynamicLevelMark CVedVideoClip::DynamicLevelMark(TInt aIndex) const |
|
292 { |
|
293 __ASSERT_ALWAYS(aIndex >= 0, |
|
294 TVedPanic::Panic(TVedPanic::EIllegalDynamicLevelMarkIndex)); |
|
295 __ASSERT_ALWAYS(aIndex < DynamicLevelMarkCount(), |
|
296 TVedPanic::Panic(TVedPanic::EIllegalDynamicLevelMarkIndex)); |
|
297 |
|
298 if ( iAudClip ) |
|
299 { |
|
300 TAudDynamicLevelMark mark = iAudClip->DynamicLevelMark(aIndex); |
|
301 return TVedDynamicLevelMark(mark.iTime, mark.iLevel); |
|
302 } |
|
303 else |
|
304 { |
|
305 return TVedDynamicLevelMark(TTimeIntervalMicroSeconds(0), 0); |
|
306 } |
|
307 } |
|
308 |
|
309 TInt CVedVideoClip::DynamicLevelMarkCount() const |
|
310 { |
|
311 if ( iAudClip ) |
|
312 { |
|
313 return iAudClip->DynamicLevelMarkCount(); |
|
314 } |
|
315 else |
|
316 { |
|
317 return 0; |
|
318 } |
|
319 } |
|
320 |
|
321 void CVedVideoClip::SetVolumeGain(TInt aVolumeGain) |
|
322 { |
|
323 if ( iAudClip ) |
|
324 { |
|
325 iAudClip->SetVolumeGain(aVolumeGain); |
|
326 } |
|
327 } |
|
328 |
|
329 TInt CVedVideoClip::GetVolumeGain() |
|
330 { |
|
331 if ( iAudClip ) |
|
332 { |
|
333 return iAudClip->GetVolumeGain(); |
|
334 } |
|
335 else |
|
336 { |
|
337 return 0; |
|
338 } |
|
339 } |
|
340 |
|
341 |
|
342 void CVedVideoClip::SetCutInTime(TTimeIntervalMicroSeconds aCutInTime) |
|
343 { |
|
344 __ASSERT_ALWAYS(aCutInTime >= TTimeIntervalMicroSeconds(0), |
|
345 TVedPanic::Panic(TVedPanic::EVideoClipIllegalCutInTime)); |
|
346 __ASSERT_ALWAYS(aCutInTime <= iCutOutTime, |
|
347 TVedPanic::Panic(TVedPanic::EVideoClipIllegalCutInTime)); |
|
348 __ASSERT_ALWAYS(iInfo->Class() == EVedVideoClipClassFile, |
|
349 TVedPanic::Panic(TVedPanic::EVideoClipNoFileAssociated)); |
|
350 |
|
351 if (aCutInTime != iCutInTime) |
|
352 { |
|
353 iCutInTime = aCutInTime; |
|
354 iMovie->RecalculateVideoClipTimings(this); |
|
355 iMovie->FireVideoClipTimingsChanged(iMovie, this); |
|
356 } |
|
357 } |
|
358 |
|
359 |
|
360 void CVedVideoClip::SetCutOutTime(TTimeIntervalMicroSeconds aCutOutTime) |
|
361 { |
|
362 __ASSERT_ALWAYS(aCutOutTime >= iCutInTime, |
|
363 TVedPanic::Panic(TVedPanic::EVideoClipIllegalCutOutTime)); |
|
364 __ASSERT_ALWAYS(iInfo->Class() == EVedVideoClipClassFile, |
|
365 TVedPanic::Panic(TVedPanic::EVideoClipNoFileAssociated)); |
|
366 |
|
367 if ( aCutOutTime > iInfo->Duration() ) |
|
368 { |
|
369 aCutOutTime = iInfo->Duration(); |
|
370 } |
|
371 |
|
372 if (aCutOutTime != iCutOutTime) |
|
373 { |
|
374 iCutOutTime = aCutOutTime; |
|
375 iMovie->RecalculateVideoClipTimings(this); |
|
376 iMovie->FireVideoClipTimingsChanged(iMovie, this); |
|
377 } |
|
378 } |
|
379 |
|
380 void CVedVideoClip::UpdateAudioClip() |
|
381 { |
|
382 if (!iAudClip) |
|
383 { |
|
384 return; |
|
385 } |
|
386 iAudClip->SetStartTime(iStartTime); |
|
387 iAudClip->SetCutInTime(iCutInTime); |
|
388 iAudClip->SetCutOutTime(iCutOutTime); |
|
389 } |
|
390 |
|
391 |
|
392 |
|
393 CVedVideoClipInfo* CVedVideoClip::Info() |
|
394 { |
|
395 return iInfo; |
|
396 } |
|
397 |
|
398 |
|
399 TBool CVedVideoClip::EditedHasAudio() const |
|
400 { |
|
401 TInt speed = Speed(); |
|
402 TBool isMuted = IsMuted(); |
|
403 TBool hasAudio = iInfo->HasAudio(); |
|
404 TBool ret = hasAudio && (speed == KVedNormalSpeed); |
|
405 ret = ret && !isMuted; |
|
406 return ret; |
|
407 } |
|
408 |
|
409 |
|
410 CVedMovieImp* CVedVideoClip::Movie() |
|
411 { |
|
412 return iMovie; |
|
413 } |
|
414 |
|
415 |
|
416 TInt CVedVideoClip::Index() const |
|
417 { |
|
418 return iIndex; |
|
419 } |
|
420 |
|
421 |
|
422 TInt CVedVideoClip::Speed() const |
|
423 { |
|
424 return iSpeed; |
|
425 } |
|
426 |
|
427 |
|
428 TVedColorEffect CVedVideoClip::ColorEffect() const |
|
429 { |
|
430 return iColorEffect; |
|
431 } |
|
432 |
|
433 |
|
434 TBool CVedVideoClip::IsMuteable() const |
|
435 { |
|
436 return (iInfo->HasAudio() && (Speed() == KVedNormalSpeed)); |
|
437 } |
|
438 |
|
439 |
|
440 TBool CVedVideoClip::Muting() const |
|
441 { |
|
442 if (!iAudClip) |
|
443 { |
|
444 return ETrue; |
|
445 } |
|
446 return iAudClip->Muting(); |
|
447 } |
|
448 |
|
449 TBool CVedVideoClip::IsMuted() const |
|
450 { |
|
451 if (!iAudClip) |
|
452 { |
|
453 return ETrue; |
|
454 } |
|
455 if ( iUserMuted ) |
|
456 { |
|
457 return ETrue; |
|
458 } |
|
459 else |
|
460 { |
|
461 // automatic mute due to slow motion is not informed to client as muted |
|
462 // since it can cause some conflicts |
|
463 return EFalse; |
|
464 } |
|
465 } |
|
466 |
|
467 void CVedVideoClip::SetNormalizing(TBool aNormalizing) |
|
468 { |
|
469 if (iAudClip) |
|
470 { |
|
471 iAudClip->SetNormalizing(aNormalizing); |
|
472 } |
|
473 } |
|
474 |
|
475 TBool CVedVideoClip::Normalizing() const |
|
476 { |
|
477 return (iAudClip && iAudClip->Normalizing()); |
|
478 } |
|
479 |
|
480 TTimeIntervalMicroSeconds CVedVideoClip::CutInTime() const |
|
481 { |
|
482 if (iInfo->Class() == EVedVideoClipClassFile) |
|
483 { |
|
484 return iCutInTime; |
|
485 } |
|
486 else |
|
487 { |
|
488 return TTimeIntervalMicroSeconds(0); |
|
489 } |
|
490 } |
|
491 |
|
492 |
|
493 TTimeIntervalMicroSeconds CVedVideoClip::CutOutTime() const |
|
494 { |
|
495 if (iInfo->Class() == EVedVideoClipClassFile) |
|
496 { |
|
497 return iCutOutTime; |
|
498 } |
|
499 else |
|
500 { |
|
501 return iInfo->Duration(); |
|
502 } |
|
503 } |
|
504 |
|
505 |
|
506 TTimeIntervalMicroSeconds CVedVideoClip::StartTime() const |
|
507 { |
|
508 return iStartTime; |
|
509 } |
|
510 |
|
511 |
|
512 TTimeIntervalMicroSeconds CVedVideoClip::EndTime() const |
|
513 { |
|
514 return TTimeIntervalMicroSeconds(iStartTime.Int64() + EditedDuration().Int64()); |
|
515 } |
|
516 |
|
517 |
|
518 TTimeIntervalMicroSeconds CVedVideoClip::EditedDuration() const |
|
519 { |
|
520 TInt64 editedDuration = CutOutTime().Int64() - CutInTime().Int64(); |
|
521 return TTimeIntervalMicroSeconds((TInt64(1000) * editedDuration) / TInt64(Speed())); |
|
522 } |
|
523 |
|