[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] gnash ChangeLog libbase/Makefile.am libmedia/Au...
From: |
Tomas Groth |
Subject: |
[Gnash-commit] gnash ChangeLog libbase/Makefile.am libmedia/Au... |
Date: |
Wed, 03 Oct 2007 21:43:06 +0000 |
CVSROOT: /sources/gnash
Module name: gnash
Changes by: Tomas Groth <tgc> 07/10/03 21:43:05
Modified files:
. : ChangeLog
libbase : Makefile.am
libmedia : AudioDecoderSimple.cpp
libmedia/sdl : AudioDecoderFfmpeg.cpp sound_handler_sdl.cpp
sound_handler_sdl.h
server : Makefile.am
Added files:
libbase : BitsReader.cpp BitsReader.h
Removed files:
server : BitsReader.cpp BitsReader.h
Log message:
* libbase/Makefile.am: Added BitsReader.{h,cpp}
* server/Makefile.am: Removed BitsReader.{h,cpp}
* server/BitsReader.{h,cpp}: moved to libbase, and added
got_bits().
* libmedia/AudioDecoderSimple.cpp: Use BitsReader in libbase.
Fixed (at least some) adpcm decoding bugs (bug #21177).
* libmedia/sdl/AudioDecoderFfmpeg.cpp: fix cvs id tag.
* libmedia/sdl/sound_handler_sdl.cpp: Only stop playback of
sound if
completely done. If nothing has been decoded assume nothing
can be
decoded, fixes bug #21219.
* libmedia/sdl/sound_handler_sdl.h: Only delete decoder if it
exists.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.4516&r2=1.4517
http://cvs.savannah.gnu.org/viewcvs/gnash/libbase/Makefile.am?cvsroot=gnash&r1=1.88&r2=1.89
http://cvs.savannah.gnu.org/viewcvs/gnash/libbase/BitsReader.cpp?cvsroot=gnash&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/gnash/libbase/BitsReader.h?cvsroot=gnash&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/gnash/libmedia/AudioDecoderSimple.cpp?cvsroot=gnash&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/gnash/libmedia/sdl/AudioDecoderFfmpeg.cpp?cvsroot=gnash&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/gnash/libmedia/sdl/sound_handler_sdl.cpp?cvsroot=gnash&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/gnash/libmedia/sdl/sound_handler_sdl.h?cvsroot=gnash&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/gnash/server/Makefile.am?cvsroot=gnash&r1=1.127&r2=1.128
http://cvs.savannah.gnu.org/viewcvs/gnash/server/BitsReader.cpp?cvsroot=gnash&r1=1.1&r2=0
http://cvs.savannah.gnu.org/viewcvs/gnash/server/BitsReader.h?cvsroot=gnash&r1=1.1&r2=0
Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.4516
retrieving revision 1.4517
diff -u -b -r1.4516 -r1.4517
--- ChangeLog 3 Oct 2007 21:20:05 -0000 1.4516
+++ ChangeLog 3 Oct 2007 21:43:04 -0000 1.4517
@@ -1,3 +1,16 @@
+2007-10-03 Tomas Groth Christensen <address@hidden>
+
+ * libbase/Makefile.am: Added BitsReader.{h,cpp}
+ * server/Makefile.am: Removed BitsReader.{h,cpp}
+ * server/BitsReader.{h,cpp}: moved to libbase, and added got_bits().
+ * libmedia/AudioDecoderSimple.cpp: Use BitsReader in libbase.
+ Fixed (at least some) adpcm decoding bugs (bug #21177).
+ * libmedia/sdl/AudioDecoderFfmpeg.cpp: fix cvs id tag.
+ * libmedia/sdl/sound_handler_sdl.cpp: Only stop playback of sound if
+ completely done. If nothing has been decoded assume nothing can be
+ decoded, fixes bug #21219.
+ * libmedia/sdl/sound_handler_sdl.h: Only delete decoder if it exists.
+
2007-10-03 Sandro Santilli <address@hidden>
* server/as_value.{cpp,h}: use boost::variant instead of the union.
Index: libbase/Makefile.am
===================================================================
RCS file: /sources/gnash/gnash/libbase/Makefile.am,v
retrieving revision 1.88
retrieving revision 1.89
diff -u -b -r1.88 -r1.89
--- libbase/Makefile.am 1 Oct 2007 12:39:23 -0000 1.88
+++ libbase/Makefile.am 3 Oct 2007 21:43:04 -0000 1.89
@@ -107,6 +107,7 @@
LoadThread.cpp \
FLVParser.cpp \
GC.cpp \
+ BitsReader.cpp \
$(NULL)
noinst_HEADERS = \
@@ -153,6 +154,7 @@
LoadThread.h \
FLVParser.h \
GC.h \
+ BitsReader.h \
$(NULL)
libgnashbase_la_LDFLAGS = -release $(VERSION)
Index: libmedia/AudioDecoderSimple.cpp
===================================================================
RCS file: /sources/gnash/gnash/libmedia/AudioDecoderSimple.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- libmedia/AudioDecoderSimple.cpp 27 Sep 2007 23:59:53 -0000 1.1
+++ libmedia/AudioDecoderSimple.cpp 3 Oct 2007 21:43:05 -0000 1.2
@@ -21,132 +21,10 @@
#include "AudioDecoderSimple.h"
#include "utility.h"
+#include "BitsReader.h"
namespace gnash {
-class BitReader
-{
-public:
- typedef unsigned char byte;
-
- /// Ownership of buffer left to caller
- BitReader(byte* input, size_t len)
- :
- start(input),
- ptr(input),
- end(ptr+len),
- usedBits(0)
- {
- }
-
- ~BitReader() {}
-
- /// Set a new buffer to work with
- void setBuffer(byte* input, size_t len)
- {
- start = ptr = input;
- end = start+len;
- usedBits = 0;
- }
-
- bool read_bit()
- {
- bool ret = (*ptr&(128>>usedBits));
- if ( ++usedBits == 8 ) advanceToNextByte();
- return ret;
- }
-
- unsigned int read_uint(unsigned short bitcount)
- {
- assert(bitcount <= 32);
-
- uint32_t value = 0;
-
- unsigned short bits_needed = bitcount;
- do
- {
- int unusedMask = 0xFF >> usedBits;
- int unusedBits = 8-usedBits;
-
- if (bits_needed == unusedBits)
- {
- // Consume all the unused bits.
- value |= (*ptr&unusedMask);
- advanceToNextByte();
- break;
-
- }
- else if (bits_needed > unusedBits)
- {
- // Consume all the unused bits.
-
- bits_needed -= unusedBits; //
assert(bits_needed>0)
-
- value |= ((*ptr&unusedMask) << bits_needed);
- advanceToNextByte();
- }
- else
- {
- assert(bits_needed <= unusedBits);
-
- // Consume some of the unused bits.
-
- unusedBits -= bits_needed;
-
- value |= ((*ptr&unusedMask) >> unusedBits);
-
- usedBits += bits_needed;
- if ( usedBits >= 8 ) advanceToNextByte();
-
- // We're done.
- break;
- }
- }
- while (bits_needed > 0);
-
- return value;
-
- }
-
-
- int32_t read_sint(unsigned short bitcount)
- {
- int32_t value = int32_t(read_uint(bitcount));
-
- // Sign extend...
- if (value & (1 << (bitcount - 1)))
- value |= -1 << bitcount;
-
- return value;
- }
-
-
-private:
-
- void advanceToNextByte()
- {
- if ( ++ptr == end )
- {
- log_debug("Going round");
- ptr=start;
- }
- usedBits=0;
- }
-
- /// Pointer to first byte
- byte* start;
-
- /// Pointer to current byte
- byte* ptr;
-
- /// Pointer to one past last byte
- byte* end;
-
- /// Number of used bits in current byte
- unsigned usedBits;
-
-};
-
// ----------------------------------------------------------------------------
// ADPCMDecoder class
// ----------------------------------------------------------------------------
@@ -209,27 +87,27 @@
}
/* Uncompress 4096 mono samples of ADPCM. */
- static void doMonoBlock(int16_t** out_data, int n_bits, int
sample_count, BitReader* in, int sample, int stepsize_index)
+ static uint32_t doMonoBlock(int16_t** out_data, int n_bits, BitsReader*
in, int sample, int stepsize_index)
{
/* First sample doesn't need to be decompressed. */
- sample_count--;
+ uint32_t sample_count = 1;
*(*out_data)++ = (int16_t) sample;
- while (sample_count--)
+ while (sample_count++ <= 4096 && in->got_bits(n_bits))
{
int raw_code = in->read_uint(n_bits);
doSample(n_bits, sample, stepsize_index, raw_code);
/* sample & stepsize_index are in/out params */
*(*out_data)++ = (int16_t) sample;
}
+ return sample_count;
}
/* Uncompress 4096 stereo sample pairs of ADPCM. */
- static void doStereoBlock(
+ static int doStereoBlock(
int16_t** out_data, // in/out param
int n_bits,
- int sample_count,
- BitReader* in,
+ BitsReader* in,
int left_sample,
int left_stepsize_index,
int right_sample,
@@ -237,11 +115,11 @@
)
{
/* First samples don't need to be decompressed. */
- sample_count--;
+ uint32_t sample_count = 2;
*(*out_data)++ = (int16_t) left_sample;
*(*out_data)++ = (int16_t) right_sample;
- while (sample_count--)
+ while (in->got_bits(n_bits*2) && sample_count++ <= 4096)
{
int left_raw_code = in->read_uint(n_bits);
doSample(n_bits, left_sample, left_stepsize_index,
left_raw_code);
@@ -251,27 +129,30 @@
doSample(n_bits, right_sample, right_stepsize_index,
right_raw_code);
*(*out_data)++ = (int16_t) right_sample;
}
+ return sample_count;
}
public:
// Utility function: uncompress ADPCM data from in BitReader to
- // out_data[]. The output buffer must have (sample_count*2)
- // bytes for mono, or (sample_count*4) bytes for stereo.
- static void adpcm_expand(
+ // out_data[]. Returns the output samplecount.
+ static uint32_t adpcm_expand(
unsigned char* &data,
- BitReader* in,
- unsigned int sample_count, // in stereo, this is number of
*pairs* of samples
+ BitsReader* in,
+ unsigned int insize,
bool stereo)
{
- int16_t* out_data = new int16_t[stereo ? sample_count*2 :
sample_count];
+ // The compression ratio is 4:1, so this should be enough...
+ int16_t* out_data = new int16_t[insize * 5];
data = reinterpret_cast<unsigned char *>(out_data);
// Read header.
//in->ensureBytes(1); // nbits
unsigned int n_bits = in->read_uint(2) + 2; // 2 to 5 bits
(TODO: use unsigned...)
- while (sample_count)
+ uint32_t sample_count = 0;
+
+ while (/*sample_count && !in->overread()*/in->got_bits(22))
{
// Read initial sample & index values.
@@ -280,20 +161,19 @@
int stepsize_index = in->read_uint(6);
assert(STEPSIZE_CT >= (1 << 6)); // ensure we
don't need to clamp.
- int samples_this_block = imin(sample_count, 4096);
- sample_count -= samples_this_block;
-
if (stereo == false)
{
-#define DO_MONO(n) doMonoBlock(&out_data, n, samples_this_block, in, sample,
stepsize_index)
- switch (n_bits)
- {
- default: assert(0); break;
- case 2: DO_MONO(2); break;
- case 3: DO_MONO(3); break;
- case 4: DO_MONO(4); break;
- case 5: DO_MONO(5); break;
+ if (n_bits == 0) {
+ assert(0);
+ } else if (n_bits == 2) {
+ sample_count += doMonoBlock(&out_data,
2, in, sample, stepsize_index);
+ } else if (n_bits == 3) {
+ sample_count += doMonoBlock(&out_data,
3, in, sample, stepsize_index);
+ } else if (n_bits == 4) {
+ sample_count += doMonoBlock(&out_data,
4, in, sample, stepsize_index);
+ } else if (n_bits == 5) {
+ sample_count += doMonoBlock(&out_data,
5, in, sample, stepsize_index);
}
}
else
@@ -307,22 +187,21 @@
int right_stepsize_index = in->read_uint(6);
assert(STEPSIZE_CT >= (1 << 6)); //
ensure we don't need to clamp.
-#define DO_STEREO(n) \
- doStereoBlock( \
- &out_data, n, samples_this_block, \
- in, sample, stepsize_index, \
- right_sample, right_stepsize_index)
-
- switch (n_bits)
- {
- default: assert(0); break;
- case 2: DO_STEREO(2); break;
- case 3: DO_STEREO(3); break;
- case 4: DO_STEREO(4); break;
- case 5: DO_STEREO(5); break;
+ if (n_bits == 0) {
+ assert(0);
+ } else if (n_bits == 2) {
+ sample_count +=
doStereoBlock(&out_data, 2, in, sample, stepsize_index, right_sample,
right_stepsize_index);
+ } else if (n_bits == 3) {
+ sample_count +=
doStereoBlock(&out_data, 3, in, sample, stepsize_index, right_sample,
right_stepsize_index);
+ } else if (n_bits == 4) {
+ sample_count +=
doStereoBlock(&out_data, 4, in, sample, stepsize_index, right_sample,
right_stepsize_index);
+ } else if (n_bits == 5) {
+ sample_count +=
doStereoBlock(&out_data, 5, in, sample, stepsize_index, right_sample,
right_stepsize_index);
}
+
}
}
+ return sample_count;
}
@@ -399,6 +278,7 @@
bool AudioDecoderSimple::setup(SoundInfo* info)
{
+
if (info->getFormat() == AUDIO_CODEC_ADPCM || info->getFormat() ==
AUDIO_CODEC_RAW || info->getFormat() == AUDIO_CODEC_UNCOMPRESSED) {
_codec = info->getFormat();
_sampleRate = info->getSampleRate();
@@ -432,8 +312,8 @@
switch (_codec) {
case AUDIO_CODEC_ADPCM:
{
- uint32_t sample_count = inputSize * ( _stereo ? 1 : 2 );
//(_sampleCount == 0 ? inputSize / ( _stereo ? 4 : 2 ) : _sampleCount);
- ADPCMDecoder::adpcm_expand(decodedData, new
BitReader(input,inputSize), sample_count, _stereo);
+ //uint32_t sample_count = inputSize * ( _stereo ? 1 : 2 );
//(_sampleCount == 0 ? inputSize / ( _stereo ? 4 : 2 ) : _sampleCount);
+ uint32_t sample_count = ADPCMDecoder::adpcm_expand(decodedData,
new BitsReader(input,inputSize), inputSize, _stereo);
outsize = sample_count * (_stereo ? 4 : 2);
}
break;
@@ -534,6 +414,7 @@
}
outputSize = tmp_raw_buffer_size;
+
decodedBytes = inputSize;
return tmp_raw_buffer;
}
Index: libmedia/sdl/AudioDecoderFfmpeg.cpp
===================================================================
RCS file: /sources/gnash/gnash/libmedia/sdl/AudioDecoderFfmpeg.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- libmedia/sdl/AudioDecoderFfmpeg.cpp 28 Sep 2007 10:49:10 -0000 1.2
+++ libmedia/sdl/AudioDecoderFfmpeg.cpp 3 Oct 2007 21:43:05 -0000 1.3
@@ -17,7 +17,7 @@
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
//
-// Id:
+// $Id:
#include "AudioDecoderFfmpeg.h"
Index: libmedia/sdl/sound_handler_sdl.cpp
===================================================================
RCS file: /sources/gnash/gnash/libmedia/sdl/sound_handler_sdl.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- libmedia/sdl/sound_handler_sdl.cpp 28 Sep 2007 10:49:11 -0000 1.2
+++ libmedia/sdl/sound_handler_sdl.cpp 3 Oct 2007 21:43:05 -0000 1.3
@@ -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_sdl.cpp,v 1.2 2007/09/28 10:49:11 tgc Exp $
+// $Id: sound_handler_sdl.cpp,v 1.3 2007/10/03 21:43:05 tgc Exp $
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -86,9 +86,6 @@
sounddata->volume = 100;
sounddata->soundinfo = sinfo;
- int16_t* adjusted_data = 0;
- int adjusted_size = 0;
-
boost::mutex::scoped_lock lock(_mutex);
switch (sounddata->soundinfo->getFormat())
@@ -750,7 +747,7 @@
decoded_size += tmp_raw_buffer_size;
// no more to decode from this sound,
so we break the loop
- if (sound->dataSize() <=
sound->position && sound->loop_count == 0) {
+ if (sound->dataSize() <=
sound->position && sound->loop_count == 0 || tmp_raw_buffer_size == 0 &&
decodedBytes == 0) {
break;
}
@@ -788,9 +785,7 @@
}
// Sound is done, remove it from the active list
- if (sound->position == sound->dataSize() &&
sound->loop_count == 0) {
- /*delete sound->decoder;
- sound->deleteDecodedData();*/
+ if (sound->position == sound->dataSize() &&
sound->raw_position == sound->rawDataSize() && sound->loop_count == 0) {
sounddata->m_active_sounds.erase(sounddata->m_active_sounds.begin() + j);
handler->soundsPlaying--;
handler->_soundsStopped++;
Index: libmedia/sdl/sound_handler_sdl.h
===================================================================
RCS file: /sources/gnash/gnash/libmedia/sdl/sound_handler_sdl.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- libmedia/sdl/sound_handler_sdl.h 28 Sep 2007 10:49:11 -0000 1.2
+++ libmedia/sdl/sound_handler_sdl.h 3 Oct 2007 21:43:05 -0000 1.3
@@ -16,7 +16,7 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-// $Id: sound_handler_sdl.h,v 1.2 2007/09/28 10:49:11 tgc Exp $
+// $Id: sound_handler_sdl.h,v 1.3 2007/10/03 21:43:05 tgc Exp $
#ifndef SOUND_HANDLER_SDL_H
#define SOUND_HANDLER_SDL_H
@@ -151,7 +151,7 @@
~active_sound()
{
deleteDecodedData();
- delete decoder;
+ if (decoder) delete decoder;
}
/// The decoder object used to convert the data into the playable format
Index: server/Makefile.am
===================================================================
RCS file: /sources/gnash/gnash/server/Makefile.am,v
retrieving revision 1.127
retrieving revision 1.128
diff -u -b -r1.127 -r1.128
--- server/Makefile.am 29 Sep 2007 08:24:21 -0000 1.127
+++ server/Makefile.am 3 Oct 2007 21:43:05 -0000 1.128
@@ -18,7 +18,7 @@
#
#
-# $Id: Makefile.am,v 1.127 2007/09/29 08:24:21 cmusick Exp $
+# $Id: Makefile.am,v 1.128 2007/10/03 21:43:05 tgc Exp $
AUTOMAKE_OPTIONS =
@@ -57,7 +57,6 @@
libgnashserver_la_SOURCES = \
BitmapMovieInstance.cpp \
- BitsReader.cpp \
GetterSetter.cpp \
PropertyList.cpp \
URLAccessManager.cpp \
@@ -116,7 +115,6 @@
$(NULL)
noinst_HEADERS = \
- BitsReader.h \
GetterSetter.h \
Property.h \
PropertyList.h \
Index: libbase/BitsReader.cpp
===================================================================
RCS file: libbase/BitsReader.cpp
diff -N libbase/BitsReader.cpp
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ libbase/BitsReader.cpp 3 Oct 2007 21:43:04 -0000 1.1
@@ -0,0 +1,104 @@
+// BitsReader.cpp: bits reader, for Gnash.
+//
+// Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc.
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+//
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "BitsReader.h"
+
+#include "log.h"
+
+namespace gnash {
+
+bool BitsReader::read_bit()
+{
+ bool ret = (*ptr&(128>>usedBits));
+ if ( ++usedBits == 8 ) advanceToNextByte();
+ return ret;
+}
+
+unsigned BitsReader::read_uint(unsigned short bitcount)
+{
+ assert(bitcount <= 32);
+
+ uint32_t value = 0;
+
+ unsigned short bits_needed = bitcount;
+ do
+ {
+ int unusedMask = 0xFF >> usedBits;
+ int unusedBits = 8-usedBits;
+
+ if (bits_needed == unusedBits)
+ {
+ // Consume all the unused bits.
+ value |= (*ptr&unusedMask);
+ advanceToNextByte();
+ break;
+
+ }
+ else if (bits_needed > unusedBits)
+ {
+ // Consume all the unused bits.
+
+ bits_needed -= unusedBits; // assert(bits_needed>0)
+
+ value |= ((*ptr&unusedMask) << bits_needed);
+ advanceToNextByte();
+ }
+ else
+ {
+ assert(bits_needed <= unusedBits);
+
+ // Consume some of the unused bits.
+
+ unusedBits -= bits_needed;
+
+ value |= ((*ptr&unusedMask) >> unusedBits);
+
+ usedBits += bits_needed;
+ if ( usedBits >= 8 ) advanceToNextByte();
+
+ // We're done.
+ break;
+ }
+ }
+ while (bits_needed > 0);
+
+ //std::cerr << "Returning value: " << value << " unused bits: " <<
(int)m_unused_bits << std::endl;
+ return value;
+
+}
+
+
+int32_t BitsReader::read_sint(unsigned short bitcount)
+{
+ int32_t value = int32_t(read_uint(bitcount));
+
+ // Sign extend...
+ if (value & (1 << (bitcount - 1)))
+ value |= -1 << bitcount;
+
+ return value;
+}
+
+
+} // end namespace gnash
+
Index: libbase/BitsReader.h
===================================================================
RCS file: libbase/BitsReader.h
diff -N libbase/BitsReader.h
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ libbase/BitsReader.h 3 Oct 2007 21:43:04 -0000 1.1
@@ -0,0 +1,188 @@
+// BitsReader.h: bits reader, for Gnash.
+//
+// Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc.
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+//
+
+
+
+#ifndef BITSREADER_H
+#define BITSREADER_H
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "container.h"
+#include "swf.h"
+#include "tu_config.h"
+#include "GnashException.h"
+#include "log.h"
+
+#include <string>
+#include <sstream>
+
+namespace gnash {
+
+/// BitsReader is used to encapsulate bit-packed buffer reads.
+//
+/// TODO: implement boundary checking, maybe by throwing an exception
+/// when attempts are made to read past end of buffer
+///
+class DSOEXPORT BitsReader
+{
+public:
+ typedef unsigned char byte;
+
+ /// Ownership of buffer left to caller
+ BitsReader(byte* input, size_t len)
+ :
+ start(input),
+ ptr(input),
+ end(ptr+len),
+ usedBits(0)
+ {
+ }
+
+ ~BitsReader() {}
+
+ /// Set a new buffer to work with
+ void setBuffer(byte* input, size_t len)
+ {
+ start = ptr = input;
+ end = start+len;
+ usedBits = 0;
+ }
+
+ /// \brief
+ /// Reads a bit-packed unsigned integer from the stream
+ /// and returns it. The given bitcount determines the
+ /// number of bits to read.
+ unsigned read_uint(unsigned short bitcount);
+
+ /// \brief
+ /// Reads a single bit off the stream
+ /// and returns it.
+ bool read_bit();
+
+ /// \brief
+ /// Reads a bit-packed little-endian signed integer
+ /// from the stream. The given bitcount determines the
+ /// number of bits to read.
+ int32_t read_sint(unsigned short bitcount);
+
+ /// Read a byte as an unsigned int (aligned)
+ uint8_t read_u8()
+ {
+ align();
+ return *ptr++;
+ }
+
+ /// Read one bytes as a signed int (aligned)
+ int8_t read_s8()
+ {
+ return static_cast<int8_t>(read_u8());
+ }
+
+ /// Read two bytes as an unsigned int (aligned)
+ uint16_t read_u16()
+ {
+ align();
+ assert(ptr+2 < end);
+ uint16_t result = *ptr++;
+ result |= *ptr++ << 8;
+ return result ;
+ }
+
+ /// Read two bytes as a signed int (aligned)
+ int16_t read_s16()
+ {
+ return static_cast<int16_t>(read_u16());
+ }
+
+ /// Read four bytes as an unsigned int (aligned)
+ uint32_t read_u32()
+ {
+ align();
+ assert(ptr+4 < end);
+ uint32_t result = *ptr++;
+ result |= *ptr++ << 8;
+ result |= *ptr++ << 16;
+ result |= *ptr++ << 24;
+ return(result);
+ }
+
+ /// Read four bytes as an signed int (aligned)
+ int32_t read_s32()
+ {
+ return static_cast<int32_t>(read_u32());
+ }
+
+ /// \brief
+ /// Discard any unused bit in the current byte
+ /// and advance to next
+ void align()
+ {
+ if ( usedBits ) advanceToNextByte();
+ }
+
+ bool got_bits(uint32_t nbits)
+ {
+
+ uint32_t gotbits = 8-usedBits +8*(end-ptr-1);
+ if (gotbits > nbits) return true;
+ else return false;
+ }
+
+private:
+
+ void advanceToNextByte()
+ {
+ if ( ++ptr == end )
+ {
+ log_debug("Going round");
+ ptr=start;
+ }
+ usedBits=0;
+ }
+
+ /// Pointer to first byte
+ byte* start;
+
+ /// Pointer to current byte
+ byte* ptr;
+
+ /// Pointer to one past last byte
+ byte* end;
+
+ /// Number of used bits in current byte
+ unsigned usedBits;
+
+};
+
+
+} // end namespace gnash
+
+
+#endif // BITSREADER_H
+
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 8
+// tab-width: 8
+// indent-tabs-mode: t
+// End:
Index: server/BitsReader.cpp
===================================================================
RCS file: server/BitsReader.cpp
diff -N server/BitsReader.cpp
--- server/BitsReader.cpp 28 Aug 2007 08:45:10 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,104 +0,0 @@
-// BitsReader.cpp: bits reader, for Gnash.
-//
-// Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc.
-//
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation; either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-//
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include "BitsReader.h"
-
-#include "log.h"
-
-namespace gnash {
-
-bool BitsReader::read_bit()
-{
- bool ret = (*ptr&(128>>usedBits));
- if ( ++usedBits == 8 ) advanceToNextByte();
- return ret;
-}
-
-unsigned BitsReader::read_uint(unsigned short bitcount)
-{
- assert(bitcount <= 32);
-
- uint32_t value = 0;
-
- unsigned short bits_needed = bitcount;
- do
- {
- int unusedMask = 0xFF >> usedBits;
- int unusedBits = 8-usedBits;
-
- if (bits_needed == unusedBits)
- {
- // Consume all the unused bits.
- value |= (*ptr&unusedMask);
- advanceToNextByte();
- break;
-
- }
- else if (bits_needed > unusedBits)
- {
- // Consume all the unused bits.
-
- bits_needed -= unusedBits; // assert(bits_needed>0)
-
- value |= ((*ptr&unusedMask) << bits_needed);
- advanceToNextByte();
- }
- else
- {
- assert(bits_needed <= unusedBits);
-
- // Consume some of the unused bits.
-
- unusedBits -= bits_needed;
-
- value |= ((*ptr&unusedMask) >> unusedBits);
-
- usedBits += bits_needed;
- if ( usedBits >= 8 ) advanceToNextByte();
-
- // We're done.
- break;
- }
- }
- while (bits_needed > 0);
-
- //std::cerr << "Returning value: " << value << " unused bits: " <<
(int)m_unused_bits << std::endl;
- return value;
-
-}
-
-
-int32_t BitsReader::read_sint(unsigned short bitcount)
-{
- int32_t value = int32_t(read_uint(bitcount));
-
- // Sign extend...
- if (value & (1 << (bitcount - 1)))
- value |= -1 << bitcount;
-
- return value;
-}
-
-
-} // end namespace gnash
-
Index: server/BitsReader.h
===================================================================
RCS file: server/BitsReader.h
diff -N server/BitsReader.h
--- server/BitsReader.h 28 Aug 2007 08:45:11 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,180 +0,0 @@
-// BitsReader.h: bits reader, for Gnash.
-//
-// Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc.
-//
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation; either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-//
-
-
-
-#ifndef BITSREADER_H
-#define BITSREADER_H
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include "container.h"
-#include "swf.h"
-#include "tu_config.h"
-#include "GnashException.h"
-#include "log.h"
-
-#include <string>
-#include <sstream>
-
-namespace gnash {
-
-/// BitsReader is used to encapsulate bit-packed buffer reads.
-//
-/// TODO: implement boundary checking, maybe by throwing an exception
-/// when attempts are made to read past end of buffer
-///
-class DSOEXPORT BitsReader
-{
-public:
- typedef unsigned char byte;
-
- /// Ownership of buffer left to caller
- BitsReader(byte* input, size_t len)
- :
- start(input),
- ptr(input),
- end(ptr+len),
- usedBits(0)
- {
- }
-
- ~BitsReader() {}
-
- /// Set a new buffer to work with
- void setBuffer(byte* input, size_t len)
- {
- start = ptr = input;
- end = start+len;
- usedBits = 0;
- }
-
- /// \brief
- /// Reads a bit-packed unsigned integer from the stream
- /// and returns it. The given bitcount determines the
- /// number of bits to read.
- unsigned read_uint(unsigned short bitcount);
-
- /// \brief
- /// Reads a single bit off the stream
- /// and returns it.
- bool read_bit();
-
- /// \brief
- /// Reads a bit-packed little-endian signed integer
- /// from the stream. The given bitcount determines the
- /// number of bits to read.
- int32_t read_sint(unsigned short bitcount);
-
- /// Read a byte as an unsigned int (aligned)
- uint8_t read_u8()
- {
- align();
- return *ptr++;
- }
-
- /// Read one bytes as a signed int (aligned)
- int8_t read_s8()
- {
- return static_cast<int8_t>(read_u8());
- }
-
- /// Read two bytes as an unsigned int (aligned)
- uint16_t read_u16()
- {
- align();
- assert(ptr+2 < end);
- uint16_t result = *ptr++;
- result |= *ptr++ << 8;
- return result ;
- }
-
- /// Read two bytes as a signed int (aligned)
- int16_t read_s16()
- {
- return static_cast<int16_t>(read_u16());
- }
-
- /// Read four bytes as an unsigned int (aligned)
- uint32_t read_u32()
- {
- align();
- assert(ptr+4 < end);
- uint32_t result = *ptr++;
- result |= *ptr++ << 8;
- result |= *ptr++ << 16;
- result |= *ptr++ << 24;
- return(result);
- }
-
- /// Read four bytes as an signed int (aligned)
- int32_t read_s32()
- {
- return static_cast<int32_t>(read_u32());
- }
-
- /// \brief
- /// Discard any unused bit in the current byte
- /// and advance to next
- void align()
- {
- if ( usedBits ) advanceToNextByte();
- }
-
-private:
-
- void advanceToNextByte()
- {
- if ( ++ptr == end )
- {
- log_debug("Going round");
- ptr=start;
- }
- usedBits=0;
- }
-
- /// Pointer to first byte
- byte* start;
-
- /// Pointer to current byte
- byte* ptr;
-
- /// Pointer to one past last byte
- byte* end;
-
- /// Number of used bits in current byte
- unsigned usedBits;
-
-};
-
-
-} // end namespace gnash
-
-
-#endif // BITSREADER_H
-
-
-// Local Variables:
-// mode: C++
-// c-basic-offset: 8
-// tab-width: 8
-// indent-tabs-mode: t
-// End:
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Gnash-commit] gnash ChangeLog libbase/Makefile.am libmedia/Au...,
Tomas Groth <=