1 #if 1
2 
3 # define startSpy();
4 # define stopSpy();
5 
6 #else
7 
8 #define RED	0xff0000
9 #define GREEN	0x00ff00
10 #define BLUE	0x0000ff
11 #define WHITE	0xffffff
12 #define BLACK	0x000000
13 
14 #include <pthread.h>
15 
rect(int h,int c,float l,float r)16 void rect(int h, int c, float l, float r)
17 {
18   extern long *dpyPixels;
19   extern int   dpyPitch;
20   int left= 250, width= 100, height= 2;
21   long *base=  dpyPixels;
22   int   pitch= dpyPitch / sizeof(long);
23   int x, y;
24 
25   //printf("rect %d %d %g %g\n", h, c, l, r);
26   assert(l >= 0.0);  assert(r >= 0.0);
27   assert(l <= 1.0);  assert(r <= 1.0);
28 
29   base+= (int)left;
30   base+= (int)(h * height * pitch);
31 
32   for (y= 0; y < height; ++y)
33     {
34       for (x= (int)(width * l); x < (int)(width * r); ++x)
35 	((long *)base)[x]= c;
36       base+= pitch;
37     }
38 }
39 
fill(int h,int c,float l,float r)40 void fill(int h, int c, float l, float r)
41 {
42   if (r > 1.0)
43     {
44       rect(h, c, l, 1.0);
45       rect(h, c, 0.0, r - 1.0);
46     }
47   else
48     rect(h, c, l, r);
49 }
50 
51 
52 #if (USE_FIFO)
53 
update(void)54 void update(void)
55 {
56   if (output)
57     {
58       Buffer *b=   output->buffer;
59       static int phase= 0;
60       float size=  b->size;
61       float out=   b->optr / size;
62       float avail= b->avail / size;
63       extern long *dpyPixels;
64 
65       fill(0,BLACK, 0.0, out);
66       fill(0,GREEN, out, out+avail);
67       if (out + avail < 1.0)
68 	fill(0,BLACK, out+avail, 1.0);
69       fill(2,GREEN, 0.0, avail);
70       fill(2,BLACK, avail, 1.0);
71 
72       phase= 1 - phase;
73       feedback(10, phase * WHITE);
74 
75       memcpy(dpyPixels + 400, output->buffer->data, 400);
76     }
77 }
78 
79 #else
80 
update(void)81 void update(void)
82 {
83 }
84 
85 #endif
86 
87 
88 static int       running= 0;
89 static pthread_t spyThread;
90 
spy(void * ignored)91 static void *spy(void *ignored)
92 {
93   struct sched_param params;
94   int                policy;
95   if (pthread_getschedparam(pthread_self(), &policy, &params))
96     perror("getschedparam");
97   params.sched_priority+= 9;
98   if (pthread_setschedparam(pthread_self(), SCHED_RR, &params))
99     perror("setschedparam");
100   for (;;)
101     {
102       update();
103       usleep(10000);
104     }
105 }
106 
startSpy(void)107 void startSpy(void)
108 {
109   if (!pthread_create(&spyThread, 0, spy, 0))
110     running= 1;
111   else
112     perror("pthread_create(spy)");
113 }
114 
stopSpy(void)115 void stopSpy(void)
116 {
117   if (running)
118     {
119       if (!pthread_cancel(spyThread))
120 	running= 0;
121       else
122 	perror("pthread_cancel(spy)");
123       running= 0;
124     }
125 }
126 
127 
128 #endif // (DEBUG)
129