Commit Graph

1274 Commits (3c407773e9ddf9debd1de71ff0d12f571bd36718)

Author SHA1 Message Date
Romain Vimont 3c407773e9 Add start() function for recorder
For consistency with the other components, do not start the internal
thread from an init() function.
2 years ago
Romain Vimont a039124d5d Open recording file from the recorder thread
The recorder opened the target file from the packet sink open()
callback, called by the demuxer. Only then the recorder thread was
started.

One golden rule for the recorder is to never block the demuxer for I/O,
because it would impact mirroring. This rule is respected on recording
packets, but not for the initial recorder opening.

Therefore, start the recorder thread from sc_recorder_init(), open the
file immediately from the recorder thread, then make it wait for the
stream to start (on packet sink open()).

Now that the recorder can report errors directly (rather than making the
demuxer call fail), it is possible to report file opening error even
before the packet sink is open.
2 years ago
Romain Vimont 6b5dfef923 Inline packet_sink impl in recorder
Remove useless wrappers.
2 years ago
Romain Vimont fb29135591 Initialize recorder fields from init()
The recorder has two initialization phases: one to initialize the
concrete recorder object, and one to open its packet_sink trait.

Initialize mutex and condvar as part of the object initialization.

If there were several packet_sink traits (spoiler: one for video, one
for audio), then the mutex and condvar would still be initialized only
once.
2 years ago
Romain Vimont b1b33e3eaf Report recorder errors
Stop scrcpy on recorder errors.

It was previously indirectly stopped by the demuxer, which failed to
push packets to a recorder in error. Report it directly instead:
 - it avoids to wait for the next demuxer call;
 - it will allow to open the target file from a separate thread and stop
   immediately on any I/O error.
2 years ago
Romain Vimont db5751a76a Move previous packet to a local variable
It is only used from run_recorder().
2 years ago
Romain Vimont b6744e7887 Move pts_origin to a local variable
It is only used from run_recorder().
2 years ago
Romain Vimont 181fb555bb Change PTS origin type from uint64_t to int64_t
It is initialized from AVPacket.pts, which is an int64_t.
2 years ago
Romain Vimont fa99763668 Fix --encoder documentation
Mention that it depends on the codec provided by --codec (which is not
necessarily H264 anymore).
2 years ago
Romain Vimont 9f8e96e895 Fix --no-clipboard-autosync bash completion
Fix typo.
2 years ago
Romain Vimont c78254fcd1 Split server stop() and join()
For consistency with the other components, call stop() and join()
separately.

This allows to stop all components, then join them all.
2 years ago
Romain Vimont e30e692b36 Print FFmpeg logs
FFmpeg logs are redirected to a specific SDL log category.

Initialize the log level for this category to print them as expected.
2 years ago
Romain Vimont 10e8295aea Move FFmpeg callback initialization
Configure FFmpeg log redirection on start from a log helper.
2 years ago
Romain Vimont f30fd963a1 Upgrade FFmpeg custom builds for Windows
Use a build which includes the pcm_s16le decoder, to support RAW audio.

Refs <https://github.com/rom1v/scrcpy-deps/commits/6.0-scrcpy-2>
2 years ago
Romain Vimont 9d60d7880b Upgrade FFmpeg (6.0) for Windows
Use the latest version (specifically built for scrcpy).

Refs <https://www.ffmpeg.org/download.html#release_6.0>
2 years ago
Romain Vimont 0fc62bfcd6 Use minimal prebuilt FFmpeg for Windows
On the scrcpy-deps repo, I built FFmpeg 5.1.2 binaries for Windows with
only the features used by scrcpy.

For comparison, here are the sizes of the dll for FFmpeg 5.1.2:
 - before: 89M
 - after: 4.7M

It also allows to upgrade the old FFmpeg version (4.3.1) used for win32.

Refs <https://github.com/rom1v/scrcpy-deps>
Refs <https://github.com/Genymobile/scrcpy/issues/1753>
2 years ago
Romain Vimont a20615066d Simplify libusb prebuilt scripts
In theory, include/ might be slightly different for win32 and win64
builds. Use each one separately to simplify.
2 years ago
Romain Vimont b5d41ad4f6 Fix useless garbage initialization
The variable `p` was initialized with a garbage value (a `const char **`
casted to `char *`). Fortunately, it was never read.

Refs <https://github.com/Genymobile/scrcpy/issues/3765>
2 years ago
Romain Vimont 389dd77b50 Fix MIN/MAX macros
Expressions like "x < MAX(y, z)" were broken.
2 years ago
Romain Vimont 3c3c07db05 Initialize server->serial in all cases
Running scrcpy --tcpip on a device already connected via TCP/IP did not
initialize server->serial.

