diff options
author | William Wilgus <me.theuser@yahoo.com> | 2023-01-11 01:14:22 -0500 |
---|---|---|
committer | William Wilgus <me.theuser@yahoo.com> | 2023-01-11 01:14:22 -0500 |
commit | 746fd7f2db241653ac4244f22962a493978e4fbf (patch) | |
tree | e4a88e395026e091a0d6437a6e3348dc9aaa5b47 /apps/playlist.c | |
parent | 89c021fbfa6cfad58d272769a1e8762cf32be204 (diff) | |
download | rockbox-746fd7f2db241653ac4244f22962a493978e4fbf.tar.gz rockbox-746fd7f2db241653ac4244f22962a493978e4fbf.zip |
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
Diffstat (limited to 'apps/playlist.c')
-rw-r--r-- | apps/playlist.c | 76 |
1 files changed, 30 insertions, 46 deletions
diff --git a/apps/playlist.c b/apps/playlist.c index 7775fc3c12..4e4e3ed42a 100644 --- a/apps/playlist.c +++ b/apps/playlist.c | |||
@@ -507,8 +507,10 @@ static void empty_playlist_unlocked(struct playlist_info* playlist, bool resume) | |||
507 | 507 | ||
508 | playlist->filename[0] = '\0'; | 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 | playlist->seed = 0; | 514 | playlist->seed = 0; |
513 | playlist->num_cached = 0; | 515 | playlist->num_cached = 0; |
514 | 516 | ||
@@ -1182,19 +1184,12 @@ static int get_track_filename(struct playlist_info* playlist, int index, int see | |||
1182 | { | 1184 | { |
1183 | max = dircache_get_fileref_path(&playlist->dcfrefs[index], | 1185 | max = dircache_get_fileref_path(&playlist->dcfrefs[index], |
1184 | tmp_buf, sizeof(tmp_buf)); | 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 | #endif /* HAVE_DIRCACHE */ | 1188 | #endif /* HAVE_DIRCACHE */ |
1190 | 1189 | ||
1191 | if (playlist->in_ram && !control_file && max < 0) | 1190 | if (playlist->in_ram && !control_file && max < 0) |
1192 | { | 1191 | { |
1193 | char *namebuf = chunk_get_data(&playlist->name_chunk_buffer, seek); | 1192 | strmemccpy(tmp_buf, (char*)&playlist->buffer[seek], sizeof(tmp_buf)); |
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 | |||
1198 | } | 1193 | } |
1199 | else if (max < 0) | 1194 | else if (max < 0) |
1200 | { | 1195 | { |
@@ -1233,7 +1228,6 @@ static int get_track_filename(struct playlist_info* playlist, int index, int see | |||
1233 | max = convert_m3u_name(tmp_buf, max, | 1228 | max = convert_m3u_name(tmp_buf, max, |
1234 | sizeof(tmp_buf), dir_buf); | 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,25 +1970,6 @@ static void dc_thread_playlist(void) | |||
1976 | #endif | 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 = ¤t_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 | * Allocate a temporary buffer for loading playlists | 1973 | * Allocate a temporary buffer for loading playlists |
1999 | */ | 1974 | */ |
2000 | static int alloc_tempbuf(size_t* buflen) | 1975 | static int alloc_tempbuf(size_t* buflen) |
@@ -2021,6 +1996,8 @@ static int move_callback(int handle, void* current, void* new) | |||
2021 | struct playlist_info* playlist = ¤t_playlist; | 1996 | struct playlist_info* playlist = ¤t_playlist; |
2022 | if (current == playlist->indices) | 1997 | if (current == playlist->indices) |
2023 | playlist->indices = new; | 1998 | playlist->indices = new; |
1999 | else if (current == playlist->buffer) | ||
2000 | playlist->buffer = new; | ||
2024 | #ifdef HAVE_DIRCACHE | 2001 | #ifdef HAVE_DIRCACHE |
2025 | else if (current == playlist->dcfrefs) | 2002 | else if (current == playlist->dcfrefs) |
2026 | playlist->dcfrefs = new; | 2003 | playlist->dcfrefs = new; |
@@ -2059,6 +2036,13 @@ void playlist_init(void) | |||
2059 | playlist->max_playlist_size * sizeof(*playlist->indices), &ops); | 2036 | playlist->max_playlist_size * sizeof(*playlist->indices), &ops); |
2060 | 2037 | ||
2061 | playlist->indices = core_get_data(handle); | 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 | initalize_new_playlist(playlist, true); | 2047 | initalize_new_playlist(playlist, true); |
2064 | 2048 | ||
@@ -2095,21 +2079,15 @@ void playlist_shutdown(void) | |||
2095 | */ | 2079 | */ |
2096 | int playlist_add(const char *filename) | 2080 | int playlist_add(const char *filename) |
2097 | { | 2081 | { |
2098 | size_t indice = CHUNK_ALLOC_INVALID; | ||
2099 | struct playlist_info* playlist = ¤t_playlist; | 2082 | struct playlist_info* playlist = ¤t_playlist; |
2100 | int len = strlen(filename); | 2083 | int len = strlen(filename); |
2101 | 2084 | ||
2102 | if (!chunk_alloc_is_initialized(&playlist->name_chunk_buffer)) | 2085 | if(len+1 > playlist->buffer_size - playlist->buffer_end_pos) |
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) | ||
2109 | { | 2086 | { |
2110 | notify_buffer_full(); | 2087 | notify_buffer_full(); |
2111 | return -2; | 2088 | return -2; |
2112 | } | 2089 | } |
2090 | |||
2113 | if(playlist->amount >= playlist->max_playlist_size) | 2091 | if(playlist->amount >= playlist->max_playlist_size) |
2114 | { | 2092 | { |
2115 | notify_buffer_full(); | 2093 | notify_buffer_full(); |
@@ -2118,18 +2096,16 @@ int playlist_add(const char *filename) | |||
2118 | 2096 | ||
2119 | playlist_mutex_lock(&(playlist->mutex)); | 2097 | playlist_mutex_lock(&(playlist->mutex)); |
2120 | 2098 | ||
2121 | playlist->indices[playlist->amount] = indice; | 2099 | playlist->indices[playlist->amount] = playlist->buffer_end_pos; |
2122 | #ifdef HAVE_DIRCACHE | 2100 | #ifdef HAVE_DIRCACHE |
2123 | dc_copy_filerefs(&playlist->dcfrefs[playlist->amount], NULL, 1); | 2101 | dc_copy_filerefs(&playlist->dcfrefs[playlist->amount], NULL, 1); |
2124 | #endif | 2102 | #endif |
2125 | 2103 | ||
2126 | playlist->amount++; | 2104 | playlist->amount++; |
2127 | 2105 | ||
2128 | char *namebuf = (char*)chunk_get_data(&playlist->name_chunk_buffer, indice); | 2106 | strcpy((char*)&playlist->buffer[playlist->buffer_end_pos], filename); |
2129 | strcpy(namebuf, filename); | 2107 | playlist->buffer_end_pos += len; |
2130 | namebuf += len; | 2108 | playlist->buffer[playlist->buffer_end_pos++] = '\0'; |
2131 | namebuf[0] = '\0'; | ||
2132 | chunk_put_data(&playlist->name_chunk_buffer, indice); | ||
2133 | 2109 | ||
2134 | playlist_mutex_unlock(&(playlist->mutex)); | 2110 | playlist_mutex_unlock(&(playlist->mutex)); |
2135 | 2111 | ||
@@ -2204,7 +2180,9 @@ int playlist_create_ex(struct playlist_info* playlist, | |||
2204 | #endif | 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 | new_playlist_unlocked(playlist, dir, file); | 2188 | new_playlist_unlocked(playlist, dir, file); |
@@ -3684,7 +3662,9 @@ int playlist_save(struct playlist_info* playlist, char *filename, | |||
3684 | if (strlcat(path, "_temp", sizeof(path)) >= sizeof (path)) | 3662 | if (strlcat(path, "_temp", sizeof(path)) >= sizeof (path)) |
3685 | return -1; | 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 | if (is_m3u8_name(path)) | 3669 | if (is_m3u8_name(path)) |
3690 | { | 3670 | { |
@@ -3819,7 +3799,11 @@ int playlist_save(struct playlist_info* playlist, char *filename, | |||
3819 | cpu_boost(false); | 3799 | cpu_boost(false); |
3820 | 3800 | ||
3821 | reset_old_buffer: | 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 | return result; | 3808 | return result; |
3825 | } | 3809 | } |