diff options
author | Yongqin Liu <yongqin.liu@linaro.org> | 2017-06-27 14:40:37 +0800 |
---|---|---|
committer | Yongqin Liu <yongqin.liu@linaro.org> | 2017-06-27 14:40:37 +0800 |
commit | 9aec4bfb5f60e6301753406eca084d92b43177e9 (patch) | |
tree | 2d9dd69fb4fb85763fdc1e2952111a8012016ff8 /libcamera/V4L2Camera.cpp | |
parent | fa8bb6c5acb3491d2550091621e8cd504e233c39 (diff) |
add some more debug information, but may have compiling error
if there is any compiling problem, please revert this commit
Change-Id: I8cbe93d75274464646cc07a5050c9ad18c3525b1
Signed-off-by: Yongqin Liu <yongqin.liu@linaro.org>
Diffstat (limited to 'libcamera/V4L2Camera.cpp')
-rw-r--r-- | libcamera/V4L2Camera.cpp | 34 |
1 files changed, 25 insertions, 9 deletions
diff --git a/libcamera/V4L2Camera.cpp b/libcamera/V4L2Camera.cpp index 0ea0d69..5e19777 100644 --- a/libcamera/V4L2Camera.cpp +++ b/libcamera/V4L2Camera.cpp @@ -36,9 +36,9 @@ V4L2Camera::~V4L2Camera() int V4L2Camera::Open (const char *device, int width, int height, int pixelformat) { int ret; - + ALOGE("LIUYQ: %s:%d:%s enter", __FILE__, __LINE__, __FUNCTION__); if ((fd = open(device, O_RDWR)) == -1) { - ALOGE("ERROR opening V4L interface: %s", strerror(errno)); + ALOGE("ERROR opening V4L interface(%s): error=[%s]", device, strerror(errno)); return -1; } @@ -47,6 +47,7 @@ int V4L2Camera::Open (const char *device, int width, int height, int pixelformat ALOGE("Error opening device: unable to query device."); return -1; } + //exclude the nonusb camera if ( NULL == strcasestr((const char*)(videoIn->cap.card), "usb") ){ ALOGE("device(%s) is not a usb camera: %s", device, (const char*)(videoIn->cap.card)); @@ -73,12 +74,14 @@ int V4L2Camera::Open (const char *device, int width, int height, int pixelformat videoIn->format.fmt.pix.height = height; videoIn->format.fmt.pix.pixelformat = pixelformat; + ALOGE("LIUYQ: %s:%d:%s ret = ioctl(fd, VIDIOC_S_FMT, &videoIn->format)", __FILE__, __LINE__, __FUNCTION__); + ALOGE("LIUYQ: format.type=V4L2_BUF_TYPE_VIDEO_CAPTURE(%d), width=%d,height=%d, pixelformat(V4L2_PIX_FMT_YUYV)=%d", V4L2_BUF_TYPE_VIDEO_CAPTURE, width, height, pixelformat); ret = ioctl(fd, VIDIOC_S_FMT, &videoIn->format); if (ret < 0) { ALOGE("Open: VIDIOC_S_FMT Failed: %s", strerror(errno)); return ret; } - + ALOGE("LIUYQ: %s:%d:%s EXIT", __FILE__, __LINE__, __FUNCTION__); return 0; } @@ -108,7 +111,7 @@ int V4L2Camera::Init() ALOGE("Init: get expected buffers: videoIn->rb.count=%d", videoIn->rb.count); } for (int i = 0; i < NB_BUFFER; i++) { - + ALOGE("LIUYQ: in for of V4L2Camera::Init : index=%d", i); memset (&videoIn->buf, 0, sizeof (struct v4l2_buffer)); videoIn->buf.index = i; @@ -120,7 +123,7 @@ int V4L2Camera::Init() ALOGE("Init: Unable to query buffer (%s)", strerror(errno)); return ret; } - + ALOGE("LIUYQ: after VIDIOC_QUERYBUF"); videoIn->mem[i] = mmap (0, videoIn->buf.length, PROT_READ | PROT_WRITE, @@ -132,14 +135,15 @@ int V4L2Camera::Init() ALOGE("Init: Unable to map buffer (%s)", strerror(errno)); return -1; } - + ALOGE("LIUYQ: before VIDIOC_QBUF"); ret = ioctl(fd, VIDIOC_QBUF, &videoIn->buf); if (ret < 0) { - ALOGE("Init: VIDIOC_QBUF Failed"); + ALOGE("Init: VIDIOC_QBUF Failed(%s): ret=%d", strerror(errno), ret); return -1; } nQueued++; + ALOGE("LIUYQ: after VIDIOC_QBUF nQueued=%d", nQueued); } return 0; @@ -173,7 +177,7 @@ int V4L2Camera::StartStreaming () { enum v4l2_buf_type type; int ret; - + ALOGE("LIUYQ: %s:%d:%s: ENTER", __FILE__, __LINE__, __FUNCTION__); if (!videoIn->isStreaming) { type = V4L2_BUF_TYPE_VIDEO_CAPTURE; @@ -185,7 +189,7 @@ int V4L2Camera::StartStreaming () videoIn->isStreaming = true; } - + ALOGE("LIUYQ: %s:%d:%s EXIT", __FILE__, __LINE__, __FUNCTION__); return 0; } @@ -356,6 +360,9 @@ bool V4L2Camera::GrabValidFrame(){ break; } } + nDequeued++; + ALOGE("LIUYQ after VIDIOC_DQBUF nDequeued=%d", nDequeued); + HERE("GrabJpegFrame: Generated a frame from capture device"); /* ALOGE("GrabJpegFrame: buf.bytesused=%d\n", videoIn->buf.bytesused); @@ -376,6 +383,8 @@ camera_memory_t* V4L2Camera::GrabJpegFrame (camera_request_memory mRequestMem if (! GrabValidFrame()){ return NULL; } + nQueued++; + ALOGE("LIUYQ after VIDIOC_QBUF nQueued=%d", nQueued); size_t bytesused = videoIn->buf.bytesused; if (char *tmpBuf = new char[bytesused]) { @@ -383,9 +392,12 @@ camera_memory_t* V4L2Camera::GrabJpegFrame (camera_request_memory mRequestMem saveYUYVtoJPEG((unsigned char *)videoIn->mem[videoIn->buf.index], videoIn->width, videoIn->height, strm, 100); strm.closeStream(); size_t fileSize = strm.getOffset(); + HERE("LIUYQ before call mRequestMemory"); camera_memory_t* picture = mRequestMemory(-1,fileSize,1,NULL); + HERE("LIUYQ after call mRequestMemory"); memcpy(picture->data, tmpBuf, fileSize); delete[] tmpBuf; + HERE("LIUYQ will return from GrabJpegFrame"); return picture; } @@ -419,7 +431,9 @@ int V4L2Camera::saveYUYVtoJPEG (unsigned char *inputBuffer, int width, int heigh jpeg_set_defaults (&cinfo); jpeg_set_quality (&cinfo, quality, TRUE); + jpeg_start_compress (&cinfo, TRUE); + z = 0; while (cinfo.next_scanline < cinfo.image_height) { int x; @@ -454,9 +468,11 @@ int V4L2Camera::saveYUYVtoJPEG (unsigned char *inputBuffer, int width, int heigh row_pointer[0] = line_buffer; jpeg_write_scanlines (&cinfo, row_pointer, 1); } + jpeg_finish_compress (&cinfo); fileSize = ftell(file); jpeg_destroy_compress (&cinfo); + free (line_buffer); return fileSize; |