Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef GNASH_SWF_MOVIE_DEFINITION_H
00024 #define GNASH_SWF_MOVIE_DEFINITION_H
00025
00026 #ifdef HAVE_CONFIG_H
00027 #include "gnashconfig.h"
00028 #endif
00029
00030 #include "smart_ptr.h"
00031 #include "GnashImageJpeg.h"
00032 #include "movie_definition.h"
00033 #include "DefinitionTag.h"
00034 #include "StringPredicates.h"
00035 #include "SWFRect.h"
00036 #include "GnashNumeric.h"
00037 #include "GnashAlgorithm.h"
00038
00039 #include <boost/intrusive_ptr.hpp>
00040 #include <vector>
00041 #include <map>
00042 #include <set>
00043 #include <string>
00044 #include <memory>
00045 #include <boost/thread/thread.hpp>
00046 #include <boost/thread/condition.hpp>
00047 #include <boost/thread/barrier.hpp>
00048 #include <boost/scoped_ptr.hpp>
00049
00050
00051 namespace gnash {
00052 class SWFMovieDefinition;
00053 class SWFStream;
00054 class movie_root;
00055 class MovieClip;
00056 class SWFMovie;
00057 class RunResources;
00058 class Font;
00059 }
00060
00061 namespace gnash {
00062
00064 class SWFMovieLoader
00065 {
00066 public:
00067
00068 SWFMovieLoader(SWFMovieDefinition& md);
00069
00070 ~SWFMovieLoader();
00071
00073
00078 bool start();
00079
00081 bool started() const;
00082
00084 bool isSelfThread() const;
00085
00086 private:
00087
00088 SWFMovieDefinition& _movie_def;
00089
00090 mutable boost::mutex _mutex;
00091 std::auto_ptr<boost::thread> _thread;
00092
00093
00094
00095
00096 boost::barrier _barrier;
00097
00099 static void execute(SWFMovieLoader& ml, SWFMovieDefinition* md);
00100
00101 };
00102
00104
00108 class CharacterDictionary
00109 {
00110 public:
00111
00113
00116 typedef std::map<int, boost::intrusive_ptr<SWF::DefinitionTag> >
00117 CharacterContainer;
00118
00119 typedef CharacterContainer::iterator CharacterIterator;
00120
00121 typedef CharacterContainer::const_iterator CharacterConstIterator;
00122
00124
00127 boost::intrusive_ptr<SWF::DefinitionTag> getDisplayObject(int id) const;
00128
00130
00133 void addDisplayObject(int id, boost::intrusive_ptr<SWF::DefinitionTag> c);
00134
00136 CharacterIterator begin() { return _map.begin(); }
00137
00139 CharacterConstIterator begin() const { return _map.begin(); }
00140
00142 CharacterIterator end() { return _map.end(); }
00143
00145 CharacterConstIterator end() const { return _map.end(); }
00146
00147 friend std::ostream& operator<<(std::ostream& o,
00148 const CharacterDictionary& cd);
00149
00150 private:
00151
00152 CharacterContainer _map;
00153
00154 };
00155
00156
00158
00162 class SWFMovieDefinition : public movie_definition
00163 {
00164 public:
00165
00167
00170 SWFMovieDefinition(const RunResources& runResources);
00171
00172 ~SWFMovieDefinition();
00173
00175 size_t get_frame_count() const {
00176 return m_frame_count;
00177 }
00178
00180 float get_frame_rate() const {
00181 return m_frame_rate;
00182 }
00183
00185 const SWFRect& get_frame_size() const {
00186 return m_frame_size;
00187 }
00188
00189 size_t get_width_pixels() const {
00190 return std::ceil(twipsToPixels(m_frame_size.width()));
00191 }
00192
00193 size_t get_height_pixels() const {
00194 return std::ceil(twipsToPixels(m_frame_size.height()));
00195 }
00196
00198 void setAS3() {
00199 _as3 = true;
00200 }
00201
00203 bool isAS3() const {
00204 return _as3;
00205 }
00206
00208
00211 virtual int get_version() const { return m_version; }
00212
00214
00222 virtual size_t get_loading_frame() const;
00223
00225
00228 size_t get_bytes_loaded() const {
00229 boost::mutex::scoped_lock lock(_bytes_loaded_mutex);
00230 return _bytes_loaded;
00231 }
00232
00234 size_t get_bytes_total() const {
00235 return m_file_length;
00236 }
00237
00238 virtual void importResources(boost::intrusive_ptr<movie_definition> source,
00239 const Imports& imports);
00240
00241 virtual void addDisplayObject(boost::uint16_t id, SWF::DefinitionTag* c);
00242
00244 SWF::DefinitionTag* getDefinitionTag(boost::uint16_t id) const;
00245
00246
00247
00248
00249 bool get_labeled_frame(const std::string& label, size_t& frame_number)
00250 const;
00251
00252 void add_font(int font_id, Font* f);
00253
00254 Font* get_font(int font_id) const;
00255
00256 Font* get_font(const std::string& name, bool bold, bool italic) const;
00257
00258
00259 CachedBitmap* getBitmap(int DisplayObject_id) const;
00260
00261
00262 void addBitmap(int DisplayObject_id, boost::intrusive_ptr<CachedBitmap> im);
00263
00264
00265 sound_sample* get_sound_sample(int DisplayObject_id) const;
00266
00267
00268 virtual void add_sound_sample(int DisplayObject_id, sound_sample* sam);
00269
00270
00271 virtual void set_loading_sound_stream_id(int id) {
00272 m_loading_sound_stream = id;
00273 }
00274
00275
00276 int get_loading_sound_stream_id() const {
00277 return m_loading_sound_stream;
00278 }
00279
00280
00281 void addControlTag(SWF::ControlTag* tag) {
00282 assert(tag);
00283 boost::mutex::scoped_lock lock(_frames_loaded_mutex);
00284 m_playlist[_frames_loaded].push_back(tag);
00285 }
00286
00287
00288
00289
00290
00291 void add_frame_name(const std::string& name);
00292
00295 void set_jpeg_loader(std::auto_ptr<JpegImageInput> j_in) {
00296 if (m_jpeg_in.get()) {
00303 log_swferror(_("More than one JPEGTABLES tag found: not "
00304 "resetting JPEG loader"));
00305 return;
00306 }
00307 m_jpeg_in = j_in;
00308 }
00309
00310
00311 JpegImageInput* get_jpeg_loader() const {
00312 return m_jpeg_in.get();
00313 }
00314
00315 virtual const PlayList* getPlaylist(size_t frame_number) const {
00316
00317 #ifndef NDEBUG
00318 boost::mutex::scoped_lock lock(_frames_loaded_mutex);
00319 assert(frame_number <= _frames_loaded);
00320 #endif
00321
00322 PlayListMap::const_iterator it = m_playlist.find(frame_number);
00323 if ( it == m_playlist.end() ) return NULL;
00324 else return &(it->second);
00325 }
00326
00328
00336 bool readHeader(std::auto_ptr<IOChannel> in, const std::string& url);
00337
00339
00345 bool completeLoad();
00346
00350 bool ensure_frame_loaded(size_t framenum) const;
00351
00353
00358 void read_all_swf();
00359
00361
00369 Movie* createMovie(Global_as& gl, DisplayObject* parent = 0);
00370
00371 virtual DisplayObject* createDisplayObject(Global_as&, DisplayObject*)
00372 const {
00373 return 0;
00374 }
00375
00376 virtual const std::string& get_url() const { return _url; }
00377
00379
00381
00386 boost::uint16_t exportID(const std::string& symbol) const;
00387
00389
00391
00395 void registerExport(const std::string& symbol, boost::uint16_t id);
00396
00397
00398 #ifdef USE_SWFTREE
00399
00400
00401
00402 virtual void storeDescriptiveMetadata(const std::string& data) {
00403 _metadata = data;
00404 }
00405
00406 virtual const std::string& getDescriptiveMetadata() const {
00407 return _metadata;
00408 }
00409
00410 #endif
00411
00412 private:
00413
00414 #ifdef USE_SWFTREE
00415
00416 std::string _metadata;
00417 #endif
00418
00420 CharacterDictionary _dictionary;
00421
00423 mutable boost::mutex _dictionaryMutex;
00424
00425 typedef std::map<int, boost::intrusive_ptr<Font> > FontMap;
00426 FontMap m_fonts;
00427
00428 typedef std::map<int, boost::intrusive_ptr<CachedBitmap> > Bitmaps;
00429 Bitmaps _bitmaps;
00430
00431 typedef std::map<int, boost::intrusive_ptr<sound_sample> > SoundSampleMap;
00432 SoundSampleMap m_sound_samples;
00433
00434 typedef std::map<size_t, PlayList> PlayListMap;
00435
00437 PlayListMap m_playlist;
00438
00440 typedef std::map<std::string, size_t, StringNoCaseLessThan> NamedFrameMap;
00441 NamedFrameMap _namedFrames;
00442
00443
00444 mutable boost::mutex _namedFramesMutex;
00445
00447 typedef std::map<std::string, boost::uint16_t,
00448 StringNoCaseLessThan> Exports;
00449
00451 Exports _exportTable;
00452
00453
00454 mutable boost::mutex _exportedResourcesMutex;
00455
00458 typedef std::vector<boost::intrusive_ptr<movie_definition> > ImportVect;
00459 ImportVect m_import_source_movies;
00460
00461 SWFRect m_frame_size;
00462 float m_frame_rate;
00463 size_t m_frame_count;
00464 int m_version;
00465
00467 size_t _frames_loaded;
00468
00470
00474 mutable boost::mutex _frames_loaded_mutex;
00475
00477 mutable boost::condition _frame_reached_condition;
00478
00480
00483 mutable size_t _waiting_for_frame;
00484
00486 unsigned long _bytes_loaded;
00487
00489
00493 mutable boost::mutex _bytes_loaded_mutex;
00494
00495 int m_loading_sound_stream;
00496
00497 boost::uint32_t m_file_length;
00498
00499 std::auto_ptr<JpegImageInput> m_jpeg_in;
00500
00501 std::string _url;
00502
00504 boost::scoped_ptr<SWFStream> _str;
00505
00506 std::auto_ptr<IOChannel> _in;
00507
00509 size_t _swf_end_pos;
00510
00512 SWFMovieLoader _loader;
00513
00521 virtual void incrementLoadedFrames();
00522
00524
00526 void setBytesLoaded(unsigned long bytes)
00527 {
00528 boost::mutex::scoped_lock lock(_bytes_loaded_mutex);
00529 _bytes_loaded=bytes;
00530 }
00531
00533 bool _loadingCanceled;
00534
00536 std::set< boost::intrusive_ptr<movie_definition> > _importSources;
00537
00538 private:
00539
00542
00546 const RunResources& _runResources;
00547
00548 bool _as3;
00549
00550 };
00551
00552 }
00553
00554 #endif