summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt6
-rw-r--r--src/main.c23
-rw-r--r--src/player.c58
-rw-r--r--src/player.h9
-rw-r--r--src/settings.c19
-rw-r--r--src/settings.h3
-rw-r--r--src/ui.c2
-rw-r--r--src/ui.h2
8 files changed, 41 insertions, 81 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 5fb020c..8a776d7 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -7,7 +7,6 @@ option (USE_FAAD "Use libfaad for aac decoding (if available)" on)
option (USE_MAD "Use libmad for mp3 decoding (if available)" on)
find_package (LibXml2 REQUIRED)
-find_package (CURL REQUIRED)
find_package (LibAo REQUIRED)
# find threading implementation
@@ -55,13 +54,14 @@ configure_file (${CMAKE_CURRENT_SOURCE_DIR}/config.h.in
include_directories (
${pianobar_SOURCE_DIR}/libpiano/src
${pianobar_SOURCE_DIR}/libwardrobe/src
+ ${pianobar_SOURCE_DIR}/libwaitress/src
${LIBXML2_INCLUDE_DIR}
- ${CURL_INCLUDE_DIRS} ${FAAD_INCLUDE_DIRS} ${LIBAO_INCLUDE_DIRS}
+ ${FAAD_INCLUDE_DIRS} ${LIBAO_INCLUDE_DIRS}
${MAD_INCLUDE_DIRS})
add_executable (pianobar main.c terminal.c settings.c player.c ui.c ui_act.c
ui_readline.c)
-target_link_libraries (pianobar piano wardrobe ${CURL_LIBRARIES}
+target_link_libraries (pianobar piano wardrobe waitress
${LIBXML2_LIBRARIES} ${FAAD_LIBRARY} ${LIBAO_LIBRARY}
${CMAKE_THREAD_LIBS_INIT} ${MAD_LIBRARIES} ${LIBM})
diff --git a/src/main.c b/src/main.c
index 70ffcc7..8409583 100644
--- a/src/main.c
+++ b/src/main.c
@@ -80,7 +80,6 @@ int main (int argc, char **argv) {
/* init some things */
BarTermSetEcho (0);
- curl_global_init (CURL_GLOBAL_SSL);
xmlInitParser ();
ao_initialize ();
PianoInit (&ph);
@@ -123,20 +122,16 @@ int main (int argc, char **argv) {
}
/* setup control connection */
- if (settings.controlProxy != NULL &&
- settings.controlProxyType != -1) {
- curl_easy_setopt (ph.curlHandle, CURLOPT_PROXY,
- settings.controlProxy);
- curl_easy_setopt (ph.curlHandle, CURLOPT_PROXYTYPE,
- settings.controlProxyType);
+ if (settings.controlProxy != NULL) {
+ char tmpPath[2];
+ WaitressSplitUrl (settings.controlProxy, ph.waith.proxyHost, sizeof (ph.waith.proxyHost), ph.waith.proxyPort, sizeof (ph.waith.proxyPort), tmpPath, sizeof (tmpPath));
}
- curl_easy_setopt (ph.curlHandle, CURLOPT_CONNECTTIMEOUT, 60);
BarTermSetBuffer (0);
BarUiMsg (MSG_INFO, "Login... ");
if (BarUiPrintPianoStatus (PianoConnect (&ph, settings.username,
- settings.password, !settings.disableSecureLogin)) !=
+ settings.password)) !=
PIANO_RET_OK) {
return 0;
}
@@ -186,7 +181,6 @@ int main (int argc, char **argv) {
}
}
WardrobeSongDestroy (&scrobbleSong);
- free (player.url);
/* FIXME: pthread_join blocks everything if network connection
* is hung up e.g. */
pthread_join (playerThread, NULL);
@@ -236,7 +230,10 @@ int main (int argc, char **argv) {
/* setup player */
memset (&player, 0, sizeof (player));
- player.url = strdup (curSong->audioUrl);
+
+ WaitressInit (&player.waith);
+ WaitressSetUrl (&player.waith, curSong->audioUrl);
+
player.gain = curSong->fileGain;
player.audioFormat = curSong->audioFormat;
@@ -287,8 +284,7 @@ int main (int argc, char **argv) {
}
/* destroy everything (including the world...) */
- if (player.url != NULL) {
- free (player.url);
+ if (player.mode != PLAYER_FREED) {
pthread_join (playerThread, NULL);
}
if (ctlFd != NULL) {
@@ -296,7 +292,6 @@ int main (int argc, char **argv) {
}
PianoDestroy (&ph);
WardrobeDestroy (&wh);
- curl_global_cleanup ();
ao_shutdown();
xmlCleanupParser ();
BarSettingsDestroy (&settings);
diff --git a/src/player.c b/src/player.c
index bbf815f..3acfe58 100644
--- a/src/player.c
+++ b/src/player.c
@@ -27,6 +27,7 @@ THE SOFTWARE.
#include <string.h>
#include <math.h>
#include <stdint.h>
+#include <limits.h>
#include "player.h"
#include "config.h"
@@ -120,13 +121,13 @@ inline void BarPlayerBufferMove (struct audioPlayer *player) {
* @param extra data (player data)
* @return received bytes or less on error
*/
-size_t BarPlayerAACCurlCb (void *ptr, size_t size, size_t nmemb, void *stream) {
+char BarPlayerAACCurlCb (void *ptr, size_t size, void *stream) {
char *data = ptr;
struct audioPlayer *player = stream;
QUIT_PAUSE_CHECK;
- if (!BarPlayerBufferFill (player, data, size*nmemb)) {
+ if (!BarPlayerBufferFill (player, data, size)) {
return 0;
}
@@ -276,7 +277,7 @@ size_t BarPlayerAACCurlCb (void *ptr, size_t size, size_t nmemb, void *stream) {
BarPlayerBufferMove (player);
- return size*nmemb;
+ return 1;
}
#endif /* ENABLE_FAAD */
@@ -299,32 +300,28 @@ inline signed short int BarPlayerMadToShort (mad_fixed_t fixed) {
return (signed short int) (fixed >> (MAD_F_FRACBITS - 15));
}
-size_t BarPlayerMp3CurlCb (void *ptr, size_t size, size_t nmemb, void *stream) {
+char BarPlayerMp3CurlCb (void *ptr, size_t size, void *stream) {
char *data = ptr;
struct audioPlayer *player = stream;
size_t i;
QUIT_PAUSE_CHECK;
- if (!BarPlayerBufferFill (player, data, size*nmemb)) {
+ if (!BarPlayerBufferFill (player, data, size)) {
return 0;
}
/* initialize song length */
if (player->mode < PLAYER_SAMPLESIZE_INITIALIZED) {
- double contentLength = 0;
- /* FIXME: curl's documentation says we should call curl_easy_getinfo
- * _after_ a transfer finished */
- curl_easy_getinfo (player->audioFd, CURLINFO_CONTENT_LENGTH_DOWNLOAD,
- &contentLength);
- player->songDuration = contentLength / ((float) MP3_BITRATE * 1024.0 /
+ player->songDuration = (float) player->waith.contentLength /
+ ((float) MP3_BITRATE * 1024.0 /
(float) BAR_PLAYER_MS_TO_S_FACTOR / 8.0);
}
/* some "prebuffering" */
if (player->mode < PLAYER_RECV_DATA &&
- player->bufferFilled < sizeof (player->buffer) / 10) {
- return size*nmemb;
+ player->bufferFilled < sizeof (player->buffer) / 2) {
+ return 1;
}
mad_stream_buffer (&player->mp3Stream, player->buffer,
@@ -391,7 +388,7 @@ size_t BarPlayerMp3CurlCb (void *ptr, size_t size, size_t nmemb, void *stream) {
BarPlayerBufferMove (player);
- return size*nmemb;
+ return 1;
}
#endif /* ENABLE_MAD */
@@ -401,14 +398,18 @@ size_t BarPlayerMp3CurlCb (void *ptr, size_t size, size_t nmemb, void *stream) {
*/
void *BarPlayerThread (void *data) {
struct audioPlayer *player = data;
+ char extraHeaders[25];
#ifdef ENABLE_FAAD
NeAACDecConfigurationPtr conf;
#endif
- CURLcode curlRet = 0;
+ WaitressReturn_t wRet = WAITRESS_RET_ERR;
/* init handles */
pthread_mutex_init (&player->pauseMutex, NULL);
- player->audioFd = curl_easy_init ();
+ player->scale = computeReplayGainScale (player->gain);
+ player->waith.data = (void *) player;
+ /* extraHeaders will be initialized later */
+ player->waith.extraHeaders = extraHeaders;
switch (player->audioFormat) {
#ifdef ENABLE_FAAD
@@ -420,8 +421,7 @@ void *BarPlayerThread (void *data) {
conf->downMatrix = 1;
NeAACDecSetConfiguration(player->aacHandle, conf);
- curl_easy_setopt (player->audioFd, CURLOPT_WRITEFUNCTION,
- BarPlayerAACCurlCb);
+ player->waith.callback = BarPlayerAACCurlCb;
break;
#endif /* ENABLE_FAAD */
@@ -431,8 +431,7 @@ void *BarPlayerThread (void *data) {
mad_frame_init (&player->mp3Frame);
mad_synth_init (&player->mp3Synth);
- curl_easy_setopt (player->audioFd, CURLOPT_WRITEFUNCTION,
- BarPlayerMp3CurlCb);
+ player->waith.callback = BarPlayerMp3CurlCb;
break;
#endif /* ENABLE_MAD */
@@ -442,26 +441,15 @@ void *BarPlayerThread (void *data) {
break;
}
- /* init replaygain */
- player->scale = computeReplayGainScale (player->gain);
-
- /* init curl */
- curl_easy_setopt (player->audioFd, CURLOPT_URL, player->url);
- curl_easy_setopt (player->audioFd, CURLOPT_WRITEDATA, (void *) player);
- curl_easy_setopt (player->audioFd, CURLOPT_USERAGENT, PACKAGE);
- curl_easy_setopt (player->audioFd, CURLOPT_CONNECTTIMEOUT, 60);
- /* start downloading from beginning of file */
- curl_easy_setopt (player->audioFd, CURLOPT_RESUME_FROM, 0);
-
player->mode = PLAYER_INITIALIZED;
/* This loop should work around song abortions by requesting the
* missing part of the song */
do {
- curl_easy_setopt (player->audioFd, CURLOPT_RESUME_FROM,
+ snprintf (extraHeaders, sizeof (extraHeaders), "Range: %u-\r\n",
player->bytesReceived);
- curlRet = curl_easy_perform (player->audioFd);
- } while (curlRet == CURLE_PARTIAL_FILE || curlRet == CURLE_RECV_ERROR);
+ wRet = WaitressFetchCall (&player->waith);
+ } while (wRet == WAITRESS_RET_PARTIAL_FILE);
switch (player->audioFormat) {
#ifdef ENABLE_FAAD
@@ -483,7 +471,7 @@ void *BarPlayerThread (void *data) {
break;
}
ao_close(player->audioOutDevice);
- curl_easy_cleanup (player->audioFd);
+ WaitressFree (&player->waith);
#ifdef ENABLE_FAAD
if (player->sampleSize != NULL) {
free (player->sampleSize);
diff --git a/src/player.h b/src/player.h
index ec77f16..0d44637 100644
--- a/src/player.h
+++ b/src/player.h
@@ -26,8 +26,6 @@ THE SOFTWARE.
#include "config.h"
-#include <curl/curl.h>
-
#ifdef ENABLE_FAAD
#include <neaacdec.h>
#endif
@@ -38,13 +36,15 @@ THE SOFTWARE.
#include <ao/ao.h>
#include <pthread.h>
+
#include <piano.h>
+#include <waitress.h>
#define BAR_PLAYER_MS_TO_S_FACTOR 1000
struct audioPlayer {
/* buffer; should be large enough */
- unsigned char buffer[CURL_MAX_WRITE_SIZE*2];
+ unsigned char buffer[WAITRESS_RECV_BUFFER*2];
size_t bufferFilled;
size_t bufferRead;
size_t bytesReceived;
@@ -85,8 +85,7 @@ struct audioPlayer {
/* audio out */
ao_device *audioOutDevice;
- CURL *audioFd;
- char *url;
+ WaitressHandle_t waith;
char doQuit;
pthread_mutex_t pauseMutex;
diff --git a/src/settings.c b/src/settings.c
index 786eb53..dfff76b 100644
--- a/src/settings.c
+++ b/src/settings.c
@@ -199,19 +199,6 @@ void BarSettingsRead (BarSettings_t *settings) {
}
if (strcmp ("control_proxy", key) == 0) {
settings->controlProxy = strdup (val);
- } else if (strcmp ("control_proxy_type", key) == 0) {
- if (strcmp ("http", val) == 0) {
- settings->controlProxyType = CURLPROXY_HTTP;
- } else if (strcmp ("socks4", val) == 0) {
- settings->controlProxyType = CURLPROXY_SOCKS4;
- } else if (strcmp ("socks4a", val) == 0) {
- settings->controlProxyType = CURLPROXY_SOCKS4A;
- } else if (strcmp ("socks5", val) == 0) {
- settings->controlProxyType = CURLPROXY_SOCKS5;
- } else {
- /* error: don't use proxy at all */
- settings->controlProxyType = -1;
- }
} else if (strcmp ("user", key) == 0) {
settings->username = strdup (val);
} else if (strcmp ("password", key) == 0) {
@@ -222,12 +209,6 @@ void BarSettingsRead (BarSettings_t *settings) {
settings->lastfmPassword = strdup (val);
} else if (strcmp ("lastfm_scrobble_percent", key) == 0) {
settings->lastfmScrobblePercent = atoi (val);
- } else if (strcmp ("disable_secure_login", key) == 0) {
- if (strcmp (val, "1") == 0) {
- settings->disableSecureLogin = 1;
- } else {
- settings->disableSecureLogin = 0;
- }
} else if (memcmp ("act_", key, 4) == 0) {
/* keyboard shortcuts */
for (i = 0; i < sizeof (defaultKeys) / sizeof (*defaultKeys);
diff --git a/src/settings.h b/src/settings.h
index 1f8b63d..b3811a6 100644
--- a/src/settings.h
+++ b/src/settings.h
@@ -24,7 +24,6 @@ THE SOFTWARE.
#ifndef _SETTINGS_H
#define _SETTINGS_H
-#include <curl/curl.h>
#include <piano.h>
#include "player.h"
@@ -37,12 +36,10 @@ struct BarSettings {
char *username;
char *password;
char *controlProxy; /* non-american listeners need this */
- curl_proxytype controlProxyType;
char *lastfmUser;
char *lastfmPassword;
unsigned char lastfmScrobblePercent;
char enableScrobbling;
- char disableSecureLogin;
struct BarKeyShortcut {
char key;
void (*cmd) (BAR_KS_ARGS);
diff --git a/src/ui.c b/src/ui.c
index 53df28c..f2630e3 100644
--- a/src/ui.c
+++ b/src/ui.c
@@ -241,7 +241,7 @@ PianoArtist_t *BarUiSelectArtist (PianoArtist_t *startArtist, FILE *curFd) {
* @param piano handle
* @return musicId or NULL on abort/error
*/
-char *BarUiSelectMusicId (const PianoHandle_t *ph, FILE *curFd) {
+char *BarUiSelectMusicId (PianoHandle_t *ph, FILE *curFd) {
char *musicId = NULL;
char lineBuf[100], selectBuf[2];
PianoSearchResult_t searchResult;
diff --git a/src/ui.h b/src/ui.h
index f7c8cc4..90b5b28 100644
--- a/src/ui.h
+++ b/src/ui.h
@@ -37,7 +37,7 @@ PianoStation_t *BarUiSelectStation (PianoHandle_t *ph, const char *prompt,
FILE *curFd);
PianoSong_t *BarUiSelectSong (PianoSong_t *startSong, FILE *curFd);
PianoArtist_t *BarUiSelectArtist (PianoArtist_t *startArtist, FILE *curFd);
-char *BarUiSelectMusicId (const PianoHandle_t *ph, FILE *curFd);
+char *BarUiSelectMusicId (PianoHandle_t *ph, FILE *curFd);
void BarStationFromGenre (PianoHandle_t *ph, FILE *curFd);
inline void BarUiPrintStation (PianoStation_t *);
inline void BarUiPrintSong (PianoSong_t *, PianoStation_t *);