[Swfdec] 4 commits - configure.ac doc/Makefile.am doc/swfdec-docs.sgml doc/swfdec-sections.txt doc/swfdec.types libswfdec-gtk/Makefile.am libswfdec-gtk/swfdec-gtk.h libswfdec-gtk/swfdec_gtk_loader.c libswfdec-gtk/swfdec_gtk_loader.h libswfdec-gtk/swfdec_gtk_player.c libswfdec-gtk/swfdec_gtk_player.h libswfdec/swfdec_loader.c libswfdec/swfdec_loader.h libswfdec/swfdec_loader_internal.h libswfdec/swfdec_player.c libswfdec/swfdec_player.h player/swfdebug.c player/swfplay.c test/dump.c test/image test/parse.c test/sound test/swfdec-extract.c test/trace

Benjamin Otte company at kemper.freedesktop.org
Mon Apr 2 04:28:55 PDT 2007


 configure.ac                       |   27 +++-
 doc/Makefile.am                    |    3 
 doc/swfdec-docs.sgml               |    1 
 doc/swfdec-sections.txt            |   18 ++
 doc/swfdec.types                   |    2 
 libswfdec-gtk/Makefile.am          |    6 
 libswfdec-gtk/swfdec-gtk.h         |    1 
 libswfdec-gtk/swfdec_gtk_loader.c  |  237 +++++++++++++++++++++++++++++++++++++
 libswfdec-gtk/swfdec_gtk_loader.h  |   44 ++++++
 libswfdec-gtk/swfdec_gtk_player.c  |   23 +--
 libswfdec-gtk/swfdec_gtk_player.h  |    9 -
 libswfdec/swfdec_loader.c          |   46 ++-----
 libswfdec/swfdec_loader.h          |    3 
 libswfdec/swfdec_loader_internal.h |   22 +++
 libswfdec/swfdec_player.c          |   14 --
 libswfdec/swfdec_player.h          |    3 
 player/swfdebug.c                  |    8 -
 player/swfplay.c                   |   15 --
 test/dump.c                        |    8 -
 test/image/image.c                 |   10 -
 test/parse.c                       |   10 -
 test/sound/sound.c                 |   10 -
 test/swfdec-extract.c              |   10 -
 test/trace/trace.c                 |    9 -
 24 files changed, 422 insertions(+), 117 deletions(-)

New commits:
diff-tree cba7ba2518e522d3f695d41a7f4c8dc4d1d19da8 (from 7d592c21a8605361c3e63aca138f3e359cdbab50)
Author: Benjamin Otte <otte at gnome.org>
Date:   Mon Apr 2 13:28:39 2007 +0200

    update docs

