Add config option for preferred Spotify bitrate. README update.

This commit is contained in:
ejurgensen 2014-03-29 22:26:46 +01:00
parent 6f577e0d0b
commit 49498800ba
4 changed files with 25 additions and 5 deletions

2
README
View File

@ -337,7 +337,7 @@ installed, otherwise the Spotify integration will not be available. You can
get libspotify here: get libspotify here:
- Original (binary) tar.gz, see <https://developer.spotify.com> - Original (binary) tar.gz, see <https://developer.spotify.com>
- Debian package (libspotify12), see <https://apt.mopidy.com> - Debian package (libspotify-dev), see <https://apt.mopidy.com>
You must also have a Spotify premium account. If you normally log into Spotify You must also have a Spotify premium account. If you normally log into Spotify
with your Facebook account you must first go to Spotify's web site where you can with your Facebook account you must first go to Spotify's web site where you can

View File

@ -120,4 +120,7 @@ spotify {
# settings_dir = "/var/cache/forked-daapd/libspotify" # settings_dir = "/var/cache/forked-daapd/libspotify"
# Cache directory # Cache directory
# cache_dir = "/tmp" # cache_dir = "/tmp"
# Set preferred bitrate for music streaming
# 0: No preference (default), 1: 96kbps, 2: 160kbps, 3: 320kbps
# bitrate = 0
} }

View File

@ -105,6 +105,7 @@ static cfg_opt_t sec_spotify[] =
{ {
CFG_STR("settings_dir", STATEDIR "/cache/" PACKAGE "/libspotify", CFGF_NONE), CFG_STR("settings_dir", STATEDIR "/cache/" PACKAGE "/libspotify", CFGF_NONE),
CFG_STR("cache_dir", "/tmp", CFGF_NONE), CFG_STR("cache_dir", "/tmp", CFGF_NONE),
CFG_INT("bitrate", 0, CFGF_NONE),
CFG_END() CFG_END()
}; };

View File

@ -175,6 +175,7 @@ typedef sp_error (*fptr_sp_session_player_unload_t)(sp_session *session);
typedef sp_error (*fptr_sp_session_player_play_t)(sp_session *session, bool play); typedef sp_error (*fptr_sp_session_player_play_t)(sp_session *session, bool play);
typedef sp_error (*fptr_sp_session_player_seek_t)(sp_session *session, int offset); typedef sp_error (*fptr_sp_session_player_seek_t)(sp_session *session, int offset);
typedef sp_connectionstate (*fptr_sp_session_connectionstate_t)(sp_session *session); typedef sp_connectionstate (*fptr_sp_session_connectionstate_t)(sp_session *session);
typedef sp_error (*fptr_sp_session_preferred_bitrate_t)(sp_session *session, sp_bitrate bitrate);
typedef sp_error (*fptr_sp_playlistcontainer_add_callbacks_t)(sp_playlistcontainer *pc, sp_playlistcontainer_callbacks *callbacks, void *userdata); typedef sp_error (*fptr_sp_playlistcontainer_add_callbacks_t)(sp_playlistcontainer *pc, sp_playlistcontainer_callbacks *callbacks, void *userdata);
typedef int (*fptr_sp_playlistcontainer_num_playlists_t)(sp_playlistcontainer *pc); typedef int (*fptr_sp_playlistcontainer_num_playlists_t)(sp_playlistcontainer *pc);
@ -224,6 +225,7 @@ fptr_sp_session_player_unload_t fptr_sp_session_player_unload;
fptr_sp_session_player_play_t fptr_sp_session_player_play; fptr_sp_session_player_play_t fptr_sp_session_player_play;
fptr_sp_session_player_seek_t fptr_sp_session_player_seek; fptr_sp_session_player_seek_t fptr_sp_session_player_seek;
fptr_sp_session_connectionstate_t fptr_sp_session_connectionstate; fptr_sp_session_connectionstate_t fptr_sp_session_connectionstate;
fptr_sp_session_preferred_bitrate_t fptr_sp_session_preferred_bitrate;
fptr_sp_playlistcontainer_add_callbacks_t fptr_sp_playlistcontainer_add_callbacks; fptr_sp_playlistcontainer_add_callbacks_t fptr_sp_playlistcontainer_add_callbacks;
fptr_sp_playlistcontainer_num_playlists_t fptr_sp_playlistcontainer_num_playlists; fptr_sp_playlistcontainer_num_playlists_t fptr_sp_playlistcontainer_num_playlists;
@ -282,6 +284,7 @@ fptr_assign_all()
&& (fptr_sp_session_player_play = dlsym(h, "sp_session_player_play")) && (fptr_sp_session_player_play = dlsym(h, "sp_session_player_play"))
&& (fptr_sp_session_player_seek = dlsym(h, "sp_session_player_seek")) && (fptr_sp_session_player_seek = dlsym(h, "sp_session_player_seek"))
&& (fptr_sp_session_connectionstate = dlsym(h, "sp_session_connectionstate")) && (fptr_sp_session_connectionstate = dlsym(h, "sp_session_connectionstate"))
&& (fptr_sp_session_preferred_bitrate = dlsym(h, "sp_session_preferred_bitrate"))
&& (fptr_sp_playlistcontainer_add_callbacks = dlsym(h, "sp_playlistcontainer_add_callbacks")) && (fptr_sp_playlistcontainer_add_callbacks = dlsym(h, "sp_playlistcontainer_add_callbacks"))
&& (fptr_sp_playlistcontainer_num_playlists = dlsym(h, "sp_playlistcontainer_num_playlists")) && (fptr_sp_playlistcontainer_num_playlists = dlsym(h, "sp_playlistcontainer_num_playlists"))
&& (fptr_sp_playlistcontainer_playlist = dlsym(h, "sp_playlistcontainer_playlist")) && (fptr_sp_playlistcontainer_playlist = dlsym(h, "sp_playlistcontainer_playlist"))
@ -1606,7 +1609,7 @@ spotify_login(char *path)
int int
spotify_init(void) spotify_init(void)
{ {
cfg_t *lib; cfg_t *spotify_cfg;
sp_session *sp; sp_session *sp;
sp_error err; sp_error err;
int ret; int ret;
@ -1719,9 +1722,9 @@ spotify_init(void)
DPRINTF(E_INFO, L_SPOTIFY, "Spotify session init\n"); DPRINTF(E_INFO, L_SPOTIFY, "Spotify session init\n");
lib = cfg_getsec(cfg, "spotify"); spotify_cfg = cfg_getsec(cfg, "spotify");
spconfig.settings_location = cfg_getstr(lib, "settings_dir"); spconfig.settings_location = cfg_getstr(spotify_cfg, "settings_dir");
spconfig.cache_location = cfg_getstr(lib, "cache_dir"); spconfig.cache_location = cfg_getstr(spotify_cfg, "cache_dir");
DPRINTF(E_DBG, L_SPOTIFY, "Creating Spotify session\n"); DPRINTF(E_DBG, L_SPOTIFY, "Creating Spotify session\n");
err = fptr_sp_session_create(&spconfig, &sp); err = fptr_sp_session_create(&spconfig, &sp);
@ -1734,6 +1737,19 @@ spotify_init(void)
g_sess = sp; g_sess = sp;
g_state = SPOTIFY_STATE_INACTIVE; g_state = SPOTIFY_STATE_INACTIVE;
switch (cfg_getint(spotify_cfg, "bitrate"))
{
case 1:
fptr_sp_session_preferred_bitrate(g_sess, SP_BITRATE_96k);
break;
case 2:
fptr_sp_session_preferred_bitrate(g_sess, SP_BITRATE_160k);
break;
case 3:
fptr_sp_session_preferred_bitrate(g_sess, SP_BITRATE_320k);
break;
}
/* Prepare audio buffer */ /* Prepare audio buffer */
g_audio_fifo = (audio_fifo_t *)malloc(sizeof(audio_fifo_t)); g_audio_fifo = (audio_fifo_t *)malloc(sizeof(audio_fifo_t));
if (!g_audio_fifo) if (!g_audio_fifo)