1 // RunResources.h Hold external and per-run resources for Gnash core. 2 // 3 // Copyright (C) 2007, 2008, 2009, 2010, 2011. 2012 4 // Free Software Foundation, Inc. 5 // 6 // This program is free software; you can redistribute it and/or modify 7 // it under the terms of the GNU General Public License as published by 8 // the Free Software Foundation; either version 3 of the License, or 9 // (at your option) any later version. 10 // 11 // This program is distributed in the hope that it will be useful, 12 // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 // GNU General Public License for more details. 15 // 16 // You should have received a copy of the GNU General Public License 17 // along with this program; if not, write to the Free Software 18 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 20 21 #ifndef GNASH_RUN_INFO_H 22 #define GNASH_RUN_INFO_H 23 24 #include <memory> 25 #include <string> 26 #include <cassert> 27 28 namespace gnash { 29 class Renderer; 30 class StreamProvider; 31 namespace SWF { 32 class TagLoadersTable; 33 } 34 namespace media { 35 class MediaHandler; 36 } 37 namespace sound { 38 class sound_handler; 39 } 40 } 41 42 namespace gnash { 43 44 /// Class to group together per-run and external resources for Gnash 45 // 46 /// This holds the following resources: 47 /// - sound::sound_handler 48 /// - StreamProvider 49 /// In addition, it stores the constant base URL for the run. 50 /// This must be kept alive for the entire duration of a run (presently 51 /// until the last SWFMovieDefinition has been destroyed). 52 /// @todo Check the lifetime and update documentation if it changes. 53 class RunResources 54 { 55 public: 56 57 /// Constructs a RunResources instance with an immutable base URL. 58 // 59 /// @param baseURL The base URL for the run. This cannot be changed after 60 /// construction. RunResources()61 RunResources() {} 62 63 /// Set the StreamProvider. 64 // 65 /// This can probably be changed during a run without ill effects. setStreamProvider(std::shared_ptr<StreamProvider> sp)66 void setStreamProvider(std::shared_ptr<StreamProvider> sp) { 67 _streamProvider = sp; 68 } 69 70 /// Get a StreamProvider instance. 71 // 72 /// This isn't optional. It must always be available, or nothing 73 /// can be loaded. 74 // 75 /// @return A StreamProvider streamProvider()76 const StreamProvider& streamProvider() const { 77 assert (_streamProvider.get()); 78 return *_streamProvider; 79 } 80 81 /// Set the sound::sound_handler. 82 // 83 /// @param s A pointer to the sound::sound_handler for use 84 /// by Gnash core. This may also be NULL. 85 // 86 /// This is cached in various places, so changing it during a run will 87 /// lead to unexpected behaviour. setSoundHandler(std::shared_ptr<sound::sound_handler> s)88 void setSoundHandler(std::shared_ptr<sound::sound_handler> s) { 89 _soundHandler = s; 90 } 91 92 /// Get a pointer to a sound::sound_handler set by a hosting application. 93 // 94 /// @return A pointer to a sound::sound_handler, or NULL if none 95 /// has yet been set. soundHandler()96 sound::sound_handler* soundHandler() const { 97 return _soundHandler.get(); 98 } 99 setMediaHandler(std::shared_ptr<media::MediaHandler> s)100 void setMediaHandler(std::shared_ptr<media::MediaHandler> s) { 101 _mediaHandler = s; 102 } 103 mediaHandler()104 media::MediaHandler* mediaHandler() const { 105 return _mediaHandler.get(); 106 } 107 setRenderer(std::shared_ptr<Renderer> r)108 void setRenderer(std::shared_ptr<Renderer> r) { 109 _renderer = r; 110 } 111 renderer()112 Renderer* renderer() const { 113 return _renderer.get(); 114 } 115 116 /// Set the loader functions for SWF parsing. 117 // 118 /// This must be present before parsing. 119 /// It is a pointer to const so that the same table can be shared between 120 /// simultaneous runs if desired. setTagLoaders(std::shared_ptr<const SWF::TagLoadersTable> loaders)121 void setTagLoaders(std::shared_ptr<const SWF::TagLoadersTable> loaders) { 122 _tagLoaders = loaders; 123 } 124 125 /// Get the loader function table for parsing a SWF. tagLoaders()126 const SWF::TagLoadersTable& tagLoaders() const { 127 assert(_tagLoaders.get()); 128 return *_tagLoaders; 129 } 130 131 #if 1 132 /// Set the renderer backend, agg, opengl, or cairo. This is set 133 /// in the users gnashrc file, or can be overridden with the 134 /// --hwaccel option to gnash. setRenderBackend(const std::string & x)135 void setRenderBackend(const std::string& x) { _renderer_backend = x; } getRenderBackend()136 std::string& getRenderBackend() { return _renderer_backend; } 137 138 /// Set the hardware video accleration backend, none or vaapi. 139 /// This is set in the users gnashrc file, or can be 140 /// overridden with the --render-mode option to gnash. getHWAccelBackend()141 std::string& getHWAccelBackend() { return _hwaccel_backend; } setHWAccelBackend(const std::string & x)142 void setHWAccelBackend(const std::string& x) { _hwaccel_backend = x; } 143 #endif 144 145 private: 146 147 std::shared_ptr<StreamProvider> _streamProvider; 148 149 std::shared_ptr<sound::sound_handler> _soundHandler; 150 151 std::shared_ptr<media::MediaHandler> _mediaHandler; 152 153 std::shared_ptr<Renderer> _renderer; 154 155 std::shared_ptr<const SWF::TagLoadersTable> _tagLoaders; 156 157 /// Whether to ue HW video decoding support, no value means disabled. 158 /// The only currently supported values are: none or vaapi. 159 /// The default is none, 160 std::string _hwaccel_backend; 161 162 /// Which renderer backend to use, no value means use the default. 163 /// The currently supported values are agg, opengl, or cairo. AGG 164 /// being the default. 165 std::string _renderer_backend; 166 }; 167 168 } // end of gnash namespace 169 170 #endif 171 172 // local Variables: 173 // mode: C++ 174 // indent-tabs-mode: t 175 // End: 176 177