2 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software
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.
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.
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
20 #ifndef GNASH_PLAYER_H
21 #define GNASH_PLAYER_H
24 #include "gnashconfig.h"
28 #include "sound_handler.h"
29 #include "MediaHandler.h"
31 #include "movie_definition.h"
32 #include "movie_root.h"
33 #include "RunResources.h"
35 #include <boost/intrusive_ptr.hpp>
37 #include <boost/shared_ptr.hpp>
40 // Forward declarations
50 /// This class is an attempt at simplifying the code required
51 /// to simply start the SWF player. The idea was to use it
52 /// from the plugin so we can set callback for getUrl and fs_commands
53 /// w/out the need of using FIFOs or sockets or whatever else.
63 /// Play the movie at the given url/path.
66 /// number of argument strings in argv
72 /// an optional url to assign to the given movie.
73 /// if unspecified the url will be set to the
77 int run(int argc
, char* argv
[],
78 const std::string
& infile
, const std::string
& url
= "");
80 float setScale(float s
);
82 // milliseconds per frame
83 void setDelay(unsigned int d
) { _delay
=d
; }
85 #ifdef GNASH_FPS_DEBUG
86 /// Set the number of seconds between FPS debugging prints
89 /// Number of seconds between FPS debugging prints.
90 /// A value of 0 disables FPS printing.
91 /// A negative value results in an assertion failure.
93 void setFpsPrintTime(float time
)
98 #endif // def GNASH_FPS_DEBUG
100 void setWidth(size_t w
) { _width
= w
; }
101 size_t getWidth() { return _width
; }
103 void setHeight(size_t h
) { _height
= h
; }
104 size_t getHeight() { return _height
; }
106 void setXPosition(int xPos
) { _xPosition
= xPos
; }
107 size_t getXPosition() { return _xPosition
; }
109 void setYPosition(int yPos
) { _yPosition
= yPos
; }
110 size_t getYPosition() { return _yPosition
; }
112 void setWindowId(unsigned long x
) { _windowID
= x
; }
114 void setDoLoop(bool b
) { _doLoop
= b
; }
116 void setDoRender(bool b
) { _doRender
= b
; }
118 void setDoSound(bool b
) { _doSound
= b
; }
120 void setMaxAdvances(unsigned long ul
) { if (ul
> 0) _maxAdvances
= ul
; }
122 /// Set the base url for this run.
124 /// The base url will be used to resolve relative
125 /// urls on load requests.
127 void setBaseUrl(const std::string
& baseurl
) {
131 float setExitTimeout(float n
) {
132 float oldtimeout
= _exitTimeout
;
137 void setParam(std::string
& name
, std::string
& value
) {
138 _params
[name
] = value
;
141 void setHostFD(int fd
) {
145 int getHostFD() const {
149 void setControlFD(int fd
) {
153 int getControlFD() const {
157 void setStartFullscreen(bool x
) {
158 _startFullscreen
= x
;
161 void hideMenu(bool x
) {
165 void setAudioDumpfile(const std::string
& filespec
) {
166 _audioDump
= filespec
;
169 /// Set the renderer backend, agg, opengl, or cairo. This is set
170 /// in the users gnashrc file, or can be overridden with the
171 /// --hwaccel option to gnash.
172 void setRenderer(const std::string
& x
) { _renderer
= x
; }
174 /// Set the hardware video accleration backend, none, vaapi, xv,
175 /// or cairo. This is set in the users gnashrc file, or can be
176 /// overridden with the --render-mode option to gnash.
177 void setHWAccel(const std::string
& x
) { _hwaccel
= x
; }
179 /// This should be a comma-separated list of frames.
181 /// Only numbers and the word "last" are valid.
183 /// We parse the string here rather than in gnash.cpp to avoid making
184 /// the interface to Player more complicated than it is already.
185 void setScreenShots(const std::string
& screenshots
) {
186 _screenshots
= screenshots
;
189 /// Set the filename for screenshot output.
191 /// A %f in the filename will be replaced with the frame number.
192 void setScreenShotFile(const std::string
& file
) {
193 _screenshotFile
= file
;
198 /// Whether to ue HW video decoding support, no value means disabled.
199 /// The only currently supported values are: none, vaapi, or xv (omap)
200 /// support coming. The default is none,
201 std::string _hwaccel
;
203 /// Which renderer backend to use, no value means use the default.
204 /// The currently supported values are agg, opengl, or cairo. AGG
205 /// being the default.
206 std::string _renderer
;
208 class CallbacksHandler
: public movie_root::AbstractIfaceCallback
,
209 public movie_root::AbstractFsCallback
212 CallbacksHandler(Gui
& gui
, const Player
& player
)
219 std::string
call(const std::string
& event
,
220 const std::string
& arg
);
222 bool yesNo(const std::string
& query
);
224 void error(const std::string
& msg
);
226 // For handling notification callbacks from ActionScript.
227 // The callback is always sent to a hosting application
228 // (i.e. if a file descriptor is supplied). It is never
229 // acted on by Gnash when running as a plugin.
230 void notify(const std::string
& event
, const std::string
& arg
);
236 const Player
& _player
;
239 std::auto_ptr
<CallbacksHandler
> _callbacksHandler
;
243 /// This aux streamer returns a silent audio stream
246 /// Pointer to user-specific data
248 /// Buffer into which method will put samples
250 /// Requested amount of samples to put
252 /// Will always set to false, silent stream never ends ..
254 /// @return always the len parameter value (silent stream never ends
255 /// and is always available)
257 static unsigned int silentStream(void* udata
, boost::int16_t* stream
,
258 unsigned int len
, bool& atEOF
);
268 /// Create the gui instance
270 /// Uses the USE_<guiname> macros to find out which one
272 std::auto_ptr
<Gui
> getGui();
274 void setFlashVars(const std::string
& varstr
);
276 void setScriptableVar(const std::string
&name
, const std::string
& value
);
278 typedef std::map
<std::string
, std::string
, StringNoCaseLessThan
> Params
;
280 // Movie parameters (for -P)
282 unsigned int _bitDepth
;
284 // the scale at which to play
291 unsigned long _windowID
;
296 std::string _baseurl
;
298 /// Initialization / destruction order is important here.
300 /// some sound_samples are destroyed in the dtor of SWFMovieDefinition,
301 /// which is called by the Gui's dtor. This means that the RunResources
302 /// and sound::sound_handler must still be alive. Initializing them
303 /// later ensures that this is the case. It is still a good idea to
304 /// initialize _gui after _runResources.
306 /// Moreover, _movieDef (the SWFMovieDefinition) would also prevent
307 /// destruction of a SWFMovieDefinition if it is not initialized after
308 /// _gui, and probably result in a segfault.
310 /// @todo This is hairy, and the core should be sorted out so that
311 /// sound_sample knows about its sound::sound_handler without
312 /// needing a RunResources.
313 boost::shared_ptr
<sound::sound_handler
> _soundHandler
;
315 std::auto_ptr
<media::MediaHandler
> _mediaHandler
;
317 /// Handlers (for sound etc) for a libcore run.
319 /// This must be kept alive for the entire lifetime of the movie_root
320 /// (currently: of the Gui).
321 std::auto_ptr
<RunResources
> _runResources
;
323 /// This must be initialized after _runResources
324 std::auto_ptr
<Gui
> _gui
;
330 boost::intrusive_ptr
<movie_definition
> _movieDef
;
332 unsigned long _maxAdvances
;
334 /// Load the "_infile" movie setting its url to "_url"
336 /// This function takes care of interpreting _infile as
337 /// stdin when it equals "-". May throw a GnashException
340 boost::intrusive_ptr
<movie_definition
> load_movie();
342 #ifdef GNASH_FPS_DEBUG
346 // Filedescriptor to use for host application requests, -1 if none
351 // Whether to start Gnash in fullscreen mode.
352 // (Or what did you think it meant?)
353 bool _startFullscreen
;
356 /// The filename to use for dumping audio.
357 std::string _audioDump
;
359 /// A comma-separated list of frames to output as screenshots.
361 /// If empty, no screenshots are required.
362 std::string _screenshots
;
364 /// The filename to save screenshots to.
366 /// If empty, a default is used.
367 std::string _screenshotFile
;
371 } // end of gnash namespace
378 // indent-tabs-mode: nil