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"
27 #include "sound_handler.h"
28 #include "MediaHandler.h"
30 #include "movie_definition.h"
31 #include "movie_root.h"
32 #include "RunResources.h"
34 #include <boost/intrusive_ptr.hpp>
36 #include <boost/shared_ptr.hpp>
39 // Forward declarations
49 /// This class is an attempt at simplifying the code required
50 /// to simply start the SWF player. The idea was to use it
51 /// from the plugin so we can set callback for getUrl and fs_commands
52 /// w/out the need of using FIFOs or sockets or whatever else.
62 /// Play the movie at the given url/path.
65 /// number of argument strings in argv
71 /// an optional url to assign to the given movie.
72 /// if unspecified the url will be set to the
76 void run(int argc
, char* argv
[],
77 const std::string
& infile
, const std::string
& url
= "");
79 float setScale(float s
);
81 // milliseconds per frame
82 void setDelay(unsigned int d
) { _delay
=d
; }
84 #ifdef GNASH_FPS_DEBUG
85 /// Set the number of seconds between FPS debugging prints
88 /// Number of seconds between FPS debugging prints.
89 /// A value of 0 disables FPS printing.
90 /// A negative value results in an assertion failure.
92 void setFpsPrintTime(float time
)
97 #endif // def GNASH_FPS_DEBUG
99 void setWidth(size_t w
) { _width
= w
; }
100 size_t getWidth() { return _width
; }
102 void setHeight(size_t h
) { _height
= h
; }
103 size_t getHeight() { return _height
; }
105 void setXPosition(int xPos
) { _xPosition
= xPos
; }
106 size_t getXPosition() { return _xPosition
; }
108 void setYPosition(int yPos
) { _yPosition
= yPos
; }
109 size_t getYPosition() { return _yPosition
; }
111 void setWindowId(unsigned long x
) { _windowID
= x
; }
113 void setDoLoop(bool b
) { _doLoop
= b
; }
115 void setDoRender(bool b
) { _doRender
= b
; }
117 void setDoSound(bool b
) { _doSound
= b
; }
119 void setMaxAdvances(unsigned long ul
) { if (ul
> 0) _maxAdvances
= ul
; }
121 /// Set the base url for this run.
123 /// The base url will be used to resolve relative
124 /// urls on load requests.
126 void setBaseUrl(const std::string
& baseurl
) {
130 float setExitTimeout(float n
) {
131 float oldtimeout
= _exitTimeout
;
136 void setParam(std::string
& name
, std::string
& value
) {
137 _params
[name
] = value
;
140 void setHostFD(int fd
) {
144 int getHostFD() const {
148 void setMedia(const std::string
& media
) {
152 void setControlFD(int fd
) {
156 int getControlFD() const {
160 void setStartFullscreen(bool x
) {
161 _startFullscreen
= x
;
164 void hideMenu(bool x
) {
168 void setAudioDumpfile(const std::string
& filespec
) {
169 _audioDump
= filespec
;
172 /// Set the renderer backend, agg, opengl, or cairo. This is set
173 /// in the users gnashrc file, or can be overridden with the
174 /// --hwaccel option to gnash.
175 void setRenderer(const std::string
& x
) { _renderer
= x
; }
177 /// Set the hardware video accleration backend, none, vaapi, xv,
178 /// or cairo. This is set in the users gnashrc file, or can be
179 /// overridden with the --render-mode option to gnash.
180 void setHWAccel(const std::string
& x
) { _hwaccel
= x
; }
182 /// This should be a comma-separated list of frames.
184 /// Only numbers and the word "last" are valid.
186 /// We parse the string here rather than in gnash.cpp to avoid making
187 /// the interface to Player more complicated than it is already.
188 void setScreenShots(const std::string
& screenshots
) {
189 _screenshots
= screenshots
;
192 /// Set the filename for screenshot output.
194 /// A %f in the filename will be replaced with the frame number.
195 void setScreenShotFile(const std::string
& file
) {
196 _screenshotFile
= file
;
201 /// Whether to ue HW video decoding support, no value means disabled.
202 /// The only currently supported values are: none, vaapi, or xv (omap)
203 /// support coming. The default is none,
204 std::string _hwaccel
;
206 /// Which renderer backend to use, no value means use the default.
207 /// The currently supported values are agg, opengl, or cairo. AGG
208 /// being the default.
209 std::string _renderer
;
211 class CallbacksHandler
: public movie_root::AbstractIfaceCallback
,
212 public movie_root::AbstractFsCallback
215 CallbacksHandler(Gui
& gui
, const Player
& player
)
222 std::string
call(const std::string
& event
,
223 const std::string
& arg
);
225 bool yesNo(const std::string
& query
);
227 void error(const std::string
& msg
);
231 // For handling notification callbacks from ActionScript.
232 // The callback is always sent to a hosting application
233 // (i.e. if a file descriptor is supplied). It is never
234 // acted on by Gnash when running as a plugin.
235 void notify(const std::string
& event
, const std::string
& arg
);
241 const Player
& _player
;
244 std::auto_ptr
<CallbacksHandler
> _callbacksHandler
;
248 /// This aux streamer returns a silent audio stream
251 /// Pointer to user-specific data
253 /// Buffer into which method will put samples
255 /// Requested amount of samples to put
257 /// Will always set to false, silent stream never ends ..
259 /// @return always the len parameter value (silent stream never ends
260 /// and is always available)
262 static unsigned int silentStream(void* udata
, boost::int16_t* stream
,
263 unsigned int len
, bool& atEOF
);
271 /// Create the gui instance
273 /// Uses the USE_<guiname> macros to find out which one
275 std::auto_ptr
<Gui
> getGui();
277 void setFlashVars(const std::string
& varstr
);
279 typedef std::map
<std::string
, std::string
, StringNoCaseLessThan
> Params
;
281 // Movie parameters (for -P)
283 unsigned int _bitDepth
;
285 // the scale at which to play
292 unsigned long _windowID
;
297 std::string _baseurl
;
299 /// Initialization / destruction order is important here.
301 /// some sound_samples are destroyed in the dtor of SWFMovieDefinition,
302 /// which is called by the Gui's dtor. This means that the RunResources
303 /// and sound::sound_handler must still be alive. Initializing them
304 /// later ensures that this is the case. It is still a good idea to
305 /// initialize _gui after _runResources.
307 /// Moreover, _movieDef (the SWFMovieDefinition) would also prevent
308 /// destruction of a SWFMovieDefinition if it is not initialized after
309 /// _gui, and probably result in a segfault.
311 /// @todo This is hairy, and the core should be sorted out so that
312 /// sound_sample knows about its sound::sound_handler without
313 /// needing a RunResources.
314 boost::shared_ptr
<sound::sound_handler
> _soundHandler
;
316 boost::shared_ptr
<media::MediaHandler
> _mediaHandler
;
318 /// Handlers (for sound etc) for a libcore run.
320 /// This must be kept alive for the entire lifetime of the movie_root
321 /// (currently: of the Gui).
322 std::auto_ptr
<RunResources
> _runResources
;
324 /// This must be initialized after _runResources
325 std::auto_ptr
<Gui
> _gui
;
331 boost::intrusive_ptr
<movie_definition
> _movieDef
;
333 unsigned long _maxAdvances
;
335 /// Load the "_infile" movie setting its url to "_url"
337 /// This function takes care of interpreting _infile as
338 /// stdin when it equals "-". May throw a GnashException
341 boost::intrusive_ptr
<movie_definition
> load_movie();
343 #ifdef GNASH_FPS_DEBUG
347 // Filedescriptor to use for host application requests, -1 if none
352 // Whether to start Gnash in fullscreen mode.
353 // (Or what did you think it meant?)
354 bool _startFullscreen
;
357 /// The filename to use for dumping audio.
358 std::string _audioDump
;
360 /// A comma-separated list of frames to output as screenshots.
362 /// If empty, no screenshots are required.
363 std::string _screenshots
;
365 /// The filename to save screenshots to.
367 /// If empty, a default is used.
368 std::string _screenshotFile
;
370 /// The identifier for the media handler.
372 /// If empty, a default is used.
377 } // end of gnash namespace
384 // indent-tabs-mode: nil