[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, 14 Nov 2006 20:05:15 +0000 |
CVSROOT: /sources/gnash
Module name: gnash
Branch: release_0_7_2
Changes by: Tomas Groth <tgc> 06/11/14 20:05:15
Modified files:
. : ChangeLog
backend : sound_handler_sdl.cpp
Log message:
Make sure the decode data is always able to fill the return buffer.
This fixes bug #18236.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&only_with_tag=release_0_7_2&r1=1.1412.2.171&r2=1.1412.2.172
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.9&r2=1.29.2.10
Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.1412.2.171
retrieving revision 1.1412.2.172
diff -u -b -r1.1412.2.171 -r1.1412.2.172
--- ChangeLog 14 Nov 2006 13:14:12 -0000 1.1412.2.171
+++ ChangeLog 14 Nov 2006 20:05:15 -0000 1.1412.2.172
@@ -1,3 +1,8 @@
+2006-11-14 Tomas Groth Christensen <address@hidden>
+
+ * backend/sound_handler_sdl.cpp: Make sure the decode data is
+ always able to fill the return buffer. This fixes bug #18236.
+
2006-11-14 Sandro Santilli <address@hidden>
* libbase/container.h: don't redefine _LIB_PTHREAD_TYPES_H.
Index: backend/sound_handler_sdl.cpp
===================================================================
RCS file: /sources/gnash/gnash/backend/sound_handler_sdl.cpp,v
retrieving revision 1.29.2.9
retrieving revision 1.29.2.10
diff -u -b -r1.29.2.9 -r1.29.2.10
--- backend/sound_handler_sdl.cpp 8 Nov 2006 15:12:06 -0000 1.29.2.9
+++ backend/sound_handler_sdl.cpp 14 Nov 2006 20:05:15 -0000
1.29.2.10
@@ -290,22 +290,20 @@
return;
}
- sound->raw_data = new uint8[AVCODEC_MAX_AUDIO_FRAME_SIZE];
- memset((void*)sound->raw_data, 0, AVCODEC_MAX_AUDIO_FRAME_SIZE);
- sound->raw_position = AVCODEC_MAX_AUDIO_FRAME_SIZE;
- sound->raw_data_size = AVCODEC_MAX_AUDIO_FRAME_SIZE;
sound->cc = avcodec_alloc_context();
avcodec_open(sound->cc, sound->codec);
+
#elif defined(USE_MAD)
// Init the mad decoder
mad_stream_init(&sound->stream);
mad_frame_init(&sound->frame);
mad_synth_init(&sound->synth);
+#endif
sound->raw_data = 0;
- sound->raw_data_size = 0;
sound->raw_position = 0;
-#endif
+ sound->raw_data_size = 0;
+
} else {
sound->raw_data_size = m_sound_data[sound_handle]->data_size;
sound->raw_data = m_sound_data[sound_handle]->data;
@@ -730,6 +728,12 @@
// Then we decode some data
int outsize = 0;
+ // We loop until the size of the decoded sound
is greater than the buffer size,
+ // or there is no more to decode.
+ unsigned int decoded_size = 0;
+ sound->raw_data_size = 0;
+ while(decoded_size < buffer_length) {
+
// If we need to loop, we reset the data pointer
if (sound->data_size == sound->position &&
sound->loop_count != 0) {
sound->loop_count--;
@@ -737,10 +741,15 @@
}
// Test if we will get problems... Should not
happen...
- assert(sound->data_size > sound->position);
+ assert(sound->data_size >=
sound->position);
+
+ // temp raw buffer
+ Uint8* tmp_raw_buffer;
+ unsigned int tmp_raw_buffer_size;
#ifdef USE_FFMPEG
- if (sound->raw_data_size > 0)
memset(sound->raw_data, 0, sound->raw_data_size);
+ tmp_raw_buffer = new
Uint8[AVCODEC_MAX_AUDIO_FRAME_SIZE];
+ tmp_raw_buffer_size =
AVCODEC_MAX_AUDIO_FRAME_SIZE;
long bytes_decoded = 0;
@@ -753,7 +762,7 @@
0 ,0); //pts,
dts
int tmp = 0;
- tmp = avcodec_decode_audio(sound->cc,
(int16_t *)sound->raw_data, &outsize, frame, framesize);
+ tmp =
avcodec_decode_audio(sound->cc, (int16_t *)tmp_raw_buffer, &outsize, frame,
framesize);
if (bytes_decoded < 0 || tmp < 0 ||
outsize < 0) {
gnash::log_error("Error while
decoding MP3-stream. Upgrading ffmpeg/libavcodec might fix this issue.\n");
@@ -808,11 +817,10 @@
outsize = sound->synth.pcm.length *
((handler->m_sound_data[i]->stereo == true) ? 4 : 2);
- if (sound->raw_data) delete[] sound->raw_data;
- sound->raw_data = new Uint8[outsize];
+ tmp_raw_buffer = new Uint8[outsize];
int sample;
- int16_t* dst = (int16_t*) sound->raw_data;
+ int16_t* dst = (int16_t*)
tmp_raw_buffer;
// transfer the decoded samples into the
sound-struct, and do some
// scaling while we're at it.
@@ -837,8 +845,9 @@
*dst++ = sample;
}
}
-
#endif
+
+
// If we need to convert samplerate...
if (outsize > 0 &&
handler->m_sound_data[i]->sample_rate != handler->audioSpec.freq) {
int16_t* adjusted_data = 0;
@@ -846,7 +855,7 @@
int sample_count = outsize /
((handler->m_sound_data[i]->stereo == true) ? 4 : 2);
// Convert to needed samplerate
-
handler->convert_raw_data(&adjusted_data, &adjusted_size, sound->raw_data,
sample_count, 0,
+
handler->convert_raw_data(&adjusted_data, &adjusted_size, tmp_raw_buffer,
sample_count, 0,
handler->m_sound_data[i]->sample_rate, handler->m_sound_data[i]->stereo);
// Hopefully this wont happen
@@ -855,18 +864,31 @@
}
// Move the new data to the sound-struct
- if (sound->raw_data) delete[]
sound->raw_data;
- sound->raw_data = new
Uint8[adjusted_size];
- memcpy(sound->raw_data, adjusted_data,
adjusted_size);
- sound->raw_data_size = adjusted_size;
- delete[] adjusted_data;
+ delete[] tmp_raw_buffer;
+ tmp_raw_buffer = (Uint8*)
adjusted_data;
+ tmp_raw_buffer_size =
adjusted_size;
} else {
- sound->raw_data_size = outsize;
+ tmp_raw_buffer_size = outsize;
}
+ Uint8* tmp_buf = new Uint8[decoded_size
+ tmp_raw_buffer_size];
+ memcpy(tmp_buf, sound->raw_data,
decoded_size);
+ memcpy(tmp_buf, tmp_raw_buffer,
tmp_raw_buffer_size);
+ decoded_size += tmp_raw_buffer_size;
+ delete[] sound->raw_data;
+ sound->raw_data = tmp_buf;
+ delete[] tmp_raw_buffer;
+
+ } // end of "decode min. bufferlength data"
while loop
+
+ sound->raw_data_size = decoded_size;
+
sound->raw_position = 0;
+ // Test if we will get problems... Should not
happen...
+ assert(buffer_length - index <
sound->raw_data_size);
+
// 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),
@@ -877,9 +899,6 @@
use_envelopes(sound, buffer_length -
index);
}
- // Test if we will get problems... Should not
happen...
- assert(sound->raw_position + buffer_length -
index < sound->raw_data_size);
-
// Then we mix the newly decoded data
SDL_MixAudio((Uint8*)(stream+index),(const
Uint8*) sound->raw_data,
buffer_length - index,
- [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, 2006/11/07
- [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 <=