Rockbox open source high quality audio player as a Music Player Daemon
mpris rockbox mpd libadwaita audio rust zig deno
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

Playback logging add Start time and rename when log size exceeds 512k

renames to playback_nnnn.log

you won't get the message when first enabling logging since it
happens at start-up..

Change-Id: I58ca65a48deff7c5bb1f93c3d86d9ee9e19f3f2e

authored by

William Wilgus and committed by
William Wilgus
731f3fd8 64d8fc7c

+64 -16
+58 -14
apps/playback.c
··· 22 22 ****************************************************************************/ 23 23 #include "config.h" 24 24 #include "system.h" 25 + #include "version.h" 25 26 #include "kernel.h" 26 27 #include "panic.h" 27 28 #include "core_alloc.h" ··· 45 46 #include "misc.h" 46 47 #include "settings.h" 47 48 #include "audiohw.h" 48 - 49 + #include "general.h" 49 50 #include <stdio.h> 50 51 51 52 #ifdef HAVE_TAGCACHE ··· 348 349 static bool codec_seeking = false; /* Codec seeking ack expected? */ 349 350 static unsigned int position_key = 0; 350 351 352 + #define PLAYBACK_LOG_PATH ROCKBOX_DIR "/playback.log" 353 + #define PLAYBACK_LOG_MAX_FILESZ_BYTES (511 << 10) /* 512k approx 1000-2500 tracks */ 354 + #define PLAYBACK_LOG_MIN_ELAPSED_MS (500) /* 500 milliseconds */ 351 355 #if (CONFIG_STORAGE & STORAGE_ATA) 352 356 #define PLAYBACK_LOG_BUFSZ (MAX_PATH * 10) 353 357 static int playback_log_handle = 0; /* core_alloc handle for playback log buffer */ ··· 1239 1243 void allocate_playback_log(void) INIT_ATTR; 1240 1244 void allocate_playback_log(void) 1241 1245 { 1246 + int fd; 1247 + char filename[MAX_PATH]; 1248 + 1249 + if (!global_settings.playback_log) 1250 + return; 1251 + 1242 1252 #if (CONFIG_STORAGE & STORAGE_ATA) 1243 - if (global_settings.playback_log && playback_log_handle == 0) 1253 + if (playback_log_handle == 0) 1244 1254 { 1245 1255 playback_log_handle = core_alloc(PLAYBACK_LOG_BUFSZ); 1246 1256 if (playback_log_handle > 0) ··· 1248 1258 DEBUGF("%s Allocated %d bytes\n", __func__, PLAYBACK_LOG_BUFSZ); 1249 1259 char *buf = core_get_data(playback_log_handle); 1250 1260 buf[0] = '\0'; 1251 - return; 1252 1261 } 1253 1262 } 1254 1263 #endif 1264 + 1265 + while (1) 1266 + { 1267 + DEBUGF("Opening %s \n", PLAYBACK_LOG_PATH); 1268 + fd = open(PLAYBACK_LOG_PATH, O_WRONLY|O_CREAT|O_APPEND, 0666); 1269 + if (fd >= 0) 1270 + { 1271 + /* check if the playback log is excessive */ 1272 + if (lseek(fd, 0, SEEK_END) > PLAYBACK_LOG_MAX_FILESZ_BYTES) 1273 + { 1274 + close(fd); 1275 + create_numbered_filename(filename, ROCKBOX_DIR, "playback_", 1276 + ".log", 4 IF_CNFN_NUM_(, NULL)); 1277 + DEBUGF("Renaming %s => %s\n", PLAYBACK_LOG_PATH, filename); 1278 + if (rename(PLAYBACK_LOG_PATH, filename) < 0) 1279 + break; /*failure*/ 1280 + continue; 1281 + } 1282 + else 1283 + { 1284 + #if CONFIG_RTC 1285 + create_datetime_filename(filename, "", " Time ", "", false); 1286 + fdprintf(fd, "# Started Ver. %s %s\n", rbversion, filename); 1287 + #else 1288 + fdprintf(fd, "# Started Ver. %s\n", rbversion); 1289 + #endif 1290 + } 1291 + close(fd); 1292 + } 1293 + break; 1294 + } 1255 1295 } 1256 1296 1257 1297 void add_playbacklog(struct mp3entry *id3) 1258 1298 { 1259 1299 if (!global_settings.playback_log) 1260 1300 return; 1301 + unsigned long timestamp = 0; 1261 1302 ssize_t used = 0; 1262 - unsigned long timestamp = current_tick * (1000 / HZ); /* milliseconds */ 1263 1303 #if (CONFIG_STORAGE & STORAGE_ATA) 1304 + ssize_t bufsz = 0; 1264 1305 char *buf = NULL; 1265 - ssize_t bufsz; 1266 - 1267 1306 /* if the user just enabled playback logging rather than stopping playback 1268 1307 * to allocate a buffer or if buffer too large just flush direct to disk 1269 1308 * buffer will attempt to be allocated next start-up */ ··· 1271 1310 { 1272 1311 buf = core_get_data(playback_log_handle); 1273 1312 used = strlen(buf); 1274 - bufsz = PLAYBACK_LOG_BUFSZ - used; 1275 - buf += used; 1313 + if (used < PLAYBACK_LOG_BUFSZ) 1314 + { 1315 + bufsz = PLAYBACK_LOG_BUFSZ - used; 1316 + buf += used; 1317 + } 1276 1318 DEBUGF("%s Used %lu Remain: %lu\n", __func__, used, bufsz); 1277 1319 } 1278 1320 #endif 1279 - if (id3 && id3->elapsed > 500) /* 500 ms*/ 1321 + if (id3 && id3->elapsed > PLAYBACK_LOG_MIN_ELAPSED_MS) 1280 1322 { 1281 1323 #if CONFIG_RTC 1282 1324 timestamp = mktime(get_time()); 1325 + #else 1326 + timestamp = current_tick * (1000 / HZ); /* milliseconds */ 1283 1327 #endif 1284 1328 #if (CONFIG_STORAGE & STORAGE_ATA) 1285 1329 if (buf) /* we have a buffer allocd from core */ ··· 1291 1335 if (entrylen < bufsz) 1292 1336 { 1293 1337 DEBUGF("BUFFERED: time: %lu elapsed %ld/%ld saving file: %s\n", 1294 - timestamp, id3->elapsed, id3->length, id3->path); 1338 + timestamp, (long)id3->elapsed, (long)id3->length, id3->path); 1295 1339 return; /* succeed or snprintf fail return */ 1296 1340 } 1297 1341 buf[0] = '\0'; ··· 1304 1348 1305 1349 if (id3 || used > 0) /* flush */ 1306 1350 { 1307 - DEBUGF("Opening %s \n", ROCKBOX_DIR "/playback.log"); 1308 - int fd = open(ROCKBOX_DIR "/playback.log", O_WRONLY|O_CREAT|O_APPEND, 0666); 1351 + DEBUGF("Opening %s \n", PLAYBACK_LOG_PATH); 1352 + int fd = open(PLAYBACK_LOG_PATH, O_WRONLY|O_CREAT|O_APPEND, 0666); 1309 1353 if (fd < 0) 1310 1354 { 1311 1355 return; /* failure */ ··· 1324 1368 { 1325 1369 /* we have the timestamp from when we tried to add to buffer */ 1326 1370 DEBUGF("LOGGED: time: %lu elapsed %ld/%ld saving file: %s\n", 1327 - timestamp, id3->elapsed, id3->length, id3->path); 1371 + timestamp, (long)id3->elapsed, (long)id3->length, id3->path); 1328 1372 fdprintf(fd, "%lu:%ld:%ld:%s\n", 1329 1373 timestamp, (long)id3->elapsed, (long)id3->length, id3->path); 1330 1374 } ··· 3115 3159 /* Go idle */ 3116 3160 filling = STATE_IDLE; 3117 3161 cancel_cpu_boost(); 3118 - add_playbacklog(NULL); 3162 + add_playbacklog(NULL); /* flush playback log */ 3119 3163 } 3120 3164 3121 3165 /* Pause the playback of the current track
+6 -2
manual/configure_rockbox/playback_options.tex
··· 332 332 Devices without a Real Time Clock will use current system tick. 333 333 Tracks played for a very short duration < 1 second will not be recorded 334 334 to minimize disk access while skipping quickly through songs. 335 - You should periodically delete this log as excessive file sizes may cause 336 - decreased device performace see \setting{LastFm Scrobbler} plugin. 335 + 336 + \note {When the device is started a comment will be written to the log, 337 + devices with Real Time Clock will record the date and time as well. 338 + When the log gets too large (\textasciitilde 1500 tracks) it will be split into playback\_nnnn.log 339 + where nnnn is 0001-9999} 340 + see \setting{LastFm Scrobbler} plugin. 337 341 \begin{verbatim} 338 342 the log can be found under '/.rockbox/playback.log' 339 343 \end{verbatim}