add chunk_alloc to playlist.c
Change-Id: Ia2e02a61f0b269dc0508717a56a2ca1a334d2378
This commit is contained in:
parent
7faf6be35f
commit
89c021fbfa
2 changed files with 51 additions and 34 deletions
|
@ -507,10 +507,8 @@ static void empty_playlist_unlocked(struct playlist_info* playlist, bool resume)
|
||||||
|
|
||||||
playlist->filename[0] = '\0';
|
playlist->filename[0] = '\0';
|
||||||
|
|
||||||
if (playlist->buffer)
|
chunk_alloc_free(&playlist->name_chunk_buffer);
|
||||||
playlist->buffer[0] = 0;
|
|
||||||
|
|
||||||
playlist->buffer_end_pos = 0;
|
|
||||||
playlist->seed = 0;
|
playlist->seed = 0;
|
||||||
playlist->num_cached = 0;
|
playlist->num_cached = 0;
|
||||||
|
|
||||||
|
@ -1184,12 +1182,19 @@ static int get_track_filename(struct playlist_info* playlist, int index, int see
|
||||||
{
|
{
|
||||||
max = dircache_get_fileref_path(&playlist->dcfrefs[index],
|
max = dircache_get_fileref_path(&playlist->dcfrefs[index],
|
||||||
tmp_buf, sizeof(tmp_buf));
|
tmp_buf, sizeof(tmp_buf));
|
||||||
|
|
||||||
|
NOTEF("%s [in DCache]: 0x%x %s", __func__,
|
||||||
|
playlist->dcfrefs[index], tmp_buf);
|
||||||
}
|
}
|
||||||
#endif /* HAVE_DIRCACHE */
|
#endif /* HAVE_DIRCACHE */
|
||||||
|
|
||||||
if (playlist->in_ram && !control_file && max < 0)
|
if (playlist->in_ram && !control_file && max < 0)
|
||||||
{
|
{
|
||||||
strmemccpy(tmp_buf, (char*)&playlist->buffer[seek], sizeof(tmp_buf));
|
char *namebuf = chunk_get_data(&playlist->name_chunk_buffer, seek);
|
||||||
|
strmemccpy(tmp_buf, namebuf, sizeof(tmp_buf));
|
||||||
|
chunk_put_data(&playlist->name_chunk_buffer, seek);
|
||||||
|
NOTEF("%s [in Ram]: 0x%x %s", __func__, seek, tmp_buf);
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (max < 0)
|
else if (max < 0)
|
||||||
{
|
{
|
||||||
|
@ -1228,6 +1233,7 @@ static int get_track_filename(struct playlist_info* playlist, int index, int see
|
||||||
max = convert_m3u_name(tmp_buf, max,
|
max = convert_m3u_name(tmp_buf, max,
|
||||||
sizeof(tmp_buf), dir_buf);
|
sizeof(tmp_buf), dir_buf);
|
||||||
}
|
}
|
||||||
|
NOTEF("%s [in File]: 0x%x %s", __func__, seek, tmp_buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1969,6 +1975,25 @@ static void dc_thread_playlist(void)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Allocate name chunk buffer header for in-ram playlists
|
||||||
|
*/
|
||||||
|
static void alloc_namebuffer(void)
|
||||||
|
{
|
||||||
|
#if MEMORYSIZE >= 16
|
||||||
|
# define NAME_CHUNK_SZ (200 << 10) /*200K*/
|
||||||
|
#elif MEMORYSIZE >= 8
|
||||||
|
# define NAME_CHUNK_SZ (100 << 10) /*100K*/
|
||||||
|
#else
|
||||||
|
# define NAME_CHUNK_SZ (50 << 10) /*50K*/
|
||||||
|
#endif
|
||||||
|
struct playlist_info* playlist = ¤t_playlist;
|
||||||
|
size_t namebufsz = (AVERAGE_FILENAME_LENGTH * global_settings.max_files_in_dir);
|
||||||
|
size_t name_chunks = (namebufsz + NAME_CHUNK_SZ - 1) / NAME_CHUNK_SZ;
|
||||||
|
core_chunk_alloc_init(&playlist->name_chunk_buffer, NAME_CHUNK_SZ, name_chunks);
|
||||||
|
#undef NAME_CHUNK_SZ
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Allocate a temporary buffer for loading playlists
|
* Allocate a temporary buffer for loading playlists
|
||||||
*/
|
*/
|
||||||
|
@ -1996,8 +2021,6 @@ static int move_callback(int handle, void* current, void* new)
|
||||||
struct playlist_info* playlist = ¤t_playlist;
|
struct playlist_info* playlist = ¤t_playlist;
|
||||||
if (current == playlist->indices)
|
if (current == playlist->indices)
|
||||||
playlist->indices = new;
|
playlist->indices = new;
|
||||||
else if (current == playlist->buffer)
|
|
||||||
playlist->buffer = new;
|
|
||||||
#ifdef HAVE_DIRCACHE
|
#ifdef HAVE_DIRCACHE
|
||||||
else if (current == playlist->dcfrefs)
|
else if (current == playlist->dcfrefs)
|
||||||
playlist->dcfrefs = new;
|
playlist->dcfrefs = new;
|
||||||
|
@ -2036,13 +2059,6 @@ void playlist_init(void)
|
||||||
playlist->max_playlist_size * sizeof(*playlist->indices), &ops);
|
playlist->max_playlist_size * sizeof(*playlist->indices), &ops);
|
||||||
|
|
||||||
playlist->indices = core_get_data(handle);
|
playlist->indices = core_get_data(handle);
|
||||||
playlist->buffer_size =
|
|
||||||
AVERAGE_FILENAME_LENGTH * global_settings.max_files_in_dir;
|
|
||||||
|
|
||||||
handle = core_alloc_ex("playlist buf",
|
|
||||||
playlist->buffer_size, &ops);
|
|
||||||
playlist->buffer = core_get_data(handle);
|
|
||||||
playlist->buffer_handle = handle;
|
|
||||||
|
|
||||||
initalize_new_playlist(playlist, true);
|
initalize_new_playlist(playlist, true);
|
||||||
|
|
||||||
|
@ -2079,15 +2095,21 @@ void playlist_shutdown(void)
|
||||||
*/
|
*/
|
||||||
int playlist_add(const char *filename)
|
int playlist_add(const char *filename)
|
||||||
{
|
{
|
||||||
|
size_t indice = CHUNK_ALLOC_INVALID;
|
||||||
struct playlist_info* playlist = ¤t_playlist;
|
struct playlist_info* playlist = ¤t_playlist;
|
||||||
int len = strlen(filename);
|
int len = strlen(filename);
|
||||||
|
|
||||||
if(len+1 > playlist->buffer_size - playlist->buffer_end_pos)
|
if (!chunk_alloc_is_initialized(&playlist->name_chunk_buffer))
|
||||||
|
alloc_namebuffer();
|
||||||
|
|
||||||
|
if (chunk_alloc_is_initialized(&playlist->name_chunk_buffer))
|
||||||
|
indice = chunk_alloc(&playlist->name_chunk_buffer, len + 1);
|
||||||
|
|
||||||
|
if(indice == CHUNK_ALLOC_INVALID)
|
||||||
{
|
{
|
||||||
notify_buffer_full();
|
notify_buffer_full();
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(playlist->amount >= playlist->max_playlist_size)
|
if(playlist->amount >= playlist->max_playlist_size)
|
||||||
{
|
{
|
||||||
notify_buffer_full();
|
notify_buffer_full();
|
||||||
|
@ -2096,16 +2118,18 @@ int playlist_add(const char *filename)
|
||||||
|
|
||||||
playlist_mutex_lock(&(playlist->mutex));
|
playlist_mutex_lock(&(playlist->mutex));
|
||||||
|
|
||||||
playlist->indices[playlist->amount] = playlist->buffer_end_pos;
|
playlist->indices[playlist->amount] = indice;
|
||||||
#ifdef HAVE_DIRCACHE
|
#ifdef HAVE_DIRCACHE
|
||||||
dc_copy_filerefs(&playlist->dcfrefs[playlist->amount], NULL, 1);
|
dc_copy_filerefs(&playlist->dcfrefs[playlist->amount], NULL, 1);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
playlist->amount++;
|
playlist->amount++;
|
||||||
|
|
||||||
strcpy((char*)&playlist->buffer[playlist->buffer_end_pos], filename);
|
char *namebuf = (char*)chunk_get_data(&playlist->name_chunk_buffer, indice);
|
||||||
playlist->buffer_end_pos += len;
|
strcpy(namebuf, filename);
|
||||||
playlist->buffer[playlist->buffer_end_pos++] = '\0';
|
namebuf += len;
|
||||||
|
namebuf[0] = '\0';
|
||||||
|
chunk_put_data(&playlist->name_chunk_buffer, indice);
|
||||||
|
|
||||||
playlist_mutex_unlock(&(playlist->mutex));
|
playlist_mutex_unlock(&(playlist->mutex));
|
||||||
|
|
||||||
|
@ -2180,9 +2204,7 @@ int playlist_create_ex(struct playlist_info* playlist,
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
playlist->buffer_size = 0;
|
chunk_alloc_free(&playlist->name_chunk_buffer);
|
||||||
playlist->buffer_handle = -1;
|
|
||||||
playlist->buffer = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
new_playlist_unlocked(playlist, dir, file);
|
new_playlist_unlocked(playlist, dir, file);
|
||||||
|
@ -3662,9 +3684,7 @@ int playlist_save(struct playlist_info* playlist, char *filename,
|
||||||
if (strlcat(path, "_temp", sizeof(path)) >= sizeof (path))
|
if (strlcat(path, "_temp", sizeof(path)) >= sizeof (path))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
/* can ignore volatile here, because core_get_data() is called later */
|
struct chunk_alloc_header old_name_chunk_buffer = playlist->name_chunk_buffer;
|
||||||
char* old_buffer = (char*)playlist->buffer;
|
|
||||||
size_t old_buffer_size = playlist->buffer_size;
|
|
||||||
|
|
||||||
if (is_m3u8_name(path))
|
if (is_m3u8_name(path))
|
||||||
{
|
{
|
||||||
|
@ -3799,11 +3819,7 @@ int playlist_save(struct playlist_info* playlist, char *filename,
|
||||||
cpu_boost(false);
|
cpu_boost(false);
|
||||||
|
|
||||||
reset_old_buffer:
|
reset_old_buffer:
|
||||||
if (playlist->buffer_handle > 0)
|
playlist->name_chunk_buffer = old_name_chunk_buffer;
|
||||||
old_buffer = core_get_data(playlist->buffer_handle);
|
|
||||||
|
|
||||||
playlist->buffer = old_buffer;
|
|
||||||
playlist->buffer_size = old_buffer_size;
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
#include "kernel.h"
|
#include "kernel.h"
|
||||||
#include "metadata.h"
|
#include "metadata.h"
|
||||||
#include "rbpaths.h"
|
#include "rbpaths.h"
|
||||||
|
#include "chunk_alloc.h"
|
||||||
|
|
||||||
#define PLAYLIST_ATTR_QUEUED 0x01
|
#define PLAYLIST_ATTR_QUEUED 0x01
|
||||||
#define PLAYLIST_ATTR_INSERTED 0x02
|
#define PLAYLIST_ATTR_INSERTED 0x02
|
||||||
|
@ -84,10 +85,10 @@ struct playlist_info
|
||||||
global_settings.max_files_in_playlist */
|
global_settings.max_files_in_playlist */
|
||||||
int num_inserted_tracks; /* number of tracks inserted */
|
int num_inserted_tracks; /* number of tracks inserted */
|
||||||
volatile unsigned long *indices; /* array of indices */
|
volatile unsigned long *indices; /* array of indices */
|
||||||
int buffer_handle; /* handle to the below buffer (-1 if non-buflib) */
|
|
||||||
volatile char *buffer;/* buffer for in-ram playlists */
|
struct chunk_alloc_header name_chunk_buffer; /* chunk buffer for
|
||||||
int buffer_size; /* size of buffer */
|
in-ram playlist */
|
||||||
int buffer_end_pos; /* last position where buffer was written */
|
|
||||||
int index; /* index of current playing track */
|
int index; /* index of current playing track */
|
||||||
int first_index; /* index of first song in playlist */
|
int first_index; /* index of first song in playlist */
|
||||||
int amount; /* number of tracks in the index */
|
int amount; /* number of tracks in the index */
|
||||||
|
|
Loading…
Reference in a new issue