Make parseInvoke more robust when <invoke> tag isn't closed. Test that.
[gnash.git] / gui / Player.h
blob131a14351d2b60e4c6a2857869f5819cffefeafe
1 //
2 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software
3 // Foundation, Inc
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 //
20 #ifndef GNASH_PLAYER_H
21 #define GNASH_PLAYER_H
23 #ifdef HAVE_CONFIG_H
24 #include "gnashconfig.h"
25 #endif
27 #include <boost/intrusive_ptr.hpp>
28 #include <string>
29 #include <boost/shared_ptr.hpp>
30 #include <map>
31 #include <memory>
33 #include "sound_handler.h"
34 #include "MediaHandler.h"
35 #include "gui.h"
36 #include "movie_definition.h"
37 #include "movie_root.h"
38 #include "RunResources.h"
40 // Forward declarations
41 namespace gnash {
42 class MovieClip;
45 namespace gnash {
47 /// This class is an attempt at simplifying the code required
48 /// to simply start the SWF player. The idea was to use it
49 /// from the plugin so we can set callback for getUrl and fs_commands
50 /// w/out the need of using FIFOs or sockets or whatever else.
51 ///
52 class Player
54 public:
56 Player();
58 ~Player();
60 /// Play the movie at the given url/path.
62 /// @param argc
63 /// number of argument strings in argv
64 ///
65 /// @param argv
66 /// argument strings
67 ///
68 /// @param url
69 /// an optional url to assign to the given movie.
70 /// if unspecified the url will be set to the
71 /// movie path/url.
72 ///
73 ///
74 void run(int argc, char* argv[],
75 const std::string& infile, const std::string& url = "");
77 float setScale(float s);
79 // milliseconds per frame
80 void setDelay(unsigned int d) { _delay=d; }
82 #ifdef GNASH_FPS_DEBUG
83 /// Set the number of seconds between FPS debugging prints
85 /// @param time
86 /// Number of seconds between FPS debugging prints.
87 /// A value of 0 disables FPS printing.
88 /// A negative value results in an assertion failure.
89 ///
90 void setFpsPrintTime(float time)
92 assert(time >= 0.0);
93 _fpsDebugTime = time;
95 #endif // def GNASH_FPS_DEBUG
97 void setWidth(size_t w) { _width = w; }
98 size_t getWidth() const { return _width; }
100 void setHeight(size_t h) { _height = h; }
101 size_t getHeight() const { return _height; }
103 void setXPosition(int xPos) { _xPosition = xPos; }
104 size_t getXPosition() const { return _xPosition; }
106 void setYPosition(int yPos) { _yPosition = yPos; }
107 size_t getYPosition() const { return _yPosition; }
109 void setWindowId(unsigned long x) { _windowID = x; }
111 void setDoLoop(bool b) { _doLoop = b; }
113 void setDoRender(bool b) { _doRender = b; }
115 void setDoSound(bool b) { _doSound = b; }
117 void setMaxAdvances(unsigned long ul) { if (ul > 0) _maxAdvances = ul; }
119 /// Set the base url for this run.
121 /// The base url will be used to resolve relative
122 /// urls on load requests.
124 void setBaseUrl(const std::string& baseurl) {
125 _baseurl = baseurl;
128 float setExitTimeout(float n) {
129 float oldtimeout = _exitTimeout;
130 _exitTimeout = n;
131 return oldtimeout;
134 void setParam(const std::string& name, const std::string& value) {
135 _params[name] = value;
138 void setHostFD(int fd) {
139 _hostfd = fd;
142 int getHostFD() const {
143 return _hostfd;
146 void setMedia(const std::string& media) {
147 _media = media;
150 void setControlFD(int fd) {
151 _controlfd = fd;
154 int getControlFD() const {
155 return _controlfd;
158 void setStartFullscreen(bool x) {
159 _startFullscreen = x;
162 void hideMenu(bool x) {
163 _hideMenu = x;
166 void setAudioDumpfile(const std::string& filespec) {
167 _audioDump = filespec;
170 /// Set the renderer backend, agg, opengl, or cairo. This is set
171 /// in the users gnashrc file, or can be overridden with the
172 /// --hwaccel option to gnash.
173 void setRenderer(const std::string& x) { _renderer = x; }
175 /// Set the hardware video accleration backend, none, vaapi, xv,
176 /// or cairo. This is set in the users gnashrc file, or can be
177 /// overridden with the --render-mode option to gnash.
178 void setHWAccel(const std::string& x) { _hwaccel = x; }
180 /// This should be a comma-separated list of frames.
182 /// Only numbers and the word "last" are valid.
184 /// We parse the string here rather than in gnash.cpp to avoid making
185 /// the interface to Player more complicated than it is already.
186 void setScreenShots(const std::string& screenshots) {
187 _screenshots = screenshots;
190 /// Set the filename for screenshot output.
192 /// A %f in the filename will be replaced with the frame number.
193 void setScreenShotFile(const std::string& file) {
194 _screenshotFile = file;
197 /// Set the quality for screenshot output.
199 /// A %f in the filename will be replaced with the frame number.
200 void setScreenShotQuality(int quality) {
201 _screenshotQuality = quality;
204 private:
206 /// Whether to ue HW video decoding support, no value means disabled.
207 /// The only currently supported values are: none, vaapi, or xv (omap)
208 /// support coming. The default is none,
209 std::string _hwaccel;
211 /// Which renderer backend to use, no value means use the default.
212 /// The currently supported values are agg, opengl, or cairo. AGG
213 /// being the default.
214 std::string _renderer;
216 class CallbacksHandler : public HostInterface, public FsCallback
218 public:
219 CallbacksHandler(Gui& gui, const Player& player)
221 _gui(gui),
222 _player(player)
226 boost::any call(const HostInterface::Message& e);
228 void exit();
230 // For handling notification callbacks from ActionScript.
231 // The callback is always sent to a hosting application
232 // (i.e. if a file descriptor is supplied). It is never
233 // acted on by Gnash when running as a plugin.
234 void notify(const std::string& event, const std::string& arg);
236 private:
238 Gui& _gui;
240 const Player& _player;
243 std::auto_ptr<CallbacksHandler> _callbacksHandler;
245 void init();
247 /// This aux streamer returns a silent audio stream
249 /// @param udata
250 /// Pointer to user-specific data
251 /// @param stream
252 /// Buffer into which method will put samples
253 /// @param len
254 /// Requested amount of samples to put
255 /// @param atEOF
256 /// Will always set to false, silent stream never ends ..
257 ///
258 /// @return always the len parameter value (silent stream never ends
259 /// and is always available)
261 static unsigned int silentStream(void* udata, boost::int16_t* stream,
262 unsigned int len, bool& atEOF);
264 void init_sound();
266 void init_logfile();
268 void init_gui();
270 /// Create the gui instance
272 /// Uses the USE_<guiname> macros to find out which one
274 std::auto_ptr<Gui> getGui();
276 void setFlashVars(const std::string& varstr);
278 typedef std::map<std::string, std::string, StringNoCaseLessThan> Params;
280 // Movie parameters (for -P)
281 Params _params;
282 unsigned int _bitDepth;
284 // the scale at which to play
285 float _scale;
286 unsigned int _delay;
287 size_t _width;
288 size_t _height;
289 int _xPosition;
290 int _yPosition;
291 unsigned long _windowID;
292 bool _doLoop;
293 bool _doRender;
294 bool _doSound;
295 float _exitTimeout;
296 std::string _baseurl;
298 /// Initialization / destruction order is important here.
300 /// some sound_samples are destroyed in the dtor of SWFMovieDefinition,
301 /// which is called by the Gui's dtor. This means that the RunResources
302 /// and sound::sound_handler must still be alive. Initializing them
303 /// later ensures that this is the case. It is still a good idea to
304 /// initialize _gui after _runResources.
306 /// Moreover, _movieDef (the SWFMovieDefinition) would also prevent
307 /// destruction of a SWFMovieDefinition if it is not initialized after
308 /// _gui, and probably result in a segfault.
310 /// @todo This is hairy, and the core should be sorted out so that
311 /// sound_sample knows about its sound::sound_handler without
312 /// needing a RunResources.
313 boost::shared_ptr<sound::sound_handler> _soundHandler;
315 boost::shared_ptr<media::MediaHandler> _mediaHandler;
317 /// Handlers (for sound etc) for a libcore run.
319 /// This must be kept alive for the entire lifetime of the movie_root
320 /// (currently: of the Gui).
321 std::auto_ptr<RunResources> _runResources;
323 /// This must be initialized after _runResources
324 std::auto_ptr<Gui> _gui;
326 std::string _url;
328 std::string _infile;
330 boost::intrusive_ptr<movie_definition> _movieDef;
332 unsigned long _maxAdvances;
334 /// Load the "_infile" movie setting its url to "_url"
336 /// This function takes care of interpreting _infile as
337 /// stdin when it equals "-". May throw a GnashException
338 /// on failure.
340 boost::intrusive_ptr<movie_definition> load_movie();
342 #ifdef GNASH_FPS_DEBUG
343 float _fpsDebugTime;
344 #endif
346 // Filedescriptor to use for host application requests, -1 if none
347 int _hostfd;
349 int _controlfd;
351 // Whether to start Gnash in fullscreen mode.
352 // (Or what did you think it meant?)
353 bool _startFullscreen;
354 bool _hideMenu;
356 /// The filename to use for dumping audio.
357 std::string _audioDump;
359 /// A comma-separated list of frames to output as screenshots.
361 /// If empty, no screenshots are required.
362 std::string _screenshots;
364 /// The filename to save screenshots to.
366 /// If empty, a default is used.
367 std::string _screenshotFile;
369 /// The filename to save screenshots to.
371 /// By default 100.
372 int _screenshotQuality;
374 /// The identifier for the media handler.
376 /// If empty, a default is used.
377 std::string _media;
381 } // end of gnash namespace
383 // end of _PLAYER_H_
384 #endif
386 // local Variables:
387 // mode: C++
388 // indent-tabs-mode: nil
389 // End: