[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] gnash ChangeLog backend/sound_handler.h backend...
From: |
Tomas Groth |
Subject: |
[Gnash-commit] gnash ChangeLog backend/sound_handler.h backend... |
Date: |
Fri, 10 Aug 2007 10:24:11 +0000 |
CVSROOT: /sources/gnash
Module name: gnash
Changes by: Tomas Groth <tgc> 07/08/10 10:24:11
Modified files:
. : ChangeLog
backend : sound_handler.h sound_handler_gst.cpp
sound_handler_gst.h sound_handler_sdl.cpp
sound_handler_sdl.h
server/swf : tag_loaders.cpp
Log message:
* backend/sound_handler.h,
backend/sound_handler_{sdl,gst}.{h,cpp},
server/swf/tag_loaders.cpp: Introduce the SoundInfo class
which
contains the properties of the sound (format, samplerate,
etc.).
When parsing a sound-tag the SoundInfo-object is created and
passed to the soundhandler along with the audio data, and the
parser can later ask for the SoundInfo-object for a specific
sound, which is needed when parsing sound-streams.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.3981&r2=1.3982
http://cvs.savannah.gnu.org/viewcvs/gnash/backend/sound_handler.h?cvsroot=gnash&r1=1.23&r2=1.24
http://cvs.savannah.gnu.org/viewcvs/gnash/backend/sound_handler_gst.cpp?cvsroot=gnash&r1=1.59&r2=1.60
http://cvs.savannah.gnu.org/viewcvs/gnash/backend/sound_handler_gst.h?cvsroot=gnash&r1=1.14&r2=1.15
http://cvs.savannah.gnu.org/viewcvs/gnash/backend/sound_handler_sdl.cpp?cvsroot=gnash&r1=1.79&r2=1.80
http://cvs.savannah.gnu.org/viewcvs/gnash/backend/sound_handler_sdl.h?cvsroot=gnash&r1=1.31&r2=1.32
http://cvs.savannah.gnu.org/viewcvs/gnash/server/swf/tag_loaders.cpp?cvsroot=gnash&r1=1.127&r2=1.128
Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.3981
retrieving revision 1.3982
diff -u -b -r1.3981 -r1.3982
--- ChangeLog 10 Aug 2007 04:36:12 -0000 1.3981
+++ ChangeLog 10 Aug 2007 10:24:10 -0000 1.3982
@@ -1,3 +1,13 @@
+2007-08-10 Tomas Groth Christensen <address@hidden>
+
+ * backend/sound_handler.h, backend/sound_handler_{sdl,gst}.{h,cpp},
+ server/swf/tag_loaders.cpp: Introduce the SoundInfo class which
+ contains the properties of the sound (format, samplerate, etc.).
+ When parsing a sound-tag the SoundInfo-object is created and
+ passed to the soundhandler along with the audio data, and the
+ parser can later ask for the SoundInfo-object for a specific
+ sound, which is needed when parsing sound-streams.
+
2007-08-10 Alexander Sack <address@hidden>
* backend/Makefile.am, libamf/Makefile.am, libbase/Makefile.am,
Index: backend/sound_handler.h
===================================================================
RCS file: /sources/gnash/gnash/backend/sound_handler.h,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -b -r1.23 -r1.24
--- backend/sound_handler.h 1 Aug 2007 16:53:47 -0000 1.23
+++ backend/sound_handler.h 10 Aug 2007 10:24:11 -0000 1.24
@@ -18,7 +18,7 @@
//
//
-/* $Id: sound_handler.h,v 1.23 2007/08/01 16:53:47 strk Exp $ */
+/* $Id: sound_handler.h,v 1.24 2007/08/10 10:24:11 tgc Exp $ */
/// \page sound_handler_intro Sound handler introduction
///
@@ -36,9 +36,11 @@
#include "tu_types.h"
#include <vector>
+#include <memory>
namespace gnash {
class stream;
+ class SoundInfo;
}
namespace gnash {
@@ -95,27 +97,16 @@
/// @param data_bytes
/// The size of the data to be stored. For soundstream this is 0.
///
- /// @param sample_count
- /// Number of samples in the data.
- ///
- /// @param format
- /// Defines what sound type the data is.
- ///
- /// @param sample_rate
- /// The sample rate of the sound.
- ///
- /// @param stereo
- /// Defines whether the sound is in stereo.
+ /// @param sinfo
+ /// A SoundInfo object contained in an auto_ptr, which contains info
about samplerate,
+ /// samplecount, stereo and more. The SoundObject must be not-NULL!
///
/// @return the id given by the soundhandler for later identification.
///
virtual int create_sound(
void* data,
- int data_bytes,
- int sample_count,
- format_type format,
- int sample_rate, /* one of 5512, 11025, 22050,
44100 */
- bool stereo
+ unsigned int data_bytes,
+ std::auto_ptr<SoundInfo> sinfo
) = 0;
/// gnash's parser calls this to fill up soundstreams data
@@ -133,20 +124,17 @@
/// @param handle_id
/// The soundhandlers id of the sound we want some info about.
///
- virtual long fill_stream_data(void* data, int data_bytes, int
sample_count, int handle_id) = 0;
+ virtual long fill_stream_data(void* data, unsigned int data_bytes,
unsigned int sample_count, int handle_id) = 0;
- /// Gives info about the format, samplerate and stereo of the sound in
question.
+ /// Returns a pointer to the SoundInfo object for the sound with the
given id.
+ /// The SoundInfo object is still owned by the soundhandler.
//
/// @param soundhandle
/// The soundhandlers id of the sound we want some info about.
///
- /// @param format
- /// Here the format id will be placed.
- ///
- /// @param stereo
- /// Here will be placed whether or not the sound is stereo.
+ /// @return a pointer to the SoundInfo object for the sound with the
given id.
///
- virtual void get_info(int sound_handle, int* format, bool* stereo) = 0;
+ virtual SoundInfo* get_sound_info(int sound_handle) = 0;
/// gnash calls this when it wants you to play the defined sound.
//
@@ -300,6 +288,97 @@
size_t _soundsStopped;
};
+///
+/// Class containing information about a sound. Is created by the parser while
+/// parsing, and ownership is then transfered to sound_data. When the parser is
+/// parsing streams, it will ask the soundhandler for this to know what
properties
+/// the stream has.
+///
+class SoundInfo {
+public:
+ /// Constructor
+ //
+ /// @param format
+ /// The format of the sound. Can be MP3, ADPCM, uncompressed or
Nellymoser
+ ///
+ /// @param stero
+ /// Defines whether the sound is in stereo.
+ ///
+ /// @param sampleRate
+ /// The sample rate of the sound.
+ ///
+ /// @param sampleCount
+ /// The sample count in the sound. In soundstreams this is an average
for each frame.
+ ///
+ /// @param is16bit
+ /// Defines whether the sound is in stereo.
+ /// Defines whether the sound is in 16bit format (samplesize == 2)?
else it
+ /// is 8bit (samplesize == 1). Used for streams when decoding adpcm.
+ ///
+ SoundInfo(sound_handler::format_type format, sound_handler::format_type
orgFormat, bool stereo, uint32_t sampleRate, uint32_t sampleCount, bool is16bit)
+ : _format(format),
+ _orgFormat(orgFormat),
+ _stereo(stereo),
+ _sampleRate(sampleRate),
+ _sampleCount(sampleCount),
+ _is16bit(is16bit)
+ {
+ }
+
+ /// Returns the current format of the sound
+ ///
+ /// @return the current format of the sound
+ sound_handler::format_type getFormat() { return _format; }
+
+ /// Returns the original format of the sound
+ ///
+ /// @return the original format of the sound
+ sound_handler::format_type getOrgFormat() { return _orgFormat; }
+
+ /// Returns the stereo status of the sound
+ ///
+ /// @return the stereo status of the sound
+ bool isStereo() { return _stereo; }
+
+ /// Returns the samplerate of the sound
+ ///
+ /// @return the samplerate of the sound
+ unsigned long getSampleRate() { return _sampleRate; }
+
+ /// Returns the samplecount of the sound
+ ///
+ /// @return the samplecount of the sound
+ unsigned long getSampleCount() { return _sampleCount; }
+
+ /// Returns the 16bit status of the sound
+ ///
+ /// @return the 16bit status of the sound
+ bool is16bit() { return _is16bit; }
+
+private:
+ /// Current format of the sound (MP3, raw, etc).
+ sound_handler::format_type _format;
+
+ /// Original format of the sound (ADPCM, etc).
+ sound_handler::format_type _orgFormat;
+
+ /// The size of the undecoded data
+ unsigned long _dataSize;
+
+ /// Stereo or not
+ bool _stereo;
+
+ /// Sample rate, one of 5512, 11025, 22050, 44100
+ uint32_t _sampleRate;
+
+ /// Number of samples
+ uint32_t _sampleCount;
+
+ /// Is the audio in 16bit format (samplesize == 2)? else it
+ /// is 8bit (samplesize == 1). Used for streams when decoding adpcm.
+ bool _is16bit;
+};
+
// TODO: move to appropriate specific sound handlers
DSOEXPORT sound_handler* create_sound_handler_sdl();
DSOEXPORT sound_handler* create_sound_handler_gst();
Index: backend/sound_handler_gst.cpp
===================================================================
RCS file: /sources/gnash/gnash/backend/sound_handler_gst.cpp,v
retrieving revision 1.59
retrieving revision 1.60
diff -u -b -r1.59 -r1.60
--- backend/sound_handler_gst.cpp 8 Aug 2007 10:39:50 -0000 1.59
+++ backend/sound_handler_gst.cpp 10 Aug 2007 10:24:11 -0000 1.60
@@ -20,7 +20,7 @@
// Based on sound_handler_sdl.cpp by Thatcher Ulrich http://tulrich.com 2003
// which has been donated to the Public Domain.
-/* $Id: sound_handler_gst.cpp,v 1.59 2007/08/08 10:39:50 tgc Exp $ */
+/* $Id: sound_handler_gst.cpp,v 1.60 2007/08/10 10:24:11 tgc Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -71,31 +71,26 @@
int GST_sound_handler::create_sound(
void* data,
- int data_bytes,
- int sample_count,
- format_type format,
- int sample_rate,
- bool stereo)
+ unsigned int data_bytes,
+ std::auto_ptr<SoundInfo> sinfo)
// Called to create a sample. We'll return a sample ID that
// can be use for playing it.
{
try_mutex::scoped_lock lock(_mutex);
+ assert(sinfo.get());
sound_data *sounddata = new sound_data;
if (!sounddata) {
- log_error(_("Could not allocate memory for sound data"));
+ log_error(_("could not allocate memory for sound data"));
return -1;
}
- sounddata->format = format;
sounddata->data_size = data_bytes;
- sounddata->stereo = stereo;
- sounddata->sample_count = sample_count;
- sounddata->sample_rate = sample_rate;
sounddata->volume = 100;
+ sounddata->soundinfo = sinfo;
- switch (format)
+ switch (sounddata->soundinfo->getFormat())
{
case FORMAT_NATIVE16:
sounddata->data = new guint8[data_bytes];
@@ -131,7 +126,7 @@
default:
// Unhandled format.
- log_error(_("Unknown sound format %d requested; gnash does not
handle it"), (int)format);
+ log_error(_("Unknown sound format %d requested; gnash does not
handle it"), (int)sounddata->soundinfo->getFormat());
return -1; // Unhandled format, set to NULL.
}
@@ -142,7 +137,7 @@
// this gets called when a stream gets more data
-long GST_sound_handler::fill_stream_data(void* data, int data_bytes, int
/*sample_count*/, int handle_id)
+long GST_sound_handler::fill_stream_data(void* data, unsigned int
data_bytes, unsigned int /*sample_count*/, int handle_id)
{
try_mutex::scoped_lock lock(_mutex);
@@ -359,7 +354,12 @@
// Create a gstreamer decoder for the chosen sound.
- if (sounddata->format == FORMAT_MP3) { // || sounddata->format ==
FORMAT_VORBIS) {
+ // Temp variables to make the code simpler and easier to read
+ format_type soundFormat = sounddata->soundinfo->getFormat();
+ bool soundStereo = sounddata->soundinfo->isStereo();
+ uint32_t soundSampleRate = sounddata->soundinfo->getSampleRate();
+
+ if (soundFormat == FORMAT_MP3) {
gst_element->decoder = gst_element_factory_make ("mad", NULL);
if (gst_element->decoder == NULL) {
@@ -386,8 +386,8 @@
GstCaps *caps = gst_caps_new_simple ("audio/mpeg",
"mpegversion", G_TYPE_INT, 1,
"layer", G_TYPE_INT, 3,
- "rate", G_TYPE_INT, sounddata->sample_rate,
- "channels", G_TYPE_INT, sounddata->stereo ? 2 : 1,
NULL);
+ "rate", G_TYPE_INT, soundSampleRate,
+ "channels", G_TYPE_INT, soundStereo ? 2 : 1, NULL);
g_object_set (G_OBJECT (gst_element->capsfilter), "caps", caps,
NULL);
gst_caps_unref (caps);
@@ -406,12 +406,12 @@
gst_element->audioresample,
gst_element->volume, NULL);
- } else if (sounddata->format == FORMAT_NATIVE16) {
+ } else if (soundFormat == FORMAT_NATIVE16) {
// Set the info about the stream so that gstreamer knows what
it is.
GstCaps *caps = gst_caps_new_simple ("audio/x-raw-int",
- "rate", G_TYPE_INT, sounddata->sample_rate,
- "channels", G_TYPE_INT, sounddata->stereo ? 2 : 1,
+ "rate", G_TYPE_INT, soundSampleRate,
+ "channels", G_TYPE_INT, soundStereo ? 2 : 1,
"endianness", G_TYPE_INT, G_BIG_ENDIAN,
"width", G_TYPE_INT, 16,
"depth", G_TYPE_INT, 16,
@@ -517,7 +517,6 @@
if (sound_handle >= 0 && (unsigned int) sound_handle <
m_sound_data.size())
{
- delete[] m_sound_data[sound_handle]->data;
delete m_sound_data[sound_handle];
m_sound_data.erase (m_sound_data.begin() + sound_handle);
}
@@ -580,15 +579,16 @@
}
-void GST_sound_handler::get_info(int sound_handle, int* format, bool* stereo) {
+SoundInfo* GST_sound_handler::get_sound_info(int sound_handle) {
try_mutex::scoped_lock lock(_mutex);
// Check if the sound exists.
- if (sound_handle >= 0 && (unsigned int) sound_handle <
m_sound_data.size())
+ if (sound_handle >= 0 && static_cast<unsigned int>(sound_handle) <
m_sound_data.size())
{
- *format = m_sound_data[sound_handle]->format;
- *stereo = m_sound_data[sound_handle]->stereo;
+ return m_sound_data[sound_handle]->soundinfo.get();
+ } else {
+ return NULL;
}
}
@@ -631,11 +631,14 @@
sound_data* sounddata = m_sound_data[sound_handle];
+ uint32_t sampleCount = sounddata->soundinfo->getSampleCount();
+ uint32_t sampleRate = sounddata->soundinfo->getSampleRate();
+
// Return the sound duration in milliseconds
- if (sounddata->sample_count > 0 && sounddata->sample_rate > 0) {
- unsigned int ret = sounddata->sample_count /
sounddata->sample_rate * 1000;
- ret += ((sounddata->sample_count % sounddata->sample_rate) *
1000) / sounddata->sample_rate;
- if (sounddata->stereo) ret = ret / 2;
+ if (sampleCount > 0 && sampleRate > 0) {
+ unsigned int ret = sampleCount / sampleRate * 1000;
+ ret += ((sampleCount % sampleRate) * 1000) / sampleRate;
+ if (sounddata->soundinfo->isStereo()) ret = ret / 2;
return ret;
} else {
return 0;
Index: backend/sound_handler_gst.h
===================================================================
RCS file: /sources/gnash/gnash/backend/sound_handler_gst.h,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -b -r1.14 -r1.15
--- backend/sound_handler_gst.h 1 Aug 2007 10:09:23 -0000 1.14
+++ backend/sound_handler_gst.h 10 Aug 2007 10:24:11 -0000 1.15
@@ -89,20 +89,11 @@
// The (un)compressed data
guint8* data;
- // data format
- int format;
-
// data size
long data_size;
- // stereo or not
- bool stereo;
-
- // number of samples
- int sample_count;
-
- // sample rate
- int sample_rate;
+ // Object holding information about the sound
+ std::auto_ptr<SoundInfo> soundinfo;
// Volume, SWF range: 0-100, GST range 0-10 (we only use 0-1, the rest
is amplified)
// It's the SWF range that is represented here
@@ -111,6 +102,11 @@
// gstreamer objects
std::vector<gst_elements*> m_gst_elements;
+ ~sound_data()
+ {
+ // TODO: use boost::scoped_array
+ delete [] data;
+ }
};
// Use gstreamer to handle sounds.
@@ -138,13 +134,12 @@
virtual ~GST_sound_handler();
/// Called to create a sound.
- virtual int create_sound(void* data, int data_bytes,
- int sample_count, format_type format,
- int sample_rate, bool stereo);
+ virtual int create_sound(void* data, unsigned int data_bytes,
+ std::auto_ptr<SoundInfo> sinfo);
/// this gets called when a stream gets more data
- virtual long fill_stream_data(void* data, int data_bytes,
- int sample_count, int handle_id);
+ virtual long fill_stream_data(void* data, unsigned int data_bytes,
+ unsigned int sample_count, int
handle_id);
/// Play the index'd sample.
virtual void play_sound(int sound_handle, int loop_count, int offset,
@@ -166,7 +161,7 @@
virtual void set_volume(int sound_handle, int volume);
/// Gnash uses this to get info about a sound. Used when a stream needs
more data.
- virtual void get_info(int sound_handle, int* format, bool* stereo);
+ virtual SoundInfo* get_sound_info(int sound_handle);
/// Gnash calls this to mute audio.
virtual void mute();
Index: backend/sound_handler_sdl.cpp
===================================================================
RCS file: /sources/gnash/gnash/backend/sound_handler_sdl.cpp,v
retrieving revision 1.79
retrieving revision 1.80
diff -u -b -r1.79 -r1.80
--- backend/sound_handler_sdl.cpp 8 Aug 2007 10:39:50 -0000 1.79
+++ backend/sound_handler_sdl.cpp 10 Aug 2007 10:24:11 -0000 1.80
@@ -18,7 +18,7 @@
// Based on sound_handler_sdl.cpp by Thatcher Ulrich http://tulrich.com 2003
// which has been donated to the Public Domain.
-// $Id: sound_handler_sdl.cpp,v 1.79 2007/08/08 10:39:50 tgc Exp $
+// $Id: sound_handler_sdl.cpp,v 1.80 2007/08/10 10:24:11 tgc Exp $
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -63,46 +63,42 @@
int SDL_sound_handler::create_sound(
void* data,
- int data_bytes,
- int sample_count,
- format_type format,
- int sample_rate,
- bool stereo)
+ unsigned int data_bytes,
+ std::auto_ptr<SoundInfo> sinfo)
// Called to create a sample. We'll return a sample ID that
// can be use for playing it.
{
+ assert(sinfo.get());
sound_data *sounddata = new sound_data;
if (!sounddata) {
log_error(_("could not allocate memory for sound data"));
return -1;
}
- sounddata->format = format;
sounddata->data_size = data_bytes;
- sounddata->stereo = stereo;
- sounddata->sample_count = sample_count;
- sounddata->sample_rate = sample_rate;
sounddata->volume = 100;
+ sounddata->soundinfo = sinfo;
int16_t* adjusted_data = 0;
int adjusted_size = 0;
mutex::scoped_lock lock(_mutex);
- switch (format)
+ switch (sounddata->soundinfo->getFormat())
{
case FORMAT_NATIVE16:
- if (data_bytes > 0) {
- convert_raw_data(&adjusted_data, &adjusted_size, data,
sample_count, 2, sample_rate, stereo,
+ if (sounddata->data_size > 0) {
+ convert_raw_data(&adjusted_data, &adjusted_size, data,
sounddata->soundinfo->getSampleCount(),
+ 2,
sounddata->soundinfo->getSampleRate(), sounddata->soundinfo->isStereo(),
audioSpec.freq, (audioSpec.channels ==
2 ? true : false));
if (!adjusted_data) {
log_error(_("Some kind of error occurred with
sound data"));
return -1;
}
sounddata->data_size = adjusted_size;
- sounddata->data = (Uint8*) adjusted_data;
+ sounddata->data =
reinterpret_cast<uint8_t*>(adjusted_data);
}
break;
@@ -137,7 +133,7 @@
default:
// Unhandled format.
- log_error(_("unknown sound format %d requested; gnash does not
handle it"), (int)format);
+ log_error(_("unknown sound format %d requested; gnash does not
handle it"), (int)sounddata->soundinfo->getFormat());
return -1; // Unhandled format, set to NULL.
}
@@ -149,7 +145,7 @@
}
// this gets called when a stream gets more data
-long SDL_sound_handler::fill_stream_data(void* data, int data_bytes, int
sample_count, int handle_id)
+long SDL_sound_handler::fill_stream_data(void* data, unsigned int
data_bytes, unsigned int sample_count, int handle_id)
{
mutex::scoped_lock lock(_mutex);
@@ -162,7 +158,7 @@
sound_data* sounddata = m_sound_data[handle_id];
// Handling of the sound data
- switch (sounddata->format) {
+ switch (sounddata->soundinfo->getFormat()) {
case FORMAT_NATIVE16:
{
int16_t* adjusted_data = 0;
@@ -170,7 +166,7 @@
convert_raw_data(&adjusted_data, &adjusted_size,
data, sample_count, 2 /*sample size*/,
- sounddata->sample_rate, sounddata->stereo,
+ sounddata->soundinfo->getSampleRate(),
sounddata->soundinfo->isStereo(),
audioSpec.freq, (audioSpec.channels == 2));
if (!adjusted_data || adjusted_size < 1) {
log_error(_("Some kind of error with resampling sound
data"));
@@ -199,6 +195,7 @@
case FORMAT_MP3:
{
+
// Reallocate the required memory.
Uint8* tmp_data = new Uint8[data_bytes + sounddata->data_size];
memcpy(tmp_data, sounddata->data, sounddata->data_size);
@@ -221,7 +218,7 @@
break;
default:
- log_error(_("Behavior for this audio codec %d is unknown.
Please send this SWF to the developers"), (int)(sounddata->format));
+ log_error(_("Behavior for this audio codec %d is unknown.
Please send this SWF to the developers"),
(int)(sounddata->soundinfo->getFormat()));
}
return start_size;
@@ -273,7 +270,7 @@
else sound->position = start_position;
if (offset < 0) sound->offset = 0;
- else sound->offset = (sounddata->stereo ? offset : offset*2); // offset
is stored as stereo
+ else sound->offset = (sounddata->soundinfo->isStereo() ? offset :
offset*2); // offset is stored as stereo
sound->envelopes = envelopes;
sound->current_env = 0;
@@ -282,7 +279,7 @@
// Set number of loop we should do. -1 is infinte loop, 0 plays it
once, 1 twice etc.
sound->loop_count = loop_count;
- if (sounddata->format == FORMAT_MP3) {
+ if (sounddata->soundinfo->getFormat() == FORMAT_MP3) {
#ifdef USE_FFMPEG
// Init the avdecoder-decoder
@@ -358,7 +355,7 @@
active_sound* sound = sounddata->m_active_sounds[i];
// Stop sound, remove it from the active list (mp3)
- if (sounddata->format == 2) {
+ if (sounddata->soundinfo->getFormat() == FORMAT_MP3) {
#ifdef USE_FFMPEG
avcodec_close(sound->cc);
av_parser_close(sound->parser);
@@ -411,7 +408,7 @@
active_sound* sound = sounddata->m_active_sounds[i];
// Stop sound, remove it from the active list (mp3)
- if (sounddata->format == 2) {
+ if (sounddata->soundinfo->getFormat() == FORMAT_MP3) {
#ifdef USE_FFMPEG
avcodec_close(sound->cc);
av_parser_close(sound->parser);
@@ -471,15 +468,16 @@
}
-void SDL_sound_handler::get_info(int sound_handle, int* format, bool* stereo) {
+SoundInfo* SDL_sound_handler::get_sound_info(int sound_handle) {
mutex::scoped_lock lock(_mutex);
// Check if the sound exists.
if (sound_handle >= 0 && static_cast<unsigned int>(sound_handle) <
m_sound_data.size())
{
- *format = m_sound_data[sound_handle]->format;
- *stereo = m_sound_data[sound_handle]->stereo;
+ return m_sound_data[sound_handle]->soundinfo.get();
+ } else {
+ return NULL;
}
}
@@ -552,11 +550,14 @@
sound_data* sounddata = m_sound_data[sound_handle];
+ uint32_t sampleCount = sounddata->soundinfo->getSampleCount();
+ uint32_t sampleRate = sounddata->soundinfo->getSampleRate();
+
// Return the sound duration in milliseconds
- if (sounddata->sample_count > 0 && sounddata->sample_rate > 0) {
- unsigned int ret = sounddata->sample_count /
sounddata->sample_rate * 1000;
- ret += ((sounddata->sample_count % sounddata->sample_rate) *
1000) / sounddata->sample_rate;
- if (sounddata->stereo) ret = ret / 2;
+ if (sampleCount > 0 && sampleRate > 0) {
+ unsigned int ret = sampleCount / sampleRate * 1000;
+ ret += ((sampleCount % sampleRate) * 1000) / sampleRate;
+ if (sounddata->soundinfo->isStereo()) ret = ret / 2;
return ret;
} else {
return 0;
@@ -774,7 +775,11 @@
sound_data* sounddata = handler->m_sound_data[i];
for(uint32_t j = 0; j < sounddata->m_active_sounds.size(); j++)
{
+ // Temp variables to make the code simpler and easier
to read
active_sound* sound = sounddata->m_active_sounds[j];
+ format_type soundFormat =
sounddata->soundinfo->getFormat();
+ bool soundStereo = sounddata->soundinfo->isStereo();
+ uint32_t soundSampleRate =
sounddata->soundinfo->getSampleRate();
// When the current sound dont have enough decoded data
to fill the buffer,
// we first mix what is already decoded, then decode
some more data, and
@@ -795,7 +800,7 @@
// If this isn't MP3 (which means its NATIVE16)
there is nothing to decode,
// reusing the available data is the only
option.
- if (sounddata->format != 2) {
+ if (soundFormat != FORMAT_MP3) {
if (index < buffer_length) {
sound->loop_count--;
sound->raw_position = 0;
@@ -902,7 +907,7 @@
mad_synth_frame (&sound->synth,
&sound->frame);
- outsize = sound->synth.pcm.length *
((sounddata->stereo == true) ? 4 : 2);
+ outsize = sound->synth.pcm.length *
((soundStereo() == true) ? 4 : 2);
tmp_raw_buffer = new Uint8[outsize];
int sample;
@@ -913,7 +918,7 @@
// scaling while we're at it.
for(int f = 0; f <
sound->synth.pcm.length; f++)
{
- for (int e = 0; e <
((sounddata->stereo == true) ? 2 : 1); e++){ // channels (stereo/mono)
+ for (int e = 0; e <
((soundStereo() == true) ? 2 : 1); e++){ // channels (stereo/mono)
mad_fixed_t mad_sample
= sound->synth.pcm.samples[e][f];
@@ -935,15 +940,15 @@
#endif
// If we need to convert samplerate
or/and from mono to stereo...
- if (outsize > 0 &&
(sounddata->sample_rate != handler->audioSpec.freq || !sounddata->stereo)) {
+ if (outsize > 0 &&
(static_cast<int>(soundSampleRate) != handler->audioSpec.freq || !soundStereo))
{
int16_t* adjusted_data = 0;
int adjusted_size = 0;
- int sample_count = outsize /
((sounddata->stereo == true) ? 4 : 2);
+ int sample_count = outsize /
((soundStereo == true) ? 4 : 2);
// Convert to needed samplerate
convert_raw_data(&adjusted_data, &adjusted_size, tmp_raw_buffer, sample_count,
0,
-
sounddata->sample_rate, sounddata->stereo,
+
soundSampleRate, soundStereo,
handler->audioSpec.freq, (handler->audioSpec.channels == 2 ? true : false));
// Hopefully this wont happen
@@ -1011,7 +1016,7 @@
}
// Sound is done, remove it from the active list (mp3)
- if (sound->position == sound->data_size &&
sound->loop_count == 0 && sounddata->format == 2) {
+ if (sound->position == sound->data_size &&
sound->loop_count == 0 && soundFormat == FORMAT_MP3) {
#ifdef USE_FFMPEG
avcodec_close(sound->cc);
av_parser_close(sound->parser);
@@ -1026,7 +1031,7 @@
// Sound is done, remove it from the active list
(adpcm/native16)
- } else if (sound->loop_count == 0 && sounddata->format
== 7 && sound->raw_position >= sound->raw_data_size && sound->raw_data_size !=
0) {
+ } else if (sound->loop_count == 0 && soundFormat ==
FORMAT_NATIVE16 && sound->raw_position >= sound->raw_data_size &&
sound->raw_data_size != 0) {
sounddata->m_active_sounds.erase(sounddata->m_active_sounds.begin() + j);
handler->soundsPlaying--;
} else if (sound->raw_position == 0 &&
sound->raw_data_size == 0) {
Index: backend/sound_handler_sdl.h
===================================================================
RCS file: /sources/gnash/gnash/backend/sound_handler_sdl.h,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -b -r1.31 -r1.32
--- backend/sound_handler_sdl.h 27 Jul 2007 15:09:41 -0000 1.31
+++ backend/sound_handler_sdl.h 10 Aug 2007 10:24:11 -0000 1.32
@@ -14,7 +14,7 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-// $Id: sound_handler_sdl.h,v 1.31 2007/07/27 15:09:41 tgc Exp $
+// $Id: sound_handler_sdl.h,v 1.32 2007/08/10 10:24:11 tgc Exp $
#ifndef SOUND_HANDLER_SDL_H
#define SOUND_HANDLER_SDL_H
@@ -123,20 +123,11 @@
/// TODO: use boost::scoped_array
uint8_t* data;
- /// Format of the sound (MP3, raw, etc).
- int format;
+ /// Object holding information about the sound
+ std::auto_ptr<SoundInfo> soundinfo;
/// The size of the undecoded data
- long data_size;
-
- /// Stereo or not
- bool stereo;
-
- /// Number of samples
- int sample_count;
-
- /// Sample rate
- int sample_rate;
+ unsigned int data_size;
/// Volume for AS-sounds, range: 0-100.
/// It's the SWF range that is represented here.
@@ -187,13 +178,11 @@
virtual ~SDL_sound_handler();
/// Called to create a sound.
- virtual int create_sound(void* data, int data_bytes,
- int sample_count, format_type format,
- int sample_rate, bool stereo);
+ virtual int create_sound(void* data, unsigned int data_bytes,
std::auto_ptr<SoundInfo> sinfo);
/// this gets called when a stream gets more data
- virtual long fill_stream_data(void* data, int data_bytes,
- int sample_count, int handle_id);
+ virtual long fill_stream_data(void* data, unsigned int data_bytes,
+ unsigned int sample_count, int
handle_id);
/// Play the index'd sample.
virtual void play_sound(int sound_handle, int loop_count, int offset,
@@ -215,7 +204,7 @@
virtual void set_volume(int sound_handle, int volume);
/// Gnash uses this to get info about a sound. Used when a stream needs
more data.
- virtual void get_info(int sound_handle, int* format, bool* stereo);
+ virtual SoundInfo* get_sound_info(int sound_handle);
/// Gnash calls this to mute audio.
virtual void mute();
Index: server/swf/tag_loaders.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/swf/tag_loaders.cpp,v
retrieving revision 1.127
retrieving revision 1.128
diff -u -b -r1.127 -r1.128
--- server/swf/tag_loaders.cpp 10 Aug 2007 03:54:16 -0000 1.127
+++ server/swf/tag_loaders.cpp 10 Aug 2007 10:24:11 -0000 1.128
@@ -17,7 +17,7 @@
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
//
-/* $Id: tag_loaders.cpp,v 1.127 2007/08/10 03:54:16 strk Exp $ */
+/* $Id: tag_loaders.cpp,v 1.128 2007/08/10 10:24:11 tgc Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -1339,7 +1339,8 @@
uint16_t character_id = in->read_u16();
- sound_handler::format_type format = (sound_handler::format_type)
in->read_uint(4);
+ sound_handler::format_type format =
static_cast<sound_handler::format_type>(in->read_uint(4));
+ sound_handler::format_type orgFormat = format;
int sample_rate = in->read_uint(2); // multiples of 5512.5
bool sample_16bit = in->read_uint(1) ? true : false;
bool stereo = in->read_uint(1) ? true : false;
@@ -1376,13 +1377,13 @@
// and modifies 3 parameters: format, data and data_bytes.
sound_expand(in, format, sample_16bit, stereo, sample_count, data,
data_bytes);
- int handler_id = handler->create_sound(
- data,
- data_bytes,
- sample_count,
- format,
- s_sample_rate_table[sample_rate],
- stereo);
+ // Store all the data in a SoundInfo object
+ std::auto_ptr<SoundInfo> sinfo;
+ sinfo.reset(new SoundInfo(format, orgFormat, stereo,
s_sample_rate_table[sample_rate], sample_count, sample_16bit));
+
+ // Stores the sounddata in the soundhandler, and the ID returned
+ // can be used to starting, stopping and deleting that sound
+ int handler_id = handler->create_sound(data, data_bytes, sinfo);
if (handler_id >= 0)
{
@@ -1436,14 +1437,6 @@
}
}
-// There is only one soundstream active per movie, so we cache the extra data
-// we need to be able to decode subsequent soundstreamblocks here.
-//
-static sound_handler::format_type stream_input_format;
-static bool stream_input_is16bit;
-static bool stream_input_stereo;
-static unsigned int stream_input_sample_count;
-
// Load a SoundStreamHead(2) tag.
void
sound_stream_head_loader(stream* in, tag_type tag, movie_definition* m)
@@ -1466,6 +1459,7 @@
int garbage = in->read_uint(8);
sound_handler::format_type format =
static_cast<sound_handler::format_type>(in->read_uint(4));
+ sound_handler::format_type orgFormat = format;
int sample_rate = in->read_uint(2); // multiples of 5512.5
bool sample_16bit = in->read_uint(1) ? true : false;
bool stereo = in->read_uint(1) ? true : false;
@@ -1500,13 +1494,6 @@
return;
}
- // Remember settings for decoding of subsequent blocks.
- // "stereo" is also in the sound object, 16bit no, format get stomped.
- stream_input_format = format;
- stream_input_is16bit = sample_16bit;
- stream_input_stereo = stereo;
- stream_input_sample_count = sample_count;
-
// Tell create_sound what format it will be receiving, in case it cares
// at this stage.
switch (format) {
@@ -1523,13 +1510,13 @@
break;
}
- int handler_id = handler->create_sound(
- NULL,
- data_bytes,
- sample_count,
- format,
- s_sample_rate_table[sample_rate],
- stereo);
+ // Store all the data in a SoundInfo object
+ std::auto_ptr<SoundInfo> sinfo;
+ sinfo.reset(new SoundInfo(format, orgFormat, stereo,
s_sample_rate_table[sample_rate], sample_count, sample_16bit));
+
+ // Stores the sounddata in the soundhandler, and the ID returned
+ // can be used to starting, stopping and deleting that sound
+ int handler_id = handler->create_sound(NULL, data_bytes, sinfo);
m->set_loading_sound_stream_id(handler_id);
}
@@ -1539,30 +1526,34 @@
void
sound_stream_block_loader(stream* in, tag_type tag, movie_definition* m)
{
- sound_handler* handler = get_sound_handler();
-
assert(tag == SWF::SOUNDSTREAMBLOCK); // 19
- // discard garbage data (MP3 only)
- // TODO: stop using statics (stream_input_format) for stream sounds..
- // tgc should be working on this
- if ( stream_input_format == sound_handler::FORMAT_MP3) in->skip_bytes(4);
+ sound_handler* handler = get_sound_handler();
// If we don't have a sound_handler registered stop here
if (!handler) return;
+ // Get the ID of the sound stream currently being loaded
int handle_id = m->get_loading_sound_stream_id();
- unsigned char *data; // Storage is allocated by sound_expand()
- unsigned data_bytes = in->get_tag_end_position() - in->get_position();
+ // Get the SoundInfo object that contains info about the sound stream.
+ // Ownership of the object is in the soundhandler
+ SoundInfo* sinfo = handler->get_sound_info(handle_id);
- // The format in the input file is in stream_input_*
- sound_handler::format_type format = stream_input_format;
+ // If there is no SoundInfo something is wrong...
+ if (!sinfo) return;
- unsigned int sample_count = stream_input_sample_count;
+ sound_handler::format_type format = sinfo->getOrgFormat();
+ unsigned int sample_count = sinfo->getSampleCount();
+
+ // discard garbage data if format is MP3
+ if (format == sound_handler::FORMAT_MP3) in->skip_bytes(4);
+
+ unsigned char *data; // Storage is allocated by sound_expand()
+ unsigned int data_bytes = in->get_tag_end_position() - in->get_position();
sound_expand(in, format,
- stream_input_is16bit, stream_input_stereo, sample_count,
+ sinfo->is16bit(), sinfo->isStereo(), sample_count,
data, data_bytes);
// "format" now reflects what we hand(ed) to the sound drivers.
// "data_bytes" now reflects the size of the uncompressed data.
@@ -1591,7 +1582,7 @@
static void
sound_expand(stream *in, sound_handler::format_type &format,
bool sample_16bit, bool stereo, unsigned int &sample_count,
- unsigned char* &data, unsigned &data_bytes)
+ unsigned char* &data, unsigned int &data_bytes)
{
// Make sure that an unassigned pointer cannot get through
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Gnash-commit] gnash ChangeLog backend/sound_handler.h backend...,
Tomas Groth <=