[Swfdec] libswfdec/swfdec_loader.c libswfdec/swfdec_loader.h libswfdec/swfdec_loader_internal.h libswfdec/swfdec_net_stream.c libswfdec/swfdec_root_movie.c libswfdec/swfdec_xml.c

Benjamin Otte company at kemper.freedesktop.org
Fri Mar 16 08:40:26 PDT 2007


 libswfdec/swfdec_loader.c          |   91 +++++++++++++++++++++++++++++++++++--
 libswfdec/swfdec_loader.h          |   13 +++++
 libswfdec/swfdec_loader_internal.h |    2 
 libswfdec/swfdec_net_stream.c      |    1 
 libswfdec/swfdec_root_movie.c      |    4 +
 libswfdec/swfdec_xml.c             |    9 +--
 6 files changed, 111 insertions(+), 9 deletions(-)

New commits:
diff-tree 0c7b304d2eb371c85616808e083f353e174bf263 (from 13a4101ff86efb11f43e4b28778f1d90a320b118)
Author: Benjamin Otte <otte at gnome.org>
Date:   Fri Mar 16 16:35:10 2007 +0100

    add the concept of data types so we can identify what we load
    
    Every loader now has an associated SwfdecLoaderDataType that's supposed
    to tell what the data is used for. New functions for using it were added.
    Includes an update to swfdec_loader_get_filename() that automatically adds
    the correct extension.

diff --git a/libswfdec/swfdec_loader.c b/libswfdec/swfdec_loader.c
index 4334562..8cd432c 100644
--- a/libswfdec/swfdec_loader.c
+++ b/libswfdec/swfdec_loader.c
@@ -59,7 +59,8 @@
 enum {
   PROP_0,
   PROP_ERROR,
-  PROP_EOF
+  PROP_EOF,
+  PROP_DATA_TYPE
 };
 
 G_DEFINE_ABSTRACT_TYPE (SwfdecLoader, swfdec_loader, G_TYPE_OBJECT)
@@ -77,6 +78,9 @@ swfdec_loader_get_property (GObject *obj
     case PROP_EOF:
       g_value_set_boolean (value, loader->eof);
       break;
+    case PROP_DATA_TYPE:
+      g_value_set_enum (value, loader->data_type);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
       break;
@@ -130,12 +134,16 @@ swfdec_loader_class_init (SwfdecLoaderCl
   g_object_class_install_property (object_class, PROP_EOF,
       g_param_spec_boolean ("eof", "eof", "TRUE when all data has been handed to the loader",
 	  FALSE, G_PARAM_READABLE));
+  g_object_class_install_property (object_class, PROP_DATA_TYPE,
+      g_param_spec_enum ("data-type", "data type", "the data's type as identified by Swfdec",
+	  SWFDEC_TYPE_LOADER_DATA_TYPE, SWFDEC_LOADER_DATA_UNKNOWN, G_PARAM_READABLE));
 }
 
 static void
 swfdec_loader_init (SwfdecLoader *loader)
 {
   loader->queue = swfdec_buffer_queue_new ();
+  loader->data_type = SWFDEC_LOADER_DATA_UNKNOWN;
 }
 
 /*** SwfdecFileLoader ***/
@@ -439,12 +447,89 @@ swfdec_loader_get_filename (SwfdecLoader
     }
   }
   ret = g_filename_from_utf8 (start, end ? end - start : -1, NULL, NULL, NULL);
-  if (ret == NULL)
-    ret = g_strdup ("unknown.swf");
+  if (ret) {
+    char *dot;
+    const char *ext;
+    
+    ext = swfdec_loader_data_type_get_extension (loader->data_type);
+    if (*ext && (dot = strrchr (ret, '.'))) {
+      char *real;
+      guint len = strlen (dot);
+      if (len <= 5) {
+	real = g_strdup_printf ("%*s.%s", dot - ret, ret, ext);
+      } else {
+	real = g_strdup_printf ("%s.%s", ret, ext);
+      }
+      g_free (ret);
+      ret = real;
+    }
+  } else {
+    ret = g_strdup ("unknown file");
+  }
 
   return ret;
 }
 
