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

Change-Id: Ia2e02a61f0b269dc0508717a56a2ca1a334d2378

authored by

William Wilgus and committed by
William Wilgus
89c021fb 7faf6be3

+51 -34
+46 -30
apps/playlist.c
··· 507 507 508 508 playlist->filename[0] = '\0'; 509 509 510 - if (playlist->buffer) 511 - playlist->buffer[0] = 0; 510 + chunk_alloc_free(&playlist->name_chunk_buffer); 512 511 513 - playlist->buffer_end_pos = 0; 514 512 playlist->seed = 0; 515 513 playlist->num_cached = 0; 516 514 ··· 1184 1182 { 1185 1183 max = dircache_get_fileref_path(&playlist->dcfrefs[index], 1186 1184 tmp_buf, sizeof(tmp_buf)); 1185 + 1186 + NOTEF("%s [in DCache]: 0x%x %s", __func__, 1187 + playlist->dcfrefs[index], tmp_buf); 1187 1188 } 1188 1189 #endif /* HAVE_DIRCACHE */ 1189 1190 1190 1191 if (playlist->in_ram && !control_file && max < 0) 1191 1192 { 1192 - strmemccpy(tmp_buf, (char*)&playlist->buffer[seek], sizeof(tmp_buf)); 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 + 1193 1198 } 1194 1199 else if (max < 0) 1195 1200 { ··· 1228 1233 max = convert_m3u_name(tmp_buf, max, 1229 1234 sizeof(tmp_buf), dir_buf); 1230 1235 } 1236 + NOTEF("%s [in File]: 0x%x %s", __func__, seek, tmp_buf); 1231 1237 } 1232 1238 } 1233 1239 ··· 1970 1976 #endif 1971 1977 1972 1978 /* 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 + /* 1973 1998 * Allocate a temporary buffer for loading playlists 1974 1999 */ 1975 2000 static int alloc_tempbuf(size_t* buflen) ··· 1996 2021 struct playlist_info* playlist = &current_playlist; 1997 2022 if (current == playlist->indices) 1998 2023 playlist->indices = new; 1999 - else if (current == playlist->buffer) 2000 - playlist->buffer = new; 2001 2024 #ifdef HAVE_DIRCACHE 2002 2025 else if (current == playlist->dcfrefs) 2003 2026 playlist->dcfrefs = new; ··· 2036 2059 playlist->max_playlist_size * sizeof(*playlist->indices), &ops); 2037 2060 2038 2061 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; 2046 2062 2047 2063 initalize_new_playlist(playlist, true); 2048 2064 ··· 2079 2095 */ 2080 2096 int playlist_add(const char *filename) 2081 2097 { 2098 + size_t indice = CHUNK_ALLOC_INVALID; 2082 2099 struct playlist_info* playlist = &current_playlist; 2083 2100 int len = strlen(filename); 2084 2101 2085 - if(len+1 > playlist->buffer_size - playlist->buffer_end_pos) 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) 2086 2109 { 2087 2110 notify_buffer_full(); 2088 2111 return -2; 2089 2112 } 2090 - 2091 2113 if(playlist->amount >= playlist->max_playlist_size) 2092 2114 { 2093 2115 notify_buffer_full(); ··· 2096 2118 2097 2119 playlist_mutex_lock(&(playlist->mutex)); 2098 2120 2099 - playlist->indices[playlist->amount] = playlist->buffer_end_pos; 2121 + playlist->indices[playlist->amount] = indice; 2100 2122 #ifdef HAVE_DIRCACHE 2101 2123 dc_copy_filerefs(&playlist->dcfrefs[playlist->amount], NULL, 1); 2102 2124 #endif 2103 2125 2104 2126 playlist->amount++; 2105 2127 2106 - strcpy((char*)&playlist->buffer[playlist->buffer_end_pos], filename); 2107 - playlist->buffer_end_pos += len; 2108 - playlist->buffer[playlist->buffer_end_pos++] = '\0'; 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); 2109 2133 2110 2134 playlist_mutex_unlock(&(playlist->mutex)); 2111 2135 ··· 2180 2204 #endif 2181 2205 } 2182 2206 2183 - playlist->buffer_size = 0; 2184 - playlist->buffer_handle = -1; 2185 - playlist->buffer = NULL; 2207 + chunk_alloc_free(&playlist->name_chunk_buffer); 2186 2208 } 2187 2209 2188 2210 new_playlist_unlocked(playlist, dir, file); ··· 3662 3684 if (strlcat(path, "_temp", sizeof(path)) >= sizeof (path)) 3663 3685 return -1; 3664 3686 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; 3687 + struct chunk_alloc_header old_name_chunk_buffer = playlist->name_chunk_buffer; 3668 3688 3669 3689 if (is_m3u8_name(path)) 3670 3690 { ··· 3799 3819 cpu_boost(false); 3800 3820 3801 3821 reset_old_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; 3822 + playlist->name_chunk_buffer = old_name_chunk_buffer; 3807 3823 3808 3824 return result; 3809 3825 }
+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 */