openstf / minicap

Stream real-time screen capture data out of Android devices.
Other
1.72k stars 622 forks source link

when is it support android Q? #168

Closed BryanYangZL closed 5 years ago

BryanYangZL commented 5 years ago

thx

sorccu commented 5 years ago

No promises. I would suggest you look at the build instructions and try to make it work with the new platform.

pcrepieux commented 5 years ago

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.

sorccu commented 5 years ago

Don’t use master. Use the preview branch.

pcrepieux commented 5 years ago

I confess I hadn't noticed android-q-preview-1 tag was available. I quickly rebuilt it. Same result.

sorccu commented 5 years ago

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.

pcrepieux commented 5 years ago

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...

pcrepieux commented 5 years ago

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

BryanYangZL commented 5 years ago

I modify minicap_28.cpp and replace getBuiltInDisplay with getPhysicalDisplayToken. It work for me in Q.

varundtsfi commented 5 years ago

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

pcrepieux commented 5 years ago

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.

wull8 commented 5 years ago

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 ? image

Thanks and Regards

pcrepieux commented 5 years ago

Hi @wull8,

I added 'double_loadable: true' in libselinux bp file to overcome this build error.

wull8 commented 5 years ago

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. image

Thanks and Regards

pcrepieux commented 5 years ago

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.

wull8 commented 5 years ago

@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.

varundtsfi commented 5 years ago

@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

pcrepieux commented 5 years ago

Well, I am afraid I cannot help much apart from trying to be a bit clearer.

+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");

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 ...

varundtsfi commented 5 years ago

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.

Screenshot from 2019-06-18 23-48-58

coinhu1995 commented 4 years ago

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)

image

coinhu1995 commented 4 years ago

I figured out, we have to copy aosp folder into external folder of android source code (instead of minicap-shared folder)

image