Giter VIP home page Giter VIP logo

vcam's Introduction

vcam: Virtual camera device driver for Linux

This Linux module implements a simplified virtual V4L2 compatible camera device driver with raw framebuffer input.

Prerequisite

The following packages must be installed before building vcam.

In order to compile the kernel driver successfully, package versions of currently used kernel, kernel-devel and kernel-headers need to be matched.

$ sudo apt install linux-headers-$(uname -r)

Since vcam is built with V4L2 (Video4Linux, second version), v4l-utils is necessary for retrieving more information and function validation:

$ sudo apt install v4l-utils

Build and Run

After running make, you should be able to generate the following files:

  • vcam.ko - Linux kernel module;
  • vcam-util - Sample utility to configure virtual camera device(s);

Before loading this kernel module, you have to satisfy its dependency:

$ sudo modprobe -a videobuf2_vmalloc videobuf2_v4l2

The module can be loaded to Linux kernel by runnning the command:

$ sudo insmod vcam.ko

Expectedly, three device nodes will be created in /dev:

  • videoX - V4L2 device;
  • vcamctl - Control device for virtual camera(s), used by control utility vcam-util;
  • fbX - controlling framebuffer device;

In /dev directory, device file fbX will be created.

The device if initialy configured to process 640x480 RGB24 image format. By writing 640x480 RGB24 raw frame data to /dev/fbX file the resulting video stream will appear on corresponding /dev/videoX V4L2 device(s).

Run vcam-util --help for more information about how to configure, add or remove virtual camera devices. e.g. list all available virtual camera device(s):

$ sudo ./vcam-util -l

You should get:

Available virtual V4L2 compatible devices:
1. fbX(640,480,rgb24) -> /dev/video0

You can use this command to check if the driver is ok:

$ sudo v4l2-compliance -d /dev/videoX -f

It will return a bunch of test lines, with 0 failed and 0 warnings at the end.

You can check if all configured formats and emulated controls are ok with this command:

$ sudo v4l2-ctl -d /dev/videoX --all

You will get information as following:

Driver Info:
	Driver name   : vcam
	Card type     : vcam
	Bus info      : platform: virtual
	Driver version: 4.15.18
	Capabilities  : 0x85200001
		Video Capture
		Read/Write
		Streaming
		Extended Pix Format
		Device Capabilities

You can check framebuffer format with this command:

$ sudo fbset -fb /dev/fbX --info

You will get information as following:

mode "640x480"
    geometry 640 480 640 480 24
    timings 0 0 0 0 0 0 0
    rgba 8/0,8/8,8/16,0/0
endmode

Frame buffer device information:
    Name        : vcamfb
    Address     : 0xffffa293438ed000
    Size        : 921600
    Type        : PACKED PIXELS
    Visual      : TRUECOLOR

Available parameters for vcam kernel module:

  • devices_max - Maximal number of devices. The default is 8.
  • create_devices - Number of devices to be created during initialization. The default is 1.
  • allow_pix_conversion - Allow pixel format conversion from RGB24 to YUYV. The default is OFF.
  • allow_scaling - Allow image scaling from 480p to 720p. The default is OFF.
  • allow_cropping - Allow image cropping in Four-Thirds system. The default is OFF.

When you load a module using insmod command, you can supply the parameters as key=value pairs for example:

$ sudo insmod vcam.ko allow_pix_conversion=1

Related Projects

License

vcam is released under the MIT License. Use of this source code is governed by a MIT License that can be found in the LICENSE file.

vcam's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

vcam's Issues

`/proc/fbX` not created

I can't forward image because of not created /proc/fbX

# ./vcam-util -l
Available virtual V4L2 compatible devices:
1. vcamfb0(640,480,rgb24) -> /dev/video0
2. vcamfb1(640,480,rgb24) -> /dev/video1
3. vcamfb2(640,480,rgb24) -> /dev/video2

# ls -al /proc/fb*
-r--r--r-- 1 root root 0 Jul  4 06:01 /proc/fb

Support ffmpeg streaming

Current vcam still need to process rawdata by users to framebuffer, and only support vlc player for display. vcam should at least support ffmpeg and ffplay for streaming display.

Fbset crashes the driver

To crash the driver is enough to use fbset on the framebuffer device to change the resolution:
fbset -xres 1920 -yres 1080 -fb /dev/fb1

What should happen instead:
if the ioctl used by fbset is unsupported, the driver should not crash, but return some error to the userspace.

Differentiation

First, thank you for making vcam and thank you for listing similar projects. One of the joys of open source is seeing developers being friendly to each other out and not treating alternatives as "competitors".

Now, my request. I know you probably don't want to talk bad about anybody else's software, but it would be helpful if there was some sort of chart showing the similarities and differences between vcam, v4l2loopback, and akvcam.

In particular, I'm running into a limitation where v4l2loopback works fine in Firefox, but the Chromium browser doesn't want to open my virtual camera. There are various ugly workarounds that people mention, like chmod 000 /dev/video0, which don't even work for me.

