Public Member Functions

gnash::SWFMovieDefinition Class Reference

Immutable definition of a SWF movie's contents. More...

#include <SWFMovieDefinition.h>

Inheritance diagram for gnash::SWFMovieDefinition:
Inheritance graph
[legend]
Collaboration diagram for gnash::SWFMovieDefinition:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 SWFMovieDefinition (const RunResources &runResources)
 Construct a SWF movie.
 ~SWFMovieDefinition ()
size_t get_frame_count () const
 Return total number of frames advertised for the SWFMovie.
float get_frame_rate () const
 Return frame rate advertised for the SWFMovie.
const SWFRectget_frame_size () const
 Return dimensions of the SWFMovie.
size_t get_width_pixels () const
 Frame width in pixels.
size_t get_height_pixels () const
 Frame height in pixels.
void setAS3 ()
 Call this to inform callers that tags should be executed using AVM2.
bool isAS3 () const
 Check whether tags should be executed using AVM2.
virtual int get_version () const
 Return the advertised version for the SWFMovie.
virtual size_t get_loading_frame () const
 Get the number of fully loaded frames.
size_t get_bytes_loaded () const
 Get number of bytes loaded from input stream.
size_t get_bytes_total () const
 Get total number of bytes as parsed from the SWF header.
virtual void importResources (boost::intrusive_ptr< movie_definition > source, const Imports &imports)
 Import resources.
virtual void addDisplayObject (boost::uint16_t id, SWF::DefinitionTag *c)
SWF::DefinitionTaggetDefinitionTag (boost::uint16_t id) const
 Return a DisplayObject from the dictionary.
bool get_labeled_frame (const std::string &label, size_t &frame_number) const
 Get 0-based index of the frame with given label.
void add_font (int font_id, Font *f)
 Add a font DisplayObject with given ID to the CharacterDictionary.
Fontget_font (int font_id) const
 Return the font with given DisplayObject id.
Fontget_font (const std::string &name, bool bold, bool italic) const
 Find a font from the movie (not shared) lib.
CachedBitmapgetBitmap (int DisplayObject_id) const
 Get a bitmap from the bitmap dictionary.
void addBitmap (int DisplayObject_id, boost::intrusive_ptr< CachedBitmap > im)
 Add a bitmap DisplayObject in the dictionary, with the specified DisplayObject id.
sound_sampleget_sound_sample (int DisplayObject_id) const
 Get the sound sample with given ID.
virtual void add_sound_sample (int DisplayObject_id, sound_sample *sam)
 Add a sound sample DisplayObject in the dictionary, with the specified DisplayObject id.
virtual void set_loading_sound_stream_id (int id)
 Set the currently being loaded sound stream.
int get_loading_sound_stream_id () const
 Get the currently being loaded sound stream, if any.
void addControlTag (SWF::ControlTag *tag)
 Add an ControlTag to this movie_definition's playlist.
void add_frame_name (const std::string &name)
 Labels the frame currently being loaded with the given name.
void set_jpeg_loader (std::auto_ptr< image::JpegInput > j_in)
image::JpegInputget_jpeg_loader () const
 Get the jpeg input loader, to load a DefineBits image (one without table info).
virtual const PlayListgetPlaylist (size_t frame_number) const
 Return the list of execute tags for given frame number.
bool readHeader (std::auto_ptr< IOChannel > in, const std::string &url)
 Read the header of the SWF file.
bool completeLoad ()
 Complete load of the SWF file.
bool ensure_frame_loaded (size_t framenum) const
 Ensure that frame number 'framenum' (1-based offset) has been loaded (load on demand).
void read_all_swf ()
 Read and parse all the SWF stream (blocking until load is finished).
MoviecreateMovie (Global_as &gl, DisplayObject *parent=0)
 Create an instance of this movie.
virtual DisplayObjectcreateDisplayObject (Global_as &, DisplayObject *) const
 Create a DisplayObject with the given parent.
virtual const std::string & get_url () const
 Return the URL of the SWF stream this definition has been read from.
boost::uint16_t exportID (const std::string &symbol) const
 Get the id that corresponds to a symbol.
void registerExport (const std::string &symbol, boost::uint16_t id)
 Register a symbol to refer to a character id.

Detailed Description

Immutable definition of a SWF movie's contents.

It cannot be played directly, and does not hold current state; for that you need to call createMovie() to get a movie instance


Constructor & Destructor Documentation

gnash::SWFMovieDefinition::SWFMovieDefinition ( const RunResources runResources  ) 

Construct a SWF movie.

