Skip to content

Commit

Permalink
Removed need V4L changed build method
Browse files Browse the repository at this point in the history
  • Loading branch information
Baoulettes committed Jul 1, 2022
1 parent c755ddd commit e1508b9
Show file tree
Hide file tree
Showing 116 changed files with 49,648 additions and 190 deletions.
61 changes: 0 additions & 61 deletions CMakeLists.txt

This file was deleted.

99 changes: 99 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
CXX ?= g++
CC ?= gcc
LD := lld
AR := ar
FORMAT := clang-format-11

UNAME := $(shell uname)
UNAMEM := $(shell uname -m)

ASAN ?= 0
DEBUG ?= 1
OPTFLAGS ?= -O0
LTO ?= 0

WARN := \
-Wno-return-type \
-funsigned-char \
-fno-stack-protector -fno-common -fno-zero-initialized-in-bss -fno-strict-aliasing -fno-inline-functions -fno-inline-small-functions -fno-toplevel-reorder -ffreestanding -fwrapv \

CXXFLAGS := $(WARN) -std=c++20 -D_GNU_SOURCE -fpermissive -no-pie -nostdlib
CFLAGS := $(WARN) -std=c99 -D_GNU_SOURCE -no-pie -nostdlib
LDFLAGS :=

ifeq ($(UNAME), Linux) #LINUX
CXXFLAGS += -mhard-float -msse2 -mfpmath=sse
CFLAGS += -mhard-float -msse2 -mfpmath=sse
endif

CPPFLAGS := -MMD


ifeq ($(UNAME), Linux) #LINUX
TARGET := lgxuserspace.elf
endif

INC_DIRS := $(addprefix -I, \
. \
src \
utils \
)

ifeq ($(UNAME), Linux) #LINUX
INC_DIRS += $(addprefix -I, \
/opt/X11/include \
)
endif


LDLIBS := \
$(addprefix -l, \
usb-1.0 \
pcap \
)

ifeq ($(UNAME), Linux) #LINUX
LDLIBS += \
$(addprefix -l, \
X11 \
SDL2 \
GL \
GLEW \
pulse-simple \
)
endif

CXX_FILES := \
$(shell find src -type f -name "*.cpp")

C_FILES := \
$(shell find utils -type f -name "*.c")

O_FILES := \
$(C_FILES:%.c=build/%.o) \
$(CXX_FILES:%.cpp=build/%.o)
D_FILES := $(O_FILES:%.o=%.d)

# create build directory
SRC_DIRS := $(shell find . -type d -a -not -path "*build*")
$(shell mkdir -p $(SRC_DIRS:%=build/%))

all:
$(MAKE) $(TARGET)

clean:
rm -rf build $(TARGET)

.PHONY: all clean

build/%.o: %.cpp
$(CXX) -c $(CXXFLAGS) $(CPPFLAGS) $(OPTFLAGS) $(INC_DIRS) $< -o $@

build/%.o: %.c
$(CC) -c $(CFLAGS) $(CPPFLAGS) $(OPTFLAGS) $(INC_DIRS) $< -o $@


$(TARGET): $(O_FILES)
$(CXX) $^ -o $@ $(LDFLAGS) $(LDDIRS) $(LDLIBS)

-include $(D_FILES)
52 changes: 19 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# LGX2 Userspace driver (with LGX support)
This software is little more than a POC and no guarantees of functionality are given and it may even be dangerous to use this software. Please
consider contacting AverMedia for a supported Linux driver.

This software is based on : [ChrisAJS/lgx2userspace]https://github.com/ChrisAJS/lgx2userspace

All thanks to them to make it possible.

All I do is minor tweak to meet my needs.

Maybe someone else would find it useful



