Index: apps/plugins/SOURCES =================================================================== --- apps/plugins/SOURCES (revision 23121) +++ apps/plugins/SOURCES (working copy) @@ -18,6 +18,7 @@ stopwatch.c vbrfix.c viewer.c +test_codec.c #ifdef HAVE_BACKLIGHT lamp.c #endif /* HAVE_BACKLIGHT */ Index: apps/settings.h =================================================================== --- apps/settings.h (revision 23121) +++ apps/settings.h (working copy) @@ -80,6 +80,7 @@ #define VIEWERS_CONFIG ROCKBOX_DIR "/viewers.config" #define CONFIGFILE ROCKBOX_DIR "/config.cfg" #define FIXEDSETTINGSFILE ROCKBOX_DIR "/fixed.cfg" +#define LOGF_FILENAME ROCKBOX_DIR "/logf.log" #define MAX_FILENAME 32 Index: apps/playback.c =================================================================== --- apps/playback.c (revision 23121) +++ apps/playback.c (working copy) @@ -29,6 +29,7 @@ #include #include "system.h" +#include "config.h" #include "thread.h" #include "file.h" #include "panic.h" @@ -90,7 +91,7 @@ #define AUDIO_REBUFFER_GUESS_SIZE (1024*32) /* Define LOGF_ENABLE to enable logf output in this file */ -/*#define LOGF_ENABLE*/ +#define LOGF_ENABLE #include "logf.h" /* macros to enable logf for queues @@ -443,7 +444,7 @@ if (talk_buf || buffer_state == AUDIOBUF_STATE_TRASHED || !talk_voice_required()) { - logf("get buffer: talk, audio"); + // logf("get buffer: talk, audio"); /* Ok to use everything from audiobuf to audiobufend - voice is loaded, the talk buffer is not needed because voice isn't being used, or could be AUDIOBUF_STATE_TRASHED already. If state is @@ -675,7 +676,7 @@ void audio_play(long offset) { - logf("audio_play"); + // logf("audio_play"); #ifdef PLAYBACK_VOICE /* Truncate any existing voice output so we don't have spelling @@ -806,7 +807,7 @@ { static const unsigned short lookup[] = {5, 15, 30, 60, 120, 180, 300, 600}; buffer_margin = lookup[setting]; - logf("buffer margin: %ld", (long)buffer_margin); + //logf("buffer margin: %ld", (long)buffer_margin); set_filebuf_watermark(); } #endif @@ -884,7 +885,7 @@ } size_t bytes = id3->bitrate * (1000/8) * seconds; buf_set_watermark(bytes); - logf("fwmark: %d", bytes); + //logf("fwmark: %d", bytes); } const char *get_codec_filename(int cod_spec) @@ -1107,7 +1108,7 @@ static void codec_seek_complete_callback(void) { - logf("seek_complete"); + // logf("seek_complete"); /* If seeking-while-playing, pcm playback is actually paused (pcm_is_paused()) * but the paused flag is not set. If seeking-while-paused, the (paused) flag is * set, but pcm playback may have actually stopped due to a previous buffer clear. @@ -1129,7 +1130,7 @@ static bool codec_seek_buffer_callback(size_t newpos) { - logf("codec_seek_buffer_callback"); + // logf("codec_seek_buffer_callback"); int ret = bufseek(CUR_TI->audio_hid, newpos); if (ret == 0) { @@ -1152,7 +1153,7 @@ static void codec_track_changed(void) { - LOGFQUEUE("codec > audio Q_AUDIO_TRACK_CHANGED"); + //LOGFQUEUE("codec > audio Q_AUDIO_TRACK_CHANGED"); queue_post(&audio_queue, Q_AUDIO_TRACK_CHANGED, 0); } @@ -1380,7 +1381,7 @@ switch (ev.id) { case Q_CODEC_LOAD_DISK: case Q_CODEC_LOAD: - LOGFQUEUE("codec < Q_CODEC_LOAD"); + logf("codec < Q_CODEC_LOAD"); if (playing) { if (ci.new_track || status != CODEC_OK) @@ -1486,7 +1487,7 @@ static void buffering_low_buffer_callback(void *data) { (void)data; - logf("low buffer callback"); + //logf("low buffer callback"); if (filling == STATE_FULL || filling == STATE_END_OF_PLAYLIST) { /* force a refill */ @@ -1504,7 +1505,7 @@ static void buffering_handle_finished_callback(int *data) { - logf("handle %d finished buffering", *data); + //logf("handle %d finished buffering", *data); if (*data == tracks[track_widx].id3_hid) { @@ -1528,7 +1529,7 @@ { /* This was the last track in the playlist. We now have all the data we need. */ - logf("last track finished buffering"); + //logf("last track finished buffering"); filling = STATE_FINISHED; } } @@ -1583,7 +1584,7 @@ { int cur_idx = track_widx; - logf("Clearing tracks:%d/%d", track_ridx, track_widx); + // logf("Clearing tracks:%d/%d", track_ridx, track_widx); /* Loop over all tracks from write-to-read */ while (1) @@ -1602,7 +1603,7 @@ { int i, cur_idx; - logf("releasing all tracks"); + // logf("releasing all tracks"); for(i = 0; i < MAX_TRACK; i++) { @@ -1669,14 +1670,19 @@ } } +/* disable buffering of codec file in ringbuffer for low memory targets*/ +/* stable MP3 playing to be tested, issue is automatic skip with new */ +/* codec, cuesheets may also be an issue */ + +#if MEMORYSIZE > 1000 codec_get_full_path(codec_path, codec_fn); - tracks[track_widx].codec_hid = bufopen(codec_path, 0, TYPE_CODEC); if (tracks[track_widx].codec_hid < 0) return false; - logf("Loaded codec"); - + +#endif +logf("!!! reloaded codec"); return true; } @@ -1692,7 +1698,7 @@ /* There is already a track load in progress, so track_widx hasn't been incremented yet. Loading another track would overwrite the one that hasn't finished loading. */ - logf("audio_load_track(): a track load is already in progress"); + //logf("audio_load_track(): a track load is already in progress"); return false; } @@ -1703,14 +1709,14 @@ metadata there). */ if (!audio_free_track_count()) { - logf("No free tracks"); + //logf("No free tracks"); return false; } last_peek_offset++; tracks[track_widx].taginfo_ready = false; - logf("Buffering track:%d/%d", track_widx, track_ridx); + //logf("Buffering track:%d/%d", track_widx, track_ridx); /* Get track name from current playlist read position. */ while ((trackname = playlist_peek(last_peek_offset)) != NULL) { @@ -1765,7 +1771,7 @@ get_metadata(&unbuffered_id3, fd, trackname); last_peek_offset--; close(fd); - logf("buffer is full for now"); + //logf("buffer is full for now"); filling = STATE_FULL; return false; } @@ -1960,7 +1966,7 @@ if (tracks[track_widx].audio_hid == ERR_BUFFER_FULL) { filling = STATE_FULL; - logf("buffer is full for now"); + //logf("buffer is full for now"); return; } else if (tracks[track_widx].audio_hid < 0) @@ -2006,7 +2012,7 @@ if (buffer_state != AUDIOBUF_STATE_INITIALIZED) audio_reset_buffer(); - logf("Starting buffer fill"); + //logf("Starting buffer fill"); if (!start_play) audio_clear_track_entries(); @@ -2019,7 +2025,7 @@ static void audio_rebuffer(void) { - logf("Forcing rebuffer"); + //logf("Forcing rebuffer"); clear_track_info(CUR_TI); @@ -2350,7 +2356,7 @@ /* Called on manual track skip */ static void audio_initiate_track_change(long direction) { - logf("audio_initiate_track_change(%ld)", direction); + //logf("audio_initiate_track_change(%ld)", direction); ci.new_track += direction; wps_offset -= direction; @@ -2370,7 +2376,7 @@ /* Called when PCM track change is complete */ static void audio_finalise_track_change(void) { - logf("audio_finalise_track_change"); + //logf("audio_finalise_track_change"); if (automatic_skip) { @@ -2397,7 +2403,7 @@ static void audio_reset_buffer(void) { /* see audio_get_recording_buffer if this is modified */ - logf("audio_reset_buffer"); + //logf("audio_reset_buffer"); /* If the setup of anything allocated before the file buffer is changed, do check the adjustments after the buffer_alloc call Index: apps/buffering.c =================================================================== --- apps/buffering.c (revision 23121) +++ apps/buffering.c (working copy) @@ -59,7 +59,7 @@ #define GUARD_BUFSIZE (32*1024) /* Define LOGF_ENABLE to enable logf output in this file */ -/*#define LOGF_ENABLE*/ +#define LOGF_ENABLE #include "logf.h" /* macros to enable logf for queues @@ -426,22 +426,30 @@ newpos = RINGBUF_ADD((void *)src - (void *)buffer, final_delta); overlap = RINGBUF_ADD_CROSS(newpos, size_to_move, buffer_len - 1); + /* The unpatched version has else if (!canwrap) instruction, + a handle with !canwrap can be wrapped because of the if ((unsigned)overlap > + datasize) instruction before. This happens rarely for the ID3 handle */ + + if (overlap > 0) { + logf("overlap: %d can_wrap: %d\n", overlap, can_wrap); /* Some part of the struct + data would wrap, maybe ok */ size_t correction = 0; - /* If the overlap lands inside the memory_handle */ - if ((unsigned)overlap > data_size) { + if (!can_wrap) { + /* The overlap falls in the data or struct area and must all be + * backed out. This may become conditional if ever we move + * data that is allowed to wrap (ie audio) */ + correction = overlap; + } else if ((unsigned)overlap > data_size) { + /* If the overlap lands inside the memory_handle */ /* Correct the position and real delta to prevent the struct from * wrapping, this guarantees an aligned delta, I think */ - correction = overlap - data_size; - } else if (!can_wrap) { - /* Otherwise the overlap falls in the data area and must all be - * backed out. This may become conditional if ever we move - * data that is allowed to wrap (ie audio) */ - correction = overlap; + correction = overlap - sizeof(struct memory_handle); + logf("correction changed: %d\n", correction); + + } /* Align correction to four bytes, up */ - correction = (correction+3) & ~3; - } + correction = (correction+3) & ~3; if (correction) { if (final_delta < correction + sizeof(struct memory_handle)) { /* Delta cannot end up less than the size of the struct */ @@ -484,11 +492,16 @@ if (src == cur_handle) cur_handle = dest; +/* Does this take into account moving a handle which is already +wrapped ? Therefore the CODEC handle has a !canwrap status in the +patch */ + + if (overlap > 0) { size_t first_part = size_to_move - overlap; + memmove(buffer, (const char *)src + first_part, overlap); memmove(dest, src, first_part); - memmove(buffer, (const char *)src + first_part, overlap); - } else { + } else { memmove(dest, src, size_to_move); } @@ -561,7 +574,7 @@ Return whether or not the buffering should continue explicitly. */ static bool buffer_handle(int handle_id) { - logf("buffer_handle(%d)", handle_id); + //logf("buffer_handle(%d)", handle_id); struct memory_handle *h = find_handle(handle_id); if (!h) return true; @@ -624,7 +637,7 @@ (unsigned)((void *)h->next - (void *)buffer)); h->filerem -= copy_n; h->filesize -= copy_n; - logf("buf alloc short %ld", (long)copy_n); + //logf("buf alloc short %ld", (long)copy_n); if (h->filerem) continue; else @@ -776,7 +789,11 @@ delta = handle_distance - h->available; /* The value of delta might change for alignment reasons */ - if (!move_handle(&h, &delta, h->available, h->type==TYPE_CODEC)) + if (!move_handle(&h, &delta, h->available, false)) + +/* h->type==TYPE_CODEC changed to false. CODEC handle gets the attribute +the status !canwrap (ID3 handle is also !canwrap) */ + return; size_t olddata = h->data; @@ -813,7 +830,7 @@ Return whether or not to continue filling after this */ static bool fill_buffer(void) { - logf("fill_buffer()"); + //logf("fill_buffer()"); struct memory_handle *m; shrink_handle(first_handle); m = first_handle; @@ -1122,7 +1139,7 @@ if (guardbuf_limit && h->type == TYPE_PACKET_AUDIO && *size > GUARD_BUFSIZE) { - logf("data request > guardbuf"); + //logf("data request > guardbuf"); /* If more than the size of the guardbuf is requested and this is a * bufgetdata, limit to guard_bufsize over the end of the buffer */ *size = MIN(*size, buffer_len - h->ridx + GUARD_BUFSIZE); Index: apps/main.c =================================================================== --- apps/main.c (revision 23121) +++ apps/main.c (working copy) @@ -62,6 +62,7 @@ #include "plugin.h" #include "misc.h" #include "dircache.h" +#include "logf.h" #ifdef HAVE_TAGCACHE #include "tagcache.h" #include "tagtree.h" @@ -116,6 +117,10 @@ #include "system-sdl.h" #endif +#ifdef ROCKBOX_HAS_LOGF +#include "logf.h" +#endif + /*#define AUTOROCK*/ /* define this to check for "autostart.rock" on boot */ const char appsversion[]=APPSVERSION; @@ -155,7 +160,9 @@ } } #endif /* #ifdef AUTOROCK */ - + + logf("beginning log\n"); + root_menu(); } @@ -332,7 +339,11 @@ tree_mem_init(); filetype_init(); playlist_init(); - +#ifdef ROCKBOX_HAS_LOGF + + //logf_file_open("/.rockbox/logf.log"); + DEBUGF("just opened: .rockbox/logf.log"); +#endif #if CONFIG_CODEC != SWCODEC mp3_init( global_settings.volume, global_settings.bass, @@ -591,6 +602,10 @@ global_settings.mdb_enable, global_settings.superbass); +#ifdef ROCKBOX_HAS_LOGF + // logf_file_open("/.rockbox/logf.log"); +#endif + /* audio_init must to know the size of voice buffer so init voice first */ talk_init(); #endif /* CONFIG_CODEC != SWCODEC */ @@ -600,6 +615,7 @@ #if (CONFIG_CODEC == SWCODEC) && defined(HAVE_RECORDING) && !defined(SIMULATOR) pcm_rec_init(); #endif + /* runtime database has to be initialized after audio_init() */ cpu_boost(false); Index: apps/misc.c =================================================================== --- apps/misc.c (revision 23121) +++ apps/misc.c (working copy) @@ -57,6 +57,7 @@ #include "playlist.h" #include "yesno.h" #include "viewport.h" +#include "logf.h" #ifdef IPOD_ACCESSORY_PROTOCOL #include "iap.h" @@ -285,7 +286,7 @@ #else long msg_id = -1; int i; - + logf("shutting down\n"); scrobbler_poweroff(); #if CONFIG_CHARGING && !defined(HAVE_POWEROFF_WHILE_CHARGING) Index: firmware/export/logf.h =================================================================== --- firmware/export/logf.h (revision 23121) +++ firmware/export/logf.h (working copy) @@ -27,13 +27,21 @@ #ifdef ROCKBOX_HAS_LOGF +/*define this if you want logging to disk (more useful for flash targets)*/ +#define LOGF_TO_DISK + #ifndef __PCTOOL__ -#define MAX_LOGF_SIZE 16384 +#define MAX_LOGF_SIZE 8192 extern unsigned char logfbuffer[MAX_LOGF_SIZE]; extern int logfindex; extern bool logfwrap; + +int logf_file_open(const char* fname); +void logf_file_close(void); +void logf_push_disk(int); + #endif /* __PCTOOL__ */ #define logf _logf Index: firmware/logf.c =================================================================== --- firmware/logf.c (revision 23121) +++ firmware/logf.c (working copy) @@ -36,6 +36,7 @@ #include "lcd-remote.h" #include "logf.h" #include "serial.h" +#include "file.h" #ifdef HAVE_USBSTACK #include "usb_core.h" @@ -45,6 +46,9 @@ /* Only provide all this if asked to */ #ifdef ROCKBOX_HAS_LOGF +static int logf_id = -1; +static char logf_path[512]; + #ifndef __PCTOOL__ unsigned char logfbuffer[MAX_LOGF_SIZE]; int logfindex; @@ -201,9 +205,9 @@ void _logf(const char *fmt, ...) { - #ifdef USB_ENABLE_SERIAL +#if defined(USB_ENABLE_SERIAL) || defined(LOGF_TO_DISK) int old_logfindex = logfindex; - #endif +#endif va_list ap; va_start(ap, fmt); @@ -212,7 +216,11 @@ /* add trailing zero */ logf_push(NULL, '\0'); +#ifdef LOGF_TO_DISK + logf_push_disk(old_logfindex); +#endif + #if defined(HAVE_SERIAL) && !defined(SIMULATOR) serial_tx("\r\n"); #endif @@ -230,6 +238,77 @@ displayremote(); } + + +int logf_file_open(const char *fname) +{ + DEBUGF("opening: %s\n", fname); + if (logf_id < 0) + { + if (strncmp(fname, logf_path, 512)){ + strcpy(logf_path, fname); + logf_id = open(logf_path, O_WRONLY | O_CREAT | O_APPEND); + if(logf_id >= 0) + write(logf_id, "logf file open\n", sizeof("logf file open\n")); + + } else{ + + logf_id = open(logf_path, O_WRONLY | O_CREAT | O_APPEND); + + + + } + // _logf("logf file %s open.", fname); + //else + //_logf("logf file %s fail.", fname); + } + + return 0; +} + +void logf_file_close(void) +{ + if(logf_id >= 0) + { + logf("%s\n", "close log"); + close(logf_id); + logf_id = -1; + } +} + +void logf_push_disk(int old_indx) +{ + //int len = logfindex-old_indx; + int i = old_indx; + int fd; + + fd = open(ROCKBOX_DIR "/logf.txt", O_CREAT|O_WRONLY|O_APPEND); + if (fd > -1) + { + //if(len < 0){ /*wrap around if needed*/ + // write(logf_id, logfbuffer+old_indx, MAX_LOGF_SIZE-old_indx); + // len = logfindex; + // old_indx=0; + //} + //write(logf_id, logfbuffer+old_indx, len); + //write(logf_id, "\n", 1); + do { + if(logfbuffer[i]=='\0') + fdprintf(fd, "\n"); + else + fdprintf(fd, "%c", logfbuffer[i]); + + i++; + if(i >= MAX_LOGF_SIZE) + i = 0; + } while(i != logfindex); + close(fd); + } + +} + + + #endif #endif