2 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010,
3 // 2011 Free Software Foundation, Inc
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 <boost/intrusive_ptr.hpp>
29 #include <boost/shared_ptr.hpp>
33 #include "sound_handler.h"
34 #include "MediaHandler.h"
36 #include "movie_definition.h"
37 #include "movie_root.h"
38 #include "RunResources.h"
40 // Forward declarations
47 /// This class is an attempt at simplifying the code required
48 /// to simply start the SWF player. The idea was to use it
49 /// from the plugin so we can set callback for getUrl and fs_commands
50 /// w/out the need of using FIFOs or sockets or whatever else.
60 /// Play the movie at the given url/path.
63 /// number of argument strings in argv
69 /// an optional url to assign to the given movie.
70 /// if unspecified the url will be set to the
74 void run(int argc
, char* argv
[],
75 const std::string
& infile
, const std::string
& url
= "");
77 float setScale(float s
);
79 // milliseconds per frame
80 void setDelay(unsigned int d
) { _delay
=d
; }
82 #ifdef GNASH_FPS_DEBUG
83 /// Set the number of seconds between FPS debugging prints
86 /// Number of seconds between FPS debugging prints.
87 /// A value of 0 disables FPS printing.
88 /// A negative value results in an assertion failure.
90 void setFpsPrintTime(float time
)
95 #endif // def GNASH_FPS_DEBUG
97 void setWidth(size_t w
) { _width
= w
; }
98 size_t getWidth() const { return _width
; }
100 void setHeight(size_t h
) { _height
= h
; }
101 size_t getHeight() const { return _height
; }
103 void setXPosition(int xPos
) { _xPosition
= xPos
; }
104 size_t getXPosition() const { return _xPosition
; }
106 void setYPosition(int yPos
) { _yPosition
= yPos
; }
107 size_t getYPosition() const { return _yPosition
; }
109 void setWindowId(unsigned long x
) { _windowID
= x
; }
111 void setDoLoop(bool b
) { _doLoop
= b
; }
113 void setDoRender(bool b
) { _doRender
= b
; }
115 void setDoSound(bool b
) { _doSound
= b
; }
117 void setMaxAdvances(unsigned long ul
) { if (ul
> 0) _maxAdvances
= ul
; }
119 /// Set the base url for this run.
121 /// The base url will be used to resolve relative
122 /// urls on load requests.
124 void setBaseUrl(const std::string
& baseurl
) {
128 float setExitTimeout(float n
) {
129 float oldtimeout
= _exitTimeout
;
134 void setParam(const std::string
& name
, const std::string
& value
) {
135 _params
[name
] = value
;
138 void setHostFD(int fd
) {
142 int getHostFD() const {
146 void setMedia(const std::string
& media
) {
150 void setControlFD(int fd
) {
154 int getControlFD() const {
158 void setStartFullscreen(bool x
) {
159 _startFullscreen
= x
;
162 void hideMenu(bool x
) {
166 void setAudioDumpfile(const std::string
& filespec
) {
167 _audioDump
= filespec
;
170 /// Set the renderer backend, agg, opengl, or cairo. This is set
171 /// in the users gnashrc file, or can be overridden with the
172 /// --renderer option to gnash.
173 void setRenderer(const std::string
& x
) { _renderer
= x
; }
175 /// Set the hardware video accleration backend, none, vaapi, xv,
176 /// or cairo. This is set in the users gnashrc file, or can be
177 /// overridden with the --hwaccel option to gnash.
178 void setHWAccel(const std::string
& x
) { _hwaccel
= x
; }
180 /// This should be a comma-separated list of frames.
182 /// Only numbers and the word "last" are valid.
184 /// We parse the string here rather than in gnash.cpp to avoid making
185 /// the interface to Player more complicated than it is already.
186 void setScreenShots(const std::string
& screenshots
) {
187 _screenshots
= screenshots
;
190 /// Set the filename for screenshot output.
192 /// A %f in the filename will be replaced with the frame number.
193 void setScreenShotFile(const std::string
& file
) {
194 _screenshotFile
= file
;
197 /// Set the quality for screenshot output.
199 /// A %f in the filename will be replaced with the frame number.
200 void setScreenShotQuality(int quality
) {
201 _screenshotQuality
= quality
;
206 /// Whether to ue HW video decoding support, no value means disabled.
207 /// The only currently supported values are: none, vaapi, or xv (omap)
208 /// support coming. The default is none,
209 std::string _hwaccel
;
211 /// Which renderer backend to use, no value means use the default.
212 /// The currently supported values are agg, opengl, or cairo. AGG
213 /// being the default.
214 std::string _renderer
;
216 class CallbacksHandler
: public HostInterface
, public FsCallback
219 CallbacksHandler(Gui
& gui
, const Player
& player
)
226 boost::any
call(const HostInterface::Message
& e
);
230 // For handling notification callbacks from ActionScript.
231 // The callback is always sent to a hosting application
232 // (i.e. if a file descriptor is supplied). It is never
233 // acted on by Gnash when running as a plugin.
234 void notify(const std::string
& event
, const std::string
& arg
);
240 const Player
& _player
;
243 std::auto_ptr
<CallbacksHandler
> _callbacksHandler
;
247 /// This aux streamer returns a silent audio stream
250 /// Pointer to user-specific data
252 /// Buffer into which method will put samples
254 /// Requested amount of samples to put
256 /// Will always set to false, silent stream never ends ..
258 /// @return always the len parameter value (silent stream never ends
259 /// and is always available)
261 static unsigned int silentStream(void* udata
, boost::int16_t* stream
,
262 unsigned int len
, bool& atEOF
);
270 /// Create the gui instance
272 /// Uses the USE_<guiname> macros to find out which one
274 std::auto_ptr
<Gui
> getGui();
276 void setFlashVars(const std::string
& varstr
);
278 typedef std::map
<std::string
, std::string
, StringNoCaseLessThan
> Params
;
280 // Movie parameters (for -P)
283 // the scale at which to play
290 unsigned long _windowID
;
295 std::string _baseurl
;
297 /// Initialization / destruction order is important here.
299 /// some sound_samples are destroyed in the dtor of SWFMovieDefinition,
300 /// which is called by the Gui's dtor. This means that the RunResources
301 /// and sound::sound_handler must still be alive. Initializing them
302 /// later ensures that this is the case. It is still a good idea to
303 /// initialize _gui after _runResources.
305 /// Moreover, _movieDef (the SWFMovieDefinition) would also prevent
306 /// destruction of a SWFMovieDefinition if it is not initialized after
307 /// _gui, and probably result in a segfault.
309 /// @todo This is hairy, and the core should be sorted out so that
310 /// sound_sample knows about its sound::sound_handler without
311 /// needing a RunResources.
312 boost::shared_ptr
<sound::sound_handler
> _soundHandler
;
314 boost::shared_ptr
<media::MediaHandler
> _mediaHandler
;
316 /// Handlers (for sound etc) for a libcore run.
318 /// This must be kept alive for the entire lifetime of the movie_root
319 /// (currently: of the Gui).
320 std::auto_ptr
<RunResources
> _runResources
;
322 /// This must be initialized after _runResources
323 std::auto_ptr
<Gui
> _gui
;
329 boost::intrusive_ptr
<movie_definition
> _movieDef
;
331 unsigned long _maxAdvances
;
333 /// Load the "_infile" movie setting its url to "_url"
335 /// This function takes care of interpreting _infile as
336 /// stdin when it equals "-". May throw a GnashException
339 boost::intrusive_ptr
<movie_definition
> load_movie();
341 #ifdef GNASH_FPS_DEBUG
345 // Filedescriptor to use for host application requests, -1 if none
350 // Whether to start Gnash in fullscreen mode.
351 // (Or what did you think it meant?)
352 bool _startFullscreen
;
355 /// The filename to use for dumping audio.
356 std::string _audioDump
;
358 /// A comma-separated list of frames to output as screenshots.
360 /// If empty, no screenshots are required.
361 std::string _screenshots
;
363 /// The filename to save screenshots to.
365 /// If empty, a default is used.
366 std::string _screenshotFile
;
368 /// The filename to save screenshots to.
371 int _screenshotQuality
;
373 /// The identifier for the media handler.
375 /// If empty, a default is used.
380 } // end of gnash namespace
387 // indent-tabs-mode: nil