Parameters:
runResources A RunResources containing information used for parsing.
gnash::SWFMovieDefinition::~SWFMovieDefinition (  ) 

Member Function Documentation

void gnash::SWFMovieDefinition::add_font ( int  ,
Font  
) [virtual]

Add a font DisplayObject with given ID to the CharacterDictionary.

This method is here to be called by DEFINEFONT tags loaders. The default implementation does nothing.

Reimplemented from gnash::movie_definition.

Referenced by importResources().

void gnash::SWFMovieDefinition::add_frame_name ( const std::string &   )  [virtual]

Labels the frame currently being loaded with the given name.

A copy of the name string is made and kept in this object. In case of multiple frames with the same name, the last added will be the one referenced by that name.

The default implementation is a no-op.

Reimplemented from gnash::movie_definition.

void gnash::SWFMovieDefinition::add_sound_sample ( int  ,
sound_sample  
) [virtual]

Add a sound sample DisplayObject in the dictionary, with the specified DisplayObject id.

The default implementation is a no-op

Reimplemented from gnash::movie_definition.

References _, IF_VERBOSE_PARSE, and gnash::sound_sample::m_sound_handler_id.

void gnash::SWFMovieDefinition::addBitmap ( int  ,
boost::intrusive_ptr< CachedBitmap  
) [virtual]

Add a bitmap DisplayObject in the dictionary, with the specified DisplayObject id.

The default implementation is a no-op (deletes the image data).

Reimplemented from gnash::movie_definition.

void gnash::SWFMovieDefinition::addControlTag ( SWF::ControlTag  )  [inline, virtual]

Add an ControlTag to this movie_definition's playlist.

The default implementation is a no-op.

Parameters:
tag The tag to add in the list of executable tags for the frame currently being loaded. Ownership is transferred to the SWFMovieDefinition.

TODO: take an auto_ptr. NOTE: the default implementation just let the ControlTag leak.

Reimplemented from gnash::movie_definition.

Referenced by addDisplayObject().

void gnash::SWFMovieDefinition::addDisplayObject ( boost::uint16_t  id,
SWF::DefinitionTag c 
) [virtual]
bool gnash::SWFMovieDefinition::completeLoad (  )  [virtual]

Complete load of the SWF file.

This function completes parsing of the SWF stream engaging a separate thread. Make sure you called readHeader before this!

Returns:
false if the loading thread could not be started.

Reimplemented from gnash::movie_definition.

References _, ensure_frame_loaded(), read_all_swf(), gnash::SWFMovieLoader::start(), and gnash::SWFMovieLoader::started().

virtual DisplayObject* gnash::SWFMovieDefinition::createDisplayObject ( Global_as gl,
DisplayObject parent 
) const [inline, virtual]

Create a DisplayObject with the given parent.

This function will determine the correct prototype and associated object using the passed global.

Parameters:
gl The global object used to set prototype and associated object. Calling this function creates a new DisplayObject from the DefinitionTag and adds it as a child of the specified parent DisplayObject.

Implements gnash::SWF::DefinitionTag.

Movie * gnash::SWFMovieDefinition::createMovie ( Global_as gl,
DisplayObject parent = 0 
) [virtual]

Create an instance of this movie.

TOCHECK: Make sure you called completeLoad() before this function is invoked (calling read() will do that for you).

TOCHECK: The _root reference of the newly created movie_root will be set to a newly created Movie.

Reimplemented from gnash::movie_definition.

Reimplemented in gnash::DummyMovieDefinition.

References gnash::NSV::CLASS_MOVIE_CLIP, gnash::getObjectWithPrototype(), and gnash::key::o.

bool gnash::SWFMovieDefinition::ensure_frame_loaded ( size_t  framenum  )  const [virtual]

Ensure that frame number 'framenum' (1-based offset) has been loaded (load on demand).

Reimplemented from gnash::movie_definition.

Reimplemented in gnash::DummyMovieDefinition.

Referenced by completeLoad().

boost::uint16_t gnash::SWFMovieDefinition::exportID ( const std::string &  symbol  )  const [virtual]

Get the id that corresponds to a symbol.

This function is thread-safe.

Parameters:
symbol The symbol to lookup in the table.
Returns:
The id corresponding to the passed symbol. 0 is not a valid id and signifies that the symbol was not (yet) exported.

Reimplemented from gnash::movie_definition.

size_t gnash::SWFMovieDefinition::get_bytes_loaded (  )  const [inline, virtual]

Get number of bytes loaded from input stream.

NOTE: this method locks _bytes_loaded_mutex

Implements gnash::movie_definition.

