Lines Matching refs:cd
251 LinuxCameraDevice* cd; in _camera_device_alloc() local
253 ANEW0(cd); in _camera_device_alloc()
254 memset(cd, 0, sizeof(*cd)); in _camera_device_alloc()
255 cd->header.opaque = cd; in _camera_device_alloc()
256 cd->handle = -1; in _camera_device_alloc()
258 return cd; in _camera_device_alloc()
290 _camera_device_reset(LinuxCameraDevice* cd) in _camera_device_reset() argument
296 if (cd->framebuffers != NULL) { in _camera_device_reset()
297 _free_framebuffers(cd->framebuffers, cd->framebuffer_num, cd->io_type); in _camera_device_reset()
298 free(cd->framebuffers); in _camera_device_reset()
299 cd->framebuffers = NULL; in _camera_device_reset()
300 cd->framebuffer_num = 0; in _camera_device_reset()
304 close(cd->handle); in _camera_device_reset()
305 cd->handle = open(cd->device_name, O_RDWR | O_NONBLOCK, 0); in _camera_device_reset()
307 if (cd->handle >= 0) { in _camera_device_reset()
310 _xioctl(cd->handle, VIDIOC_CROPCAP, &cropcap); in _camera_device_reset()
313 _xioctl (cd->handle, VIDIOC_S_CROP, &crop); in _camera_device_reset()
324 _camera_device_mmap_framebuffer(LinuxCameraDevice* cd) in _camera_device_mmap_framebuffer() argument
334 if(_xioctl(cd->handle, VIDIOC_REQBUFS, &req)) { in _camera_device_mmap_framebuffer()
337 __FUNCTION__, cd->device_name); in _camera_device_mmap_framebuffer()
347 cd->framebuffers = calloc(req.count, sizeof(CameraFrameBuffer)); in _camera_device_mmap_framebuffer()
348 if (cd->framebuffers == NULL) { in _camera_device_mmap_framebuffer()
355 for(cd->framebuffer_num = 0; cd->framebuffer_num < req.count; in _camera_device_mmap_framebuffer()
356 cd->framebuffer_num++) { in _camera_device_mmap_framebuffer()
362 buf.index = cd->framebuffer_num; in _camera_device_mmap_framebuffer()
363 if(_xioctl(cd->handle, VIDIOC_QUERYBUF, &buf) < 0) { in _camera_device_mmap_framebuffer()
368 cd->framebuffers[cd->framebuffer_num].size = buf.length; in _camera_device_mmap_framebuffer()
369 cd->framebuffers[cd->framebuffer_num].data = in _camera_device_mmap_framebuffer()
371 cd->handle, buf.m.offset); in _camera_device_mmap_framebuffer()
372 if (MAP_FAILED == cd->framebuffers[cd->framebuffer_num].data) { in _camera_device_mmap_framebuffer()
382 buf.index = cd->framebuffer_num; in _camera_device_mmap_framebuffer()
383 if (_xioctl(cd->handle, VIDIOC_QBUF, &buf) < 0) { in _camera_device_mmap_framebuffer()
389 cd->io_type = CAMERA_IO_MEMMAP; in _camera_device_mmap_framebuffer()
401 _camera_device_user_framebuffer(LinuxCameraDevice* cd) in _camera_device_user_framebuffer() argument
411 if(_xioctl(cd->handle, VIDIOC_REQBUFS, &req)) { in _camera_device_user_framebuffer()
414 __FUNCTION__, cd->device_name); in _camera_device_user_framebuffer()
424 cd->framebuffers = calloc(req.count, sizeof(CameraFrameBuffer)); in _camera_device_user_framebuffer()
425 if (cd->framebuffers == NULL) { in _camera_device_user_framebuffer()
431 for(cd->framebuffer_num = 0; cd->framebuffer_num < req.count; in _camera_device_user_framebuffer()
432 cd->framebuffer_num++) { in _camera_device_user_framebuffer()
433 cd->framebuffers[cd->framebuffer_num].size = in _camera_device_user_framebuffer()
434 cd->actual_pixel_format.sizeimage; in _camera_device_user_framebuffer()
435 cd->framebuffers[cd->framebuffer_num].data = in _camera_device_user_framebuffer()
436 malloc(cd->framebuffers[cd->framebuffer_num].size); in _camera_device_user_framebuffer()
437 if (cd->framebuffers[cd->framebuffer_num].data == NULL) { in _camera_device_user_framebuffer()
447 buf.m.userptr = (unsigned long)cd->framebuffers[cd->framebuffer_num].data; in _camera_device_user_framebuffer()
448 buf.length = cd->framebuffers[cd->framebuffer_num].size; in _camera_device_user_framebuffer()
449 if (_xioctl(cd->handle, VIDIOC_QBUF, &buf) < 0) { in _camera_device_user_framebuffer()
455 cd->io_type = CAMERA_IO_USERPTR; in _camera_device_user_framebuffer()
467 _camera_device_direct_framebuffer(LinuxCameraDevice* cd) in _camera_device_direct_framebuffer() argument
470 cd->framebuffer_num = 1; in _camera_device_direct_framebuffer()
471 cd->framebuffers = malloc(sizeof(CameraFrameBuffer)); in _camera_device_direct_framebuffer()
472 if (cd->framebuffers == NULL) { in _camera_device_direct_framebuffer()
477 cd->framebuffers[0].size = cd->actual_pixel_format.sizeimage; in _camera_device_direct_framebuffer()
478 cd->framebuffers[0].data = malloc(cd->framebuffers[0].size); in _camera_device_direct_framebuffer()
479 if (cd->framebuffers[0].data == NULL) { in _camera_device_direct_framebuffer()
484 cd->io_type = CAMERA_IO_DIRECT; in _camera_device_direct_framebuffer()
496 _camera_device_open(LinuxCameraDevice* cd) in _camera_device_open() argument
500 if (stat(cd->device_name, &st)) { in _camera_device_open()
505 E("%s: '%s' is not a device", __FUNCTION__, cd->device_name); in _camera_device_open()
510 cd->handle = open(cd->device_name, O_RDWR | O_NONBLOCK, 0); in _camera_device_open()
511 if (cd->handle < 0) { in _camera_device_open()
513 __FUNCTION__, cd->device_name, strerror(errno)); in _camera_device_open()
516 if (_xioctl(cd->handle, VIDIOC_QUERYCAP, &cd->caps) < 0) { in _camera_device_open()
519 __FUNCTION__, cd->device_name); in _camera_device_open()
520 close(cd->handle); in _camera_device_open()
521 cd->handle = -1; in _camera_device_open()
525 __FUNCTION__, cd->device_name); in _camera_device_open()
526 close(cd->handle); in _camera_device_open()
527 cd->handle = -1; in _camera_device_open()
533 if (!(cd->caps.capabilities & V4L2_CAP_VIDEO_CAPTURE)) { in _camera_device_open()
535 __FUNCTION__, cd->device_name); in _camera_device_open()
536 close(cd->handle); in _camera_device_open()
537 cd->handle = -1; in _camera_device_open()
556 _camera_device_enum_format_sizes(LinuxCameraDevice* cd, in _camera_device_enum_format_sizes() argument
570 if(_xioctl(cd->handle, VIDIOC_ENUM_FRAMESIZES, &size_enum)) { in _camera_device_enum_format_sizes()
612 if(_xioctl(cd->handle, VIDIOC_ENUM_FRAMESIZES, &size_enum)) { in _camera_device_enum_format_sizes()
671 _camera_device_enum_pixel_formats(LinuxCameraDevice* cd, QemuPixelFormat** fmts) in _camera_device_enum_pixel_formats() argument
683 if(_xioctl(cd->handle, VIDIOC_ENUM_FMT, &fmt_enum)) { in _camera_device_enum_pixel_formats()
706 if(_xioctl(cd->handle, VIDIOC_ENUM_FMT, &fmt_enum)) { in _camera_device_enum_pixel_formats()
722 _camera_device_enum_format_sizes(cd, fmt_enum.pixelformat, in _camera_device_enum_pixel_formats()
753 _camera_device_get_info(LinuxCameraDevice* cd, CameraInfo* cis) in _camera_device_get_info() argument
758 int num_pix_fmts = _camera_device_enum_pixel_formats(cd, &formats); in _camera_device_get_info()
776 cis->device_name = ASTRDUP(cd->device_name); in _camera_device_get_info()
777 cis->inp_channel = cd->input_channel; in _camera_device_get_info()
802 LinuxCameraDevice* cd; in camera_device_open() local
805 cd = _camera_device_alloc(); in camera_device_open()
806 cd->device_name = name != NULL ? ASTRDUP(name) : ASTRDUP("/dev/video0"); in camera_device_open()
807 cd->input_channel = inp_channel; in camera_device_open()
810 if (_camera_device_open(cd)) { in camera_device_open()
811 _camera_device_free(cd); in camera_device_open()
817 _xioctl(cd->handle, VIDIOC_CROPCAP, &cropcap); in camera_device_open()
820 _xioctl (cd->handle, VIDIOC_S_CROP, &crop); in camera_device_open()
822 return &cd->header; in camera_device_open()
832 LinuxCameraDevice* cd; in camera_device_start_capturing() local
841 cd = (LinuxCameraDevice*)ccd->opaque; in camera_device_start_capturing()
842 if (cd->handle < 0) { in camera_device_start_capturing()
853 if (_xioctl(cd->handle, VIDIOC_S_FMT, &fmt) < 0) { in camera_device_start_capturing()
857 __FUNCTION__, cd->device_name, fmt_str, frame_width, frame_height); in camera_device_start_capturing()
858 _camera_device_reset(cd); in camera_device_start_capturing()
868 _camera_device_reset(cd); in camera_device_start_capturing()
871 memcpy(&cd->actual_pixel_format, &fmt.fmt.pix, sizeof(struct v4l2_pix_format)); in camera_device_start_capturing()
879 r = _camera_device_mmap_framebuffer(cd); in camera_device_start_capturing()
882 _camera_device_reset(cd); in camera_device_start_capturing()
887 r = _camera_device_user_framebuffer(cd); in camera_device_start_capturing()
890 _camera_device_reset(cd); in camera_device_start_capturing()
894 if (!(cd->caps.capabilities & V4L2_CAP_READWRITE)) { in camera_device_start_capturing()
896 __FUNCTION__, cd->device_name); in camera_device_start_capturing()
897 _camera_device_reset(cd); in camera_device_start_capturing()
900 r = _camera_device_direct_framebuffer(cd); in camera_device_start_capturing()
903 _camera_device_reset(cd); in camera_device_start_capturing()
910 if (cd->io_type != CAMERA_IO_DIRECT) { in camera_device_start_capturing()
913 if (_xioctl (cd->handle, VIDIOC_STREAMON, &type) < 0) { in camera_device_start_capturing()
915 __FUNCTION__, cd->device_name, strerror(errno)); in camera_device_start_capturing()
916 _camera_device_reset(cd); in camera_device_start_capturing()
927 LinuxCameraDevice* cd; in camera_device_stop_capturing() local
934 cd = (LinuxCameraDevice*)ccd->opaque; in camera_device_stop_capturing()
935 if (cd->handle < 0) { in camera_device_stop_capturing()
940 switch (cd->io_type) { in camera_device_stop_capturing()
948 if (_xioctl(cd->handle, VIDIOC_STREAMOFF, &type) < 0) { in camera_device_stop_capturing()
950 __FUNCTION__, cd->device_name, strerror(errno)); in camera_device_stop_capturing()
955 E("%s: Unknown I/O method: %d", __FUNCTION__, cd->io_type); in camera_device_stop_capturing()
962 _camera_device_reset(cd); in camera_device_stop_capturing()
972 LinuxCameraDevice* cd; in camera_device_read_frame() local
979 cd = (LinuxCameraDevice*)ccd->opaque; in camera_device_read_frame()
980 if (cd->handle < 0) { in camera_device_read_frame()
985 if (cd->io_type == CAMERA_IO_DIRECT) { in camera_device_read_frame()
989 void* buff = cd->framebuffers[0].data; in camera_device_read_frame()
992 read(cd->handle, buff + total_read_bytes, in camera_device_read_frame()
993 cd->actual_pixel_format.sizeimage - total_read_bytes); in camera_device_read_frame()
1001 __FUNCTION__, cd->device_name, strerror(errno)); in camera_device_read_frame()
1006 } while (total_read_bytes < cd->actual_pixel_format.sizeimage); in camera_device_read_frame()
1008 return convert_frame(buff, cd->actual_pixel_format.pixelformat, in camera_device_read_frame()
1009 cd->actual_pixel_format.sizeimage, in camera_device_read_frame()
1010 cd->actual_pixel_format.width, in camera_device_read_frame()
1011 cd->actual_pixel_format.height, in camera_device_read_frame()
1019 buf.memory = cd->io_type == CAMERA_IO_MEMMAP ? V4L2_MEMORY_MMAP : in camera_device_read_frame()
1022 const int res = _xioctl(cd->handle, VIDIOC_DQBUF, &buf); in camera_device_read_frame()
1029 __FUNCTION__, cd->device_name, strerror(errno)); in camera_device_read_frame()
1035 res = convert_frame(cd->framebuffers[buf.index].data, in camera_device_read_frame()
1036 cd->actual_pixel_format.pixelformat, in camera_device_read_frame()
1037 cd->actual_pixel_format.sizeimage, in camera_device_read_frame()
1038 cd->actual_pixel_format.width, in camera_device_read_frame()
1039 cd->actual_pixel_format.height, in camera_device_read_frame()
1043 if (_xioctl(cd->handle, VIDIOC_QBUF, &buf) < 0) { in camera_device_read_frame()
1045 __FUNCTION__, cd->device_name, strerror(errno)); in camera_device_read_frame()
1055 LinuxCameraDevice* cd; in camera_device_close() local
1059 cd = (LinuxCameraDevice*)ccd->opaque; in camera_device_close()
1060 _camera_device_free(cd); in camera_device_close()
1074 CameraDevice* cd; in enumerate_camera_devices() local
1077 cd = camera_device_open(dev_name, 0); in enumerate_camera_devices()
1078 if (cd != NULL) { in enumerate_camera_devices()
1079 LinuxCameraDevice* lcd = (LinuxCameraDevice*)cd->opaque; in enumerate_camera_devices()
1087 camera_device_close(cd); in enumerate_camera_devices()