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 #include "NetworkAdapter.h" // for setCookiesIn
31 
32 #include <boost/intrusive_ptr.hpp>
33 #include <string>
34 #include <boost/shared_ptr.hpp>
35 #include <map>
36 #include <memory>
37 
38 // Forward declarations
39 namespace gnash {
40  class MovieClip;
41  class RunResources;
42  class Gui;
43  namespace media {
44  class MediaHandler;
45  }
46  namespace sound {
47  class sound_handler;
48  }
49 }
50 
51 namespace gnash {
52 
58 class Player
59 {
60 public:
61 
62  Player();
63 
64  ~Player();
65 
67  //
80  void run(int argc, char* argv[],
81  const std::string& infile, const std::string& url = "");
82 
83  float setScale(float s);
84 
85  // milliseconds per frame
86  void setDelay(unsigned int d) { _delay=d; }
87 
88 #ifdef GNASH_FPS_DEBUG
89  //
96  void setFpsPrintTime(float time)
97  {
98  assert(time >= 0.0);
99  _fpsDebugTime = time;
100  }
101 #endif // def GNASH_FPS_DEBUG
102 
103  void setWidth(size_t w) { _width = w; }
104  size_t getWidth() const { return _width; }
105 
106  void setHeight(size_t h) { _height = h; }
107  size_t getHeight() const { return _height; }
108 
109  void setXPosition(int xPos) { _xPosition = xPos; }
110  size_t getXPosition() const { return _xPosition; }
111 
112  void setYPosition(int yPos) { _yPosition = yPos; }
113  size_t getYPosition() const { return _yPosition; }
114 
115  void setWindowId(unsigned long x) { _windowID = x; }
116 
117  void setDoLoop(bool b) { _doLoop = b; }
118 
119  void setDoRender(bool b) { _doRender = b; }
120 
121  void setDoSound(bool b) { _doSound = b; }
122 
123  void setMaxAdvances(unsigned long ul) { if (ul > 0) _maxAdvances = ul; }
124 
126  //
130  void setBaseUrl(const std::string& baseurl) {
131  _baseurl = baseurl;
132  }
133 
134  float setExitTimeout(float n) {
135  float oldtimeout = _exitTimeout;
136  _exitTimeout = n;
137  return oldtimeout;
138  }
139 
140  void setParam(const std::string& name, const std::string& value) {
141  _params[name] = value;
142  }
143 
144  void setHostFD(int fd) {
145  _hostfd = fd;
146  }
147 
148  int getHostFD() const {
149  return _hostfd;
150  }
151 
152  void setMedia(const std::string& media) {
153  _media = media;
154  }
155 
156  void setControlFD(int fd) {
157  _controlfd = fd;
158  }
159 
160  int getControlFD() const {
161  return _controlfd;
162  }
163 
164  void setCookiesIn(const std::string& filename) {
166  }
167 
168  void setStartFullscreen(bool x) {
169  _startFullscreen = x;
170  }
171 
172  void hideMenu(bool x) {
173  _hideMenu = x;
174  }
175 
176  void setAudioDumpfile(const std::string& filespec) {
177  _audioDump = filespec;
178  }
179 
183  void setRenderer(const std::string& x) { _renderer = x; }
184 
188  void setHWAccel(const std::string& x) { _hwaccel = x; }
189 
191  //
193  //
196  void setScreenShots(const std::string& screenshots) {
197  _screenshots = screenshots;
198  }
199 
201  //
203  void setScreenShotFile(const std::string& file) {
204  _screenshotFile = file;
205  }
206 
208  //
210  void setScreenShotQuality(int quality) {
211  _screenshotQuality = quality;
212  }
213 
214 private:
215 
219  std::string _hwaccel;
220 
224  std::string _renderer;
225 
226  class CallbacksHandler : public HostInterface, public FsCallback
227  {
228  public:
229  CallbacksHandler(Gui& gui, const Player& player)
230  :
231  _gui(gui),
232  _player(player)
233  {
234  }
235 
236  boost::any call(const HostInterface::Message& e);
237 
238  void exit();
239 
240  // For handling notification callbacks from ActionScript.
241  // The callback is always sent to a hosting application
242  // (i.e. if a file descriptor is supplied). It is never
243  // acted on by Gnash when running as a plugin.
244  void notify(const std::string& event, const std::string& arg);
245 
246  private:
247 
248  Gui& _gui;
249 
250  const Player& _player;
251  };
252 
253  std::auto_ptr<CallbacksHandler> _callbacksHandler;
254 
255  void init();
256 
271  static unsigned int silentStream(void* udata, boost::int16_t* stream,
272  unsigned int len, bool& atEOF);
273 
274  void init_sound();
275 
276  void init_logfile();
277 
278  void init_gui();
279 
281  //
284  std::auto_ptr<Gui> getGui();
285 
286  void setFlashVars(const std::string& varstr);
287 
288  typedef std::map<std::string, std::string, StringNoCaseLessThan> Params;
289 
290  // Movie parameters (for -P)
291  Params _params;
292 
293  // the scale at which to play
294  float _scale;
295  unsigned int _delay;
296  size_t _width;
297  size_t _height;
298  int _xPosition;
299  int _yPosition;
300  unsigned long _windowID;
301  bool _doLoop;
302  bool _doRender;
303  bool _doSound;
304  float _exitTimeout;
305  std::string _baseurl;
306 
308  //
314  //
318  //
322  boost::shared_ptr<sound::sound_handler> _soundHandler;
323 
324  boost::shared_ptr<media::MediaHandler> _mediaHandler;
325 
327  //
330  std::auto_ptr<RunResources> _runResources;
331 
333  std::auto_ptr<Gui> _gui;
334 
335  std::string _url;
336 
337  std::string _infile;
338 
339  boost::intrusive_ptr<movie_definition> _movieDef;
340 
341  unsigned long _maxAdvances;
342 
344  //
349  boost::intrusive_ptr<movie_definition> load_movie();
350 
351 #ifdef GNASH_FPS_DEBUG
352  float _fpsDebugTime;
353 #endif
354 
355  // Filedescriptor to use for host application requests, -1 if none
356  int _hostfd;
357 
358  int _controlfd;
359 
360  // Whether to start Gnash in fullscreen mode.
361  // (Or what did you think it meant?)
362  bool _startFullscreen;
363  bool _hideMenu;
364 
366  std::string _audioDump;
367 
369  //
371  std::string _screenshots;
372 
374  //
376  std::string _screenshotFile;
377 
379  //
381  int _screenshotQuality;
382 
384  //
386  std::string _media;
387 
388 };
389 
390 } // end of gnash namespace
391 
392 // end of _PLAYER_H_
393 #endif
394 
395 // local Variables:
396 // mode: C++
397 // indent-tabs-mode: nil
398 // End:
Player()
Definition: Player.cpp:194
void setWindowId(unsigned long x)
Definition: Player.h:115
void run(int argc, char *argv[], const std::string &infile, const std::string &url="")
Play the movie at the given url/path.
Definition: Player.cpp:377
void setHWAccel(const std::string &x)
Definition: Player.h:188
void setScreenShotFile(const std::string &file)
Set the filename for screenshot output.
Definition: Player.h:203
Definition: GnashKey.h:150
float setExitTimeout(float n)
Definition: Player.h:134
void setBaseUrl(const std::string &baseurl)
Set the base url for this run.
Definition: Player.h:130
SWFStream & s
Definition: DefineBitsTag.cpp:73
void setMaxAdvances(unsigned long ul)
Definition: Player.h:123
void setCookiesIn(const std::string &filename)
Definition: Player.h:164
void setControlFD(int fd)
Definition: Player.h:156
~Player()
Definition: Player.cpp:856
void setScreenShots(const std::string &screenshots)
This should be a comma-separated list of frames.
Definition: Player.h:196
void setRenderer(const std::string &x)
Definition: Player.h:183
Abstract base class for FS handlers.
Definition: HostInterface.h:199
void setXPosition(int xPos)
Definition: Player.h:109
boost::variant< HostMessage, CustomMessage > Message
Definition: HostInterface.h:213
size_t getWidth() const
Definition: Player.h:104
size_t getXPosition() const
Definition: Player.h:110
void hideMenu(bool x)
Definition: Player.h:172
static void setCookiesIn(const std::string &cookiesin)
Set CookiesIn variable to cookiefile path.
Definition: NetworkAdapter.h:96
size_t getHeight() const
Definition: Player.h:107
void setAudioDumpfile(const std::string &filespec)
Definition: Player.h:176
void setMedia(const std::string &media)
Definition: Player.h:152
void setHeight(size_t h)
Definition: Player.h:106
void setDelay(unsigned int d)
Definition: Player.h:86
Definition: GnashKey.h:160
Parent class from which all GUI implementations will depend.
Definition: gui.h:87
void setHostFD(int fd)
Definition: Player.h:144
float setScale(float s)
Definition: Player.cpp:221
The MediaHandler class acts as a factory to provide parser and decoders.
Definition: MediaHandler.h:68
void setWidth(size_t w)
Definition: Player.h:103
int getControlFD() const
Definition: Player.h:160
void setDoRender(bool b)
Definition: Player.h:119
void setScreenShotQuality(int quality)
Set the quality for screenshot output.
Definition: Player.h:210
int getHostFD() const
Definition: Player.h:148
boost::int32_t x
Definition: BitmapData_as.cpp:434
Definition: GnashKey.h:148
size_t getYPosition() const
Definition: Player.h:113
Definition: GnashKey.h:154
std::string url
Definition: gnash.cpp:59
Definition: GnashKey.h:151
Abstract base class for hosting app handler.
Definition: HostInterface.h:207
tuple w
Definition: test.py:8
void setStartFullscreen(bool x)
Definition: Player.h:168
void setDoSound(bool b)
Definition: Player.h:121
Definition: Player.h:58
void setDoLoop(bool b)
Definition: Player.h:117
std::string name
Definition: LocalConnection_as.cpp:151
void setYPosition(int yPos)
Definition: Player.h:112
void setParam(const std::string &name, const std::string &value)
Definition: Player.h:140