#include "../screen/screen.h" #ifdef CAMU_SCREEN_DEBUG_KEY #define AL_LOG_SECTION "input_simulator" #include #include #include #include "input_simulator.h" // This is ignoring all thread-safety. static s32 quit = 1; static struct nn_thread thread; enum { SKIP, BACKSKIP, TOGGLE_PAUSE, SEEK, SHUFFLE, MARK, // count }; static nn_thread_result NNWT_THREADCALL input_simulation_thread(void *userdata) { struct camu_sink *sink = (struct camu_sink *)userdata; nn_thread_set_name("input_simulator"); while (!quit) { //nn_thread_sleep(NNWT_TS_FROM_USEC(2000000 + al_random_int(0, 1750000))); //nn_thread_sleep(NNWT_TS_FROM_USEC(60000)); nn_thread_sleep(NNWT_TS_FROM_USEC(30000)); switch (al_random_int(0, MARK - 1)) { case SKIP: { s32 n = al_random_int(1, 5); log_info("SKIP (n: %d).", n); camu_sink_skip(sink, n); break; } case BACKSKIP: { s32 n = al_random_int(-5, -1); log_info("BACKSKIP (n: %d).", n); camu_sink_skip(sink, n); break; } case SHUFFLE: { log_info("SHUFFLE."); camu_sink_shuffle(sink); break; } case TOGGLE_PAUSE: { log_info("TOGGLE_PAUSE."); camu_sink_toggle_pause(sink); break; } case SEEK: { f64 pos = al_rand() / (f64)AL_RAND_MAX; if (pos < 0.005) pos = 0.0; if (pos > 0.995) pos = 1.0; else if (pos > 0.99) pos = 0.9999; log_info("SEEK (pos: %f).", pos); camu_sink_seek(sink, &pos, CAMU_SEEK_PERCENT); break; } } } return 0; } void camu_input_simulator_run(struct camu_sink *sink) { quit = 0; nn_thread_create(&thread, input_simulation_thread, sink); } bool camu_input_simulator_running(void) { return quit == 0; } void camu_input_simulator_stop(void) { quit = 1; nn_thread_join(&thread); } #endif