Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

[Android] Native Crash (SIGSEGV) injecting Bitmap from PixelCopy into WebRTC VideoSource (GetStream)

Aperta
#320 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
25/100
Tipo di issue
Bug
Chiarezza
Da chiarire
Stato di attività
Tranquilla
Stack tecnologico
android, kotlin

Direzione di ricerca

Inizia con il PixelCopy callback e con gli entry point org.webrtc.NV21Buffer, VideoFrame e VideoSource capturerObserver mostrati nel report. Confronta gli approcci JavaI420Buffer, ByteBuffer diretto, SurfaceTextureHelper e HandlerThread, quindi verifica che la pipeline Bitmap personalizzata non causi più il SIGSEGV nativo durante l’invio dei frames.

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

Descrizione

Hello everyone. I'm building a hybrid streaming app where I need to broadcast via RTMP (using the device's camera) and simultaneously establish a WebRTC P2P connection. Since Android doesn't allow two camera clients simultaneously, I'm trying to create a custom VideoCapturer that captures the RTMP SurfaceView using PixelCopy and feeds those frames into WebRTC.

I'm using: implementation("io.getstream:stream-webrtc-android:1.3.1")

The Issue:
The P2P connection (IceConnectionState.CONNECTED) establishes perfectly. However, the moment the WebRTC engine tries to process my custom injected frames to send them over the network, the app suffers a silent Native Crash (SIGSEGV). I suspect it's a memory violation regarding how I'm allocating the byte array or a thread context issue with SurfaceTextureHelper.

My current approach (Simplified):

Kotlin
// I have an active SurfaceView rendering the local camera.
// I run this at 15 FPS using a Handler.

PixelCopy.request(surfaceView, bitmapOriginal, { result ->
if (result == PixelCopy.SUCCESS) {

    // 1. Scale down to avoid massive memory usage
    val scaledBitmap = Bitmap.createScaledBitmap(bitmapOriginal, 320, 240, true)
    
    // 2. Convert Bitmap to NV21 ByteArray (Custom math method)
    val nv21Bytes = convertBitmapToNV21(scaledBitmap) 
    
    // 3. Inject into WebRTC
    val timestampNs = System.nanoTime()
    val buffer = org.webrtc.NV21Buffer(nv21Bytes, 320, 240, null)
    val videoFrame = org.webrtc.VideoFrame(buffer, 0, timestampNs)

    // videoSource is my org.webrtc.VideoSource
    videoSource?.capturerObserver?.onFrameCaptured(videoFrame)
    
    videoFrame.release()
}

}, myHandler)
My Questions:

What is the thread-safe and memory-safe (JNI-compliant) way to convert an Android Bitmap into a WebRTC VideoFrame using the GetStream library?

Should I be using JavaI420Buffer.allocate() or a direct ByteBuffer instead of a standard Kotlin ByteArray for the NV21Buffer to prevent the C++ segfault?

Do I strictly need to wrap this PixelCopy loop inside a SurfaceTextureHelper thread, or is a standard Android HandlerThread sufficient if I'm just pushing byte arrays?

Any guidance or snippet on how to properly implement a custom Bitmap to VideoFrame pipeline without crashing the native lib would be hugely appreciated!

Lingua principale
Kotlin
Stelle
884
Fork
108
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

  • Nessun Dockerfile né file Docker Compose
  • Ha un modello di pull request
  • Nessuna guida per i contributori

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 GetStream/webrtc-android

Tutte le issue di GetStream/webrtc-android

Issue simili

Altre issue su Kotlin

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.