[Goodies-commits] r5576 - xfburn/trunk/xfburn

David Mohr squisher at xfce.org
Sun Oct 12 02:53:33 CEST 2008


Author: squisher
Date: 2008-10-12 00:53:33 +0000 (Sun, 12 Oct 2008)
New Revision: 5576

Modified:
   xfburn/trunk/xfburn/Makefile.am
   xfburn/trunk/xfburn/xfburn-audio-composition.c
   xfburn/trunk/xfburn/xfburn-main.c
   xfburn/trunk/xfburn/xfburn-transcoder-basic.c
   xfburn/trunk/xfburn/xfburn-transcoder.c
   xfburn/trunk/xfburn/xfburn-transcoder.h
Log:
Moving basic audio detection code into transcoder-basic, adding code for using GError in xfburn

Modified: xfburn/trunk/xfburn/Makefile.am
===================================================================
--- xfburn/trunk/xfburn/Makefile.am	2008-10-11 22:10:02 UTC (rev 5575)
+++ xfburn/trunk/xfburn/Makefile.am	2008-10-12 00:53:33 UTC (rev 5576)
@@ -10,6 +10,7 @@
 
 xfburn_headers = 							\
 	xfburn-global.h							\
+	xfburn-error.h							\
 	xfburn-adding-progress.h					\
 	xfburn-blank-dialog.h						\
 	xfburn-perform-burn.h						\
@@ -46,6 +47,7 @@
 	
 xfburn_SOURCES =							\
 	$(xfburn_headers)						\
+	xfburn-error.c          					\
 	xfburn-adding-progress.c					\
 	xfburn-blank-dialog.c						\
 	xfburn-perform-burn.c						\

Modified: xfburn/trunk/xfburn/xfburn-audio-composition.c
===================================================================
--- xfburn/trunk/xfburn/xfburn-audio-composition.c	2008-10-11 22:10:02 UTC (rev 5575)
+++ xfburn/trunk/xfburn/xfburn-audio-composition.c	2008-10-12 00:53:33 UTC (rev 5576)
@@ -29,11 +29,6 @@
 #include <string.h>
 #endif
 
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <fcntl.h>
-
 #include <errno.h>
 
 #include <gtk/gtk.h>
@@ -50,6 +45,7 @@
 
 #include "xfburn-audio-composition.h"
 #include "xfburn-global.h"
+#include "xfburn-error.h"
 
 #include "xfburn-adding-progress.h"
 #include "xfburn-composition.h"
@@ -57,6 +53,7 @@
 #include "xfburn-main-window.h"
 #include "xfburn-utils.h"
 #include "xfburn-burn-audio-cd-composition-dialog.h"
+#include "xfburn-transcoder.h"
 
 #define XFBURN_AUDIO_COMPOSITION_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), XFBURN_TYPE_AUDIO_COMPOSITION, XfburnAudioCompositionPrivate))
 
@@ -167,9 +164,6 @@
                                                    GtkTreeIter * insertion, GtkTreeViewDropPosition position);
 static gboolean thread_add_file_to_list (XfburnAudioComposition * dc, GtkTreeModel * model, const gchar * path, 
                                          GtkTreeIter * iter, GtkTreeIter * insertion, GtkTreeViewDropPosition position);
-static gboolean has_audio_ext (const gchar *path);
-static gboolean valid_wav_headers (guchar header[44]);
-static gboolean is_valid_wav (const gchar *path);
                                   
 typedef struct
 {
@@ -200,6 +194,7 @@
   GtkWidget *disc_usage;
   GtkWidget *progress;
 
+  XfburnTranscoder *trans;
 } XfburnAudioCompositionPrivate;
 
 /* globals */
@@ -468,6 +463,8 @@
                     
   action = gtk_action_group_get_action (priv->action_group, "remove-file");
   gtk_action_set_sensitive (GTK_ACTION (action), FALSE);
+
+  priv->trans = xfburn_transcoder_get_global ();
 }
 
 static void
@@ -489,6 +486,9 @@
       icon_file = NULL;
     }
   }
+
+  g_object_unref (priv->trans);
+  priv->trans = NULL;
   
   G_OBJECT_CLASS (parent_class)->finalize (object);
 }
@@ -778,7 +778,10 @@
     priv->full_paths_to_add = NULL;
   }
 
-  g_free (priv->thread_params);
+  if (priv->thread_params) {
+    g_free (priv->thread_params);
+    priv->thread_params = NULL;
+  }
 
   tracks_changed (dc);
 
@@ -1028,92 +1031,6 @@
   }
 }
 