diff --git a/configure.ac b/configure.ac
index 3550a5c..fdf2a31 100644
--- a/configure.ac
+++ b/configure.ac
@@ -226,13 +226,13 @@ AM_CONDITIONAL(HAVE_GNOMEVFS, [test "x$H
 AC_SUBST(GLOBAL_CFLAGS)
 AC_SUBST(GLOBAL_CFLAGS)
 
-SWFDEC_CFLAGS="-I\$(top_srcdir) $GLIB_CFLAGS"
-SWFDEC_LIBS="\$(top_builddir)/libswfdec/libswfdec-$SWFDEC_MAJORMINOR.la $GLIB_LIBS -lz"
+SWFDEC_CFLAGS="-I\$(top_srcdir) $GLIB_CFLAGS $CAIRO_CFLAGS"
+SWFDEC_LIBS="\$(top_builddir)/libswfdec/libswfdec-$SWFDEC_MAJORMINOR.la $GLIB_LIBS $CAIRO_LIBS -lz"
 AC_SUBST(SWFDEC_LIBS)
 AC_SUBST(SWFDEC_CFLAGS)
 
-SWFDEC_GTK_CFLAGS="$SWFDEC_CFLAGS"
-SWFDEC_GTK_LIBS="\$(top_builddir)/libswfdec-gtk/libswfdec-gtk-$SWFDEC_MAJORMINOR.la $SWFDEC_LIBS"
+SWFDEC_GTK_CFLAGS="$SWFDEC_CFLAGS $GTK_CFLAGS"
+SWFDEC_GTK_LIBS="\$(top_builddir)/libswfdec-gtk/libswfdec-gtk-$SWFDEC_MAJORMINOR.la $SWFDEC_LIBS $GTK_LIBS"
 AC_SUBST(SWFDEC_GTK_LIBS)
 AC_SUBST(SWFDEC_GTK_CFLAGS)
 
diff --git a/doc/Makefile.am b/doc/Makefile.am
index 0b037de..4855ce8 100644
--- a/doc/Makefile.am
+++ b/doc/Makefile.am
@@ -109,6 +109,7 @@ IGNORE_HFILES= \
 	swfdec_xml.h
 
 EXTRA_HFILES = \
+	../libswfdec-gtk/swfdec_gtk_loader.h \
 	../libswfdec-gtk/swfdec_gtk_player.h \
 	../libswfdec-gtk/swfdec_gtk_widget.h
 
@@ -131,7 +132,7 @@ expand_content_files=
 # e.g. INCLUDES=-I$(top_srcdir) -I$(top_builddir) $(GTK_DEBUG_FLAGS)
 # e.g. GTKDOC_LIBS=$(top_builddir)/gtk/$(gtktargetlib)
 INCLUDES=$(SWFDEC_GTK_CFLAGS) $(CAIRO_CFLAGS)
-GTKDOC_LIBS=$(SWFDEC_GTK_LIBS)
+GTKDOC_LIBS=$(SWFDEC_GTK_LIBS) 
 
 # This includes the standard gtk-doc make rules, copied by gtkdocize.
 include $(top_srcdir)/gtk-doc.make
diff --git a/doc/swfdec-docs.sgml b/doc/swfdec-docs.sgml
index e5b1d71..aa1c339 100644
--- a/doc/swfdec-docs.sgml
+++ b/doc/swfdec-docs.sgml
@@ -10,6 +10,7 @@
     <title>Swfdec Gtk library</title>
     <xi:include href="xml/SwfdecGtkPlayer.xml"/>
     <xi:include href="xml/SwfdecGtkWidget.xml"/>
+    <xi:include href="xml/SwfdecGtkLoader.xml"/>
   </chapter>
   <chapter>
     <title>Swfdec library</title>
diff --git a/doc/swfdec-sections.txt b/doc/swfdec-sections.txt
index 3d270af..e0454c7 100644
--- a/doc/swfdec-sections.txt
+++ b/doc/swfdec-sections.txt
@@ -118,7 +118,7 @@ swfdec_mouse_cursor_get_type
 <TITLE>SwfdecGtkPlayer</TITLE>
 SwfdecGtkPlayer
 swfdec_gtk_player_new
-swfdec_gtk_player_new_from_file
+swfdec_gtk_player_new_from_uri
 swfdec_gtk_player_get_playing
 swfdec_gtk_player_set_playing
 swfdec_gtk_player_get_speed
@@ -162,3 +162,19 @@ SWFDEC_IS_GTK_WIDGET
 SWFDEC_IS_GTK_WIDGET_CLASS
 SWFDEC_TYPE_GTK_WIDGET
 </SECTION>
+
+<SECTION>
+<FILE>SwfdecGtkLoader</FILE>
+<TITLE>SwfdecGtkLoader</TITLE>
+SwfdecGtkLoader
+swfdec_gtk_loader_new
+<SUBSECTION Standard>
+swfdec_gtk_loader_get_type
+SwfdecGtkLoaderClass
+SWFDEC_GTK_LOADER
+SWFDEC_GTK_LOADER_CLASS
+SWFDEC_GTK_LOADER_GET_CLASS
+SWFDEC_IS_GTK_LOADER
+SWFDEC_IS_GTK_LOADER_CLASS
+SWFDEC_TYPE_GTK_LOADER
+</SECTION>
diff --git a/doc/swfdec.types b/doc/swfdec.types
index dbd39e4..9b70671 100644
--- a/doc/swfdec.types
+++ b/doc/swfdec.types
@@ -1,8 +1,10 @@
 #include <libswfdec/swfdec.h>
+#include <libswfdec-gtk/swfdec-gtk.h>
 
 swfdec_player_get_type
 swfdec_audio_get_type
 swfdec_loader_get_type
+swfdec_gtk_loader_get_type
 swfdec_gtk_player_get_type
 swfdec_gtk_widget_get_type
 
diff --git a/libswfdec-gtk/swfdec_gtk_loader.c b/libswfdec-gtk/swfdec_gtk_loader.c
index 9267e86..643fb3e 100644
--- a/libswfdec-gtk/swfdec_gtk_loader.c
+++ b/libswfdec-gtk/swfdec_gtk_loader.c
@@ -23,6 +23,28 @@
 
 #include "swfdec_gtk_loader.h"
 
+/*** GTK-DOC ***/
+
+/**
+ * SECTION:SwfdecGtkLoader
+ * @title: SwfdecGtkLoader
+ * @short_description: advanced loader able to load network ressources
+ * @see_also: #SwfdecLoader
+ *
+ * #SwfdecGtkLoader is a #SwfdecLoader that is intended as an easy way to be 
+ * access ressources that are not stored in files, such as http. It can 
+ * however be compiled with varying support for different protocols, so don't
+ * rely on support for a particular protocol being available. If you need this,
+ * code your own SwfdecLoader subclass.
+ */
+
+/**
+ * SwfdecGtkLoader:
+ *
+ * This is the object used to represent a loader. Since it may use varying 
+ * backends, it is completely private.
+ */
+
 #ifndef HAVE_GNOMEVFS
 
 #include <libswfdec/swfdec_loader_internal.h>
diff-tree 7d592c21a8605361c3e63aca138f3e359cdbab50 (from parents)
Merge: a7488cbdfbdc0e33215e8e401c4199c143fa88d6 f516f0186bef8f00810f200034d63776bfab9271
Author: Benjamin Otte <otte at gnome.org>
Date:   Mon Apr 2 12:41:14 2007 +0200

    Merge branch 'master' of ssh://company@git.freedesktop.org/git/swfdec

diff-tree a7488cbdfbdc0e33215e8e401c4199c143fa88d6 (from a6d61c0101f96f031463545c96383b3ebfeafe63)
Author: Benjamin Otte <otte at gnome.org>
Date:   Mon Apr 2 12:36:58 2007 +0200

    Add a loader that loads other stuff than files (in particular http)
    
    It's currently using gnome-vfs but gnome-vfs somehow doesn't like to give me
    the file size. So I'll most likely switch to something else soon.

diff --git a/configure.ac b/configure.ac
index 65be1fc..aef0a9a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -204,6 +204,25 @@ else
 fi
 AM_CONDITIONAL(HAVE_FFMPEG, [test "x$HAVE_FFMPEG" = xyes])
 
+AC_ARG_ENABLE(gnome-vfs,
+	AS_HELP_STRING([--enable-gnome-vfs],
+			[enable gnome-vfs support for swfdec-gtk (default=yes)])],
+	enable_gnomevfs=$enableval,
+	enable_gnomevfs="yes")
+
+if test "$enable_gnomevfs" = "yes"; then
+	PKG_CHECK_MODULES(GNOMEVFS, gnome-vfs-2.0 >= 2.14.0, HAVE_GNOMEVFS=yes, HAVE_GNOMEVFS=no)
+	if test "x$HAVE_GNOMEVFS" = xyes; then
+	  AC_DEFINE(HAVE_GNOMEVFS, 1, [Define if gnome-vfs is enabled])
+	else
+	  AC_MSG_ERROR([Couldn't find gnome-vfs-2.0.])
+	fi
+else
+	AC_MSG_WARN([*** gnome-vfs support was not enabled. ***])
+fi
+AM_CONDITIONAL(HAVE_GNOMEVFS, [test "x$HAVE_GNOMEVFS" = xyes])
+
+AC_SUBST(GLOBAL_CFLAGS)
 AC_SUBST(GLOBAL_CFLAGS)
 
 SWFDEC_CFLAGS="-I\$(top_srcdir) $GLIB_CFLAGS"
diff --git a/libswfdec-gtk/Makefile.am b/libswfdec-gtk/Makefile.am
index eb16f88..b2dfb72 100644
--- a/libswfdec-gtk/Makefile.am
+++ b/libswfdec-gtk/Makefile.am
@@ -13,6 +13,7 @@ lib_LTLIBRARIES = libswfdec-gtk- at SWFDEC_
 libswfdec_gtk_ at SWFDEC_MAJORMINOR@_la_SOURCES = \
 	swfdec_playback.c \
 	swfdec_source.c \
+	swfdec_gtk_loader.c \
 	swfdec_gtk_player.c \
 	swfdec_gtk_widget.c
 
@@ -21,15 +22,16 @@ noinst_HEADERS = \
 	swfdec_source.h
 
 libswfdec_gtk_ at SWFDEC_MAJORMINOR@_la_CFLAGS = \
-	$(GLOBAL_CFLAGS) $(SWFDEC_CFLAGS) $(GTK_CFLAGS) $(AUDIO_CFLAGS) \
+	$(GLOBAL_CFLAGS) $(SWFDEC_CFLAGS) $(GTK_CFLAGS) $(AUDIO_CFLAGS) $(GNOMEVFS_CFLAGS) \
 	-DG_LOG_DOMAIN=\"Swfdec-Gtk\" -DXP_UNIX
 libswfdec_gtk_ at SWFDEC_MAJORMINOR@_la_LDFLAGS = \
 	-version-info $(SWFDEC_LIBVERSION) \
 	-export-symbols-regex '^(swfdec_.*)' \
-	$(GTK_LIBS) $(SWFDEC_LIBS) $(AUDIO_LIBS)
+	$(GTK_LIBS) $(SWFDEC_LIBS) $(AUDIO_LIBS) $(GNOMEVFS_LIBS)
 libswfdec_ at SWFDEC_MAJORMINOR@includedir = $(includedir)/swfdec- at SWFDEC_MAJORMINOR@/libswfdec-gtk
 libswfdec_ at SWFDEC_MAJORMINOR@include_HEADERS = \
 	swfdec-gtk.h \
+	swfdec_gtk_loader.h \
 	swfdec_gtk_player.h \
 	swfdec_gtk_widget.h
 
diff --git a/libswfdec-gtk/swfdec-gtk.h b/libswfdec-gtk/swfdec-gtk.h
index c9a0ac8..5615fa0 100644
--- a/libswfdec-gtk/swfdec-gtk.h
+++ b/libswfdec-gtk/swfdec-gtk.h
@@ -20,6 +20,7 @@
 #ifndef __SWFDEC_GTK_H__
 #define __SWFDEC_GTK_H__
 
+#include <libswfdec-gtk/swfdec_gtk_loader.h>
 #include <libswfdec-gtk/swfdec_gtk_player.h>
 #include <libswfdec-gtk/swfdec_gtk_widget.h>
 
diff --git a/libswfdec-gtk/swfdec_gtk_loader.c b/libswfdec-gtk/swfdec_gtk_loader.c
new file mode 100644
index 0000000..9267e86
--- /dev/null
+++ b/libswfdec-gtk/swfdec_gtk_loader.c
@@ -0,0 +1,215 @@
+/* Swfdec
+ * Copyright (C) 2006 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_gtk_loader.h"
+
+#ifndef HAVE_GNOMEVFS
+
+#include <libswfdec/swfdec_loader_internal.h>
+
+GType
+swfdec_gtk_loader_get_type (void)
+{
+  return SWFDEC_TYPE_FILE_LOADER;
+}
+
+SwfdecLoader *
+swfdec_gtk_loader_new (const char *uri)
+{
+  g_return_val_if_fail (uri != NULL, NULL);
+
+  return swfdec_loader_new_from_file (uri);
+}
+
+
+#else /* HAVE_GNOMEVFS */
+
+/* size of buffer we read */
+#define BUFFER_SIZE 4096
+
+#include <libgnomevfs/gnome-vfs.h>
+
+struct _SwfdecGtkLoader
+{
+  SwfdecLoader		loader;
+
+  GnomeVFSURI *		guri;		/* GnomeVFS URI used for resolving */
+  GnomeVFSAsyncHandle *	handle;		/* handle to file or NULL when done */
+  SwfdecBuffer *	current_buffer;	/* current buffer we're reading into */
+};
+
+struct _SwfdecGtkLoaderClass {
+  SwfdecLoaderClass	loader_class;
+};
+
+/*** SwfdecGtkLoader ***/
+
+G_DEFINE_TYPE (SwfdecGtkLoader, swfdec_gtk_loader, SWFDEC_TYPE_LOADER)
+
+static void swfdec_gtk_loader_start_read (SwfdecGtkLoader *gtk);
+static void
+swfdec_gtk_loader_read_cb (GnomeVFSAsyncHandle *handle, GnomeVFSResult result,
+    gpointer buffer, GnomeVFSFileSize bytes_requested, GnomeVFSFileSize bytes_read, 
+    gpointer loaderp)
+{
+  SwfdecGtkLoader *gtk = loaderp;
+  SwfdecLoader *loader = loaderp;
+
+  if (result == GNOME_VFS_ERROR_EOF) {
+    swfdec_loader_eof (loader);
+    swfdec_buffer_unref (gtk->current_buffer);
+    gtk->current_buffer = NULL;
+    gnome_vfs_async_cancel (gtk->handle);
+    gtk->handle = NULL;
+    return;
+  } else if (result != GNOME_VFS_OK) {
+    swfdec_loader_error (loader, gnome_vfs_result_to_string (result));
+    swfdec_buffer_unref (gtk->current_buffer);
+    gtk->current_buffer = NULL;
+    gnome_vfs_async_cancel (gtk->handle);
+    gtk->handle = NULL;
+    return;
+  }
+  if (bytes_read) {
+    gtk->current_buffer->length = bytes_read;
+    swfdec_loader_push (loader, gtk->current_buffer);
+  } else {
+    swfdec_buffer_unref (gtk->current_buffer);
+  }
+  gtk->current_buffer = NULL;
+  swfdec_gtk_loader_start_read (gtk);
+}
+
+static void
+swfdec_gtk_loader_start_read (SwfdecGtkLoader *gtk)
+{
+  g_assert (gtk->current_buffer == NULL);
+  g_assert (gtk->handle != NULL);
+
+  gtk->current_buffer = swfdec_buffer_new_and_alloc (BUFFER_SIZE);
+  gnome_vfs_async_read (gtk->handle, gtk->current_buffer->data,
+      gtk->current_buffer->length, swfdec_gtk_loader_read_cb, gtk);
+}
+
+static void
+swfdec_gtk_loader_open_cb (GnomeVFSAsyncHandle *handle, GnomeVFSResult result, 
+    gpointer loaderp)
+{
+  SwfdecGtkLoader *gtk = loaderp;
+  SwfdecLoader *loader = loaderp;
+
+  if (result != GNOME_VFS_OK) {
+    swfdec_loader_error (loader, gnome_vfs_result_to_string (result));
+    gnome_vfs_async_cancel (gtk->handle);
+    gtk->handle = NULL;
+    return;
+  }
+  swfdec_gtk_loader_start_read (gtk);
+}
+
+static SwfdecLoader *
+swfdec_gtk_loader_new_from_uri (GnomeVFSURI *uri)
+{
+  SwfdecGtkLoader *gtk;
+
+  g_assert (uri);
+  gtk = g_object_new (SWFDEC_TYPE_GTK_LOADER, NULL);
+  gtk->guri = uri;
+  gnome_vfs_async_open_uri (&gtk->handle, uri, GNOME_VFS_OPEN_READ, 
+      GNOME_VFS_PRIORITY_DEFAULT, swfdec_gtk_loader_open_cb, gtk);
+  SWFDEC_LOADER (gtk)->url = gnome_vfs_uri_to_string (uri, GNOME_VFS_URI_HIDE_PASSWORD);
+  return SWFDEC_LOADER (gtk);
+}
+
+static void
+swfdec_gtk_loader_dispose (GObject *object)
+{
+  SwfdecGtkLoader *gtk = SWFDEC_GTK_LOADER (object);
+
+  if (gtk->current_buffer) {
+    swfdec_buffer_unref (gtk->current_buffer);
+    gtk->current_buffer = NULL;
+  }
+  if (gtk->handle) {
+    gnome_vfs_async_cancel (gtk->handle);
+    gtk->handle = NULL;
+  }
+  if (gtk->guri) {
+    gnome_vfs_uri_unref (gtk->guri);
+    gtk->guri = NULL;
+  }
+
+  G_OBJECT_CLASS (swfdec_gtk_loader_parent_class)->dispose (object);
+}
+
+static SwfdecLoader *
+swfdec_gtk_loader_load (SwfdecLoader *loader, const char *url)
+{
+  SwfdecGtkLoader *gtk = SWFDEC_GTK_LOADER (loader);
+  GnomeVFSURI *parent, *new;
+
+  /* FIXME: security! */
+  parent = gnome_vfs_uri_get_parent (gtk->guri);
+  new = gnome_vfs_uri_resolve_relative (parent, url);
+  gnome_vfs_uri_unref (parent);
+  return swfdec_gtk_loader_new_from_uri (new);
+}
+
+static void
+swfdec_gtk_loader_class_init (SwfdecGtkLoaderClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  SwfdecLoaderClass *loader_class = SWFDEC_LOADER_CLASS (klass);
+
+  object_class->dispose = swfdec_gtk_loader_dispose;
+
+  loader_class->load = swfdec_gtk_loader_load;
+}
+
+static void
+swfdec_gtk_loader_init (SwfdecGtkLoader *gtk_loader)
+{
+}
+
+/**
+ * swfdec_gtk_loader_new:
+ * @uri: The location of the file to open
+ *
+ * Creates a new loader for the given URI using gnome-vfs (or using the local
+ * file backend, if compiled without gnome-vfs support).
+ *
+ * Returns: a new #SwfdecLoader using gnome-vfs.
+ **/
+SwfdecLoader *
+swfdec_gtk_loader_new (const char *uri)
+{
+  GnomeVFSURI *guri;
+
+  g_return_val_if_fail (uri != NULL, NULL);
+
+  gnome_vfs_init ();
+  guri = gnome_vfs_uri_new (uri);
+  return swfdec_gtk_loader_new_from_uri (guri);
+}
+
+#endif /* HAVE_GNOMEVFS */
diff --git a/libswfdec-gtk/swfdec_gtk_loader.h b/libswfdec-gtk/swfdec_gtk_loader.h
new file mode 100644
index 0000000..09a3558
--- /dev/null
+++ b/libswfdec-gtk/swfdec_gtk_loader.h
@@ -0,0 +1,44 @@
+/* Swfdec
+ * Copyright (C) 2006 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_GTK_LOADER_H_
+#define _SWFDEC_GTK_LOADER_H_
+
+#include <libswfdec/swfdec.h>
+
+G_BEGIN_DECLS
+
+
+typedef struct _SwfdecGtkLoader SwfdecGtkLoader;
+typedef struct _SwfdecGtkLoaderClass SwfdecGtkLoaderClass;
+
+#define SWFDEC_TYPE_GTK_LOADER                    (swfdec_gtk_loader_get_type())
+#define SWFDEC_IS_GTK_LOADER(obj)                 (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SWFDEC_TYPE_GTK_LOADER))
+#define SWFDEC_IS_GTK_LOADER_CLASS(klass)         (G_TYPE_CHECK_CLASS_TYPE ((klass), SWFDEC_TYPE_GTK_LOADER))
+#define SWFDEC_GTK_LOADER(obj)                    (G_TYPE_CHECK_INSTANCE_CAST ((obj), SWFDEC_TYPE_GTK_LOADER, SwfdecGtkLoader))
+#define SWFDEC_GTK_LOADER_CLASS(klass)            (G_TYPE_CHECK_CLASS_CAST ((klass), SWFDEC_TYPE_GTK_LOADER, SwfdecGtkLoaderClass))
+#define SWFDEC_GTK_LOADER_GET_CLASS(obj)          (G_TYPE_INSTANCE_GET_CLASS ((obj), SWFDEC_TYPE_GTK_LOADER, SwfdecGtkLoaderClass))
+
+GType		swfdec_gtk_loader_get_type   	(void);
+
+SwfdecLoader *	swfdec_gtk_loader_new	  	(const char *	uri);
+					 
+
+G_END_DECLS
+#endif
diff --git a/libswfdec-gtk/swfdec_gtk_player.c b/libswfdec-gtk/swfdec_gtk_player.c
index 58edd40..06a71c5 100644
--- a/libswfdec-gtk/swfdec_gtk_player.c
+++ b/libswfdec-gtk/swfdec_gtk_player.c
@@ -22,6 +22,7 @@
 #endif
 
 #include <libswfdec/swfdec_player_internal.h>
+#include "libswfdec-gtk/swfdec_gtk_loader.h"
 #include "libswfdec-gtk/swfdec_gtk_player.h"
 #include "libswfdec-gtk/swfdec_playback.h"
 #include "libswfdec-gtk/swfdec_source.h"
@@ -190,14 +191,14 @@ swfdec_gtk_player_new (void)
  * Returns: a new player.
  **/
 SwfdecPlayer *
-swfdec_gtk_player_new_from_file (const char *uri)
+swfdec_gtk_player_new_from_uri (const char *uri)
 {
   SwfdecLoader *loader;
   SwfdecPlayer *player;
 
   g_return_val_if_fail (uri != NULL, NULL);
 
-  loader = swfdec_loader_new_new_from_file (uri);
+  loader = swfdec_gtk_loader_new (uri);
   player = swfdec_gtk_player_new ();
   swfdec_player_set_loader (player, loader);
 
diff --git a/libswfdec-gtk/swfdec_gtk_player.h b/libswfdec-gtk/swfdec_gtk_player.h
index 50bce84..b040fe9 100644
--- a/libswfdec-gtk/swfdec_gtk_player.h
+++ b/libswfdec-gtk/swfdec_gtk_player.h
@@ -37,14 +37,16 @@ typedef struct _SwfdecGtkPlayerClass Swf
 GType 		swfdec_gtk_player_get_type    	(void);
 
 SwfdecPlayer *	swfdec_gtk_player_new	      	(void);
-SwfdecPlayer *	swfdec_gtk_player_new_from_file	(const char *		filename);
+SwfdecPlayer *	swfdec_gtk_player_new_from_uri	(const char *		uri);
 
 void		swfdec_gtk_player_set_playing 	(SwfdecGtkPlayer *	player,
 						 gboolean		playing);
 gboolean	swfdec_gtk_player_get_playing 	(SwfdecGtkPlayer *	player);
-void		swfdec_gtk_player_set_audio_enabled	(SwfdecGtkPlayer *	player,
+void		swfdec_gtk_player_set_audio_enabled	
+						(SwfdecGtkPlayer *	player,
 						 gboolean		enabled);
-gboolean	swfdec_gtk_player_get_audio_enabled 	(SwfdecGtkPlayer *	player);
+gboolean	swfdec_gtk_player_get_audio_enabled
+						(SwfdecGtkPlayer *	player);
 void		swfdec_gtk_player_set_speed	(SwfdecGtkPlayer *	player,
 						 double			speed);
 double		swfdec_gtk_player_get_speed 	(SwfdecGtkPlayer *	player);
diff-tree a6d61c0101f96f031463545c96383b3ebfeafe63 (from 493905baa1c07054276adb078f086e7ca4acc26b)
Author: Benjamin Otte <otte at gnome.org>
Date:   Mon Apr 2 12:04:05 2007 +0200

    Change the semantics of swfdec_loader_new_from_file
    
    This function will now always return a loader (no NULL with error anymore),
    but will set the loader's error property instead.

diff --git a/libswfdec-gtk/swfdec_gtk_player.c b/libswfdec-gtk/swfdec_gtk_player.c
index 766f92d..58edd40 100644
--- a/libswfdec-gtk/swfdec_gtk_player.c
+++ b/libswfdec-gtk/swfdec_gtk_player.c
@@ -177,27 +177,27 @@ swfdec_gtk_player_new (void)
 }
 
 /**
- * swfdec_gtk_player_new_from_file:
- * @filename: name of the file to play
- * @error: return location for error or %NULL
+ * swfdec_gtk_player_new_from_uri:
+ * @uri: URI to play
  *
- * Tries to create a player to play back the given file. If the file does not
- * exist or another error occurs, %NULL is returned.
+ * Create a player to play back the given URI. If compiled with gnome-vfs
+ * support, it will use gnome-vfs to resolve the given URI. Note that there
+ * is no way to figure out if the referenced URI really references a file that
+ * Swfdec can play back. If you need this, you should use #SwfdecGtkLoader
+ * directly and use its error property.
  * This function calls swfdec_init () for you if it wasn't called before.
  *
- * Returns: a new player or %NULL on error.
+ * Returns: a new player.
  **/
 SwfdecPlayer *
-swfdec_gtk_player_new_from_file (const char *filename, GError **error)
+swfdec_gtk_player_new_from_file (const char *uri)
 {
   SwfdecLoader *loader;
   SwfdecPlayer *player;
 
-  g_return_val_if_fail (filename != NULL, NULL);
+  g_return_val_if_fail (uri != NULL, NULL);
 
-  loader = swfdec_loader_new_from_file (filename, error);
-  if (loader == NULL)
-    return NULL;
+  loader = swfdec_loader_new_new_from_file (uri);
   player = swfdec_gtk_player_new ();
   swfdec_player_set_loader (player, loader);
 
diff --git a/libswfdec-gtk/swfdec_gtk_player.h b/libswfdec-gtk/swfdec_gtk_player.h
index 715259b..50bce84 100644
--- a/libswfdec-gtk/swfdec_gtk_player.h
+++ b/libswfdec-gtk/swfdec_gtk_player.h
@@ -37,8 +37,7 @@ typedef struct _SwfdecGtkPlayerClass Swf
 GType 		swfdec_gtk_player_get_type    	(void);
 
 SwfdecPlayer *	swfdec_gtk_player_new	      	(void);
-SwfdecPlayer *	swfdec_gtk_player_new_from_file	(const char *		filename,
-			      	      		 GError **		error);
+SwfdecPlayer *	swfdec_gtk_player_new_from_file	(const char *		filename);
 
 void		swfdec_gtk_player_set_playing 	(SwfdecGtkPlayer *	player,
 						 gboolean		playing);
diff --git a/libswfdec/swfdec_loader.c b/libswfdec/swfdec_loader.c
index 81d536c..35a74c7 100644
--- a/libswfdec/swfdec_loader.c
+++ b/libswfdec/swfdec_loader.c
@@ -181,28 +181,6 @@ swfdec_loader_init (SwfdecLoader *loader
 
 /*** SwfdecFileLoader ***/
 
-typedef struct _SwfdecFileLoader SwfdecFileLoader;
-typedef struct _SwfdecFileLoaderClass SwfdecFileLoaderClass;
-
-#define SWFDEC_TYPE_FILE_LOADER                    (swfdec_file_loader_get_type())
-#define SWFDEC_IS_FILE_LOADER(obj)                 (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SWFDEC_TYPE_FILE_LOADER))
-#define SWFDEC_IS_FILE_LOADER_CLASS(klass)         (G_TYPE_CHECK_CLASS_TYPE ((klass), SWFDEC_TYPE_FILE_LOADER))
-#define SWFDEC_FILE_LOADER(obj)                    (G_TYPE_CHECK_INSTANCE_CAST ((obj), SWFDEC_TYPE_FILE_LOADER, SwfdecFileLoader))
-#define SWFDEC_FILE_LOADER_CLASS(klass)            (G_TYPE_CHECK_CLASS_CAST ((klass), SWFDEC_TYPE_FILE_LOADER, SwfdecFileLoaderClass))
-#define SWFDEC_FILE_LOADER_GET_CLASS(obj)          (G_TYPE_INSTANCE_GET_CLASS ((obj), SWFDEC_TYPE_FILE_LOADER, SwfdecFileLoaderClass))
-
-struct _SwfdecFileLoader
-{
-  SwfdecLoader		loader;
-
-  char *		dir;		/* base directory for load operations */
-};
-
-struct _SwfdecFileLoaderClass
-{
-  SwfdecLoaderClass   	loader_class;
-};
-
 G_DEFINE_TYPE (SwfdecFileLoader, swfdec_file_loader, SWFDEC_TYPE_LOADER)
 
 static void
@@ -316,23 +294,22 @@ swfdec_loader_queue_parse (SwfdecLoader 
 /**
  * swfdec_loader_new_from_file:
  * @filename: name of the file to load
- * @error: return loacation for an error or NULL
  *
- * Creates a new loader for local files.
+ * Creates a new loader for local files. If an error occurred, the loader will
+ * be in error.
  *
- * Returns: a new loader on success or NULL on failure
+ * Returns: a new loader
  **/
 SwfdecLoader *
-swfdec_loader_new_from_file (const char *filename, GError ** error)
+swfdec_loader_new_from_file (const char *filename)
 {
   SwfdecBuffer *buf;
   SwfdecLoader *loader;
+  GError *error = NULL;
 
   g_return_val_if_fail (filename != NULL, NULL);
 
-  buf = swfdec_buffer_new_from_file (filename, error);
-  if (buf == NULL)
-    return NULL;
+  buf = swfdec_buffer_new_from_file (filename, &error);
 
   loader = g_object_new (SWFDEC_TYPE_FILE_LOADER, NULL);
   if (g_path_is_absolute (filename)) {
@@ -343,9 +320,14 @@ swfdec_loader_new_from_file (const char 
     g_free (cur);
   }
   SWFDEC_FILE_LOADER (loader)->dir = g_path_get_dirname (loader->url);
-  swfdec_loader_set_size (loader, buf->length);
-  swfdec_loader_push (loader, buf);
-  swfdec_loader_eof (loader);
+  if (buf == NULL) {
+    swfdec_loader_error (loader, error->message);
+    g_error_free (error);
+  } else {
+    swfdec_loader_set_size (loader, buf->length);
+    swfdec_loader_push (loader, buf);
+    swfdec_loader_eof (loader);
+  }
   return loader;
 }
 
diff --git a/libswfdec/swfdec_loader.h b/libswfdec/swfdec_loader.h
index 482c810..b64c9a4 100644
--- a/libswfdec/swfdec_loader.h
+++ b/libswfdec/swfdec_loader.h
@@ -68,8 +68,7 @@ struct _SwfdecLoaderClass
 
 GType		swfdec_loader_get_type		(void);
 
-SwfdecLoader *	swfdec_loader_new_from_file	(const char * 	filename,
-						 GError **	error);
+SwfdecLoader *	swfdec_loader_new_from_file	(const char *	 	filename);
 
 void		swfdec_loader_push		(SwfdecLoader *		loader,
 						 SwfdecBuffer *		buffer);
diff --git a/libswfdec/swfdec_loader_internal.h b/libswfdec/swfdec_loader_internal.h
index d47a1ed..303088a 100644
--- a/libswfdec/swfdec_loader_internal.h
+++ b/libswfdec/swfdec_loader_internal.h
@@ -25,6 +25,28 @@
 
 G_BEGIN_DECLS
 
+typedef struct _SwfdecFileLoader SwfdecFileLoader;
+typedef struct _SwfdecFileLoaderClass SwfdecFileLoaderClass;
+
+#define SWFDEC_TYPE_FILE_LOADER                    (swfdec_file_loader_get_type())
+#define SWFDEC_IS_FILE_LOADER(obj)                 (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SWFDEC_TYPE_FILE_LOADER))
+#define SWFDEC_IS_FILE_LOADER_CLASS(klass)         (G_TYPE_CHECK_CLASS_TYPE ((klass), SWFDEC_TYPE_FILE_LOADER))
+#define SWFDEC_FILE_LOADER(obj)                    (G_TYPE_CHECK_INSTANCE_CAST ((obj), SWFDEC_TYPE_FILE_LOADER, SwfdecFileLoader))
+#define SWFDEC_FILE_LOADER_CLASS(klass)            (G_TYPE_CHECK_CLASS_CAST ((klass), SWFDEC_TYPE_FILE_LOADER, SwfdecFileLoaderClass))
+#define SWFDEC_FILE_LOADER_GET_CLASS(obj)          (G_TYPE_INSTANCE_GET_CLASS ((obj), SWFDEC_TYPE_FILE_LOADER, SwfdecFileLoaderClass))
+
+struct _SwfdecFileLoader
+{
+  SwfdecLoader		loader;
+
+  char *		dir;		/* base directory for load operations */
+};
+
+struct _SwfdecFileLoaderClass
+{
+  SwfdecLoaderClass   	loader_class;
+};
+
 
 SwfdecLoader *		swfdec_loader_load		(SwfdecLoader *		loader,
 							 const char *		url);
diff --git a/libswfdec/swfdec_player.c b/libswfdec/swfdec_player.c
index b9bf7e9..f0c360d 100644
--- a/libswfdec/swfdec_player.c
+++ b/libswfdec/swfdec_player.c
@@ -1155,25 +1155,23 @@ swfdec_player_set_loader_with_variables 
 /**
  * swfdec_player_new_from_file:
  * @filename: name of the file to play
- * @error: return location for error or NULL
  *
- * Tries to create a player to play back the given file. If the file does not
- * exist or another error occurs, NULL is returned.
+ * Creates a player to play back the given file. If the file does not
+ * exist or another error occurs, the player will be in an error state and not
+ * be initialized.
  * This function calls swfdec_init () for you if it wasn't called before.
  *
- * Returns: a new player or NULL on error.
+ * Returns: a new player
  **/
 SwfdecPlayer *
-swfdec_player_new_from_file (const char *filename, GError **error)
+swfdec_player_new_from_file (const char *filename)
 {
   SwfdecLoader *loader;
   SwfdecPlayer *player;
 
   g_return_val_if_fail (filename != NULL, NULL);
 
-  loader = swfdec_loader_new_from_file (filename, error);
-  if (loader == NULL)
-    return NULL;
+  loader = swfdec_loader_new_from_file (filename);
   player = swfdec_player_new ();
   swfdec_player_set_loader (player, loader);
 
diff --git a/libswfdec/swfdec_player.h b/libswfdec/swfdec_player.h
index 0c6f70c..0bbf3d9 100644
--- a/libswfdec/swfdec_player.h
+++ b/libswfdec/swfdec_player.h
@@ -48,8 +48,7 @@ void		swfdec_init			(void);
 GType		swfdec_player_get_type		(void);
 
 SwfdecPlayer *	swfdec_player_new		(void);
-SwfdecPlayer *	swfdec_player_new_from_file	(const char *	filename,
-						 GError **	error);
+SwfdecPlayer *	swfdec_player_new_from_file	(const char *	filename);
 void		swfdec_player_set_loader	(SwfdecPlayer *	player,
 						 SwfdecLoader *	loader);
 void		swfdec_player_set_loader_with_variables 
diff --git a/player/swfdebug.c b/player/swfdebug.c
index af7f7dc..8b2e9f2 100644
--- a/player/swfdebug.c
+++ b/player/swfdebug.c
@@ -408,10 +408,10 @@ main (int argc, char *argv[])
     return 1;
   }
 
-  loader = swfdec_loader_new_from_file (argv[1], &error);
-  if (loader == NULL) {
-    g_printerr ("Couldn't open file \"%s\": %s\n", argv[1], error->message);
-    g_error_free (error);
+  loader = swfdec_loader_new_from_file (argv[1]);
+  if (loader->error) {
+    g_printerr ("Couldn't open file \"%s\": %s\n", argv[1], loader->error);
+    g_object_unref (loader);
     return 1;
   }
   player = swfdec_debugger_new ();
diff --git a/player/swfplay.c b/player/swfplay.c
index 81bbd3c..78c5c48 100644
--- a/player/swfplay.c
+++ b/player/swfplay.c
@@ -109,10 +109,10 @@ main (int argc, char *argv[])
     return 1;
   }
 
-  loader = swfdec_loader_new_from_file (argv[1], &error);
-  if (loader == NULL) {
-    g_printerr ("Couldn't open file \"%s\": %s\n", argv[1], error->message);
-    g_error_free (error);
+  loader = swfdec_gtk_loader_new (argv[1]);
+  if (loader->error) {
+    g_printerr ("Couldn't open file \"%s\": %s\n", argv[1], loader->error);
+    g_object_unref (loader);
     return 1;
   }
   player = swfdec_gtk_player_new ();
@@ -123,13 +123,6 @@ main (int argc, char *argv[])
     loader = swfdec_slow_loader_new (loader, delay);
 
   swfdec_player_set_loader_with_variables (player, loader, variables);
-  /* FIXME add smarter "not my file" detection */
-  if (!swfdec_player_is_initialized (player) && delay == 0) {
-    g_printerr ("File \"%s\" is not a file Swfdec can play\n", argv[1]);
-    g_object_unref (player);
-    player = NULL;
-    return 1;
-  }
 
   if (no_sound)
     swfdec_gtk_player_set_audio_enabled (SWFDEC_GTK_PLAYER (player), FALSE);
diff --git a/test/dump.c b/test/dump.c
index e248729..9c0475e 100644
--- a/test/dump.c
+++ b/test/dump.c
@@ -382,10 +382,10 @@ main (int argc, char *argv[])
 	fn = argv[1];
   }
 
-  player = swfdec_player_new_from_file (argv[1], &error);
-  if (player == NULL) {
-    g_printerr ("Couldn't open file \"%s\": %s\n", argv[1], error->message);
-    g_error_free (error);
+  player = swfdec_player_new_from_file (argv[1]);
+  if (player->loader->error) {
+    g_printerr ("Couldn't open file \"%s\": %s\n", argv[1], player->loader->error);
+    g_object_unref (player);
     return 1;
   }
   s = (SwfdecSwfDecoder *) SWFDEC_ROOT_MOVIE (player->roots->data)->decoder;
diff --git a/test/image/image.c b/test/image/image.c
index 29b96a3..4113304 100644
--- a/test/image/image.c
+++ b/test/image/image.c
@@ -155,16 +155,16 @@ run_test (const char *filename)
   SwfdecLoader *loader;
   SwfdecPlayer *player = NULL;
   guint i, msecs;
-  GError *error = NULL;
   int w, h;
   cairo_surface_t *surface;
   cairo_t *cr;
 
   g_print ("Testing %s:\n", filename);
 
-  loader = swfdec_loader_new_from_file (filename, &error);
-  if (loader == NULL) {
-    g_print ("  ERROR: %s\n", error->message);
+  loader = swfdec_loader_new_from_file (filename);
+  if (loader->error) {
+    g_print ("  ERROR: %s\n", loader->error);
+    g_object_unref (loader);
     goto error;
   }
   player = swfdec_player_new ();
@@ -193,8 +193,6 @@ run_test (const char *filename)
   return TRUE;
 
 error:
-  if (error)
-    g_error_free (error);
   if (player)
     g_object_unref (player);
   return FALSE;
diff --git a/test/parse.c b/test/parse.c
index d56c22c..6fa7234 100644
--- a/test/parse.c
+++ b/test/parse.c
@@ -30,7 +30,6 @@ main (int argc, char *argv[])
 {
   char *fn = "it.swf";
   SwfdecPlayer *player;
-  GError *error = NULL;
 
   swfdec_init ();
 
@@ -38,13 +37,8 @@ main (int argc, char *argv[])
 	fn = argv[1];
   }
 
-  player = swfdec_player_new_from_file (argv[1], &error);
-  if (player == NULL) {
-    g_printerr ("Couldn't open file \"%s\": %s\n", argv[1], error->message);
-    g_error_free (error);
-    return 1;
-  }
-  if (swfdec_player_get_rate (player) == 0) {
+  player = swfdec_player_new_from_file (argv[1]);
+  if (!swfdec_player_is_initialized (player)) {
     g_printerr ("Error parsing file \"%s\"\n", argv[1]);
     g_object_unref (player);
     player = NULL;
diff --git a/test/sound/sound.c b/test/sound/sound.c
index f42149f..4cf348a 100644
--- a/test/sound/sound.c
+++ b/test/sound/sound.c
@@ -184,6 +184,7 @@ run_test (const char *filename)
   dir = g_dir_open (dirname, 0, &error);
   if (!dir) {
     g_print ("  ERROR: %s\n", error->message);
+    g_error_free (error);
     return FALSE;
   }
   while ((name = g_dir_read_name (dir))) {
@@ -195,9 +196,10 @@ run_test (const char *filename)
   }
   g_dir_close (dir);
 
-  loader = swfdec_loader_new_from_file (filename, &error);
-  if (loader == NULL) {
-    g_print ("  ERROR: %s\n", error->message);
+  loader = swfdec_loader_new_from_file (filename);
+  if (loader->error) {
+    g_print ("  ERROR: %s\n", loader->error);
+    g_object_unref (loader);
     goto error;
   }
   player = swfdec_player_new ();
@@ -233,8 +235,6 @@ run_test (const char *filename)
   }
 
 error:
-  if (error)
-    g_error_free (error);
   if (player)
     g_object_unref (player);
   g_list_foreach (data.files, (GFunc) g_free, NULL);
diff --git a/test/swfdec-extract.c b/test/swfdec-extract.c
index da0964b..5ac1f8b 100644
--- a/test/swfdec-extract.c
+++ b/test/swfdec-extract.c
@@ -229,7 +229,6 @@ main (int argc, char *argv[])
   SwfdecCharacter *character;
   int ret = 0;
   SwfdecPlayer *player;
-  GError *error = NULL;
   glong id;
 
   swfdec_init ();
@@ -239,13 +238,8 @@ main (int argc, char *argv[])
     return 0;
   }
 
-  player = swfdec_player_new_from_file (argv[1], &error);
-  if (player == NULL) {
-    g_printerr ("Couldn't open file \"%s\": %s\n", argv[1], error->message);
-    g_error_free (error);
-    return 1;
-  }
-  if (swfdec_player_get_rate (player) == 0) {
+  player = swfdec_player_new_from_file (argv[1]);
+  if (!SWFDEC_IS_ROOT_MOVIE (player->roots->data)) {
     g_printerr ("Error parsing file \"%s\"\n", argv[1]);
     g_object_unref (player);
     player = NULL;
diff --git a/test/trace/trace.c b/test/trace/trace.c
index 9a5a841..2c7ced7 100644
--- a/test/trace/trace.c
+++ b/test/trace/trace.c
@@ -18,14 +18,14 @@ run_test (const char *filename)
   SwfdecPlayer *player;
   SwfdecBuffer *buffer;
   guint time_left;
-  GError *error = NULL;
   char *str;
   GString *string;
+  GError *error = NULL;
 
   g_print ("Testing %s:\n", filename);
-  loader = swfdec_loader_new_from_file (filename, &error);
-  if (loader == NULL) {
-    g_print ("  ERROR: %s\n", error->message);
+  loader = swfdec_loader_new_from_file (filename);
+  if (loader->error) {
+    g_print ("  ERROR: %s\n", loader->error);
     return FALSE;
   }
   string = g_string_new ("");
@@ -69,6 +69,7 @@ run_test (const char *filename)
       if (!g_spawn_sync (NULL, command, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL,
 	  NULL, NULL, NULL, &error)) {
 	g_printerr ("  Couldn't spawn diff to compare the results: %s\n", error->message);
+	g_error_free (error);
       }
     }
     g_string_free (string, TRUE);


More information about the Swfdec mailing list