|
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 MPEG-4 timing functions. |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 /* |
|
22 * Includes |
|
23 */ |
|
24 |
|
25 #include "mpeg4timer.h" |
|
26 #include "vedvideosettings.h" |
|
27 |
|
28 // Debug print macro |
|
29 #ifdef _DEBUG |
|
30 #include <e32svr.h> |
|
31 #define PRINT(x) RDebug::Print x |
|
32 #else |
|
33 #define PRINT(x) |
|
34 #endif |
|
35 |
|
36 |
|
37 /* |
|
38 * ~CMPEG4Timer |
|
39 * |
|
40 * Parameters: |
|
41 * |
|
42 * Function: |
|
43 * Destruction |
|
44 * Returns: |
|
45 * |
|
46 * Error codes: |
|
47 * None |
|
48 * |
|
49 */ |
|
50 CMPEG4Timer::~CMPEG4Timer() |
|
51 { |
|
52 } |
|
53 |
|
54 /* |
|
55 * NewL |
|
56 * |
|
57 * Parameters: |
|
58 * |
|
59 * Function: |
|
60 * Symbian two-phased constructor |
|
61 * Returns: |
|
62 * pointer to constructed object, or NULL |
|
63 * Error codes: |
|
64 * None |
|
65 * |
|
66 */ |
|
67 CMPEG4Timer* CMPEG4Timer::NewL(CMovieProcessorImpl * aMovProcessor, TInt aTimeIncrementResolution) |
|
68 { |
|
69 CMPEG4Timer* self = new (ELeave) CMPEG4Timer(); |
|
70 CleanupStack::PushL( self ); |
|
71 self->ConstructL(aMovProcessor, aTimeIncrementResolution); |
|
72 CleanupStack::Pop(); |
|
73 return self; |
|
74 } |
|
75 |
|
76 /* |
|
77 * ConstructL |
|
78 * |
|
79 * Parameters: |
|
80 * |
|
81 * Function: |
|
82 * Symbian 2nd phase constructor (can leave) |
|
83 * Returns: |
|
84 * None |
|
85 * Error codes: |
|
86 * None |
|
87 * |
|
88 */ |
|
89 void CMPEG4Timer::ConstructL(CMovieProcessorImpl * aMovProcessor, TInt aTimeIncrementResolution) |
|
90 { |
|
91 iProcessor = aMovProcessor; |
|
92 iMPEG4TimeStamp.modulo_time_base = 0; |
|
93 iMPEG4TimeStamp.time_inc = 0; |
|
94 iPrevModuloTimeBaseVal = 0; |
|
95 iMPEG4TimeResolution = aTimeIncrementResolution; |
|
96 iMPEG4DurationInMsSinceLastModulo = 0; |
|
97 } |
|
98 |
|
99 |
|
100 |
|
101 /* |
|
102 * GetMPEG4DurationInMsSinceLastModulo |
|
103 * |
|
104 * Parameters: |
|
105 * |
|
106 * Function: |
|
107 * This function gets the frame duration in millisec from the last frame with modulo base larger than zero |
|
108 * Returns: |
|
109 * Frame duration |
|
110 * Error codes: |
|
111 * None |
|
112 * |
|
113 */ |
|
114 TInt64 CMPEG4Timer::GetMPEG4DurationInMsSinceLastModulo() |
|
115 { |
|
116 return iMPEG4DurationInMsSinceLastModulo; |
|
117 } |
|
118 |
|
119 /* |
|
120 * UpdateMPEG4Time |
|
121 * |
|
122 * Parameters: |
|
123 * |
|
124 * Function: |
|
125 * This function updates the time stamp and duration of the last frame for MPEG-4 video |
|
126 * Returns: |
|
127 * Nothing |
|
128 * Error codes: |
|
129 * None |
|
130 * |
|
131 */ |
|
132 void CMPEG4Timer::UpdateMPEG4Time(TInt aAbsFrameNumber, TInt /*aFrameNumber*/, TInt aTimeScale) |
|
133 { |
|
134 TInt cur = aAbsFrameNumber; |
|
135 TInt next = cur+1; |
|
136 TInt64 frameDuration; |
|
137 int Tdiff; |
|
138 |
|
139 iPrevModuloTimeBaseVal += iMPEG4TimeStamp.modulo_time_base; |
|
140 |
|
141 iMPEG4DurationInMsSinceLastModulo = (TInt)((TReal)(iPrevModuloTimeBaseVal * iMPEG4TimeResolution + iMPEG4TimeStamp.time_inc)/ |
|
142 (TReal)(iMPEG4TimeResolution) * 1000000.0 + 0.5); |
|
143 |
|
144 if(next >= iProcessor->GetOutputNumberOfFrames()) |
|
145 frameDuration = iProcessor->GetVideoTimeInMsFromTicks( I64INT( (iProcessor->GetVideoClipDuration() - iProcessor->VideoFrameTimeStamp(cur)) ), EFalse)*1000; |
|
146 else |
|
147 frameDuration = iProcessor->GetVideoTimeInMsFromTicks(iProcessor->VideoFrameTimeStamp(next) - iProcessor->VideoFrameTimeStamp(cur), EFalse)*1000; |
|
148 |
|
149 if (frameDuration <0 ) |
|
150 frameDuration = 100000; |
|
151 |
|
152 frameDuration = TInt( I64REAL(frameDuration) / (TReal)aTimeScale * 1000.0 + 0.5); |
|
153 |
|
154 if ( I64INT(frameDuration) > KVedMaxFrameDuration ) |
|
155 { |
|
156 // max duration is limited since there are some variables e.g. in video decoder than can handle only limited length fields. |
|
157 PRINT((_L("CMPEG4Timer::UpdateMPEG4Time() limiting frame duration to 30 sec"))); |
|
158 frameDuration = KVedMaxFrameDuration; |
|
159 } |
|
160 Tdiff = TInt(iMPEG4TimeStamp.time_inc + I64REAL(frameDuration) * iMPEG4TimeResolution/1000000.0 + 0.5); |
|
161 iMPEG4TimeStamp.modulo_time_base = Tdiff/iMPEG4TimeResolution; |
|
162 iMPEG4TimeStamp.time_inc = Tdiff - (iMPEG4TimeResolution * iMPEG4TimeStamp.modulo_time_base); |
|
163 |
|
164 } |
|
165 |