From b21ddd251951faecb2cfda0cac2bf587379bcbf7 Mon Sep 17 00:00:00 2001 From: Kamil Trzcinski Date: Sun, 10 Apr 2022 14:29:22 +0200 Subject: [PATCH] Fix support for keyframes --- device/camera/camera.c | 1 + device/v4l2/device.c | 4 ++-- device/v4l2/device_media.c | 18 ++++++++++-------- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/device/camera/camera.c b/device/camera/camera.c index 4e0c1f1..fe45fd8 100644 --- a/device/camera/camera.c +++ b/device/camera/camera.c @@ -125,6 +125,7 @@ int camera_set_params(camera_t *camera) device_set_option_string(camera->codec_h264, "video_bitrate_mode", "0"); device_set_option_string(camera->codec_h264, "video_bitrate", "5000000"); + device_set_option_string(camera->codec_h264, "repeat_sequence_header", "1"); device_set_option_string(camera->codec_h264, "h264_i_frame_period", "30"); device_set_option_string(camera->codec_h264, "h264_level", "11"); device_set_option_string(camera->codec_h264, "h264_profile", "4"); diff --git a/device/v4l2/device.c b/device/v4l2/device.c index 03f50f4..e722565 100644 --- a/device/v4l2/device.c +++ b/device/v4l2/device.c @@ -13,6 +13,8 @@ int v4l2_device_open(device_t *dev) goto error; } + E_LOG_INFO(dev, "Device path=%s fd=%d opened", dev->path, dev->v4l2.dev_fd); + E_LOG_DEBUG(dev, "Querying device capabilities ..."); struct v4l2_capability v4l2_cap; E_XIOCTL(dev, dev->v4l2.dev_fd, VIDIOC_QUERYCAP, &v4l2_cap, "Can't query device capabilities"); @@ -23,8 +25,6 @@ int v4l2_device_open(device_t *dev) strcpy(dev->bus_info, v4l2_cap.bus_info); dev->v4l2.subdev_fd = v4l2_device_open_v4l2_subdev(dev, 0); - E_LOG_INFO(dev, "Device path=%s fd=%d opened", dev->path, dev->v4l2.dev_fd); - return 0; error: diff --git a/device/v4l2/device_media.c b/device/v4l2/device_media.c index 0b86e1a..fe94332 100644 --- a/device/v4l2/device_media.c +++ b/device/v4l2/device_media.c @@ -67,8 +67,9 @@ int v4l2_device_open_v4l2_subdev(device_t *dev, int subdev) }; int rc = ioctl(media_fd, MEDIA_IOC_ENUM_ENTITIES, &entity); - if (rc < 0 && errno == EINVAL) + if (rc < 0 && errno == EINVAL) { break; + } if (rc < 0) { goto error; @@ -79,26 +80,27 @@ int v4l2_device_open_v4l2_subdev(device_t *dev, int subdev) sprintf(path, "/sys/dev/char/%d:%d", entity.dev.major, entity.dev.minor); char link[256]; - if (readlink(path, link, sizeof(link)) < 0) { + if ((rc = readlink(path, link, sizeof(link)-1)) < 0) { E_LOG_ERROR(dev, "Cannot readlink '%s'", path); - goto error; } + link[rc] = 0; - char * last = strrchr(link, '/'); + char *last = strrchr(link, '/'); if (!last) { E_LOG_ERROR(dev, "Link '%s' for '%s' does not end with '/'", link, path); - goto error; } if (strstr(last, "/v4l-subdev") != last) { - goto error; + E_LOG_ERROR(dev, "Link '%s' does not contain '/v4l-subdev'", link, path); } sprintf(path, "/dev%s", last); ret = open(path, O_RDWR); - if (ret >= 0) { - E_LOG_INFO(dev, "Opened '%s' (fd=%d)", path, ret); + if (ret < 0) { + E_LOG_ERROR(dev, "Cannot open '%s' (ret=%d)", path, ret); } + + E_LOG_INFO(dev, "Opened '%s' (fd=%d)", path, ret); break; }