ScummVM API documentation
videoplayer.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  *
21  * This file is dual-licensed.
22  * In addition to the GPLv3 license mentioned above, this code is also
23  * licensed under LGPL 2.1. See LICENSES/COPYING.LGPL file for the
24  * full text of the license.
25  *
26  */
27 
28 #ifndef GOB_VIDEOPLAYER_H
29 #define GOB_VIDEOPLAYER_H
30 
31 #include "common/array.h"
32 #include "common/list.h"
33 #include "common/rect.h"
34 #include "common/str.h"
35 
36 #include "graphics/surface.h"
37 
38 #include "gob/util.h"
39 #include "gob/draw.h"
40 
41 namespace Video {
42 class CoktelDecoder;
43 }
44 
45 namespace Gob {
46 
47 class GobEngine;
48 class DataStream;
49 
50 class VideoPlayer {
51 public:
52  enum Flags {
53  kFlagNone = 0x000000,
54  kFlagUseBackSurfaceContentOrDoubleVideo = 0x000040,
55  // In later version of the engine, this 0x40 flag indicates instead that the video should be doubled.
56  kFlagFrontSurface = 0x000080,
57  kFlagNoVideo = 0x000100,
58  kFlagOtherSurface = 0x000800,
59  kFlagScreenSurface = 0x400000
60  };
61 
63  enum Type {
64  kVideoTypeTry = -1,
65  kVideoTypeIMD = 0,
66  kVideoTypePreIMD = 1,
67  kVideoTypeVMD = 2,
68  kVideoTypeRMD = 3
69  };
70 
71  struct Properties {
73 
74  int sprite;
75 
76  int32 x;
77  int32 y;
78  int32 width;
79  int32 height;
80 
81  uint32 flags;
82 
84 
85  int32 startFrame;
86  int32 lastFrame;
87  int32 endFrame;
88 
89  bool forceSeek;
90 
91  int16 breakKey;
92 
93  uint16 palCmd;
94  int16 palStart;
95  int16 palEnd;
96  int32 palFrame;
97 
98  bool noBlock;
99 
100  bool loop;
101  bool fade;
102 
104 
105  bool hasSound;
106  bool canceled;
107 
108  int slot;
109  bool reuseSlotWitSameFilename;
110 
111  bool noWaitSound;
112 
113  Properties();
114  };
115 
116  VideoPlayer(GobEngine *vm);
117  ~VideoPlayer();
118 
119  void evaluateFlags(Properties &properties);
120 
121  int openVideo(bool primary, const Common::String &file, Properties &properties);
122  bool closeVideo(int slot = 0);
123 
124  void closeLiveVideos();
125  void closeAll();
126 
127  bool reopenVideo(int slot = 0);
128  bool reopenAll();
129 
130  void pauseVideo(int slot, bool pause);
131  void pauseAll(bool pause);
132 
133  void finishVideoSound(int slot);
134  void waitSoundEnd(int slot);
135 
136  bool play(int slot, Properties &properties);
137  void waitEndFrame(int slot, bool onlySound = false);
138  int32 getExpectedFrameFromCurrentTime(int slot);
139 
140  bool isPlayingLive() const;
141  bool isSoundPlaying() const;
142 
143  void updateVideos(bool force = false, int exceptSlot = -1);
144  void liveVideosLoop();
145 
146  bool slotIsOpen(int slot = 0) const;
147 
148  Common::String getFileName(int slot = 0) const;
149 
150  uint32 getFrameCount (int slot = 0) const;
151  uint32 getCurrentFrame (int slot = 0) const;
152  uint16 getWidth (int slot = 0) const;
153  uint16 getHeight (int slot = 0) const;
154  uint16 getDefaultX (int slot = 0) const;
155  uint16 getDefaultY (int slot = 0) const;
156  uint32 getFlags (int slot = 0) const;
157  uint16 getSoundFlags (int slot = 0) const;
158  uint32 getVideoBufferSize(int slot = 0) const;
159  bool hasVideo (int slot = 0) const;
160 
161 
162  bool getFrameCoords(int slot, int16 frame, int16 &x, int16 &y, int16 &width, int16 &height) const;
163 
164  const Common::List<Common::Rect> *getDirtyRects(int slot = 0) const;
165 
166  bool hasEmbeddedFile(const Common::String &fileName, int slot = 0) const;
167  Common::SeekableReadStream *getEmbeddedFile(const Common::String &fileName, int slot = 0);
168 
169  int32 getSubtitleIndex(int slot = 0) const;
170 
171  void writeVideoInfo(const Common::String &file, uint16 varX, uint16 varY,
172  uint16 varFrames, uint16 varWidth, uint16 varHeight);
173 
174  bool copyFrame(int slot, Surface &dest,
175  uint16 left, uint16 top, uint16 width, uint16 height, uint16 x, uint16 y,
176  int32 transp = -1, bool yAxisReflexion = false) const;
177 
178 private:
179  struct Video {
180  ::Video::CoktelDecoder *decoder;
181  Common::String fileName;
182 
183  SurfacePtr surface;
184  SurfacePtr tmpSurfDouble;
185  int16 doubleVideoDestX;
186  int16 doubleVideoDestY;
187  Common::SharedPtr<Graphics::Surface> tmpSurfBppConversion;
188  uint32 *highColorMap;
189 
190  Properties properties;
191 
192  bool doubleVideo;
193  bool live;
194  bool autoUpdate;
195 
196  Video();
197 
198  bool isEmpty() const;
199  void close();
200 
201  void reopen();
202  };
203 
204  static const int kVideoSlotCount = 32;
205  static const int kPrimaryVideoSlot = 0;
206  static const int kLiveVideoSlotCount = 6;
207  static const int kVideoSlotWithCurFrameVarCount = 4;
208 
209  static const char *const _extensions[];
210 
211  GobEngine *_vm;
212 
213  // _videoSlots[0] is reserved for the "primary" video
214  Video _videoSlots[kVideoSlotCount];
215 
216  bool _needBlit;
217 
218  bool _noCursorSwitch;
219  bool _woodruffCohCottWorkaround;
220  uint32 _lastLiveVideosLoopCall;
221 
222 
223  const Video *getVideoBySlot(int slot) const;
224  Video *getVideoBySlot(int slot);
225 
226  int getNextFreeSlot();
227 
228  Common::String findFile(const Common::String &file, Properties &properties);
229 
230  ::Video::CoktelDecoder *openVideo(const Common::String &file, Properties &properties);
231 
232  bool reopenVideo(Video &video);
233 
234  bool lastFrameReached(Video &video, Properties &properties);
235  bool playFrame(int slot, Properties &properties);
236 
237  void checkAbort(Video &video, Properties &properties);
238  void evalBgShading(Video &video);
239 
240  void copyPalette(const Video &video, int16 palStart, int16 palEnd);
241 
242  void updateVideo(int slot, bool force = false);
243 };
244 
245 } // End of namespace Gob
246 
247 #endif // GOB_VIDEOPLAYER_H
int32 x
X coordinate of the video.
Definition: videoplayer.h:76
int slot
Explicit slot index (-1 = auto).
Definition: videoplayer.h:108
Definition: gob.h:166
Definition: str.h:59
bool noBlock
Non-blocking "live" video?
Definition: videoplayer.h:98
int32 y
Y coordinate of the video.
Definition: videoplayer.h:77
int32 lastFrame
Frame to stop playback at.
Definition: videoplayer.h:86
int16 breakKey
Keycode of the break/abort key.
Definition: videoplayer.h:91
int32 startFrame
Frame to start playback from.
Definition: videoplayer.h:85
Definition: stream.h:745
Flags
Definition: videoplayer.h:52
Type type
Type of the video to open.
Definition: videoplayer.h:72
Definition: anifile.h:40
bool hasSound
Does the video have sound?
Definition: videoplayer.h:105
int32 width
Width of the video.
Definition: videoplayer.h:78
bool switchColorMode
Switch between paletted / true color modes?
Definition: videoplayer.h:83
bool canceled
Was the video canceled?
Definition: videoplayer.h:106
int16 palEnd
Palette entry to end at.
Definition: videoplayer.h:95
int16 palStart
Palette entry to start with.
Definition: videoplayer.h:94
bool waitEndFrame
Wait for the frame&#39;s time to run out?
Definition: videoplayer.h:103
int32 palFrame
Frame to apply the palette command at.
Definition: videoplayer.h:96
Type
Definition: videoplayer.h:63
Definition: surface.h:106
Definition: videoplayer.h:71
int sprite
The sprite onto which to draw the video.
Definition: videoplayer.h:74
uint16 palCmd
Palette command.
Definition: videoplayer.h:93
bool fade
Fade in?
Definition: videoplayer.h:101
uint32 flags
Video flags.
Definition: videoplayer.h:81
Definition: animation.h:37
bool forceSeek
Force the seeking to the start frame.
Definition: videoplayer.h:89
int32 endFrame
Last frame of this playback cycle.
Definition: videoplayer.h:87
int32 height
Height of the video.
Definition: videoplayer.h:79
bool loop
Loop the video?
Definition: videoplayer.h:100
Definition: videoplayer.h:50