Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/README b/README
- index cd35424f..4803d147 100644
- --- a/README
- +++ b/README
- @@ -57,3 +57,55 @@ actual package names for your Linux distribution may vary.
- 2. licensing
- DeaDBeeF core uses ZLIB license. See COPYING in each subdirectory for details.
- +
- +
- +
- +
- +
- +---------------------------
- +
- +MinGW section
- +(please note, this whole source code tree is still a work in progress - no warranty provided)
- +
- +The needed libraries above will build and install almost out-of-the-box.
- +For jansson, download some recent version (>=2.8), because I committed a fix for mingw environment which allows the full test suite to complete.
- +
- +With recent versions of pthreads-win32 (installed with msys1/mingw) you'll have to comment out the declaration of timespec struct type (into pthread.h), since it is already declared in parts/time.h and having both will raise a compilation error. (seems this is not needed anymore...)
- +
- +You'll get a ready-to-go binary zip file with GTK+2.24.10 on www.gtk.org, it contains also every single dependency library needed for deadbeef (gdk, glib, gthread, pango, cairo, atk and so on) and they're all built as DLL.
- +Well, if you prefer GTK+3 or any other gtk release, feel free to try. Version 2 is what I used, since it is easy to go with.
- +
- +At the time of writing, I am quite confident a minimal deadbeef binary can be built with:
- +
- +./configure --disable-vtx --disable-gme --disable-sid --disable-adplug --disable-wildmidi --disable-psf --disable-dumb --disable-shn --disable-sc68 --disable-shellexec --disable-ffap --disable-nls --disable-converter
- +
- +It will support mpeg1/2 (if you install libmad and/or mpg123), aac (if you install faad2), vorbis (if you install libogg and libvorbis), musepack (it is shipped with deadbeef), flac (if you install flac), wavpack (if you install wavpack), sndfile (if you install libsndfile) and wma decoding (shipped) and resampling (if you install libsamplerate aka SecretRabbitCode). (maybe something else, disable what's unwanted)
- +
- +The default null output plugin will be built, and I added a nice feature simulating real audio output delay. Quite useful, sometimes.
- +The WaveOut output plugin version 1.0 is now ready and it can play sounds through any audio device your OS currently supports. The deadbeef preference window lets you choose among the devices detected by the plugin.
- +QUALITY: a few tests I run on Windows7 platform (NOT into a VM) revealed some audio artifact and far metallic echoes during playback. The same audio source sounds far better when played through DirectSound API (same hardware involved). Well, the WaveOut plugin has no flaws (none I'm aware of), IMHO this means the audio content is "enriched" with a light DSP by the audio driver in the latter case. After all, the WaveOut interface is pretty old and those kind of scenarios may push everyone in software migration. If I'll have some time, then I'll write a DirectSound output plugin, although the current WaveOut plugin works indeed.
- +
- +After the usual 'make' the main executable should be built (linking against wsock32 is needed).
- +Note: chances are that recent mingw compiler (gcc) creates an executable which needs an extra lib, called libgcc_s_dw2-1.dll.
- +Now, want a static deadbeef executable (I do) ? Then add the '-static' option to the compiler command line.
- +Have static and shared versions of pthreads libraries (I do) ? The default behaviour is to build against the shared version (dll) but you'll have to ship the library together with your executable. If this is not what you want, then add the '-D_PTW32_STATIC_LIB' definition to the preprocessor flags and you will get deadbeef.exe with no pthread dependency.
- +
- +Now, 'make install' will install the package and you will be able to run deadbeef but - nothing else will happen.
- +Why?
- +Plugins are missing! - well, they are yet to be built for windows environment, that is, they have to be built as dll libraries.
- +
- +This step is pretty easy - just annoying.
- +Go into the plugin directory (you have to follow this step for every plugin you want to build/install) and type:
- +
- +gcc -s -shared -o somethingplugin.dll *.o libdependency.a -Wl,-no-undefined -Wl,--enable-runtime-pseudo-reloc
- +
- +where somethingplugin.dll is the name of the output dll. Replace that *.o with the object files created by make (usually you'll find them into .libs/) and those libdependency.a with the library needed for the full linking process. For example, when linking the mp3 deconding library, mp3.dll, you will need to link libmad.a (and/or libmpg123.a) also (include their FULL path!).
- +Naming: IT IS MANDATORY the dll has to be named as the plugin it contains (and case DOES matter)! If different, deadbeef won't find the entry point for the functions it searches it in.
- +The only exception is for gui plugins, they are named accordingly to the rules reported here https://github.com/Alexey-Yakovenko/deadbeef/wiki/Developing-your-own-plugin . Anyway, if in doubt, name the plugin exactly as its linux counterpart, just with .dll extension.
- +
- +Copy the dll file into the plugins/ directory and the whole game will play nicely.
- +
- +Have fun.
- +
- +Elio
- +
- diff --git a/conf.c b/conf.c
- index ab774e91..0b4fbaa5 100644
- --- a/conf.c
- +++ b/conf.c
- @@ -27,6 +27,10 @@
- #endif
- #include <stdio.h>
- #include <stdint.h>
- +#ifdef __MINGW32__
- +#undef __STRICT_ANSI__
- +#undef _NO_OLDNAMES
- +#endif
- #include <string.h>
- #include <stdlib.h>
- #include <limits.h>
- @@ -45,7 +49,7 @@
- static DB_conf_item_t *conf_items;
- static int changed = 0;
- -static uintptr_t mutex;
- +static db_mutex_t mutex;
- void
- conf_init (void) {
- @@ -83,7 +87,11 @@ conf_load (void) {
- char fname[l + sizeof(configfile)];
- memcpy (fname, dbconfdir, l);
- memcpy (fname + l, configfile, sizeof (configfile));
- +#ifdef __MINGW32__
- + FILE *fp = fopen (fname, "rb");
- +#else
- FILE *fp = fopen (fname, "rt");
- +#endif
- if (!fp) {
- fprintf (stderr, "failed to load config file\n");
- fp = fopen (fname, "w+b");
- @@ -104,6 +112,7 @@ conf_load (void) {
- uint8_t *buffer = malloc (l+1);
- if (l != fread (buffer, 1, l, fp)) {
- free (buffer);
- + fclose (fp);
- fprintf (stderr, "failed to read entire config file to memory\n");
- return -1;
- }
- @@ -187,6 +196,10 @@ conf_save (void) {
- }
- }
- fclose (fp);
- +#ifdef __MINGW32__
- + if (unlink(str)!=0)
- + fprintf (stderr, "deleting %s failed: %s\n", str, strerror (errno));
- +#endif
- err = rename (tempfile, str);
- if (err != 0) {
- fprintf (stderr, "config rename %s -> %s failed: %s\n", tempfile, str, strerror (errno));
- diff --git a/deadbeef.h b/deadbeef.h
- index 72faa83b..5017c117 100644
- --- a/deadbeef.h
- +++ b/deadbeef.h
- @@ -29,6 +29,7 @@
- #include <time.h>
- #include <stdio.h>
- #include <dirent.h>
- +#include "threading.h"
- #ifdef __cplusplus
- extern "C" {
- @@ -598,21 +599,23 @@ typedef struct {
- void (*quit) (void);
- // threading
- - intptr_t (*thread_start) (void (*fn)(void *ctx), void *ctx);
- - intptr_t (*thread_start_low_priority) (void (*fn)(void *ctx), void *ctx);
- - int (*thread_join) (intptr_t tid);
- - int (*thread_detach) (intptr_t tid);
- + db_thread_t (*thread_start) (void (*fn)(void *ctx), void *ctx);
- + db_thread_t (*thread_start_low_priority) (void (*fn)(void *ctx), void *ctx);
- + int (*thread_join) (db_thread_t tid);
- + int (*thread_detach) (db_thread_t tid);
- + int (*thread_alive) (db_thread_t tid);
- + void (*thread_wipeid) (db_thread_t *tid);
- void (*thread_exit) (void *retval);
- - uintptr_t (*mutex_create) (void);
- - uintptr_t (*mutex_create_nonrecursive) (void);
- - void (*mutex_free) (uintptr_t mtx);
- - int (*mutex_lock) (uintptr_t mtx);
- - int (*mutex_unlock) (uintptr_t mtx);
- - uintptr_t (*cond_create) (void);
- - void (*cond_free) (uintptr_t cond);
- - int (*cond_wait) (uintptr_t cond, uintptr_t mutex);
- - int (*cond_signal) (uintptr_t cond);
- - int (*cond_broadcast) (uintptr_t cond);
- + db_mutex_t (*mutex_create) (void);
- + db_mutex_t (*mutex_create_nonrecursive) (void);
- + void (*mutex_free) (db_mutex_t mtx);
- + int (*mutex_lock) (db_mutex_t mtx);
- + int (*mutex_unlock) (db_mutex_t mtx);
- + db_cond_t (*cond_create) (void);
- + void (*cond_free) (db_cond_t cond);
- + int (*cond_wait) (db_cond_t cond, db_mutex_t mutex);
- + int (*cond_signal) (db_cond_t cond);
- + int (*cond_broadcast) (db_cond_t cond);
- /////// playlist management //////
- void (*plt_ref) (ddb_playlist_t *plt);
- diff --git a/handler.c b/handler.c
- index 13dfec49..4ccd79ce 100644
- --- a/handler.c
- +++ b/handler.c
- @@ -24,13 +24,13 @@
- Alexey Yakovenko waker@users.sourceforge.net
- */
- -#include "handler.h"
- +
- #include <stdio.h>
- #include <string.h>
- #include <assert.h>
- #include <stdlib.h>
- -#include "handler.h"
- #include "threading.h"
- +#include "handler.h"
- typedef struct message_s {
- uint32_t id;
- @@ -45,8 +45,8 @@ typedef struct handler_s {
- message_t *mfree;
- message_t *mqueue;
- message_t *mqtail;
- - uintptr_t mutex;
- - uintptr_t cond;
- + db_mutex_t mutex;
- + db_cond_t cond;
- message_t pool[1];
- } handler_t;
- diff --git a/junklib.c b/junklib.c
- index 6f8cbe48..d237b290 100644
- --- a/junklib.c
- +++ b/junklib.c
- @@ -30,10 +30,16 @@
- #include "junklib.h"
- #include <stdio.h>
- #include <stdlib.h>
- +#ifdef __MINGW32__
- +#undef __STRICT_ANSI__
- +#undef _NO_OLDNAMES
- +#endif
- #include <string.h>
- #undef HAVE_ICI
- #if HAVE_ICONV
- +#ifndef __MINGW32__
- #define LIBICONV_PLUG
- +#endif
- #include <iconv.h>
- #elif HAVE_ICU
- #warning icu
- @@ -586,7 +592,7 @@ junk_iconv (const char *in, int inlen, char *out, int outlen, const char *cs_in,
- if (cd == (iconv_t)-1) {
- return -1;
- }
- -#ifdef __linux__
- +#if defined(__linux__) || defined(__MINGW32__)
- char *pin = (char*)in;
- #else
- const char *pin = in;
- diff --git a/main.c b/main.c
- index d7471002..c5f066ac 100644
- --- a/main.c
- +++ b/main.c
- @@ -30,6 +30,9 @@
- #include <stdio.h>
- #include <stdint.h>
- #include <string.h>
- +#ifdef __MINGW32__
- +#undef __STRICT_ANSI__ /* this will make stdlib.h declare the prototype for '_fullpath' */
- +#endif
- #include <stdlib.h>
- #include <stddef.h>
- #include <time.h>
- @@ -37,7 +40,7 @@
- #ifdef __linux__
- #include <sys/prctl.h>
- #endif
- -#ifndef __linux__
- +#if !defined(__linux__) && !defined(_POSIX_C_SOURCE)
- #define _POSIX_C_SOURCE 1
- #endif
- #include <limits.h>
- @@ -45,11 +48,16 @@
- #include <sys/stat.h>
- #include <sys/types.h>
- #include <sys/types.h>
- +#ifdef __MINGW32__
- +#include <winsock2.h>
- +#define DEFAULT_LISTENING_PORT 48879
- +#else
- #include <sys/socket.h>
- #include <sys/select.h>
- #include <sys/un.h>
- -#include <sys/fcntl.h>
- #include <sys/errno.h>
- +#endif
- +#include <sys/fcntl.h>
- #include <signal.h>
- #ifdef __GLIBC__
- #include <execinfo.h>
- @@ -70,6 +78,9 @@
- #endif
- #include "playqueue.h"
- #include "tf.h"
- +#ifdef __MINGW32__
- +#include "mingw32_layer.h"
- +#endif
- #ifndef PREFIX
- #error PREFIX must be defined
- @@ -153,7 +164,13 @@ prepare_command_line (int argc, char *argv[], int *size) {
- // if argument is a filename, try to resolve it
- char resolved[PATH_MAX];
- char *arg;
- +#ifdef __MINGW32__
- + struct _stati64 dummy;
- + realpath (argv[i], resolved);
- + if ((!strncmp ("--", argv[i], 2) && !seen_ddash) || _stati64(argv[i], &dummy)) {
- +#else
- if (!strncmp ("--", argv[i], 2) && !seen_ddash || !realpath (argv[i], resolved)) {
- +#endif
- arg = argv[i];
- }
- else {
- @@ -200,7 +217,7 @@ server_exec_command_line (const char *cmdline, int len, char *sendback, int sbsi
- const uint8_t *pend = cmdline + len;
- int queue = 0;
- while (parg < pend) {
- - const char *parg_c = parg;
- +// const char *parg_c = parg;
- if (strlen (parg) >= 2 && parg[0] == '-' && parg[1] != '-') {
- parg += strlen (parg);
- parg++;
- @@ -403,8 +420,13 @@ server_exec_command_line (const char *cmdline, int len, char *sendback, int sbsi
- return 0;
- }
- +#ifdef __MINGW32__
- +static struct sockaddr_in srv_local;
- +static struct sockaddr_in srv_remote;
- +#else
- static struct sockaddr_un srv_local;
- static struct sockaddr_un srv_remote;
- +#endif
- static unsigned srv_socket;
- #if USE_ABSTRACT_SOCKET_NAME
- @@ -413,7 +435,17 @@ static char server_id[] = "\0deadbeefplayer";
- int
- server_start (void) {
- + int len;
- +
- fprintf (stderr, "server_start\n");
- +#ifdef __MINGW32__
- + srv_socket = socket (AF_INET, SOCK_STREAM, 0);
- + unsigned long flags = 1;
- + if (ioctlsocket(srv_socket, FIONBIO, &flags) == SOCKET_ERROR) {
- + perror ("ioctlsocket FIONBIO");
- + return -1;
- + }
- +#else
- srv_socket = socket (AF_UNIX, SOCK_STREAM, 0);
- int flags;
- flags = fcntl (srv_socket, F_GETFL,0);
- @@ -425,20 +457,30 @@ server_start (void) {
- perror ("fcntl F_SETFL");
- return -1;
- }
- +#endif
- memset (&srv_local, 0, sizeof (srv_local));
- +
- +#ifdef __MINGW32__
- + srv_local.sin_family = AF_INET;
- + srv_local.sin_addr.s_addr = INADDR_ANY;
- + srv_local.sin_port = htons(DEFAULT_LISTENING_PORT);
- +
- + len = sizeof(srv_local);
- +#else
- srv_local.sun_family = AF_UNIX;
- #if USE_ABSTRACT_SOCKET_NAME
- memcpy (srv_local.sun_path, server_id, sizeof (server_id));
- - int len = offsetof(struct sockaddr_un, sun_path) + sizeof (server_id)-1;
- + len = offsetof(struct sockaddr_un, sun_path) + sizeof (server_id)-1;
- #else
- char *socketdirenv = getenv ("DDB_SOCKET_DIR");
- snprintf (srv_local.sun_path, sizeof (srv_local.sun_path), "%s/socket", socketdirenv ? socketdirenv : dbconfdir);
- if (unlink(srv_local.sun_path) < 0) {
- perror ("INFO: unlink socket");
- }
- - int len = offsetof(struct sockaddr_un, sun_path) + strlen (srv_local.sun_path);
- + len = offsetof(struct sockaddr_un, sun_path) + strlen (srv_local.sun_path);
- #endif
- +#endif /* __MINGW32__ */
- if (bind(srv_socket, (struct sockaddr *)&srv_local, len) < 0) {
- perror ("bind");
- @@ -455,7 +497,11 @@ server_start (void) {
- void
- server_close (void) {
- if (srv_socket) {
- +#ifdef __MINGW32__
- + closesocket (srv_socket);
- +#else
- close (srv_socket);
- +#endif
- srv_socket = 0;
- }
- }
- @@ -480,7 +526,11 @@ read_entire_message (int sockfd, int *size) {
- int rd = recv(sockfd, buf + rdp, bufsize - rdp, 0);
- if (rd < 0) {
- +#ifdef __MINGW32__
- + if (WSAGetLastError() == WSAEWOULDBLOCK) {
- +#else
- if (errno == EAGAIN) {
- +#endif
- usleep (50000);
- continue;
- }
- @@ -503,7 +553,11 @@ server_update (void) {
- int t = sizeof (srv_remote);
- unsigned s2;
- s2 = accept(srv_socket, (struct sockaddr *)&srv_remote, &t);
- +#ifdef __MINGW32__
- + if (s2 == -1 && WSAGetLastError() != WSAEWOULDBLOCK) {
- +#else
- if (s2 == -1 && errno != EAGAIN && errno != EWOULDBLOCK) {
- +#endif
- perror("accept");
- return -1;
- }
- @@ -527,7 +581,11 @@ server_update (void) {
- else {
- send (s2, "", 1, 0);
- }
- +#ifdef __MINGW32__
- + closesocket (s2);
- +#else
- close(s2);
- +#endif
- if (buf) {
- free(buf);
- @@ -536,7 +594,7 @@ server_update (void) {
- return 0;
- }
- -static uintptr_t server_tid;
- +static db_thread_t server_tid;
- static int server_terminate;
- void
- @@ -728,7 +786,7 @@ restore_resume_state (void) {
- }
- }
- -uintptr_t mainloop_tid;
- +db_thread_t mainloop_tid;
- DB_plugin_t *
- plug_get_gui (void) {
- @@ -744,10 +802,10 @@ plug_get_gui (void) {
- void
- main_cleanup_and_quit (void) {
- // terminate server and wait for completion
- - if (server_tid) {
- + if (thread_alive (server_tid)) {
- server_terminate = 1;
- thread_join (server_tid);
- - server_tid = 0;
- + thread_wipeid (&server_tid);
- }
- // save config
- @@ -801,6 +859,9 @@ mainloop_thread (void *ctx) {
- int
- main (int argc, char *argv[]) {
- +#ifdef __MINGW32__
- + char current_dir[MAX_PATH];
- +#endif
- int portable = 0;
- #if STATICLINK
- int staticlink = 1;
- @@ -808,6 +869,9 @@ main (int argc, char *argv[]) {
- int staticlink = 0;
- #endif
- #if PORTABLE
- +#ifdef __MINGW32__
- + GetCurrentDirectory(PATH_MAX, dbinstalldir);
- +#else
- portable = 1;
- if (!realpath (argv[0], dbinstalldir)) {
- strcpy (dbinstalldir, argv[0]);
- @@ -820,6 +884,7 @@ main (int argc, char *argv[]) {
- fprintf (stderr, "couldn't determine install folder from path %s\n", argv[0]);
- exit (-1);
- }
- +#endif /* __MINGW32__ */
- #else
- if (!realpath (argv[0], dbinstalldir)) {
- strcpy (dbinstalldir, argv[0]);
- @@ -869,6 +934,13 @@ main (int argc, char *argv[]) {
- prctl (PR_SET_NAME, "deadbeef-main", 0, 0, 0, 0);
- #endif
- +#ifdef __MINGW32__
- + WSADATA wsaData;
- + if (WSAStartup(MAKEWORD(2,2), &wsaData) != 0)
- + fprintf(stderr, "Error with WSAStartup(), WinSock startup failed.\n");
- + else
- + fprintf(stderr, "WinSock init ok, library version %d.%d\n", HIBYTE(wsaData.wVersion), LOBYTE(wsaData.wVersion));
- +#endif
- #if PORTABLE_FULL
- if (snprintf (confdir, sizeof (confdir), "%s/config", dbinstalldir) > sizeof (confdir)) {
- fprintf (stderr, "fatal: too long install path %s\n", dbinstalldir);
- @@ -882,7 +954,11 @@ main (int argc, char *argv[]) {
- return -1;
- }
- #else
- +#ifdef __MINGW32__
- + char *homedir = getenv ("USERPROFILE");
- +#else
- char *homedir = getenv ("HOME");
- +#endif
- if (!homedir) {
- fprintf (stderr, "unable to find home directory. stopping.\n");
- return -1;
- @@ -941,7 +1017,12 @@ main (int argc, char *argv[]) {
- mkdir (dbplugindir, 0755);
- }
- else {
- +#ifdef __MINGW32__
- + GetCurrentDirectory(MAX_PATH, current_dir);
- + if (snprintf (dbdocdir, sizeof (dbdocdir), "%s/doc", current_dir) > sizeof (dbdocdir)) {
- +#else
- if (snprintf (dbdocdir, sizeof (dbdocdir), "%s", DOCDIR) > sizeof (dbdocdir)) {
- +#endif
- fprintf (stderr, "fatal: too long install path %s\n", dbinstalldir);
- return -1;
- }
- @@ -953,11 +1034,19 @@ main (int argc, char *argv[]) {
- return -1;
- }
- }
- +#ifdef __MINGW32__
- + else if (snprintf (dbplugindir, sizeof (dbplugindir), "%s/plugins", current_dir) > sizeof (dbplugindir)) {
- +#else
- else if (snprintf (dbplugindir, sizeof (dbplugindir), "%s/deadbeef", LIBDIR) > sizeof (dbplugindir)) {
- +#endif
- fprintf (stderr, "fatal: too long install path %s\n", dbinstalldir);
- return -1;
- }
- +#ifdef __MINGW32__
- + if (snprintf (dbpixmapdir, sizeof (dbpixmapdir), "%s/pixmaps", current_dir) > sizeof (dbpixmapdir)) {
- +#else
- if (snprintf (dbpixmapdir, sizeof (dbpixmapdir), "%s/share/deadbeef/pixmaps", PREFIX) > sizeof (dbpixmapdir)) {
- +#endif
- fprintf (stderr, "fatal: too long install path %s\n", dbinstalldir);
- return -1;
- }
- @@ -996,15 +1085,28 @@ main (int argc, char *argv[]) {
- // try to connect to remote player
- int s, len;
- - struct sockaddr_un remote;
- +#ifdef __MINGW32__
- + struct sockaddr_in remote;
- + if ((s = socket(AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET) {
- +#else
- + struct sockaddr_un remote;
- if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
- +#endif
- perror("socket");
- exit(1);
- }
- memset (&remote, 0, sizeof (remote));
- +#ifdef __MINGW32__
- + remote.sin_family = AF_INET;
- + remote.sin_addr.s_addr = inet_addr("127.0.0.1");
- + remote.sin_port = htons(DEFAULT_LISTENING_PORT);
- +
- + len = sizeof(remote);
- +#else
- remote.sun_family = AF_UNIX;
- +
- #if USE_ABSTRACT_SOCKET_NAME
- memcpy (remote.sun_path, server_id, sizeof (server_id));
- len = offsetof(struct sockaddr_un, sun_path) + sizeof (server_id)-1;
- @@ -1013,6 +1115,7 @@ main (int argc, char *argv[]) {
- snprintf (remote.sun_path, sizeof (remote.sun_path), "%s/socket", socketdirenv ? socketdirenv : dbconfdir);
- len = offsetof(struct sockaddr_un, sun_path) + strlen (remote.sun_path);
- #endif
- +#endif /* __MINGW32__ */
- if (connect(s, (struct sockaddr *)&remote, len) == 0) {
- // pass args to remote and exit
- if (send(s, cmdline, size, 0) == -1) {
- @@ -1047,14 +1150,21 @@ main (int argc, char *argv[]) {
- if (out) {
- free (out);
- }
- +#ifdef __MINGW32__
- + closesocket (s);
- +#else
- close (s);
- +#endif
- exit (0);
- }
- // else {
- // perror ("INFO: failed to connect to existing session:");
- // }
- +#ifdef __MINGW32__
- + closesocket (s);
- +#else
- close(s);
- -
- +#endif
- // become a server
- if (server_start () < 0) {
- exit (-1);
- diff --git a/messagepump.c b/messagepump.c
- index e3f422b8..2b0d12db 100644
- --- a/messagepump.c
- +++ b/messagepump.c
- @@ -45,8 +45,8 @@ static message_t pool[MAX_MESSAGES];
- static message_t *mfree;
- static message_t *mqueue;
- static message_t *mqtail;
- -static uintptr_t mutex;
- -static uintptr_t cond;
- +static db_mutex_t mutex;
- +static db_cond_t cond;
- static void
- messagepump_reset (void);
- diff --git a/mingw32_layer.h b/mingw32_layer.h
- new file mode 100644
- index 00000000..ab0ed438
- --- /dev/null
- +++ b/mingw32_layer.h
- @@ -0,0 +1,39 @@
- +
- +#ifndef _MINGW32_LAYER_H_
- +#define _MINGW32_LAYER_H_
- +
- +#include <errno.h>
- +#include <dirent.h>
- +#include <malloc.h>
- +
- +
- +#define mkdir(X,Y) mkdir(X)
- +#define realpath(X,Y) _fullpath(Y,X,PATH_MAX)
- +#define EWOULDBLOCK EAGAIN
- +#define SHUT_WR 1
- +#define lstat stat
- +
- +#define PROT_READ 0x1
- +#define PROT_WRITE 0x2
- +/* This flag is only available in WinXP+ */
- +#ifdef FILE_MAP_EXECUTE
- +#define PROT_EXEC 0x4
- +#else
- +#define PROT_EXEC 0x0
- +#define FILE_MAP_EXECUTE 0
- +#endif
- +
- +#define MAP_SHARED 0x01
- +#define MAP_PRIVATE 0x02
- +#define MAP_ANONYMOUS 0x20
- +#define MAP_ANON MAP_ANONYMOUS
- +#define MAP_FAILED ((void *) -1)
- +
- +
- +int scandir (const char *__dir, struct dirent ***__namelist, int (*__selector) (const struct dirent *), int (*__cmp) (const struct dirent **, const struct dirent **));
- +void *mmap(void *, size_t, int, int, int, off_t);
- +int munmap(void *, size_t);
- +char *strndup(char *, size_t);
- +char *strcasestr(const char *, const char *);
- +
- +#endif
- diff --git a/mingw32_mmap.c b/mingw32_mmap.c
- new file mode 100644
- index 00000000..856e60b2
- --- /dev/null
- +++ b/mingw32_mmap.c
- @@ -0,0 +1,102 @@
- +/* mmap() replacement for Windows
- + *
- + * Author: Mike Frysinger <vapier@gentoo.org>
- + * Placed into the public domain
- + *
- + * File edited by JimF, for proper integration into JtR
- + * edits placed into public domain.
- + */
- +
- +/* References:
- + * CreateFileMapping: http://msdn.microsoft.com/en-us/library/aa366537(VS.85).aspx
- + * CloseHandle: http://msdn.microsoft.com/en-us/library/ms724211(VS.85).aspx
- + * MapViewOfFile: http://msdn.microsoft.com/en-us/library/aa366761(VS.85).aspx
- + * UnmapViewOfFile: http://msdn.microsoft.com/en-us/library/aa366882(VS.85).aspx
- + */
- +
- +#include <io.h>
- +#include <windows.h>
- +#include <sys/types.h>
- +#include "memdbg.h"
- +#include "mingw32_layer.h"
- +
- +#ifdef __USE_FILE_OFFSET64
- +# define DWORD_HI(x) (x >> 32)
- +# define DWORD_LO(x) ((x) & 0xffffffff)
- +#else
- +# define DWORD_HI(x) (0)
- +# define DWORD_LO(x) (x)
- +#endif
- +
- +void *mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset)
- +{
- + DWORD flProtect;
- + off_t end;
- + HANDLE mmap_fd, h;
- + DWORD dwDesiredAccess;
- + void *ret;
- +
- + if (prot & ~(PROT_READ | PROT_WRITE | PROT_EXEC))
- + return 0;
- + if (fd == -1) {
- + if (!(flags & MAP_ANON) || offset)
- + return 0;
- + } else if (flags & MAP_ANON)
- + return 0;
- +
- + if (prot & PROT_WRITE) {
- + if (prot & PROT_EXEC)
- + flProtect = PAGE_EXECUTE_READWRITE;
- + else
- + flProtect = PAGE_READWRITE;
- + } else if (prot & PROT_EXEC) {
- + if (prot & PROT_READ)
- + flProtect = PAGE_EXECUTE_READ;
- + else if (prot & PROT_EXEC)
- + flProtect = PAGE_EXECUTE;
- + } else
- + flProtect = PAGE_READONLY;
- +
- + end = length + offset;
- + if (fd == -1)
- + mmap_fd = INVALID_HANDLE_VALUE;
- + else
- + mmap_fd = (HANDLE)_get_osfhandle(fd);
- + h = CreateFileMapping(mmap_fd, NULL, flProtect, DWORD_HI(end), DWORD_LO(end), NULL);
- + //h = CreateFileMapping(mmap_fd, NULL, flProtect, 0, 0, NULL);
- + if (h == NULL) {
- + /* we will log this at some time, once I know PROPER fixes */
- + DWORD x = GetLastError();
- + fprintf(stderr, "Error, CreateFileMapping failed, Error code %x\n", x);
- + return 0;
- + }
- +
- + if (prot & PROT_WRITE)
- + dwDesiredAccess = FILE_MAP_WRITE;
- + else
- + dwDesiredAccess = FILE_MAP_READ;
- + if (prot & PROT_EXEC)
- + dwDesiredAccess |= FILE_MAP_EXECUTE;
- + if (flags & MAP_PRIVATE)
- + dwDesiredAccess |= FILE_MAP_COPY;
- +
- + ret = MapViewOfFile(h, dwDesiredAccess, DWORD_HI(offset), DWORD_LO(offset), length);
- + //ret = MapViewOfFile(h, dwDesiredAccess, 0, 0, length);
- + if (ret == NULL) {
- + /* we will log this at some time, once I know PROPER fixes */
- + DWORD x = GetLastError();
- + fprintf(stderr, "Error, MapViewOfFile failed, Error code %x\n", x);
- + CloseHandle(h);
- + ret = 0;
- + }
- + return ret;
- +}
- +
- +int munmap(void *addr, size_t length)
- +{
- + return !(UnmapViewOfFile(addr));
- + /* ruh-ro, we leaked handle from CreateFileMapping() ... */
- +}
- +
- +#undef DWORD_HI
- +#undef DWORD_LO
- diff --git a/mingw32_scandir.c b/mingw32_scandir.c
- new file mode 100644
- index 00000000..52d2a03c
- --- /dev/null
- +++ b/mingw32_scandir.c
- @@ -0,0 +1,102 @@
- +
- +#include <dirent.h>
- +#include <stdlib.h>
- +#include <string.h>
- +
- +int scandir (const char *__dir,
- + struct dirent ***__namelist,
- + int (*__selector) (const struct dirent *),
- + int (*__cmp) (const struct dirent **, const struct dirent **))
- +{
- + int count = -1; /* this will store the scandir result - will be -1 for errors */
- + DIR *curr_dir;
- + struct dirent **templist;
- +
- + if (__dir != NULL && __namelist != NULL)
- + {
- + curr_dir = opendir(__dir);
- + if (curr_dir != NULL)
- + {
- + int to_be_added;
- + struct dirent *direntry;
- + int idx, jdx;
- + struct dirent *temp;
- +
- + count = 0;
- +
- + /* start! */
- + direntry = readdir(curr_dir);
- + while (direntry != NULL)
- + {
- + /* an entry was found! */
- + if (__selector != NULL)
- + {
- + /* '__selector' is a function which returns 1 or 0 */
- + to_be_added = __selector(direntry);
- + }
- + else
- + {
- + to_be_added = 1;
- + }
- +
- + if (to_be_added)
- + {
- + /* this entry has to be added */
- +
- + /* realloc the pointer array */
- + templist = realloc(*__namelist, sizeof(struct dirent *)*(count+1));
- + if (templist == NULL)
- + {
- + /* no room for a new pointer! */
- + /* in this case '__namelist' still holds the pointer to the old untouched array
- + so it is still a consistent result to give back */
- + break;
- + }
- + /* reallocation was succesfull but 'templist' may be different from '*__namelist'
- + in case a relocation (and a copy) was required */
- + *__namelist = templist;
- +
- + /* claim room for the new item */
- + (*__namelist)[count] = (struct dirent *)malloc(sizeof(struct dirent));
- + if ((*__namelist)[count] == NULL)
- + {
- + /* memory allocation failed! */
- + break;
- + }
- + memcpy((*__namelist)[count], direntry, sizeof(struct dirent));
- + /* the entry got added to the array - now let's concern about sorting */
- + if (__cmp != NULL)
- + {
- + /* a sorting routine is provided */
- + if (count != 0)
- + {
- + /* scan the array for the right position */
- + idx = 0;
- + while (__cmp((const struct dirent **)&(*__namelist)[count],
- + (const struct dirent **)&(*__namelist)[idx]) > 0)
- + idx++;
- +
- + if (idx < count) /* idx == count when the entry is already in its own right position */
- + {
- + /* this happens when the entry is NOT in the right position */
- + /* save the pointer of the new entry structure */
- + temp = (*__namelist)[count];
- + /* shift the tail of the array */
- + for (jdx=count; jdx>idx; jdx--)
- + {
- + (*__namelist)[jdx] = (*__namelist)[jdx-1];
- + }
- + /* put the new entry in the 'idx' position */
- + (*__namelist)[idx] = temp;
- + }
- + }
- + }
- + count++;
- + }
- + direntry = readdir(curr_dir);
- + }
- + closedir(curr_dir);
- + }
- + }
- + return count;
- +}
- diff --git a/mingw32_strcasestr.c b/mingw32_strcasestr.c
- new file mode 100644
- index 00000000..f58822eb
- --- /dev/null
- +++ b/mingw32_strcasestr.c
- @@ -0,0 +1,52 @@
- +
- +#include <stdio.h>
- +#include <string.h>
- +#include <ctype.h>
- +
- +
- +
- +char *strcasestr(const char *haystack, const char *needle)
- +{
- + char *result = NULL;
- + int needle_len, length;
- + int idx, jdx;
- +
- + if (haystack != NULL && needle != NULL)
- + {
- + needle_len = (int)strlen(needle);
- + length = strlen(haystack) - needle_len;
- + idx = 0;
- + while ((result=strchr(&haystack[idx],tolower(needle[0])))!=NULL
- + ||
- + (result=strchr(&haystack[idx],toupper(needle[0])))!=NULL)
- + {
- + idx = (int)(result - haystack);
- + if (idx > length)
- + {
- + /* needle cannot fit into remaining characters */
- + result = NULL;
- + break;
- + }
- + for (jdx=0; jdx<needle_len; jdx++)
- + {
- + if (tolower(result[jdx]) != tolower(needle[jdx]))
- + {
- + break;
- + }
- + }
- + if (jdx == needle_len)
- + {
- + /* we found needle! */
- + break;
- + }
- + else
- + {
- + idx++;
- + }
- + }
- + }
- +
- + return result;
- +}
- +
- +
- diff --git a/mingw32_strndup.c b/mingw32_strndup.c
- new file mode 100644
- index 00000000..1bed4265
- --- /dev/null
- +++ b/mingw32_strndup.c
- @@ -0,0 +1,23 @@
- +
- +#include <malloc.h>
- +#include <string.h>
- +
- +char *strndup(char *buff, size_t bufflen)
- +{
- + char *result = NULL;
- +
- + if (strlen(buff)>bufflen)
- + {
- + if ((result=malloc(1+bufflen)) != NULL)
- + {
- + memcpy(result, buff, bufflen);
- + result[bufflen] = 0;
- + }
- + }
- + else
- + {
- + result = strdup(buff);
- + }
- +
- + return result;
- +}
- diff --git a/playlist.c b/playlist.c
- index 1397a9b0..e8af112e 100644
- --- a/playlist.c
- +++ b/playlist.c
- @@ -31,9 +31,15 @@
- # include <alloca.h>
- #endif
- #include <stdlib.h>
- +#ifdef __MINGW32__
- +#undef __STRICT_ANSI__
- +#undef _NO_OLDNAMES
- +#endif
- #include <string.h>
- #include <dirent.h>
- +#ifndef __MINGW32__
- #include <fnmatch.h>
- +#endif
- #include <stdio.h>
- #include <ctype.h>
- #include <sys/types.h>
- @@ -42,7 +48,7 @@
- #include <assert.h>
- #include <time.h>
- #include <sys/time.h>
- -#ifndef __linux__
- +#if !defined(__linux__) && !defined(_POSIX_C_SOURCE)
- #define _POSIX_C_SOURCE 1
- #endif
- #include <limits.h>
- @@ -66,6 +72,9 @@
- #include "strdupa.h"
- #include "tf.h"
- #include "playqueue.h"
- +#ifdef __MINGW32__
- +#include "mingw32_layer.h"
- +#endif
- // disable custom title function, until we have new title formatting (0.7)
- #define DISABLE_CUSTOM_TITLE
- @@ -106,7 +115,7 @@ static playlist_t *playlist = NULL; // current playlist
- static int plt_loading = 0; // disable sending event about playlist switch, config regen, etc
- #if !DISABLE_LOCKING
- -static uintptr_t mutex;
- +static db_mutex_t mutex;
- #endif
- #define LOCK {pl_lock();}
- @@ -415,6 +424,10 @@ plt_add (int before, const char *title) {
- fprintf (stderr, "error: failed to make path string for playlist file\n");
- continue;
- }
- +#ifdef __MINGW32__
- + if (unlink(path2)!=0)
- + fprintf (stderr, "deleting %s failed: %s\n", path2, strerror (errno));
- +#endif
- int err = rename (path1, path2);
- if (err != 0) {
- fprintf (stderr, "playlist rename failed: %s\n", strerror (errno));
- @@ -462,6 +475,10 @@ plt_remove (int plt) {
- fprintf (stderr, "error: failed to make path string for playlist file\n");
- continue;
- }
- +#ifdef __MINGW32__
- + if (unlink(path1)!=0)
- + fprintf (stderr, "deleting %s failed: %s\n", path1, strerror (errno));
- +#endif
- int err = rename (path2, path1);
- if (err != 0) {
- fprintf (stderr, "playlist rename failed: %s\n", strerror (errno));
- @@ -695,7 +712,10 @@ plt_move (int from, int to) {
- int err = stat (path1, &st);
- if (!err) {
- trace ("rename %s->%s\n", path1, temp);
- -
- +#ifdef __MINGW32__
- + if (unlink(temp)!=0)
- + fprintf (stderr, "deleting %s failed: %s\n", temp, strerror (errno));
- +#endif
- int err = rename (path1, temp);
- if (err != 0) {
- fprintf (stderr, "playlist rename %s->%s failed: %s\n", path1, temp, strerror (errno));
- @@ -735,6 +755,10 @@ plt_move (int from, int to) {
- int err = stat (path2, &st);
- if (!err) {
- trace ("rename %s->%s\n", path2, path1);
- +#ifdef __MINGW32__
- + if (unlink(path1)!=0)
- + fprintf (stderr, "deleting %s failed: %s\n", path1, strerror (errno));
- +#endif
- int err = rename (path2, path1);
- if (err != 0) {
- fprintf (stderr, "playlist rename %s->%s failed: %s\n", path2, path1, strerror (errno));
- @@ -756,6 +780,10 @@ plt_move (int from, int to) {
- int err = stat (path1, &st);
- if (!err) {
- trace ("rename %s->%s\n", path1, path2);
- +#ifdef __MINGW32__
- + if (unlink(path2)!=0)
- + fprintf (stderr, "deleting %s failed: %s\n", path2, strerror (errno));
- +#endif
- int err = rename (path1, path2);
- if (err != 0) {
- fprintf (stderr, "playlist rename %s->%s failed: %s\n", path1, path2, strerror (errno));
- @@ -770,6 +798,10 @@ plt_move (int from, int to) {
- int err = stat (temp, &st);
- if (!err) {
- trace ("move %s->%s\n", temp, path1);
- +#ifdef __MINGW32__
- + if (unlink(path1)!=0)
- + fprintf (stderr, "deleting %s failed: %s\n", path1, strerror (errno));
- +#endif
- int err = rename (temp, path1);
- if (err != 0) {
- fprintf (stderr, "playlist rename %s->%s failed: %s\n", temp, path1, strerror (errno));
- @@ -1490,9 +1522,11 @@ plt_insert_dir_int (int visibility, playlist_t *playlist, DB_vfs_t *vfs, playIte
- if (!follow_symlinks && !vfs) {
- struct stat buf;
- lstat (dirname, &buf);
- +#ifndef __MINGW32__
- if (S_ISLNK(buf.st_mode)) {
- return NULL;
- }
- +#endif
- }
- struct dirent **namelist = NULL;
- int n;
- @@ -2167,6 +2201,10 @@ plt_save (playlist_t *plt, playItem_t *first, playItem_t *last, const char *fnam
- UNLOCK;
- fclose (fp);
- +#ifdef __MINGW32__
- + if (unlink(fname)!=0)
- + fprintf (stderr, "deleting %s failed: %s\n", fname, strerror (errno));
- +#endif
- if (rename (tempfile, fname) != 0) {
- fprintf (stderr, "playlist rename %s -> %s failed: %s\n", tempfile, fname, strerror (errno));
- return -1;
- diff --git a/plmeta.c b/plmeta.c
- index 98ce3b19..350ea7ae 100644
- --- a/plmeta.c
- +++ b/plmeta.c
- @@ -25,6 +25,10 @@
- Alexey Yakovenko waker@users.sourceforge.net
- */
- +#ifdef __MINGW32__
- +#undef __STRICT_ANSI__
- +#undef _NO_OLDNAMES
- +#endif
- #include <string.h>
- #include <stdlib.h>
- #include "playlist.h"
- diff --git a/pltmeta.c b/pltmeta.c
- index f0a4438d..75558458 100644
- --- a/pltmeta.c
- +++ b/pltmeta.c
- @@ -25,6 +25,10 @@
- Alexey Yakovenko waker@users.sourceforge.net
- */
- +#ifdef __MINGW32__
- +#undef __STRICT_ANSI__
- +#undef _NO_OLDNAMES
- +#endif
- #include <string.h>
- #include <stdlib.h>
- #include "playlist.h"
- diff --git a/plugins.c b/plugins.c
- index eb79e7ad..2ae4c89a 100644
- --- a/plugins.c
- +++ b/plugins.c
- @@ -29,10 +29,14 @@
- #include <assert.h>
- #include <stdio.h>
- #include <stdlib.h>
- +#ifdef __MINGW32__
- +#undef __STRICT_ANSI__
- +#undef _NO_OLDNAMES
- +#endif
- #include <string.h>
- #include <sys/stat.h>
- #include <unistd.h>
- -#ifndef __linux__
- +#if !defined(__linux__) && !defined(_POSIX_C_SOURCE)
- #define _POSIX_C_SOURCE 1
- #endif
- #include <limits.h>
- @@ -58,6 +62,9 @@
- #include "tf.h"
- #include "playqueue.h"
- #include "sort.h"
- +#ifdef __MINGW32__
- +#include "mingw32_layer.h"
- +#endif
- #define trace(...) { fprintf(stderr, __VA_ARGS__); }
- //#define trace(fmt,...)
- @@ -67,8 +74,12 @@
- #if defined(HAVE_COCOAUI) || defined(OSX_APPBUNDLE)
- #define PLUGINEXT ".dylib"
- #else
- +#ifdef __MINGW32__
- +#define PLUGINEXT ".dll"
- +#else
- #define PLUGINEXT ".so"
- #endif
- +#endif
- const char *lowprio_plugin_ids[] = {
- "ffmpeg",
- @@ -114,7 +125,7 @@ static DB_output_t *output_plugin = NULL;
- #define MAX_PLAYLIST_PLUGINS 10
- static DB_playlist_t *g_playlist_plugins[MAX_PLAYLIST_PLUGINS+1];
- -static uintptr_t background_jobs_mutex;
- +static db_mutex_t background_jobs_mutex;
- static int num_background_jobs;
- // deadbeef api
- @@ -154,6 +165,8 @@ static DB_functions_t deadbeef_api = {
- .thread_start_low_priority = thread_start_low_priority,
- .thread_join = thread_join,
- .thread_detach = thread_detach,
- + .thread_alive = thread_alive,
- + .thread_wipeid = thread_wipeid,
- .thread_exit = thread_exit,
- .mutex_create = mutex_create,
- .mutex_create_nonrecursive = mutex_create_nonrecursive,
- @@ -711,7 +724,7 @@ load_plugin (const char *plugdir, char *d_name, int l) {
- #if defined(ANDROID) || defined(HAVE_COCOAUI)
- return -1;
- #else
- - strcpy (fullname + strlen(fullname) - sizeof (PLUGINEXT)+1, ".fallback.so");
- + strcpy (fullname + strlen(fullname) - sizeof (PLUGINEXT)+1, ".fallback" PLUGINEXT);
- trace ("trying %s...\n", fullname);
- handle = dlopen (fullname, RTLD_NOW);
- if (!handle) {
- @@ -923,7 +936,11 @@ plug_load_all (void) {
- strncpy (xdg_plugin_dir, xdg_local_home, sizeof (xdg_plugin_dir));
- xdg_plugin_dir[sizeof(xdg_plugin_dir)-1] = 0;
- } else {
- +#ifdef __MINGW32__
- + char *homedir = getenv ("USERPROFILE");
- +#else
- char *homedir = getenv ("HOME");
- +#endif
- if (!homedir) {
- trace ("plug_load_all: warning: unable to find home directory\n");
- @@ -933,7 +950,11 @@ plug_load_all (void) {
- // multilib support:
- // 1. load from lib$ARCH if present
- // 2. load from lib if present
- +#ifdef __MINGW32__
- + int written = snprintf (xdg_plugin_dir, sizeof (xdg_plugin_dir), "%s/.config/deadbeef/plugins", homedir);
- +#else
- int written = snprintf (xdg_plugin_dir, sizeof (xdg_plugin_dir), "%s/.local/lib/deadbeef", homedir);
- +#endif
- if (written > sizeof (xdg_plugin_dir)) {
- trace ("warning: XDG_LOCAL_HOME value is too long: %s. Ignoring.", xdg_local_home);
- xdg_plugin_dir[0] = 0;
- @@ -947,7 +968,11 @@ plug_load_all (void) {
- }
- // load from HOME 1st, than replace from installdir if needed
- +#ifdef __MINGW32__
- + const char *plugins_dirs[] = { xdg_plugin_dir, dirname, NULL };
- +#else
- const char *plugins_dirs[] = { xdg_plugin_dir_explicit_arch, xdg_plugin_dir, dirname, NULL };
- +#endif
- // If xdg_plugin_dir and dirname is the same, we should avoid each plugin
- // to be load twice.
- diff --git a/plugins/aac/aac.c b/plugins/aac/aac.c
- index 471d0b47..60b703c5 100644
- --- a/plugins/aac/aac.c
- +++ b/plugins/aac/aac.c
- @@ -17,6 +17,10 @@
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
- +#ifdef __MINGW32__
- +#undef __STRICT_ANSI__
- +#undef _NO_OLDNAMES
- +#endif
- #include <string.h>
- #include <stdio.h>
- #include <unistd.h>
- @@ -28,6 +32,9 @@
- #include <math.h>
- #include "../../deadbeef.h"
- #include "aac_parser.h"
- +#ifdef __MINGW32__
- +#include "mingw32_layer.h"
- +#endif
- #include "mp4ff.h"
- diff --git a/plugins/adplug/adplug/a2m.h b/plugins/adplug/adplug/a2m.h
- index e21d1dff..432f6935 100644
- --- a/plugins/adplug/adplug/a2m.h
- +++ b/plugins/adplug/adplug/a2m.h
- @@ -55,7 +55,11 @@ private:
- #define ADPLUG_A2M_CODESPERRANGE (ADPLUG_A2M_MAXCOPY - ADPLUG_A2M_MINCOPY + 1)
- #define ADPLUG_A2M_MAXCHAR (ADPLUG_A2M_FIRSTCODE + ADPLUG_A2M_COPYRANGES * ADPLUG_A2M_CODESPERRANGE - 1)
- #define ADPLUG_A2M_TWICEMAX (2 * ADPLUG_A2M_MAXCHAR + 1)
- -
- +#ifdef __MINGW32__
- +#ifdef MAXCHAR
- +#undef MAXCHAR
- +#endif
- +#endif
- static const unsigned int MAXFREQ, MINCOPY, MAXCOPY, COPYRANGES,
- CODESPERRANGE, TERMINATE, FIRSTCODE, MAXCHAR, SUCCMAX, TWICEMAX, ROOT,
- MAXBUF, MAXDISTANCE, MAXSIZE;
- diff --git a/plugins/adplug/adplug/fmopl.c b/plugins/adplug/adplug/fmopl.c
- index 04912bc0..730e855b 100644
- --- a/plugins/adplug/adplug/fmopl.c
- +++ b/plugins/adplug/adplug/fmopl.c
- @@ -596,7 +596,7 @@ static void init_timetables( FM_OPL *OPL , int ARRATE , int DRRATE )
- OPL->AR_TABLE[i] = rate / ARRATE;
- OPL->DR_TABLE[i] = rate / DRRATE;
- }
- - for (i = 60;i < 76;i++)
- + for (i = 61;i <=74;i++)
- {
- OPL->AR_TABLE[i] = EG_AED-1;
- OPL->DR_TABLE[i] = OPL->DR_TABLE[60];
- diff --git a/plugins/adplug/adplug/mid.cpp b/plugins/adplug/adplug/mid.cpp
- index 5c13b144..090a3993 100644
- --- a/plugins/adplug/adplug/mid.cpp
- +++ b/plugins/adplug/adplug/mid.cpp
- @@ -870,7 +870,7 @@ void CmidPlayer::rewind(int subsong)
- adlib_mode=ADLIB_MELODIC;
- for (i=0; i<128; i++)
- for (j=0; j<16; j++)
- - myinsbank[i][j]=midi_fm_instruments[i][j];
- + myinsbank[i][j]=midi_fm_instruments[i][j < 14 ? j : 0];
- for (i=0; i<16; i++)
- {
- ch[i].inum=0;
- diff --git a/plugins/artwork/artwork.c b/plugins/artwork/artwork.c
- index b1b3ded0..92361f38 100644
- --- a/plugins/artwork/artwork.c
- +++ b/plugins/artwork/artwork.c
- @@ -27,12 +27,22 @@
- #endif
- #include <stdio.h>
- #include <stdlib.h>
- +#ifdef __MINGW32__
- +#undef __STRICT_ANSI__
- +#undef _NO_OLDNAMES
- +#endif
- #include <string.h>
- #include <ctype.h>
- #include <libgen.h>
- #include <dirent.h>
- #include <unistd.h>
- +#ifndef __MINGW32__
- #include <fnmatch.h>
- +#else
- +#define NAME_MAX FILENAME_MAX
- +#define WINSHLWAPI
- +#include <shlwapi.h>
- +#endif
- #include <pthread.h>
- #include <errno.h>
- #include <sys/stat.h>
- @@ -60,6 +70,9 @@
- #include "wos.h"
- #include "cache.h"
- #include "artwork.h"
- +#ifdef __MINGW32__
- +#include "../../mingw32_layer.h"
- +#endif
- //#define trace(...) { fprintf (stderr, __VA_ARGS__); }
- #define trace(...)
- @@ -88,9 +101,9 @@ typedef struct cover_query_s {
- static cover_query_t *queue;
- static cover_query_t *queue_tail;
- static int terminate;
- -static intptr_t tid;
- -static uintptr_t queue_mutex;
- -static uintptr_t queue_cond;
- +static db_thread_t tid;
- +static db_mutex_t queue_mutex;
- +static db_cond_t queue_cond;
- static int artwork_enable_embedded;
- static int artwork_enable_local;
- @@ -1124,12 +1137,16 @@ static char *filter_custom_mask = NULL;
- static int
- filter_custom (const struct dirent *f)
- {
- +#ifdef __MINGW32__
- + return ((PathMatchSpec(f->d_name, filter_custom_mask)==TRUE)? 0 : 1);
- +#else
- // FNM_CASEFOLD is not defined on solaris. On other platforms it is.
- // It should be safe to define it as FNM_INGORECASE if it isn't defined.
- #ifndef FNM_CASEFOLD
- #define FNM_CASEFOLD FNM_IGNORECASE
- #endif
- return !fnmatch (filter_custom_mask, f->d_name, FNM_CASEFOLD);
- +#endif
- }
- static char *
- @@ -2075,7 +2092,7 @@ artwork_get_actions (DB_playItem_t *it)
- static int
- artwork_plugin_stop (void)
- {
- - if (tid) {
- + if (deadbeef->thread_alive (tid)) {
- trace ("Stopping fetcher thread ... \n");
- deadbeef->mutex_lock (queue_mutex);
- queue_clear ();
- @@ -2089,7 +2106,7 @@ artwork_plugin_stop (void)
- }
- deadbeef->mutex_unlock (queue_mutex);
- deadbeef->thread_join (tid);
- - tid = 0;
- + deadbeef->thread_wipeid (&tid);
- trace ("Fetcher thread stopped\n");
- }
- if (queue_mutex) {
- @@ -2131,7 +2148,7 @@ artwork_plugin_start (void)
- if (queue_mutex && queue_cond) {
- tid = deadbeef->thread_start_low_priority (fetcher_thread, NULL);
- }
- - if (!tid) {
- + if (deadbeef->thread_alive (tid)) {
- artwork_plugin_stop ();
- return -1;
- }
- diff --git a/plugins/artwork/artwork_internal.c b/plugins/artwork/artwork_internal.c
- index f035d3dd..d091ff38 100644
- --- a/plugins/artwork/artwork_internal.c
- +++ b/plugins/artwork/artwork_internal.c
- @@ -26,6 +26,10 @@
- #include "../../config.h"
- #endif
- #include <stdlib.h>
- +#ifdef __MINGW32__
- +#undef __STRICT_ANSI__
- +#undef _NO_OLDNAMES
- +#endif
- #include <string.h>
- #include <libgen.h>
- #include <errno.h>
- @@ -35,6 +39,9 @@
- #include <limits.h>
- #include "../../deadbeef.h"
- #include "artwork_internal.h"
- +#ifdef __MINGW32__
- +#include "../../mingw32_layer.h"
- +#endif
- //#define trace(...) { fprintf(stderr, __VA_ARGS__); }
- #define trace(...)
- @@ -42,7 +49,7 @@
- extern DB_functions_t *deadbeef;
- static DB_FILE *http_request;
- -static uintptr_t http_mutex;
- +static db_mutex_t http_mutex;
- static DB_FILE *
- new_http_request (const char *url)
- diff --git a/plugins/artwork/cache.c b/plugins/artwork/cache.c
- index e178d81f..fe3e70f5 100644
- --- a/plugins/artwork/cache.c
- +++ b/plugins/artwork/cache.c
- @@ -32,19 +32,25 @@
- #include <unistd.h>
- #include <pthread.h>
- #include <sys/stat.h>
- +#ifdef __MINGW32__
- +#undef __STRICT_ANSI__
- +#endif
- #include <limits.h>
- #include "artwork_internal.h"
- #include "../../deadbeef.h"
- +#ifdef __MINGW32__
- +#include "../../mingw32_layer.h"
- +#endif
- //#define trace(...) { fprintf(stderr, __VA_ARGS__); }
- #define trace(...)
- extern DB_functions_t *deadbeef;
- -static uintptr_t files_mutex;
- -static intptr_t tid;
- -static uintptr_t thread_mutex;
- -static uintptr_t thread_cond;
- +static db_mutex_t files_mutex;
- +static db_thread_t tid;
- +static db_mutex_t thread_mutex;
- +static db_cond_t thread_cond;
- static int terminate;
- static int32_t cache_expiry_seconds;
- @@ -204,13 +210,13 @@ void cache_configchanged (void)
- void stop_cache_cleaner (void)
- {
- - if (tid) {
- + if (deadbeef->thread_alive (tid)) {
- deadbeef->mutex_lock (thread_mutex);
- terminate = 1;
- deadbeef->cond_signal (thread_cond);
- deadbeef->mutex_unlock (thread_mutex);
- deadbeef->thread_join (tid);
- - tid = 0;
- + deadbeef->thread_wipeid (&tid);
- trace ("Cache cleaner thread stopped\n");
- }
- @@ -242,7 +248,7 @@ int start_cache_cleaner (void)
- trace ("Cache cleaner thread started\n");
- }
- - if (!tid) {
- + if (deadbeef->thread_alive (tid)) {
- stop_cache_cleaner ();
- return -1;
- }
- diff --git a/plugins/cdda/cdda.c b/plugins/cdda/cdda.c
- index 9ef085d2..79891de3 100644
- --- a/plugins/cdda/cdda.c
- +++ b/plugins/cdda/cdda.c
- @@ -658,13 +658,13 @@ insert_disc (ddb_playlist_t *plt, DB_playItem_t *after, const char *path, const
- if (!(got_cdtext && prefer_cdtext) && enable_cddb) {
- trace("cdda: querying freedb...\n");
- tid = deadbeef->thread_start(cddb_thread, p);
- - if (tid) {
- + if (deadbeef->thread_alive (tid)) {
- deadbeef->thread_detach(tid);
- }
- }
- }
- - if (!tid) {
- + if (!deadbeef->thread_alive (tid)) {
- cleanup_thread_params(p);
- }
- diff --git a/plugins/converter/converter.c b/plugins/converter/converter.c
- index 71b86a94..8c796aad 100644
- --- a/plugins/converter/converter.c
- +++ b/plugins/converter/converter.c
- @@ -29,6 +29,10 @@
- #endif
- #include <stdlib.h>
- #include <limits.h>
- +#ifdef __MINGW32__
- +#undef __STRICT_ANSI__
- +#undef _NO_OLDNAMES
- +#endif
- #include <string.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- @@ -39,6 +43,9 @@
- #include "converter.h"
- #include "../../deadbeef.h"
- #include "../../strdupa.h"
- +#ifdef __MINGW32__
- +#include "../../mingw32_layer.h"
- +#endif
- #ifndef __linux__
- #define O_LARGEFILE 0
- diff --git a/plugins/dca/bitstream.c b/plugins/dca/bitstream.c
- index f77cbc70..baef9874 100644
- --- a/plugins/dca/bitstream.c
- +++ b/plugins/dca/bitstream.c
- @@ -27,6 +27,9 @@
- #include <stdio.h>
- #include <inttypes.h>
- +#ifdef __MINGW32__
- +#include <stdlib.h> /* for the needed 'llabs' */
- +#endif
- #include "dca.h"
- #include "dca_internal.h"
- diff --git a/plugins/dca/downmix.c b/plugins/dca/downmix.c
- index ff02127f..33b488d8 100644
- --- a/plugins/dca/downmix.c
- +++ b/plugins/dca/downmix.c
- @@ -27,6 +27,9 @@
- #include <string.h>
- #include <inttypes.h>
- +#ifdef __MINGW32__
- +#include <stdlib.h> /* for the needed 'llabs' */
- +#endif
- #include "dca.h"
- #include "dca_internal.h"
- diff --git a/plugins/dsp_libsrc/src.c b/plugins/dsp_libsrc/src.c
- index f3103d11..c1a80de4 100644
- --- a/plugins/dsp_libsrc/src.c
- +++ b/plugins/dsp_libsrc/src.c
- @@ -20,6 +20,9 @@
- #include <stdlib.h>
- #include <string.h>
- #include <assert.h>
- +#ifdef __MINGW32__
- +#undef __STRICT_ANSI__
- +#endif
- #include "../../deadbeef.h"
- #include "src.h"
- diff --git a/plugins/ffap/ffap.c b/plugins/ffap/ffap.c
- index 5102c8c4..8c698131 100644
- --- a/plugins/ffap/ffap.c
- +++ b/plugins/ffap/ffap.c
- @@ -38,6 +38,9 @@
- #include <assert.h>
- #include <math.h>
- #include "../../deadbeef.h"
- +#ifdef __MINGW32__
- +#include <malloc.h>
- +#endif
- #ifdef TARGET_ANDROID
- int posix_memalign (void **memptr, size_t alignment, size_t size) {
- @@ -734,8 +737,13 @@ ffap_init (DB_fileinfo_t *_info, DB_playItem_t *it)
- if (!ape_filter_orders[info->ape_ctx.fset][i])
- break;
- info->ape_ctx.filterbuf_size[i] = (ape_filter_orders[info->ape_ctx.fset][i] * 3 + HISTORY_SIZE) * 4;
- +#ifdef __MINGW32__
- + info->ape_ctx.filterbuf[i] = __mingw_aligned_malloc(16, info->ape_ctx.filterbuf_size[i]);
- + if (info->ape_ctx.filterbuf[i] == NULL ) {
- +#else
- int err = posix_memalign ((void **)&info->ape_ctx.filterbuf[i], 16, info->ape_ctx.filterbuf_size[i]);
- if (err) {
- +#endif
- trace ("ffap: out of memory (posix_memalign)\n");
- return -1;
- }
- diff --git a/plugins/flac/flac.c b/plugins/flac/flac.c
- index 9399970b..ff4b8e36 100644
- --- a/plugins/flac/flac.c
- +++ b/plugins/flac/flac.c
- @@ -33,6 +33,11 @@
- #ifdef HAVE_CONFIG_H
- #include <config.h>
- #endif
- +#ifdef __MINGW32__
- +#undef __STRICT_ANSI__
- +#undef _NO_OLDNAMES
- +#include <malloc.h>
- +#endif
- #include <string.h>
- #include <stdio.h>
- #include <stdlib.h>
- diff --git a/plugins/gme/cgme.c b/plugins/gme/cgme.c
- index dff30c5b..655d5452 100644
- --- a/plugins/gme/cgme.c
- +++ b/plugins/gme/cgme.c
- @@ -27,6 +27,10 @@
- #include <stdio.h>
- #include <fcntl.h>
- #include <stdlib.h>
- +#ifdef __MINGW32__
- +#undef __STRICT_ANSI__
- +#undef _NO_OLDNAMES
- +#endif
- #include <string.h>
- #include <math.h>
- #include "gme/gme.h"
- @@ -89,7 +93,7 @@ read_gzfile (const char *fname, char **buffer, int *size) {
- tmp = "/tmp";
- }
- char nm[PATH_MAX];
- -#if defined(ANDROID) || defined(STATICLINK)
- +#if defined(ANDROID) || defined(STATICLINK) || defined(__MINGW32__)
- snprintf (nm, sizeof (nm), "%s/ddbgmeXXXXXX", tmp);
- fd = mkstemp (nm);
- #else
- diff --git a/plugins/gme/game-music-emu-0.6pre/gme/Data_Reader.cpp b/plugins/gme/game-music-emu-0.6pre/gme/Data_Reader.cpp
- index bb5cd52d..ce6c0e0c 100644
- --- a/plugins/gme/game-music-emu-0.6pre/gme/Data_Reader.cpp
- +++ b/plugins/gme/game-music-emu-0.6pre/gme/Data_Reader.cpp
- @@ -4,7 +4,15 @@
- #include "blargg_endian.h"
- #include "blargg_common.h"
- +#ifdef __MINGW32__
- +#define __USE_MINGW_FSEEK /* request mingw internal implementation of fseeko64 */
- +#endif
- #include <stdio.h>
- +#ifdef __MINGW32__
- +#define off_t off64_t
- +#define fseeko fseeko64
- +#define ftello ftello64
- +#endif
- #include <errno.h>
- #if BLARGG_UTF8_PATHS
- diff --git a/plugins/gme/game-music-emu-0.6pre/gme/blargg_source.h b/plugins/gme/game-music-emu-0.6pre/gme/blargg_source.h
- index d7145097..180cba8d 100644
- --- a/plugins/gme/game-music-emu-0.6pre/gme/blargg_source.h
- +++ b/plugins/gme/game-music-emu-0.6pre/gme/blargg_source.h
- @@ -65,7 +65,7 @@ static inline void blargg_dprintf_( const char [], ... ) { }
- #include <stdio.h>
- #undef dprintf
- #define dprintf (1) ? (void) 0 : blargg_dprintf_
- -#ifndef _WIN32
- +#if !defined(_WIN32) || defined(__MINGW32__)
- #include <stdio.h>
- static inline void blargg_dprintf_( const char * fmt, ... )
- {
- diff --git a/plugins/gtkui/actionhandlers.c b/plugins/gtkui/actionhandlers.c
- index 9680f54a..a02e4603 100644
- --- a/plugins/gtkui/actionhandlers.c
- +++ b/plugins/gtkui/actionhandlers.c
- @@ -25,6 +25,10 @@
- #endif
- #include <stdlib.h>
- +#ifdef __MINGW32__
- +#undef __STRICT_ANSI__
- +#undef _NO_OLDNAMES
- +#endif
- #include <string.h>
- #include <gtk/gtk.h>
- #include <unistd.h>
- @@ -772,7 +776,7 @@ action_load_playlist_handler_cb (void *data) {
- gchar *fname = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dlg));
- gtk_widget_destroy (dlg);
- if (fname) {
- - uintptr_t tid = deadbeef->thread_start (load_playlist_thread, fname);
- + db_thread_t tid = deadbeef->thread_start (load_playlist_thread, fname);
- deadbeef->thread_detach (tid);
- }
- }
- diff --git a/plugins/gtkui/actions.c b/plugins/gtkui/actions.c
- index c8e4edd8..9eb2ce9e 100644
- --- a/plugins/gtkui/actions.c
- +++ b/plugins/gtkui/actions.c
- @@ -22,6 +22,10 @@
- */
- #include <stdio.h>
- +#ifdef __MINGW32__
- +#undef __STRICT_ANSI__
- +#undef _NO_OLDNAMES
- +#endif
- #include <string.h>
- #include <stdlib.h>
- diff --git a/plugins/gtkui/callbacks.c b/plugins/gtkui/callbacks.c
- index 25d2f07f..c21c8e6a 100644
- --- a/plugins/gtkui/callbacks.c
- +++ b/plugins/gtkui/callbacks.c
- @@ -25,6 +25,9 @@
- # include <config.h>
- #endif
- +#ifdef __MINGW32__
- +#undef __STRICT_ANSI__
- +#endif
- #include <gtk/gtk.h>
- #include <math.h>
- #include <stdlib.h>
- @@ -33,7 +36,7 @@
- #include <assert.h>
- #include <ctype.h>
- #include <gdk/gdkkeysyms.h>
- -#ifndef __APPLE__
- +#if !defined(__APPLE__) && !defined(__MINGW32__)
- #include <X11/Xlib.h>
- #endif
- #include "../../gettext.h"
- diff --git a/plugins/gtkui/coverart.c b/plugins/gtkui/coverart.c
- index 590dfc71..35b57db6 100644
- --- a/plugins/gtkui/coverart.c
- +++ b/plugins/gtkui/coverart.c
- @@ -22,6 +22,10 @@
- */
- #include <sys/time.h>
- +#ifdef __MINGW32__
- +#undef __STRICT_ANSI__
- +#undef _NO_OLDNAMES
- +#endif
- #include <string.h>
- #include <stdlib.h>
- #include <pthread.h>
- @@ -76,9 +80,9 @@ typedef struct load_query_s {
- } load_query_t;
- static int terminate;
- -static uintptr_t mutex;
- -static uintptr_t cond;
- -static uintptr_t tid;
- +static db_mutex_t mutex;
- +static db_cond_t cond;
- +static db_thread_t tid;
- static load_query_t *queue;
- static load_query_t *tail;
- @@ -664,14 +668,14 @@ void
- cover_art_free (void) {
- trace ("coverart: terminating cover art loader...\n");
- - if (tid) {
- + if (deadbeef->thread_alive (tid)) {
- deadbeef->mutex_lock(mutex);
- terminate = 1;
- trace("coverart: sending terminate signal to art loader thread...\n");
- deadbeef->cond_signal(cond);
- deadbeef->mutex_unlock(mutex);
- deadbeef->thread_join(tid);
- - tid = 0;
- + deadbeef->thread_wipeid (&tid);
- }
- while (queue) {
- diff --git a/plugins/gtkui/ddblistview.c b/plugins/gtkui/ddblistview.c
- index 64e530e9..20f86519 100644
- --- a/plugins/gtkui/ddblistview.c
- +++ b/plugins/gtkui/ddblistview.c
- @@ -29,6 +29,10 @@
- #include <math.h>
- #include <stdlib.h>
- #include <time.h>
- +#ifdef __MINGW32__
- +#undef __STRICT_ANSI__
- +#undef _NO_OLDNAMES
- +#endif
- #include <string.h>
- #include <unistd.h>
- #include <ctype.h>
- diff --git a/plugins/gtkui/dspconfig.c b/plugins/gtkui/dspconfig.c
- index 60fd7127..b315dc64 100644
- --- a/plugins/gtkui/dspconfig.c
- +++ b/plugins/gtkui/dspconfig.c
- @@ -25,9 +25,15 @@
- # include <config.h>
- #endif
- +#ifdef __MINGW32__
- +#undef __STRICT_ANSI__
- +#endif
- #include <gtk/gtk.h>
- #include <math.h>
- #include <stdlib.h>
- +#ifdef __MINGW32__
- +#undef _NO_OLDNAMES
- +#endif
- #include <string.h>
- #include <unistd.h>
- #include <assert.h>
- @@ -39,6 +45,9 @@
- #include "../../deadbeef.h"
- #include "gtkui.h"
- #include "pluginconf.h"
- +#ifdef __MINGW32__
- +#include "mingw32_layer.h"
- +#endif
- static ddb_dsp_context_t *chain;
- static GtkWidget *prefwin;
- diff --git a/plugins/gtkui/fileman.c b/plugins/gtkui/fileman.c
- index 0a074185..5b8e2f64 100644
- --- a/plugins/gtkui/fileman.c
- +++ b/plugins/gtkui/fileman.c
- @@ -112,7 +112,7 @@ add_dirs_worker (void *data) {
- void
- gtkui_add_dirs (GSList *lst) {
- - intptr_t tid = deadbeef->thread_start (add_dirs_worker, lst);
- + db_thread_t tid = deadbeef->thread_start (add_dirs_worker, lst);
- deadbeef->thread_detach (tid);
- }
- @@ -124,7 +124,7 @@ add_files_worker (void *data) {
- void
- gtkui_add_files (struct _GSList *lst) {
- - intptr_t tid = deadbeef->thread_start (add_files_worker, lst);
- + db_thread_t tid = deadbeef->thread_start (add_files_worker, lst);
- deadbeef->thread_detach (tid);
- }
- @@ -144,7 +144,7 @@ gtkui_open_files (struct _GSList *lst) {
- deadbeef->pl_clear ();
- deadbeef->sendmessage (DB_EV_PLAYLISTCHANGED, 0, DDB_PLAYLIST_CHANGE_CONTENT, 0);
- - intptr_t tid = deadbeef->thread_start (open_files_worker, lst);
- + db_thread_t tid = deadbeef->thread_start (open_files_worker, lst);
- deadbeef->thread_detach (tid);
- }
- @@ -297,6 +297,6 @@ gtkui_receive_fm_drop (DB_playItem_t *before, char *mem, int length) {
- }
- data->drop_before = before;
- // since it happens in separate thread, we need to addref
- - intptr_t tid = deadbeef->thread_start (fmdrop_worker, data);
- + db_thread_t tid = deadbeef->thread_start (fmdrop_worker, data);
- deadbeef->thread_detach (tid);
- }
- diff --git a/plugins/gtkui/gtkui.c b/plugins/gtkui/gtkui.c
- index 8a3dd6b0..83e8a0c0 100644
- --- a/plugins/gtkui/gtkui.c
- +++ b/plugins/gtkui/gtkui.c
- @@ -27,6 +27,10 @@
- #ifdef HAVE_CONFIG_H
- #include "../../config.h"
- #endif
- +#ifdef __MINGW32__
- +#undef __STRICT_ANSI__
- +#undef _NO_OLDNAMES
- +#endif
- #include <string.h>
- #include <stdlib.h>
- #include <math.h>
- @@ -57,11 +61,13 @@
- #include "gtkui_api.h"
- #include "wingeom.h"
- #include "widgets.h"
- +#ifndef __MINGW32__
- #ifndef __APPLE__
- #include "X11/Xlib.h"
- #else
- #include "retina.h"
- #endif
- +#endif
- #include "actionhandlers.h"
- #include "hotkeys.h"
- #include "../hotkeys/hotkeys.h"
- @@ -547,7 +553,11 @@ gtkui_update_status_icon (gpointer unused) {
- if (!gtk_icon_theme_has_icon(theme, icon_name)) {
- char iconpath[1024];
- +#ifdef __MINGW32__
- + snprintf (iconpath, sizeof (iconpath), "%s/deadbeef.png", deadbeef->get_pixmap_dir ());
- +#else
- snprintf (iconpath, sizeof (iconpath), "%s/deadbeef.png", deadbeef->get_prefix ());
- +#endif
- trayicon = gtk_status_icon_new_from_file(iconpath);
- }
- else {
- @@ -1054,7 +1064,11 @@ gtkui_thread (void *ctx) {
- else {
- // try loading icon from $prefix/deadbeef.png (for static build)
- char iconpath[1024];
- +#ifdef __MINGW32__
- + snprintf (iconpath, sizeof (iconpath), "%s/deadbeef.png", deadbeef->get_pixmap_dir ());
- +#else
- snprintf (iconpath, sizeof (iconpath), "%s/deadbeef.png", deadbeef->get_prefix ());
- +#endif
- gtk_window_set_icon_from_file (GTK_WINDOW (mainwin), iconpath, NULL);
- }
- diff --git a/plugins/gtkui/hotkeys.c b/plugins/gtkui/hotkeys.c
- index e9ef508d..a0fbc2aa 100644
- --- a/plugins/gtkui/hotkeys.c
- +++ b/plugins/gtkui/hotkeys.c
- @@ -49,6 +49,10 @@ typedef struct
- # include <config.h>
- #endif
- #include <gtk/gtk.h>
- +#ifdef __MINGW32__
- +#undef __STRICT_ANSI__
- +#undef _NO_OLDNAMES
- +#endif
- #include <string.h>
- #include <stdlib.h>
- #include "../../gettext.h"
- @@ -57,7 +61,7 @@ typedef struct
- #include "interface.h"
- #include "../libparser/parser.h"
- #include "../hotkeys/hotkeys.h"
- -#ifndef __APPLE__
- +#if !defined(__APPLE__) && !defined(__MINGW32__)
- #include <X11/Xlib.h> // only for the KeySym type
- #endif
- #include "hotkeys.h"
- diff --git a/plugins/gtkui/mainplaylist.c b/plugins/gtkui/mainplaylist.c
- index a02a55ee..53616ff7 100644
- --- a/plugins/gtkui/mainplaylist.c
- +++ b/plugins/gtkui/mainplaylist.c
- @@ -25,6 +25,10 @@
- # include <config.h>
- #endif
- #include <stdlib.h>
- +#ifdef __MINGW32__
- +#undef __STRICT_ANSI__
- +#undef _NO_OLDNAMES
- +#endif
- #include <string.h>
- #include "../../gettext.h"
- #include "../libparser/parser.h"
- diff --git a/plugins/gtkui/plcommon.c b/plugins/gtkui/plcommon.c
- index 27b3faff..86c62445 100644
- --- a/plugins/gtkui/plcommon.c
- +++ b/plugins/gtkui/plcommon.c
- @@ -22,6 +22,10 @@
- */
- #include <stdlib.h>
- +#ifdef __MINGW32__
- +#undef __STRICT_ANSI__
- +#undef _NO_OLDNAMES
- +#endif
- #include <string.h>
- #include <unistd.h>
- #include <gdk/gdkkeysyms.h>
- diff --git a/plugins/gtkui/prefwin.c b/plugins/gtkui/prefwin.c
- index 2d753040..855f3b73 100644
- --- a/plugins/gtkui/prefwin.c
- +++ b/plugins/gtkui/prefwin.c
- @@ -25,6 +25,10 @@
- # include <config.h>
- #endif
- #include <gtk/gtk.h>
- +#ifdef __MINGW32__
- +#undef __STRICT_ANSI__
- +#undef _NO_OLDNAMES
- +#endif
- #include <string.h>
- #include <assert.h>
- #include <stdlib.h>
- diff --git a/plugins/gtkui/search.c b/plugins/gtkui/search.c
- index ab570f36..3ea0fba5 100644
- --- a/plugins/gtkui/search.c
- +++ b/plugins/gtkui/search.c
- @@ -29,6 +29,10 @@
- #include <gdk/gdkkeysyms.h>
- #include <math.h>
- #include <stdlib.h>
- +#ifdef __MINGW32__
- +#undef __STRICT_ANSI__
- +#undef _NO_OLDNAMES
- +#endif
- #include <string.h>
- #include "../../gettext.h"
- diff --git a/plugins/gtkui/trkproperties.c b/plugins/gtkui/trkproperties.c
- index f90ad6cf..e83fcfef 100644
- --- a/plugins/gtkui/trkproperties.c
- +++ b/plugins/gtkui/trkproperties.c
- @@ -26,6 +26,10 @@
- #endif
- #include <gtk/gtk.h>
- #include <gdk/gdkkeysyms.h>
- +#ifdef __MINGW32__
- +#undef __STRICT_ANSI__
- +#undef _NO_OLDNAMES
- +#endif
- #include <string.h>
- #include <math.h>
- #include <assert.h>
- @@ -723,7 +727,7 @@ on_write_tags_clicked (GtkButton *button,
- gtk_window_set_transient_for (GTK_WINDOW (progressdlg), GTK_WINDOW (trackproperties));
- // start new thread for writing metadata
- - intptr_t tid = deadbeef->thread_start (write_meta_worker, NULL);
- + db_thread_t tid = deadbeef->thread_start (write_meta_worker, NULL);
- deadbeef->thread_detach (tid);
- }
- diff --git a/plugins/gtkui/widgets.c b/plugins/gtkui/widgets.c
- index 198a8666..58f5860f 100644
- --- a/plugins/gtkui/widgets.c
- +++ b/plugins/gtkui/widgets.c
- @@ -22,6 +22,10 @@
- */
- #include <stdlib.h>
- +#ifdef __MINGW32__
- +#undef __STRICT_ANSI__
- +#undef _NO_OLDNAMES
- +#endif
- #include <string.h>
- #include <assert.h>
- #include <math.h>
- @@ -155,7 +159,7 @@ typedef struct {
- float *samples;
- int nsamples;
- int resized;
- - intptr_t mutex;
- + db_mutex_t mutex;
- cairo_surface_t *surf;
- } w_scope_t;
- diff --git a/plugins/hotkeys/hotkeys.c b/plugins/hotkeys/hotkeys.c
- index 1485dfbc..b930c19b 100644
- --- a/plugins/hotkeys/hotkeys.c
- +++ b/plugins/hotkeys/hotkeys.c
- @@ -504,7 +504,7 @@ static int
- hotkeys_connect (void) {
- #ifndef __APPLE__
- finished = 0;
- - loop_tid = 0;
- + deadbeef->thread_wipeid (&loop_tid);
- disp = XOpenDisplay (NULL);
- if (!disp)
- {
- @@ -533,7 +533,7 @@ hotkeys_connect (void) {
- static int
- hotkeys_disconnect (void) {
- #ifndef __APPLE__
- - if (loop_tid) {
- + if (deadbeef->thread_alive (loop_tid)) {
- finished = 1;
- deadbeef->thread_join (loop_tid);
- }
- diff --git a/plugins/lastfm/lastfm.c b/plugins/lastfm/lastfm.c
- index c5ec862e..5813c1c1 100644
- --- a/plugins/lastfm/lastfm.c
- +++ b/plugins/lastfm/lastfm.c
- @@ -789,7 +789,7 @@ lastfm_stop (void) {
- deadbeef->cond_signal (lfm_cond);
- trace ("waiting for thread to finish\n");
- deadbeef->thread_join (lfm_tid);
- - lfm_tid = 0;
- + deadbeef->thread_wipeid (&lfm_tid);
- deadbeef->cond_free (lfm_cond);
- deadbeef->mutex_free (lfm_mutex);
- }
- diff --git a/plugins/libmp4ff/mp4ff_int_types.h b/plugins/libmp4ff/mp4ff_int_types.h
- index 15e7fd60..5fcbc05c 100644
- --- a/plugins/libmp4ff/mp4ff_int_types.h
- +++ b/plugins/libmp4ff/mp4ff_int_types.h
- @@ -1,11 +1,11 @@
- #ifndef _MP4FF_INT_TYPES_H_
- #define _MP4FF_INT_TYPES_H_
- -#if defined (_WIN32)
- +#if defined (_WIN32) && !defined(__MINGW32__)
- -#ifdef __MINGW32__
- -#include <stdlib.h>
- -#endif /* #ifdef __MINGW32__ */
- +//#ifdef __MINGW32__
- +//#include <stdlib.h>
- +//#endif /* #ifdef __MINGW32__ */
- typedef signed char int8_t;
- typedef unsigned char uint8_t;
- diff --git a/plugins/liboggedit/oggedit_flac.c b/plugins/liboggedit/oggedit_flac.c
- index 8a238f72..c80252fe 100644
- --- a/plugins/liboggedit/oggedit_flac.c
- +++ b/plugins/liboggedit/oggedit_flac.c
- @@ -30,6 +30,9 @@
- #include <stdlib.h>
- #include <string.h>
- #include <unistd.h>
- +#ifdef __MINGW32__
- +#undef __STRICT_ANSI__
- +#endif
- #include <limits.h>
- #include "oggedit_internal.h"
- diff --git a/plugins/liboggedit/oggedit_internal.c b/plugins/liboggedit/oggedit_internal.c
- index a7a6acda..73c1777e 100644
- --- a/plugins/liboggedit/oggedit_internal.c
- +++ b/plugins/liboggedit/oggedit_internal.c
- @@ -29,6 +29,10 @@
- #endif
- #include <stdio.h>
- #include <stdlib.h>
- +#ifdef __MINGW32__
- +#undef __STRICT_ANSI__
- +#undef _NO_OLDNAMES
- +#endif
- #include <string.h>
- #include <unistd.h>
- #include <libgen.h>
- @@ -36,6 +40,9 @@
- #include <sys/stat.h>
- #include <limits.h>
- #include "oggedit_internal.h"
- +#ifdef __MINGW32__
- +#include "mingw32_layer.h"
- +#endif
- static char *cat_string(char *dest, const char *src, const char *sep)
- {
- diff --git a/plugins/liboggedit/oggedit_opus.c b/plugins/liboggedit/oggedit_opus.c
- index bdf46124..b4478dc5 100644
- --- a/plugins/liboggedit/oggedit_opus.c
- +++ b/plugins/liboggedit/oggedit_opus.c
- @@ -30,6 +30,9 @@
- #include <stdlib.h>
- #include <string.h>
- #include <unistd.h>
- +#ifdef __MINGW32__
- +#undef __STRICT_ANSI__
- +#endif
- #include <limits.h>
- #include "oggedit_internal.h"
- diff --git a/plugins/liboggedit/oggedit_utils.c b/plugins/liboggedit/oggedit_utils.c
- index e01d8294..4fd42471 100644
- --- a/plugins/liboggedit/oggedit_utils.c
- +++ b/plugins/liboggedit/oggedit_utils.c
- @@ -29,6 +29,10 @@
- #endif
- #include <stdlib.h>
- #include <stdint.h>
- +#ifdef __MINGW32__
- +#undef __STRICT_ANSI__
- +#undef _NO_OLDNAMES
- +#endif
- #include <string.h>
- #include <ctype.h>
- #include "oggedit_internal.h"
- diff --git a/plugins/liboggedit/oggedit_vorbis.c b/plugins/liboggedit/oggedit_vorbis.c
- index 9ea0474b..f4c06b5f 100644
- --- a/plugins/liboggedit/oggedit_vorbis.c
- +++ b/plugins/liboggedit/oggedit_vorbis.c
- @@ -30,6 +30,9 @@
- #include <stdlib.h>
- #include <string.h>
- #include <unistd.h>
- +#ifdef __MINGW32__
- +#undef __STRICT_ANSI__
- +#endif
- #include <limits.h>
- #include "oggedit_internal.h"
- diff --git a/plugins/m3u/m3u.c b/plugins/m3u/m3u.c
- index af942739..84253f2b 100644
- --- a/plugins/m3u/m3u.c
- +++ b/plugins/m3u/m3u.c
- @@ -24,12 +24,19 @@
- #ifdef HAVE_CONFIG_H
- # include "../../config.h"
- #endif
- +#ifdef __MINGW32__
- +#undef __STRICT_ANSI__
- +#undef _NO_OLDNAMES
- +#endif
- #include <string.h>
- #include <stdlib.h>
- #include <limits.h>
- #include <math.h> // for ceil
- #include "../../deadbeef.h"
- +#ifdef __MINGW32__
- +#include "mingw32_layer.h"
- +#endif
- //#define trace(...) { fprintf(stderr, __VA_ARGS__); }
- #define trace(fmt,...)
- diff --git a/plugins/mms/libmms/mms.c b/plugins/mms/libmms/mms.c
- index b23130fe..5c3d56d9 100644
- --- a/plugins/mms/libmms/mms.c
- +++ b/plugins/mms/libmms/mms.c
- @@ -28,11 +28,25 @@
- #include "config.h"
- #endif
- -#include <unistd.h>
- -#include <stdio.h>
- +#ifdef __MINGW32__
- +#define __USE_MINGW_FSEEK /* request mingw internal implementation of fseeko64 */
- +#undef __STRICT_ANSI__
- +#undef _NO_OLDNAMES
- +#define WINVER 0x0501
- +#include <winsock2.h>
- +#include <ws2tcpip.h>
- +#else
- #include <sys/socket.h>
- #include <netinet/in.h>
- #include <netdb.h>
- +#endif
- +#include <unistd.h>
- +#include <stdio.h>
- +#ifdef __MINGW32__
- +#define off_t __int64
- +#define fseeko fseeko64
- +#define ftello ftello64
- +#endif
- #include <string.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- @@ -51,6 +65,14 @@
- extern DB_functions_t *deadbeef;
- #endif
- +#ifdef __MINGW32__
- +#include "../../../mingw32_layer.h"
- +#define MSG_DONTWAIT 0 /* useless when you set all your sockets as 'non-blocking' */
- +#define EINPROGRESS WSAEINPROGRESS
- +#define EALREADY WSAEALREADY
- +#define EISCONN WSAEISCONN
- +#endif
- +
- /********** logging **********/
- #define lprintf(...) if (getenv("LIBMMS_DEBUG")) fprintf(stderr, __VA_ARGS__)
- @@ -256,7 +278,12 @@ static int fallback_io_tcp_connect(void *data, const char *host, int port, int *
- return -1;
- }
- +#ifdef __MINGW32__
- + unsigned long flags = 1;
- + if (ioctlsocket(s, FIONBIO, &flags) == SOCKET_ERROR) {
- +#else
- if (fcntl (s, F_SETFL, fcntl (s, F_GETFL) | O_NONBLOCK) == -1) {
- +#endif
- lprintf("mms: failed to set socket flags: %s\n", strerror(errno));
- return -1;
- }
- @@ -326,7 +353,11 @@ static int fallback_io_tcp_connect(void *data, const char *host, int port, int *
- freeaddrinfo(res);
- }
- #endif
- +#ifdef __MINGW32__
- + closesocket(s);
- +#else
- close(s);
- +#endif
- return -1;
- }
- @@ -1390,7 +1421,11 @@ mms_t *mms_connect (mms_io_t *io, void *data, const char *url, int bandwidth, in
- fail:
- if (this->s != -1)
- +#ifdef __MINGW32__
- + closesocket (this->s);
- +#else
- close (this->s);
- +#endif
- if (this->url)
- free(this->url);
- if (this->guri)
- @@ -1873,7 +1908,11 @@ off_t mms_seek (mms_io_t *io, mms_t *this, off_t offset, int origin) {
- void mms_close (mms_t *this) {
- if (this->s != -1)
- +#ifdef __MINGW32__
- + closesocket (this->s);
- +#else
- close (this->s);
- +#endif
- if (this->url)
- free(this->url);
- if (this->guri)
- diff --git a/plugins/mms/libmms/mmsh.c b/plugins/mms/libmms/mmsh.c
- index 0606ac53..084bfac2 100644
- --- a/plugins/mms/libmms/mmsh.c
- +++ b/plugins/mms/libmms/mmsh.c
- @@ -34,12 +34,28 @@
- #include "config.h"
- #endif
- +#ifdef __MINGW32__
- +#undef __STRICT_ANSI__
- +#endif
- #include <unistd.h>
- -#include <stdio.h>
- #include <stdlib.h>
- +#ifdef __MINGW32__
- +#define __USE_MINGW_FSEEK /* request mingw internal implementation of fseeko64 */
- +#undef __STRICT_ANSI__
- +#undef _NO_OLDNAMES
- +#include <winsock2.h>
- +#define EINPROGRESS WSAEINPROGRESS
- +#else
- #include <sys/socket.h>
- #include <netinet/in.h>
- #include <netdb.h>
- +#endif
- +#include <stdio.h>
- +#ifdef __MINGW32__
- +#define off_t off64_t
- +#define fseeko fseeko64
- +#define ftello ftello64
- +#endif
- #include <string.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- @@ -266,7 +282,12 @@ static int fallback_io_tcp_connect(void *data, const char *host, int port, int *
- return -1;
- }
- +#ifdef __MINGW32__
- + unsigned long flags = 1;
- + if (ioctlsocket(s, FIONBIO, &flags) == SOCKET_ERROR) {
- +#else
- if (fcntl (s, F_SETFL, fcntl (s, F_GETFL) & ~O_NONBLOCK) == -1) {
- +#endif
- lprintf("mmsh: failed to set socket flags: %s\n", strerror(errno));
- return -1;
- }
- @@ -286,7 +307,11 @@ static int fallback_io_tcp_connect(void *data, const char *host, int port, int *
- return s;
- }
- +#ifdef __MINGW32__
- + closesocket(s);
- +#else
- close(s);
- +#endif
- return -1;
- }
- @@ -847,7 +872,11 @@ static int mmsh_connect_int (mms_io_t *io, mmsh_t *this, off_t seek, uint32_t ti
- /* Close exisiting connection (if any) and connect */
- if (this->s != -1)
- +#ifdef __MINGW32__
- + closesocket(this->s);
- +#else
- close(this->s);
- +#endif
- if (mmsh_tcp_connect(io, this)) {
- return 0;
- @@ -878,7 +907,11 @@ static int mmsh_connect_int (mms_io_t *io, mmsh_t *this, off_t seek, uint32_t ti
- if (!this->packet_length || !this->num_stream_ids)
- goto fail;
- +#ifdef __MINGW32__
- + closesocket(this->s);
- +#else
- close(this->s);
- +#endif
- /* choose the best quality for the audio stream */
- /* i've never seen more than one audio stream */
- @@ -1012,7 +1045,11 @@ static int mmsh_connect_int (mms_io_t *io, mmsh_t *this, off_t seek, uint32_t ti
- }
- return 1;
- fail:
- +#ifdef __MINGW32__
- + closesocket(this->s);
- +#else
- close(this->s);
- +#endif
- this->s = -1;
- return 0;
- }
- @@ -1133,7 +1170,11 @@ fail:
- if (uri)
- gnet_uri_delete(uri);
- if (this->s != -1)
- +#ifdef __MINGW32__
- + closesocket(this->s);
- +#else
- close(this->s);
- +#endif
- if (this->url)
- free(this->url);
- if (this->proxy_url)
- @@ -1362,7 +1403,11 @@ off_t mmsh_seek (mms_io_t *io, mmsh_t *this, off_t offset, int origin) {
- this->packet_length != orig_asf_packet_len) {
- lprintf("mmsh: AIIEEE asf header or packet length changed on re-open for seek\n");
- /* Its a different stream, so its useless! */
- +#ifdef __MINGW32__
- + closesocket (this->s);
- +#else
- close (this->s);
- +#endif
- this->s = -1;
- return this->current_pos = -1;
- }
- @@ -1404,7 +1449,11 @@ off_t mmsh_seek (mms_io_t *io, mmsh_t *this, off_t offset, int origin) {
- this->packet_length != orig_asf_packet_len) {
- lprintf("mmsh: AIIEEE asf header or packet length changed on re-open for seek\n");
- /* Its a different stream, so its useless! */
- +#ifdef __MINGW32__
- + closesocket (this->s);
- +#else
- close (this->s);
- +#endif
- this->s = -1;
- return this->current_pos = -1;
- }
- @@ -1456,7 +1505,11 @@ int mmsh_time_seek (mms_io_t *io, mmsh_t *this, double time_sec) {
- this->packet_length != orig_asf_packet_len) {
- lprintf("mmsh: AIIEEE asf header or packet length changed on re-open for seek\n");
- /* Its a different stream, so its useless! */
- +#ifdef __MINGW32__
- + closesocket (this->s);
- +#else
- close (this->s);
- +#endif
- this->s = -1;
- this->current_pos = -1;
- return 0;
- @@ -1474,7 +1527,11 @@ int mmsh_time_seek (mms_io_t *io, mmsh_t *this, double time_sec) {
- void mmsh_close (mmsh_t *this) {
- if (this->s != -1)
- +#ifdef __MINGW32__
- + closesocket(this->s);
- +#else
- close(this->s);
- +#endif
- if (this->url)
- free(this->url);
- if (this->proxy_url)
- diff --git a/plugins/mms/libmms/mmsio.h b/plugins/mms/libmms/mmsio.h
- index 376e6736..f897993e 100644
- --- a/plugins/mms/libmms/mmsio.h
- +++ b/plugins/mms/libmms/mmsio.h
- @@ -3,6 +3,11 @@
- #define LIBMMS_HAVE_64BIT_OFF_T 1
- +#ifdef __MINGW32__
- +#undef __STRICT_ANSI__
- +#include <sys/types.h>
- +#define mms_off_t off64_t
- +#else
- /* On 64 bit file offset capable systems, libmms' configure script adds
- -D_FILE_OFFSET_BITS=64 to the CFLAGS. This causes off_t to be 64 bit,
- When an app which includes this header file gets compiled without
- @@ -13,6 +18,7 @@
- #else
- #define mms_off_t off_t
- #endif
- +#endif /* __MINGW32__ */
- #ifdef __cplusplus
- extern "C" {
- diff --git a/plugins/mms/libmms/uri.c b/plugins/mms/libmms/uri.c
- index 38bb8dba..2756508e 100644
- --- a/plugins/mms/libmms/uri.c
- +++ b/plugins/mms/libmms/uri.c
- @@ -18,6 +18,10 @@
- */
- /* FIXME: #include "gnet-private.h" */
- +#ifdef __MINGW32__
- +#undef __STRICT_ANSI__
- +#undef _NO_OLDNAMES
- +#endif
- #include <string.h>
- #include <stdlib.h>
- #include <ctype.h>
- diff --git a/plugins/mms/mmsplug.c b/plugins/mms/mmsplug.c
- index da07dc2a..17bbdc13 100644
- --- a/plugins/mms/mmsplug.c
- +++ b/plugins/mms/mmsplug.c
- @@ -21,6 +21,10 @@
- 3. This notice may not be removed or altered from any source distribution.
- */
- +#ifdef __MINGW32__
- +#undef __STRICT_ANSI__
- +#undef _NO_OLDNAMES
- +#endif
- #include "../../deadbeef.h"
- #include <stdio.h>
- #include <stdlib.h>
- diff --git a/plugins/mp3/mp3.c b/plugins/mp3/mp3.c
- index a206c85f..c920efeb 100644
- --- a/plugins/mp3/mp3.c
- +++ b/plugins/mp3/mp3.c
- @@ -22,6 +22,9 @@
- */
- #include <string.h>
- +#ifdef __MINGW32__
- +#undef __STRICT_ANSI__
- +#endif
- #include <stdio.h>
- #include <assert.h>
- #include <stdlib.h>
- diff --git a/plugins/nullout/nullout.c b/plugins/nullout/nullout.c
- old mode 100644
- new mode 100755
- index b98dc3d0..2e6e09b1
- --- a/plugins/nullout/nullout.c
- +++ b/plugins/nullout/nullout.c
- @@ -30,18 +30,22 @@
- #include <string.h>
- #include "../../deadbeef.h"
- -//#define trace(...) { fprintf(stderr, __VA_ARGS__); }
- +#define NULLOUT_AUDIO_BLOCK_DURATION 32 /* ms */
- +
- +//#define trace(...) { fprintf(stderr, __VA_ARGS__); fflush(stderr);}
- #define trace(fmt,...)
- static DB_output_t plugin;
- DB_functions_t *deadbeef;
- -static intptr_t null_tid;
- +static db_thread_t null_tid;
- static int null_terminate;
- static int state;
- +static int nullout_simulate = 0;
- +int bytesread, block_size;
- -static void
- -pnull_callback (char *stream, int len);
- +//static void
- +//pnull_callback (char *stream, int len);
- static void
- pnull_thread (void *context);
- @@ -71,14 +75,27 @@ int
- pnull_init (void) {
- trace ("pnull_init\n");
- state = OUTPUT_STATE_STOPPED;
- + nullout_simulate = deadbeef->conf_get_int ("null.simulate", 0);
- null_terminate = 0;
- null_tid = deadbeef->thread_start (pnull_thread, NULL);
- return 0;
- }
- +static int
- +null_message (uint32_t id, uintptr_t ctx, uint32_t p1, uint32_t p2) {
- + switch (id) {
- + case DB_EV_CONFIGCHANGED:
- + nullout_simulate = deadbeef->conf_get_int ("null.simulate", 0);
- + break;
- + }
- + return 0;
- +}
- +
- int
- pnull_setformat (ddb_waveformat_t *fmt) {
- memcpy (&plugin.fmt, fmt, sizeof (ddb_waveformat_t));
- + block_size = (plugin.fmt.bps*plugin.fmt.samplerate*plugin.fmt.channels)*NULLOUT_AUDIO_BLOCK_DURATION/8000;
- + trace("nullout: new format sr %d ch %d bps %d - block_size=%d\n",plugin.fmt.samplerate,plugin.fmt.channels,plugin.fmt.bps,block_size);
- return 0;
- }
- @@ -86,11 +103,11 @@ int
- pnull_free (void) {
- trace ("pnull_free\n");
- if (!null_terminate) {
- - if (null_tid) {
- + if (deadbeef->thread_alive (null_tid)) {
- null_terminate = 1;
- deadbeef->thread_join (null_tid);
- }
- - null_tid = 0;
- + deadbeef->thread_wipeid (&null_tid);
- state = OUTPUT_STATE_STOPPED;
- null_terminate = 0;
- }
- @@ -99,7 +116,7 @@ pnull_free (void) {
- int
- pnull_play (void) {
- - if (!null_tid) {
- + if (!deadbeef->thread_alive (null_tid)) {
- pnull_init ();
- }
- state = OUTPUT_STATE_PLAYING;
- @@ -132,6 +149,7 @@ pnull_unpause (void) {
- return 0;
- }
- +#if 0
- static int
- pnull_get_endianness (void) {
- #if WORDS_BIGENDIAN
- @@ -140,9 +158,14 @@ pnull_get_endianness (void) {
- return 0;
- #endif
- }
- +#endif
- static void
- pnull_thread (void *context) {
- +#define AUDIO_BUFFER_SIZE (4*1024)
- + char buf[AUDIO_BUFFER_SIZE];
- + int playable=0;
- + float sleep_time;
- #ifdef __linux__
- prctl (PR_SET_NAME, "deadbeef-null", 0, 0, 0, 0);
- #endif
- @@ -151,27 +174,47 @@ pnull_thread (void *context) {
- break;
- }
- if (state != OUTPUT_STATE_PLAYING) {
- - usleep (10000);
- + usleep (16000);
- continue;
- }
- - char buf[4096];
- - pnull_callback (buf, 1024);
- + //pnull_callback (buf, AUDIO_BUFFER_SIZE);
- + /* receiving audio data */
- + do
- + {
- + bytesread = 0;
- + if(deadbeef->streamer_ok_to_read(AUDIO_BUFFER_SIZE))
- + {
- + bytesread = deadbeef->streamer_read (buf, AUDIO_BUFFER_SIZE);
- + playable += bytesread;
- + }
- + }
- + while(bytesread > 0 && playable < block_size);
- + /* 'consuming' audio data */
- + if (nullout_simulate)
- + {
- + sleep_time = 8000000.0/plugin.fmt.samplerate*((playable<block_size)?playable:block_size)/plugin.fmt.channels/plugin.fmt.bps;
- + playable = (playable<block_size)? 0 : (playable%block_size);
- + usleep((int)sleep_time);
- + }
- }
- }
- +#if 0
- static void
- pnull_callback (char *stream, int len) {
- if (!deadbeef->streamer_ok_to_read (len)) {
- memset (stream, 0, len);
- + bytesread = 0;
- return;
- }
- - int bytesread = deadbeef->streamer_read (stream, len);
- + bytesread = deadbeef->streamer_read (stream, len);
- if (bytesread < len) {
- memset (stream + bytesread, 0, len-bytesread);
- }
- }
- +#endif
- int
- pnull_get_state (void) {
- @@ -194,12 +237,16 @@ nullout_load (DB_functions_t *api) {
- return DB_PLUGIN (&plugin);
- }
- +static const char settings_dlg[] =
- + "property \"Simulate audio output\" checkbox null.simulate 0;\n"
- +;
- +
- // define plugin interface
- static DB_output_t plugin = {
- .plugin.api_vmajor = 1,
- .plugin.api_vminor = 0,
- .plugin.version_major = 1,
- - .plugin.version_minor = 0,
- + .plugin.version_minor = 1,
- .plugin.type = DB_PLUGIN_OUTPUT,
- .plugin.id = "nullout",
- .plugin.name = "Null output plugin",
- @@ -229,6 +276,8 @@ static DB_output_t plugin = {
- .plugin.website = "http://deadbeef.sf.net",
- .plugin.start = null_start,
- .plugin.stop = null_stop,
- + .plugin.configdialog = settings_dlg,
- + .plugin.message = null_message,
- .init = pnull_init,
- .free = pnull_free,
- .setformat = pnull_setformat,
- diff --git a/plugins/pltbrowser/pltbrowser.c b/plugins/pltbrowser/pltbrowser.c
- index 009c3ca3..8bcd6051 100644
- --- a/plugins/pltbrowser/pltbrowser.c
- +++ b/plugins/pltbrowser/pltbrowser.c
- @@ -23,6 +23,10 @@
- #include "../../deadbeef.h"
- #include <gtk/gtk.h>
- #include <stdlib.h>
- +#ifdef __MINGW32__
- +#undef __STRICT_ANSI__
- +#undef _NO_OLDNAMES
- +#endif
- #include <string.h>
- #ifdef HAVE_CONFIG_H
- #include "../../config.h"
- diff --git a/plugins/pulse/pulse.c b/plugins/pulse/pulse.c
- index a2dca968..b18efe11 100644
- --- a/plugins/pulse/pulse.c
- +++ b/plugins/pulse/pulse.c
- @@ -220,12 +220,12 @@ static int pulse_free(void)
- {
- trace("pulse_free\n");
- - if (!pulse_tid) {
- + if (!deadbeef->thread_alive (pulse_tid)) {
- return 0;
- }
- intptr_t tid = pulse_tid;
- - pulse_tid = 0;
- + deadbeef->thread_wipeid (&pulse_tid);
- pulse_terminate = 1;
- deadbeef->thread_join(tid);
- @@ -242,7 +242,7 @@ static int pulse_free(void)
- static int pulse_play(void)
- {
- trace ("pulse_play\n");
- - if (!pulse_tid)
- + if (!deadbeef->thread_alive (pulse_tid))
- {
- if (pulse_init () < 0)
- {
- diff --git a/plugins/supereq/supereq.c b/plugins/supereq/supereq.c
- index e701a94a..219357b8 100644
- --- a/plugins/supereq/supereq.c
- +++ b/plugins/supereq/supereq.c
- @@ -34,7 +34,7 @@ typedef struct {
- float preamp;
- void *paramsroot;
- int params_changed;
- - uintptr_t mutex;
- + db_mutex_t mutex;
- SuperEqState state;
- int enabled;
- } ddb_supereq_ctx_t;
- diff --git a/plugins/vfs_curl/vfs_curl.c b/plugins/vfs_curl/vfs_curl.c
- index 40049e42..55650345 100644
- --- a/plugins/vfs_curl/vfs_curl.c
- +++ b/plugins/vfs_curl/vfs_curl.c
- @@ -66,7 +66,7 @@ typedef struct {
- int32_t remaining; // remaining bytes in buffer read from stream
- int64_t skipbytes;
- intptr_t tid; // thread id which does http requests
- - intptr_t mutex;
- + db_mutex_t mutex;
- uint8_t nheaderpackets;
- char *content_type;
- CURL *curl;
- @@ -793,7 +793,7 @@ http_close (DB_FILE *stream) {
- HTTP_FILE *fp = (HTTP_FILE *)stream;
- http_abort (stream);
- - if (fp->tid) {
- + if (deadbeef->thread_alive (fp->tid)) {
- deadbeef->thread_join (fp->tid);
- }
- http_cancel_abort ((DB_FILE *)fp);
- @@ -813,7 +813,7 @@ http_read (void *ptr, size_t size, size_t nmemb, DB_FILE *stream) {
- errno = ECONNABORTED;
- return 0;
- }
- - if (!fp->tid) {
- + if (!deadbeef->thread_alive (fp->tid)) {
- http_start_streamer (fp);
- }
- @@ -899,7 +899,7 @@ http_seek (DB_FILE *stream, int64_t offset, int whence) {
- trace ("vfs_curl: can't seek in curl stream relative to EOF\n");
- return -1;
- }
- - if (!fp->tid) {
- + if (!deadbeef->thread_alive (fp->tid)) {
- if (offset == 0 && (whence == SEEK_SET || whence == SEEK_CUR)) {
- return 0;
- }
- @@ -956,7 +956,7 @@ http_rewind (DB_FILE *stream) {
- trace ("http_rewind\n");
- assert (stream);
- HTTP_FILE *fp = (HTTP_FILE *)stream;
- - if (fp->tid) {
- + if (deadbeef->thread_alive (fp->tid)) {
- deadbeef->mutex_lock (fp->mutex);
- fp->status = STATUS_SEEK;
- http_stream_reset (fp);
- @@ -974,7 +974,7 @@ http_getlength (DB_FILE *stream) {
- trace ("length: -1\n");
- return -1;
- }
- - if (!fp->tid) {
- + if (!deadbeef->thread_alive (fp->tid)) {
- http_start_streamer (fp);
- }
- while (fp->status == STATUS_INITIAL) {
- @@ -995,7 +995,7 @@ http_get_content_type (DB_FILE *stream) {
- if (fp->gotheader) {
- return fp->content_type;
- }
- - if (!fp->tid) {
- + if (!deadbeef->thread_alive (fp->tid)) {
- http_start_streamer (fp);
- }
- trace ("http_get_content_type waiting for response...\n");
- diff --git a/plugins/vfs_zip/vfs_zip.c b/plugins/vfs_zip/vfs_zip.c
- index 792baefe..0ff56db4 100644
- --- a/plugins/vfs_zip/vfs_zip.c
- +++ b/plugins/vfs_zip/vfs_zip.c
- @@ -22,6 +22,9 @@
- */
- #include <string.h>
- +#ifdef __MINGW32__
- +#define ZIP_STATIC
- +#endif
- #include <zip.h>
- #include <stdlib.h>
- #include <assert.h>
- diff --git a/plugins/vorbis/vorbis.c b/plugins/vorbis/vorbis.c
- index aad220cf..5e26d6df 100644
- --- a/plugins/vorbis/vorbis.c
- +++ b/plugins/vorbis/vorbis.c
- @@ -24,6 +24,11 @@
- #ifdef HAVE_CONFIG_H
- #include <config.h>
- #endif
- +#ifdef __MINGW32__
- +#undef __STRICT_ANSI__
- +#undef _NO_OLDNAMES
- +#include <malloc.h>
- +#endif
- #include <string.h>
- #include <stdlib.h>
- #include <limits.h>
- diff --git a/plugins/vtx/vtxfile.c b/plugins/vtx/vtxfile.c
- index 04978a08..3ddc0b31 100644
- --- a/plugins/vtx/vtxfile.c
- +++ b/plugins/vtx/vtxfile.c
- @@ -5,7 +5,12 @@
- #include <ctype.h>
- #include <unistd.h>
- +#ifdef __MINGW32__
- +#include <windows.h>
- +#include "../../mingw32_layer.h"
- +#else
- #include <sys/mman.h>
- +#endif
- #include <sys/stat.h>
- #include <fcntl.h>
- @@ -213,7 +218,13 @@ ayemu_vtx_t * ayemu_vtx_header_from_file(const char *filename)
- {
- ayemu_vtx_t *ret;
- size_t size;
- +#ifdef __MINGW32__
- + SYSTEM_INFO si;
- + GetSystemInfo(&si);
- + const size_t page_size = (size_t) si.dwPageSize;
- +#else
- const size_t page_size = (size_t) sysconf (_SC_PAGESIZE);
- +#endif
- int fd;
- struct stat st;
- @@ -252,7 +263,13 @@ ayemu_vtx_t * ayemu_vtx_header_from_file(const char *filename)
- ayemu_vtx_t * ayemu_vtx_load_from_file(const char *filename)
- {
- size_t size;
- +#ifdef __MINGW32__
- + SYSTEM_INFO si;
- + GetSystemInfo(&si);
- + const size_t page_size = (size_t) si.dwPageSize;
- +#else
- const size_t page_size = (size_t) sysconf (_SC_PAGESIZE);
- +#endif
- int fd;
- struct stat st;
- ayemu_vtx_t *ret;
- diff --git a/plugins/waveout/COPYING b/plugins/waveout/COPYING
- new file mode 100644
- index 00000000..d0aecd3a
- --- /dev/null
- +++ b/plugins/waveout/COPYING
- @@ -0,0 +1,20 @@
- +WaveOut output plugin for DeaDBeeF Player
- +Copyright (C) 2016 Elio Blanca
- +
- +This software is provided 'as-is', without any express or implied
- +warranty. In no event will the authors be held liable for any damages
- +arising from the use of this software.
- +
- +Permission is granted to anyone to use this software for any purpose,
- +including commercial applications, and to alter it and redistribute it
- +freely, subject to the following restrictions:
- +
- +1. The origin of this software must not be misrepresented; you must not
- + claim that you wrote the original software. If you use this software
- + in a product, an acknowledgment in the product documentation would be
- + appreciated but is not required.
- +
- +2. Altered source versions must be plainly marked as such, and must not be
- + misrepresented as being the original software.
- +
- +3. This notice may not be removed or altered from any source distribution.
- diff --git a/plugins/waveout/waveout.c b/plugins/waveout/waveout.c
- new file mode 100644
- index 00000000..b4e46aaa
- --- /dev/null
- +++ b/plugins/waveout/waveout.c
- @@ -0,0 +1,671 @@
- +/*
- + waveout output plugin for DeaDBeeF Player
- + Copyright (C) 2016-2017 Elio Blanca
- +
- + This software is provided 'as-is', without any express or implied
- + warranty. In no event will the authors be held liable for any damages
- + arising from the use of this software.
- +
- + Permission is granted to anyone to use this software for any purpose,
- + including commercial applications, and to alter it and redistribute it
- + freely, subject to the following restrictions:
- +
- + 1. The origin of this software must not be misrepresented; you must not
- + claim that you wrote the original software. If you use this software
- + in a product, an acknowledgment in the product documentation would be
- + appreciated but is not required.
- +
- + 2. Altered source versions must be plainly marked as such, and must not be
- + misrepresented as being the original software.
- +
- + 3. This notice may not be removed or altered from any source distribution.
- +*/
- +
- +#ifdef __MINGW32__
- +
- +/* some functions will require WindowsXP at least */
- +#define WINVER 0x0501
- +
- +#define __USE_MINGW_ANSI_STDIO 1
- +
- +
- +#define AUDIO_BUFFER_NO 10 /* max number of audio blocks */
- +/* block buffers have to be large enough to maintain at least 20 ms of music (maybe 25?), else stuttering may be heard */
- +#define AUDIO_BUFFER_DURATION 25 /* ms of audio data per block */
- +/* cannot rely on time measures below 10 ms because we are really close to the NT default time granularity (1/64 s),
- + so even the sound card driver may behave oddly */
- +
- +
- +#define AUDIO_BUFFER_MAXIMUM_REQ 6 /* kilobytes per millisecond */
- +/* 1 ms of a 192 KHz 7.1 (32 bit/sample) stream require 6 kB */
- +/* this is the most demanding audio stream I can think of, so I'll use this as reference */
- +/* in case of more challenging streams, then less audio blocks will be used, so everything will work anyway */
- +
- +/* max size reserved for audio buffers - rarely used */
- +#define AUDIO_BUFFER_SIZE (AUDIO_BUFFER_NO*AUDIO_BUFFER_MAXIMUM_REQ*AUDIO_BUFFER_DURATION*1024)
- +
- +#define CHARACTER_SPACE ' '
- +#define CHARACTER_UNDERSCORE '_'
- +
- +
- +#include <unistd.h>
- +
- +#include <windows.h>
- +#include <mmreg.h>
- +#include "../../deadbeef.h"
- +
- +//#define trace(...) { fprintf(stderr, __VA_ARGS__); fflush(stderr); }
- +#define trace(fmt,...)
- +
- +/* both found on the internet... */
- +static const GUID KSDATAFORMAT_SUBTYPE_PCM = {0x00000001,0x0000,0x0010,{0x80,0x00,0x00,0xaa,0x00,0x38,0x9b,0x71}};
- +static const GUID KSDATAFORMAT_SUBTYPE_IEEE_FLOAT = {0x00000003,0x0000,0x0010,{0x80,0x00,0x00,0xaa,0x00,0x38,0x9b,0x71}};
- +
- +static DB_output_t plugin;
- +DB_functions_t *deadbeef;
- +
- +/* waveOut device number and description */
- +static unsigned int waveout_device;
- +static char setup_dev[MAXPNAMELEN]="default";
- +
- +static db_thread_t waveout_tid;
- +static int wave_terminate, state;
- +static int audio_blocks_sent, audio_block_write_index;
- +static int bytesread, bytes_per_block, avail_audio_buffers;
- +static WAVEFORMATEXTENSIBLE wave_format;
- +static HWAVEOUT device_handle;
- +static WAVEHDR waveout_headers[AUDIO_BUFFER_NO];
- +static CRITICAL_SECTION waveoutCS;
- +static void *audio_data;
- +
- +char audio_format_change_pending;
- +
- +
- +static void
- +pwaveout_thread (void *context);
- +
- +int
- +pwaveout_stop (void);
- +
- +static void
- +remove_blanks (char *buffer, int len)
- +{
- + int idx;
- +
- + if (buffer != NULL && len > 0)
- + {
- + for (idx=0; idx<len; idx++)
- + {
- + if (buffer[idx] == CHARACTER_SPACE)
- + buffer[idx] = CHARACTER_UNDERSCORE;
- + }
- + }
- +}
- +
- +int
- +pwaveout_init (void)
- +{
- + trace("pwaveout_init\n");
- + state = OUTPUT_STATE_STOPPED;
- + wave_terminate = 0;
- +
- + return 0;
- +}
- +
- +static int
- +waveout_message (uint32_t id, uintptr_t ctx, uint32_t p1, uint32_t p2)
- +{
- + int num_devices, idx;
- + WAVEOUTCAPS woc;
- + char my_dev[MAXPNAMELEN];
- + const char *current_dev;
- + unsigned int new_wdevice;
- +
- + switch (id) {
- + case DB_EV_CONFIGCHANGED:
- + new_wdevice = waveout_device;
- + current_dev = deadbeef->conf_get_str_fast ("alsa_soundcard", "default");
- +
- + if (strcmp(current_dev, "default") == 0)
- + {
- + trace("waveout_message: default device WAVE_MAPPER\n");
- + new_wdevice = WAVE_MAPPER;
- + }
- + else
- + {
- + num_devices = waveOutGetNumDevs();
- + if (num_devices != 0)
- + {
- + for (idx=0; idx<num_devices; idx++)
- + {
- + if (waveOutGetDevCaps(idx, &woc, sizeof(WAVEOUTCAPS)) == MMSYSERR_NOERROR)
- + {
- + memcpy(my_dev, woc.szPname, MAXPNAMELEN);
- + remove_blanks(my_dev, MAXPNAMELEN);
- + if (strcmp(my_dev, current_dev) == 0)
- + {
- + trace("waveout_message: device match %s\n",my_dev);
- + memcpy(setup_dev, my_dev, MAXPNAMELEN);
- + new_wdevice = idx;
- + break;
- + }
- + }
- + }
- + }
- + }
- +
- + /* new device? */
- + if (waveout_device != new_wdevice)
- + {
- + /* replace wave device */
- + waveout_device = new_wdevice;
- + /* re-init output plugin */
- + trace ("waveout_message: config option changed, restarting\n");
- + deadbeef->sendmessage (DB_EV_REINIT_SOUND, 0, 0, 0);
- + }
- + break;
- +#if 0
- + case DB_EV_SONGSTARTED:
- + if (/* notification balloon requested */)
- + {
- + }
- + break;
- +#endif
- + }
- + return 0;
- +}
- +
- +int
- +pwaveout_setformat (ddb_waveformat_t *fmt)
- +{
- + int result = 0;
- + MMRESULT openresult;
- +
- + trace("pwaveout_setformat\n");
- +
- + memcpy (&plugin.fmt, fmt, sizeof (ddb_waveformat_t));
- + trace("pwaveout_setformat: new settings sr %d ch %d bps %d channelmask=%08X\n",plugin.fmt.samplerate,plugin.fmt.channels,plugin.fmt.bps,fmt->channelmask);
- +
- + wave_format.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE;
- + wave_format.Format.nChannels = plugin.fmt.channels;
- + wave_format.Format.nSamplesPerSec = plugin.fmt.samplerate;
- + wave_format.Format.wBitsPerSample = plugin.fmt.bps;
- + wave_format.Format.nBlockAlign = wave_format.Format.nChannels * wave_format.Format.wBitsPerSample / 8;
- + wave_format.Format.nAvgBytesPerSec = wave_format.Format.nSamplesPerSec * wave_format.Format.nBlockAlign;
- + wave_format.Format.cbSize = 22;
- + wave_format.Samples.wValidBitsPerSample = wave_format.Format.wBitsPerSample;
- + wave_format.SubFormat = (fmt->is_float)? KSDATAFORMAT_SUBTYPE_IEEE_FLOAT : KSDATAFORMAT_SUBTYPE_PCM;
- + /* set channel mask */
- + wave_format.dwChannelMask = 0;
- + if (fmt->channelmask & DDB_SPEAKER_FRONT_LEFT)
- + wave_format.dwChannelMask |= SPEAKER_FRONT_LEFT;
- + if (fmt->channelmask & DDB_SPEAKER_FRONT_RIGHT)
- + wave_format.dwChannelMask |= SPEAKER_FRONT_RIGHT;
- + if (fmt->channelmask & DDB_SPEAKER_FRONT_CENTER)
- + wave_format.dwChannelMask |= SPEAKER_FRONT_CENTER;
- + if (fmt->channelmask & DDB_SPEAKER_LOW_FREQUENCY)
- + wave_format.dwChannelMask |= SPEAKER_LOW_FREQUENCY;
- + if (fmt->channelmask & DDB_SPEAKER_BACK_LEFT)
- + wave_format.dwChannelMask |= SPEAKER_BACK_LEFT;
- + if (fmt->channelmask & DDB_SPEAKER_BACK_RIGHT)
- + wave_format.dwChannelMask |= SPEAKER_BACK_RIGHT;
- + if (fmt->channelmask & DDB_SPEAKER_FRONT_LEFT_OF_CENTER)
- + wave_format.dwChannelMask |= SPEAKER_FRONT_LEFT_OF_CENTER;
- + if (fmt->channelmask & DDB_SPEAKER_FRONT_RIGHT_OF_CENTER)
- + wave_format.dwChannelMask |= SPEAKER_FRONT_RIGHT_OF_CENTER;
- + if (fmt->channelmask & DDB_SPEAKER_BACK_CENTER)
- + wave_format.dwChannelMask |= SPEAKER_BACK_CENTER;
- + if (fmt->channelmask & DDB_SPEAKER_SIDE_LEFT)
- + wave_format.dwChannelMask |= SPEAKER_SIDE_LEFT;
- + if (fmt->channelmask & DDB_SPEAKER_SIDE_RIGHT)
- + wave_format.dwChannelMask |= SPEAKER_SIDE_RIGHT;
- + if (fmt->channelmask & DDB_SPEAKER_TOP_CENTER)
- + wave_format.dwChannelMask |= SPEAKER_TOP_CENTER;
- + if (fmt->channelmask & DDB_SPEAKER_TOP_FRONT_LEFT)
- + wave_format.dwChannelMask |= SPEAKER_TOP_FRONT_LEFT;
- + if (fmt->channelmask & DDB_SPEAKER_TOP_FRONT_CENTER)
- + wave_format.dwChannelMask |= SPEAKER_TOP_FRONT_CENTER;
- + if (fmt->channelmask & DDB_SPEAKER_TOP_FRONT_RIGHT)
- + wave_format.dwChannelMask |= SPEAKER_TOP_FRONT_RIGHT;
- + if (fmt->channelmask & DDB_SPEAKER_TOP_BACK_LEFT)
- + wave_format.dwChannelMask |= SPEAKER_TOP_BACK_LEFT;
- + if (fmt->channelmask & DDB_SPEAKER_TOP_BACK_CENTER)
- + wave_format.dwChannelMask |= SPEAKER_TOP_BACK_CENTER;
- + if (fmt->channelmask & DDB_SPEAKER_TOP_BACK_RIGHT)
- + wave_format.dwChannelMask |= SPEAKER_TOP_BACK_RIGHT;
- +
- +
- + if (state == OUTPUT_STATE_STOPPED && audio_blocks_sent == 0)
- + {
- + openresult = waveOutOpen(NULL, waveout_device, (WAVEFORMATEX *)&wave_format, 0, 0, WAVE_FORMAT_QUERY);
- + if (openresult != MMSYSERR_NOERROR)
- + {
- + trace("pwaveout_setformat: audio format not supported by the selected device (result=%d)\n",openresult);
- + memset((void *)&wave_format, 0, sizeof(WAVEFORMATEXTENSIBLE));
- + result = -1;
- + }
- + else
- + {
- + trace("pwaveout_setformat: new format supported\n");
- + }
- + }
- + else
- + {
- + /* cannot query the audio device just now - promise we'll do this later */
- + trace("pwaveout_setformat: audio format query deferred\n");
- + audio_format_change_pending = 1;
- + }
- + return result;
- +}
- +
- +int
- +pwaveout_free (void)
- +{
- + trace("pwaveout_free\n");
- + if (!wave_terminate)
- + {
- + if (deadbeef->thread_alive(waveout_tid))
- + {
- + wave_terminate = 1;
- + trace("pwaveout_free: waiting for thread join...\n");
- + deadbeef->thread_join(waveout_tid);
- + trace("pwaveout_free: thread join done\n");
- + }
- + state = OUTPUT_STATE_STOPPED;
- + wave_terminate = 0;
- + }
- + return 0;
- +}
- +
- +void CALLBACK waveOutProc(HWAVEOUT hwo,
- + UINT uMsg,
- + DWORD_PTR dwInstance,
- + DWORD_PTR dwParam1,
- + DWORD_PTR dwParam2)
- +{
- + if (hwo == device_handle && uMsg == WOM_DONE)
- + {
- + EnterCriticalSection(&waveoutCS);
- + audio_blocks_sent--;
- + LeaveCriticalSection(&waveoutCS);
- + /* DON'T DO THIS! */
- + /* Calling waveOutAnything functions from within this callback will cause a deadlock! */
- + //waveOutUnprepareHeader(device_handle, (LPWAVEHDR)dwParam1, sizeof(WAVEHDR));
- + }
- +}
- +
- +int
- +pwaveout_play (void)
- +{
- + int result = -1;
- +
- + trace("pwaveout_play\n");
- + if (!deadbeef->thread_alive(waveout_tid))
- + {
- + waveout_tid = deadbeef->thread_start(pwaveout_thread, NULL);
- + }
- + if (deadbeef->thread_alive(waveout_tid))
- + {
- + if (wave_format.Format.wFormatTag == WAVE_FORMAT_EXTENSIBLE)
- + {
- + if (audio_blocks_sent)
- + {
- + trace("pwaveout_play: DANGEROUS audio_blocks_sent=%d\n",audio_blocks_sent);
- + }
- + /* device setup is ok, let's open */
- + if (waveOutOpen(&device_handle, waveout_device, (WAVEFORMATEX *)&wave_format, (DWORD_PTR)waveOutProc, 0, CALLBACK_FUNCTION) == MMSYSERR_NOERROR)
- + {
- + /* let's dance! - setup buffers */
- + bytes_per_block = wave_format.Format.nAvgBytesPerSec * AUDIO_BUFFER_DURATION / 1000;
- + avail_audio_buffers = AUDIO_BUFFER_SIZE / bytes_per_block;
- + if (avail_audio_buffers > AUDIO_BUFFER_NO) avail_audio_buffers = AUDIO_BUFFER_NO;
- +
- + audio_block_write_index = 0;
- + result = 0;
- + state = OUTPUT_STATE_PLAYING;
- + trace("pwaveout_play: go! (bytes_per_block=%d)\n",bytes_per_block);
- + }
- + }
- + }
- + return result;
- +}
- +
- +int
- +pwaveout_stop (void)
- +{
- + int idx;
- +
- + trace("pwaveout_stop\n");
- +
- + if (device_handle != NULL)
- + {
- + if (state == OUTPUT_STATE_PAUSED)
- + /* cannot close a paused device */
- + waveOutRestart(device_handle);
- +
- + /* inhibit pwaveout_thread from sending more audio blocks to the device */
- + state = OUTPUT_STATE_STOPPED;
- + waveOutReset(device_handle);
- + /* ensure pwaveout_thread catches the new state */
- + __mingw_sleep(0, AUDIO_BUFFER_DURATION*1000000);
- +
- + if (audio_blocks_sent)
- + {
- + trace("pwaveout_stop: audio_blocks_sent = %d\n",audio_blocks_sent);
- + do
- + {
- + __mingw_sleep(0, AUDIO_BUFFER_DURATION*1000000);
- + trace(".");
- + }
- + while(audio_blocks_sent != 0);
- + trace("\n");
- + }
- +
- + /* unprepare waveheaders and free resources */
- + for (idx=0; idx<AUDIO_BUFFER_NO; idx++)
- + {
- + if (waveout_headers[idx].dwFlags & WHDR_PREPARED)
- + waveOutUnprepareHeader(device_handle, &waveout_headers[idx], sizeof(WAVEHDR));
- + }
- + }
- +
- + state = OUTPUT_STATE_STOPPED;
- +
- + deadbeef->streamer_reset(1);
- +
- + return 0;
- +}
- +
- +int
- +pwaveout_pause (void)
- +{
- + trace("pwaveout_pause\n");
- + if (state == OUTPUT_STATE_STOPPED) {
- + return -1;
- + }
- +
- + if (state == OUTPUT_STATE_PLAYING)
- + {
- + waveOutPause(device_handle);
- + state = OUTPUT_STATE_PAUSED;
- + }
- + return 0;
- +}
- +
- +int
- +pwaveout_unpause (void)
- +{
- + trace("pwaveout_unpause\n");
- +
- + if (state == OUTPUT_STATE_PAUSED)
- + {
- + waveOutRestart(device_handle);
- + state = OUTPUT_STATE_PLAYING;
- + }
- + return 0;
- +}
- +
- +
- +static void
- +pwaveout_thread (void *context)
- +{
- + MMRESULT mmresult;
- + int idx;
- +
- + trace("pwaveout_thread started\n");
- +
- + while (1)
- + {
- + if (wave_terminate)
- + break;
- +
- + if (state != OUTPUT_STATE_PLAYING && !audio_format_change_pending)
- + {
- + __mingw_sleep(0, AUDIO_BUFFER_DURATION*1000000); /* __mingw_sleep(seconds, nanoseconds) */
- + }
- + else
- + {
- + /* is the device full? */
- + if (audio_blocks_sent >= avail_audio_buffers)
- + /* idle wait */
- + __mingw_sleep(0, AUDIO_BUFFER_DURATION*1000000);
- +
- + /* 'consuming' audio data */
- + if (deadbeef->streamer_ok_to_read(bytes_per_block)
- + &&
- + audio_blocks_sent < avail_audio_buffers
- + &&
- + !audio_format_change_pending)
- + {
- + bytesread = deadbeef->streamer_read(audio_data+audio_block_write_index*bytes_per_block, bytes_per_block);
- + if (bytesread > 0)
- + {
- + /* I cannot "unprepare" into the callback, so this seems a good place to do it */
- + if (waveout_headers[audio_block_write_index].dwFlags & WHDR_PREPARED)
- + waveOutUnprepareHeader(device_handle, &waveout_headers[audio_block_write_index], sizeof(WAVEHDR));
- + waveout_headers[audio_block_write_index].dwBufferLength = bytesread;
- + waveout_headers[audio_block_write_index].lpData = audio_data+audio_block_write_index*bytes_per_block;
- + waveout_headers[audio_block_write_index].dwFlags = 0;
- +
- + mmresult = waveOutPrepareHeader(device_handle, &waveout_headers[audio_block_write_index], sizeof(WAVEHDR));
- + if (mmresult == MMSYSERR_NOERROR)
- + {
- + waveOutWrite(device_handle, &waveout_headers[audio_block_write_index], sizeof(WAVEHDR));
- + EnterCriticalSection(&waveoutCS);
- + audio_blocks_sent++;
- + LeaveCriticalSection(&waveoutCS);
- + audio_block_write_index = (audio_block_write_index+1) % avail_audio_buffers;
- + }
- + }
- + else
- + {
- + trace("pwaveout_thread: read nothing\n");
- + }
- + }
- + if (audio_blocks_sent == 0 && audio_format_change_pending)
- + {
- + trace("pwaveout_thread: there is a format change pending\n");
- +
- + /* handle the format change... */
- + mmresult = waveOutOpen(&device_handle, waveout_device, (WAVEFORMATEX *)&wave_format, (DWORD_PTR)waveOutProc, 0, CALLBACK_FUNCTION);
- + if (mmresult != MMSYSERR_NOERROR)
- + {
- + /* FATAL! cannot continue playback */
- + trace("pwaveout_thread: FATAL audio format not supported by the selected device (result=%d)\n",mmresult);
- + memset((void *)&wave_format, 0, sizeof(WAVEFORMATEXTENSIBLE));
- + //result = -1;
- + break;
- + }
- + else
- + {
- + /* let's dance! - setup buffers */
- + bytes_per_block = wave_format.Format.nAvgBytesPerSec * AUDIO_BUFFER_DURATION / 1000;
- + avail_audio_buffers = AUDIO_BUFFER_SIZE / bytes_per_block;
- + if (avail_audio_buffers > AUDIO_BUFFER_NO) avail_audio_buffers = AUDIO_BUFFER_NO;
- +
- + audio_block_write_index = 0;
- + trace("pwaveout_thread: format change done (bytes_per_block=%d)\n",bytes_per_block);
- + }
- +
- + audio_format_change_pending = 0;
- + }
- + }
- + }
- +
- + /* closing operations */
- +
- + if (device_handle != NULL)
- + {
- + /* stop playback */
- + waveOutReset(device_handle);
- + while (audio_blocks_sent)
- + __mingw_sleep(0, AUDIO_BUFFER_DURATION*1000000);
- +
- + for (idx=0; idx<AUDIO_BUFFER_NO; idx++)
- + {
- + /* free resources still locked */
- + if (waveout_headers[idx].dwFlags & WHDR_PREPARED)
- + waveOutUnprepareHeader(device_handle, &waveout_headers[idx], sizeof(WAVEHDR));
- + }
- + /* close the device */
- + waveOutClose(device_handle);
- + }
- +
- + /* clean the thread ID struct - pretty ugly doin' this here, but useful */
- + waveout_tid.p = NULL; waveout_tid.x = 0;
- +
- + trace("pwaveout_thread terminating\n");
- +}
- +
- +int
- +pwaveout_get_state (void) {
- + //trace("pwaveout_get_state\n"); /* this routine is called several times a second, so too much logging */
- + return state;
- +}
- +
- +
- +/*
- + * 'start' is the very first function called after loading
- + */
- +int
- +waveout_start (void) {
- + int result = 0;
- +
- + trace("waveout_start\n");
- + state = OUTPUT_STATE_STOPPED;
- + audio_blocks_sent = 0;
- + audio_format_change_pending = 0;
- + device_handle = NULL;
- + waveout_device = WAVE_MAPPER;
- + waveout_tid.p = NULL; waveout_tid.x = 0;
- +
- + if (waveOutGetNumDevs() != 0)
- + {
- + /* let's allocate enough room for needed audio data */
- + audio_data = malloc(AUDIO_BUFFER_SIZE);
- + if (audio_data != NULL)
- + {
- + InitializeCriticalSection(&waveoutCS);
- + trace("waveout_start: setup successful\n");
- + }
- + else
- + /* memory allocation failed - fatal */
- + result = -1;
- + }
- + else
- + /* no audio devices detected - communicate this failure */
- + result = -1;
- +
- + return result;
- +}
- +
- +
- +static void
- +pwaveout_enumdevices (void (*callback)(const char *name, const char *desc, void *), void *userdata)
- +{
- + int idx, num_devices;
- + WAVEOUTCAPS woc;
- + char desc[MAXPNAMELEN];
- +
- + num_devices = waveOutGetNumDevs();
- + if (num_devices != 0)
- + {
- + /* there is at least an audio output device */
- + for (idx=0; idx<num_devices; idx++)
- + {
- + if (waveOutGetDevCaps(idx, &woc, sizeof(WAVEOUTCAPS)) == MMSYSERR_NOERROR)
- + {
- + memcpy(desc, woc.szPname, MAXPNAMELEN);
- +
- + /* clean the name in order to save it into config file */
- + remove_blanks(desc, MAXPNAMELEN);
- +
- + callback (desc, woc.szPname, userdata);
- + trace("pwaveout_enumdevices: '%s %s'\n", desc, woc.szPname);
- + }
- + else
- + {
- + callback ("(no_description)", "(no description)", userdata);
- + trace("pwaveout_enumdevices: '(no_description) (no description)'\n");
- + }
- + }
- + }
- +}
- +
- +
- +/*
- + * 'stop' is the very last function called before closing the output plugin
- + * this is the best place for freeing resources
- + */
- +int
- +waveout_stop (void) {
- + trace("waveout_stop\n");
- + free(audio_data);
- + DeleteCriticalSection(&waveoutCS);
- + return 0;
- +}
- +
- +DB_plugin_t *
- +waveout_load (DB_functions_t *api) {
- + trace("waveout_load\n");
- + deadbeef = api;
- + return DB_PLUGIN (&plugin);
- +}
- +
- +
- +// define plugin interface
- +static DB_output_t plugin = {
- + .plugin.type = DB_PLUGIN_OUTPUT,
- + .plugin.api_vmajor = 1,
- + .plugin.api_vminor = 9,
- + .plugin.version_major = 1,
- + .plugin.version_minor = 0,
- + .plugin.id = "waveout",
- + .plugin.name = "WaveOut output plugin",
- + .plugin.descr = "Output plugin for the WaveOut interface\non Windows(R) OSs.\nRequires Windows XP at least.",
- + .plugin.copyright =
- + "WaveOut output plugin for DeaDBeeF Player\n"
- + "Copyright (C) 2016-2017 Elio Blanca\n"
- + "\n"
- + "This software is provided 'as-is', without any express or implied\n"
- + "warranty. In no event will the authors be held liable for any damages\n"
- + "arising from the use of this software.\n"
- + "\n"
- + "Permission is granted to anyone to use this software for any purpose,\n"
- + "including commercial applications, and to alter it and redistribute it\n"
- + "freely, subject to the following restrictions:\n"
- + "\n"
- + "1. The origin of this software must not be misrepresented; you must not\n"
- + " claim that you wrote the original software. If you use this software\n"
- + " in a product, an acknowledgement in the product documentation would be\n"
- + " appreciated but is not required.\n"
- + "\n"
- + "2. Altered source versions must be plainly marked as such, and must not be\n"
- + " misrepresented as being the original software.\n"
- + "\n"
- + "3. This notice may not be removed or altered from any source distribution.\n",
- + .plugin.website = "https://github.com/eblanca/deadbeef-0.7.2",
- + .plugin.command = NULL,
- + .plugin.start = waveout_start,
- + .plugin.stop = waveout_stop,
- + .plugin.connect = NULL,
- + .plugin.disconnect = NULL,
- + .plugin.exec_cmdline = NULL,
- + .plugin.get_actions = NULL,
- + .plugin.message = waveout_message,
- + .plugin.configdialog = NULL,
- + .init = pwaveout_init,
- + .free = pwaveout_free,
- + .setformat = pwaveout_setformat,
- + .play = pwaveout_play,
- + .stop = pwaveout_stop,
- + .pause = pwaveout_pause,
- + .unpause = pwaveout_unpause,
- + .state = pwaveout_get_state,
- + .enum_soundcards = pwaveout_enumdevices,
- + .fmt = {.samplerate = 44100, .channels = 2, .bps = 16, .channelmask = DDB_SPEAKER_FRONT_LEFT | DDB_SPEAKER_FRONT_RIGHT},
- + /* waveOut API has the waveOutGetVolume and waveOutSetVolume interfaces: fix this? */
- + .has_volume = 0
- +};
- +#endif /* __MINGW32__ */
- +
- diff --git a/plugins/wavpack/wavpack.c b/plugins/wavpack/wavpack.c
- index 0b9f9aca..7180501c 100644
- --- a/plugins/wavpack/wavpack.c
- +++ b/plugins/wavpack/wavpack.c
- @@ -37,6 +37,9 @@
- #include <stdlib.h>
- #include <math.h>
- #include "../../deadbeef.h"
- +#ifdef __MINGW32__
- +#include <malloc.h>
- +#endif
- #define min(x,y) ((x)<(y)?(x):(y))
- #define max(x,y) ((x)>(y)?(x):(y))
- diff --git a/plugins/wildmidi/src/wildmidi_lib.c b/plugins/wildmidi/src/wildmidi_lib.c
- index 26bf72ac..0283722c 100644
- --- a/plugins/wildmidi/src/wildmidi_lib.c
- +++ b/plugins/wildmidi/src/wildmidi_lib.c
- @@ -150,6 +150,10 @@
- #include <stdarg.h>
- #include <stdio.h>
- #include <stdlib.h>
- +#ifdef __MINGW32__
- +#undef __STRICT_ANSI__
- +#undef _NO_OLDNAMES
- +#endif
- #include <string.h>
- #include <sys/stat.h>
- #include <sys/types.h>
- diff --git a/streamer.c b/streamer.c
- index e73bb994..5b029e57 100644
- --- a/streamer.c
- +++ b/streamer.c
- @@ -25,6 +25,10 @@
- Alexey Yakovenko waker@users.sourceforge.net
- */
- #include <stdlib.h>
- +#ifdef __MINGW32__
- +#undef __STRICT_ANSI__
- +#undef _NO_OLDNAMES
- +#endif
- #include <string.h>
- #include <stdio.h>
- #include <assert.h>
- @@ -52,6 +56,9 @@
- #include "plugins/libparser/parser.h"
- #include "strdupa.h"
- #include "playqueue.h"
- +#ifdef __MINGW32__
- +#include "mingw32_layer.h"
- +#endif
- //#define trace(...) { fprintf(stderr, __VA_ARGS__); }
- #define trace(fmt,...)
- @@ -72,7 +79,7 @@ streamer_read_async (char *bytes, int size);
- static int
- streamer_set_output_format (void);
- -static intptr_t streamer_tid;
- +static db_thread_t streamer_tid;
- static ddb_dsp_context_t *dsp_chain;
- static float dsp_ratio = 1;
- @@ -118,9 +125,9 @@ static ringbuf_t streamer_ringbuf;
- static char streambuffer[STREAM_BUFFER_SIZE];
- static int bytes_until_next_song = 0;
- -static uintptr_t mutex;
- -static uintptr_t currtrack_mutex;
- -static uintptr_t wdl_mutex; // wavedata listener
- +static db_mutex_t mutex;
- +static db_mutex_t currtrack_mutex;
- +static db_mutex_t wdl_mutex; // wavedata listener
- static int nextsong = -1;
- static int nextsong_pstate = -1;
- @@ -855,7 +862,7 @@ typedef struct ctmap_s {
- static ctmap_t *streamer_ctmap;
- static char conf_network_ctmapping[2048];
- -static uintptr_t ctmap_mutex;
- +static db_mutex_t ctmap_mutex;
- static void
- ctmap_init_mutex (void) {
- @@ -2063,6 +2070,10 @@ streamer_dsp_chain_save_internal (const char *fname, ddb_dsp_context_t *chain) {
- }
- fclose (fp);
- +#ifdef __MINGW32__
- + if (unlink(fname)!=0)
- + fprintf (stderr, "deleting %s failed: %s\n", fname, strerror (errno));
- +#endif
- if (rename (tempfile, fname) != 0) {
- fprintf (stderr, "dspconfig rename %s -> %s failed: %s\n", tempfile, fname, strerror (errno));
- return -1;
- diff --git a/threading.h b/threading.h
- index 62ea44b6..7f606378 100644
- --- a/threading.h
- +++ b/threading.h
- @@ -27,52 +27,68 @@
- #ifndef __THREADING_H
- #define __THREADING_H
- +#ifdef __MINGW32__
- +#include <pthread.h>
- +typedef pthread_t db_thread_t;
- +typedef pthread_mutex_t *db_mutex_t;
- +typedef pthread_cond_t *db_cond_t;
- +#else
- #include <stdint.h>
- +#define db_thread_t intptr_t
- +#define db_mutex_t uintptr_t
- +#define db_cond_t uintptr_t
- +#endif
- -intptr_t
- +db_thread_t//intptr_t
- thread_start (void (*fn)(void *ctx), void *ctx);
- -intptr_t
- +db_thread_t//intptr_t
- thread_start_low_priority (void (*fn)(void *ctx), void *ctx);
- int
- -thread_join (intptr_t tid);
- +thread_join (db_thread_t/*intptr_t*/ tid);
- +
- +int
- +thread_detach (db_thread_t/*intptr_t*/ tid);
- int
- -thread_detach (intptr_t tid);
- +thread_alive (db_thread_t/*intptr_t*/ tid);
- +
- +void
- +thread_wipeid (db_thread_t *tid);
- void
- thread_exit (void *retval);
- -uintptr_t
- +db_mutex_t//uintptr_t
- mutex_create (void);
- -uintptr_t
- +db_mutex_t//uintptr_t
- mutex_create_nonrecursive (void);
- void
- -mutex_free (uintptr_t mtx);
- +mutex_free (db_mutex_t/*uintptr_t*/ mtx);
- int
- -mutex_lock (uintptr_t mtx);
- +mutex_lock (db_mutex_t/*uintptr_t*/ mtx);
- int
- -mutex_unlock (uintptr_t mtx);
- +mutex_unlock (db_mutex_t/*uintptr_t*/ mtx);
- -uintptr_t
- +db_cond_t//uintptr_t
- cond_create (void);
- void
- -cond_free (uintptr_t cond);
- +cond_free (db_cond_t/*uintptr_t*/ cond);
- int
- -cond_wait (uintptr_t cond, uintptr_t mutex);
- +cond_wait (db_cond_t/*uintptr_t*/ cond, db_mutex_t/*uintptr_t*/ mutex);
- int
- -cond_signal (uintptr_t cond);
- +cond_signal (db_cond_t/*uintptr_t*/ cond);
- int
- -cond_broadcast (uintptr_t cond);
- +cond_broadcast (db_cond_t/*uintptr_t*/ cond);
- #endif
- diff --git a/threading_pthread.c b/threading_pthread.c
- index ab9381db..698750e6 100644
- --- a/threading_pthread.c
- +++ b/threading_pthread.c
- @@ -34,30 +34,48 @@
- #include <config.h>
- #endif
- -intptr_t
- +db_thread_t
- thread_start (void (*fn)(void *ctx), void *ctx) {
- pthread_t tid;
- pthread_attr_t attr;
- int s = pthread_attr_init (&attr);
- if (s != 0) {
- fprintf (stderr, "pthread_attr_init failed: %s\n", strerror (s));
- +#ifdef __MINGW32__
- + tid.p = NULL;
- + tid.x = 0;
- + return tid;
- +#else
- return 0;
- +#endif
- }
- s = pthread_create (&tid, &attr, (void *(*)(void *))fn, (void*)ctx);
- if (s != 0) {
- fprintf (stderr, "pthread_create failed: %s\n", strerror (s));
- +#ifdef __MINGW32__
- + tid.p = NULL;
- + tid.x = 0;
- + return tid;
- +#else
- return 0;
- +#endif
- }
- s = pthread_attr_destroy (&attr);
- if (s != 0) {
- fprintf (stderr, "pthread_attr_destroy failed: %s\n", strerror (s));
- +#ifdef __MINGW32__
- + tid.p = NULL;
- + tid.x = 0;
- + return tid;
- +#else
- return 0;
- +#endif
- }
- return tid;
- }
- -intptr_t
- +db_thread_t
- thread_start_low_priority (void (*fn)(void *ctx), void *ctx) {
- #if defined(__linux__) && !defined(ANDROID)
- pthread_t tid;
- @@ -104,7 +122,7 @@ thread_start_low_priority (void (*fn)(void *ctx), void *ctx) {
- }
- int
- -thread_join (intptr_t tid) {
- +thread_join (db_thread_t tid) {
- void *retval;
- int s = pthread_join ((pthread_t)tid, &retval);
- if (s) {
- @@ -115,7 +133,7 @@ thread_join (intptr_t tid) {
- }
- int
- -thread_detach (intptr_t tid) {
- +thread_detach (db_thread_t tid) {
- int s = pthread_detach ((pthread_t)tid);
- if (s) {
- fprintf (stderr, "pthread_detach failed: %s\n", strerror (s));
- @@ -124,12 +142,30 @@ thread_detach (intptr_t tid) {
- return 0;
- }
- +int
- +thread_alive (db_thread_t tid) {
- + return (pthread_kill (tid, 0) == 0);
- +}
- +
- +void
- +thread_wipeid (db_thread_t *tid) {
- + if (tid != NULL)
- + {
- +#ifdef __MINGW32__
- + tid->p = NULL;
- + tid->x = 0;
- +#else
- + *tid = 0;
- +#endif
- + }
- +}
- +
- void
- thread_exit (void *retval) {
- pthread_exit (retval);
- }
- -uintptr_t
- +db_mutex_t
- mutex_create_nonrecursive (void) {
- pthread_mutex_t *mtx = malloc (sizeof (pthread_mutex_t));
- pthread_mutexattr_t attr = {0};
- @@ -138,13 +174,17 @@ mutex_create_nonrecursive (void) {
- int err = pthread_mutex_init (mtx, &attr);
- if (err != 0) {
- fprintf (stderr, "pthread_mutex_init failed: %s\n", strerror (err));
- +#ifdef __MINGW32__
- + return NULL;
- +#else
- return 0;
- +#endif
- }
- pthread_mutexattr_destroy (&attr);
- - return (uintptr_t)mtx;
- + return (db_mutex_t)mtx;
- }
- -uintptr_t
- +db_mutex_t
- mutex_create (void) {
- pthread_mutex_t *mtx = malloc (sizeof (pthread_mutex_t));
- pthread_mutexattr_t attr = {0};
- @@ -153,21 +193,25 @@ mutex_create (void) {
- int err = pthread_mutex_init (mtx, &attr);
- if (err != 0) {
- fprintf (stderr, "pthread_mutex_init failed: %s\n", strerror (err));
- +#ifdef __MINGW32__
- + return NULL;
- +#else
- return 0;
- +#endif
- }
- pthread_mutexattr_destroy (&attr);
- - return (uintptr_t)mtx;
- + return (db_mutex_t)mtx;
- }
- void
- -mutex_free (uintptr_t _mtx) {
- +mutex_free (db_mutex_t _mtx) {
- pthread_mutex_t *mtx = (pthread_mutex_t *)_mtx;
- pthread_mutex_destroy (mtx);
- free (mtx);
- }
- int
- -mutex_lock (uintptr_t _mtx) {
- +mutex_lock (db_mutex_t _mtx) {
- pthread_mutex_t *mtx = (pthread_mutex_t *)_mtx;
- int err = pthread_mutex_lock (mtx);
- if (err != 0) {
- @@ -177,7 +221,7 @@ mutex_lock (uintptr_t _mtx) {
- }
- int
- -mutex_unlock (uintptr_t _mtx) {
- +mutex_unlock (db_mutex_t _mtx) {
- pthread_mutex_t *mtx = (pthread_mutex_t *)_mtx;
- int err = pthread_mutex_unlock (mtx);
- if (err != 0) {
- @@ -186,19 +230,23 @@ mutex_unlock (uintptr_t _mtx) {
- return err;
- }
- -uintptr_t
- +db_cond_t
- cond_create (void) {
- pthread_cond_t *cond = malloc (sizeof (pthread_cond_t));
- int err = pthread_cond_init (cond, NULL);
- if (err != 0) {
- fprintf (stderr, "pthread_cond_init failed: %s\n", strerror (err));
- +#ifdef __MINGW32__
- + return NULL;
- +#else
- return 0;
- +#endif
- }
- - return (uintptr_t)cond;
- + return (db_cond_t)cond;
- }
- void
- -cond_free (uintptr_t c) {
- +cond_free (db_cond_t c) {
- if (c) {
- pthread_cond_t *cond = (pthread_cond_t *)c;
- pthread_cond_destroy (cond);
- @@ -207,7 +255,7 @@ cond_free (uintptr_t c) {
- }
- int
- -cond_wait (uintptr_t c, uintptr_t m) {
- +cond_wait (db_cond_t c, db_mutex_t m) {
- pthread_cond_t *cond = (pthread_cond_t *)c;
- pthread_mutex_t *mutex = (pthread_mutex_t *)m;
- int err = mutex_lock (m);
- @@ -222,7 +270,7 @@ cond_wait (uintptr_t c, uintptr_t m) {
- }
- int
- -cond_signal (uintptr_t c) {
- +cond_signal (db_cond_t c) {
- pthread_cond_t *cond = (pthread_cond_t *)c;
- int err = pthread_cond_signal (cond);
- if (err != 0) {
- @@ -232,7 +280,7 @@ cond_signal (uintptr_t c) {
- }
- int
- -cond_broadcast (uintptr_t c) {
- +cond_broadcast (db_cond_t c) {
- pthread_cond_t *cond = (pthread_cond_t *)c;
- int err = pthread_cond_broadcast (cond);
- if (err != 0) {
- diff --git a/utf8.c b/utf8.c
- index f3f13093..35ce8205 100644
- --- a/utf8.c
- +++ b/utf8.c
- @@ -45,7 +45,9 @@
- #include "utf8.h"
- #include "u8_lc_map.h"
- #include "u8_uc_map.h"
- -
- +#ifdef __MINGW32__
- +#include <malloc.h>
- +#endif
- static const uint32_t offsetsFromUTF8[6] = {
- 0x00000000UL, 0x00003080UL, 0x000E2080UL,
- 0x03C82080UL, 0xFA082080UL, 0x82082080UL
- diff --git a/vfs.c b/vfs.c
- index 2be32dea..47495dbe 100644
- --- a/vfs.c
- +++ b/vfs.c
- @@ -24,6 +24,10 @@
- Alexey Yakovenko waker@users.sourceforge.net
- */
- +#ifdef __MINGW32__
- +#undef __STRICT_ANSI__
- +#undef _NO_OLDNAMES
- +#endif
- #include <string.h>
- #include <stdio.h>
- #include "vfs.h"
- diff --git a/vfs_stdio.c b/vfs_stdio.c
- index 7e6e6b7b..b1ec439b 100644
- --- a/vfs_stdio.c
- +++ b/vfs_stdio.c
- @@ -25,6 +25,9 @@
- Alexey Yakovenko waker@users.sourceforge.net
- */
- #include "deadbeef.h"
- +#ifdef __MINGW32__
- +#define __USE_MINGW_FSEEK /* request mingw internal implementation of fseeko64 */
- +#endif
- #include <stdio.h>
- #include <stdlib.h>
- #include <assert.h>
- @@ -35,9 +38,16 @@
- #include <unistd.h>
- #ifndef __linux__
- +#ifdef __MINGW32__
- +#define off_t off64_t
- +#define fseeko fseeko64
- +#define ftello ftello64
- +#define USE_STDIO
- +#else
- #define off64_t off_t
- #define lseek64 lseek
- -#define O_LARGEFILE 0
- +#endif /* __MINGW32__ */
- +#define O_LARGEFILE 0 /* this is a linux extension, anyway set this to 0 is the same as O_RDONLY */
- #endif
- //#define USE_STDIO
- @@ -98,6 +108,7 @@ stdio_close (DB_FILE *stream) {
- free (stream);
- }
- +#ifndef USE_STDIO
- static int
- fillbuffer (STDIO_FILE *f) {
- assert (f->bufremaining >= 0);
- @@ -111,6 +122,7 @@ fillbuffer (STDIO_FILE *f) {
- }
- return f->bufremaining;
- }
- +#endif
- static size_t
- stdio_read (void *ptr, size_t size, size_t nmemb, DB_FILE *stream) {
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement