diff options
author | Alexey Yakovenko <wakeroid@gmail.com> | 2010-04-25 13:02:53 +0200 |
---|---|---|
committer | Alexey Yakovenko <wakeroid@gmail.com> | 2010-04-25 13:02:53 +0200 |
commit | 5a59ffc070744e94675201d6e8164befec6d9813 (patch) | |
tree | 8f378ffd01e3488440c320f0bec6e5afc566695e | |
parent | 48594c75a15c4d3976efede324ad5bb92e38381e (diff) |
removed old curl hacks/workarounds
-rw-r--r-- | deadbeef.h | 6 | ||||
-rw-r--r-- | plugins.c | 1 | ||||
-rw-r--r-- | plugins/mpgmad/mpgmad.c | 2 | ||||
-rw-r--r-- | plugins/vfs_curl/vfs_curl.c | 47 | ||||
-rw-r--r-- | plugins/vorbis/vorbis.c | 23 | ||||
-rw-r--r-- | streamer.c | 5 | ||||
-rw-r--r-- | vfs.c | 6 | ||||
-rw-r--r-- | vfs.h | 2 |
8 files changed, 42 insertions, 50 deletions
@@ -222,7 +222,6 @@ enum { DB_EV_SONGCHANGED = 1, // triggers when song was just changed DB_EV_SONGSTARTED = 2, // triggers when song started playing (for scrobblers and such) DB_EV_SONGFINISHED = 3, // triggers when song finished playing (for scrobblers and such) -// DB_EV_TRACKDELETED = 4, // triggers when track is to be deleted from playlist DB_EV_CONFIGCHANGED = 5, // configuration option changed DB_EV_ACTIVATE = 6, // will be fired every time player is activated DB_EV_TRACKINFOCHANGED = 7, // notify plugins that trackinfo was changed @@ -230,7 +229,6 @@ enum { DB_EV_PLAYLISTCHANGED = 9, // playlist contents were changed DB_EV_VOLUMECHANGED = 10, // volume was changed DB_EV_OUTPUTCHANGED = 11, // sound output plugin changed - DB_EV_ABORTREAD = 12, // tells plugins to stop reading operations, e.g. long-time http requests DB_EV_PLAYLISTSWITCH = 13, // playlist switch occured DB_EV_MAX }; @@ -491,7 +489,7 @@ typedef struct { int64_t (*fgetlength) (DB_FILE *stream); const char *(*fget_content_type) (DB_FILE *stream); void (*fset_track) (DB_FILE *stream, DB_playItem_t *it); - void (*fstop) (DB_FILE *stream); + void (*fabort) (DB_FILE *stream); // message passing int (*sendmessage) (uint32_t id, uintptr_t ctx, uint32_t p1, uint32_t p2); // configuration access @@ -564,6 +562,7 @@ typedef struct DB_fileinfo_s { int channels; int samplerate; float readpos; + DB_FILE *file; } DB_fileinfo_t; // decoder plugin @@ -671,6 +670,7 @@ typedef struct DB_vfs_s { void (*rewind) (DB_FILE *stream); int64_t (*getlength)(DB_FILE *stream); const char * (*get_content_type) (DB_FILE *stream); + void (*abort) (DB_FILE *stream); const char **scheme_names; // NULL-terminated list of supported schemes, e.g. {"http", "ftp", NULL} unsigned streaming : 1; } DB_vfs_t; @@ -223,6 +223,7 @@ static DB_functions_t deadbeef_api = { .fgetlength = vfs_fgetlength, .fget_content_type = vfs_get_content_type, .fset_track = (void (*) (DB_FILE *stream, DB_playItem_t *it))vfs_set_track, + .fabort = vfs_fabort, // message passing .sendmessage = messagepump_push, // configuration access diff --git a/plugins/mpgmad/mpgmad.c b/plugins/mpgmad/mpgmad.c index b9ac42e2..1a7a8450 100644 --- a/plugins/mpgmad/mpgmad.c +++ b/plugins/mpgmad/mpgmad.c @@ -570,6 +570,7 @@ cmp3_init (DB_playItem_t *it) { if (!info->buffer.file) { return NULL; } + info->info.file = info->buffer.file; deadbeef->pl_item_ref (it); info->buffer.it = it; info->info.readpos = 0; @@ -909,6 +910,7 @@ cmp3_free (DB_fileinfo_t *_info) { } deadbeef->fclose (info->buffer.file); info->buffer.file = NULL; + info->info.file = NULL; mad_synth_finish (&info->synth); mad_frame_finish (&info->frame); mad_stream_finish (&info->stream); diff --git a/plugins/vfs_curl/vfs_curl.c b/plugins/vfs_curl/vfs_curl.c index 7cc6298d..0080e68c 100644 --- a/plugins/vfs_curl/vfs_curl.c +++ b/plugins/vfs_curl/vfs_curl.c @@ -24,8 +24,8 @@ #include <curl/curlver.h> #include "../../deadbeef.h" -//#define trace(...) { fprintf(stderr, __VA_ARGS__); } -#define trace(fmt,...) +#define trace(...) { fprintf(stderr, __VA_ARGS__); } +//#define trace(fmt,...) #define min(x,y) ((x)<(y)?(x):(y)) #define max(x,y) ((x)>(y)?(x):(y)) @@ -60,8 +60,6 @@ typedef struct { intptr_t mutex; uint8_t nheaderpackets; char *content_type; -// char *content_name; -// char *content_genre; CURL *curl; struct timeval last_read_time; uint8_t status; @@ -83,8 +81,6 @@ static DB_vfs_t plugin; static char http_err[CURL_ERROR_SIZE]; -static int vfs_curl_abort; -static int vfs_curl_count; static int allow_new_streams; static size_t @@ -94,9 +90,6 @@ static size_t http_curl_write_wrapper (HTTP_FILE *fp, void *ptr, size_t size) { size_t avail = size; while (avail > 0) { - if (vfs_curl_abort) { - break; - } deadbeef->mutex_lock (fp->mutex); if (fp->status == STATUS_SEEK) { trace ("vfs_curl seek request, aborting current request\n"); @@ -441,10 +434,6 @@ http_curl_control (void *stream, double dltotal, double dlnow, double ultotal, d trace ("vfs_curl STATUS_ABORTED in progress callback\n"); return -1; } - if (vfs_curl_abort) { - trace ("vfs_curl: aborting stream %p due to external request\n"); - return -1; - } return 0; } @@ -514,9 +503,7 @@ http_thread_func (void *ctx) { #endif curl_easy_setopt (curl, CURLOPT_PROXYTYPE, curlproxytype); } - vfs_curl_count++; status = curl_easy_perform (curl); - vfs_curl_count--; trace ("vfs_curl: curl_easy_perform status=%d\n", status); if (status != 0) { trace ("curl error:\n%s\n", http_err); @@ -575,6 +562,7 @@ http_open (const char *fname) { fp->url = strdup (fname); return (DB_FILE*)fp; } + static void http_set_track (DB_FILE *f, DB_playItem_t *it) { HTTP_FILE *fp = (HTTP_FILE *)f; @@ -624,7 +612,7 @@ http_read (void *ptr, size_t size, size_t nmemb, DB_FILE *stream) { while (fp->status != STATUS_FINISHED && sz > 0) { // wait until data is available - while ((fp->remaining == 0 || fp->skipbytes > 0) && fp->status != STATUS_FINISHED && !vfs_curl_abort) { + while ((fp->remaining == 0 || fp->skipbytes > 0) && fp->status != STATUS_FINISHED) { // trace ("vfs_curl: readwait..\n"); deadbeef->mutex_lock (fp->mutex); if (fp->status == STATUS_READING) { @@ -793,39 +781,31 @@ http_get_content_type (DB_FILE *stream) { http_start_streamer (fp); } trace ("http_get_content_type waiting for response...\n"); - while (fp->status != STATUS_FINISHED && fp->status != STATUS_ABORTED && !fp->gotheader && !vfs_curl_abort) { + while (fp->status != STATUS_FINISHED && fp->status != STATUS_ABORTED && !fp->gotheader) { usleep (3000); } return fp->content_type; } -static int -vfs_curl_on_abort (DB_event_t *ev, uintptr_t data) { - trace ("vfs_curl: got abort signal (vfs_curl_count=%d)!\n", vfs_curl_count); - if (vfs_curl_count > 0) { - vfs_curl_abort = 1; - while (vfs_curl_count > 0) { - trace ("vfs_curl: (vfs_curl_count=%d)!\n", vfs_curl_count); - usleep (20000); - } - vfs_curl_abort = 0; - } - trace ("vfs_curl: abort handler done!\n"); - return 0; +void +http_abort (DB_FILE *fp) { + trace ("http_abort\n"); + HTTP_FILE *f = (HTTP_FILE *)fp; + deadbeef->mutex_lock (f->mutex); + f->status = STATUS_ABORTED; + deadbeef->mutex_unlock (f->mutex); + deadbeef->thread_join (f->tid); } static int vfs_curl_start (void) { - deadbeef->ev_subscribe (DB_PLUGIN (&plugin), DB_EV_ABORTREAD, DB_CALLBACK (vfs_curl_on_abort), 0); allow_new_streams = 1; return 0; } static int vfs_curl_stop (void) { - deadbeef->ev_unsubscribe (DB_PLUGIN (&plugin), DB_EV_ABORTREAD, DB_CALLBACK (vfs_curl_on_abort), 0); allow_new_streams = 0; - vfs_curl_on_abort (NULL, 0); return 0; } @@ -848,6 +828,7 @@ static DB_vfs_t plugin = { .open = http_open, .set_track = http_set_track, .close = http_close, + .abort = http_abort, .read = http_read, .seek = http_seek, .tell = http_tell, diff --git a/plugins/vorbis/vorbis.c b/plugins/vorbis/vorbis.c index d31d9f35..c35bf190 100644 --- a/plugins/vorbis/vorbis.c +++ b/plugins/vorbis/vorbis.c @@ -39,7 +39,6 @@ static DB_functions_t *deadbeef; typedef struct { DB_fileinfo_t info; - DB_FILE *file; OggVorbis_File vorbis_file; vorbis_info *vi; int cur_bit_stream; @@ -136,20 +135,20 @@ cvorbis_init (DB_playItem_t *it) { DB_fileinfo_t *_info = malloc (sizeof (ogg_info_t)); ogg_info_t *info = (ogg_info_t *)_info; memset (info, 0, sizeof (ogg_info_t)); - info->file = NULL; + info->info.file = NULL; info->vi = NULL; info->cur_bit_stream = -1; info->ptrack = it; deadbeef->pl_item_ref (it); - info->file = deadbeef->fopen (it->fname); - if (!info->file) { + info->info.file = deadbeef->fopen (it->fname); + if (!info->info.file) { trace ("ogg: failed to open file %s\n", it->fname); plugin.free (_info); return NULL; } - int ln = deadbeef->fgetlength (info->file); - if (info->file->vfs->streaming && ln == -1) { + int ln = deadbeef->fgetlength (info->info.file); + if (info->info.file->vfs->streaming && ln == -1) { ov_callbacks ovcb = { .read_func = cvorbis_fread, .seek_func = NULL, @@ -158,7 +157,7 @@ cvorbis_init (DB_playItem_t *it) { }; trace ("calling ov_open_callbacks\n"); - int err = ov_open_callbacks (info->file, &info->vorbis_file, NULL, 0, ovcb); + int err = ov_open_callbacks (info->info.file, &info->vorbis_file, NULL, 0, ovcb); if (err != 0) { trace ("ov_open_callbacks returned %d\n", err); plugin.free (_info); @@ -176,7 +175,7 @@ cvorbis_init (DB_playItem_t *it) { }; trace ("calling ov_open_callbacks\n"); - int err = ov_open_callbacks (info->file, &info->vorbis_file, NULL, 0, ovcb); + int err = ov_open_callbacks (info->info.file, &info->vorbis_file, NULL, 0, ovcb); if (err != 0) { trace ("ov_open_callbacks returned %d\n", err); plugin.free (_info); @@ -202,7 +201,7 @@ cvorbis_init (DB_playItem_t *it) { _info->samplerate = info->vi->rate; _info->readpos = 0; info->currentsample = 0; - if (!info->file->vfs->streaming) { + if (!info->info.file->vfs->streaming) { if (it->endsample > 0) { info->startsample = it->startsample; info->endsample = it->endsample; @@ -231,7 +230,7 @@ static void cvorbis_free (DB_fileinfo_t *_info) { ogg_info_t *info = (ogg_info_t *)_info; if (info) { - if (info->file) { + if (info->info.file) { if (info->ptrack) { deadbeef->pl_item_unref (info->ptrack); } @@ -246,7 +245,7 @@ static int cvorbis_read (DB_fileinfo_t *_info, char *bytes, int size) { ogg_info_t *info = (ogg_info_t *)_info; // trace ("cvorbis_read %d bytes\n", size); - if (!info->file->vfs->streaming) { + if (!info->info.file->vfs->streaming) { if (info->currentsample + size / (2 * _info->channels) > info->endsample) { size = (info->endsample - info->currentsample + 1) * 2 * _info->channels; trace ("size truncated to %d bytes, cursample=%d, info->endsample=%d, totalsamples=%d\n", size, info->currentsample, info->endsample, ov_pcm_total (&info->vorbis_file, -1)); @@ -326,7 +325,7 @@ cvorbis_seek_sample (DB_fileinfo_t *_info, int sample) { trace ("vorbis: negative seek sample - ignored, but it is a bug!\n"); return -1; } - if (!info->file) { + if (!info->info.file) { trace ("vorbis: file is NULL on seek\n"); return -1; } @@ -572,7 +572,10 @@ streamer_get_apx_bitrate (void) { void streamer_set_nextsong (int song, int pstate) { trace ("streamer_set_nextsong %d %d\n", song, pstate); - plug_trigger_event (DB_EV_ABORTREAD, 0); + //plug_trigger_event (DB_EV_ABORTREAD, 0); + if (fileinfo && fileinfo->file) { + deadbeef->fabort (fileinfo->file); + } nextsong = song; nextsong_pstate = pstate; if (p_isstopped ()) { @@ -91,3 +91,9 @@ vfs_get_content_type (DB_FILE *stream) { return stream->vfs->get_content_type (stream); } +void +vfs_fabort (DB_FILE *stream) { + if (stream->vfs->abort) { + stream->vfs->abort (stream); + } +} @@ -31,6 +31,6 @@ int64_t vfs_ftell (DB_FILE *stream); void vfs_rewind (DB_FILE *stream); int64_t vfs_fgetlength (DB_FILE *stream); const char *vfs_get_content_type (DB_FILE *stream); -void vfs_fstop (DB_FILE *stream); +void vfs_fabort (DB_FILE *stream); #endif // __VFS_H |