Skip to content
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

Turn device screen off _after_ everything has been set up #3902

Closed
wants to merge 1 commit into from

Conversation

metayan
Copy link

@metayan metayan commented Apr 8, 2023

Sometimes it can take quite a while for everything to get set up and the screen to appear.

Note:
Intentionally kept the double if construct so it matches the previous blocks.

Sometimes it can take quite a while for everything to get set up and
the screen to appear.
rom1v pushed a commit that referenced this pull request Apr 12, 2023
Sometimes it can take quite a while for everything to get set up and
the screen to appear.

PR #3902 <#3902>

Signed-off-by: Romain Vimont <rom@rom1v.com>
@rom1v
Copy link
Collaborator

rom1v commented Apr 12, 2023

Intentionally kept the double if construct so it matches the previous blocks.

I merged the conditions in a single if, rebased on dev, and adapted the commit message to respect the 50-72 rule.

Please check before I merge: pr3902

@metayan
Copy link
Author

metayan commented Apr 12, 2023

Please check before I merge: pr3902

Checked and it works fine - as intended.

(Under some special conditions there is sometimes still quite a gap between when the device screen is turned off and the scrcpy screen appears, but I suspect it would be too complicated to turn off the device screen even later.
The gap is much shorter with this fix, though, so time to let got of some perfectionism...)

@metayan
Copy link
Author

metayan commented Apr 12, 2023

Oh, and thanks for the tweaks you did.

@rom1v
Copy link
Collaborator

rom1v commented Apr 13, 2023

Under some special conditions there is sometimes still quite a gap between when the device screen is turned off and the scrcpy screen appears

Weird. How long? Can you reproduce a starting delay without turning the screen off? With another encoder (see scrcpy --list-encoders)? With another device? With another computer?

@metayan
Copy link
Author

metayan commented Apr 13, 2023

It's most likely a macOS issue, or maybe how some other programs handle OpenGL or Metal under macOS. When I have many windows with many tabs open in Safari (or other browser), some programs that want to use OpenGL take a long time to start. It seems like they're fighting over resources.
Not specific to scrcpy, so no worries. That's the background of this patch, with which it's a lot better.
If I shut down the browser, startup is fast.
And without any gap with this patch.

Anyway, here are timings with the different encoders, as requested, with many browser windows and tabs open in Safari:

h264 'OMX.qcom.video.encoder.avc'

./run x --verbosity=verbose --render-driver=opengl -S \
  --video-codec=h264 --video-encoder='OMX.qcom.video.encoder.avc' \
  2>&1 |ts -i "%.s" |ts -s "%.s"
0.009515 0.009038 scrcpy 2.0 <https://github.com/Genymobile/scrcpy>
0.009953 0.000687 DEBUG: ADB device found:
0.009992 0.000054 DEBUG:     -->   (usb)  BH901SGS9E                      device  G8441
0.010022 0.000036 DEBUG: Device serial: BH901SGS9E
0.010048 0.000027 DEBUG: Using SCRCPY_SERVER_PATH: x/server/scrcpy-server
0.054708 0.044866 x/server/scrcpy-server: 1 file pushed, 0 skipped. 34.2 MB/s (52576 bytes in 0.001s)
0.418564 0.364011 [server] INFO: Device: Sony G8441 (Android 9)
0.432197 0.013627 [server] DEBUG: Creating encoder by name: 'OMX.qcom.video.encoder.avc'
0.447559 0.015350 [server] WARN: Audio disabled: it is not supported before Android 11
0.447601 0.000050 [server] DEBUG: Audio encoder stopped
0.487790 0.040180 DEBUG: Server connected
0.487860 0.000069 DEBUG: Starting controller thread
0.487884 0.000025 DEBUG: Starting receiver thread
4.104331 3.616099 INFO: Renderer: opengl
4.104659 0.000252 DEBUG: Creating OpenGL Core Profile context
4.311615 0.204830 INFO: OpenGL version: 4.1 NVIDIA-14.0.32 355.11.11.10.10.143
4.312340 0.000435 INFO: Trilinear filtering enabled
4.312396 0.002819 DEBUG: Using SCRCPY_ICON_PATH: app/data/icon.png
4.315984 0.001805 DEBUG: Demuxer 'video': starting thread
4.317313 0.000053 DEBUG: Demuxer 'audio': starting thread
4.317334 0.000177 VERBOSE: input: power mode off
4.317349 0.001737 WARN: Demuxer 'audio': stream explicitly disabled by the device
4.538242 0.221880 [server] INFO: Device screen turned off
4.812837 0.274850 INFO: Texture: 720x1280

6.865194 2.052314 DEBUG: User requested to quit
6.865253 0.000114 DEBUG: quit...
6.882626 0.017391 DEBUG: Demuxer 'video': end of frames
6.882686 0.000063 DEBUG: Receiver stopped
6.896467 0.013760 [server] DEBUG: Controller stopped
7.883926 0.987442 WARN: Killing the server...
7.884731 0.000835 DEBUG: Server disconnected
7.884783 0.000071 DEBUG: Server terminated

h264 'OMX.google.h264.encoder'

./run x --verbosity=verbose --render-driver=opengl -S \
  --video-codec=h264 --video-encoder='OMX.google.h264.encoder' \
  2>&1 |ts -i "%.s" |ts -s "%.s"
0.007618 0.007043 scrcpy 2.0 <https://github.com/Genymobile/scrcpy>
0.008147 0.000442 DEBUG: ADB device found:
0.008180 0.000027 DEBUG:     -->   (usb)  BH901SGS9E                      device  G8441
0.008203 0.000023 DEBUG: Device serial: BH901SGS9E
0.008224 0.000023 DEBUG: Using SCRCPY_SERVER_PATH: x/server/scrcpy-server
0.044439 0.036680 x/server/scrcpy-server: 1 file pushed, 0 skipped. 26.6 MB/s (52576 bytes in 0.002s)
0.401706 0.357253 [server] INFO: Device: Sony G8441 (Android 9)
0.416879 0.015193 [server] DEBUG: Creating encoder by name: 'OMX.google.h264.encoder'
0.432658 0.015683 [server] WARN: Audio disabled: it is not supported before Android 11
0.432768 0.000137 [server] DEBUG: Audio encoder stopped
0.473085 0.040376 DEBUG: Server connected
0.473164 0.000065 DEBUG: Starting controller thread
0.473184 0.000018 DEBUG: Starting receiver thread
4.177282 3.702588 INFO: Renderer: opengl
4.178143 0.000912 DEBUG: Creating OpenGL Core Profile context
4.423208 0.246514 INFO: OpenGL version: 4.1 NVIDIA-14.0.32 355.11.11.10.10.143
4.423391 0.000089 INFO: Trilinear filtering enabled
4.423459 0.000072 DEBUG: Using SCRCPY_ICON_PATH: app/data/icon.png
4.442043 0.018316 DEBUG: Demuxer 'video': starting thread
4.442180 0.000083 DEBUG: Demuxer 'audio': starting thread
4.442346 0.000030 VERBOSE: input: power mode off
4.442766 0.000351 WARN: Demuxer 'audio': stream explicitly disabled by the device
4.662484 0.212725 INFO: Texture: 720x1280
4.680320 0.025439 [server] INFO: Device screen turned off

7.063408 2.383099 DEBUG: User requested to quit
7.063494 0.000086 DEBUG: quit...
7.132611 0.069085 DEBUG: Demuxer 'video': end of frames
7.132739 0.000126 DEBUG: Receiver stopped
7.141736 0.008969 [server] DEBUG: Controller stopped
8.137681 0.995998 WARN: Killing the server...
8.138543 0.000877 DEBUG: Server disconnected
8.138638 0.000083 DEBUG: Server terminated

h265 'OMX.qcom.video.encoder.hevc'

./run x --verbosity=verbose --render-driver=opengl -S \
  --video-codec=h265 --video-encoder='OMX.qcom.video.encoder.hevc' \
  2>&1 |ts -i "%.s" |ts -s "%.s"
0.021340 0.020698 scrcpy 2.0 <https://github.com/Genymobile/scrcpy>
0.021941 0.000608 DEBUG: ADB device found:
0.021976 0.000036 DEBUG:     -->   (usb)  BH901SGS9E                      device  G8441
0.022002 0.000025 DEBUG: Device serial: BH901SGS9E
0.022026 0.000022 DEBUG: Using SCRCPY_SERVER_PATH: x/server/scrcpy-server
0.061733 0.040112 x/server/scrcpy-server: 1 file pushed, 0 skipped. 43.3 MB/s (52576 bytes in 0.001s)
0.416839 0.355237 [server] INFO: Device: Sony G8441 (Android 9)
0.428774 0.011944 [server] DEBUG: Creating encoder by name: 'OMX.qcom.video.encoder.hevc'
0.438099 0.009193 [server] WARN: Audio disabled: it is not supported before Android 11
0.438238 0.000178 [server] DEBUG: Audio encoder stopped
0.494027 0.055816 DEBUG: Server connected
0.494100 0.000108 DEBUG: Starting controller thread
0.494123 0.000025 DEBUG: Starting receiver thread
4.642947 4.145164 INFO: Renderer: opengl
4.643841 0.000360 DEBUG: Creating OpenGL Core Profile context
4.643918 0.003561 INFO: OpenGL version: 4.1 NVIDIA-14.0.32 355.11.11.10.10.143
4.643947 0.000034 INFO: Trilinear filtering enabled
4.643971 0.000028 DEBUG: Using SCRCPY_ICON_PATH: app/data/icon.png
4.643993 0.000088 DEBUG: Demuxer 'video': starting thread
4.644017 0.000027 DEBUG: Demuxer 'audio': starting thread
4.644040 0.000024 VERBOSE: input: power mode off
4.644065 0.000022 WARN: Demuxer 'audio': stream explicitly disabled by the device
4.726567 0.068650 INFO: Texture: 720x1280
4.901029 0.188959 [server] INFO: Device screen turned off

6.431134 1.530085 DEBUG: User requested to quit
6.431226 0.000094 DEBUG: quit...
6.452380 0.021135 DEBUG: Demuxer 'video': end of frames
6.452546 0.000081 DEBUG: Receiver stopped
6.462964 0.010543 [server] DEBUG: Controller stopped
7.455235 0.992272 WARN: Killing the server...
7.456022 0.000803 DEBUG: Server disconnected
7.456077 0.000058 DEBUG: Server terminated

To get correct timing I added

diff --git a/app/src/util/log.h b/app/src/util/log.h
index 8e1b73a2..f5c683ab 100644
--- a/app/src/util/log.h
+++ b/app/src/util/log.h
@@ -10,11 +10,11 @@
 #define LOG_STR_IMPL_(x) # x
 #define LOG_STR(x) LOG_STR_IMPL_(x)
 
-#define LOGV(...) SDL_LogVerbose(SDL_LOG_CATEGORY_APPLICATION, __VA_ARGS__)
-#define LOGD(...) SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, __VA_ARGS__)
-#define LOGI(...) SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, __VA_ARGS__)
-#define LOGW(...) SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, __VA_ARGS__)
-#define LOGE(...) SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, __VA_ARGS__)
+#define LOGV(...) { SDL_LogVerbose(SDL_LOG_CATEGORY_APPLICATION, __VA_ARGS__); fflush(stdout); }
+#define LOGD(...) { SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, __VA_ARGS__); fflush(stdout); }
+#define LOGI(...) { SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, __VA_ARGS__); fflush(stdout); }
+#define LOGW(...) { SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, __VA_ARGS__); fflush(stderr); }
+#define LOGE(...) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, __VA_ARGS__); fflush(stderr); }
 
 #define LOG_OOM() \
     LOGE("OOM: %s:%d %s()", __FILE__, __LINE__, __func__)

I'll also make timings without any browser running while I'm at it.

@metayan
Copy link
Author

metayan commented Apr 13, 2023

Timings without any other OpenGL/Metal-using programs:

h264 'OMX.qcom.video.encoder.avc'

./run x --verbosity=verbose --render-driver=opengl -S \
  --video-codec=h264 --video-encoder='OMX.qcom.video.encoder.avc' \
  2>&1 |ts -i "%.s" |ts -s "%.s"
0.008024 0.007690 scrcpy 2.0 <https://github.com/Genymobile/scrcpy>
0.008521 0.000254 DEBUG: ADB device found:
0.008567 0.000022 DEBUG:     -->   (usb)  BH901SGS9E                      device  G8441
0.008592 0.000013 DEBUG: Device serial: BH901SGS9E
0.008614 0.000012 DEBUG: Using SCRCPY_SERVER_PATH: x/server/scrcpy-server
0.045004 0.036881 x/server/scrcpy-server: 1 file pushed, 0 skipped. 98.1 MB/s (52576 bytes in 0.001s)
0.397182 0.352163 [server] INFO: Device: Sony G8441 (Android 9)
0.410796 0.013628 [server] DEBUG: Creating encoder by name: 'OMX.qcom.video.encoder.avc'
0.416833 0.006034 [server] WARN: Audio disabled: it is not supported before Android 11
0.416895 0.000059 [server] DEBUG: Audio encoder stopped
0.457307 0.040133 DEBUG: Server connected
0.457471 0.000310 DEBUG: Starting controller thread
0.457512 0.000098 DEBUG: Starting receiver thread
1.411399 0.953957 INFO: Renderer: opengl
1.411442 0.000054 DEBUG: Creating OpenGL Core Profile context
1.432754 0.021267 INFO: OpenGL version: 4.1 NVIDIA-14.0.32 355.11.11.10.10.143
1.432828 0.000081 INFO: Trilinear filtering enabled
1.432855 0.000032 DEBUG: Using SCRCPY_ICON_PATH: app/data/icon.png
1.445209 0.012351 DEBUG: Demuxer 'video': starting thread
1.445266 0.000103 DEBUG: Demuxer 'audio': starting thread
1.445292 0.000056 VERBOSE: input: power mode off
1.445382 0.000046 WARN: Demuxer 'audio': stream explicitly disabled by the device
1.473740 0.028338 INFO: Texture: 720x1280
1.662478 0.188737 [server] INFO: Device screen turned off

2.782003 1.119535 DEBUG: User requested to quit
2.782047 0.000061 DEBUG: quit...
2.782399 0.000369 DEBUG: Demuxer 'video': end of frames
2.782442 0.000047 DEBUG: Receiver stopped
2.796258 0.013803 [server] DEBUG: Controller stopped
3.785394 0.989093 WARN: Killing the server...
3.786020 0.000667 DEBUG: Server disconnected
3.786092 0.000055 DEBUG: Server terminated

h264 'OMX.google.h264.encoder'

./run x --verbosity=verbose --render-driver=opengl -S \
  --video-codec=h264 --video-encoder='OMX.google.h264.encoder' \
  2>&1 |ts -i "%.s" |ts -s "%.s"
