diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/input/input_http.c | 118 | ||||
-rw-r--r-- | src/input/input_net.c | 69 | ||||
-rw-r--r-- | src/input/mms.c | 73 | ||||
-rw-r--r-- | src/input/mmsh.c | 65 |
4 files changed, 123 insertions, 202 deletions
diff --git a/src/input/input_http.c b/src/input/input_http.c index 553000183..e67bc43ef 100644 --- a/src/input/input_http.c +++ b/src/input/input_http.c @@ -389,76 +389,71 @@ static off_t http_plugin_read (input_plugin_t *this_gen, http_input_plugin_t *this = (http_input_plugin_t *) this_gen; off_t n, num_bytes; - nbc_check_buffers (this->nbc); - num_bytes = 0; - while (num_bytes < nlen) { - - if (this->shoutcast_mode && (this->shoutcast_pos == this->shoutcast_metaint)) { - http_plugin_read_metainf(this_gen); - } + if (this->shoutcast_mode && (this->shoutcast_pos == this->shoutcast_metaint)) { + http_plugin_read_metainf(this_gen); + } - if (this->preview_pos < this->preview_size) { + if (this->preview_pos < this->preview_size) { - n = this->preview_size - this->preview_pos; - if (n > (nlen - num_bytes)) - n = nlen - num_bytes; + n = this->preview_size - this->preview_pos; + if (n > (nlen - num_bytes)) + n = nlen - num_bytes; #ifdef LOG - printf ("input_http: %lld bytes from preview (which has %lld bytes)\n", - n, this->preview_size); + printf ("input_http: %lld bytes from preview (which has %lld bytes)\n", + n, this->preview_size); #endif - if (this->shoutcast_mode) { - if ((this->shoutcast_pos + n) < this->shoutcast_metaint) { - memcpy (&buf[num_bytes], &this->preview[this->preview_pos], n); - this->shoutcast_pos += n; - } else { - n = this->shoutcast_metaint - this->shoutcast_pos; - memcpy (&buf[num_bytes], &this->preview[this->preview_pos], n); - this->shoutcast_pos += n; - } - } else { - memcpy (&buf[num_bytes], &this->preview[this->preview_pos], n); + if (this->shoutcast_mode) { + if ((this->shoutcast_pos + n) >= this->shoutcast_metaint) { + int i = this->shoutcast_metaint - this->shoutcast_pos; + memcpy (&buf[num_bytes], &this->preview[this->preview_pos], i); + this->shoutcast_pos += i; + this->preview_pos += i; + num_bytes += i; + this->curpos += i; + n -= i; + http_plugin_read_metainf(this_gen); } - this->preview_pos += n; - } else { - n = nlen - num_bytes; - if (this->shoutcast_mode) { - if ((this->shoutcast_pos + n) < this->shoutcast_metaint) { - n = read (this->fh, &buf[num_bytes], n); - this->shoutcast_pos += n; - } else { - n = this->shoutcast_metaint - this->shoutcast_pos; - n = read (this->fh, &buf[num_bytes], n); - this->shoutcast_pos += n; - } - } else { - n = read (this->fh, &buf[num_bytes], n); - } + this->shoutcast_pos += n; } - /* read errors */ - if (n < 0) { - if(errno == EAGAIN) { - fd_set rset; - struct timeval timeout; + memcpy (&buf[num_bytes], &this->preview[this->preview_pos], n); - FD_ZERO (&rset); - FD_SET (this->fh, &rset); + this->preview_pos += n; + num_bytes += n; + this->curpos += n; + } + + n = nlen - num_bytes; + if( n && this->shoutcast_mode) { + if ((this->shoutcast_pos + n) >= this->shoutcast_metaint) { + int i = this->shoutcast_metaint - this->shoutcast_pos; + i = xine_read_abort (this->stream, this->fh, &buf[num_bytes], i); + if (i < 0) { + xine_message(this->stream, XINE_MSG_READ_ERROR, NULL); + xine_log (this->stream->xine, XINE_LOG_MSG, _("input_http: read error %d\n"), errno); + return 0; + } - timeout.tv_sec = 30; - timeout.tv_usec = 0; + this->shoutcast_pos += i; + num_bytes += i; + this->curpos += i; + n -= i; + http_plugin_read_metainf(this_gen); + } - if (select (this->fh+1, &rset, NULL, NULL, &timeout) <= 0) { - xine_message(this->stream, XINE_MSG_READ_ERROR, "network timeout", NULL); - xine_log (this->stream->xine, XINE_LOG_MSG, _("input_http: timeout\n")); - return 0; - } - continue; - } + this->shoutcast_pos += n; + } + + if( n ) { + n = xine_read_abort (this->stream, this->fh, &buf[num_bytes], n); + + /* read errors */ + if (n < 0) { xine_message(this->stream, XINE_MSG_READ_ERROR, NULL); xine_log (this->stream->xine, XINE_LOG_MSG, _("input_http: read error %d\n"), errno); return 0; @@ -466,9 +461,6 @@ static off_t http_plugin_read (input_plugin_t *this_gen, num_bytes += n; this->curpos += n; - - /* end of stream */ - if (!n) break; } return num_bytes; @@ -592,10 +584,11 @@ static off_t http_plugin_seek(input_plugin_t *this_gen, off_t offset, int origin if ((origin == SEEK_CUR) && (offset >= 0)) { for (;((int)offset) - BUFSIZE > 0; offset -= BUFSIZE) { - http_plugin_read (this_gen, this->seek_buf, BUFSIZE); + if( !this_gen->read (this_gen, this->seek_buf, BUFSIZE) ) + return this->curpos; } - http_plugin_read (this_gen, this->seek_buf, offset); + this_gen->read (this_gen, this->seek_buf, offset); } if (origin == SEEK_SET) { @@ -606,10 +599,11 @@ static off_t http_plugin_seek(input_plugin_t *this_gen, off_t offset, int origin offset -= this->curpos; for (;((int)offset) - BUFSIZE > 0; offset -= BUFSIZE) { - http_plugin_read (this_gen, this->seek_buf, BUFSIZE); + if( !this_gen->read (this_gen, this->seek_buf, BUFSIZE) ) + return this->curpos; } - http_plugin_read (this_gen, this->seek_buf, offset); + this_gen->read (this_gen, this->seek_buf, offset); } } diff --git a/src/input/input_net.c b/src/input/input_net.c index ee457df0d..eebcf39b8 100644 --- a/src/input/input_net.c +++ b/src/input/input_net.c @@ -20,7 +20,7 @@ * Read from a tcp network stream over a lan (put a tweaked mp1e encoder the * other end and you can watch tv anywhere in the house ..) * - * $Id: input_net.c,v 1.43 2003/04/13 16:02:53 tmattern Exp $ + * $Id: input_net.c,v 1.44 2003/04/13 16:34:51 miguelfreitas Exp $ * * how to set up mp1e for use with this plugin: * @@ -171,38 +171,37 @@ static off_t net_plugin_read (input_plugin_t *this_gen, printf ("input_net: reading %d bytes...\n", len); #endif - nbc_check_buffers (this->nbc); - total=0; - while (total<len){ - - if (this->preview_pos < this->preview_size) { - n = this->preview_size - this->preview_pos; - if (n > (len - total)) - n = len - total; + if (this->preview_pos < this->preview_size) { + n = this->preview_size - this->preview_pos; + if (n > (len - total)) + n = len - total; #ifdef LOG - printf ("input_net: %lld bytes from preview (which has %lld bytes)\n", - n, this->preview_size); + printf ("input_net: %lld bytes from preview (which has %lld bytes)\n", + n, this->preview_size); #endif - memcpy (&buf[total], &this->preview[this->preview_pos], n); - this->preview_pos += n; - } else - { - n = read (this->fh, &buf[total], len-total); - } + memcpy (&buf[total], &this->preview[this->preview_pos], n); + this->preview_pos += n; + this->curpos += n; + total += n; + } + + if( (len-total) > 0 ) { + n = xine_read_abort (this->stream, this->fh, &buf[total], len-total); #ifdef LOG printf ("input_net: got %lld bytes (%lld/%lld bytes read)\n", n,total,len); #endif - if (n > 0){ - this->curpos += n; - total += n; + if (n < 0) { + xine_message(this->stream, XINE_MSG_READ_ERROR, NULL); + return 0; } - else if (n<0 && errno!=EAGAIN) - return total; + + this->curpos += n; + total += n; } return total; } @@ -255,18 +254,30 @@ static off_t net_plugin_get_current_pos (input_plugin_t *this_gen){ static off_t net_plugin_seek (input_plugin_t *this_gen, off_t offset, int origin) { net_input_plugin_t *this = (net_input_plugin_t *) this_gen; - printf ("input_net: seek %lld bytes, origin %d\n", - offset, origin); - - /* only relative forward-seeking is implemented */ - if ((origin == SEEK_CUR) && (offset >= 0)) { for (;((int)offset) - BUFSIZE > 0; offset -= BUFSIZE) { - this->curpos += net_plugin_read (this_gen, this->seek_buf, BUFSIZE); + if( !this_gen->read (this_gen, this->seek_buf, BUFSIZE) ) + return this->curpos; } - this->curpos += net_plugin_read (this_gen, this->seek_buf, offset); + this_gen->read (this_gen, this->seek_buf, offset); + } + + if (origin == SEEK_SET) { + + if (offset < this->curpos) + printf ("input_net: cannot seek back! (%lld > %lld)\n", this->curpos, offset); + else { + offset -= this->curpos; + + for (;((int)offset) - BUFSIZE > 0; offset -= BUFSIZE) { + if( !this_gen->read (this_gen, this->seek_buf, BUFSIZE) ) + return this->curpos; + } + + this_gen->read (this_gen, this->seek_buf, offset); + } } return this->curpos; diff --git a/src/input/mms.c b/src/input/mms.c index abc48ef0a..db549948b 100644 --- a/src/input/mms.c +++ b/src/input/mms.c @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * - * $Id: mms.c,v 1.22 2003/02/28 02:51:48 storri Exp $ + * $Id: mms.c,v 1.23 2003/04/13 16:34:51 miguelfreitas Exp $ * * based on work from major mms * utility functions to handle communication with an mms server @@ -65,6 +65,8 @@ struct mms_s { + xine_stream_t *stream; + int s; char *host; @@ -101,50 +103,6 @@ struct mms_s { int has_video; }; -/* network/socket utility functions */ - -static ssize_t read_timeout(int fd, void *buf, size_t count) { - - ssize_t ret, total; - - total = 0; - - while (total < count) { - - ret=read (fd, ((uint8_t*)buf)+total, count-total); - - if (ret<0) { - if(errno == EAGAIN) { - fd_set rset; - struct timeval timeout; - - FD_ZERO (&rset); - FD_SET (fd, &rset); - - timeout.tv_sec = 30; - timeout.tv_usec = 0; - - if (select (fd+1, &rset, NULL, NULL, &timeout) <= 0) { - return -1; - } - continue; - } - - printf ("mms: read error.\n"); - return ret; - } else - total += ret; - - /* end of stream */ - if (!ret) break; - } - -#ifdef LOG - printf ("mms: read completed %d/%d\n", total, count); -#endif - - return total; -} static int host_connect_attempt(struct in_addr ia, int port) { @@ -425,7 +383,7 @@ static int get_answer (mms_t *this) { while (command == 0x1b) { int len, length; - len = read_timeout (this->s, this->buf, 12); + len = xine_read_abort (this->stream, this->s, this->buf, 12); if (len != 12) { printf ("\nalert! eof\n"); return 0; @@ -437,7 +395,7 @@ static int get_answer (mms_t *this) { printf ("\n\npacket length: %d\n", length); #endif - len = read_timeout (this->s, this->buf+12, length+4) ; + len = xine_read_abort (this->stream, this->s, this->buf+12, length+4) ; if (len<=0) { printf ("alert! eof\n"); return 0; @@ -456,11 +414,11 @@ static int get_answer (mms_t *this) { return 1; } -static int receive (int s, char *buf, size_t count) { +static int receive (xine_stream_t *stream, int s, char *buf, size_t count) { ssize_t len; - len = read_timeout (s, buf, count); + len = xine_read_abort (stream, s, buf, count); if (len < 0) { perror ("read error:"); return 0; @@ -477,7 +435,7 @@ static int get_header (mms_t *this) { while (1) { - if (!receive (this->s, pre_header, 8)) { + if (!receive (this->stream, this->s, pre_header, 8)) { printf ("libmms: pre-header read failed\n"); return 0; } @@ -502,7 +460,7 @@ static int get_header (mms_t *this) { packet_len); #endif - if (!receive (this->s, &this->asf_header[this->asf_header_len], packet_len)) { + if (!receive (this->stream, this->s, &this->asf_header[this->asf_header_len], packet_len)) { printf ("libmms: header data read failed\n"); return 0; } @@ -524,7 +482,7 @@ static int get_header (mms_t *this) { int packet_len, command; - if (!receive (this->s, (char *) &packet_len, 4)) { + if (!receive (this->stream, this->s, (char *) &packet_len, 4)) { printf ("packet_len read failed\n"); return 0; } @@ -536,7 +494,7 @@ static int get_header (mms_t *this) { packet_len); #endif - if (!receive (this->s, this->buf, packet_len)) { + if (!receive (this->stream, this->s, this->buf, packet_len)) { printf ("command data read failed\n"); return 0 ; } @@ -832,6 +790,7 @@ mms_t *mms_connect (xine_stream_t *stream, const char *url_, int bandwidth) { this = (mms_t*) xine_xmalloc (sizeof (mms_t)); + this->stream = stream; this->url = url; this->host = host; this->path = path; @@ -1049,7 +1008,7 @@ mms_t *mms_connect (xine_stream_t *stream, const char *url_, int bandwidth) { static int get_media_packet (mms_t *this) { unsigned char pre_header[8]; - if (!receive (this->s, pre_header, 8)) { + if (!receive (this->stream, this->s, pre_header, 8)) { printf ("pre-header read failed\n"); return 0; } @@ -1074,7 +1033,7 @@ static int get_media_packet (mms_t *this) { packet_len); #endif - if (!receive (this->s, this->buf, packet_len)) { + if (!receive (this->stream, this->s, this->buf, packet_len)) { printf ("media data read failed\n"); return 0; } @@ -1087,7 +1046,7 @@ static int get_media_packet (mms_t *this) { int packet_len, command; - if (!receive (this->s, (char *)&packet_len, 4)) { + if (!receive (this->stream, this->s, (char *)&packet_len, 4)) { printf ("packet_len read failed\n"); return 0; } @@ -1099,7 +1058,7 @@ static int get_media_packet (mms_t *this) { packet_len); #endif - if (!receive (this->s, this->buf, packet_len)) { + if (!receive (this->stream, this->s, this->buf, packet_len)) { printf ("command data read failed\n"); return 0; } diff --git a/src/input/mmsh.c b/src/input/mmsh.c index 2268292e0..0a9f6a8a6 100644 --- a/src/input/mmsh.c +++ b/src/input/mmsh.c @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * - * $Id: mmsh.c,v 1.13 2003/02/28 02:51:48 storri Exp $ + * $Id: mmsh.c,v 1.14 2003/04/13 16:34:51 miguelfreitas Exp $ * * based on mms.c and specs from avifile * (http://avifile.sourceforge.net/asf-1.0.htm) @@ -129,6 +129,8 @@ static const char* mmsh_RangeRequest = struct mmsh_s { + xine_stream_t *stream; + int s; char *host; @@ -169,52 +171,6 @@ struct mmsh_s { int has_video; }; -/* network/socket utility functions */ - -static ssize_t read_timeout(int fd, void *buf, size_t count) { - - ssize_t ret, total; - - total = 0; - - while (total < count) { - - ret=read (fd, ((uint8_t*)buf)+total, count-total); - - if (ret<0) { - if(errno == EAGAIN) { - fd_set rset; - struct timeval timeout; - - FD_ZERO (&rset); - FD_SET (fd, &rset); - - timeout.tv_sec = 30; - timeout.tv_usec = 0; - - if (select (fd+1, &rset, NULL, NULL, &timeout) <= 0) { - return -1; - } - continue; - } - -#ifdef LOG - printf ("libmmsh: read error.\n"); -#endif - return ret; - } else - total += ret; - - /* end of stream */ - if (!ret) break; - } - -#ifdef LOG - /* printf ("libmmsh: read completed %d/%d\n", total, count); */ -#endif - - return total; -} static int host_connect_attempt(struct in_addr ia, int port) { @@ -379,7 +335,7 @@ static int get_answer (mmsh_t *this) { while (!done) { - if (read_timeout (this->s, &(this->buf[len]), 1) <= 0) { + if (xine_read_abort (this->stream, this->s, &(this->buf[len]), 1) <= 0) { printf ("libmmsh: alert: end of stream\n"); return 0; } @@ -456,11 +412,11 @@ static int get_answer (mmsh_t *this) { return 1; } -static int receive (int s, char *buf, size_t count) { +static int receive (xine_stream_t *stream, int s, char *buf, size_t count) { ssize_t len; - len = read_timeout (s, buf, count); + len = xine_read_abort (stream, s, buf, count); if (len < 0) { perror ("libmmsh: read error:"); return 0; @@ -477,7 +433,7 @@ static int get_chunk_header (mmsh_t *this) { printf ("libmmsh: get_chunk\n"); #endif /* chunk header */ - len = receive (this->s, chunk_header, CHUNK_HEADER_LENGTH); + len = receive (this->stream, this->s, chunk_header, CHUNK_HEADER_LENGTH); if (len != CHUNK_HEADER_LENGTH) { printf ("libmmsh: chunk header read failed\n"); return 0; @@ -519,7 +475,7 @@ static int get_header (mmsh_t *this) { printf ("libmmsh: the asf header exceed %d bytes\n", ASF_HEADER_SIZE); return 0; } else { - len = read_timeout (this->s, this->asf_header + this->asf_header_len, + len = xine_read_abort (this->stream, this->s, this->asf_header + this->asf_header_len, this->chunk_length); this->asf_header_len += len; if (len != this->chunk_length) { @@ -535,7 +491,7 @@ static int get_header (mmsh_t *this) { } /* read the first data chunk */ - len = read_timeout (this->s, this->buf, this->chunk_length); + len = xine_read_abort (this->stream, this->s, this->buf, this->chunk_length); if (len != this->chunk_length) { return 0; } else { @@ -807,6 +763,7 @@ mmsh_t *mmsh_connect (xine_stream_t *stream, const char *url_, int bandwidth) { this = (mmsh_t*) xine_xmalloc (sizeof (mmsh_t)); + this->stream = stream; this->url = url; this->host = host; this->path = path; @@ -1012,7 +969,7 @@ static int get_media_packet (mmsh_t *this) { printf("libmmsh: invalid chunk length\n"); return 0; } else { - len = read_timeout (this->s, this->buf, this->chunk_length); + len = xine_read_abort (this->stream, this->s, this->buf, this->chunk_length); if (len == this->chunk_length) { /* explicit padding with 0 */ |