-
Notifications
You must be signed in to change notification settings - Fork 10.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Audio capture fails on BlueStacks Android 11 #4054
Comments
Let's add more logs: diffdiff --git a/server/src/main/java/com/genymobile/scrcpy/AudioCapture.java b/server/src/main/java/com/genymobile/scrcpy/AudioCapture.java
index 9228e3d71..1e2a071ad 100644
--- a/server/src/main/java/com/genymobile/scrcpy/AudioCapture.java
+++ b/server/src/main/java/com/genymobile/scrcpy/AudioCapture.java
@@ -137,10 +137,12 @@ public final class AudioCapture {
// - an estimation from the previous PTS and the packet size as a fallback.
//
// Therefore, the property that PTS are monotonically increasing is no guaranteed in corner cases, so enforce it.
+ Ln.i("=== Estimated");
pts = previousPts + 1;
}
previousPts = pts;
+ Ln.i("=== PTS: " + pts);
outBufferInfo.set(0, r, pts, 0);
return r;
} Replace this binary in your scrcpy v2.0 folder:
And retry your last command. |
Forget about the previous comment, I added one more log, please test with this version instead: diffdiff --git a/server/src/main/java/com/genymobile/scrcpy/AudioCapture.java b/server/src/main/java/com/genymobile/scrcpy/AudioCapture.java
index 9228e3d71..1e2a071ad 100644
--- a/server/src/main/java/com/genymobile/scrcpy/AudioCapture.java
+++ b/server/src/main/java/com/genymobile/scrcpy/AudioCapture.java
@@ -137,10 +137,12 @@ public final class AudioCapture {
// - an estimation from the previous PTS and the packet size as a fallback.
//
// Therefore, the property that PTS are monotonically increasing is no guaranteed in corner cases, so enforce it.
+ Ln.i("=== Estimated");
pts = previousPts + 1;
}
previousPts = pts;
+ Ln.i("=== PTS: " + pts);
outBufferInfo.set(0, r, pts, 0);
return r;
}
diff --git a/server/src/main/java/com/genymobile/scrcpy/AudioEncoder.java b/server/src/main/java/com/genymobile/scrcpy/AudioEncoder.java
index 24d685c52..b6dd8d177 100644
--- a/server/src/main/java/com/genymobile/scrcpy/AudioEncoder.java
+++ b/server/src/main/java/com/genymobile/scrcpy/AudioEncoder.java
@@ -107,6 +107,7 @@ public final class AudioEncoder implements AsyncProcessor {
OutputTask task = outputTasks.take();
ByteBuffer buffer = mediaCodec.getOutputBuffer(task.index);
try {
+ Ln.i("=== output PTS: " + task.bufferInfo.presentationTimeUs);
streamer.writePacket(buffer, task.bufferInfo);
} finally {
mediaCodec.releaseOutputBuffer(task.index, false);
|
Here's the new output:
|
Thank you, but in that capture:
You did not reproduce the problem, which was:
|
OK, I was able to reproduce it this time.
|
OK, the culprit is here:
So the encoder produces invalid timestamps. Here is a branch which should fix it: Here is a full release (based on
Please confirm that it fixes the problem for you. |
Unfortunately, it still produces the same error.
|
Oh, it wants the PTS strictly increasing! This branch should fix it: Here is a full release:
|
Still the same :(
|
WTF 🤔 With more logs: diffdiff --git a/server/src/main/java/com/genymobile/scrcpy/AudioEncoder.java b/server/src/main/java/com/genymobile/scrcpy/AudioEncoder.java
index 460017d4d..1b57def69 100644
--- a/server/src/main/java/com/genymobile/scrcpy/AudioEncoder.java
+++ b/server/src/main/java/com/genymobile/scrcpy/AudioEncoder.java
@@ -105,17 +105,20 @@ public final class AudioEncoder implements AsyncProcessor {
private void outputThread(MediaCodec mediaCodec) throws IOException, InterruptedException {
streamer.writeAudioHeader();
- long lastPts = 0;
+ long lastPts = -1; // so that it the test works also when presentationTimeUs == 0
while (!Thread.currentThread().isInterrupted()) {
OutputTask task = outputTasks.take();
if (task.bufferInfo.presentationTimeUs <= lastPts) {
// Fix PTS if not strictly monotonically increasing
+ Ln.i("=== pts=" + task.bufferInfo.presentationTimeUs + "; lastPts=" + lastPts);
task.bufferInfo.presentationTimeUs = ++lastPts;
+ Ln.i("=== newPts=" + task.bufferInfo.presentationTimeUs);
} else {
lastPts = task.bufferInfo.presentationTimeUs;
}
+ Ln.i("PTS=" + task.bufferInfo.presentationTimeUs);
ByteBuffer buffer = mediaCodec.getOutputBuffer(task.index);
try {
streamer.writePacket(buffer, task.bufferInfo); Replace this binary in your
|
Here you go:
|
Thank you, so now the PTS look good (strictly increasing) on the server side. Let's add some logs on the client side: diffdiff --git a/app/src/recorder.c b/app/src/recorder.c
index be1cbe719..604b7de99 100644
--- a/app/src/recorder.c
+++ b/app/src/recorder.c
@@ -387,8 +387,11 @@ sc_recorder_process_packets(struct sc_recorder *recorder) {
}
if (audio_pkt) {
+ sc_tick pts = audio_pkt->pts;
audio_pkt->pts -= pts_origin;
audio_pkt->dts = audio_pkt->pts;
+ LOGI("RECORD PTS=%"PRIi64", relPTS=%"PRIi64", dts=%"PRIi64,
+ pts, audio_pkt->pts, audio_pkt->dts);
bool ok = sc_recorder_write_audio(recorder, audio_pkt);
if (!ok) {
|
Here it is:
|
Thank you. I think I get it, it's due to PTS rescaling. I will fix it soon. |
Should be fixed on branch Here is a binary:
|
I can confirm that it's fixed now. Thanks!
|
Thank you for your tests (and the report). Fix merged: 323ea2f |
Environment
Describe the bug
I'm trying to record the screen of a BlueStacks Android 11 (beta) instance.
First I've tried:
Then:
And then:
So I can capture video but not audio.
The text was updated successfully, but these errors were encountered: