mirror of
https://github.com/Genymobile/scrcpy.git
synced 2025-12-17 21:44:20 +01:00
Quit on audio configuration failure
When audio capture fails on the device, scrcpy continues mirroring the video stream. This allows to enable audio by default only when supported. However, if an audio configuration occurs (for example the user explicitly selected an unknown audio encoder), this must be treated as an error and scrcpy must exit. PR #3757 <https://github.com/Genymobile/scrcpy/pull/3757>
This commit is contained in:
@@ -222,7 +222,7 @@ public final class AudioEncoder {
|
||||
public void encode() throws IOException, ConfigurationException {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {
|
||||
Ln.w("Audio disabled: it is not supported before Android 11");
|
||||
streamer.writeDisableStream();
|
||||
streamer.writeDisableStream(false);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -279,9 +279,13 @@ public final class AudioEncoder {
|
||||
outputThread.start();
|
||||
|
||||
waitEnded();
|
||||
} catch (ConfigurationException e) {
|
||||
// Notify the error to make scrcpy exit
|
||||
streamer.writeDisableStream(true);
|
||||
throw e;
|
||||
} catch (Throwable e) {
|
||||
// Notify the client that the audio could not be captured
|
||||
streamer.writeDisableStream();
|
||||
streamer.writeDisableStream(false);
|
||||
throw e;
|
||||
} finally {
|
||||
// Cleanup everything (either at the end or on error at any step of the initialization)
|
||||
|
||||
@@ -40,10 +40,15 @@ public final class Streamer {
|
||||
}
|
||||
}
|
||||
|
||||
public void writeDisableStream() throws IOException {
|
||||
// Writing 0 (32-bit) as codec-id means that the device disables the stream (because it could not capture)
|
||||
byte[] zeros = new byte[4];
|
||||
IO.writeFully(fd, zeros, 0, zeros.length);
|
||||
public void writeDisableStream(boolean error) throws IOException {
|
||||
// Writing a specific code as codec-id means that the device disables the stream
|
||||
// code 0: it explicitly disables the stream (because it could not capture audio), scrcpy should continue mirroring video only
|
||||
// code 1: a configuration error occurred, scrcpy must be stopped
|
||||
byte[] code = new byte[4];
|
||||
if (error) {
|
||||
code[3] = 1;
|
||||
}
|
||||
IO.writeFully(fd, code, 0, code.length);
|
||||
}
|
||||
|
||||
public void writePacket(ByteBuffer buffer, long pts, boolean config, boolean keyFrame) throws IOException {
|
||||
|
||||
Reference in New Issue
Block a user