0.005748 0.006740 scrcpy 2.0 <https://github.com/Genymobile/scrcpy>
0.006165 0.000273 DEBUG: ADB device found:
0.006194 0.000022 DEBUG:     -->   (usb)  BH901SGS9E                      device  G8441
0.006214 0.000012 DEBUG: Device serial: BH901SGS9E
0.006233 0.000013 DEBUG: Using SCRCPY_SERVER_PATH: x/server/scrcpy-server
0.046630 0.040532 x/server/scrcpy-server: 1 file pushed, 0 skipped. 51.9 MB/s (52576 bytes in 0.001s)
0.411004 0.364611 [server] INFO: Device: Sony G8441 (Android 9)
0.427502 0.016505 [server] DEBUG: Creating encoder by name: 'OMX.google.h264.encoder'
0.442682 0.015125 [server] WARN: Audio disabled: it is not supported before Android 11
0.442738 0.000072 [server] DEBUG: Audio encoder stopped
0.451225 0.008445 DEBUG: Server connected
0.451352 0.000136 DEBUG: Starting controller thread
0.451389 0.000051 DEBUG: Starting receiver thread
1.286342 0.834987 INFO: Renderer: opengl
1.286389 0.000057 DEBUG: Creating OpenGL Core Profile context
1.308164 0.021740 INFO: OpenGL version: 4.1 NVIDIA-14.0.32 355.11.11.10.10.143
1.308239 0.000079 INFO: Trilinear filtering enabled
1.308267 0.000029 DEBUG: Using SCRCPY_ICON_PATH: app/data/icon.png
1.320757 0.012509 DEBUG: Demuxer 'video': starting thread
1.320819 0.000078 DEBUG: Demuxer 'audio': starting thread
1.320845 0.000045 VERBOSE: input: power mode off
1.320870 0.000023 WARN: Demuxer 'audio': stream explicitly disabled by the device
1.346838 0.025961 INFO: Texture: 720x1280
1.540273 0.193398 [server] INFO: Device screen turned off

2.928698 1.388447 DEBUG: User requested to quit
2.928741 0.000054 DEBUG: quit...
2.929107 0.000375 DEBUG: Demuxer 'video': end of frames
2.929152 0.000050 DEBUG: Receiver stopped
2.940539 0.011378 [server] DEBUG: Controller stopped
3.933722 0.993129 WARN: Killing the server...
3.934347 0.000688 DEBUG: Server disconnected
3.934404 0.000047 DEBUG: Server terminated

h265 'OMX.qcom.video.encoder.hevc'

./run x --verbosity=verbose --render-driver=opengl -S \
  --video-codec=h265 --video-encoder='OMX.qcom.video.encoder.hevc' \
  2>&1 |ts -i "%.s" |ts -s "%.s"
0.012964 0.012130 scrcpy 2.0 <https://github.com/Genymobile/scrcpy>
0.013387 0.000280 DEBUG: ADB device found:
0.013432 0.000034 DEBUG:     -->   (usb)  BH901SGS9E                      device  G8441
0.013471 0.000025 DEBUG: Device serial: BH901SGS9E
0.013497 0.000022 DEBUG: Using SCRCPY_SERVER_PATH: x/server/scrcpy-server
0.052338 0.039147 x/server/scrcpy-server: 1 file pushed, 0 skipped. 108.4 MB/s (52576 bytes in 0.000s)
0.404325 0.352074 [server] INFO: Device: Sony G8441 (Android 9)
0.416890 0.012570 [server] DEBUG: Creating encoder by name: 'OMX.qcom.video.encoder.hevc'
0.422464 0.005515 [server] WARN: Audio disabled: it is not supported before Android 11
0.422541 0.000097 [server] DEBUG: Audio encoder stopped
0.452923 0.030414 DEBUG: Server connected
0.452982 0.000092 DEBUG: Starting controller thread
0.453013 0.000029 DEBUG: Starting receiver thread
1.400158 0.947103 INFO: Renderer: opengl
1.400201 0.000057 DEBUG: Creating OpenGL Core Profile context
1.422178 0.021930 INFO: OpenGL version: 4.1 NVIDIA-14.0.32 355.11.11.10.10.143
1.422251 0.000081 INFO: Trilinear filtering enabled
1.422279 0.000027 DEBUG: Using SCRCPY_ICON_PATH: app/data/icon.png
1.435335 0.013071 DEBUG: Demuxer 'video': starting thread
1.435396 0.000101 DEBUG: Demuxer 'audio': starting thread
1.435461 0.000053 VERBOSE: input: power mode off
1.435490 0.000034 WARN: Demuxer 'audio': stream explicitly disabled by the device
1.463124 0.027563 INFO: Texture: 720x1280
1.646464 0.183371 [server] INFO: Device screen turned off

