Rockbox open source high quality audio player as a Music Player Daemon
mpris rockbox mpd libadwaita audio rust zig deno
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

authored by

William Wilgus and committed by
William Wilgus
2d9cb673 00c7817c

+54 -39
+49 -35
apps/playlist.c
··· 520 520 521 521 playlist->filename[0] = '\0'; 522 522 523 - if (playlist->buffer) 524 - playlist->buffer[0] = 0; 523 + chunk_alloc_free(&playlist->name_chunk_buffer); 525 524 526 - playlist->buffer_end_pos = 0; 527 525 playlist->seed = 0; 528 526 playlist->num_cached = 0; 529 527 ··· 1196 1194 { 1197 1195 max = dircache_get_fileref_path(&playlist->dcfrefs[index], 1198 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 1201 #endif /* HAVE_DIRCACHE */ 1201 1202 1202 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 1210 else if (max < 0) 1207 1211 { ··· 1239 1243 if (!utf8) 1240 1244 max = convert_m3u_name(tmp_buf, max, 1241 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 1996 #endif 1991 1997 1992 1998 /* 1999 + * Allocate name chunk buffer header for in-ram playlists 2000 + */ 2001 + static 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 2018 * Allocate a temporary buffer for loading playlists 1994 2019 */ 1995 2020 static int alloc_tempbuf(size_t* buflen) ··· 2016 2041 struct playlist_info* playlist = &current_playlist; 2017 2042 if (current == playlist->indices) 2018 2043 playlist->indices = new; 2019 - else if (current == playlist->buffer) 2020 - playlist->buffer = new; 2021 2044 #ifdef HAVE_DIRCACHE 2022 2045 else if (current == playlist->dcfrefs) 2023 2046 playlist->dcfrefs = new; ··· 2056 2079 playlist->max_playlist_size * sizeof(*playlist->indices), &ops); 2057 2080 2058 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 2083 initalize_new_playlist(playlist, true); 2068 2084 ··· 2099 2115 */ 2100 2116 int playlist_add(const char *filename) 2101 2117 { 2118 + size_t indice = CHUNK_ALLOC_INVALID; 2102 2119 struct playlist_info* playlist = &current_playlist; 2103 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 2131 notify_buffer_full(); 2108 2132 return -2; 2109 2133 } ··· 2116 2140 2117 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 2152 #ifdef HAVE_DIRCACHE 2121 2153 dc_copy_filerefs(&playlist->dcfrefs[playlist->amount], NULL, 1); 2122 2154 #endif 2123 2155 2124 2156 playlist->amount++; 2125 - 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 2157 2130 2158 playlist_mutex_unlock(&(playlist->mutex)); 2131 2159 ··· 2200 2228 #endif 2201 2229 } 2202 2230 2203 - playlist->buffer_size = 0; 2204 - playlist->buffer_handle = -1; 2205 - playlist->buffer = NULL; 2231 + chunk_alloc_free(&playlist->name_chunk_buffer); 2206 2232 } 2207 2233 2208 2234 new_playlist_unlocked(playlist, dir, file); ··· 3701 3727 if (strlcat(path, "_temp", sizeof(path)) >= sizeof (path)) 3702 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 3730 if (is_m3u8_name(path)) 3709 3731 { 3710 3732 fd = open_utf8(path, O_CREAT|O_WRONLY|O_TRUNC); ··· 3718 3740 if (fd < 0) 3719 3741 { 3720 3742 notify_access_error(); 3721 - result = -1; 3722 - goto reset_old_buffer; 3743 + return -1; 3723 3744 } 3724 3745 3725 3746 display_playlist_count(count, ID2P(LANG_PLAYLIST_SAVE_COUNT), false); ··· 3838 3859 close(fd); 3839 3860 3840 3861 cpu_boost(false); 3841 - 3842 - reset_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 3862 3849 3863 return result; 3850 3864 }
+5 -4
apps/playlist.h
··· 28 28 #include "kernel.h" 29 29 #include "metadata.h" 30 30 #include "rbpaths.h" 31 + #include "chunk_alloc.h" 31 32 32 33 #define PLAYLIST_ATTR_QUEUED 0x01 33 34 #define PLAYLIST_ATTR_INSERTED 0x02 ··· 84 85 global_settings.max_files_in_playlist */ 85 86 int num_inserted_tracks; /* number of tracks inserted */ 86 87 volatile unsigned long *indices; /* array of indices */ 87 - int buffer_handle; /* handle to the below buffer (-1 if non-buflib) */ 88 - volatile char *buffer;/* buffer for in-ram playlists */ 89 - int buffer_size; /* size of buffer */ 90 - int buffer_end_pos; /* last position where buffer was written */ 88 + 89 + struct chunk_alloc_header name_chunk_buffer; /* chunk buffer for 90 + in-ram playlist */ 91 + 91 92 int index; /* index of current playing track */ 92 93 int first_index; /* index of first song in playlist */ 93 94 int amount; /* number of tracks in the index */