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.

Revert "add chunk_alloc to playlist.c"

This reverts commit 89c021fbfa6cfad58d272769a1e8762cf32be204.

Reason for revert: crash when playing on disk playlist then playing a directory as an in-ram playlist

Change-Id: Ia5cf5da9f46f8c10c5c0f3707e7978c05664b8a4

+34 -51
+30 -46
apps/playlist.c
··· 507 507 508 508 playlist->filename[0] = '\0'; 509 509 510 - chunk_alloc_free(&playlist->name_chunk_buffer); 510 + if (playlist->buffer) 511 + playlist->buffer[0] = 0; 511 512 513 + playlist->buffer_end_pos = 0; 512 514 playlist->seed = 0; 513 515 playlist->num_cached = 0; 514 516 ··· 1182 1184 { 1183 1185 max = dircache_get_fileref_path(&playlist->dcfrefs[index], 1184 1186 tmp_buf, sizeof(tmp_buf)); 1185 - 1186 - NOTEF("%s [in DCache]: 0x%x %s", __func__, 1187 - playlist->dcfrefs[index], tmp_buf); 1188 1187 } 1189 1188 #endif /* HAVE_DIRCACHE */ 1190 1189 1191 1190 if (playlist->in_ram && !control_file && max < 0) 1192 1191 { 1193 - char *namebuf = chunk_get_data(&playlist->name_chunk_buffer, seek); 1194 - strmemccpy(tmp_buf, namebuf, sizeof(tmp_buf)); 1195 - chunk_put_data(&playlist->name_chunk_buffer, seek); 1196 - NOTEF("%s [in Ram]: 0x%x %s", __func__, seek, tmp_buf); 1197 - 1192 + strmemccpy(tmp_buf, (char*)&playlist->buffer[seek], sizeof(tmp_buf)); 1198 1193 } 1199 1194 else if (max < 0) 1200 1195 { ··· 1233 1228 max = convert_m3u_name(tmp_buf, max, 1234 1229 sizeof(tmp_buf), dir_buf); 1235 1230 } 1236 - NOTEF("%s [in File]: 0x%x %s", __func__, seek, tmp_buf); 1237 1231 } 1238 1232 } 1239 1233 ··· 1976 1970 #endif 1977 1971 1978 1972 /* 1979 - * Allocate name chunk buffer header for in-ram playlists 1980 - */ 1981 - static void alloc_namebuffer(void) 1982 - { 1983 - #if MEMORYSIZE >= 16 1984 - # define NAME_CHUNK_SZ (200 << 10) /*200K*/ 1985 - #elif MEMORYSIZE >= 8 1986 - # define NAME_CHUNK_SZ (100 << 10) /*100K*/ 1987 - #else 1988 - # define NAME_CHUNK_SZ (50 << 10) /*50K*/ 1989 - #endif 1990 - struct playlist_info* playlist = &current_playlist; 1991 - size_t namebufsz = (AVERAGE_FILENAME_LENGTH * global_settings.max_files_in_dir); 1992 - size_t name_chunks = (namebufsz + NAME_CHUNK_SZ - 1) / NAME_CHUNK_SZ; 1993 - core_chunk_alloc_init(&playlist->name_chunk_buffer, NAME_CHUNK_SZ, name_chunks); 1994 - #undef NAME_CHUNK_SZ 1995 - } 1996 - 1997 - /* 1998 1973 * Allocate a temporary buffer for loading playlists 1999 1974 */ 2000 1975 static int alloc_tempbuf(size_t* buflen) ··· 2021 1996 struct playlist_info* playlist = &current_playlist; 2022 1997 if (current == playlist->indices) 2023 1998 playlist->indices = new; 1999 + else if (current == playlist->buffer) 2000 + playlist->buffer = new; 2024 2001 #ifdef HAVE_DIRCACHE 2025 2002 else if (current == playlist->dcfrefs) 2026 2003 playlist->dcfrefs = new; ··· 2059 2036 playlist->max_playlist_size * sizeof(*playlist->indices), &ops); 2060 2037 2061 2038 playlist->indices = core_get_data(handle); 2039 + playlist->buffer_size = 2040 + AVERAGE_FILENAME_LENGTH * global_settings.max_files_in_dir; 2041 + 2042 + handle = core_alloc_ex("playlist buf", 2043 + playlist->buffer_size, &ops); 2044 + playlist->buffer = core_get_data(handle); 2045 + playlist->buffer_handle = handle; 2062 2046 2063 2047 initalize_new_playlist(playlist, true); 2064 2048 ··· 2095 2079 */ 2096 2080 int playlist_add(const char *filename) 2097 2081 { 2098 - size_t indice = CHUNK_ALLOC_INVALID; 2099 2082 struct playlist_info* playlist = &current_playlist; 2100 2083 int len = strlen(filename); 2101 2084 2102 - if (!chunk_alloc_is_initialized(&playlist->name_chunk_buffer)) 2103 - alloc_namebuffer(); 2104 - 2105 - if (chunk_alloc_is_initialized(&playlist->name_chunk_buffer)) 2106 - indice = chunk_alloc(&playlist->name_chunk_buffer, len + 1); 2107 - 2108 - if(indice == CHUNK_ALLOC_INVALID) 2085 + if(len+1 > playlist->buffer_size - playlist->buffer_end_pos) 2109 2086 { 2110 2087 notify_buffer_full(); 2111 2088 return -2; 2112 2089 } 2090 + 2113 2091 if(playlist->amount >= playlist->max_playlist_size) 2114 2092 { 2115 2093 notify_buffer_full(); ··· 2118 2096 2119 2097 playlist_mutex_lock(&(playlist->mutex)); 2120 2098 2121 - playlist->indices[playlist->amount] = indice; 2099 + playlist->indices[playlist->amount] = playlist->buffer_end_pos; 2122 2100 #ifdef HAVE_DIRCACHE 2123 2101 dc_copy_filerefs(&playlist->dcfrefs[playlist->amount], NULL, 1); 2124 2102 #endif 2125 2103 2126 2104 playlist->amount++; 2127 2105 2128 - char *namebuf = (char*)chunk_get_data(&playlist->name_chunk_buffer, indice); 2129 - strcpy(namebuf, filename); 2130 - namebuf += len; 2131 - namebuf[0] = '\0'; 2132 - chunk_put_data(&playlist->name_chunk_buffer, indice); 2106 + strcpy((char*)&playlist->buffer[playlist->buffer_end_pos], filename); 2107 + playlist->buffer_end_pos += len; 2108 + playlist->buffer[playlist->buffer_end_pos++] = '\0'; 2133 2109 2134 2110 playlist_mutex_unlock(&(playlist->mutex)); 2135 2111 ··· 2204 2180 #endif 2205 2181 } 2206 2182 2207 - chunk_alloc_free(&playlist->name_chunk_buffer); 2183 + playlist->buffer_size = 0; 2184 + playlist->buffer_handle = -1; 2185 + playlist->buffer = NULL; 2208 2186 } 2209 2187 2210 2188 new_playlist_unlocked(playlist, dir, file); ··· 3684 3662 if (strlcat(path, "_temp", sizeof(path)) >= sizeof (path)) 3685 3663 return -1; 3686 3664 3687 - struct chunk_alloc_header old_name_chunk_buffer = playlist->name_chunk_buffer; 3665 + /* can ignore volatile here, because core_get_data() is called later */ 3666 + char* old_buffer = (char*)playlist->buffer; 3667 + size_t old_buffer_size = playlist->buffer_size; 3688 3668 3689 3669 if (is_m3u8_name(path)) 3690 3670 { ··· 3819 3799 cpu_boost(false); 3820 3800 3821 3801 reset_old_buffer: 3822 - playlist->name_chunk_buffer = old_name_chunk_buffer; 3802 + if (playlist->buffer_handle > 0) 3803 + old_buffer = core_get_data(playlist->buffer_handle); 3804 + 3805 + playlist->buffer = old_buffer; 3806 + playlist->buffer_size = old_buffer_size; 3823 3807 3824 3808 return result; 3825 3809 }
+4 -5
apps/playlist.h
··· 28 28 #include "kernel.h" 29 29 #include "metadata.h" 30 30 #include "rbpaths.h" 31 - #include "chunk_alloc.h" 32 31 33 32 #define PLAYLIST_ATTR_QUEUED 0x01 34 33 #define PLAYLIST_ATTR_INSERTED 0x02 ··· 85 84 global_settings.max_files_in_playlist */ 86 85 int num_inserted_tracks; /* number of tracks inserted */ 87 86 volatile unsigned long *indices; /* array of indices */ 88 - 89 - struct chunk_alloc_header name_chunk_buffer; /* chunk buffer for 90 - in-ram playlist */ 91 - 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 */ 92 91 int index; /* index of current playing track */ 93 92 int first_index; /* index of first song in playlist */ 94 93 int amount; /* number of tracks in the index */