summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/playlist.c39
1 files changed, 31 insertions, 8 deletions
diff --git a/apps/playlist.c b/apps/playlist.c
index b721a82093..f3a7bd2c9f 100644
--- a/apps/playlist.c
+++ b/apps/playlist.c
@@ -124,8 +124,8 @@
124//NOTEF 124//NOTEF
125#endif 125#endif
126 126
127 127/* default load buffer size (should be at least 1 KiB) */
128 128#define PLAYLIST_LOAD_BUFLEN (32*1024)
129 129
130 130
131#define PLAYLIST_CONTROL_FILE_VERSION 2 131#define PLAYLIST_CONTROL_FILE_VERSION 2
@@ -1999,6 +1999,23 @@ static int rotate_index(const struct playlist_info* playlist, int index)
1999} 1999}
2000 2000
2001/* 2001/*
2002 * Allocate a temporary buffer for loading playlists
2003 */
2004static int alloc_tempbuf(size_t* buflen)
2005{
2006 /* request a reasonable size first */
2007 int handle = core_alloc_ex(NULL, PLAYLIST_LOAD_BUFLEN, &buflib_ops_locked);
2008 if (handle > 0)
2009 {
2010 *buflen = PLAYLIST_LOAD_BUFLEN;
2011 return handle;
2012 }
2013
2014 /* otherwise, try being unreasonable */
2015 return core_alloc_maximum(NULL, buflen, &buflib_ops_locked);
2016}
2017
2018/*
2002 * Need no movement protection since all 3 allocations are not passed to 2019 * Need no movement protection since all 3 allocations are not passed to
2003 * other functions which can yield(). 2020 * other functions which can yield().
2004 */ 2021 */
@@ -2097,14 +2114,17 @@ int playlist_create(const char *dir, const char *file)
2097 2114
2098 if (file) 2115 if (file)
2099 { 2116 {
2100 int handle;
2101 size_t buflen; 2117 size_t buflen;
2102 /* use mp3 buffer for maximum load speed */ 2118 int handle = alloc_tempbuf(&buflen);
2103 handle = core_alloc_maximum("temp", &buflen, &buflib_ops_locked);
2104 if (handle > 0) 2119 if (handle > 0)
2105 { 2120 {
2121 /* align for faster load times */
2122 void* buf = core_get_data(handle);
2123 STORAGE_ALIGN_BUFFER(buf, buflen);
2124 buflen = ALIGN_DOWN(buflen, 512); /* to avoid partial sector I/O */
2125
2106 /* load the playlist file */ 2126 /* load the playlist file */
2107 add_indices_to_playlist(playlist, core_get_data(handle), buflen); 2127 add_indices_to_playlist(playlist, buf, buflen);
2108 core_free(handle); 2128 core_free(handle);
2109 } 2129 }
2110 else 2130 else
@@ -2145,14 +2165,17 @@ int playlist_resume(void)
2145 dircache_wait(); /* we need the dircache to use the files in the playlist */ 2165 dircache_wait(); /* we need the dircache to use the files in the playlist */
2146#endif 2166#endif
2147 2167
2148 /* use mp3 buffer for maximum load speed */ 2168 handle = alloc_tempbuf(&buflen);
2149 handle = core_alloc_maximum("temp", &buflen, &buflib_ops_locked);
2150 if (handle < 0) 2169 if (handle < 0)
2151 { 2170 {
2152 splashf(HZ * 2, "%s(): OOM", __func__); 2171 splashf(HZ * 2, "%s(): OOM", __func__);
2153 return -1; 2172 return -1;
2154 } 2173 }
2174
2175 /* align buffer for faster load times */
2155 buffer = core_get_data(handle); 2176 buffer = core_get_data(handle);
2177 STORAGE_ALIGN_BUFFER(buffer, buflen);
2178 buflen = ALIGN_DOWN(buflen, 512); /* to avoid partial sector I/O */
2156 2179
2157 playlist_shutdown(); /* flush any cached control commands to disk */ 2180 playlist_shutdown(); /* flush any cached control commands to disk */
2158 empty_playlist(playlist, true); 2181 empty_playlist(playlist, true);