1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
|
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#ifndef MOHAWK_VIDEO_H
#define MOHAWK_VIDEO_H
#include "audio/timestamp.h"
#include "common/array.h"
#include "common/list.h"
#include "common/noncopyable.h"
#include "common/ptr.h"
#include "common/rational.h"
#include "graphics/pixelformat.h"
namespace Video {
class VideoDecoder;
}
namespace Mohawk {
class MohawkEngine;
/**
* A video monitored by the VideoManager
*/
class VideoEntry : private Common::NonCopyable {
// The private members should be able to be manipulated by VideoManager
friend class VideoManager;
private:
// Hide the destructor/constructor
// Only VideoManager should be allowed
VideoEntry();
VideoEntry(Video::VideoDecoder *video, const Common::String &fileName);
VideoEntry(Video::VideoDecoder *video, int id);
public:
~VideoEntry();
/**
* Convenience implicit cast to bool
*/
operator bool() const { return isOpen(); }
/**
* Is the video open?
*/
bool isOpen() const { return _video != 0; }
/**
* Close the video
*/
void close();
/**
* Has the video reached its end?
*/
bool endOfVideo() const;
/**
* Get the X position of where the video is displayed
*/
uint16 getX() const { return _x; }
/**
* Get the Y position of where the video is displayed
*/
uint16 getY() const { return _y; }
/**
* Is the video looping?
*/
bool isLooping() const { return _loop; }
/**
* Is the video enabled? (Drawing to the screen)
*/
bool isEnabled() const { return _enabled; }
/**
* Get the start time of the video bounds
*/
const Audio::Timestamp &getStart() const { return _start; }
/**
* Get the file name of the video, or empty if by ID
*/
const Common::String &getFileName() const { return _fileName; }
/**
* Get the ID of the video, or -1 if by file name
*/
int getID() const { return _id; }
/**
* Get the current frame of the video
*/
int getCurFrame() const;
/**
* Get the frame count of the video
*/
uint32 getFrameCount() const;
/**
* Get the current time position of the video
*/
uint32 getTime() const;
/**
* Get the duration of the video
*/
Audio::Timestamp getDuration() const;
/**
* Get the current playback rate of the videos
*/
Common::Rational getRate() const;
/**
* Move the x position of the video
*/
void setX(uint16 x) { _x = x; }
/**
* Move the y position of the video
*/
void setY(uint16 y) { _y = y; }
/**
* Move the video to the specified coordinates
*/
void moveTo(uint16 x, uint16 y) { setX(x); setY(y); }
/**
* Center the video on the screen
*/
void center();
/**
* Set the start time when using video bounds
*/
void setStart(const Audio::Timestamp &time) { _start = time; }
/**
* Set the video to loop (true) or not (false)
*/
void setLooping(bool loop) { _loop = loop; }
/**
* Set the video's enabled status
*/
void setEnabled(bool enabled) { _enabled = enabled; }
/**
* Set the bounds of the video
*
* This automatically seeks to the start time
*/
void setBounds(const Audio::Timestamp &startTime, const Audio::Timestamp &endTime);
/**
* Seek to the given time
*/
void seek(const Audio::Timestamp &time);
/**
* Set the playback rate
*/
void setRate(const Common::Rational &rate);
/**
* Pause the video
*/
void pause(bool isPaused);
/**
* Start playing the video
*/
void start();
/**
* Stop playing the video
*/
void stop();
/**
* Is the video playing?
*/
bool isPlaying() const;
/**
* Get the volume of the video
*/
int getVolume() const;
/**
* Set the volume of the video
*/
void setVolume(int volume);
private:
// Non-changing variables
Video::VideoDecoder *_video;
Common::String _fileName; // External video files
int _id; // Internal Mohawk files
// Playback variables
uint16 _x;
uint16 _y;
bool _loop;
bool _enabled;
Audio::Timestamp _start;
};
typedef Common::SharedPtr<VideoEntry> VideoEntryPtr;
class VideoManager {
public:
VideoManager(MohawkEngine *vm);
virtual ~VideoManager();
// Generic movie functions
void playMovieBlocking(const Common::String &filename, uint16 x, uint16 y);
void playMovieBlockingCentered(const Common::String &filename);
VideoEntryPtr playMovie(const Common::String &filename);
VideoEntryPtr playMovie(uint16 id);
bool updateMovies();
void pauseVideos();
void resumeVideos();
void stopVideos();
bool isVideoPlaying();
// Handle functions
VideoEntryPtr findVideo(uint16 id);
VideoEntryPtr findVideo(const Common::String &fileName);
void waitUntilMovieEnds(const VideoEntryPtr &video);
void drawVideoFrame(const VideoEntryPtr &video, const Audio::Timestamp &time);
protected:
MohawkEngine *_vm;
// Keep tabs on any videos playing
typedef Common::List<VideoEntryPtr> VideoList;
VideoList _videos;
// Utility functions for managing entries
VideoEntryPtr open(uint16 id);
VideoEntryPtr open(const Common::String &fileName);
VideoList::iterator findEntry(VideoEntryPtr ptr);
void removeEntry(VideoEntryPtr ptr);
bool drawNextFrame(VideoEntryPtr videoEntry);
// Dithering control
bool _enableDither;
void checkEnableDither(VideoEntryPtr &entry);
};
} // End of namespace Mohawk
#endif
|