diff options
Diffstat (limited to 'plugins/mms')
-rw-r--r-- | plugins/mms/libmms/mms.c | 16 | ||||
-rw-r--r-- | plugins/mms/libmms/mms.h | 2 | ||||
-rw-r--r-- | plugins/mms/libmms/mmsh.c | 7 | ||||
-rw-r--r-- | plugins/mms/libmms/mmsh.h | 2 | ||||
-rw-r--r-- | plugins/mms/libmms/mmsio.h | 2 | ||||
-rw-r--r-- | plugins/mms/libmms/mmsx.c | 6 | ||||
-rw-r--r-- | plugins/mms/mmsplug.c | 48 |
7 files changed, 62 insertions, 21 deletions
diff --git a/plugins/mms/libmms/mms.c b/plugins/mms/libmms/mms.c index ad63e6f8..15c9cca9 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) @@ -191,7 +192,7 @@ static off_t fallback_io_write(void *data, int socket, char *buf, off_t num) return (off_t)write(socket, buf, num); } -static int fallback_io_tcp_connect(void *data, const char *host, int port) +static int fallback_io_tcp_connect(void *data, const char *host, int port, int *need_abort) { struct hostent *h; @@ -225,7 +226,7 @@ static int fallback_io_tcp_connect(void *data, const char *host, int port) time_t t = time (NULL); int error = 0; - for (;;) { + while (!need_abort || !(*need_abort)) { int res = connect(s, (struct sockaddr *)&sin, sizeof(sin)); if (res == -1 && (errno == EINPROGRESS || errno == EALREADY)) { if (time (NULL) - t > 3) { @@ -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; @@ -879,7 +882,7 @@ static int mms_tcp_connect(mms_io_t *io, mms_t *this) { * try to connect */ lprintf("mms: trying to connect to %s on port %d\n", this->host, this->port); - this->s = io_connect(io, this->host, this->port); + this->s = io_connect(io, this->host, this->port, this->need_abort); if (this->s == -1) { lprintf("mms: failed to connect to %s\n", this->host); return 1; @@ -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..0606ac53 100644 --- a/plugins/mms/libmms/mmsh.c +++ b/plugins/mms/libmms/mmsh.c @@ -248,7 +248,7 @@ static off_t fallback_io_write(void *data, int socket, char *buf, off_t num) return (off_t)write(socket, buf, num); } -static int fallback_io_tcp_connect(void *data, const char *host, int port) +static int fallback_io_tcp_connect(void *data, const char *host, int port, int *need_abort) { struct hostent *h; @@ -822,7 +822,7 @@ static int mmsh_tcp_connect(mms_io_t *io, mmsh_t *this) { */ lprintf("mmsh: try to connect to %s on port %d \n", this->connect_host, this->connect_port); - this->s = io_connect (io, this->connect_host, this->connect_port); + this->s = io_connect (io, this->connect_host, this->connect_port, this->need_abort); if (this->s == -1) { lprintf("mmsh: failed to connect '%s'\n", this->connect_host); @@ -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/mmsio.h b/plugins/mms/libmms/mmsio.h index a1cb93bb..376e6736 100644 --- a/plugins/mms/libmms/mmsio.h +++ b/plugins/mms/libmms/mmsio.h @@ -66,7 +66,7 @@ typedef int (*mms_io_select_func)(void *data, int fd, int state, int timeout_mse * * returns a socket descriptor or -1 if an error occured */ -typedef int (*mms_io_tcp_connect_func)(void *data, const char *host, int port); +typedef int (*mms_io_tcp_connect_func)(void *data, const char *host, int port, int *need_abort); typedef struct { 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..cb339a96 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); } @@ -121,6 +156,7 @@ mms_is_streaming (void) { static void mms_abort (DB_FILE *fp) { + //fprintf (stderr, "\033[0;35mabort called\033[37;0m\n"); ((MMS_FILE *)fp)->need_abort = 1; } |