[Swfdec-commits] 2 commits - swfdec/Makefile.am swfdec/swfdec_audio_event.c swfdec/swfdec_audio_stream.c swfdec/swfdec_load_sound.c swfdec/swfdec_sound.c swfdec/swfdec_sound_object.c swfdec/swfdec_sound_object.h swfdec/swfdec_sound_provider.c swfdec/swfdec_sound_provider.h

Benjamin Otte company at kemper.freedesktop.org
Tue Jun 17 13:17:24 PDT 2008


 swfdec/Makefile.am             |    2 +
 swfdec/swfdec_audio_event.c    |    2 -
 swfdec/swfdec_audio_stream.c   |    2 -
 swfdec/swfdec_load_sound.c     |   26 +++++++++++++
 swfdec/swfdec_sound.c          |   26 ++++++++++++-
 swfdec/swfdec_sound_object.c   |   53 +++++++++++++++-------------
 swfdec/swfdec_sound_object.h   |    4 +-
 swfdec/swfdec_sound_provider.c |   77 +++++++++++++++++++++++++++++++++++++++++
 swfdec/swfdec_sound_provider.h |   55 +++++++++++++++++++++++++++++
 9 files changed, 216 insertions(+), 31 deletions(-)

New commits:
commit b78f6c4ea12451fb439bdbb845164576976fba8b
Author: Benjamin Otte <otte at gnome.org>
Date:   Tue Jun 17 22:12:06 2008 +0200

    assert the right thing

diff --git a/swfdec/swfdec_audio_stream.c b/swfdec/swfdec_audio_stream.c
index 62bff62..2869804 100644
--- a/swfdec/swfdec_audio_stream.c
+++ b/swfdec/swfdec_audio_stream.c
@@ -211,7 +211,7 @@ void
 swfdec_audio_stream_done (SwfdecAudioStream *stream)
 {
   g_return_if_fail (SWFDEC_IS_AUDIO_STREAM (stream));
-  g_return_if_fail (stream->done);
+  g_return_if_fail (!stream->done);
 
   stream->done = TRUE;
 }
commit 4198543b8cdefa1930f515184c1f259daffacff6
Author: Benjamin Otte <otte at gnome.org>
Date:   Tue Jun 17 15:10:02 2008 +0200

    add a SwfdecSoundProvider class

diff --git a/swfdec/Makefile.am b/swfdec/Makefile.am
index a4ea245..816dd4e 100644
--- a/swfdec/Makefile.am
+++ b/swfdec/Makefile.am
@@ -131,6 +131,7 @@ libswfdec_source_files = \
 	swfdec_sound.c \
 	swfdec_sound_matrix.c \
 	swfdec_sound_object.c \
+	swfdec_sound_provider.c \
 	swfdec_sprite.c \
 	swfdec_sprite_movie.c \
 	swfdec_sprite_movie_as.c \
@@ -297,6 +298,7 @@ noinst_HEADERS = \
 	swfdec_sound.h \
 	swfdec_sound_matrix.h \
 	swfdec_sound_object.h \
+	swfdec_sound_provider.h \
 	swfdec_sprite.h \
 	swfdec_sprite_movie.h \
 	swfdec_swf_decoder.h \
