Commit Graph

2084 Commits (f1b2d6bbbb5afd1f95913a49b94eda7cfb85226b)
 

Author SHA1 Message Date
Romain Vimont f1b2d6bbbb Bump version to 2.0 1 year ago
Romain Vimont 90926d40ad Merge branch 'master' into dev 1 year ago
Romain Vimont f12590ed08 Rework README and documentation
The README.md page is HUGE. Split it up.

Also document audio forwarding and improve installation instructions for
each platform and user documentation.

PR #3774 <https://github.com/Genymobile/scrcpy/pull/3774>
1 year ago
Romain Vimont 05a55e3687 Happy new year 2023! 1 year ago
Romain Vimont affda26bfa Document audio player
Add some high-level documentation on the audio player implementation.
1 year ago
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.
1 year ago
Romain Vimont 73727e7fdf Disable clock drift compensation for tiny values
For less than 1ms, the estimated drift is just noise.
1 year ago
Romain Vimont c22c87eded Fail on deprecated options
Suggest the video and audio specific options instead.
1 year ago
Romain Vimont 426dfbf21d Remove dead code about the deprecated -F option
The -F option was already removed.
1 year ago
Romain Vimont 5512777404 Remove deprecated option --render-expired-frames
This option did nothing since it was deprecated. Totally remove it.
1 year ago
Romain Vimont cc07f8dac4 Upgrade platform-tools (34.0.1) for Windows
Include the latest version of adb in Windows releases.
1 year ago
Romain Vimont f5bb9e576d Upgrade SDL (2.26.4) for Windows
Include the latest version of SDL in Windows releases.
1 year ago
Romain Vimont 2380879376 Remove unused IOException
IOException may not be thrown from this method.
1 year ago
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.
1 year ago
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).
1 year ago
Romain Vimont e06acc1ba2 Simplify bytebuf naming
Rename read_available to can_read and write_available to can_write.
This is more readable.
1 year ago
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.
1 year ago
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.
1 year ago
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.
1 year ago
Romain Vimont 3a72f3fb4d Report errors on screen event error
Make scrcpy fail if an important screen event (like frame update) fails.
1 year ago
Romain Vimont aa1efbc35c Rename sendCodecId to sendCodecMeta
This will allow the codec header to contain more than the codec id.
1 year ago
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.
1 year ago
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.
1 year ago
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).
1 year ago
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.
1 year ago
Romain Vimont 4db50ddbb7 Enable log signaling buffering threshold exceeded
It is as important as underflow logs.
1 year ago
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.
1 year ago
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>
1 year ago
Romain Vimont 408f458636 Decrease recorder thread priority
Recording is background task, writing the packets to a file is not
urgent.
1 year ago
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.
1 year ago
Romain Vimont 5ee59e0f13 Add thread priority API
Expose an API to change the priority of the current thread.
1 year ago
Romain Vimont 4a25f3e53b Print info logs to stdout
All server logs were printed to stdout, while all client logs were
printed to stderr.

Instead, use stderr for warnings and errors, stdout for the others:
 - stdout: verbose, debug, info
 - stderr: warn, error
1 year ago
Romain Vimont bb56472d4e Print server logs and newline in one call
System.out.println() first prints the message, then the new line.
Between these two calls, the client might print a message, breaking
formatting.

Instead, call System.out.print() with '\n' appended to the message.
1 year ago
Romain Vimont 7da45c246e Warn on ignored audio options
For raw audio codec, some audio options are ignored.

PR #3757 <https://github.com/Genymobile/scrcpy/pull/3757>
1 year ago
Romain Vimont d2952c7e93 Add --audio-codec=raw option
Add support for raw (PCM S16 LE) audio codec (a raw decoder is included
in FFmpeg).

PR #3757 <https://github.com/Genymobile/scrcpy/pull/3757>
1 year ago
Romain Vimont 66b6c06443 Add raw audio recorder
Add an alternative AudioRecorder to stream raw packets without encoding.

PR #3757 <https://github.com/Genymobile/scrcpy/pull/3757>
1 year ago
Romain Vimont dc228eaad0 Extract async processor interface
On the server side, several components are started, stopped and joined.
Extract an interface to handle them generically.

