Commit fee7a101 authored by Laurent Aimar's avatar Laurent Aimar Committed by Jean-Baptiste Kempf

Load files to memory when needed for loading GME files.

It happens when the size information is missing.
It closes #5766.
(cherry picked from commit 5e0e7978)
Signed-off-by: default avatarJean-Baptiste Kempf <jb@videolan.org>
parent 025280c1
......@@ -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)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment