1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
#include "../screen/screen.h"
#ifdef CAMU_SCREEN_DEBUG_KEY
#define AL_LOG_SECTION "input_simulator"
#include <al/log.h>
#include <al/random.h>
#include <nnwt/thread.h>
#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
|