This will help to support both encoded and raw audio stream, because
they will be two different concrete components, but implementing the
same interface.

PR #3757 <https://github.com/Genymobile/scrcpy/pull/3757>
1 year ago
Romain Vimont 65cc9d765d Extract audio capture
The audio capture was implemented in AudioEncoder.

In order to reuse it without encoding, extract it to a separate class.

PR #3757 <https://github.com/Genymobile/scrcpy/pull/3757>
1 year ago
Romain Vimont 02dd1be4a1 Stop on decoder frame push error
On push, frame sinks report downstream errors to stop upstream
components. Do not ignore the error.
1 year ago
Romain Vimont df55bc2683 Add --audio-buffer
Expose an option to add a buffering delay (in milliseconds) before
playing audio.

This is similar to the options --display-buffer and --v4l2-buffer for
video frames.

PR #3757 <https://github.com/Genymobile/scrcpy/pull/3757>
1 year ago
Romain Vimont d66b0b3dcc Add compat support for FFmpeg < 5.1
The new chlayout API has been introduced in FFmpeg 5.1. Use the old
channel_layout API on older versions.

PR #3757 <https://github.com/Genymobile/scrcpy/pull/3757>
1 year ago
Romain Vimont fbe0f951e1 Add audio player
Play the decoded audio using SDL.

The audio player frame sink receives the audio frames, resample them
and write them to a byte buffer (introduced by this commit).

On SDL audio callback (from an internal SDL thread), copy samples from
this byte buffer to the SDL audio buffer.

The byte buffer is protected by the SDL_AudioDeviceLock(), but it has
been designed so that the producer and the consumer may write and read
in parallel, provided that they don't access the same slices of the
ring-buffer buffer.

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

Co-authored-by: Simon Chan <1330321+yume-chan@users.noreply.github.com>
1 year ago
Romain Vimont e1333f6f3b Optionally do not delay the first frame
A delay buffer delayed all the frames except the first one, to open the
scrcpy window immediately and get a picture.

Make this feature optional, so that the delay buffer might also be used
for audio (especially for simulating a high delay for debugging).

PR #3757 <https://github.com/Genymobile/scrcpy/pull/3757>
1 year ago
Romain Vimont 9b3ca208bf Accept clock estimation with a single point
If there is only one point, assume the slope is 1.

PR #3757 <https://github.com/Genymobile/scrcpy/pull/3757>
1 year ago
Romain Vimont 48a537d45c Remove anonymous struct in delay buffer
For clarity, the fields used only when a delay was set were wrapped in
an anonymous structure.

Now that the delay buffer has been extracted to a separate component,
the delay is necessarily set (it may not be 0), so the fields are always
used.

PR #3757 <https://github.com/Genymobile/scrcpy/pull/3757>
1 year ago
Romain Vimont 1230149fdd Use delay buffer as a frame source/sink
The components needing delayed frames (sc_screen and sc_v4l2_sink)
managed a sc_video_buffer instance, which itself embedded a
sc_frame_buffer instance (to keep only the most recent frame).

In theory, these components should not be aware of delaying: they should
just receive AVFrames later, and only handle a sc_frame_buffer.

Therefore, refactor sc_delay_buffer as a frame source (it consumes)
frames) and a frame sink (it produces frames, after some delay), and
plug an instance in the pipeline only when a delay is requested.

This also removes the need for a specific sc_video_buffer.

PR #3757 <https://github.com/Genymobile/scrcpy/pull/3757>
1 year ago
Romain Vimont 974227a3fc Use frame source trait in decoder 1 year ago
Romain Vimont 6543964f12 Introduce frame source trait
There was a frame sink trait, implemented by components able to receive
AVFrames, but each frame source had to manually send frame to sinks.

In order to mutualise sink management, add a frame sink trait.
1 year ago
Romain Vimont f3197e178d Use packet source trait in demuxer 1 year ago
Romain Vimont c39054a63d Introduce packet source trait
There was a packet sink trait, implemented by components able to
receive AVPackets, but each packet source had to manually send packets
to sinks.

In order to mutualise sink management, add a packet source trait.
1 year ago