Commit b1f4e35f authored by Albert Astals Cid's avatar Albert Astals Cid

Make Stream incRef/decRef private

Object handles it for us

Also remove incRef/decRef from OutStream
parent d34e5304
......@@ -476,7 +476,7 @@ find_annot_movie_for_action (PopplerDocument *document,
if (annotObj.isDict ()) {
Object tmp;
annot = new AnnotMovie (document->doc, annotObj.getDict(), &tmp);
annot = new AnnotMovie (document->doc, &annotObj, &tmp);
if (!annot->isOk ()) {
delete annot;
annot = NULL;
......
......@@ -35,7 +35,7 @@
typedef struct _PopplerAttachmentPrivate PopplerAttachmentPrivate;
struct _PopplerAttachmentPrivate
{
Object *obj_stream;
Object obj_stream;
};
#define POPPLER_ATTACHMENT_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), POPPLER_TYPE_ATTACHMENT, PopplerAttachmentPrivate))
......@@ -64,12 +64,7 @@ poppler_attachment_dispose (GObject *obj)
PopplerAttachmentPrivate *priv;
priv = POPPLER_ATTACHMENT_GET_PRIVATE (obj);
if (priv->obj_stream)
{
delete priv->obj_stream;
priv->obj_stream = NULL;
}
priv->obj_stream = Object();
G_OBJECT_CLASS (poppler_attachment_parent_class)->dispose (obj);
}
......@@ -126,9 +121,7 @@ _poppler_attachment_new (FileSpec *emb_file)
if (embFile->checksum () && embFile->checksum ()->getLength () > 0)
attachment->checksum = g_string_new_len (embFile->checksum ()->getCString (),
embFile->checksum ()->getLength ());
priv->obj_stream = new Object(embFile->stream());
// Copy the stream
embFile->stream()->incRef();
priv->obj_stream = embFile->streamObject()->copy();
return attachment;
}
......@@ -241,7 +234,7 @@ poppler_attachment_save_to_callback (PopplerAttachment *attachment,
g_return_val_if_fail (POPPLER_IS_ATTACHMENT (attachment), FALSE);
stream = POPPLER_ATTACHMENT_GET_PRIVATE (attachment)->obj_stream->getStream();
stream = POPPLER_ATTACHMENT_GET_PRIVATE (attachment)->obj_stream.getStream();
stream->reset();
do
......
......@@ -40,7 +40,7 @@ struct _PopplerMedia
gchar *filename;
gchar *mime_type;
Stream *stream;
Object stream;
};
struct _PopplerMediaClass
......@@ -65,10 +65,7 @@ poppler_media_finalize (GObject *object)
media->mime_type = NULL;
}
if (media->stream) {
media->stream->decRef();
media->stream = NULL;
}
media->stream = Object();
G_OBJECT_CLASS (poppler_media_parent_class)->finalize (object);
}
......@@ -98,7 +95,7 @@ _poppler_media_new (MediaRendition *poppler_media)
if (poppler_media->getIsEmbedded()) {
GooString* mime_type;
media->stream = poppler_media->getEmbbededStream();
media->stream = poppler_media->getEmbbededStreamObject()->copy();
mime_type = poppler_media->getContentType();
if (mime_type)
media->mime_type = g_strdup (mime_type->getCString());
......@@ -124,7 +121,7 @@ const gchar *
poppler_media_get_filename (PopplerMedia *poppler_media)
{
g_return_val_if_fail (POPPLER_IS_MEDIA (poppler_media), NULL);
g_return_val_if_fail (poppler_media->stream == NULL, NULL);
g_return_val_if_fail (!poppler_media->stream.isStream(), NULL);
return poppler_media->filename;
}
......@@ -147,7 +144,7 @@ poppler_media_is_embedded (PopplerMedia *poppler_media)
{
g_return_val_if_fail (POPPLER_IS_MEDIA (poppler_media), FALSE);
return poppler_media->stream != NULL;
return poppler_media->stream.isStream();
}
/**
......@@ -215,7 +212,7 @@ poppler_media_save (PopplerMedia *poppler_media,
FILE *f;
g_return_val_if_fail (POPPLER_IS_MEDIA (poppler_media), FALSE);
g_return_val_if_fail (poppler_media->stream != NULL, FALSE);
g_return_val_if_fail (poppler_media->stream.isStream(), FALSE);
f = g_fopen (filename, "wb");
......@@ -281,9 +278,9 @@ poppler_media_save_to_callback (PopplerMedia *poppler_media,
gboolean eof_reached = FALSE;
g_return_val_if_fail (POPPLER_IS_MEDIA (poppler_media), FALSE);
g_return_val_if_fail (poppler_media->stream != NULL, FALSE);
g_return_val_if_fail (poppler_media->stream.isStream(), FALSE);
stream = poppler_media->stream;
stream = poppler_media->stream.getStream();
stream->reset();
do
......
......@@ -32,6 +32,7 @@ public:
GooString *createDate() { return m_createDate; }
GooString *checksum() { return m_checksum; }
GooString *mimeType() { return m_mimetype; }
Object *streamObject() { return &m_objStr; }
Stream *stream() { return isOk() ? m_objStr.getStream() : NULL; }
GBool isOk() { return m_objStr.isStream(); }
GBool save(const char *path);
......
......@@ -246,14 +246,8 @@ void MediaParameters::parseMediaScreenParameters(Object* obj) {
}
MediaRendition::~MediaRendition() {
if (fileName)
delete fileName;
if (contentType)
delete contentType;
if (embeddedStream && (!embeddedStream->decRef())) {
delete embeddedStream;
}
delete fileName;
delete contentType;
}
MediaRendition::MediaRendition(Object* obj) {
......@@ -263,7 +257,6 @@ MediaRendition::MediaRendition(Object* obj) {
fileName = NULL;
contentType = NULL;
isEmbedded = gFalse;
embeddedStream = NULL;
//
// Parse media clip data
......@@ -285,9 +278,7 @@ MediaRendition::MediaRendition(Object* obj) {
Object embedded = obj2.dictLookup("F");
if (embedded.isStream()) {
isEmbedded = gTrue;
embeddedStream = embedded.getStream();
// "copy" stream
embeddedStream->incRef();
embeddedStreamObject = embedded.copy();
}
}
......@@ -346,14 +337,32 @@ MediaRendition::MediaRendition(Object* obj) {
}
}
MediaRendition::MediaRendition(const MediaRendition &other) {
ok = other.ok;
MH = other.MH;
BE = other.BE;
isEmbedded = other.isEmbedded;
embeddedStreamObject = other.embeddedStreamObject.copy();
if (other.contentType)
contentType = other.contentType->copy();
else
contentType = nullptr;
if (other.fileName)
fileName = other.fileName->copy();
else
fileName = nullptr;
}
void MediaRendition::outputToFile(FILE* fp) {
if (!isEmbedded)
return;
embeddedStream->reset();
embeddedStreamObject.streamReset();
while (1) {
int c = embeddedStream->getChar();
int c = embeddedStreamObject.streamGetChar();
if (c == EOF)
break;
......@@ -362,19 +371,9 @@ void MediaRendition::outputToFile(FILE* fp) {
}
MediaRendition *MediaRendition::copy() {
// call default copy constructor
MediaRendition* new_media = new MediaRendition(*this);
if (contentType)
new_media->contentType = contentType->copy();
if (fileName)
new_media->fileName = fileName->copy();
if (new_media->embeddedStream)
new_media->embeddedStream->incRef();
return new_media;
MediaRendition* MediaRendition::copy()
{
return new MediaRendition(*this);
}
// TODO: SelectorRendition
......@@ -118,6 +118,7 @@ struct MediaParameters {
class MediaRendition {
public:
MediaRendition(Object *obj);
MediaRendition(const MediaRendition &other);
~MediaRendition();
GBool isOk () { return ok; }
......@@ -129,7 +130,8 @@ class MediaRendition {
GooString* getFileName() { return fileName; }
GBool getIsEmbedded() { return isEmbedded; }
Stream* getEmbbededStream() { return embeddedStream; }
Stream* getEmbbededStream() { return isEmbedded ? embeddedStreamObject.getStream() : nullptr; }
Object* getEmbbededStreamObject() { return isEmbedded ? &embeddedStreamObject : nullptr; }
// write embedded stream to file
void outputToFile(FILE*);
......@@ -148,7 +150,7 @@ class MediaRendition {
GooString* contentType;
// if it's embedded
Stream* embeddedStream;
Object embeddedStreamObject;
// if it's not embedded
GooString* fileName;
......
......@@ -343,7 +343,6 @@ Stream *Stream::makeFilter(char *name, Stream *str, Object *params, int recursio
//------------------------------------------------------------------------
OutStream::OutStream ()
{
ref = 1;
}
OutStream::~OutStream ()
......
......@@ -105,10 +105,6 @@ public:
// Destructor.
virtual ~Stream();
// Reference counting.
int incRef();
int decRef();
// Get kind of stream.
virtual StreamKind getKind() = 0;
......@@ -230,6 +226,12 @@ public:
Stream *addFilters(Dict *dict, int recursion = 0);
private:
friend class Object; // for incRef/decRef
// Reference counting.
int incRef();
int decRef();
virtual GBool hasGetChars() { return false; }
virtual int getChars(int nChars, Guchar *buffer);
......@@ -255,10 +257,6 @@ public:
// Desctructor.
virtual ~OutStream ();
// Reference counting.
int incRef() { return ++ref; }
int decRef() { return --ref; }
// Close the stream
virtual void close() = 0;
......@@ -269,10 +267,6 @@ public:
virtual void put (char c) = 0;
virtual void printf (const char *format, ...) GCC_PRINTF_FORMAT(2,3) = 0;
private:
int ref; // reference count
};
//------------------------------------------------------------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment