changeset 726:53a4210889e2

Move engine choosing / initialization code to xs_player.c
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 12 Jun 2009 18:31:19 +0300
parents 82be5d6b70ab
children 369c1f4414e2
files Makefile.am src/xmms-sid.c src/xs_player.c src/xs_player.h
diffstat 4 files changed, 79 insertions(+), 71 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile.am	Thu Feb 12 18:29:59 2009 +0200
+++ b/Makefile.am	Fri Jun 12 18:31:19 2009 +0300
@@ -101,9 +101,10 @@
 	src/xs_stil.c		src/xs_stil.h		\
 	src/xs_title.c		src/xs_title.h		\
 	src/xs_fileinfo.c	src/xs_fileinfo.h	\
-	src/xs_sidplay.h	src/xs_player.h		\
+	src/xs_sidplay.h				\
 	src/xs_sidplay1.cc	src/xs_sidplay1.h	\
 	src/xs_sidplay2.cc	src/xs_sidplay2.h	\
 	src/xs_slsup.c		src/xs_slsup.h		\
+	src/xs_player.c		src/xs_player.h		\
 	src/xmms-sid.c		src/xmms-sid.h
 
--- a/src/xmms-sid.c	Thu Feb 12 18:29:59 2009 +0200
+++ b/src/xmms-sid.c	Fri Jun 12 18:31:19 2009 +0300
@@ -42,46 +42,6 @@
 
 
 /*
- * Include player engines
- */
-#ifdef HAVE_SIDPLAY1
-#include "xs_sidplay1.h"
-#endif
-#ifdef HAVE_SIDPLAY2
-#include "xs_sidplay2.h"
-#endif
-
-
-/*
- * List of players and links to their functions
- */
-static const xs_player_t xs_playerlist[] = {
-#ifdef HAVE_SIDPLAY1
-    {XS_ENG_SIDPLAY1,
-     xs_sidplay1_probe,
-     xs_sidplay1_init, xs_sidplay1_close,
-     xs_sidplay1_initsong, xs_sidplay1_fillbuffer,
-     xs_sidplay1_load, xs_sidplay1_delete,
-     xs_sidplay1_getinfo, xs_sidplay1_updateinfo,
-     NULL
-    },
-#endif
-#ifdef HAVE_SIDPLAY2
-    {XS_ENG_SIDPLAY2,
-     xs_sidplay2_probe,
-     xs_sidplay2_init, xs_sidplay2_close,
-     xs_sidplay2_initsong, xs_sidplay2_fillbuffer,
-     xs_sidplay2_load, xs_sidplay2_delete,
-     xs_sidplay2_getinfo, xs_sidplay2_updateinfo,
-     xs_sidplay2_flush
-    },
-#endif
-};
-
-static const gint xs_nplayerlist = (sizeof(xs_playerlist) / sizeof(xs_playerlist[0]));
-
-
-/*
  * Global variables
  */
 xs_status_t xs_status;
@@ -164,34 +124,7 @@
     xs_status.oversampleFactor = xs_cfg.oversampleFactor;
 
     /* Try to initialize emulator engine */
-    XSDEBUG("initializing emulator engine #%i...\n", xs_cfg.playerEngine);
-
-    player = 0;
-    initialized = FALSE;
-    while ((player < xs_nplayerlist) && !initialized) {
-        if (xs_playerlist[player].plrIdent == xs_cfg.playerEngine) {
-            if (xs_playerlist[player].plrInit(&xs_status)) {
-                initialized = TRUE;
-                xs_status.sidPlayer = (xs_player_t *) & xs_playerlist[player];
-            }
-        }
-        player++;
-    }
-
-    XSDEBUG("init#1: %s, %i\n", (initialized) ? "OK" : "FAILED", player);
-
-    player = 0;
-    while ((player < xs_nplayerlist) && !initialized) {
-        if (xs_playerlist[player].plrInit(&xs_status)) {
-            initialized = TRUE;
-            xs_status.sidPlayer = (xs_player_t *) & xs_playerlist[player];
-            xs_cfg.playerEngine = xs_playerlist[player].plrIdent;
-        } else
-            player++;
-    }
-
-    XSDEBUG("init#2: %s, %i\n", (initialized) ? "OK" : "FAILED", player);
-
+    xs_init_emu_engine(&xs_cfg.playerEngine, &xs_status);
 
     /* Get settings back, in case the chosen emulator backend changed them */
     xs_cfg.audioFrequency = xs_status.audioFrequency;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/xs_player.c	Fri Jun 12 18:31:19 2009 +0300
@@ -0,0 +1,73 @@
+#include "xs_player.h"
+
+#ifdef HAVE_SIDPLAY1
+#include "xs_sidplay1.h"
+#endif
+#ifdef HAVE_SIDPLAY2
+#include "xs_sidplay2.h"
+#endif
+
+
+/* List of emulator engines
+ */
+static const xs_engine_t xs_enginelist[] = {
+#ifdef HAVE_SIDPLAY1
+    {XS_ENG_SIDPLAY1,
+     xs_sidplay1_probe,
+     xs_sidplay1_init, xs_sidplay1_close,
+     xs_sidplay1_initsong, xs_sidplay1_fillbuffer,
+     xs_sidplay1_load, xs_sidplay1_delete,
+     xs_sidplay1_getinfo, xs_sidplay1_updateinfo,
+     NULL
+    },
+#endif
+#ifdef HAVE_SIDPLAY2
+    {XS_ENG_SIDPLAY2,
+     xs_sidplay2_probe,
+     xs_sidplay2_init, xs_sidplay2_close,
+     xs_sidplay2_initsong, xs_sidplay2_fillbuffer,
+     xs_sidplay2_load, xs_sidplay2_delete,
+     xs_sidplay2_getinfo, xs_sidplay2_updateinfo,
+     xs_sidplay2_flush
+    },
+#endif
+};
+
+static const gint xs_nenginelist = (sizeof(xs_enginelist) / sizeof(xs_enginelist[0]));
+
+
+gboolean xs_init_emu_engine(int *configured, xs_status_t *status)
+{
+    gint engine;
+    gboolean initialized;
+    
+    XSDEBUG("initializing emulator engine #%i...\n", *configured);
+
+    engine = 0;
+    initialized = FALSE;
+    while (engine < xs_nenginelist && !initialized) {
+        if (xs_enginelist[engine].plrIdent == *configured) {
+            if (xs_enginelist[engine].plrInit(status)) {
+                initialized = TRUE;
+                status->sidPlayer = (xs_engine_t *) & xs_enginelist[engine];
+            }
+        }
+        engine++;
+    }
+
+    XSDEBUG("init#1: %s, %i\n", initialized ? "OK" : "FAILED", engine);
+
+    engine = 0;
+    while (engine < xs_nenginelist && !initialized) {
+        if (xs_enginelist[engine].plrInit(status)) {
+            initialized = TRUE;
+            status->sidPlayer = (xs_engine_t *) &xs_enginelist[engine];
+            *configured = xs_enginelist[engine].plrIdent;
+        } else
+            engine++;
+    }
+
+    XSDEBUG("init#2: %s, %i\n", initialized ? "OK" : "FAILED", engine);
+    return initialized;
+}
+
--- a/src/xs_player.h	Thu Feb 12 18:29:59 2009 +0200
+++ b/src/xs_player.h	Fri Jun 12 18:31:19 2009 +0300
@@ -22,7 +22,7 @@
     xs_tuneinfo_t*    (*plrGetSIDInfo)(const gchar *);
     gboolean    (*plrUpdateSIDInfo)(struct xs_status_t *);
     void        (*plrFlush)(struct xs_status_t *);
-} xs_player_t;
+} xs_engine_t;
 
 
 typedef struct xs_status_t {
@@ -36,7 +36,7 @@
                                     emulation backend supports oversampling.
                                     */
     void        *sidEngine;         /* SID-emulation internal engine data */
-    xs_player_t *sidPlayer;         /* Selected player engine */
+    xs_engine_t *sidPlayer;         /* Selected player engine */
     gboolean    isError,
                 isPlaying,
                 isInitialized;
@@ -54,6 +54,7 @@
 extern xs_status_t    xs_status;
 XS_MUTEX_H(xs_status);
 
+gboolean xs_init_emu_engine(int *configured, xs_status_t *status);
 
 #ifdef __cplusplus
 }