-static gboolean 
-has_audio_ext (const gchar *path)
-{
-  int len = strlen (path);
-  const gchar *ext = path + len - 3;
-
-  return (strcmp (ext, "wav") == 0);
-}
-
-static gboolean 
-is_valid_wav (const gchar *path)
-{
-  int fd;
-  guchar header[44];
-  gboolean ret;
-
-  fd = open (path, 0);
-
-  if (fd == -1) {
-    xfce_warn (_("Could not open %s!"), path);
-    return FALSE;
-  }
-
-  read (fd, header, 44);
-
-  ret = valid_wav_headers (header);
-
-  close (fd);
-
-  return ret;
-}
-
-/*
- * Simple check of .wav headers, most info from
- * http://ccrma.stanford.edu/courses/422/projects/WaveFormat/
- *
- * This check might very well not be complete, but should catch
- * the most important pieces.
- * FIXME: eventually replace this with a proper check,
- * also this works on x86, and does not consider endianness!
- */
-static gboolean
-valid_wav_headers (guchar header[44])
-{
-  /* check if first 4 bytes are RIFF or RIFX */
-  if (header[0] == 'R' && header[1] == 'I' && header[2] == 'F') {
-    if (!(header[3] == 'X' || header[3] == 'F')) {
-      g_warning ("File not in riff format");
-      return FALSE;
-    }
-  }
-
-  /* check if bytes 8-11 are WAVE */
-  if (!(header[8] == 'W' && header[9] == 'A' && header[10] == 'V' && header[11] == 'E')) {
-    g_warning ("RIFF file not in WAVE format");
-    return FALSE;
-  }
-
-  /* subchunk starts with 'fmt ' */
-  if (!(header[12] == 'f' && header[13] == 'm' && header[14] == 't' && header[15] == ' ')) {
-    g_warning ("Could not find format subchunk");
-    return FALSE;
-  }
-
-  /* check for PCM format */
-  if (header[16] != 16 || header[20] != 1) {
-    g_warning ("Not in PCM format");
-    return FALSE;
-  }
-
-  /* check for stereo */
-  if (header[22] != 2) {
-    g_warning ("Not in stereo");
-    return FALSE;
-  }
-
-  /* check for 44100 Hz sample rate,
-   * being lazy here and just compare the bytes to what I know they should be */
-  if (!(header[24] == 0x44 && header[25] == 0xAC && header[26] == 0 && header[27] == 0)) {
-    g_warning ("Does not have a sample rate of 44100 Hz");
-    return FALSE;
-  }
-
-  return TRUE;
-}
-
 static void
 notify_not_adding (XfburnAudioComposition * dc, XfburnNotAddingReason r, const gchar *path)
 {
@@ -1240,19 +1157,25 @@
     }
     /* new file */
     else if (S_ISREG (s.st_mode)) {
-      if (!has_audio_ext (path)) {
-        gdk_threads_enter ();
-        notify_not_adding (dc, NOT_ADDING_EXT, path);
-        gdk_threads_leave ();
-        return FALSE;
-      }
+      GError *error = NULL;
 
-      if (!is_valid_wav (path)) {
+      DBG ("foo1");
+      if (!xfburn_transcoder_is_audio_file (priv->trans, path, &error)) {
+        XfburnNotAddingReason reason;
+
+        if (error->code == XFBURN_ERROR_NOT_AUDIO_EXT)
+          reason = NOT_ADDING_EXT;
+        else if (error->code == XFBURN_ERROR_NOT_AUDIO_FORMAT)
+          reason = NOT_ADDING_FMT;
+
+        g_error_free (error);
+
         gdk_threads_enter ();
-        notify_not_adding (dc, NOT_ADDING_FMT, path);
+        notify_not_adding (dc, reason, path);
         gdk_threads_leave ();
         return FALSE;
       }
+      DBG ("bar1");
 
       gdk_threads_enter ();
       if (insertion != NULL) {
@@ -1726,12 +1649,16 @@
         full_path[strlen (full_path) - 1] = '\0';
 
       /* remember path to add it later in another thread */
-      if (has_audio_ext (full_path)) {
+      priv->full_paths_to_add = g_list_append (priv->full_paths_to_add, full_path);
+      ret = TRUE;
+      /*
+      if (xfburn_transcoder_is_audio_file (priv->trans, full_path, NULL)) {
         priv->full_paths_to_add = g_list_append (priv->full_paths_to_add, full_path);
         ret = TRUE;
       } else {
         notify_not_adding (composition, NOT_ADDING_EXT, full_path);
       }
+      */
 
       file = strtok (NULL, "\n");
     }
@@ -1778,12 +1705,17 @@
         full_path = thunar_vfs_path_dup_string (path);
         g_debug ("adding uri path: %s", full_path);
 
-        if (has_audio_ext (full_path)) {
+        priv->full_paths_to_add = g_list_prepend (priv->full_paths_to_add, full_path);
+        ret = TRUE;
+        /*
+        if (xfburn_transcoder_is_audio_file (priv->trans, full_path, NULL)) {
           priv->full_paths_to_add = g_list_prepend (priv->full_paths_to_add, full_path);
           ret = TRUE;
         } else {
+          g_error_free (error);
           notify_not_adding (composition, NOT_ADDING_EXT, full_path);
         }
+        */
       }
       thunar_vfs_path_list_free (vfs_paths);
 

Modified: xfburn/trunk/xfburn/xfburn-main.c
===================================================================
--- xfburn/trunk/xfburn/xfburn-main.c	2008-10-11 22:10:02 UTC (rev 5575)
+++ xfburn/trunk/xfburn/xfburn-main.c	2008-10-12 00:53:33 UTC (rev 5576)
@@ -298,7 +298,7 @@
   }
 
   transcoder = XFBURN_TRANSCODER (xfburn_transcoder_basic_new ());
-  xfburn_set_transcoder (transcoder);
+  xfburn_transcoder_set_global (transcoder);
 
   /* evaluate parsed command line options */
 

Modified: xfburn/trunk/xfburn/xfburn-transcoder-basic.c
===================================================================
--- xfburn/trunk/xfburn/xfburn-transcoder-basic.c	2008-10-11 22:10:02 UTC (rev 5575)
+++ xfburn/trunk/xfburn/xfburn-transcoder-basic.c	2008-10-12 00:53:33 UTC (rev 5576)
@@ -26,20 +26,33 @@
 #include <string.h>
 #endif
 
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <fcntl.h>
+
 #include <libxfce4util/libxfce4util.h>
 #include <libxfcegui4/libxfcegui4.h>
 
 #include "xfburn-global.h"
+#include "xfburn-error.h"
 
 #include "xfburn-transcoder-basic.h"
 
+/** Prototypes **/
+/* class initialization */
 static void xfburn_transcoder_basic_class_init (XfburnTranscoderBasicClass * klass);
 static void xfburn_transcoder_basic_init (XfburnTranscoderBasic * obj);
 static void xfburn_transcoder_basic_finalize (GObject * object);
 static void transcoder_interface_init (XfburnTranscoderInterface *iface, gpointer iface_data);
 
-static gboolean is_audio_file (XfburnTranscoder *trans, const gchar *fn);
+/* internals */
+static gboolean is_audio_file (XfburnTranscoder *trans, const gchar *fn, GError **error);
+static gboolean has_audio_ext (const gchar *path);
+static gboolean is_valid_wav (const gchar *path);
+static gboolean valid_wav_headers (guchar header[44]);
 
+
 #define XFBURN_TRANSCODER_BASIC_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), XFBURN_TYPE_TRANSCODER_BASIC, XfburnTranscoderBasicPrivate))
 
 enum {
@@ -131,12 +144,107 @@
 /*           */
 
 static gboolean
-is_audio_file (XfburnTranscoder *trans, const gchar *fn)
+is_audio_file (XfburnTranscoder *trans, const gchar *fn, GError **error)
 {
-  g_message ("TranscoderBasic is_audio_file");
-  return FALSE;
+  if (!has_audio_ext (fn)) {
+    g_set_error (error, XFBURN_ERROR, XFBURN_ERROR_NOT_AUDIO_EXT,
+                 "File %s does not have a .wav extension", fn);
+    return FALSE;
+  }
+  if (!is_valid_wav (fn)) {
+    g_set_error (error, XFBURN_ERROR, XFBURN_ERROR_NOT_AUDIO_FORMAT,
+                 "File %s does not contain uncompressed PCM wave audio", fn);
+    return FALSE;
+  }
+
+  return TRUE;
 }
 
+static gboolean 
+has_audio_ext (const gchar *path)
+{
+  int len = strlen (path);
+  const gchar *ext = path + len - 3;
+
+  return (strcmp (ext, "wav") == 0);
+}
+
+static gboolean 
+is_valid_wav (const gchar *path)
+{
+  int fd;
+  guchar header[44];
+  gboolean ret;
+
+  fd = open (path, 0);
+
+  if (fd == -1) {
+    xfce_warn (_("Could not open %s!"), path);
+    return FALSE;
+  }
+
+  read (fd, header, 44);
+
+  ret = valid_wav_headers (header);
+
+  close (fd);
+
+  return ret;
+}
+
+/*
+ * Simple check of .wav headers, most info from
+ * http://ccrma.stanford.edu/courses/422/projects/WaveFormat/
+ *
+ * I did not take particular care to make sure this check is complete.
+ * As far as I can tell yes, but not much effort was put into verifying it.
+ * FIXME: this works on x86, and does not consider endianness!
+ */
+static gboolean
+valid_wav_headers (guchar header[44])
+{
+  /* check if first 4 bytes are RIFF or RIFX */
+  if (header[0] == 'R' && header[1] == 'I' && header[2] == 'F') {
+    if (!(header[3] == 'X' || header[3] == 'F')) {
+      g_warning ("File not in riff format");
+      return FALSE;
+    }
+  }
+
+  /* check if bytes 8-11 are WAVE */
+  if (!(header[8] == 'W' && header[9] == 'A' && header[10] == 'V' && header[11] == 'E')) {
+    g_warning ("RIFF file not in WAVE format");
+    return FALSE;
+  }
+
+  /* subchunk starts with 'fmt ' */
+  if (!(header[12] == 'f' && header[13] == 'm' && header[14] == 't' && header[15] == ' ')) {
+    g_warning ("Could not find format subchunk");
+    return FALSE;
+  }
+
+  /* check for PCM format */
+  if (header[16] != 16 || header[20] != 1) {
+    g_warning ("Not in PCM format");
+    return FALSE;
+  }
+
+  /* check for stereo */
+  if (header[22] != 2) {
+    g_warning ("Not in stereo");
+    return FALSE;
+  }
+
+  /* check for 44100 Hz sample rate,
+   * being lazy here and just compare the bytes to what I know they should be */
+  if (!(header[24] == 0x44 && header[25] == 0xAC && header[26] == 0 && header[27] == 0)) {
+    g_warning ("Does not have a sample rate of 44100 Hz");
+    return FALSE;
+  }
+
+  return TRUE;
+}
+
 /*        */
 /* public */
 /*        */

Modified: xfburn/trunk/xfburn/xfburn-transcoder.c
===================================================================
--- xfburn/trunk/xfburn/xfburn-transcoder.c	2008-10-11 22:10:02 UTC (rev 5575)
+++ xfburn/trunk/xfburn/xfburn-transcoder.c	2008-10-12 00:53:33 UTC (rev 5576)
@@ -91,11 +91,11 @@
 /*        */
 
 gboolean
-xfburn_transcoder_is_audio_file (XfburnTranscoder *trans, const gchar *fn)
+xfburn_transcoder_is_audio_file (XfburnTranscoder *trans, const gchar *fn, GError **error)
 {
   XfburnTranscoderInterface *iface = XFBURN_TRANSCODER_GET_INTERFACE (trans);
   if (iface->is_audio_file)
-    return iface->is_audio_file (trans, fn);
+    return iface->is_audio_file (trans, fn, error);
   
   g_warning ("Falling back to base implementation for xfburn_transcoder_is_audio_file, which always says false.");
   return FALSE;
@@ -103,13 +103,14 @@
 
 
 void 
-xfburn_set_transcoder (XfburnTranscoder *trans)
+xfburn_transcoder_set_global (XfburnTranscoder *trans)
 {
   transcoder = trans;
 }
 
 XfburnTranscoder *
-xfburn_get_transcoder()
+xfburn_transcoder_get_global ()
 {
+  g_object_ref (transcoder);
   return transcoder;
 }

Modified: xfburn/trunk/xfburn/xfburn-transcoder.h
===================================================================
--- xfburn/trunk/xfburn/xfburn-transcoder.h	2008-10-11 22:10:02 UTC (rev 5575)
+++ xfburn/trunk/xfburn/xfburn-transcoder.h	2008-10-12 00:53:33 UTC (rev 5576)
@@ -41,15 +41,15 @@
 {
   GTypeInterface parent;
 
-  gboolean (*is_audio_file) (XfburnTranscoder *trans, const gchar *fn);
+  gboolean (*is_audio_file) (XfburnTranscoder *trans, const gchar *fn, GError **error);
   
 } XfburnTranscoderInterface;
 
 GtkType xfburn_transcoder_get_type ();
-gboolean xfburn_transcode_is_audio_file (XfburnTranscoder *trans);
+gboolean xfburn_transcoder_is_audio_file (XfburnTranscoder *trans, const gchar *fn, GError **error);
 
-void xfburn_set_transcoder (XfburnTranscoder *trans);
-XfburnTranscoder *xfburn_get_transcoder();
+void xfburn_transcoder_set_global (XfburnTranscoder *trans);
+XfburnTranscoder *xfburn_transcoder_get_global ();
 
 G_END_DECLS
 




More information about the Goodies-commits mailing list