+/**
+ * swfdec_loader_get_data_type:
+ * @loader: a #SwfdecLoader
+ *
+ * Queries the type of data this loader provides. The type is determined 
+ * automatically by Swfdec.
+ *
+ * Returns: the type this data was identified to be in or 
+ *          #SWFDEC_LOADER_DATA_UNKNOWN if not identified
+ **/
+SwfdecLoaderDataType
+swfdec_loader_get_data_type (SwfdecLoader *loader)
+{
+  g_return_val_if_fail (SWFDEC_IS_LOADER (loader), SWFDEC_LOADER_DATA_UNKNOWN);
+
+  return loader->data_type;
+}
+
+void
+swfdec_loader_set_data_type (SwfdecLoader *loader, SwfdecLoaderDataType	type)
+{
+  g_return_if_fail (SWFDEC_IS_LOADER (loader));
+  g_return_if_fail (loader->data_type == SWFDEC_LOADER_DATA_UNKNOWN);
+  g_return_if_fail (type != SWFDEC_LOADER_DATA_UNKNOWN);
+
+  loader->data_type = type;
+  g_object_notify (G_OBJECT (loader), "data-type");
+}
+
+/**
+ * swfdec_loader_data_type_get_extension:
+ * @type: a #SwfdecLoaderDataType
+ *
+ * Queries the extension to be used for data of the given @type.
+ *
+ * Returns: the typical extension for this data type or the empty string
+ *          if the type has no extension
+ **/
+const char *
+swfdec_loader_data_type_get_extension (SwfdecLoaderDataType type)
+{
+  switch (type) {
+    case SWFDEC_LOADER_DATA_UNKNOWN:
+      return "";
+    case SWFDEC_LOADER_DATA_SWF:
+      return "swf";
+    case SWFDEC_LOADER_DATA_FLV:
+      return "flv";
+    case SWFDEC_LOADER_DATA_XML:
+      return "xml";
+    case SWFDEC_LOADER_DATA_TEXT:
+      return "txt";
+    default:
+      g_warning ("unknown data type %u", type);
+      return "";
+  }
+}
+
+/*** X-WWW-FORM-URLENCODED ***/
+
 /* if speed ever gets an issue, use a 256 byte array instead of strchr */
 static const char *urlencode_unescaped="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_.:/";
 static void
diff --git a/libswfdec/swfdec_loader.h b/libswfdec/swfdec_loader.h
index c6bc678..fc4983c 100644
--- a/libswfdec/swfdec_loader.h
+++ b/libswfdec/swfdec_loader.h
@@ -25,6 +25,13 @@
 
 G_BEGIN_DECLS
 
+typedef enum {
+  SWFDEC_LOADER_DATA_UNKNOWN,
+  SWFDEC_LOADER_DATA_SWF,
+  SWFDEC_LOADER_DATA_FLV,
+  SWFDEC_LOADER_DATA_XML,
+  SWFDEC_LOADER_DATA_TEXT
+} SwfdecLoaderDataType;
 
 typedef struct _SwfdecLoader SwfdecLoader;
 typedef struct _SwfdecLoaderClass SwfdecLoaderClass;
@@ -46,6 +53,7 @@ struct _SwfdecLoader
   char *		error;		/* if there's an error (from parsing the loader) */
   gpointer		target;		/* SwfdecLoaderTarget that gets notified about loading progress */
   SwfdecBufferQueue *	queue;		/* SwfdecBufferQueue managing the input buffers */
+  SwfdecLoaderDataType	data_type;	/* type this stream is in (identified by swfdec) */
 };
 
 struct _SwfdecLoaderClass
