summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Alexey Yakovenko <wakeroid@gmail.com>2010-01-09 20:49:12 +0100
committerGravatar Alexey Yakovenko <wakeroid@gmail.com>2010-01-09 20:54:03 +0100
commitf26c90bb66c1aa0d8ec7ddcffada1edf1a12bf92 (patch)
treebc16badfa4d86e1ff4a6fbdf8125017a5498b163
parent418960f37fe1d615b420f0b9ba9afcd7ba5434c1 (diff)
support for interruption of http streaming at any time
-rw-r--r--deadbeef.h2
-rw-r--r--plugins.c1
-rw-r--r--plugins/mpgmad/mpgmad.c3
-rw-r--r--plugins/vfs_curl/vfs_curl.c25
-rw-r--r--plugins/vorbis/vorbis.c3
-rw-r--r--streamer.c18
-rw-r--r--vfs.c7
7 files changed, 15 insertions, 44 deletions
diff --git a/deadbeef.h b/deadbeef.h
index 195ba86b..c656a39e 100644
--- a/deadbeef.h
+++ b/deadbeef.h
@@ -423,7 +423,6 @@ typedef struct DB_plugin_s {
} DB_plugin_t;
typedef struct {
- DB_FILE *file;
int bps;
int channels;
int samplerate;
@@ -531,7 +530,6 @@ typedef struct DB_vfs_s {
int64_t (*tell) (DB_FILE *stream);
void (*rewind) (DB_FILE *stream);
int64_t (*getlength)(DB_FILE *stream);
- void (*stop)(DB_FILE *stream);
const char * (*get_content_type) (DB_FILE *stream);
const char * (*get_content_name) (DB_FILE *stream);
const char * (*get_content_genre) (DB_FILE *stream);
diff --git a/plugins.c b/plugins.c
index 74f78c7f..fc779173 100644
--- a/plugins.c
+++ b/plugins.c
@@ -158,7 +158,6 @@ static DB_functions_t deadbeef_api = {
.fget_content_type = vfs_get_content_type,
.fget_content_name = vfs_get_content_name,
.fget_content_genre = vfs_get_content_genre,
- .fstop = vfs_fstop,
// message passing
.sendmessage = messagepump_push,
// configuration access
diff --git a/plugins/mpgmad/mpgmad.c b/plugins/mpgmad/mpgmad.c
index 9bef2bc8..0dec44d0 100644
--- a/plugins/mpgmad/mpgmad.c
+++ b/plugins/mpgmad/mpgmad.c
@@ -516,7 +516,7 @@ cmp3_scan_stream (buffer_t *buffer, int sample) {
static int
cmp3_init (DB_playItem_t *it) {
memset (&buffer, 0, sizeof (buffer));
- buffer.file = plugin.info.file = deadbeef->fopen (it->fname);
+ buffer.file = deadbeef->fopen (it->fname);
if (!buffer.file) {
return -1;
}
@@ -840,7 +840,6 @@ cmp3_decode_float32 (void) {
static void
cmp3_free (void) {
- plugin.info.file = NULL;
if (buffer.file) {
deadbeef->fclose (buffer.file);
buffer.file = NULL;
diff --git a/plugins/vfs_curl/vfs_curl.c b/plugins/vfs_curl/vfs_curl.c
index 1ef633b1..411ddd13 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))
@@ -131,6 +131,9 @@ http_curl_write (void *ptr, size_t size, size_t nmemb, void *stream) {
}
deadbeef->mutex_unlock (fp->mutex);
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");
@@ -314,7 +317,6 @@ http_curl_control (void *stream, double dltotal, double dlnow, double ultotal, d
static void
http_thread_func (void *ctx) {
- vfs_curl_count++;
HTTP_FILE *fp = (HTTP_FILE *)ctx;
CURL *curl;
curl = curl_easy_init ();
@@ -378,7 +380,9 @@ 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);
@@ -399,7 +403,6 @@ http_thread_func (void *ctx) {
fp->status = STATUS_FINISHED;
deadbeef->mutex_unlock (fp->mutex);
fp->tid = 0;
- vfs_curl_count--;
}
static void
@@ -462,6 +465,7 @@ http_read (void *ptr, size_t size, size_t nmemb, DB_FILE *stream) {
{
// wait until data is available
while ((fp->remaining == 0 || fp->skipbytes > 0) && fp->status != STATUS_FINISHED && !vfs_curl_abort) {
+ trace ("vfs_curl: readwait..\n");
deadbeef->mutex_lock (fp->mutex);
int skip = min (fp->remaining, fp->skipbytes);
if (skip > 0) {
@@ -665,24 +669,18 @@ http_get_content_genre (DB_FILE *stream) {
}
#endif
-static void
-http_stop (DB_FILE *stream) {
- trace ("http_stop\n");
- assert (stream);
- HTTP_FILE *fp = (HTTP_FILE *)stream;
- fp->status = STATUS_ABORTED;
-}
-
static int
vfs_curl_on_abort (DB_event_t *ev, uintptr_t data) {
- trace ("vfs_curl: got abort signal!\n");
+ 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;
}
@@ -724,7 +722,6 @@ static DB_vfs_t plugin = {
.get_content_type = http_get_content_type,
.get_content_name = http_get_content_name,
.get_content_genre = http_get_content_type,
- .stop = http_stop,
.scheme_names = scheme_names,
.streaming = 1
};
diff --git a/plugins/vorbis/vorbis.c b/plugins/vorbis/vorbis.c
index 1eb3f002..9a631a73 100644
--- a/plugins/vorbis/vorbis.c
+++ b/plugins/vorbis/vorbis.c
@@ -128,7 +128,7 @@ cvorbis_init (DB_playItem_t *it) {
cur_bit_stream = -1;
ptrack = it;
- file = plugin.info.file = deadbeef->fopen (it->fname);
+ file = deadbeef->fopen (it->fname);
if (!file) {
return -1;
}
@@ -209,7 +209,6 @@ cvorbis_init (DB_playItem_t *it) {
static void
cvorbis_free (void) {
- plugin.info.file = NULL;
if (file) {
ptrack = NULL;
ov_clear (&vorbis_file);
diff --git a/streamer.c b/streamer.c
index 3eac2219..3a29866f 100644
--- a/streamer.c
+++ b/streamer.c
@@ -36,8 +36,8 @@
#include "volume.h"
#include "vfs.h"
-#define trace(...) { fprintf(stderr, __VA_ARGS__); }
-//#define trace(fmt,...)
+//#define trace(...) { fprintf(stderr, __VA_ARGS__); }
+#define trace(fmt,...)
static intptr_t streamer_tid;
static int src_quality;
@@ -57,7 +57,6 @@ static float g_fbuffer[INPUT_BUFFER_SIZE];
#define SRC_BUFFER_SIZE (INPUT_BUFFER_SIZE*2)
static float g_srcbuffer[SRC_BUFFER_SIZE];
static int streaming_terminate;
-static playItem_t *streamer_initializing_item;
// buffer up to 3 seconds at 44100Hz stereo
#define STREAM_BUFFER_SIZE 0x80000 // slightly more than 3 seconds of 44100 stereo
@@ -179,11 +178,9 @@ streamer_set_current (playItem_t *it) {
}
if (it->decoder) {
streamer_lock ();
- streamer_initializing_item = it;
streamer_unlock ();
int ret = it->decoder->init (DB_PLAYITEM (it));
streamer_lock ();
- streamer_initializing_item = NULL;
streamer_unlock ();
pl_item_copy (&str_streaming_song, it);
if (ret < 0) {
@@ -246,17 +243,6 @@ streamer_set_nextsong (int song, int pstate) {
playpos = 0;
// try to interrupt file operation
streamer_lock ();
- if (streamer_file && streamer_file->vfs->streaming) {
- trace ("interrupting streamer file access...\n");
- vfs_fstop (streamer_file);
- }
- else if (streamer_initializing_item) {
- playItem_t *it = streamer_initializing_item;
- if (it->decoder->info.file && it->decoder->info.file->vfs->streaming) {
- trace ("interrupting plugin stream %p...\n", it->decoder->info.file);
- vfs_fstop (it->decoder->info.file);
- }
- }
streamer_unlock ();
}
}
diff --git a/vfs.c b/vfs.c
index 0b8fc3b8..aff6c0ad 100644
--- a/vfs.c
+++ b/vfs.c
@@ -99,10 +99,3 @@ vfs_get_content_genre (DB_FILE *stream) {
}
return NULL;
}
-
-void
-vfs_fstop (DB_FILE *stream) {
- if (stream->vfs->stop) {
- stream->vfs->stop (stream);
- }
-}