Gnash  0.8.10
Player.h
Go to the documentation of this file.
00001 // 
00002 //   Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010,
00003 //   2011 Free Software Foundation, Inc
00004 // 
00005 // This program is free software; you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation; either version 3 of the License, or
00008 // (at your option) any later version.
00009 // 
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 // 
00015 // You should have received a copy of the GNU General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018 // 
00019 
00020 #ifndef GNASH_PLAYER_H
00021 #define GNASH_PLAYER_H
00022 
00023 #ifdef HAVE_CONFIG_H
00024 #include "gnashconfig.h"
00025 #endif
00026 
00027 #include <boost/intrusive_ptr.hpp>
00028 #include <string>
00029 #include <boost/shared_ptr.hpp>
00030 #include <map>
00031 #include <memory>
00032 
00033 #include "sound_handler.h"
00034 #include "MediaHandler.h" 
00035 #include "gui.h"
00036 #include "movie_definition.h" 
00037 #include "movie_root.h"
00038 #include "RunResources.h"
00039 
00040 // Forward declarations
00041 namespace gnash {
00042     class MovieClip;
00043 }
00044 
00045 namespace gnash {
00046 
00052 class Player
00053 {
00054 public:
00055     
00056     Player();
00057     
00058     ~Player();
00059     
00061     //
00074     void run(int argc, char* argv[],
00075             const std::string& infile, const std::string& url = "");
00076     
00077     float setScale(float s);
00078     
00079     // milliseconds per frame
00080     void setDelay(unsigned int d) { _delay=d; }
00081     
00082 #ifdef GNASH_FPS_DEBUG
00083 
00084     //
00090     void setFpsPrintTime(float time)
00091     {
00092         assert(time >= 0.0);
00093         _fpsDebugTime = time;
00094     }
00095 #endif // def GNASH_FPS_DEBUG
00096     
00097     void setWidth(size_t w) { _width = w; }
00098     size_t getWidth() const { return _width; }
00099     
00100     void setHeight(size_t h) { _height = h; }
00101     size_t getHeight() const { return _height; }
00102     
00103     void setXPosition(int xPos) { _xPosition = xPos; }
00104     size_t getXPosition() const { return _xPosition; }
00105     
00106     void setYPosition(int yPos) { _yPosition = yPos; }
00107     size_t getYPosition() const { return _yPosition; }
00108     
00109     void setWindowId(unsigned long x) { _windowID = x; }
00110     
00111     void setDoLoop(bool b) { _doLoop = b; }
00112     
00113     void setDoRender(bool b) { _doRender = b; }
00114     
00115     void setDoSound(bool b) { _doSound = b; }
00116     
00117     void setMaxAdvances(unsigned long ul) { if (ul > 0) _maxAdvances = ul; }
00118     
00120     //
00124     void setBaseUrl(const std::string& baseurl) {
00125         _baseurl = baseurl;
00126     }
00127     
00128     float setExitTimeout(float n) {
00129         float oldtimeout = _exitTimeout;
00130         _exitTimeout = n;
00131         return oldtimeout;
00132     }
00133     
00134     void setParam(const std::string& name, const std::string& value) {
00135         _params[name] = value;
00136     }
00137     
00138     void setHostFD(int fd) {
00139         _hostfd = fd;
00140     }
00141     
00142     int getHostFD() const {
00143         return _hostfd;
00144     }
00145 
00146     void setMedia(const std::string& media) {
00147         _media = media;
00148     }
00149 
00150     void setControlFD(int fd) {
00151         _controlfd = fd;
00152     }
00153     
00154     int getControlFD() const {
00155         return _controlfd;
00156     }
00157 
00158     void setStartFullscreen(bool x) {
00159         _startFullscreen = x;
00160     }
00161     
00162     void hideMenu(bool x) {
00163         _hideMenu = x;
00164     }
00165     
00166     void setAudioDumpfile(const std::string& filespec) {
00167         _audioDump = filespec;
00168     }
00169     
00173     void setRenderer(const std::string& x) { _renderer = x; }
00174     
00178     void setHWAccel(const std::string& x) { _hwaccel = x; }
00179 
00181     //
00183     //
00186     void setScreenShots(const std::string& screenshots) {
00187         _screenshots = screenshots;
00188     }
00189 
00191     //
00193     void setScreenShotFile(const std::string& file) {
00194         _screenshotFile = file;
00195     }
00196 
00198     //
00200     void setScreenShotQuality(int quality) {
00201         _screenshotQuality = quality;
00202     }
00203 
00204 private:
00205 
00209     std::string _hwaccel;
00210     
00214     std::string _renderer;
00215 
00216     class CallbacksHandler : public HostInterface, public FsCallback
00217     {
00218     public:
00219         CallbacksHandler(Gui& gui, const Player& player)
00220             :
00221             _gui(gui),
00222             _player(player)
00223         {
00224         }
00225         
00226         boost::any call(const HostInterface::Message& e);
00227 
00228         void exit();
00229         
00230         // For handling notification callbacks from ActionScript.
00231         // The callback is always sent to a hosting application
00232         // (i.e. if a file descriptor is supplied). It is never
00233         // acted on by Gnash when running as a plugin.
00234         void notify(const std::string& event, const std::string& arg);
00235         
00236     private:
00237         
00238         Gui& _gui;
00239         
00240         const Player& _player;
00241     };
00242     
00243     std::auto_ptr<CallbacksHandler> _callbacksHandler;
00244     
00245     void init();
00246     
00261     static unsigned int silentStream(void* udata, boost::int16_t* stream,
00262                      unsigned int len, bool& atEOF);
00263     
00264     void init_sound();
00265     
00266     void init_logfile();
00267     
00268     void init_gui();
00269     
00271     //
00274     std::auto_ptr<Gui> getGui();
00275     
00276     void setFlashVars(const std::string& varstr);
00277 
00278     typedef std::map<std::string, std::string, StringNoCaseLessThan> Params;
00279     
00280     // Movie parameters (for -P)
00281     Params      _params;
00282     
00283     // the scale at which to play 
00284     float       _scale;
00285     unsigned int _delay;
00286     size_t      _width;
00287     size_t      _height;
00288     int         _xPosition;
00289     int         _yPosition;
00290     unsigned long _windowID;
00291     bool        _doLoop;
00292     bool        _doRender;
00293     bool        _doSound;
00294     float       _exitTimeout;
00295     std::string _baseurl;
00296     
00298     //
00304     //
00308     //
00312     boost::shared_ptr<sound::sound_handler> _soundHandler;
00313     
00314     boost::shared_ptr<media::MediaHandler> _mediaHandler;
00315     
00317     //
00320     std::auto_ptr<RunResources> _runResources;
00321     
00323     std::auto_ptr<Gui> _gui;
00324     
00325     std::string         _url;
00326     
00327     std::string         _infile;
00328     
00329     boost::intrusive_ptr<movie_definition> _movieDef;
00330     
00331     unsigned long       _maxAdvances;
00332     
00334     // 
00339     boost::intrusive_ptr<movie_definition> load_movie();
00340     
00341 #ifdef GNASH_FPS_DEBUG
00342     float       _fpsDebugTime;
00343 #endif
00344     
00345     // Filedescriptor to use for host application requests, -1 if none
00346     int         _hostfd;
00347     
00348     int         _controlfd;
00349 
00350     // Whether to start Gnash in fullscreen mode.
00351     // (Or what did you think it meant?)
00352     bool        _startFullscreen;
00353     bool        _hideMenu;
00354     
00356     std::string _audioDump;
00357     
00359     //
00361     std::string _screenshots;
00362     
00364     //
00366     std::string _screenshotFile;
00367     
00369     //
00371     int _screenshotQuality;
00372 
00374     //
00376     std::string _media;
00377 
00378 };
00379  
00380 } // end of gnash namespace
00381 
00382 // end of _PLAYER_H_
00383 #endif
00384 
00385 // local Variables:
00386 // mode: C++
00387 // indent-tabs-mode: nil
00388 // End: