/* dio.c */ #include "videoport.h" int main(int argc, char **argv) { videoport p; int direction = (tolower(*argv[1]) == 'v') ? VIDEOPORT_DIRECTION_VM : VIDEOPORT_DIRECTION_MV; char *filename = argv[2]; int issue_count; diskperformance diskperf = diskperformance_open(); int fd; int nbytes; struct dioattr dioinfo; NC(p = videoport_open(direction, 20, VIDEOPORT_ADVISE_NOACCESS)); if (direction == VIDEOPORT_DIRECTION_VM) { printf("writing input video to file %s\n", filename); OC(fd = open(filename, O_RDWR|O_TRUNC|O_CREAT|O_DIRECT, 0644)); } else /* direction == VIDEOPORT_DIRECTION_MV */ { printf("reading video from file %s for output\n", filename); OC(fd = open(filename, O_RDONLY|O_DIRECT, 0644)); } nbytes = p->max_valid_bytes_per_field; /* get direct I/O constraints for this fd */ OC(fcntl(fd, F_DIOINFO, &dioinfo)); assert(nbytes >= dioinfo.d_miniosz); assert(nbytes <= dioinfo.d_maxiosz); assert((nbytes % dioinfo.d_miniosz) == 0); issue_count = 0; diskperformance_datapoint(diskperf, 0, p); for(;;) { int rc; videofield *f; videoport_wait_for_space_or_data(p); f = videoport_get_one_field(p); assert((((uintptr_t)f->pixels) % dioinfo.d_mem) == 0); if (direction == VIDEOPORT_DIRECTION_VM) { OC(rc = write(fd, f->pixels, nbytes)); } else { OC(rc = read(fd, f->pixels, nbytes)); } if (rc != nbytes) error_exit("EOF or out of disk space"); ++issue_count; diskperformance_datapoint(diskperf, ((off64_t)issue_count) * nbytes, p); videoport_put_one_field(p, f); } }