1 #include <stdlib.h>
2 #include <stdint.h>
3 #include <stdio.h>
4 #include <inttypes.h>
5 #include <unistd.h>
6 #include <stdbool.h>
7 #include <arcan_shmif.h>
8 
9 #ifdef ENABLE_FSRV_AVFEED
afsrv_avfeed(struct arcan_shmif_cont * con,struct arg_arr * args)10 int afsrv_avfeed(struct arcan_shmif_cont* con, struct arg_arr* args)
11 {
12 	struct arcan_shmif_cont cont = *con;
13 #else
14 int main(int argc, char** argv){
15 	struct arcan_shmif_cont cont = arcan_shmif_open(
16 		SEGID_APPLICATION, SHMIF_ACQUIRE_FATALFAIL, NULL);
17 #endif
18 
19 	arcan_event ev;
20 	struct {shmif_pixel* vp; shmif_pixel col;} ca[3] = {0};
21 
22 	arcan_shmif_resize_ext(&cont, 640, 480, (struct shmif_resize_ext){
23 		.abuf_sz = 0, .abuf_cnt = 0, .vbuf_cnt = 3
24 	});
25 
26 /* We pair vidp pointer value with slot in array, so that each possible video
27  * buffer slot gets a known color. If every frame is red, the cycling is
28  * entirely ignored. If every frame is blue, only the latest is shown and we
29  * are maintaing a clock that match the display. */
30 	ca[0].col = SHMIF_RGBA(255, 0, 0, 255);
31 	ca[1].col = SHMIF_RGBA(0, 255, 0, 255);
32 	ca[2].col = SHMIF_RGBA(0, 0, 255, 255);
33 	int i = 0;
34 	int fc = 500;
35 
36 	while(cont.addr->dms && fc--){
37 		shmif_pixel color;
38 /* grab matching color, we don't know the other vidps so have to log */
39 		for (i=0; i < 3; i++){
40 			if (ca[i].vp == cont.vidp){
41 				color = ca[i].col;
42 				break;
43 			}
44 		}
45 
46 /* not found, register */
47 		if (i==3){
48 			for (i=0; i < 3; i++){
49 				if(ca[i].vp == NULL){
50 					ca[i].vp = cont.vidp;
51 					color = ca[i].col;
52 					printf("buffer: %"PRIxPTR" associated with %i\n",
53 						(uintptr_t)cont.vidp, i);
54 					break;
55 				}
56 			}
57 		}
58 
59 		if (i==3){
60 			printf("buffer - slot mismatch\n");
61 			return EXIT_FAILURE;
62 		}
63 
64 	for (size_t row = 0; row < cont.addr->h; row++)
65 		for (size_t col = 0; col < cont.addr->w; col++)
66 			cont.vidp[ row * cont.addr->w + col ] = color;
67 
68 		long long time = arcan_timemillis();
69 		arcan_shmif_signal(&cont, SHMIF_SIGVID);
70 		long long endt = arcan_timemillis();
71 
72 		printf("synch took: %lld, mask: %d\n", endt - time, cont.addr->vpending);
73 
74 		while (arcan_shmif_poll(&cont, &ev) == 1)
75 			;
76 	}
77 
78 	FILE* outf = fopen("counter.dump", "w+");
79 	fwrite(cont.addr, 1, cont.shmsize, outf);
80 	fclose(outf);
81 
82 	return EXIT_SUCCESS;
83 }
84