void put_poms_out(){ printf("put poms out \n"); turn_left(); double sec= seconds(); while(analog10(LEFT_SENSOR)<left_blk-150&&analog10(RIGHT_SENSOR)<right_blk-150&&(sec+1)>seconds()){ } forward(); while(analog10(LEFT_SENSOR)<left_blk-150&&analog10(RIGHT_SENSOR)<right_blk-150){} if(analog10(LEFT_SENSOR)>=left_blk-150&&analog10(RIGHT_SENSOR)>=right_blk-150){ put_out(); } else if(analog10(LEFT_SENSOR)>=left_blk-150){ turn_left(); while(analog10(RIGHT_SENSOR)>=right_blk-150){} stop(); msleep(1000); forward(); while(analog10(LEFT_SENSOR)<left_blk-150){} stop(); msleep(1000); turn_left(); while(analog10(RIGHT_SENSOR)<right_blk-150){} put_out(); } else if(analog10(RIGHT_SENSOR)>=right_blk-150){ turn_right(); while(analog10(LEFT_SENSOR)>=left_blk-150){} stop(); msleep(1000); forward(); while(analog10(RIGHT_SENSOR)<right_blk-150){} stop(); msleep(1000); turn_right(); while(analog10(LEFT_SENSOR)<left_blk-150){} put_out(); } }
int main(void) { uint8_t buf[1 << 16], *out; uint8_t state = 0; unsigned i, j, type = 0x20; struct { uint8_t buf[256]; unsigned pos; } psbuf[2], *cps = NULL; for (;;) { ssize_t got = read(0, (out = buf), sizeof(buf)); if (got < 0) die("Read error: %m"); if (got == 0) break; for (i = 0; i < (unsigned) got; i++) { switch (state) { case 0x57: /* 0x00000001 */ type = buf[i] & 0x1F; switch (type) { case NUT_SPS: case NUT_PPS: /* if we have PPS/SPS record it in the appropriate buffer */ cps = &psbuf[type == NUT_SPS ? 0 : 1 ]; cps->pos = 0; break; case NUT_CODED_SLICE_IDR: /* If we have an IDR (key) frame push the stored SPS/PPS out in front of it */ if (!cps) { got -= push_out(&out, &buf[i] - out); for (j = 0; j < 2; j++) put_out(psbuf[j].buf, psbuf[j].pos); } default: /* Anything other than SPS/PPS: stop recording */ cps = NULL; break; } break; } /* state of last four bytes packed into one byte; two bits for unseen/zero/over * one/one (0..3 respectively). */ state = (state << 2) | (buf[i] == 0x00 ? 1 : buf[i] == 0x01 ? 3 : 2); if (cps) { if (cps->pos == sizeof(cps->buf)) { fprintf(stderr, "Warning: SPS/PPS overrun!\n"); /* discard and forget about it. SPS/PPS are quite small - * if this buffer fills it's more likely that we're being * given something other than h264 than that the SPS or PPS is * that large. */ cps->pos = 0; cps = NULL; } cps->buf[cps->pos++] = buf[i]; } } /* push whatever is left at the end */ push_out(&out, got); } return 0; }
static size_t push_out(uint8_t **buf, size_t len) { put_out(*buf, len); *buf += len; return len; }