diff --git a/swfdec/swfdec_audio_event.c b/swfdec/swfdec_audio_event.c
index 4e993a9..2f835e9 100644
--- a/swfdec/swfdec_audio_event.c
+++ b/swfdec/swfdec_audio_event.c
@@ -221,7 +221,7 @@ swfdec_audio_event_create (SwfdecSound *sound, guint offset, guint end_offset, g
  * swfdec_audio_event_new:
  * @player: the #SwfdecPlayer to play the sound in
  * @sound: the sound to be played
- * @offset: offset into sound at which to start playing
+ * @offset: offset into sound in samples at which to start playing
  * @n_loops: number of times the sound should be played
  *
  * Starts playing back a sound from the given offset and loops the sound 
diff --git a/swfdec/swfdec_load_sound.c b/swfdec/swfdec_load_sound.c
index 3bb096d..1b3b029 100644
--- a/swfdec/swfdec_load_sound.c
+++ b/swfdec/swfdec_load_sound.c
@@ -24,14 +24,37 @@
 #include "swfdec_load_sound.h"
 #include "swfdec_as_strings.h"
 #include "swfdec_audio_decoder.h"
+#include "swfdec_audio_load.h"
 #include "swfdec_bits.h"
 #include "swfdec_buffer.h"
 #include "swfdec_debug.h"
 #include "swfdec_loader_internal.h"
 #include "swfdec_player_internal.h"
 #include "swfdec_sandbox.h"
+#include "swfdec_sound_provider.h"
 #include "swfdec_stream_target.h"
 
+/*** SWFDEC_SOUND_PROVIDER ***/
+
+static SwfdecAudio *
+swfdec_load_sound_sound_provider_start (SwfdecSoundProvider *provider,
+    SwfdecPlayer *player, gsize samples_offset, guint loops)
+{
+  SwfdecLoadSound *sound = SWFDEC_LOAD_SOUND (provider);
+
+  if (samples_offset > 0 || loops > 1) {
+    SWFDEC_FIXME ("implement starting at offset %"G_GSIZE_FORMAT" with %u loops",
+	samples_offset, loops);
+  }
+  return swfdec_audio_load_new (player, sound);
+}
+
+static void
+swfdec_load_sound_sound_provider_init (SwfdecSoundProviderInterface *iface)
+{
+  iface->start = swfdec_load_sound_sound_provider_start;
+}
+
 /*** SWFDEC_STREAM_TARGET ***/
 
 static SwfdecPlayer *
@@ -275,7 +298,8 @@ swfdec_load_sound_stream_target_init (SwfdecStreamTargetInterface *iface)
 /*** SWFDEC_LOAD_SOUND ***/
 
 G_DEFINE_TYPE_WITH_CODE (SwfdecLoadSound, swfdec_load_sound, G_TYPE_OBJECT,
-    G_IMPLEMENT_INTERFACE (SWFDEC_TYPE_STREAM_TARGET, swfdec_load_sound_stream_target_init))
+    G_IMPLEMENT_INTERFACE (SWFDEC_TYPE_STREAM_TARGET, swfdec_load_sound_stream_target_init);
+    G_IMPLEMENT_INTERFACE (SWFDEC_TYPE_SOUND_PROVIDER, swfdec_load_sound_sound_provider_init))
 
 static void
 swfdec_load_sound_dispose (GObject *object)
diff --git a/swfdec/swfdec_sound.c b/swfdec/swfdec_sound.c
index cc5862b..45dbcd4 100644
--- a/swfdec/swfdec_sound.c
+++ b/swfdec/swfdec_sound.c
@@ -1,7 +1,7 @@
 /* Swfdec
  * Copyright (C) 2003-2006 David Schleef <ds at schleef.org>
  *		 2005-2006 Eric Anholt <eric at anholt.net>
- *		 2006-2007 Benjamin Otte <otte at gnome.org>
+ *		 2006-2008 Benjamin Otte <otte at gnome.org>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -25,16 +25,38 @@
 
 #include "swfdec_sound.h"
 #include "swfdec_audio_decoder.h"
+#include "swfdec_audio_event.h"
 #include "swfdec_audio_internal.h"
 #include "swfdec_bits.h"
 #include "swfdec_buffer.h"
 #include "swfdec_button.h"
 #include "swfdec_debug.h"
 #include "swfdec_player_internal.h"
+#include "swfdec_sound_provider.h"
 #include "swfdec_sprite.h"
 #include "swfdec_swf_decoder.h"
 
-G_DEFINE_TYPE (SwfdecSound, swfdec_sound, SWFDEC_TYPE_CHARACTER)
+/*** SWFDEC_SOUND_PROVIDER ***/
+
+static SwfdecAudio *
+swfdec_sound_sound_provider_start (SwfdecSoundProvider *provider,
+    SwfdecPlayer *player, gsize samples_offset, guint loops)
+{
+  SwfdecSound *sound = SWFDEC_SOUND (provider);
+
+  return swfdec_audio_event_new (player, sound, samples_offset, loops);
+}
+
+static void
+swfdec_sound_sound_provider_init (SwfdecSoundProviderInterface *iface)
+{
+  iface->start = swfdec_sound_sound_provider_start;
+}
+
+/*** SWFDEC_SOUND ***/
+
+G_DEFINE_TYPE_WITH_CODE (SwfdecSound, swfdec_sound, SWFDEC_TYPE_CHARACTER,
+    G_IMPLEMENT_INTERFACE (SWFDEC_TYPE_SOUND_PROVIDER, swfdec_sound_sound_provider_init))
 
 static void
 swfdec_sound_dispose (GObject *object)
