[Swfdec] configure.ac doc/swfdec-sections.txt libswfdec/swfdec_buffer.c libswfdec/swfdec_buffer.h libswfdec/swfdec_codec_adpcm.c libswfdec/swfdec_codec_ffmpeg.c libswfdec/swfdec_codec_mad.c libswfdec/swfdec_loader.c libswfdec/swfdec_sound.c libswfdec/swfdec_swf_decoder.c test/sound test/swfdec-extract.c test/swfedit_file.c

Benjamin Otte company at kemper.freedesktop.org
Wed Mar 28 13:37:15 PDT 2007


 configure.ac                    |    2 
 doc/swfdec-sections.txt         |   10 +++-
 libswfdec/swfdec_buffer.c       |   95 ++++++++++++++++++++++++++++++++++++----
 libswfdec/swfdec_buffer.h       |   16 +++++-
 libswfdec/swfdec_codec_adpcm.c  |    2 
 libswfdec/swfdec_codec_ffmpeg.c |    6 +-
 libswfdec/swfdec_codec_mad.c    |    2 
 libswfdec/swfdec_loader.c       |    2 
 libswfdec/swfdec_sound.c        |    2 
 libswfdec/swfdec_swf_decoder.c  |    2 
 test/sound/sound.c              |    2 
 test/swfdec-extract.c           |    4 -
 test/swfedit_file.c             |    2 
 13 files changed, 120 insertions(+), 27 deletions(-)

