From: David Flynn <[email protected]>

SchroDecoderTag inherits from SchroTag, which provides a free function.

Signed-off-by: David Flynn <[email protected]>
---
 schroedinger/schrobuffer.c     |    4 ++--
 schroedinger/schrobuffer.h     |    4 ++--
 schroedinger/schrobufferlist.c |   11 +++--------
 schroedinger/schrodecoder.c    |   35 ++++++++++++++++++++++-------------
 schroedinger/schrodecoder.h    |   14 ++++++++++----
 schroedinger/schroutils.h      |    7 +++++++
 6 files changed, 46 insertions(+), 29 deletions(-)

diff --git a/schroedinger/schrobuffer.c b/schroedinger/schrobuffer.c
index a38916d..a3f19fb 100644
--- a/schroedinger/schrobuffer.c
+++ b/schroedinger/schrobuffer.c
@@ -82,8 +82,8 @@ schro_buffer_unref (SchroBuffer * buffer)
     SCHRO_DEBUG("free %p", buffer);
     if (buffer->free)
       buffer->free (buffer, buffer->priv);
-    if (buffer->tag_free)
-      buffer->tag_free (buffer->tag);
+    if (buffer->tag)
+      buffer->tag->free (buffer->tag);
     schro_free (buffer);
   }
 }
diff --git a/schroedinger/schrobuffer.h b/schroedinger/schrobuffer.h
index c822049..3a3879d 100644
--- a/schroedinger/schrobuffer.h
+++ b/schroedinger/schrobuffer.h
@@ -20,8 +20,8 @@ struct _SchroBuffer
 
   void (*free) (SchroBuffer *, void *);
   void *priv;
-  void (*tag_free) (void *); /* NB, must be able to handle tag_free(NULL) */
-  void *tag;
+
+  SchroTag* tag;
 };
 
 SchroBuffer *schro_buffer_new (void);
diff --git a/schroedinger/schrobufferlist.c b/schroedinger/schrobufferlist.c
index 05a588b..fd79cbd 100644
--- a/schroedinger/schrobufferlist.c
+++ b/schroedinger/schrobufferlist.c
@@ -233,8 +233,7 @@ SchroBuffer *
 schro_buflist_extract (SchroBufferList *buflist, unsigned start, unsigned len)
 {
   SchroBuffer *buf, *dst;
-  void *tag = NULL;
-  void (*tag_free) (void *) = NULL;
+  SchroTag *tag = NULL;
   unsigned pos = start;
   int bufidx;
   uint8_t tmp;
@@ -265,7 +264,6 @@ schro_buflist_extract (SchroBufferList *buflist, unsigned 
start, unsigned len)
    *  - Ownership of the tag is transfered to the output buffer
    */
   tag = buf->tag;
-  tag_free = buf->tag_free;
   buf->tag = NULL;
 
   if (pos + len <= buf->length) {
@@ -273,14 +271,12 @@ schro_buflist_extract (SchroBufferList *buflist, unsigned 
start, unsigned len)
      * buffer, then use a subbuffer */
     dst = schro_buffer_new_subbuffer (buf, pos, len);
     dst->tag = tag;
-    dst->tag_free = tag_free;
     return dst;
   }
 
   /* dataunit spans multiple buffers */
   dst = schro_buffer_new_and_alloc (len);
   dst->tag = tag;
-  dst->tag_free = tag_free;
   tag = NULL;
   schro_buflist_peekbytes (dst->data, len, buflist, start);
 
@@ -297,8 +293,8 @@ schro_buflist_extract (SchroBufferList *buflist, unsigned 
start, unsigned len)
       buf->tag = NULL;
     }
     /* any intermediate tags are discarded */
-    if (buf->tag_free) {
-      buf->tag_free(buf->tag);
+    if (buf->tag) {
+      buf->tag->free (buf->tag);
       buf->tag = NULL;
     }
     pos += buf->length;
@@ -308,7 +304,6 @@ schro_buflist_extract (SchroBufferList *buflist, unsigned 
start, unsigned len)
   /* xxx, this may need to be moved to the next buffer if
    * exact consumption of buf occurs */
   buf->tag = tag;
-  buf->tag_free = tag_free;
 
   return dst;
 }
diff --git a/schroedinger/schrodecoder.c b/schroedinger/schrodecoder.c
index 439f8aa..cb7daea 100644
--- a/schroedinger/schrodecoder.c
+++ b/schroedinger/schrodecoder.c
@@ -419,13 +419,26 @@ schro_picture_unref (SchroPicture *picture)
     if (picture->ref0) schro_picture_unref (picture->ref0);
     if (picture->ref1) schro_picture_unref (picture->ref1);
 
-    if (picture->tag_free) picture->tag_free (picture->tag);
+    if (picture->tag) picture->tag->base.free (picture->tag);
 
     schro_free (picture);
   }
 }
 
 /**
+ * schro_decoder_tag_new:
+ *
+ * Returns: An empty decoder tag structure
+ */
+SchroDecoderTag *
+schro_decoder_tag_new ()
+{
+    SchroDecoderTag *tag = schro_malloc0 (sizeof(*tag));
+    tag->base.free = schro_free;
+    return tag;
+}
+
+/**
  * schro_decoder_reset:
  * @decoder: a decoder object
  *
@@ -510,7 +523,7 @@ schro_decoder_get_picture_number (SchroDecoder *decoder)
  *
  * Returns: a tag represented by void* or NULL
  */
