google / google/android-emulator-container-scripts

Slowdown when resuming a paused emulator

Open
#242 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
2.1k
Forks
294
PR merge metrics
No merged PRs in 30d

Description

When pausing the emulator and then resuming it a bit later results in a temporary slowdown of the videostream when connecting over VP8, the effect is that the stream is really laggy for the first few seconds.

One possible fix is to update previous frames timestamp in the TIMEOUT phase of GrpcVideoSource.cpp as well as sleeping for 16ms instead of 500ms. This will result in higher bandwidth usage as more frames are sent even tho there is no change in the stream. But end result is that the stream supports pasuing and resuming the emulator.

```
diff --git a/android/android-webrtc/videobridge/emulator/webrtc/capture/GrpcVideoSource.cpp b/android/android-webrtc/videobridge/emulator/webrtc/capture/GrpcVideoSource.cpp
index 533df08f82..00ec780300 100644
--- a/android/android-webrtc/videobridge/emulator/webrtc/capture/GrpcVideoSource.cpp
+++ b/android/android-webrtc/videobridge/emulator/webrtc/capture/GrpcVideoSource.cpp
@@ -131,7 +131,7 @@ void GrpcVideoSource::captureFrames() {
// Start the async rpc.
rpc->StartCall((void*) 1);
rpc->Read(&img, my_tag);
- bool ok = false, completed = false;
+ bool ok = false, completed = false, isPaused = false;
do {

// Wait at most 500ms for the next frame, so we can deliver at least 2 fps to the decoder
@@ -139,10 +139,11 @@ void GrpcVideoSource::captureFrames() {
// new connections however will get an immediate frame.
auto state =
cq.AsyncNext(&got_tag, &ok,
- grpc_timeout_to_deadline(std::chrono::milliseconds(500)));
+ grpc_timeout_to_deadline(std::chrono::milliseconds(isPaused ? 16 : 500)));
// RTC_LOG(INFO) << "Got state: " << state << " tag " << (uint64_t) got_tag << " == " << (uint64_t) my_tag;
switch (state) {
case ::grpc::CompletionQueue::NextStatus::GOT_EVENT:
+ isPaused = false;
if (ok && got_tag == my_tag) {
if (img.format().rotation().rotation() !=
Rotation::PORTRAIT &&
@@ -182,8 +183,8 @@ void GrpcVideoSource::captureFrames() {
rpc->Read(&img, my_tag);
}
case ::grpc::CompletionQueue::NextStatus::TIMEOUT:
- // Attached decoders will immediately drop duplicate frames if android did not
- // give us a new video frame.
+ isPaused = true;
+ currentFrame.set_timestamp_us(rtc::TimeMicros());
mBroadcaster.OnFrame(currentFrame);
break;
case ::grpc::CompletionQueue::NextStatus::SHUTDOWN:

```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.