Configurable dir browser file buffer size. No more 400-file limit. No more whining.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@3661 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Linus Nielsen Feltzing 2003-05-09 16:01:21 +00:00
parent af2b7adefe
commit 20d031f9c7
19 changed files with 209 additions and 81 deletions

View File

@ -1507,3 +1507,13 @@ id: LANG_INVERT_LCD_INVERSE
desc: in settings_menu
eng: "Inverse"
new:
id: LANG_MAX_FILES_IN_DIR
desc: in settings_menu
eng: "Max files in dir browser"
new:
id: LANG_MAX_FILES_IN_PLAYLIST
desc: in settings_menu
eng: "Max playlist size"
new:

View File

@ -49,6 +49,7 @@
#include "language.h"
#include "wps-display.h"
#include "playlist.h"
#include "buffer.h"
char appsversion[]=APPSVERSION;
@ -65,6 +66,7 @@ void app_main(void)
void init(void)
{
init_threads();
buffer_init();
lcd_init();
font_init();
show_logo();
@ -97,6 +99,8 @@ void init(void)
system_init();
kernel_init();
buffer_init();
settings_reset();
lcd_init();
@ -165,6 +169,14 @@ void init(void)
settings_load();
status_init();
usb_start_monitoring();
power_init();
playlist_init();
tree_init();
/* This one must be the last one, since it wants the rest of the buffer
space */
mpeg_init( global_settings.volume,
global_settings.bass,
global_settings.treble,
@ -173,11 +185,6 @@ void init(void)
global_settings.bass_boost,
global_settings.avc,
global_settings.channel_config );
status_init();
usb_start_monitoring();
power_init();
playlist_init();
}
int main(void)

View File

@ -41,6 +41,7 @@
#include "fat.h"
#include "sleeptimer.h"
#include "wps.h"
#include "buffer.h"
#ifdef HAVE_FMRADIO
#include "radio.h"
#endif
@ -152,14 +153,7 @@ bool show_credits(void)
}
#ifdef SIMULATOR
#define mp3buf 0
#define mp3end 0
extern bool simulate_usb(void);
#else
/* defined in linker script */
extern unsigned char mp3buf[];
extern unsigned char mp3end[];
#endif
bool show_info(void)
{

View File

@ -37,6 +37,7 @@
#include "id3.h"
#include "screens.h"
#include "tree.h"
#include "buffer.h"
static char* selected_file = NULL;
static bool reload_dir = false;
@ -113,10 +114,6 @@ static void xingupdate(int percent)
}
/* defined in linker script */
extern unsigned char mp3buf[];
extern unsigned char mp3end[];
static int insert_data_in_file(char *fname, int fpos, char *buf, int num_bytes)
{
int readlen;

View File

@ -31,6 +31,7 @@
#include "status.h"
#include "applimits.h"
#include "screens.h"
#include "buffer.h"
#ifdef HAVE_LCD_BITMAP
#include "icons.h"
#include "widgets.h"
@ -42,10 +43,8 @@ static struct playlist_info playlist;
#define QUEUE_FILE ROCKBOX_DIR "/.queue_file"
#define PLAYLIST_BUFFER_SIZE (AVERAGE_FILENAME_LENGTH*MAX_FILES_IN_DIR)
static unsigned char playlist_buffer[PLAYLIST_BUFFER_SIZE];
static unsigned char *playlist_buffer;
extern unsigned char mp3buf[],mp3end;
static int playlist_end_pos = 0;
static char now_playing[MAX_PATH+1];
@ -53,6 +52,11 @@ static char now_playing[MAX_PATH+1];
void playlist_init(void)
{
playlist.fd = -1;
playlist.max_playlist_size = global_settings.max_files_in_playlist;
playlist.indices = buffer_alloc(playlist.max_playlist_size);
playlist.buffer_size =
AVERAGE_FILENAME_LENGTH * global_settings.max_files_in_dir;
playlist_buffer = buffer_alloc(playlist.buffer_size);
}
/*
@ -291,7 +295,7 @@ int playlist_add(char *filename)
{
int len = strlen(filename);
if(len+2 > PLAYLIST_BUFFER_SIZE - playlist_end_pos)
if(len+2 > playlist.buffer_size - playlist_end_pos)
return -1;
strcpy(&playlist_buffer[playlist_end_pos], filename);
@ -655,7 +659,7 @@ void add_indices_to_playlist(void)
int i = 0;
int count = 0;
unsigned char* buffer = playlist_buffer;
int buflen = PLAYLIST_BUFFER_SIZE;
int buflen = playlist.buffer_size;
bool store_index;
unsigned char *p;
@ -667,7 +671,7 @@ void add_indices_to_playlist(void)
#ifndef SIMULATOR
/* use mp3 buffer for maximum load speed */
buflen = (&mp3end - &mp3buf[0]);
buflen = (mp3end - mp3buf);
buffer = mp3buf;
#endif
}
@ -705,7 +709,7 @@ void add_indices_to_playlist(void)
/* Store a new entry */
playlist.indices[ playlist.amount ] = i+count;
playlist.amount++;
if ( playlist.amount >= MAX_PLAYLIST_SIZE ) {
if ( playlist.amount >= playlist.max_playlist_size ) {
lcd_clear_display();
lcd_puts(0,0,str(LANG_PLAYINDICES_PLAYLIST));
lcd_puts(0,1,str(LANG_PLAYINDICES_BUFFER));
@ -772,7 +776,7 @@ void sort_playlist(bool start_current)
if (playlist.amount > 0)
{
qsort(&playlist.indices, playlist.amount, sizeof(playlist.indices[0]), compare);
qsort(playlist.indices, playlist.amount, sizeof(playlist.indices[0]), compare);
}
if (start_current)

View File

@ -31,7 +31,10 @@ struct playlist_info
char filename[MAX_PATH]; /* path name of m3u playlist on disk */
int fd; /* file descriptor of the open playlist */
int dirlen; /* Length of the path to the playlist file */
int indices[MAX_PLAYLIST_SIZE]; /* array of indices */
int *indices; /* array of indices */
int max_playlist_size; /* Max number of files in playlist. Mirror of
global_settings.max_files_in_playlist */
int buffer_size; /* Playlist buffer size */
int index; /* index of current playing track */
int first_index; /* index of first song in playlist */
int seed; /* random seed */

View File

@ -126,6 +126,8 @@ modified unless the header & checksum test fails.
Rest of config block, only saved to disk:
0xAA Max number of files in playlist (1000-20000)
0xAC Max number of files in dir (50-10000)
0xAE fade on pause/unpause/stop setting (bit 0)
caption backlight (bit 1)
0xB0 peak meter clip hold timeout (bit 0-4), peak meter performance (bit 7)
@ -379,6 +381,14 @@ int settings_save( void )
config_block[0x29]=(unsigned char)(global_settings.topruntime >> 8);
}
config_block[0xaa] = (unsigned char)
global_settings.max_files_in_playlist & 0xff;
config_block[0xab] = (unsigned char)
(global_settings.max_files_in_playlist >> 8) & 0xff;
config_block[0xac] = (unsigned char)
global_settings.max_files_in_dir & 0xff;
config_block[0xad] = (unsigned char)
(global_settings.max_files_in_dir >> 8) & 0xff;
config_block[0xae] = (unsigned char)
((global_settings.fade_on_stop & 1) |
((global_settings.caption_backlight & 1) << 1));
@ -695,6 +705,14 @@ void settings_load(void)
if (config_block[0xae] != 0xff)
global_settings.fade_on_stop = config_block[0xae];
if (config_block[0xac] != 0xff)
global_settings.max_files_in_dir =
config_block[0xac] | (config_block[0xad] << 8);
if (config_block[0xaa] != 0xff)
global_settings.max_files_in_playlist =
config_block[0xaa] | (config_block[0xab] << 8);
memcpy(&global_settings.resume_first_index, &config_block[0xF4], 4);
memcpy(&global_settings.resume_seed, &config_block[0xF8], 4);
@ -1025,6 +1043,12 @@ bool settings_load_config(char* file)
#endif
else if (!strcasecmp(name, "volume fade"))
set_cfg_bool(&global_settings.fade_on_stop, value);
else if (!strcasecmp(name, "max files in dir"))
set_cfg_int(&global_settings.max_files_in_dir, value,
50, 10000);
else if (!strcasecmp(name, "max files in playlist"))
set_cfg_int(&global_settings.max_files_in_playlist, value,
1000, 20000);
}
close(fd);
@ -1302,6 +1326,11 @@ bool settings_save_config(void)
boolopt[global_settings.rec_editable]);
#endif
fprintf(fd, "max files in dir: %d\r\n", global_settings.max_files_in_dir);
fprintf(fd, "max files in playlist: %d\r\n",
global_settings.max_files_in_playlist);
close(fd);
lcd_clear_display();
@ -1384,32 +1413,8 @@ void settings_reset(void) {
global_settings.runtime = 0;
global_settings.topruntime = 0;
global_settings.fade_on_stop = true;
}
/*
* dump the list of current settings
*/
void settings_display(void)
{
#ifdef DEBUG
DEBUGF( "\nsettings_display()\n" );
DEBUGF( "\nvolume:\t\t%d\nbalance:\t%d\nbass:\t\t%d\ntreble:\t\t%d\n"
"loudness:\t%d\nbass boost:\t%d\n",
global_settings.volume,
global_settings.balance,
global_settings.bass,
global_settings.treble,
global_settings.loudness,
global_settings.bass_boost );
DEBUGF( "contrast:\t%d\ninvert:\t%d\npoweroff:\t%d\nbacklight_timeout:\t%d\n",
global_settings.contrast,
global_settings.invert,
global_settings.poweroff,
global_settings.backlight_timeout );
#endif
global_settings.max_files_in_dir = 400;
global_settings.max_files_in_playlist = 10000;
}
bool set_bool(char* string, bool* variable )

View File

@ -154,6 +154,16 @@ struct user_settings
bool fade_on_stop; /* fade on pause/unpause/stop */
bool caption_backlight; /* turn on backlight at end and start of track */
#ifdef HAVE_FMRADIO
int fm_freq_step; /* Frequency step for manual tuning, in kHz */
bool fm_force_mono; /* Forces Mono mode if true */
bool fm_full_range; /* Enables full 10MHz-160MHz range if true, else
only 88MHz-108MHz */
#endif
int max_files_in_dir; /* Max entries in directory (file browser) */
int max_files_in_playlist; /* Max entries in playlist */
};
/* prototypes */
@ -209,9 +219,3 @@ enum { REPEAT_OFF, REPEAT_ALL, REPEAT_ONE, NUM_REPEAT_MODES };
enum { SHOW_ALL, SHOW_SUPPORTED, SHOW_MUSIC, SHOW_PLAYLIST, NUM_FILTER_MODES };
#endif /* __SETTINGS_H__ */

View File

@ -567,6 +567,20 @@ static bool poweroff(void)
}
#endif
static bool max_files_in_dir(void)
{
return set_int(str(LANG_MAX_FILES_IN_DIR), "",
&global_settings.max_files_in_dir,
NULL, 50, 50, 10000 );
}
static bool max_files_in_playlist(void)
{
return set_int(str(LANG_MAX_FILES_IN_PLAYLIST), "",
&global_settings.max_files_in_playlist,
NULL, 1000, 1000, 10000 );
}
static bool buffer_margin(void)
{
return set_int(str(LANG_MP3BUFFER_MARGIN), "s",
@ -574,7 +588,7 @@ static bool buffer_margin(void)
mpeg_set_buffer_margin, 1, 0, 7 );
}
static bool ff_rewind_min_step(void)
static bool ff_rewind_min_step(void)
{
char* names[] = { "1s", "2s", "3s", "4s",
"5s", "6s", "8s", "10s",
@ -783,6 +797,8 @@ static bool system_settings_menu(void)
#ifdef HAVE_ATA_POWER_OFF
{ str(LANG_POWEROFF), poweroff },
#endif
{ str(LANG_MAX_FILES_IN_DIR), max_files_in_dir },
{ str(LANG_MAX_FILES_IN_PLAYLIST), max_files_in_playlist },
#ifndef SIMULATOR
{ str(LANG_BATTERY_CAPACITY), battery_capacity },
#endif

View File

@ -51,21 +51,25 @@
#include "screens.h"
#include "keyboard.h"
#include "onplay.h"
#include "buffer.h"
#ifdef HAVE_LCD_BITMAP
#include "widgets.h"
#endif
#define NAME_BUFFER_SIZE (AVERAGE_FILENAME_LENGTH * MAX_FILES_IN_DIR)
/* Mirror of global_settings.max_files_in_dir */
int max_files_in_dir;
static char name_buffer[NAME_BUFFER_SIZE];
static int name_buffer_length;
static char *name_buffer;
static int name_buffer_size; /* Size of allocated buffer */
static int name_buffer_length; /* Currently used amount */
struct entry {
short attr; /* FAT attributes + file type flags */
char *name;
};
static struct entry dircache[MAX_FILES_IN_DIR];
static struct entry *dircache;
static int dircursor;
static int dirstart;
static int dirlevel;
@ -249,7 +253,7 @@ static int showdir(char *path, int start)
name_buffer_length = 0;
dir_buffer_full = false;
for ( i=0; i<MAX_FILES_IN_DIR; i++ ) {
for ( i=0; i < max_files_in_dir; i++ ) {
int len;
struct dirent *entry = readdir(dir);
struct entry* dptr = &dircache[i];
@ -333,7 +337,7 @@ static int showdir(char *path, int start)
continue;
}
if (len > NAME_BUFFER_SIZE - name_buffer_length - 1) {
if (len > name_buffer_size - name_buffer_length - 1) {
/* Tell the world that we ran out of buffer space */
dir_buffer_full = true;
break;
@ -348,7 +352,7 @@ static int showdir(char *path, int start)
lastdir[sizeof(lastdir)-1] = 0;
qsort(dircache,filesindir,sizeof(struct entry),compare);
if ( dir_buffer_full || filesindir == MAX_FILES_IN_DIR ) {
if ( dir_buffer_full || filesindir == max_files_in_dir ) {
#ifdef HAVE_LCD_CHARCELLS
lcd_double_height(false);
#endif
@ -1317,3 +1321,14 @@ bool create_playlist(void)
return true;
}
void tree_init(void)
{
/* We copy the settings value in case it is changed by the user. We can't
use the next reboot. */
max_files_in_dir = global_settings.max_files_in_dir;
name_buffer_size = AVERAGE_FILENAME_LENGTH * max_files_in_dir;
name_buffer = buffer_alloc(name_buffer_size);
dircache = buffer_alloc(max_files_in_dir * sizeof(struct entry));
}

View File

@ -32,6 +32,7 @@
#define TREE_ATTR_LNG 0x1000 /* binary lang file */
#define TREE_ATTR_MASK 0xffd0 /* which bits tree.c uses (above + DIR) */
void tree_init(void);
void browse_root(void);
void set_current_file(char *path);
bool dirbrowse(char *root);

View File

@ -77,7 +77,7 @@ SECTIONS
.mp3buf :
{
_mp3buf = .;
_mp3buffer = .;
} > DRAM
.mp3end ENDADDR - 0x300:

43
firmware/buffer.c Normal file
View File

@ -0,0 +1,43 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2002 by Linus Nielsen Feltzing
*
* All files in this archive are subject to the GNU General Public License.
* See the file COPYING in the source tree root for full license agreement.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#include <stdio.h>
#include "buffer.h"
#ifdef SIMULATOR
unsigned char mp3buffer[0x100000];
unsigned char mp3end[1];
#else
/* defined in linker script */
extern unsigned char mp3buffer[];
#endif
unsigned char *mp3buf;
void buffer_init(void)
{
mp3buf = mp3buffer;
}
void *buffer_alloc(size_t size)
{
void *retval = mp3buf;
mp3buf += size;
return retval;
}

30
firmware/export/buffer.h Normal file
View File

@ -0,0 +1,30 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2002 by Linus Nielsen Feltzing
*
* All files in this archive are subject to the GNU General Public License.
* See the file COPYING in the source tree root for full license agreement.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#ifndef BUFFER_H
#define BUFFER_H
/* defined in linker script */
extern unsigned char mp3end[];
extern unsigned char *mp3buf;
void buffer_init(void);
void *buffer_alloc(size_t size);
#endif

View File

@ -34,6 +34,7 @@
#include "debug.h"
#include "mp3data.h"
#include "file.h"
#include "buffer.h"
#define DEBUG_VERBOSE
@ -253,13 +254,6 @@ unsigned long find_next_frame(int fd, int *offset, int max_offset, unsigned long
return header;
}
#ifdef SIMULATOR
unsigned char mp3buf[0x100000];
unsigned char mp3end[1];
#else
extern unsigned char mp3buf[];
extern unsigned char mp3end[];
#endif
static int fnf_read_index;
static int fnf_buf_len;

View File

@ -27,6 +27,7 @@
#include <kernel.h>
#include "thread.h"
#include "mp3data.h"
#include "buffer.h"
#ifndef SIMULATOR
#include "i2c.h"
#include "mas.h"
@ -460,10 +461,6 @@ static struct event_queue mpeg_queue;
static char mpeg_stack[DEFAULT_STACK_SIZE + 0x1000];
static char mpeg_thread_name[] = "mpeg";
/* defined in linker script */
extern unsigned char mp3buf[];
extern unsigned char mp3end[];
static int mp3buflen;
static int mp3buf_write;
static int mp3buf_swapwrite;

View File

@ -26,6 +26,7 @@
#include "system.h"
#include "i2c.h"
#include "string.h"
#include "buffer.h"
#define IRQ0_EDGE_TRIGGER 0x80
@ -36,6 +37,8 @@ static void rolo_error(char *text)
lcd_puts_scroll(0, 1, text);
lcd_update();
button_get(true);
button_get(true);
button_get(true);
lcd_stop_scroll();
}
/***************************************************************************
@ -49,7 +52,6 @@ int rolo_load(char* filename)
{
int fd,slen;
unsigned long length,file_length,i;
extern unsigned char mp3buf[],mp3end;
unsigned short checksum,file_checksum;
unsigned char* ramstart = (void*)0x09000000;
void (*start_func)(void) = (void*)ramstart + 0x200;
@ -88,7 +90,7 @@ int rolo_load(char* filename)
lseek(fd, FIRMWARE_OFFSET_FILE_DATA, SEEK_SET);
/* verify that file can be read and descrambled */
if ((&mp3buf[0] + (2*length)+4) >= &mp3end) {
if ((mp3buf + (2*length)+4) >= &mp3end) {
rolo_error("Not enough room to load file");
return -1;
}

View File

@ -89,7 +89,7 @@ else
LCDSRSC = lcd-playersim.c lcd-player.c lcd-player-charset.c font-player.c
endif
FIRMSRCS = $(LCDSRSC) id3.c mp3data.c usb.c mpeg.c powermgmt.c power.c \
sprintf.c
sprintf.c buffer.c
APPS = main.c tree.c menu.c credits.c main_menu.c icons.c language.c \
playlist.c wps.c wps-display.c settings.c status.c \
@ -272,6 +272,9 @@ $(OBJDIR)/mpeg.o: $(FIRMWAREDIR)/mpeg.c
$(OBJDIR)/sprintf.o: $(COMMON)/sprintf.c
$(CC) $(CFLAGS) -c $< -o $@
$(OBJDIR)/buffer.o: $(FIRMWAREDIR)/buffer.c
$(CC) $(CFLAGS) -c $< -o $@
$(OBJDIR)/ctype.o: $(COMMON)/ctype.c
$(CC) $(CFLAGS) $(APPINCLUDES) -c $< -o $@

View File

@ -88,7 +88,7 @@ else
LCDSRSC = lcd-playersim.c lcd-player.c font-player.c lcd-player-charset.c
endif
FIRMSRCS = $(LCDSRSC) id3.c debug.c usb.c mpeg.c power.c\
powermgmt.c panic.c mp3data.c sprintf.c
powermgmt.c panic.c mp3data.c sprintf.c buffer.c
APPS = main.c tree.c menu.c credits.c main_menu.c language.c\
playlist.c wps.c wps-display.c settings.c status.c icons.c\
@ -247,6 +247,9 @@ $(OBJDIR)/mpeg.o: $(FIRMWAREDIR)/mpeg.c
$(OBJDIR)/sprintf.o: $(COMMON)/sprintf.c
$(CC) $(CFLAGS) -c $< -o $@
$(OBJDIR)/buffer.o: $(FIRMWAREDIR)/buffer.c
$(CC) $(CFLAGS) -c $< -o $@
$(OBJDIR)/ctype.o: $(COMMON)/ctype.c
$(CC) $(CFLAGS) $(APPINCLUDES) -c $< -o $@