Gnash  0.8.11dev
Player.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010,
3 // 2011 Free Software 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 //
19 
20 #ifndef GNASH_PLAYER_H
21 #define GNASH_PLAYER_H
22 
23 #ifdef HAVE_CONFIG_H
24 #include "gnashconfig.h"
25 #endif
26 
27 #include <boost/intrusive_ptr.hpp>
28 #include <string>
29 #include <boost/shared_ptr.hpp>
30 #include <map>
31 #include <memory>
32 
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"
39 
40 // Forward declarations
41 namespace gnash {
42  class MovieClip;
43 }
44 
45 namespace gnash {
46 
52 class Player
53 {
54 public:
55 
56  Player();
57 
58  ~Player();
59 
61  //
74  void run(int argc, char* argv[],
75  const std::string& infile, const std::string& url = "");
76 
77  float setScale(float s);
78 
79  // milliseconds per frame
80  void setDelay(unsigned int d) { _delay=d; }
81 
82 #ifdef GNASH_FPS_DEBUG
83 
84  //
90  void setFpsPrintTime(float time)
91  {
92  assert(time >= 0.0);
93  _fpsDebugTime = time;
94  }
95 #endif // def GNASH_FPS_DEBUG
96 
97  void setWidth(size_t w) { _width = w; }
98  size_t getWidth() const { return _width; }
99 
100  void setHeight(size_t h) { _height = h; }
101  size_t getHeight() const { return _height; }
102 
103  void setXPosition(int xPos) { _xPosition = xPos; }
104  size_t getXPosition() const { return _xPosition; }
105 
106  void setYPosition(int yPos) { _yPosition = yPos; }
107  size_t getYPosition() const { return _yPosition; }
108 
109  void setWindowId(unsigned long x) { _windowID = x; }
110 
111  void setDoLoop(bool b) { _doLoop = b; }
112 
113  void setDoRender(bool b) { _doRender = b; }
114 
115  void setDoSound(bool b) { _doSound = b; }
116 
117  void setMaxAdvances(unsigned long ul) { if (ul > 0) _maxAdvances = ul; }
118 
120  //
124  void setBaseUrl(const std::string& baseurl) {
125  _baseurl = baseurl;
126  }
127 
128  float setExitTimeout(float n) {
129  float oldtimeout = _exitTimeout;
130  _exitTimeout = n;
131  return oldtimeout;
132  }
133 
134  void setParam(const std::string& name, const std::string& value) {
135  _params[name] = value;
136  }
137 
138  void setHostFD(int fd) {
139  _hostfd = fd;
140  }
141 
142  int getHostFD() const {
143  return _hostfd;
144  }
145 
146  void setMedia(const std::string& media) {
147  _media = media;
148  }
149 
150  void setControlFD(int fd) {
151  _controlfd = fd;
152  }
153 
154  int getControlFD() const {
155  return _controlfd;
156  }
157 
158  void setStartFullscreen(bool x) {
159  _startFullscreen = x;
160  }
161 
162  void hideMenu(bool x) {
163  _hideMenu = x;
164  }
165 
166  void setAudioDumpfile(const std::string& filespec) {
167  _audioDump = filespec;
168  }
169 
173  void setRenderer(const std::string& x) { _renderer = x; }
174 
178  void setHWAccel(const std::string& x) { _hwaccel = x; }
179 
181  //
183  //
186  void setScreenShots(const std::string& screenshots) {
187  _screenshots = screenshots;
188  }
189 
191  //
193  void setScreenShotFile(const std::string& file) {
194  _screenshotFile = file;
195  }
196 
198  //
200  void setScreenShotQuality(int quality) {
201  _screenshotQuality = quality;
202  }
203 
204 private:
205 
209  std::string _hwaccel;
210 
214  std::string _renderer;
215 
216  class CallbacksHandler : public HostInterface, public FsCallback
217  {
218  public:
219  CallbacksHandler(Gui& gui, const Player& player)
220  :
221  _gui(gui),
222  _player(player)
223  {
224  }
225 
226  boost::any call(const HostInterface::Message& e);
227 
228  void exit();
229 
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);
235 
236  private:
237 
238  Gui& _gui;
239 
240  const Player& _player;
241  };
242 
243  std::auto_ptr<CallbacksHandler> _callbacksHandler;
244 
245  void init();
246 
261  static unsigned int silentStream(void* udata, boost::int16_t* stream,
262  unsigned int len, bool& atEOF);
263 
264  void init_sound();
265 
266  void init_logfile();
267 
268  void init_gui();
269 
271  //
274  std::auto_ptr<Gui> getGui();
275 
276  void setFlashVars(const std::string& varstr);
277 
278  typedef std::map<std::string, std::string, StringNoCaseLessThan> Params;
279 
280  // Movie parameters (for -P)
281  Params _params;
282 
283  // the scale at which to play
284  float _scale;
285  unsigned int _delay;
286  size_t _width;
287  size_t _height;
288  int _xPosition;
289  int _yPosition;
290  unsigned long _windowID;
291  bool _doLoop;
292  bool _doRender;
293  bool _doSound;
294  float _exitTimeout;
295  std::string _baseurl;
296 
298  //
304  //
308  //
312  boost::shared_ptr<sound::sound_handler> _soundHandler;
313 
314  boost::shared_ptr<media::MediaHandler> _mediaHandler;
315 
317  //
320  std::auto_ptr<RunResources> _runResources;
321 
323  std::auto_ptr<Gui> _gui;
324 
325  std::string _url;
326 
327  std::string _infile;
328 
329  boost::intrusive_ptr<movie_definition> _movieDef;
330 
331  unsigned long _maxAdvances;
332 
334  //
339  boost::intrusive_ptr<movie_definition> load_movie();
340 
341 #ifdef GNASH_FPS_DEBUG
342  float _fpsDebugTime;
343 #endif
344 
345  // Filedescriptor to use for host application requests, -1 if none
346  int _hostfd;
347 
348  int _controlfd;
349 
350  // Whether to start Gnash in fullscreen mode.
351  // (Or what did you think it meant?)
352  bool _startFullscreen;
353  bool _hideMenu;
354 
356  std::string _audioDump;
357 
359  //
361  std::string _screenshots;
362 
364  //
366  std::string _screenshotFile;
367 
369  //
371  int _screenshotQuality;
372 
374  //
376  std::string _media;
377 
378 };
379 
380 } // end of gnash namespace
381 
382 // end of _PLAYER_H_
383 #endif
384 
385 // local Variables:
386 // mode: C++
387 // indent-tabs-mode: nil
388 // End: