diff options
author | Aaron Bockover <abock@src.gnome.org> | 2005-08-29 08:10:23 +0000 |
---|---|---|
committer | Aaron Bockover <abock@src.gnome.org> | 2005-08-29 08:10:23 +0000 |
commit | b7d3a46435a5ef3e0ee617faf573d1077259ecd7 (patch) | |
tree | 7289d34262fc50e923eca9f3fad8b2dc564ce450 | |
parent | b2d6a2a854b3ae832859d154a86fcb9b6ea7bf84 (diff) |
Audio CD SupportBANSHEE_0_9_0
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | libbanshee/Makefile.am | 11 | ||||
-rw-r--r-- | libbanshee/cd-test.c | 21 | ||||
-rw-r--r-- | src/AudioCdCore.cs | 151 | ||||
-rw-r--r-- | src/Library.cs | 2 |
5 files changed, 148 insertions, 41 deletions
@@ -1,5 +1,9 @@ 2005-08-28 Aaron Bockover <aaron@aaronbock.net> + * banshee: Version 0.9.0 + * src/AudioCdCore.cs: Implementing cd-info bindings + * libbanshee/cd-info.c: Disk/Track info objects, GStreamer to detect + sectors, offsets, and track numbers/layouts * src/Library.cs: New AudioCdSource * src/SourceView.cs: Listen to AudioCdCore for events to update the SourceView diff --git a/libbanshee/Makefile.am b/libbanshee/Makefile.am index 14432f6c7..3ba143831 100644 --- a/libbanshee/Makefile.am +++ b/libbanshee/Makefile.am @@ -3,7 +3,8 @@ INCLUDES = \ -Wall \ -ggdb3 \ -D_FORTIFY_SOURCE=2 \ - $(HAL_CFLAGS) + $(HAL_CFLAGS) \ + $(GST_CFLAGS) bansheelibdir = $(pkglibdir) bansheelib_LTLIBRARIES = libbanshee.la @@ -11,9 +12,11 @@ bansheelib_LTLIBRARIES = libbanshee.la libbanshee_la_LDFLAGS = -avoid-version -module libbanshee_la_SOURCES = \ cd-detect.c \ - cd-detect.h + cd-detect.h \ + cd-info.c \ + cd-info.h -libbanshee_la_LIBADD = $(HAL_LIBS) +libbanshee_la_LIBADD = $(HAL_LIBS) $(GST_LIBS) CLEANFILES = cdtest DISTCLEANFILES = Makefile.in @@ -21,5 +24,5 @@ DISTCLEANFILES = Makefile.in EXTRA_DIST = cd-test.c test: - $(CC) -o cdtest $(HAL_LIBS) $(HAL_CFLAGS) cd-test.c $(libbanshee_la_SOURCES) + $(CC) -o cdtest $(INCLUDES) $(libbanshee_la_LIBADD) cd-test.c $(libbanshee_la_SOURCES) diff --git a/libbanshee/cd-test.c b/libbanshee/cd-test.c index 76c1b2f46..32b122754 100644 --- a/libbanshee/cd-test.c +++ b/libbanshee/cd-test.c @@ -32,10 +32,12 @@ #include <glib.h> #include "cd-detect.h" +#include "cd-info.h" void on_cd_added(const gchar *udi) { g_printf("NEW AUDIO CD: %s\n", udi); + } void on_device_removed(const gchar *udi) @@ -47,7 +49,10 @@ gint main() { GMainLoop *loop; CdDetect *cd_detect; - + CdDiskInfo *disk; + DiskInfo **disks; + int i; + loop = g_main_loop_new(g_main_context_default(), FALSE); cd_detect = cd_detect_new(); @@ -59,8 +64,18 @@ gint main() cd_detect_set_device_added_callback(cd_detect, on_cd_added); cd_detect_set_device_removed_callback(cd_detect, on_device_removed); - g_printf("Listening for Audio-CD-specific HAL events...\n"); - g_main_loop_run(loop); + disks = cd_detect_get_disk_array(cd_detect); + + for(i = 0; disks[i] != NULL; i++) { + disk = cd_disk_info_new(disks[i]->device_node); + g_printf("Tracks: %lld\n", disk->n_tracks); + cd_disk_info_free(disk); + } + + cd_detect_disk_array_free(disks); + +// g_printf("Listening for Audio-CD-specific HAL events...\n"); +// g_main_loop_run(loop); cd_detect_free(cd_detect); diff --git a/src/AudioCdCore.cs b/src/AudioCdCore.cs index 9f7e536b8..f47a02810 100644 --- a/src/AudioCdCore.cs +++ b/src/AudioCdCore.cs @@ -35,48 +35,132 @@ namespace Banshee { internal delegate void CdDetectUdiCallback(IntPtr udiPtr); - [StructLayout(LayoutKind.Explicit)] + [StructLayout(LayoutKind.Sequential)] internal struct DiskInfoRaw { - [FieldOffset(0)] public IntPtr Udi; - [FieldOffset(4)] public IntPtr DeviceNode; - [FieldOffset(8)] public IntPtr DriveName; + public IntPtr Udi; + public IntPtr DeviceNode; + public IntPtr DriveName; + } + + [StructLayout(LayoutKind.Sequential)] + internal struct CdDiskInfoRaw + { + public IntPtr device_node; + + public long n_tracks; + public long total_sectors; + public long total_time; + + public IntPtr tracks; + } + + [StructLayout(LayoutKind.Sequential)] + internal struct CdTrackInfoRaw + { + int number; + + int duration; + int minutes; + int seconds; + + long start_sector; + long end_sector; + long sectors; + long start_time; + long end_time; } public class AudioDisk { - public string Udi; - public string DeviceNode; - public string DriveName; - - [DllImport("libc")] - static extern int ioctl(int device, EjectOperation request); - - private enum EjectOperation { - Open = 0x5309, - Close = 0x5319 - } + private string udi; + private string deviceNode; + private string driveName; + + private int trackCount; + + [DllImport("libbanshee")] + private static extern IntPtr cd_disk_info_new(string device_node); + + [DllImport("libbanshee")] + private static extern void cd_disk_info_free(IntPtr diskPtr); + + public AudioDisk(string udi, string deviceNode, string driveName) + { + this.udi = udi; + this.deviceNode = deviceNode; + this.driveName = driveName; + + LoadDiskInfo(); + } + + private void LoadDiskInfo() + { + IntPtr diskPtr = cd_disk_info_new(deviceNode); + CdDiskInfoRaw diskRaw = (CdDiskInfoRaw)Marshal.PtrToStructure( + diskPtr, typeof(CdDiskInfoRaw)); + + trackCount = (int)diskRaw.n_tracks; + + cd_disk_info_free(diskPtr); + } + + [DllImport("libc")] + private static extern int ioctl(int device, EjectOperation request); + + private enum EjectOperation { + Open = 0x5309, + Close = 0x5319 + } public bool Eject() { return Eject(true); } - public bool Eject(bool open) - { - try { - using(UnixStream stream = UnixFile.Open(DeviceNode, - OpenFlags.O_RDONLY | OpenFlags.O_NONBLOCK)) { - return ioctl(stream.Handle, open - ? EjectOperation.Open - : EjectOperation.Close) == 0; - } - } catch { - return false; - } - } + public bool Eject(bool open) + { + try { + using(UnixStream stream = UnixFile.Open(deviceNode, + OpenFlags.O_RDONLY | OpenFlags.O_NONBLOCK)) { + return ioctl(stream.Handle, open + ? EjectOperation.Open + : EjectOperation.Close) == 0; + } + } catch { + return false; + } + } + + public string Udi + { + get { + return udi; + } + } + + public string DeviceNode + { + get { + return deviceNode; + } + } + + public string DriveName + { + get { + return driveName; + } + } + + public int TrackCount + { + get { + return trackCount; + } + } } - + public class AudioCdCore : IDisposable { private static AudioCdCore instance; @@ -142,10 +226,11 @@ namespace Banshee DiskInfoRaw diskRaw = (DiskInfoRaw)Marshal.PtrToStructure( rawPtr, typeof(DiskInfoRaw)); - AudioDisk disk = new AudioDisk(); - disk.Udi = Marshal.PtrToStringAnsi(diskRaw.Udi); - disk.DeviceNode = Marshal.PtrToStringAnsi(diskRaw.DeviceNode); - disk.DriveName = Marshal.PtrToStringAnsi(diskRaw.DriveName); + AudioDisk disk = new AudioDisk( + Marshal.PtrToStringAnsi(diskRaw.Udi), + Marshal.PtrToStringAnsi(diskRaw.DeviceNode), + Marshal.PtrToStringAnsi(diskRaw.DriveName) + ); disks[disk.Udi] = disk; } diff --git a/src/Library.cs b/src/Library.cs index c99cd2f59..3230397e2 100644 --- a/src/Library.cs +++ b/src/Library.cs @@ -279,7 +279,7 @@ namespace Banshee public override int Count { get { - return 0; + return disk.TrackCount; } } |