Reimplemented in gnash::DummyMovieDefinition.

size_t gnash::SWFMovieDefinition::get_bytes_total (  )  const [inline, virtual]

Get total number of bytes as parsed from the SWF header.

Implements gnash::movie_definition.

Reimplemented in gnash::DummyMovieDefinition.

Font * gnash::SWFMovieDefinition::get_font ( int   )  const [virtual]

Return the font with given DisplayObject id.

Returns:
NULL if the given id doesn't correspond to any registered font (default).
See also:
add_font

Reimplemented from gnash::movie_definition.

References s2x::f.

Font * gnash::SWFMovieDefinition::get_font ( const std::string &  ,
bool  ,
bool   
) const [virtual]

Find a font from the movie (not shared) lib.

Reimplemented from gnash::movie_definition.

References s2x::f, and gnash::Font::matches().

size_t gnash::SWFMovieDefinition::get_frame_count (  )  const [inline, virtual]

Return total number of frames advertised for the SWFMovie.

Implements gnash::movie_definition.

Reimplemented in gnash::DummyMovieDefinition.

float gnash::SWFMovieDefinition::get_frame_rate (  )  const [inline, virtual]

Return frame rate advertised for the SWFMovie.

Implements gnash::movie_definition.

Reimplemented in gnash::DummyMovieDefinition.

const SWFRect& gnash::SWFMovieDefinition::get_frame_size (  )  const [inline, virtual]

Return dimensions of the SWFMovie.

Implements gnash::movie_definition.

Reimplemented in gnash::DummyMovieDefinition.

size_t gnash::SWFMovieDefinition::get_height_pixels (  )  const [inline, virtual]

Frame height in pixels.

The frame size is in twips and may be rounded up.

Implements gnash::movie_definition.

Reimplemented in gnash::DummyMovieDefinition.

References gnash::SWFRect::height(), and gnash::twipsToPixels().

image::JpegInput* gnash::SWFMovieDefinition::get_jpeg_loader (  )  const [inline, virtual]

Get the jpeg input loader, to load a DefineBits image (one without table info).

This method should probably not be there but in some higher-level class, like a Parser class..

The default implementation returns NULL

NOTE: ownership of the returned object is NOT transferred

Reimplemented from gnash::movie_definition.

bool gnash::SWFMovieDefinition::get_labeled_frame ( const std::string &  ,
size_t &   
) const [virtual]

Get 0-based index of the frame with given label.

The default implementation is to always return false, as if NO frame with given label was found.

Parameters:
label Label of the frame we're looking for.
frame_number Where to write frame number to (if a match is found). A 0-based index will be written there.
Returns:
true if a frame with that label was found, false otherwise

Reimplemented from gnash::movie_definition.

size_t gnash::SWFMovieDefinition::get_loading_frame (  )  const [virtual]

Get the number of fully loaded frames.

The number returned is also the index of the frame currently being loaded/parsed, except when parsing finishes, in which case it an index to on-past-last frame.

NOTE: this method locks _frames_loaded_mutex

Implements gnash::movie_definition.

Reimplemented in gnash::DummyMovieDefinition.

Referenced by read_all_swf().

int gnash::SWFMovieDefinition::get_loading_sound_stream_id (  )  const [inline, virtual]

Get the currently being loaded sound stream, if any.

See also:
set_loading_sound_stream_id

The default implementation returns -1

Returns:
-1 if no sound stream is being currently loading

Reimplemented from gnash::movie_definition.

sound_sample * gnash::SWFMovieDefinition::get_sound_sample ( int   )  const [virtual]

Get the sound sample with given ID.

Returns:
NULL if the given DisplayObject ID isn't found in the dictionary or it is not a sound sample.

The default implementation always returns NULL

Reimplemented from gnash::movie_definition.

virtual const std::string& gnash::SWFMovieDefinition::get_url (  )  const [inline, virtual]

Return the URL of the SWF stream this definition has been read from.

Implements gnash::movie_definition.

Reimplemented in gnash::DummyMovieDefinition.

Referenced by importResources(), and registerExport().

virtual int gnash::SWFMovieDefinition::get_version (  )  const [inline, virtual]

Return the advertised version for the SWFMovie.

This is stored and used in AS interpretation for some version-based behaviour.

Implements gnash::movie_definition.

Reimplemented in gnash::DummyMovieDefinition.

size_t gnash::SWFMovieDefinition::get_width_pixels (  )  const [inline, virtual]

Frame width in pixels.

The frame size is in twips and may be rounded up.

Implements gnash::movie_definition.

