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.h backend...


From: Sandro Santilli
Subject: [Gnash-commit] gnash ChangeLog backend/sound_handler.h backend...
Date: Tue, 25 Sep 2007 20:24:08 +0000

CVSROOT:        /sources/gnash
Module name:    gnash
Changes by:     Sandro Santilli <strk>  07/09/25 20:24:08

Modified files:
        .              : ChangeLog 
        backend        : sound_handler.h sound_handler_gst.cpp 
                         sound_handler_gst.h 

Log message:
                * backend/sound_handler.h: document fill_stream_data return 
value.
                * backend/sound_handler_gst.{cpp,h}: Make buffer member of 
sound_data
                  private, provide an ::append() function with optimized 
reallocs.
                  Makes ninja parsing much faster. Same should be done for 
ffmpeg...
                  See http://wiki.gnashdev.org/wiki/index.php/NinjaProfile.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.4410&r2=1.4411
http://cvs.savannah.gnu.org/viewcvs/gnash/backend/sound_handler.h?cvsroot=gnash&r1=1.25&r2=1.26
http://cvs.savannah.gnu.org/viewcvs/gnash/backend/sound_handler_gst.cpp?cvsroot=gnash&r1=1.62&r2=1.63
http://cvs.savannah.gnu.org/viewcvs/gnash/backend/sound_handler_gst.h?cvsroot=gnash&r1=1.16&r2=1.17

Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.4410
retrieving revision 1.4411
diff -u -b -r1.4410 -r1.4411
--- ChangeLog   25 Sep 2007 18:58:42 -0000      1.4410
+++ ChangeLog   25 Sep 2007 20:24:07 -0000      1.4411
@@ -1,5 +1,13 @@
 2007-09-26 Sandro Santilli <address@hidden>
 
+       * backend/sound_handler.h: document fill_stream_data return value.
+       * backend/sound_handler_gst.{cpp,h}: Make buffer member of sound_data
+         private, provide an ::append() function with optimized reallocs.
+         Makes ninja parsing much faster. Same should be done for ffmpeg...
+         See http://wiki.gnashdev.org/wiki/index.php/NinjaProfile.
+
+2007-09-26 Sandro Santilli <address@hidden>
+
        * backend/: sound_handler.h, sound_handler_gst.{cpp,h},
          sound_handler_sdl.{cpp,h}: changed fill_stream_data
          interface to take ownership of the data array.

Index: backend/sound_handler.h
===================================================================
RCS file: /sources/gnash/gnash/backend/sound_handler.h,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -b -r1.25 -r1.26
--- backend/sound_handler.h     25 Sep 2007 18:58:43 -0000      1.25
+++ backend/sound_handler.h     25 Sep 2007 20:24:08 -0000      1.26
@@ -18,7 +18,7 @@
 // 
 //
 
-/* $Id: sound_handler.h,v 1.25 2007/09/25 18:58:43 strk Exp $ */
+/* $Id: sound_handler.h,v 1.26 2007/09/25 20:24:08 strk Exp $ */
 
 /// \page sound_handler_intro Sound handler introduction
 ///
@@ -124,6 +124,8 @@
        /// @param handle_id
        /// The soundhandlers id of the sound we want some info about.
        ///
+       /// @return size of the data buffer before the new data is appended
+       ///
        virtual long    fill_stream_data(unsigned char* data, unsigned int 
data_bytes, unsigned int sample_count, int handle_id) = 0;
 
        /// Returns a pointer to the SoundInfo object for the sound with the 
given id.

