summaryrefslogtreecommitdiff
path: root/src/input/input_pnm.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/input/input_pnm.c')
-rw-r--r--src/input/input_pnm.c64
1 files changed, 38 insertions, 26 deletions
diff --git a/src/input/input_pnm.c b/src/input/input_pnm.c
index 680c5b1e8..6d9809a6a 100644
--- a/src/input/input_pnm.c
+++ b/src/input/input_pnm.c
@@ -1,18 +1,18 @@
/*
* Copyright (C) 2002-2003 the xine project
- *
+ *
* This file is part of xine, a free video player.
- *
+ *
* xine is free software; you can redistribute it and/or modify
* 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
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
@@ -61,36 +61,35 @@ typedef struct {
input_plugin_t input_plugin;
xine_stream_t *stream;
-
+
pnm_t *pnm;
char *mrl;
off_t curpos;
- nbc_t *nbc;
+ nbc_t *nbc;
char scratch[BUFSIZE];
} pnm_input_plugin_t;
-static off_t pnm_plugin_read (input_plugin_t *this_gen,
+static off_t pnm_plugin_read (input_plugin_t *this_gen,
char *buf, off_t len) {
pnm_input_plugin_t *this = (pnm_input_plugin_t *) this_gen;
off_t n;
lprintf ("pnm_plugin_read: %"PRId64" bytes ...\n", len);
- nbc_check_buffers (this->nbc);
-
n = pnm_read (this->pnm, buf, len);
- this->curpos += n;
+ if (n >= 0)
+ this->curpos += n;
return n;
}
-static buf_element_t *pnm_plugin_read_block (input_plugin_t *this_gen,
+static buf_element_t *pnm_plugin_read_block (input_plugin_t *this_gen,
fifo_buffer_t *fifo, off_t todo) {
/*pnm_input_plugin_t *this = (pnm_input_plugin_t *) this_gen; */
buf_element_t *buf = fifo->buffer_pool_alloc (fifo);
@@ -98,9 +97,16 @@ static buf_element_t *pnm_plugin_read_block (input_plugin_t *this_gen,
lprintf ("pnm_plugin_read_block: %"PRId64" bytes...\n", todo);
+ if (todo > buf->max_size)
+ todo = buf->max_size;
+ if (todo < 0) {
+ buf->free_buffer (buf);
+ return NULL;
+ }
+
buf->content = buf->mem;
buf->type = BUF_DEMUX_BLOCK;
-
+
total_bytes = pnm_plugin_read (this_gen, (char*)buf->content, todo);
if (total_bytes != todo) {
@@ -125,10 +131,16 @@ static off_t pnm_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) {
- this->curpos += pnm_plugin_read (this_gen, this->scratch, BUFSIZE);
+ off_t n = pnm_plugin_read (this_gen, this->scratch, BUFSIZE);
+ if (n <= 0)
+ return this->curpos;
+ this->curpos += n;
}
- this->curpos += pnm_plugin_read (this_gen, this->scratch, offset);
+ off_t n = pnm_plugin_read (this_gen, this->scratch, offset);
+ if (n <= 0)
+ return this->curpos;
+ this->curpos += n;
}
return this->curpos;
@@ -137,7 +149,7 @@ static off_t pnm_plugin_seek (input_plugin_t *this_gen, off_t offset, int origin
static off_t pnm_plugin_get_length (input_plugin_t *this_gen) {
/*
- pnm_input_plugin_t *this = (pnm_input_plugin_t *) this_gen;
+ pnm_input_plugin_t *this = (pnm_input_plugin_t *) this_gen;
off_t length;
*/
@@ -174,10 +186,10 @@ static void pnm_plugin_dispose (input_plugin_t *this_gen) {
nbc_close (this->nbc);
this->nbc = NULL;
}
-
+
if(this->mrl)
free(this->mrl);
-
+
free (this);
}
@@ -187,7 +199,7 @@ static const char* pnm_plugin_get_mrl (input_plugin_t *this_gen) {
return this->mrl;
}
-static int pnm_plugin_get_optional_data (input_plugin_t *this_gen,
+static int pnm_plugin_get_optional_data (input_plugin_t *this_gen,
void *data, int data_type) {
pnm_input_plugin_t *this = (pnm_input_plugin_t *) this_gen;
@@ -215,11 +227,11 @@ static int pnm_plugin_open (input_plugin_t *this_gen) {
}
this->pnm = pnm;
-
+
return 1;
}
-static input_plugin_t *pnm_class_get_instance (input_class_t *cls_gen, xine_stream_t *stream,
+static input_plugin_t *pnm_class_get_instance (input_class_t *cls_gen, xine_stream_t *stream,
const char *data) {
/* pnm_input_class_t *cls = (pnm_input_class_t *) cls_gen; */
@@ -231,13 +243,13 @@ static input_plugin_t *pnm_class_get_instance (input_class_t *cls_gen, xine_stre
return NULL;
}
- this = (pnm_input_plugin_t *) xine_xmalloc (sizeof (pnm_input_plugin_t));
+ this = calloc(1, sizeof (pnm_input_plugin_t));
this->stream = stream;
this->pnm = NULL;
- this->mrl = mrl;
+ this->mrl = mrl;
this->nbc = nbc_init (this->stream);
-
+
this->input_plugin.open = pnm_plugin_open;
this->input_plugin.get_capabilities = pnm_plugin_get_capabilities;
this->input_plugin.read = pnm_plugin_read;
@@ -250,7 +262,7 @@ static input_plugin_t *pnm_class_get_instance (input_class_t *cls_gen, xine_stre
this->input_plugin.dispose = pnm_plugin_dispose;
this->input_plugin.get_optional_data = pnm_plugin_get_optional_data;
this->input_plugin.input_class = cls_gen;
-
+
return &this->input_plugin;
}
@@ -276,7 +288,7 @@ static void *init_class (xine_t *xine, void *data) {
pnm_input_class_t *this;
- this = (pnm_input_class_t *) xine_xmalloc (sizeof (pnm_input_class_t));
+ this = calloc(1, sizeof (pnm_input_class_t));
this->xine = xine;
@@ -296,7 +308,7 @@ static void *init_class (xine_t *xine, void *data) {
*/
const plugin_info_t xine_plugin_info[] EXPORTED = {
- /* type, API, "name", version, special_info, init_function */
+ /* type, API, "name", version, special_info, init_function */
{ PLUGIN_INPUT, 17, "pnm", XINE_VERSION_CODE, NULL, init_class },
{ PLUGIN_NONE, 0, "", 0, NULL, NULL }
};