[rygel-gst-0-10-plugins] Cleanup RygelMediaExportMetadataExtractor.



commit ae00a1018acb1813df4b2fcbc6a66d512e1c7c2b
Author: Krzesimir Nowak <krnowak openismus com>
Date:   Wed Jan 30 15:07:19 2013 +0100

    Cleanup RygelMediaExportMetadataExtractor.

 .../rygel-media-export-metadata-extractor.c        |  607 ++++++++------------
 src/media-export/rygel-media-export-plugin.c       |    1 -
 src/media-export/rygel-media-export-plugin.h       |    2 +
 3 files changed, 255 insertions(+), 355 deletions(-)
---
diff --git a/src/media-export/rygel-media-export-metadata-extractor.c b/src/media-export/rygel-media-export-metadata-extractor.c
index ff0be71..d0bad24 100644
--- a/src/media-export/rygel-media-export-metadata-extractor.c
+++ b/src/media-export/rygel-media-export-metadata-extractor.c
@@ -1,6 +1,3 @@
-/* rygel-media-export-metadata-extractor.c generated by valac 0.18.1, the Vala compiler
- * generated from rygel-media-export-metadata-extractor.vala, do not modify */
-
 /*
  * Copyright (C) 2008 Zeeshan Ali (Khattak) <zeeshanak gnome org>.
  * Copyright (C) 2009 Jens Georg <mail jensge org>.
@@ -30,389 +27,291 @@
 #include <libgupnp-dlna/gupnp-dlna-information.h>
 #include <gst/pbutils/pbutils.h>
 #include <glib/gi18n-lib.h>
+#include "rygel-media-export-plugin.h"
 
 G_DEFINE_TYPE (RygelMediaExportMetadataExtractor, rygel_media_export_metadata_extractor, G_TYPE_OBJECT)
 
 struct _RygelMediaExportMetadataExtractorPrivate {
-	GUPnPDLNADiscoverer* discoverer;
-	GeeHashMap* file_hash;
-	guint64 timeout;
-	gboolean extract_metadata;
+  GUPnPDLNADiscoverer *discoverer;
+  GeeHashMap *file_hash;
+  gboolean extract_metadata;
 };
 
-#define RYGEL_MEDIA_EXPORT_METADATA_EXTRACTOR_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), RYGEL_MEDIA_EXPORT_TYPE_METADATA_EXTRACTOR, RygelMediaExportMetadataExtractorPrivate))
-
-static void rygel_media_export_metadata_extractor_on_done (RygelMediaExportMetadataExtractor* self, GUPnPDLNAInformation* dlna, GError* err);
-static void _rygel_media_export_metadata_extractor_on_done_gupnp_dlna_discoverer_done (GUPnPDLNADiscoverer* _sender, GUPnPDLNAInformation* dlna, GError* err, gpointer self);
-static void rygel_media_export_metadata_extractor_extract_basic_information (RygelMediaExportMetadataExtractor* self, GFile* file, GUPnPDLNAInformation* dlna);
-static void g_cclosure_user_marshal_VOID__OBJECT_OBJECT_OBJECT (GClosure * closure, GValue * return_value, guint n_param_values, const GValue * param_values, gpointer invocation_hint, gpointer marshal_data);
-static void g_cclosure_user_marshal_VOID__OBJECT_POINTER (GClosure * closure, GValue * return_value, guint n_param_values, const GValue * param_values, gpointer invocation_hint, gpointer marshal_data);
-static void rygel_media_export_metadata_extractor_finalize (GObject* obj);
-
-
-RygelMediaExportMetadataExtractor* rygel_media_export_metadata_extractor_construct (GType object_type) {
-	RygelMediaExportMetadataExtractor * self = NULL;
-	GeeHashMap* _tmp0_;
-	RygelMetaConfig* _tmp1_ = NULL;
-	RygelMetaConfig* config;
-	gboolean _tmp4_;
-	GError * _inner_error_ = NULL;
-	self = (RygelMediaExportMetadataExtractor*) g_object_new (object_type, NULL);
-	_tmp0_ = gee_hash_map_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, g_free, G_TYPE_FILE, (GBoxedCopyFunc) g_object_ref, g_object_unref, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
-	g_object_unref (self->priv->file_hash);
-	self->priv->file_hash = _tmp0_;
-	_tmp1_ = rygel_meta_config_get_default ();
-	config = _tmp1_;
-	{
-		gboolean _tmp2_ = FALSE;
-		gboolean _tmp3_;
-		_tmp2_ = rygel_configuration_get_bool ((RygelConfiguration*) config, "MediaExport", "extract-metadata", &_inner_error_);
-		_tmp3_ = _tmp2_;
-		if (_inner_error_ != NULL) {
-			goto __catch22_g_error;
-		}
-		self->priv->extract_metadata = _tmp3_;
-	}
-	goto __finally22;
-	__catch22_g_error:
-	{
-		GError* _error_ = NULL;
-		_error_ = _inner_error_;
-		_inner_error_ = NULL;
-		self->priv->extract_metadata = TRUE;
-		g_error_free (_error_);
-	}
-	__finally22:
-	if (_inner_error_ != NULL) {
-		g_object_unref (config);
-		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
-		g_clear_error (&_inner_error_);
-		return NULL;
-	}
-	_tmp4_ = self->priv->extract_metadata;
-	if (_tmp4_) {
-	}
-	g_object_unref (config);
-	return self;
-}
+enum {
+  EXTRACTION_DONE,
+  ERROR,
 
+  SIGNALS_COUNT
+};
 
-RygelMediaExportMetadataExtractor* rygel_media_export_metadata_extractor_new (void) {
-	return rygel_media_export_metadata_extractor_construct (RYGEL_MEDIA_EXPORT_TYPE_METADATA_EXTRACTOR);
-}
+static guint signals [SIGNALS_COUNT];
 
+#define RYGEL_MEDIA_EXPORT_METADATA_EXTRACTOR_GET_PRIVATE(o) \
+  (G_TYPE_INSTANCE_GET_PRIVATE ((o), \
+				RYGEL_MEDIA_EXPORT_TYPE_METADATA_EXTRACTOR, \
+				RygelMediaExportMetadataExtractorPrivate))
 
-static void _rygel_media_export_metadata_extractor_on_done_gupnp_dlna_discoverer_done (GUPnPDLNADiscoverer* _sender G_GNUC_UNUSED, GUPnPDLNAInformation* dlna, GError* err, gpointer self) {
-	rygel_media_export_metadata_extractor_on_done (self, dlna, err);
-}
+#define EXTRACTOR_OPTION "extract-metadata"
+#define EXTRACTOR_TIMEOUT G_GUINT64_CONSTANT(10)
 
+static void
+on_config_changed (RygelConfiguration *config,
+		   const gchar *section,
+		   const gchar *key,
+		   gpointer user_data) {
+  RygelMediaExportMetadataExtractor *self;
+  GError *error;
+  gboolean option;
 
-void rygel_media_export_metadata_extractor_extract (RygelMediaExportMetadataExtractor* self, GFile* file) {
-	gboolean _tmp0_;
-	g_return_if_fail (self != NULL);
-	g_return_if_fail (file != NULL);
-	_tmp0_ = self->priv->extract_metadata;
-	if (_tmp0_) {
-		GFile* _tmp1_;
-		gchar* _tmp2_ = NULL;
-		gchar* uri;
-		GeeHashMap* _tmp3_;
-		const gchar* _tmp4_;
-		GFile* _tmp5_;
-		guint64 _tmp6_;
-		GstClockTime gst_timeout;
-		GstClockTime _tmp7_;
-		GUPnPDLNADiscoverer* _tmp8_;
-		GUPnPDLNADiscoverer* _tmp9_;
-		GUPnPDLNADiscoverer* _tmp10_;
-		GUPnPDLNADiscoverer* _tmp11_;
-		const gchar* _tmp12_;
-		_tmp1_ = file;
-		_tmp2_ = g_file_get_uri (_tmp1_);
-		uri = _tmp2_;
-		_tmp3_ = self->priv->file_hash;
-		_tmp4_ = uri;
-		_tmp5_ = file;
-		gee_abstract_map_set ((GeeAbstractMap*) _tmp3_, _tmp4_, _tmp5_);
-		_tmp6_ = self->priv->timeout;
-		gst_timeout = (GstClockTime) (_tmp6_ * GST_SECOND);
-		_tmp7_ = gst_timeout;
-		_tmp8_ = gupnp_dlna_discoverer_new (_tmp7_, TRUE, TRUE);
-		g_object_unref (self->priv->discoverer);
-		self->priv->discoverer = _tmp8_;
-		_tmp9_ = self->priv->discoverer;
-		g_signal_connect_object (_tmp9_, "done", (GCallback) _rygel_media_export_metadata_extractor_on_done_gupnp_dlna_discoverer_done, self, 0);
-		_tmp10_ = self->priv->discoverer;
-		gst_discoverer_start ((GstDiscoverer*) _tmp10_);
-		_tmp11_ = self->priv->discoverer;
-		_tmp12_ = uri;
-		gupnp_dlna_discoverer_discover_uri (_tmp11_, _tmp12_);
-		g_free (uri);
-	} else {
-		GFile* _tmp13_;
-		_tmp13_ = file;
-		rygel_media_export_metadata_extractor_extract_basic_information (self, _tmp13_, NULL);
-	}
-}
+  if (g_strcmp0 (section, RYGEL_MEDIA_EXPORT_PLUGIN_NAME) || g_strcmp0 (key, EXTRACTOR_OPTION)) {
+    return;
+  }
 
+  self = RYGEL_MEDIA_EXPORT_METADATA_EXTRACTOR (user_data);
+  error = NULL;
+  option = rygel_configuration_get_bool (config, RYGEL_MEDIA_EXPORT_PLUGIN_NAME, EXTRACTOR_OPTION, &error);
 
-static void rygel_media_export_metadata_extractor_on_done (RygelMediaExportMetadataExtractor* self, GUPnPDLNAInformation* dlna, GError* err) {
-	GUPnPDLNADiscoverer* _tmp0_;
-	guint _tmp1_ = 0U;
-	GeeHashMap* _tmp2_;
-	GUPnPDLNAInformation* _tmp3_;
-	const GstDiscovererInfo* _tmp4_;
-	const GstDiscovererInfo* _tmp5_;
-	const gchar* _tmp6_ = NULL;
-	gpointer _tmp7_ = NULL;
-	GFile* file;
-	GFile* _tmp8_;
-	GeeHashMap* _tmp13_;
-	GUPnPDLNAInformation* _tmp14_;
-	const GstDiscovererInfo* _tmp15_;
-	const GstDiscovererInfo* _tmp16_;
-	const gchar* _tmp17_ = NULL;
-	GUPnPDLNAInformation* _tmp18_;
-	const GstDiscovererInfo* _tmp19_;
-	const GstDiscovererInfo* _tmp20_;
-	GstDiscovererResult _tmp21_ = 0;
-	GFile* _tmp31_;
-	GUPnPDLNAInformation* _tmp32_;
-	g_return_if_fail (self != NULL);
-	g_return_if_fail (dlna != NULL);
-	_tmp0_ = self->priv->discoverer;
-	g_signal_parse_name ("done", GUPNP_TYPE_DLNA_DISCOVERER, &_tmp1_, NULL, FALSE);
-	g_signal_handlers_disconnect_matched (_tmp0_, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp1_, 0, NULL, (GCallback) _rygel_media_export_metadata_extractor_on_done_gupnp_dlna_discoverer_done, self);
-	g_object_unref (self->priv->discoverer);
-	self->priv->discoverer = NULL;
-	_tmp2_ = self->priv->file_hash;
-	_tmp3_ = dlna;
-	_tmp4_ = gupnp_dlna_information_get_info (_tmp3_);
-	_tmp5_ = _tmp4_;
-	_tmp6_ = gst_discoverer_info_get_uri (_tmp5_);
-	_tmp7_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp2_, _tmp6_);
-	file = (GFile*) _tmp7_;
-	_tmp8_ = file;
-	if (_tmp8_ == NULL) {
-		GUPnPDLNAInformation* _tmp9_;
-		const GstDiscovererInfo* _tmp10_;
-		const GstDiscovererInfo* _tmp11_;
-		const gchar* _tmp12_ = NULL;
-		_tmp9_ = dlna;
-		_tmp10_ = gupnp_dlna_information_get_info (_tmp9_);
-		_tmp11_ = _tmp10_;
-		_tmp12_ = gst_discoverer_info_get_uri (_tmp11_);
-		g_warning ("rygel-media-export-metadata-extractor.vala:96: File %s already handled" \
-", ignoring event", _tmp12_);
-		g_object_unref (file);
-		return;
-	}
-	_tmp13_ = self->priv->file_hash;
-	_tmp14_ = dlna;
-	_tmp15_ = gupnp_dlna_information_get_info (_tmp14_);
-	_tmp16_ = _tmp15_;
-	_tmp17_ = gst_discoverer_info_get_uri (_tmp16_);
-	gee_abstract_map_unset ((GeeAbstractMap*) _tmp13_, _tmp17_, NULL);
-	_tmp18_ = dlna;
-	_tmp19_ = gupnp_dlna_information_get_info (_tmp18_);
-	_tmp20_ = _tmp19_;
-	_tmp21_ = gst_discoverer_info_get_result (_tmp20_);
-	if ((_tmp21_ & GST_DISCOVERER_TIMEOUT) != 0) {
-		GFile* _tmp22_;
-		gchar* _tmp23_ = NULL;
-		gchar* _tmp24_;
-		_tmp22_ = file;
-		_tmp23_ = g_file_get_uri (_tmp22_);
-		_tmp24_ = _tmp23_;
-		g_debug ("rygel-media-export-metadata-extractor.vala:105: Extraction timed out o" \
-"n %s", _tmp24_);
-		g_free (_tmp24_);
-		dlna = NULL;
-	} else {
-		GUPnPDLNAInformation* _tmp25_;
-		const GstDiscovererInfo* _tmp26_;
-		const GstDiscovererInfo* _tmp27_;
-		GstDiscovererResult _tmp28_ = 0;
-		_tmp25_ = dlna;
-		_tmp26_ = gupnp_dlna_information_get_info (_tmp25_);
-		_tmp27_ = _tmp26_;
-		_tmp28_ = gst_discoverer_info_get_result (_tmp27_);
-		if ((_tmp28_ & GST_DISCOVERER_ERROR) != 0) {
-			GFile* _tmp29_;
-			GError* _tmp30_;
-			_tmp29_ = file;
-			_tmp30_ = err;
-			g_signal_emit_by_name (self, "error", _tmp29_, _tmp30_);
-			g_object_unref (file);
-			return;
-		}
-	}
-	_tmp31_ = file;
-	_tmp32_ = dlna;
-	rygel_media_export_metadata_extractor_extract_basic_information (self, _tmp31_, _tmp32_);
-	g_object_unref (file);
+  if (error) {
+    option = TRUE;
+    g_error_free (error);
+  }
+  self->priv->extract_metadata = option;
 }
 
-static void rygel_media_export_metadata_extractor_extract_basic_information (RygelMediaExportMetadataExtractor* self, GFile* file, GUPnPDLNAInformation* dlna) {
-	GError * _inner_error_ = NULL;
-	g_return_if_fail (self != NULL);
-	g_return_if_fail (file != NULL);
-	{
-		GFileInfo* file_info = NULL;
-		GFile* _tmp11_;
-		GUPnPDLNAInformation* _tmp12_;
-		{
-			GFile* _tmp0_;
-			GFileInfo* _tmp1_ = NULL;
-			GFileInfo* _tmp2_;
-			_tmp0_ = file;
-			_tmp1_ = g_file_query_info (_tmp0_, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE "," G_FILE_ATTRIBUTE_STANDARD_SIZE "," G_FILE_ATTRIBUTE_TIME_MODIFIED "," G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME, G_FILE_QUERY_INFO_NONE, NULL, &_inner_error_);
-			_tmp2_ = _tmp1_;
-			if (_inner_error_ != NULL) {
-				goto __catch24_g_error;
-			}
-			g_object_unref (file_info);
-			file_info = _tmp2_;
-		}
-		goto __finally24;
-		__catch24_g_error:
-		{
-			GError* _error_ = NULL;
-			const gchar* _tmp3_ = NULL;
-			GFile* _tmp4_;
-			gchar* _tmp5_ = NULL;
-			gchar* _tmp6_;
-			GFile* _tmp7_;
-			GError* _tmp8_;
-			GError* _tmp9_;
-			GError* _tmp10_;
-			_error_ = _inner_error_;
-			_inner_error_ = NULL;
-			_tmp3_ = _ ("Failed to query content type for '%s'");
-			_tmp4_ = file;
-			_tmp5_ = g_file_get_uri (_tmp4_);
-			_tmp6_ = _tmp5_;
-			g_warning (_tmp3_, _tmp6_);
-			g_free (_tmp6_);
-			_tmp7_ = file;
-			_tmp8_ = _error_;
-			g_signal_emit_by_name (self, "error", _tmp7_, _tmp8_);
-			_tmp9_ = _error_;
-			_tmp10_ = g_error_copy (_tmp9_);
-			_inner_error_ = _tmp10_;
-			g_error_free (_error_);
-			goto __finally24;
-		}
-		__finally24:
-		if (_inner_error_ != NULL) {
-			g_object_unref (file_info);
-			goto __catch23_g_error;
-		}
-		_tmp11_ = file;
-		_tmp12_ = dlna;
-		g_signal_emit_by_name (self, "extraction-done", _tmp11_, _tmp12_, file_info);
-		g_object_unref (file_info);
-	}
-	goto __finally23;
-	__catch23_g_error:
-	{
-		GError* _error_ = NULL;
-		GFile* _tmp13_;
-		gchar* _tmp14_ = NULL;
-		gchar* _tmp15_;
-		GError* _tmp16_;
-		const gchar* _tmp17_;
-		GFile* _tmp18_;
-		GError* _tmp19_;
-		_error_ = _inner_error_;
-		_inner_error_ = NULL;
-		_tmp13_ = file;
-		_tmp14_ = g_file_get_uri (_tmp13_);
-		_tmp15_ = _tmp14_;
-		_tmp16_ = _error_;
-		_tmp17_ = _tmp16_->message;
-		g_debug ("rygel-media-export-metadata-extractor.vala:147: Failed to extract basi" \
-"c metadata from %s: %s", _tmp15_, _tmp17_);
-		g_free (_tmp15_);
-		_tmp18_ = file;
-		_tmp19_ = _error_;
-		g_signal_emit_by_name (self, "error", _tmp18_, _tmp19_);
-		g_error_free (_error_);
-	}
-	__finally23:
-	if (_inner_error_ != NULL) {
-		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
-		g_clear_error (&_inner_error_);
-		return;
-	}
+RygelMediaExportMetadataExtractor *
+rygel_media_export_metadata_extractor_new (void) {
+  return RYGEL_MEDIA_EXPORT_METADATA_EXTRACTOR (g_object_new (RYGEL_MEDIA_EXPORT_TYPE_METADATA_EXTRACTOR, NULL));
 }
 
+/* Needed because of cycle: dlna_discoverer_done calls on_done, which
+ * calls dlna_discoverer_done.
+ */
+static void
+rygel_media_export_metadata_extractor_on_done_gupnp_dlna_discoverer_done (GUPnPDLNADiscoverer  *sender G_GNUC_UNUSED,
+									  GUPnPDLNAInformation *dlna,
+									  GError               *err,
+									  gpointer              self);
+
+static void
+rygel_media_export_metadata_extractor_extract_basic_information (RygelMediaExportMetadataExtractor *self,
+								 GFile                             *file,
+								 GUPnPDLNAInformation              *dlna) {
+  GError *error;
+  GFileInfo *file_info;
+
+  g_return_if_fail (RYGEL_MEDIA_EXPORT_IS_METADATA_EXTRACTOR (self));
+  g_return_if_fail (G_IS_FILE (file));
+  g_return_if_fail (dlna == NULL || GUPNP_IS_DLNA_INFORMATION (dlna));
 
-static void g_cclosure_user_marshal_VOID__OBJECT_OBJECT_OBJECT (GClosure * closure, GValue * return_value G_GNUC_UNUSED, guint n_param_values, const GValue * param_values, gpointer invocation_hint G_GNUC_UNUSED, gpointer marshal_data) {
-	typedef void (*GMarshalFunc_VOID__OBJECT_OBJECT_OBJECT) (gpointer data1, gpointer arg_1, gpointer arg_2, gpointer arg_3, gpointer data2);
-	register GMarshalFunc_VOID__OBJECT_OBJECT_OBJECT callback;
-	register GCClosure * cc;
-	register gpointer data1;
-	register gpointer data2;
-	cc = (GCClosure *) closure;
-	g_return_if_fail (n_param_values == 4);
-	if (G_CCLOSURE_SWAP_DATA (closure)) {
-		data1 = closure->data;
-		data2 = param_values->data[0].v_pointer;
-	} else {
-		data1 = param_values->data[0].v_pointer;
-		data2 = closure->data;
-	}
-	callback = (GMarshalFunc_VOID__OBJECT_OBJECT_OBJECT) (marshal_data ? marshal_data : cc->callback);
-	callback (data1, g_value_get_object (param_values + 1), g_value_get_object (param_values + 2), g_value_get_object (param_values + 3), data2);
+  error = NULL;
+  file_info = g_file_query_info (file,
+				 G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE ","
+				 G_FILE_ATTRIBUTE_STANDARD_SIZE ","
+				 G_FILE_ATTRIBUTE_TIME_MODIFIED ","
+				 G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME,
+				 G_FILE_QUERY_INFO_NONE,
+				 NULL,
+				 &error);
+  if (error) {
+    gchar *uri = g_file_get_uri (file);
+
+    g_warning (_("Failed to query content type for '%s'"), uri);
+    g_debug ("Failed to extract basic metadata from %s: %s", uri, error->message);
+    g_signal_emit (self, signals[ERROR], 0, file, error);
+    g_error_free (error);
+    return;
+  }
+  g_signal_emit (self, signals[EXTRACTION_DONE], 0, file, dlna, file_info);
+  g_object_unref (file_info);
 }
 
+static void
+rygel_media_export_metadata_extractor_on_done (RygelMediaExportMetadataExtractor *self,
+					       GUPnPDLNAInformation              *dlna,
+					       GError                            *err) {
+  RygelMediaExportMetadataExtractorPrivate *priv;
+  guint signal_id;
+  const GstDiscovererInfo *gst_info;
+  const gchar *uri;
+  GeeAbstractMap *abstract_file_hash;
+  GstDiscovererResult result;
+  GFile *file;
+
+  g_return_if_fail (RYGEL_MEDIA_EXPORT_IS_METADATA_EXTRACTOR (self));
+  g_return_if_fail (GUPNP_IS_DLNA_INFORMATION (dlna));
+
+  priv = self->priv;
+  signal_id = 0;
+  g_signal_parse_name ("done", GUPNP_TYPE_DLNA_DISCOVERER, &signal_id, NULL, FALSE);
+  g_signal_handlers_disconnect_matched (priv->discoverer,
+					G_SIGNAL_MATCH_ID |
+					G_SIGNAL_MATCH_FUNC |
+					G_SIGNAL_MATCH_DATA, signal_id,
+					0,
+					NULL,
+					G_CALLBACK (rygel_media_export_metadata_extractor_on_done_gupnp_dlna_discoverer_done),
+					self);
+
+  g_object_unref (priv->discoverer);
+  priv->discoverer = NULL;
+  gst_info = gupnp_dlna_information_get_info (dlna);
+  uri = gst_discoverer_info_get_uri (gst_info);
+  abstract_file_hash = GEE_ABSTRACT_MAP (priv->file_hash);
+  file = G_FILE (gee_abstract_map_get (abstract_file_hash, uri));
+  if (!file) {
+    g_warning ("File %s already handled, ignoring event", uri);
+    return;
+  }
+  gee_abstract_map_unset (abstract_file_hash, uri, NULL);
+  result = gst_discoverer_info_get_result (gst_info);
+
+  if ((result & GST_DISCOVERER_ERROR) == GST_DISCOVERER_ERROR) {
+    g_signal_emit (self, signals[ERROR], 0, file, err);
+  } else {
+    if ((result & GST_DISCOVERER_TIMEOUT) == GST_DISCOVERER_TIMEOUT) {
+      gchar* file_uri = g_file_get_uri (file);
 
-static void g_cclosure_user_marshal_VOID__OBJECT_POINTER (GClosure * closure, GValue * return_value G_GNUC_UNUSED, guint n_param_values, const GValue * param_values, gpointer invocation_hint G_GNUC_UNUSED, gpointer marshal_data) {
-	typedef void (*GMarshalFunc_VOID__OBJECT_POINTER) (gpointer data1, gpointer arg_1, gpointer arg_2, gpointer data2);
-	register GMarshalFunc_VOID__OBJECT_POINTER callback;
-	register GCClosure * cc;
-	register gpointer data1;
-	register gpointer data2;
-	cc = (GCClosure *) closure;
-	g_return_if_fail (n_param_values == 3);
-	if (G_CCLOSURE_SWAP_DATA (closure)) {
-		data1 = closure->data;
-		data2 = param_values->data[0].v_pointer;
-	} else {
-		data1 = param_values->data[0].v_pointer;
-		data2 = closure->data;
-	}
-	callback = (GMarshalFunc_VOID__OBJECT_POINTER) (marshal_data ? marshal_data : cc->callback);
-	callback (data1, g_value_get_object (param_values + 1), g_value_get_pointer (param_values + 2), data2);
+      g_debug ("Extraction timed out on %s", file_uri);
+      g_free (file_uri);
+      dlna = NULL;
+    }
+    rygel_media_export_metadata_extractor_extract_basic_information (self, file, dlna);
+  }
+
+  g_object_unref (file);
+}
+
+static void
+rygel_media_export_metadata_extractor_on_done_gupnp_dlna_discoverer_done (GUPnPDLNADiscoverer  *sender G_GNUC_UNUSED,
+									  GUPnPDLNAInformation *dlna,
+									  GError               *err,
+									  gpointer              self) {
+  rygel_media_export_metadata_extractor_on_done (self, dlna, err);
 }
 
+void
+rygel_media_export_metadata_extractor_extract (RygelMediaExportMetadataExtractor *self,
+					       GFile                             *file) {
+  RygelMediaExportMetadataExtractorPrivate *priv;
+
+  g_return_if_fail (RYGEL_MEDIA_EXPORT_IS_METADATA_EXTRACTOR (self));
+  g_return_if_fail (G_IS_FILE (file));
 
-static void rygel_media_export_metadata_extractor_class_init (RygelMediaExportMetadataExtractorClass * klass) {
-	rygel_media_export_metadata_extractor_parent_class = g_type_class_peek_parent (klass);
-	g_type_class_add_private (klass, sizeof (RygelMediaExportMetadataExtractorPrivate));
-	G_OBJECT_CLASS (klass)->finalize = rygel_media_export_metadata_extractor_finalize;
-	g_signal_new ("extraction_done", RYGEL_MEDIA_EXPORT_TYPE_METADATA_EXTRACTOR, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_user_marshal_VOID__OBJECT_OBJECT_OBJECT, G_TYPE_NONE, 3, G_TYPE_FILE, GUPNP_TYPE_DLNA_INFORMATION, g_file_info_get_type ());
-	/**
-	     * Signalize that an error occured during metadata extraction
-	     */
-	g_signal_new ("error", RYGEL_MEDIA_EXPORT_TYPE_METADATA_EXTRACTOR, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_user_marshal_VOID__OBJECT_POINTER, G_TYPE_NONE, 2, G_TYPE_FILE, G_TYPE_POINTER);
+  priv = self->priv;
+
+  if (priv->extract_metadata) {
+    gchar *uri;
+    GstClockTime gst_timeout;
+    GUPnPDLNADiscoverer *discoverer;
+
+    uri = g_file_get_uri (file);
+    gee_abstract_map_set (GEE_ABSTRACT_MAP (priv->file_hash), uri, file);
+    gst_timeout = (GstClockTime) (EXTRACTOR_TIMEOUT * GST_SECOND);
+    discoverer = gupnp_dlna_discoverer_new (gst_timeout, TRUE, TRUE);
+    if (priv->discoverer) {
+      g_object_unref (priv->discoverer);
+    }
+    priv->discoverer = discoverer;
+    g_signal_connect_object (discoverer,
+			     "done",
+			     G_CALLBACK (rygel_media_export_metadata_extractor_on_done_gupnp_dlna_discoverer_done),
+			     self,
+			     0);
+    gupnp_dlna_discoverer_start (discoverer);
+    gupnp_dlna_discoverer_discover_uri (discoverer, uri);
+    g_free (uri);
+  } else {
+    rygel_media_export_metadata_extractor_extract_basic_information (self, file, NULL);
+  }
 }
 
+static void
+rygel_media_export_metadata_extractor_dispose (GObject *object) {
+  RygelMediaExportMetadataExtractor *self = RYGEL_MEDIA_EXPORT_METADATA_EXTRACTOR (object);
+  RygelMediaExportMetadataExtractorPrivate *priv = self->priv;
+
+  if (priv->discoverer) {
+    GUPnPDLNADiscoverer *discoverer = priv->discoverer;
 
-static void rygel_media_export_metadata_extractor_init (RygelMediaExportMetadataExtractor * self) {
-	self->priv = RYGEL_MEDIA_EXPORT_METADATA_EXTRACTOR_GET_PRIVATE (self);
-	self->priv->timeout = (guint64) 10;
+    priv->discoverer = NULL;
+    g_object_unref (discoverer);
+  }
+  if (priv->file_hash) {
+    GeeHashMap *file_hash = priv->file_hash;
+
+    priv->file_hash = NULL;
+    g_object_unref (file_hash);
+  }
+
+  G_OBJECT_CLASS (rygel_media_export_metadata_extractor_parent_class)->dispose (object);
 }
 
+static void
+rygel_media_export_metadata_extractor_constructed (GObject *object) {
+  RygelMediaExportMetadataExtractor *self = RYGEL_MEDIA_EXPORT_METADATA_EXTRACTOR (object);
+  RygelMediaExportMetadataExtractorPrivate *priv = self->priv;
+  RygelConfiguration *config;
+
+  G_OBJECT_CLASS (rygel_media_export_metadata_extractor_parent_class)->constructed (object);
 
-static void rygel_media_export_metadata_extractor_finalize (GObject* obj) {
-	RygelMediaExportMetadataExtractor * self;
-	self = G_TYPE_CHECK_INSTANCE_CAST (obj, RYGEL_MEDIA_EXPORT_TYPE_METADATA_EXTRACTOR, RygelMediaExportMetadataExtractor);
-	g_object_unref (self->priv->discoverer);
-	g_object_unref (self->priv->file_hash);
-	G_OBJECT_CLASS (rygel_media_export_metadata_extractor_parent_class)->finalize (obj);
+  priv->file_hash = gee_hash_map_new (G_TYPE_STRING,
+				      (GBoxedCopyFunc) g_strdup,
+				      g_free,
+				      G_TYPE_FILE,
+				      (GBoxedCopyFunc) g_object_ref,
+				      g_object_unref,
+				      NULL,
+				      NULL,
+				      NULL,
+				      NULL,
+				      NULL,
+				      NULL,
+				      NULL,
+				      NULL,
+				      NULL);
+  config = RYGEL_CONFIGURATION (rygel_meta_config_get_default ());
+  g_signal_connect (config, "setting-changed", G_CALLBACK (on_config_changed), self);
+  on_config_changed (config, RYGEL_MEDIA_EXPORT_PLUGIN_NAME, EXTRACTOR_OPTION, self);
+  g_object_unref (config);
 }
 
+static void
+rygel_media_export_metadata_extractor_class_init (RygelMediaExportMetadataExtractorClass *extractor_class) {
+  GObjectClass *object_class = G_OBJECT_CLASS (extractor_class);
 
+  object_class->dispose = rygel_media_export_metadata_extractor_dispose;
+  object_class->constructed = rygel_media_export_metadata_extractor_constructed;
+  signals[EXTRACTION_DONE] = g_signal_new ("extraction_done",
+					   RYGEL_MEDIA_EXPORT_TYPE_METADATA_EXTRACTOR,
+					   G_SIGNAL_RUN_LAST,
+					   0,
+					   NULL,
+					   NULL,
+					   NULL, /* libffi based marshaller */
+					   G_TYPE_NONE,
+					   3,
+					   G_TYPE_FILE,
+					   GUPNP_TYPE_DLNA_INFORMATION,
+					   G_TYPE_FILE_INFO);
+  /**
+   * Signalize that an error occured during metadata extraction
+   */
+  signals[ERROR] = g_signal_new ("error",
+				 RYGEL_MEDIA_EXPORT_TYPE_METADATA_EXTRACTOR,
+				 G_SIGNAL_RUN_LAST,
+				 0,
+				 NULL,
+				 NULL,
+				 NULL, /* libffi based marshaller */
+				 G_TYPE_NONE,
+				 2,
+				 G_TYPE_FILE,
+				 G_TYPE_ERROR);
 
+  g_type_class_add_private (extractor_class, sizeof (RygelMediaExportMetadataExtractorPrivate));
+}
+
+static void
+rygel_media_export_metadata_extractor_init (RygelMediaExportMetadataExtractor *self) {
+  self->priv = RYGEL_MEDIA_EXPORT_METADATA_EXTRACTOR_GET_PRIVATE (self);
+}
diff --git a/src/media-export/rygel-media-export-plugin.c b/src/media-export/rygel-media-export-plugin.c
index 11b45b1..ae00b6e 100644
--- a/src/media-export/rygel-media-export-plugin.c
+++ b/src/media-export/rygel-media-export-plugin.c
@@ -25,7 +25,6 @@
 
 G_DEFINE_TYPE (RygelMediaExportPlugin, rygel_media_export_plugin, RYGEL_TYPE_MEDIA_SERVER_PLUGIN)
 
-#define RYGEL_MEDIA_EXPORT_PLUGIN_NAME "MediaExport"
 RygelMediaExportPlugin *rygel_media_export_plugin_construct (GType object_type);
 
 /**
diff --git a/src/media-export/rygel-media-export-plugin.h b/src/media-export/rygel-media-export-plugin.h
index f2330a1..8b86f7b 100644
--- a/src/media-export/rygel-media-export-plugin.h
+++ b/src/media-export/rygel-media-export-plugin.h
@@ -36,6 +36,8 @@ G_BEGIN_DECLS
 #define RYGEL_MEDIA_EXPORT_IS_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), RYGEL_MEDIA_EXPORT_TYPE_PLUGIN))
 #define RYGEL_MEDIA_EXPORT_PLUGIN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), RYGEL_MEDIA_EXPORT_TYPE_PLUGIN, RygelMediaExportPluginClass))
 
+#define RYGEL_MEDIA_EXPORT_PLUGIN_NAME "MediaExport"
+
 typedef struct _RygelMediaExportPlugin RygelMediaExportPlugin;
 typedef struct _RygelMediaExportPluginClass RygelMediaExportPluginClass;
 typedef struct _RygelMediaExportPluginPrivate RygelMediaExportPluginPrivate;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]