Index: backend/sound_handler_gst.cpp
===================================================================
RCS file: /sources/gnash/gnash/backend/sound_handler_gst.cpp,v
retrieving revision 1.62
retrieving revision 1.63
diff -u -b -r1.62 -r1.63
--- backend/sound_handler_gst.cpp       25 Sep 2007 18:58:43 -0000      1.62
+++ backend/sound_handler_gst.cpp       25 Sep 2007 20:24:08 -0000      1.63
@@ -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.62 2007/09/25 18:58:43 strk Exp $ */
+/* $Id: sound_handler_gst.cpp,v 1.63 2007/09/25 20:24:08 strk Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -51,6 +51,39 @@
 
 namespace gnash {
 
+void
+sound_data::append(unsigned char* newData, unsigned int size)
+{
+       if ( ! _capacity )
+       {
+               _data = newData;
+               _dataSize = size;
+               _capacity = _dataSize;
+               return;
+       }
+
+       if ( _capacity < _dataSize+size )
+       {
+               // TODO: find the smallest bigger power of 2 ?
+               unsigned long newCapacity = std::max(_capacity*2, 
_dataSize+size);
+
+               //log_debug("sound_data %p reallocating from %lu to %lu bytes", 
(void*)this, _capacity, newCapacity);
+
+               _capacity = newCapacity;
+
+               guint8* tmp = _data;
+               _data = new guint8[_capacity];
+               memcpy(_data, tmp, _dataSize);
+               delete [] tmp;
+       }
+
+       assert(_capacity >= _dataSize+size);
+       memcpy(_data+_dataSize, newData, size);
+       _dataSize += size;
+       delete [] newData;
+}
+
+
 GST_sound_handler::GST_sound_handler()
        : looping(false),
          muted(false)
@@ -70,7 +103,7 @@
 
 
 int    GST_sound_handler::create_sound(
-       void* data,
+       void* data_,
        unsigned int data_bytes,
        std::auto_ptr<SoundInfo> sinfo)
 // Called to create a sample.  We'll return a sample ID that
@@ -79,6 +112,8 @@
 
        try_mutex::scoped_lock lock(_mutex);
 
+       unsigned char* data = static_cast<unsigned char*>(data_);
+
        assert(sinfo.get());
        sound_data *sounddata = new sound_data;
        if (!sounddata) {
@@ -86,30 +121,18 @@
                return -1;
        }
 
-       sounddata->data_size = data_bytes;
        sounddata->volume = 100;
        sounddata->soundinfo = sinfo;
 
        switch (sounddata->soundinfo->getFormat())
        {
        case FORMAT_NATIVE16:
-               sounddata->data = new guint8[data_bytes];
-               if (!sounddata->data) { 
-                       log_error(_("Could not allocate space for data in sound 
handler"));
-                       return -1;
-               }
-               memcpy(sounddata->data, data, data_bytes);
+               sounddata->append(data, data_bytes);
                break;
 
        case FORMAT_MP3:
        //case FORMAT_VORBIS:
-               sounddata->data = new guint8[data_bytes];
-               if (!sounddata->data) { 
-                       log_error(_("Could not allocate space for data in sound 
handler"));
-                       return -1;
-               }
-               memcpy(sounddata->data, data, data_bytes);
-
+               sounddata->append(data, data_bytes);
                break;
 
        case FORMAT_RAW:
@@ -147,28 +170,24 @@
        {
                sound_data* sounddata = m_sound_data[handle_id];
 
-               // Reallocate the required memory.
-               guint8* tmp_data = new guint8[data_bytes + 
sounddata->data_size];
-               memcpy(tmp_data, sounddata->data, sounddata->data_size);
-               memcpy(tmp_data + sounddata->data_size, data, data_bytes);
-               if (sounddata->data_size > 0) delete [] sounddata->data;
-               sounddata->data = tmp_data;
+               long startSize = sounddata->dataSize();
 
-               sounddata->data_size += data_bytes;
+               sounddata->append(data, data_bytes);
 
                // If playback has already started, we also update the active 
sounds
                for (size_t i=0, e=sounddata->m_gst_elements.size(); i < e; 
++i) {
                        gst_elements* sound = sounddata->m_gst_elements[i];
-                       sound->data_size = sounddata->data_size;
-                       sound->set_data(tmp_data);
+                       sound->data_size = sounddata->dataSize();
+                       sound->set_data(sounddata->data());
                }
 
-               delete [] data;
-               return sounddata->data_size - data_bytes;
+               return startSize;
        }
-
+       else
+       {
        delete [] data;
        return 0;
+       }
 }
 
 // This stops sounds when they are done playing
@@ -222,7 +241,7 @@
                return;
        }
 
-       guint8* data_pos = gstelements->get_data_ptr(gstelements->position);
+       const guint8* data_pos = 
gstelements->get_data_ptr(gstelements->position);
 
        // Last callback - the last re-fill
        if (gstelements->position+BUFFER_SIZE > gstelements->data_size) {
@@ -278,7 +297,7 @@
                return;
        }
        // Make sure sound actually got some data
-       if (sounddata->data_size < 1) {
+       if (sounddata->dataSize() < 1) {
                IF_VERBOSE_MALFORMED_SWF(
                        log_swferror(_("Trying to play sound with size 0"));
                );
@@ -296,8 +315,8 @@
        gst_element->handler = this;
 
        // Copy data-info to the "gst_elements"
-       gst_element->data_size = sounddata->data_size;
-       gst_element->set_data(sounddata->data);
+       gst_element->data_size = sounddata->dataSize();
+       gst_element->set_data(sounddata->data());
        gst_element->position = start_position;
 
        // Set number of loop we should do. -1 is infinte loop, 0 plays it 
once, 1 twice etc.
@@ -684,12 +703,13 @@
 }
 
 // Pointer handling and checking functions
-uint8_t* gst_elements::get_data_ptr(unsigned long int pos) {
+const uint8_t* gst_elements::get_data_ptr(unsigned long int pos)
+{
        assert(data_size > pos);
        return data + pos;
 }
 
-void gst_elements::set_data(uint8_t* idata) {
+void gst_elements::set_data(const uint8_t* idata) {
        data = idata;
 }
 

Index: backend/sound_handler_gst.h
===================================================================
RCS file: /sources/gnash/gnash/backend/sound_handler_gst.h,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -b -r1.16 -r1.17
--- backend/sound_handler_gst.h 25 Sep 2007 18:58:43 -0000      1.16
+++ backend/sound_handler_gst.h 25 Sep 2007 20:24:08 -0000      1.17
@@ -70,14 +70,14 @@
 
        /// Returns the data pointer in the undecoded datastream
        /// for the given position. Boundaries are checked.
-       uint8_t* get_data_ptr(unsigned long int pos);
+       const uint8_t* get_data_ptr(unsigned long int pos);
 
        /// Set the undecoded data pointer
-       void set_data(uint8_t*);
+       void set_data(const uint8_t*);
 
 private:
        // The (un)compressed data
-       guint8* data;
+       const guint8* data;
 
 };
 
@@ -85,12 +85,39 @@
 // Used to hold the sounddata when doing on-demand-decoding
 class sound_data
 {
-public:
        // The (un)compressed data
-       guint8* data;
+       guint8* _data;
 
        // data size
-       long data_size;
+       unsigned long _dataSize;
+
+       /// Allocated memory for _data
+       unsigned long _capacity;
+
+public:
+
+       sound_data()
+               :
+               _data(0),
+               _dataSize(0),
+               _capacity(0)
+       {}
+
+       /// Append size bytes to this sound
+       //
+       /// @param data
+       ///     Data bytes, allocated with new[]. Ownership transferred.
+       ///
+       /// @param size
+       ///     Size of the 'data' buffer.
+       ///
+       void append(unsigned char* data, unsigned int size);
+
+       /// Return data size
+       unsigned long dataSize() const { return _dataSize; }
+
+       /// Return data buffer
+       const unsigned char* data() { return _data; }
 
        // Object holding information about the sound
        std::auto_ptr<SoundInfo> soundinfo;
@@ -104,8 +131,8 @@
 
        ~sound_data()
        {
-               // TODO: use boost::scoped_array
-               delete [] data;
+               // TODO: use boost::scoped_array ?
+               delete [] _data;
        }
 };
 




reply via email to

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