From 2d236e281f7fa0a2e1a065c8735d7dbb7ae407f9 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sat, 14 Nov 2009 01:51:01 +0100 Subject: decoder/mikmod: static mod_Data object Don't allocate this object, put it on the stack. --- src/decoder/mikmod_plugin.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'src/decoder/mikmod_plugin.c') diff --git a/src/decoder/mikmod_plugin.c b/src/decoder/mikmod_plugin.c index c01395772..9b331aa9e 100644 --- a/src/decoder/mikmod_plugin.c +++ b/src/decoder/mikmod_plugin.c @@ -131,48 +131,46 @@ typedef struct _mod_Data { SBYTE audio_buffer[MIKMOD_FRAME_SIZE]; } mod_Data; -static mod_Data *mod_open(const char *path) +static bool +mod_open(mod_Data *data, const char *path) { char *path2; MODULE *moduleHandle; - mod_Data *data; path2 = g_strdup(path); moduleHandle = Player_Load(path2, 128, 0); g_free(path2); if (moduleHandle == NULL) - return NULL; + return false; /* Prevent module from looping forever */ moduleHandle->loop = 0; - data = g_new(mod_Data, 1); data->moduleHandle = moduleHandle; Player_Start(data->moduleHandle); - return data; + return true; } static void mod_close(mod_Data * data) { Player_Stop(); Player_Free(data->moduleHandle); - g_free(data); } static void mod_decode(struct decoder *decoder, const char *path) { - mod_Data *data; + mod_Data data; struct audio_format audio_format; float total_time = 0.0; int ret; float secPerByte; enum decoder_command cmd = DECODE_COMMAND_NONE; - if (!(data = mod_open(path))) { + if (!mod_open(&data, path)) { g_warning("failed to open mod: %s\n", path); return; } @@ -187,14 +185,14 @@ mod_decode(struct decoder *decoder, const char *path) decoder_initialized(decoder, &audio_format, false, 0); while (cmd == DECODE_COMMAND_NONE && Player_Active()) { - ret = VC_WriteBytes(data->audio_buffer, MIKMOD_FRAME_SIZE); + ret = VC_WriteBytes(data.audio_buffer, MIKMOD_FRAME_SIZE); total_time += ret * secPerByte; cmd = decoder_data(decoder, NULL, - data->audio_buffer, ret, + data.audio_buffer, ret, total_time, 0, NULL); } - mod_close(data); + mod_close(&data); } static struct tag *modTagDup(const char *file) -- cgit v1.2.3