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 <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  //
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 setCookiesIn(const std::string& filename) {
165  }
166 
167  void setStartFullscreen(bool x) {
168  _startFullscreen = x;
169  }
170 
171  void hideMenu(bool x) {
172  _hideMenu = x;
173  }
174 
175  void setAudioDumpfile(const std::string& filespec) {
176  _audioDump = filespec;
177  }
178 
182  void setRenderer(const std::string& x) { _renderer = x; }
183 
187  void setHWAccel(const std::string& x) { _hwaccel = x; }
188 
190  //
192  //
195  void setScreenShots(const std::string& screenshots) {
196  _screenshots = screenshots;
197  }
198 
200  //
202  void setScreenShotFile(const std::string& file) {
203  _screenshotFile = file;
204  }
205 
207  //
209  void setScreenShotQuality(int quality) {
210  _screenshotQuality = quality;
211  }
212 
213 private:
214 
218  std::string _hwaccel;
219 
223  std::string _renderer;
224 
225  class CallbacksHandler : public HostInterface, public FsCallback
226  {
227  public:
228  CallbacksHandler(Gui& gui, const Player& player)
229  :
230  _gui(gui),
231  _player(player)
232  {
233  }
234 
235  boost::any call(const HostInterface::Message& e);
236 
237  void exit();
238 
239  // For handling notification callbacks from ActionScript.
240  // The callback is always sent to a hosting application
241  // (i.e. if a file descriptor is supplied). It is never
242  // acted on by Gnash when running as a plugin.
243  void notify(const std::string& event, const std::string& arg);
244 
245  private:
246 
247  Gui& _gui;
248 
249  const Player& _player;
250  };
251 
252  std::shared_ptr<CallbacksHandler> _callbacksHandler;
253 
254  void init();
255 
270  static unsigned int silentStream(void* udata, std::int16_t* stream,
271  unsigned int len, bool& atEOF);
272 
273  void init_sound();
274 
275  void init_logfile();
276 
277  void init_gui();
278 
280  //
283  std::unique_ptr<Gui> getGui();
284 
285  void setFlashVars(const std::string& varstr);
286 
287  typedef std::map<std::string, std::string, StringNoCaseLessThan> Params;
288 
289  // Movie parameters (for -P)
290  Params _params;
291 
292  // the scale at which to play
293  float _scale;
294  unsigned int _delay;
295  size_t _width;
296  size_t _height;
297  int _xPosition;
298  int _yPosition;
299  unsigned long _windowID;
300  bool _doLoop;
301  bool _doRender;
302  bool _doSound;
303  float _exitTimeout;
304  std::string _baseurl;
305 
307  //
313  //
317  //
321  std::shared_ptr<sound::sound_handler> _soundHandler;
322 
323  std::shared_ptr<media::MediaHandler> _mediaHandler;
324 
326  //
329  std::shared_ptr<RunResources> _runResources;
330 
332  std::shared_ptr<Gui> _gui;
333 
334  std::string _url;
335 
336  std::string _infile;
337 
338  boost::intrusive_ptr<movie_definition> _movieDef;
339 
340  unsigned long _maxAdvances;
341 
343  //
348  boost::intrusive_ptr<movie_definition> load_movie();
349 
350 #ifdef GNASH_FPS_DEBUG
351  float _fpsDebugTime;
352 #endif
353 
354  // Filedescriptor to use for host application requests, -1 if none
355  int _hostfd;
356 
357  int _controlfd;
358 
359  // Whether to start Gnash in fullscreen mode.
360  // (Or what did you think it meant?)
361  bool _startFullscreen;
362  bool _hideMenu;
363 
365  std::string _audioDump;
366 
368  //
370  std::string _screenshots;
371 
373  //
375  std::string _screenshotFile;
376 
378  //
380  int _screenshotQuality;
381 
383  //
385  std::string _media;
386 
387 };
388 
389 } // end of gnash namespace
390 
391 // end of _PLAYER_H_
392 #endif
393 
394 // local Variables:
395 // mode: C++
396 // indent-tabs-mode: nil
397 // End:
void setWindowId(unsigned long x)
Definition: Player.h:114
void setHWAccel(const std::string &x)
Definition: Player.h:187
void setScreenShotFile(const std::string &file)
Set the filename for screenshot output.
Definition: Player.h:202
Definition: GnashKey.h:150
float setExitTimeout(float n)
Definition: Player.h:133
void setBaseUrl(const std::string &baseurl)
Set the base url for this run.
Definition: Player.h:129
void setMaxAdvances(unsigned long ul)
Definition: Player.h:122
void setCookiesIn(const std::string &filename)
Definition: Player.h:163
void setControlFD(int fd)
Definition: Player.h:155
void setScreenShots(const std::string &screenshots)
This should be a comma-separated list of frames.
Definition: Player.h:195
void setRenderer(const std::string &x)
Definition: Player.h:182
size_t getWidth() const
Definition: Player.h:103
Abstract base class for FS handlers.
Definition: HostInterface.h:199
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:40
void setXPosition(int xPos)
Definition: Player.h:108
boost::variant< HostMessage, CustomMessage > Message
Definition: HostInterface.h:213
size_t getYPosition() const
Definition: Player.h:112
void hideMenu(bool x)
Definition: Player.h:171
static void setCookiesIn(const std::string &cookiesin)
Set CookiesIn variable to cookiefile path.
Definition: NetworkAdapter.h:96
void setAudioDumpfile(const std::string &filespec)
Definition: Player.h:175
void setMedia(const std::string &media)
Definition: Player.h:151
void setHeight(size_t h)
Definition: Player.h:105
size_t getHeight() const
Definition: Player.h:106
void setDelay(unsigned int d)
Definition: Player.h:85
Definition: GnashKey.h:160
Parent class from which all GUI implementations will depend.
Definition: gui.h:88
void setHostFD(int fd)
Definition: Player.h:143
The MediaHandler class acts as a factory to provide parser and decoders.
Definition: MediaHandler.h:69
void setWidth(size_t w)
Definition: Player.h:102
void setDoRender(bool b)
Definition: Player.h:118
void setScreenShotQuality(int quality)
Set the quality for screenshot output.
Definition: Player.h:209
std::int32_t x
Definition: BitmapData_as.cpp:434
Definition: GnashKey.h:148
Definition: GnashKey.h:154
w
Definition: test.py:8
std::string url
Definition: gnash.cpp:59
int getHostFD() const
Definition: Player.h:147
size_t getXPosition() const
Definition: Player.h:109
Definition: GnashKey.h:151
Abstract base class for hosting app handler.
Definition: HostInterface.h:207
void setStartFullscreen(bool x)
Definition: Player.h:167
void setDoSound(bool b)
Definition: Player.h:120
Definition: Player.h:57
Definition: GnashKey.h:165
void setDoLoop(bool b)
Definition: Player.h:116
int getControlFD() const
Definition: Player.h:159
std::string name
Definition: LocalConnection_as.cpp:149
void setYPosition(int yPos)
Definition: Player.h:111
void setParam(const std::string &name, const std::string &value)
Definition: Player.h:139