Skip to content

Releases: vladimirvivien/go4vl

v0.0.5

02 Oct 17:32
5e2fbd8
Compare
Choose a tag to compare

This release primarily focused on code changes to support updates to the webcam example, including:

  • New updates to the webcam example GUI
  • Streaming loop code update to copy frames to corruption by device during capture
  • Update webcam to include face detection feature
  • New examples including snapshot and simplecam
  • Updates to the example documentation

v0.0.4

18 Sep 21:18
b1aac42
Compare
Choose a tag to compare

This release introduced crucial bug fixes and other features including:

  • Support for extended controls (i.e. querying, value get/set, enumerating)
  • Capture sequence refactor to fix device-open bug
  • Memory leak identified when running video capture programs for long period

Support for extended video controls

This release introduces support for V4L2 extended controls.

  • Use existing control types, values for V4L2 extended control features
  • Addition of low level Go functions to query, get, and set control values
  • Ability to enumerate extended controls and their values.

The following example shows how to retrieve all available extended controls from the driver.

func main() {
	device, err := dev.Open("/dev/video0")
	if err != nil {
		log.Fatalf("failed to open device: %s", err)
	}
	defer device.Close()

	ctrls, err := v4l2.QueryAllExtControls(device.Fd())
	if err != nil {
		log.Fatalf("failed to get ext controls: %s", err)
	}
	if len(ctrls) == 0 {
		log.Println("Device does not have extended controls")
		os.Exit(0)
	}
	for _, ctrl := range ctrls {
		printControl(ctrl)
	}
       
       func printControl(ctrl v4l2.Contro) { ... }
}

See full example here

Capture sequence refactor

Since the inception of the project, it was known there were some bugs that needed to be revisited. We found out that some of the examples were failing when running on a Raspberry PI and capturing from a Raspberry Pi HD camera module. The code's use of the Go's standard library os.OpenFile was causing the device to report busy (when compared to similar programs in C).

So this called for an overhaul of the entire capture sequence which delivered the followings

  • Fix device open failure by providing a simpler device operation that make system calls directly
  • Successful test using the Raspberry Pi's HD camera module connected as a capture device
  • Add more aggressive system call error handling for v4l2 calls including open, ioctl VIDIOC_QBUF, VIDIOC_DQBUFF, etc. This causes to run smoother, remove internal flickers that would happen sometimes

Memory leak fix

User @oyarzun reported a memory leak when running the webcam example (see issue #22). After a few hours of Go program profiling, it was found that the internal stream loop was leaking Go channel resources (by reinitialize the channel in the loop). After a simple fix (moving the channel initialization outside of the loop), the leak went away. After running the webcam program for over 25 hours on a RPi 3, it was observed that the memory consumption did not go over 1%. That was an awesome find.

v0.0.3

03 Sep 17:28
ab7db70
Compare
Choose a tag to compare

VL2 user control support

The main theme for this release is the introduction of the Control API with initial support of the V4L2 user controls. This release adds the followings:

  • Control types, values, and functions
  • Addition of low level Go functions, in the v4l2 package, to query, get, and set control values
  • Update to the Device type to add new methods to work with the control API
func main() {
        device, err := dev.Open(devName)
	if err != nil {
		log.Fatalf("failed to open device: %s", err)
	}
	defer device.Close()

        // set single device control value
        val := 12
        device.SetControlValue(v4l2.CtrlBrightness, v4l2.CtrlValue(val))

        // retrieve Control
        ctrl, _ := device.GetControl(ctrlID)

       fmt.Printf("Control id (%d) name: %s\t[min: %d; max: %d; step: %d; default: %d current_val: %d]\n",
		ctrl.ID, ctrl.Name, ctrl.Minimum, ctrl.Maximum, ctrl.Step, ctrl.Default, ctrl.Value)
}

For more detail, see the example

V4L2 header files added

Another improvement contributed by the community (thanks @ajcasagrande) is the inclusion of V4L2 header files as part of the project. This will provide consistent builds without relying on user's local header files (which can sometimes be outdated).

See the include directory for detail.

Local development

To ease local development for non-Linux environment, this release comes with a script that can launch a Canonical Ubuntu VM managed by Multipass. This provides a VM along with a fake V4L2 driver (V4L2Loopback) to help run and test the project without the need of an environment with a real video camera attached.

See the multipass directory for detail.

v0.0.2

21 May 16:32
4f52a3b
Compare
Choose a tag to compare

This release introduces major refactor that simplifies the way the API works. Unfortunately, these changes are not backward compatible with the previous version. Meaning, if you adopt this release, you will have to modify your existing code a bit.

The new device package

This release introduces a new device package to create and access device functionalities.

Creating a device with the device package

The device API creates a device without having to use the v4l2 directly.

import  "github.com/vladimirvivien/go4vl/device"

func main() {
    device, err := device.Open("/dev/video0")
    ...
}

function device.Open supports variable length arguments that can be used to specify the configuration of the device as it is being created:

func main() {
    device, err := device.Open("/dev/video0",
        device.WithIOType(v4l2.IOTypeMMAP),
        device.WithPixFormat(v4l2.PixFormat{PixelFormat: getFormatType(format), Width: uint32(width), Height: uint32(height)}),
        device.WithFPS(uint32(frameRate)),
    )
}

Starting a device

Once a device is created, it can be started with a context as shown below

func main() {
    device, err := device.Open("/dev/video0")
    ctx, stop := context.WithCancel(context.TODO())
    if err := device.Start(ctx); err != nil {
        log.Fatalf("failed to start stream: %s", err)
    }
}

Streaming device output

After a device has started, it's stream can be accessed as shown

func main() {
    device, err := device.Open("/dev/video0")
    ctx, stop := context.WithCancel(context.TODO())
    if err := device.Start(ctx); err != nil {
        log.Fatalf("failed to start stream: %s", err)
    }

    for frame := range device.GetOutput() {
    ....
    }
}

Other enhancements

This release introduces access to more device information via additional types.

  • Ability to enumerate all attached v4l2 devices
  • Enhanced device capability information (including capability description)
  • Access to media info (including bus info, driver, card, model, etc)
  • Driver version information
  • Video input information (i.e. video input status)
  • Enhanced pixel format description (including format sizes)
  • Enhanced crop capability (with default crop bounds)
  • Access to stream parameters (including both capture and output capabilities and capture modes)

See the device info example for detail.

v0.0.1

14 Nov 22:39
1a3878d
Compare
Choose a tag to compare

This release comes after an internal rewrite to use cgo-generated types and values (instead of hand-crafted types) to deal with type alignment issues. Since the project targets the Linux OS, there is no need to be concerned with portability or cross-platform supportability.

The API is the same from the previous release. However, there are some changes that will cause code breakage (if you are using the previously tagged version) in how some types expose their values.

Features

  • Capture and control video data from your Go programs
  • Idiomatic Go API for device access and video capture
  • Use cgo-generated types for correct data representation in Go
  • Use familiar types such as channels to stream video data
  • Exposes device enumeration and information
  • Provides device capture control
  • Access to video format information
  • Streaming support using memory map (other methods coming later)

Examples

The ./examples directory contains additional examples including:

  • device_info - queries and prints devince information
  • webcam - uses the v4l2 package to create a simple webcam that streams images from an attached camera accessible via a web page.