Finish_frame() function is not being called

Hi there, I am building and testing custom platform plugin based on the Anbox Platform SDK 1.17.0.

I expected finish_frame() to be called for every frame, but it stops being called after index 500, as shown in the log below.
Is there any reason why finish_frame() is not being called?

I configured begin_frame() and finish_frame() to only output the following logs without glBindFrameBuffer/glBindTexture.

If I am misunderstanding anything, I appreciate your patience and would be grateful for clarification.
Any advice or guidance on this issue would be greatly appreciated.

Best regards,

Environment

Install Anbox cloud appliance
Ubuntu 22.04 pro
GPU : Nvidia Geforce RTX 3060 Ti, Driver Version: 535.129.03, CUDA Version: 12.2

test command

amc launch --raw —cpus 4 --gpu-slots 1 --memory 3221225472 --disk-size 3221225472
triplet=$(dpkg-architecture -qDEB_BUILD_MULTIARCH)
amc exec “${id}” mkdir “/usr/lib/${triplet}/anbox/platforms/myplatform”
lxc file push “platform_myplatform.so” “ams-${id}/usr/lib/${triplet}/anbox/platforms/myplatform/”
cat << EOF | amc exec “${id}” tee /var/lib/anbox/session.yaml
log-level: debug
platform: myplatform

platform code

void MyPlatformGraphicsProcessor::begin_frame() {
static int64_t begin_frame_idx = 0;
begin_frame_idx++;
if (begin_frame_idx % 60 == 0)
std::cout << “begin_frame_idx=” << begin_frame_idx << std::endl;
}
void MyPlatformGraphicsProcessor::finish_frame() {
static int64_t frame_idx = 0;
frame_idx++;
if (frame_idx % 60 == 0)
std::cout << “frame_idx=” << frame_idx << std::endl;
}

log

