1
0
Fork 0
forked from len0rd/rockbox

FS#7971 - mpegplayer - start menu loads quicker - menu clean up - code clean up

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@15143 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Robert Kukla 2007-10-16 14:23:50 +00:00
parent 94c23df2ab
commit 0b911fefea
4 changed files with 264 additions and 237 deletions

View file

@ -54,8 +54,6 @@ static void * mpeg_malloc_internal (unsigned char *mallocbuf,
x = &mallocbuf[*mem_ptr];
*mem_ptr += (size + 3) & ~3; /* Keep memory 32-bit aligned */
rb->memset(x,0,size);
return x;
(void)reason;
}
@ -75,7 +73,6 @@ size_t mpeg_alloc_init(unsigned char *buf, size_t mallocsize,
mallocbuf = (char *)(((intptr_t)buf + 15) & ~15);
/* Adjust for real size */
bufsize -= mallocbuf - buf;
rb->memset(buf,0,bufsize);
/* Separate allocator for video */
libmpeg2size = (libmpeg2size + 15) & ~15;

View file

@ -99,54 +99,78 @@ static struct configdata config[] =
{TYPE_INT, 0, 2, &settings.showfps, "Show FPS", NULL, NULL},
{TYPE_INT, 0, 2, &settings.limitfps, "Limit FPS", NULL, NULL},
{TYPE_INT, 0, 2, &settings.skipframes, "Skip frames", NULL, NULL},
{TYPE_INT, 0, INT_MAX, &settings.resume_count, "Resume count",
NULL, NULL},
#if defined(TOSHIBA_GIGABEAT_F) || defined(SANSA_E200)
{TYPE_INT, 0, INT_MAX, &settings.displayoptions, "Display options",
NULL, NULL},
#endif
};
enum mpeg_menu_ids
{
__MPEG_OPTION_START = -1,
#if defined(TOSHIBA_GIGABEAT_F) || defined(SANSA_E200)
MPEG_OPTION_DISPLAY_SETTINGS,
#endif
MPEG_OPTION_DISPLAY_FPS,
MPEG_OPTION_LIMIT_FPS,
MPEG_OPTION_SKIP_FRAMES,
MPEG_OPTION_CLEAR_RESUMES,
MPEG_OPTION_QUIT,
};
static const struct opt_items noyes[2] = {
{ "No", -1 },
{ "Yes", -1 },
};
#if defined(TOSHIBA_GIGABEAT_F) || defined(SANSA_E200)
static bool set_option_dithering(void)
{
int val = (settings.displayoptions & LCD_YUV_DITHER) ? 1 : 0;
rb->set_option("Dithering", &val, INT, noyes, 2, NULL);
settings.displayoptions = (settings.displayoptions & ~LCD_YUV_DITHER)
| ((val != 0) ? LCD_YUV_DITHER : 0);
rb->lcd_yuv_set_options(settings.displayoptions);
return false;
}
static void display_options(void)
{
int result;
int menu_id;
int options_quit = 0;
static const struct menu_item items[] = {
{ "Dithering", set_option_dithering },
#if defined(TOSHIBA_GIGABEAT_F) || defined(SANSA_E200)
[MPEG_OPTION_DITHERING] =
{ "Dithering", NULL },
#endif /* #ifdef TOSHIBA_GIGABEAT_F */
[MPEG_OPTION_DISPLAY_FPS] =
{ "Display FPS", NULL },
[MPEG_OPTION_LIMIT_FPS] =
{ "Limit FPS", NULL },
[MPEG_OPTION_SKIP_FRAMES] =
{ "Skip frames", NULL },
};
int m = menu_init(rb, items, ARRAYLEN(items),
menu_id = menu_init(rb, items, ARRAYLEN(items),
NULL, NULL, NULL, NULL);
menu_run(m);
menu_exit(m);
}
rb->button_clear_queue();
while(options_quit == 0)
{
result = menu_show(menu_id);
switch (result)
{
#if defined(TOSHIBA_GIGABEAT_F) || defined(SANSA_E200)
case MPEG_OPTION_DITHERING:
result = (settings.displayoptions & LCD_YUV_DITHER) ? 1 : 0;
rb->set_option("Dithering", &result, INT, noyes, 2, NULL);
settings.displayoptions = (settings.displayoptions & ~LCD_YUV_DITHER)
| ((result != 0) ? LCD_YUV_DITHER : 0);
rb->lcd_yuv_set_options(settings.displayoptions);
break;
#endif /* #ifdef TOSHIBA_GIGABEAT_F */
case MPEG_OPTION_DISPLAY_FPS:
rb->set_option("Display FPS",&settings.showfps,INT,
noyes, 2, NULL);
break;
case MPEG_OPTION_LIMIT_FPS:
rb->set_option("Limit FPS",&settings.limitfps,INT,
noyes, 2, NULL);
break;
case MPEG_OPTION_SKIP_FRAMES:
rb->set_option("Skip frames",&settings.skipframes,INT,
noyes, 2, NULL);
break;
default:
options_quit=1;
break;
}
}
menu_exit(menu_id);
}
void draw_slider(int slider_ypos, int max_val, int current_val)
{
@ -181,18 +205,18 @@ void draw_slider(int slider_ypos, int max_val, int current_val)
int get_start_time(int play_time, int in_file)
{
int quit = 0;
int seek_quit = 0;
int button = 0;
int resume_time = settings.resume_time;
int slider_ypos = LCD_HEIGHT-45;
int seek_rtn;
int seek_return;
slider_state = state0;
thumbDelayTimer = *(rb->current_tick);
rb->lcd_clear_display();
rb->lcd_update();
while(quit == 0)
while(seek_quit == 0)
{
button = rb->button_get(false);
switch (button)
@ -234,18 +258,13 @@ int get_start_time(int play_time, int in_file)
thumbDelayTimer = *(rb->current_tick);
break;
case MPEG_SELECT:
quit = 1;
break;
settings.resume_time = resume_time;
case MPEG_EXIT:
resume_time = -1;
quit = 1;
seek_quit = 1;
break;
default:
if (rb->default_event_handler(button) == SYS_USB_CONNECTED)
{
resume_time = -1;
quit = 1;
}
seek_quit = 1;
break;
}
@ -267,15 +286,15 @@ int get_start_time(int play_time, int in_file)
slider_state = state2;
if (resume_time == 0)
{
seek_rtn = 0;
seek_return = 0;
slider_state = state5;
}
draw_slider(slider_ypos, play_time, resume_time);
break;
case state2:
if ( (seek_rtn = seek_PTS(in_file, resume_time, 1)) >= 0)
if ( (seek_return = seek_PTS(in_file, resume_time, 1)) >= 0)
slider_state = state3;
else if (seek_rtn == -101)
else if (seek_return == -101)
{
slider_state = state0;
thumbDelayTimer = *(rb->current_tick);
@ -297,12 +316,12 @@ int get_start_time(int play_time, int in_file)
}
}
return resume_time;
return button;
}
int mpeg_start_menu(int play_time, int in_file)
enum mpeg_start_id mpeg_start_menu(int play_time, int in_file)
{
int m;
int menu_id;
int result = 0;
int menu_quit = 0;
@ -313,59 +332,60 @@ int mpeg_start_menu(int play_time, int in_file)
rb->snprintf(resume_str, sizeof(resume_str),
"Resume time (min): %d.%d", time_hol, time_rem);
struct menu_item items[] = {
struct menu_item items[] =
{
[MPEG_START_RESTART] =
{ "Play from beginning", NULL },
[MPEG_START_RESUME] =
{ resume_str, NULL },
[MPEG_START_SEEK] =
{ "Set start time (min)", NULL },
[MPEG_START_QUIT] =
{ "Quit mpegplayer", NULL },
};
m = menu_init(rb, items, sizeof(items) / sizeof(*items),
menu_id = menu_init(rb, items, sizeof(items) / sizeof(*items),
NULL, NULL, NULL, NULL);
rb->button_clear_queue();
while(menu_quit == 0)
{
result = menu_show(m);
result = menu_show(menu_id);
switch (result)
{
case 0:
case MPEG_START_RESTART:
settings.resume_time = 0;
menu_quit = 1;
result = 0;
break;
case 1:
case MPEG_START_RESUME:
menu_quit = 1;
result = settings.resume_time;
break;
case 2:
case MPEG_START_SEEK:
#ifndef HAVE_LCD_COLOR
gray_show(true);
#endif
if ((result = get_start_time(play_time, in_file)) >= 0)
if (get_start_time(play_time, in_file) == MPEG_SELECT)
menu_quit = 1;
#ifndef HAVE_LCD_COLOR
gray_show(false);
#endif
break;
case 3:
case MPEG_START_QUIT:
menu_quit = 1;
result = -1;
break;
default:
if (result == MENU_ATTACHED_USB)
{
result = MPEG_START_QUIT;
menu_quit = 1;
result = -1;
}
break;
}
}
menu_exit(m);
settings.resume_time = result;
return (int)result;
menu_exit(menu_id);
return result;
}
void clear_resume_count(void)
@ -380,9 +400,9 @@ void clear_resume_count(void)
configfile_update_entry(SETTINGS_FILENAME, "Resume count", 0);
}
bool mpeg_menu(void)
enum mpeg_menu_id mpeg_menu(void)
{
int m;
int menu_id;
int result;
int menu_quit=0;
@ -392,68 +412,48 @@ bool mpeg_menu(void)
"Clear all resumes: %u", settings.resume_count);
struct menu_item items[] = {
#if defined(TOSHIBA_GIGABEAT_F) || defined(SANSA_E200)
[MPEG_OPTION_DISPLAY_SETTINGS] =
[MPEG_MENU_DISPLAY_SETTINGS] =
{ "Display Options", NULL },
#endif
[MPEG_OPTION_DISPLAY_FPS] =
{ "Display FPS", NULL },
[MPEG_OPTION_LIMIT_FPS] =
{ "Limit FPS", NULL },
[MPEG_OPTION_SKIP_FRAMES] =
{ "Skip frames", NULL },
[MPEG_OPTION_CLEAR_RESUMES] =
[MPEG_MENU_CLEAR_RESUMES] =
{ clear_str, NULL },
[MPEG_OPTION_QUIT] =
[MPEG_MENU_QUIT] =
{ "Quit mpegplayer", NULL },
};
m = menu_init(rb, items, ARRAYLEN(items), NULL, NULL, NULL, NULL);
menu_id = menu_init(rb, items, ARRAYLEN(items),
NULL, NULL, NULL, NULL);
rb->button_clear_queue();
while (!menu_quit) {
result=menu_show(m);
while (menu_quit == 0)
{
result=menu_show(menu_id);
switch(result)
{
#if defined(TOSHIBA_GIGABEAT_F) || defined(SANSA_E200)
case MPEG_OPTION_DISPLAY_SETTINGS:
case MPEG_MENU_DISPLAY_SETTINGS:
display_options();
break;
#endif
case MPEG_OPTION_DISPLAY_FPS:
rb->set_option("Display FPS",&settings.showfps,INT,
noyes, 2, NULL);
break;
case MPEG_OPTION_LIMIT_FPS:
rb->set_option("Limit FPS",&settings.limitfps,INT,
noyes, 2, NULL);
break;
case MPEG_OPTION_SKIP_FRAMES:
rb->set_option("Skip frames",&settings.skipframes,INT,
noyes, 2, NULL);
break;
case MPEG_OPTION_CLEAR_RESUMES:
case MPEG_MENU_CLEAR_RESUMES:
clear_resume_count();
rb->snprintf(clear_str, sizeof(clear_str),
"Clear all resumes: %u", 0);
break;
case MPEG_OPTION_QUIT:
case MPEG_MENU_QUIT:
default:
menu_quit=1;
if (result == MENU_ATTACHED_USB)
result = MPEG_OPTION_QUIT;
result = MPEG_MENU_QUIT;
break;
}
}
menu_exit(m);
menu_exit(menu_id);
rb->lcd_clear_display();
rb->lcd_update();
return (result==MPEG_OPTION_QUIT);
return result;
}
void init_settings(const char* filename)
@ -469,15 +469,9 @@ void init_settings(const char* filename)
configfile_init(rb);
/* If the config file don't contain resume count
or the load fails, then rebuild the config file.
This eliminates the worry for older config files
having unused data. */
if (((settings.resume_count = configfile_get_value
(SETTINGS_FILENAME, "Resume count")) < 0) ||
(configfile_load(SETTINGS_FILENAME, config,
if (configfile_load(SETTINGS_FILENAME, config,
sizeof(config)/sizeof(*config),
SETTINGS_MIN_VERSION) < 0))
SETTINGS_MIN_VERSION) < 0)
{
/* Generate a new config file with default values */
configfile_save(SETTINGS_FILENAME, config,
@ -498,8 +492,6 @@ void init_settings(const char* filename)
if (settings.resume_count < 0)
{
settings.resume_count = 0;
/* add this place holder so the count is above resume entries */
configfile_update_entry(SETTINGS_FILENAME, "Resume count", 0);
}

View file

@ -1,6 +1,31 @@
#include "plugin.h"
enum mpeg_option_id
{
#if defined(TOSHIBA_GIGABEAT_F) || defined(SANSA_E200)
MPEG_OPTION_DITHERING,
#endif
MPEG_OPTION_DISPLAY_FPS,
MPEG_OPTION_LIMIT_FPS,
MPEG_OPTION_SKIP_FRAMES,
};
enum mpeg_start_id
{
MPEG_START_RESTART,
MPEG_START_RESUME,
MPEG_START_SEEK,
MPEG_START_QUIT,
};
enum mpeg_menu_id
{
MPEG_MENU_DISPLAY_SETTINGS,
MPEG_MENU_CLEAR_RESUMES,
MPEG_MENU_QUIT,
};
struct mpeg_settings {
int showfps; /* flag to display fps */
int limitfps; /* flag to limit fps */
@ -8,7 +33,6 @@ struct mpeg_settings {
int resume_count; /* total # of resumes in config file */
int resume_time; /* resume time for current mpeg (in half minutes) */
char resume_filename[128]; /* filename of current mpeg */
#if defined(TOSHIBA_GIGABEAT_F) || defined(SANSA_E200)
int displayoptions;
#endif
@ -17,8 +41,8 @@ struct mpeg_settings {
extern struct mpeg_settings settings;
int get_start_time(int play_time, int in_file);
int mpeg_start_menu(int play_time, int in_file);
bool mpeg_menu(void);
enum mpeg_start_id mpeg_start_menu(int play_time, int in_file);
enum mpeg_menu_id mpeg_menu(void);
void init_settings(const char* filename);
void save_settings(void);
void clear_resume_count(void);

View file

@ -1042,7 +1042,7 @@ static inline int32_t clip_sample(int32_t sample)
static int button_loop(void)
{
bool result;
int result;
int vol, minvol, maxvol;
int button;
@ -1118,15 +1118,19 @@ static int button_loop(void)
/* The menu can change the font, so restore */
rb->lcd_setfont(FONT_SYSFIXED);
if (result) {
switch (result)
{
case MPEG_MENU_QUIT:
settings.resume_time = (int)(get_stream_time()/CLOCK_RATE/
30-start_pts_time);
str_send_msg(&video_str, STREAM_QUIT, 0);
audio_str.status = STREAM_STOPPED;
} else {
break;
default:
audio_str.status = STREAM_PLAYING;
str_send_msg(&video_str, STREAM_PLAY, 0);
pcm_playback_play_pause(true);
break;
}
break;
@ -2203,6 +2207,7 @@ ssize_t seek_PTS( int in_file, int start_time, int accept_button )
enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
{
int status = PLUGIN_ERROR; /* assume failure */
int result;
int start_time = -1;
void* audiobuf;
ssize_t audiosize;
@ -2295,8 +2300,6 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
rb->lcd_set_foreground(LCD_WHITE);
rb->lcd_set_background(LCD_BLACK);
#endif
rb->lcd_clear_display();
rb->lcd_update();
init_settings((char*)parameter);
@ -2312,10 +2315,21 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
find_end_pts( in_file );
/* start menu */
start_time = mpeg_start_menu(end_pts_time-start_pts_time, in_file);
if ( start_time == -1 )
rb->lcd_clear_display();
rb->lcd_update();
result = mpeg_start_menu(end_pts_time-start_pts_time, in_file);
switch (result)
{
case MPEG_START_QUIT:
return 0;
else if ( start_time < 0 )
default:
start_time = settings.resume_time;
break;
}
/* basic time checks */
if ( start_time < 0 )
start_time = 0;
else if ( start_time > (end_pts_time-start_pts_time) )
start_time = (end_pts_time-start_pts_time);