Compare commits

...

32 Commits

Author SHA1 Message Date
dec05eba
ac15027657 5.13.1 2026-04-19 00:49:02 +02:00
dec05eba
5d03193f29 Fix compile error with old vulkan header: ifdef check vulkan video encoding 2026-04-19 00:42:00 +02:00
dec05eba
2f4a906b78 5.13.0 2026-04-17 01:13:57 +02:00
dec05eba
3e6bc0224a v4l2: skip resolutions that we cant import with eglCreateImage for yuyv 2026-04-17 01:10:27 +02:00
dec05eba
286158a838 Implement vulkan video capture (h264, hevc and av1) 2026-04-17 00:56:22 +02:00
dec05eba
8b953e95d8 wip 2026-04-16 00:01:18 +02:00
dec05eba
4ed04830c1 Add void linux to README, update pkill command 2026-03-18 15:39:41 +01:00
dec05eba
755340454d Poll reset revents 2026-03-11 11:32:45 +01:00
dec05eba
2f8212b122 5.12.5 2026-03-02 00:00:38 +01:00
dec05eba
23782889be Minor check 2026-03-01 23:52:59 +01:00
dec05eba
fd08cdb9b4 pipewire video: fail video map texture if state is not streaming
Fixes portal capture failing on some systems
2026-03-01 19:30:17 +01:00
dec05eba
6079a0162d Portal capture: test disable modifier recheck same 2026-03-01 18:12:00 +01:00
dec05eba
eff5d619eb Fix incorrect manpage 2026-02-25 01:08:05 +01:00
dec05eba
309c4e5f2e Update info about reporting bugs in the manpage, move gpu-screen-recorder.env to ~/.config/gpu-screen-recorder but keep old path as well 2026-02-23 23:15:09 +01:00
dec05eba
0555cfde58 FAQ browser av1 2026-02-19 22:29:55 +01:00
p0358
ff030ba63f don't show microphone indicator on KDE 2026-02-19 20:04:55 +01:00
dec05eba
0de75e5b7e 5.12.4 2026-02-12 01:24:26 +01:00
dec05eba
c79fb1e5c9 pipewire-video: do correct removal of modifier 2026-02-12 01:07:48 +01:00
eonphi
4a4af85b6d attempt EGLImage without modifiers when last failed 2026-02-12 00:41:21 +01:00
dec05eba
8f7608e7ee Add --list-monitors option to list only monitors, refactor 2026-02-09 15:03:10 +01:00
dec05eba
f3235ed1bf Improve manpage 2026-02-09 13:59:18 +01:00
dec05eba
3666bba518 aur -> official repo 2026-02-06 19:02:23 +01:00
dec05eba
5d8d14eeaf FAQ vlc 2026-02-04 01:43:27 +01:00
dec05eba
57caf13d65 5.12.3 2026-01-28 01:39:09 +01:00
dec05eba
bdf1950ca2 Dont use dbus_bus_request_name 2026-01-28 01:37:50 +01:00
Victor Nova
144b481526 Add -write-first-frame-ts switch
Add -write-first-frame-ts switch that creates a .ts file next to the output
file with values from CLOCK_MONOTONIC and CLOCK_REALTIME corresponding to the
first frame to be able to synchronize video with other timestamped data.
2026-01-27 17:43:41 +01:00
dec05eba
f4ee71a094 Remove fixed TODO 2026-01-26 15:18:26 +01:00
dec05eba
2dce92d82f Use constant bitrate mode in example scripts 2026-01-25 03:16:56 +01:00
Mroik
933911bdde Install example scripts and add fix man example 2026-01-25 03:08:15 +01:00
dec05eba
01d0df500c Revert "Test dont set environment variables"
This reverts commit 95415f7ac7.
2026-01-24 15:41:31 +01:00
dec05eba
95415f7ac7 Test dont set environment variables 2026-01-24 15:19:31 +01:00
dec05eba
a39dad1c02 Remove capture source property clamp, cleanup manpage 2026-01-23 01:39:49 +01:00
29 changed files with 1430 additions and 596 deletions

View File

@@ -29,14 +29,14 @@ Supported image formats:
This software works on X11 and Wayland on AMD, Intel and NVIDIA.
# Installation
If you are running an Arch Linux based distro then you can find gpu screen recorder on aur under the name gpu-screen-recorder (`yay -S gpu-screen-recorder`).\
If you are running an Arch Linux based distro then you can find gpu screen recorder in the official repositories under the name gpu-screen-recorder (`sudo pacman -S gpu-screen-recorder`).\
If you are running another distro then you can run `sudo ./install.sh`, but you need to manually install the dependencies, as described below.\
You can also install gpu screen recorder ([the ui version](https://git.dec05eba.com/gpu-screen-recorder-gtk/)) from [flathub](https://flathub.org/apps/details/com.dec05eba.gpu_screen_recorder), which is the easiest method
to install GPU Screen Recorder on non-arch based distros.\
If you install GPU Screen Recorder flatpak, which is the gtk gui version then you can still run GPU Screen Recorder command line by using the flatpak command option, for example `flatpak run --command=gpu-screen-recorder com.dec05eba.gpu_screen_recorder -w screen -f 60 -o video.mp4`. Note that if you want to record your monitor on AMD/Intel then you need to install the flatpak system-wide (like so: `flatpak install --system com.dec05eba.gpu_screen_recorder`).
## Unofficial install methods
The only official ways to install GPU Screen Recorder is either from source, AUR or flathub. Other sources may be out of date and missing features or may not work correctly.\
The only official ways to install GPU Screen Recorder is either from source, arch linux extra repository or flathub. Other sources may be out of date and missing features or may not work correctly.\
If you install GPU Screen Recorder from somewhere else and have an issue then try installing it from one of the official sources before reporting it as an issue.\
If you still prefer to install GPU Screen Recorder with a package manager instead of from source or as a flatpak then you may be able to find a package for your distro.\
Here are some known unofficial packages:
@@ -48,6 +48,7 @@ Here are some known unofficial packages:
* Solus: [gpu-screen-recorder](https://github.com/getsolus/packages/tree/main/packages/g/gpu-screen-recorder)
* Nobara: [Nobara wiki](https://wiki.nobaraproject.org/en/general-usage/additional-software/GPU-Screen-Recorder)
* AppImage [AppImage GitHub releases](https://github.com/pkgforge-dev/gpu-screen-recorder-AppImage/releases)
* Void Linux: [gpu-screen-recorder](https://voidlinux.org/packages/?arch=x86_64&q=gpu-screen-recorder) (Make sure to read the README in the package)
# Dependencies
GPU Screen Recorder uses meson build system so you need to install `meson` to build GPU Screen Recorder.
@@ -91,12 +92,12 @@ There are also additional dependencies needed at runtime depending on your GPU v
* xnvctrl (libxnvctrl0, when using the `-oc` option)
# How to use
Run `gpu-screen-recorder --help` to see all options and also examples.\
Run `gpu-screen-recorder --help` to see all options and run `man gpu-screen-recorder` to see more detailed explanations for the options and also examples.\
There is also a gui for the gpu screen recorder called [GPU Screen Recorder GTK](https://git.dec05eba.com/gpu-screen-recorder-gtk/).\
There is also a new alternative UI for GPU Screen Recorder in the style of ShadowPlay called [GPU Screen Recorder UI](https://git.dec05eba.com/gpu-screen-recorder-ui/).
## Recording
Here is an example of how to record your monitor and the default audio output: `gpu-screen-recorder -w screen -f 60 -a default_output -o ~/Videos/test_video.mp4`.
Yyou can stop and save the recording with `Ctrl+C` or by running `pkill -SIGINT -f gpu-screen-recorder`.
Yyou can stop and save the recording with `Ctrl+C` or by running `pkill -SIGINT -f "^gpu-screen-recorder"`.
You can see a list of capture options to record if you run `gpu-screen-recorder --list-capture-options`. This will list possible capture options and monitor names, for example:\
```
window
@@ -122,12 +123,12 @@ GPU Screen Recorder uses Ffmpeg so GPU Screen Recorder supports all protocols th
If you want to reduce latency one thing you can do is to use the `-keyint` option, for example `-keyint 0.5`. Lower value means lower latency at the cost of increased bitrate/decreased quality.
## Recording while using replay/streaming
You can record a regular video while using replay/streaming by launching GPU Screen Recorder with the `-ro` option to specify a directory where to save the recording (for example: `gpu-screen-recorder -w screen -c mp4 -r 60 -o "$HOME/Videos/replays" -ro "$HOME/Videos/recordings"`).\
To start/stop (and save) recording use the SIGRTMIN signal, for example `pkill -SIGRTMIN -f gpu-screen-recorder`. The path to the video will be displayed in stdout when saving the video.\
To start/stop (and save) recording use the SIGRTMIN signal, for example `pkill -SIGRTMIN -f "^gpu-screen-recorder"`. The path to the video will be displayed in stdout when saving the video.\
This way of recording while using replay/streaming is more efficient than running GPU Screen Recorder multiple times since this way it only records the screen and encodes the video once.
## Controlling GPU Screen Recorder remotely
To save a video in replay mode, you need to send signal SIGUSR1 to gpu screen recorder. You can do this by running `pkill -SIGUSR1 -f gpu-screen-recorder`.\
To stop recording send SIGINT to gpu screen recorder. You can do this by running `pkill -SIGINT -f gpu-screen-recorder` or pressing `Ctrl-C` in the terminal that runs gpu screen recorder. When recording a regular non-replay video this will also save the video.\
To pause/unpause recording send SIGUSR2 to gpu screen recorder. You can do this by running `pkill -SIGUSR2 -f gpu-screen-recorder`. This is only applicable and useful when recording (not streaming nor replay).\
To save a video in replay mode, you need to send signal SIGUSR1 to gpu screen recorder. You can do this by running `pkill -SIGUSR1 -f "^gpu-screen-recorder"`.\
To stop recording send SIGINT to gpu screen recorder. You can do this by running `pkill -SIGINT -f "^gpu-screen-recorder"` or pressing `Ctrl-C` in the terminal that runs gpu screen recorder. When recording a regular non-replay video this will also save the video.\
To pause/unpause recording send SIGUSR2 to gpu screen recorder. You can do this by running `pkill -SIGUSR2 -f "^gpu-screen-recorder"`. This is only applicable and useful when recording (not streaming nor replay).\
There are more signals to control GPU Screen Recorder. Run `gpu-screen-recorder --help` to list them all (under `NOTES` section).
## Simple way to run replay without gui
Run the script `scripts/start-replay.sh` to start replay and then `scripts/save-replay.sh` to save a replay and `scripts/stop-replay.sh` to stop the replay. The videos are saved to `$HOME/Videos`.
@@ -135,7 +136,7 @@ You can use these scripts to start replay at system startup if you add `scripts/
hotkey settings on your system and choose a hotkey to run the script `scripts/save-replay.sh`. Modify `scripts/start-replay.sh` if you want to use other replay options.
## Run replay on system startup
If you installed GPU Screen Recorder from AUR or from source and you are running a distro that uses systemd then you will have a systemd service installed that can be started with `systemctl enable --now --user gpu-screen-recorder`. This systemd service runs GPU Screen Recorder on system startup.\
It's configured with `$HOME/.config/gpu-screen-recorder.env` (create it if it doesn't exist). You can look at [extra/gpu-screen-recorder.env](https://git.dec05eba.com/gpu-screen-recorder/plain/extra/gpu-screen-recorder.env) to see an example.
It's configured with `$HOME/.config/gpu-screen-recorder/gpu-screen-recorder.env` (create it if it doesn't exist). You can look at [extra/gpu-screen-recorder.env](https://git.dec05eba.com/gpu-screen-recorder/plain/extra/gpu-screen-recorder.env) to see an example.
You can see which variables that you can use in the `gpu-screen-recorder.env` file by looking at the `extra/gpu-screen-recorder.service` file. Note that all of the variables are optional, you only have to set the ones that are you interested in.
You can use the `scripts/save-replay.sh` script to save a replay and by default the systemd service saves videos in `$HOME/Videos`.
## Run a script when a video is saved
@@ -209,7 +210,7 @@ Newer ffmpeg versions don't support older nvidia cards. Try installing GPU Scree
## I get a black screen/glitches while live streaming
It seems like ffmpeg earlier than version 6.1 has some type of bug. Install ffmpeg version 6.1 or later and then reinstall GPU Screen Recorder to fix this issue. The flatpak version of GPU Screen Recorder comes with a newer version of ffmpeg so no extra steps are needed.
## I can't play the video in my browser directly or in discord
Browsers and discord don't support hevc video codec at the moment. Choose h264 video codec instead with the -k h264 option.
Browsers and discord don't support hevc video codec at the moment. You can instead choose h264 video codec with the -k h264 option or av1 video codec with the -k av1 option.
Note that websites such as youtube support hevc so there is no need to choose h264 video codec if you intend to upload the video to youtube or if you want to play the video locally or if you intend to
edit the video with a video editor. Hevc allows for better video quality (especially at lower file sizes) so hevc (or av1) is recommended for source videos.
## I get a black bar/distorted colors on the sides in the video
@@ -261,3 +262,5 @@ If the root user is disabled on your system then you can instead record with `-w
## GPU usage is high on my laptop
GPU usage on battery powered devices is misleading. For example Intel iGPUs has multiple performance levels and the GPU usage reported on the system is the GPU usage at the current performance level.
The performance level changes depending on the GPU load, so it may say that GPU usage is 80%, but the actual GPU usage may be 5%.
## The video is too dark when capturing full-range video or 10-bit video
This is an issue in some broken video players such as vlc. Play the video with a video player such as mpv (or a mpv frontend such as celluloid) or a browser instead.

27
TODO
View File

@@ -312,10 +312,6 @@ Check if region capture works properly with fractional scaling on wayland.
Add option to specify medium/high/very high/ultra for -bm cbr as well, which should automatically pick bitrate based on resolution and framerate.
This should also be reflected in gsr ui.
Create a manpage and move --help text there and mention the manpage command to view it (and make it work in flatpak, maybe with man <link-to-manpage-file>).
Implement webcam support by using mjpeg with v4l2 and use ffmpeg mjpeg decoder.
After adding rpc, making recording while in replay/streaming work differently. Start recording should take audio as an argument, to optionally specify different audio for recording than replay/stream.
After adding rpc, make it possible to add/remove audio and video. The same number of audio tracks should remain, but the audio devices/app should be possible to configure. You should be able to configure the capture sources however you want.
@@ -398,4 +394,25 @@ Return the max resolution of each codec in --info to display an error in the UI
Should -low-power option also use vaapi/vulkan low power, if available?
Should capture option x=bla;y=bla be scaled by -s (output resolution scale)? width and height is.
Should capture option x=bla;y=bla be scaled by -s (output resolution scale)? width and height is.
Add option to capture all monitors automatically.
Make -w optional, to only capture audio.
Use GL_RGBA16F or GL_RGBA32F for hdr, that allows color values to be outside the 0.0 to 1.0 range.
https://registry.khronos.org/EGL/extensions/EXT/EGL_EXT_surface_SMPTE2086_metadata.txt
Doesn't work: sibs run --args -w "/dev/video0;camera_width=800;camera_height=600;pixfmt=yuyv" -fm content -o video.mp4
Delay adding audio data until 1 frames time has passed.
Allow av1 in the flatpak. Do that by patching ffmpeg to support multiple nvenc codepaths by using header versions, the same way gsr does in the nvenc query.
Increase qp on av1 non-nvidia, decrease qp on h264 nvidia. For vulkan.
Check if the vulkan codec query works on nvidia x11.
Fix webcam capture on nvidia x11. It doesn't work when capturing a webcam at the same time as capturing the monitor (nvfbc) because nvfbc requires glx context active (in older nvfbc version, works with egl in newer version)
while v4l2 requires egl. All other capture methods require egl so they cant be used together with nvfbc.

View File

@@ -3,6 +3,7 @@ Description=GPU Screen Recorder Service
[Service]
EnvironmentFile=-%h/.config/gpu-screen-recorder.env
EnvironmentFile=-%h/.config/gpu-screen-recorder/gpu-screen-recorder.env
Environment=WINDOW=screen
Environment=CONTAINER=mp4
Environment=QUALITY=40000

View File

@@ -14,13 +14,17 @@ gpu-screen-recorder \- The fastest screen recording tool for Linux
|
.B \-\-version
|
.B \-\-info
|
.B \-\-list\-capture\-options
|
.B \-\-list\-monitors
|
.B \-\-list\-v4l2\-devices
|
.B \-\-list\-audio\-devices
|
.B \-\-list\-application\-audio
|
.B \-\-info
.SH DESCRIPTION
.B gpu-screen-recorder
is the fastest screen recording tool for Linux. It uses the GPU
@@ -92,10 +96,6 @@ Run
.B \-\-list\-capture\-options
to list available capture sources.
.PP
Run
.B \-\-list\-v4l2\-devices
to list available camera devices (V4L2).
.PP
Additional options can be passed to each capture source by splitting capture source with
.B ;
for example
@@ -105,18 +105,18 @@ These are the available options for all capture sources (optional):
.RS
.IP \(bu 3
.B x
- The X position in pixels. If the number ends with % and is a number between 0 and 100 then it's a position relative to the video size
- The X position in pixels. If the number ends with % then this sets the X position relative to the video width (integer percentage where 100 = 100%)
.IP \(bu 3
.B y
- The Y position in pixels. If the number ends with % and is a number between 0 and 100 then it's a position relative to the video size
- The Y position in pixels. If the number ends with % then this sets the Y position relative to the video height (integer percentage where 100 = 100%)
.IP \(bu 3
.B width
- The width in pixels. If the number ends with % and is a number between 0 and 100 then it's a size relative to the video size.
- The width in pixels. If the number ends with % then this sets the width relative to the video width (integer percentage where 100 = 100%).
A value of 0 means to not scale the capture source and instead use the original width.
.IP \(bu 3
.B height
- The height in pixels. If the number ends with % and is a number between 0 and 100 then it's a size relative to the video size
- The height in pixels. If the number ends with % then this sets the height relative to the video height (integer percentage where 100 = 100%).
A value of 0 means to not scale the capture source and instead use the original height.
.IP \(bu 3
@@ -209,7 +209,7 @@ A value of 0 means to use the best option available.
.BI \-region " WxH+X+Y"
Specify region to capture when using
.BR \-w " region."
Format is width x height + X offset + Y offset. Use 0x0 for full monitor.
Format is width x height + X offset + Y offset. Set width and height to 0 to capture the whole monitor that contains the position.
It is compatible with tools such as slop (X11) and slurp (Wayland).
.TP
@@ -274,19 +274,28 @@ Audio bitrate in kbps (default: 128 for opus/flac, 160 for aac). 0 = automatic.
.TP
.BI \-k " codec"
Video codec:
.BR auto ", " h264 ", " hevc ", " av1 ", " vp8 ", " vp9 ", " hevc_hdr ", " av1_hdr ", " hevc_10bit ", " av1_10bit
(default: auto → h264). HDR options not available on X11 or portal capture.
.BR auto ", " h264 ", " hevc ", " av1 ", " vp8 ", " vp9 ", " hevc_hdr ", " av1_hdr ", " hevc_10bit ", " av1_10bit ", " h264_vulkan ", " hevc_vulkan ", " hevc_10bit_vulkan ", " av1_vulkan ", " av1_hdr_vulkan ", " av1_10bit_vulkan
10-bit capture reduces banding but may not be supported properly by all video players.
HDR options not available on X11 or portal capture. 10-bit capture reduces banding but may not be supported properly by all video players.
.br
Vulkan codec options are experimental. They may not work properly on your system because of GPU driver issues.
.br
Using vulkan codecs may result in better gaming performance, especially on NVIDIA as it doesn't suffer from an issue known as "cuda p2 state"
.br
where the GPU gets downclocked when using nvenc (regular video codecs on NVIDIA).
(default: auto → h264).
.TP
.BI \-q " quality"
Quality preset (medium, high, very_high, ultra) for QP/VBR mode, or bitrate (kbps) for CBR mode (default: very_high).
.TP
.BI \-bm " auto|qp|vbr|cbr"
Bitrate mode (default: auto → qp). CBR recommended for replay buffer.
Bitrate mode (default: auto → qp). CBR recommended for replay buffer and live streaming.
QP means to capture with constant quality, even in motion, while VBR and CBR means to capture with constant size.
.TP
.BI \-fm " cfr|vfr|content"
Frame rate mode: constant, variable, or match content (default: vfr). Content mode only on X11 or portal.
Frame rate mode: cfr (constant), vfr (variable), or content (match content) (default: vfr). Content mode is only available on X11 or portal.
Content mode syncs video to the captured content and is recommended for smoothest video when the game is running
at the same frame rate or lower than what you are trying to record at.
@@ -372,6 +381,14 @@ It's recommended to also use the option
when this is set to
.B yes
to only encode frames when the screen content updates to lower GPU and video encoding usage when the system is idle.
.TP
.BI \-write\-first\-frame\-ts " yes|no"
When enabled, writes a timestamp file with extra extension \fI.ts\fR next to the output video containing:
.nf
monotonic_microsec realtime_microsec
<monotonic_microsec> <realtime_microsec>
.fi
(default: no). Ignored for live streaming and when output is piped.
.SS Output Options
.TP
.BI \-o " output"
@@ -393,6 +410,9 @@ Show system info (codecs, capture options).
.B \-\-list\-capture\-options
List available capture sources (window, monitors, portal, v4l2 device path).
.TP
.B \-\-list\-monitors
List available monitors.
.TP
.B \-\-list\-v4l2\-devices
List available cameras devices (V4L2).
.TP
@@ -437,7 +457,7 @@ Save last 30 minutes (replay mode).
Use
.B pkill
to send signals (e.g.,
.BR "pkill -SIGUSR1 -f gpu-screen-recorder" ).
.BR "pkill -SIGUSR1 -f ""^gpu-screen-recorder""" ).
.SH EXAMPLES
Record monitor at 60 FPS with desktop audio:
.PP
@@ -467,7 +487,7 @@ Instant replay (last 60 seconds):
.PP
.nf
.RS
gpu-screen-recorder -w screen -f 60 -c mkv -r 60 -o ~/Videos
gpu-screen-recorder -w screen -c mkv -r 60 -o ~/Videos
.RE
.fi
.PP
@@ -491,15 +511,15 @@ Instant replay and launch a script when saving replay:
.PP
.nf
.RS
gpu-screen-recorder -w screen -f 60 -c mkv -r 60 -sc ./script.sh -o ~/Videos
gpu-screen-recorder -w screen -c mkv -r 60 -sc ./script.sh -o ~/Videos
.RE
.fi
.PP
Stream to Twitch:
Stream to Twitch with constant bitrate mode:
.PP
.nf
.RS
gpu-screen-recorder -w screen -f 60 -a default_output -o "rtmp://live.twitch.tv/app/stream_key"
gpu-screen-recorder -w screen -c flv -a default_output -bm cbr -q 8000 -o "rtmp://live.twitch.tv/app/stream_key"
.RE
.fi
.PP
@@ -536,7 +556,7 @@ gpu-screen-recorder -w "DP-1|DP-2;x=1920" -o video.mp4
.fi
.SH FILES
.TP
.I ~/.config/gpu-screen-recorder.env
.I ~/.config/gpu-screen-recorder/gpu-screen-recorder.env
Environment variables for systemd service (optional).
.TP
.I /usr/lib/modprobe.d/gsr-nvidia.conf
@@ -568,7 +588,7 @@ Close other screen recorders (including idle OBS)
.IP \(bu 3
NVIDIA: CUDA breaks after suspend (install gsr-nvidia.conf fix)
.IP \(bu 3
AMD: Possible black bars colors with HEVC/AV1 (use H264 or FFmpeg >=8)
AMD: Possible black bars in output video with HEVC/AV1 (use H264 or FFmpeg >=8)
.SH SEE ALSO
.UR https://git.dec05eba.com/gpu-screen-recorder
Project homepage
@@ -593,8 +613,16 @@ ShadowPlay-style UI
Developed by dec05eba and contributors.
.SH COPYRIGHT
Copyright © dec05eba. Licensed under GPL3-only.
.SH BUGS
.SH REPORTING BUGS
Report bugs at
.UR mailto:dec05eba@protonmail.com
dec05eba@protonmail.com
.UE .
.UR https://git.dec05eba.com/?p=about
See more information about reporting bugs at the gpu-screen-recorder website
.UE .
.br
.UR https://git.dec05eba.com/gpu-screen-recorder/about/
Before reporting a bug or an issue, please take a look at FAQ part of the README
.UE .
The bug or issue may have been previously reported or may not be related to gpu-screen-recorder.

View File

@@ -8,7 +8,7 @@
typedef struct gsr_egl gsr_egl;
#define NUM_ARGS 36
#define NUM_ARGS 37
typedef enum {
GSR_CAPTURE_SOURCE_TYPE_WINDOW,
@@ -63,6 +63,7 @@ typedef struct {
void (*list_application_audio)(void *userdata);
void (*list_v4l2_devices)(void *userdata);
void (*list_capture_options)(const char *card_path, void *userdata);
void (*list_monitors)(void *userdata);
} args_handlers;
typedef struct {
@@ -97,6 +98,7 @@ typedef struct {
bool restore_portal_session;
bool restart_replay_on_save;
bool overclock;
bool write_first_frame_ts;
bool is_livestream;
bool is_output_piped;
bool low_latency_recording;

View File

@@ -3,6 +3,6 @@
#include "codec_query.h"
bool gsr_get_supported_video_codecs_vulkan(gsr_supported_video_codecs *video_codecs, const char *card_path, bool cleanup);
bool gsr_get_supported_video_codecs_vulkan(gsr_supported_video_codecs *video_codecs, const char *card_path, int *device_index_ret, bool cleanup);
#endif /* GSR_CODEC_QUERY_VULKAN_H */

View File

@@ -51,6 +51,11 @@ typedef enum {
GSR_VIDEO_CODEC_VP9,
GSR_VIDEO_CODEC_H264_VULKAN,
GSR_VIDEO_CODEC_HEVC_VULKAN,
GSR_VIDEO_CODEC_HEVC_HDR_VULKAN,
GSR_VIDEO_CODEC_HEVC_10BIT_VULKAN,
GSR_VIDEO_CODEC_AV1_VULKAN,
GSR_VIDEO_CODEC_AV1_HDR_VULKAN,
GSR_VIDEO_CODEC_AV1_10BIT_VULKAN,
} gsr_video_codec;
typedef enum {

View File

@@ -169,6 +169,9 @@ typedef void (*FUNC_glTexStorageMem2DEXT)(unsigned int target, int levels, unsig
typedef void (*FUNC_glBufferStorageMemEXT)(unsigned int target, ssize_t size, unsigned int memory, uint64_t offset);
typedef void (*FUNC_glNamedBufferStorageMemEXT)(unsigned int buffer, ssize_t size, unsigned int memory, uint64_t offset);
typedef void (*FUNC_glMemoryObjectParameterivEXT)(unsigned int memoryObject, unsigned int pname, const int *params);
typedef void (*FUNC_glGenSemaphoresEXT)(int n, unsigned int *semaphores);
typedef void (*FUNC_glImportSemaphoreFdEXT)(unsigned int semaphore, unsigned int handleType, int fd);
typedef void (*FUNC_glSignalSemaphoreEXT)(unsigned int semaphore, unsigned int numBufferBarriers, const unsigned int *buffers, unsigned int numTextureBarriers, const unsigned int *textures, const unsigned int *dstLayouts);
typedef enum {
GSR_GL_CONTEXT_TYPE_EGL,
@@ -195,6 +198,7 @@ struct gsr_egl {
gsr_gpu_info gpu_info;
char card_path[128];
int vulkan_device_index;
int32_t (*eglGetError)(void);
EGLDisplay (*eglGetDisplay)(EGLNativeDisplayType display_id);
@@ -226,6 +230,9 @@ struct gsr_egl {
FUNC_glBufferStorageMemEXT glBufferStorageMemEXT;
FUNC_glNamedBufferStorageMemEXT glNamedBufferStorageMemEXT;
FUNC_glMemoryObjectParameterivEXT glMemoryObjectParameterivEXT;
FUNC_glGenSemaphoresEXT glGenSemaphoresEXT;
FUNC_glImportSemaphoreFdEXT glImportSemaphoreFdEXT;
FUNC_glSignalSemaphoreEXT glSignalSemaphoreEXT;
__GLXextFuncPtr (*glXGetProcAddress)(const unsigned char *procName);
GLXFBConfig* (*glXChooseFBConfig)(Display *dpy, int screen, const int *attribList, int *nitems);

View File

@@ -20,6 +20,8 @@ typedef struct {
AVStream *stream;
int64_t start_pts;
bool has_received_keyframe;
char *first_frame_ts_filepath;
bool first_frame_ts_written;
} gsr_encoder_recording_destination;
typedef struct {
@@ -43,5 +45,6 @@ void gsr_encoder_receive_packets(gsr_encoder *self, AVCodecContext *codec_contex
/* Returns the id to the recording destination, or -1 on error */
size_t gsr_encoder_add_recording_destination(gsr_encoder *self, AVCodecContext *codec_context, AVFormatContext *format_context, AVStream *stream, int64_t start_pts);
bool gsr_encoder_remove_recording_destination(gsr_encoder *self, size_t id);
bool gsr_encoder_set_recording_destination_first_frame_ts_filepath(gsr_encoder *self, size_t id, const char *filepath);
#endif /* GSR_ENCODER_H */

View File

@@ -112,6 +112,7 @@ typedef struct {
bool paused;
double paused_start_secs;
bool streaming;
gsr_monitor_rotation rotation;
} gsr_pipewire_video;

View File

@@ -378,6 +378,7 @@ int gsr_kms_client_init(gsr_kms_client *self, const char *card_path) {
goto err;
}
}
poll_fd.revents = 0;
}
fprintf(stderr, "gsr info: gsr_kms_client_init: server connected\n");

View File

@@ -1,4 +1,4 @@
project('gpu-screen-recorder', ['c', 'cpp'], version : '5.12.2', default_options : ['warning_level=2'])
project('gpu-screen-recorder', ['c', 'cpp'], version : '5.13.1', default_options : ['warning_level=2'])
add_project_arguments('-Wshadow', language : ['c', 'cpp'])
if get_option('buildtype') == 'debug'
@@ -74,6 +74,7 @@ dep = [
dependency('libdrm'),
dependency('wayland-egl'),
dependency('wayland-client'),
dependency('vulkan'),
]
if build_machine.system() == 'linux'
@@ -117,6 +118,7 @@ executable('gpu-screen-recorder', src, dependencies : dep, install : true)
install_headers('plugin/plugin.h', install_dir : 'include/gsr')
install_man('gpu-screen-recorder.1', 'gsr-kms-server.1')
install_subdir('scripts', install_dir: 'share/gpu-screen-recorder')
if get_option('systemd') == true
install_data(files('extra/gpu-screen-recorder.service'), install_dir : 'lib/systemd/user')

View File

@@ -1,7 +1,7 @@
[package]
name = "gpu-screen-recorder"
type = "executable"
version = "5.12.2"
version = "5.13.1"
platforms = ["posix"]
[config]

View File

@@ -4,4 +4,4 @@
[ "$#" -ne 4 ] && echo "usage: twitch-stream-local-copy.sh <window_id> <fps> <livestream_key> <local_file>" && exit 1
active_sink=default_output
gpu-screen-recorder -w "$1" -c flv -f "$2" -q high -a "$active_sink" | tee -- "$4" | ffmpeg -i pipe:0 -c copy -f flv -- "rtmp://live.twitch.tv/app/$3"
gpu-screen-recorder -w "$1" -c flv -f "$2" -bm cbr -q 8000 -a "$active_sink" | tee -- "$4" | ffmpeg -i pipe:0 -c copy -f flv -- "rtmp://live.twitch.tv/app/$3"

View File

@@ -2,4 +2,4 @@
[ "$#" -ne 3 ] && echo "usage: twitch-stream.sh <window_id> <fps> <livestream_key>" && exit 1
active_sink=default_output
gpu-screen-recorder -w "$1" -c flv -f "$2" -q high -a "$active_sink" -o "rtmp://live.twitch.tv/app/$3"
gpu-screen-recorder -w "$1" -c flv -f "$2" -bm cbr -q 8000 -a "$active_sink" -o "rtmp://live.twitch.tv/app/$3"

View File

@@ -2,4 +2,4 @@
[ "$#" -ne 3 ] && echo "usage: youtube-hls-stream.sh <window_id> <fps> <livestream_key>" && exit 1
active_sink=default_output
gpu-screen-recorder -w "$1" -c hls -f "$2" -q high -a "$active_sink" -ac aac -o "https://a.upload.youtube.com/http_upload_hls?cid=$3&copy=0&file=stream.m3u8"
gpu-screen-recorder -w "$1" -c hls -f "$2" -bm cbr -q 8000 -a "$active_sink" -ac aac -o "https://a.upload.youtube.com/http_upload_hls?cid=$3&copy=0&file=stream.m3u8"

View File

@@ -17,17 +17,24 @@
#endif
static const ArgEnum video_codec_enums[] = {
{ .name = "auto", .value = GSR_VIDEO_CODEC_AUTO },
{ .name = "h264", .value = GSR_VIDEO_CODEC_H264 },
{ .name = "h265", .value = GSR_VIDEO_CODEC_HEVC },
{ .name = "hevc", .value = GSR_VIDEO_CODEC_HEVC },
{ .name = "hevc_hdr", .value = GSR_VIDEO_CODEC_HEVC_HDR },
{ .name = "hevc_10bit", .value = GSR_VIDEO_CODEC_HEVC_10BIT },
{ .name = "av1", .value = GSR_VIDEO_CODEC_AV1 },
{ .name = "av1_hdr", .value = GSR_VIDEO_CODEC_AV1_HDR },
{ .name = "av1_10bit", .value = GSR_VIDEO_CODEC_AV1_10BIT },
{ .name = "vp8", .value = GSR_VIDEO_CODEC_VP8 },
{ .name = "vp9", .value = GSR_VIDEO_CODEC_VP9 },
{ .name = "auto", .value = GSR_VIDEO_CODEC_AUTO },
{ .name = "h264", .value = GSR_VIDEO_CODEC_H264 },
{ .name = "h265", .value = GSR_VIDEO_CODEC_HEVC },
{ .name = "hevc", .value = GSR_VIDEO_CODEC_HEVC },
{ .name = "hevc_hdr", .value = GSR_VIDEO_CODEC_HEVC_HDR },
{ .name = "hevc_10bit", .value = GSR_VIDEO_CODEC_HEVC_10BIT },
{ .name = "av1", .value = GSR_VIDEO_CODEC_AV1 },
{ .name = "av1_hdr", .value = GSR_VIDEO_CODEC_AV1_HDR },
{ .name = "av1_10bit", .value = GSR_VIDEO_CODEC_AV1_10BIT },
{ .name = "vp8", .value = GSR_VIDEO_CODEC_VP8 },
{ .name = "vp9", .value = GSR_VIDEO_CODEC_VP9 },
{ .name = "h264_vulkan", .value = GSR_VIDEO_CODEC_H264_VULKAN },
{ .name = "hevc_vulkan", .value = GSR_VIDEO_CODEC_HEVC_VULKAN },
{ .name = "hevc_hdr_vulkan", .value = GSR_VIDEO_CODEC_HEVC_HDR_VULKAN },
{ .name = "hevc_10bit_vulkan", .value = GSR_VIDEO_CODEC_HEVC_10BIT_VULKAN },
{ .name = "av1_vulkan", .value = GSR_VIDEO_CODEC_AV1_VULKAN },
{ .name = "av1_hdr_vulkan", .value = GSR_VIDEO_CODEC_AV1_HDR_VULKAN },
{ .name = "av1_10bit_vulkan", .value = GSR_VIDEO_CODEC_AV1_10BIT_VULKAN },
};
static const ArgEnum audio_codec_enums[] = {
@@ -196,7 +203,8 @@ static void usage_header(void) {
"[-bm auto|qp|vbr|cbr] [-cr limited|full] [-tune performance|quality] [-df yes|no] [-sc <script_path>] [-p <plugin_path>] "
"[-cursor yes|no] [-keyint <value>] [-restore-portal-session yes|no] [-portal-session-token-filepath filepath] [-encoder gpu|cpu] "
"[-fallback-cpu-encoding yes|no] [-o <output_file>] [-ro <output_directory>] [-ffmpeg-opts <options>] [--list-capture-options [card_path]] "
"[--list-audio-devices] [--list-application-audio] [--list-v4l2-devices] [-low-power yes|no] [-v yes|no] [-gl-debug yes|no] [--version] [-h|--help]\n", program_name);
"[--list-monitors] [--list-audio-devices] [--list-application-audio] [--list-v4l2-devices] [-write-first-frame-ts yes|no] [-low-power yes|no] "
"[-v yes|no] [-gl-debug yes|no] [--version] [-h|--help]\n", program_name);
fflush(stdout);
}
@@ -255,6 +263,7 @@ static bool args_parser_set_values(args_parser *self) {
self->restart_replay_on_save = args_get_boolean_by_key(self->args, NUM_ARGS, "-restart-replay-on-save", false);
self->overclock = args_get_boolean_by_key(self->args, NUM_ARGS, "-oc", false);
self->fallback_cpu_encoding = args_get_boolean_by_key(self->args, NUM_ARGS, "-fallback-cpu-encoding", false);
self->write_first_frame_ts = args_get_boolean_by_key(self->args, NUM_ARGS, "-write-first-frame-ts", false);
self->low_power = args_get_boolean_by_key(self->args, NUM_ARGS, "-low-power", false);
self->audio_bitrate = args_get_i64_by_key(self->args, NUM_ARGS, "-ab", 0);
@@ -432,6 +441,10 @@ static bool args_parser_set_values(args_parser *self) {
self->is_output_piped = strcmp(self->filename, "/dev/stdout") == 0;
self->low_latency_recording = self->is_livestream || self->is_output_piped;
if(self->write_first_frame_ts && (self->is_livestream || self->is_output_piped)) {
fprintf(stderr, "gsr warning: -write-first-frame-ts is ignored for livestreaming or when output is piped\n");
self->write_first_frame_ts = false;
}
self->replay_recording_directory = args_get_value_by_key(self->args, NUM_ARGS, "-ro");
@@ -495,6 +508,11 @@ bool args_parser_parse(args_parser *self, int argc, char **argv, const args_hand
}
}
if(strcmp(argv[1], "--list-monitors") == 0) {
arg_handlers->list_monitors(userdata);
return true;
}
if(argc == 2 && strcmp(argv[1], "--version") == 0) {
arg_handlers->version(userdata);
return true;
@@ -536,6 +554,7 @@ bool args_parser_parse(args_parser *self, int argc, char **argv, const args_hand
self->args[arg_index++] = (Arg){ .key = "-ffmpeg-opts", .optional = true, .list = false, .type = ARG_TYPE_STRING };
self->args[arg_index++] = (Arg){ .key = "-ffmpeg-video-opts", .optional = true, .list = false, .type = ARG_TYPE_STRING };
self->args[arg_index++] = (Arg){ .key = "-ffmpeg-audio-opts", .optional = true, .list = false, .type = ARG_TYPE_STRING };
self->args[arg_index++] = (Arg){ .key = "-write-first-frame-ts", .optional = true, .list = false, .type = ARG_TYPE_BOOLEAN };
self->args[arg_index++] = (Arg){ .key = "-low-power", .optional = true, .list = false, .type = ARG_TYPE_BOOLEAN };
assert(arg_index == NUM_ARGS);

View File

@@ -222,6 +222,13 @@ static size_t gsr_capture_v4l2_get_supported_resolutions(int fd, gsr_capture_v4l
while(xioctl(fd, VIDIOC_ENUM_FRAMESIZES, &fmt) == 0) {
if(fmt.type == V4L2_FRMSIZE_TYPE_DISCRETE && resolution_index < max_resolutions) {
// Skip unsupported resolutions for now (those that eglCreateImage cant import because of pitch hardware limitation).
// TODO: Find a fix for this.
if(pixfmt == GSR_CAPTURE_V4L2_PIXFMT_YUYV && (fmt.discrete.width % 128 != 0)) {
++fmt.index;
continue;
}
resolutions[resolution_index] = (gsr_capture_v4l2_resolution){
.width = fmt.discrete.width,
.height = fmt.discrete.height,
@@ -305,6 +312,7 @@ uint32_t gsr_capture_v4l2_framerate_to_number(gsr_capture_v4l2_framerate framera
return (uint32_t)((double)framerate.denominator / (double)framerate.numerator);
}
// TODO: Select the resolution closest to |camera_resolution|, if it's not 0, 0
static bool gsr_capture_v4l2_get_best_matching_setup(
const gsr_capture_v4l2_supported_setup *supported_setups,
size_t num_supported_setups,

View File

@@ -187,6 +187,7 @@ static void gsr_capture_xcomposite_on_event(gsr_capture *cap, gsr_egl *egl) {
break;
}
case ConfigureNotify: {
// TODO: Use PresentConfigureNotify instead
self->window_pos.x = xev->xconfigure.x;
self->window_pos.y = xev->xconfigure.y;

View File

@@ -1,11 +1,13 @@
#include "../../include/codec_query/vulkan.h"
#include "../../include/utils.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <xf86drm.h>
#include <dlfcn.h>
#define VK_NO_PROTOTYPES
//#include <vulkan/vulkan.h>
#include <vulkan/vulkan.h>
#define MAX_PHYSICAL_DEVICES 32
@@ -21,15 +23,167 @@ static const char *required_device_extensions[] = {
};
static int num_required_device_extensions = 8;
bool gsr_get_supported_video_codecs_vulkan(gsr_supported_video_codecs *video_codecs, const char *card_path, bool cleanup) {
static void set_h264_max_resolution(PFN_vkGetPhysicalDeviceVideoCapabilitiesKHR vkGetPhysicalDeviceVideoCapabilitiesKHR, VkPhysicalDevice physical_device, gsr_supported_video_codecs *video_codecs) {
#ifdef VK_KHR_video_encode_h264
const VkVideoEncodeH264ProfileInfoKHR h264_profile = {
.sType = VK_STRUCTURE_TYPE_VIDEO_ENCODE_H264_PROFILE_INFO_KHR,
.pNext = NULL,
.stdProfileIdc = STD_VIDEO_H264_PROFILE_IDC_HIGH
};
const VkVideoProfileInfoKHR video_profile = {
.sType = VK_STRUCTURE_TYPE_VIDEO_PROFILE_INFO_KHR,
.pNext = &h264_profile, // Chain the codec-specific profile
.videoCodecOperation = VK_VIDEO_CODEC_OPERATION_ENCODE_H264_BIT_KHR,
.chromaSubsampling = VK_VIDEO_CHROMA_SUBSAMPLING_420_BIT_KHR,
.lumaBitDepth = VK_VIDEO_COMPONENT_BIT_DEPTH_8_BIT_KHR,
.chromaBitDepth = VK_VIDEO_COMPONENT_BIT_DEPTH_8_BIT_KHR
};
VkVideoEncodeH264CapabilitiesKHR encode_caps = {
.sType = VK_STRUCTURE_TYPE_VIDEO_ENCODE_H264_CAPABILITIES_KHR,
.pNext = NULL
};
VkVideoCapabilitiesKHR video_caps = {
.sType = VK_STRUCTURE_TYPE_VIDEO_CAPABILITIES_KHR,
.pNext = &encode_caps
};
if (vkGetPhysicalDeviceVideoCapabilitiesKHR(physical_device, &video_profile, &video_caps) == VK_SUCCESS) {
video_codecs->h264.max_resolution.x = video_caps.maxCodedExtent.width;
video_codecs->h264.max_resolution.y = video_caps.maxCodedExtent.height;
}
#else
(void)vkGetPhysicalDeviceVideoCapabilitiesKHR;
(void)physical_device;
(void)video_codecs;
#endif
}
static void set_hevc_max_resolution(PFN_vkGetPhysicalDeviceVideoCapabilitiesKHR vkGetPhysicalDeviceVideoCapabilitiesKHR, VkPhysicalDevice physical_device, gsr_supported_video_codecs *video_codecs) {
#ifdef VK_KHR_video_encode_h265
const VkVideoEncodeH265ProfileInfoKHR hevc_profile = {
.sType = VK_STRUCTURE_TYPE_VIDEO_ENCODE_H265_PROFILE_INFO_KHR,
.pNext = NULL,
.stdProfileIdc = STD_VIDEO_H265_PROFILE_IDC_MAIN
};
const VkVideoProfileInfoKHR video_profile = {
.sType = VK_STRUCTURE_TYPE_VIDEO_PROFILE_INFO_KHR,
.pNext = &hevc_profile, // Chain the codec-specific profile
.videoCodecOperation = VK_VIDEO_CODEC_OPERATION_ENCODE_H265_BIT_KHR,
.chromaSubsampling = VK_VIDEO_CHROMA_SUBSAMPLING_420_BIT_KHR,
.lumaBitDepth = VK_VIDEO_COMPONENT_BIT_DEPTH_8_BIT_KHR,
.chromaBitDepth = VK_VIDEO_COMPONENT_BIT_DEPTH_8_BIT_KHR
};
VkVideoEncodeH265CapabilitiesKHR encode_caps = {
.sType = VK_STRUCTURE_TYPE_VIDEO_ENCODE_H265_CAPABILITIES_KHR,
.pNext = NULL
};
VkVideoCapabilitiesKHR video_caps = {
.sType = VK_STRUCTURE_TYPE_VIDEO_CAPABILITIES_KHR,
.pNext = &encode_caps
};
if (vkGetPhysicalDeviceVideoCapabilitiesKHR(physical_device, &video_profile, &video_caps) == VK_SUCCESS) {
video_codecs->hevc.max_resolution.x = video_caps.maxCodedExtent.width;
video_codecs->hevc.max_resolution.y = video_caps.maxCodedExtent.height;
video_codecs->hevc_hdr.max_resolution.x = video_caps.maxCodedExtent.width;
video_codecs->hevc_hdr.max_resolution.y = video_caps.maxCodedExtent.height;
video_codecs->hevc_10bit.max_resolution.x = video_caps.maxCodedExtent.width;
video_codecs->hevc_10bit.max_resolution.y = video_caps.maxCodedExtent.height;
}
#else
(void)vkGetPhysicalDeviceVideoCapabilitiesKHR;
(void)physical_device;
(void)video_codecs;
#endif
}
static void set_av1_max_resolution(PFN_vkGetPhysicalDeviceVideoCapabilitiesKHR vkGetPhysicalDeviceVideoCapabilitiesKHR, VkPhysicalDevice physical_device, gsr_supported_video_codecs *video_codecs) {
#ifdef VK_KHR_video_encode_av1
const VkVideoEncodeAV1ProfileInfoKHR av1_profile = {
.sType = VK_STRUCTURE_TYPE_VIDEO_ENCODE_AV1_PROFILE_INFO_KHR,
.pNext = NULL,
.stdProfile = STD_VIDEO_AV1_PROFILE_MAIN
};
const VkVideoProfileInfoKHR video_profile = {
.sType = VK_STRUCTURE_TYPE_VIDEO_PROFILE_INFO_KHR,
.pNext = &av1_profile, // Chain the codec-specific profile
.videoCodecOperation = VK_VIDEO_CODEC_OPERATION_ENCODE_AV1_BIT_KHR,
.chromaSubsampling = VK_VIDEO_CHROMA_SUBSAMPLING_420_BIT_KHR,
.lumaBitDepth = VK_VIDEO_COMPONENT_BIT_DEPTH_8_BIT_KHR,
.chromaBitDepth = VK_VIDEO_COMPONENT_BIT_DEPTH_8_BIT_KHR
};
VkVideoEncodeAV1CapabilitiesKHR encode_caps = {
.sType = VK_STRUCTURE_TYPE_VIDEO_ENCODE_AV1_CAPABILITIES_KHR,
.pNext = NULL
};
VkVideoCapabilitiesKHR video_caps = {
.sType = VK_STRUCTURE_TYPE_VIDEO_CAPABILITIES_KHR,
.pNext = &encode_caps
};
if (vkGetPhysicalDeviceVideoCapabilitiesKHR(physical_device, &video_profile, &video_caps) == VK_SUCCESS) {
video_codecs->av1.max_resolution.x = video_caps.maxCodedExtent.width;
video_codecs->av1.max_resolution.y = video_caps.maxCodedExtent.height;
video_codecs->av1_hdr.max_resolution.x = video_caps.maxCodedExtent.width;
video_codecs->av1_hdr.max_resolution.y = video_caps.maxCodedExtent.height;
video_codecs->av1_10bit.max_resolution.x = video_caps.maxCodedExtent.width;
video_codecs->av1_10bit.max_resolution.y = video_caps.maxCodedExtent.height;
}
#else
(void)vkGetPhysicalDeviceVideoCapabilitiesKHR;
(void)physical_device;
(void)video_codecs;
#endif
}
bool gsr_get_supported_video_codecs_vulkan(gsr_supported_video_codecs *video_codecs, const char *card_path, int *device_index_ret, bool cleanup) {
memset(video_codecs, 0, sizeof(*video_codecs));
#if 0
*device_index_ret = 0;
bool success = false;
void* libvulkan = NULL;
VkInstance instance = NULL;
VkPhysicalDevice physical_devices[MAX_PHYSICAL_DEVICES];
VkDevice device = NULL;
VkExtensionProperties *device_extensions = NULL;
char render_path[128];
if(!gsr_card_path_get_render_path(card_path, render_path)) {
fprintf(stderr, "gsr error: gsr_get_supported_video_codecs_vulkan: failed to get /dev/dri/renderDXXX file from %s\n", card_path);
return false;
}
libvulkan = dlopen("libvulkan.so.1", RTLD_NOW);
if (!libvulkan) {
fprintf(stderr, "gsr error: gsr_get_supported_video_codecs_vulkan: failed to load libvulkan.so.1, error: %s\n", dlerror());
return false;
}
PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr = (PFN_vkGetInstanceProcAddr)dlsym(libvulkan, "vkGetInstanceProcAddr");
if (!vkGetInstanceProcAddr) {
fprintf(stderr, "gsr error: gsr_get_supported_video_codecs_vulkan: could not find vkGetInstanceProcAddr in libvulkan.so.1\n");
goto done;
}
PFN_vkCreateInstance vkCreateInstance = (PFN_vkCreateInstance)vkGetInstanceProcAddr(NULL, "vkCreateInstance");
if(!vkCreateInstance) {
fprintf(stderr, "gsr error: gsr_get_supported_video_codecs_vulkan: could not find vkCreateInstance in libvulkan.so.1\n");
goto done;
}
const VkApplicationInfo app_info = {
.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO,
.pApplicationName = "GPU Screen Recorder",
@@ -49,6 +203,26 @@ bool gsr_get_supported_video_codecs_vulkan(gsr_supported_video_codecs *video_cod
goto done;
}
PFN_vkEnumeratePhysicalDevices vkEnumeratePhysicalDevices = NULL;
PFN_vkDestroyInstance vkDestroyInstance = NULL;
PFN_vkGetPhysicalDeviceProperties2 vkGetPhysicalDeviceProperties2 = NULL;
PFN_vkCreateDevice vkCreateDevice = NULL;
PFN_vkEnumerateDeviceExtensionProperties vkEnumerateDeviceExtensionProperties = NULL;
PFN_vkDestroyDevice vkDestroyDevice = NULL;
PFN_vkGetPhysicalDeviceVideoCapabilitiesKHR vkGetPhysicalDeviceVideoCapabilitiesKHR = NULL;
#define LOAD_INST(name) name = (PFN_##name)vkGetInstanceProcAddr(instance, #name); if(!name) { fprintf(stderr, "gsr error: gsr_get_supported_video_codecs_vulkan: could not find " #name " in libvulkan.so.1\n"); goto done; }
LOAD_INST(vkEnumeratePhysicalDevices)
LOAD_INST(vkDestroyInstance)
LOAD_INST(vkGetPhysicalDeviceProperties2)
LOAD_INST(vkCreateDevice)
LOAD_INST(vkEnumerateDeviceExtensionProperties)
LOAD_INST(vkDestroyDevice)
LOAD_INST(vkGetPhysicalDeviceVideoCapabilitiesKHR)
#undef LOAD_INST
uint32_t num_devices = 0;
if(vkEnumeratePhysicalDevices(instance, &num_devices, NULL) != VK_SUCCESS) {
fprintf(stderr, "gsr error: gsr_get_supported_video_codecs_vulkan: vkEnumeratePhysicalDevices (query num devices) failed\n");
@@ -81,12 +255,13 @@ bool gsr_get_supported_video_codecs_vulkan(gsr_supported_video_codecs *video_cod
};
vkGetPhysicalDeviceProperties2(physical_devices[i], &device_properties);
if(!device_drm_properties.hasPrimary)
if(!device_drm_properties.hasRender)
continue;
snprintf(device_card_path, sizeof(device_card_path), DRM_DEV_NAME, DRM_DIR_NAME, (int)device_drm_properties.primaryMinor);
if(strcmp(device_card_path, card_path) == 0) {
snprintf(device_card_path, sizeof(device_card_path), DRM_RENDER_DEV_NAME, DRM_DIR_NAME, (int)device_drm_properties.renderMinor);
if(strcmp(device_card_path, render_path) == 0) {
physical_device = physical_devices[i];
*device_index_ret = i;
break;
}
}
@@ -126,31 +301,36 @@ bool gsr_get_supported_video_codecs_vulkan(gsr_supported_video_codecs *video_cod
for(uint32_t i = 0; i < num_device_extensions; ++i) {
if(strcmp(device_extensions[i].extensionName, "VK_KHR_video_encode_h264") == 0) {
video_codecs->h264 = true;
video_codecs->h264.supported = true;
} else if(strcmp(device_extensions[i].extensionName, "VK_KHR_video_encode_h265") == 0) {
// TODO: Verify if 10bit and hdr are actually supported
video_codecs->hevc = true;
video_codecs->hevc_10bit = true;
video_codecs->hevc_hdr = true;
video_codecs->hevc.supported = true;
video_codecs->hevc_10bit.supported = true;
video_codecs->hevc_hdr.supported = true;
} else if(strcmp(device_extensions[i].extensionName, "VK_KHR_video_encode_av1") == 0) {
// TODO: Verify if 10bit and hdr are actually supported
video_codecs->av1.supported = true;
video_codecs->av1_10bit.supported = true;
video_codecs->av1_hdr.supported = true;
}
}
set_h264_max_resolution(vkGetPhysicalDeviceVideoCapabilitiesKHR, physical_device, video_codecs);
set_hevc_max_resolution(vkGetPhysicalDeviceVideoCapabilitiesKHR, physical_device, video_codecs);
set_av1_max_resolution(vkGetPhysicalDeviceVideoCapabilitiesKHR, physical_device, video_codecs);
success = true;
done:
if(device_extensions)
free(device_extensions);
if(cleanup) {
if(device)
vkDestroyDevice(device, NULL);
if(instance)
vkDestroyInstance(instance, NULL);
}
if(device_extensions)
free(device_extensions);
if(libvulkan)
dlclose(libvulkan);
return success;
#else
// TODO: Low power query
video_codecs->h264 = (gsr_supported_video_codec){ true, false };
video_codecs->hevc = (gsr_supported_video_codec){ true, false };
return true;
#endif
}

View File

@@ -78,14 +78,6 @@ bool gsr_dbus_init(gsr_dbus *self, const char *screencast_restore_token) {
return false;
}
/* TODO: Check the name */
const int ret = dbus_bus_request_name(self->con, "com.dec05eba.gpu_screen_recorder", DBUS_NAME_FLAG_REPLACE_EXISTING, &self->err);
if(dbus_error_is_set(&self->err)) {
fprintf(stderr, "gsr error: gsr_dbus_init: dbus_bus_request_name failed with error: %s\n", self->err.message);
gsr_dbus_deinit(self);
return false;
}
if(screencast_restore_token) {
self->screencast_restore_token = strdup(screencast_restore_token);
if(!self->screencast_restore_token) {
@@ -95,12 +87,6 @@ bool gsr_dbus_init(gsr_dbus *self, const char *screencast_restore_token) {
}
}
(void)ret;
// if(ret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
// fprintf(stderr, "gsr error: gsr_capture_portal_setup_dbus: dbus_bus_request_name failed to get primary owner\n");
// return false;
// }
return true;
}
@@ -119,8 +105,6 @@ void gsr_dbus_deinit(gsr_dbus *self) {
if(self->con) {
dbus_error_free(&self->err);
dbus_bus_release_name(self->con, "com.dec05eba.gpu_screen_recorder", NULL);
// Apparently shouldn't be used when a connection is setup by using dbus_bus_get
//dbus_connection_close(self->con);
dbus_connection_unref(self->con);

View File

@@ -2,10 +2,11 @@
#include <assert.h>
bool video_codec_is_hdr(gsr_video_codec video_codec) {
// TODO: Vulkan
switch(video_codec) {
case GSR_VIDEO_CODEC_HEVC_HDR:
case GSR_VIDEO_CODEC_AV1_HDR:
case GSR_VIDEO_CODEC_HEVC_HDR_VULKAN:
case GSR_VIDEO_CODEC_AV1_HDR_VULKAN:
return true;
default:
return false;
@@ -13,24 +14,30 @@ bool video_codec_is_hdr(gsr_video_codec video_codec) {
}
gsr_video_codec hdr_video_codec_to_sdr_video_codec(gsr_video_codec video_codec) {
// TODO: Vulkan
switch(video_codec) {
case GSR_VIDEO_CODEC_HEVC_HDR:
return GSR_VIDEO_CODEC_HEVC;
case GSR_VIDEO_CODEC_AV1_HDR:
return GSR_VIDEO_CODEC_AV1;
case GSR_VIDEO_CODEC_HEVC_HDR_VULKAN:
return GSR_VIDEO_CODEC_HEVC_VULKAN;
case GSR_VIDEO_CODEC_AV1_HDR_VULKAN:
return GSR_VIDEO_CODEC_AV1_VULKAN;
default:
return video_codec;
}
}
gsr_color_depth video_codec_to_bit_depth(gsr_video_codec video_codec) {
// TODO: 10-bit Vulkan
switch(video_codec) {
case GSR_VIDEO_CODEC_HEVC_HDR:
case GSR_VIDEO_CODEC_HEVC_10BIT:
case GSR_VIDEO_CODEC_AV1_HDR:
case GSR_VIDEO_CODEC_AV1_10BIT:
case GSR_VIDEO_CODEC_HEVC_HDR_VULKAN:
case GSR_VIDEO_CODEC_HEVC_10BIT_VULKAN:
case GSR_VIDEO_CODEC_AV1_HDR_VULKAN:
case GSR_VIDEO_CODEC_AV1_10BIT_VULKAN:
return GSR_COLOR_DEPTH_10_BITS;
default:
return GSR_COLOR_DEPTH_8_BITS;
@@ -39,28 +46,34 @@ gsr_color_depth video_codec_to_bit_depth(gsr_video_codec video_codec) {
const char* video_codec_to_string(gsr_video_codec video_codec) {
switch(video_codec) {
case GSR_VIDEO_CODEC_H264: return "h264";
case GSR_VIDEO_CODEC_HEVC: return "hevc";
case GSR_VIDEO_CODEC_HEVC_HDR: return "hevc_hdr";
case GSR_VIDEO_CODEC_HEVC_10BIT: return "hevc_10bit";
case GSR_VIDEO_CODEC_AV1: return "av1";
case GSR_VIDEO_CODEC_AV1_HDR: return "av1_hdr";
case GSR_VIDEO_CODEC_AV1_10BIT: return "av1_10bit";
case GSR_VIDEO_CODEC_VP8: return "vp8";
case GSR_VIDEO_CODEC_VP9: return "vp9";
case GSR_VIDEO_CODEC_H264_VULKAN: return "h264_vulkan";
case GSR_VIDEO_CODEC_HEVC_VULKAN: return "hevc_vulkan";
case GSR_VIDEO_CODEC_H264: return "h264";
case GSR_VIDEO_CODEC_HEVC: return "hevc";
case GSR_VIDEO_CODEC_HEVC_HDR: return "hevc_hdr";
case GSR_VIDEO_CODEC_HEVC_10BIT: return "hevc_10bit";
case GSR_VIDEO_CODEC_AV1: return "av1";
case GSR_VIDEO_CODEC_AV1_HDR: return "av1_hdr";
case GSR_VIDEO_CODEC_AV1_10BIT: return "av1_10bit";
case GSR_VIDEO_CODEC_VP8: return "vp8";
case GSR_VIDEO_CODEC_VP9: return "vp9";
case GSR_VIDEO_CODEC_H264_VULKAN: return "h264_vulkan";
case GSR_VIDEO_CODEC_HEVC_VULKAN: return "hevc_vulkan";
case GSR_VIDEO_CODEC_HEVC_HDR_VULKAN: return "hevc_hdr_vulkan";
case GSR_VIDEO_CODEC_HEVC_10BIT_VULKAN: return "hevc_10bit_vulkan";
case GSR_VIDEO_CODEC_AV1_VULKAN: return "av1_vulkan";
case GSR_VIDEO_CODEC_AV1_HDR_VULKAN: return "av1_hdr_vulkan";
case GSR_VIDEO_CODEC_AV1_10BIT_VULKAN: return "av1_10bit_vulkan";
}
return "";
}
// bool video_codec_is_hevc(gsr_video_codec video_codec) {
// // TODO: 10-bit vulkan
// switch(video_codec) {
// case GSR_VIDEO_CODEC_HEVC:
// case GSR_VIDEO_CODEC_HEVC_HDR:
// case GSR_VIDEO_CODEC_HEVC_10BIT:
// case GSR_VIDEO_CODEC_HEVC_VULKAN:
// case GSR_VIDEO_CODEC_HEVC_HDR_VULKAN:
// case GSR_VIDEO_CODEC_HEVC_10BIT_VULKAN:
// return true;
// default:
// return false;
@@ -68,11 +81,13 @@ const char* video_codec_to_string(gsr_video_codec video_codec) {
// }
bool video_codec_is_av1(gsr_video_codec video_codec) {
// TODO: Vulkan
switch(video_codec) {
case GSR_VIDEO_CODEC_AV1:
case GSR_VIDEO_CODEC_AV1_HDR:
case GSR_VIDEO_CODEC_AV1_10BIT:
case GSR_VIDEO_CODEC_AV1_VULKAN:
case GSR_VIDEO_CODEC_AV1_HDR_VULKAN:
case GSR_VIDEO_CODEC_AV1_10BIT_VULKAN:
return true;
default:
return false;
@@ -83,6 +98,11 @@ bool video_codec_is_vulkan(gsr_video_codec video_codec) {
switch(video_codec) {
case GSR_VIDEO_CODEC_H264_VULKAN:
case GSR_VIDEO_CODEC_HEVC_VULKAN:
case GSR_VIDEO_CODEC_HEVC_HDR_VULKAN:
case GSR_VIDEO_CODEC_HEVC_10BIT_VULKAN:
case GSR_VIDEO_CODEC_AV1_VULKAN:
case GSR_VIDEO_CODEC_AV1_HDR_VULKAN:
case GSR_VIDEO_CODEC_AV1_10BIT_VULKAN:
return true;
default:
return false;

View File

@@ -216,6 +216,10 @@ static bool gsr_egl_proc_load_egl(gsr_egl *self) {
self->glNamedBufferStorageMemEXT = (FUNC_glNamedBufferStorageMemEXT)self->eglGetProcAddress("glNamedBufferStorageMemEXT");
self->glMemoryObjectParameterivEXT = (FUNC_glMemoryObjectParameterivEXT)self->eglGetProcAddress("glMemoryObjectParameterivEXT");
self->glGenSemaphoresEXT = (FUNC_glGenSemaphoresEXT)self->eglGetProcAddress("glGenSemaphoresEXT");
self->glImportSemaphoreFdEXT = (FUNC_glImportSemaphoreFdEXT)self->eglGetProcAddress("glImportSemaphoreFdEXT");
self->glSignalSemaphoreEXT = (FUNC_glSignalSemaphoreEXT)self->eglGetProcAddress("glSignalSemaphoreEXT");
if(!self->eglExportDMABUFImageQueryMESA) {
fprintf(stderr, "gsr error: gsr_egl_load failed: could not find eglExportDMABUFImageQueryMESA\n");
return false;

View File

@@ -3,10 +3,37 @@
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <time.h>
#include <errno.h>
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
static uint64_t clock_gettime_microseconds(clockid_t clock_id) {
struct timespec ts;
ts.tv_sec = 0;
ts.tv_nsec = 0;
clock_gettime(clock_id, &ts);
return (uint64_t)ts.tv_sec * 1000000ULL + (uint64_t)ts.tv_nsec / 1000ULL;
}
static void gsr_write_first_frame_timestamp_file(const char *filepath) {
const uint64_t evdev_compatible_ts = clock_gettime_microseconds(CLOCK_MONOTONIC);
const uint64_t unix_time_microsec = clock_gettime_microseconds(CLOCK_REALTIME);
FILE *file = fopen(filepath, "w");
if(!file) {
fprintf(stderr, "gsr warning: failed to open timestamp file '%s': %s\n", filepath, strerror(errno));
return;
}
fputs("monotonic_microsec\trealtime_microsec\n", file);
fprintf(file, "%" PRIu64 "\t%" PRIu64 "\n", evdev_compatible_ts, unix_time_microsec);
fclose(file);
}
bool gsr_encoder_init(gsr_encoder *self, gsr_replay_storage replay_storage, size_t replay_buffer_num_packets, double replay_buffer_time, const char *replay_directory) {
memset(self, 0, sizeof(*self));
self->num_recording_destinations = 0;
@@ -39,6 +66,16 @@ bool gsr_encoder_init(gsr_encoder *self, gsr_replay_storage replay_storage, size
}
void gsr_encoder_deinit(gsr_encoder *self) {
if(self->file_write_mutex_created)
pthread_mutex_lock(&self->file_write_mutex);
for(size_t i = 0; i < self->num_recording_destinations; ++i) {
free(self->recording_destinations[i].first_frame_ts_filepath);
self->recording_destinations[i].first_frame_ts_filepath = NULL;
self->recording_destinations[i].first_frame_ts_written = false;
}
if(self->file_write_mutex_created)
pthread_mutex_unlock(&self->file_write_mutex);
if(self->replay_buffer) {
pthread_mutex_lock(&self->replay_mutex);
gsr_replay_buffer_destroy(self->replay_buffer);
@@ -94,6 +131,11 @@ void gsr_encoder_receive_packets(gsr_encoder *self, AVCodecContext *codec_contex
else if(!recording_destination->has_received_keyframe)
continue;
if(recording_destination->first_frame_ts_filepath && !recording_destination->first_frame_ts_written) {
gsr_write_first_frame_timestamp_file(recording_destination->first_frame_ts_filepath);
recording_destination->first_frame_ts_written = true;
}
av_packet->pts = pts - recording_destination->start_pts;
av_packet->dts = pts - recording_destination->start_pts;
@@ -148,6 +190,8 @@ size_t gsr_encoder_add_recording_destination(gsr_encoder *self, AVCodecContext *
recording_destination->stream = stream;
recording_destination->start_pts = start_pts;
recording_destination->has_received_keyframe = false;
recording_destination->first_frame_ts_filepath = NULL;
recording_destination->first_frame_ts_written = false;
++self->recording_destination_id_counter;
++self->num_recording_destinations;
@@ -161,6 +205,9 @@ bool gsr_encoder_remove_recording_destination(gsr_encoder *self, size_t id) {
pthread_mutex_lock(&self->file_write_mutex);
for(size_t i = 0; i < self->num_recording_destinations; ++i) {
if(self->recording_destinations[i].id == id) {
free(self->recording_destinations[i].first_frame_ts_filepath);
self->recording_destinations[i].first_frame_ts_filepath = NULL;
self->recording_destinations[i].first_frame_ts_written = false;
self->recording_destinations[i] = self->recording_destinations[self->num_recording_destinations - 1];
--self->num_recording_destinations;
found = true;
@@ -170,3 +217,26 @@ bool gsr_encoder_remove_recording_destination(gsr_encoder *self, size_t id) {
pthread_mutex_unlock(&self->file_write_mutex);
return found;
}
bool gsr_encoder_set_recording_destination_first_frame_ts_filepath(gsr_encoder *self, size_t id, const char *filepath) {
if(!filepath)
return false;
bool found = false;
pthread_mutex_lock(&self->file_write_mutex);
for(size_t i = 0; i < self->num_recording_destinations; ++i) {
if(self->recording_destinations[i].id == id) {
char *filepath_copy = strdup(filepath);
if(!filepath_copy)
break;
free(self->recording_destinations[i].first_frame_ts_filepath);
self->recording_destinations[i].first_frame_ts_filepath = filepath_copy;
self->recording_destinations[i].first_frame_ts_written = false;
found = true;
break;
}
}
pthread_mutex_unlock(&self->file_write_mutex);
return found;
}

View File

@@ -4,29 +4,120 @@
#include <libavcodec/avcodec.h>
#define VK_NO_PROTOTYPES
//#include <libavutil/hwcontext_vulkan.h>
#include <libavutil/hwcontext_vulkan.h>
//#include <vulkan/vulkan_core.h>
#include <vulkan/vulkan_core.h>
#define GL_HANDLE_TYPE_OPAQUE_FD_EXT 0x9586
#define GL_TEXTURE_TILING_EXT 0x9580
#define GL_OPTIMAL_TILING_EXT 0x9584
#define GL_LINEAR_TILING_EXT 0x9585
#define GL_HANDLE_TYPE_OPAQUE_FD_EXT 0x9586
#define GL_TEXTURE_TILING_EXT 0x9580
#define GL_OPTIMAL_TILING_EXT 0x9584
#define GL_LINEAR_TILING_EXT 0x9585
#define GL_DEDICATED_MEMORY_OBJECT_EXT 0x9581
#define GL_LAYOUT_GENERAL_EXT 0x958D
typedef struct {
PFN_vkCreateImage vkCreateImage;
PFN_vkDestroyImage vkDestroyImage;
PFN_vkGetImageMemoryRequirements vkGetImageMemoryRequirements;
PFN_vkAllocateMemory vkAllocateMemory;
PFN_vkFreeMemory vkFreeMemory;
PFN_vkBindImageMemory vkBindImageMemory;
PFN_vkGetMemoryFdKHR vkGetMemoryFdKHR;
PFN_vkGetPhysicalDeviceMemoryProperties vkGetPhysicalDeviceMemoryProperties;
PFN_vkCreateCommandPool vkCreateCommandPool;
PFN_vkDestroyCommandPool vkDestroyCommandPool;
PFN_vkAllocateCommandBuffers vkAllocateCommandBuffers;
PFN_vkBeginCommandBuffer vkBeginCommandBuffer;
PFN_vkEndCommandBuffer vkEndCommandBuffer;
PFN_vkCmdPipelineBarrier vkCmdPipelineBarrier;
PFN_vkCmdCopyImage vkCmdCopyImage;
PFN_vkCreateFence vkCreateFence;
PFN_vkDestroyFence vkDestroyFence;
PFN_vkResetFences vkResetFences;
PFN_vkWaitForFences vkWaitForFences;
PFN_vkGetDeviceQueue vkGetDeviceQueue;
PFN_vkQueueSubmit vkQueueSubmit;
PFN_vkResetCommandBuffer vkResetCommandBuffer;
PFN_vkCreateSemaphore vkCreateSemaphore;
PFN_vkDestroySemaphore vkDestroySemaphore;
PFN_vkGetSemaphoreFdKHR vkGetSemaphoreFdKHR;
} gsr_vk_funcs;
typedef struct {
gsr_video_encoder_vulkan_params params;
unsigned int target_textures[2];
vec2i texture_sizes[2];
AVBufferRef *device_ctx;
gsr_vk_funcs vk;
VkDevice vk_device;
VkQueue vk_queue;
/* Exportable images that GL renders into */
VkImage export_images[2];
VkDeviceMemory export_memory[2];
VkDeviceSize export_memory_size[2];
unsigned int gl_memory_objects[2];
/* Vulkan command infrastructure for copying to encoder frame */
VkCommandPool command_pool;
VkCommandBuffer command_buffer;
VkFence fence;
bool fence_submitted; /* true if the fence was submitted and not yet waited on */
/* GL→Vulkan semaphore (binary, exported to GL via GL_EXT_semaphore_fd) */
VkSemaphore gl_ready_semaphore;
unsigned int gl_semaphore;
} gsr_video_encoder_vulkan;
static bool gsr_vk_funcs_load(gsr_vk_funcs *vk, PFN_vkGetInstanceProcAddr get_inst_proc, VkInstance inst, VkDevice dev) {
PFN_vkGetDeviceProcAddr get_dev_proc = (PFN_vkGetDeviceProcAddr)get_inst_proc(inst, "vkGetDeviceProcAddr");
if(!get_dev_proc) {
fprintf(stderr, "gsr error: gsr_vk_funcs_load: failed to load vkGetDeviceProcAddr\n");
return false;
}
#define LOAD_INST(name) vk->name = (PFN_##name)get_inst_proc(inst, #name); if(!vk->name) { fprintf(stderr, "gsr error: gsr_vk_funcs_load: failed to load " #name "\n"); return false; }
#define LOAD_DEV(name) vk->name = (PFN_##name)get_dev_proc(dev, #name); if(!vk->name) { fprintf(stderr, "gsr error: gsr_vk_funcs_load: failed to load " #name "\n"); return false; }
LOAD_INST(vkGetPhysicalDeviceMemoryProperties)
LOAD_DEV(vkCreateImage)
LOAD_DEV(vkDestroyImage)
LOAD_DEV(vkGetImageMemoryRequirements)
LOAD_DEV(vkAllocateMemory)
LOAD_DEV(vkFreeMemory)
LOAD_DEV(vkBindImageMemory)
LOAD_DEV(vkGetMemoryFdKHR)
LOAD_DEV(vkCreateCommandPool)
LOAD_DEV(vkDestroyCommandPool)
LOAD_DEV(vkAllocateCommandBuffers)
LOAD_DEV(vkBeginCommandBuffer)
LOAD_DEV(vkEndCommandBuffer)
LOAD_DEV(vkCmdPipelineBarrier)
LOAD_DEV(vkCmdCopyImage)
LOAD_DEV(vkCreateFence)
LOAD_DEV(vkDestroyFence)
LOAD_DEV(vkResetFences)
LOAD_DEV(vkWaitForFences)
LOAD_DEV(vkGetDeviceQueue)
LOAD_DEV(vkQueueSubmit)
LOAD_DEV(vkResetCommandBuffer)
LOAD_DEV(vkCreateSemaphore)
LOAD_DEV(vkDestroySemaphore)
LOAD_DEV(vkGetSemaphoreFdKHR)
#undef LOAD_INST
#undef LOAD_DEV
return true;
}
static bool gsr_video_encoder_vulkan_setup_context(gsr_video_encoder_vulkan *self, AVCodecContext *video_codec_context) {
AVDictionary *options = NULL;
//av_dict_set(&options, "linear_images", "1", 0);
//av_dict_set(&options, "disable_multiplane", "1", 0);
#if 0
// TODO: Use correct device
if(av_hwdevice_ctx_create(&self->device_ctx, AV_HWDEVICE_TYPE_VULKAN, NULL, options, 0) < 0) {
char device_index_str[32];
snprintf(device_index_str, sizeof(device_index_str), "%d", self->params.egl->vulkan_device_index);
if(av_hwdevice_ctx_create(&self->device_ctx, AV_HWDEVICE_TYPE_VULKAN, device_index_str, options, 0) < 0) {
fprintf(stderr, "gsr error: gsr_video_encoder_vulkan_setup_context: failed to create hardware device context\n");
return false;
}
@@ -45,23 +136,19 @@ static bool gsr_video_encoder_vulkan_setup_context(gsr_video_encoder_vulkan *sel
hw_frame_context->format = video_codec_context->pix_fmt;
hw_frame_context->device_ctx = (AVHWDeviceContext*)self->device_ctx->data;
//AVVulkanFramesContext *vk_frame_ctx = (AVVulkanFramesContext*)hw_frame_context->hwctx;
//hw_frame_context->initial_pool_size = 20;
if (av_hwframe_ctx_init(frame_context) < 0) {
fprintf(stderr, "gsr error: gsr_video_encoder_vulkan_setup_context: failed to initialize hardware frame context "
"(note: ffmpeg version needs to be > 4.0)\n");
av_buffer_unref(&self->device_ctx);
//av_buffer_unref(&frame_context);
return false;
}
video_codec_context->hw_frames_ctx = av_buffer_ref(frame_context);
av_buffer_unref(&frame_context);
#endif
return true;
}
#if 0
static AVVulkanDeviceContext* video_codec_context_get_vulkan_data(AVCodecContext *video_codec_context) {
AVBufferRef *hw_frames_ctx = video_codec_context->hw_frames_ctx;
if(!hw_frames_ctx)
@@ -75,24 +162,118 @@ static AVVulkanDeviceContext* video_codec_context_get_vulkan_data(AVCodecContext
return (AVVulkanDeviceContext*)device_context->hwctx;
}
static int get_graphics_queue_family(AVVulkanDeviceContext *vv) {
for(int i = 0; i < vv->nb_qf; i++) {
if(vv->qf[i].flags & VK_QUEUE_GRAPHICS_BIT)
return vv->qf[i].idx;
}
/* Fall back to any queue that supports transfer */
for(int i = 0; i < vv->nb_qf; i++) {
if(vv->qf[i].flags & VK_QUEUE_TRANSFER_BIT)
return vv->qf[i].idx;
}
return -1;
}
static uint32_t get_memory_type_idx(VkPhysicalDevice pdev, const VkMemoryRequirements *mem_reqs, VkMemoryPropertyFlagBits prop_flags, PFN_vkGetPhysicalDeviceMemoryProperties vkGetPhysicalDeviceMemoryProperties) {
VkPhysicalDeviceMemoryProperties pdev_mem_props;
uint32_t i;
vkGetPhysicalDeviceMemoryProperties(pdev, &pdev_mem_props);
for (i = 0; i < pdev_mem_props.memoryTypeCount; i++) {
const VkMemoryType *type = &pdev_mem_props.memoryTypes[i];
if ((mem_reqs->memoryTypeBits & (1 << i)) &&
(type->propertyFlags & prop_flags) == prop_flags) {
for(uint32_t i = 0; i < pdev_mem_props.memoryTypeCount; i++) {
if((mem_reqs->memoryTypeBits & (1 << i)) &&
(pdev_mem_props.memoryTypes[i].propertyFlags & prop_flags) == prop_flags) {
return i;
break;
}
}
return UINT32_MAX;
}
#endif
static bool create_exportable_image(
const gsr_vk_funcs *vk,
VkDevice dev,
VkPhysicalDevice phys_dev,
int width, int height,
VkFormat format,
VkImage *out_image,
VkDeviceMemory *out_memory,
VkDeviceSize *out_size)
{
VkExternalMemoryImageCreateInfo ext_img_info = {
.sType = VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_IMAGE_CREATE_INFO,
.handleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT,
};
VkImageCreateInfo img_info = {
.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
.pNext = &ext_img_info,
.imageType = VK_IMAGE_TYPE_2D,
.format = format,
.extent = { (uint32_t)width, (uint32_t)height, 1 },
.mipLevels = 1,
.arrayLayers = 1,
.samples = VK_SAMPLE_COUNT_1_BIT,
.tiling = VK_IMAGE_TILING_OPTIMAL,
.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT |
VK_IMAGE_USAGE_SAMPLED_BIT |
VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
VK_IMAGE_USAGE_STORAGE_BIT,
.flags = VK_IMAGE_CREATE_ALIAS_BIT | VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT,
.sharingMode = VK_SHARING_MODE_EXCLUSIVE,
.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED,
};
if(vk->vkCreateImage(dev, &img_info, NULL, out_image) != VK_SUCCESS) {
fprintf(stderr, "gsr error: create_exportable_image: vkCreateImage failed\n");
return false;
}
VkMemoryRequirements mem_reqs;
vk->vkGetImageMemoryRequirements(dev, *out_image, &mem_reqs);
uint32_t mem_type_idx = get_memory_type_idx(phys_dev, &mem_reqs,
VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, vk->vkGetPhysicalDeviceMemoryProperties);
if(mem_type_idx == UINT32_MAX) {
fprintf(stderr, "gsr error: create_exportable_image: no suitable memory type\n");
vk->vkDestroyImage(dev, *out_image, NULL);
*out_image = VK_NULL_HANDLE;
return false;
}
VkMemoryDedicatedAllocateInfo ded_info = {
.sType = VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO,
.image = *out_image,
};
VkExportMemoryAllocateInfo exp_mem_info = {
.sType = VK_STRUCTURE_TYPE_EXPORT_MEMORY_ALLOCATE_INFO,
.pNext = &ded_info,
.handleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT,
};
VkMemoryAllocateInfo mem_alloc_info = {
.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,
.pNext = &exp_mem_info,
.allocationSize = mem_reqs.size,
.memoryTypeIndex = mem_type_idx,
};
if(vk->vkAllocateMemory(dev, &mem_alloc_info, NULL, out_memory) != VK_SUCCESS) {
fprintf(stderr, "gsr error: create_exportable_image: vkAllocateMemory failed\n");
vk->vkDestroyImage(dev, *out_image, NULL);
*out_image = VK_NULL_HANDLE;
return false;
}
if(vk->vkBindImageMemory(dev, *out_image, *out_memory, 0) != VK_SUCCESS) {
fprintf(stderr, "gsr error: create_exportable_image: vkBindImageMemory failed\n");
vk->vkFreeMemory(dev, *out_memory, NULL);
vk->vkDestroyImage(dev, *out_image, NULL);
*out_memory = VK_NULL_HANDLE;
*out_image = VK_NULL_HANDLE;
return false;
}
*out_size = mem_reqs.size;
return true;
}
static bool gsr_video_encoder_vulkan_setup_textures(gsr_video_encoder_vulkan *self, AVCodecContext *video_codec_context, AVFrame *frame) {
const int res = av_hwframe_get_buffer(video_codec_context->hw_frames_ctx, frame, 0);
if(res < 0) {
@@ -101,135 +282,179 @@ static bool gsr_video_encoder_vulkan_setup_textures(gsr_video_encoder_vulkan *se
}
while(self->params.egl->glGetError()) {}
#if 0
AVVkFrame *target_surface_id = (AVVkFrame*)frame->data[0];
AVVulkanDeviceContext* vv = video_codec_context_get_vulkan_data(video_codec_context);
const size_t luma_size = frame->width * frame->height;
if(vv) {
PFN_vkGetImageMemoryRequirements vkGetImageMemoryRequirements = (PFN_vkGetImageMemoryRequirements)vv->get_proc_addr(vv->inst, "vkGetImageMemoryRequirements");
PFN_vkAllocateMemory vkAllocateMemory = (PFN_vkAllocateMemory)vv->get_proc_addr(vv->inst, "vkAllocateMemory");
PFN_vkGetPhysicalDeviceMemoryProperties vkGetPhysicalDeviceMemoryProperties = (PFN_vkGetPhysicalDeviceMemoryProperties)vv->get_proc_addr(vv->inst, "vkGetPhysicalDeviceMemoryProperties");
PFN_vkGetMemoryFdKHR vkGetMemoryFdKHR = (PFN_vkGetMemoryFdKHR)vv->get_proc_addr(vv->inst, "vkGetMemoryFdKHR");
VkMemoryRequirements mem_reqs = {0};
vkGetImageMemoryRequirements(vv->act_dev, target_surface_id->img[0], &mem_reqs);
AVVulkanDeviceContext *vv = video_codec_context_get_vulkan_data(video_codec_context);
if(!vv) {
fprintf(stderr, "gsr error: gsr_video_encoder_vulkan_setup_textures: failed to get vulkan device context\n");
return false;
}
fprintf(stderr, "size: %lu, alignment: %lu, memory bits: 0x%08x\n", mem_reqs.size, mem_reqs.alignment, mem_reqs.memoryTypeBits);
VkDeviceMemory mem;
{
VkExportMemoryAllocateInfo exp_mem_info;
VkMemoryAllocateInfo mem_alloc_info;
VkMemoryDedicatedAllocateInfoKHR ded_info;
if(!gsr_vk_funcs_load(&self->vk, vv->get_proc_addr, vv->inst, vv->act_dev))
return false;
memset(&exp_mem_info, 0, sizeof(exp_mem_info));
exp_mem_info.sType = VK_STRUCTURE_TYPE_EXPORT_MEMORY_ALLOCATE_INFO;
exp_mem_info.handleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT;
memset(&ded_info, 0, sizeof(ded_info));
ded_info.sType = VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO;
ded_info.image = target_surface_id->img[0];
self->vk_device = vv->act_dev;
exp_mem_info.pNext = &ded_info;
const bool is_p010 = self->params.color_depth == GSR_COLOR_DEPTH_10_BITS;
const VkFormat fmt_y = is_p010 ? VK_FORMAT_R16_UNORM : VK_FORMAT_R8_UNORM;
const VkFormat fmt_uv = is_p010 ? VK_FORMAT_R16G16_UNORM : VK_FORMAT_R8G8_UNORM;
const unsigned int gl_fmt_y = is_p010 ? GL_R16 : GL_R8;
const unsigned int gl_fmt_uv = is_p010 ? GL_RG16 : GL_RG8;
memset(&mem_alloc_info, 0, sizeof(mem_alloc_info));
mem_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
mem_alloc_info.pNext = &exp_mem_info;
mem_alloc_info.allocationSize = target_surface_id->size[0];
mem_alloc_info.memoryTypeIndex = get_memory_type_idx(vv->phys_dev, &mem_reqs, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, vkGetPhysicalDeviceMemoryProperties);
if(!create_exportable_image(&self->vk, vv->act_dev, vv->phys_dev,
frame->width, frame->height, fmt_y,
&self->export_images[0], &self->export_memory[0], &self->export_memory_size[0]))
return false;
if (mem_alloc_info.memoryTypeIndex == UINT32_MAX) {
fprintf(stderr, "No suitable memory type index found.\n");
return VK_NULL_HANDLE;
if(!create_exportable_image(&self->vk, vv->act_dev, vv->phys_dev,
frame->width / 2, frame->height / 2, fmt_uv,
&self->export_images[1], &self->export_memory[1], &self->export_memory_size[1]))
return false;
/* Export Vulkan memory as FDs and import into GL */
for(int i = 0; i < 2; i++) {
VkMemoryGetFdInfoKHR fd_info = {
.sType = VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR,
.memory = self->export_memory[i],
.handleType = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT,
};
int fd = -1;
if(self->vk.vkGetMemoryFdKHR(vv->act_dev, &fd_info, &fd) != VK_SUCCESS) {
fprintf(stderr, "gsr error: gsr_video_encoder_vulkan_setup_textures: vkGetMemoryFdKHR failed for plane %d\n", i);
return false;
}
self->params.egl->glCreateMemoryObjectsEXT(1, &self->gl_memory_objects[i]);
const int dedicated = 1;
self->params.egl->glMemoryObjectParameterivEXT(self->gl_memory_objects[i],
GL_DEDICATED_MEMORY_OBJECT_EXT, &dedicated);
self->params.egl->glImportMemoryFdEXT(self->gl_memory_objects[i], self->export_memory_size[i],
GL_HANDLE_TYPE_OPAQUE_FD_EXT, fd);
if(!self->params.egl->glIsMemoryObjectEXT(self->gl_memory_objects[i])) {
fprintf(stderr, "gsr error: gsr_video_encoder_vulkan_setup_textures: failed to import memory FD for plane %d\n", i);
return false;
}
}
/* Create GL textures backed by the exportable images */
self->params.egl->glGenTextures(2, self->target_textures);
self->params.egl->glBindTexture(GL_TEXTURE_2D, self->target_textures[0]);
self->params.egl->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_TILING_EXT, GL_OPTIMAL_TILING_EXT);
self->params.egl->glTexStorageMem2DEXT(GL_TEXTURE_2D, 1, gl_fmt_y,
frame->width, frame->height,
self->gl_memory_objects[0], 0);
self->params.egl->glBindTexture(GL_TEXTURE_2D, 0);
self->params.egl->glBindTexture(GL_TEXTURE_2D, self->target_textures[1]);
self->params.egl->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_TILING_EXT, GL_OPTIMAL_TILING_EXT);
self->params.egl->glTexStorageMem2DEXT(GL_TEXTURE_2D, 1, gl_fmt_uv,
frame->width / 2, frame->height / 2,
self->gl_memory_objects[1], 0);
self->params.egl->glBindTexture(GL_TEXTURE_2D, 0);
self->texture_sizes[0] = (vec2i){ frame->width, frame->height };
self->texture_sizes[1] = (vec2i){ frame->width / 2, frame->height / 2 };
/* Set up Vulkan command infrastructure */
VkCommandPoolCreateInfo pool_info = {
.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,
.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT,
.queueFamilyIndex = (uint32_t)get_graphics_queue_family(vv),
};
if(self->vk.vkCreateCommandPool(vv->act_dev, &pool_info, NULL, &self->command_pool) != VK_SUCCESS) {
fprintf(stderr, "gsr error: gsr_video_encoder_vulkan_setup_textures: vkCreateCommandPool failed\n");
return false;
}
VkCommandBufferAllocateInfo cb_alloc_info = {
.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,
.commandPool = self->command_pool,
.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY,
.commandBufferCount = 1,
};
if(self->vk.vkAllocateCommandBuffers(vv->act_dev, &cb_alloc_info, &self->command_buffer) != VK_SUCCESS) {
fprintf(stderr, "gsr error: gsr_video_encoder_vulkan_setup_textures: vkAllocateCommandBuffers failed\n");
return false;
}
VkFenceCreateInfo fence_info = {
.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,
};
if(self->vk.vkCreateFence(vv->act_dev, &fence_info, NULL, &self->fence) != VK_SUCCESS) {
fprintf(stderr, "gsr error: gsr_video_encoder_vulkan_setup_textures: vkCreateFence failed\n");
return false;
}
self->vk.vkGetDeviceQueue(vv->act_dev, (uint32_t)get_graphics_queue_family(vv), 0, &self->vk_queue);
/* Transition export images UNDEFINED → GENERAL so GL can use them */
VkCommandBufferBeginInfo begin_info = {
.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT,
};
self->vk.vkBeginCommandBuffer(self->command_buffer, &begin_info);
VkImageMemoryBarrier init_barriers[2];
for(int i = 0; i < 2; i++) {
init_barriers[i] = (VkImageMemoryBarrier){
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
.srcAccessMask = 0,
.dstAccessMask = 0,
.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED,
.newLayout = VK_IMAGE_LAYOUT_GENERAL,
.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
.image = self->export_images[i],
.subresourceRange = {
.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
.levelCount = 1,
.layerCount = 1,
},
};
}
self->vk.vkCmdPipelineBarrier(self->command_buffer,
VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT,
0, 0, NULL, 0, NULL, 2, init_barriers);
self->vk.vkEndCommandBuffer(self->command_buffer);
VkSubmitInfo submit_info = {
.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO,
.commandBufferCount = 1,
.pCommandBuffers = &self->command_buffer,
};
self->vk.vkQueueSubmit(self->vk_queue, 1, &submit_info, self->fence);
self->vk.vkWaitForFences(vv->act_dev, 1, &self->fence, VK_TRUE, UINT64_MAX);
self->vk.vkResetFences(vv->act_dev, 1, &self->fence);
self->vk.vkResetCommandBuffer(self->command_buffer, 0);
/* Create GL→Vulkan sync semaphore (binary, exported via OPAQUE_FD) */
if(self->params.egl->glGenSemaphoresEXT && self->params.egl->glImportSemaphoreFdEXT) {
VkExportSemaphoreCreateInfo exp_sem_info = {
.sType = VK_STRUCTURE_TYPE_EXPORT_SEMAPHORE_CREATE_INFO,
.handleTypes = VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT,
};
VkSemaphoreCreateInfo sem_info = {
.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO,
.pNext = &exp_sem_info,
};
if(self->vk.vkCreateSemaphore(vv->act_dev, &sem_info, NULL, &self->gl_ready_semaphore) == VK_SUCCESS) {
VkSemaphoreGetFdInfoKHR get_fd_info = {
.sType = VK_STRUCTURE_TYPE_SEMAPHORE_GET_FD_INFO_KHR,
.semaphore = self->gl_ready_semaphore,
.handleType = VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT,
};
int sem_fd = -1;
if(self->vk.vkGetSemaphoreFdKHR(vv->act_dev, &get_fd_info, &sem_fd) == VK_SUCCESS) {
self->params.egl->glGenSemaphoresEXT(1, &self->gl_semaphore);
self->params.egl->glImportSemaphoreFdEXT(self->gl_semaphore, GL_HANDLE_TYPE_OPAQUE_FD_EXT, sem_fd);
} else {
self->vk.vkDestroySemaphore(vv->act_dev, self->gl_ready_semaphore, NULL);
self->gl_ready_semaphore = VK_NULL_HANDLE;
}
if (vkAllocateMemory(vv->act_dev, &mem_alloc_info, 0, &mem) !=
VK_SUCCESS)
return VK_NULL_HANDLE;
fprintf(stderr, "memory: %p\n", (void*)mem);
}
}
fprintf(stderr, "target surface id: %p, %zu, %zu\n", (void*)target_surface_id->mem[0], target_surface_id->offset[0], target_surface_id->offset[1]);
fprintf(stderr, "vkGetMemoryFdKHR: %p\n", (void*)vkGetMemoryFdKHR);
int fd = 0;
VkMemoryGetFdInfoKHR fd_info;
memset(&fd_info, 0, sizeof(fd_info));
fd_info.sType = VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR;
fd_info.memory = target_surface_id->mem[0];
fd_info.handleType = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT;
if(vkGetMemoryFdKHR(vv->act_dev, &fd_info, &fd) != VK_SUCCESS) {
fprintf(stderr, "failed!\n");
} else {
fprintf(stderr, "fd: %d\n", fd);
}
fprintf(stderr, "glImportMemoryFdEXT: %p, size: %zu\n", (void*)self->params.egl->glImportMemoryFdEXT, target_surface_id->size[0]);
const int tiling = target_surface_id->tiling == VK_IMAGE_TILING_LINEAR ? GL_LINEAR_TILING_EXT : GL_OPTIMAL_TILING_EXT;
if(tiling != GL_OPTIMAL_TILING_EXT) {
fprintf(stderr, "tiling %d is not supported, only GL_OPTIMAL_TILING_EXT (%d) is supported\n", tiling, GL_OPTIMAL_TILING_EXT);
}
unsigned int gl_memory_obj = 0;
self->params.egl->glCreateMemoryObjectsEXT(1, &gl_memory_obj);
//const int dedicated = GL_TRUE;
//self->params.egl->glMemoryObjectParameterivEXT(gl_memory_obj, GL_DEDICATED_MEMORY_OBJECT_EXT, &dedicated);
self->params.egl->glImportMemoryFdEXT(gl_memory_obj, target_surface_id->size[0], GL_HANDLE_TYPE_OPAQUE_FD_EXT, fd);
if(!self->params.egl->glIsMemoryObjectEXT(gl_memory_obj))
fprintf(stderr, "failed to create object!\n");
fprintf(stderr, "gl memory obj: %u, error: %d\n", gl_memory_obj, self->params.egl->glGetError());
// fprintf(stderr, "0 gl error: %d\n", self->params.egl->glGetError());
// unsigned int vertex_buffer = 0;
// self->params.egl->glGenBuffers(1, &vertex_buffer);
// self->params.egl->glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer);
// self->params.egl->glBufferStorageMemEXT(GL_ARRAY_BUFFER, target_surface_id->size[0], gl_memory_obj, target_surface_id->offset[0]);
// fprintf(stderr, "1 gl error: %d\n", self->params.egl->glGetError());
// fprintf(stderr, "0 gl error: %d\n", self->params.egl->glGetError());
// unsigned int buffer = 0;
// self->params.egl->glCreateBuffers(1, &buffer);
// self->params.egl->glNamedBufferStorageMemEXT(buffer, target_surface_id->size[0], gl_memory_obj, target_surface_id->offset[0]);
// fprintf(stderr, "1 gl error: %d\n", self->params.egl->glGetError());
self->params.egl->glGenTextures(1, &self->target_textures[0]);
self->params.egl->glBindTexture(GL_TEXTURE_2D, self->target_textures[0]);
fprintf(stderr, "1 gl error: %d\n", self->params.egl->glGetError());
self->params.egl->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_TILING_EXT, tiling);
fprintf(stderr, "tiling: %d\n", tiling);
fprintf(stderr, "2 gl error: %d\n", self->params.egl->glGetError());
self->params.egl->glTexStorageMem2DEXT(GL_TEXTURE_2D, 1, GL_R8, frame->width, frame->height, gl_memory_obj, target_surface_id->offset[0]);
fprintf(stderr, "3 gl error: %d\n", self->params.egl->glGetError());
self->params.egl->glBindTexture(GL_TEXTURE_2D, 0);
self->params.egl->glGenTextures(1, &self->target_textures[1]);
self->params.egl->glBindTexture(GL_TEXTURE_2D, self->target_textures[1]);
fprintf(stderr, "1 gl error: %d\n", self->params.egl->glGetError());
self->params.egl->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_TILING_EXT, tiling);
fprintf(stderr, "tiling: %d\n", tiling);
fprintf(stderr, "2 gl error: %d\n", self->params.egl->glGetError());
self->params.egl->glTexStorageMem2DEXT(GL_TEXTURE_2D, 1, GL_RG8, frame->width/2, frame->height/2, gl_memory_obj, target_surface_id->offset[0] + luma_size);
fprintf(stderr, "3 gl error: %d\n", self->params.egl->glGetError());
self->params.egl->glBindTexture(GL_TEXTURE_2D, 0);
self->texture_sizes[0] = (vec2i){ frame->width, frame->height };
self->texture_sizes[1] = (vec2i){ frame->width/2, frame->height/2 };
}
#endif
return true;
}
@@ -263,11 +488,332 @@ static bool gsr_video_encoder_vulkan_start(gsr_video_encoder *encoder, AVCodecCo
return true;
}
static void gsr_video_encoder_vulkan_copy_textures_to_frame(gsr_video_encoder *encoder, AVFrame *frame, gsr_color_conversion *color_conversion) {
(void)color_conversion;
gsr_video_encoder_vulkan *self = encoder->priv;
AVVkFrame *vk_frame = (AVVkFrame*)frame->data[0];
/* Wait for the previous frame's copy to finish before reusing the command buffer */
// if(self->fence_submitted) {
// self->vk.vkWaitForFences(self->vk_device, 1, &self->fence, VK_TRUE, UINT64_MAX);
self->vk.vkResetFences(self->vk_device, 1, &self->fence);
self->fence_submitted = false;
// }
if(self->gl_ready_semaphore != VK_NULL_HANDLE && self->params.egl->glSignalSemaphoreEXT) {
/* GPU-side GL→Vulkan sync: signal the semaphore from GL, then flush (no CPU stall) */
unsigned int gl_textures[2] = { self->target_textures[0], self->target_textures[1] };
unsigned int dst_layouts[2] = { GL_LAYOUT_GENERAL_EXT, GL_LAYOUT_GENERAL_EXT };
self->params.egl->glSignalSemaphoreEXT(self->gl_semaphore, 0, NULL, 2, gl_textures, dst_layouts);
self->params.egl->glFlush();
} else {
/* Fallback: CPU stall to ensure GL has finished */
self->params.egl->glFinish();
}
self->vk.vkResetCommandBuffer(self->command_buffer, 0);
VkCommandBufferBeginInfo begin_info = {
.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT,
};
self->vk.vkBeginCommandBuffer(self->command_buffer, &begin_info);
/* Transition export images: GENERAL → TRANSFER_SRC_OPTIMAL */
VkImageMemoryBarrier src_barriers[2];
for(int i = 0; i < 2; i++) {
src_barriers[i] = (VkImageMemoryBarrier){
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
.srcAccessMask = VK_ACCESS_MEMORY_WRITE_BIT,
.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT,
.oldLayout = VK_IMAGE_LAYOUT_GENERAL,
.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
.image = self->export_images[i],
.subresourceRange = {
.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
.levelCount = 1,
.layerCount = 1,
},
};
}
self->vk.vkCmdPipelineBarrier(self->command_buffer,
VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT,
0, 0, NULL, 0, NULL, 2, src_barriers);
/*
* Detect whether the encoder frame uses one multi-plane image (default NV12/P010
* in FFmpeg) or two separate single-plane images.
* Multi-plane: img[1] == VK_NULL_HANDLE or img[1] == img[0]
*/
const bool multiplane = (vk_frame->img[1] == VK_NULL_HANDLE || vk_frame->img[1] == vk_frame->img[0]);
if(multiplane) {
/* Transition the encoder's multi-plane image to TRANSFER_DST_OPTIMAL */
VkImageMemoryBarrier dst_barrier = {
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
.srcAccessMask = VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT,
.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT,
.oldLayout = vk_frame->layout[0],
.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
.image = vk_frame->img[0],
.subresourceRange = {
.aspectMask = VK_IMAGE_ASPECT_PLANE_0_BIT | VK_IMAGE_ASPECT_PLANE_1_BIT,
.levelCount = 1,
.layerCount = 1,
},
};
self->vk.vkCmdPipelineBarrier(self->command_buffer,
VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT,
0, 0, NULL, 0, NULL, 1, &dst_barrier);
/* Copy Y plane: export_images[0] (R8/R16) → encoder img PLANE_0 */
VkImageCopy copy_y = {
.srcSubresource = { VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1 },
.dstSubresource = { VK_IMAGE_ASPECT_PLANE_0_BIT, 0, 0, 1 },
.extent = { (uint32_t)frame->width, (uint32_t)frame->height, 1 },
};
self->vk.vkCmdCopyImage(self->command_buffer,
self->export_images[0], VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
vk_frame->img[0], VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
1, &copy_y);
/* Copy UV plane: export_images[1] (RG8/RG16) → encoder img PLANE_1 */
VkImageCopy copy_uv = {
.srcSubresource = { VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1 },
.dstSubresource = { VK_IMAGE_ASPECT_PLANE_1_BIT, 0, 0, 1 },
.extent = { (uint32_t)frame->width / 2, (uint32_t)frame->height / 2, 1 },
};
self->vk.vkCmdCopyImage(self->command_buffer,
self->export_images[1], VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
vk_frame->img[0], VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
1, &copy_uv);
/* Transition encoder image to GENERAL and update tracked layout */
VkImageMemoryBarrier dst_barrier_back = {
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT,
.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT,
.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
.newLayout = VK_IMAGE_LAYOUT_GENERAL,
.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
.image = vk_frame->img[0],
.subresourceRange = {
.aspectMask = VK_IMAGE_ASPECT_PLANE_0_BIT | VK_IMAGE_ASPECT_PLANE_1_BIT,
.levelCount = 1,
.layerCount = 1,
},
};
self->vk.vkCmdPipelineBarrier(self->command_buffer,
VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
0, 0, NULL, 0, NULL, 1, &dst_barrier_back);
vk_frame->layout[0] = VK_IMAGE_LAYOUT_GENERAL;
vk_frame->layout[1] = VK_IMAGE_LAYOUT_GENERAL;
} else {
/* Two separate single-plane images */
VkImageMemoryBarrier dst_barriers[2] = {
{
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
.srcAccessMask = VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT,
.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT,
.oldLayout = vk_frame->layout[0],
.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
.image = vk_frame->img[0],
.subresourceRange = {
.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
.levelCount = 1,
.layerCount = 1,
},
},
{
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
.srcAccessMask = VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT,
.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT,
.oldLayout = vk_frame->layout[1],
.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
.image = vk_frame->img[1],
.subresourceRange = {
.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
.levelCount = 1,
.layerCount = 1,
},
},
};
self->vk.vkCmdPipelineBarrier(self->command_buffer,
VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT,
0, 0, NULL, 0, NULL, 2, dst_barriers);
for(int i = 0; i < 2; i++) {
VkImageCopy copy = {
.srcSubresource = { VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1 },
.dstSubresource = { VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1 },
.extent = {
(uint32_t)(i == 0 ? frame->width : frame->width / 2),
(uint32_t)(i == 0 ? frame->height : frame->height / 2),
1
},
};
self->vk.vkCmdCopyImage(self->command_buffer,
self->export_images[i], VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
vk_frame->img[i], VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
1, &copy);
}
VkImageMemoryBarrier dst_barriers_back[2] = {
{
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT,
.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT,
.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
.newLayout = VK_IMAGE_LAYOUT_GENERAL,
.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
.image = vk_frame->img[0],
.subresourceRange = {
.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
.levelCount = 1,
.layerCount = 1,
},
},
{
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT,
.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT,
.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
.newLayout = VK_IMAGE_LAYOUT_GENERAL,
.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
.image = vk_frame->img[1],
.subresourceRange = {
.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
.levelCount = 1,
.layerCount = 1,
},
},
};
self->vk.vkCmdPipelineBarrier(self->command_buffer,
VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
0, 0, NULL, 0, NULL, 2, dst_barriers_back);
vk_frame->layout[0] = VK_IMAGE_LAYOUT_GENERAL;
vk_frame->layout[1] = VK_IMAGE_LAYOUT_GENERAL;
}
/* Transition export images back: TRANSFER_SRC_OPTIMAL → GENERAL for next GL frame */
VkImageMemoryBarrier src_barriers_back[2];
for(int i = 0; i < 2; i++) {
src_barriers_back[i] = (VkImageMemoryBarrier){
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
.srcAccessMask = VK_ACCESS_TRANSFER_READ_BIT,
.dstAccessMask = VK_ACCESS_MEMORY_WRITE_BIT,
.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
.newLayout = VK_IMAGE_LAYOUT_GENERAL,
.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
.image = self->export_images[i],
.subresourceRange = {
.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
.levelCount = 1,
.layerCount = 1,
},
};
}
self->vk.vkCmdPipelineBarrier(self->command_buffer,
VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
0, 0, NULL, 0, NULL, 2, src_barriers_back);
self->vk.vkEndCommandBuffer(self->command_buffer);
/*
* Detect whether the encoder frame is multiplane to know how many timeline
* semaphores need to be signaled.
*/
const bool mp = (vk_frame->img[1] == VK_NULL_HANDLE || vk_frame->img[1] == vk_frame->img[0]);
const int num_sems = mp ? 1 : 2;
if(self->gl_ready_semaphore != VK_NULL_HANDLE) {
/*
* GPU-side sync path:
* - Wait on the GL binary semaphore before executing the copy.
* - Signal each AVVkFrame timeline semaphore so FFmpeg knows the frame is ready.
*/
uint64_t signal_values[2];
VkSemaphore signal_sems[2];
for(int i = 0; i < num_sems; i++) {
signal_values[i] = vk_frame->sem_value[i] + 1;
signal_sems[i] = vk_frame->sem[i];
}
VkTimelineSemaphoreSubmitInfo timeline_info = {
.sType = VK_STRUCTURE_TYPE_TIMELINE_SEMAPHORE_SUBMIT_INFO,
.signalSemaphoreValueCount = (uint32_t)num_sems,
.pSignalSemaphoreValues = signal_values,
};
const VkPipelineStageFlags wait_stage = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
VkSubmitInfo submit_info = {
.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO,
.pNext = &timeline_info,
.waitSemaphoreCount = 1,
.pWaitSemaphores = &self->gl_ready_semaphore,
.pWaitDstStageMask = &wait_stage,
.commandBufferCount = 1,
.pCommandBuffers = &self->command_buffer,
.signalSemaphoreCount = (uint32_t)num_sems,
.pSignalSemaphores = signal_sems,
};
self->vk.vkQueueSubmit(self->vk_queue, 1, &submit_info, self->fence);
for(int i = 0; i < num_sems; i++)
vk_frame->sem_value[i]++;
} else {
/* Fallback: plain submit, we already stalled via glFinish() */
VkSubmitInfo submit_info = {
.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO,
.commandBufferCount = 1,
.pCommandBuffers = &self->command_buffer,
};
self->vk.vkQueueSubmit(self->vk_queue, 1, &submit_info, self->fence);
}
self->fence_submitted = true;
}
void gsr_video_encoder_vulkan_stop(gsr_video_encoder_vulkan *self, AVCodecContext *video_codec_context) {
self->params.egl->glDeleteTextures(2, self->target_textures);
self->target_textures[0] = 0;
self->target_textures[1] = 0;
if(self->vk_device) {
/* Drain any in-flight copy before freeing resources */
if(self->fence_submitted) {
self->vk.vkWaitForFences(self->vk_device, 1, &self->fence, VK_TRUE, UINT64_MAX);
self->fence_submitted = false;
}
if(self->gl_ready_semaphore)
self->vk.vkDestroySemaphore(self->vk_device, self->gl_ready_semaphore, NULL);
if(self->fence)
self->vk.vkDestroyFence(self->vk_device, self->fence, NULL);
/* Destroying the command pool also frees the command buffer */
if(self->command_pool)
self->vk.vkDestroyCommandPool(self->vk_device, self->command_pool, NULL);
for(int i = 0; i < 2; i++) {
if(self->export_images[i])
self->vk.vkDestroyImage(self->vk_device, self->export_images[i], NULL);
if(self->export_memory[i])
self->vk.vkFreeMemory(self->vk_device, self->export_memory[i], NULL);
}
}
if(video_codec_context->hw_frames_ctx)
av_buffer_unref(&video_codec_context->hw_frames_ctx);
if(self->device_ctx)
@@ -305,7 +851,7 @@ gsr_video_encoder* gsr_video_encoder_vulkan_create(const gsr_video_encoder_vulka
*encoder = (gsr_video_encoder) {
.start = gsr_video_encoder_vulkan_start,
.copy_textures_to_frame = NULL,
.copy_textures_to_frame = gsr_video_encoder_vulkan_copy_textures_to_frame,
.get_textures = gsr_video_encoder_vulkan_get_textures,
.destroy = gsr_video_encoder_vulkan_destroy,
.priv = encoder_vulkan

View File

@@ -425,7 +425,7 @@ static AVCodecContext *create_video_codec_context(AVPixelFormat pix_fmt, const A
if (codec_context->codec_id == AV_CODEC_ID_MPEG1VIDEO)
codec_context->mb_decision = 2;
if(!use_software_video_encoder && egl.gpu_info.vendor != GSR_GPU_VENDOR_NVIDIA && arg_parser.bitrate_mode != GSR_BITRATE_MODE_CBR) {
if(!use_software_video_encoder && (egl.gpu_info.vendor != GSR_GPU_VENDOR_NVIDIA || video_codec_is_vulkan(arg_parser.video_codec)) && arg_parser.bitrate_mode != GSR_BITRATE_MODE_CBR) {
// 8 bit / 10 bit = 80%, and increase it even more
const float quality_multiply = hdr ? (8.0f/10.0f * 0.7f) : 1.0f;
if(codec_context->codec_id == AV_CODEC_ID_AV1 || codec_context->codec_id == AV_CODEC_ID_H264 || codec_context->codec_id == AV_CODEC_ID_HEVC) {
@@ -479,7 +479,7 @@ static AVCodecContext *create_video_codec_context(AVPixelFormat pix_fmt, const A
av_opt_set_int(codec_context->priv_data, "b_ref_mode", 0, 0);
//av_opt_set_int(codec_context->priv_data, "cbr", true, 0);
if(egl.gpu_info.vendor != GSR_GPU_VENDOR_NVIDIA) {
if(egl.gpu_info.vendor != GSR_GPU_VENDOR_NVIDIA || video_codec_is_vulkan(arg_parser.video_codec)) {
// TODO: More options, better options
//codec_context->bit_rate = codec_context->width * codec_context->height;
switch(arg_parser.bitrate_mode) {
@@ -614,51 +614,19 @@ static void dict_set_profile(AVCodecContext *codec_context, gsr_gpu_vendor vendo
static void video_software_set_qp(AVCodecContext *codec_context, gsr_video_quality video_quality, bool hdr, AVDictionary **options) {
// 8 bit / 10 bit = 80%
const float qp_multiply = hdr ? 8.0f/10.0f : 1.0f;
if(codec_context->codec_id == AV_CODEC_ID_AV1) {
switch(video_quality) {
case GSR_VIDEO_QUALITY_MEDIUM:
av_dict_set_int(options, "qp", 35 * qp_multiply, 0);
break;
case GSR_VIDEO_QUALITY_HIGH:
av_dict_set_int(options, "qp", 30 * qp_multiply, 0);
break;
case GSR_VIDEO_QUALITY_VERY_HIGH:
av_dict_set_int(options, "qp", 25 * qp_multiply, 0);
break;
case GSR_VIDEO_QUALITY_ULTRA:
av_dict_set_int(options, "qp", 22 * qp_multiply, 0);
break;
}
} else if(codec_context->codec_id == AV_CODEC_ID_H264) {
switch(video_quality) {
case GSR_VIDEO_QUALITY_MEDIUM:
av_dict_set_int(options, "qp", 34 * qp_multiply, 0);
break;
case GSR_VIDEO_QUALITY_HIGH:
av_dict_set_int(options, "qp", 30 * qp_multiply, 0);
break;
case GSR_VIDEO_QUALITY_VERY_HIGH:
av_dict_set_int(options, "qp", 25 * qp_multiply, 0);
break;
case GSR_VIDEO_QUALITY_ULTRA:
av_dict_set_int(options, "qp", 22 * qp_multiply, 0);
break;
}
} else {
switch(video_quality) {
case GSR_VIDEO_QUALITY_MEDIUM:
av_dict_set_int(options, "qp", 35 * qp_multiply, 0);
break;
case GSR_VIDEO_QUALITY_HIGH:
av_dict_set_int(options, "qp", 30 * qp_multiply, 0);
break;
case GSR_VIDEO_QUALITY_VERY_HIGH:
av_dict_set_int(options, "qp", 25 * qp_multiply, 0);
break;
case GSR_VIDEO_QUALITY_ULTRA:
av_dict_set_int(options, "qp", 22 * qp_multiply, 0);
break;
}
switch(video_quality) {
case GSR_VIDEO_QUALITY_MEDIUM:
av_dict_set_int(options, "qp", 35 * qp_multiply, 0);
break;
case GSR_VIDEO_QUALITY_HIGH:
av_dict_set_int(options, "qp", 30 * qp_multiply, 0);
break;
case GSR_VIDEO_QUALITY_VERY_HIGH:
av_dict_set_int(options, "qp", 25 * qp_multiply, 0);
break;
case GSR_VIDEO_QUALITY_ULTRA:
av_dict_set_int(options, "qp", 22 * qp_multiply, 0);
break;
}
}
@@ -723,118 +691,19 @@ static void video_set_rc(gsr_video_codec video_codec, gsr_gpu_vendor vendor, gsr
static void video_hardware_set_qp(AVCodecContext *codec_context, gsr_video_quality video_quality, gsr_gpu_vendor vendor, bool hdr, AVDictionary **options) {
// 8 bit / 10 bit = 80%
const float qp_multiply = hdr ? 8.0f/10.0f : 1.0f;
if(vendor == GSR_GPU_VENDOR_NVIDIA) {
// TODO: Test if these should be in the same range as vaapi
if(codec_context->codec_id == AV_CODEC_ID_AV1) {
switch(video_quality) {
case GSR_VIDEO_QUALITY_MEDIUM:
av_dict_set_int(options, "qp", 35 * qp_multiply, 0);
break;
case GSR_VIDEO_QUALITY_HIGH:
av_dict_set_int(options, "qp", 30 * qp_multiply, 0);
break;
case GSR_VIDEO_QUALITY_VERY_HIGH:
av_dict_set_int(options, "qp", 25 * qp_multiply, 0);
break;
case GSR_VIDEO_QUALITY_ULTRA:
av_dict_set_int(options, "qp", 22 * qp_multiply, 0);
break;
}
} else if(codec_context->codec_id == AV_CODEC_ID_H264) {
switch(video_quality) {
case GSR_VIDEO_QUALITY_MEDIUM:
av_dict_set_int(options, "qp", 35 * qp_multiply, 0);
break;
case GSR_VIDEO_QUALITY_HIGH:
av_dict_set_int(options, "qp", 30 * qp_multiply, 0);
break;
case GSR_VIDEO_QUALITY_VERY_HIGH:
av_dict_set_int(options, "qp", 25 * qp_multiply, 0);
break;
case GSR_VIDEO_QUALITY_ULTRA:
av_dict_set_int(options, "qp", 22 * qp_multiply, 0);
break;
}
} else if(codec_context->codec_id == AV_CODEC_ID_HEVC) {
switch(video_quality) {
case GSR_VIDEO_QUALITY_MEDIUM:
av_dict_set_int(options, "qp", 35 * qp_multiply, 0);
break;
case GSR_VIDEO_QUALITY_HIGH:
av_dict_set_int(options, "qp", 30 * qp_multiply, 0);
break;
case GSR_VIDEO_QUALITY_VERY_HIGH:
av_dict_set_int(options, "qp", 25 * qp_multiply, 0);
break;
case GSR_VIDEO_QUALITY_ULTRA:
av_dict_set_int(options, "qp", 22 * qp_multiply, 0);
break;
}
} else if(codec_context->codec_id == AV_CODEC_ID_VP8 || codec_context->codec_id == AV_CODEC_ID_VP9) {
switch(video_quality) {
case GSR_VIDEO_QUALITY_MEDIUM:
av_dict_set_int(options, "qp", 35 * qp_multiply, 0);
break;
case GSR_VIDEO_QUALITY_HIGH:
av_dict_set_int(options, "qp", 30 * qp_multiply, 0);
break;
case GSR_VIDEO_QUALITY_VERY_HIGH:
av_dict_set_int(options, "qp", 25 * qp_multiply, 0);
break;
case GSR_VIDEO_QUALITY_ULTRA:
av_dict_set_int(options, "qp", 22 * qp_multiply, 0);
break;
}
}
} else {
if(codec_context->codec_id == AV_CODEC_ID_AV1) {
// Using global_quality option
} else if(codec_context->codec_id == AV_CODEC_ID_H264) {
switch(video_quality) {
case GSR_VIDEO_QUALITY_MEDIUM:
av_dict_set_int(options, "qp", 35 * qp_multiply, 0);
break;
case GSR_VIDEO_QUALITY_HIGH:
av_dict_set_int(options, "qp", 30 * qp_multiply, 0);
break;
case GSR_VIDEO_QUALITY_VERY_HIGH:
av_dict_set_int(options, "qp", 25 * qp_multiply, 0);
break;
case GSR_VIDEO_QUALITY_ULTRA:
av_dict_set_int(options, "qp", 22 * qp_multiply, 0);
break;
}
} else if(codec_context->codec_id == AV_CODEC_ID_HEVC) {
switch(video_quality) {
case GSR_VIDEO_QUALITY_MEDIUM:
av_dict_set_int(options, "qp", 35 * qp_multiply, 0);
break;
case GSR_VIDEO_QUALITY_HIGH:
av_dict_set_int(options, "qp", 30 * qp_multiply, 0);
break;
case GSR_VIDEO_QUALITY_VERY_HIGH:
av_dict_set_int(options, "qp", 25 * qp_multiply, 0);
break;
case GSR_VIDEO_QUALITY_ULTRA:
av_dict_set_int(options, "qp", 22 * qp_multiply, 0);
break;
}
} else if(codec_context->codec_id == AV_CODEC_ID_VP8 || codec_context->codec_id == AV_CODEC_ID_VP9) {
switch(video_quality) {
case GSR_VIDEO_QUALITY_MEDIUM:
av_dict_set_int(options, "qp", 35 * qp_multiply, 0);
break;
case GSR_VIDEO_QUALITY_HIGH:
av_dict_set_int(options, "qp", 30 * qp_multiply, 0);
break;
case GSR_VIDEO_QUALITY_VERY_HIGH:
av_dict_set_int(options, "qp", 25 * qp_multiply, 0);
break;
case GSR_VIDEO_QUALITY_ULTRA:
av_dict_set_int(options, "qp", 22 * qp_multiply, 0);
break;
}
}
switch(video_quality) {
case GSR_VIDEO_QUALITY_MEDIUM:
av_dict_set_int(options, "qp", 35 * qp_multiply, 0);
break;
case GSR_VIDEO_QUALITY_HIGH:
av_dict_set_int(options, "qp", 30 * qp_multiply, 0);
break;
case GSR_VIDEO_QUALITY_VERY_HIGH:
av_dict_set_int(options, "qp", 25 * qp_multiply, 0);
break;
case GSR_VIDEO_QUALITY_ULTRA:
av_dict_set_int(options, "qp", 22 * qp_multiply, 0);
break;
}
}
@@ -854,9 +723,19 @@ static void open_video_hardware(AVCodecContext *codec_context, bool low_power, c
if(video_codec_is_vulkan(arg_parser.video_codec)) {
av_dict_set_int(&options, "async_depth", 3, 0);
av_dict_set(&options, "tune", "hq", 0);
av_dict_set(&options, "usage", "record", 0); // TODO: Set to stream when streaming
av_dict_set(&options, "content", "rendered", 0);
av_dict_set(&options, "tune", "ll", 0); // Low latency
av_dict_set(&options, "usage", arg_parser.is_livestream ? "stream" : "record", 0);
av_dict_set(&options, "content", "rendered", 0); // Game or 3D content
if(codec_context->codec_id == AV_CODEC_ID_H264) {
// Removed because it causes stutter in games for some people
//av_dict_set_int(&options, "quality", 5, 0); // quality preset
} else if(codec_context->codec_id == AV_CODEC_ID_AV1) {
av_dict_set(&options, "tier", "main", 0);
} else if(codec_context->codec_id == AV_CODEC_ID_HEVC) {
if(hdr)
av_dict_set(&options, "sei", "hdr", 0);
}
} else if(egl.gpu_info.vendor == GSR_GPU_VENDOR_NVIDIA) {
// TODO: These dont seem to be necessary
// av_dict_set_int(&options, "zerolatency", 1, 0);
@@ -866,7 +745,7 @@ static void open_video_hardware(AVCodecContext *codec_context, bool low_power, c
// av_dict_set(&options, "preset", "llhq", 0);
// av_dict_set(&options, "tune", "ll", 0);
// }
av_dict_set(&options, "tune", "hq", 0);
av_dict_set(&options, "tune", "ll", 0);
switch(arg_parser.tune) {
case GSR_TUNE_PERFORMANCE:
@@ -1674,7 +1553,7 @@ static bool get_supported_video_codecs(gsr_egl *egl, gsr_video_codec video_codec
}
if(video_codec_is_vulkan(video_codec))
return gsr_get_supported_video_codecs_vulkan(video_codecs, egl->card_path, cleanup);
return gsr_get_supported_video_codecs_vulkan(video_codecs, egl->card_path, &egl->vulkan_device_index, cleanup);
switch(egl->gpu_info.vendor) {
case GSR_GPU_VENDOR_AMD:
@@ -1779,7 +1658,13 @@ static const AVCodec* get_ffmpeg_video_codec(gsr_video_codec video_codec, gsr_gp
case GSR_VIDEO_CODEC_H264_VULKAN:
return avcodec_find_encoder_by_name("h264_vulkan");
case GSR_VIDEO_CODEC_HEVC_VULKAN:
case GSR_VIDEO_CODEC_HEVC_HDR_VULKAN:
case GSR_VIDEO_CODEC_HEVC_10BIT_VULKAN:
return avcodec_find_encoder_by_name("hevc_vulkan");
case GSR_VIDEO_CODEC_AV1_VULKAN:
case GSR_VIDEO_CODEC_AV1_HDR_VULKAN:
case GSR_VIDEO_CODEC_AV1_10BIT_VULKAN:
return avcodec_find_encoder_by_name("av1_vulkan");
}
return nullptr;
}
@@ -1819,6 +1704,12 @@ static void set_supported_video_codecs_ffmpeg(gsr_supported_video_codecs *suppor
supported_video_codecs_vulkan->hevc_hdr.supported = false;
supported_video_codecs_vulkan->hevc_10bit.supported = false;
}
if(!get_ffmpeg_video_codec(GSR_VIDEO_CODEC_AV1_VULKAN, vendor)) {
supported_video_codecs_vulkan->av1.supported = false;
supported_video_codecs_vulkan->av1_hdr.supported = false;
supported_video_codecs_vulkan->av1_10bit.supported = false;
}
}
}
@@ -1852,10 +1743,20 @@ static void list_supported_video_codecs(gsr_egl *egl, bool wayland) {
puts("vp8");
if(supported_video_codecs.vp9.supported)
puts("vp9");
//if(supported_video_codecs_vulkan.h264.supported)
// puts("h264_vulkan");
//if(supported_video_codecs_vulkan.hevc.supported)
// puts("hevc_vulkan"); // TODO: hdr, 10 bit
if(supported_video_codecs_vulkan.h264.supported)
puts("h264_vulkan");
if(supported_video_codecs_vulkan.hevc.supported)
puts("hevc_vulkan");
if(supported_video_codecs_vulkan.hevc_hdr.supported && wayland)
puts("hevc_hdr_vulkan");
if(supported_video_codecs_vulkan.hevc_10bit.supported)
puts("hevc_10bit_vulkan");
if(supported_video_codecs_vulkan.av1.supported)
puts("av1_vulkan");
if(supported_video_codecs_vulkan.av1_hdr.supported && wayland)
puts("av1_hdr_vulkan");
if(supported_video_codecs_vulkan.av1_10bit.supported)
puts("av1_10bit_vulkan");
}
static bool monitor_capture_use_drm(const gsr_window *window, gsr_gpu_vendor vendor) {
@@ -1888,23 +1789,31 @@ static void camera_query_callback(const char *path, const gsr_capture_v4l2_suppo
printf("%s|%ux%u@%uhz|%s\n", path, setup->resolution.width, setup->resolution.height, gsr_capture_v4l2_framerate_to_number(setup->framerate), gsr_capture_v4l2_pixfmt_to_string(setup->pixfmt));
}
static void list_supported_capture_options(const gsr_window *window, const char *card_path, bool list_monitors) {
// Returns the number of monitors found
static int list_monitors(const gsr_window *window, const char *card_path) {
capture_options_callback options;
options.window = window;
options.num_monitors = 0;
const bool is_x11 = gsr_window_get_display_server(window) == GSR_DISPLAY_SERVER_X11;
const gsr_connection_type connection_type = is_x11 ? GSR_CONNECTION_X11 : GSR_CONNECTION_DRM;
for_each_active_monitor_output(window, card_path, connection_type, output_monitor_info, &options);
return options.num_monitors;
}
static void list_supported_capture_options(const gsr_window *window, const char *card_path, bool do_list_monitors) {
const bool wayland = gsr_window_get_display_server(window) == GSR_DISPLAY_SERVER_WAYLAND;
if(!wayland) {
puts("window");
puts("focused");
}
capture_options_callback options;
options.window = window;
options.num_monitors = 0;
if(list_monitors) {
const bool is_x11 = gsr_window_get_display_server(window) == GSR_DISPLAY_SERVER_X11;
const gsr_connection_type connection_type = is_x11 ? GSR_CONNECTION_X11 : GSR_CONNECTION_DRM;
for_each_active_monitor_output(window, card_path, connection_type, output_monitor_info, &options);
}
int num_monitors = 0;
if(do_list_monitors)
num_monitors = list_monitors(window, card_path);
if(options.num_monitors > 0)
if(num_monitors > 0)
puts("region");
gsr_capture_v4l2_list_devices(camera_query_callback, NULL);
@@ -1933,11 +1842,20 @@ static void version_command(void *userdata) {
_exit(0);
}
static void info_command(void *userdata) {
(void)userdata;
struct WindowingSetup {
Display *dpy;
gsr_window *window;
gsr_egl egl;
bool list_monitors;
};
static WindowingSetup setup_windowing(bool setup_egl) {
WindowingSetup setup;
memset(&setup, 0, sizeof(setup));
bool wayland = false;
Display *dpy = XOpenDisplay(nullptr);
if (!dpy) {
setup.dpy = XOpenDisplay(nullptr);
if (!setup.dpy) {
wayland = true;
fprintf(stderr, "gsr warning: failed to connect to the X server. Assuming wayland is running without Xwayland\n");
}
@@ -1946,7 +1864,7 @@ static void info_command(void *userdata) {
XSetIOErrorHandler(x11_io_error_handler);
if(!wayland)
wayland = is_xwayland(dpy);
wayland = is_xwayland(setup.dpy);
if(!wayland && is_using_prime_run()) {
// Disable prime-run and similar options as it doesn't work, the monitor to capture has to be run on the same device.
@@ -1956,46 +1874,56 @@ static void info_command(void *userdata) {
disable_prime_run();
}
gsr_window *window = gsr_window_create(dpy, wayland);
if(!window) {
setup.window = gsr_window_create(setup.dpy, wayland);
if(!setup.window) {
fprintf(stderr, "gsr error: failed to create window\n");
_exit(1);
}
gsr_egl egl;
if(!gsr_egl_load(&egl, window, false, false)) {
fprintf(stderr, "gsr error: failed to load opengl\n");
_exit(22);
}
setup.list_monitors = true;
bool list_monitors = true;
egl.card_path[0] = '\0';
if(monitor_capture_use_drm(window, egl.gpu_info.vendor)) {
// TODO: Allow specifying another card, and in other places
if(!gsr_get_valid_card_path(&egl, egl.card_path, true)) {
fprintf(stderr, "gsr error: no /dev/dri/cardX device found. Make sure that you have at least one monitor connected\n");
list_monitors = false;
if(setup_egl) {
if(!gsr_egl_load(&setup.egl, setup.window, false, false)) {
fprintf(stderr, "gsr error: failed to load opengl\n");
_exit(22);
}
setup.egl.card_path[0] = '\0';
if(monitor_capture_use_drm(setup.window, setup.egl.gpu_info.vendor)) {
// TODO: Allow specifying another card, and in other places
if(!gsr_get_valid_card_path(&setup.egl, setup.egl.card_path, true)) {
fprintf(stderr, "gsr error: no /dev/dri/cardX device found. Make sure that you have at least one monitor connected\n");
setup.list_monitors = false;
}
}
}
return setup;
}
static void info_command(void *userdata) {
(void)userdata;
WindowingSetup windowing_setup = setup_windowing(true);
const bool wayland = gsr_window_get_display_server(windowing_setup.window) == GSR_DISPLAY_SERVER_WAYLAND;
av_log_set_level(AV_LOG_FATAL);
puts("section=system_info");
list_system_info(wayland);
if(egl.gpu_info.is_steam_deck)
if(windowing_setup.egl.gpu_info.is_steam_deck)
puts("is_steam_deck|yes");
else
puts("is_steam_deck|no");
printf("gsr_version|%s\n", GSR_VERSION);
puts("section=gpu_info");
list_gpu_info(&egl);
list_gpu_info(&windowing_setup.egl);
puts("section=video_codecs");
list_supported_video_codecs(&egl, wayland);
list_supported_video_codecs(&windowing_setup.egl, wayland);
puts("section=image_formats");
puts("jpeg");
puts("png");
puts("section=capture_options");
list_supported_capture_options(window, egl.card_path, list_monitors);
list_supported_capture_options(windowing_setup.window, windowing_setup.egl.card_path, windowing_setup.list_monitors);
fflush(stdout);
@@ -2058,53 +1986,30 @@ static void list_v4l2_devices(void *userdata) {
// |card_path| can be NULL. If not NULL then |vendor| has to be valid
static void list_capture_options_command(const char *card_path, void *userdata) {
(void)userdata;
bool wayland = false;
Display *dpy = XOpenDisplay(nullptr);
if (!dpy) {
wayland = true;
fprintf(stderr, "gsr warning: failed to connect to the X server. Assuming wayland is running without Xwayland\n");
}
WindowingSetup windowing_setup = setup_windowing(card_path != nullptr);
XSetErrorHandler(x11_error_handler);
XSetIOErrorHandler(x11_io_error_handler);
if(card_path)
list_supported_capture_options(windowing_setup.window, card_path, true);
else
list_supported_capture_options(windowing_setup.window, windowing_setup.egl.card_path, windowing_setup.list_monitors);
if(!wayland)
wayland = is_xwayland(dpy);
fflush(stdout);
if(!wayland && is_using_prime_run()) {
// Disable prime-run and similar options as it doesn't work, the monitor to capture has to be run on the same device.
// This is fine on wayland since nvidia uses drm interface there and the monitor query checks the monitors connected
// to the drm device.
fprintf(stderr, "gsr warning: use of prime-run on X11 is not supported. Disabling prime-run\n");
disable_prime_run();
}
// Not needed as this will just slow down shutdown
//gsr_egl_unload(&egl);
//gsr_window_destroy(&window);
//if(dpy)
// XCloseDisplay(dpy);
gsr_window *window = gsr_window_create(dpy, wayland);
if(!window) {
fprintf(stderr, "gsr error: failed to create window\n");
_exit(1);
}
_exit(0);
}
if(card_path) {
list_supported_capture_options(window, card_path, true);
} else {
gsr_egl egl;
if(!gsr_egl_load(&egl, window, false, false)) {
fprintf(stderr, "gsr error: failed to load opengl\n");
_exit(1);
}
static void list_monitors_command(void *userdata) {
(void)userdata;
WindowingSetup windowing_setup = setup_windowing(true);
bool list_monitors = true;
egl.card_path[0] = '\0';
if(monitor_capture_use_drm(window, egl.gpu_info.vendor)) {
// TODO: Allow specifying another card, and in other places
if(!gsr_get_valid_card_path(&egl, egl.card_path, true)) {
fprintf(stderr, "gsr error: no /dev/dri/cardX device found. Make sure that you have at least one monitor connected\n");
list_monitors = false;
}
}
list_supported_capture_options(window, egl.card_path, list_monitors);
}
if(windowing_setup.list_monitors)
list_monitors(windowing_setup.window, windowing_setup.egl.card_path);
fflush(stdout);
@@ -2269,6 +2174,7 @@ static std::string region_get_data(gsr_egl *egl, vec2i *region_size, vec2i *regi
} else {
region_position->x -= monitor_pos.x;
region_position->y -= monitor_pos.y;
// Match drm plane coordinate space (1x scaling) to wayland coordinate space (which may have scaling set by user)
region_position->x *= monitor_scale_inverted;
region_position->y *= monitor_scale_inverted;
@@ -2799,15 +2705,6 @@ static bool string_to_bool(const char *str, size_t len, bool *value) {
}
}
static int clamp_scalar(int value) {
if(value < -100)
return -100;
else if(value > 100)
return 100;
else
return value;
}
static void parse_capture_source_options(const std::string &capture_source_str, CaptureSource &capture_source) {
bool is_first_column = true;
@@ -2829,9 +2726,6 @@ static void parse_capture_source_options(const std::string &capture_source_str,
fprintf(stderr, "gsr error: invalid capture target value for option x: \"%.*s\", expected a number\n", (int)size, sub);
_exit(1);
}
if(capture_source.pos.x_type == VVEC2I_TYPE_SCALAR)
capture_source.pos.x = clamp_scalar(capture_source.pos.x);
} else if(string_starts_with(sub, size, "y=")) {
capture_source.pos.y_type = sub[size - 1] == '%' ? VVEC2I_TYPE_SCALAR : VVEC2I_TYPE_PIXELS;
sub += 2;
@@ -2841,8 +2735,6 @@ static void parse_capture_source_options(const std::string &capture_source_str,
_exit(1);
}
if(capture_source.pos.y_type == VVEC2I_TYPE_SCALAR)
capture_source.pos.y = clamp_scalar(capture_source.pos.y);
} else if(string_starts_with(sub, size, "width=")) {
capture_source.size.x_type = sub[size - 1] == '%' ? VVEC2I_TYPE_SCALAR : VVEC2I_TYPE_PIXELS;
sub += 6;
@@ -2851,9 +2743,6 @@ static void parse_capture_source_options(const std::string &capture_source_str,
fprintf(stderr, "gsr error: invalid capture target value for option width: \"%.*s\", expected a number\n", (int)size, sub);
_exit(1);
}
if(capture_source.size.x_type == VVEC2I_TYPE_SCALAR)
capture_source.size.x = clamp_scalar(capture_source.size.x);
} else if(string_starts_with(sub, size, "height=")) {
capture_source.size.y_type = sub[size - 1] == '%' ? VVEC2I_TYPE_SCALAR : VVEC2I_TYPE_PIXELS;
sub += 7;
@@ -2862,9 +2751,6 @@ static void parse_capture_source_options(const std::string &capture_source_str,
fprintf(stderr, "gsr error: invalid capture target value for option height: \"%.*s\", expected a number\n", (int)size, sub);
_exit(1);
}
if(capture_source.size.y_type == VVEC2I_TYPE_SCALAR)
capture_source.size.y = clamp_scalar(capture_source.size.y);
} else if(string_starts_with(sub, size, "halign=")) {
sub += 7;
size -= 7;
@@ -3101,56 +2987,68 @@ static gsr_audio_codec select_audio_codec_with_fallback(gsr_audio_codec audio_co
static bool video_codec_only_supports_low_power_mode(const gsr_supported_video_codecs &supported_video_codecs, gsr_video_codec video_codec) {
switch(video_codec) {
case GSR_VIDEO_CODEC_H264: return supported_video_codecs.h264.low_power;
case GSR_VIDEO_CODEC_HEVC: return supported_video_codecs.hevc.low_power;
case GSR_VIDEO_CODEC_HEVC_HDR: return supported_video_codecs.hevc_hdr.low_power;
case GSR_VIDEO_CODEC_HEVC_10BIT: return supported_video_codecs.hevc_10bit.low_power;
case GSR_VIDEO_CODEC_AV1: return supported_video_codecs.av1.low_power;
case GSR_VIDEO_CODEC_AV1_HDR: return supported_video_codecs.av1_hdr.low_power;
case GSR_VIDEO_CODEC_AV1_10BIT: return supported_video_codecs.av1_10bit.low_power;
case GSR_VIDEO_CODEC_VP8: return supported_video_codecs.vp8.low_power;
case GSR_VIDEO_CODEC_VP9: return supported_video_codecs.vp9.low_power;
case GSR_VIDEO_CODEC_H264_VULKAN: return supported_video_codecs.h264.low_power;
case GSR_VIDEO_CODEC_HEVC_VULKAN: return supported_video_codecs.hevc.low_power; // TODO: hdr, 10 bit
case GSR_VIDEO_CODEC_H264: return supported_video_codecs.h264.low_power;
case GSR_VIDEO_CODEC_HEVC: return supported_video_codecs.hevc.low_power;
case GSR_VIDEO_CODEC_HEVC_HDR: return supported_video_codecs.hevc_hdr.low_power;
case GSR_VIDEO_CODEC_HEVC_10BIT: return supported_video_codecs.hevc_10bit.low_power;
case GSR_VIDEO_CODEC_AV1: return supported_video_codecs.av1.low_power;
case GSR_VIDEO_CODEC_AV1_HDR: return supported_video_codecs.av1_hdr.low_power;
case GSR_VIDEO_CODEC_AV1_10BIT: return supported_video_codecs.av1_10bit.low_power;
case GSR_VIDEO_CODEC_VP8: return supported_video_codecs.vp8.low_power;
case GSR_VIDEO_CODEC_VP9: return supported_video_codecs.vp9.low_power;
case GSR_VIDEO_CODEC_H264_VULKAN: return supported_video_codecs.h264.low_power;
case GSR_VIDEO_CODEC_HEVC_VULKAN: return supported_video_codecs.hevc.low_power;
case GSR_VIDEO_CODEC_HEVC_HDR_VULKAN: return supported_video_codecs.hevc_hdr.low_power;
case GSR_VIDEO_CODEC_HEVC_10BIT_VULKAN: return supported_video_codecs.hevc_10bit.low_power;
case GSR_VIDEO_CODEC_AV1_VULKAN: return supported_video_codecs.av1.low_power;
case GSR_VIDEO_CODEC_AV1_HDR_VULKAN: return supported_video_codecs.av1_hdr.low_power;
case GSR_VIDEO_CODEC_AV1_10BIT_VULKAN: return supported_video_codecs.av1_10bit.low_power;
}
return false;
}
static const AVCodec* get_av_codec_if_supported(gsr_video_codec video_codec, gsr_egl *egl, bool use_software_video_encoder, const gsr_supported_video_codecs *supported_video_codecs) {
switch(video_codec) {
case GSR_VIDEO_CODEC_H264: {
case GSR_VIDEO_CODEC_H264:
case GSR_VIDEO_CODEC_H264_VULKAN: {
if(use_software_video_encoder)
return avcodec_find_encoder_by_name("libx264");
else if(supported_video_codecs->h264.supported)
return get_ffmpeg_video_codec(video_codec, egl->gpu_info.vendor);
break;
}
case GSR_VIDEO_CODEC_HEVC: {
case GSR_VIDEO_CODEC_HEVC:
case GSR_VIDEO_CODEC_HEVC_VULKAN: {
if(supported_video_codecs->hevc.supported)
return get_ffmpeg_video_codec(video_codec, egl->gpu_info.vendor);
break;
}
case GSR_VIDEO_CODEC_HEVC_HDR: {
case GSR_VIDEO_CODEC_HEVC_HDR:
case GSR_VIDEO_CODEC_HEVC_HDR_VULKAN: {
if(supported_video_codecs->hevc_hdr.supported)
return get_ffmpeg_video_codec(video_codec, egl->gpu_info.vendor);
break;
}
case GSR_VIDEO_CODEC_HEVC_10BIT: {
case GSR_VIDEO_CODEC_HEVC_10BIT:
case GSR_VIDEO_CODEC_HEVC_10BIT_VULKAN: {
if(supported_video_codecs->hevc_10bit.supported)
return get_ffmpeg_video_codec(video_codec, egl->gpu_info.vendor);
break;
}
case GSR_VIDEO_CODEC_AV1: {
case GSR_VIDEO_CODEC_AV1:
case GSR_VIDEO_CODEC_AV1_VULKAN: {
if(supported_video_codecs->av1.supported)
return get_ffmpeg_video_codec(video_codec, egl->gpu_info.vendor);
break;
}
case GSR_VIDEO_CODEC_AV1_HDR: {
case GSR_VIDEO_CODEC_AV1_HDR:
case GSR_VIDEO_CODEC_AV1_HDR_VULKAN: {
if(supported_video_codecs->av1_hdr.supported)
return get_ffmpeg_video_codec(video_codec, egl->gpu_info.vendor);
break;
}
case GSR_VIDEO_CODEC_AV1_10BIT: {
case GSR_VIDEO_CODEC_AV1_10BIT:
case GSR_VIDEO_CODEC_AV1_10BIT_VULKAN: {
if(supported_video_codecs->av1_10bit.supported)
return get_ffmpeg_video_codec(video_codec, egl->gpu_info.vendor);
break;
@@ -3165,56 +3063,52 @@ static const AVCodec* get_av_codec_if_supported(gsr_video_codec video_codec, gsr
return get_ffmpeg_video_codec(video_codec, egl->gpu_info.vendor);
break;
}
case GSR_VIDEO_CODEC_H264_VULKAN: {
if(supported_video_codecs->h264.supported)
return get_ffmpeg_video_codec(video_codec, egl->gpu_info.vendor);
break;
}
case GSR_VIDEO_CODEC_HEVC_VULKAN: {
// TODO: hdr, 10 bit
if(supported_video_codecs->hevc.supported)
return get_ffmpeg_video_codec(video_codec, egl->gpu_info.vendor);
break;
}
}
return nullptr;
}
static vec2i codec_get_max_resolution(gsr_video_codec video_codec, bool use_software_video_encoder, const gsr_supported_video_codecs *supported_video_codecs) {
switch(video_codec) {
case GSR_VIDEO_CODEC_H264: {
case GSR_VIDEO_CODEC_H264:
case GSR_VIDEO_CODEC_H264_VULKAN: {
if(use_software_video_encoder)
return {4096, 2304};
else if(supported_video_codecs->h264.supported)
return supported_video_codecs->h264.max_resolution;
break;
}
case GSR_VIDEO_CODEC_HEVC: {
case GSR_VIDEO_CODEC_HEVC:
case GSR_VIDEO_CODEC_HEVC_VULKAN: {
if(supported_video_codecs->hevc.supported)
return supported_video_codecs->hevc.max_resolution;
break;
}
case GSR_VIDEO_CODEC_HEVC_HDR: {
case GSR_VIDEO_CODEC_HEVC_HDR:
case GSR_VIDEO_CODEC_HEVC_HDR_VULKAN: {
if(supported_video_codecs->hevc_hdr.supported)
return supported_video_codecs->hevc_hdr.max_resolution;
break;
}
case GSR_VIDEO_CODEC_HEVC_10BIT: {
case GSR_VIDEO_CODEC_HEVC_10BIT:
case GSR_VIDEO_CODEC_HEVC_10BIT_VULKAN: {
if(supported_video_codecs->hevc_10bit.supported)
return supported_video_codecs->hevc_10bit.max_resolution;
break;
}
case GSR_VIDEO_CODEC_AV1: {
case GSR_VIDEO_CODEC_AV1:
case GSR_VIDEO_CODEC_AV1_VULKAN: {
if(supported_video_codecs->av1.supported)
return supported_video_codecs->av1.max_resolution;
break;
}
case GSR_VIDEO_CODEC_AV1_HDR: {
case GSR_VIDEO_CODEC_AV1_HDR:
case GSR_VIDEO_CODEC_AV1_HDR_VULKAN: {
if(supported_video_codecs->av1_hdr.supported)
return supported_video_codecs->av1_hdr.max_resolution;
break;
}
case GSR_VIDEO_CODEC_AV1_10BIT: {
case GSR_VIDEO_CODEC_AV1_10BIT:
case GSR_VIDEO_CODEC_AV1_10BIT_VULKAN: {
if(supported_video_codecs->av1_10bit.supported)
return supported_video_codecs->av1_10bit.max_resolution;
break;
@@ -3229,17 +3123,6 @@ static vec2i codec_get_max_resolution(gsr_video_codec video_codec, bool use_soft
return supported_video_codecs->vp9.max_resolution;
break;
}
case GSR_VIDEO_CODEC_H264_VULKAN: {
if(supported_video_codecs->h264.supported)
return supported_video_codecs->h264.max_resolution;
break;
}
case GSR_VIDEO_CODEC_HEVC_VULKAN: {
// TODO: hdr, 10 bit
if(supported_video_codecs->hevc.supported)
return supported_video_codecs->hevc.max_resolution;
break;
}
}
return {0, 0};
}
@@ -3282,7 +3165,7 @@ static const AVCodec* pick_video_codec(gsr_egl *egl, args_parser *args_parser, b
if(!video_codec_f && use_fallback_codec && args_parser->video_encoder != GSR_VIDEO_ENCODER_HW_CPU) {
switch(args_parser->video_codec) {
case GSR_VIDEO_CODEC_H264: {
fprintf(stderr, "gsr error: selected video codec h264 is not supported\n");
fprintf(stderr, "gsr error: selected video codec h264 is not supported by your hardware\n");
if(args_parser->fallback_cpu_encoding) {
fprintf(stderr, "gsr warning: gpu encoding is not available on your system, trying cpu encoding instead because -fallback-cpu-encoding is enabled. Install the proper vaapi drivers on your system (if supported) if you experience performance issues\n");
force_cpu_encoding(args_parser);
@@ -3292,14 +3175,14 @@ static const AVCodec* pick_video_codec(gsr_egl *egl, args_parser *args_parser, b
case GSR_VIDEO_CODEC_HEVC:
case GSR_VIDEO_CODEC_HEVC_HDR:
case GSR_VIDEO_CODEC_HEVC_10BIT: {
fprintf(stderr, "gsr warning: selected video codec hevc is not supported, trying h264 instead\n");
fprintf(stderr, "gsr warning: selected video codec hevc is not supported by your hardware, trying h264 instead\n");
args_parser->video_codec = GSR_VIDEO_CODEC_H264;
return pick_video_codec(egl, args_parser, true, low_power, supported_video_codecs);
}
case GSR_VIDEO_CODEC_AV1:
case GSR_VIDEO_CODEC_AV1_HDR:
case GSR_VIDEO_CODEC_AV1_10BIT: {
fprintf(stderr, "gsr warning: selected video codec av1 is not supported, trying h264 instead\n");
fprintf(stderr, "gsr warning: selected video codec av1 is not supported by your hardware, trying h264 instead\n");
args_parser->video_codec = GSR_VIDEO_CODEC_H264;
return pick_video_codec(egl, args_parser, true, low_power, supported_video_codecs);
}
@@ -3308,7 +3191,7 @@ static const AVCodec* pick_video_codec(gsr_egl *egl, args_parser *args_parser, b
// TODO: Cant fallback to other codec because webm only supports vp8/vp9
break;
case GSR_VIDEO_CODEC_H264_VULKAN: {
fprintf(stderr, "gsr warning: selected video codec h264_vulkan is not supported, trying h264 instead\n");
fprintf(stderr, "gsr warning: selected video codec h264_vulkan is not supported by your hardware, trying h264 instead\n");
args_parser->video_codec = GSR_VIDEO_CODEC_H264;
// Need to do a query again because this time it's without vulkan
if(!get_supported_video_codecs(egl, args_parser->video_codec, false, true, supported_video_codecs)) {
@@ -3318,8 +3201,10 @@ static const AVCodec* pick_video_codec(gsr_egl *egl, args_parser *args_parser, b
}
return pick_video_codec(egl, args_parser, true, low_power, supported_video_codecs);
}
case GSR_VIDEO_CODEC_HEVC_VULKAN: {
fprintf(stderr, "gsr warning: selected video codec hevc_vulkan is not supported, trying hevc instead\n");
case GSR_VIDEO_CODEC_HEVC_VULKAN:
case GSR_VIDEO_CODEC_HEVC_HDR_VULKAN:
case GSR_VIDEO_CODEC_HEVC_10BIT_VULKAN: {
fprintf(stderr, "gsr warning: selected video codec hevc_vulkan is not supported by your hardware, trying hevc instead\n");
args_parser->video_codec = GSR_VIDEO_CODEC_HEVC;
// Need to do a query again because this time it's without vulkan
if(!get_supported_video_codecs(egl, args_parser->video_codec, false, true, supported_video_codecs)) {
@@ -3329,6 +3214,19 @@ static const AVCodec* pick_video_codec(gsr_egl *egl, args_parser *args_parser, b
}
return pick_video_codec(egl, args_parser, true, low_power, supported_video_codecs);
}
case GSR_VIDEO_CODEC_AV1_VULKAN:
case GSR_VIDEO_CODEC_AV1_HDR_VULKAN:
case GSR_VIDEO_CODEC_AV1_10BIT_VULKAN: {
fprintf(stderr, "gsr warning: selected video codec av1_vulkan is not supported by your hardware, trying av1 instead\n");
args_parser->video_codec = GSR_VIDEO_CODEC_AV1;
// Need to do a query again because this time it's without vulkan
if(!get_supported_video_codecs(egl, args_parser->video_codec, false, true, supported_video_codecs)) {
fprintf(stderr, "gsr error: failed to query for supported video codecs\n");
print_codec_error(args_parser->video_codec);
_exit(11);
}
return pick_video_codec(egl, args_parser, true, low_power, supported_video_codecs);
}
}
video_codec_f = get_av_codec_if_supported(args_parser->video_codec, egl, args_parser->video_encoder == GSR_VIDEO_ENCODER_HW_CPU, supported_video_codecs);
@@ -3365,10 +3263,15 @@ static gsr_video_codec select_appropriate_video_codec_automatically(vec2i video_
}
static const AVCodec* select_video_codec_with_fallback(vec2i video_size, args_parser *args_parser, const char *file_extension, gsr_egl *egl, bool *low_power) {
gsr_supported_video_codecs supported_video_codecs;
get_supported_video_codecs(egl, args_parser->video_codec, args_parser->video_encoder == GSR_VIDEO_ENCODER_HW_CPU, true, &supported_video_codecs);
// TODO: Use gsr_supported_video_codecs *supported_video_codecs_vulkan here to properly query vulkan video support
set_supported_video_codecs_ffmpeg(&supported_video_codecs, nullptr, egl->gpu_info.vendor);
gsr_supported_video_codecs supported_video_codecs_non_vulkan;
get_supported_video_codecs(egl, args_parser->video_codec, args_parser->video_encoder == GSR_VIDEO_ENCODER_HW_CPU, true, &supported_video_codecs_non_vulkan);
gsr_supported_video_codecs supported_video_codecs_vulkan = supported_video_codecs_non_vulkan;
set_supported_video_codecs_ffmpeg(&supported_video_codecs_non_vulkan, &supported_video_codecs_vulkan, egl->gpu_info.vendor);
gsr_supported_video_codecs *supported_video_codecs = video_codec_is_vulkan(args_parser->video_codec)
? &supported_video_codecs_vulkan
: &supported_video_codecs_non_vulkan;
const bool video_codec_auto = args_parser->video_codec == (gsr_video_codec)GSR_VIDEO_CODEC_AUTO;
if(video_codec_auto) {
@@ -3379,7 +3282,7 @@ static const AVCodec* select_video_codec_with_fallback(vec2i video_size, args_pa
fprintf(stderr, "gsr info: using h264 encoder because a codec was not specified\n");
args_parser->video_codec = GSR_VIDEO_CODEC_H264;
} else if(args_parser->video_encoder != GSR_VIDEO_ENCODER_HW_CPU) {
args_parser->video_codec = select_appropriate_video_codec_automatically(video_size, &supported_video_codecs);
args_parser->video_codec = select_appropriate_video_codec_automatically(video_size, &supported_video_codecs_non_vulkan);
if(args_parser->video_codec == (gsr_video_codec)-1) {
if(args_parser->fallback_cpu_encoding) {
fprintf(stderr, "gsr warning: gpu encoding is not available on your system or your gpu doesn't support recording at the resolution you are trying to record, trying cpu encoding instead because -fallback-cpu-encoding is enabled. Install the proper vaapi drivers on your system (if supported) if you experience performance issues\n");
@@ -3405,9 +3308,9 @@ static const AVCodec* select_video_codec_with_fallback(vec2i video_size, args_pa
}
}
const AVCodec *codec = pick_video_codec(egl, args_parser, true, low_power, &supported_video_codecs);
const AVCodec *codec = pick_video_codec(egl, args_parser, true, low_power, supported_video_codecs);
const vec2i codec_max_resolution = codec_get_max_resolution(args_parser->video_codec, args_parser->video_encoder == GSR_VIDEO_ENCODER_HW_CPU, &supported_video_codecs);
const vec2i codec_max_resolution = codec_get_max_resolution(args_parser->video_codec, args_parser->video_encoder == GSR_VIDEO_ENCODER_HW_CPU, supported_video_codecs);
if(!codec_supports_resolution(codec_max_resolution, video_size)) {
const char *video_codec_name = video_codec_to_string(args_parser->video_codec);
fprintf(stderr, "gsr error: The max resolution for video codec %s is %dx%d while you are trying to capture at resolution %dx%d. Change capture resolution or video codec and try again\n",
@@ -3579,7 +3482,7 @@ static void set_display_server_environment_variables() {
const char *wayland_display = getenv("WAYLAND_DISPLAY");
if(!wayland_display) {
wayland_display = "wayland-1";
wayland_display = "wayland-0";
setenv("WAYLAND_DISPLAY", wayland_display, true);
}
}
@@ -3701,6 +3604,7 @@ int main(int argc, char **argv) {
arg_handlers.list_application_audio = list_application_audio_command;
arg_handlers.list_v4l2_devices = list_v4l2_devices;
arg_handlers.list_capture_options = list_capture_options_command;
arg_handlers.list_monitors = list_monitors_command;
args_parser arg_parser;
if(!args_parser_parse(&arg_parser, argc, argv, &arg_handlers, NULL))
@@ -3728,11 +3632,16 @@ int main(int argc, char **argv) {
int driver_major_version = 0;
int driver_minor_version = 0;
if(get_nvidia_driver_version(&driver_major_version, &driver_minor_version) && (driver_major_version > 580 || (driver_major_version == 580 && driver_minor_version >= 105))) {
fprintf(stderr, "gsr info: overclocking was set by has been forcefully disabled since your gpu supports CUDA_DISABLE_PERF_BOOST to workaround driver issue (overclocking is not needed)\n");
fprintf(stderr, "gsr info: overclocking was set but has been forcefully disabled since your gpu supports CUDA_DISABLE_PERF_BOOST to workaround driver issue (overclocking is not needed)\n");
arg_parser.overclock = false;
}
}
if(arg_parser.overclock && video_codec_is_vulkan(arg_parser.video_codec)) {
fprintf(stderr, "gsr info: overclocking was set but has been forcefully disabled since you're using vulkan video encoder which doesn't suffer from cuda p2 power level issues\n");
arg_parser.overclock = false;
}
//av_log_set_level(AV_LOG_TRACE);
const Arg *audio_input_arg = args_parser_get_arg(&arg_parser, "-a");
@@ -4007,7 +3916,11 @@ int main(int argc, char **argv) {
if(video_stream) {
avcodec_parameters_from_context(video_stream->codecpar, video_codec_context);
gsr_encoder_add_recording_destination(&encoder, video_codec_context, av_format_context, video_stream, 0);
const size_t video_destination_id = gsr_encoder_add_recording_destination(&encoder, video_codec_context, av_format_context, video_stream, 0);
if(arg_parser.write_first_frame_ts && video_destination_id != (size_t)-1) {
std::string ts_filepath = std::string(arg_parser.filename) + ".ts";
gsr_encoder_set_recording_destination_first_frame_ts_filepath(&encoder, video_destination_id, ts_filepath.c_str());
}
}
int audio_max_frame_size = 1024;
@@ -4546,6 +4459,11 @@ int main(int argc, char **argv) {
replay_recording_start_result = start_recording_create_streams(replay_recording_filepath.c_str(), arg_parser, video_codec_context, audio_tracks, hdr, video_sources);
if(replay_recording_start_result.av_format_context) {
const size_t video_recording_destination_id = gsr_encoder_add_recording_destination(&encoder, video_codec_context, replay_recording_start_result.av_format_context, replay_recording_start_result.video_stream, video_frame->pts);
if(arg_parser.write_first_frame_ts && video_recording_destination_id != (size_t)-1) {
std::string ts_filepath = replay_recording_filepath + ".ts";
gsr_encoder_set_recording_destination_first_frame_ts_filepath(&encoder, video_recording_destination_id, ts_filepath.c_str());
}
if(video_recording_destination_id != (size_t)-1)
replay_recording_items.push_back(video_recording_destination_id);

View File

@@ -134,7 +134,7 @@ static void on_process_cb(void *user_data) {
}
struct spa_buffer *buffer = pw_buf->buffer;
const bool has_buffer = buffer->datas[0].chunk->size != 0;
const bool has_buffer = buffer->n_datas > 0 && buffer->datas[0].chunk->size != 0;
pthread_mutex_lock(&self->mutex);
@@ -348,6 +348,7 @@ static void on_state_changed_cb(void *user_data, enum pw_stream_state prev_state
} else {
self->paused = false;
}
self->streaming = (new_state == PW_STREAM_STATE_STREAMING);
pthread_mutex_unlock(&self->mutex);
}
@@ -532,31 +533,36 @@ static bool spa_video_format_get_modifiers(gsr_pipewire_video *self, const enum
static void gsr_pipewire_video_init_modifiers(gsr_pipewire_video *self) {
for(size_t i = 0; i < GSR_PIPEWIRE_VIDEO_NUM_VIDEO_FORMATS; i++) {
self->supported_video_formats[i].format = video_formats[i];
int32_t num_modifiers = 0;
spa_video_format_get_modifiers(self, self->supported_video_formats[i].format, self->modifiers + self->num_modifiers, GSR_PIPEWIRE_VIDEO_MAX_MODIFIERS - self->num_modifiers, &num_modifiers);
int32_t num_modifiers_video_format = 0;
spa_video_format_get_modifiers(self, self->supported_video_formats[i].format, self->modifiers + self->num_modifiers, GSR_PIPEWIRE_VIDEO_MAX_MODIFIERS - self->num_modifiers, &num_modifiers_video_format);
self->supported_video_formats[i].modifiers_index = self->num_modifiers;
self->supported_video_formats[i].modifiers_size = num_modifiers;
self->num_modifiers += num_modifiers;
self->supported_video_formats[i].modifiers_size = num_modifiers_video_format;
self->num_modifiers += num_modifiers_video_format;
}
}
static void gsr_pipewire_video_format_remove_modifier(gsr_pipewire_video *self, gsr_video_format *video_format, uint64_t modifier) {
/* Returns the number of modifiers */
static size_t gsr_pipewire_video_format_remove_modifier(gsr_pipewire_video *self, gsr_video_format *video_format, uint64_t modifier) {
for(size_t i = 0; i < video_format->modifiers_size; ++i) {
if(self->modifiers[video_format->modifiers_index + i] != modifier)
continue;
if(self->modifiers[video_format->modifiers_index + i] == modifier) {
for(size_t j = i + 1; j < video_format->modifiers_size; ++j) {
self->modifiers[video_format->modifiers_index + j - 1] = self->modifiers[video_format->modifiers_index + j];
}
for(size_t j = i + 1; j < video_format->modifiers_size; ++j) {
self->modifiers[j - 1] = self->modifiers[j];
--video_format->modifiers_size;
break;
}
--video_format->modifiers_size;
return;
}
return video_format->modifiers_size;
}
static void gsr_pipewire_video_remove_modifier(gsr_pipewire_video *self, uint64_t modifier) {
self->num_modifiers = 0;
for(size_t i = 0; i < GSR_PIPEWIRE_VIDEO_NUM_VIDEO_FORMATS; i++) {
gsr_video_format *video_format = &self->supported_video_formats[i];
gsr_pipewire_video_format_remove_modifier(self, video_format, modifier);
const size_t num_modifiers_video_format = gsr_pipewire_video_format_remove_modifier(self, video_format, modifier);
video_format->modifiers_index = self->num_modifiers;
self->num_modifiers += num_modifiers_video_format;
}
}
@@ -793,7 +799,7 @@ static EGLImage gsr_pipewire_video_create_egl_image_with_fallback(gsr_pipewire_v
self->no_modifiers_fallback = true;
image = gsr_pipewire_video_create_egl_image(self, fds, offsets, pitches, modifiers, false);
} else {
fprintf(stderr, "gsr error: gsr_pipewire_video_create_egl_image_with_fallback: failed to create egl image with modifiers, renegotiating with a different modifier\n");
fprintf(stderr, "gsr error: gsr_pipewire_video_create_egl_image_with_fallback: failed to create egl image with modifier 0x%" PRIx64 ", renegotiating with a different modifier\n", self->format.info.raw.modifier);
self->negotiated = false;
pw_thread_loop_lock(self->thread_loop);
gsr_pipewire_video_remove_modifier(self, self->format.info.raw.modifier);
@@ -853,7 +859,7 @@ bool gsr_pipewire_video_map_texture(gsr_pipewire_video *self, gsr_texture_map te
output->rotation = GSR_MONITOR_ROT_0;
pthread_mutex_lock(&self->mutex);
if(!self->negotiated || self->dmabuf_data[0].fd <= 0) {
if(!self->negotiated || !self->streaming || self->dmabuf_data[0].fd <= 0) {
pthread_mutex_unlock(&self->mutex);
return false;
}

View File

@@ -91,6 +91,7 @@ static unsigned int load_program(gsr_egl *egl, const char *vertex_shader, const
if(!success) {
if(program_id)
egl->glDeleteProgram(program_id);
program_id = 0;
}
if(fragment_shader_id)
egl->glDeleteShader(fragment_shader_id);

View File

@@ -340,11 +340,18 @@ static bool pa_sound_device_handle_reconnect(pa_handle *p, char *device_name, si
return false;
}
if(!(p->stream = pa_stream_new(p->context, p->stream_name, &p->ss, NULL))) {
pa_proplist *proplist = pa_proplist_new();
// This prevents microphone recording indicator from being shown on KDE
pa_proplist_sets(proplist, "node.virtual", "true");
if(!(p->stream = pa_stream_new_with_proplist(p->context, p->stream_name, &p->ss, NULL, proplist))) {
//pa_context_errno(p->context);
pa_proplist_free(proplist);
return false;
}
pa_proplist_free(proplist);
const int r = pa_stream_connect_record(p->stream, device_name, &p->attr,
(pa_stream_flags_t)(PA_STREAM_INTERPOLATE_TIMING|PA_STREAM_ADJUST_LATENCY|PA_STREAM_AUTO_TIMING_UPDATE|PA_STREAM_DONT_MOVE));