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
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.
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, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 /*
24  * This file is based on WME Lite.
25  * http://dead-code.org/redir.php?target=wmelite
26  * Copyright (c) 2011 Jan Nedoma
27  */
28 
29 #ifndef WINTERMUTE_VIDTHEORAPLAYER_H
30 #define WINTERMUTE_VIDTHEORAPLAYER_H
31 
32 #include "engines/wintermute/base/base.h"
33 #include "engines/wintermute/persistent.h"
34 #include "engines/wintermute/video/video_subtitler.h"
35 #include "video/video_decoder.h"
36 #include "common/stream.h"
37 #include "graphics/surface.h"
38 
39 namespace Wintermute {
40 class BaseSurface;
41 class BaseImage;
42 class VideoTheoraPlayer : public BaseClass {
43 private:
44 	enum {
45 		THEORA_STATE_NONE = 0,
46 		THEORA_STATE_PLAYING = 1,
47 		THEORA_STATE_PAUSED = 2,
48 		THEORA_STATE_FINISHED = 3
49 	};
50 	Video::VideoDecoder *_theoraDecoder;
51 	Graphics::Surface _surface;
52 public:
53 	DECLARE_PERSISTENT(VideoTheoraPlayer, BaseClass)
54 
55 	VideoTheoraPlayer(BaseGame *inGame);
56 	virtual ~VideoTheoraPlayer(void);
57 
58 	// external objects
59 	Common::SeekableReadStream *_file;
60 	Common::String _filename;
61 
62 	BaseSurface *_texture;
63 	VideoSubtitler *_subtitler;
64 
65 	// control methods
66 	bool initialize(const Common::String &filename, const Common::String &subtitleFile = Common::String());
67 	bool initializeSimple();
68 	bool update();
69 	bool play(TVideoPlayback type = VID_PLAY_CENTER, int x = 0, int y = 0, bool freezeGame = false, bool freezeMusic = true, bool looping = false, uint32 startTime = 0, float forceZoom = -1.0f, int volume = -1);
70 	bool stop();
71 	bool display(uint32 alpha = 0xFFFFFFFF);
72 
73 	bool pause();
74 	bool resume();
75 
isPlaying()76 	bool isPlaying() const {
77 		return _state == THEORA_STATE_PLAYING;
78 	};
isFinished()79 	bool isFinished() const {
80 		return _state == THEORA_STATE_FINISHED;
81 	};
isPaused()82 	bool isPaused() const {
83 		return _state == THEORA_STATE_PAUSED;
84 	};
85 
86 	uint32 getMovieTime() const;
87 
88 	BaseSurface *getTexture() const;
89 
90 	// alpha related
91 	BaseImage *_alphaImage;
92 	Common::String _alphaFilename;
93 	bool setAlphaImage(const Common::String &filename);
94 	byte getAlphaAt(int x, int y) const;
95 	void writeAlpha();
96 
97 	bool seekToTime(uint32 Time);
98 
99 	void cleanup();
100 	bool resetStream();
101 
102 	// video properties
103 	int32 _posX;
104 	int32 _posY;
105 
106 	bool _dontDropFrames;
107 private:
108 	int32 _state;
109 	uint32 _startTime;
110 
111 	int32 _savedState;
112 	uint32 _savedPos;
113 
114 	// video properties
115 	TVideoPlayback _playbackType;
116 	bool _looping;
117 	float _playZoom;
118 	int32 _volume;
119 
120 	bool _freezeGame;
121 	uint32 _currentTime;
122 
123 	// seeking support
124 	bool _seekingKeyframe;
125 	float _timeOffset;
126 
127 	bool _frameRendered;
128 
getIsFrameReady()129 	bool getIsFrameReady() const {
130 		return _videoFrameReady;
131 	}
132 
133 	bool _audioFrameReady;
134 	bool _videoFrameReady;
135 	float _videobufTime;
136 
137 	bool writeVideo();
138 
139 	bool _playbackStarted;
140 
141 	bool _foundSubtitles;
142 
143 	// helpers
144 	void SetDefaults();
145 };
146 
147 } // End of namespace Wintermute
148 
149 #endif
150