-void *
+SchroDecoderTag *
 schro_decoder_get_picture_tag (SchroDecoder *decoder)
 {
   SchroDecoderInstance *instance = decoder->instance;
@@ -521,9 +534,8 @@ schro_decoder_get_picture_tag (SchroDecoder *decoder)
     picture = schro_queue_peek (instance->reorder_queue);
   }
   if (picture) {
-    void *tag = picture->tag;
+    SchroDecoderTag *tag = picture->tag;
     picture->tag = NULL;
-    picture->tag_free = NULL;
     return tag;
   }
   return NULL;
@@ -1056,8 +1068,8 @@ schro_decoder_push (SchroDecoder *decoder, SchroBuffer 
*buffer)
 
     if (!instance->have_sequence_header) {
       SCHRO_INFO ("no sequence header -- dropping picture");
-      if (decoder->free_picture_tag)
-        decoder->free_picture_tag(decoder->next_picture_tag);
+      if (decoder->next_picture_tag)
+        decoder->next_picture_tag->base.free (decoder->next_picture_tag);
       decoder->next_picture_tag = NULL;
       schro_buffer_unref (buffer);
       return SCHRO_DECODER_OK;
@@ -1098,13 +1110,12 @@ schro_decoder_autoparse_push (SchroDecoder *decoder, 
SchroBuffer *buffer)
     /* Buffers may have associated (tagged) private data.
      * This data is to be associated with the next(/this) picture data unit */
     if (buffer->tag) {
-      if (decoder->free_picture_tag) {
-        decoder->free_picture_tag (decoder->next_picture_tag);
+      if (decoder->next_picture_tag) {
+        decoder->next_picture_tag->base.free (decoder->next_picture_tag);
       }
-      decoder->next_picture_tag = buffer->tag;
-      decoder->free_picture_tag = buffer->tag_free;
+      decoder->next_picture_tag = (SchroDecoderTag*) buffer->tag;
     }
-    buffer->tag_free = buffer->tag = NULL;
+    buffer->tag = NULL;
 
     switch (schro_decoder_push (decoder, buffer)) {
     default:
@@ -1132,8 +1143,6 @@ schro_decoder_iterate_picture (SchroDecoderInstance 
*instance, SchroBuffer *buff
   picture->input_buffer = buffer;
 
   picture->tag = decoder->next_picture_tag;
-  picture->tag_free = decoder->free_picture_tag;
-  decoder->free_picture_tag =
   decoder->next_picture_tag = NULL;
 
   params->num_refs = SCHRO_PARSE_CODE_NUM_REFS(parse_code);
diff --git a/schroedinger/schrodecoder.h b/schroedinger/schrodecoder.h
index e435ed4..9ddaf0e 100644
--- a/schroedinger/schrodecoder.h
+++ b/schroedinger/schrodecoder.h
@@ -19,6 +19,7 @@ SCHRO_BEGIN_DECLS
 typedef struct _SchroDecoder SchroDecoder;
 typedef struct _SchroDecoderInstance SchroDecoderInstance;
 typedef struct _SchroPicture SchroPicture;
+typedef struct _SchroDecoderTag SchroDecoderTag;
 
 #ifdef SCHRO_ENABLE_UNSTABLE_API
 
@@ -54,8 +55,7 @@ struct _SchroDecoder {
 
   /* private data that is supplied with the input bitstream and
    * is to be associated with the next picture to occur */
-  void *next_picture_tag;
-  void (*free_picture_tag) (void*);
+  SchroDecoderTag *next_picture_tag;
 
   SchroDecoderInstance *instance;
 };
@@ -148,9 +148,14 @@ struct _SchroPicture {
   uint8_t md5_checksum[32];
 
   /* private data that is associated with this picture */
+  SchroDecoderTag *tag;
+};
+
+struct _SchroDecoderTag {
+  SchroTag base;
   void *tag;
-  void (*tag_free) (void*);
 };
+
 #endif
 
 enum {
@@ -198,7 +203,8 @@ int schro_decoder_autoparse_wait (SchroDecoder *decoder);
 int schro_decoder_autoparse_push (SchroDecoder *decoder, SchroBuffer *buffer);
 int schro_decoder_autoparse_push_end_of_sequence (SchroDecoder *decoder);
 
-void* schro_decoder_get_picture_tag (SchroDecoder *decoder);
+SchroDecoderTag * schro_decoder_tag_new ();
+SchroDecoderTag* schro_decoder_get_picture_tag (SchroDecoder *decoder);
 
 int schro_decoder_decode_parse_header (SchroUnpack *unpack);
 void schro_decoder_parse_sequence_header (SchroDecoderInstance *instance, 
SchroUnpack *unpack);
diff --git a/schroedinger/schroutils.h b/schroedinger/schroutils.h
index 17eda4b..abdb0e6 100644
--- a/schroedinger/schroutils.h
+++ b/schroedinger/schroutils.h
@@ -30,8 +30,15 @@ typedef unsigned int schro_bool;
  */
 typedef int SchroCUDAStream;
 
+/* Base for tag structures */
+typedef struct _SchroTag SchroTag;
+
 #ifdef SCHRO_ENABLE_UNSTABLE_API
 
+struct _SchroTag {
+    void (*free) (void *);
+};
+
 #define SCHRO_PICTURE_NUMBER_INVALID (-1)
 
 #define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
-- 
1.5.6.5


------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
Schrodinger-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/schrodinger-devel

Reply via email to