banshee r5005 - in trunk/banshee: . src/Dap/Banshee.Dap.Mtp/Banshee.Dap.Mtp src/Libraries/Mtp/Mtp



Author: gburt
Date: Tue Feb  3 21:16:19 2009
New Revision: 5005
URL: http://svn.gnome.org/viewvc/banshee?rev=5005&view=rev

Log:
2009-02-03  Gabriel Burt  <gabriel burt gmail com>

	This patch fixes issues with adding tracks to a MTP device, the symptoms
	of which are Banshee freezing and files not getting added (BGO #567093)

	* Dap/Banshee.Dap.Mtp/Banshee.Dap.Mtp/MtpSource.cs: Do a better job of
	locking various MTP functions.

	* Dap/Banshee.Dap.Mtp/Banshee.Dap.Mtp/MtpTrackInfo.cs: Fix bug where we
	set the filesize of the Mtp.Track to the TrackInfo's FileSize, when it
	should be set to the file size of the passed in track URI (which might be
	different than track.Uri if it was transcoded).

	* Libraries/Mtp/Mtp/Error.cs: Style fix.

	* Libraries/Mtp/Mtp/Track.cs: Treat any m4* extension as mp4.

Modified:
   trunk/banshee/ChangeLog
   trunk/banshee/src/Dap/Banshee.Dap.Mtp/Banshee.Dap.Mtp/MtpSource.cs
   trunk/banshee/src/Dap/Banshee.Dap.Mtp/Banshee.Dap.Mtp/MtpTrackInfo.cs
   trunk/banshee/src/Libraries/Mtp/Mtp/Error.cs
   trunk/banshee/src/Libraries/Mtp/Mtp/Track.cs

Modified: trunk/banshee/src/Dap/Banshee.Dap.Mtp/Banshee.Dap.Mtp/MtpSource.cs
==============================================================================
--- trunk/banshee/src/Dap/Banshee.Dap.Mtp/Banshee.Dap.Mtp/MtpSource.cs	(original)
+++ trunk/banshee/src/Dap/Banshee.Dap.Mtp/Banshee.Dap.Mtp/MtpSource.cs	Tue Feb  3 21:16:19 2009
@@ -61,7 +61,7 @@
         private Dictionary<string, Album> album_cache = new Dictionary<string, Album> ();
 
         private bool supports_jpegs = false;
-        private bool can_sync = NeverSyncAlbumArtSchema.Get () == false;
+        private bool can_sync_albumart = NeverSyncAlbumArtSchema.Get () == false;
         private int thumb_width = AlbumArtWidthSchema.Get ();
 
         public override void DeviceInitialize (IDevice device)
@@ -150,13 +150,16 @@
         {
             track_map = new Dictionary<int, Track> ();
             try {
-                List<Track> files = mtp_device.GetAllTracks (delegate (ulong current, ulong total, IntPtr data) {
-                    //user_event.Progress = (double)current / total;
-                    // Translators: {0} is the name of the MTP audio device (eg Gabe's Zen Player), {1} is the
-                    // track currently being loaded, and {2} is the total # of tracks that will be loaded.
-                    SetStatus (String.Format (Catalog.GetString ("Loading {0} - {1} of {2}"), Name, current, total), false);
-                    return 0;
-                });
+                List<Track> files = null;
+                lock (mtp_device) {
+                    files = mtp_device.GetAllTracks (delegate (ulong current, ulong total, IntPtr data) {
+                        //user_event.Progress = (double)current / total;
+                        // Translators: {0} is the name of the MTP audio device (eg Gabe's Zen Player), {1} is the
+                        // track currently being loaded, and {2} is the total # of tracks that will be loaded.
+                        SetStatus (String.Format (Catalog.GetString ("Loading {0} - {1} of {2}"), Name, current, total), false);
+                        return 0;
+                    });
+                }
 
                 /*if (user_event.IsCancelRequested) {
                     return;
@@ -178,15 +181,18 @@
                 Hyena.Data.Sqlite.HyenaSqliteCommand insert_cmd = new Hyena.Data.Sqlite.HyenaSqliteCommand (
                     @"INSERT INTO CorePlaylistEntries (PlaylistID, TrackID)
                         SELECT ?, TrackID FROM CoreTracks WHERE PrimarySourceID = ? AND ExternalID = ?");
-                foreach (MTP.Playlist playlist in mtp_device.GetPlaylists ()) {
-                    PlaylistSource pl_src = new PlaylistSource (playlist.Name, this);
-                    pl_src.Save ();
-                    // TODO a transaction would make sense here (when the threading issue is fixed)
-                    foreach (int id in playlist.TrackIds) {
-                        ServiceManager.DbConnection.Execute (insert_cmd, pl_src.DbId, this.DbId, id);
+
+                lock (mtp_device) {
+                    foreach (MTP.Playlist playlist in mtp_device.GetPlaylists ()) {
+                        PlaylistSource pl_src = new PlaylistSource (playlist.Name, this);
+                        pl_src.Save ();
+                        // TODO a transaction would make sense here (when the threading issue is fixed)
+                        foreach (int id in playlist.TrackIds) {
+                            ServiceManager.DbConnection.Execute (insert_cmd, pl_src.DbId, this.DbId, id);
+                        }
+                        pl_src.UpdateCounts ();
+                        AddChildSource (pl_src);
                     }
-                    pl_src.UpdateCounts ();
-                    AddChildSource (pl_src);
                 }
 
             } catch (Exception e) {
@@ -272,27 +278,31 @@
             }
         }
 
+        private long bytes_used;
         public override long BytesUsed {
             get {
-                long count = 0;
-                lock (mtp_device) {
+                if (Monitor.TryEnter (mtp_device)) {
+                    bytes_used = 0;
                     foreach (DeviceStorage s in mtp_device.GetStorage ()) {
-                        count += (long) s.MaxCapacity - (long) s.FreeSpaceInBytes;
+                        bytes_used += (long) s.MaxCapacity - (long) s.FreeSpaceInBytes;
                     }
+                    Monitor.Exit (mtp_device);
                 }
-                return count;
+                return bytes_used;
             }
         }
         
+        private long bytes_capacity;
         public override long BytesCapacity {
             get {
-                long count = 0;
-                lock (mtp_device) {
+                if (Monitor.TryEnter (mtp_device)) {
+                    bytes_capacity = 0;
                     foreach (DeviceStorage s in mtp_device.GetStorage ()) {
-                        count += (long) s.MaxCapacity;
+                        bytes_capacity += (long) s.MaxCapacity;
                     }
+                    Monitor.Exit (mtp_device);
                 }
-                return count;
+                return bytes_capacity;
             }
         }
 
@@ -305,43 +315,43 @@
             if (track.PrimarySourceId == DbId)
                 return;
 
-            Track mtp_track = TrackInfoToMtpTrack (track, fromUri);
-            bool video = (track.MediaAttributes & TrackMediaAttributes.VideoStream) != 0;
             lock (mtp_device) {
+                Track mtp_track = TrackInfoToMtpTrack (track, fromUri);
+                bool video = track.HasAttribute (TrackMediaAttributes.VideoStream);
                 mtp_device.UploadTrack (fromUri.LocalPath, mtp_track, GetFolderForTrack (track), OnUploadProgress);
-            }
 
-            // Add/update album art
-            if (!video) {
-                string key = MakeAlbumKey (track.ArtistName, track.AlbumTitle);
-                if (!album_cache.ContainsKey (key)) {
-                    Album album = new Album (mtp_device, track.AlbumTitle, track.ArtistName, track.Genre);
-                    album.AddTrack (mtp_track);
-
-                    if (supports_jpegs && can_sync) {
-                        try {
-                            Gdk.Pixbuf pic = ServiceManager.Get<Banshee.Collection.Gui.ArtworkManager> ().LookupScalePixbuf (
-                                track.ArtworkId, thumb_width
-                            );
-                            if (pic != null) {
-                                byte [] bytes = pic.SaveToBuffer ("jpeg");
-                                album.Save (bytes, (uint)pic.Width, (uint)pic.Height);
-                                Banshee.Collection.Gui.ArtworkManager.DisposePixbuf (pic);
-                            }
-                            album_cache[key] = album;
-                        } catch {}
+                // Add/update album art
+                if (!video) {
+                    string key = MakeAlbumKey (track.ArtistName, track.AlbumTitle);
+                    if (!album_cache.ContainsKey (key)) {
+                        Album album = new Album (mtp_device, track.AlbumTitle, track.ArtistName, track.Genre);
+                        album.AddTrack (mtp_track);
+
+                        if (supports_jpegs && can_sync_albumart) {
+                            try {
+                                Gdk.Pixbuf pic = ServiceManager.Get<Banshee.Collection.Gui.ArtworkManager> ().LookupScalePixbuf (
+                                    track.ArtworkId, thumb_width
+                                );
+                                if (pic != null) {
+                                    byte [] bytes = pic.SaveToBuffer ("jpeg");
+                                    album.Save (bytes, (uint)pic.Width, (uint)pic.Height);
+                                    Banshee.Collection.Gui.ArtworkManager.DisposePixbuf (pic);
+                                }
+                                album_cache[key] = album;
+                            } catch {}
+                        }
+                    } else {
+                        Album album = album_cache[key];
+                        album.AddTrack (mtp_track);
+                        album.Save ();
                     }
-                } else {
-                    Album album = album_cache[key];
-                    album.AddTrack (mtp_track);
-                    album.Save ();
                 }
-            }
 
-            MtpTrackInfo new_track = new MtpTrackInfo (mtp_device, mtp_track);
-            new_track.PrimarySource = this;
-            new_track.Save (false);
-            track_map[new_track.TrackId] = mtp_track;
+                MtpTrackInfo new_track = new MtpTrackInfo (mtp_device, mtp_track);
+                new_track.PrimarySource = this;
+                new_track.Save (false);
+                track_map[new_track.TrackId] = mtp_track;
+            }
         }
 
         private Folder GetFolderForTrack (TrackInfo track)

Modified: trunk/banshee/src/Dap/Banshee.Dap.Mtp/Banshee.Dap.Mtp/MtpTrackInfo.cs
==============================================================================
--- trunk/banshee/src/Dap/Banshee.Dap.Mtp/Banshee.Dap.Mtp/MtpTrackInfo.cs	(original)
+++ trunk/banshee/src/Dap/Banshee.Dap.Mtp/Banshee.Dap.Mtp/MtpTrackInfo.cs	Tue Feb  3 21:16:19 2009
@@ -97,13 +97,11 @@
             f.Artist = track.ArtistName;
             f.Duration = (uint)track.Duration.TotalMilliseconds;
             f.Genre = track.Genre;
+            f.UseCount = (uint)track.PlayCount;
             f.Rating = (ushort)(track.Rating * 20);
             f.Title = track.TrackTitle;
             f.TrackNumber = (ushort)track.TrackNumber;
-            f.UseCount = (uint)track.PlayCount;
             f.Year = track.Year;
-            //f.Bitrate = (uint)track.BitRate;
-            f.FileSize = (ulong)track.FileSize;
         }
     }
 }

Modified: trunk/banshee/src/Libraries/Mtp/Mtp/Error.cs
==============================================================================
--- trunk/banshee/src/Libraries/Mtp/Mtp/Error.cs	(original)
+++ trunk/banshee/src/Libraries/Mtp/Mtp/Error.cs	Tue Feb  3 21:16:19 2009
@@ -55,8 +55,7 @@
 				return;
 			
 			LibMtpException ex = null;
-			while (ptr != IntPtr.Zero)
-			{
+			while (ptr != IntPtr.Zero) {
 				Error e = (Error)Marshal.PtrToStructure (ptr, typeof(Error));
 				ex = new LibMtpException (e.errornumber, e.error_text, ex);
 				ptr = e.next;

Modified: trunk/banshee/src/Libraries/Mtp/Mtp/Track.cs
==============================================================================
--- trunk/banshee/src/Libraries/Mtp/Mtp/Track.cs	(original)
+++ trunk/banshee/src/Libraries/Mtp/Mtp/Track.cs	Tue Feb  3 21:16:19 2009
@@ -185,8 +185,8 @@
             if (ext.Length > 0)
                 ext = ext.Substring (1, ext.Length - 1);
 
-            // this is a hack
-            if (ext == "m4v" || ext == "M4V")
+            // this is a hack; catch all m4(a|b|v|p)
+            if (ext != null && ext.ToLower ().StartsWith ("m4"))
                 ext = "mp4";
 
             FileType type = (FileType) Enum.Parse (typeof(FileType), ext, true);



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