Search code examples
androidgccarmscreen-capturenative-code

How get fast pixel color on Android use ScreenshotClient?


I want get color pixel use an binary file with params x and y. The screencap is very slow. Using a virtual display also does not give the desired result.

I found and code screencap, and good project: sji-android-screen-capture-old and sji-android-screen-capture-new.

But those solutions don't run in my phone. If run get-raw-image.cpp after compile get-raw-image.cpp I get errors:

WARNING: linker: /data/local/tmp/get-raw-image-4.1.2: unused DT entry: type 0xf arg 0x21d
CANNOT LINK EXECUTABLE: cannot locate symbol "_ZN7android16ScreenshotClient6updateERKNS_2spINS_7IBinderEEE".

For compilation, I use the following settings:

/root/arm/bin/arm-linux-androideabi-clang -pie get-raw-image.cpp -lsupc++ libgui.so -o /get-raw-image-4.1.2 -Xlinker -rpath=/system/lib -DTARGET_JB

If run Android-fast-screen-capture:

/root/arm/bin/arm-linux-androideabi-clang -pie /screen/ascreencap.cpp -o /test -std=c++11

I had errors:

In file included from /screen/ascreencap.cpp:8:
In file included from /root/arm/bin/../sysroot/usr/include/binder/IPCThreadState.h:21:
/root/arm/bin/../sysroot/usr/include/binder/Parcel.h:86:11: error: unknown type
      name 'binder_size_t'
    const binder_size_t* objects() const;
          ^
/root/arm/bin/../sysroot/usr/include/binder/Parcel.h:220:47: error: unknown type
      name 'binder_size_t'
                                        const binder_size_t* objects, si...
                                              ^
/root/arm/bin/../sysroot/usr/include/binder/Parcel.h:228:51: error: unknown type
      name 'binder_size_t'
                                            const binder_size_t* objects...
                                                  ^
/root/arm/bin/../sysroot/usr/include/binder/Parcel.h:264:5: error: unknown type
      name 'binder_size_t'
    binder_size_t*      mObjects;
    ^
In file included from /screen/ascreencap.cpp:8:
/root/arm/bin/../sysroot/usr/include/binder/IPCThreadState.h:114:50: error:
      unknown type name 'binder_size_t'
                                           const binder_size_t* objects...
                                                 ^
5 errors generated.

Also I found the question how-to-use-screenshotclient-in-my-android-application but I don't understand how set link to ScreenshotClient, so that the compiler does not return an error.

My phone is Homtom HT16:

Processor   : ARMv7 Processor rev 3 (v7l)
processor   : 0
model name  : ARMv7 Processor rev 3 (v7l)
BogoMIPS    : 26.00
Features    : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm

Maybe someone will tell you how to compile the code under my phone or which way to go to solve the problem.


Solution

  • I solved my problem.

    Steps:

    1) Copy need library from android phone (libgui.so, libui.so, libcutils.so, libutils.so, libbinder.so).

    2) Add in sys_root (when save ndk lib code files from Android Android 6_r1 libs: utils, cutils, system, log, hardware, system, ports, core, include/gui, include/ui, include/binder). You can run this code for find your system root:

    echo "#include <bogus.h> int main(){}" > t.c; GCC_OR_CLANG_BINARY_LINK -v t.c; rm t.c
    

    Erors printed all paths where compiler search include files. or use --sysroot=YOUR_PATH for set your path.

    3) Add flags -Wl,--unresolved-symbols=ignore-all for ignore errors and --target=armv7-none-linux-androideabi23 (23 or other) for set target version.

    Full my clang command:

    /Users/macbookair/Documents/test/bin/clang -fPIE -pie fast-screen-capture.cpp *.so -o ./screencap --target=armv7-none-linux-androideabi23 -Wl,--unresolved-symbols=ignore-all -s
    

    Successes!