diff options
author | William Wilgus <wilgus.william@gmail.com> | 2023-01-08 23:47:13 -0500 |
---|---|---|
committer | William Wilgus <me.theuser@yahoo.com> | 2023-01-10 23:59:19 -0500 |
commit | 89c021fbfa6cfad58d272769a1e8762cf32be204 (patch) | |
tree | 15b06928ffb4f96804fc9b59e77a8149b52c4115 | |
parent | 7faf6be35f1025fe3439e02f4fd403f0eb990c68 (diff) | |
download | rockbox-89c021fbfa6cfad58d272769a1e8762cf32be204.tar.gz rockbox-89c021fbfa6cfad58d272769a1e8762cf32be204.zip |
add chunk_alloc to playlist.c
Change-Id: Ia2e02a61f0b269dc0508717a56a2ca1a334d2378
-rw-r--r-- | apps/playlist.c | 76 | ||||
-rw-r--r-- | apps/playlist.h | 9 |
2 files changed, 51 insertions, 34 deletions
diff --git a/apps/playlist.c b/apps/playlist.c index 4e4e3ed42a..7775fc3c12 100644 --- a/apps/playlist.c +++ b/apps/playlist.c | |||
@@ -507,10 +507,8 @@ 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 | if (playlist->buffer) | 510 | chunk_alloc_free(&playlist->name_chunk_buffer); |
511 | playlist->buffer[0] = 0; | ||
512 | 511 | ||
513 | playlist->buffer_end_pos = 0; | ||
514 | playlist->seed = 0; | 512 | playlist->seed = 0; |
515 | playlist->num_cached = 0; | 513 | playlist->num_cached = 0; |
516 | 514 | ||
@@ -1184,12 +1182,19 @@ static int get_track_filename(struct playlist_info* playlist, int index, int see | |||
1184 | { | 1182 | { |
1185 | max = dircache_get_fileref_path(&playlist->dcfrefs[index], | 1183 | max = dircache_get_fileref_path(&playlist->dcfrefs[index], |
1186 | tmp_buf, sizeof(tmp_buf)); | 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 | #endif /* HAVE_DIRCACHE */ | 1189 | #endif /* HAVE_DIRCACHE */ |
1189 | 1190 | ||
1190 | if (playlist->in_ram && !control_file && max < 0) | 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 | else if (max < 0) | 1199 | else if (max < 0) |
1195 | { | 1200 | { |
@@ -1228,6 +1233,7 @@ static int get_track_filename(struct playlist_info* playlist, int index, int see | |||
1228 | max = convert_m3u_name(tmp_buf, max, | 1233 | max = convert_m3u_name(tmp_buf, max, |
1229 | sizeof(tmp_buf), dir_buf); | 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,6 +1976,25 @@ static void dc_thread_playlist(void) | |||
1970 | #endif | 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 = ¤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 | /* | ||
1973 | * Allocate a temporary buffer for loading playlists | 1998 | * Allocate a temporary buffer for loading playlists |
1974 | */ | 1999 | */ |
1975 | static int alloc_tempbuf(size_t* buflen) | 2000 | static int alloc_tempbuf(size_t* buflen) |
@@ -1996,8 +2021,6 @@ static int move_callback(int handle, void* current, void* new) | |||
1996 | struct playlist_info* playlist = ¤t_playlist; | 2021 | struct playlist_info* playlist = ¤t_playlist; |
1997 | if (current == playlist->indices) | 2022 | if (current == playlist->indices) |
1998 | playlist->indices = new; | 2023 | playlist->indices = new; |
1999 | else if (current == playlist->buffer) | ||
2000 | playlist->buffer = new; | ||
2001 | #ifdef HAVE_DIRCACHE | 2024 | #ifdef HAVE_DIRCACHE |
2002 | else if (current == playlist->dcfrefs) | 2025 | else if (current == playlist->dcfrefs) |
2003 | playlist->dcfrefs = new; | 2026 | playlist->dcfrefs = new; |
@@ -2036,13 +2059,6 @@ void playlist_init(void) | |||
2036 | playlist->max_playlist_size * sizeof(*playlist->indices), &ops); | 2059 | playlist->max_playlist_size * sizeof(*playlist->indices), &ops); |
2037 | 2060 | ||
2038 | playlist->indices = core_get_data(handle); | 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 | initalize_new_playlist(playlist, true); | 2063 | initalize_new_playlist(playlist, true); |
2048 | 2064 | ||
@@ -2079,15 +2095,21 @@ void playlist_shutdown(void) | |||
2079 | */ | 2095 | */ |
2080 | int playlist_add(const char *filename) | 2096 | int playlist_add(const char *filename) |
2081 | { | 2097 | { |
2098 | size_t indice = CHUNK_ALLOC_INVALID; | ||
2082 | struct playlist_info* playlist = ¤t_playlist; | 2099 | struct playlist_info* playlist = ¤t_playlist; |
2083 | int len = strlen(filename); | 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 | notify_buffer_full(); | 2110 | notify_buffer_full(); |
2088 | return -2; | 2111 | return -2; |
2089 | } | 2112 | } |
2090 | |||
2091 | if(playlist->amount >= playlist->max_playlist_size) | 2113 | if(playlist->amount >= playlist->max_playlist_size) |
2092 | { | 2114 | { |
2093 | notify_buffer_full(); | 2115 | notify_buffer_full(); |
@@ -2096,16 +2118,18 @@ int playlist_add(const char *filename) | |||
2096 | 2118 | ||
2097 | playlist_mutex_lock(&(playlist->mutex)); | 2119 | playlist_mutex_lock(&(playlist->mutex)); |
2098 | 2120 | ||
2099 | playlist->indices[playlist->amount] = playlist->buffer_end_pos; | 2121 | playlist->indices[playlist->amount] = indice; |
2100 | #ifdef HAVE_DIRCACHE | 2122 | #ifdef HAVE_DIRCACHE |
2101 | dc_copy_filerefs(&playlist->dcfrefs[playlist->amount], NULL, 1); | 2123 | dc_copy_filerefs(&playlist->dcfrefs[playlist->amount], NULL, 1); |
2102 | #endif | 2124 | #endif |
2103 | 2125 | ||
2104 | playlist->amount++; | 2126 | playlist->amount++; |
2105 | 2127 | ||
2106 | strcpy((char*)&playlist->buffer[playlist->buffer_end_pos], filename); | 2128 | char *namebuf = (char*)chunk_get_data(&playlist->name_chunk_buffer, indice); |
2107 | playlist->buffer_end_pos += len; | 2129 | strcpy(namebuf, filename); |
2108 | playlist->buffer[playlist->buffer_end_pos++] = '\0'; | 2130 | namebuf += len; |
2131 | namebuf[0] = '\0'; | ||
2132 | chunk_put_data(&playlist->name_chunk_buffer, indice); | ||
2109 | 2133 | ||
2110 | playlist_mutex_unlock(&(playlist->mutex)); | 2134 | playlist_mutex_unlock(&(playlist->mutex)); |
2111 | 2135 | ||
@@ -2180,9 +2204,7 @@ int playlist_create_ex(struct playlist_info* playlist, | |||
2180 | #endif | 2204 | #endif |
2181 | } | 2205 | } |
2182 | 2206 | ||
2183 | playlist->buffer_size = 0; | 2207 | chunk_alloc_free(&playlist->name_chunk_buffer); |
2184 | playlist->buffer_handle = -1; | ||
2185 | playlist->buffer = NULL; | ||
2186 | } | 2208 | } |
2187 | 2209 | ||
2188 | new_playlist_unlocked(playlist, dir, file); | 2210 | new_playlist_unlocked(playlist, dir, file); |
@@ -3662,9 +3684,7 @@ int playlist_save(struct playlist_info* playlist, char *filename, | |||
3662 | if (strlcat(path, "_temp", sizeof(path)) >= sizeof (path)) | 3684 | if (strlcat(path, "_temp", sizeof(path)) >= sizeof (path)) |
3663 | return -1; | 3685 | return -1; |
3664 | 3686 | ||
3665 | /* can ignore volatile here, because core_get_data() is called later */ | 3687 | struct chunk_alloc_header old_name_chunk_buffer = playlist->name_chunk_buffer; |
3666 | char* old_buffer = (char*)playlist->buffer; | ||
3667 | size_t old_buffer_size = playlist->buffer_size; | ||
3668 | 3688 | ||
3669 | if (is_m3u8_name(path)) | 3689 | if (is_m3u8_name(path)) |
3670 | { | 3690 | { |
@@ -3799,11 +3819,7 @@ int playlist_save(struct playlist_info* playlist, char *filename, | |||
3799 | cpu_boost(false); | 3819 | cpu_boost(false); |
3800 | 3820 | ||
3801 | reset_old_buffer: | 3821 | reset_old_buffer: |
3802 | if (playlist->buffer_handle > 0) | 3822 | playlist->name_chunk_buffer = old_name_chunk_buffer; |
3803 | old_buffer = core_get_data(playlist->buffer_handle); | ||
3804 | |||
3805 | playlist->buffer = old_buffer; | ||
3806 | playlist->buffer_size = old_buffer_size; | ||
3807 | 3823 | ||
3808 | return result; | 3824 | return result; |
3809 | } | 3825 | } |
diff --git a/apps/playlist.h b/apps/playlist.h index 1ab330e513..a2fd6d8ea8 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 */ |