Jan 23 03:42:51 ams-cmnjb2ii2j060b6a5gu0 sh[4083]: + [ android-booted != android-booted ]
Jan 23 03:42:51 ams-cmnjb2ii2j060b6a5gu0 sh[4084]: + cat /var/lib/anbox/features
Jan 23 03:42:51 ams-cmnjb2ii2j060b6a5gu0 sh[4085]: + grep -q enable_virtual_keyboard
Jan 23 03:42:51 ams-cmnjb2ii2j060b6a5gu0 sh[4083]: + exit 0
Jan 23 03:42:51 ams-cmnjb2ii2j060b6a5gu0 anbox[3092]: Render thread could not read data from stream
Jan 23 03:42:51 ams-cmnjb2ii2j060b6a5gu0 anbox[3092]: Released socket based GL processed for com.android.settings
Jan 23 03:42:51 ams-cmnjb2ii2j060b6a5gu0 anbox[3092]: Created socket based GL processor for com.android.launcher3
Jan 23 03:42:51 ams-cmnjb2ii2j060b6a5gu0 anbox[3092]: Generated new GL process pipe ID 7
Jan 23 03:42:51 ams-cmnjb2ii2j060b6a5gu0 amsctl[4164]: 2024/01/23 03:42:51 Not sending feedback to AMS as feedback URL is not available
Jan 23 03:42:51 ams-cmnjb2ii2j060b6a5gu0 systemd[1]: Started Anbox.
Jan 23 03:42:51 ams-cmnjb2ii2j060b6a5gu0 anbox[3092]: Created socket based GL processor for com.android.settings
Jan 23 03:42:51 ams-cmnjb2ii2j060b6a5gu0 anbox[3092]: [API] [PERFORMANCE] [131218] Program/shader state performance warning: Fragment shader in program 3 is being recompiled based on GL state.
Jan 23 03:42:51 ams-cmnjb2ii2j060b6a5gu0 anbox[3092]: [API] [PERFORMANCE] [131218] Program/shader state performance warning: Vertex shader in program 3 is being recompiled based on GL state.
Jan 23 03:42:51 ams-cmnjb2ii2j060b6a5gu0 anbox[3092]: Created socket based GL processor for com.android.launcher3
Jan 23 03:42:51 ams-cmnjb2ii2j060b6a5gu0 anbox[3092]: [API] [PERFORMANCE] [131218] Program/shader state performance warning: Fragment shader in program 3 is being recompiled based on GL state.
Jan 23 03:42:51 ams-cmnjb2ii2j060b6a5gu0 anbox[3092]: [API] [PERFORMANCE] [131218] Program/shader state performance warning: Vertex shader in program 3 is being recompiled based on GL state.
Jan 23 03:42:51 ams-cmnjb2ii2j060b6a5gu0 anbox[3092]: Created socket based GL processor for com.android.launcher3
Jan 23 03:42:51 ams-cmnjb2ii2j060b6a5gu0 anbox[3092]: Created socket based GL processor for com.android.launcher3
Jan 23 03:42:51 ams-cmnjb2ii2j060b6a5gu0 anbox-starter[3092]: begin_frame_idx=60
Jan 23 03:42:51 ams-cmnjb2ii2j060b6a5gu0 anbox-starter[3092]: frame_idx=60
Jan 23 03:42:52 ams-cmnjb2ii2j060b6a5gu0 anbox-starter[3092]: begin_frame_idx=120
Jan 23 03:42:52 ams-cmnjb2ii2j060b6a5gu0 anbox-starter[3092]: frame_idx=120
Jan 23 03:42:52 ams-cmnjb2ii2j060b6a5gu0 anbox-starter[3092]: begin_frame_idx=180
Jan 23 03:42:52 ams-cmnjb2ii2j060b6a5gu0 anbox-starter[3092]: frame_idx=180
Jan 23 03:42:53 ams-cmnjb2ii2j060b6a5gu0 anbox[3092]: Failed to reach ADB server, ignorning
Jan 23 03:42:55 ams-cmnjb2ii2j060b6a5gu0 anbox-starter[3092]: begin_frame_idx=240
Jan 23 03:42:55 ams-cmnjb2ii2j060b6a5gu0 anbox-starter[3092]: frame_idx=240
Jan 23 03:42:56 ams-cmnjb2ii2j060b6a5gu0 anbox[3092]: Render thread could not read data from stream
Jan 23 03:42:56 ams-cmnjb2ii2j060b6a5gu0 anbox[3092]: Released socket based GL processed for com.android.launcher3
Jan 23 03:42:57 ams-cmnjb2ii2j060b6a5gu0 anbox-starter[3092]: begin_frame_idx=300
Jan 23 03:42:57 ams-cmnjb2ii2j060b6a5gu0 anbox-starter[3092]: frame_idx=300
Jan 23 03:42:59 ams-cmnjb2ii2j060b6a5gu0 anbox-starter[3092]: begin_frame_idx=360
Jan 23 03:42:59 ams-cmnjb2ii2j060b6a5gu0 anbox-starter[3092]: frame_idx=360
Jan 23 03:43:01 ams-cmnjb2ii2j060b6a5gu0 anbox-starter[3092]: begin_frame_idx=420
Jan 23 03:43:01 ams-cmnjb2ii2j060b6a5gu0 anbox-starter[3092]: frame_idx=420
Jan 23 03:43:03 ams-cmnjb2ii2j060b6a5gu0 anbox-starter[3092]: begin_frame_idx=480
Jan 23 03:43:03 ams-cmnjb2ii2j060b6a5gu0 anbox-starter[3092]: frame_idx=480
(log does not appear after this point)

I confirmed that it occurred due to the power-saving mode.

I changed the app to prevent it from entering power-saving mode, and now the begin_frame() and finish_frame() is called repeatly.

hey @adlecddqq1

It’s not necessarily power saving mode which is causing Android to not send a constant 60 FPS. SurfaceFlinger will be design only put updates to the hwcomposer module when something has changed at the next vsync interval. Otherwise it will not send anything on the next vsync.

begin_frame/end_frame are called as a consequence of SurfaceFlinger calling present on the hwcomposer implementation. So if you want to receive a constant frame rate inside your platform (e.g. to pass it into a video encoder) you will need to sample from the last frame and update accordingly. This is what the webrtc platform in Anbox Cloud does.

Thanks to your detailed explanation, I was able to understand the operation of begin_frame/finish_frame.