@@ -68,6 +76,11 @@ void		swfdec_loader_eof		(SwfdecLoader *
 void		swfdec_loader_error		(SwfdecLoader *		loader,
 						 const char *		error);
 char *  	swfdec_loader_get_filename	(SwfdecLoader *		loader);
+SwfdecLoaderDataType
+		swfdec_loader_get_data_type	(SwfdecLoader *		loader);
+
+const char *	swfdec_loader_data_type_get_extension
+						(SwfdecLoaderDataType	type);
 					 
 
 G_END_DECLS
diff --git a/libswfdec/swfdec_loader_internal.h b/libswfdec/swfdec_loader_internal.h
index 7d5aaef..d47a1ed 100644
--- a/libswfdec/swfdec_loader_internal.h
+++ b/libswfdec/swfdec_loader_internal.h
@@ -32,6 +32,8 @@ void			swfdec_loader_parse		(SwfdecLoade
 void			swfdec_loader_queue_parse	(SwfdecLoader *		loader);
 void			swfdec_loader_set_target	(SwfdecLoader *		loader,
 							 SwfdecLoaderTarget *	target);
+void			swfdec_loader_set_data_type	(SwfdecLoader *		loader,
+							 SwfdecLoaderDataType	type);
 void	  		swfdec_loader_error_locked	(SwfdecLoader *		loader,
 							 const char *		error);
 
diff --git a/libswfdec/swfdec_net_stream.c b/libswfdec/swfdec_net_stream.c
index 8840d78..1e69ac3 100644
--- a/libswfdec/swfdec_net_stream.c
+++ b/libswfdec/swfdec_net_stream.c
@@ -200,6 +200,7 @@ swfdec_net_stream_loader_target_parse (S
     SWFDEC_DECODER (stream->flvdecoder)->player = stream->player;
     SWFDEC_DECODER (stream->flvdecoder)->queue = loader->queue;
     swfdec_net_stream_onstatus (stream, "NetStream.Play.Start", "status");
+    swfdec_loader_set_data_type (loader, SWFDEC_LOADER_DATA_FLV);
   }
   klass = SWFDEC_DECODER_GET_CLASS (stream->flvdecoder);
   g_return_if_fail (klass->parse);
diff --git a/libswfdec/swfdec_root_movie.c b/libswfdec/swfdec_root_movie.c
index 6396f3d..d644b44 100644
--- a/libswfdec/swfdec_root_movie.c
+++ b/libswfdec/swfdec_root_movie.c
@@ -60,10 +60,14 @@ static gboolean
 swfdec_root_movie_loader_target_set_decoder (SwfdecLoaderTarget *target,
     SwfdecDecoder *decoder)
 {
+  SwfdecRootMovie *movie = SWFDEC_ROOT_MOVIE (target);
+
   if (SWFDEC_IS_FLV_DECODER (decoder)) {
+    swfdec_loader_set_data_type (movie->loader, SWFDEC_LOADER_DATA_FLV);
     swfdec_flv_decoder_add_movie (SWFDEC_FLV_DECODER (decoder), 
 	SWFDEC_MOVIE (target));
   } else if (SWFDEC_IS_SWF_DECODER (decoder)) {
+    swfdec_loader_set_data_type (movie->loader, SWFDEC_LOADER_DATA_SWF);
     SWFDEC_ROOT_MOVIE (target)->decoder = decoder;
   } else {
     g_object_unref (decoder);
diff --git a/libswfdec/swfdec_xml.c b/libswfdec/swfdec_xml.c
index 675e532..366bf60 100644
--- a/libswfdec/swfdec_xml.c
+++ b/libswfdec/swfdec_xml.c
@@ -80,6 +80,7 @@ swfdec_xml_loader_target_parse (SwfdecLo
   } else {
     guint size;
     g_assert (loader->eof);
+    swfdec_loader_set_data_type (loader, SWFDEC_LOADER_DATA_TEXT);
     size = swfdec_buffer_queue_get_depth (loader->queue);
     xml->text = g_try_malloc (size + 1);
     if (xml->text) {
@@ -184,10 +185,6 @@ swfdec_xml_load (SwfdecXml *xml, const c
 
   swfdec_xml_reset (xml);
   xml->loader = swfdec_player_load (xml->player, url);
-  if (xml->loader == NULL) {
-    swfdec_xml_ondata (xml);
-  } else {
-    swfdec_loader_set_target (xml->loader, SWFDEC_LOADER_TARGET (xml));
-    swfdec_loader_queue_parse (xml->loader);
-  }
+  swfdec_loader_set_target (xml->loader, SWFDEC_LOADER_TARGET (xml));
+  swfdec_loader_queue_parse (xml->loader);
 }


More information about the Swfdec mailing list