Commit graph

1391 commits

Author SHA1 Message Date
Romain Vimont
98f4f4e68a Refactor command line checks
Several checks are performed when opts->record_filename is not NULL.
Group them in a single block.

PR #3978 <https://github.com/Genymobile/scrcpy/pull/3978>
2023-05-08 17:11:34 +02:00
Romain Vimont
be86e14e05 Factorize record format parsing
Convert either the filename extension or the explicit record format
to a sc_record_format using the same function.

PR #3978 <https://github.com/Genymobile/scrcpy/pull/3978>
2023-05-08 17:11:34 +02:00
Romain Vimont
8c650e53cd Add --no-video
Similar to --no-audio, add --no-video to play audio only.

Fixes #3842 <https://github.com/Genymobile/scrcpy/issues/3842>
PR #3978 <https://github.com/Genymobile/scrcpy/pull/3978>
2023-05-08 17:11:34 +02:00
Romain Vimont
e89e772c7c Remove unnecessary 'else'
Some server parameters may depend on one another. For example,
audio_bit_rate is meaningless if audio is false.

But it is inconsistent to disable some parameters based on these
dependencies checks, but not others. Handling all dependencies between
parameters would add too much complexity for no benefit.

So just pass individual parameters independently.

PR #3978 <https://github.com/Genymobile/scrcpy/pull/3978>
2023-05-08 16:41:12 +02:00
Romain Vimont
92483fe11b Disable controls on --no-mirror
If mirroring is disabled, control must also be disabled.

PR #3978 <https://github.com/Genymobile/scrcpy/pull/3978>
2023-05-08 16:41:01 +02:00
Romain Vimont
6928acdeac Rename --no-display to --no-mirror
The option impacts both video and audio playback, so "no display" is not
an appropriate name.

PR #3978 <https://github.com/Genymobile/scrcpy/pull/3978>
2023-05-08 16:40:58 +02:00
Romain Vimont
0f3af2d20b Fix build for FFmpeg < 3.3
The constant AV_CODEC_ID_AV1 was introduced in FFmpeg 3.3. Add an ifdef
to support older versions.

Fixes #3939 <https://github.com/Genymobile/scrcpy/issues/3939>
2023-04-23 12:26:46 +02:00
Yan
c083a7cc90 Force OpenGL Core Profile context on macOS
By default, SDL creates an OpenGL 2.1 context on macOS for an OpenGL
renderer. As a consequence, mipmapping is not supported.

Force to use a core profile context, to get a higher version.

Before:

    INFO: Renderer: opengl
    INFO: OpenGL version: 2.1 NVIDIA-14.0.32 355.11.11.10.10.143
    WARN: Trilinear filtering disabled (OpenGL 3.0+ or ES 2.0+ required)

After:

    INFO: Renderer: opengl
    DEBUG: Creating OpenGL Core Profile context
    INFO: OpenGL version: 4.1 NVIDIA-14.0.32 355.11.11.10.10.143
    INFO: Trilinear filtering enabled

when running with:

    scrcpy --verbosity=debug --render-driver=opengl

Note: Since SDL_CreateRenderer() causes a fallback to OpenGL 2.1, the
profile and version attributes have to be set and the context created
_after_.

PR #3895 <https://github.com/Genymobile/scrcpy/pull/3895>

Signed-off-by: Romain Vimont <rom@rom1v.com>
2023-04-12 21:26:24 +02:00
Romain Vimont
9eb6591913 Add missing --no-audio option in manpage 2023-04-10 19:30:04 +02:00
Romain Vimont
051b74c883 Extract sc_display from sc_screen
Move the display code to a separate component.
2023-04-06 19:48:26 +02:00
Romain Vimont
2e532afd2b Pass const pointers to events
SDL_Events are only read.
2023-04-06 19:48:01 +02:00
Romain Vimont
669e9a8d1e Fix "ip route" parsing
If a line did not end with '\r', then the final `\n' was replaced by
'\0' for parsing the current line. This `\0` was then mistakenly
considered as the end of the whole "ip route" output, so the remaining
lines were not parsed, causing "scrcpy --tcpip" to fail in some cases.

To fix the issue, read the final character of the current line before it
is (possibly) overwritten by '\0'.
2023-04-02 19:30:23 +02:00
Romain Vimont
2f9396e24a Simplify clock estimation
The slope encodes the drift between the device clock and the computer
clock. Its real value is expected very close to 1.

To estimate it, just assume it is exactly 1.

Since the clock is used to estimate very close points in the future, the
error caused by clock drift is totally negligible, and in practice it is
way lower than the slope estimation error.

Therefore, only estimate the offset.
2023-03-30 20:58:33 +02:00
Yan
0ebb3df69c Fix debug build by adding compat.c to tests
Linking of tests that needed something from compat.c failed.

PR #3865 <https://github.com/Genymobile/scrcpy/pull/3865>

Signed-off-by: Romain Vimont <rom@rom1v.com>
2023-03-27 15:28:59 +02:00
sixg0000d
53cb5635cf Fix pause message
The pause terminates only once the Enter key is pressed, not any key.

PR #3826 <https://github.com/Genymobile/scrcpy/pull/3826>

Signed-off-by: Romain Vimont <rom@rom1v.com>
2023-03-16 18:21:00 +01:00
Romain Vimont
39544f34b4 Add --audio-output-buffer
On some systems, the SDL audio callback is not called frequently enough
(for example it requests 5ms of samples every 10ms), because the output
buffer is too small.

By default, we want to use a small value (5ms) to minimize latency and
buffer underrun, but if it does not work well, users need a way to
increase it.

Refs #3793 <https://github.com/Genymobile/scrcpy/issues/3793>
2023-03-14 23:54:07 +01:00
Romain Vimont
4755b97908 Fix bash auto-completion handling
Options having an argument impossible to auto-complete must be handled
separately.
2023-03-14 23:51:48 +01:00
Romain Vimont
cba2501254 Add missing auto-completion for --audio-buffer 2023-03-14 23:41:06 +01:00
Bernard Cafarelli
d2b7315ba6 Fix linux desktop files validation
Follow quoting rules from:
<https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html#exec-variables>

PR #3817 <https://github.com/Genymobile/scrcpy/pull/3817>
Fixes #3633 <https://github.com/Genymobile/scrcpy/issues/3633>

Signed-off-by: Romain Vimont <rom@rom1v.com>
2023-03-14 23:15:09 +01:00
Romain Vimont
cbca79b95b Fix v4l2 sink
The codec id to write as codec parameters is the one from the v4l2
encoder, not from the decoder.

Regression introduced by be985b8242.

Fixes #3795 <https://github.com/Genymobile/scrcpy/issues/3795>
2023-03-12 12:45:49 +01:00
Romain Vimont
02586cf21f Fix build issue on FFmpeg < 5.1
An include was missing.

Fixes #3783 <https://github.com/Genymobile/scrcpy/issues/3783>
2023-03-12 08:54:42 +01:00
Romain Vimont
80a6fa7a01 Fix comparison warning
An int was compared with an unsigned:

    ../app/src/audio_player.c:290:27: warning: comparison of integers of
    different signs: 'int' and 'unsigned int' [-Wsign-compare]
                if (abs(diff) < ap->sample_rate / 1000) {
                    ~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~
2023-03-12 08:37:08 +01:00
Ruoyu Zhong
6b769675fa Fix an "expected expression" error
In C, a label can only be followed by a statement, not a declaration.
An error in `app/src/screen.c` violated this, and led to a build error
with an error message similar to the one below:

    ../app/src/screen.c:821:13: error: expected expression
                bool ok = sc_screen_init_size(screen);
                ^
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/13.0.0/include/stdbool.h:15:14: note: expanded from macro 'bool'
    #define bool _Bool
                 ^
    ../app/src/screen.c:822:18: error: use of undeclared identifier 'ok'
                if (!ok) {
                     ^
    2 errors generated.

This could be fixed by introducing a new block (or compound statement;
as is already being done in the next `case`). That is a statement.

Fixes #3785 <https://github.com/Genymobile/scrcpy/issues/3785>
PR #3787 <https://github.com/Genymobile/scrcpy/pull/3787>

Signed-off-by: Ruoyu Zhong <zhongruoyu@outlook.com>
Signed-off-by: Romain Vimont <rom@rom1v.com>
2023-03-12 08:26:17 +01:00
Romain Vimont
f1b2d6bbbb Bump version to 2.0 2023-03-12 02:05:37 +01:00
Romain Vimont
05a55e3687 Happy new year 2023! 2023-03-12 02:04:58 +01:00
Romain Vimont
affda26bfa Document audio player
Add some high-level documentation on the audio player implementation.
2023-03-12 02:04:58 +01:00
Romain Vimont
0bf866fa8d Apply new compensation only if it changed
If the compensation is the same (typically when it is 0), do not reapply
it.
2023-03-12 02:04:58 +01:00
Romain Vimont
73727e7fdf Disable clock drift compensation for tiny values
For less than 1ms, the estimated drift is just noise.
2023-03-12 02:04:58 +01:00
Romain Vimont
c22c87eded Fail on deprecated options
Suggest the video and audio specific options instead.
2023-03-12 02:04:58 +01:00
Romain Vimont
426dfbf21d Remove dead code about the deprecated -F option
The -F option was already removed.
2023-03-12 02:04:58 +01:00
Romain Vimont
5512777404 Remove deprecated option --render-expired-frames
This option did nothing since it was deprecated. Totally remove it.
2023-03-12 02:04:58 +01:00
Romain Vimont
cc07f8dac4 Upgrade platform-tools (34.0.1) for Windows
Include the latest version of adb in Windows releases.
2023-03-12 02:04:58 +01:00
Romain Vimont
f5bb9e576d Upgrade SDL (2.26.4) for Windows
Include the latest version of SDL in Windows releases.
2023-03-12 02:04:58 +01:00
Romain Vimont
eca8766545 Compute buffering and compensation without lock
Once underflow has been read with a lock, the buffering and compensation
may be performed without shared variables.
2023-03-12 02:04:58 +01:00
Romain Vimont
0b8a5ca923 Do not read avg_buffering from the player thread
On buffer underflow, the average buffering must be updated, but it is
intended to be accessed only from the receiver thread.

Make the player and the receiver thread communicate the underflow via a
new field (ap->underflow).
2023-03-12 02:04:58 +01:00
Romain Vimont
e06acc1ba2 Simplify bytebuf naming
Rename read_available to can_read and write_available to can_write.
This is more readable.
2023-03-12 02:04:57 +01:00
Romain Vimont
14f9d82fda Add audio sample ring-buffer
Add a thin wrapper around bytebuf to handle samples instead of bytes.
This simplifies the audio player, which mostly handles samples.
2023-03-12 02:04:07 +01:00
Romain Vimont
bb509d9317 Define the audio output buffer in milliseconds
In theory, this buffer must be dimensioned for a target duration, so its
size in bytes should depend on the sample rate.
2023-03-11 15:57:25 +01:00
Romain Vimont
238ab872ba Pass video size as codec metadata
On initial connection, scrcpy sent some device metadata:
 - the device name (to be used as window title)
 - the initial video size (before any frame or even SPS/PPS)

But it is better to provide the initial video size as part as the video
stream, so that it can be demuxed and exposed via AVCodecContext to
sinks.

This avoids to pass an explicit "initial frame size" for the screen, the
recorder and the v4l2 sink.
2023-03-11 15:57:25 +01:00
Romain Vimont
3a72f3fb4d Report errors on screen event error
Make scrcpy fail if an important screen event (like frame update) fails.
2023-03-11 15:57:25 +01:00
Romain Vimont
be985b8242 Copy codec parameters from context
Now that the recorder have access to the codec context, it may
automatically initialize the stream codec parameters.

The V4L2 sink could do the same.
2023-03-11 15:57:25 +01:00
Romain Vimont
a9f6001f51 Simplify recorder
After the refactor performed by the previous commit, the functions to
wait the video stream and the audio stream could be inlined.
2023-03-11 15:57:25 +01:00
Romain Vimont
5052e15f7f Create recorder streams from packet sinks ops
Previously, the packet sink push() implementation just set the codec and
notified a wait condition. Then the recorder thread read the codec and
created the AVStream.

But this was racy: an AVFrame could be pushed before the creation of the
AVStream, causing its video_stream_index or audio_stream_index to be
initialized to -1.

Also, in the future, the AVStream initialization might need data
provided by the packet sink open(), so initialize it there (with a
mutex).
2023-03-11 15:57:25 +01:00
Romain Vimont
4bdf632dfa Pass AVCodecContext to packet sinks
Create the codec context from the demuxer, so that it can fill context
data for the decoder and recorder.
2023-03-11 15:57:25 +01:00
Romain Vimont
4db50ddbb7 Enable log signaling buffering threshold exceeded
It is as important as underflow logs.
2023-03-11 15:55:44 +01:00
Romain Vimont
46f6918179 Stop and join sc_file_pusher only if initialized
The sc_file_pusher is lazy-initialized, but it was stopped and joined in
all cases (accessing uninitialized values).

Detected by poisoning the struct scrcpy instance with ASAN enabled.
2023-03-10 22:45:48 +01:00
chengjian.scj
d93582724d Initialize interrupted field explicitly
The field sc_fps_counter.interrupted was never initialized explicitly.

Signed-off-by: Romain Vimont <rom@rom1v.com>
2023-03-10 22:33:52 +01:00
Romain Vimont
408f458636 Decrease recorder thread priority
Recording is background task, writing the packets to a file is not
urgent.
2023-03-10 22:22:16 +01:00
Romain Vimont
aa450ffc3f Increase audio thread priority
The audio demuxer thread is the one filling the audio buffer read by the
SDL audio thread. It is time critical to avoid buffer underflow.
2023-03-10 22:22:16 +01:00
Romain Vimont
5ee59e0f13 Add thread priority API
Expose an API to change the priority of the current thread.
2023-03-10 22:22:16 +01:00