gnash-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gnash-commit] gnash ChangeLog backend/sound_handler_sdl.cpp


From: Tomas Groth
Subject: [Gnash-commit] gnash ChangeLog backend/sound_handler_sdl.cpp
Date: Tue, 14 Nov 2006 21:11:45 +0000

CVSROOT:        /sources/gnash
Module name:    gnash
Changes by:     Tomas Groth <tgc>       06/11/14 21:11:45

Modified files:
        .              : ChangeLog 
        backend        : sound_handler_sdl.cpp 

Log message:
        Make sure the decoded data is always able to fill the return buffer.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.1617&r2=1.1618
http://cvs.savannah.gnu.org/viewcvs/gnash/backend/sound_handler_sdl.cpp?cvsroot=gnash&r1=1.35&r2=1.36

Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.1617
retrieving revision 1.1618
diff -u -b -r1.1617 -r1.1618
--- ChangeLog   14 Nov 2006 13:15:10 -0000      1.1617
+++ ChangeLog   14 Nov 2006 21:11:45 -0000      1.1618
@@ -1,3 +1,8 @@
+2006-11-14 Tomas Groth Christensen <address@hidden>
+
+       * backend/sound_handler_sdl.cpp: Make sure the decoded data is
+         always able to fill the return buffer.
+
 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.35
retrieving revision 1.36
diff -u -b -r1.35 -r1.36
--- backend/sound_handler_sdl.cpp       8 Nov 2006 15:40:30 -0000       1.35
+++ backend/sound_handler_sdl.cpp       14 Nov 2006 21:11:45 -0000      1.36
@@ -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;
@@ -780,6 +778,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--;
@@ -787,10 +791,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;
 
@@ -803,7 +812,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");
@@ -858,11 +867,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.
@@ -887,8 +895,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;
@@ -896,7 +905,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
@@ -905,18 +914,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), 
@@ -927,9 +949,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,




reply via email to

[Prev in Thread] Current Thread [Next in Thread]