diff options
Diffstat (limited to 'streamer.c')
-rw-r--r-- | streamer.c | 134 |
1 files changed, 112 insertions, 22 deletions
@@ -111,6 +111,7 @@ static int bytes_until_next_song = 0; static uintptr_t mutex; static uintptr_t decodemutex; static uintptr_t wdl_mutex; // wavedata listener + static int nextsong = -1; static int nextsong_pstate = -1; static int badsong = -1; @@ -204,8 +205,7 @@ streamer_abort_files (void) { } - -void +static void streamer_set_replaygain (playItem_t *it) { // setup replaygain pl_lock (); @@ -257,7 +257,7 @@ send_trackchanged (playItem_t *from, playItem_t *to) { messagepump_push_event ((ddb_event_t *)event, 0, 0); } -void +static void streamer_start_playback (playItem_t *from, playItem_t *it) { if (from) { pl_item_ref (from); @@ -360,7 +360,8 @@ send_trackinfochanged (playItem_t *track) { messagepump_push_event ((ddb_event_t*)ev, 0, 0); } -int stop_after_album_check (playItem_t *cur, playItem_t *next) { +static int +stop_after_album_check (playItem_t *cur, playItem_t *next) { if (!stop_after_album) { return 0; } @@ -416,8 +417,11 @@ int stop_after_album_check (playItem_t *cur, playItem_t *next) { return 1; } -int -streamer_move_to_nextsong (int reason) { +static int +streamer_move_to_nextsong_real (int reason) { + if (reason) { + plug_get_output ()->stop (); + } trace ("streamer_move_to_nextsong (%d)\n", reason); pl_lock (); if (!streamer_playlist) { @@ -635,8 +639,9 @@ streamer_move_to_nextsong (int reason) { return -1; } -int -streamer_move_to_prevsong (void) { +static int +streamer_move_to_prevsong_real (void) { + plug_get_output ()->stop (); pl_lock (); if (streamer_playlist) { plt_unref (streamer_playlist); @@ -748,8 +753,9 @@ streamer_move_to_prevsong (void) { return -1; } -int -streamer_move_to_randomsong (void) { +static int +streamer_move_to_randomsong_real (void) { + plug_get_output ()->stop (); if (!streamer_playlist) { streamer_playlist = plt_get_curr (); } @@ -776,6 +782,21 @@ streamer_move_to_randomsong (void) { return 0; } +int +streamer_move_to_nextsong (int reason) { + handler_push (handler, STR_EV_NEXT, 0, reason, 0); +} + +int +streamer_move_to_prevsong (void) { + handler_push (handler, STR_EV_PREV, 0, 0, 0); +} + +int +streamer_move_to_randomsong (void) { + handler_push (handler, STR_EV_RAND, 0, 0, 0); +} + // playlist must call that whenever item was removed void streamer_song_removed_notify (playItem_t *it) { @@ -1021,6 +1042,7 @@ streamer_set_current (playItem_t *it) { char *buf = NULL; int fd = -1; FILE *out = NULL; + char tempfile[1000] = ""; int size = vfs_fgetlength (fp); if (size <= 0) { @@ -1037,7 +1059,6 @@ streamer_set_current (playItem_t *it) { trace ("failed to download %d bytes (got %d bytes)\n", size, rd); goto m3u_error; } - char tempfile[1000]; const char *tmpdir = getenv ("TMPDIR"); if (!tmpdir) { tmpdir = "/tmp"; @@ -1113,11 +1134,17 @@ streamer_set_current (playItem_t *it) { if (to) { pl_item_unref (to); } + if (buf) { + free (buf); + } + unlink (tempfile); return res; } - unlink (tempfile); m3u_error: + if (*tempfile) { + unlink (tempfile); + } err = -1; if (buf) { free (buf); @@ -1301,7 +1328,16 @@ streamer_get_apx_bitrate (void) { void streamer_set_nextsong (int song, int pstate) { + handler_push (handler, STR_EV_PLAY_TRACK_IDX, 0, song, pstate); +} + +static void +streamer_set_nextsong_real (int song, int pstate) { DB_output_t *output = plug_get_output (); + if (pstate == 4) { + pstate = 1; + output->stop (); + } trace ("streamer_set_nextsong %d %d\n", song, pstate); streamer_abort_files (); streamer_lock (); @@ -1324,7 +1360,7 @@ streamer_set_nextsong (int song, int pstate) { streamer_unlock (); } -void +static void streamer_set_generic_output_format (void) { output_format.bps = 16; output_format.is_float = 0; @@ -1336,7 +1372,7 @@ streamer_set_generic_output_format (void) { void streamer_set_seek (float pos) { - seekpos = pos; + handler_push (handler, STR_EV_SEEK, 0, *((uint32_t *)&pos), 0); } static void @@ -1448,7 +1484,7 @@ streamer_start_new_song (void) { } } -void +static void streamer_next (int bytesread) { streamer_lock (); bytes_until_next_song = streamer_ringbuf.remaining + bytesread; @@ -1467,6 +1503,21 @@ streamer_next (int bytesread) { } } +static int +streamer_move_to_nextsong_real (int reason); + +static int +streamer_move_to_prevsong_real (void); + +static int +streamer_move_to_randomsong_real (void); + +static void +streamer_play_current_track_real (void); + +static void +streamer_set_current_playlist_real (int plt); + void streamer_thread (void *ctx) { #ifdef __linux__ @@ -1478,6 +1529,35 @@ streamer_thread (void *ctx) { DB_output_t *output = plug_get_output (); gettimeofday (&tm1, NULL); + uint32_t id; + uintptr_t ctx; + uint32_t p1, p2; + if (!handler_pop (handler, &id, &ctx, &p1, &p2)) { + switch (id) { + case STR_EV_PLAY_TRACK_IDX: + streamer_set_nextsong_real (p1, p2); + break; + case STR_EV_PLAY_CURR: + streamer_play_current_track_real (); + break; + case STR_EV_NEXT: + streamer_move_to_nextsong_real (p1); + break; + case STR_EV_PREV: + streamer_move_to_prevsong_real (); + break; + case STR_EV_RAND: + streamer_move_to_randomsong_real (); + break; + case STR_EV_SEEK: + seekpos = *((float *)&p1); + break; + case STR_EV_SET_CURR_PLT: + streamer_set_current_playlist_real (p1); + break; + } + } + if (nextsong >= 0) { // start streaming next song trace ("\033[0;34mnextsong=%d\033[37;0m\n", nextsong); if (playing_track) { @@ -1919,7 +1999,7 @@ streamer_dsp_chain_save (void) { return streamer_dsp_chain_save_internal (fname, dsp_chain); } -void +static void streamer_dsp_postinit (void) { // note about EQ hack: // we 1st check if there's an EQ in dsp chain, and just use it @@ -1978,7 +2058,7 @@ streamer_dsp_refresh (void) { mutex_unlock (decodemutex); } -void +static void streamer_dsp_init (void) { // load dsp chain from file char fname[PATH_MAX]; @@ -2543,7 +2623,7 @@ streamer_read (char *bytes, int size) { return sz; } -int +static int streamer_get_fill (void) { return streamer_ringbuf.remaining; } @@ -2596,8 +2676,8 @@ streamer_configchanged (void) { } } -void -streamer_play_current_track (void) { +static void +streamer_play_current_track_real (void) { playlist_t *plt = plt_get_curr (); DB_output_t *output = plug_get_output (); if (output->state () == OUTPUT_STATE_PAUSED && playing_track) { @@ -2648,13 +2728,18 @@ streamer_play_current_track (void) { } } +void +streamer_play_current_track (void) { + handler_push (handler, STR_EV_PLAY_CURR, 0, 0, 0); +} + struct DB_fileinfo_s * streamer_get_current_fileinfo (void) { return fileinfo; } -void -streamer_set_current_playlist (int plt) { +static void +streamer_set_current_playlist_real (int plt) { pl_lock (); if (streamer_playlist) { plt_unref (streamer_playlist); @@ -2663,6 +2748,11 @@ streamer_set_current_playlist (int plt) { pl_unlock (); } +void +streamer_set_current_playlist (int plt) { + handler_push (handler, STR_EV_SET_CURR_PLT, 0, plt, 0); +} + int streamer_get_current_playlist (void) { pl_lock (); |