1 /*
2  * No copyright claimed, Public Domain
3  */
4 #include <stdlib.h>
5 #include <stdio.h>
6 #include <stdbool.h>
7 #include <stdint.h>
8 #include <unistd.h>
9 #include <sys/types.h>
10 #include <pthread.h>
11 
12 #include <arcan_shmif.h>
13 #include "frameserver.h"
14 
update_frame(struct arcan_shmif_cont * shms,shmif_pixel val)15 static void update_frame(struct arcan_shmif_cont* shms, shmif_pixel val)
16 {
17 	shmif_pixel* cptr = shms->vidp;
18 
19 	int np = shms->addr->w * shms->addr->h;
20 	for (int i = 0; i < np; i++)
21 		*cptr++ = val;
22 
23 	arcan_shmif_signal(shms, SHMIF_SIGVID);
24 }
25 
dump_help()26 static void dump_help()
27 {
28 	fprintf(stdout, "the avfeed- frameserver is primarily intended"
29 		" for testing and prototyping purposes and is not particularly"
30 		" useful on its own.\n");
31 }
32 
33 /*
34  * Quick skeleton to map up a audio/video/input
35  * source to an arcan frameserver along with some helpers.
36  */
afsrv_avfeed(struct arcan_shmif_cont * con,struct arg_arr * args)37 int afsrv_avfeed(struct arcan_shmif_cont* con, struct arg_arr* args)
38 {
39 	if (!con){
40 		dump_help();
41 		return EXIT_FAILURE;
42 	}
43 	struct arcan_shmif_cont shms = *con;
44 
45 	if (!arcan_shmif_resize(&shms, 320, 200)){
46 		LOG("arcan_frameserver(decode) shmpage setup, resize failed\n");
47 		return EXIT_FAILURE;
48 	}
49 
50 	update_frame(&shms, RGBA(0xff, 0xff, 0xff, 0xff));
51 	arcan_event ev;
52 
53 	while(1)
54 		while(arcan_shmif_wait(&shms, &ev)){
55 			if (ev.category == EVENT_TARGET){
56 			if (ev.tgt.kind == TARGET_COMMAND_EXIT){
57 				fprintf(stdout, "parent requested termination, leaving.\n");
58 				return EXIT_SUCCESS;
59 			}
60 			else {
61 				static int red;
62 				update_frame(&shms, RGBA(red++, 0x00, 0x00, 0xff));
63 			}
64 			}
65 		}
66 
67 	return EXIT_FAILURE;
68 }
69