/* * Quick skeleton to map up a audio/video/input * source to an arcan frameserver along with some helpers. */ int afsrv_avfeed(struct arcan_shmif_cont* con, struct arg_arr* args) { if (!con){ dump_help(); return EXIT_FAILURE; } struct arcan_shmif_cont shms = *con; if (!arcan_shmif_resize(&shms, 320, 200)){ LOG("arcan_frameserver(decode) shmpage setup, resize failed\n"); return EXIT_FAILURE; } update_frame(&shms, RGBA(0xff, 0xff, 0xff, 0xff)); arcan_event ev; while(1) while(arcan_shmif_wait(&shms, &ev)){ if (ev.category == EVENT_TARGET){ if (ev.tgt.kind == TARGET_COMMAND_EXIT){ fprintf(stdout, "parent requested termination, leaving.\n"); return EXIT_SUCCESS; } else { static int red; update_frame(&shms, RGBA(red++, 0x00, 0x00, 0xff)); } } } return EXIT_FAILURE; }
static ssize_t ch_data(struct senseye_ch* ch, const void* buf, size_t ntw) { if (!ch || !ch->in_pr) return -1; struct senseye_priv* chp = ch->in_pr; size_t ofs = 0; retry: if (!chp->running) return -1; /* flush if the controlling UI has specified one or several framesteps */ if (!chp->paused || chp->framecount > 0){ int fc; while (chp->framecount > 0 && ntw - ofs > 0){ ofs += ch->in->data(ch->in, (uint8_t*) buf + ofs, ntw, &fc); chp->framecount -= fc; } } /* otherwise, block thread, wait for user action and retry */ else{ arcan_event ev; if (arcan_shmif_wait(&chp->cont, &ev)){ dispatch_event(&ev, ch->in, chp); goto retry; } } ch_pump(ch); return ofs; }
int main(int argc, char** argv) { struct arg_arr* aarr; struct arcan_shmif_cont cont = arcan_shmif_open( SEGID_APPLICATION, SHMIF_ACQUIRE_FATALFAIL, &aarr); arcan_event ev; bool running = true; arcan_shmif_resize(&cont, 320, 200); /* fill with red and transfer */ for (size_t row = 0; row < cont.addr->h; row++) for (size_t col = 0; col < cont.addr->w; col++) cont.vidp[ row * cont.addr->w + col ] = RGBA(255, 0, 0, 255); arcan_shmif_signal(&cont, SHMIF_SIGVID); while (running && arcan_shmif_wait(&cont, &ev)){ if (ev.category == EVENT_TARGET) switch (ev.tgt.kind){ case TARGET_COMMAND_EXIT: running = false; default: break; } } return EXIT_SUCCESS; }
int main(int argc, char** argv) { struct arg_arr* aarr; struct arcan_shmif_cont cont = arcan_shmif_open( SEGID_APPLICATION, SHMIF_ACQUIRE_FATALFAIL, &aarr); arcan_event ev = { .ext.kind = ARCAN_EVENT(CLOCKREQ), .ext.clock.rate = 2, .ext.clock.dynamic = (argc > 1 && strcmp(argv[1], "dynamic") == 0) }; arcan_shmif_enqueue(&cont, &ev); ev.ext.clock.dynamic = false; int tbl[] = {20, 40, 42, 44, 60, 80, 86, 88, 100, 120}; int step = 0; for (size_t i=0; i < sizeof(tbl)/sizeof(tbl[0]); i++){ ev.ext.clock.once = true; ev.ext.clock.rate = tbl[i]; ev.ext.clock.id = i + 2; /* 0 index and 1 is reserved */ arcan_shmif_enqueue(&cont, &ev); } while(arcan_shmif_wait(&cont, &ev) != 0){ if (ev.category == EVENT_TARGET) switch(ev.tgt.kind){ case TARGET_COMMAND_STEPFRAME: printf("step: %d, source: %d\n", ev.tgt.ioevs[0].iv, ev.tgt.ioevs[1].iv); if (ev.tgt.ioevs[1].iv > 1){ if (step == ev.tgt.ioevs[1].iv-2) printf("custom timer %d OK\n", step); else printf("timer out of synch, expected %d got %d\n", step, ev.tgt.ioevs[1].iv-2); step++; } break; case TARGET_COMMAND_EXIT: goto done; /* break(1), please */ default: break; } } done: arcan_shmif_drop(&cont); return EXIT_SUCCESS; }
bool senseye_pump(struct senseye_cont* cont, bool block) { struct senseye_priv* cpriv = cont->priv; arcan_event sr; if (block){ if (!arcan_shmif_wait(&cpriv->cont, &sr) || (sr.category == EVENT_TARGET && sr.tgt.kind == TARGET_COMMAND_EXIT)) return false; else process_event(cont, &sr); return true; } int rc = arcan_shmif_poll(&cpriv->cont, &sr); if (rc > 0) process_event(cont, &sr); return rc != -1; }
int main(int argc, char** argv) { int id = SEGID_APPLICATION; struct arg_arr* aarr; if (argc > 1){ if (strcmp(argv[1], "-game") == 0) id = SEGID_GAME; else if (strcmp(argv[1], "-terminal") == 0) id = SEGID_TERMINAL; else if (strcmp(argv[1], "-vm") == 0) id = SEGID_VM; else{ printf("usage: \n\tiodump to identify as normal application" "\n\tiodump -game to identify as game" "\n\tiodump -terminal to identify as terminal" "\n\tiodump -vm to identify as vm\n" ); return EXIT_FAILURE; } } struct arcan_shmif_cont cont = arcan_shmif_open( id, SHMIF_ACQUIRE_FATALFAIL, &aarr); printf("open\n"); arcan_event ev; /* just send garbage so the correct events are being propagated */ arcan_shmif_signal(&cont, SHMIF_SIGVID); printf("loop\n"); while (arcan_shmif_wait(&cont, &ev)){ if (ev.category == EVENT_TARGET){ switch (ev.tgt.kind){ case TARGET_COMMAND_BCHUNK_IN: printf("bchunk in\n"); dump_eof(ev.tgt.ioevs[0].iv); break; case TARGET_COMMAND_BCHUNK_OUT: printf("bchunk out\n"); write_eof(ev.tgt.ioevs[0].iv); break; case TARGET_COMMAND_MESSAGE: printf("message: %s\n", ev.tgt.message); break; case TARGET_COMMAND_EXIT: return EXIT_SUCCESS; default: printf("event: %s\n", arcan_shmif_eventstr(&ev, NULL, 0)); break; } } else if (ev.category == EVENT_IO){ switch (ev.io.datatype){ case EVENT_IDATATYPE_TRANSLATED: printf("(%s)[kbd(%d):%s] %d:mask=%d,sym:%d,code:%d,utf8:%s\n", ev.io.label, ev.io.devid, ev.io.input.translated.active ? "pressed" : "released", (int)ev.io.subid, (int)ev.io.input.translated.modifiers, (int)ev.io.input.translated.keysym, (int)ev.io.input.translated.scancode, ev.io.input.translated.utf8 ); break; case EVENT_IDATATYPE_ANALOG: printf("(%s)[%s(%d):%d] rel: %s, v(%d){%d, %d, %d, %d}\n", ev.io.label, ev.io.devkind == EVENT_IDEVKIND_MOUSE ? "mouse" : "analog", ev.io.devid, ev.io.subid, ev.io.input.analog.gotrel ? "yes" : "no", (int)ev.io.input.analog.nvalues, (int)ev.io.input.analog.axisval[0], (int)ev.io.input.analog.axisval[1], (int)ev.io.input.analog.axisval[2], (int)ev.io.input.analog.axisval[3] ); break; case EVENT_IDATATYPE_TOUCH: printf("(%s)[touch(%d)] %d: @%d,%d pressure: %f, size: %f\n", ev.io.label, ev.io.devid, ev.io.subid, (int) ev.io.input.touch.x, (int) ev.io.input.touch.y, ev.io.input.touch.pressure, ev.io.input.touch.size ); break; case EVENT_IDATATYPE_DIGITAL: if (ev.io.devkind == EVENT_IDEVKIND_MOUSE) printf("[mouse(%d):%d], %s:%s\n", ev.io.devid, ev.io.subid, msub_to_lbl(ev.io.subid), ev.io.input.digital.active ? "pressed" : "released" ); else printf("[digital(%d):%d], %s\n", ev.io.devid, ev.io.subid, ev.io.input.digital.active ? "pressed" : "released"); break; default: break; } } } return EXIT_SUCCESS; }