|
1 /* |
|
2 * Copyright (c) 2007,2009 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 "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: Calculates playback time for rendering state machine |
|
15 * |
|
16 */ |
|
17 |
|
18 #ifndef UPNPRENDERINGPLAYTIMECALCULATOR_H |
|
19 #define UPNPRENDERINGPLAYTIMECALCULATOR_H |
|
20 |
|
21 // INCLUDES |
|
22 #include <e32base.h> |
|
23 |
|
24 // FORWARD DECLARATIONS |
|
25 |
|
26 // CLASS DECLARATION |
|
27 |
|
28 |
|
29 /** |
|
30 * A class that keeps track of playback time by setting a timestamp at given |
|
31 * play, pause, resume and stop events and maybe also comparing that to given |
|
32 * fixed progress positions along the way. By doing that we will be able to |
|
33 * tell how long the track has been playing when a stop signal arrives. This |
|
34 * is important so that we can tell if it is a natural "track complete" stop |
|
35 * or an "user interrupt" type of stop. |
|
36 */ |
|
37 NONSHARABLE_CLASS( CUpnpRenderingPlaytimeCalculator ) |
|
38 { |
|
39 public: // the interface |
|
40 |
|
41 /** |
|
42 * Default constructor |
|
43 */ |
|
44 CUpnpRenderingPlaytimeCalculator(); |
|
45 |
|
46 /** |
|
47 * Marks START timestamp. |
|
48 * Calling Start() will reset the calculator. |
|
49 */ |
|
50 void Start(); |
|
51 |
|
52 /** |
|
53 * Marks PAUSE timestamp. |
|
54 * Can be called multiple times, ceach Pause will replace previous mark. |
|
55 */ |
|
56 void Pause(); |
|
57 |
|
58 /** |
|
59 * Marks RESUME timestamp. |
|
60 * Can NOT be called multiple times. |
|
61 */ |
|
62 void Resume(); |
|
63 |
|
64 /** |
|
65 * Marks STOP timestamp. |
|
66 * Can be called multiple times. |
|
67 */ |
|
68 void Stop(); |
|
69 |
|
70 /** |
|
71 * Sets the track duration as it is represented in the media server. |
|
72 * This method should be used to set the initial duration so that |
|
73 * the calculator works even if renderer NEVER sends position info. |
|
74 * @param aDuration track duration in milliseconds |
|
75 */ |
|
76 void SetDuration( TInt aDuration ); |
|
77 |
|
78 /** |
|
79 * Returns the track duration if it is known, otherwise KErrNotFound. |
|
80 */ |
|
81 TInt Duration() const; |
|
82 |
|
83 /** |
|
84 * Acknowledges track duration and position info that was received from |
|
85 * the renderer. Following things are done here: |
|
86 * 1. The renderer's understanding of duration might be different from |
|
87 * media server's understanding. If it is, we MAY modify it. |
|
88 * 2. The position is compared to the calculated position and if it is |
|
89 * different, an offset is calculated and used in future Position calls. |
|
90 */ |
|
91 void AcknowledgePositionInfo( TInt aDuration, TInt aPosition ); |
|
92 |
|
93 /** |
|
94 * Estimates position now, or returns total playtime of previous track. |
|
95 */ |
|
96 TInt Position() const; |
|
97 |
|
98 /** |
|
99 * returns true if last track track playtime would indicate that it was |
|
100 * played back entirely. |
|
101 */ |
|
102 TBool IsTrackComplete() const; |
|
103 |
|
104 /** |
|
105 * Returns true if calculator is in playing state. |
|
106 */ |
|
107 TBool IsPlaying() const; |
|
108 |
|
109 /** |
|
110 * Adjust the start mark according to the new postion; use case is seek |
|
111 */ |
|
112 void RestartAt( TInt aNewPosition ); |
|
113 |
|
114 private: |
|
115 |
|
116 /** |
|
117 * calculates playtime estimate starting from PLAY mark until given time, |
|
118 * tacking in account all time spent in PAUSE and also cinsidering offset. |
|
119 */ |
|
120 TInt PositionAt( TTime& aTime ) const; |
|
121 |
|
122 /** |
|
123 * calculates time spent in pause |
|
124 */ |
|
125 TInt PausetimeAt( TTime& aTime ) const; |
|
126 |
|
127 /** |
|
128 * calculates the offset from current time and the position |
|
129 */ |
|
130 TInt OffsetFromNow( TInt aPosition ) const; |
|
131 |
|
132 private: |
|
133 |
|
134 // duration of the track |
|
135 TInt iDuration; |
|
136 |
|
137 // the start timestamp |
|
138 TTime iStartMark; |
|
139 |
|
140 // the stop timestamp |
|
141 TTime iStopMark; |
|
142 |
|
143 // the pause mark |
|
144 TTime iPauseMark; |
|
145 |
|
146 // total time spent in pause |
|
147 TInt iPauseTime; |
|
148 |
|
149 // the offset to real position |
|
150 TInt iOffset; |
|
151 |
|
152 // is a track playing |
|
153 TBool iPlaying; |
|
154 |
|
155 // is track paused |
|
156 TBool iPaused; |
|
157 |
|
158 }; |
|
159 |
|
160 |
|
161 |
|
162 #endif // UPNPRENDERINGPLAYTIMECALCULATOR_H |
|
163 |
|
164 // End of File |