Speech bubbles can point down right.
[scummvm-innocent.git] / graphics / video / video_player.h
blobeb02032b500866147f3df5dbda61e8b2d81e5128
1 /* ScummVM - Graphic Adventure Engine
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.
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
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.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 * $URL$
22 * $Id$
26 #ifndef GRAPHICS_VIDEO_PLAYER_H
27 #define GRAPHICS_VIDEO_PLAYER_H
29 #include "common/events.h"
30 #include "common/list.h"
31 #include "common/stream.h"
33 namespace Common {
34 class SeekableReadStream;
37 namespace Graphics {
39 /**
40 * Implementation of a generic video decoder
42 class VideoDecoder {
43 public:
44 VideoDecoder();
45 virtual ~VideoDecoder();
47 /**
48 * Returns the width of the video
49 * @return the width of the video
51 virtual int getWidth();
53 /**
54 * Returns the height of the video
55 * @return the height of the video
57 virtual int getHeight();
59 /**
60 * Returns the current frame number of the video
61 * @return the current frame number of the video
63 virtual int32 getCurFrame();
65 /**
66 * Returns the amount of frames in the video
67 * @return the amount of frames in the video
69 virtual int32 getFrameCount();
71 /**
72 * Returns the frame rate of the video
73 * @return the frame rate of the video
75 virtual int32 getFrameRate();
77 /**
78 * Returns the time to wait for each frame in 1/100 ms (to avoid rounding errors)
79 * @return the time to wait for each frame in 1/100 ms (to avoid rounding errors)
81 virtual int32 getFrameDelay();
83 /**
84 * Returns the current A/V lag in 1/100 ms (to avoid rounding errors)
85 * If > 0, audio lags behind
86 * If < 0, video lags behind
87 * @return the current A/V lag in 1/100 ms (to avoid rounding errors)
89 virtual int32 getAudioLag();
91 /**
92 * Returns the time to wait until the next frame in ms, minding any lag
93 * @return the time to wait until the next frame in ms
95 virtual uint32 getFrameWaitTime();
97 /**
98 * Load a video file
99 * @param filename the filename to load
101 virtual bool loadFile(const char *filename) = 0;
104 * Close a video file
106 virtual void closeFile() = 0;
109 * Returns if a video file is loaded or not
111 bool isVideoLoaded() { return (_fileStream != NULL); }
114 * Set RGB palette, based on current frame
115 * @param pal the RGB palette data
117 virtual void setPalette(byte *pal);
120 * Gets the value of the pixel at the specified x and y coordinates
121 * Note: This method assumes that the video's pitch equals its width, and that
122 * the video has an 8bpp palette
123 * @param x the x coordinate of the pixel
124 * @param y the y coordinate of the pixel
126 byte getPixel(int x, int y) {
127 return *(_videoFrameBuffer + y * _videoInfo.width + x * 1);
131 * Gets the value of the pixel at the specified offset
132 * @param offset the offset of the pixel in the video buffer
134 byte getPixel(int offset) { return getPixel(offset, 0); }
137 * Return the black palette color for the current frame
139 byte getBlack() { return _curFrameBlack; }
142 * Return the white palette color for the current frame
144 byte getWhite() { return _curFrameWhite; }
147 * Copy current frame into the specified position of the destination
148 * buffer.
149 * @param dst the buffer
150 * @param x the x position of the buffer
151 * @param y the y position of the buffer
152 * @param pitch the pitch of buffer
154 void copyFrameToBuffer(byte *dst, uint x, uint y, uint pitch);
157 * Decode the next frame to _videoFrameBuffer
159 virtual bool decodeNextFrame() = 0;
161 protected:
162 struct {
163 uint32 width;
164 uint32 height;
165 uint32 frameCount;
166 int32 frameRate;
167 int32 frameDelay; // 1/100 ms (to avoid rounding errors)
168 uint32 firstframeOffset;
169 uint32 currentFrame;
170 uint32 startTime;
171 } _videoInfo;
173 byte _curFrameBlack, _curFrameWhite;
175 Common::SeekableReadStream *_fileStream;
176 byte *_videoFrameBuffer;
179 class VideoPlayer {
180 public:
181 VideoPlayer(VideoDecoder* decoder) : _skipVideo(false), _decoder(decoder)
183 virtual ~VideoPlayer() { }
185 * A default implementation of a video player
186 * Plays a non-interactive full screen video till it's stopped by a
187 * specific event
188 * @param filename the name of the file to play
189 * @param stopEvents a list of events that can stop the video
191 * Returns true if the video was played to the end, false if skipped
193 bool playVideo(Common::List<Common::Event> &stopEvents);
195 protected:
197 * Perform postprocessing once the frame data is copied to the screen,
198 * right before the frame is drawn. Called by playVideo()
200 virtual void performPostProcessing(byte *screen);
202 bool _skipVideo;
203 VideoDecoder* _decoder;
205 void processVideoEvents(Common::List<Common::Event> &stopEvents);
208 } // End of namespace Graphics
210 #endif