forked from len0rd/rockbox
puzzles: enable fallback to audiobuf when smalloc() fails
- upon a failed smalloc(), the audio buffer will be used for further allocations - should fix things on low-memory targets (c100 and c200v2), but breaks playback - playback should still be intact on other targets Change-Id: Ic239f1316efadc957050afacf5c614dbbca3f805
This commit is contained in:
parent
954d934ad2
commit
637c7414a9
2 changed files with 55 additions and 7 deletions
|
@ -14,12 +14,40 @@
|
||||||
int allocs = 0;
|
int allocs = 0;
|
||||||
int frees = 0;
|
int frees = 0;
|
||||||
|
|
||||||
|
bool audiobuf_available =
|
||||||
|
#ifndef COMBINED
|
||||||
|
true;
|
||||||
|
#else
|
||||||
|
false;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static bool grab_audiobuf(void)
|
||||||
|
{
|
||||||
|
if(!audiobuf_available)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if(rb->audio_status())
|
||||||
|
rb->audio_stop();
|
||||||
|
|
||||||
|
size_t sz, junk;
|
||||||
|
void *audiobuf = rb->plugin_get_audio_buffer(&sz);
|
||||||
|
extern char *giant_buffer;
|
||||||
|
|
||||||
|
add_new_area(audiobuf, sz, giant_buffer);
|
||||||
|
audiobuf_available = false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void *smalloc(size_t size) {
|
void *smalloc(size_t size) {
|
||||||
void *p;
|
void *p;
|
||||||
p = malloc(size);
|
p = malloc(size);
|
||||||
LOGF("allocs: %d", ++allocs);
|
LOGF("allocs: %d", ++allocs);
|
||||||
if (!p)
|
if (!p)
|
||||||
fatal("out of memory");
|
{
|
||||||
|
if(grab_audiobuf())
|
||||||
|
return smalloc(size);
|
||||||
|
fatal("out of memory");
|
||||||
|
}
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,7 +58,7 @@ void sfree(void *p) {
|
||||||
if (p) {
|
if (p) {
|
||||||
++frees;
|
++frees;
|
||||||
LOGF("frees: %d, total outstanding: %d", frees, allocs - frees);
|
LOGF("frees: %d, total outstanding: %d", frees, allocs - frees);
|
||||||
free(p);
|
free(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,7 +74,11 @@ void *srealloc(void *p, size_t size) {
|
||||||
q = malloc(size);
|
q = malloc(size);
|
||||||
}
|
}
|
||||||
if (!q)
|
if (!q)
|
||||||
fatal("out of memory");
|
{
|
||||||
|
if(grab_audiobuf())
|
||||||
|
return srealloc(p, size);
|
||||||
|
fatal("out of memory");
|
||||||
|
}
|
||||||
return q;
|
return q;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -71,6 +71,7 @@ static void fix_size(void);
|
||||||
|
|
||||||
static struct viewport clip_rect;
|
static struct viewport clip_rect;
|
||||||
static bool clipped = false;
|
static bool clipped = false;
|
||||||
|
extern bool audiobuf_available;
|
||||||
|
|
||||||
static struct settings_t {
|
static struct settings_t {
|
||||||
int slowmo_factor;
|
int slowmo_factor;
|
||||||
|
@ -1026,7 +1027,10 @@ static int pausemenu_cb(int action, const struct menu_item_ex *this_item)
|
||||||
* care, I bet */
|
* care, I bet */
|
||||||
return ACTION_EXIT_MENUITEM;
|
return ACTION_EXIT_MENUITEM;
|
||||||
#else
|
#else
|
||||||
break;
|
if(audiobuf_available)
|
||||||
|
break;
|
||||||
|
else
|
||||||
|
return ACTION_EXIT_MENUITEM;
|
||||||
#endif
|
#endif
|
||||||
case 9:
|
case 9:
|
||||||
if(!midend_num_presets(me))
|
if(!midend_num_presets(me))
|
||||||
|
@ -1355,10 +1359,10 @@ void deactivate_timer(frontend *fe)
|
||||||
|
|
||||||
#ifdef COMBINED
|
#ifdef COMBINED
|
||||||
/* can't use audio buffer */
|
/* can't use audio buffer */
|
||||||
static char giant_buffer[1024*1024*4];
|
char giant_buffer[1024*1024*4];
|
||||||
#else
|
#else
|
||||||
/* points to audiobuf */
|
/* points to pluginbuf */
|
||||||
static char *giant_buffer = NULL;
|
char *giant_buffer = NULL;
|
||||||
#endif
|
#endif
|
||||||
static size_t giant_buffer_len = 0; /* set on start */
|
static size_t giant_buffer_len = 0; /* set on start */
|
||||||
|
|
||||||
|
@ -1565,6 +1569,18 @@ static int mainmenu_cb(int action, const struct menu_item_ex *this_item)
|
||||||
return ACTION_EXIT_MENUITEM;
|
return ACTION_EXIT_MENUITEM;
|
||||||
#else
|
#else
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
|
case 4:
|
||||||
|
#ifdef COMBINED
|
||||||
|
/* audio buf is used, so no playback */
|
||||||
|
/* TODO: neglects app builds, but not many people will
|
||||||
|
* care, I bet */
|
||||||
|
return ACTION_EXIT_MENUITEM;
|
||||||
|
#else
|
||||||
|
if(audiobuf_available)
|
||||||
|
break;
|
||||||
|
else
|
||||||
|
return ACTION_EXIT_MENUITEM;
|
||||||
#endif
|
#endif
|
||||||
case 5:
|
case 5:
|
||||||
if(!midend_num_presets(me))
|
if(!midend_num_presets(me))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue