Skip to content

use libv4l2 (https://github.com/philips/libv4l) for local USB cameras .#3733

Open
sletteland wants to merge 5 commits intoZoneMinder:masterfrom
sletteland:libv4l2
Open

use libv4l2 (https://github.com/philips/libv4l) for local USB cameras .#3733
sletteland wants to merge 5 commits intoZoneMinder:masterfrom
sletteland:libv4l2

Conversation

@sletteland
Copy link
Copy Markdown
Contributor

This allows very simple/primitive cameras to work out of the box . (like USB cameras using the gspca driver )

simple/primitive USB cameras ( for example using the gspsa driver ) do not work properly with ZoneMinder (zmc keeps crashing )

for example : 0c45:6005 Microdia Sweex Mini Webcam ,

I propose a fix for that (patch against zm 37.40 / master dev )
This uses libv4l2 (https://github.com/philips/libv4l) for local USB cameras .

This allows very simple/primitive cameras to work out of the box .
(like for example USB cameras using the gspca driver )

A pull Request has just been made (sletteland/zoneminder branch libv4l2 )

root and others added 2 commits July 2, 2023 10:07
This allows very simple/primitive cameras to work out of the box .
(like USB cameras using the gspca driver )
@connortechnology
Copy link
Copy Markdown
Member

This is straight forward enough.

My understand in the past was that we could load v4l2 at runtime but I never got it to work. So perhaps this is the way to go.

We will need to add the lib to the package dependencies as well.

I am going to have to dig up my lego cam to see if this allows it to work!

@connortechnology
Copy link
Copy Markdown
Member

I think my issue with this is... it makes v4l2 a requirement... it should fall back to not using v4l2. So I'm not opposed to this, but we need #else conditions

@sletteland
Copy link
Copy Markdown
Contributor Author

sletteland commented Jul 2, 2025 via email

@connortechnology
Copy link
Copy Markdown
Member

Hey @sletteland did you ever get logged back into github?

Not much on the h265 front, other than some work to support on-the-fly re-encode to h264 for those who can't support h265. WE have the go2rtc support, so if your browser supports it, it should work. I havn't tested it though.

Just a ping here, I am aiming at Christmas for a 1.38 release and would love to get this in. I am thinking to just merge it as is... I think making v4l2 a required lib is not such a big deal anymore. I'll give it a test with my available v4l2 devices and see if it breaks anything.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to improve stability/compatibility for “primitive” local USB V4L2 cameras by routing LocalCamera device access through libv4l2 (v4l2_open/ioctl/mmap/etc.) instead of direct syscalls.

Changes:

  • Switch LocalCamera device open/ioctl/mmap/munmap/close calls to libv4l2 wrappers.
  • Add libv4l2 header include and adjust ioctl wrapper to use v4l2_ioctl.
  • Change CMake default ZM_EXTRA_LIBS to include v4l2.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
src/zm_local_camera.cpp Uses libv4l2 wrappers for device access; adds libv4l2 include and modifies open/mmap/close paths.
CMakeLists.txt Changes default extra libraries to link against libv4l2.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 28 to +53
@@ -38,13 +42,15 @@
static unsigned int BigEndian;
static bool primed;

#if ZM_HAS_V4L2
static int vidioctl(int fd, int request, void *arg) {
int result = -1;
do {
result = ioctl(fd, request, arg);
result = v4l2_ioctl( fd, request, arg );
} while( result == -1 && errno == EINTR );
return result;
}
#endif // ZM_HAS_V4L2
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#if ZM_HAS_V4L2 is currently based on finding linux/videodev2.h, but this patch unconditionally includes/uses libv4l2 (<libv4l2.h>, v4l2_open/ioctl/mmap/...) under the same macro. Systems with V4L2 headers but without libv4l2 installed will now fail to compile/link. Consider adding a separate CMake check for the V4L2::libv4l2 component and guarding the libv4l2 include/calls behind a dedicated macro, with a fallback to open/ioctl/mmap/close when libv4l2 is unavailable.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot open a new pull request to apply changes based on this feedback

connortechnology and others added 3 commits March 10, 2026 17:08
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants