Encode dependency on libboost-program-options-dev package
[gnash.git] / gui / Player.h
blob089f749fd19bed0323b267b0a89b8545d35e54ec
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 "sound_handler.h"
28 #include "MediaHandler.h"
29 #include "gui.h"
30 #include "movie_definition.h"
31 #include "movie_root.h"
32 #include "RunResources.h"
34 #include <boost/intrusive_ptr.hpp>
35 #include <string>
36 #include <boost/shared_ptr.hpp>
37 #include <map>
39 // Forward declarations
40 namespace gnash
42 class MovieClip;
46 namespace gnash
49 /// This class is an attempt at simplifying the code required
50 /// to simply start the SWF player. The idea was to use it
51 /// from the plugin so we can set callback for getUrl and fs_commands
52 /// w/out the need of using FIFOs or sockets or whatever else.
53 ///
54 class Player
56 public:
58 Player();
60 ~Player();
62 /// Play the movie at the given url/path.
64 /// @param argc
65 /// number of argument strings in argv
66 ///
67 /// @param argv
68 /// argument strings
69 ///
70 /// @param url
71 /// an optional url to assign to the given movie.
72 /// if unspecified the url will be set to the
73 /// movie path/url.
74 ///
75 ///
76 void run(int argc, char* argv[],
77 const std::string& infile, const std::string& url = "");
79 float setScale(float s);
81 // milliseconds per frame
82 void setDelay(unsigned int d) { _delay=d; }
84 #ifdef GNASH_FPS_DEBUG
85 /// Set the number of seconds between FPS debugging prints
87 /// @param time
88 /// Number of seconds between FPS debugging prints.
89 /// A value of 0 disables FPS printing.
90 /// A negative value results in an assertion failure.
91 ///
92 void setFpsPrintTime(float time)
94 assert(time >= 0.0);
95 _fpsDebugTime = time;
97 #endif // def GNASH_FPS_DEBUG
99 void setWidth(size_t w) { _width = w; }
100 size_t getWidth() { return _width; }
102 void setHeight(size_t h) { _height = h; }
103 size_t getHeight() { return _height; }
105 void setXPosition(int xPos) { _xPosition = xPos; }
106 size_t getXPosition() { return _xPosition; }
108 void setYPosition(int yPos) { _yPosition = yPos; }
109 size_t getYPosition() { return _yPosition; }
111 void setWindowId(unsigned long x) { _windowID = x; }
113 void setDoLoop(bool b) { _doLoop = b; }
115 void setDoRender(bool b) { _doRender = b; }
117 void setDoSound(bool b) { _doSound = b; }
119 void setMaxAdvances(unsigned long ul) { if (ul > 0) _maxAdvances = ul; }
121 /// Set the base url for this run.
123 /// The base url will be used to resolve relative
124 /// urls on load requests.
126 void setBaseUrl(const std::string& baseurl) {
127 _baseurl = baseurl;
130 float setExitTimeout(float n) {
131 float oldtimeout = _exitTimeout;
132 _exitTimeout = n;
133 return oldtimeout;
136 void setParam(std::string& name, std::string& value) {
137 _params[name] = value;
140 void setHostFD(int fd) {
141 _hostfd = fd;
144 int getHostFD() const {
145 return _hostfd;
148 void setMedia(const std::string& media) {
149 _media = media;
152 void setControlFD(int fd) {
153 _controlfd = fd;
156 int getControlFD() const {
157 return _controlfd;
160 void setStartFullscreen(bool x) {
161 _startFullscreen = x;
164 void hideMenu(bool x) {
165 _hideMenu = x;
168 void setAudioDumpfile(const std::string& filespec) {
169 _audioDump = filespec;
172 /// Set the renderer backend, agg, opengl, or cairo. This is set
173 /// in the users gnashrc file, or can be overridden with the
174 /// --hwaccel option to gnash.
175 void setRenderer(const std::string& x) { _renderer = x; }
177 /// Set the hardware video accleration backend, none, vaapi, xv,
178 /// or cairo. This is set in the users gnashrc file, or can be
179 /// overridden with the --render-mode option to gnash.
180 void setHWAccel(const std::string& x) { _hwaccel = x; }
182 /// This should be a comma-separated list of frames.
184 /// Only numbers and the word "last" are valid.
186 /// We parse the string here rather than in gnash.cpp to avoid making
187 /// the interface to Player more complicated than it is already.
188 void setScreenShots(const std::string& screenshots) {
189 _screenshots = screenshots;
192 /// Set the filename for screenshot output.
194 /// A %f in the filename will be replaced with the frame number.
195 void setScreenShotFile(const std::string& file) {
196 _screenshotFile = file;
199 private:
201 /// Whether to ue HW video decoding support, no value means disabled.
202 /// The only currently supported values are: none, vaapi, or xv (omap)
203 /// support coming. The default is none,
204 std::string _hwaccel;
206 /// Which renderer backend to use, no value means use the default.
207 /// The currently supported values are agg, opengl, or cairo. AGG
208 /// being the default.
209 std::string _renderer;
211 class CallbacksHandler : public movie_root::AbstractIfaceCallback,
212 public movie_root::AbstractFsCallback
214 public:
215 CallbacksHandler(Gui& gui, const Player& player)
217 _gui(gui),
218 _player(player)
222 std::string call(const std::string& event,
223 const std::string& arg);
225 bool yesNo(const std::string& query);
227 void error(const std::string& msg);
229 void exit();
231 // For handling notification callbacks from ActionScript.
232 // The callback is always sent to a hosting application
233 // (i.e. if a file descriptor is supplied). It is never
234 // acted on by Gnash when running as a plugin.
235 void notify(const std::string& event, const std::string& arg);
237 private:
239 Gui& _gui;
241 const Player& _player;
244 std::auto_ptr<CallbacksHandler> _callbacksHandler;
246 void init();
248 /// This aux streamer returns a silent audio stream
250 /// @param udata
251 /// Pointer to user-specific data
252 /// @param stream
253 /// Buffer into which method will put samples
254 /// @param len
255 /// Requested amount of samples to put
256 /// @param atEOF
257 /// Will always set to false, silent stream never ends ..
258 ///
259 /// @return always the len parameter value (silent stream never ends
260 /// and is always available)
262 static unsigned int silentStream(void* udata, boost::int16_t* stream,
263 unsigned int len, bool& atEOF);
265 void init_sound();
267 void init_logfile();
269 void init_gui();
271 /// Create the gui instance
273 /// Uses the USE_<guiname> macros to find out which one
275 std::auto_ptr<Gui> getGui();
277 void setFlashVars(const std::string& varstr);
279 typedef std::map<std::string, std::string, StringNoCaseLessThan> Params;
281 // Movie parameters (for -P)
282 Params _params;
283 unsigned int _bitDepth;
285 // the scale at which to play
286 float _scale;
287 unsigned int _delay;
288 size_t _width;
289 size_t _height;
290 int _xPosition;
291 int _yPosition;
292 unsigned long _windowID;
293 bool _doLoop;
294 bool _doRender;
295 bool _doSound;
296 float _exitTimeout;
297 std::string _baseurl;
299 /// Initialization / destruction order is important here.
301 /// some sound_samples are destroyed in the dtor of SWFMovieDefinition,
302 /// which is called by the Gui's dtor. This means that the RunResources
303 /// and sound::sound_handler must still be alive. Initializing them
304 /// later ensures that this is the case. It is still a good idea to
305 /// initialize _gui after _runResources.
307 /// Moreover, _movieDef (the SWFMovieDefinition) would also prevent
308 /// destruction of a SWFMovieDefinition if it is not initialized after
309 /// _gui, and probably result in a segfault.
311 /// @todo This is hairy, and the core should be sorted out so that
312 /// sound_sample knows about its sound::sound_handler without
313 /// needing a RunResources.
314 boost::shared_ptr<sound::sound_handler> _soundHandler;
316 boost::shared_ptr<media::MediaHandler> _mediaHandler;
318 /// Handlers (for sound etc) for a libcore run.
320 /// This must be kept alive for the entire lifetime of the movie_root
321 /// (currently: of the Gui).
322 std::auto_ptr<RunResources> _runResources;
324 /// This must be initialized after _runResources
325 std::auto_ptr<Gui> _gui;
327 std::string _url;
329 std::string _infile;
331 boost::intrusive_ptr<movie_definition> _movieDef;
333 unsigned long _maxAdvances;
335 /// Load the "_infile" movie setting its url to "_url"
337 /// This function takes care of interpreting _infile as
338 /// stdin when it equals "-". May throw a GnashException
339 /// on failure.
341 boost::intrusive_ptr<movie_definition> load_movie();
343 #ifdef GNASH_FPS_DEBUG
344 float _fpsDebugTime;
345 #endif
347 // Filedescriptor to use for host application requests, -1 if none
348 int _hostfd;
350 int _controlfd;
352 // Whether to start Gnash in fullscreen mode.
353 // (Or what did you think it meant?)
354 bool _startFullscreen;
355 bool _hideMenu;
357 /// The filename to use for dumping audio.
358 std::string _audioDump;
360 /// A comma-separated list of frames to output as screenshots.
362 /// If empty, no screenshots are required.
363 std::string _screenshots;
365 /// The filename to save screenshots to.
367 /// If empty, a default is used.
368 std::string _screenshotFile;
370 /// The identifier for the media handler.
372 /// If empty, a default is used.
373 std::string _media;
377 } // end of gnash namespace
379 // end of _PLAYER_H_
380 #endif
382 // local Variables:
383 // mode: C++
384 // indent-tabs-mode: nil
385 // End: