diff --git a/qt4/src/CMakeLists.txt b/qt4/src/CMakeLists.txt index ae17376..63e0269 100644 --- a/qt4/src/CMakeLists.txt +++ b/qt4/src/CMakeLists.txt @@ -25,7 +25,6 @@ set(poppler_qt4_SRCS poppler-sound.cc poppler-textbox.cc poppler-page-transition.cc - poppler-streamsequentialdevice.cc poppler-media.cc ${CMAKE_SOURCE_DIR}/poppler/ArthurOutputDev.cc ) diff --git a/qt4/src/poppler-media.cc b/qt4/src/poppler-media.cc index 422aaad..c318147 100644 --- a/qt4/src/poppler-media.cc +++ b/qt4/src/poppler-media.cc @@ -21,7 +21,10 @@ #include "Rendition.h" #include "poppler-private.h" -#include "poppler-streamsequentialdevice-private.h" + +#include + +#define BUFFER_MAX 4096 namespace Poppler { @@ -31,26 +34,20 @@ class MediaRenditionPrivate public: MediaRenditionPrivate(::MediaRendition *rendition) - : rendition(rendition), device(0) + : rendition(rendition) { } ::MediaRendition *rendition; - QIODevice *device; }; MediaRendition::MediaRendition(::MediaRendition *rendition) : d_ptr(new MediaRenditionPrivate(rendition)) { - Q_D( MediaRendition ); - - if (d->rendition) - d->device = new StreamSequentialDevice(d->rendition->getEmbbededStream()); } MediaRendition::~MediaRendition() { - delete d_ptr->device; delete d_ptr; } @@ -85,11 +82,27 @@ MediaRendition::isEmbedded() const return d->rendition->getIsEmbedded(); } -QIODevice * -MediaRendition::streamDevice() const +QByteArray +MediaRendition::data() const { + Q_ASSERT(isValid() && "Invalid media rendition."); Q_D( const MediaRendition ); - return d->device; + + Stream *s = d->rendition->getEmbbededStream(); + if (!s) + return QByteArray(); + + QBuffer buffer; + Guchar data[BUFFER_MAX]; + int bread; + + buffer.open(QIODevice::WriteOnly); + s->reset(); + while ((bread = s->doGetChars(BUFFER_MAX, data)) != 0) + buffer.write(reinterpret_cast(data), bread); + buffer.close(); + + return buffer.data(); } bool diff --git a/qt4/src/poppler-media.h b/qt4/src/poppler-media.h index 3b6f68d..69e74cb 100644 --- a/qt4/src/poppler-media.h +++ b/qt4/src/poppler-media.h @@ -60,9 +60,9 @@ namespace Poppler bool isEmbedded() const; /** - Returns data stream device. + Returns data buffer. */ - QIODevice *streamDevice() const; + QByteArray data() const; /** Convenience accessor for auto-play parameter. diff --git a/qt4/src/poppler-page.cc b/qt4/src/poppler-page.cc index 1369e44..44a117b 100644 --- a/qt4/src/poppler-page.cc +++ b/qt4/src/poppler-page.cc @@ -59,7 +59,6 @@ #include "poppler-annotation-private.h" #include "poppler-form.h" #include "poppler-media.h" -#include "poppler-streamsequentialdevice-private.h" namespace Poppler { diff --git a/qt4/src/poppler-streamsequentialdevice-private.h b/qt4/src/poppler-streamsequentialdevice-private.h deleted file mode 100644 index ec2dae2..0000000 --- a/qt4/src/poppler-streamsequentialdevice-private.h +++ /dev/null @@ -1,51 +0,0 @@ -/* poppler-streamdevice-private.h: Qt4 interface to poppler - * Copyright (C) 2012, Guillermo A. Amaral B. - * - * 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 2, 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 Street - Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#ifndef POPPLER_STREAMSEQUENTIALDEVICE_PRIVATE_H -#define POPPLER_STREAMSEQUENTIALDEVICE_PRIVATE_H - -#include - -class Stream; - -namespace Poppler { - -class StreamSequentialDevice : public QIODevice -{ - public: - StreamSequentialDevice(Stream *stream, QObject *parent = 0); - virtual ~StreamSequentialDevice(); - - virtual void close(); - - virtual bool isSequential() const - { return true; } - - protected: - virtual qint64 readData(char *data, qint64 maxSize); - inline virtual qint64 writeData(const char *, qint64) - { return 0; } - - private: - Q_DISABLE_COPY(StreamSequentialDevice); - Stream *m_stream; -}; - -} - -#endif diff --git a/qt4/src/poppler-streamsequentialdevice.cc b/qt4/src/poppler-streamsequentialdevice.cc deleted file mode 100644 index fa5a064..0000000 --- a/qt4/src/poppler-streamsequentialdevice.cc +++ /dev/null @@ -1,56 +0,0 @@ -/* poppler-streamdevice.cc: Qt4 interface to poppler - * Copyright (C) 2012, Guillermo A. Amaral B. - * - * 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 2, 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 Street - Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include "poppler-streamsequentialdevice-private.h" - -#include "Object.h" -#include "Stream.h" - -namespace Poppler { - -StreamSequentialDevice::StreamSequentialDevice(Stream *stream, QObject *parent) - : QIODevice(parent) - , m_stream(stream) -{ - Q_ASSERT(m_stream && "Invalid stream assigned."); - m_stream->incRef(); - m_stream->reset(); - open(QIODevice::ReadOnly); -} - -StreamSequentialDevice::~StreamSequentialDevice() -{ - m_stream->decRef(); - m_stream = 0; -} - -void -StreamSequentialDevice::close() -{ - m_stream->close(); - QIODevice::close(); -} - -qint64 -StreamSequentialDevice::readData(char *data, qint64 maxSize) -{ - return m_stream->doGetChars(maxSize, reinterpret_cast(data)); -} - -} -