void VideoCaptureV4L2::update() { if(!is_opened) { printf("WARNING: calling update() but not device opened.\n"); return; } struct v4l2_buffer buf; switch(io_method) { case LINCAP_IO_METHOD_MMAP: { memset(&buf, 0, sizeof(buf)); buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; buf.memory = V4L2_MEMORY_MMAP; if(ioctl(fd, VIDIOC_DQBUF, &buf) == -1) { if(errno == EAGAIN) { //printf("VERBOSE: non-blocking, and no new frame in buffer (EAGAIN). \n"); return; } else if(errno == EINVAL) { printf("ERROR: The buffer type is not supported, or the index is out of bound. no buffer allocated. (EINVAL)\n"); return; } else if(EIO) { printf("ERROR: VIDIOC_DQBUF failed due to an internal error. VIDIOC_QBUF.(EIO)\n"); return ; } else { printf("ERROR: cannot get buffer; unhandled..\n"); return; } } if(frame_cb) { //printf("buf.index: %d, buf.bytes_used: %d, buffers[buf.index].length: %zu\n", buf.index, buf.bytesused, buffers[buf.index]->length); frame_cb(buffers[buf.index]->start, buffers[buf.index]->length, frame_user); } if(ioctl(fd, VIDIOC_QBUF, &buf) == -1) { printf("ERROR: cannot enqueue buf again.\n"); return; } break; } default: { printf("ERROR: unhandled io_method for update().\n"); break; } } }
static void parse_string(sd_stringparser *parser, void(*frame_cb)(sd_stringparser*, void*, char,int), void(*tag_cb)(sd_stringparser*, void*, tag_attribute*, int param), void *data) { if(parser->string) { int pos = 0; while(1) { const char *start = parser->string + pos; const char *str = parser->string + pos; int type = next_tag(&str); pos += (str-start); start = parser->string + pos; if(type == TAG_TAG) { // a tag tag_attribute attrib; if(rn_tag_attribute(static_taglist, &str, &attrib) == 0) { // read the numeric param and call the callback function // if a param is not present, 0 is assumed int pos = 0; int param = rn_int(&pos, str); str += pos; if(tag_cb) tag_cb(parser, data, &attrib, param); } } else if(type == TAG_FRAME) { // a frame int duration=0; char frame_letter=0; rn_frame(&str, &frame_letter, &duration); if(frame_cb) frame_cb(parser, data, frame_letter, duration); } else if(type == TAG_MARKER) { // an end of frame descriptor marker (a dash, '-') rn_descriptor_marker(&str); } else { // the end of stream break; } pos += (str-start); } } }