What improvements does vcam offer? Does it play nice with whatever the heck Chromium is looking for in a video camera?

Thanks!

Can't change video manually

I wrote the test.c as below

#include <fcntl.h>
#include <stdlib.h>
#include <signal.h>
#include <sys/ioctl.h>
#include <unistd.h>

static char fb_path[128] = "/dev/fb1";
static int fd;

void signal_exit_handler(int sig)
{
    close(fd);
    exit(0);
}

int main()
{
    signal(SIGINT, signal_exit_handler);
    fd = open(fb_path, O_RDWR);
    unsigned char rgb[3] = {10, 60, 128};
    while (1) {
        for (int i = 0; i < 480; i++) {
            for (int j = 0; j < 640; j++) {
                write(fd, rgb, sizeof(rgb));
            }
        }
        for (int i = 0; i < 3; i++) {
            rgb[i]++;
        }
    }
    return 0;
}

after compile I enter this command

./test # terminal 1
vlc v4l2:///dev/video2 # terminal 2

but video is still the original black and white gradient picture

Problem in `VIDIOC_G/TRY/S_FMT` on `allow_scaling=1` and `allow_cropping=1`

There is a few problems in VIDIOC_G/TRY/S_FMT implementation. Some issue result in test fail on v4l2-compliance, others comes from that the implement is incompliant with document description, and nevertheless some questions from my own.

allow_scaling=1

  1. allow_scaling=1 will lead to test failure on VIDIOC_G/TRY/S_FMT (710). The issue comes from the inconsistency, which the return format first acquire from G_FMT should match the later returning format from TRY_FMT.
createInvalidFmt(fmt, clip, type);
doioctl(node, VIDIOC_G_FMT, &fmt);
fmt_try = fmt;
ret = doioctl(node, VIDIOC_TRY_FMT, &fmt_try);
...
if (!matchFormats(fmt, fmt_try))
    result = fail("%s: TRY_FMT(G_FMT) != G_FMT\n",
            buftype2s(type).c_str());
  1. While vcam device with parameter setting allow_scaling=1, TRY_FMT would force to change the ouputbuffer and vcamfb size to {1280, 720}, I am curious that is it intended?
/* find the nearest size from {vcam_sizes[n_avail - 1].width, vcam_sizes[n_avail - 1].height}
 * which is specify to {1280, 720}
 */
const struct v4l2_frmsize_discrete *sz = v4l2_find_nearest_size(
            vcam_sizes, n_avail, width, height, vcam_sizes[n_avail - 1].width,
            vcam_sizes[n_avail - 1].height);
  1. If the behavior is intended, there will be two problem for the implementation:
  • 3.1 According to the document, TRY_FMT should not change the driver state. The job should transfer to S_FMT to accomplish.

The VIDIOC_TRY_FMT ioctl is equivalent to VIDIOC_S_FMT with one exception: it does not change driver state. It can also be called at any time, never returning EBUSY. This function is provided to negotiate parameters, to learn about hardware limitations, without disabling I/O or possibly time consuming hardware preparations.

  • 3.2 When allow_scaling=1, TRY_FMT will always return fmt with size={1280, 720}. Than test [710] will always fail if default size was not {1280, 720}.

allow_cropping=1

  1. dev->crop_output_format is first assign in TRY_FMT. However in practice, application would first call G_FMT to query current format, than further call S_FMT to modify the desire format. The problem lead to test fail in (441) and also (710). The assignment should be happen before G_FMT were called. (In my opinion, it might be reasonable to assign while create_vcam_device).

Good practice is to query the current parameters first, and to modify only those parameters not suitable for the application.

vcamfb_update

  1. This is a question from me only. I am not sure why it is necessary to update the vcamfb after TRY/S_FMT, while the device can handle different input and output buffer format in submit_copy_buffer
  2. Finally, what is the difference between fb.c/vcamfb_update and control.c/control_iocontrol_modify_input_setting, in my opinion, the two function has similar purpose and might be a chance to combine together?

Warnings raised by Sparse

Sparse is a semantic checker for C programs; it can be used to find a number of potential problems with kernel code. There are various warnings raised by Sparse.

Steps:

  1. Make sure sparse installed in advance. See https://www.kernel.org/doc/html/latest/dev-tools/sparse.html
  2. Run the command:
make -C /lib/modules/`uname -r`/build M=`pwd` modules C=1

Warnings:

control.c:47:5: warning: cast removes address space '__user' of expression
control.c:61:5: warning: cast removes address space '__user' of expression
fb.c:101:45: warning: cast removes address space '__user' of expression
fb.c:101:45: warning: incorrect type in argument 2 (different address spaces)
fb.c:101:45:    expected void const [noderef] __user *from
fb.c:101:45:    got void
fb.c:227:45: warning: cast removes address space '__user' of expression
fb.c:227:45: warning: incorrect type in argument 2 (different address spaces)
fb.c:227:45:    expected void const [noderef] __user *from
fb.c:227:45:    got void *

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.