[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] gnash ChangeLog backend/sound_handler_sdl.cpp [release_0_
From: |
Tomas Groth |
Subject: |
[Gnash-commit] gnash ChangeLog backend/sound_handler_sdl.cpp [release_0_7_2] |
Date: |
Tue, 07 Nov 2006 11:43:01 +0000 |
CVSROOT: /sources/gnash
Module name: gnash
Branch: release_0_7_2
Changes by: Tomas Groth <tgc> 06/11/07 11:43:00
Modified files:
. : ChangeLog
backend : sound_handler_sdl.cpp
Log message:
Made stop_all_sounds() thread safe. Reverted some "0-index fixes".
Changed some asserts, and added some more.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&only_with_tag=release_0_7_2&r1=1.1412.2.104&r2=1.1412.2.105
http://cvs.savannah.gnu.org/viewcvs/gnash/backend/sound_handler_sdl.cpp?cvsroot=gnash&only_with_tag=release_0_7_2&r1=1.29.2.5&r2=1.29.2.6
Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.1412.2.104
retrieving revision 1.1412.2.105
diff -u -b -r1.1412.2.104 -r1.1412.2.105
--- ChangeLog 7 Nov 2006 10:11:46 -0000 1.1412.2.104
+++ ChangeLog 7 Nov 2006 11:43:00 -0000 1.1412.2.105
@@ -1,3 +1,9 @@
+2006-11-07 Tomas Groth Christensen <address@hidden>
+
+ * backend/sound_handler_sdl.cpp: Made stop_all_sounds()
+ thread safe. Reverted some "0-index fixes". Changed some
+ asserts, and added some more.
+
2006-11-07 Sandro Santilli <address@hidden>
* server/parser/movie_def_impl.cpp: fix support
Index: backend/sound_handler_sdl.cpp
===================================================================
RCS file: /sources/gnash/gnash/backend/sound_handler_sdl.cpp,v
retrieving revision 1.29.2.5
retrieving revision 1.29.2.6
diff -u -b -r1.29.2.5 -r1.29.2.6
--- backend/sound_handler_sdl.cpp 6 Nov 2006 23:47:55 -0000 1.29.2.5
+++ backend/sound_handler_sdl.cpp 7 Nov 2006 11:43:00 -0000 1.29.2.6
@@ -393,9 +393,35 @@
// for what sounds is associated with what SWF.
void SDL_sound_handler::stop_all_sounds()
{
+ pthread_mutex_lock(&mutex);
+
int32_t num_sounds = (int32_t) m_sound_data.size()-1;
- for (int32_t i = num_sounds; i > -1; i--) //Optimized
- stop_sound(i);
+ for (int32_t j = num_sounds; j > -1; j--) {//Optimized
+ int32_t num_active_sounds = (int32_t)
m_sound_data[j]->m_active_sounds.size()-1;
+ for (int32_t i = num_active_sounds; i > -1; i--) {
+
+ // Stop sound, remove it from the active list (mp3)
+ if (m_sound_data[j]->format == 2) {
+#ifdef USE_FFMPEG
+
avcodec_close(m_sound_data[j]->m_active_sounds[i]->cc);
+
av_parser_close(m_sound_data[j]->m_active_sounds[i]->parser);
+#elif defined(USE_MAD)
+
mad_synth_finish(&m_sound_data[j]->m_active_sounds[i]->synth);
+
mad_frame_finish(&m_sound_data[j]->m_active_sounds[i]->frame);
+
mad_stream_finish(&m_sound_data[j]->m_active_sounds[i]->stream);
+#endif
+ delete[]
m_sound_data[j]->m_active_sounds[i]->raw_data;
+
m_sound_data[j]->m_active_sounds.erase(m_sound_data[j]->m_active_sounds.begin()
+ i);
+ soundsPlaying--;
+
+ // Stop sound, remove it from the active list
(adpcm/native16)
+ } else {
+
m_sound_data[i]->m_active_sounds.erase(m_sound_data[j]->m_active_sounds.begin()
+ i);
+ soundsPlaying--;
+ }
+ }
+ }
+ pthread_mutex_unlock(&mutex);
}
@@ -598,13 +624,14 @@
next_env_pos =
(*sound->envelopes)[sound->current_env+1].m_mark44;
}
- int startpos = 0;
+ unsigned int startpos = 0;
// Make sure we start adjusting at the right sample
if (sound->current_env == 0 &&
(*sound->envelopes)[sound->current_env].m_mark44 > sound->samples_played) {
startpos = sound->raw_position +
((*sound->envelopes)[sound->current_env].m_mark44 - sound->samples_played)*2;
} else {
startpos = sound->raw_position;
}
+ assert(sound->raw_data_size > startpos);
int16_t* data = (int16_t*) (sound->raw_data + startpos);
for (unsigned int i=0; i < length/2; i+=2) {
@@ -628,7 +655,14 @@
}
-// The callback function which refills the buffer with data
+/// The callback function which refills the buffer with data
+/// We run through all of the sounds, and mix all of the active sounds
+/// into the stream given by the callback.
+/// If sound is compresssed (mp3) a mp3-frame is decoded into a buffer,
+/// and resampled if needed. When the buffer has been sampled, another
+/// frame is decoded until all frames has been decoded.
+/// If a sound is looping it will be decoded from the beginning again.
+
static void
sdl_audio_callback (void *udata, Uint8 *stream, int buffer_length_in)
{
@@ -641,11 +675,7 @@
unsigned int buffer_length = static_cast<unsigned
int>(buffer_length_in);
- // We run through all of the sounds, and mix all of the active sounds
- // into the stream given by the callback.
- // If a sound is looping it will be decoded from the beginning again.
- // When a sound is finished the empty space in the stream will be set
to 0.
-
+ // Get the soundhandler
SDL_sound_handler* handler = static_cast<SDL_sound_handler*>(udata);
// If nothing to play there is no reason to play
@@ -671,15 +701,15 @@
// mix some more until the buffer is full. If a sound
loops the magic
// happens here ;)
if (sound->raw_data_size - sound->raw_position <
buffer_length
- && (sound->position+1 < sound->data_size ||
sound->loop_count != 0)) {
+ && (sound->position < sound->data_size ||
sound->loop_count != 0)) {
// First we mix what is decoded
unsigned int index = 0;
- if (sound->raw_data_size - sound->raw_position
> 1) {
+ if (sound->raw_data_size - sound->raw_position
> 0) {
// If the volume needs adjustments we
call a function to do that
if (handler->m_sound_data[i]->volume !=
100) {
adjust_volume((int16_t*)(sound->raw_data + sound->raw_position),
- sound->raw_data_size-1
- sound->raw_position,
+ sound->raw_data_size -
sound->raw_position,
handler->m_sound_data[i]->volume);
} else if (sound->envelopes != NULL) {
assert(sound->raw_data_size >
sound->raw_position);
@@ -687,10 +717,10 @@
}
// Test if we will get problems...
Should not happen...
- assert(sound->raw_position +
sound->raw_data_size-1 - sound->raw_position < sound->raw_data_size);
+ assert(sound->raw_data_size >
sound->raw_position);
SDL_MixAudio(stream, (const
Uint8*)(sound->raw_data + sound->raw_position),
- sound->raw_data_size-1 -
sound->raw_position,
+ sound->raw_data_size -
sound->raw_position,
SDL_MIX_MAXVOLUME);
index = sound->raw_data_size -
sound->raw_position;
}
@@ -701,11 +731,14 @@
int outsize = 0;
// If we need to loop, we reset the data pointer
- if (sound->data_size == sound->position+1 &&
sound->loop_count != 0) {
+ if (sound->data_size == sound->position &&
sound->loop_count != 0) {
sound->loop_count--;
sound->position = 0;
}
+ // Test if we will get problems... Should not
happen...
+ assert(sound->data_size > sound->position);
+
#ifdef USE_FFMPEG
if (sound->raw_data_size > 0)
memset(sound->raw_data, 0, sound->raw_data_size);
@@ -836,7 +869,7 @@
// If the volume needs adjustments we call a
function to do that
if (handler->m_sound_data[i]->volume != 100) {
adjust_volume((int16_t*)(sound->raw_data + sound->raw_position),
- sound->raw_data_size-1 -
sound->raw_position,
+ sound->raw_data_size -
sound->raw_position,
handler->m_sound_data[i]->volume);
} else if (sound->envelopes != NULL) {
assert(buffer_length >= index);
@@ -861,15 +894,12 @@
// If the volume needs adjustments we call a
function to do that
if (handler->m_sound_data[i]->volume != 100) {
adjust_volume((int16_t*)(sound->raw_data + sound->raw_position),
- sound->raw_data_size-1 -
sound->raw_position,
+ sound->raw_data_size -
sound->raw_position,
handler->m_sound_data[i]->volume);
} else if (sound->envelopes != NULL) {
use_envelopes(sound, buffer_length);
}
- // Test if we will get problems... Should not
happen...
- assert(sound->raw_position + buffer_length <
sound->raw_data_size);
-
// Mix the raw data
SDL_MixAudio((Uint8*)(stream),(const Uint8*)
(sound->raw_data + sound->raw_position),
buffer_length,
@@ -892,14 +922,11 @@
use_envelopes(sound,
sound->raw_data_size - sound->raw_position);
}
- // Test if we will get problems... Should not
happen...
- assert(sound->raw_position +
sound->raw_data_size-1 - sound->raw_position < sound->raw_data_size);
-
// Mix the remaining data
SDL_MixAudio((Uint8*)(stream),(const Uint8*)
(sound->raw_data + sound->raw_position),
- sound->raw_data_size-1 -
sound->raw_position,
+ sound->raw_data_size -
sound->raw_position,
SDL_MIX_MAXVOLUME);
- sound->raw_position = sound->raw_data_size-1;
+ sound->raw_position = sound->raw_data_size;
}
// Sound is done, remove it from the active list (mp3)
- [Gnash-commit] gnash ChangeLog backend/sound_handler_sdl.cpp [release_0_7_2], Tomas Groth, 2006/11/03
- [Gnash-commit] gnash ChangeLog backend/sound_handler_sdl.cpp [release_0_7_2], Tomas Groth, 2006/11/06
- [Gnash-commit] gnash ChangeLog backend/sound_handler_sdl.cpp [release_0_7_2], Tomas Groth, 2006/11/06
- [Gnash-commit] gnash ChangeLog backend/sound_handler_sdl.cpp [release_0_7_2],
Tomas Groth <=
- [Gnash-commit] gnash ChangeLog backend/sound_handler_sdl.cpp [release_0_7_2], Tomas Groth, 2006/11/08
- [Gnash-commit] gnash ChangeLog backend/sound_handler_sdl.cpp [release_0_7_2], Tomas Groth, 2006/11/08
- [Gnash-commit] gnash ChangeLog backend/sound_handler_sdl.cpp [release_0_7_2], Tomas Groth, 2006/11/08
- [Gnash-commit] gnash ChangeLog backend/sound_handler_sdl.cpp [release_0_7_2], Tomas Groth, 2006/11/14