capture_get_picture(...) 从摄像头得到一帧图片
int capture_get_picture (void *id, Picture *pic)
{
// 获取, 转换
Ctx *ctx = (Ctx*)id;
v4l2_buffer buf;
memset(&buf, 0, sizeof(buf));
buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
buf.memory = V4L2_MEMORY_MMAP;
if (ioctl(ctx->vid, VIDIOC_DQBUF, &buf) < 0) {
fprintf(stderr, "%s: VIDIOC_DQBUF err/n", __func__);
return -1;
}
// _save_pic(ctx->bufs[buf.index].start, buf.length);
// __asm("int $3");
ctx->pic_src.data[0] = (unsigned char*)ctx->bufs[buf.index].start;
ctx->pic_src.data[1] = ctx->pic_src.data[2] = ctx->pic_src.data[3] = 0;
ctx->pic_src.linesize[0] = ctx->bytesperrow;
ctx->pic_src.linesize[1] = ctx->pic_src.linesize[2] = ctx->pic_src.linesize[3] = 0;
// sws_scale
int rs = sws_scale(ctx->sws, ctx->pic_src.data, ctx->pic_src.linesize,
0, ctx->rows, ctx->pic_target.data, ctx->pic_target.linesize);
// out
for (int i = 0; i < 4; i++) {
pic->data[i] = ctx->pic_target.data[i];
pic->stride[i] = ctx->pic_target.linesize[i];
}
// re queue buf
if (ioctl(ctx->vid, VIDIOC_QBUF, &buf) < 0) {
fprintf(stderr, "%s: VIDIOC_QBUF err/n", __func__);
return -1;
}
return 1;
}
2. X11 的本地回显: 采用 XShm, 效率还行
vs_open ()
XOpenDisplay()
XCreateSimpleWindow()
XCreateGC()
XMapWindow()
XShmCreateImage()
shmget()
shmat()