summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorWilliam Wilgus <wilgus.william@gmail.com>2023-01-12 08:09:47 -0500
committerWilliam Wilgus <me.theuser@yahoo.com>2023-01-12 19:36:38 -0500
commit2d9cb673e58a0b3cc2a94884983ac689ed68ebee (patch)
treebbf776331a6a7dc035da50fb2c969959596da856 /apps
parent00c7817c9c326368c2cd89f1e786584283935c9c (diff)
downloadrockbox-2d9cb673e58a0b3cc2a94884983ac689ed68ebee.tar.gz
rockbox-2d9cb673e58a0b3cc2a94884983ac689ed68ebee.zip
add chunk_alloc to playlist.c #2
dc_thread_playlist was asking for invalid indices since previously the name buffer would have been valid it just got whatever junk data was left over add dc_discard_playlist_pointers for HAVE_DIRCACHE targets this allows the dc_playlist_thread to stop its current lookup loop Change-Id: I6f25b97b8c4e314d27c5e1e6ff0925b5a3e93f26
Diffstat (limited to 'apps')
-rw-r--r--apps/playlist.c84
-rw-r--r--apps/playlist.h9
2 files changed, 54 insertions, 39 deletions
diff --git a/apps/playlist.c b/apps/playlist.c
index f3f084b702..25bd60dd2a 100644
--- a/apps/playlist.c
+++ b/apps/playlist.c
@@ -520,10 +520,8 @@ static void empty_playlist_unlocked(struct playlist_info* playlist, bool resume)
520 520
521 playlist->filename[0] = '\0'; 521 playlist->filename[0] = '\0';
522 522
523 if (playlist->buffer) 523 chunk_alloc_free(&playlist->name_chunk_buffer);
524 playlist->buffer[0] = 0;
525 524
526 playlist->buffer_end_pos = 0;
527 playlist->seed = 0; 525 playlist->seed = 0;
528 playlist->num_cached = 0; 526 playlist->num_cached = 0;
529 527
@@ -1196,12 +1194,18 @@ static int get_track_filename(struct playlist_info* playlist, int index, int see
1196 { 1194 {
1197 max = dircache_get_fileref_path(&playlist->dcfrefs[index], 1195 max = dircache_get_fileref_path(&playlist->dcfrefs[index],
1198 tmp_buf, sizeof(tmp_buf)); 1196 tmp_buf, sizeof(tmp_buf));
1197
1198 NOTEF("%s [in DCache]: 0x%x %s", __func__,
1199 playlist->dcfrefs[index], tmp_buf);
1199 } 1200 }
1200#endif /* HAVE_DIRCACHE */ 1201#endif /* HAVE_DIRCACHE */
1201 1202
1202 if (playlist->in_ram && !control_file && max < 0) 1203 if (playlist->in_ram && !control_file && max < 0)
1203 { 1204 {
1204 strmemccpy(tmp_buf, (char*)&playlist->buffer[seek], sizeof(tmp_buf)); 1205 char *namebuf = chunk_get_data(&playlist->name_chunk_buffer, seek);
1206 strmemccpy(tmp_buf, namebuf, sizeof(tmp_buf));
1207 chunk_put_data(&playlist->name_chunk_buffer, seek);
1208 NOTEF("%s [in Ram]: 0x%x %s", __func__, seek, tmp_buf);
1205 } 1209 }
1206 else if (max < 0) 1210 else if (max < 0)
1207 { 1211 {
@@ -1239,6 +1243,8 @@ static int get_track_filename(struct playlist_info* playlist, int index, int see
1239 if (!utf8) 1243 if (!utf8)
1240 max = convert_m3u_name(tmp_buf, max, 1244 max = convert_m3u_name(tmp_buf, max,
1241 sizeof(tmp_buf), dir_buf); 1245 sizeof(tmp_buf), dir_buf);
1246
1247 NOTEF("%s [in File]: 0x%x %s", __func__, seek, tmp_buf);
1242 } 1248 }
1243 } 1249 }
1244 } 1250 }
@@ -1990,6 +1996,25 @@ static void dc_thread_playlist(void)
1990#endif 1996#endif
1991 1997
1992/* 1998/*
1999 * Allocate name chunk buffer header for in-ram playlists
2000 */
2001static void alloc_namebuffer(void)
2002{
2003#if MEMORYSIZE >= 16
2004# define NAME_CHUNK_SZ (200 << 10) /*200K*/
2005#elif MEMORYSIZE >= 8
2006# define NAME_CHUNK_SZ (100 << 10) /*100K*/
2007#else
2008# define NAME_CHUNK_SZ (50 << 10) /*50K*/
2009#endif
2010 struct playlist_info* playlist = &current_playlist;
2011 size_t namebufsz = (AVERAGE_FILENAME_LENGTH * global_settings.max_files_in_dir);
2012 size_t name_chunks = (namebufsz + NAME_CHUNK_SZ - 1) / NAME_CHUNK_SZ;
2013 core_chunk_alloc_init(&playlist->name_chunk_buffer, NAME_CHUNK_SZ, name_chunks);
2014#undef NAME_CHUNK_SZ
2015}
2016
2017/*
1993 * Allocate a temporary buffer for loading playlists 2018 * Allocate a temporary buffer for loading playlists
1994 */ 2019 */
1995static int alloc_tempbuf(size_t* buflen) 2020static int alloc_tempbuf(size_t* buflen)
@@ -2016,8 +2041,6 @@ static int move_callback(int handle, void* current, void* new)
2016 struct playlist_info* playlist = &current_playlist; 2041 struct playlist_info* playlist = &current_playlist;
2017 if (current == playlist->indices) 2042 if (current == playlist->indices)
2018 playlist->indices = new; 2043 playlist->indices = new;
2019 else if (current == playlist->buffer)
2020 playlist->buffer = new;
2021#ifdef HAVE_DIRCACHE 2044#ifdef HAVE_DIRCACHE
2022 else if (current == playlist->dcfrefs) 2045 else if (current == playlist->dcfrefs)
2023 playlist->dcfrefs = new; 2046 playlist->dcfrefs = new;
@@ -2056,13 +2079,6 @@ void playlist_init(void)
2056 playlist->max_playlist_size * sizeof(*playlist->indices), &ops); 2079 playlist->max_playlist_size * sizeof(*playlist->indices), &ops);
2057 2080
2058 playlist->indices = core_get_data(handle); 2081 playlist->indices = core_get_data(handle);
2059 playlist->buffer_size =
2060 AVERAGE_FILENAME_LENGTH * global_settings.max_files_in_dir;
2061
2062 handle = core_alloc_ex("playlist buf",
2063 playlist->buffer_size, &ops);
2064 playlist->buffer = core_get_data(handle);
2065 playlist->buffer_handle = handle;
2066 2082
2067 initalize_new_playlist(playlist, true); 2083 initalize_new_playlist(playlist, true);
2068 2084
@@ -2099,11 +2115,19 @@ void playlist_shutdown(void)
2099 */ 2115 */
2100int playlist_add(const char *filename) 2116int playlist_add(const char *filename)
2101{ 2117{
2118 size_t indice = CHUNK_ALLOC_INVALID;
2102 struct playlist_info* playlist = &current_playlist; 2119 struct playlist_info* playlist = &current_playlist;
2103 int len = strlen(filename); 2120 int len = strlen(filename);
2104 2121
2105 if(len+1 > playlist->buffer_size - playlist->buffer_end_pos) 2122 if (!chunk_alloc_is_initialized(&playlist->name_chunk_buffer))
2123 alloc_namebuffer();
2124
2125 if (chunk_alloc_is_initialized(&playlist->name_chunk_buffer))
2126 indice = chunk_alloc(&playlist->name_chunk_buffer, len + 1);
2127
2128 if(indice == CHUNK_ALLOC_INVALID)
2106 { 2129 {
2130
2107 notify_buffer_full(); 2131 notify_buffer_full();
2108 return -2; 2132 return -2;
2109 } 2133 }
@@ -2116,17 +2140,21 @@ int playlist_add(const char *filename)
2116 2140
2117 playlist_mutex_lock(&(playlist->mutex)); 2141 playlist_mutex_lock(&(playlist->mutex));
2118 2142
2119 playlist->indices[playlist->amount] = playlist->buffer_end_pos; 2143 char *namebuf = (char*)chunk_get_data(&playlist->name_chunk_buffer, indice);
2144 strcpy(namebuf, filename);
2145
2146 namebuf += len;
2147 namebuf[0] = '\0';
2148
2149 chunk_put_data(&playlist->name_chunk_buffer, indice);
2150 playlist->indices[playlist->amount] = indice;
2151
2120#ifdef HAVE_DIRCACHE 2152#ifdef HAVE_DIRCACHE
2121 dc_copy_filerefs(&playlist->dcfrefs[playlist->amount], NULL, 1); 2153 dc_copy_filerefs(&playlist->dcfrefs[playlist->amount], NULL, 1);
2122#endif 2154#endif
2123 2155
2124 playlist->amount++; 2156 playlist->amount++;
2125 2157
2126 strcpy((char*)&playlist->buffer[playlist->buffer_end_pos], filename);
2127 playlist->buffer_end_pos += len;
2128 playlist->buffer[playlist->buffer_end_pos++] = '\0';
2129
2130 playlist_mutex_unlock(&(playlist->mutex)); 2158 playlist_mutex_unlock(&(playlist->mutex));
2131 2159
2132 return 0; 2160 return 0;
@@ -2200,9 +2228,7 @@ int playlist_create_ex(struct playlist_info* playlist,
2200#endif 2228#endif
2201 } 2229 }
2202 2230
2203 playlist->buffer_size = 0; 2231 chunk_alloc_free(&playlist->name_chunk_buffer);
2204 playlist->buffer_handle = -1;
2205 playlist->buffer = NULL;
2206 } 2232 }
2207 2233
2208 new_playlist_unlocked(playlist, dir, file); 2234 new_playlist_unlocked(playlist, dir, file);
@@ -3701,10 +3727,6 @@ int playlist_save(struct playlist_info* playlist, char *filename,
3701 if (strlcat(path, "_temp", sizeof(path)) >= sizeof (path)) 3727 if (strlcat(path, "_temp", sizeof(path)) >= sizeof (path))
3702 return -1; 3728 return -1;
3703 3729
3704 /* can ignore volatile here, because core_get_data() is called later */
3705 char* old_buffer = (char*)playlist->buffer;
3706 size_t old_buffer_size = playlist->buffer_size;
3707
3708 if (is_m3u8_name(path)) 3730 if (is_m3u8_name(path))
3709 { 3731 {
3710 fd = open_utf8(path, O_CREAT|O_WRONLY|O_TRUNC); 3732 fd = open_utf8(path, O_CREAT|O_WRONLY|O_TRUNC);
@@ -3718,8 +3740,7 @@ int playlist_save(struct playlist_info* playlist, char *filename,
3718 if (fd < 0) 3740 if (fd < 0)
3719 { 3741 {
3720 notify_access_error(); 3742 notify_access_error();
3721 result = -1; 3743 return -1;
3722 goto reset_old_buffer;
3723 } 3744 }
3724 3745
3725 display_playlist_count(count, ID2P(LANG_PLAYLIST_SAVE_COUNT), false); 3746 display_playlist_count(count, ID2P(LANG_PLAYLIST_SAVE_COUNT), false);
@@ -3839,13 +3860,6 @@ int playlist_save(struct playlist_info* playlist, char *filename,
3839 3860
3840 cpu_boost(false); 3861 cpu_boost(false);
3841 3862
3842reset_old_buffer:
3843 if (playlist->buffer_handle > 0)
3844 old_buffer = core_get_data(playlist->buffer_handle);
3845
3846 playlist->buffer = old_buffer;
3847 playlist->buffer_size = old_buffer_size;
3848
3849 return result; 3863 return result;
3850} 3864}
3851 3865
diff --git a/apps/playlist.h b/apps/playlist.h
index 1ab330e513..ef943f1bd9 100644
--- a/apps/playlist.h
+++ b/apps/playlist.h
@@ -28,6 +28,7 @@
28#include "kernel.h" 28#include "kernel.h"
29#include "metadata.h" 29#include "metadata.h"
30#include "rbpaths.h" 30#include "rbpaths.h"
31#include "chunk_alloc.h"
31 32
32#define PLAYLIST_ATTR_QUEUED 0x01 33#define PLAYLIST_ATTR_QUEUED 0x01
33#define PLAYLIST_ATTR_INSERTED 0x02 34#define PLAYLIST_ATTR_INSERTED 0x02
@@ -84,10 +85,10 @@ struct playlist_info
84 global_settings.max_files_in_playlist */ 85 global_settings.max_files_in_playlist */
85 int num_inserted_tracks; /* number of tracks inserted */ 86 int num_inserted_tracks; /* number of tracks inserted */
86 volatile unsigned long *indices; /* array of indices */ 87 volatile unsigned long *indices; /* array of indices */
87 int buffer_handle; /* handle to the below buffer (-1 if non-buflib) */ 88
88 volatile char *buffer;/* buffer for in-ram playlists */ 89 struct chunk_alloc_header name_chunk_buffer; /* chunk buffer for
89 int buffer_size; /* size of buffer */ 90 in-ram playlist */
90 int buffer_end_pos; /* last position where buffer was written */ 91
91 int index; /* index of current playing track */ 92 int index; /* index of current playing track */
92 int first_index; /* index of first song in playlist */ 93 int first_index; /* index of first song in playlist */
93 int amount; /* number of tracks in the index */ 94 int amount; /* number of tracks in the index */