Compare commits

..

26 Commits

Author SHA1 Message Date
Romain Vimont
e4108a311a Add support for AAC audio codec
Add option --audio-codec=aac.
2023-02-19 02:32:49 +01:00
Romain Vimont
430ecc36c1 Add option to select audio codec
Introduce the selection mechanism. Alternative codecs will be added
later.
2023-02-19 02:32:49 +01:00
Romain Vimont
1ad2abec1d Add --audio-bit-rate option
Add an option to configure the audio bit-rate.
2023-02-19 02:32:49 +01:00
Romain Vimont
c61f86af0b Disable MethodLength checkstyle on createOptions()
This method will grow as needed to initialize options.
2023-02-19 02:32:49 +01:00
Romain Vimont
8fe6d78070 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:32:49 +01:00
Romain Vimont
3f532ab5b5 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:32:49 +01:00
Romain Vimont
b006c6f3ef 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:32:49 +01:00
Romain Vimont
662615baa8 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:32:49 +01:00
Romain Vimont
0f92c17b62 Rename video-specific variables in recorder
This paves the way to add audio-specific variables.
2023-02-19 02:32:49 +01:00
Romain Vimont
9f4c16bc77 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:32:49 +01:00
Romain Vimont
5e964c7cb9 Add an audio demuxer
Add a demuxer which will read the stream from the audio socket.
2023-02-19 02:32:49 +01:00
Romain Vimont
90c2ce8885 Give a name to demuxer instances
This will be useful in logs.
2023-02-19 02:32:49 +01:00
Romain Vimont
98d4e64a0f Rename demuxer to video_demuxer
There will be another demuxer instance for audio.
2023-02-19 02:32:49 +01:00
Romain Vimont
f9cbd8726f 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:32:49 +01:00
Romain Vimont
101d7908b2 Use a streamer to send the audio stream
Send each encoded audio packet using a streamer.
2023-02-19 02:32:49 +01:00
Romain Vimont
c1a4c91c51 Encode recorded audio on the device
For now, the encoded packets are just logged in the console.
2023-02-19 02:32:17 +01:00
Simon Chan
5865b5f9b4 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:32:17 +01:00
Simon Chan
6ff4c92f3e 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:32:17 +01:00
Simon Chan
d9e5356586 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:32:17 +01:00
Romain Vimont
60b39cdda5 Use FakeContext for Application instance
This will expose the correct package name and UID to the application
context.
2023-02-19 02:32:17 +01:00
Romain Vimont
b581fd78c1 Use shell package name for workarounds
For consistency.
2023-02-19 02:32:17 +01:00
Romain Vimont
97d773524c Use PACKAGE_NAME from FakeContext
Remove duplicated constant.
2023-02-19 02:32:17 +01:00
Romain Vimont
6b396f8297 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:32:17 +01:00
Simon Chan
6b9365e71b 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:32:17 +01:00
Romain Vimont
be6ec050b3 Use Process.ROOT_UID
Replace ServiceManager.USER_ID by existing constant Process.ROOT_UID.
2023-02-19 02:32:17 +01:00
Romain Vimont
5782bb8743 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:32:17 +01:00
4 changed files with 8 additions and 5 deletions

View File

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

View File

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

View File

@@ -159,6 +159,7 @@ 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,7 +2,6 @@ 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;