rockchip-linux / mpp

Media Process Platform (MPP) module
467 stars 156 forks source link

bug v4l2采集堵塞导致外设异常时无法退出 #546

Open xiangxud opened 3 months ago

xiangxud commented 3 months ago

增加一个非阻塞模式的ioctl static RK_S32 camera_source_ioctl_timeout(RK_S32 fd, RK_S32 req, void* arg, int timeout_sec) { struct timespec poll_time; RK_S32 ret;

// 将文件描述符设置为非阻塞模式
int flags = fcntl(fd, F_GETFL, 0);
fcntl(fd, F_SETFL, flags | O_NONBLOCK);

// 计算超时时间
struct timeval start_time, current_time;
gettimeofday(&start_time, NULL);
int elapsed_time = 0;

while ((ret = ioctl(fd, req, arg))) {
    if (ret == -1 && (EINTR != errno && EAGAIN != errno)) {
        mpp_err("ret = %d, errno %d", ret, errno);
        break;
    }
    //  else {
    //     if (ret == -1) {
    //         if (check_video_source_status(fd) != 0) {
    //             mpp_err("ret = %d, errno %d", ret, errno);
    //             break;
    //         }
    //     }
    // }

    // 检查超时
    gettimeofday(&current_time, NULL);
    elapsed_time = (current_time.tv_sec - start_time.tv_sec) * 1000 +
                   (current_time.tv_usec - start_time.tv_usec) / 1000;
    if (elapsed_time >= timeout_sec * 1000) {
        mpp_err("ioctl timeout");
        ret = -1;
        break;
    }

    mpp_log("camera_source_ioctl waiting ...");
    // 10 milliseconds
    poll_time.tv_sec = 0;
    poll_time.tv_nsec = 10000000;
    nanosleep(&poll_time, NULL);
}

// 还原文件描述符的阻塞模式
fcntl(fd, F_SETFL, flags);

return ret;

}

HermanChen commented 3 months ago

可以提交个完整的补丁~