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 "HostInterface.h" // for HostInterface, FsCallback, etc
28 #include "StringPredicates.h" // for StringNoCaseLessThan
29 #include "movie_definition.h"
30 
31 #include <boost/intrusive_ptr.hpp>
32 #include <string>
33 #include <boost/shared_ptr.hpp>
34 #include <map>
35 #include <memory>
36 
37 // Forward declarations
38 namespace gnash {
39  class MovieClip;
40  class RunResources;
41  class Gui;
42  namespace media {
43  class MediaHandler;
44  }
45  namespace sound {
46  class sound_handler;
47  }
48 }
49 
50 namespace gnash {
51 
57 class Player
58 {
59 public:
60 
61  Player();
62 
63  ~Player();
64 
66  //
79  void run(int argc, char* argv[],
80  const std::string& infile, const std::string& url = "");
81 
82  float setScale(float s);
83 
84  // milliseconds per frame
85  void setDelay(unsigned int d) { _delay=d; }
86 
87 #ifdef GNASH_FPS_DEBUG
88 
89  //
95  void setFpsPrintTime(float time)
96  {
97  assert(time >= 0.0);
98  _fpsDebugTime = time;
99  }
100 #endif // def GNASH_FPS_DEBUG
101 
102  void setWidth(size_t w) { _width = w; }
103  size_t getWidth() const { return _width; }
104 
105  void setHeight(size_t h) { _height = h; }
106  size_t getHeight() const { return _height; }
107 
108  void setXPosition(int xPos) { _xPosition = xPos; }
109  size_t getXPosition() const { return _xPosition; }
110 
111  void setYPosition(int yPos) { _yPosition = yPos; }
112  size_t getYPosition() const { return _yPosition; }
113 
114  void setWindowId(unsigned long x) { _windowID = x; }
115 
116  void setDoLoop(bool b) { _doLoop = b; }
117 
118  void setDoRender(bool b) { _doRender = b; }
119 
120  void setDoSound(bool b) { _doSound = b; }
121 
122  void setMaxAdvances(unsigned long ul) { if (ul > 0) _maxAdvances = ul; }
123 
125  //
129  void setBaseUrl(const std::string& baseurl) {
130  _baseurl = baseurl;
131  }
132 
133  float setExitTimeout(float n) {
134  float oldtimeout = _exitTimeout;
135  _exitTimeout = n;
136  return oldtimeout;
137  }
138 
139  void setParam(const std::string& name, const std::string& value) {
140  _params[name] = value;
141  }
142 
143  void setHostFD(int fd) {
144  _hostfd = fd;
145  }
146 
147  int getHostFD() const {
148  return _hostfd;
149  }
150 
151  void setMedia(const std::string& media) {
152  _media = media;
153  }
154 
155  void setControlFD(int fd) {
156  _controlfd = fd;
157  }
158 
159  int getControlFD() const {
160  return _controlfd;
161  }
162 
163  void setStartFullscreen(bool x) {
164  _startFullscreen = x;
165  }
166 
167  void hideMenu(bool x) {
168  _hideMenu = x;
169  }
170 
171  void setAudioDumpfile(const std::string& filespec) {
172  _audioDump = filespec;
173  }
174 
178  void setRenderer(const std::string& x) { _renderer = x; }
179 
183  void setHWAccel(const std::string& x) { _hwaccel = x; }
184 
186  //
188  //
191  void setScreenShots(const std::string& screenshots) {
192  _screenshots = screenshots;
193  }
194 
196  //
198  void setScreenShotFile(const std::string& file) {
199  _screenshotFile = file;
200  }
201 
203  //
205  void setScreenShotQuality(int quality) {
206  _screenshotQuality = quality;
207  }
208 
209 private:
210 
214  std::string _hwaccel;
215 
219  std::string _renderer;
220 
221  class CallbacksHandler : public HostInterface, public FsCallback
222  {
223  public:
224  CallbacksHandler(Gui& gui, const Player& player)
225  :
226  _gui(gui),
227  _player(player)
228  {
229  }
230 
231  boost::any call(const HostInterface::Message& e);
232 
233  void exit();
234 
235  // For handling notification callbacks from ActionScript.
236  // The callback is always sent to a hosting application
237  // (i.e. if a file descriptor is supplied). It is never
238  // acted on by Gnash when running as a plugin.
239  void notify(const std::string& event, const std::string& arg);
240 
241  private:
242 
243  Gui& _gui;
244 
245  const Player& _player;
246  };
247 
248  std::auto_ptr<CallbacksHandler> _callbacksHandler;
249 
250  void init();
251 
266  static unsigned int silentStream(void* udata, boost::int16_t* stream,
267  unsigned int len, bool& atEOF);
268 
269  void init_sound();
270 
271  void init_logfile();
272 
273  void init_gui();
274 
276  //
279  std::auto_ptr<Gui> getGui();
280 
281  void setFlashVars(const std::string& varstr);
282 
283  typedef std::map<std::string, std::string, StringNoCaseLessThan> Params;
284 
285  // Movie parameters (for -P)
286  Params _params;
287 
288  // the scale at which to play
289  float _scale;
290  unsigned int _delay;
291  size_t _width;
292  size_t _height;
293  int _xPosition;
294  int _yPosition;
295  unsigned long _windowID;
296  bool _doLoop;
297  bool _doRender;
298  bool _doSound;
299  float _exitTimeout;
300  std::string _baseurl;
301 
303  //
309  //
313  //
317  boost::shared_ptr<sound::sound_handler> _soundHandler;
318 
319  boost::shared_ptr<media::MediaHandler> _mediaHandler;
320 
322  //
325  std::auto_ptr<RunResources> _runResources;
326 
328  std::auto_ptr<Gui> _gui;
329 
330  std::string _url;
331 
332  std::string _infile;
333 
334  boost::intrusive_ptr<movie_definition> _movieDef;
335 
336  unsigned long _maxAdvances;
337 
339  //
344  boost::intrusive_ptr<movie_definition> load_movie();
345 
346 #ifdef GNASH_FPS_DEBUG
347  float _fpsDebugTime;
348 #endif
349 
350  // Filedescriptor to use for host application requests, -1 if none
351  int _hostfd;
352 
353  int _controlfd;
354 
355  // Whether to start Gnash in fullscreen mode.
356  // (Or what did you think it meant?)
357  bool _startFullscreen;
358  bool _hideMenu;
359 
361  std::string _audioDump;
362 
364  //
366  std::string _screenshots;
367 
369  //
371  std::string _screenshotFile;
372 
374  //
376  int _screenshotQuality;
377 
379  //
381  std::string _media;
382 
383 };
384 
385 } // end of gnash namespace
386 
387 // end of _PLAYER_H_
388 #endif
389 
390 // local Variables:
391 // mode: C++
392 // indent-tabs-mode: nil
393 // End: