From ea255fbc3a5842d200e943522cea9bd2cb701dd6 Mon Sep 17 00:00:00 2001 From: Michael Sevakis Date: Fri, 22 Jun 2007 09:34:57 +0000 Subject: Prevent initial spinup when starting first file when in a stopped state on non-RTC targets. Fix some states that are dangerous on SWCODEC and could result in data loss. Had to make plugin API incopatible since specified numbered filename creation is enabled now on all non-RTC targets with recording; increase version and sort the items that looked like they had a place to go. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@13683 a1c6a512-1295-4272-9138-f99709370657 --- apps/misc.h | 6 +-- apps/plugin.c | 24 ++++----- apps/plugin.h | 40 +++++++-------- apps/recorder/recording.c | 127 ++++++++++++++++++++++++++++------------------ 4 files changed, 110 insertions(+), 87 deletions(-) (limited to 'apps') diff --git a/apps/misc.h b/apps/misc.h index b0adb92a0e..25937fae29 100644 --- a/apps/misc.h +++ b/apps/misc.h @@ -38,9 +38,9 @@ char *output_dyn_value(char *buf, int buf_size, int value, * less than zero to number automatically. The final number used will also * be returned in *num. If *num is >= 0 then *num will be incremented by * one. */ -#if CONFIG_CODEC == SWCODEC && defined(HAVE_RECORDING) && (CONFIG_RTC == 0) -/* this feature is needed by SWCODEC recording without a RTC to prevent - disk access when changing files */ +#if defined(HAVE_RECORDING) && (CONFIG_RTC == 0) +/* this feature is needed by recording without a RTC to prevent disk access + when changing files */ #define IF_CNFN_NUM_(...) __VA_ARGS__ #define IF_CNFN_NUM #else diff --git a/apps/plugin.c b/apps/plugin.c index ca0b8a2ba6..e81ae25ed1 100644 --- a/apps/plugin.c +++ b/apps/plugin.c @@ -104,6 +104,7 @@ static const struct plugin_api rockbox_api = { lcd_get_background, lcd_bitmap_part, lcd_bitmap, + lcd_get_backdrop, lcd_set_backdrop, #endif #if LCD_DEPTH == 16 @@ -217,6 +218,7 @@ static const struct plugin_api rockbox_api = { #endif ata_spindown, reload_directory, + create_numbered_filename, /* dir */ PREFIX(opendir), @@ -241,6 +243,7 @@ static const struct plugin_api rockbox_api = { ¤t_tick, default_event_handler, default_event_handler_ex, + threads, create_thread, remove_thread, reset_poweroff_timer, @@ -403,8 +406,12 @@ static const struct plugin_api rockbox_api = { gui_syncstatusbar_draw, /* options */ set_option, + set_bool_options, set_int, set_bool, +#ifdef HAVE_LCD_COLOR + set_color, +#endif /* action handling */ get_custom_action, @@ -470,12 +477,6 @@ static const struct plugin_api rockbox_api = { wheel_status, wheel_send_events, #endif -#if LCD_DEPTH > 1 - lcd_get_backdrop, -#endif - - /* new stuff at the end, sort into place next time - the API gets incompatible */ #ifdef IRIVER_H100_SERIES /* Routines for the iriver_flash -plugin. */ @@ -483,7 +484,8 @@ static const struct plugin_api rockbox_api = { detect_flashed_ramimage, detect_flashed_romimage, #endif - + /* new stuff at the end, sort into place next time + the API gets incompatible */ #if NUM_CORES > 1 spinlock_init, spinlock_lock, @@ -492,14 +494,8 @@ static const struct plugin_api rockbox_api = { #if (CONFIG_CODEC == SWCODEC) codec_load_file, - get_metadata, get_codec_filename, -#endif - threads, - create_numbered_filename, - set_bool_options, -#ifdef HAVE_LCD_COLOR - set_color, + get_metadata, #endif }; diff --git a/apps/plugin.h b/apps/plugin.h index 29e7f5d318..a95d80b7aa 100644 --- a/apps/plugin.h +++ b/apps/plugin.h @@ -115,12 +115,12 @@ #define PLUGIN_MAGIC 0x526F634B /* RocK */ /* increase this every time the api struct changes */ -#define PLUGIN_API_VERSION 59 +#define PLUGIN_API_VERSION 60 /* update this to latest version if a change to the api struct breaks backwards compatibility (and please take the opportunity to sort in any new function which are "waiting" at the end of the function table) */ -#define PLUGIN_MIN_API_VERSION 58 +#define PLUGIN_MIN_API_VERSION 60 /* plugin return codes */ enum plugin_status { @@ -179,6 +179,7 @@ struct plugin_api { int stride, int x, int y, int width, int height); void (*lcd_bitmap)(const fb_data *src, int x, int y, int width, int height); + fb_data* (*lcd_get_backdrop)(void); void (*lcd_set_backdrop)(fb_data* backdrop); #endif #if LCD_DEPTH == 16 @@ -310,6 +311,9 @@ struct plugin_api { #endif void (*ata_spindown)(int seconds); void (*reload_directory)(void); + char *(*create_numbered_filename)(char *buffer, const char *path, + const char *prefix, const char *suffix, + int numberlen IF_CNFN_NUM_(, int *num)); /* dir */ DIR* (*PREFIX(opendir))(const char* name); @@ -333,6 +337,7 @@ struct plugin_api { long* current_tick; long (*default_event_handler)(long event); long (*default_event_handler_ex)(long event, void (*callback)(void *), void *parameter); + struct thread_entry* threads; struct thread_entry* (*create_thread)(void (*function)(void), void* stack, int stack_size, const char *name IF_PRIO(, int priority) @@ -507,11 +512,19 @@ struct plugin_api { bool (*set_option)(const char* string, void* variable, enum optiontype type, const struct opt_items* options, int numoptions, void (*function)(int)); + bool (*set_bool_options)(const char* string, bool* variable, + const char* yes_str, int yes_voice, + const char* no_str, int no_voice, + void (*function)(bool)); bool (*set_int)(const unsigned char* string, const char* unit, int voice_unit, int* variable, void (*function)(int), int step, int min, int max, void (*formatter)(char*, int, int, const char*) ); bool (*set_bool)(const char* string, bool* variable ); +#ifdef HAVE_LCD_COLOR + bool (*set_color)(struct screen *display, char *title, unsigned *color, + unsigned banned_color); +#endif /* action handling */ int (*get_custom_action)(int context,int timeout, const struct button_mapping* (*get_context_map)(int)); @@ -587,11 +600,6 @@ struct plugin_api { int (*wheel_status)(void); void (*wheel_send_events)(bool send); #endif -#if LCD_DEPTH > 1 - fb_data* (*lcd_get_backdrop)(void); -#endif - /* new stuff at the end, sort into place next time - the API gets incompatible */ #ifdef IRIVER_H100_SERIES /* Routines for the iriver_flash -plugin. */ @@ -599,6 +607,8 @@ struct plugin_api { bool (*detect_flashed_ramimage)(void); bool (*detect_flashed_romimage)(void); #endif + /* new stuff at the end, sort into place next time + the API gets incompatible */ #if NUM_CORES > 1 void (*spinlock_init)(struct mutex *m); @@ -608,23 +618,9 @@ struct plugin_api { #if (CONFIG_CODEC == SWCODEC) int (*codec_load_file)(const char* codec, struct codec_api *api); + const char *(*get_codec_filename)(int cod_spec); bool (*get_metadata)(struct track_info* track, int fd, const char* trackname, bool v1first); - const char *(*get_codec_filename)(int cod_spec); -#endif - struct thread_entry* threads; - - char *(*create_numbered_filename)(char *buffer, const char *path, - const char *prefix, const char *suffix, - int numberlen IF_CNFN_NUM_(, int *num)); - - bool (*set_bool_options)(const char* string, bool* variable, - const char* yes_str, int yes_voice, - const char* no_str, int no_voice, - void (*function)(bool)); -#ifdef HAVE_LCD_COLOR - bool (*set_color)(struct screen *display, char *title, unsigned *color, - unsigned banned_color); #endif }; diff --git a/apps/recorder/recording.c b/apps/recorder/recording.c index f7ceb508d5..17ed1052cb 100644 --- a/apps/recorder/recording.c +++ b/apps/recorder/recording.c @@ -70,11 +70,20 @@ #include "radio.h" #ifdef HAVE_RECORDING -static bool in_screen = false; - +/* recording screen status flags */ +enum rec_status_flags +{ + RCSTAT_IN_RECSCREEN = 0x00000001, + RCSTAT_BEEN_IN_USB_MODE = 0x00000002, + RCSTAT_CREATED_DIRECTORY = 0x00000004, + RCSTAT_HAVE_RECORDED = 0x00000008, +}; + +static int rec_status = 0; + bool in_recording_screen(void) { - return in_screen; + return (rec_status & RCSTAT_IN_RECSCREEN) != 0; } #define PM_HEIGHT ((LCD_HEIGHT >= 72) ? 2 : 1) @@ -92,13 +101,13 @@ static bool remote_display_on = true; #endif /** File name creation **/ -#if CONFIG_CODEC == SWCODEC - -#ifdef IF_CNFN_NUM +#if CONFIG_RTC == 0 /* current file number to assist in creating unique numbered filenames without actually having to create the file on disk */ static int file_number = -1; -#endif /* IF_CNFN_NUM */ +#endif /* CONFIG_RTC */ + +#if CONFIG_CODEC == SWCODEC #define REC_FILE_ENDING(rec_format) \ (audio_formats[rec_format_afmt[rec_format]].ext_list) @@ -511,16 +520,26 @@ char *rec_create_filename(char *buffer) snprintf(ext, sizeof(ext), ".%s", REC_FILE_ENDING(global_settings.rec_format)); -#if CONFIG_RTC +#if CONFIG_RTC == 0 + return create_numbered_filename(buffer, buffer, "rec_", ext, 4, + &file_number); +#else /* We'll wait at least up to the start of the next second so no duplicate names are created */ return create_datetime_filename(buffer, buffer, "R", ext, true); -#else - return create_numbered_filename(buffer, buffer, "rec_", ext, 4 - IF_CNFN_NUM_(, &file_number)); #endif } +#if CONFIG_RTC == 0 +/* Hit disk to get a starting filename for the type */ +void rec_init_filename(void) +{ + file_number = -1; + rec_create_filename(path_buffer); + file_number--; +} +#endif + int rec_create_directory(void) { int rc; @@ -594,7 +613,6 @@ void rec_record(void) #if CONFIG_CODEC != SWCODEC talk_buffer_steal(); /* we use the mp3 buffer */ #endif - IF_CNFN_NUM_(file_number = -1;) /* Hit disk for number */ audio_record(rec_create_filename(path_buffer)); } @@ -617,12 +635,15 @@ static void trigger_listener(int trigger_status) switch (trigger_status) { case TRIG_GO: - if((audio_status() & AUDIO_STATUS_RECORD) != AUDIO_STATUS_RECORD) + if(!(audio_status() & AUDIO_STATUS_RECORD)) { + rec_status |= RCSTAT_HAVE_RECORDED; rec_record(); +#if CONFIG_CODEC != SWCODEC /* give control to mpeg thread so that it can start recording */ yield(); yield(); yield(); +#endif } /* if we're already recording this is a retrigger */ @@ -648,11 +669,7 @@ static void trigger_listener(int trigger_status) switch(global_settings.rec_trigger_type) { case 0: /* Stop */ -#if CONFIG_CODEC == SWCODEC audio_stop_recording(); -#else - audio_stop(); -#endif break; case 1: /* Pause */ @@ -686,11 +703,9 @@ bool recording_screen(bool no_source) char buf2[32]; int w, h; int update_countdown = 1; - bool have_recorded = false; unsigned int seconds; int hours, minutes; char filename[13]; - bool been_in_usb_mode = false; int last_audio_stat = -1; int audio_stat; #if CONFIG_CODEC == SWCODEC @@ -733,7 +748,7 @@ bool recording_screen(bool no_source) struct audio_recording_options rec_options; - in_screen = true; + rec_status = RCSTAT_IN_RECSCREEN; cursor = 0; #if (CONFIG_LED == LED_REAL) && !defined(SIMULATOR) ata_set_led_enabled(false); @@ -761,6 +776,15 @@ bool recording_screen(bool no_source) rec_set_recording_options(&rec_options); set_gain(); + + if(rec_create_directory() > 0) + rec_status |= RCSTAT_CREATED_DIRECTORY; + +#if CONFIG_RTC == 0 + /* Create new filename for recording start */ + rec_init_filename(); +#endif + settings_apply_trigger(); #ifdef HAVE_AGC @@ -788,9 +812,7 @@ bool recording_screen(bool no_source) filename_offset[i] = ((screens[i].height >= 80) ? 1 : 0); pm_y[i] = 8 + h * (2 + filename_offset[i]); } - - if(rec_create_directory() > 0) - have_recorded = true; + #ifdef HAVE_REMOTE_LCD if (!remote_display_on) { @@ -859,9 +881,9 @@ bool recording_screen(bool no_source) if (last_audio_stat != audio_stat) { - if (audio_stat == AUDIO_STATUS_RECORD) + if (audio_stat & AUDIO_STATUS_RECORD) { - have_recorded = true; + rec_status |= RCSTAT_HAVE_RECORDED; } last_audio_stat = audio_stat; } @@ -926,7 +948,7 @@ bool recording_screen(bool no_source) (peak_meter_trigger_status() != TRIG_OFF)) { /* manual recording */ - have_recorded = true; + rec_status |= RCSTAT_HAVE_RECORDED; rec_record(); last_seconds = 0; if (global_settings.talk_menu) @@ -1119,7 +1141,11 @@ bool recording_screen(bool no_source) break; case ACTION_STD_MENU: +#if CONFIG_CODEC == SWCODEC + if(!(audio_stat & AUDIO_STATUS_RECORD)) +#else if(audio_stat != AUDIO_STATUS_RECORD) +#endif { #ifdef HAVE_FMRADIO_REC const int prev_rec_source = global_settings.rec_source; @@ -1132,7 +1158,7 @@ bool recording_screen(bool no_source) if (recording_menu(no_source)) { done = true; - been_in_usb_mode = true; + rec_status |= RCSTAT_BEEN_IN_USB_MODE; #ifdef HAVE_FMRADIO_REC radio_status = FMRADIO_OFF; #endif @@ -1152,11 +1178,18 @@ bool recording_screen(bool no_source) audio_close_recording(); audio_init_recording(0); #endif + rec_init_recording_options(&rec_options); rec_set_recording_options(&rec_options); if(rec_create_directory() > 0) - have_recorded = true; + rec_status |= RCSTAT_CREATED_DIRECTORY; + +#if CONFIG_CODEC == SWCODEC && CONFIG_RTC == 0 + /* If format changed, a new number is required */ + rec_init_filename(); +#endif + #ifdef HAVE_AGC if (global_settings.rec_source == AUDIO_SRC_MIC) { agc_preset = global_settings.rec_agc_preset_mic; @@ -1192,7 +1225,7 @@ bool recording_screen(bool no_source) #endif if (f2_rec_screen()) { - have_recorded = true; + rec_status |= RCSTAT_HAVE_RECORDED; done = true; } else @@ -1208,31 +1241,28 @@ bool recording_screen(bool no_source) } else { - if(audio_stat != AUDIO_STATUS_RECORD) - { #if (CONFIG_LED == LED_REAL) - /* led is restored at begin of loop / end of function */ - led(false); + /* led is restored at begin of loop / end of function */ + led(false); #endif - if (f3_rec_screen()) - { - have_recorded = true; - done = true; - } - else - update_countdown = 1; /* Update immediately */ + if (f3_rec_screen()) + { + rec_status |= RCSTAT_HAVE_RECORDED; + done = true; } + else + update_countdown = 1; /* Update immediately */ } break; #endif /* CONFIG_KEYPAD == RECORDER_PAD */ case SYS_USB_CONNECTED: /* Only accept USB connection when not recording */ - if(audio_stat != AUDIO_STATUS_RECORD) + if(!(audio_stat & AUDIO_STATUS_RECORD)) { default_event_handler(SYS_USB_CONNECTED); done = true; - been_in_usb_mode = true; + rec_status |= RCSTAT_BEEN_IN_USB_MODE; #ifdef HAVE_FMRADIO_REC radio_status = FMRADIO_OFF; #endif @@ -1467,12 +1497,11 @@ bool recording_screen(bool no_source) { switch (global_settings.rec_source) { -#if defined(HAVE_LINE_REC) || defined(HAVE_FMRADIO_REC) HAVE_LINE_REC_(case AUDIO_SRC_LINEIN:) HAVE_FMRADIO_REC_(case AUDIO_SRC_FMRADIO:) line[i] = 5; break; -#endif + case AUDIO_SRC_MIC: line[i] = 4; break; @@ -1678,7 +1707,7 @@ bool recording_screen(bool no_source) break; } } - + #if CONFIG_CODEC == SWCODEC audio_stop_recording(); audio_close_recording(); @@ -1704,13 +1733,15 @@ bool recording_screen(bool no_source) peak_meter_trigger(false); peak_meter_set_trigger_listener(NULL); - in_screen = false; + rec_status &= ~RCSTAT_IN_RECSCREEN; sound_settings_apply(); FOR_NB_SCREENS(i) screens[i].setfont(FONT_UI); - if (have_recorded) + /* if the directory was created or recording happened, make sure the + browser is updated */ + if (rec_status & (RCSTAT_CREATED_DIRECTORY | RCSTAT_HAVE_RECORDED)) reload_directory(); #if (CONFIG_LED == LED_REAL) && !defined(SIMULATOR) @@ -1719,7 +1750,7 @@ bool recording_screen(bool no_source) settings_save(); - return been_in_usb_mode; + return (rec_status & RCSTAT_BEEN_IN_USB_MODE) != 0; } /* recording_screen */ #if CONFIG_KEYPAD == RECORDER_PAD -- cgit v1.2.3