From 47f411b6964dc2f0af7d0f35ac0016204f1d9e96 Mon Sep 17 00:00:00 2001 From: waker Date: Wed, 20 Oct 2010 22:04:31 +0200 Subject: added portable build mode (--enable-portable configure option) --- main.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 64 insertions(+), 11 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index 75185052..4552e00f 100644 --- a/main.c +++ b/main.c @@ -54,10 +54,7 @@ #include "conf.h" #include "volume.h" #include "plugins.h" - -#ifndef PATH_MAX -#define PATH_MAX 1024 /* max # of characters in a path name */ -#endif +#include "common.h" #ifndef PREFIX #error PREFIX must be defined @@ -67,12 +64,18 @@ #define USE_ABSTRACT_NAME 0 #endif -//#define trace(...) { fprintf(stderr, __VA_ARGS__); } -#define trace(fmt,...) +#define trace(...) { fprintf(stderr, __VA_ARGS__); } +//#define trace(fmt,...) + // some common global variables -char confdir[1024]; // $HOME/.config -char dbconfdir[1024]; // $HOME/.config/deadbeef +char sys_install_path[PATH_MAX]; // see deadbeef->get_prefix +char confdir[PATH_MAX]; // $HOME/.config +char dbconfdir[PATH_MAX]; // $HOME/.config/deadbeef +char dbinstalldir[PATH_MAX]; // see deadbeef->get_prefix +char dbdocdir[PATH_MAX]; // see deadbeef->get_doc_dir +char dbplugindir[PATH_MAX]; // see deadbeef->get_plugin_dir +char dbpixmapdir[PATH_MAX]; // see deadbeef->get_pixmap_dir // client-side commandline support // -1 error, program must exit with error code -1 @@ -529,11 +532,45 @@ main (int argc, char *argv[]) { bind_textdomain_codeset (PACKAGE, "UTF-8"); textdomain (PACKAGE); #endif - fprintf (stderr, "starting deadbeef " VERSION "\n"); + fprintf (stderr, "starting deadbeef " VERSION "%s\n", PORTABLE ? " [portable build]" : ""); srand (time (NULL)); #ifdef __linux__ prctl (PR_SET_NAME, "deadbeef-main", 0, 0, 0, 0); #endif + +#if PORTABLE + strcpy (dbinstalldir, argv[0]); + char *e = dbinstalldir + strlen (dbinstalldir); + while (e >= dbinstalldir && *e != '/') { + e--; + } + *e = 0; + if (snprintf (confdir, sizeof (confdir), "%s/config", dbinstalldir) > sizeof (confdir)) { + fprintf (stderr, "fatal: too long install path %s\n", dbinstalldir); + return -1; + } + + strcpy (dbconfdir, confdir); + + if (snprintf (dbdocdir, sizeof (dbdocdir), "%s/doc", dbinstalldir) > sizeof (dbdocdir)) { + fprintf (stderr, "fatal: too long install path %s\n", dbinstalldir); + return -1; + } + if (snprintf (dbplugindir, sizeof (dbplugindir), "%s/plugins", dbinstalldir) > sizeof (dbplugindir)) { + fprintf (stderr, "fatal: too long install path %s\n", dbinstalldir); + return -1; + } + if (snprintf (dbpixmapdir, sizeof (dbpixmapdir), "%s/pixmaps", dbinstalldir) > sizeof (dbpixmapdir)) { + fprintf (stderr, "fatal: too long install path %s\n", dbinstalldir); + return -1; + } + trace ("installdir: %s\n", dbinstalldir); + trace ("confdir: %s\n", confdir); + trace ("docdir: %s\n", dbdocdir); + trace ("plugindir: %s\n", dbplugindir); + mkdir (dbplugindir, 0755); + trace ("pixmapdir: %s\n", dbpixmapdir); +#else char *homedir = getenv ("HOME"); if (!homedir) { fprintf (stderr, "unable to find home directory. stopping.\n"); @@ -553,11 +590,25 @@ main (int argc, char *argv[]) { return -1; } } - mkdir (confdir, 0755); if (snprintf (dbconfdir, sizeof (dbconfdir), "%s/deadbeef", confdir) > sizeof (dbconfdir)) { fprintf (stderr, "fatal: out of memory while configuring\n"); return -1; } + mkdir (confdir, 0755); + if (snprintf (dbdocdir, sizeof (dbdocdir), "%s", DOCDIR) > sizeof (dbdocdir)) { + fprintf (stderr, "fatal: too long install path %s\n", dbinstalldir); + return -1; + } + if (snprintf (dbplugindir, sizeof (dbplugindir), "%s/deadbeef", LIBDIR) > sizeof (dbplugindir)) { + fprintf (stderr, "fatal: too long install path %s\n", dbinstalldir); + return -1; + } + if (snprintf (dbpixmapdir, sizeof (dbpixmapdir), "%s/share/deadbeef/pixmaps", PREFIX) > sizeof (dbpixmapdir)) { + fprintf (stderr, "fatal: too long install path %s\n", dbinstalldir); + return -1; + } +#endif + mkdir (dbconfdir, 0755); char cmdline[2048]; @@ -679,7 +730,9 @@ main (int argc, char *argv[]) { conf_load (); // required by some plugins at startup volume_set_db (conf_get_float ("playback.volume", 0)); // volume need to be initialized before plugins start messagepump_init (); // required to push messages while handling commandline - plug_load_all (); // required to add files to playlist from commandline + if (plug_load_all ()) { // required to add files to playlist from commandline + exit (-1); + } pl_load_all (); plt_set_curr (conf_get_int ("playlist.current", 0)); -- cgit v1.2.3 From c307cf0c0eb3029de065f503140f9dfdc272930f Mon Sep 17 00:00:00 2001 From: waker Date: Tue, 26 Oct 2010 20:49:36 +0200 Subject: on session resume, don't seek next track in failed to start also better seekpos reporting --- main.c | 4 +++- streamer.c | 28 +++++++++++++++++++++------- 2 files changed, 24 insertions(+), 8 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index 75185052..5e776b73 100644 --- a/main.c +++ b/main.c @@ -509,9 +509,11 @@ restore_resume_state (void) { int paused = conf_get_int ("resume.paused", 0); trace ("resume: track %d pos %f playlist %d\n", track, pos, plt); if (plt >= 0 && track >= 0 && pos >= 0) { + streamer_lock (); // need to hold streamer thread to make the resume operation atomic streamer_set_current_playlist (plt); - streamer_set_seek (pos); streamer_set_nextsong (track, paused ? 2 : 3); + streamer_set_seek (pos); + streamer_unlock (); } } } diff --git a/streamer.c b/streamer.c index 3191cc5b..7f238e4e 100644 --- a/streamer.c +++ b/streamer.c @@ -524,6 +524,7 @@ streamer_song_removed_notify (playItem_t *it) { if (!mutex) { return; // streamer is not running } + streamer_lock (); if (it == playlist_track) { playlist_track = playlist_track->next[PL_MAIN]; // queue new next song for streaming @@ -532,6 +533,7 @@ streamer_song_removed_notify (playItem_t *it) { streamer_move_to_nextsong (0); } } + streamer_unlock (); } // that must be called after last sample from str_playing_song was done reading @@ -678,9 +680,6 @@ streamer_set_current (playItem_t *it) { } return -1; } -// if (bytes_until_next_song == -1) { -// bytes_until_next_song = 0; -// } success: plug_trigger_event_trackinfochanged (to); @@ -699,6 +698,10 @@ error: float streamer_get_playpos (void) { + float seek = seekpos; + if (seek >= 0) { + return seek; + } return playpos; } @@ -717,6 +720,7 @@ streamer_get_apx_bitrate (void) { void streamer_set_nextsong (int song, int pstate) { trace ("streamer_set_nextsong %d %d\n", song, pstate); + streamer_lock (); streamer_abort_files (); nextsong = song; nextsong_pstate = pstate; @@ -727,8 +731,9 @@ streamer_set_nextsong (int song, int pstate) { // no sense to wait until end of previous song, reset buffer bytes_until_next_song = 0; playpos = 0; -// seekpos = -1; + seekpos = -1; } + streamer_unlock (); } void @@ -847,13 +852,16 @@ streamer_thread (void *ctx) { gettimeofday (&tm1, NULL); if (nextsong >= 0) { // start streaming next song trace ("\033[0;34mnextsong=%d\033[37;0m\n", nextsong); + streamer_lock (); streamer_start_new_song (); + streamer_unlock (); // it's totally possible that song was switched // while streamer_set_current was running, // so we need to restart here continue; } else if (nextsong == -2 && (nextsong_pstate==0 || bytes_until_next_song == 0)) { + streamer_lock (); playItem_t *from = playing_track; bytes_until_next_song = -1; trace ("nextsong=-2\n"); @@ -875,6 +883,7 @@ streamer_thread (void *ctx) { if (from) { pl_item_unref (from); } + streamer_unlock (); continue; } else if (p_isstopped ()) { @@ -883,11 +892,13 @@ streamer_thread (void *ctx) { } if (bytes_until_next_song == 0) { + streamer_lock (); if (!streaming_track) { // means last song was deleted during final drain nextsong = -1; p_stop (); streamer_set_current (NULL); + streamer_unlock (); continue; } trace ("bytes_until_next_song=0, starting playback of new song\n"); @@ -952,16 +963,19 @@ streamer_thread (void *ctx) { if (p_play () < 0) { fprintf (stderr, "streamer: failed to start playback after samplerate change; output plugin doesn't work\n"); streamer_set_nextsong (-2, 0); + streamer_unlock (); continue; } } } + streamer_unlock (); } - if (seekpos >= 0) { - trace ("seeking to %f\n", seekpos); - float pos = seekpos; + int seek = seekpos; + if (seek >= 0) { seekpos = -1; + trace ("seeking to %f\n", seek); + float pos = seek; if (playing_track != streaming_track) { trace ("streamer already switched to next track\n"); -- cgit v1.2.3