设为首页 加入收藏

TOP

uvc摄像头代码解析7(三)
2015-11-21 01:42:23 来源: 作者: 【 】 浏览:25
Tags:uvc 摄像头 代码 解析
??
? ? switch (cmd) { ?
? ? ... ?
? ? case ...: ?
? ? { ?
? ? ? ? ... ?
? ? ? ? break; ?
? ? } ?
? ? return ret; ?
} ?
a.VIDIOC_STREAMON 开始视频显示函数
[cpp] ?
 ? case VIDIOC_STREAMON: ?
 
? ? { ?
? ? ? ? int *type = arg; ?
? ? ? ? if (*type != stream->type) ?
? ? ? ? ? ? return -EINVAL; ?
? ? ? ? if (!uvc_has_privileges(handle)) ?
? ? ? ? ? ? return -EBUSY; ?
? ? ? ? mutex_lock(&stream->mutex); ?
? ? ? ? ret = uvc_video_enable(stream, 1); ?//uvc视频流使能 ?
? ? ? ? mutex_unlock(&stream->mutex); ?
? ? ? ? if (ret < 0) ?
? ? ? ? ? ? return ret; ?
? ? ? ? break; ?
? ? }a.1 uvc视频流使能
?
int uvc_video_enable(struct uvc_streaming *stream, int enable) ?
 
{ ?
? ? int ret; ?
? ? if (!enable) { ?
? ? ? ? uvc_uninit_video(stream, 1);//逆初始化视频 ?
? ? ? ? usb_set_interface(stream->dev->udev, stream->intfnum, 0); ?
? ? ? ? uvc_queue_enable(&stream->queue, 0);//uvc禁用队列 ?
? ? ? ? return 0; ?
? ? } ?
? ? ret = uvc_queue_enable(&stream->queue, 1); ? //uvc使能队列 ?
? ? if (ret < 0) ?
? ? ? ? return ret; ?
? ? /* Commit the streaming parameters. */ ?
? ? ret = uvc_commit_video(stream, &stream->ctrl); ? //uvc提交视频参数 ?
? ? if (ret < 0) ?
? ? ? ? return ret; ?
? ? return uvc_init_video(stream, GFP_KERNEL); ?//uvc初始化视频 ?
}a.1.1 uvc使能队列 ?
 ?
 
static int uvc_queue_enable(struct uvc_video_queue *queue, int enable) ?
 
{ ?
? ? unsigned int i; ?
? ? int ret = 0; ?
? ? mutex_lock(&queue->mutex); ?
? ? if (enable) { ? //使能uvc队列 ?
? ? ? ? if (uvc_queue_streaming(queue)) { ? //判断队列标志是否为UVC_QUEUE_STREAMING ?
? ? ? ? ? ? ret = -EBUSY; ?
? ? ? ? ? ? goto done; ?
? ? ? ? } ?
? ? ? ? queue->sequence = 0; ?
? ? ? ? queue->flags |= UVC_QUEUE_STREAMING; //设置队列标志 ?
? ? ? ? queue->buf_used = 0; //设置缓冲区使用标志 ?
? ? } ??
? ? else { ?
? ? ? ? uvc_queue_cancel(queue, 0); //取消uvc队列 ?
? ? ? ? INIT_LIST_HEAD(&queue->mainqueue); ? //重新初始化uvc队列mainqueue队列头 ?
? ? ? ? for (i = 0; i < queue->count; ++i) ?
? ? ? ? ? ? queue->buffer[i].state = UVC_BUF_STATE_IDLE; //设置缓冲区状态为闲置态 ?
? ? ? ? queue->flags &= ~UVC_QUEUE_STREAMING; ? ?//设置队列标志 ?
? ? } ?
done: ?
? ? mutex_unlock(&queue->mutex); ?
? ? return ret; ?
}a.1.2 uvc提交视频参数 ?
 ?
 
int uvc_commit_video(struct uvc_streaming *stream,struct uvc_streaming_control *probe) ?
 
{ ?
? ? return uvc_set_video_ctrl(stream, probe, 0); ? ?//uvc设置视频控制 ?
}a.1.3 uvc初始化视频 ?
 ?
 
static int uvc_init_video(struct uvc_streaming *stream, gfp_t gfp_flags) ?
 
{ ?
? ? struct usb_interface *intf = stream->intf; ?
? ? struct usb_host_endpoint *ep; ?
? ? unsigned int i; ?
? ? int ret; ?
? ? stream->sequence = -1; ?
? ? stream->last_fid = -1; ?
? ? stream->bulk.header_size = 0; ?
? ? stream->bulk.skip_payload = 0; ?
? ? stream->bulk.payload_size = 0; ?
? ? if (intf->num_altsetting > 1) { ? //同步方式 ?
? ? ? ? struct usb_host_endpoint *best_ep = NULL; ?
? ? ? ? unsigned int best_psize = 3 * 1024; ?
? ? ? ? unsigned int bandwidth; ?
? ? ? ? unsigned int uninitialized_var(altsetting); ?
? ? ? ? int intfnum = stream->intfnum; ?
? ? ? ? /* Isochronous endpoint, select the alternate setting. */ ?
? ? ? ? bandwidth = stream->ctrl.dwMaxPayloadTransferSize; ?
? ? ? ? if (bandwidth == 0) { ?
? ? ? ? ? ? uvc_trace(UVC_TRACE_VIDEO, "Device requested null bandwidth, defaulting to lowest.\n"); ?
? ? ? ? ? ? bandwidth = 1; ?
? ? ? ? } ??
? ? ? ? else { ?
? ? ? ? ? ? uvc_trace(UVC_TRACE_VIDEO, "Device requested %u B/frame bandwidth.\n", bandwidth); ?
? ? ? ? } ?
? ? ? ? for (i = 0; i < intf->num_altsetting; ++i) { ?
? ? ? ? ? ? struct usb_host_in
首页 上一页 1 2 3 4 5 下一页 尾页 3/5/5
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇uvc摄像头代码解析6 下一篇poj1698 Alice's Chance

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: