Merge branch 'CR_1392_1592_v4l2test_sync_Kevin.xie' into 'jh7110-devel'
Cr 1392 1592 v4l2test sync kevin.xie See merge request sdk/buildroot!32
This commit is contained in:
@@ -384,17 +384,6 @@ LOG(STF_LEVEL_INFO, "width=%d,height=%d,pitch=%d,bo_handle=%d,fb_id=%d\n",
|
|||||||
|
|
||||||
dev->saved_crtc = drmModeGetCrtc(fd, dev->crtc_id); /* must store crtc data */
|
dev->saved_crtc = drmModeGetCrtc(fd, dev->crtc_id); /* must store crtc data */
|
||||||
|
|
||||||
/* First buffer to DRM */
|
|
||||||
if (drmModeSetCrtc(fd, dev->crtc_id, dev->bufs[0].fb_id, 0, 0,
|
|
||||||
&dev->conn_id, 1, &dev->mode)) {
|
|
||||||
fatal("drmModeSetCrtc() failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
/* First flip */
|
|
||||||
drmModePageFlip(fd, dev->crtc_id,
|
|
||||||
dev->bufs[0].fb_id, DRM_MODE_PAGE_FLIP_EVENT,
|
|
||||||
dev);
|
|
||||||
|
|
||||||
LOG(STF_LEVEL_TRACE, "Exit\n");
|
LOG(STF_LEVEL_TRACE, "Exit\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ ConfigParam_t *gp_cfg_param = NULL;
|
|||||||
|
|
||||||
static int g_drm_buf_next_idx = -1;
|
static int g_drm_buf_next_idx = -1;
|
||||||
static int g_drm_buf_curr_idx = 0;
|
static int g_drm_buf_curr_idx = 0;
|
||||||
|
static int drm_buf_id = 0;
|
||||||
|
|
||||||
static void alloc_default_config(ConfigParam_t **pp_data)
|
static void alloc_default_config(ConfigParam_t **pp_data)
|
||||||
{
|
{
|
||||||
@@ -403,18 +404,22 @@ static int frameRead(void)
|
|||||||
struct v4l2_buffer buf;
|
struct v4l2_buffer buf;
|
||||||
V4l2Param_t *pv4l2_param = &gp_cfg_param->v4l2_param;
|
V4l2Param_t *pv4l2_param = &gp_cfg_param->v4l2_param;
|
||||||
uint8_t *dst = NULL;
|
uint8_t *dst = NULL;
|
||||||
|
int next_index;
|
||||||
|
|
||||||
if (STF_DISP_FB == gp_cfg_param->disp_type) {
|
if (STF_DISP_FB == gp_cfg_param->disp_type) {
|
||||||
dst = gp_cfg_param->fb_param.screen_buf;
|
dst = gp_cfg_param->fb_param.screen_buf;
|
||||||
} else if (STF_DISP_DRM == gp_cfg_param->disp_type &&
|
} else if (STF_DISP_DRM == gp_cfg_param->disp_type &&
|
||||||
IO_METHOD_DMABUF != gp_cfg_param->io_mthd) {
|
IO_METHOD_DMABUF != gp_cfg_param->io_mthd) {
|
||||||
dst = gp_cfg_param->drm_param.dev_head->bufs[0].buf;
|
//Get ready to compose the backgound buffer
|
||||||
|
next_index = (drm_buf_id + 1) % 2;
|
||||||
|
dst = gp_cfg_param->drm_param.dev_head->bufs[next_index].buf;
|
||||||
} else {
|
} else {
|
||||||
LOG(STF_LEVEL_LOG, "Not display\n");
|
LOG(STF_LEVEL_LOG, "Not display\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (pv4l2_param->io_mthd) {
|
switch (pv4l2_param->io_mthd) {
|
||||||
case IO_METHOD_READ:
|
case IO_METHOD_READ:
|
||||||
|
{
|
||||||
if (-1 == v4l2_read(pv4l2_param->fd, pv4l2_param->pBuffers[0].start,
|
if (-1 == v4l2_read(pv4l2_param->fd, pv4l2_param->pBuffers[0].start,
|
||||||
pv4l2_param->pBuffers[0].length)) {
|
pv4l2_param->pBuffers[0].length)) {
|
||||||
switch (errno) {
|
switch (errno) {
|
||||||
@@ -434,26 +439,42 @@ static int frameRead(void)
|
|||||||
timestamp.tv_usec = ts.tv_nsec/1000;
|
timestamp.tv_usec = ts.tv_nsec/1000;
|
||||||
imageProcess((uint8_t *)(pv4l2_param->pBuffers[0].start), dst, timestamp);
|
imageProcess((uint8_t *)(pv4l2_param->pBuffers[0].start), dst, timestamp);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case IO_METHOD_MMAP:
|
case IO_METHOD_MMAP:
|
||||||
|
{
|
||||||
stf_v4l2_dequeue_buffer(pv4l2_param, &buf);
|
stf_v4l2_dequeue_buffer(pv4l2_param, &buf);
|
||||||
LOG(STF_LEVEL_LOG, "buf.index=%d, n_buffers=%d\n",
|
LOG(STF_LEVEL_LOG, "buf.index=%d, n_buffers=%d\n",
|
||||||
buf.index, gp_cfg_param->v4l2_param.n_buffers);
|
buf.index, gp_cfg_param->v4l2_param.n_buffers);
|
||||||
imageProcess((uint8_t *)(pv4l2_param->pBuffers[buf.index].start), dst, buf.timestamp);
|
imageProcess((uint8_t *)(pv4l2_param->pBuffers[buf.index].start), dst, buf.timestamp);
|
||||||
stf_v4l2_queue_buffer(pv4l2_param, buf.index);
|
|
||||||
if (STF_DISP_DRM == gp_cfg_param->disp_type) {
|
if (STF_DISP_DRM == gp_cfg_param->disp_type) {
|
||||||
drmModePageFlip(gp_cfg_param->drm_param.fd, gp_cfg_param->drm_param.dev_head->crtc_id,
|
drm_buf_id = next_index; // Move background buffer to foreground
|
||||||
gp_cfg_param->drm_param.dev_head->bufs[0].fb_id,
|
static int first_frame = 1;
|
||||||
DRM_MODE_PAGE_FLIP_EVENT, gp_cfg_param->drm_param.dev_head);
|
if(first_frame) {
|
||||||
|
drm_dev_t* dev = gp_cfg_param->drm_param.dev_head;
|
||||||
|
/* First buffer to DRM */
|
||||||
|
if (drmModeSetCrtc(gp_cfg_param->drm_param.fd,
|
||||||
|
dev->crtc_id, dev->bufs[drm_buf_id].fb_id,
|
||||||
|
0, 0, &dev->conn_id, 1, &dev->mode)) {
|
||||||
|
fatal("drmModeSetCrtc() failed");
|
||||||
|
}
|
||||||
|
/* First flip */
|
||||||
|
drmModePageFlip(gp_cfg_param->drm_param.fd,
|
||||||
|
dev->crtc_id, dev->bufs[drm_buf_id].fb_id,
|
||||||
|
DRM_MODE_PAGE_FLIP_EVENT, dev);
|
||||||
|
first_frame = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
stf_v4l2_queue_buffer(pv4l2_param, buf.index);
|
||||||
LOG(STF_LEVEL_LOG, "buf.index: %d, buf.bytesused=%d\n", buf.index, buf.bytesused);
|
LOG(STF_LEVEL_LOG, "buf.index: %d, buf.bytesused=%d\n", buf.index, buf.bytesused);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case IO_METHOD_USERPTR:
|
case IO_METHOD_USERPTR:
|
||||||
|
{
|
||||||
stf_v4l2_dequeue_buffer(pv4l2_param, &buf);
|
stf_v4l2_dequeue_buffer(pv4l2_param, &buf);
|
||||||
imageProcess((uint8_t *)(buf.m.userptr), dst, buf.timestamp);
|
imageProcess((uint8_t *)(buf.m.userptr), dst, buf.timestamp);
|
||||||
stf_v4l2_queue_buffer(pv4l2_param, buf.index);
|
stf_v4l2_queue_buffer(pv4l2_param, buf.index);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case IO_METHOD_DMABUF:
|
case IO_METHOD_DMABUF:
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@@ -528,6 +549,15 @@ static void page_flip_handler(int fd, unsigned int frame,
|
|||||||
DRM_MODE_PAGE_FLIP_EVENT, dev);
|
DRM_MODE_PAGE_FLIP_EVENT, dev);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void mmap_page_flip_handler(int fd, unsigned int frame,
|
||||||
|
unsigned int sec, unsigned int usec,
|
||||||
|
void *data)
|
||||||
|
{
|
||||||
|
drmModePageFlip(gp_cfg_param->drm_param.fd, gp_cfg_param->drm_param.dev_head->crtc_id,
|
||||||
|
gp_cfg_param->drm_param.dev_head->bufs[drm_buf_id].fb_id,
|
||||||
|
DRM_MODE_PAGE_FLIP_EVENT, gp_cfg_param->drm_param.dev_head);
|
||||||
|
}
|
||||||
|
|
||||||
static void mainloop()
|
static void mainloop()
|
||||||
{
|
{
|
||||||
struct v4l2_buffer buf;
|
struct v4l2_buffer buf;
|
||||||
@@ -538,14 +568,30 @@ static void mainloop()
|
|||||||
uint32_t nfds = 0;
|
uint32_t nfds = 0;
|
||||||
|
|
||||||
LOG(STF_LEVEL_TRACE, "Enter\n");
|
LOG(STF_LEVEL_TRACE, "Enter\n");
|
||||||
if (STF_DISP_FB == gp_cfg_param->disp_type ||
|
if (STF_DISP_FB == gp_cfg_param->disp_type) {
|
||||||
IO_METHOD_MMAP == gp_cfg_param->io_mthd) {
|
// fb
|
||||||
// fb or (drm + mmap)
|
|
||||||
nfds = 1;
|
nfds = 1;
|
||||||
fds = (struct pollfd*)malloc(sizeof(struct pollfd) * nfds);
|
fds = (struct pollfd*)malloc(sizeof(struct pollfd) * nfds);
|
||||||
memset(fds, 0, sizeof(struct pollfd) * nfds);
|
memset(fds, 0, sizeof(struct pollfd) * nfds);
|
||||||
fds[0].fd = gp_cfg_param->v4l2_param.fd;
|
fds[0].fd = gp_cfg_param->v4l2_param.fd;
|
||||||
fds[0].events = POLLIN;
|
fds[0].events = POLLIN;
|
||||||
|
|
||||||
|
} else if (STF_DISP_DRM == gp_cfg_param->disp_type &&
|
||||||
|
IO_METHOD_MMAP == gp_cfg_param->io_mthd) {
|
||||||
|
// drm + mmap
|
||||||
|
nfds = 2;
|
||||||
|
fds = (struct pollfd*)malloc(sizeof(struct pollfd) * nfds);
|
||||||
|
memset(fds, 0, sizeof(struct pollfd) * nfds);
|
||||||
|
fds[0].fd = gp_cfg_param->v4l2_param.fd;
|
||||||
|
fds[0].events = POLLIN;
|
||||||
|
fds[1].fd = gp_cfg_param->drm_param.fd;
|
||||||
|
fds[1].events = POLLIN;
|
||||||
|
|
||||||
|
memset(&ev, 0, sizeof ev);
|
||||||
|
ev.version = DRM_EVENT_CONTEXT_VERSION;
|
||||||
|
ev.vblank_handler = NULL;
|
||||||
|
ev.page_flip_handler = mmap_page_flip_handler;
|
||||||
|
|
||||||
} else if (STF_DISP_DRM == gp_cfg_param->disp_type &&
|
} else if (STF_DISP_DRM == gp_cfg_param->disp_type &&
|
||||||
IO_METHOD_DMABUF == gp_cfg_param->io_mthd) {
|
IO_METHOD_DMABUF == gp_cfg_param->io_mthd) {
|
||||||
// (drm + dmabuf)
|
// (drm + dmabuf)
|
||||||
@@ -589,19 +635,44 @@ static void mainloop()
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (STF_DISP_FB == gp_cfg_param->disp_type ||
|
if (STF_DISP_FB == gp_cfg_param->disp_type) {
|
||||||
IO_METHOD_MMAP == gp_cfg_param->io_mthd) {
|
// fb
|
||||||
// fb or (drm + mmap)
|
|
||||||
if (fds[0].revents & POLLIN) {
|
if (fds[0].revents & POLLIN) {
|
||||||
frameRead();
|
frameRead();
|
||||||
calc_frame_fps();
|
calc_frame_fps();
|
||||||
}
|
}
|
||||||
|
} else if (STF_DISP_DRM == gp_cfg_param->disp_type &&
|
||||||
|
IO_METHOD_MMAP == gp_cfg_param->io_mthd) {
|
||||||
|
// drm + mmap
|
||||||
|
if (fds[0].revents & POLLIN) {
|
||||||
|
frameRead();
|
||||||
|
calc_frame_fps();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fds[1].revents & POLLIN) {
|
||||||
|
drmHandleEvent(gp_cfg_param->drm_param.fd, &ev);
|
||||||
|
}
|
||||||
} else if (STF_DISP_DRM == gp_cfg_param->disp_type &&
|
} else if (STF_DISP_DRM == gp_cfg_param->disp_type &&
|
||||||
IO_METHOD_DMABUF == gp_cfg_param->io_mthd) {
|
IO_METHOD_DMABUF == gp_cfg_param->io_mthd) {
|
||||||
// drm + dmabuf
|
// drm + dmabuf
|
||||||
if (fds[0].revents & POLLIN) {
|
if (fds[0].revents & POLLIN) {
|
||||||
int dequeued = stf_v4l2_dequeue_buffer(&gp_cfg_param->v4l2_param, &buf);
|
int dequeued = stf_v4l2_dequeue_buffer(&gp_cfg_param->v4l2_param, &buf);
|
||||||
if (dequeued) {
|
if (dequeued) {
|
||||||
|
static int first_frame = 1;
|
||||||
|
if(first_frame) {
|
||||||
|
drm_dev_t* dev = gp_cfg_param->drm_param.dev_head;
|
||||||
|
/* First buffer to DRM */
|
||||||
|
if (drmModeSetCrtc(gp_cfg_param->drm_param.fd,
|
||||||
|
dev->crtc_id, dev->bufs[buf.index].fb_id,
|
||||||
|
0, 0, &dev->conn_id, 1, &dev->mode)) {
|
||||||
|
fatal("drmModeSetCrtc() failed");
|
||||||
|
}
|
||||||
|
/* First flip */
|
||||||
|
drmModePageFlip(gp_cfg_param->drm_param.fd,
|
||||||
|
dev->crtc_id, dev->bufs[buf.index].fb_id,
|
||||||
|
DRM_MODE_PAGE_FLIP_EVENT, dev);
|
||||||
|
first_frame = 0;
|
||||||
|
}
|
||||||
g_drm_buf_next_idx = buf.index;
|
g_drm_buf_next_idx = buf.index;
|
||||||
frameRead(); // TODO: add support for save file later
|
frameRead(); // TODO: add support for save file later
|
||||||
calc_frame_fps();
|
calc_frame_fps();
|
||||||
@@ -618,7 +689,7 @@ static void mainloop()
|
|||||||
count = 3;
|
count = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
usleep(1 * 1000);
|
//usleep(1 * 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fds) {
|
if (fds) {
|
||||||
|
|||||||
Reference in New Issue
Block a user