New commits:
diff-tree 7f7d106034cd5fac344b12e3c93562a24ecd825f (from 579955e4dcc87dd9c91428ee1967e01bc9cfa69b)
Author: Benjamin Otte <otte at gnome.org>
Date:   Wed Mar 28 22:38:10 2007 +0200

    make SwfdecBuffer and SwfdecBufferQueue boxed types
    
    - add and document the types
    - change SwfdecBufferQueue to be refcounted
      (most changes here are s/_buffer_queue_free/_buffer_queue_unref/
    - break API by removing swfdec_buffer_queue_unref

diff --git a/configure.ac b/configure.ac
index 5309072..30801ce 100644
--- a/configure.ac
+++ b/configure.ac
@@ -33,7 +33,7 @@ else
 fi
 AC_DEFINE_UNQUOTED(SWFDEC_LEVEL_DEFAULT, $DEFAULT_DEBUG_LEVEL, [Default debug level used])
 
-SWFDEC_LIBVERSION="2:0:0"
+SWFDEC_LIBVERSION="3:0:0"
 AC_SUBST(SWFDEC_LIBVERSION)
 AM_PROG_LIBTOOL
 
diff --git a/doc/swfdec-sections.txt b/doc/swfdec-sections.txt
index a6e2d96..3d270af 100644
--- a/doc/swfdec-sections.txt
+++ b/doc/swfdec-sections.txt
@@ -57,7 +57,7 @@ swfdec_player_render
 swfdec_player_advance
 swfdec_player_handle_mouse
 swfdec_player_render_audio
-swfdec_player_get_audio_enabled
+swfdec_player_get_audio
 <SUBSECTION Standard>
 SwfdecPlayerClass
 SWFDEC_PLAYER
@@ -73,7 +73,9 @@ SWFDEC_PLAYER_GET_CLASS
 <FILE>SwfdecBuffer</FILE>
 <TITLE>SwfdecBuffer</TITLE>
 SwfdecBuffer
+SWFDEC_TYPE_BUFFER
 SwfdecBufferQueue
+SWFDEC_TYPE_BUFFER_QUEUE
 swfdec_buffer_new
 swfdec_buffer_new_and_alloc
 swfdec_buffer_new_and_alloc0
@@ -84,13 +86,17 @@ swfdec_buffer_ref
 swfdec_buffer_unref
 swfdec_buffer_queue_new
 swfdec_buffer_queue_clear
-swfdec_buffer_queue_free
+swfdec_buffer_queue_ref
+swfdec_buffer_queue_unref
 swfdec_buffer_queue_get_depth
 swfdec_buffer_queue_get_offset
 swfdec_buffer_queue_push
 swfdec_buffer_queue_pull
 swfdec_buffer_queue_pull_buffer
 swfdec_buffer_queue_peek
+<SUBSECTION Standard>
+swfdec_buffer_get_type
+swfdec_buffer_queue_get_type
 </SECTION>
 
 <SECTION>
diff --git a/libswfdec/swfdec_buffer.c b/libswfdec/swfdec_buffer.c
index 49d47e7..3b8e929 100644
--- a/libswfdec/swfdec_buffer.c
+++ b/libswfdec/swfdec_buffer.c
@@ -54,6 +54,26 @@
 /*** SwfdecBuffer ***/
 
 /**
+ * SWFDEC_TYPE_BUFFER:
+ *
+ * #SwfdecBuffer is a boxed type for the glib type system. This macro
+ * returns its type.
+ **/
+GType
+swfdec_buffer_get_type (void)
+{
+  static GType type_swfdec_buffer = 0;
+
+  if (!type_swfdec_buffer)
+    type_swfdec_buffer = g_boxed_type_register_static
+      ("SwfdecBuffer", 
+       (GBoxedCopyFunc) swfdec_buffer_ref,
+       (GBoxedFreeFunc) swfdec_buffer_unref);
+
+  return type_swfdec_buffer;
+}
+
+/**
  * swfdec_buffer_new:
  *
  * Creates a new #SwfdecBuffer to be filled by the user. Use like this:
@@ -267,12 +287,36 @@ swfdec_buffer_unref (SwfdecBuffer * buff
   }
 }
 
-/*** SwfdecBuffer ***/
+/*** SwfdecBufferQueue ***/
+
+/**
+ * SWFDEC_TYPE_BUFFER_QUEUE:
+ *
+ * #SwfdecBufferQueue is a boxed type for the glib type system. This macro
+ * returns its type.
+ **/
+GType
+swfdec_buffer_queue_get_type (void)
+{
+  static GType type_swfdec_buffer_queue = 0;
+
+  if (!type_swfdec_buffer_queue)
+    type_swfdec_buffer_queue = g_boxed_type_register_static
+      ("SwfdecBufferQueue", 
+       (GBoxedCopyFunc) swfdec_buffer_queue_ref,
+       (GBoxedFreeFunc) swfdec_buffer_queue_unref);
+
+  return type_swfdec_buffer_queue;
+}
 
 SwfdecBufferQueue *
 swfdec_buffer_queue_new (void)
 {
-  return g_new0 (SwfdecBufferQueue, 1);
+  SwfdecBufferQueue *buffer_queue;
+
+  buffer_queue = g_new0 (SwfdecBufferQueue, 1);
+  buffer_queue->ref_count = 1;
+  return buffer_queue;
 }
 
 int
@@ -296,13 +340,6 @@ swfdec_buffer_queue_clear (SwfdecBufferQ
 }
 
 void
-swfdec_buffer_queue_free (SwfdecBufferQueue * queue)
-{
-  swfdec_buffer_queue_clear (queue);
-  g_free (queue);
-}
-
-void
 swfdec_buffer_queue_push (SwfdecBufferQueue * queue, SwfdecBuffer * buffer)
 {
   g_return_if_fail (queue != NULL);
@@ -443,3 +480,43 @@ swfdec_buffer_queue_peek (SwfdecBufferQu
 
   return newbuffer;
 }
+
+/**
+ * swfdec_buffer_queue_ref:
+ * @queue: a #SwfdecBufferQueue
+ *
+ * increases the reference count of @queue by one.
+ *
+ * Returns: The passed in @queue.
+ **/
+SwfdecBufferQueue *
+swfdec_buffer_queue_ref (SwfdecBufferQueue * queue)
+{
+  g_return_val_if_fail (queue != NULL, NULL);
+  g_return_val_if_fail (queue->ref_count > 0, NULL);
+
+  queue->ref_count++;
+  return queue;
+}
+
+/**
+ * swfdec_buffer_queue_unref:
+ * @queue: a #SwfdecBufferQueue
+ *
+ * Decreases the reference count of @queue by one. If no reference 
+ * to this buffer exists anymore, the buffer and the memory 
+ * it manages are freed.
+ **/
+void
+swfdec_buffer_queue_unref (SwfdecBufferQueue * queue)
+{
+  g_return_if_fail (queue != NULL);
+  g_return_if_fail (queue->ref_count > 0);
+
+  queue->ref_count--;
+  if (queue->ref_count == 0) {
+    swfdec_buffer_queue_clear (queue);
+    g_free (queue);
+  }
+}
+
diff --git a/libswfdec/swfdec_buffer.h b/libswfdec/swfdec_buffer.h
index 81f6f66..38a7f2f 100644
--- a/libswfdec/swfdec_buffer.h
+++ b/libswfdec/swfdec_buffer.h
@@ -23,6 +23,7 @@
 #define __SWFDEC_BUFFER_H__
 
 #include <glib.h>
+#include <glib-object.h>
 
 typedef struct _SwfdecBuffer SwfdecBuffer;
 typedef struct _SwfdecBufferQueue SwfdecBufferQueue;
@@ -40,13 +41,21 @@ struct _SwfdecBuffer
   void *priv;
 };
 
+#define SWFDEC_TYPE_BUFFER swfdec_buffer_get_type()
+GType swfdec_buffer_get_type  (void);
+
 struct _SwfdecBufferQueue
 {
   GList *buffers;
   unsigned int depth;
   unsigned int offset;
+  
+  int ref_count;
 };
 
+#define SWFDEC_TYPE_BUFFER_QUEUE swfdec_buffer_queue_get_type()
+GType swfdec_buffer_queue_get_type  (void);
+
 SwfdecBuffer *swfdec_buffer_new (void);
 SwfdecBuffer *swfdec_buffer_new_and_alloc (unsigned int size);
 SwfdecBuffer *swfdec_buffer_new_and_alloc0 (unsigned int size);
@@ -54,12 +63,11 @@ SwfdecBuffer *swfdec_buffer_new_for_data
 SwfdecBuffer *swfdec_buffer_new_subbuffer (SwfdecBuffer * buffer, unsigned int offset,
     unsigned int length);
 SwfdecBuffer *swfdec_buffer_new_from_file (const char *filename, GError **error);
-SwfdecBuffer * swfdec_buffer_ref (SwfdecBuffer * buffer);
+SwfdecBuffer *swfdec_buffer_ref (SwfdecBuffer * buffer);
 void swfdec_buffer_unref (SwfdecBuffer * buffer);
 
 SwfdecBufferQueue *swfdec_buffer_queue_new (void);
 void swfdec_buffer_queue_clear (SwfdecBufferQueue *queue);
-void swfdec_buffer_queue_free (SwfdecBufferQueue * queue);
 int swfdec_buffer_queue_get_depth (SwfdecBufferQueue * queue);
 int swfdec_buffer_queue_get_offset (SwfdecBufferQueue * queue);
 void swfdec_buffer_queue_push (SwfdecBufferQueue * queue,
@@ -67,5 +75,7 @@ void swfdec_buffer_queue_push (SwfdecBuf
 SwfdecBuffer *swfdec_buffer_queue_pull (SwfdecBufferQueue * queue, unsigned int length);
 SwfdecBuffer *swfdec_buffer_queue_pull_buffer (SwfdecBufferQueue * queue);
 SwfdecBuffer *swfdec_buffer_queue_peek (SwfdecBufferQueue * queue, unsigned int length);
-
+SwfdecBufferQueue *swfdec_buffer_queue_ref (SwfdecBufferQueue * queue);
+void swfdec_buffer_queue_unref (SwfdecBufferQueue * queue);
 #endif
+
diff --git a/libswfdec/swfdec_codec_adpcm.c b/libswfdec/swfdec_codec_adpcm.c
index f0fcc0d..93775c2 100644
--- a/libswfdec/swfdec_codec_adpcm.c
+++ b/libswfdec/swfdec_codec_adpcm.c
@@ -157,7 +157,7 @@ swfdec_codec_adpcm_decode (gpointer data
   } else {
     buffer = NULL;
   }
-  swfdec_buffer_queue_free (queue);
+  swfdec_buffer_queue_unref (queue);
   return buffer;
 }
 
diff --git a/libswfdec/swfdec_codec_ffmpeg.c b/libswfdec/swfdec_codec_ffmpeg.c
index cc5852a..127e1bd 100644
--- a/libswfdec/swfdec_codec_ffmpeg.c
+++ b/libswfdec/swfdec_codec_ffmpeg.c
@@ -151,7 +151,7 @@ swfdec_codec_ffmpeg_decode (gpointer ctx
 
     if (len < 0) {
       SWFDEC_ERROR ("Error %d while decoding", len);
-      swfdec_buffer_queue_free (queue);
+      swfdec_buffer_queue_unref (queue);
       swfdec_buffer_unref (outbuf);
       return NULL;
     }
@@ -160,7 +160,7 @@ swfdec_codec_ffmpeg_decode (gpointer ctx
       outbuf->length = out_size;
       convert = swfdec_codec_ffmpeg_convert (ctx, outbuf);
       if (convert == NULL) {
-	swfdec_buffer_queue_free (queue);
+	swfdec_buffer_queue_unref (queue);
 	swfdec_buffer_unref (outbuf);
 	return NULL;
       }
@@ -176,7 +176,7 @@ swfdec_codec_ffmpeg_decode (gpointer ctx
     outbuf = swfdec_buffer_queue_pull (queue, amount);
   else
     outbuf = NULL;
-  swfdec_buffer_queue_free (queue);
+  swfdec_buffer_queue_unref (queue);
 
   return outbuf;
 }
diff --git a/libswfdec/swfdec_codec_mad.c b/libswfdec/swfdec_codec_mad.c
index 18ca2fb..fa59e9c 100644
--- a/libswfdec/swfdec_codec_mad.c
+++ b/libswfdec/swfdec_codec_mad.c
@@ -189,7 +189,7 @@ swfdec_codec_mad_decode (gpointer datap,
     out = swfdec_buffer_queue_pull (queue, size);
   else
     out = NULL;
-  swfdec_buffer_queue_free (queue);
+  swfdec_buffer_queue_unref (queue);
 
   return out;
 }
diff --git a/libswfdec/swfdec_loader.c b/libswfdec/swfdec_loader.c
index 81d536c..fc5b1b6 100644
--- a/libswfdec/swfdec_loader.c
+++ b/libswfdec/swfdec_loader.c
@@ -139,7 +139,7 @@ swfdec_loader_dispose (GObject *object)
 {
   SwfdecLoader *loader = SWFDEC_LOADER (object);
 
-  swfdec_buffer_queue_free (loader->queue);
+  swfdec_buffer_queue_unref (loader->queue);
   g_free (loader->url);
   g_free (loader->error);
 
diff --git a/libswfdec/swfdec_sound.c b/libswfdec/swfdec_sound.c
index 85e3bb8..bc4ea93 100644
--- a/libswfdec/swfdec_sound.c
+++ b/libswfdec/swfdec_sound.c
@@ -223,7 +223,7 @@ swfdec_sound_get_decoded (SwfdecSound *s
       swfdec_buffer_queue_push (queue, tmp);
       swfdec_buffer_queue_push (queue, tmp2);
       tmp = swfdec_buffer_queue_pull (queue, swfdec_buffer_queue_get_depth (queue));
-      swfdec_buffer_queue_free (queue);
+      swfdec_buffer_queue_unref (queue);
     }
   }
   SWFDEC_LOG ("after decoding, got %u samples, should get %u and skip %u", 
diff --git a/libswfdec/swfdec_swf_decoder.c b/libswfdec/swfdec_swf_decoder.c
index f205eed..3954b36 100644
--- a/libswfdec/swfdec_swf_decoder.c
+++ b/libswfdec/swfdec_swf_decoder.c
@@ -60,7 +60,7 @@ swfdec_decoder_dispose (GObject *object)
     swfdec_buffer_unref (s->uncompressed_buffer);
     s->uncompressed_buffer = NULL;
   }
-  swfdec_buffer_queue_free (s->input_queue);
+  swfdec_buffer_queue_unref (s->input_queue);
 
   if (s->jpegtables) {
     swfdec_buffer_unref (s->jpegtables);
diff --git a/test/sound/sound.c b/test/sound/sound.c
index f42149f..6cbb5cc 100644
--- a/test/sound/sound.c
+++ b/test/sound/sound.c
@@ -119,7 +119,7 @@ finish_stream (TestStream *stream)
   gboolean ret = TRUE;
 
   buffer = swfdec_buffer_queue_pull (stream->queue, swfdec_buffer_queue_get_depth (stream->queue));
-  swfdec_buffer_queue_free (stream->queue);
+  swfdec_buffer_queue_unref (stream->queue);
   file = swfdec_buffer_new_from_file (stream->name, &error);
   if (file) {
     ret = audio_diff (buffer, file, stream->name);
diff --git a/test/swfdec-extract.c b/test/swfdec-extract.c
index da0964b..36ae146 100644
--- a/test/swfdec-extract.c
+++ b/test/swfdec-extract.c
@@ -122,12 +122,12 @@ export_sprite_sound (SwfdecSprite *sprit
   }
   depth = swfdec_buffer_queue_get_depth (queue);
   if (depth == 0) {
-    swfdec_buffer_queue_free (queue);
+    swfdec_buffer_queue_unref (queue);
     g_printerr ("Sprite contains no sound\n");
     return FALSE;
   }
   buffer = swfdec_buffer_queue_pull (queue, depth);
-  swfdec_buffer_queue_free (queue);
+  swfdec_buffer_queue_unref (queue);
   wav = encode_wav (buffer);
   swfdec_buffer_unref (buffer);
   if (!g_file_set_contents (filename, (char *) wav->data, 
diff --git a/test/swfedit_file.c b/test/swfedit_file.c
index 26699de..e257010 100644
--- a/test/swfedit_file.c
+++ b/test/swfedit_file.c
@@ -260,7 +260,7 @@ swfedit_file_write (SwfeditFile *file)
     swfdec_out_put_buffer (out, buffer);
     swfdec_buffer_unref (buffer);
   }
-  swfdec_buffer_queue_free (queue);
+  swfdec_buffer_queue_unref (queue);
   return swfdec_out_close (out);
 }
 


More information about the Swfdec mailing list