[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] gnash ChangeLog libbase/IOChannel.h libbase/zli...
From: |
Sandro Santilli |
Subject: |
[Gnash-commit] gnash ChangeLog libbase/IOChannel.h libbase/zli... |
Date: |
Tue, 10 Jun 2008 12:30:27 +0000 |
CVSROOT: /sources/gnash
Module name: gnash
Changes by: Sandro Santilli <strk> 08/06/10 12:30:26
Modified files:
. : ChangeLog
libbase : IOChannel.h zlib_adapter.cpp
Log message:
* libbase/IOChannel.h: give a default implementation for get_size()
and a meaning to -1 (unknown).
* libbase/zlib_adapter.cpp: implement zlib adapter as a proper
IOChannel subclass.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.6890&r2=1.6891
http://cvs.savannah.gnu.org/viewcvs/gnash/libbase/IOChannel.h?cvsroot=gnash&r1=1.6&r2=1.7
http://cvs.savannah.gnu.org/viewcvs/gnash/libbase/zlib_adapter.cpp?cvsroot=gnash&r1=1.27&r2=1.28
Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.6890
retrieving revision 1.6891
diff -u -b -r1.6890 -r1.6891
--- ChangeLog 10 Jun 2008 11:46:14 -0000 1.6890
+++ ChangeLog 10 Jun 2008 12:30:25 -0000 1.6891
@@ -1,3 +1,10 @@
+2008-06-10 Sandro Santilli <address@hidden>
+
+ * libbase/IOChannel.h: give a default implementation for get_size()
+ and a meaning to -1 (unknown).
+ * libbase/zlib_adapter.cpp: implement zlib adapter as a proper
+ IOChannel subclass.
+
2008-06-10 Benjamin Wolsey <address@hidden>
* server/FreetypeGlyphsProvider.h: boost/cstdint.h include.
Index: libbase/IOChannel.h
===================================================================
RCS file: /sources/gnash/gnash/libbase/IOChannel.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- libbase/IOChannel.h 9 Jun 2008 19:08:25 -0000 1.6
+++ libbase/IOChannel.h 10 Jun 2008 12:30:26 -0000 1.7
@@ -195,9 +195,9 @@
/// and some have one but isn't necessarely truthful
/// (a few HTTP severs are bogus in this reguard).
///
- /// @return unreliable input size.
+ /// @return unreliable input size, -1 if not known.
///
- virtual int size() const=0;
+ virtual int size() const { return -1; }
};
Index: libbase/zlib_adapter.cpp
===================================================================
RCS file: /sources/gnash/gnash/libbase/zlib_adapter.cpp,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -b -r1.27 -r1.28
--- libbase/zlib_adapter.cpp 9 Jun 2008 19:08:26 -0000 1.27
+++ libbase/zlib_adapter.cpp 10 Jun 2008 12:30:26 -0000 1.28
@@ -8,8 +8,7 @@
#include "zlib_adapter.h"
-#include "tu_file.h"
-#include "IOChannel.h"
+#include "IOChannel.h" // for inheritance
#include "log.h"
#include "GnashException.h"
#include <algorithm> // std::min
@@ -48,17 +47,57 @@
namespace zlib_adapter
{
- const int ZBUF_SIZE = 4096;
- class inflater_impl
+const int ZBUF_SIZE = 4096;
+
+class InflaterIOChannel : public IOChannel
+{
+public:
+
+ /// Constructor.
+ InflaterIOChannel(std::auto_ptr<IOChannel> in);
+
+ ~InflaterIOChannel() {
+ rewind_unused_bytes();
+ inflateEnd(&(m_zstream));
+ }
+
+ // See dox in IOChannel
+ virtual int seek(int pos);
+
+ // See dox in IOChannel
+ virtual int read(void* dst, int bytes)
+ {
+ if (m_error) return 0;
+ return inflate_from_stream(dst, bytes);
+ }
+
+ // See dox in IOChannel
+ virtual void go_to_end();
+
+ // See dox in IOChannel
+ virtual int tell() const
+ {
+ return m_logical_stream_pos;
+ }
+
+ // See dox in IOChannel
+ virtual bool eof() const
{
- private:
+ return m_at_eof;
+ }
+
+ // See dox in IOChannel
+ virtual int get_error() const
+ {
+ return m_error;
+ }
+
+private:
+
std::auto_ptr<IOChannel> m_in;
int m_initial_stream_pos; // position of the
input stream where we started inflating.
unsigned char m_rawdata[ZBUF_SIZE];
-
- public:
-
z_stream m_zstream;
// current stream position of uncompressed data.
@@ -67,46 +106,44 @@
bool m_at_eof;
int m_error;
- inflater_impl(std::auto_ptr<IOChannel> in)
- // Constructor.
- :
- m_in(in),
- m_initial_stream_pos(m_in->tell()),
- m_logical_stream_pos(m_initial_stream_pos),
- m_at_eof(false),
- m_error(0)
- {
- assert(m_in.get());
+ /// Discard current results and rewind to the beginning.
+ //
+ //
+ /// Necessary in order to seek backwards.
+ ///
+ /// might throw a ParserException if unable to reset the uderlying
+ /// stream to original position.
+ ///
+ void reset();
- m_zstream.zalloc = (alloc_func)0;
- m_zstream.zfree = (free_func)0;
- m_zstream.opaque = (voidpf)0;
+ int inflate_from_stream(void* dst, int bytes);
- m_zstream.next_in = 0;
- m_zstream.avail_in = 0;
+ // If we have unused bytes in our input buffer, rewind
+ // to before they started.
+ void rewind_unused_bytes();
- m_zstream.next_out = 0;
- m_zstream.avail_out = 0;
- int err = inflateInit(&m_zstream);
- if (err != Z_OK) {
- gnash::log_error("inflater_impl::ctor()
inflateInit() returned %d", err);
- m_error = 1;
- return;
- }
+};
- // Ready to go!
- }
+void
+InflaterIOChannel::rewind_unused_bytes()
+{
+ if (m_zstream.avail_in > 0)
+ {
+ int pos = m_in->tell();
+ int rewound_pos = pos - m_zstream.avail_in;
+ assert(pos >= 0);
+ assert(pos >= m_initial_stream_pos);
+ assert(rewound_pos >= 0);
+ assert(rewound_pos >= m_initial_stream_pos);
+ m_in->seek(rewound_pos);
+ }
+}
- // Discard current results and rewind to the beginning.
- // Necessary in order to seek backwards.
- //
- // might throw a ParserException if unable to reset the
uderlying
- // stream to original position.
- //
- void reset()
- {
+void
+InflaterIOChannel::reset()
+{
m_error = 0;
m_at_eof = 0;
int err = inflateReset(&m_zstream);
@@ -131,11 +168,11 @@
}
m_logical_stream_pos = m_initial_stream_pos;
- }
-
+}
- int inflate_from_stream(void* dst, int bytes)
- {
+int
+InflaterIOChannel::inflate_from_stream(void* dst, int bytes)
+{
using gnash::ParserException;
assert(bytes);
@@ -216,54 +253,36 @@
m_logical_stream_pos += bytes_read;
return bytes_read;
- }
+}
- void rewind_unused_bytes()
- // If we have unused bytes in our input buffer, rewind
- // to before they started.
- {
- if (m_zstream.avail_in > 0)
+void
+InflaterIOChannel::go_to_end()
+{
+ if (m_error)
{
- int pos = m_in->tell();
- int rewound_pos = pos - m_zstream.avail_in;
- assert(pos >= 0);
- assert(pos >= m_initial_stream_pos);
- assert(rewound_pos >= 0);
- assert(rewound_pos >= m_initial_stream_pos);
-
- m_in->seek(rewound_pos);
- }
+ throw IOException("InflaterIOChannel is in error condition,
can't seek to end");
}
- };
+ // Keep reading until we can't read any more.
+
+ unsigned char temp[ZBUF_SIZE];
- inline int inflate_read(void* dst, int bytes, void* appdata)
- // Return number of bytes actually read.
+ // Seek forwards.
+ for (;;)
{
- inflater_impl* inf = (inflater_impl*) appdata;
- if (inf->m_error)
+ int bytes_read = inflate_from_stream(temp, ZBUF_SIZE);
+ if (bytes_read == 0)
{
- return 0;
- }
-
- return inf->inflate_from_stream(dst, bytes);
+ // We've seeked as far as we can.
+ break;
}
-
-
- inline int inflate_write(const void* /* src */, int /* bytes */, void*
/* appdata */)
- // Return number of bytes actually written.
- {
- // *In*flaters can't write!!!
- abort();
- return 0;
}
+}
-
- int inflate_seek(int pos, void* appdata)
- // Try to go to pos. Return 0 on success or TU_FILE_SEEK_ERROR on
error.
- {
- inflater_impl* inf = (inflater_impl*) appdata;
- if (inf->m_error)
+int
+InflaterIOChannel::seek(int pos)
+{
+ if (m_error)
{
gnash::log_debug("Inflater is in error condition");
return TU_FILE_SEEK_ERROR;
@@ -271,23 +290,23 @@
}
// If we're seeking backwards, then restart from the beginning.
- if (pos < inf->m_logical_stream_pos)
+ if (pos < m_logical_stream_pos)
{
- log_debug("inflater reset due to seek back from %d to
%d", inf->m_logical_stream_pos, pos );
- inf->reset();
+ log_debug("inflater reset due to seek back from %d to %d",
m_logical_stream_pos, pos );
+ reset();
}
unsigned char temp[ZBUF_SIZE];
// Now seek forwards, by just reading data in blocks.
- while (inf->m_logical_stream_pos < pos)
+ while (m_logical_stream_pos < pos)
{
- int to_read = pos - inf->m_logical_stream_pos;
+ int to_read = pos - m_logical_stream_pos;
assert(to_read > 0);
int to_read_this_time = std::min<int>(to_read,
ZBUF_SIZE);
assert(to_read_this_time > 0);
- int bytes_read = inf->inflate_from_stream(temp,
to_read_this_time);
+ int bytes_read = inflate_from_stream(temp,
to_read_this_time);
assert(bytes_read <= to_read_this_time);
if (bytes_read == 0)
{
@@ -298,101 +317,53 @@
}
}
- //assert(inf->m_logical_stream_pos <= pos);
- assert(inf->m_logical_stream_pos == pos);
-
- return 0; // inf->m_logical_stream_pos;
- }
-
-
- int inflate_seek_to_end(void* appdata)
- {
- GNASH_REPORT_FUNCTION;
- inflater_impl* inf = (inflater_impl*) appdata;
- if (inf->m_error)
- {
- return inf->m_logical_stream_pos;
- }
-
- // Keep reading until we can't read any more.
-
- unsigned char temp[ZBUF_SIZE];
-
- // Seek forwards.
- for (;;)
- {
- int bytes_read = inf->inflate_from_stream(temp,
ZBUF_SIZE);
- if (bytes_read == 0)
- {
- // We've seeked as far as we can.
- break;
- }
- }
+ assert(m_logical_stream_pos == pos);
- return inf->m_logical_stream_pos;
- }
+ return 0; // m_logical_stream_pos;
+}
- inline int inflate_tell(void* appdata)
- {
- inflater_impl* inf = (inflater_impl*) appdata;
+InflaterIOChannel::InflaterIOChannel(std::auto_ptr<IOChannel> in)
+ :
+ m_in(in),
+ m_initial_stream_pos(m_in->tell()),
+ m_logical_stream_pos(m_initial_stream_pos),
+ m_at_eof(false),
+ m_error(0)
+{
+ assert(m_in.get());
- return inf->m_logical_stream_pos;
- }
+ m_zstream.zalloc = (alloc_func)0;
+ m_zstream.zfree = (free_func)0;
+ m_zstream.opaque = (voidpf)0;
- inline bool inflate_get_eof(void* appdata)
- {
- inflater_impl* inf = (inflater_impl*) appdata;
+ m_zstream.next_in = 0;
+ m_zstream.avail_in = 0;
- return inf->m_at_eof;
- }
+ m_zstream.next_out = 0;
+ m_zstream.avail_out = 0;
- inline int inflate_get_err(void* appdata)
- {
- inflater_impl* inf = (inflater_impl*) appdata;
- return inf->m_error;
+ int err = inflateInit(&m_zstream);
+ if (err != Z_OK) {
+ gnash::log_error("inflater_impl::ctor() inflateInit() returned
%d", err);
+ m_error = 1;
+ return;
}
- inline int inflate_close(void* appdata)
- {
- inflater_impl* inf = (inflater_impl*) appdata;
-
- inf->rewind_unused_bytes();
- int err = inflateEnd(&(inf->m_zstream));
-
- delete inf;
-
- if (err != Z_OK)
- {
- return TU_FILE_CLOSE_ERROR;
- }
+ // Ready to go!
+}
- return 0;
- }
- std::auto_ptr<IOChannel> make_inflater(std::auto_ptr<IOChannel> in)
- {
+std::auto_ptr<IOChannel> make_inflater(std::auto_ptr<IOChannel> in)
+{
assert(in.get());
+ return std::auto_ptr<IOChannel> (new InflaterIOChannel(in));
+}
- inflater_impl* inflater = new inflater_impl(in);
- return std::auto_ptr<IOChannel> (
- new tu_file(
- inflater,
- inflate_read,
- inflate_write,
- inflate_seek,
- inflate_seek_to_end,
- inflate_tell,
- inflate_get_eof,
- inflate_get_err,
- NULL, // get stream size
- inflate_close)
- );
- }
+// @@ TODO
+// IOChannel* make_deflater(IOChannel* out) { ... }
- // @@ TODO
- // IOChannel* make_deflater(IOChannel* out) { ... }
}
#endif // HAVE_ZLIB_H
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Gnash-commit] gnash ChangeLog libbase/IOChannel.h libbase/zli...,
Sandro Santilli <=