diff options
author | 2012-10-08 22:12:58 +0200 | |
---|---|---|
committer | 2012-10-08 22:12:58 +0200 | |
commit | 961135a83d63b56055e8c2c71d16c175bdf78520 (patch) | |
tree | f7e0f46450b227c879664666ec814c3a9347e848 /plugins | |
parent | 857b5d6aa589203770ff42e049288e982d8664a9 (diff) |
mms: improved aborting, increased timeout length
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/mms/libmms/mms.c | 10 | ||||
-rw-r--r-- | plugins/mms/libmms/mms.h | 2 | ||||
-rw-r--r-- | plugins/mms/libmms/mmsh.c | 3 | ||||
-rw-r--r-- | plugins/mms/libmms/mmsh.h | 2 | ||||
-rw-r--r-- | plugins/mms/libmms/mmsx.c | 6 | ||||
-rw-r--r-- | plugins/mms/mmsplug.c | 47 |
6 files changed, 55 insertions, 15 deletions
diff --git a/plugins/mms/libmms/mms.c b/plugins/mms/libmms/mms.c index ad63e6f8..e8cfae80 100644 --- a/plugins/mms/libmms/mms.c +++ b/plugins/mms/libmms/mms.c @@ -161,8 +161,9 @@ static off_t fallback_io_read(void *data, int socket, char *buf, off_t num, int off_t len = 0, ret; /* lprintf("%d\n", fallback_io_select(data, socket, MMS_IO_READ_READY, 1000)); */ errno = 0; - int nretry = 200; - while (len < num && nretry > 0) + int nretry = 600; + lprintf ("mms: fallback_io_read: need_abort ptr = %p\n", need_abort); + while (len < num && nretry > 0 && (!need_abort || !(*need_abort))) { ret = (off_t)read(socket, buf + len, num - len); if(ret == 0) @@ -499,6 +500,7 @@ static int string_utf16(iconv_t url_conv, char *dest, char *src, int dest_len) static int get_packet_header (mms_io_t *io, mms_t *this, mms_packet_header_t *header) { size_t len; int packet_type; + lprintf ("mms: get_packet_header: need_abort ptr = %p\n", this->need_abort); header->packet_len = 0; header->packet_seq = 0; @@ -576,6 +578,7 @@ static int get_answer (mms_io_t *io, mms_t *this) { int command = 0; mms_packet_header_t header; + lprintf ("mms: get_answer: need_abort ptr = %p\n", this->need_abort); switch (get_packet_header (io, this, &header)) { case MMS_PACKET_ERR: break; @@ -1039,7 +1042,7 @@ int static mms_choose_best_streams(mms_io_t *io, mms_t *this) { * network timing request */ /* FIXME: got somewhat broken during xine_stream_t->(void*) conversion */ -mms_t *mms_connect (mms_io_t *io, void *data, const char *url, int bandwidth) { +mms_t *mms_connect (mms_io_t *io, void *data, const char *url, int bandwidth, int *need_abort) { iconv_t url_conv = (iconv_t)-1; mms_t *this; int res; @@ -1070,6 +1073,7 @@ mms_t *mms_connect (mms_io_t *io, void *data, const char *url, int bandwidth) { this->bandwidth = bandwidth; this->current_pos = 0; this->eos = 0; + this->need_abort = need_abort; this->guri = gnet_uri_new(this->url); if(!this->guri) { diff --git a/plugins/mms/libmms/mms.h b/plugins/mms/libmms/mms.h index be329eef..e5eb3bb8 100644 --- a/plugins/mms/libmms/mms.h +++ b/plugins/mms/libmms/mms.h @@ -37,7 +37,7 @@ extern "C" { typedef struct mms_s mms_t; -mms_t* mms_connect (mms_io_t *io, void *data, const char *url, int bandwidth); +mms_t* mms_connect (mms_io_t *io, void *data, const char *url, int bandwidth, int *need_abort); int mms_read (mms_io_t *io, mms_t *instance, char *data, int len, int *need_abort); int mms_request_time_seek (mms_io_t *io, mms_t *instance, double time_sec); diff --git a/plugins/mms/libmms/mmsh.c b/plugins/mms/libmms/mmsh.c index a0552f6c..fe3d12ce 100644 --- a/plugins/mms/libmms/mmsh.c +++ b/plugins/mms/libmms/mmsh.c @@ -1017,7 +1017,7 @@ fail: return 0; } -mmsh_t *mmsh_connect (mms_io_t *io, void *data, const char *url, int bandwidth) { +mmsh_t *mmsh_connect (mms_io_t *io, void *data, const char *url, int bandwidth, int *need_abort) { mmsh_t *this; GURI *uri = NULL; GURI *proxy_uri = NULL; @@ -1041,6 +1041,7 @@ mmsh_t *mmsh_connect (mms_io_t *io, void *data, const char *url, int bandwidth) this->host_user = NULL; this->host_password = NULL; this->uri = NULL; + this->need_abort = need_abort; this->url = strdup(url); if ((proxy_env = getenv("http_proxy")) != NULL) diff --git a/plugins/mms/libmms/mmsh.h b/plugins/mms/libmms/mmsh.h index 744eefc0..898894bb 100644 --- a/plugins/mms/libmms/mmsh.h +++ b/plugins/mms/libmms/mmsh.h @@ -37,7 +37,7 @@ extern "C" { typedef struct mmsh_s mmsh_t; char* mmsh_connect_common(int *s ,int *port, char *url, char **host, char **path, char **file); -mmsh_t* mmsh_connect (mms_io_t *io, void *data, const char *url_, int bandwidth); +mmsh_t* mmsh_connect (mms_io_t *io, void *data, const char *url_, int bandwidth, int *need_abort); int mmsh_read (mms_io_t *io, mmsh_t *instance, char *data, int len, int *need_abort); int mmsh_time_seek (mms_io_t *io, mmsh_t *instance, double time_sec); diff --git a/plugins/mms/libmms/mmsx.c b/plugins/mms/libmms/mmsx.c index e2c3fd9b..8d206b8f 100644 --- a/plugins/mms/libmms/mmsx.c +++ b/plugins/mms/libmms/mmsx.c @@ -53,17 +53,17 @@ mmsx_t *mmsx_connect(mms_io_t *io, void *data, const char *url, int bandwidth, i handle it. The LIBMMS_TRY_MMS_FIRST environment variable is there for testing the mms code against servers which accept both mmsh and mms. */ if (try_mms_first, 1) { - mmsx->connection = mms_connect(io, data, url, bandwidth); + mmsx->connection = mms_connect(io, data, url, bandwidth, need_abort); if (mmsx->connection) return mmsx; } - mmsx->connection_h = mmsh_connect(io, data, url, bandwidth); + mmsx->connection_h = mmsh_connect(io, data, url, bandwidth, need_abort); if (mmsx->connection_h) return mmsx; if (!try_mms_first, 0) { - mmsx->connection = mms_connect(io, data, url, bandwidth); + mmsx->connection = mms_connect(io, data, url, bandwidth, need_abort); if (mmsx->connection) return mmsx; } diff --git a/plugins/mms/mmsplug.c b/plugins/mms/mmsplug.c index 3d2e3faf..928a527d 100644 --- a/plugins/mms/mmsplug.c +++ b/plugins/mms/mmsplug.c @@ -26,6 +26,7 @@ static DB_functions_t *deadbeef; typedef struct { DB_vfs_t *vfs; + char *fname; mmsx_t *stream; const mms_io_t *io; int need_abort; @@ -49,35 +50,61 @@ const char * mms_bandwidth_strs[]={"14.4 Kbps (Modem)", "19.2 Kbps (Modem)", static DB_FILE * mms_open (const char *fname) { MMS_FILE *fp = malloc (sizeof (MMS_FILE)); + memset (fp, 0, sizeof (MMS_FILE)); fp->io = mms_get_default_io_impl(); - fp->stream = mmsx_connect ((mms_io_t *)fp->io, fp, fname, 1544000, &fp->need_abort); - if (!fp->stream) { - free (fp); - return NULL; - } + fp->fname = strdup (fname); fp->vfs = &plugin; return (DB_FILE*)fp; } static void mms_close (DB_FILE *stream) { +// fprintf (stderr, "\033[0;32mmms_close was called\033[37;0m\n"); assert (stream); - mmsx_close (((MMS_FILE *)stream)->stream); + MMS_FILE *fp = (MMS_FILE *)stream; + if (fp->stream) { + mmsx_close (fp->stream); + } + if (fp->fname) { + free (fp->fname); + } free (stream); } +static int +mms_ensure_connected (MMS_FILE *fp) { + if (!fp->stream) { + fp->stream = mmsx_connect ((mms_io_t *)fp->io, fp, fp->fname, 1544000, &fp->need_abort); + if (!fp->stream) { + return -1; + } + } + return 0; +} + static size_t mms_read (void *ptr, size_t size, size_t nmemb, DB_FILE *stream) { assert (stream); assert (ptr); + int connect_err = mms_ensure_connected ((MMS_FILE *)stream); + if (connect_err < 0) { + return connect_err; + } MMS_FILE *fp = (MMS_FILE *)stream; int res = mmsx_read ((mms_io_t *)fp->io, fp->stream, ptr, size * nmemb); + if (fp->need_abort) { + return -1; + } return res; } static int mms_seek (DB_FILE *stream, int64_t offset, int whence) { assert (stream); + int connect_err = mms_ensure_connected ((MMS_FILE *)stream); + if (connect_err < 0) { + return connect_err; + } MMS_FILE *fp = (MMS_FILE *)stream; return mmsx_seek ((mms_io_t *)fp->io, fp->stream, offset, whence); } @@ -85,6 +112,10 @@ mms_seek (DB_FILE *stream, int64_t offset, int whence) { static int64_t mms_tell (DB_FILE *stream) { assert (stream); + int connect_err = mms_ensure_connected ((MMS_FILE *)stream); + if (connect_err < 0) { + return connect_err; + } return mmsx_get_current_pos (((MMS_FILE *)stream)->stream); } @@ -98,6 +129,10 @@ mms_rewind (DB_FILE *stream) { static int64_t mms_getlength (DB_FILE *stream) { assert (stream); + int connect_err = mms_ensure_connected ((MMS_FILE *)stream); + if (connect_err < 0) { + return connect_err; + } MMS_FILE *f = (MMS_FILE *)stream; return mmsx_get_length (f->stream); } |