Reimplemented in gnash::DummyMovieDefinition.

References gnash::twipsToPixels(), and gnash::SWFRect::width().

CachedBitmap * gnash::SWFMovieDefinition::getBitmap ( int   )  const [virtual]

Get a bitmap from the bitmap dictionary.

Note that only top-level movies (those belonging to a single SWF stream) have a bitmap dictionary, thus our SWFMovieDefinition. The other derived class, sprite_definition will seek for DisplayObjects in its base SWFMovieDefinition.

Returns:
0 if no DisplayObject with the given ID is found, or if the corresponding DisplayObject is not a bitmap.

The default implementation returns 0.

Reimplemented from gnash::movie_definition.

SWF::DefinitionTag * gnash::SWFMovieDefinition::getDefinitionTag ( boost::uint16_t  id  )  const [virtual]

Return a DisplayObject from the dictionary.

Reimplemented from gnash::movie_definition.

References gnash::CharacterDictionary::getDisplayObject().

virtual const PlayList* gnash::SWFMovieDefinition::getPlaylist ( size_t   )  const [inline, virtual]

Return the list of execute tags for given frame number.

Parameters:
frame_number Frame number, 0-based (ie: first frame is 0)
Returns:
NULL if no execute tags are defined for the given frame number (the default implementation) or a pointer to the vector of them (PlayList)

Reimplemented from gnash::movie_definition.

void gnash::SWFMovieDefinition::importResources ( boost::intrusive_ptr< movie_definition ,
const Imports  
) [virtual]

Import resources.

Parameters:
source Movie containing the resources being imported
imports Resources to import, each with the id to use in our dictionary

Reimplemented from gnash::movie_definition.

References _, add_font(), addDisplayObject(), gnash::key::e, s2x::f, get_url(), gnash::gnashSleep(), gnash::key::i, and registerExport().

bool gnash::SWFMovieDefinition::isAS3 (  )  const [inline, virtual]

Check whether tags should be executed using AVM2.

Reimplemented from gnash::movie_definition.

void gnash::SWFMovieDefinition::read_all_swf (  ) 

Read and parse all the SWF stream (blocking until load is finished).

This function uses a private TagLoadersTable to interpret specific tag types. Currently the TagLoadersTable in use is the TagLoadersTable singleton.

References _, gnash::key::e, get_loading_frame(), IF_VERBOSE_MALFORMED_SWF, gnash::SWFMovieLoader::isSelfThread(), gnash::SWFMovieLoader::started(), and startPos.

Referenced by completeLoad().

bool gnash::SWFMovieDefinition::readHeader ( std::auto_ptr< IOChannel in,
const std::string &  url 
)

Read the header of the SWF file.

This function only reads the header of the SWF stream and assigns the movie an URL. Call completeLoad() to fire up the loader thread.

Parameters:
in the IOChannel from which to read SWF
url the url associated with the input
Returns:
false if SWF header could not be parsed

References _, IF_VERBOSE_MALFORMED_SWF, IF_VERBOSE_PARSE, gnash::SWFRect::is_null(), gnash::zlib_adapter::make_inflater(), and gnash::SWFRect::read().

void gnash::SWFMovieDefinition::registerExport ( const std::string &  symbol,
boost::uint16_t  id 
) [virtual]

Register a symbol to refer to a character id.

This function is thread safe.

Parameters:
id The id of the character to map to the symbol. NB: this must never be 0!
symbol The symbol to map to the id.

Reimplemented from gnash::movie_definition.

References get_url().

Referenced by importResources().

void gnash::SWFMovieDefinition::set_jpeg_loader ( std::auto_ptr< image::JpegInput j_in  )  [inline, virtual]

Set an input object for later loading DefineBits images (JPEG images without the table info).

There should be only one JPEGTABLES tag in an SWF (see: http://www.m2osw.com/en/swf_alexref.html#tag_jpegtables) Discard any subsequent attempts to set the jpeg loader to avoid crashing on very malformed SWFs. (No conclusive tests for pp behaviour, though one version also crashes out on the malformed SWF that triggers this assert in Gnash).

Reimplemented from gnash::movie_definition.

References _.

virtual void gnash::SWFMovieDefinition::set_loading_sound_stream_id ( int   )  [inline, virtual]

Set the currently being loaded sound stream.

The default implementation is a no-op

Reimplemented from gnash::movie_definition.

void gnash::SWFMovieDefinition::setAS3 (  )  [inline, virtual]

Call this to inform callers that tags should be executed using AVM2.

Reimplemented from gnash::movie_definition.


The documentation for this class was generated from the following files: