Public Types | Public Member Functions | Public Attributes

gnash::sound::EmbedSound Class Reference

Definition of an embedded sound. More...

#include <EmbedSound.h>

List of all members.

Public Types

typedef std::map
< boost::uint32_t,
boost::uint32_t > 
FrameSizeMap
typedef std::list
< EmbedSoundInst * > 
Instances
 Vector containing the active instances of this sounds being played.

Public Member Functions

 EmbedSound (std::auto_ptr< SimpleBuffer > data, std::auto_ptr< media::SoundInfo > info, int nVolume, size_t paddingBytes)
 Construct a sound with given data, info and volume.
 ~EmbedSound ()
void append (boost::uint8_t *data, unsigned int size)
 Append size bytes to this sound.
size_t size () const
 Return size of the data buffer.
bool empty () const
 Is the data buffer empty ?
const boost::uint8_t * data () const
 Return a pointer to the underlying buffer.
boost::uint8_t * data ()
 Return a pointer to the underlying buffer.
const boost::uint8_t * data (size_t pos) const
 Return a pointer to an offset in the underlying buffer.
boost::uint8_t * data (size_t pos)
 Return a pointer to an offset in the underlying buffer.
bool isPlaying () const
 Are there known playing instances of this sound ?
size_t numPlayingInstances () const
 Return number of playing instances of this sound.
void getPlayingInstances (std::vector< InputStream * > &to) const
 Append to the given vector all playing instances of this sound def.
EmbedSoundInstfirstPlayingInstance () const
 Return the first created instance of this sound.
std::auto_ptr< EmbedSoundInstcreateInstance (media::MediaHandler &mh, unsigned long blockOffset, unsigned int inPoint, unsigned int outPoint, const SoundEnvelopes *envelopes, unsigned int loopCount)
 Create an instance of this sound.
void clearInstances ()
 Drop all active sounds.
Instances::iterator eraseActiveSound (Instances::iterator i)
 Drop an active sound (by iterator).
void eraseActiveSound (EmbedSoundInst *inst)
 Drop an active sound (by pointer).

Public Attributes

std::auto_ptr< media::SoundInfosoundinfo
 Object holding information about the sound.
FrameSizeMap m_frames_size
 Maps frame sizes to start-of-frame offsets.
int volume
Instances _soundInstances
 Playing instances of this sound definition.
boost::mutex _soundInstancesMutex
 Mutex protecting access to _soundInstances.
const size_t _paddingBytes

Detailed Description

Definition of an embedded sound.


Member Typedef Documentation

typedef std::map<boost::uint32_t,boost::uint32_t> gnash::sound::EmbedSound::FrameSizeMap

Vector containing the active instances of this sounds being played.

NOTE: This class does NOT own the active sounds


Constructor & Destructor Documentation

gnash::sound::EmbedSound::EmbedSound ( std::auto_ptr< SimpleBuffer data,
std::auto_ptr< media::SoundInfo info,
int  nVolume,
size_t  paddingBytes 
)

Construct a sound with given data, info and volume.

Parameters:
data The encoded sound data. May be the NULL pointer for streaming sounds, in which case data will be appended later using append()
info encoding info
nVolume initial volume (0..100). Optional, defaults to 100.

Referenced by append().

gnash::sound::EmbedSound::~EmbedSound (  ) 

Member Function Documentation

void gnash::sound::EmbedSound::append ( boost::uint8_t *  data,
unsigned int  size 
)

Append size bytes to this sound.

Parameters:
data Data bytes, allocated with new[]. Ownership transferred.
size Size of the 'data' buffer.

Todo:
, rather then copying the data over, keep it in its original form (multi-buffer) This way we avoid memory copies and we'd have no need for the additional m_frames_sizes map..

References _buf, _paddingBytes, data, EmbedSound(), info, m_frames_size, and volume.

Referenced by gnash::sound::sound_handler::addSoundBlock().

void gnash::sound::EmbedSound::clearInstances (  ) 

Drop all active sounds.

Locks _soundInstancesMutex

References _buf.

std::auto_ptr< EmbedSoundInst > gnash::sound::EmbedSound::createInstance ( media::MediaHandler mh,
unsigned long  blockOffset,
unsigned int  inPoint,
unsigned int  outPoint,
const SoundEnvelopes envelopes,
unsigned int  loopCount 
)

