Closed BryanYangZL closed 5 years ago
No promises. I would suggest you look at the build instructions and try to make it work with the new platform.
For what it's worth, I compiled minicap_28.cpp with current AOSP master branch and tried it on a Pixel3 XL running Q. Apparently it segfaults when applying the SurfaceComposerClient::Transaction on line 282. I personnaly have no clue. In case, it might be of any help, https://github.com/Genymobile/scrcpy seems to be able to grab the screen with a different approach that works on my device. So there might be a solution.
Don’t use master. Use the preview branch.
I confess I hadn't noticed android-q-preview-1 tag was available. I quickly rebuilt it. Same result.
Lately Google doesn’t release the actual code they use so it’s difficult to patch minicap before the official release. You’d have to disassemble the libgui library from a device running Q and try to figure out what’s changed.
Couldn't seriously investigate it for now but oddly enough, moving the transaction to a global variable makes it work (apparently, on 2 different devices I have at hand). I wouldn't call it a fix but maybe could be a temporary workaround or at least food for thought...
Q Beta 2 removed SurfaceComposerClient::getBuiltInDisplay(int) from libgui.so
CANNOT LINK EXECUTABLE "/data/local/tmp/minicap-devel/minicap": cannot locate symbol ''' "_ZN7android21SurfaceComposerClient17getBuiltInDisplayEi" referenced by "/data/local/tmp/minicap-devel/minicap.so"
According to screenrecord binary, it looks like it's been replaced by android::SurfaceComposerClient::getInternalDisplayToken() which is mangled as _ZN7android21SurfaceComposerClient23getInternalDisplayTokenEv. Apparently, they are equivalent. Using dlsym to substitute the call to SurfaceComposerClient::getBuiltInDisplay looks OK (at least on my pixel3 XL with Q beta 2).
int
minicap_try_get_display_info(int32_t displayId, Minicap::DisplayInfo* info) {
- android::sp<android::IBinder> dpy = android::SurfaceComposerClient::getBuiltInDisplay(displayId);
+ (void)displayId;// makes "-Werror,-Wunused-parameter" happy
+ typedef android::sp<android::IBinder> (*getInternalDisplayTokenFunction)(void);
+ void* handle = dlopen("libgui.so", RTLD_LAZY);
+ getInternalDisplayTokenFunction getBuiltInDisplay = reinterpret_cast<getInternalDisplayTokenFunction>(dlsym(handle, "_ZN7android21SurfaceComposerClient23getInternalDisplayTokenEv"));
+ android::sp<android::IBinder> dpy = getBuiltInDisplay();
Waiting for the next beta to break something else ... meanwhile, it's might be OK to play with even if those are likely unreliable workarounds
I modify minicap_28.cpp and replace getBuiltInDisplay with getPhysicalDisplayToken. It work for me in Q.
I have downloaded android Q beta version 2.5. I wanted to build minicap.so against this. Could you let me know the steps to build minicap.so.
@BryanYangZL and @pcrepieux
Build instructions are here. The aosp.sh script in the docker image has a "build" command to generate the library.
$ docker run openstf/aosp:jdk8
Usage: /aosp.sh <command>
Commands:
...
build <target> <local-module> [make-options]
Required volumes:
/app For your app code (i.e. an Android.mk containing folder)
/aosp For the AOSP branch checkout (see checkout-branch)
/artifacts For build artifacts
Builds <local-module> for <target> (see `lunch`) after copying /app
to /aosp/external/MY_<local-module>. <local-module> must not conflict
with with any built-in project or your module will not build. The
prefix is added so that even if you accidentally do use a built-in
name, at the very least you won't overwrite the files. Note that
<local-module> must match the LOCAL_MODULE value in your Android.mk
exactly. You will also need to set `LOCAL_MODULE_TAGS := optional` in
your Android.mk because the build system requires it.
You can refere to this Makefile to have an idea how to call it for a specific version.
But if you already have an AOSP build environment, you can also directly put the minicap-shared directory in your AOSP tree (eg: in "external") and compile it with:
$ . build/envsetup.sh
$ lunch aosp_arm64-eng
$ make minicap -j <your_number_of_cpu>
from aosp root directory (that's basically what aosp.sh build command does)
Note that I am not a maintainer of this project, so this is only based on my personal experience and my understanding of the project.
Hi @BryanYangZL @pcrepieux I checked out branch android-q-preview-1 and tried to compile minicap_28.cpp with it. But I got the error as follows. Are you familiar with such kind of error ?
Thanks and Regards
Hi @wull8,
I added 'double_loadable: true' in libselinux bp file to overcome this build error.
Hi @pcrepieux Thanks so much !!! The build succeeded. And I tried to run it on Google Pixel with build QPP4 (preview 4). I got the error as follows, have you encountered this before ? BTW, I use the lasted code of minicap.
Thanks and Regards
I haven't checked since preview 2. Oddly enough, I got rid of the segfault by moving the SurfaceComposerClient::Transaction declaration to a global variable (I have no idea why ...) I don't know what other changes have been made in AOSP source code since then. You might still have to do a few changes like the one I mentioned here or the one @BryanYangZL mentioned here (I haven't tested that one) or even something else for now on ... I'll give a it try with preview 4 when I find a bit of time.
@pcrepieux Thanks a lot. I applied the fix which declares the transaction globally and managed to build minicap.so with android-q-preview-4, but there is still "Segementation fault" error when I tried to run it on Pixel device (Beta 4 image). Android Q has a lot of changes, comparing to Android P. It mights needs more modifications on minicap source code.
@pcrepieux Thanks a lot. I applied the fix which declares the transaction globally and managed to build minicap.so with android-q-preview-4, but there is still "Segementation fault" error when I tried to run it on Pixel device (Beta 4 image). Android Q has a lot of changes, comparing to Android P. It mights needs more modifications on minicap source code.
Hi @pcrepieux
I am also facing the same issue. I have build minicap with android q preview 4 and using Pixel device which is running on QPP4. I have applied both of your suggestions.
adb shell LD_LIBRARY_PATH=/data/local/tmp/minicap-devel /data/local/tmp/minicap-devel/minicap -P 1080x1920@1080x1920/0
INFO: (/home/radmin/Desktop/minicap/jni/minicap/minicap.cpp:218) MAIN IS CALLING PID: 10050 INFO: Using projection 1080x1920@1080x1920/0 INFO: (external/MY_minicap/minicap/src/minicap_28.cpp:235) Height and Width 1080 1920 1080 1920 INFO: (external/MY_minicap/minicap/src/minicap_28.cpp:242) Creating SurfaceComposerClient INFO: (external/MY_minicap/minicap/src/minicap_28.cpp:245) Performing SurfaceComposerClient init check INFO: (external/MY_minicap/minicap/src/minicap_28.cpp:256) Creating virtual display INFO: (external/MY_minicap/minicap/src/minicap_28.cpp:262) Creating buffer queue INFO: (external/MY_minicap/minicap/src/minicap_28.cpp:265) Setting buffer options INFO: (external/MY_minicap/minicap/src/minicap_28.cpp:269) Creating CPU consumer INFO: (external/MY_minicap/minicap/src/minicap_28.cpp:273) Creating frame waiter INFO: (external/MY_minicap/minicap/src/minicap_28.cpp:277) Publishing virtual display INFO: (/home/radmin/Desktop/minicap/jni/minicap/JpgEncoder.cpp:64) Allocating 6268932 bytes for JPG encoder INFO: (/home/radmin/Desktop/minicap/jni/minicap/JpgEncoder.cpp:75) Allocating 1080 width INFO: (/home/radmin/Desktop/minicap/jni/minicap/JpgEncoder.cpp:76) Allocating 1920 height INFO: (external/MY_minicap/minicap/src/minicap_28.cpp:291) Destroying virtual display Segmentation fault
Well, I am afraid I cannot help much apart from trying to be a bit clearer.
I use a pixel 3XL
I have now initialized repo with android-q-preview-4 source code
repo init -u https://android.googlesource.com/platform/manifest -b android-q-preview-4
Later during compilation stage, if the build complains, you can safely remove those files/dir: .out-dir, Android.mk, CleanSpec.mk, cts/hostsidetests/jdwptunnel/
here are the changes I described earlier (nothing more). You can apply this patch with git apply
:
diff --git a/jni/minicap-shared/aosp/src/minicap_28.cpp b/jni/minicap-shared/aosp/src/minicap_28.cpp
index c5a04d3..defb961 100644
--- a/jni/minicap-shared/aosp/src/minicap_28.cpp
+++ b/jni/minicap-shared/aosp/src/minicap_28.cpp
@@ -70,6 +70,8 @@ error_name(int32_t err) {
}
}
+android::SurfaceComposerClient::Transaction t; + class FrameProxy: public android::ConsumerBase::FrameAvailableListener { public: FrameProxy(Minicap::FrameAvailableListener* listener): mUserListener(listener) { @@ -274,7 +276,6 @@ private: mConsumer->setFrameAvailableListener(mFrameProxy);
MCINFO("Publishing virtual display");
android::SurfaceComposerClient::Transaction t; t.setDisplaySurface(mVirtualDisplay, mBufferProducer); t.setDisplayProjection(mVirtualDisplay, android::DISPLAY_ORIENTATION_0, layerStackRect, visibleRect); @@ -340,7 +341,12 @@ private:
int minicap_try_get_display_info(int32_t displayId, Minicap::DisplayInfo* info) {
android::sp
(void)displayId;// makes "-Werror,-Wunused-parameter" happy
typedef android::sp
void* handle = dlopen("libgui.so", RTLD_LAZY);
getInternalDisplayTokenFunction getBuiltInDisplay = reinterpret_cast
dlsym(handle, "_ZN7android21SurfaceComposerClient23getInternalDisplayTokenEv"));
android::sp
android::Vector
_One trick is that AOSP android-q-preview-4 source code still uses 28 as the API level, though the preview image uses 29. That's why I modified minicap_28.cpp and put it in libs/android-29_
Compile with:
docker run --rm -a stdout -a stderr -v /<AOSP_SRC>:/aosp \
-v /<MINICAP_SRC>/jni/minicap-shared/aosp:/app \
-v /<MINICAP_SRC>/jni/minicap-shared/aosp/libs/android-29/arm64-v8a/:/artifacts \
openstf/aosp:jdk8 /aosp.sh build aosp_arm64-eng minicap
Then ./run autosize
should be just fine
...
adb push jni/minicap-shared/aosp/libs/android-29/arm64-v8a/minicap.so /data/local/tmp/minicap-devel jni/minicap-shared/aosp/libs/android-29/arm64-v8a/minicap.so: 1 file pushed. 6.8 MB/s (29248 bytes in 0.004s)
adb shell LD_LIBRARY_PATH=/data/local/tmp/minicap-devel /data/local/tmp/minicap-devel/minicap -P 1440x2960@1440x2960/0 PID: 11130 INFO: Using projection 1440x2960@1440x2960/0 INFO: (external/MY_minicap/src/minicap_28.cpp:243) Creating SurfaceComposerClient INFO: (external/MY_minicap/src/minicap_28.cpp:246) Performing SurfaceComposerClient init check INFO: (external/MY_minicap/src/minicap_28.cpp:257) Creating virtual display INFO: (external/MY_minicap/src/minicap_28.cpp:263) Creating buffer queue INFO: (external/MY_minicap/src/minicap_28.cpp:266) Setting buffer options INFO: (external/MY_minicap/src/minicap_28.cpp:270) Creating CPU consumer INFO: (external/MY_minicap/src/minicap_28.cpp:274) Creating frame waiter INFO: (external/MY_minicap/src/minicap_28.cpp:278) Publishing virtual display INFO: (jni/minicap/JpgEncoder.cpp:64) Allocating 12789252 bytes for JPG encoder INFO: (jni/minicap/minicap.cpp:449) New client connection
I have just tested and it looks fine.
![minicap-Q-screen](https://user-images.githubusercontent.com/1419986/59610226-3de2e280-9119-11e9-9013-9d28d43513f3.png)
If it still ends up crashing, give a look to the logcat and see if you have crash_dump info that could help narrow down the root cause of your segfault.
I hope I didn't missed something ...
getInternalDisplayTokenFunction getBuiltInDisplay = reinterpret_cast
{
- dlsym(handle, "_ZN7android21SurfaceComposerClient23getInternalDisplayTokenEv"));
Hi @pcrepieux. I have done the same and result was expected. It's working sir. I am really thankful to you. Even I have investigated what I was doing wrong. I really appreciate your support sir.
Hi @pcrepieux, I faced this error after build with these instruction
But if you already have an AOSP build environment, you can also directly put the minicap-shared directory in your AOSP tree (eg: in "external") and compile it with: $ . build/envsetup.sh $ lunch aosp_arm64-eng $ make minicap -j
from aosp root directory (that's basically what aosp.sh build command does)
I figured out, we have to copy aosp
folder into external folder of android source code (instead of minicap-shared
folder)
thx