2.664422 1.017992 DEBUG: User requested to quit
2.664466 0.000056 DEBUG: quit...
2.664787 0.000329 DEBUG: Demuxer 'video': end of frames
2.664828 0.000044 DEBUG: Receiver stopped
2.677581 0.012698 [server] DEBUG: Controller stopped
3.665437 0.987851 WARN: Killing the server...
3.666184 0.000743 DEBUG: Server disconnected
3.666252 0.000086 DEBUG: Server terminated

This is on macOS Catalina (10.15.7)
MacBook Pro 2.5 GHz Quad-Core Intel Core i7
NVIDIA GeForce GT 750M

@metayan
Copy link
Author

metayan commented Apr 14, 2023

Logged the startup without the macOS OpenGL core profile patch, just to make sure that it isn't adding to the startup time, and the timing is approximately the same.
Sometimes it is even quite a bit longer, but that is probably macOS busy with something else.

Here is a run without the OpenGL core profile patch and with Safari open with a lot of windows and tabs:

./run x --verbosity=verbose --render-driver=opengl -S \
  --video-codec=h264 --video-encoder='OMX.qcom.video.encoder.avc' \
  2>&1 |ts -i "%.s" |ts -s "%.s"
0.001281 0.000834 scrcpy 2.0 <https://github.com/Genymobile/scrcpy>
0.001873 0.000518 DEBUG: ADB device found:
0.001911 0.000035 DEBUG:     -->   (usb)  BH901SGS9E                      device  G8441
0.001941 0.000025 DEBUG: Device serial: BH901SGS9E
0.001967 0.000023 DEBUG: Using SCRCPY_SERVER_PATH: x/server/scrcpy-server
0.024232 0.022807 x/server/scrcpy-server: 1 file pushed, 0 skipped. 31.6 MB/s (52576 bytes in 0.002s)
0.364510 0.340248 [server] INFO: Device: Sony G8441 (Android 9)
0.376524 0.012041 [server] DEBUG: Creating encoder by name: 'OMX.qcom.video.encoder.avc'
0.395209 0.018649 [server] WARN: Audio disabled: it is not supported before Android 11
0.395369 0.000089 [server] DEBUG: Audio encoder stopped
0.405912 0.010657 DEBUG: Server connected
0.405960 0.000060 DEBUG: Starting controller thread
0.405986 0.000027 DEBUG: Starting receiver thread
0.406009 0.000020 VERBOSE: input: power mode off
0.612237 0.206218 [server] INFO: Device screen turned off
5.730884 5.108450 INFO: Renderer: opengl
        [^^^ This is the long delay while setting up OpenGL]
