2

簡単なアプリケーションを作成しようとしています。このアプリケーションはカメラを取得し、それをネイティブ ウィンドウに出力します。ここまでで、ウィンドウを作成し、その背景色を設定し、カメラを取得できました。ただし、サーフェスを取得してプレビューに使用する方法がわかりません。ここに私の既存のコードのスニペットがあります....

struct android_app* app;
EGLDisplay display;
EGLSurface surface;
EGLContext context;
using namespace android;
sp<Camera> cam;

void init_camera(){
    int num = Camera::getNumberOfCameras();
    if(num == 0){
        LOGI("No Camera found not using one");
        return;
    }
    else if(num >1 ){
        LOGI("%d Cameras Found using the first");
    }

    CameraInfo camInfo;
    status_t infoRes = Camera::getCameraInfo(0, &camInfo);
    if(infoRes == NO_ERROR){
        int facing = camInfo.facing;
        if(facing == 0){
            LOGI("Using rear camera");
        }
        else{
            LOGI("Using front camera");
        }
    }
    else{
        LOGE("There was an error getting information");
    }
    cam = Camera::connect(0);
    status_t info1 = cam->setPreviewDisplay(&surface);
}

しかし、コンパイルしようとすると...

jni/../../AOSP/frameworks/native/include/utils/StrongPointer.h: In constructor 'android::sp<T>::sp(U*) [with U = void*, T = android::Surface]':
jni/main.cpp:51:51:   instantiated from here
jni/../../AOSP/frameworks/native/include/utils/StrongPointer.h:134:34: error: cannot convert 'void**' to 'android::Surface*' in initialization
jni/../../AOSP/frameworks/native/include/utils/StrongPointer.h:136:16: error: invalid use of incomplete type 'struct android::Surface'
jni/../../AOSP/frameworks/native/include/ui/GraphicBuffer.h:124:18: error: forward declaration of 'struct android::Surface'
jni/../../AOSP/frameworks/native/include/utils/StrongPointer.h: In destructor 'android::sp<T>::~sp() [with T = android::Surface]':
jni/main.cpp:51:51:   instantiated from here
jni/../../AOSP/frameworks/native/include/utils/StrongPointer.h:149:16: error: invalid use of incomplete type 'struct android::Surface'
jni/../../AOSP/frameworks/native/include/ui/GraphicBuffer.h:124:18: error: forward declaration of 'struct android::Surface'
make: *** [obj/local/armeabi/objs/gonative/main.o] Error 1

これを行う方法はありますか?

アップデート

この「かもしれない」動作...

void connectSurface() {
    // set up the thread-pool
    //sp<ProcessState> proc(ProcessState::self());
    //ProcessState::self()->startThreadPool();
    // create a client to surfaceflinger
    sp<SurfaceComposerClient> client = new SurfaceComposerClient();
    String8* s = new String8("test");
    sp<SurfaceControl> surfaceControl = client->createSurface(*s, 160, 240, PIXEL_FORMAT_RGB_565);
    SurfaceComposerClient::openGlobalTransaction();
    surfaceControl->setLayer(100000);
    SurfaceComposerClient::closeGlobalTransaction();

    // pretend it went cross-process
    Parcel parcel;
    SurfaceControl::writeSurfaceToParcel(surfaceControl, &parcel);
    parcel.setDataPosition(0);
    surfacew = Surface::readFromParcel(parcel);
    //ANativeWindow* window = surfacew.get();
    app->window = surfacew.get();
    /////////////////////////
}

または同様のもの(おそらく間違ったビットマップなど)。しかし、これには

uid=10052 の android.permission.ACCESS_SURFACE_FLINGER をチェック => 拒否 (2700 us)

振り出しに戻ります。どうすれば表面を取得できますか?

4

0 に答える 0