diff src/madplug/decoder.c @ 896:f0846bdd9de6 trunk

[svn] - small cleanups.
author yaz
date Sat, 24 Mar 2007 09:44:44 -0700
parents 0f9c8d4d3ac4
children a8494c2a87eb
line wrap: on
line diff
--- a/src/madplug/decoder.c	Sat Mar 24 09:29:41 2007 -0700
+++ b/src/madplug/decoder.c	Sat Mar 24 09:44:44 2007 -0700
@@ -377,6 +377,19 @@
     return (info->frames != 0 || info->remote == TRUE);
 }
 
+// sanity check for audio open parameters
+static gboolean check_audio_param(struct mad_info_t *info)
+{
+    if(info->fmt < FMT_U8 || info->fmt > FMT_S16_NE)
+        return FALSE;
+    if(info->freq < 0) // not sure about maximum frequency. --yaz
+        return FALSE;
+    if(info->channels < 1 || info->channels > 2)
+        return FALSE;
+
+    return TRUE;
+}
+
 gpointer decode_loop(gpointer arg)
 {
     unsigned char buffer[BUFFER_SIZE];
@@ -413,14 +426,10 @@
 #ifdef DEBUG
     g_message("decode: fmt = %d freq = %d channels = %d", info->fmt, info->freq, info->channels);
 #endif
-    // sanity check.
-    if(info->fmt < FMT_U8 || info->fmt > FMT_S16_NE)
+
+    if(check_audio_param(info) == FALSE)
         return NULL;
-    if(info->freq < 0) // not sure about maximum frequency. --yaz
-        return NULL;
-    if(info->channels < 1 || info->channels > 2)
-        return NULL;
-    
+
     if (!info->playback->output->open_audio(info->fmt, info->freq, info->channels)) {
         g_mutex_lock(pb_mutex);
         info->playback->error = TRUE;
@@ -506,7 +515,7 @@
         while (info->playback->playing) {
             if (info->seek != -1 && info->size > 0) {
 #ifdef DEBUG
-                g_message("seeking: %d", info->seek);
+                g_message("seeking: %ld", info->seek);
 #endif
                 int new_position;
                 gulong milliseconds =
@@ -598,12 +607,7 @@
                 info->channels = MAD_NCHANNELS(&frame.header);
                 info->playback->output->close_audio();
 
-                // sanity check.
-                if(info->fmt < FMT_U8 || info->fmt > FMT_S16_NE)
-                    return NULL;
-                if(info->freq < 0) // not sure about maximum frequency. --yaz
-                    return NULL;
-                if(info->channels < 1 || info->channels > 2)
+                if(check_audio_param(info) == FALSE)
                     return NULL;
 
                 if (!info->playback->output->open_audio(info->fmt, info->freq,
@@ -648,11 +652,11 @@
             
             g_mutex_lock(mad_mutex);
             g_cond_timed_wait(mad_cond, mad_mutex, &sleeptime);
+            g_mutex_unlock(mad_mutex);
             if (!info->playback->playing) {
-                g_mutex_unlock(mad_mutex);
                 break;
             }
-            g_mutex_unlock(mad_mutex);
+
         }
     }
 #ifdef DEBUG