[Bug/Question] NDK Camera2 callbacks (onImageAvailable) not firing in standalone C++ executable (No JNI/Java)

Aperta
#1,170 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
25/100
Tipo di issue
Bug
Chiarezza
Da chiarire
Stato di attività
Ferma
Stack tecnologico
android, cpp
Ambito
mobile

Direzione di ricerca

Inizia esaminando il ciclo ALooper_prepare e ALooper_pollAll e la configurazione del callback NDK Camera2 mostrati nell’issue. Verifica se il processo autonomo, l’identità shell/root e l’assenza di una superficie Java influiscono sulla consegna dei callback, quindi documenta le condizioni o le limitazioni necessarie affinché i callback vengano attivati.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Issue Description:
1. Problem Statement

I am developing a pure C++ tool using the NDK Camera2 API (NdkCameraManager, NdkCameraDevice, AImageReader) without any Java or JNI glue code. The goal is to capture frames and save them to the local filesystem from the shell.

The binary initializes successfully, and ACameraManager_openCamera returns ACAMERA_OK. However, none of the callbacks are being triggered:

  • ACameraDevice_StateCallbacks (e.g., onOpened) are not called.
  • ACameraCaptureSession_stateCallbacks (e.g., onReady) are not called.
  • AImageReader_ImageCallback (onImageAvailable) is never triggered.

The program enters a loop but stays idle until the timeout, with no error messages in logcat related to camera service denials.

2. Minimal Code Snippet

I am using ALooper to handle asynchronous callbacks as follows:

// In main thread
ALooper* looper = ALooper_prepare(0);

camera.startCapture(1920, 1080, 10);

int64_t start_time = time(nullptr);
while (time(nullptr) - start_time < 10) {
    int ident = ALooper_pollAll(1000, nullptr, nullptr, nullptr);
    if (ident == ALOOPER_POLL_TIMEOUT) {
    }
}

3. What I Have Tried
  • Root Access: Ran the binary as root.
  • SELinux: Set setenforce 0 to rule out SELinux policy issues.
  • Looper: Added ALooper_prepare and ALooper_pollAll in the main thread to ensure the event loop is running.
  • Verification: Verified that cmd camera list-cameras shows the cameras are available.
4. Questions
  1. Is it possible to use NDK Camera2 API in a standalone binary without a View or SurfaceTexture from the Java side?
  2. Does the shell UID (2000) or root UID (0) have inherent restrictions for accessing CameraService via NDK even if SELinux is disabled?
  3. Am I missing any specific initialization required for the ALooper to correctly route CameraService callbacks to a native process?
Lingua principale
C++
Stelle
10.5k
Fork
4.2k
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di android/ndk-samples

Tutte le issue di android/ndk-samples

Issue simili

Altre issue su C++

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.