This project contains a userspace driver for the [AverMedia LGX2 (GC551)](https://avermedia.com/LGX2) as well support for the [AverMedia LGX (GC550)](https://avermedia.com/LGX).

Expand All @@ -9,37 +17,29 @@ to forward the captured video and audio to a virtual video capture device.

## Building
To build the project, you will need:
* CMake
* Libusb
* Libpcap
* SDL2
* V4L2Loopback

Execute the following commands to build in the root of the project:

```bash
mkdir build && cd build
cmake ..
make
make -j $(nproc)
```

## Setup
The userspace driver will require read and write access to the LGX/LGX2.

On a Linux system, this can be granted to the user by adding the following rules to Udev.
You want to clean it ?

```bash
sudo cp 999-avermedia.rules /etc/udev/rules.d/999-avermedia.rules
sudo udevadm control --reload-rules
make clean
```

After the rule has been added, unplug and re-plug in the LGX/LGX2.

## Running
This gonna have a a system redesign, you will be able to select it with a Dear ImGui menu.
Once udev has been configured to grant read and write permission to the device it
will be possible to run the application by executing `lgx2userspace`.
will be possible to run the application by executing `lgx2userspace.elf`.

If you are using the LGX GC550, use the command line option `x` - `./lgx2userspace -x`.
If you are using the LGX GC550, use the command line option `x` - `./lgx2userspace.elf -x`.

The application will take a few seconds to run as it streams setup information to the device,
and it will eventually display a window that will then start to display captured frames.
Expand All @@ -49,8 +49,7 @@ started. For example, a Nintendo Switch will not recognise the LGX/LGX2 as an ou
it is undocked and re-docked.

### Options when running
When using the default SDL2 renderer for video output, it is possible to toggle fullscreen
by pressing `F` and to exit fullscreen by pressing `G`.
--will be updated with something cool soon

### Gathering diagnostic information
To help diagnose problems that may be fixed in the future, when submitting an issue
Expand All @@ -63,21 +62,8 @@ process frame data and time taken to render both audio and video.
This information could be valuable when identifying issues so please try your best to include it
in any issues you raise, thank you!

## Running with V4L2 Output and Pulseaudio Output
### V4L2 Output setup
To output video to a virtual webcam output source, load the V4L2 Loopback Linux module with an easy to identify device
number:

```bash
sudo modprobe v4l2loopback video_nr=99 exclusive_caps=1 card_label="LGX2"
```

You should now see `/dev/video99` exists:

```bash
ls /dev/video99
/dev/video99
```
## Running with Pulseaudio Output
All that too I want to simplify it.

### Pulseaudio Setup
Pulseaudio can be configured by issuing the following commands:
Expand Down
111 changes: 111 additions & 0 deletions README_original.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# LGX2 Userspace driver (with LGX support)
This software is little more than a POC and no guarantees of functionality are given and it may even be dangerous to use this software. Please
consider contacting AverMedia for a supported Linux driver.

This project contains a userspace driver for the [AverMedia LGX2 (GC551)](https://avermedia.com/LGX2) as well support for the [AverMedia LGX (GC550)](https://avermedia.com/LGX).

It can be used to display the captured video and audio in a standalone window or
to forward the captured video and audio to a virtual video capture device.

## Building
To build the project, you will need:
* CMake
* Libusb
* Libpcap
* SDL2
* V4L2Loopback

Execute the following commands to build in the root of the project:

```bash
mkdir build && cd build
cmake ..
make
```

## Setup
The userspace driver will require read and write access to the LGX/LGX2.

On a Linux system, this can be granted to the user by adding the following rules to Udev.

```bash
sudo cp 999-avermedia.rules /etc/udev/rules.d/999-avermedia.rules
sudo udevadm control --reload-rules
```

After the rule has been added, unplug and re-plug in the LGX/LGX2.

## Running
Once udev has been configured to grant read and write permission to the device it
will be possible to run the application by executing `lgx2userspace`.

If you are using the LGX GC550, use the command line option `x` - `./lgx2userspace -x`.

The application will take a few seconds to run as it streams setup information to the device,
and it will eventually display a window that will then start to display captured frames.

In my limited testing, certain devices may need to be re-plugged in after the application has
started. For example, a Nintendo Switch will not recognise the LGX/LGX2 as an output source until
it is undocked and re-docked.

### Options when running
When using the default SDL2 renderer for video output, it is possible to toggle fullscreen
by pressing `F` and to exit fullscreen by pressing `G`.

### Gathering diagnostic information
To help diagnose problems that may be fixed in the future, when submitting an issue
please try to give as much information about your setup as possible and in the case of
inadequate video or audio output, run the userspace driver with the `-v` switch enabled.

With the `-v` switch enabled, the driver will output information regarding time taken to
process frame data and time taken to render both audio and video.

This information could be valuable when identifying issues so please try your best to include it
in any issues you raise, thank you!

## Running with V4L2 Output and Pulseaudio Output
### V4L2 Output setup
To output video to a virtual webcam output source, load the V4L2 Loopback Linux module with an easy to identify device
number:

```bash
sudo modprobe v4l2loopback video_nr=99 exclusive_caps=1 card_label="LGX2"
```

You should now see `/dev/video99` exists:

```bash
ls /dev/video99
/dev/video99
```

### Pulseaudio Setup
Pulseaudio can be configured by issuing the following commands:
```bash
pactl load-module module-null-sink sink_name=lgx2 sink_properties=device.description=LGX2
pactl load-module module-remap-source master=lgx2.monitor source_name=lgx2 source_properties=device.description=LGX2Audio
```
This will create an audio sink called `LGX2 Audio Sink` which can be added to OBS as a Pulseaudio output capture device.

**NOTE: Even if you are using the LGX GC550- leaving the names as lgx2 is required and will not affect behaviour.**
**NOTE: The best way to control the audio volume is to use the gain OBS filter whilst leaving the sink volume at max.**

### Running with configure V4L2 device
Run the userspace driver with the `-d` option to specify which V4L2Loopback device to use:

```bash
./lgx2userspace -d /dev/video99
```

To run using the Pulseaudio sink that you created, use the `-a` switch with the name of the sink:

```bash
./lgx2userspace -a lgx2
```

**NOTE: You may need to unplug and replug in your video source.**

Go to OBS or other streaming software and select the LGX2 V4L2 source. You should now see video from the input device being output.

## Demo
See it in action over at [YouTube](https://www.youtube.com/watch?v=-yzHMbUn-w0).
Binary file added lgxuserspace.elf
Binary file not shown.
Loading

0 comments on commit e1508b9

Please sign in to comment.