1 /* for png- output mode */
2 #include <arcan_shmif.h>
3 #include "arcan_img.h"
4 
png_stream_run(struct arg_arr * args,struct arcan_shmif_cont cont)5 void png_stream_run(struct arg_arr* args, struct arcan_shmif_cont cont)
6 {
7 	const char* prefix = "./";
8 	const char* str;
9 
10 	size_t skip = 0;
11 	size_t count = 0;
12 	size_t limit = 0;
13 
14 	char fnbuf[strlen(prefix) + sizeof("xxxxxx.png")];
15 
16 	if (arg_lookup(args, "prefix", 0, &str) && str){
17 		prefix = str;
18 	}
19 
20 	if (arg_lookup(args, "limit", 0, &str) && str){
21 		limit = strtoul(str, NULL, 10);
22 	}
23 
24 	if (arg_lookup(args, "skip", 0, &str) && str){
25 		skip = strtoul(str, NULL, 10);
26 	}
27 
28 	struct arcan_event ev;
29 	while (arcan_shmif_wait(&cont, &ev)){
30 		if (ev.category != EVENT_TARGET)
31 			continue;
32 
33 		switch(ev.tgt.kind){
34 		case TARGET_COMMAND_STEPFRAME:{
35 			while(!cont.addr->vready){}
36 			if (skip){
37 				cont.addr->vready = false;
38 				skip--;
39 				continue;
40 			}
41 
42 			count++;
43 			snprintf(fnbuf, sizeof(fnbuf), "%s%04zu.png", prefix, count);
44 			FILE* fout = fopen(fnbuf, "w+");
45 			if (!fout){
46 				fprintf(stderr, "(encode-png) couldn't open %s for writing\n", fnbuf);
47 				continue;
48 			}
49 
50 			arcan_img_outpng(fout, cont.vidp, cont.w, cont.h, false);
51 			cont.addr->vready = false;
52 			fclose(fout);
53 
54 			if (limit && count == limit)
55 				goto out;
56 
57 		}
58 		default:
59 		break;
60 		}
61 	}
62 
63 out:
64 	arcan_shmif_drop(&cont);
65 /* get arguments:
66  * prefix
67  * limit
68  * skip
69  */
70 }
71