[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: |
Sandro Santilli |
Subject: |
[Gnash-commit] gnash ChangeLog backend/sound_handler.h backend... |
Date: |
Wed, 26 Sep 2007 07:09:02 +0000 |
CVSROOT: /sources/gnash
Module name: gnash
Changes by: Sandro Santilli <strk> 07/09/26 07:09:02
Modified files:
. : ChangeLog
backend : sound_handler.h sound_handler_gst.cpp
sound_handler_gst.h
Log message:
* backend/sound_handler.h: define a Buffer class
to avoid duplicating code within the different
versions of sound_data and active_sound.
* backend/sound_handler_gst.{cpp,h}: Use a Buffer
member in the sound_data.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.4411&r2=1.4412
http://cvs.savannah.gnu.org/viewcvs/gnash/backend/sound_handler.h?cvsroot=gnash&r1=1.26&r2=1.27
http://cvs.savannah.gnu.org/viewcvs/gnash/backend/sound_handler_gst.cpp?cvsroot=gnash&r1=1.63&r2=1.64
http://cvs.savannah.gnu.org/viewcvs/gnash/backend/sound_handler_gst.h?cvsroot=gnash&r1=1.17&r2=1.18
Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.4411
retrieving revision 1.4412
diff -u -b -r1.4411 -r1.4412
--- ChangeLog 25 Sep 2007 20:24:07 -0000 1.4411
+++ ChangeLog 26 Sep 2007 07:09:01 -0000 1.4412
@@ -1,5 +1,13 @@
2007-09-26 Sandro Santilli <address@hidden>
+ * backend/sound_handler.h: define a Buffer class
+ to avoid duplicating code within the different
+ versions of sound_data and active_sound.
+ * backend/sound_handler_gst.{cpp,h}: Use a Buffer
+ member in the sound_data.
+
+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.
Index: backend/sound_handler.h
===================================================================
RCS file: /sources/gnash/gnash/backend/sound_handler.h,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -b -r1.26 -r1.27
--- backend/sound_handler.h 25 Sep 2007 20:24:08 -0000 1.26
+++ backend/sound_handler.h 26 Sep 2007 07:09:02 -0000 1.27
@@ -18,7 +18,7 @@
//
//
-/* $Id: sound_handler.h,v 1.26 2007/09/25 20:24:08 strk Exp $ */
+/* $Id: sound_handler.h,v 1.27 2007/09/26 07:09:02 strk Exp $ */
/// \page sound_handler_intro Sound handler introduction
///
@@ -37,6 +37,7 @@
#include <vector>
#include <memory>
+#include <cassert>
namespace gnash {
class stream;
@@ -45,6 +46,79 @@
namespace gnash {
+/// A buffer of bytes
+class Buffer {
+public:
+ Buffer()
+ :
+ _capacity(0),
+ _data(0),
+ _size(0)
+ {}
+
+ /// Append data to this buffer
+ //
+ /// @param newData data to append to this buffer.
+ ///
+ /// @param size number of elements
+ ///
+ void append(uint8_t* newData, size_t size)
+ {
+ if ( ! _capacity )
+ {
+ _data = newData;
+ _size = size;
+ _capacity = _size;
+ return;
+ }
+
+ if ( _capacity < _size+size )
+ {
+ // TODO: find the smallest bigger power of 2 ?
+ unsigned long newCapacity = std::max(_capacity*2,
_size+size);
+
+ //log_debug("Buffer %p reallocating from %lu to %lu
bytes", (void*)this, _capacity, newCapacity);
+
+ _capacity = newCapacity;
+
+ uint8_t* tmp = _data;
+ _data = new uint8_t[_capacity];
+ memcpy(_data, tmp, _size);
+ delete [] tmp;
+ }
+
+ assert(_capacity >= _size+size);
+ memcpy(_data+_size, newData, size);
+ _size += size;
+ delete [] newData;
+ }
+
+ const uint8_t* data() const
+ {
+ return _data;
+ }
+
+ size_t size() const
+ {
+ return _size;
+ }
+
+ ~Buffer()
+ {
+ delete [] _data;
+ }
+
+private:
+
+ size_t _capacity;
+
+ uint8_t* _data;
+
+ size_t _size;
+
+};
+
+
/// Sound handler.
//
/// Stores the audio found by the parser and plays on demand.
Index: backend/sound_handler_gst.cpp
===================================================================
RCS file: /sources/gnash/gnash/backend/sound_handler_gst.cpp,v
retrieving revision 1.63
retrieving revision 1.64
diff -u -b -r1.63 -r1.64
--- backend/sound_handler_gst.cpp 25 Sep 2007 20:24:08 -0000 1.63
+++ backend/sound_handler_gst.cpp 26 Sep 2007 07:09:02 -0000 1.64
@@ -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.63 2007/09/25 20:24:08 strk Exp $ */
+/* $Id: sound_handler_gst.cpp,v 1.64 2007/09/26 07:09:02 strk Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -51,39 +51,6 @@
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)
Index: backend/sound_handler_gst.h
===================================================================
RCS file: /sources/gnash/gnash/backend/sound_handler_gst.h,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -b -r1.17 -r1.18
--- backend/sound_handler_gst.h 25 Sep 2007 20:24:08 -0000 1.17
+++ backend/sound_handler_gst.h 26 Sep 2007 07:09:02 -0000 1.18
@@ -86,21 +86,11 @@
class sound_data
{
// The (un)compressed data
- guint8* _data;
-
- // data size
- unsigned long _dataSize;
-
- /// Allocated memory for _data
- unsigned long _capacity;
+ Buffer _data;
public:
sound_data()
- :
- _data(0),
- _dataSize(0),
- _capacity(0)
{}
/// Append size bytes to this sound
@@ -111,13 +101,16 @@
/// @param size
/// Size of the 'data' buffer.
///
- void append(unsigned char* data, unsigned int size);
+ void append(unsigned char* data, unsigned int size)
+ {
+ _data.append(data, size);
+ }
/// Return data size
- unsigned long dataSize() const { return _dataSize; }
+ size_t dataSize() const { return _data.size(); }
/// Return data buffer
- const unsigned char* data() { return _data; }
+ const uint8_t* data() { return _data.data(); }
// Object holding information about the sound
std::auto_ptr<SoundInfo> soundinfo;
@@ -129,11 +122,6 @@
// gstreamer objects
std::vector<gst_elements*> m_gst_elements;
- ~sound_data()
- {
- // TODO: use boost::scoped_array ?
- delete [] _data;
- }
};
// Use gstreamer to handle sounds.