diff --git a/swfdec/swfdec_sound_object.c b/swfdec/swfdec_sound_object.c
index 2f0fd45..dbd234d 100644
--- a/swfdec/swfdec_sound_object.c
+++ b/swfdec/swfdec_sound_object.c
@@ -29,7 +29,7 @@
 #include "swfdec_as_object.h"
 #include "swfdec_as_strings.h"
 #include "swfdec_audio_event.h"
-#include "swfdec_audio_load.h"
+#include "swfdec_audio_internal.h"
 #include "swfdec_debug.h"
 #include "swfdec_internal.h"
 #include "swfdec_player_internal.h"
@@ -55,13 +55,9 @@ swfdec_sound_object_dispose (GObject *object)
 {
   SwfdecSoundObject *sound = SWFDEC_SOUND_OBJECT (object);
 
-  if (sound->attached) {
-    g_object_unref (sound->attached);
-    sound->attached = NULL;
-  }
-  if (sound->load) {
-    g_object_unref (sound->load);
-    sound->load = NULL;
+  if (sound->provider) {
+    g_object_unref (sound->provider);
+    sound->provider = NULL;
   }
 
   G_OBJECT_CLASS (swfdec_sound_object_parent_class)->dispose (object);
@@ -296,11 +292,17 @@ swfdec_sound_object_loadSound (SwfdecAsContext *cx, SwfdecAsObject *object,
 
   SWFDEC_AS_CHECK (SWFDEC_TYPE_SOUND_OBJECT, &sound, "sb", &url, &stream);
 
-  if (sound->load)
-    g_object_unref (sound->load);
-  sound->load = swfdec_load_sound_new (object, url);
+  if (sound->audio) {
+    swfdec_audio_remove (sound->audio);
+    g_object_unref (sound->audio);
+    sound->audio = NULL;
+  }
+  if (sound->provider)
+    g_object_unref (sound->provider);
+  sound->provider = SWFDEC_SOUND_PROVIDER (swfdec_load_sound_new (object, url));
   if (stream)
-    sound->audio = swfdec_audio_load_new (SWFDEC_PLAYER (cx), sound->load);
+    sound->audio = swfdec_sound_provider_start (sound->provider,
+	SWFDEC_PLAYER (cx), 0, 1);
 }
 
 SWFDEC_AS_NATIVE (500, 14, swfdec_sound_object_getBytesLoaded)
@@ -359,9 +361,9 @@ swfdec_sound_object_attachSound (SwfdecAsContext *cx, SwfdecAsObject *object, gu
 
   new = swfdec_sound_object_get_sound (sound, name);
   if (new) {
-    if (sound->attached)
-      g_object_unref (sound->attached);
-    sound->attached = g_object_ref (new);
+    if (sound->provider)
+      g_object_unref (sound->provider);
+    sound->provider = g_object_ref (new);
   }
 }
 
@@ -373,11 +375,10 @@ swfdec_sound_object_start (SwfdecAsContext *cx, SwfdecAsObject *object, guint ar
   SwfdecSoundObject *sound;
   double offset;
   int loops;
-  SwfdecAudio *audio;
 
   SWFDEC_AS_CHECK (SWFDEC_TYPE_SOUND_OBJECT, &sound, "|ni", &offset, &loops);
 
-  if (sound->attached == NULL) {
+  if (sound->provider == NULL) {
     SWFDEC_INFO ("no sound attached when calling Sound.start()");
     return;
   }
@@ -386,15 +387,19 @@ swfdec_sound_object_start (SwfdecAsContext *cx, SwfdecAsObject *object, guint ar
   if (offset < 0 || !isfinite (offset))
     offset = 0;
 
-  audio = swfdec_audio_event_new (SWFDEC_PLAYER (cx), sound->attached, offset / 44100, loops);
+  if (sound->audio) {
+    swfdec_audio_remove (sound->audio);
+    g_object_unref (sound->audio);
+  }
+  sound->audio = swfdec_sound_provider_start (sound->provider, SWFDEC_PLAYER (cx), 
+      offset * 44100, loops);
   if (sound->target && !sound->global)
-    swfdec_audio_set_actor (audio, SWFDEC_ACTOR (sound->target));
-  g_object_unref (audio);
+    swfdec_audio_set_actor (sound->audio, SWFDEC_ACTOR (sound->target));
 }
 
 typedef struct {
-  SwfdecMovie *movie;
-  SwfdecSound *sound;
+  SwfdecMovie *	movie;
+  gpointer	sound;
 } RemoveData;
 
 static gboolean
@@ -432,8 +437,8 @@ swfdec_sound_object_stop (SwfdecAsContext *cx, SwfdecAsObject *object, guint arg
     data.sound = swfdec_sound_object_get_sound (sound, name);
     if (data.sound == NULL)
       return;
-  } else if (sound->attached) {
-    data.sound = sound->attached;
+  } else if (sound->provider) {
+    data.sound = sound->provider;
   } else {
     data.sound = NULL;
   }
diff --git a/swfdec/swfdec_sound_object.h b/swfdec/swfdec_sound_object.h
index c053057..0a79bc0 100644
--- a/swfdec/swfdec_sound_object.h
+++ b/swfdec/swfdec_sound_object.h
@@ -23,6 +23,7 @@
 #include <swfdec/swfdec_audio.h>
 #include <swfdec/swfdec_load_sound.h>
 #include <swfdec/swfdec_movie.h>
+#include <swfdec/swfdec_sound_provider.h>
 
 G_BEGIN_DECLS
 
@@ -42,8 +43,7 @@ struct _SwfdecSoundObject {
 
   SwfdecMovie *		target;		/* target movie or NULL on constructing error */
   gboolean		global;		/* TRUE if handling global sound */
-  SwfdecSound *		attached;	/* sound that was attached */
-  SwfdecLoadSound *	load;		/* sound that is/was loaded using loadSound */
+  SwfdecSoundProvider *	provider;	/* sound that we play */
   SwfdecAudio *		audio;		/* audio stream we started */
 };
 
diff --git a/swfdec/swfdec_sound_provider.c b/swfdec/swfdec_sound_provider.c
new file mode 100644
index 0000000..add6ef9
--- /dev/null
+++ b/swfdec/swfdec_sound_provider.c
@@ -0,0 +1,77 @@
+/* Swfdec
+ * Copyright (C) 2008 Benjamin Otte <otte at gnome.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ * This library 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
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, 
+ * Boston, MA  02110-1301  USA
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "swfdec_sound_provider.h"
+#include "swfdec_debug.h"
+#include "swfdec_player_internal.h"
+
+static void
+swfdec_sound_provider_base_init (gpointer klass)
+{
+  static gboolean initialized = FALSE;
+
+  if (G_UNLIKELY (!initialized)) {
+    initialized = TRUE;
+  }
+}
+
+GType
+swfdec_sound_provider_get_type (void)
+{
+  static GType sound_provider_type = 0;
+  
+  if (!sound_provider_type) {
+    static const GTypeInfo sound_provider_info = {
+      sizeof (SwfdecSoundProviderInterface),
+      swfdec_sound_provider_base_init,
+      NULL,
+      NULL,
+      NULL,
+      NULL,
+      0,
+      0,
+      NULL,
+    };
+    
+    sound_provider_type = g_type_register_static (G_TYPE_INTERFACE,
+        "SwfdecSoundProvider", &sound_provider_info, 0);
+    g_type_interface_add_prerequisite (sound_provider_type, G_TYPE_OBJECT);
+  }
+  
+  return sound_provider_type;
+}
+
+SwfdecAudio *
+swfdec_sound_provider_start (SwfdecSoundProvider *provider, 
+    SwfdecPlayer *player, gsize samples_offset, guint loops)
+{
+  SwfdecSoundProviderInterface *iface;
+  
+  g_return_val_if_fail (SWFDEC_IS_SOUND_PROVIDER (provider), NULL);
+  g_return_val_if_fail (SWFDEC_IS_PLAYER (player), NULL);
+  g_return_val_if_fail (loops > 0, NULL);
+
+  iface = SWFDEC_SOUND_PROVIDER_GET_INTERFACE (provider);
+  return iface->start (provider, player, samples_offset, loops);
+}
+
diff --git a/swfdec/swfdec_sound_provider.h b/swfdec/swfdec_sound_provider.h
new file mode 100644
index 0000000..76689a2
--- /dev/null
+++ b/swfdec/swfdec_sound_provider.h
@@ -0,0 +1,55 @@
+/* Swfdec
+ * Copyright (C) 2008 Benjamin Otte <otte at gnome.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ * This library 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
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, 
+ * Boston, MA  02110-1301  USA
+ */
+
+#ifndef __SWFDEC_SOUND_PROVIDER_H__
+#define __SWFDEC_SOUND_PROVIDER_H__
+
+#include <swfdec/swfdec.h>
+
+G_BEGIN_DECLS
+
+
+#define SWFDEC_TYPE_SOUND_PROVIDER                (swfdec_sound_provider_get_type ())
+#define SWFDEC_SOUND_PROVIDER(obj)                (G_TYPE_CHECK_INSTANCE_CAST ((obj), SWFDEC_TYPE_SOUND_PROVIDER, SwfdecSoundProvider))
+#define SWFDEC_IS_SOUND_PROVIDER(obj)             (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SWFDEC_TYPE_SOUND_PROVIDER))
+#define SWFDEC_SOUND_PROVIDER_GET_INTERFACE(inst) (G_TYPE_INSTANCE_GET_INTERFACE ((inst), SWFDEC_TYPE_SOUND_PROVIDER, SwfdecSoundProviderInterface))
+
+typedef struct _SwfdecSoundProvider SwfdecSoundProvider; /* dummy object */
+typedef struct _SwfdecSoundProviderInterface SwfdecSoundProviderInterface;
+
+struct _SwfdecSoundProviderInterface {
+  GTypeInterface	interface;
+
+  SwfdecAudio *		(* start)				(SwfdecSoundProvider *  provider,
+								 SwfdecPlayer *		player, 
+								 gsize			samples_offset,
+								 guint			loops);
+};
+
+GType			swfdec_sound_provider_get_type		(void) G_GNUC_CONST;
+
+SwfdecAudio *     	swfdec_sound_provider_start		(SwfdecSoundProvider *	provider,
+								 SwfdecPlayer *		player, 
+								 gsize			samples_offset,
+								 guint			loops);
+
+
+G_END_DECLS
+
+#endif /* __SWFDEC_SOUND_PROVIDER_H__ */


More information about the Swfdec-commits mailing list