# HG changeset patch # User Matti Hamalainen # Date 1352428645 -7200 # Node ID b02f934d8224eac49a29327346632f6ff7cefbe2 # Parent d183ac29b879fd6e55aa07808929c687779594f0 Move some code to xs_backend. diff -r d183ac29b879 -r b02f934d8224 Makefile.am --- a/Makefile.am Fri Nov 09 04:24:48 2012 +0200 +++ b/Makefile.am Fri Nov 09 04:37:25 2012 +0200 @@ -131,6 +131,6 @@ src/xs_title.c src/xs_title.h \ src/xs_fileinfo.c src/xs_fileinfo.h \ src/xs_slsup.c src/xs_slsup.h \ - src/xs_player.h \ + src/xs_backend.c src/xs_backend.h \ src/xmms-sid.c src/xmms-sid.h diff -r d183ac29b879 -r b02f934d8224 src/xmms-sid.c --- a/src/xmms-sid.c Fri Nov 09 04:24:48 2012 +0200 +++ b/src/xmms-sid.c Fri Nov 09 04:37:25 2012 +0200 @@ -37,62 +37,10 @@ #include "xs_fileinfo.h" #include "xs_interface.h" #include "xs_glade.h" -#include "xs_player.h" +#include "xs_backend.h" #include "xs_slsup.h" -/* List of emulator engines - */ -#ifdef HAVE_SIDPLAY1 -# include "xs_sidplay1.h" -#endif -#ifdef HAVE_SIDPLAY2 -# include "xs_sidplay2.h" -#endif -#ifdef HAVE_SIDPLAYFP -# include "xs_sidplayfp.h" -#endif - -static XSEngine 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 -#ifdef HAVE_SIDPLAYFP - { - XS_ENG_SIDPLAYFP, - xs_sidplayfp_probe, - xs_sidplayfp_init, xs_sidplayfp_close, - xs_sidplayfp_initsong, xs_sidplayfp_fillbuffer, - xs_sidplayfp_load, xs_sidplayfp_delete, - xs_sidplayfp_getinfo, xs_sidplayfp_updateinfo, - xs_sidplayfp_flush - }, -#endif -}; - -static const gint xs_nenginelist = sizeof(xs_enginelist) / sizeof(xs_enginelist[0]); - - /* Global variables */ XSEngineState xs_status; @@ -137,9 +85,6 @@ */ void xs_reinit(void) { - gint engine; - gboolean initialized = FALSE; - /* Stop playing, if we are */ XS_MUTEX_LOCK(xs_status); if (xs_status.playing) @@ -176,19 +121,7 @@ xs_status.audioFormat = -1; /* Try to initialize emulator engine */ - XSDEBUG("initializing emulator engine #%i...\n", xs_cfg.playerEngine); - - for (engine = 0; engine < xs_nenginelist && !initialized; engine++) - { - if (xs_enginelist[engine].plrIdent == xs_cfg.playerEngine && - xs_enginelist[engine].plrInit(&xs_status)) - { - initialized = TRUE; - xs_status.engine = &xs_enginelist[engine]; - } - } - - XSDEBUG("init#1: %s, %i\n", initialized ? "OK" : "FAILED", xs_cfg.playerEngine); + xs_init_emu_backend(&xs_cfg.playerEngine); /* Get settings back, in case the chosen emulator backend changed them */ xs_cfg.audioFrequency = xs_status.audioFrequency; diff -r d183ac29b879 -r b02f934d8224 src/xs_backend.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/xs_backend.c Fri Nov 09 04:37:25 2012 +0200 @@ -0,0 +1,98 @@ +/* + XMMS-SID - SIDPlay input plugin for X MultiMedia System (XMMS) + + Backend handling + + Programmed and designed by Matti 'ccr' Hamalainen + (C) Copyright 1999-2012 Tecnic Software productions (TNSP) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ +#include "xs_backend.h" +#include "xs_config.h" + +/* List of emulator engines + */ +#ifdef HAVE_SIDPLAY1 +# include "xs_sidplay1.h" +#endif +#ifdef HAVE_SIDPLAY2 +# include "xs_sidplay2.h" +#endif +#ifdef HAVE_SIDPLAYFP +# include "xs_sidplayfp.h" +#endif + + +static XSEngine 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 +#ifdef HAVE_SIDPLAYFP + { + XS_ENG_SIDPLAYFP, + xs_sidplayfp_probe, + xs_sidplayfp_init, xs_sidplayfp_close, + xs_sidplayfp_initsong, xs_sidplayfp_fillbuffer, + xs_sidplayfp_load, xs_sidplayfp_delete, + xs_sidplayfp_getinfo, xs_sidplayfp_updateinfo, + xs_sidplayfp_flush + }, +#endif +}; + +static const gint xs_nenginelist = sizeof(xs_enginelist) / sizeof(xs_enginelist[0]); + + +gboolean xs_initialize_emu_backend(XSEngineState *state, gint *preferred) +{ + gint engine; + gboolean initialized = FALSE; + + XSDEBUG("trying emulator engine #%i...\n", *preferred); + + for (engine = 0; engine < xs_nenginelist && !initialized; engine++) + { + if (xs_enginelist[engine].plrIdent == *preferred && + xs_enginelist[engine].plrInit(state)) + { + initialized = TRUE; + state->engine = &xs_enginelist[engine]; + } + } + + XSDEBUG("init#1: %s, %i\n", initialized ? "OK" : "FAILED", *preferred); + return initialized; +} diff -r d183ac29b879 -r b02f934d8224 src/xs_backend.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/xs_backend.h Fri Nov 09 04:37:25 2012 +0200 @@ -0,0 +1,52 @@ +#ifndef XS_PLAYER_H +#define XS_PLAYER_H + +#include "xmms-sid.h" +#include "xs_support.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct XSEngineState; + +typedef struct { + gint plrIdent; + gboolean (*plrProbe)(XSFile *); + gboolean (*plrInit)(struct XSEngineState *); + void (*plrClose)(struct XSEngineState *); + gboolean (*plrInitSong)(struct XSEngineState *); + guint (*plrFillBuffer)(struct XSEngineState *, gchar *, guint); + gboolean (*plrLoadSID)(struct XSEngineState *, gchar *); + void (*plrDeleteSID)(struct XSEngineState *); + XSTuneInfo* (*plrGetSIDInfo)(const gchar *); + gboolean (*plrUpdateSIDInfo)(struct XSEngineState *); + void (*plrFlush)(struct XSEngineState *); +} XSEngine; + + +typedef struct XSEngineState { + gint audioFrequency, /* Audio settings */ + audioChannels, + audioBitsPerSample; + AFormat audioFormat; + + void *internal; /* SID-emulation internal engine data */ + XSEngine *engine; /* Selected player engine */ + gboolean error, + playing, + paused; + gint currSong, /* Current sub-tune */ + lastTime; + + XSTuneInfo *tuneInfo; +} XSEngineState; + + +gboolean xs_initialize_emu_backend(XSEngineState *state, gint *preferred); + + +#ifdef __cplusplus +} +#endif +#endif /* XS_PLAYER_H */ diff -r d183ac29b879 -r b02f934d8224 src/xs_fileinfo.c --- a/src/xs_fileinfo.c Fri Nov 09 04:24:48 2012 +0200 +++ b/src/xs_fileinfo.c Fri Nov 09 04:37:25 2012 +0200 @@ -24,7 +24,7 @@ #include #include "xs_fileinfo.h" -#include "xs_player.h" +#include "xs_backend.h" #include "xs_support.h" #include "xs_config.h" #include "xs_interface.h" diff -r d183ac29b879 -r b02f934d8224 src/xs_player.h --- a/src/xs_player.h Fri Nov 09 04:24:48 2012 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,48 +0,0 @@ -#ifndef XS_PLAYER_H -#define XS_PLAYER_H - -#include "xmms-sid.h" - -#ifdef __cplusplus -extern "C" { -#endif - -struct XSEngineState; - -typedef struct { - gint plrIdent; - gboolean (*plrProbe)(XSFile *); - gboolean (*plrInit)(struct XSEngineState *); - void (*plrClose)(struct XSEngineState *); - gboolean (*plrInitSong)(struct XSEngineState *); - guint (*plrFillBuffer)(struct XSEngineState *, gchar *, guint); - gboolean (*plrLoadSID)(struct XSEngineState *, gchar *); - void (*plrDeleteSID)(struct XSEngineState *); - XSTuneInfo* (*plrGetSIDInfo)(const gchar *); - gboolean (*plrUpdateSIDInfo)(struct XSEngineState *); - void (*plrFlush)(struct XSEngineState *); -} XSEngine; - - -typedef struct XSEngineState { - gint audioFrequency, /* Audio settings */ - audioChannels, - audioBitsPerSample; - AFormat audioFormat; - - void *internal; /* SID-emulation internal engine data */ - XSEngine *engine; /* Selected player engine */ - gboolean error, - playing, - paused; - gint currSong, /* Current sub-tune */ - lastTime; - - XSTuneInfo *tuneInfo; -} XSEngineState; - - -#ifdef __cplusplus -} -#endif -#endif /* XS_PLAYER_H */ diff -r d183ac29b879 -r b02f934d8224 src/xs_sidplay1.h --- a/src/xs_sidplay1.h Fri Nov 09 04:24:48 2012 +0200 +++ b/src/xs_sidplay1.h Fri Nov 09 04:37:25 2012 +0200 @@ -1,7 +1,7 @@ #ifndef XS_SIDPLAY1_H #define XS_SIDPLAY1_H -#include "xs_player.h" +#include "xs_backend.h" #include "xs_support.h" #ifdef __cplusplus diff -r d183ac29b879 -r b02f934d8224 src/xs_sidplay2.h --- a/src/xs_sidplay2.h Fri Nov 09 04:24:48 2012 +0200 +++ b/src/xs_sidplay2.h Fri Nov 09 04:37:25 2012 +0200 @@ -1,7 +1,7 @@ #ifndef XS_SIDPLAY2_H #define XS_SIDPLAY2_H -#include "xs_player.h" +#include "xs_backend.h" #include "xs_support.h" #ifdef __cplusplus diff -r d183ac29b879 -r b02f934d8224 src/xs_sidplayfp.h --- a/src/xs_sidplayfp.h Fri Nov 09 04:24:48 2012 +0200 +++ b/src/xs_sidplayfp.h Fri Nov 09 04:37:25 2012 +0200 @@ -1,7 +1,7 @@ #ifndef XS_SIDPLAYFP_H #define XS_SIDPLAYFP_H -#include "xs_player.h" +#include "xs_backend.h" #include "xs_support.h" #ifdef __cplusplus