As a consequence, in debug mode, an assertion failed:

    scrcpy: ../app/src/server.c:770: run_server: Assertion
    `server->serial' failed.

In release mode, scrcpy failed with this error:

    adb: -s requires an argument
2 years ago
Romain Vimont 6b422e21bf Fix error message on icon loading failure 2 years ago
Romain Vimont 8e8b039a63 Do not use avformat network
Scrcpy does not use FFmpeg network features. Initialize network locally
instead (useful only for Windows).

The include block has been moved to fix the following warning:

    Please include winsock2.h before windows.h
2 years ago
Romain Vimont 0702be86d8 Accept Windows Sockets from version 1.1
Version 2.2 is probably not necessary (1.1 is the version required by
FFmpeg when network is enabled).

Refs <891ed24f77/libavformat/network.c (L63)>
Refs <https://learn.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-wsastartup>
2 years ago
Romain Vimont 0cea7fb24c Fix WSAStartup() error check on Windows 2 years ago
Romain Vimont 3d10fbd9b4 Fix --bit-rate option in bash completion script
The option is --bit-rate, not --bitrate.
2 years ago
Romain Vimont 3e3756a323 Add auto-completion for --codec option
Add missing command to bash and zsh completion scripts.
2 years ago
Romain Vimont 5d6bcc5966 Use enum for long options constants
This avoids to manually assign values.
2 years ago
Romain Vimont 5973d4cdd7 Initialize mouse_input_mode explicitly
The explicit initialization was missing. It had no consequences because
SC_MOUSE_INPUT_MODE_INJECT == 0.

Fixes #3749 <https://github.com/Genymobile/scrcpy/issues/3749>
2 years ago
Romain Vimont 0a151b96fe Accept muxing AV1 into MP4 container
MP4 supports AV1.

Refs d2dce51038
2 years ago
Romain Vimont e02f30f895 Remove unnecessary error logs
When a call to a packet or frame sink fails, do not log the error on the
caller side: either the "failure" is expected (explicitly stopped) or it
must be logged by the packet or frame sink implementation.
2 years ago
Romain Vimont 25e2eb7d7c Document default video codec
Mention the default option value, like for other commands.
2 years ago
Romain Vimont 280a9afda8 Fix command-line help typo 2 years ago
Romain Vimont e91618586c Prefix receiver by sc_
Like all other components in scrcpy.
2 years ago
Romain Vimont 680ddf64be Fix demuxer error message
Now that there are several possible codecs, do not hardcode H.264 in the
error message.

Refs 3e517cd40e
2 years ago
Romain Vimont 439a1fd4ed Rename 'uid' to 'scid'
A random identifier is generated to differentiate multiple running
scrcpy instances. Rename it from 'uid' to 'scid' (scrcpy id) not to
confuse it with Linux UID.

Fixes #3729 <https://github.com/Genymobile/scrcpy/issues/3729>
Refs 4315be1648
2 years ago
Romain Vimont 49eb326ce9 Extract packet merging
Config packets must be prepended to the next media packet. Extract the
logic to a new sc_packet_merger helper to simplify the demuxer code.
2 years ago
Romain Vimont f03f32267e Remove unused parser
Since 1c02b58412, the parser is not used
anymore.
2 years ago
Romain Vimont 730eb1086a Properly report demuxer errors
All demuxer errors were reported as "device disconnected", even if the
failure was not related to device socket read.
2 years ago
Romain Vimont 4f9e9c6619 Prefix UI events constants by SC_ 2 years ago
Romain Vimont 953edfd1df Split codec_id reading
Receive codec id and convert it to AVCodecID separately.

This will allow the caller to distinguish between EOS and unknown codec
id.
2 years ago
Romain Vimont 230b8274b9 Fix error return value
The function returns an enum AVCodecID, not a bool.
2 years ago
Romain Vimont 40866ddc10 Fix demuxer error message
The message applies to all packets, not only config packets.
2 years ago
Romain Vimont bd56c0abf7 Remove unused codec context
The demuxer does not need any codec context.
2 years ago
Romain Vimont d2dce51038 Add support for AV1
Add option --codec=av1.

PR #3713 <https://github.com/Genymobile/scrcpy/pull/3713>
2 years ago
Romain Vimont 4342c5637d Add support for H265
Add option --codec=h265.

PR #3713 <https://github.com/Genymobile/scrcpy/pull/3713>
Fixes #3092 <https://github.com/Genymobile/scrcpy/issues/3092>
2 years ago
Romain Vimont 3e517cd40e Add option to select video codec
Introduce the selection mechanism. Alternative codecs will be added in
further commits.

PR #3713 <https://github.com/Genymobile/scrcpy/pull/3713>
2 years ago
Romain Vimont f70f6cdd3e Simplify server info initialization
Use sc_read16be() to read 16-bit integer fields.
2 years ago
Romain Vimont 1c82c3923d Compute relative PTS on the client-side
The PTS received from MediaCodec are expressed relative to an arbitrary
clock origin. We consider the PTS of the first frame to be 0, and the
PTS of every other frame is relative to this first PTS (note that the
PTS is only used for recording, it is ignored for mirroring).

For simplicity, this relative PTS was computed on the server-side.

To prepare support for multiple stream (video and audio), send the
packet with its original PTS, and handle the PTS offset on the
client-side (by the recorder).

Since we can't know in advance which stream will produce the first
packet with the lowest PTS (a packet received later on one stream may
have a PTS lower than a packet received earlier on another stream),
computing the PTS on the server-side would require unnecessary waiting.
2 years ago
Romain Vimont 6a07e3d470 Fix manpage formatting
Only the option arguments must be underlined.
2 years ago
Simon Chan 0afef0c634 Forward action button to device
On click event, only the whole buttons state was passed to the device.
In addition, on ACTION_DOWN and ACTION_UP, pass the button associated to
the action.

Refs #3635 <https://github.com/Genymobile/scrcpy/issues/3635>

Co-authored-by: Romain Vimont <rom@rom1v.com>
Signed-off-by: Romain Vimont <rom@rom1v.com>
2 years ago