mirror of
https://repo.dec05eba.com/gpu-screen-recorder
synced 2026-04-01 17:32:47 +09:00
Compare commits
49 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4ed04830c1 | ||
|
|
755340454d | ||
|
|
2f8212b122 | ||
|
|
23782889be | ||
|
|
fd08cdb9b4 | ||
|
|
6079a0162d | ||
|
|
eff5d619eb | ||
|
|
309c4e5f2e | ||
|
|
0555cfde58 | ||
|
|
ff030ba63f | ||
|
|
0de75e5b7e | ||
|
|
c79fb1e5c9 | ||
|
|
4a4af85b6d | ||
|
|
8f7608e7ee | ||
|
|
f3235ed1bf | ||
|
|
3666bba518 | ||
|
|
5d8d14eeaf | ||
|
|
57caf13d65 | ||
|
|
bdf1950ca2 | ||
|
|
144b481526 | ||
|
|
f4ee71a094 | ||
|
|
2dce92d82f | ||
|
|
933911bdde | ||
|
|
01d0df500c | ||
|
|
95415f7ac7 | ||
|
|
a39dad1c02 | ||
|
|
c1af143406 | ||
|
|
4cebc3f0ee | ||
|
|
f6013d094d | ||
|
|
45daccff84 | ||
|
|
ede1e46503 | ||
|
|
6b37b82f97 | ||
|
|
19add54c0c | ||
|
|
a44e119c43 | ||
|
|
054282bafe | ||
|
|
1e7fe1fec1 | ||
|
|
d2f449bd73 | ||
|
|
91f48ce332 | ||
|
|
f4d061eee7 | ||
|
|
8af761f9bd | ||
|
|
b2f0d13512 | ||
|
|
6cbf660afa | ||
|
|
827751cc55 | ||
|
|
a4b3be3786 | ||
|
|
240ccf569c | ||
|
|
88d356386b | ||
|
|
c4104e18cc | ||
|
|
640e377c90 | ||
|
|
2545db7e50 |
21
README.md
21
README.md
@@ -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.
|
||||
@@ -96,7 +97,7 @@ There is also a gui for the gpu screen recorder called [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.
|
||||
|
||||
22
TODO
22
TODO
@@ -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.
|
||||
@@ -392,4 +388,20 @@ Close pipewire links or maybe there are file descriptor leaks?
|
||||
|
||||
Make multiple capture sources work properly in regards to size. The size of the video should be the region size of each capture source.
|
||||
|
||||
--
|
||||
Support hdr camera capture.
|
||||
|
||||
Return the max resolution of each codec in --info to display an error in the UI before capture starts. Right now its fine since the UI will report bad resolution after capture starts and fails but it doesn't say what the max resolution is.
|
||||
|
||||
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.
|
||||
|
||||
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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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,31 +96,27 @@ 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
|
||||
.BR "screen;x=50;y=50".
|
||||
.br
|
||||
These are the available options for capture sources:
|
||||
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
|
||||
@@ -129,9 +129,9 @@ or
|
||||
|
||||
Set to
|
||||
.B center
|
||||
by default, except for camera (V4L2) when capturing the camera above something else in which case this is set to
|
||||
by default when using one capture source, otherwise it's set to
|
||||
.B start
|
||||
by default
|
||||
by default.
|
||||
.IP \(bu 3
|
||||
.B valign
|
||||
- The vertical alignment, should be either
|
||||
@@ -142,9 +142,9 @@ or
|
||||
|
||||
Set to
|
||||
.B center
|
||||
by default, except for camera (V4L2) when capturing the camera above something else in which case this is set to
|
||||
.B end
|
||||
by default
|
||||
by default when using one capture source, otherwise it's set to
|
||||
.B start
|
||||
by default.
|
||||
.IP \(bu 3
|
||||
.B hflip
|
||||
- If the source should be flipped horizontally, should be either
|
||||
@@ -163,9 +163,13 @@ or
|
||||
Set to
|
||||
.B false
|
||||
by default
|
||||
.RE
|
||||
.PP
|
||||
These are the additional options available for camera (V4L2) sources (optional):
|
||||
.RS
|
||||
.IP \(bu 3
|
||||
.B pixfmt
|
||||
- The pixel format for cameras (V4L2), should be either
|
||||
- The pixel format, should be either
|
||||
.BR "auto",
|
||||
.B yuyv
|
||||
or
|
||||
@@ -173,12 +177,39 @@ or
|
||||
Set to
|
||||
.B auto
|
||||
by default
|
||||
.IP \(bu 3
|
||||
.B camera_fps
|
||||
- The camera fps. Has to match a camera fps returned in
|
||||
.B --info
|
||||
or
|
||||
.B --list-v4l2-devices
|
||||
for the device.
|
||||
|
||||
A value of 0 means to use the best option available.
|
||||
.IP \(bu 3
|
||||
.B camera_width
|
||||
- The camera width in pixels. Has to match a camera width returned in
|
||||
.B --info
|
||||
or
|
||||
.B --list-v4l2-devices
|
||||
for the device.
|
||||
|
||||
A value of 0 means to use the best option available.
|
||||
.IP \(bu 3
|
||||
.B camera_height
|
||||
- The camera height in pixels. Has to match a camera height returned in
|
||||
.B --info
|
||||
or
|
||||
.B --list-v4l2-devices
|
||||
for the device.
|
||||
|
||||
A value of 0 means to use the best option available.
|
||||
.RE
|
||||
.TP
|
||||
.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
|
||||
@@ -252,10 +283,12 @@ Video codec:
|
||||
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.
|
||||
@@ -327,6 +360,28 @@ OpenGL debug output (default: no).
|
||||
.TP
|
||||
.BI \-v " yes|no"
|
||||
Print FPS and damage info (default: yes).
|
||||
.TP
|
||||
.BI \-low-power " yes|no"
|
||||
Run in low power mode. This currently has only an affect on AMD (as it's only an issue on AMD) and allows the GPU to go into a lower power mode when recording (default: no).
|
||||
.br
|
||||
Setting this to
|
||||
.B yes
|
||||
might not always be ideal because of AMD driver issues where after playing a video with VAAPI on the system the video encoding performance
|
||||
also reduces, which affects GPU Screen Recorder.
|
||||
.br
|
||||
It's recommended to also use the option
|
||||
.B -fm content
|
||||
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"
|
||||
@@ -348,6 +403,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
|
||||
@@ -392,7 +450,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
|
||||
@@ -422,7 +480,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
|
||||
@@ -446,15 +504,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
|
||||
@@ -474,16 +532,24 @@ gpu-screen-recorder -w "screen|/dev/video0" -o video.mp4
|
||||
.PP
|
||||
.RE
|
||||
.fi
|
||||
Record screen and camera. The camera is located at the bottom right flipped horizontally:
|
||||
Record screen and camera. The camera is located at the bottom right and flipped horizontally:
|
||||
.PP
|
||||
.nf
|
||||
.RS
|
||||
gpu-screen-recorder -w "monitor:screen|v4l2:/dev/video0;halign=end;valign=end;hflip=true" -o video.mp4
|
||||
gpu-screen-recorder -w "screen|/dev/video0;halign=end;valign=end;hflip=true;width=30%;height=30%" -o video.mp4
|
||||
.PP
|
||||
.RE
|
||||
.fi
|
||||
Record two monitors, side by side (assuming the first monitor has a resolution of 1920x1080)
|
||||
.PP
|
||||
.nf
|
||||
.RS
|
||||
gpu-screen-recorder -w "DP-1|DP-2;x=1920" -o video.mp4
|
||||
.RE
|
||||
.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
|
||||
@@ -540,8 +606,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.
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
typedef struct gsr_egl gsr_egl;
|
||||
|
||||
#define NUM_ARGS 35
|
||||
#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 {
|
||||
@@ -91,11 +92,13 @@ typedef struct {
|
||||
bool verbose;
|
||||
bool gl_debug;
|
||||
bool fallback_cpu_encoding;
|
||||
bool low_power;
|
||||
bool record_cursor;
|
||||
bool date_folders;
|
||||
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;
|
||||
|
||||
@@ -10,21 +10,35 @@ typedef enum {
|
||||
} gsr_capture_v4l2_pixfmt;
|
||||
|
||||
typedef struct {
|
||||
bool yuyv;
|
||||
bool mjpeg;
|
||||
} gsr_capture_v4l2_supported_pixfmts;
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
} gsr_capture_v4l2_resolution;
|
||||
|
||||
typedef struct {
|
||||
uint32_t denominator;
|
||||
uint32_t numerator;
|
||||
} gsr_capture_v4l2_framerate;
|
||||
|
||||
typedef struct {
|
||||
gsr_capture_v4l2_pixfmt pixfmt;
|
||||
gsr_capture_v4l2_resolution resolution;
|
||||
gsr_capture_v4l2_framerate framerate;
|
||||
} gsr_capture_v4l2_supported_setup;
|
||||
|
||||
typedef struct {
|
||||
gsr_egl *egl;
|
||||
vec2i output_resolution;
|
||||
const char *device_path;
|
||||
gsr_capture_v4l2_pixfmt pixfmt;
|
||||
int fps;
|
||||
uint32_t camera_fps; /* Set to 0 if the best option should be chosen */
|
||||
gsr_capture_v4l2_resolution camera_resolution; /* Set to 0, 0 if the best option should be chosen */
|
||||
} gsr_capture_v4l2_params;
|
||||
|
||||
gsr_capture* gsr_capture_v4l2_create(const gsr_capture_v4l2_params *params);
|
||||
|
||||
typedef void (*v4l2_devices_query_callback)(const char *path, gsr_capture_v4l2_supported_pixfmts supported_pixfmts, vec2i size, void *userdata);
|
||||
const char* gsr_capture_v4l2_pixfmt_to_string(gsr_capture_v4l2_pixfmt pixfmt);
|
||||
uint32_t gsr_capture_v4l2_framerate_to_number(gsr_capture_v4l2_framerate framerate);
|
||||
typedef void (*v4l2_devices_query_callback)(const char *path, const gsr_capture_v4l2_supported_setup *supported_setup, void *userdata);
|
||||
void gsr_capture_v4l2_list_devices(v4l2_devices_query_callback callback, void *userdata);
|
||||
|
||||
#endif /* GSR_CAPTURE_V4L2_H */
|
||||
|
||||
@@ -20,12 +20,18 @@ 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 {
|
||||
gsr_replay_buffer *replay_buffer;
|
||||
|
||||
pthread_mutex_t file_write_mutex;
|
||||
bool mutex_created;
|
||||
bool file_write_mutex_created;
|
||||
|
||||
pthread_mutex_t replay_mutex;
|
||||
bool replay_mutex_created;
|
||||
|
||||
gsr_encoder_recording_destination recording_destinations[GSR_MAX_RECORDING_DESTINATIONS];
|
||||
size_t num_recording_destinations;
|
||||
@@ -39,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 */
|
||||
|
||||
@@ -112,6 +112,7 @@ typedef struct {
|
||||
|
||||
bool paused;
|
||||
double paused_start_secs;
|
||||
bool streaming;
|
||||
|
||||
gsr_monitor_rotation rotation;
|
||||
} gsr_pipewire_video;
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
#define GSR_REPLAY_BUFFER_H
|
||||
|
||||
#include "../defs.h"
|
||||
#include <pthread.h>
|
||||
#include <stdbool.h>
|
||||
#include <libavcodec/packet.h>
|
||||
|
||||
@@ -27,17 +26,11 @@ struct gsr_replay_buffer {
|
||||
/* Returns {-1, 0} if not found */
|
||||
gsr_replay_buffer_iterator (*find_keyframe)(gsr_replay_buffer *self, gsr_replay_buffer_iterator start_iterator, int stream_index, bool invert_stream_index);
|
||||
bool (*iterator_next)(gsr_replay_buffer *self, gsr_replay_buffer_iterator *iterator);
|
||||
|
||||
pthread_mutex_t mutex;
|
||||
bool mutex_initialized;
|
||||
gsr_replay_buffer *original_replay_buffer;
|
||||
};
|
||||
|
||||
gsr_replay_buffer* gsr_replay_buffer_create(gsr_replay_storage replay_storage, const char *replay_directory, double replay_buffer_time, size_t replay_buffer_num_packets);
|
||||
void gsr_replay_buffer_destroy(gsr_replay_buffer *self);
|
||||
|
||||
void gsr_replay_buffer_lock(gsr_replay_buffer *self);
|
||||
void gsr_replay_buffer_unlock(gsr_replay_buffer *self);
|
||||
bool gsr_replay_buffer_append(gsr_replay_buffer *self, const AVPacket *av_packet, double timestamp);
|
||||
void gsr_replay_buffer_clear(gsr_replay_buffer *self);
|
||||
AVPacket* gsr_replay_buffer_iterator_get_packet(gsr_replay_buffer *self, gsr_replay_buffer_iterator iterator);
|
||||
|
||||
@@ -16,6 +16,8 @@ typedef struct {
|
||||
int name_len;
|
||||
vec2i pos; /* This is 0, 0 on wayland. Use |drm_monitor_get_display_server_data| to get the position */
|
||||
vec2i size;
|
||||
vec2i logical_pos;
|
||||
vec2i logical_size;
|
||||
uint32_t connector_id; /* Only on x11 and drm */
|
||||
gsr_monitor_rotation rotation; /* Only on x11 and wayland */
|
||||
uint32_t monitor_identifier; /* On x11 this is the crtc id */
|
||||
|
||||
@@ -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");
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
project('gpu-screen-recorder', ['c', 'cpp'], version : '5.11.3', default_options : ['warning_level=2'])
|
||||
project('gpu-screen-recorder', ['c', 'cpp'], version : '5.12.5', default_options : ['warning_level=2'])
|
||||
|
||||
add_project_arguments('-Wshadow', language : ['c', 'cpp'])
|
||||
if get_option('buildtype') == 'debug'
|
||||
@@ -117,6 +117,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')
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
[package]
|
||||
name = "gpu-screen-recorder"
|
||||
type = "executable"
|
||||
version = "5.11.3"
|
||||
version = "5.12.5"
|
||||
platforms = ["posix"]
|
||||
|
||||
[config]
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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©=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©=0&file=stream.m3u8"
|
||||
@@ -9,7 +9,6 @@
|
||||
#include <inttypes.h>
|
||||
#include <limits.h>
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <libgen.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
@@ -197,7 +196,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] [-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);
|
||||
}
|
||||
|
||||
@@ -256,6 +256,8 @@ 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);
|
||||
self->audio_bitrate *= 1000LL;
|
||||
@@ -432,6 +434,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 +501,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 +547,8 @@ 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);
|
||||
|
||||
for(int i = 1; i < argc; i += 2) {
|
||||
|
||||
@@ -34,7 +34,8 @@ typedef struct {
|
||||
vec2i capture_size;
|
||||
MonitorId monitor_id;
|
||||
|
||||
gsr_monitor_rotation monitor_rotation;
|
||||
gsr_monitor_rotation display_server_monitor_rotation;
|
||||
gsr_monitor_rotation final_monitor_rotation;
|
||||
|
||||
unsigned int input_texture_id;
|
||||
unsigned int external_input_texture_id;
|
||||
@@ -137,8 +138,8 @@ static void monitor_callback(const gsr_monitor *monitor, void *userdata) {
|
||||
fprintf(stderr, "gsr warning: reached max connector ids\n");
|
||||
}
|
||||
|
||||
static vec2i rotate_capture_size_if_rotated(gsr_capture_kms *self, vec2i capture_size) {
|
||||
if(self->monitor_rotation == GSR_MONITOR_ROT_90 || self->monitor_rotation == GSR_MONITOR_ROT_270) {
|
||||
static vec2i rotate_capture_size_if_rotated(gsr_capture_kms *self, vec2i capture_size, gsr_monitor_rotation rotation) {
|
||||
if(rotation == GSR_MONITOR_ROT_90 || rotation == GSR_MONITOR_ROT_270) {
|
||||
int tmp_x = capture_size.x;
|
||||
capture_size.x = capture_size.y;
|
||||
capture_size.y = tmp_x;
|
||||
@@ -172,14 +173,14 @@ static int gsr_capture_kms_start(gsr_capture *cap, gsr_capture_metadata *capture
|
||||
|
||||
monitor.name = self->params.display_to_capture;
|
||||
vec2i monitor_position = {0, 0};
|
||||
drm_monitor_get_display_server_data(self->params.egl->window, &monitor, &self->monitor_rotation, &monitor_position);
|
||||
drm_monitor_get_display_server_data(self->params.egl->window, &monitor, &self->display_server_monitor_rotation, &monitor_position);
|
||||
|
||||
self->capture_pos = monitor.pos;
|
||||
/* Monitor size is already rotated on x11 when the monitor is rotated, no need to apply it ourselves */
|
||||
if(self->is_x11)
|
||||
self->capture_size = monitor.size;
|
||||
else
|
||||
self->capture_size = rotate_capture_size_if_rotated(self, monitor.size);
|
||||
self->capture_size = rotate_capture_size_if_rotated(self, monitor.size, self->display_server_monitor_rotation);
|
||||
|
||||
if(self->params.output_resolution.x > 0 && self->params.output_resolution.y > 0) {
|
||||
self->params.output_resolution = scale_keep_aspect_ratio(self->capture_size, self->params.output_resolution);
|
||||
@@ -403,7 +404,7 @@ static void render_drm_cursor(gsr_capture_kms *self, gsr_color_conversion *color
|
||||
const vec2i cursor_size = {cursor_drm_fd->width, cursor_drm_fd->height};
|
||||
|
||||
const gsr_monitor_rotation cursor_plane_rotation = kms_rotation_to_gsr_monitor_rotation(cursor_drm_fd->rotation);
|
||||
const gsr_monitor_rotation rotation = sub_rotations(self->monitor_rotation, cursor_plane_rotation);
|
||||
const gsr_monitor_rotation rotation = sub_rotations(self->display_server_monitor_rotation, cursor_plane_rotation);
|
||||
|
||||
vec2i cursor_pos = {cursor_drm_fd->x, cursor_drm_fd->y};
|
||||
switch(rotation) {
|
||||
@@ -539,14 +540,14 @@ static void gsr_capture_kms_update_connector_ids(gsr_capture_kms *self) {
|
||||
monitor.name = self->params.display_to_capture;
|
||||
vec2i monitor_position = {0, 0};
|
||||
// TODO: This is cached. We need it updated.
|
||||
drm_monitor_get_display_server_data(self->params.egl->window, &monitor, &self->monitor_rotation, &monitor_position);
|
||||
drm_monitor_get_display_server_data(self->params.egl->window, &monitor, &self->display_server_monitor_rotation, &monitor_position);
|
||||
|
||||
self->capture_pos = monitor.pos;
|
||||
/* Monitor size is already rotated on x11 when the monitor is rotated, no need to apply it ourselves */
|
||||
if(self->is_x11)
|
||||
self->capture_size = monitor.size;
|
||||
else
|
||||
self->capture_size = rotate_capture_size_if_rotated(self, monitor.size);
|
||||
self->capture_size = rotate_capture_size_if_rotated(self, monitor.size, self->display_server_monitor_rotation);
|
||||
}
|
||||
|
||||
static void gsr_capture_kms_pre_capture(gsr_capture *cap, gsr_capture_metadata *capture_metadata, gsr_color_conversion *color_conversion) {
|
||||
@@ -571,7 +572,10 @@ static void gsr_capture_kms_pre_capture(gsr_capture *cap, gsr_capture_metadata *
|
||||
if(self->drm_fd->has_hdr_metadata && self->params.hdr && hdr_metadata_is_supported_format(&self->drm_fd->hdr_metadata))
|
||||
gsr_kms_set_hdr_metadata(self, self->drm_fd);
|
||||
|
||||
self->capture_size = rotate_capture_size_if_rotated(self, (vec2i){ self->drm_fd->src_w, self->drm_fd->src_h });
|
||||
const gsr_monitor_rotation plane_rotation = kms_rotation_to_gsr_monitor_rotation(self->drm_fd->rotation);
|
||||
self->final_monitor_rotation = self->capture_is_combined_plane ? GSR_MONITOR_ROT_0 : sub_rotations(self->display_server_monitor_rotation, plane_rotation);
|
||||
|
||||
self->capture_size = rotate_capture_size_if_rotated(self, (vec2i){ self->drm_fd->src_w, self->drm_fd->src_h }, self->final_monitor_rotation);
|
||||
if(self->params.region_size.x > 0 && self->params.region_size.y > 0)
|
||||
self->capture_size = self->params.region_size;
|
||||
|
||||
@@ -603,13 +607,10 @@ static int gsr_capture_kms_capture(gsr_capture *cap, gsr_capture_metadata *captu
|
||||
self->params.egl->eglDestroyImage(self->params.egl->egl_display, image);
|
||||
}
|
||||
|
||||
const gsr_monitor_rotation plane_rotation = kms_rotation_to_gsr_monitor_rotation(self->drm_fd->rotation);
|
||||
const gsr_monitor_rotation rotation = self->capture_is_combined_plane ? GSR_MONITOR_ROT_0 : sub_rotations(self->monitor_rotation, plane_rotation);
|
||||
|
||||
gsr_color_conversion_draw(color_conversion, self->external_texture_fallback ? self->external_input_texture_id : self->input_texture_id,
|
||||
self->target_pos, self->output_size,
|
||||
capture_pos, self->capture_size, (vec2i){ self->drm_fd->width, self->drm_fd->height },
|
||||
gsr_monitor_rotation_to_rotation(rotation), capture_metadata->flip, GSR_SOURCE_COLOR_RGB, self->external_texture_fallback);
|
||||
gsr_monitor_rotation_to_rotation(self->final_monitor_rotation), capture_metadata->flip, GSR_SOURCE_COLOR_RGB, self->external_texture_fallback);
|
||||
|
||||
if(self->params.record_cursor) {
|
||||
gsr_kms_response_item *cursor_drm_fd = find_cursor_drm_if_on_monitor(self, self->drm_fd->connector_id, self->capture_is_combined_plane);
|
||||
@@ -623,7 +624,7 @@ static int gsr_capture_kms_capture(gsr_capture *cap, gsr_capture_metadata *captu
|
||||
cursor_monitor_offset.y += self->params.region_position.y;
|
||||
render_x11_cursor(self, color_conversion, capture_metadata, cursor_monitor_offset, self->target_pos, self->output_size);
|
||||
} else if(cursor_drm_fd) {
|
||||
const vec2i framebuffer_size = rotate_capture_size_if_rotated(self, (vec2i){ self->drm_fd->src_w, self->drm_fd->src_h });
|
||||
const vec2i framebuffer_size = rotate_capture_size_if_rotated(self, (vec2i){ self->drm_fd->src_w, self->drm_fd->src_h }, self->final_monitor_rotation);
|
||||
render_drm_cursor(self, color_conversion, capture_metadata, cursor_drm_fd, self->target_pos, self->output_size, framebuffer_size);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,6 +43,11 @@ typedef enum {
|
||||
V4L2_BUFFER_TYPE_MMAP
|
||||
} v4l2_buffer_type;
|
||||
|
||||
typedef struct {
|
||||
bool yuyv;
|
||||
bool mjpeg;
|
||||
} gsr_capture_v4l2_supported_pixfmts;
|
||||
|
||||
typedef struct {
|
||||
gsr_capture_v4l2_params params;
|
||||
vec2i capture_size;
|
||||
@@ -157,7 +162,35 @@ static void gsr_capture_v4l2_reset_cropping(gsr_capture_v4l2 *self) {
|
||||
}
|
||||
}
|
||||
|
||||
gsr_capture_v4l2_supported_pixfmts gsr_capture_v4l2_get_supported_pixfmts(int fd) {
|
||||
static uint32_t gsr_pixfmt_to_v4l2_pixfmt(gsr_capture_v4l2_pixfmt pixfmt) {
|
||||
switch(pixfmt) {
|
||||
case GSR_CAPTURE_V4L2_PIXFMT_AUTO:
|
||||
assert(false);
|
||||
break;
|
||||
case GSR_CAPTURE_V4L2_PIXFMT_YUYV:
|
||||
return V4L2_PIX_FMT_YUYV;
|
||||
case GSR_CAPTURE_V4L2_PIXFMT_MJPEG:
|
||||
return V4L2_PIX_FMT_MJPEG;
|
||||
}
|
||||
assert(false);
|
||||
return V4L2_PIX_FMT_YUYV;
|
||||
}
|
||||
|
||||
const char* gsr_capture_v4l2_pixfmt_to_string(gsr_capture_v4l2_pixfmt pixfmt) {
|
||||
switch(pixfmt) {
|
||||
case GSR_CAPTURE_V4L2_PIXFMT_AUTO:
|
||||
assert(false);
|
||||
break;
|
||||
case GSR_CAPTURE_V4L2_PIXFMT_YUYV:
|
||||
return "yuyv";
|
||||
case GSR_CAPTURE_V4L2_PIXFMT_MJPEG:
|
||||
return "mjpeg";
|
||||
}
|
||||
assert(false);
|
||||
return "";
|
||||
}
|
||||
|
||||
static gsr_capture_v4l2_supported_pixfmts gsr_capture_v4l2_get_supported_pixfmts(int fd) {
|
||||
gsr_capture_v4l2_supported_pixfmts result = {0};
|
||||
|
||||
struct v4l2_fmtdesc fmt = {
|
||||
@@ -179,28 +212,189 @@ gsr_capture_v4l2_supported_pixfmts gsr_capture_v4l2_get_supported_pixfmts(int fd
|
||||
return result;
|
||||
}
|
||||
|
||||
static uint32_t gsr_pixfmt_to_v4l2_pixfmt(gsr_capture_v4l2_pixfmt pixfmt) {
|
||||
switch(pixfmt) {
|
||||
case GSR_CAPTURE_V4L2_PIXFMT_AUTO:
|
||||
assert(false);
|
||||
break;
|
||||
case GSR_CAPTURE_V4L2_PIXFMT_YUYV:
|
||||
return V4L2_PIX_FMT_YUYV;
|
||||
case GSR_CAPTURE_V4L2_PIXFMT_MJPEG:
|
||||
return V4L2_PIX_FMT_MJPEG;
|
||||
/* Returns the number of resolutions added */
|
||||
static size_t gsr_capture_v4l2_get_supported_resolutions(int fd, gsr_capture_v4l2_pixfmt pixfmt, gsr_capture_v4l2_resolution *resolutions, size_t max_resolutions) {
|
||||
size_t resolution_index = 0;
|
||||
struct v4l2_frmsizeenum fmt = {
|
||||
.type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
|
||||
.pixel_format = gsr_pixfmt_to_v4l2_pixfmt(pixfmt),
|
||||
};
|
||||
|
||||
while(xioctl(fd, VIDIOC_ENUM_FRAMESIZES, &fmt) == 0) {
|
||||
if(fmt.type == V4L2_FRMSIZE_TYPE_DISCRETE && resolution_index < max_resolutions) {
|
||||
resolutions[resolution_index] = (gsr_capture_v4l2_resolution){
|
||||
.width = fmt.discrete.width,
|
||||
.height = fmt.discrete.height,
|
||||
};
|
||||
++resolution_index;
|
||||
}
|
||||
++fmt.index;
|
||||
}
|
||||
assert(false);
|
||||
return V4L2_PIX_FMT_YUYV;
|
||||
|
||||
return resolution_index;
|
||||
}
|
||||
|
||||
static bool gsr_capture_v4l2_validate_pixfmt(gsr_capture_v4l2 *self, const gsr_capture_v4l2_supported_pixfmts supported_pixfmts) {
|
||||
/* Returns the number of framerates added */
|
||||
static size_t gsr_capture_v4l2_get_supported_framerates(int fd, gsr_capture_v4l2_pixfmt pixfmt, gsr_capture_v4l2_resolution resolution, gsr_capture_v4l2_framerate *framerates, size_t max_framerates) {
|
||||
size_t framerate_index = 0;
|
||||
struct v4l2_frmivalenum fmt = {
|
||||
.type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
|
||||
.pixel_format = gsr_pixfmt_to_v4l2_pixfmt(pixfmt),
|
||||
.width = resolution.width,
|
||||
.height = resolution.height,
|
||||
};
|
||||
|
||||
while(xioctl(fd, VIDIOC_ENUM_FRAMEINTERVALS, &fmt) == 0) {
|
||||
if(fmt.type == V4L2_FRMIVAL_TYPE_DISCRETE && fmt.discrete.denominator > 0 && fmt.discrete.numerator > 0 && framerate_index < max_framerates) {
|
||||
framerates[framerate_index] = (gsr_capture_v4l2_framerate){
|
||||
.denominator = fmt.discrete.denominator,
|
||||
.numerator = fmt.discrete.numerator,
|
||||
};
|
||||
++framerate_index;
|
||||
}
|
||||
++fmt.index;
|
||||
}
|
||||
|
||||
return framerate_index;
|
||||
}
|
||||
|
||||
/* Returns the number of setups added */
|
||||
static size_t gsr_capture_v4l2_get_supported_setups(int fd, gsr_capture_v4l2_supported_setup *supported_setups, size_t max_supported_setups, bool has_libturbojpeg_lib) {
|
||||
const gsr_capture_v4l2_supported_pixfmts supported_pixfmts = gsr_capture_v4l2_get_supported_pixfmts(fd);
|
||||
|
||||
size_t num_pixfmts = 0;
|
||||
gsr_capture_v4l2_pixfmt pixfmts[2];
|
||||
|
||||
if(supported_pixfmts.yuyv)
|
||||
pixfmts[num_pixfmts++] = GSR_CAPTURE_V4L2_PIXFMT_YUYV;
|
||||
|
||||
if(supported_pixfmts.mjpeg && has_libturbojpeg_lib)
|
||||
pixfmts[num_pixfmts++] = GSR_CAPTURE_V4L2_PIXFMT_MJPEG;
|
||||
|
||||
gsr_capture_v4l2_resolution resolutions[32];
|
||||
gsr_capture_v4l2_framerate framerates[32];
|
||||
size_t supported_setup_index = 0;
|
||||
|
||||
for(size_t pixfmt_index = 0; pixfmt_index < num_pixfmts; ++pixfmt_index) {
|
||||
const gsr_capture_v4l2_pixfmt pixfmt = pixfmts[pixfmt_index];
|
||||
const size_t num_resolutions = gsr_capture_v4l2_get_supported_resolutions(fd, pixfmt, resolutions, 32);
|
||||
|
||||
for(size_t resolution_index = 0; resolution_index < num_resolutions; ++resolution_index) {
|
||||
const gsr_capture_v4l2_resolution resolution = resolutions[resolution_index];
|
||||
const size_t num_framerates = gsr_capture_v4l2_get_supported_framerates(fd, pixfmt, resolution, framerates, 32);
|
||||
|
||||
for(size_t framerate_index = 0; framerate_index < num_framerates; ++framerate_index) {
|
||||
const gsr_capture_v4l2_framerate framerate = framerates[framerate_index];
|
||||
|
||||
if(supported_setup_index < max_supported_setups) {
|
||||
supported_setups[supported_setup_index] = (gsr_capture_v4l2_supported_setup){
|
||||
.pixfmt = pixfmt,
|
||||
.resolution = resolution,
|
||||
.framerate = framerate,
|
||||
};
|
||||
++supported_setup_index;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return supported_setup_index;
|
||||
}
|
||||
|
||||
uint32_t gsr_capture_v4l2_framerate_to_number(gsr_capture_v4l2_framerate framerate) {
|
||||
return (uint32_t)((double)framerate.denominator / (double)framerate.numerator);
|
||||
}
|
||||
|
||||
static bool gsr_capture_v4l2_get_best_matching_setup(
|
||||
const gsr_capture_v4l2_supported_setup *supported_setups,
|
||||
size_t num_supported_setups,
|
||||
gsr_capture_v4l2_pixfmt pixfmt,
|
||||
uint32_t camera_fps,
|
||||
gsr_capture_v4l2_resolution camera_resolution,
|
||||
gsr_capture_v4l2_supported_setup *best_supported_setup)
|
||||
{
|
||||
memset(best_supported_setup, 0, sizeof(*best_supported_setup));
|
||||
|
||||
int best_match_index = -1;
|
||||
uint64_t best_match_score = 0;
|
||||
|
||||
for(size_t i = 0; i < num_supported_setups; ++i) {
|
||||
const gsr_capture_v4l2_supported_setup *setup = &supported_setups[i];
|
||||
if(pixfmt != GSR_CAPTURE_V4L2_PIXFMT_AUTO && pixfmt != setup->pixfmt)
|
||||
continue;
|
||||
|
||||
uint64_t setup_resolution_width = (uint64_t)setup->resolution.width;
|
||||
uint64_t setup_resolution_height = (uint64_t)setup->resolution.height;
|
||||
uint64_t setup_framerate = gsr_capture_v4l2_framerate_to_number(setup->framerate);
|
||||
|
||||
if(setup_resolution_width == camera_resolution.width && setup_resolution_height == camera_resolution.height) {
|
||||
setup_resolution_width = 50000;
|
||||
setup_resolution_height = 50000;
|
||||
}
|
||||
|
||||
if(setup_framerate == camera_fps) {
|
||||
setup_framerate = 50000;
|
||||
}
|
||||
|
||||
const uint64_t match_score = setup_resolution_width * setup_resolution_height * setup_framerate + (pixfmt == GSR_CAPTURE_V4L2_PIXFMT_YUYV ? 5 : 0);
|
||||
if(match_score > best_match_score) {
|
||||
best_match_score = match_score;
|
||||
best_match_index = i;
|
||||
}
|
||||
|
||||
//fprintf(stderr, "supported setup[%d]: pixfmt: %d, size: %ux%u, fps: %u/%u\n", (int)i, setup->pixfmt, setup->resolution.width, setup->resolution.height, setup->framerate.denominator, setup->framerate.numerator);
|
||||
}
|
||||
|
||||
if(best_match_index == -1)
|
||||
return false;
|
||||
|
||||
//fprintf(stderr, "best match index: %d\n", best_match_index);
|
||||
*best_supported_setup = supported_setups[best_match_index];
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Seems like some cameras need this? */
|
||||
static void gsr_capture_v4l2_update_params(int fd) {
|
||||
struct v4l2_streamparm streamparm = {
|
||||
.type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
|
||||
};
|
||||
if(xioctl(fd, VIDIOC_G_PARM, &streamparm) == -1) {
|
||||
fprintf(stderr, "gsr error: gsr_capture_v4l2_set_framerate: VIDIOC_G_PARM failed, error: %s\n", strerror(errno));
|
||||
return;
|
||||
}
|
||||
|
||||
if(xioctl(fd, VIDIOC_S_PARM, &streamparm) == -1) {
|
||||
fprintf(stderr, "gsr error: gsr_capture_v4l2_set_framerate: VIDIOC_S_PARM failed, error: %s\n", strerror(errno));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
static void gsr_capture_v4l2_set_framerate(int fd, gsr_capture_v4l2_framerate framerate) {
|
||||
struct v4l2_streamparm streamparm = {
|
||||
.type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
|
||||
};
|
||||
if(xioctl(fd, VIDIOC_G_PARM, &streamparm) == -1) {
|
||||
fprintf(stderr, "gsr error: gsr_capture_v4l2_set_framerate: VIDIOC_G_PARM failed, error: %s\n", strerror(errno));
|
||||
return;
|
||||
}
|
||||
|
||||
streamparm.parm.capture.timeperframe.denominator = framerate.denominator;
|
||||
streamparm.parm.capture.timeperframe.numerator = framerate.numerator;
|
||||
if(xioctl(fd, VIDIOC_S_PARM, &streamparm) == -1) {
|
||||
fprintf(stderr, "gsr error: gsr_capture_v4l2_set_framerate: VIDIOC_S_PARM failed, error: %s\n", strerror(errno));
|
||||
return;
|
||||
}
|
||||
|
||||
if(streamparm.parm.capture.timeperframe.denominator == 0 || streamparm.parm.capture.timeperframe.numerator == 0) {
|
||||
fprintf(stderr, "gsr error: gsr_capture_v4l2_set_framerate: VIDIOC_S_PARM failed, error: invalid framerate: %u/%u\n", framerate.denominator, framerate.numerator);;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
static bool gsr_capture_v4l2_validate_pixfmt(const gsr_capture_v4l2 *self, const gsr_capture_v4l2_supported_pixfmts supported_pixfmts) {
|
||||
switch(self->params.pixfmt) {
|
||||
case GSR_CAPTURE_V4L2_PIXFMT_AUTO: {
|
||||
if(supported_pixfmts.yuyv) {
|
||||
self->params.pixfmt = GSR_CAPTURE_V4L2_PIXFMT_YUYV;
|
||||
} else if(supported_pixfmts.mjpeg) {
|
||||
self->params.pixfmt = GSR_CAPTURE_V4L2_PIXFMT_MJPEG;
|
||||
} else {
|
||||
if(!supported_pixfmts.yuyv && !supported_pixfmts.mjpeg) {
|
||||
fprintf(stderr, "gsr error: gsr_capture_v4l2_create: %s doesn't support yuyv nor mjpeg. GPU Screen Recorder supports only yuyv and mjpeg at the moment. Report this as an issue, see: https://git.dec05eba.com/?p=about\n", self->params.device_path);
|
||||
return false;
|
||||
}
|
||||
@@ -208,14 +402,14 @@ static bool gsr_capture_v4l2_validate_pixfmt(gsr_capture_v4l2 *self, const gsr_c
|
||||
}
|
||||
case GSR_CAPTURE_V4L2_PIXFMT_YUYV: {
|
||||
if(!supported_pixfmts.yuyv) {
|
||||
fprintf(stderr, "gsr error: gsr_capture_v4l2_create: %s doesn't support yuyv. Try recording with -pixfmt mjpeg or -pixfmt auto instead\n", self->params.device_path);
|
||||
fprintf(stderr, "gsr error: gsr_capture_v4l2_create: %s doesn't support yuyv. Try recording with pixfmt=mjpeg or pixfmt=auto instead\n", self->params.device_path);
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case GSR_CAPTURE_V4L2_PIXFMT_MJPEG: {
|
||||
if(!supported_pixfmts.mjpeg) {
|
||||
fprintf(stderr, "gsr error: gsr_capture_v4l2_create: %s doesn't support mjpeg. Try recording with -pixfmt yuyv or -pixfmt auto instead\n", self->params.device_path);
|
||||
fprintf(stderr, "gsr error: gsr_capture_v4l2_create: %s doesn't support mjpeg. Try recording with pixfmt=yuyv or pixfmt=auto instead\n", self->params.device_path);
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
@@ -264,6 +458,7 @@ static bool gsr_capture_v4l2_map_buffer(gsr_capture_v4l2 *self, const struct v4l
|
||||
|
||||
if(!self->dma_image[i]) {
|
||||
self->yuyv_conversion_fallback = true;
|
||||
// This doesn't work for everybody on nvidia. On pop os 24.04 when egl_display is NULL (when capturing monitor on x11) then this fails with EGL_BAD_DISPLAY
|
||||
self->dma_image[i] = self->params.egl->eglCreateImage(self->params.egl->egl_display, 0, EGL_LINUX_DMA_BUF_EXT, NULL, (intptr_t[]) {
|
||||
EGL_WIDTH, fmt->fmt.pix.width,
|
||||
EGL_HEIGHT, fmt->fmt.pix.height,
|
||||
@@ -321,6 +516,14 @@ static bool gsr_capture_v4l2_map_buffer(gsr_capture_v4l2 *self, const struct v4l
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool is_libturbojpeg_library_available(void) {
|
||||
void *libturbojpeg_lib = dlopen("libturbojpeg.so.0", RTLD_LAZY);
|
||||
const bool has_libturbojpeg_lib = libturbojpeg_lib != NULL;
|
||||
if(libturbojpeg_lib)
|
||||
dlclose(libturbojpeg_lib);
|
||||
return has_libturbojpeg_lib;
|
||||
}
|
||||
|
||||
static int gsr_capture_v4l2_setup(gsr_capture_v4l2 *self) {
|
||||
self->fd = open(self->params.device_path, O_RDWR | O_NONBLOCK);
|
||||
if(self->fd < 0) {
|
||||
@@ -351,10 +554,35 @@ static int gsr_capture_v4l2_setup(gsr_capture_v4l2 *self) {
|
||||
|
||||
gsr_capture_v4l2_reset_cropping(self);
|
||||
|
||||
const bool has_libturbojpeg_lib = is_libturbojpeg_library_available();
|
||||
if(!has_libturbojpeg_lib && self->params.pixfmt == GSR_CAPTURE_V4L2_PIXFMT_AUTO) {
|
||||
fprintf(stderr, "gsr warning: gsr_capture_v4l2_create: libturbojpeg.so.0 isn't available on the system, yuyv camera capture will be used\n");
|
||||
self->params.pixfmt = GSR_CAPTURE_V4L2_PIXFMT_YUYV;
|
||||
}
|
||||
|
||||
const gsr_capture_v4l2_supported_pixfmts supported_pixfmts = gsr_capture_v4l2_get_supported_pixfmts(self->fd);
|
||||
if(!gsr_capture_v4l2_validate_pixfmt(self, supported_pixfmts))
|
||||
return -1;
|
||||
|
||||
gsr_capture_v4l2_supported_setup supported_setups[128];
|
||||
const size_t num_supported_setups = gsr_capture_v4l2_get_supported_setups(self->fd, supported_setups, 128, has_libturbojpeg_lib);
|
||||
|
||||
gsr_capture_v4l2_supported_setup best_supported_setup = {0};
|
||||
if(!gsr_capture_v4l2_get_best_matching_setup(supported_setups, num_supported_setups, self->params.pixfmt, self->params.camera_fps, self->params.camera_resolution, &best_supported_setup)) {
|
||||
fprintf(stderr, "gsr error: gsr_capture_v4l2_create: %s doesn't report any frame resolutions and framerates\n", self->params.device_path);
|
||||
return -1;
|
||||
}
|
||||
|
||||
fprintf(stderr, "gsr info: gsr_capture_v4l2_create: capturing %s at %ux%u@%dhz, pixfmt: %s\n",
|
||||
self->params.device_path,
|
||||
best_supported_setup.resolution.width,
|
||||
best_supported_setup.resolution.height,
|
||||
gsr_capture_v4l2_framerate_to_number(best_supported_setup.framerate),
|
||||
gsr_capture_v4l2_pixfmt_to_string(best_supported_setup.pixfmt));
|
||||
|
||||
gsr_capture_v4l2_update_params(self->fd);
|
||||
self->params.pixfmt = best_supported_setup.pixfmt;
|
||||
|
||||
if(self->params.pixfmt == GSR_CAPTURE_V4L2_PIXFMT_MJPEG) {
|
||||
dlerror(); /* clear */
|
||||
self->libturbojpeg_lib = dlopen("libturbojpeg.so.0", RTLD_LAZY);
|
||||
@@ -384,7 +612,9 @@ static int gsr_capture_v4l2_setup(gsr_capture_v4l2 *self) {
|
||||
const uint32_t v4l2_pixfmt = gsr_pixfmt_to_v4l2_pixfmt(self->params.pixfmt);
|
||||
struct v4l2_format fmt = {
|
||||
.type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
|
||||
.fmt.pix.pixelformat = v4l2_pixfmt
|
||||
.fmt.pix.pixelformat = v4l2_pixfmt,
|
||||
.fmt.pix.width = best_supported_setup.resolution.width,
|
||||
.fmt.pix.height = best_supported_setup.resolution.height,
|
||||
};
|
||||
if(xioctl(self->fd, VIDIOC_S_FMT, &fmt) == -1) {
|
||||
fprintf(stderr, "gsr error: gsr_capture_v4l2_create: VIDIOC_S_FMT failed, error: %s\n", strerror(errno));
|
||||
@@ -399,6 +629,8 @@ static int gsr_capture_v4l2_setup(gsr_capture_v4l2 *self) {
|
||||
self->capture_size.x = fmt.fmt.pix.width;
|
||||
self->capture_size.y = fmt.fmt.pix.height;
|
||||
|
||||
gsr_capture_v4l2_set_framerate(self->fd, best_supported_setup.framerate);
|
||||
|
||||
struct v4l2_requestbuffers reqbuf = {
|
||||
.type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
|
||||
.memory = V4L2_MEMORY_MMAP,
|
||||
@@ -645,12 +877,10 @@ gsr_capture* gsr_capture_v4l2_create(const gsr_capture_v4l2_params *params) {
|
||||
}
|
||||
|
||||
void gsr_capture_v4l2_list_devices(v4l2_devices_query_callback callback, void *userdata) {
|
||||
void *libturbojpeg_lib = dlopen("libturbojpeg.so.0", RTLD_LAZY);
|
||||
const bool has_libturbojpeg_lib = libturbojpeg_lib != NULL;
|
||||
if(libturbojpeg_lib)
|
||||
dlclose(libturbojpeg_lib);
|
||||
|
||||
const bool has_libturbojpeg_lib = is_libturbojpeg_library_available();
|
||||
char v4l2_device_path[128];
|
||||
gsr_capture_v4l2_supported_setup supported_setups[128];
|
||||
|
||||
for(int i = 0; i < 8; ++i) {
|
||||
snprintf(v4l2_device_path, sizeof(v4l2_device_path), "/dev/video%d", i);
|
||||
|
||||
@@ -674,12 +904,14 @@ void gsr_capture_v4l2_list_devices(v4l2_devices_query_callback callback, void *u
|
||||
if(xioctl(fd, VIDIOC_G_FMT, &fmt) == -1)
|
||||
goto next;
|
||||
|
||||
gsr_capture_v4l2_supported_pixfmts supported_pixfmts = gsr_capture_v4l2_get_supported_pixfmts(fd);
|
||||
if(!has_libturbojpeg_lib)
|
||||
supported_pixfmts.mjpeg = false;
|
||||
const size_t num_supported_setups = gsr_capture_v4l2_get_supported_setups(fd, supported_setups, 128, has_libturbojpeg_lib);
|
||||
if(num_supported_setups == 0)
|
||||
continue;
|
||||
|
||||
if(supported_pixfmts.yuyv || supported_pixfmts.mjpeg)
|
||||
callback(v4l2_device_path, supported_pixfmts, (vec2i){ fmt.fmt.pix.width, fmt.fmt.pix.height }, userdata);
|
||||
for(size_t j = 0; j < num_supported_setups; ++j) {
|
||||
const gsr_capture_v4l2_supported_setup *setup = &supported_setups[j];
|
||||
callback(v4l2_device_path, setup, userdata);
|
||||
}
|
||||
|
||||
next:
|
||||
close(fd);
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
16
src/dbus.c
16
src/dbus.c
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
@@ -14,9 +41,17 @@ bool gsr_encoder_init(gsr_encoder *self, gsr_replay_storage replay_storage, size
|
||||
|
||||
if(pthread_mutex_init(&self->file_write_mutex, NULL) != 0) {
|
||||
fprintf(stderr, "gsr error: gsr_encoder_init: failed to create mutex\n");
|
||||
gsr_encoder_deinit(self);
|
||||
return false;
|
||||
}
|
||||
self->mutex_created = true;
|
||||
self->file_write_mutex_created = true;
|
||||
|
||||
if(pthread_mutex_init(&self->replay_mutex, NULL) != 0) {
|
||||
fprintf(stderr, "gsr error: gsr_encoder_init: failed to create mutex\n");
|
||||
gsr_encoder_deinit(self);
|
||||
return false;
|
||||
}
|
||||
self->replay_mutex_created = true;
|
||||
|
||||
if(replay_buffer_num_packets > 0) {
|
||||
self->replay_buffer = gsr_replay_buffer_create(replay_storage, replay_directory, replay_buffer_time, replay_buffer_num_packets);
|
||||
@@ -31,14 +66,31 @@ bool gsr_encoder_init(gsr_encoder *self, gsr_replay_storage replay_storage, size
|
||||
}
|
||||
|
||||
void gsr_encoder_deinit(gsr_encoder *self) {
|
||||
if(self->mutex_created) {
|
||||
self->mutex_created = false;
|
||||
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);
|
||||
self->replay_buffer = NULL;
|
||||
pthread_mutex_unlock(&self->replay_mutex);
|
||||
}
|
||||
|
||||
if(self->file_write_mutex_created) {
|
||||
self->file_write_mutex_created = false;
|
||||
pthread_mutex_destroy(&self->file_write_mutex);
|
||||
}
|
||||
|
||||
if(self->replay_buffer) {
|
||||
gsr_replay_buffer_destroy(self->replay_buffer);
|
||||
self->replay_buffer = NULL;
|
||||
if(self->replay_mutex_created) {
|
||||
self->replay_mutex_created = false;
|
||||
pthread_mutex_destroy(&self->replay_mutex);
|
||||
}
|
||||
|
||||
self->num_recording_destinations = 0;
|
||||
@@ -60,9 +112,11 @@ void gsr_encoder_receive_packets(gsr_encoder *self, AVCodecContext *codec_contex
|
||||
av_packet->dts = pts;
|
||||
|
||||
if(self->replay_buffer) {
|
||||
pthread_mutex_lock(&self->replay_mutex);
|
||||
const double time_now = clock_get_monotonic_seconds();
|
||||
if(!gsr_replay_buffer_append(self->replay_buffer, av_packet, time_now))
|
||||
fprintf(stderr, "gsr error: gsr_encoder_receive_packets: failed to add replay buffer data\n");
|
||||
pthread_mutex_unlock(&self->replay_mutex);
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&self->file_write_mutex);
|
||||
@@ -77,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;
|
||||
|
||||
@@ -131,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;
|
||||
@@ -144,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;
|
||||
@@ -153,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;
|
||||
}
|
||||
|
||||
@@ -245,8 +245,8 @@ static bool gsr_video_encoder_vaapi_start(gsr_video_encoder *encoder, AVCodecCon
|
||||
video_codec_context->width = FFALIGN(video_codec_context->width, 2);
|
||||
video_codec_context->height = FFALIGN(video_codec_context->height, 2);
|
||||
} else {
|
||||
video_codec_context->width = FFALIGN(video_codec_context->width, 256);
|
||||
video_codec_context->height = FFALIGN(video_codec_context->height, 256);
|
||||
video_codec_context->width = FFALIGN(video_codec_context->width, 64);
|
||||
video_codec_context->height = FFALIGN(video_codec_context->height, 16);
|
||||
}
|
||||
} else if(self->params.egl->gpu_info.vendor == GSR_GPU_VENDOR_AMD && video_codec_context->codec_id == AV_CODEC_ID_AV1) {
|
||||
// TODO: Dont do this for VCN 5 and forward which should fix this hardware bug
|
||||
|
||||
388
src/main.cpp
388
src/main.cpp
@@ -110,26 +110,23 @@ typedef struct {
|
||||
char *output_name;
|
||||
vec2i monitor_pos;
|
||||
vec2i monitor_size;
|
||||
double monitor_scale_inverted;
|
||||
} MonitorByPositionCallback;
|
||||
|
||||
static void get_monitor_by_position_callback(const gsr_monitor *monitor, void *userdata) {
|
||||
MonitorByPositionCallback *data = (MonitorByPositionCallback*)userdata;
|
||||
|
||||
vec2i monitor_position = monitor->pos;
|
||||
vec2i monitor_size = monitor->size;
|
||||
if(gsr_window_get_display_server(data->window) == GSR_DISPLAY_SERVER_WAYLAND) {
|
||||
gsr_monitor_rotation monitor_rotation = GSR_MONITOR_ROT_0;
|
||||
drm_monitor_get_display_server_data(data->window, monitor, &monitor_rotation, &monitor_position);
|
||||
if(monitor_rotation == GSR_MONITOR_ROT_90 || monitor_rotation == GSR_MONITOR_ROT_270)
|
||||
std::swap(monitor_size.x, monitor_size.y);
|
||||
}
|
||||
const vec2i monitor_position = monitor->logical_pos;
|
||||
const vec2i monitor_size = monitor->size;
|
||||
const vec2i monitor_logical_size = monitor->logical_size;
|
||||
|
||||
if(!data->output_name && data->position.x >= monitor_position.x && data->position.x <= monitor_position.x + monitor_size.x
|
||||
&& data->position.y >= monitor_position.y && data->position.y <= monitor_position.y + monitor_size.y)
|
||||
if(!data->output_name && data->position.x >= monitor_position.x && data->position.x <= monitor_position.x + monitor_logical_size.x
|
||||
&& data->position.y >= monitor_position.y && data->position.y <= monitor_position.y + monitor_logical_size.y)
|
||||
{
|
||||
data->output_name = strdup(monitor->name);
|
||||
data->monitor_pos = monitor_position;
|
||||
data->monitor_size = monitor_size;
|
||||
data->monitor_scale_inverted = (double)monitor_size.x / (double)monitor_logical_size.x;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1194,6 +1191,8 @@ struct CaptureSource {
|
||||
vec2i region_size = {0, 0};
|
||||
bool region_set = false;
|
||||
int64_t window_id = 0;
|
||||
int camera_fps = 0;
|
||||
vec2i camera_resolution = {0, 0};
|
||||
};
|
||||
|
||||
struct VideoSource {
|
||||
@@ -1202,9 +1201,9 @@ struct VideoSource {
|
||||
CaptureSource *capture_source;
|
||||
};
|
||||
|
||||
static RecordingStartResult start_recording_create_streams(const char *filename, const args_parser &args_parser, AVCodecContext *video_codec_context, const std::vector<AudioTrack> &audio_tracks, bool hdr, std::vector<VideoSource> &video_sources) {
|
||||
static RecordingStartResult start_recording_create_streams(const char *filename, const args_parser &arg_parser, AVCodecContext *video_codec_context, const std::vector<AudioTrack> &audio_tracks, bool hdr, std::vector<VideoSource> &video_sources) {
|
||||
AVFormatContext *av_format_context;
|
||||
avformat_alloc_output_context2(&av_format_context, nullptr, args_parser.container_format, filename);
|
||||
avformat_alloc_output_context2(&av_format_context, nullptr, arg_parser.container_format, filename);
|
||||
|
||||
AVStream *video_stream = create_stream(av_format_context, video_codec_context);
|
||||
avcodec_parameters_from_context(video_stream->codecpar, video_codec_context);
|
||||
@@ -1229,8 +1228,8 @@ static RecordingStartResult start_recording_create_streams(const char *filename,
|
||||
AVDictionary *options = nullptr;
|
||||
av_dict_set(&options, "strict", "experimental", 0);
|
||||
|
||||
if(args_parser.ffmpeg_opts)
|
||||
av_dict_parse_string(&options, args_parser.ffmpeg_opts, "=", ";", 0);
|
||||
if(arg_parser.ffmpeg_opts)
|
||||
av_dict_parse_string(&options, arg_parser.ffmpeg_opts, "=", ";", 0);
|
||||
|
||||
const int header_write_ret = avformat_write_header(av_format_context, &options);
|
||||
av_dict_free(&options);
|
||||
@@ -1294,48 +1293,60 @@ struct AudioPtsOffset {
|
||||
int stream_index = 0;
|
||||
};
|
||||
|
||||
static void save_replay_async(AVCodecContext *video_codec_context, int video_stream_index, const std::vector<AudioTrack> &audio_tracks, gsr_replay_buffer *replay_buffer, const args_parser &arg_parser, const std::string &file_extension, bool date_folders, bool hdr, std::vector<VideoSource> &video_sources, int current_save_replay_seconds) {
|
||||
static void save_replay_async(AVCodecContext *video_codec_context, int video_stream_index, const std::vector<AudioTrack> &audio_tracks, gsr_encoder *encoder, const args_parser &arg_parser, const std::string &file_extension, bool date_folders, bool hdr, std::vector<VideoSource> &video_sources, int current_save_replay_seconds) {
|
||||
if(save_replay_thread.valid())
|
||||
return;
|
||||
|
||||
const gsr_replay_buffer_iterator search_start_iterator = current_save_replay_seconds == save_replay_seconds_full ? gsr_replay_buffer_iterator{0, 0} : gsr_replay_buffer_find_packet_index_by_time_passed(replay_buffer, current_save_replay_seconds);
|
||||
const gsr_replay_buffer_iterator video_start_iterator = gsr_replay_buffer_find_keyframe(replay_buffer, search_start_iterator, video_stream_index, false);
|
||||
if(video_start_iterator.packet_index == (size_t)-1) {
|
||||
fprintf(stderr, "gsr error: failed to save replay: failed to find a video keyframe. perhaps replay was saved too fast, before anything has been recorded\n");
|
||||
return;
|
||||
}
|
||||
|
||||
const int64_t video_pts_offset = gsr_replay_buffer_iterator_get_packet(replay_buffer, video_start_iterator)->pts;
|
||||
|
||||
std::vector<AudioPtsOffset> audio_pts_offsets;
|
||||
audio_pts_offsets.reserve(audio_tracks.size());
|
||||
for(const AudioTrack &audio_track : audio_tracks) {
|
||||
const gsr_replay_buffer_iterator audio_start_iterator = gsr_replay_buffer_find_keyframe(replay_buffer, video_start_iterator, audio_track.stream_index, false);
|
||||
const int64_t audio_pts_offset = audio_start_iterator.packet_index == (size_t)-1 ? 0 : gsr_replay_buffer_iterator_get_packet(replay_buffer, audio_start_iterator)->pts;
|
||||
audio_pts_offsets.push_back(AudioPtsOffset{audio_pts_offset, audio_track.stream_index});
|
||||
}
|
||||
|
||||
gsr_replay_buffer *cloned_replay_buffer = gsr_replay_buffer_clone(replay_buffer);
|
||||
pthread_mutex_lock(&encoder->replay_mutex);
|
||||
gsr_replay_buffer *cloned_replay_buffer = gsr_replay_buffer_clone(encoder->replay_buffer);
|
||||
pthread_mutex_unlock(&encoder->replay_mutex);
|
||||
if(!cloned_replay_buffer) {
|
||||
// TODO: Return this error to mark the replay as failed
|
||||
fprintf(stderr, "gsr error: failed to save replay: failed to clone replay buffer\n");
|
||||
return;
|
||||
}
|
||||
|
||||
const gsr_replay_buffer_iterator search_start_iterator = current_save_replay_seconds == save_replay_seconds_full ? gsr_replay_buffer_iterator{0, 0} : gsr_replay_buffer_find_packet_index_by_time_passed(cloned_replay_buffer, current_save_replay_seconds);
|
||||
const gsr_replay_buffer_iterator video_start_iterator = gsr_replay_buffer_find_keyframe(cloned_replay_buffer, search_start_iterator, video_stream_index, false);
|
||||
if(video_start_iterator.packet_index == (size_t)-1) {
|
||||
fprintf(stderr, "gsr error: failed to save replay: failed to find a video keyframe. perhaps replay was saved too fast, before anything has been recorded\n");
|
||||
pthread_mutex_lock(&encoder->replay_mutex);
|
||||
gsr_replay_buffer_destroy(cloned_replay_buffer);
|
||||
pthread_mutex_unlock(&encoder->replay_mutex);
|
||||
return;
|
||||
}
|
||||
|
||||
const int64_t video_pts_offset = gsr_replay_buffer_iterator_get_packet(cloned_replay_buffer, video_start_iterator)->pts;
|
||||
|
||||
std::vector<AudioPtsOffset> audio_pts_offsets;
|
||||
audio_pts_offsets.reserve(audio_tracks.size());
|
||||
for(const AudioTrack &audio_track : audio_tracks) {
|
||||
const gsr_replay_buffer_iterator audio_start_iterator = gsr_replay_buffer_find_keyframe(cloned_replay_buffer, video_start_iterator, audio_track.stream_index, false);
|
||||
const int64_t audio_pts_offset = audio_start_iterator.packet_index == (size_t)-1 ? 0 : gsr_replay_buffer_iterator_get_packet(cloned_replay_buffer, audio_start_iterator)->pts;
|
||||
audio_pts_offsets.push_back(AudioPtsOffset{audio_pts_offset, audio_track.stream_index});
|
||||
}
|
||||
|
||||
std::string output_filepath = create_new_recording_filepath_from_timestamp(arg_parser.filename, "Replay", file_extension, date_folders);
|
||||
RecordingStartResult recording_start_result = start_recording_create_streams(output_filepath.c_str(), arg_parser, video_codec_context, audio_tracks, hdr, video_sources);
|
||||
if(!recording_start_result.av_format_context)
|
||||
if(!recording_start_result.av_format_context) {
|
||||
pthread_mutex_lock(&encoder->replay_mutex);
|
||||
gsr_replay_buffer_destroy(cloned_replay_buffer);
|
||||
pthread_mutex_unlock(&encoder->replay_mutex);
|
||||
return;
|
||||
}
|
||||
|
||||
save_replay_output_filepath = std::move(output_filepath);
|
||||
|
||||
save_replay_thread = std::async(std::launch::async, [video_stream_index, recording_start_result, video_start_iterator, video_pts_offset, audio_pts_offsets{std::move(audio_pts_offsets)}, video_codec_context, cloned_replay_buffer]() mutable {
|
||||
save_replay_thread = std::async(std::launch::async, [video_stream_index, recording_start_result, video_start_iterator, video_pts_offset, audio_pts_offsets{std::move(audio_pts_offsets)}, video_codec_context, cloned_replay_buffer, encoder]() mutable {
|
||||
gsr_replay_buffer_iterator replay_iterator = video_start_iterator;
|
||||
for(;;) {
|
||||
AVPacket *replay_packet = gsr_replay_buffer_iterator_get_packet(cloned_replay_buffer, replay_iterator);
|
||||
uint8_t *replay_packet_data = NULL;
|
||||
if(replay_packet)
|
||||
if(replay_packet) {
|
||||
pthread_mutex_lock(&encoder->replay_mutex);
|
||||
replay_packet_data = gsr_replay_buffer_iterator_get_packet_data(cloned_replay_buffer, replay_iterator);
|
||||
pthread_mutex_unlock(&encoder->replay_mutex);
|
||||
}
|
||||
|
||||
if(!replay_packet) {
|
||||
fprintf(stderr, "gsr error: save_replay_async: no replay packet\n");
|
||||
@@ -1398,7 +1409,10 @@ static void save_replay_async(AVCodecContext *video_codec_context, int video_str
|
||||
}
|
||||
|
||||
stop_recording_close_streams(recording_start_result.av_format_context);
|
||||
|
||||
pthread_mutex_lock(&encoder->replay_mutex);
|
||||
gsr_replay_buffer_destroy(cloned_replay_buffer);
|
||||
pthread_mutex_unlock(&encoder->replay_mutex);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1869,37 +1883,36 @@ static void output_monitor_info(const gsr_monitor *monitor, void *userdata) {
|
||||
++options->num_monitors;
|
||||
}
|
||||
|
||||
static void camera_query_callback(const char *path, gsr_capture_v4l2_supported_pixfmts supported_pixfmts, vec2i size, void *userdata) {
|
||||
static void camera_query_callback(const char *path, const gsr_capture_v4l2_supported_setup *setup, void *userdata) {
|
||||
(void)userdata;
|
||||
|
||||
char pixfmt_str[32];
|
||||
if(supported_pixfmts.yuyv && supported_pixfmts.mjpeg)
|
||||
snprintf(pixfmt_str, sizeof(pixfmt_str), "yuyv,mjpeg");
|
||||
else if(supported_pixfmts.yuyv)
|
||||
snprintf(pixfmt_str, sizeof(pixfmt_str), "yuyv");
|
||||
else if(supported_pixfmts.mjpeg)
|
||||
snprintf(pixfmt_str, sizeof(pixfmt_str), "mjpeg");
|
||||
|
||||
printf("%s|%dx%d|%s\n", path, size.x, size.y, pixfmt_str);
|
||||
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);
|
||||
@@ -1928,11 +1941,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");
|
||||
}
|
||||
@@ -1941,7 +1963,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.
|
||||
@@ -1951,46 +1973,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);
|
||||
|
||||
@@ -2053,53 +2085,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);
|
||||
|
||||
@@ -2147,9 +2156,9 @@ static std::string validate_monitor_get_valid(const gsr_egl *egl, const char* wi
|
||||
return capture_source_result;
|
||||
}
|
||||
|
||||
static std::string get_monitor_by_region_center(const gsr_egl *egl, vec2i region_position, vec2i region_size, vec2i *monitor_pos, vec2i *monitor_size) {
|
||||
static std::string get_monitor_by_region_center(const gsr_egl *egl, vec2i region_position, vec2i region_size, vec2i *monitor_pos, vec2i *monitor_size, double *monitor_scale_inverted) {
|
||||
const bool is_x11 = gsr_window_get_display_server(egl->window) == GSR_DISPLAY_SERVER_X11;
|
||||
const gsr_connection_type connection_type = is_x11 ? GSR_CONNECTION_X11 : GSR_CONNECTION_DRM;
|
||||
const gsr_connection_type connection_type = is_x11 ? GSR_CONNECTION_X11 : GSR_CONNECTION_WAYLAND;
|
||||
|
||||
MonitorByPositionCallback data;
|
||||
data.window = egl->window;
|
||||
@@ -2157,6 +2166,7 @@ static std::string get_monitor_by_region_center(const gsr_egl *egl, vec2i region
|
||||
data.output_name = NULL;
|
||||
data.monitor_pos = {0, 0};
|
||||
data.monitor_size = {0, 0};
|
||||
data.monitor_scale_inverted = 1.0;
|
||||
for_each_active_monitor_output(egl->window, egl->card_path, connection_type, get_monitor_by_position_callback, &data);
|
||||
|
||||
std::string result;
|
||||
@@ -2166,6 +2176,7 @@ static std::string get_monitor_by_region_center(const gsr_egl *egl, vec2i region
|
||||
}
|
||||
*monitor_pos = data.monitor_pos;
|
||||
*monitor_size = data.monitor_size;
|
||||
*monitor_scale_inverted = data.monitor_scale_inverted;
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -2233,18 +2244,25 @@ static gsr_capture* create_monitor_capture(const args_parser &arg_parser, gsr_eg
|
||||
}
|
||||
}
|
||||
|
||||
static void monitor_output_callback_print_region(const gsr_monitor *monitor, void *userdata) {
|
||||
const vec2i monitor_position = monitor->logical_pos;
|
||||
const vec2i monitor_size = monitor->logical_size;
|
||||
fprintf(stderr, " \"%.*s\" (%dx%d+%d+%d)\n", monitor->name_len, monitor->name, monitor_size.x, monitor_size.y, monitor_position.x, monitor_position.y);
|
||||
}
|
||||
|
||||
static std::string region_get_data(gsr_egl *egl, vec2i *region_size, vec2i *region_position) {
|
||||
vec2i monitor_pos = {0, 0};
|
||||
vec2i monitor_size = {0, 0};
|
||||
std::string window = get_monitor_by_region_center(egl, *region_position, *region_size, &monitor_pos, &monitor_size);
|
||||
double monitor_scale_inverted = 1.0;
|
||||
std::string window = get_monitor_by_region_center(egl, *region_position, *region_size, &monitor_pos, &monitor_size, &monitor_scale_inverted);
|
||||
if(window.empty()) {
|
||||
const bool is_x11 = gsr_window_get_display_server(egl->window) == GSR_DISPLAY_SERVER_X11;
|
||||
const gsr_connection_type connection_type = is_x11 ? GSR_CONNECTION_X11 : GSR_CONNECTION_DRM;
|
||||
const gsr_connection_type connection_type = is_x11 ? GSR_CONNECTION_X11 : GSR_CONNECTION_WAYLAND;
|
||||
fprintf(stderr, "gsr error: the region %dx%d+%d+%d doesn't match any monitor. Available monitors and their regions:\n", region_size->x, region_size->y, region_position->x, region_position->y);
|
||||
|
||||
MonitorOutputCallbackUserdata userdata;
|
||||
userdata.window = egl->window;
|
||||
for_each_active_monitor_output(egl->window, egl->card_path, connection_type, monitor_output_callback_print, &userdata);
|
||||
for_each_active_monitor_output(egl->window, egl->card_path, connection_type, monitor_output_callback_print_region, &userdata);
|
||||
_exit(51);
|
||||
}
|
||||
|
||||
@@ -2255,6 +2273,12 @@ 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;
|
||||
|
||||
region_size->x *= monitor_scale_inverted;
|
||||
region_size->y *= monitor_scale_inverted;
|
||||
}
|
||||
return window;
|
||||
}
|
||||
@@ -2316,7 +2340,9 @@ static gsr_capture* create_capture_impl(const args_parser &arg_parser, gsr_egl *
|
||||
v4l2_params.output_resolution = arg_parser.output_resolution;
|
||||
v4l2_params.device_path = capture_source.name.c_str();
|
||||
v4l2_params.pixfmt = capture_source.v4l2_pixfmt;
|
||||
v4l2_params.fps = arg_parser.fps;
|
||||
v4l2_params.camera_fps = capture_source.camera_fps;
|
||||
v4l2_params.camera_resolution.width = capture_source.camera_resolution.x;
|
||||
v4l2_params.camera_resolution.height = capture_source.camera_resolution.y;
|
||||
capture = gsr_capture_v4l2_create(&v4l2_params);
|
||||
if(!capture)
|
||||
_exit(1);
|
||||
@@ -2398,13 +2424,30 @@ static std::vector<VideoSource> create_video_sources(const args_parser &arg_pars
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Video size should be end pos - start pos, where start pos = pos and end pos = pos + size
|
||||
video_size = {0, 0};
|
||||
vec2i start_pos = {99999, 99999};
|
||||
vec2i end_pos = {-99999, -99999};
|
||||
for(const VideoSource &video_source : video_sources) {
|
||||
video_size.x = std::max(video_size.x, video_source.metadata.video_size.x);
|
||||
video_size.y = std::max(video_size.y, video_source.metadata.video_size.y);
|
||||
// TODO: Skip scalar positions for now, but this should be handled in a better way.
|
||||
// Maybe handle scalars at the next loop by multiplying video size by the scalar.
|
||||
if(video_source.capture_source->pos.x_type == VVEC2I_TYPE_SCALAR || video_source.capture_source->pos.y_type == VVEC2I_TYPE_SCALAR
|
||||
|| (video_source.capture_source->size.x_type == VVEC2I_TYPE_SCALAR && video_source.capture_source->size.x != 100)
|
||||
|| (video_source.capture_source->size.y_type == VVEC2I_TYPE_SCALAR && video_source.capture_source->size.y != 100))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
const vec2i video_source_start_pos = {video_source.capture_source->pos.x, video_source.capture_source->pos.y};
|
||||
const vec2i video_source_end_pos = {video_source_start_pos.x + video_source.metadata.video_size.x, video_source_start_pos.y + video_source.metadata.video_size.y};
|
||||
|
||||
start_pos.x = std::min(start_pos.x, video_source_start_pos.x);
|
||||
start_pos.y = std::min(start_pos.y, video_source_start_pos.y);
|
||||
|
||||
end_pos.x = std::max(end_pos.x, video_source_end_pos.x);
|
||||
end_pos.y = std::max(end_pos.y, video_source_end_pos.y);
|
||||
}
|
||||
|
||||
video_size.x = std::max(0, end_pos.x - start_pos.x);
|
||||
video_size.y = std::max(0, end_pos.y - start_pos.y);
|
||||
|
||||
for(VideoSource &video_source : video_sources) {
|
||||
video_source.metadata.video_size = video_size;
|
||||
}
|
||||
@@ -2790,6 +2833,7 @@ static void parse_capture_source_options(const std::string &capture_source_str,
|
||||
fprintf(stderr, "gsr error: invalid capture target value for option y: \"%.*s\", expected a number\n", (int)size, sub);
|
||||
_exit(1);
|
||||
}
|
||||
|
||||
} else if(string_starts_with(sub, size, "width=")) {
|
||||
capture_source.size.x_type = sub[size - 1] == '%' ? VVEC2I_TYPE_SCALAR : VVEC2I_TYPE_PIXELS;
|
||||
sub += 6;
|
||||
@@ -2849,8 +2893,29 @@ static void parse_capture_source_options(const std::string &capture_source_str,
|
||||
|
||||
if(vflip)
|
||||
capture_source.flip |= GSR_FLIP_VERTICAL;
|
||||
} else if(string_starts_with(sub, size, "camera_fps=")) {
|
||||
sub += 11;
|
||||
size -= 11;
|
||||
if(!string_to_int(sub, size, &capture_source.camera_fps)) {
|
||||
fprintf(stderr, "gsr error: invalid capture target value for option camera_fps: \"%.*s\", expected a number\n", (int)size, sub);
|
||||
_exit(1);
|
||||
}
|
||||
} else if(string_starts_with(sub, size, "camera_width=")) {
|
||||
sub += 13;
|
||||
size -= 13;
|
||||
if(!string_to_int(sub, size, &capture_source.camera_resolution.x)) {
|
||||
fprintf(stderr, "gsr error: invalid capture target value for option camera_width: \"%.*s\", expected a number\n", (int)size, sub);
|
||||
_exit(1);
|
||||
}
|
||||
} else if(string_starts_with(sub, size, "camera_height=")) {
|
||||
sub += 14;
|
||||
size -= 14;
|
||||
if(!string_to_int(sub, size, &capture_source.camera_resolution.y)) {
|
||||
fprintf(stderr, "gsr error: invalid capture target value for option camera_height: \"%.*s\", expected a number\n", (int)size, sub);
|
||||
_exit(1);
|
||||
}
|
||||
} else {
|
||||
fprintf(stderr, "gsr error: invalid capture target option \"%.*s\", expected x, y, width, height, halign, valign, pixfmt, hflip or vflip\n", (int)size, sub);
|
||||
fprintf(stderr, "gsr error: invalid capture target option \"%.*s\", expected x, y, width, height, halign, valign, pixfmt, hflip, vflip, camera_fps, camera_width or camera_height\n", (int)size, sub);
|
||||
_exit(1);
|
||||
}
|
||||
|
||||
@@ -2860,6 +2925,7 @@ static void parse_capture_source_options(const std::string &capture_source_str,
|
||||
|
||||
static std::vector<CaptureSource> parse_capture_source_arg(const char *capture_source_arg, const args_parser &arg_parser) {
|
||||
std::vector<CaptureSource> requested_capture_sources;
|
||||
const bool has_multiple_capture_sources = strchr(capture_source_arg, '|') != nullptr;
|
||||
|
||||
split_string(capture_source_arg, '|', [&](const char *sub, size_t size) {
|
||||
if(size == 0)
|
||||
@@ -2901,12 +2967,10 @@ static std::vector<CaptureSource> parse_capture_source_arg(const char *capture_s
|
||||
}
|
||||
}
|
||||
|
||||
/* We want good default values for v4l2 (webcam) capture, by setting webcam at bottom right, offset by -10%,-10% pixels and at size 30%,30% */
|
||||
if(capture_source.type == GSR_CAPTURE_SOURCE_TYPE_V4L2 && !requested_capture_sources.empty()) {
|
||||
if(has_multiple_capture_sources) {
|
||||
capture_source.halign = GSR_CAPTURE_ALIGN_START;
|
||||
capture_source.valign = GSR_CAPTURE_ALIGN_END;
|
||||
capture_source.valign = GSR_CAPTURE_ALIGN_START;
|
||||
capture_source.pos = {0, 0, VVEC2I_TYPE_PIXELS, VVEC2I_TYPE_PIXELS};
|
||||
capture_source.size = {30, 30, VVEC2I_TYPE_SCALAR, VVEC2I_TYPE_SCALAR};
|
||||
}
|
||||
|
||||
parse_capture_source_options(std::string(substr_start, size), capture_source);
|
||||
@@ -3203,7 +3267,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);
|
||||
@@ -3213,14 +3277,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);
|
||||
}
|
||||
@@ -3229,7 +3293,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)) {
|
||||
@@ -3240,7 +3304,7 @@ 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");
|
||||
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)) {
|
||||
@@ -3271,12 +3335,12 @@ static gsr_video_codec select_appropriate_video_codec_automatically(vec2i video_
|
||||
fprintf(stderr, "gsr info: using h264 encoder because a codec was not specified\n");
|
||||
return GSR_VIDEO_CODEC_H264;
|
||||
} else if(supported_video_codecs->hevc.supported && codec_supports_resolution(supported_video_codecs->hevc.max_resolution, video_size)) {
|
||||
fprintf(stderr, "gsr info: using hevc encoder because a codec was not specified and h264 supported max resolution (%dx%d) is less than capture resolution (%dx%d)\n",
|
||||
fprintf(stderr, "gsr info: using hevc encoder because a codec was not specified and h264 supported max resolution (%dx%d) is less than the capture resolution (%dx%d)\n",
|
||||
supported_video_codecs->h264.max_resolution.x, supported_video_codecs->h264.max_resolution.y,
|
||||
video_size.x, video_size.y);
|
||||
return GSR_VIDEO_CODEC_HEVC;
|
||||
} else if(supported_video_codecs->av1.supported && codec_supports_resolution(supported_video_codecs->av1.max_resolution, video_size)) {
|
||||
fprintf(stderr, "gsr info: using av1 encoder because a codec was not specified and hevc supported max resolution (%dx%d) is less than capture resolution (%dx%d)\n",
|
||||
fprintf(stderr, "gsr info: using av1 encoder because a codec was not specified and hevc supported max resolution (%dx%d) is less than the capture resolution (%dx%d)\n",
|
||||
supported_video_codecs->hevc.max_resolution.x, supported_video_codecs->hevc.max_resolution.y,
|
||||
video_size.x, video_size.y);
|
||||
return GSR_VIDEO_CODEC_AV1;
|
||||
@@ -3314,7 +3378,6 @@ static const AVCodec* select_video_codec_with_fallback(vec2i video_size, args_pa
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Allow hevc, vp9 and av1 in (enhanced) flv (supported since ffmpeg 6.1)
|
||||
if(LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(60, 10, 100) && strcmp(file_extension, "flv") == 0) {
|
||||
if(args_parser->video_codec != GSR_VIDEO_CODEC_H264) {
|
||||
args_parser->video_codec = GSR_VIDEO_CODEC_H264;
|
||||
@@ -3501,7 +3564,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);
|
||||
}
|
||||
}
|
||||
@@ -3602,13 +3665,6 @@ int main(int argc, char **argv) {
|
||||
// If this is set to 1 then cuGraphicsGLRegisterImage will fail for egl context with error: invalid OpenGL or DirectX context,
|
||||
// so we overwrite it
|
||||
setenv("__GL_THREADED_OPTIMIZATIONS", "0", true);
|
||||
// Forces low latency encoding mode. Use this environment variable until vaapi supports setting this as a parameter.
|
||||
// The downside of this is that it always uses maximum power, which is not ideal for replay mode that runs on system startup.
|
||||
// This option was added in mesa 24.1.4, released in july 17, 2024.
|
||||
// TODO: Add an option to enable/disable this?
|
||||
// Seems like the performance issue is not in encoding, but rendering the frame.
|
||||
// Some frames end up taking 10 times longer. Seems to be an issue with amd gpu power management when letting the application sleep on the cpu side?
|
||||
setenv("AMD_DEBUG", "lowlatencyenc", true);
|
||||
// Some people set this to nvidia (for nvdec) or vdpau (for nvidia vdpau), which breaks gpu screen recorder since
|
||||
// nvidia doesn't support vaapi and nvidia-vaapi-driver doesn't support encoding yet.
|
||||
// Let vaapi find the right vaapi driver instead of forcing a specific one.
|
||||
@@ -3630,11 +3686,21 @@ 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))
|
||||
_exit(1);
|
||||
|
||||
if(!arg_parser.low_power) {
|
||||
// Forces low latency encoding mode. Use this environment variable until vaapi supports setting this as a parameter.
|
||||
// The downside of this is that it always uses maximum power, which is not ideal for replay mode that runs on system startup.
|
||||
// This option was added in mesa 24.1.4, released in july 17, 2024.
|
||||
// Seems like the performance issue is not in encoding, but rendering the frame.
|
||||
// Some frames end up taking 10 times longer. Seems to be an issue with amd gpu power management when letting the application sleep on the cpu side?
|
||||
setenv("AMD_DEBUG", "lowlatencyenc", true);
|
||||
}
|
||||
|
||||
std::vector<CaptureSource> capture_sources = parse_capture_source_arg(arg_parser.capture_source, arg_parser);
|
||||
if(capture_sources.empty()) {
|
||||
fprintf(stderr, "gsr error: option -w can't be empty. You need to capture video from at least one source\n");
|
||||
@@ -3927,7 +3993,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;
|
||||
@@ -4466,6 +4536,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);
|
||||
|
||||
@@ -4525,10 +4600,13 @@ int main(int argc, char **argv) {
|
||||
|
||||
save_replay_seconds = 0;
|
||||
save_replay_output_filepath.clear();
|
||||
save_replay_async(video_codec_context, VIDEO_STREAM_INDEX, audio_tracks, encoder.replay_buffer, arg_parser, file_extension, arg_parser.date_folders, hdr, video_sources, current_save_replay_seconds);
|
||||
save_replay_async(video_codec_context, VIDEO_STREAM_INDEX, audio_tracks, &encoder, arg_parser, file_extension, arg_parser.date_folders, hdr, video_sources, current_save_replay_seconds);
|
||||
|
||||
if(arg_parser.restart_replay_on_save && current_save_replay_seconds == save_replay_seconds_full)
|
||||
if(arg_parser.restart_replay_on_save && current_save_replay_seconds == save_replay_seconds_full) {
|
||||
pthread_mutex_lock(&encoder.replay_mutex);
|
||||
gsr_replay_buffer_clear(encoder.replay_buffer);
|
||||
pthread_mutex_unlock(&encoder.replay_mutex);
|
||||
}
|
||||
}
|
||||
|
||||
const double time_at_frame_end = clock_get_monotonic_seconds() - paused_time_offset;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -16,48 +16,14 @@ gsr_replay_buffer* gsr_replay_buffer_create(gsr_replay_storage replay_storage, c
|
||||
replay_buffer = gsr_replay_buffer_disk_create(replay_directory, replay_buffer_time);
|
||||
break;
|
||||
}
|
||||
|
||||
replay_buffer->mutex_initialized = false;
|
||||
replay_buffer->original_replay_buffer = NULL;
|
||||
if(pthread_mutex_init(&replay_buffer->mutex, NULL) != 0) {
|
||||
gsr_replay_buffer_destroy(replay_buffer);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
replay_buffer->mutex_initialized = true;
|
||||
return replay_buffer;
|
||||
}
|
||||
|
||||
void gsr_replay_buffer_destroy(gsr_replay_buffer *self) {
|
||||
self->destroy(self);
|
||||
if(self->mutex_initialized && !self->original_replay_buffer) {
|
||||
pthread_mutex_destroy(&self->mutex);
|
||||
self->mutex_initialized = false;
|
||||
}
|
||||
self->original_replay_buffer = NULL;
|
||||
free(self);
|
||||
}
|
||||
|
||||
void gsr_replay_buffer_lock(gsr_replay_buffer *self) {
|
||||
if(self->original_replay_buffer) {
|
||||
gsr_replay_buffer_lock(self->original_replay_buffer);
|
||||
return;
|
||||
}
|
||||
|
||||
if(self->mutex_initialized)
|
||||
pthread_mutex_lock(&self->mutex);
|
||||
}
|
||||
|
||||
void gsr_replay_buffer_unlock(gsr_replay_buffer *self) {
|
||||
if(self->original_replay_buffer) {
|
||||
gsr_replay_buffer_unlock(self->original_replay_buffer);
|
||||
return;
|
||||
}
|
||||
|
||||
if(self->mutex_initialized)
|
||||
pthread_mutex_unlock(&self->mutex);
|
||||
}
|
||||
|
||||
bool gsr_replay_buffer_append(gsr_replay_buffer *self, const AVPacket *av_packet, double timestamp) {
|
||||
return self->append(self, av_packet, timestamp);
|
||||
}
|
||||
|
||||
@@ -94,7 +94,6 @@ static void gsr_replay_buffer_file_unref(gsr_replay_buffer_file *self, const cha
|
||||
|
||||
static void gsr_replay_buffer_disk_clear(gsr_replay_buffer *replay_buffer) {
|
||||
gsr_replay_buffer_disk *self = (gsr_replay_buffer_disk*)replay_buffer;
|
||||
gsr_replay_buffer_lock(&self->replay_buffer);
|
||||
|
||||
for(size_t i = 0; i < self->num_files; ++i) {
|
||||
gsr_replay_buffer_file_unref(self->files[i], self->replay_directory);
|
||||
@@ -107,7 +106,6 @@ static void gsr_replay_buffer_disk_clear(gsr_replay_buffer *replay_buffer) {
|
||||
}
|
||||
|
||||
self->storage_num_bytes_written = 0;
|
||||
gsr_replay_buffer_unlock(&self->replay_buffer);
|
||||
}
|
||||
|
||||
static void gsr_replay_buffer_disk_destroy(gsr_replay_buffer *replay_buffer) {
|
||||
@@ -197,7 +195,6 @@ static void gsr_replay_buffer_disk_remove_first_file(gsr_replay_buffer_disk *sel
|
||||
static bool gsr_replay_buffer_disk_append(gsr_replay_buffer *replay_buffer, const AVPacket *av_packet, double timestamp) {
|
||||
gsr_replay_buffer_disk *self = (gsr_replay_buffer_disk*)replay_buffer;
|
||||
bool success = false;
|
||||
gsr_replay_buffer_lock(&self->replay_buffer);
|
||||
|
||||
if(self->storage_fd <= 0) {
|
||||
if(!gsr_replay_buffer_disk_create_next_file(self, timestamp))
|
||||
@@ -215,7 +212,6 @@ static bool gsr_replay_buffer_disk_append(gsr_replay_buffer *replay_buffer, cons
|
||||
success = data_written;
|
||||
|
||||
done:
|
||||
gsr_replay_buffer_unlock(&self->replay_buffer);
|
||||
return success;
|
||||
}
|
||||
|
||||
@@ -265,11 +261,7 @@ static gsr_replay_buffer* gsr_replay_buffer_disk_clone(gsr_replay_buffer *replay
|
||||
return NULL;
|
||||
|
||||
gsr_replay_buffer_disk_set_impl_funcs(destination);
|
||||
gsr_replay_buffer_lock(&self->replay_buffer);
|
||||
|
||||
destination->replay_buffer.original_replay_buffer = replay_buffer;
|
||||
destination->replay_buffer.mutex = self->replay_buffer.mutex;
|
||||
destination->replay_buffer.mutex_initialized = self->replay_buffer.mutex_initialized;
|
||||
destination->replay_buffer_time = self->replay_buffer_time;
|
||||
destination->storage_counter = self->storage_counter;
|
||||
destination->storage_num_bytes_written = self->storage_num_bytes_written;
|
||||
@@ -283,7 +275,6 @@ static gsr_replay_buffer* gsr_replay_buffer_disk_clone(gsr_replay_buffer *replay
|
||||
snprintf(destination->replay_directory, sizeof(destination->replay_directory), "%s", self->replay_directory);
|
||||
destination->owns_directory = false;
|
||||
|
||||
gsr_replay_buffer_unlock(&self->replay_buffer);
|
||||
return (gsr_replay_buffer*)destination;
|
||||
}
|
||||
|
||||
@@ -319,11 +310,9 @@ static size_t gsr_replay_buffer_file_find_packet_index_by_time_passed(const gsr_
|
||||
/* Binary search */
|
||||
static gsr_replay_buffer_iterator gsr_replay_buffer_disk_find_file_index_by_time_passed(gsr_replay_buffer *replay_buffer, int seconds) {
|
||||
gsr_replay_buffer_disk *self = (gsr_replay_buffer_disk*)replay_buffer;
|
||||
gsr_replay_buffer_lock(&self->replay_buffer);
|
||||
|
||||
const double now = clock_get_monotonic_seconds();
|
||||
if(self->num_files == 0) {
|
||||
gsr_replay_buffer_unlock(&self->replay_buffer);
|
||||
return (gsr_replay_buffer_iterator){0, 0};
|
||||
}
|
||||
|
||||
@@ -352,14 +341,12 @@ static gsr_replay_buffer_iterator gsr_replay_buffer_disk_find_file_index_by_time
|
||||
const gsr_replay_buffer_file *file = self->files[file_index];
|
||||
const size_t packet_index = gsr_replay_buffer_file_find_packet_index_by_time_passed(file, seconds);
|
||||
|
||||
gsr_replay_buffer_unlock(&self->replay_buffer);
|
||||
return (gsr_replay_buffer_iterator){packet_index, file_index};
|
||||
}
|
||||
|
||||
static gsr_replay_buffer_iterator gsr_replay_buffer_disk_find_keyframe(gsr_replay_buffer *replay_buffer, gsr_replay_buffer_iterator start_iterator, int stream_index, bool invert_stream_index) {
|
||||
gsr_replay_buffer_disk *self = (gsr_replay_buffer_disk*)replay_buffer;
|
||||
gsr_replay_buffer_iterator keyframe_iterator = {(size_t)-1, 0};
|
||||
gsr_replay_buffer_lock(&self->replay_buffer);
|
||||
size_t packet_index = start_iterator.packet_index;
|
||||
for(size_t file_index = start_iterator.file_index; file_index < self->num_files; ++file_index) {
|
||||
const gsr_replay_buffer_file *file = self->files[file_index];
|
||||
@@ -374,7 +361,6 @@ static gsr_replay_buffer_iterator gsr_replay_buffer_disk_find_keyframe(gsr_repla
|
||||
packet_index = 0;
|
||||
}
|
||||
done:
|
||||
gsr_replay_buffer_unlock(&self->replay_buffer);
|
||||
return keyframe_iterator;
|
||||
}
|
||||
|
||||
|
||||
@@ -54,7 +54,6 @@ static void gsr_av_packet_ram_unref(gsr_av_packet_ram *self) {
|
||||
|
||||
static void gsr_replay_buffer_ram_destroy(gsr_replay_buffer *replay_buffer) {
|
||||
gsr_replay_buffer_ram *self = (gsr_replay_buffer_ram*)replay_buffer;
|
||||
gsr_replay_buffer_lock(&self->replay_buffer);
|
||||
for(size_t i = 0; i < self->num_packets; ++i) {
|
||||
if(self->packets[i]) {
|
||||
gsr_av_packet_ram_unref(self->packets[i]);
|
||||
@@ -62,7 +61,6 @@ static void gsr_replay_buffer_ram_destroy(gsr_replay_buffer *replay_buffer) {
|
||||
}
|
||||
}
|
||||
self->num_packets = 0;
|
||||
gsr_replay_buffer_unlock(&self->replay_buffer);
|
||||
|
||||
if(self->packets) {
|
||||
free(self->packets);
|
||||
@@ -75,12 +73,9 @@ static void gsr_replay_buffer_ram_destroy(gsr_replay_buffer *replay_buffer) {
|
||||
|
||||
static bool gsr_replay_buffer_ram_append(gsr_replay_buffer *replay_buffer, const AVPacket *av_packet, double timestamp) {
|
||||
gsr_replay_buffer_ram *self = (gsr_replay_buffer_ram*)replay_buffer;
|
||||
gsr_replay_buffer_lock(&self->replay_buffer);
|
||||
gsr_av_packet_ram *packet = gsr_av_packet_ram_create(av_packet, timestamp);
|
||||
if(!packet) {
|
||||
gsr_replay_buffer_unlock(&self->replay_buffer);
|
||||
if(!packet)
|
||||
return false;
|
||||
}
|
||||
|
||||
if(self->packets[self->index]) {
|
||||
gsr_av_packet_ram_unref(self->packets[self->index]);
|
||||
@@ -93,13 +88,11 @@ static bool gsr_replay_buffer_ram_append(gsr_replay_buffer *replay_buffer, const
|
||||
if(self->num_packets > self->capacity_num_packets)
|
||||
self->num_packets = self->capacity_num_packets;
|
||||
|
||||
gsr_replay_buffer_unlock(&self->replay_buffer);
|
||||
return true;
|
||||
}
|
||||
|
||||
static void gsr_replay_buffer_ram_clear(gsr_replay_buffer *replay_buffer) {
|
||||
gsr_replay_buffer_ram *self = (gsr_replay_buffer_ram*)replay_buffer;
|
||||
gsr_replay_buffer_lock(&self->replay_buffer);
|
||||
for(size_t i = 0; i < self->num_packets; ++i) {
|
||||
if(self->packets[i]) {
|
||||
gsr_av_packet_ram_unref(self->packets[i]);
|
||||
@@ -108,7 +101,6 @@ static void gsr_replay_buffer_ram_clear(gsr_replay_buffer *replay_buffer) {
|
||||
}
|
||||
self->num_packets = 0;
|
||||
self->index = 0;
|
||||
gsr_replay_buffer_unlock(&self->replay_buffer);
|
||||
}
|
||||
|
||||
static gsr_av_packet_ram* gsr_replay_buffer_ram_get_packet_at_index(gsr_replay_buffer *replay_buffer, size_t index) {
|
||||
@@ -141,17 +133,12 @@ static gsr_replay_buffer* gsr_replay_buffer_ram_clone(gsr_replay_buffer *replay_
|
||||
return NULL;
|
||||
|
||||
gsr_replay_buffer_ram_set_impl_funcs(destination);
|
||||
gsr_replay_buffer_lock(&self->replay_buffer);
|
||||
|
||||
destination->replay_buffer.original_replay_buffer = replay_buffer;
|
||||
destination->replay_buffer.mutex = self->replay_buffer.mutex;
|
||||
destination->replay_buffer.mutex_initialized = self->replay_buffer.mutex_initialized;
|
||||
destination->capacity_num_packets = self->capacity_num_packets;
|
||||
destination->index = self->index;
|
||||
destination->packets = calloc(destination->capacity_num_packets, sizeof(gsr_av_packet_ram*));
|
||||
if(!destination->packets) {
|
||||
free(destination);
|
||||
gsr_replay_buffer_unlock(&self->replay_buffer);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -160,18 +147,15 @@ static gsr_replay_buffer* gsr_replay_buffer_ram_clone(gsr_replay_buffer *replay_
|
||||
destination->packets[i] = gsr_av_packet_ram_ref(self->packets[i]);
|
||||
}
|
||||
|
||||
gsr_replay_buffer_unlock(&self->replay_buffer);
|
||||
return (gsr_replay_buffer*)destination;
|
||||
}
|
||||
|
||||
/* Binary search */
|
||||
static gsr_replay_buffer_iterator gsr_replay_buffer_ram_find_packet_index_by_time_passed(gsr_replay_buffer *replay_buffer, int seconds) {
|
||||
gsr_replay_buffer_ram *self = (gsr_replay_buffer_ram*)replay_buffer;
|
||||
gsr_replay_buffer_lock(&self->replay_buffer);
|
||||
|
||||
const double now = clock_get_monotonic_seconds();
|
||||
if(self->num_packets == 0) {
|
||||
gsr_replay_buffer_unlock(&self->replay_buffer);
|
||||
return (gsr_replay_buffer_iterator){0, 0};
|
||||
}
|
||||
|
||||
@@ -194,14 +178,12 @@ static gsr_replay_buffer_iterator gsr_replay_buffer_ram_find_packet_index_by_tim
|
||||
}
|
||||
}
|
||||
|
||||
gsr_replay_buffer_unlock(&self->replay_buffer);
|
||||
return (gsr_replay_buffer_iterator){index, 0};
|
||||
}
|
||||
|
||||
static gsr_replay_buffer_iterator gsr_replay_buffer_ram_find_keyframe(gsr_replay_buffer *replay_buffer, gsr_replay_buffer_iterator start_iterator, int stream_index, bool invert_stream_index) {
|
||||
gsr_replay_buffer_ram *self = (gsr_replay_buffer_ram*)replay_buffer;
|
||||
size_t keyframe_index = (size_t)-1;
|
||||
gsr_replay_buffer_lock(&self->replay_buffer);
|
||||
for(size_t i = start_iterator.packet_index; i < self->num_packets; ++i) {
|
||||
const gsr_av_packet_ram *packet = gsr_replay_buffer_ram_get_packet_at_index(replay_buffer, i);
|
||||
if((packet->packet.flags & AV_PKT_FLAG_KEY) && (invert_stream_index ? packet->packet.stream_index != stream_index : packet->packet.stream_index == stream_index)) {
|
||||
@@ -209,7 +191,6 @@ static gsr_replay_buffer_iterator gsr_replay_buffer_ram_find_keyframe(gsr_replay
|
||||
break;
|
||||
}
|
||||
}
|
||||
gsr_replay_buffer_unlock(&self->replay_buffer);
|
||||
return (gsr_replay_buffer_iterator){keyframe_index, 0};
|
||||
}
|
||||
|
||||
|
||||
@@ -59,17 +59,26 @@ struct pa_handle {
|
||||
std::mutex reconnect_mutex;
|
||||
DeviceType device_type;
|
||||
char stream_name[256];
|
||||
char node_name[256];
|
||||
bool reconnect;
|
||||
double reconnect_last_tried_seconds;
|
||||
|
||||
char device_name[DEVICE_NAME_MAX_SIZE];
|
||||
char default_output_device_name[DEVICE_NAME_MAX_SIZE];
|
||||
char default_input_device_name[DEVICE_NAME_MAX_SIZE];
|
||||
|
||||
pa_proplist *proplist;
|
||||
bool connected;
|
||||
};
|
||||
|
||||
static void pa_sound_device_free(pa_handle *p) {
|
||||
assert(p);
|
||||
|
||||
if(p->proplist) {
|
||||
pa_proplist_free(p->proplist);
|
||||
p->proplist = NULL;
|
||||
}
|
||||
|
||||
if (p->stream) {
|
||||
pa_stream_unref(p->stream);
|
||||
p->stream = NULL;
|
||||
@@ -186,6 +195,7 @@ static pa_handle* pa_sound_device_new(const char *server,
|
||||
p = pa_xnew0(pa_handle, 1);
|
||||
p->attr = *attr;
|
||||
p->ss = *ss;
|
||||
snprintf(p->node_name, sizeof(p->node_name), "%s", name);
|
||||
snprintf(p->stream_name, sizeof(p->stream_name), "%s", stream_name);
|
||||
|
||||
p->reconnect = true;
|
||||
@@ -206,17 +216,17 @@ static pa_handle* pa_sound_device_new(const char *server,
|
||||
p->output_length = buffer_size;
|
||||
p->output_index = 0;
|
||||
|
||||
pa_proplist *proplist = pa_proplist_new();
|
||||
pa_proplist_sets(proplist, PA_PROP_MEDIA_ROLE, "production");
|
||||
p->proplist = pa_proplist_new();
|
||||
pa_proplist_sets(p->proplist, PA_PROP_MEDIA_ROLE, "production");
|
||||
if(strcmp(device_name, "") == 0) {
|
||||
pa_proplist_sets(proplist, "node.autoconnect", "false");
|
||||
pa_proplist_sets(proplist, "node.dont-reconnect", "true");
|
||||
pa_proplist_sets(p->proplist, "node.autoconnect", "false");
|
||||
pa_proplist_sets(p->proplist, "node.dont-reconnect", "true");
|
||||
}
|
||||
|
||||
if (!(p->mainloop = pa_mainloop_new()))
|
||||
goto fail;
|
||||
|
||||
if (!(p->context = pa_context_new_with_proplist(pa_mainloop_get_api(p->mainloop), name, proplist)))
|
||||
if (!(p->context = pa_context_new_with_proplist(pa_mainloop_get_api(p->mainloop), p->node_name, p->proplist)))
|
||||
goto fail;
|
||||
|
||||
if (pa_context_connect(p->context, server, PA_CONTEXT_NOFLAGS, NULL) < 0) {
|
||||
@@ -246,17 +256,58 @@ static pa_handle* pa_sound_device_new(const char *server,
|
||||
if(pa)
|
||||
pa_operation_unref(pa);
|
||||
|
||||
pa_proplist_free(proplist);
|
||||
p->connected = true;
|
||||
return p;
|
||||
|
||||
fail:
|
||||
if (rerror)
|
||||
*rerror = error;
|
||||
pa_sound_device_free(p);
|
||||
pa_proplist_free(proplist);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void pa_sound_device_update_context_status(pa_handle *p) {
|
||||
if(p->connected || !p->context || pa_context_get_state(p->context) != PA_CONTEXT_READY)
|
||||
return;
|
||||
|
||||
p->connected = true;
|
||||
pa_context_set_subscribe_callback(p->context, subscribe_cb, p);
|
||||
pa_operation *pa = pa_context_subscribe(p->context, PA_SUBSCRIPTION_MASK_SERVER, NULL, NULL);
|
||||
if(pa)
|
||||
pa_operation_unref(pa);
|
||||
}
|
||||
|
||||
static bool pa_sound_device_handle_context_recreate(pa_handle *p) {
|
||||
if(p->context) {
|
||||
pa_context_disconnect(p->context);
|
||||
pa_context_unref(p->context);
|
||||
p->context = NULL;
|
||||
p->connected = false;
|
||||
}
|
||||
|
||||
if (!(p->context = pa_context_new_with_proplist(pa_mainloop_get_api(p->mainloop), p->node_name, p->proplist))) {
|
||||
fprintf(stderr, "gsr error: pa_context_new_with_proplist failed\n");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if(pa_context_connect(p->context, nullptr, PA_CONTEXT_NOFLAGS, NULL) < 0) {
|
||||
fprintf(stderr, "gsr error: pa_context_connect failed\n");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
pa_mainloop_iterate(p->mainloop, 0, NULL);
|
||||
pa_sound_device_update_context_status(p);
|
||||
return true;
|
||||
|
||||
fail:
|
||||
if(p->context) {
|
||||
pa_context_disconnect(p->context);
|
||||
pa_context_unref(p->context);
|
||||
p->context = NULL;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool pa_sound_device_should_reconnect(pa_handle *p, double now, char *device_name, size_t device_name_size) {
|
||||
std::lock_guard<std::mutex> lock(p->reconnect_mutex);
|
||||
|
||||
@@ -276,7 +327,6 @@ static bool pa_sound_device_should_reconnect(pa_handle *p, double now, char *dev
|
||||
}
|
||||
|
||||
static bool pa_sound_device_handle_reconnect(pa_handle *p, char *device_name, size_t device_name_size, double now) {
|
||||
int r;
|
||||
if(!pa_sound_device_should_reconnect(p, now, device_name, device_name_size))
|
||||
return true;
|
||||
|
||||
@@ -284,15 +334,26 @@ static bool pa_sound_device_handle_reconnect(pa_handle *p, char *device_name, si
|
||||
pa_stream_disconnect(p->stream);
|
||||
pa_stream_unref(p->stream);
|
||||
p->stream = NULL;
|
||||
|
||||
pa_sound_device_handle_context_recreate(p);
|
||||
if(!p->connected)
|
||||
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;
|
||||
}
|
||||
|
||||
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_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));
|
||||
|
||||
if(r < 0) {
|
||||
//pa_context_errno(p->context);
|
||||
@@ -320,6 +381,15 @@ static int pa_sound_device_read(pa_handle *p, double timeout_seconds) {
|
||||
|
||||
pa_mainloop_iterate(p->mainloop, 0, NULL);
|
||||
|
||||
if(!p->context) {
|
||||
if(!pa_sound_device_handle_context_recreate(p))
|
||||
goto fail;
|
||||
}
|
||||
|
||||
pa_sound_device_update_context_status(p);
|
||||
if(!p->connected)
|
||||
goto fail;
|
||||
|
||||
if(!pa_sound_device_handle_reconnect(p, device_name, sizeof(device_name), start_time) || !p->stream)
|
||||
goto fail;
|
||||
|
||||
|
||||
@@ -121,6 +121,8 @@ void for_each_active_monitor_output_x11_not_cached(Display *display, active_moni
|
||||
.name_len = out_info->nameLen,
|
||||
.pos = { .x = crt_info->x, .y = crt_info->y },
|
||||
.size = monitor_size,
|
||||
.logical_pos = { .x = crt_info->x, .y = crt_info->y },
|
||||
.logical_size = monitor_size,
|
||||
.connector_id = x11_output_get_connector_id(display, screen_res->outputs[i], randr_connector_id_atom),
|
||||
.rotation = rotation,
|
||||
.monitor_identifier = out_info->crtc
|
||||
@@ -229,6 +231,8 @@ static void for_each_active_monitor_output_drm(const char *card_path, active_mon
|
||||
.name_len = display_name_len,
|
||||
.pos = { .x = crtc->x, .y = crtc->y },
|
||||
.size = { .x = (int)crtc->width, .y = (int)crtc->height },
|
||||
.logical_pos = { .x = crtc->x, .y = crtc->y },
|
||||
.logical_size = { .x = (int)crtc->width, .y = (int)crtc->height },
|
||||
.connector_id = connector->connector_id,
|
||||
.rotation = GSR_MONITOR_ROT_0,
|
||||
.monitor_identifier = connector_type_index_name != -1 ? monitor_identifier_from_type_and_count(connector_type_index_name, connector->connector_type_id) : 0
|
||||
@@ -264,6 +268,8 @@ static void get_monitor_by_name_callback(const gsr_monitor *monitor, void *userd
|
||||
if(!data->found_monitor && strcmp(data->name, monitor->name) == 0) {
|
||||
data->monitor->pos = monitor->pos;
|
||||
data->monitor->size = monitor->size;
|
||||
data->monitor->logical_pos = monitor->logical_pos;
|
||||
data->monitor->logical_size = monitor->logical_size;
|
||||
data->monitor->connector_id = monitor->connector_id;
|
||||
data->monitor->rotation = monitor->rotation;
|
||||
data->monitor->monitor_identifier = monitor->monitor_identifier;
|
||||
|
||||
@@ -21,6 +21,7 @@ typedef struct {
|
||||
struct zxdg_output_v1 *xdg_output;
|
||||
vec2i pos;
|
||||
vec2i size;
|
||||
vec2i logical_size;
|
||||
int32_t transform;
|
||||
char *name;
|
||||
} gsr_wayland_output;
|
||||
@@ -123,6 +124,7 @@ static void registry_add_object(void *data, struct wl_registry *registry, uint32
|
||||
.output = wl_registry_bind(registry, name, &wl_output_interface, 4),
|
||||
.pos = { .x = 0, .y = 0 },
|
||||
.size = { .x = 0, .y = 0 },
|
||||
.logical_size = { .x = 0, .y = 0 },
|
||||
.transform = 0,
|
||||
.name = NULL,
|
||||
};
|
||||
@@ -160,10 +162,10 @@ static void xdg_output_logical_position(void *data, struct zxdg_output_v1 *zxdg_
|
||||
}
|
||||
|
||||
static void xdg_output_handle_logical_size(void *data, struct zxdg_output_v1 *xdg_output, int32_t width, int32_t height) {
|
||||
(void)data;
|
||||
(void)xdg_output;
|
||||
(void)width;
|
||||
(void)height;
|
||||
gsr_wayland_output *gsr_xdg_output = data;
|
||||
gsr_xdg_output->logical_size.x = width;
|
||||
gsr_xdg_output->logical_size.y = height;
|
||||
}
|
||||
|
||||
static void xdg_output_handle_done(void *data, struct zxdg_output_v1 *xdg_output) {
|
||||
@@ -206,6 +208,42 @@ static void gsr_window_wayland_set_monitor_outputs_from_xdg_output(gsr_window_wa
|
||||
wl_display_roundtrip(self->display);
|
||||
}
|
||||
|
||||
// static int monitor_sort_x_pos(const void* a, const void* b) {
|
||||
// const gsr_wayland_output *arg1 = *(const gsr_wayland_output**)a;
|
||||
// const gsr_wayland_output *arg2 = *(const gsr_wayland_output**)b;
|
||||
// return arg1->logical_pos.x - arg2->logical_pos.x;
|
||||
// }
|
||||
|
||||
// static int monitor_sort_y_pos(const void* a, const void* b) {
|
||||
// const gsr_wayland_output *arg1 = *(const gsr_wayland_output**)a;
|
||||
// const gsr_wayland_output *arg2 = *(const gsr_wayland_output**)b;
|
||||
// return arg1->logical_pos.y - arg2->logical_pos.y;
|
||||
// }
|
||||
|
||||
static void gsr_window_wayland_set_monitor_real_positions(gsr_window_wayland *self) {
|
||||
gsr_wayland_output *sorted_outputs[GSR_MAX_OUTPUTS];
|
||||
for(int i = 0; i < self->num_outputs; ++i) {
|
||||
sorted_outputs[i] = &self->outputs[i];
|
||||
}
|
||||
|
||||
// TODO: set correct physical positions
|
||||
|
||||
// qsort(sorted_outputs, self->num_outputs, sizeof(gsr_wayland_output*), monitor_sort_x_pos);
|
||||
// int x_pos = 0;
|
||||
// for(int i = 0; i < self->num_outputs; ++i) {
|
||||
// fprintf(stderr, "monitor: %s\n", sorted_outputs[i]->name);
|
||||
// sorted_outputs[i]->pos.x = x_pos;
|
||||
// x_pos += sorted_outputs[i]->logical_size.x;
|
||||
// }
|
||||
|
||||
// qsort(sorted_outputs, self->num_outputs, sizeof(gsr_wayland_output*), monitor_sort_y_pos);
|
||||
// int y_pos = 0;
|
||||
// for(int i = 0; i < self->num_outputs; ++i) {
|
||||
// sorted_outputs[i]->pos.y = y_pos;
|
||||
// y_pos += sorted_outputs[i]->logical_size.y;
|
||||
// }
|
||||
}
|
||||
|
||||
static void gsr_window_wayland_deinit(gsr_window_wayland *self) {
|
||||
if(self->window) {
|
||||
wl_egl_window_destroy(self->window);
|
||||
@@ -273,6 +311,7 @@ static bool gsr_window_wayland_init(gsr_window_wayland *self) {
|
||||
wl_display_roundtrip(self->display);
|
||||
|
||||
gsr_window_wayland_set_monitor_outputs_from_xdg_output(self);
|
||||
gsr_window_wayland_set_monitor_real_positions(self);
|
||||
|
||||
if(!self->compositor) {
|
||||
fprintf(stderr, "gsr error: gsr_window_wayland_init failed: failed to find compositor\n");
|
||||
@@ -337,6 +376,16 @@ static gsr_monitor_rotation wayland_transform_to_gsr_rotation(int32_t rot) {
|
||||
return GSR_MONITOR_ROT_0;
|
||||
}
|
||||
|
||||
static vec2i get_monitor_size_rotated(int width, int height, gsr_monitor_rotation rotation) {
|
||||
vec2i size = { .x = width, .y = height };
|
||||
if(rotation == GSR_MONITOR_ROT_90 || rotation == GSR_MONITOR_ROT_270) {
|
||||
int tmp_x = size.x;
|
||||
size.x = size.y;
|
||||
size.y = tmp_x;
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
static void gsr_window_wayland_for_each_active_monitor_output_cached(const gsr_window *window, active_monitor_callback callback, void *userdata) {
|
||||
const gsr_window_wayland *self = window->priv;
|
||||
for(int i = 0; i < self->num_outputs; ++i) {
|
||||
@@ -344,15 +393,26 @@ static void gsr_window_wayland_for_each_active_monitor_output_cached(const gsr_w
|
||||
if(!output->name)
|
||||
continue;
|
||||
|
||||
const gsr_monitor_rotation rotation = wayland_transform_to_gsr_rotation(output->transform);
|
||||
|
||||
vec2i size = { .x = output->size.x, .y = output->size.y };
|
||||
size = get_monitor_size_rotated(size.x, size.y, rotation);
|
||||
|
||||
vec2i logical_size = { .x = output->logical_size.x, .y = output->logical_size.y };
|
||||
if(logical_size.x == 0 || logical_size.y == 0)
|
||||
logical_size = size;
|
||||
|
||||
const int connector_type_index = get_connector_type_by_name(output->name);
|
||||
const int connector_type_id = get_connector_type_id_by_name(output->name);
|
||||
const gsr_monitor monitor = {
|
||||
.name = output->name,
|
||||
.name_len = strlen(output->name),
|
||||
.pos = { .x = output->pos.x, .y = output->pos.y },
|
||||
.size = { .x = output->size.x, .y = output->size.y },
|
||||
.size = size,
|
||||
.logical_pos = { .x = output->pos.x, .y = output->pos.y },
|
||||
.logical_size = logical_size,
|
||||
.connector_id = 0,
|
||||
.rotation = wayland_transform_to_gsr_rotation(output->transform),
|
||||
.rotation = rotation,
|
||||
.monitor_identifier = (connector_type_index != -1 && connector_type_id != -1) ? monitor_identifier_from_type_and_count(connector_type_index, connector_type_id) : 0
|
||||
};
|
||||
callback(&monitor, userdata);
|
||||
|
||||
@@ -121,6 +121,8 @@ static void gsr_window_x11_for_each_active_monitor_output_cached(const gsr_windo
|
||||
.name_len = strlen(output->name),
|
||||
.pos = output->pos,
|
||||
.size = output->size,
|
||||
.logical_pos = output->pos,
|
||||
.logical_size = output->size,
|
||||
.connector_id = output->connector_id,
|
||||
.rotation = output->rotation,
|
||||
.monitor_identifier = output->monitor_identifier
|
||||
|
||||
Reference in New Issue
Block a user