Create an instance of this sound.

The returned instance ownership is transferred

Parameters:
mh The MediaHandler to use for on-demand decoding
blockOffset Byte offset in the immutable (encoded) data this instance should start decoding. This is currently used for streaming embedded sounds to refer to a specific StreamSoundBlock.
See also:
gnash::swf::StreamSoundBlockTag
Parameters:
inPoint Offset in output samples this instance should start playing from. These are post-resampling samples from the start of the specified blockId.
outPoint Offset in output samples this instance should stop playing at. These are post-resampling samples from the start of the specified blockId.
envelopes SoundEnvelopes to apply to this sound. May be 0 for none.
loopCount Number of times this instance should loop over the defined sound.
Todo:
document if every loop starts at secsOffset !
Todo:
split this in createEventSoundInstance and createStreamingSoundInstance

Locks the _soundInstancesMutex when pushing to it

References _soundInstances, and _soundInstancesMutex.

const boost::uint8_t* gnash::sound::EmbedSound::data (  )  const [inline]

Return a pointer to the underlying buffer.

boost::uint8_t* gnash::sound::EmbedSound::data (  )  [inline]

Return a pointer to the underlying buffer.

const boost::uint8_t* gnash::sound::EmbedSound::data ( size_t  pos  )  const [inline]

Return a pointer to an offset in the underlying buffer.

Parameters:
pos The offset value. An assertion will fail if pos > size()

References size().

boost::uint8_t* gnash::sound::EmbedSound::data ( size_t  pos  )  [inline]

Return a pointer to an offset in the underlying buffer.

Parameters:
pos The offset value. An assertion will fail if pos > size()

References size().

bool gnash::sound::EmbedSound::empty (  )  const [inline]

Is the data buffer empty ?

EmbedSound::Instances::iterator gnash::sound::EmbedSound::eraseActiveSound ( Instances::iterator  i  ) 

Drop an active sound (by iterator).

Does *NOT* lock the _soundInstancesMutex

Returns:
iterator after the one being erased

References _buf.

Referenced by gnash::sound::EmbedSoundInst::~EmbedSoundInst().

void gnash::sound::EmbedSound::eraseActiveSound ( EmbedSoundInst inst  ) 

Drop an active sound (by pointer).

Parameters:
inst The active sound instance to unregister

This is intended to be called by EmbedSoundInst destructor, which may be called by a separate thread so MUST be thread-safe

Does lock the _soundInstancesMutex

Todo:
make private and mark EmbedSoundInst as friend ?
EmbedSoundInst * gnash::sound::EmbedSound::firstPlayingInstance (  )  const

Return the first created instance of this sound.

Locks _soundInstancesMutex

References _soundInstances, and _soundInstancesMutex.

Referenced by gnash::sound::sound_handler::tell().

void gnash::sound::EmbedSound::getPlayingInstances ( std::vector< InputStream * > &  to  )  const

Append to the given vector all playing instances of this sound def.

References _soundInstances, and _soundInstancesMutex.

bool gnash::sound::EmbedSound::isPlaying (  )  const

Are there known playing instances of this sound ?

Locks _soundInstancesMutex

Referenced by gnash::sound::sound_handler::tell().

size_t gnash::sound::EmbedSound::numPlayingInstances (  )  const

Return number of playing instances of this sound.

Locks _soundInstancesMutex

Referenced by gnash::sound::sound_handler::delete_all_sounds().

size_t gnash::sound::EmbedSound::size (  )  const [inline]

Return size of the data buffer.

Referenced by gnash::sound::sound_handler::addSoundBlock(), and data().


Member Data Documentation

Referenced by append().

Playing instances of this sound definition.

Multithread access to this member is protected by the _soundInstancesMutex mutex

Todo:
make private

Referenced by createInstance(), firstPlayingInstance(), and getPlayingInstances().

Mutex protecting access to _soundInstances.

Todo:
make private

Referenced by createInstance(), firstPlayingInstance(), and getPlayingInstances().

Maps frame sizes to start-of-frame offsets.

Referenced by append().

Object holding information about the sound.

Referenced by gnash::sound::sound_handler::get_duration(), and gnash::sound::sound_handler::startSound().

Volume for AS-sounds, range: 0-100. It's the SWF range that is represented here.


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