5.797064 0.008457 INFO: OpenGL version: 2.1 NVIDIA-14.0.32 355.11.11.10.10.143
5.797111 0.000164 WARN: Trilinear filtering disabled (OpenGL 3.0+ or ES 2.0+ required
5.797261 0.000167 DEBUG: Using SCRCPY_ICON_PATH: app/data/icon.png
5.797298 0.000223 DEBUG: Demuxer 'video': starting thread
5.797323 0.000038 DEBUG: Demuxer 'audio': starting thread
5.797345 0.000069 WARN: Demuxer 'audio': stream explicitly disabled by the device
5.797367 0.000051 INFO: Texture: 720x1280

12.064831 6.334931 DEBUG: User requested to quit
12.064925 0.000082 DEBUG: quit...
12.066849 0.001987 DEBUG: Demuxer 'video': end of frames
12.066909 0.000050 DEBUG: Receiver stopped
12.078015 0.011104 [server] DEBUG: Controller stopped
13.067095 0.989044 WARN: Killing the server...
13.067806 0.000744 DEBUG: Server disconnected
13.067904 0.000064 DEBUG: Server terminated

Anyway, nothing to worry about. I don't see the long delay as a scrcpy issue.

@rom1v
Copy link
Collaborator

rom1v commented Apr 14, 2023

And without --render-driver=opengl?

@metayan
Copy link
Author

metayan commented Apr 14, 2023

And without --render-driver=opengl?

Good point.
Similar delays.

With lots of windows and tabs in Safari

./run x --verbosity=verbose -S \
  --video-codec=h264 --video-encoder='OMX.qcom.video.encoder.avc' \
  2>&1 |ts -i "%.s" |ts -s "%.s"
0.002456 0.002025 scrcpy 2.0 <https://github.com/Genymobile/scrcpy>
0.003342 0.000415 DEBUG: ADB device found:
0.003376 0.000039 DEBUG:     -->   (usb)  BH901SGS9E                      device  G8441
0.003399 0.000027 DEBUG: Device serial: BH901SGS9E
0.003422 0.000026 DEBUG: Using SCRCPY_SERVER_PATH: x/server/scrcpy-server
0.051011 0.048373 x/server/scrcpy-server: 1 file pushed, 0 skipped. 26.1 MB/s (52576 bytes in 0.002s)
1.058392 1.007360 [server] INFO: Device: Sony G8441 (Android 9)
1.074980 0.016635 [server] DEBUG: Creating encoder by name: 'OMX.qcom.video.encoder.avc'
1.083481 0.008496 [server] WARN: Audio disabled: it is not supported before Android 11
1.083523 0.000043 [server] DEBUG: Audio encoder stopped
1.166413 0.082820 DEBUG: Server connected
1.166496 0.000138 DEBUG: Starting controller thread
1.166555 0.000042 DEBUG: Starting receiver thread
6.195868 5.029260 INFO: Renderer: metal
        [^^^]
6.196058 0.000120 DEBUG: Trilinear filtering disabled (not an OpenGL renderer
6.196143 0.000036 DEBUG: Using SCRCPY_ICON_PATH: app/data/icon.png
6.306953 0.110712 DEBUG: Demuxer 'video': starting thread
6.320481 0.000079 DEBUG: Demuxer 'audio': starting thread
6.321911 0.000030 VERBOSE: input: power mode off
6.331767 0.011775 WARN: Demuxer 'audio': stream explicitly disabled by the device
6.520577 0.202020 [server] INFO: Device screen turned off
7.471523 0.912220 INFO: Texture: 720x1280

9.772552 2.339766 DEBUG: User requested to quit
9.772618 0.000078 DEBUG: quit...
9.773856 0.001174 DEBUG: Demuxer 'video': end of frames
9.773917 0.000117 DEBUG: Receiver stopped
9.783215 0.009319 [server] DEBUG: Controller stopped
10.778078 0.994817 WARN: Killing the server...
10.779054 0.001003 DEBUG: Server disconnected
10.779111 0.000071 DEBUG: Server terminated

With nothing going on

./run x --verbosity=verbose -S \
  --video-codec=h264 --video-encoder='OMX.qcom.video.encoder.avc' \
  2>&1 |ts -i "%.s" |ts -s "%.s"
0.006046 0.005661 scrcpy 2.0 <https://github.com/Genymobile/scrcpy>
0.006576 0.000350 DEBUG: ADB device found:
0.006610 0.000035 DEBUG:     -->   (usb)  BH901SGS9E                      device  G8441
0.006636 0.000022 DEBUG: Device serial: BH901SGS9E
0.006660 0.000021 DEBUG: Using SCRCPY_SERVER_PATH: x/server/scrcpy-server
0.035490 0.029289 x/server/scrcpy-server: 1 file pushed, 0 skipped. 131.8 MB/s (52576 bytes in 0.000s)
0.360263 0.324766 [server] INFO: Device: Sony G8441 (Android 9)
0.377530 0.017270 [server] DEBUG: Creating encoder by name: 'OMX.qcom.video.encoder.avc'
0.380638 0.003086 [server] WARN: Audio disabled: it is not supported before Android 11
0.380726 0.000101 [server] DEBUG: Audio encoder stopped
0.386727 0.006057 DEBUG: Server connected
0.386767 0.000050 DEBUG: Starting controller thread
0.386784 0.000023 DEBUG: Starting receiver thread
1.209370 0.822518 INFO: Renderer: metal
        [^^^]
1.209419 0.000085 DEBUG: Trilinear filtering disabled (not an OpenGL renderer
1.209440 0.000034 DEBUG: Using SCRCPY_ICON_PATH: app/data/icon.png
1.221447 0.011936 DEBUG: Demuxer 'video': starting thread
1.221522 0.000111 DEBUG: Demuxer 'audio': starting thread
1.221539 0.000038 VERBOSE: input: power mode off
1.221558 0.000021 WARN: Demuxer 'audio': stream explicitly disabled by the device
1.263713 0.042146 INFO: Texture: 720x1280
1.436921 0.173181 [server] INFO: Device screen turned off

2.419327 0.982421 DEBUG: User requested to quit
2.419376 0.000055 DEBUG: quit...
2.419738 0.000383 DEBUG: Demuxer 'video': end of frames
2.419784 0.000041 DEBUG: Receiver stopped
2.428461 0.008679 [server] DEBUG: Controller stopped
2.589124 0.160600 [server] DEBUG: Screen streaming stopped
2.589210 0.000089 [server] DEBUG: Device message sender stopped
2.867756 0.278565 DEBUG: Server disconnected
2.867837 0.000092 DEBUG: Server terminated

macOS seems to be quite tricky to get to behave when setting up
OpenGL/Metal.

I have now tried some examples both from SDL and GLFW, and the setting
up and removal of the OpenGL context makes the whole system stagger.
Even more during teardown than setup actually. For example, if audio
is playing, it stutters.

So this behaviour is not specific to scrcpy.

So far, the only program I have found that behaves well is mpv.

Just for comparison - and maybe inspiration - here is an example of
mpv playing the first half second of a video (with lots of windows
and tabs in Safari):

./build/mpv --end=0.5 --keep-open=no test.mp4 --msg-level=libmpv_render=v,vo=v \
  |ts -i "%.s" |ts -s "%.s" |tee timing
0.099105 0.097076 [libmpv_render] GL_VERSION='4.1 INTEL-14.7.28'
[Here the OpenGL context is already set up]
0.099539 0.000311 [libmpv_render] Detected desktop OpenGL 4.1.
0.099560 0.000033 [libmpv_render] GL_VENDOR='Intel Inc.'
0.099572 0.000026 [libmpv_render] GL_RENDERER='Intel Iris Pro OpenGL Engine'
0.099584 0.000024 [libmpv_render] GL_SHADING_LANGUAGE_VERSION='4.10'
[...]
0.112607 0.012386  (+) Video --vid=1 (*) (h264 1920x1080 29.970fps)
0.119624 0.006995 [vo/libmpv] Assuming 59.990270 FPS for display sync.
[...]
0.282833 0.050312 [libmpv_render] Window size: 3840x2160 (Borders: l=0 t=0 r=0 b=0)
0.282912 0.000071 [libmpv_render] Video source: 1920x1080 (1:1)
0.282947 0.000016 [libmpv_render] Video display: (0, 0) 1920x1080 -> (0, 0) 3840x2160
[...]
0.746894 0.000089 Exiting... (End of file)

The whole setup, playing, and teardown is done in three quarters of a second.
Without any disruption to any other program running.
Hmm.

@rom1v
Copy link
Collaborator

rom1v commented Apr 14, 2023

Possibly an issue with your graphics drivers, since apparently it does not happen for many users (nobody ever reported such a delay).

@metayan
Copy link
Author

metayan commented Apr 14, 2023

Maybe others don't have hundreds of tabs open in Safari... ;)

Anyway, it's not an issue with normal scrcpy use, since it's fine once it's running.
Only a bit of a nuisance when recompiling/restarting when "developing".

rom1v pushed a commit that referenced this pull request May 27, 2023
Sometimes it can take quite a while for everything to get set up and
the screen to appear.

PR #3902 <#3902>

Signed-off-by: Romain Vimont <rom@rom1v.com>
@rom1v
Copy link
Collaborator

rom1v commented May 27, 2023

In any case, it can be merged (moreover if something fails to start, it's better if the device is not turned off for nothing): 798dfd2

@rom1v rom1v closed this May 27, 2023
@metayan metayan deleted the screen-off-later branch November 28, 2023 00:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants