[libdmapsharing] Don't transcode if format already correct; Vala-related changes Signed-off-by: W. Michael Petullo <m



commit 23815d008e90e48cd03b2a56efa874a4a012b3ab
Author: W. Michael Petullo <mike flyn org>
Date:   Tue Dec 21 17:31:13 2010 -0600

    Don't transcode if format already correct; Vala-related changes
    Signed-off-by: W. Michael Petullo <mike flyn org>

 libdmapsharing/daap-share.c |    5 +-
 tests/Makefile.am           |   31 ++++++++--
 tests/dmapcopy.vala         |  103 ++++++++++++++++++++++++++++++
 tests/dpapview.vala         |  144 ++-----------------------------------------
 tests/vala-dmap-db.vala     |   60 ++++++++++++++++++
 tests/vala-dpap-record.vala |  114 ++++++++++++++++++++++++++++++++++
 6 files changed, 312 insertions(+), 145 deletions(-)
---
diff --git a/libdmapsharing/daap-share.c b/libdmapsharing/daap-share.c
index b35a608..6617491 100644
--- a/libdmapsharing/daap-share.c
+++ b/libdmapsharing/daap-share.c
@@ -396,6 +396,7 @@ static struct DMAPMetaDataMap meta_data_map[] = {
 static void
 send_chunked_file (SoupServer *server, SoupMessage *message, DAAPRecord *record, guint64 filesize, guint64 offset, const gchar *transcode_mimetype)
 {
+	gchar *format = NULL;
 	GInputStream *stream;
 	gboolean has_video;
 	const char *location;
@@ -420,7 +421,9 @@ send_chunked_file (SoupServer *server, SoupMessage *message, DAAPRecord *record,
 		return;
 	}
 
-	if (transcode_format == NULL) {
+	g_object_get (record, "format", &format, NULL);
+	if (transcode_format == NULL || ! strcmp (format, transcode_format)) {
+		g_debug ("Not transcoding");
 		cd->stream = stream;
 #ifdef HAVE_GSTREAMERAPP
 	} else if (! strcmp ("mp3", transcode_format)) {
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 6fb3e7f..0b7828a 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1,7 +1,7 @@
 noinst_PROGRAMS = test-dmap-client test-dmap-server
 
 if HAVE_VALA
-noinst_PROGRAMS += dpapview
+noinst_PROGRAMS += dpapview dmapcopy
 endif
 
 test_dmap_client_SOURCES = \
@@ -43,17 +43,22 @@ test_dmap_server_LDADD = \
 	$(MDNS_LIBS)
 
 if MAINTAINER_MODE
-PACKAGES = --pkg gee-1.0 --pkg gtk+-2.0 --pkg gstreamer-0.10 --pkg libdmapsharing-2.2 --pkg libsoup-2.4 --pkg glib-2.0
-BUILT_SOURCES = vala.stamp
+BUILT_SOURCES = dpapview.stamp dmapcopy.stamp
 
-vala.stamp: $(dpapview_VALASOURCES)
-	$(VALAC) --vapidir=$(srcdir) $(PACKAGES) $^ -C
+dpapview.stamp: $(dpapview_VALASOURCES)
+	$(VALAC) --vapidir=$(srcdir) --pkg gee-1.0 --pkg gtk+-2.0 --pkg gstreamer-0.10 --pkg libdmapsharing-2.2 --pkg libsoup-2.4 --pkg glib-2.0 $^ -C
+	touch $@
+
+dmapcopy.stamp: $(dmapcopy_VALASOURCES)
+	$(VALAC) --vapidir=$(srcdir) --pkg gee-1.0 --pkg gstreamer-0.10 --pkg libdmapsharing-2.2 --pkg libsoup-2.4 --pkg glib-2.0 $^ -C
 	touch $@
 endif
 
 if HAVE_VALA
 dpapview_VALASOURCES = \
-	dpapview.vala
+	dpapview.vala \
+	vala-dmap-db.vala \
+	vala-dpap-record.vala
 
 dpapview_VALABUILTSOURCES = $(dpapview_VALASOURCES:.vala=.c)
 
@@ -64,6 +69,20 @@ dpapview_LDADD = \
 	$(top_builddir)/libdmapsharing/libdmapsharing-3.0.la \
 	$(GTK_LIBS) \
 	$(GEE_LIBS)
+
+dmapcopy_VALASOURCES = \
+	dmapcopy.vala \
+	vala-dmap-db.vala \
+	vala-dpap-record.vala
+
+dmapcopy_VALABUILTSOURCES = $(dmapcopy_VALASOURCES:.vala=.c)
+
+dmapcopy_SOURCES = \
+	$(dmapcopy_VALABUILTSOURCES)
+
+dmapcopy_LDADD = \
+	$(top_builddir)/libdmapsharing/libdmapsharing-3.0.la \
+	$(GEE_LIBS)
 endif
 
 AM_CPPFLAGS = \
diff --git a/tests/dmapcopy.vala b/tests/dmapcopy.vala
new file mode 100644
index 0000000..0711551
--- /dev/null
+++ b/tests/dmapcopy.vala
@@ -0,0 +1,103 @@
+/*   FILE: dmapcopy.vala -- Copy files from a DMAP server
+ * AUTHOR: W. Michael Petullo <mike flyn org>
+ *   DATE: 20 December 2010 
+ *
+ * Copyright (c) 2010 W. Michael Petullo <new flyn org>
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+private class DPAPCopy {
+	private DMAP.MdnsBrowser browser;
+	private DMAP.Connection connection;
+	private ValaDMAPDb db;
+	private ValaDPAPRecordFactory factory;
+
+	private bool connected_cb (DMAP.Connection connection, bool result, string? reason) {
+		GLib.debug ("%lld entries\n", db.count ());
+
+		db.foreach ((k, v) => {
+
+			stdout.printf ("%s\n", ((ValaDPAPRecord) v).location);
+
+			/* Uncomment to copy the data:
+			var session = new Soup.SessionAsync ();
+			var message = new Soup.Message ("GET", ((ValaDPAPRecord) v).location);
+			message.request_headers = connection.get_headers (((ValaDPAPRecord) v).location);
+
+			GLib.debug ("GET %s", ((ValaDPAPRecord) v).location);
+			session.send_message (message);
+
+			var file = File.new_for_path (((int) k).to_string ());
+			var file_stream = file.create (FileCreateFlags.NONE);
+
+			// Test for the existence of file
+			if (file.query_exists ()) {
+				stdout.printf ("File successfully created.\n");
+			}
+
+			// Write text data to file
+			var data_stream = new DataOutputStream (file_stream);
+			data_stream.write (message.response_body.data, (size_t) message.response_body.length, null);
+			*/
+		});
+
+		return true;
+	}
+
+	private void service_added_cb (void *service) {
+		/* FIXME: fix void * argument, see libdmapsharing TODO: */
+		DMAP.MdnsBrowserService *FIXME = service;
+		/* FIXME: fix int cast: should not be requried: */
+		connection = (DMAP.Connection) new DPAP.Connection (FIXME->service_name, FIXME->host, (int) FIXME->port, false, db, factory);
+		connection.connect (connected_cb);
+	}
+
+	public DPAPCopy () throws GLib.Error {
+		db = new ValaDMAPDb ();
+		factory = new ValaDPAPRecordFactory ();
+
+		browser = new DMAP.MdnsBrowser (DMAP.MdnsBrowserServiceType.DPAP);
+		browser.service_added.connect (service_added_cb);
+		browser.start ();
+	}
+}
+
+void debug_printf (string? log_domain,
+		   GLib.LogLevelFlags log_level,
+		   string? message)
+{
+	stdout.printf ("%s\n", message);
+}
+
+void debug_null (string? log_domain,
+		 GLib.LogLevelFlags log_level,
+		 string? message)
+{
+}
+
+int main (string[] args) {     
+	var loop = new GLib.MainLoop ();
+
+	GLib.Log.set_handler ("libdmapsharing", GLib.LogLevelFlags.LEVEL_DEBUG, debug_null);
+	GLib.Log.set_handler (null, GLib.LogLevelFlags.LEVEL_DEBUG, debug_null);
+
+	var dmapcopy = new DPAPCopy ();
+
+	loop.run ();
+
+	return 0;
+}
diff --git a/tests/dpapview.vala b/tests/dpapview.vala
index f211160..21fd658 100644
--- a/tests/dpapview.vala
+++ b/tests/dpapview.vala
@@ -20,144 +20,12 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-private class ViewerDMAPDb : GLib.Object, DMAP.Db {
-	// A dumb database that stores everything in an array
-
-	private Gee.ArrayList<ViewerDPAPRecord> db = new Gee.ArrayList<ViewerDPAPRecord> ();
-
-	public uint add (DMAP.Record record) {
-		db.add (((ViewerDPAPRecord) record));
-		return db.size;
-	}
-
-	public uint add_path (string path) {
-		GLib.error ("add_path not implemented");
-	}
-
-	public uint add_with_id (DMAP.Record record, uint id) {
-		GLib.error ("add_with_id not implemented");
-	}
-
-	public int64 count () {
-		return db.size;
-	}
-
-	public void @foreach (GLib.HFunc func) {
-		int i;
-		for (i = 0; i < db.size; i++) {
-			func (i.to_pointer (), db[i]);
-		}
-	}
-
-	public unowned DMAP.Record lookup_by_id (uint id) {
-		GLib.error ("lookup_by_id not implemented");
-	}
-
-
-	public uint lookup_id_by_location (string location){
-		GLib.error ("lookup_id_by_location not implemented");
-	}
-}
-
-private class ViewerDPAPRecordFactory : GLib.Object, DMAP.RecordFactory {
-	public DMAP.Record create (void* user_data) {
-		return new ViewerDPAPRecord ();
-	}
-}
-
-private class ViewerDPAPRecord : GLib.Object, DMAP.Record, DPAP.Record {
-	private string _location;
-	private string _filename;
-	private string _aspect_ratio;
-	private string _format;
-	private string _comments;
-	private uchar *_thumbnail;
-	private int _filesize;
-	private int _large_filesize;
-	private int _height;
-	private int _width;
-	private int _rating;
-	private int _creation_date;
-
-	public string location {
-		get { return _location; }
-		set { _location = value; }
-	}
-
-	public string filename {
-		get { return _filename; }
-		set { _filename = value; }
-	}
-
-	public string aspect_ratio {
-		get { return _aspect_ratio; }
-		set { _aspect_ratio = value; }
-	}
-
-	public string format {
-		get { return _format; }
-		set { _format = value; }
-	}
-
-	public uchar *thumbnail {
-		get { return _thumbnail; }
-		set { _thumbnail = value; }
-	}
-
-	public string comments {
-		get { return _comments; }
-		set { _comments = value; }
-	}
-
-	public int filesize {
-		get { return _filesize; }
-		set { _filesize = value; }
-	}
-
-	public int large_filesize {
-		get { return _large_filesize; }
-		set { _large_filesize = value; }
-	}
-
-	public int height {
-		get { return _height; }
-		set { _height = value; }
-	}
-
-	public int width {
-		get { return _width; }
-		set { _width = value; }
-	}
-
-	public int rating {
-		get { return _rating; }
-		set { _rating = value; }
-	}
-
-	public int creation_date {
-		get { return _creation_date; }
-		set { _creation_date = value; }
-	}
-
-	public unowned GLib.InputStream read () throws GLib.Error {
-		GLib.error ("read not implemented");
-	}
-
-	public unowned DMAP.Record set_from_blob (GLib.ByteArray blob) {
-		GLib.error ("set_from_blob not implemented");
-	}
-
-	public unowned GLib.ByteArray to_blob () {
-		GLib.error ("to_blob not implemented");
-	}
-}
-
 private class DPAPViewer {
 	private DMAP.MdnsBrowser browser;
 	private DMAP.Connection connection;
 	private Gtk.ListStore liststore;
-	private ViewerDMAPDb db;
-	private ViewerDPAPRecordFactory factory;
+	private ValaDMAPDb db;
+	private ValaDPAPRecordFactory factory;
 
 	private bool connected_cb (DMAP.Connection connection, bool result, string? reason) {
 		GLib.debug ("%lld entries\n", db.count ());
@@ -165,14 +33,14 @@ private class DPAPViewer {
 		db.foreach ((k, v) => {
 			string path;
 			int fd = GLib.FileUtils.open_tmp ("dpapview.XXXXXX", out path);
-			GLib.FileUtils.set_contents (path, (string) ((ViewerDPAPRecord) v).thumbnail, ((ViewerDPAPRecord) v).filesize);
+			GLib.FileUtils.set_contents (path, (string) ((ValaDPAPRecord) v).thumbnail, ((ValaDPAPRecord) v).filesize);
 			var pixbuf = new Gdk.Pixbuf.from_file (path);
 			GLib.FileUtils.close (fd);
 			GLib.FileUtils.unlink (path);
 
 			Gtk.TreeIter iter;
 			liststore.append (out iter);
-			liststore.set (iter, 0, pixbuf, 1, ((ViewerDPAPRecord) v).filename);
+			liststore.set (iter, 0, pixbuf, 1, ((ValaDPAPRecord) v).filename);
 		});
 
 		return true;
@@ -192,8 +60,8 @@ private class DPAPViewer {
 		Gtk.Widget widget = builder.get_object ("window") as Gtk.Widget;
 		Gtk.IconView iconview = builder.get_object ("iconview") as Gtk.IconView;
 		liststore = builder.get_object ("liststore") as Gtk.ListStore;
-		db = new ViewerDMAPDb ();
-		factory = new ViewerDPAPRecordFactory ();
+		db = new ValaDMAPDb ();
+		factory = new ValaDPAPRecordFactory ();
 
 		iconview.set_pixbuf_column (0);
 		iconview.set_text_column (1);
diff --git a/tests/vala-dmap-db.vala b/tests/vala-dmap-db.vala
new file mode 100644
index 0000000..a5d8cb3
--- /dev/null
+++ b/tests/vala-dmap-db.vala
@@ -0,0 +1,60 @@
+/*   FILE: vala-dmap-db.vala -- A DMAPDb implementation in Vala
+ * AUTHOR: W. Michael Petullo <mike flyn org>
+ *   DATE: 21 December 2010 
+ *
+ * Copyright (c) 2010 W. Michael Petullo <new flyn org>
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+private class ValaDMAPDb : GLib.Object, DMAP.Db {
+	// A dumb database that stores everything in an array
+
+	private Gee.ArrayList<ValaDPAPRecord> db = new Gee.ArrayList<ValaDPAPRecord> ();
+
+	public uint add (DMAP.Record record) {
+		db.add (((ValaDPAPRecord) record));
+		return db.size;
+	}
+
+	public uint add_path (string path) {
+		GLib.error ("add_path not implemented");
+	}
+
+	public uint add_with_id (DMAP.Record record, uint id) {
+		GLib.error ("add_with_id not implemented");
+	}
+
+	public int64 count () {
+		return db.size;
+	}
+
+	public void @foreach (GLib.HFunc func) {
+		int i;
+		for (i = 0; i < db.size; i++) {
+			func (i.to_pointer (), db[i]);
+		}
+	}
+
+	public unowned DMAP.Record lookup_by_id (uint id) {
+		GLib.error ("lookup_by_id not implemented");
+	}
+
+
+	public uint lookup_id_by_location (string location){
+		GLib.error ("lookup_id_by_location not implemented");
+	}
+}
diff --git a/tests/vala-dpap-record.vala b/tests/vala-dpap-record.vala
new file mode 100644
index 0000000..f66cdb8
--- /dev/null
+++ b/tests/vala-dpap-record.vala
@@ -0,0 +1,114 @@
+/*   FILE: vala-dpap-record.vala -- A DPAPRecord implementation in Vala
+ * AUTHOR: W. Michael Petullo <mike flyn org>
+ *   DATE: 21 December 2010
+ *
+ * Copyright (c) 2010 W. Michael Petullo <new flyn org>
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+private class ValaDPAPRecord : GLib.Object, DMAP.Record, DPAP.Record {
+	private string _location;
+	private string _filename;
+	private string _aspect_ratio;
+	private string _format;
+	private string _comments;
+	private uchar *_thumbnail;
+	private int _filesize;
+	private int _large_filesize;
+	private int _height;
+	private int _width;
+	private int _rating;
+	private int _creation_date;
+
+	public string location {
+		get { return _location; }
+		set { _location = value; }
+	}
+
+	public string filename {
+		get { return _filename; }
+		set { _filename = value; }
+	}
+
+	public string aspect_ratio {
+		get { return _aspect_ratio; }
+		set { _aspect_ratio = value; }
+	}
+
+	public string format {
+		get { return _format; }
+		set { _format = value; }
+	}
+
+	public uchar *thumbnail {
+		get { return _thumbnail; }
+		set { _thumbnail = value; }
+	}
+
+	public string comments {
+		get { return _comments; }
+		set { _comments = value; }
+	}
+
+	public int filesize {
+		get { return _filesize; }
+		set { _filesize = value; }
+	}
+
+	public int large_filesize {
+		get { return _large_filesize; }
+		set { _large_filesize = value; }
+	}
+
+	public int height {
+		get { return _height; }
+		set { _height = value; }
+	}
+
+	public int width {
+		get { return _width; }
+		set { _width = value; }
+	}
+
+	public int rating {
+		get { return _rating; }
+		set { _rating = value; }
+	}
+
+	public int creation_date {
+		get { return _creation_date; }
+		set { _creation_date = value; }
+	}
+
+	public unowned GLib.InputStream read () throws GLib.Error {
+		GLib.error ("read not implemented");
+	}
+
+	public unowned DMAP.Record set_from_blob (GLib.ByteArray blob) {
+		GLib.error ("set_from_blob not implemented");
+	}
+
+	public unowned GLib.ByteArray to_blob () {
+		GLib.error ("to_blob not implemented");
+	}
+}
+
+private class ValaDPAPRecordFactory : GLib.Object, DMAP.RecordFactory {
+	public DMAP.Record create (void* user_data) {
+		return new ValaDPAPRecord ();
+	}
+}



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