begeekmyfriend / yasea

RTMP live streaming client for Android
MIT License
4.89k stars 1.32k forks source link

bitmap bytebuffer stream #369

Closed sereja93 closed 7 years ago

sereja93 commented 7 years ago

How I can stream bitmap bytebuffer in RGB565 format ? How correctly transform picture bytebuffer to streaming

begeekmyfriend commented 7 years ago

You should use TextureView instead of GLSurfaceView and call getBitmap in onSurfaceTextureUpdated to obtain the pictures in bitmap. And change the color format in libenc.cc and rebuild the libenc.so.

However I suggest ARGB_8888 since it is the default format in getBitmap.

sereja93 commented 7 years ago

I m using FOURCC_RGBP = FOURCC('R', 'G', 'B', 'P'), but not work.

this my code. streaming must work in background service. I not using android view

private fun createSurfaceTexture(): SurfaceTexture {
        val textures = IntArray(1)
        GLES20.glGenTextures(1, textures, 0)
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textures[0])
        val width = 4 // size of preview
        val height = 4  // size of preview
        GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, width,
                height, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, null)
        GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE)
        GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE)
        GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR)
        GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR)

        val texture = SurfaceTexture(textures[0])
        texture.setDefaultBufferSize(4, 4)
        return texture
    }

    private val bitmapBack = Bitmap.createBitmap(UVCCamera.DEFAULT_PREVIEW_WIDTH, UVCCamera.DEFAULT_PREVIEW_HEIGHT, Bitmap.Config.RGB_565)

    private inner class PictureThreadBack internal constructor(private val mCamera: UVCCamera) : Thread() {
        val surfaceTexture = createSurfaceTexture()
        override fun run() {
            mCamera.setPreviewTexture(surfaceTexture)
            mCamera.startPreview()
            mCamera.setFrameCallback(mIFrameCallbackBack, UVCCamera.PIXEL_FORMAT_RGB565)
        }

        private val mIFrameCallbackBack = IFrameCallback { frame ->
            synchronized(bitmapBack) {
                bitmapBack.copyPixelsFromBuffer(frame)
                val arr = ByteArray(frame.remaining())
                frame.get(arr)
                mPublisher.onDrawFrame(arr)
            }
        }
    }
begeekmyfriend commented 7 years ago

What you did is far from enough and in wrong way...

sereja93 commented 7 years ago

how run stream in backround. What to change in the code?