[vlc-commits] Load files to memory when needed for loading GME files.
Laurent Aimar
git at videolan.org
Sat Jan 7 01:22:24 CET 2012
vlc | branch: master | Laurent Aimar <fenrir at videolan.org> | Sat Jan 7 01:15:42 2012 +0100| [5e0e7978ffa0ad34c780c08caf518efcc4082127] | committer: Laurent Aimar
Load files to memory when needed for loading GME files.
It happens when the size information is missing.
It closes #5766.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=5e0e7978ffa0ad34c780c08caf518efcc4082127
---
modules/demux/gme.c | 33 ++++++++++++++++++++++++++++-----
1 files changed, 28 insertions(+), 5 deletions(-)
diff --git a/modules/demux/gme.c b/modules/demux/gme.c
index 5d6d214..64f04e0 100644
--- a/modules/demux/gme.c
+++ b/modules/demux/gme.c
@@ -64,15 +64,15 @@ struct demux_sys_t
static int Demux (demux_t *);
static int Control (demux_t *, int, va_list);
-static gme_err_t Reader (void *, void *, int);
+static gme_err_t ReaderStream (void *, void *, int);
+static gme_err_t ReaderBlock (void *, void *, int);
static int Open (vlc_object_t *obj)
{
demux_t *demux = (demux_t *)obj;
int64_t size = stream_Size (demux->s);
- if (size < 4 /* GME needs to know the file size */
- || size > LONG_MAX /* too big for GME */)
+ if (size > LONG_MAX /* too big for GME */)
return VLC_EGENERIC;
/* Auto detection */
@@ -85,6 +85,14 @@ static int Open (vlc_object_t *obj)
return VLC_EGENERIC;
msg_Dbg (obj, "detected file type %s", type);
+ block_t *data = NULL;
+ if (size <= 0)
+ {
+ data = stream_BlockRemaining (demux->s, 100000000);
+ if (!data )
+ return VLC_EGENERIC;
+ }
+
/* Initialization */
demux_sys_t *sys = malloc (sizeof (*sys));
if (unlikely(sys == NULL))
@@ -96,7 +104,11 @@ static int Open (vlc_object_t *obj)
free (sys);
return VLC_ENOMEM;
}
- gme_load_custom (sys->emu, Reader, size, demux->s);
+ if (data)
+ gme_load_custom (sys->emu, ReaderBlock, data->i_buffer, data);
+ else
+ gme_load_custom (sys->emu, ReaderStream, size, demux->s);
+ block_Release(data);
gme_start_track (sys->emu, sys->track_id = 0);
es_format_t fmt;
@@ -158,7 +170,7 @@ static void Close (vlc_object_t *obj)
}
-static gme_err_t Reader (void *data, void *buf, int length)
+static gme_err_t ReaderStream (void *data, void *buf, int length)
{
stream_t *s = data;
@@ -166,7 +178,18 @@ static gme_err_t Reader (void *data, void *buf, int length)
return "short read";
return NULL;
}
+static gme_err_t ReaderBlock (void *data, void *buf, int length)
+{
+ block_t *block = data;
+ int max = __MIN (length, (int)block->i_buffer);
+ memcpy (buf, block->p_buffer, max);
+ block->i_buffer -= max;
+ block->p_buffer += max;
+ if (max != length)
+ return "short read";
+ return NULL;
+}
#define SAMPLES (RATE / 10)
More information about the vlc-commits
mailing list