From: Miguel F. <mig...@us...> - 2001-09-10 00:47:41
|
Update of /cvsroot/xine/xine-lib/src/input In directory usw-pr-cvs1:/tmp/cvs-serv6773/src/input Modified Files: input_dvd.c input_file.c Log Message: better responsiveness by providing pthread cancellation point inside block read (dvd and file inputs). Index: input_dvd.c =================================================================== RCS file: /cvsroot/xine/xine-lib/src/input/input_dvd.c,v retrieving revision 1.21 retrieving revision 1.22 diff -u -r1.21 -r1.22 --- input_dvd.c 2001/09/08 00:44:40 1.21 +++ input_dvd.c 2001/09/10 00:47:37 1.22 @@ -1,4 +1,4 @@ -/* +/* * Copyright (C) 2000-2001 the xine project * * This file is part of xine, a unix video player. @@ -7,7 +7,7 @@ * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. - * + * * xine is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the @@ -214,7 +214,7 @@ dvd_input_plugin_t *this = (dvd_input_plugin_t *) this_gen; if (nlen != DVD_VIDEO_LB_LEN) { - /* + /* * Hide the error reporting now, demuxer try to read 6 bytes * at STAGE_BY_CONTENT probe stage */ @@ -222,7 +222,7 @@ "is not a sector!\n", nlen); return 0; } - + if (this->file_size_left < nlen) return 0; @@ -239,41 +239,57 @@ } /* + * helper function to release buffer + * in case demux thread is cancelled + */ +static void pool_release_buffer (void *arg) { + buf_element_t *buf = (buf_element_t *) arg; + if( buf != NULL ) + buf->free_buffer(buf); +} + + +/* * */ -static buf_element_t *dvd_plugin_read_block (input_plugin_t *this_gen, +static buf_element_t *dvd_plugin_read_block (input_plugin_t *this_gen, fifo_buffer_t *fifo, off_t nlen) { dvd_input_plugin_t *this = (dvd_input_plugin_t *) this_gen; - buf_element_t *buf = fifo->buffer_pool_alloc (fifo); + buf_element_t *buf; - if (nlen != DVD_VIDEO_LB_LEN) { - /* + if (nlen != DVD_VIDEO_LB_LEN || this->file_size_left < nlen) { + /* * Hide the error reporting now, demuxer try to read 6 bytes * at STAGE_BY_CONTENT probe stage */ - fprintf (stderr, "ERROR in input_dvd plugin read: %Ld bytes " + if(nlen != DVD_VIDEO_LB_LEN) + fprintf (stderr, "ERROR in input_dvd plugin read: %Ld bytes " "is not a sector!\n", nlen); - goto read_block_failure; + return NULL; } - if (this->file_size_left < nlen) - goto read_block_failure; + buf = fifo->buffer_pool_alloc (fifo); + pthread_setcancelstate(PTHREAD_CANCEL_ENABLE,NULL); + pthread_cleanup_push( pool_release_buffer, buf ); + buf->content = buf->mem; - if ((buf->size = read (this->raw_fd, buf->mem, DVD_VIDEO_LB_LEN)) > 0) { + pthread_testcancel(); + if ((buf->size = dvd_plugin_read (this_gen, buf->mem, DVD_VIDEO_LB_LEN)) > 0) { this->file_lbcur++; this->file_size_left -= DVD_VIDEO_LB_LEN; buf->type = BUF_DEMUX_BLOCK; - return buf; - } else + } else { + buf->free_buffer (buf); + buf = NULL; fprintf (stderr, "read error in input_dvd plugin\n"); + } - read_block_failure: + pthread_setcancelstate(PTHREAD_CANCEL_DISABLE,NULL); + pthread_cleanup_pop(0); - buf->free_buffer (buf); - - return NULL; + return buf; } /* @@ -298,7 +314,7 @@ this->file_size_left = this->file_size - ((this->file_lbcur - this->file_lbstart) * DVD_VIDEO_LB_LEN); } else { - return (this->file_lbcur - this->file_lbstart) * + return (this->file_lbcur - this->file_lbstart) * (off_t) DVD_VIDEO_LB_LEN; } @@ -455,7 +471,7 @@ if (nLen<4) continue; - + if (!strcasecmp (&this->filelist[i][nLen-4], ".VOB")) { char str[1024]; @@ -472,7 +488,7 @@ realloc(this->mrls[nFiles2]->mrl, strlen(this->filelist[i]) + 7); } else { - this->mrls[nFiles2]->mrl = (char *) + this->mrls[nFiles2]->mrl = (char *) xmalloc(strlen(this->filelist[i]) + 7); } @@ -542,7 +558,7 @@ if (nLen<4) continue; - + if (!strcasecmp (&this->filelist[i][nLen-4], ".VOB")) { sprintf (this->filelist2[nFiles2], "dvd://%s", this->filelist[i]); Index: input_file.c =================================================================== RCS file: /cvsroot/xine/xine-lib/src/input/input_file.c,v retrieving revision 1.22 retrieving revision 1.23 diff -u -r1.22 -r1.23 --- input_file.c 2001/09/08 00:44:40 1.22 +++ input_file.c 2001/09/10 00:47:37 1.23 @@ -1,4 +1,4 @@ -/* +/* * Copyright (C) 2000 the xine project * * This file is part of xine, a unix video player. @@ -176,7 +176,7 @@ int mode; uint32_t file_type = 0; char buf[PATH_MAX + NAME_MAX + 1]; - + if((lstat(filepathname, &pstat)) < 0) { sprintf(buf, "%s/%s", origin, filepathname); if((lstat(buf, &pstat)) < 0) { @@ -278,6 +278,16 @@ } /* + * helper function to release buffer + * in case demux thread is cancelled + */ +static void pool_release_buffer (void *arg) { + buf_element_t *buf = (buf_element_t *) arg; + if( buf != NULL ) + buf->free_buffer(buf); +} + +/* * */ static buf_element_t *file_plugin_read_block (input_plugin_t *this_gen, fifo_buffer_t *fifo, off_t todo) { @@ -286,20 +296,29 @@ file_input_plugin_t *this = (file_input_plugin_t *) this_gen; buf_element_t *buf = fifo->buffer_pool_alloc (fifo); + pthread_setcancelstate(PTHREAD_CANCEL_ENABLE,NULL); + pthread_cleanup_push( pool_release_buffer, buf ); + buf->content = buf->mem; buf->type = BUF_DEMUX_BLOCK; total_bytes = 0; while (total_bytes < todo) { + pthread_testcancel(); num_bytes = read (this->fh, buf->mem + total_bytes, todo-total_bytes); total_bytes += num_bytes; if (!num_bytes) { buf->free_buffer (buf); - return NULL; + buf = NULL; + break; } } + + if( buf != NULL ) + buf->size = total_bytes; - buf->size = total_bytes; + pthread_setcancelstate(PTHREAD_CANCEL_DISABLE,NULL); + pthread_cleanup_pop(0); return buf; } @@ -381,7 +400,7 @@ */ if(!filename) { char *pwd; - + if((pwd = getenv("PWD")) == NULL) snprintf(current_dir, 1, "%s", "."); else @@ -396,7 +415,7 @@ snprintf(current_dir, PATH_MAX, "%s", filename); } - + if(strcasecmp(current_dir, "/")) sprintf(current_dir_slashed, "%s/", current_dir); else |