[spotify] Flush audio buffer on playback stop - and since we are

flushing from another thread we use evbuffer_enable_locking() which
in turn adds a requirement for libevent_pthreads to be present
This commit is contained in:
ejurgensen 2017-01-30 22:50:02 +01:00
parent 3ba2fb741b
commit bbb3322ddc
3 changed files with 16 additions and 2 deletions

View File

@ -222,6 +222,11 @@ dnl Build with libcurl
FORK_ARG_WITH_CHECK([FORKED], [libcurl support], [libcurl], [LIBCURL],
[libcurl], [curl_global_init], [curl/curl.h])
dnl Build with libevent_pthreads
FORK_ARG_WITH_CHECK([FORKED], [libevent_pthreads support], [libevent_pthreads],
[LIBEVENT_PTHREADS], [libevent_pthreads], [evthread_use_pthreads],
[event2/thread.h])
dnl Build with json-c
FORK_ARG_WITH_CHECK([FORKED], [json-c support], [json], [JSON_C],
[json-c >= 0.11], [json_tokener_parse], [json.h], [],
@ -254,6 +259,8 @@ dnl Spotify with dynamic linking to libspotify
FORK_ARG_ENABLE([Spotify support], [spotify], [SPOTIFY],
[AS_IF([[test "x$with_json" = "xno"]],
[AC_MSG_ERROR([[Spotify support requires json-c]])])
AS_IF([[test "x$with_libevent_pthreads" = "xno"]],
[AC_MSG_ERROR([[Spotify support requires libevent_pthreads]])])
AC_CHECK_HEADER([[libspotify/api.h]], [],
[AC_MSG_ERROR([[libspotify/api.h not found]])])
AC_DEFINE([HAVE_SPOTIFY_H], 1,

View File

@ -46,6 +46,7 @@
#include <getopt.h>
#include <event2/event.h>
#include <event2/thread.h>
#include <libavutil/log.h>
#include <libavformat/avformat.h>
#include <libavfilter/avfilter.h>
@ -683,7 +684,11 @@ main(int argc, char **argv)
}
/* Initialize event base (after forking) */
evbase_main = event_base_new();
CHECK_NULL(L_MAIN, evbase_main = event_base_new());
#ifdef SPOTIFY
CHECK_ERR(L_MAIN, evthread_use_pthreads());
#endif
DPRINTF(E_LOG, L_MAIN, "mDNS init\n");
ret = mdns_init();

View File

@ -1252,6 +1252,7 @@ playback_stop(void *arg, int *retval)
g_state = SPOTIFY_STATE_STOPPED;
evbuffer_drain(spotify_audio_buffer, evbuffer_get_length(spotify_audio_buffer));
*retval = 0;
return COMMAND_END;
@ -1297,7 +1298,6 @@ playback_eot(void *arg, int *retval)
g_state = SPOTIFY_STATE_STOPPING;
// TODO 1) This will block for a while, but perhaps ok?
// 2) spotify_audio_buffer not entirely thread safe here (but unlikely risk...)
input_write(spotify_audio_buffer, INPUT_FLAG_EOF);
*retval = 0;
@ -2487,6 +2487,8 @@ spotify_init(void)
spotify_audio_buffer = evbuffer_new();
CHECK_ERR(L_SPOTIFY, evbuffer_enable_locking(spotify_audio_buffer, NULL));
CHECK_ERR(L_SPOTIFY, mutex_init(&login_lck));
CHECK_ERR(L_SPOTIFY, pthread_cond_init(&login_cond, NULL));