Compare commits

..

25 Commits

Author SHA1 Message Date
Romain Vimont
3c2f81b161 Add support for AAC audio codec
Add option --audio-codec=aac.
2023-02-19 02:19:26 +01:00
Romain Vimont
5e2a08b328 Add option to select audio codec
Introduce the selection mechanism. Alternative codecs will be added
later.
2023-02-19 02:19:26 +01:00
Romain Vimont
ff36c1c680 Add --audio-bit-rate option
Add an option to configure the audio bit-rate.
2023-02-19 02:19:26 +01:00
Romain Vimont
1deefb1305 Remove default bit-rate on client side
If no bit-rate is passed, let the server use the default value (8Mbps).

This avoids to define a default value on both sides, and to pass the
default bit-rate as an argument when starting the server.
2023-02-19 02:19:26 +01:00
Romain Vimont
dd20172eed Record at least video packets on stop
If the recorder is stopped while it has not received any audio packet
yet, make sure the video stream is correctly recorded.
2023-02-19 02:19:26 +01:00
Romain Vimont
4b6508edd6 Disable audio on initialization error
By default, audio is enabled (--no-audio must be explicitly passed to
disable it).

However, some devices may not support audio capture (typically devices
below Android 11, or Android 11 when the shell application is not
foreground on start).

In that case, make the server notify the client to dynamically disable
audio forwarding so that it does not wait indefinitely for an audio
stream.

Also disable audio on unknown codec or missing decoder on the
client-side, for the same reasons.
2023-02-19 02:19:26 +01:00
Romain Vimont
07db9acba4 Add record audio support
Make the recorder accept two input sources (video and audio), and mux
them into a single file.
2023-02-19 02:13:04 +01:00
Romain Vimont
e891cd86b2 Rename video-specific variables in recorder
This paves the way to add audio-specific variables.
2023-02-19 02:13:04 +01:00
Romain Vimont
9bd3521d5c Do not merge config audio packets
For video streams (at least H.264 and H.265), the config packet
containing SPS/PPS must be prepended to the next packet (the following
keyframe).

For audio streams (at least OPUS), they must not be merged.
2023-02-19 02:13:04 +01:00
Romain Vimont
0ac2c5846f Add an audio demuxer
Add a demuxer which will read the stream from the audio socket.
2023-02-19 02:13:04 +01:00
Romain Vimont
e55de613a9 Give a name to demuxer instances
This will be useful in logs.
2023-02-19 02:13:02 +01:00
Romain Vimont
7bc3df83f0 Rename demuxer to video_demuxer
There will be another demuxer instance for audio.
2023-02-19 02:12:25 +01:00
Romain Vimont
b992a3fbe5 Extract OPUS extradata
For OPUS codec, FFmpeg expects the raw extradata, but MediaCodec wraps
it in some structure.

Fix the config packet to send only the raw extradata.
2023-02-19 02:12:25 +01:00
Romain Vimont
0b19079386 Use a streamer to send the audio stream
Send each encoded audio packet using a streamer.
2023-02-19 02:12:25 +01:00
Romain Vimont
1355ed6b33 Encode recorded audio in OPUS on the device
For now, the encoded packets are just logged in the console.
2023-02-19 02:12:25 +01:00
Simon Chan
0691f76929 Capture device audio
Create an AudioRecorder to capture the audio source REMOTE_SUBMIX.

For now, the captured packets are just logged in the console.

Co-authored-by: Romain Vimont <rom@rom1v.com>
Signed-off-by: Romain Vimont <rom@rom1v.com>
2023-02-19 02:12:25 +01:00
Simon Chan
668ccbf568 Add a new socket for audio stream
When audio is enabled, open a new socket to send the audio stream from
the device to the client.

Co-authored-by: Romain Vimont <rom@rom1v.com>
Signed-off-by: Romain Vimont <rom@rom1v.com>
2023-02-19 02:12:25 +01:00
Simon Chan
1795276cd8 Add --no-audio option
Audio will be enabled by default (when supported). Add an option to
disable it.

Co-authored-by: Romain Vimont <rom@rom1v.com>
Signed-off-by: Romain Vimont <rom@rom1v.com>
2023-02-19 02:12:25 +01:00
Romain Vimont
2ecfc36875 Use FakeContext for Application instance
This will expose the correct package name and UID to the application
context.
2023-02-19 02:12:25 +01:00
Romain Vimont
7db4fb538d Use shell package name for workarounds
For consistency.
2023-02-19 02:12:25 +01:00
Romain Vimont
95d9590dfa Use PACKAGE_NAME from FakeContext
Remove duplicated constant.
2023-02-19 02:12:25 +01:00
Romain Vimont
cae2a39def Use AttributionSource from FakeContext
FakeContext already provides an AttributeSource instance.

Co-authored-by: Simon Chan <1330321+yume-chan@users.noreply.github.com>
2023-02-19 02:12:25 +01:00
Simon Chan
72cd233a4e Add a fake Android Context
Since scrcpy-server is not an Android application (it's a java
executable), it has no Context.

Some features will require a Context instance to get the package name
and the UID. Add a FakeContext for this purpose.

Co-authored-by: Romain Vimont <rom@rom1v.com>
Signed-off-by: Romain Vimont <rom@rom1v.com>
2023-02-19 02:12:25 +01:00
Romain Vimont
bf5f10a96a Use Process.ROOT_UID
Replace ServiceManager.USER_ID by existing constant Process.ROOT_UID.
2023-02-19 02:12:25 +01:00
Romain Vimont
7a5a77818e Make streamer independent of codec type
Rename VideoStreamer to Streamer, and extract a Codec interface which
will also support audio codecs.
2023-02-19 02:12:25 +01:00
4 changed files with 5 additions and 8 deletions

View File

@@ -20,7 +20,7 @@ import java.util.concurrent.BlockingQueue;
public final class AudioEncoder {
private static class InputTask {
private final int index;
final int index;
InputTask(int index) {
this.index = index;
@@ -28,8 +28,8 @@ public final class AudioEncoder {
}
private static class OutputTask {
private final int index;
private final MediaCodec.BufferInfo bufferInfo;
final int index;
final MediaCodec.BufferInfo bufferInfo;
OutputTask(int index, MediaCodec.BufferInfo bufferInfo) {
this.index = index;

View File

@@ -2,10 +2,7 @@ package com.genymobile.scrcpy;
public interface Codec {
enum Type {
VIDEO,
AUDIO,
}
enum Type {VIDEO, AUDIO}
Type getType();

View File

@@ -159,7 +159,6 @@ public final class Server {
return thread;
}
@SuppressWarnings("MethodLength")
private static Options createOptions(String... args) {
if (args.length < 1) {
throw new IllegalArgumentException("Missing client version");

View File

@@ -2,6 +2,7 @@ package com.genymobile.scrcpy;
import android.annotation.SuppressLint;
import android.app.Application;
import android.app.Instrumentation;
import android.content.ContextWrapper;
import android.content.pm.ApplicationInfo;
import android.os.Looper;