1- package io.github.kenneycode.videostudio.demo
1+ package io.github.kenneycode.videostudio.demo.samples
22
33import android.graphics.SurfaceTexture
4- import android.opengl.GLES11Ext
5- import android.opengl.GLES30
64import android.opengl.GLSurfaceView
7- import android.support.v7.app.AppCompatActivity
85import android.os.Bundle
96import android.util.Log
10- import io.github.kenneycode.funrenderer.common.Keys
11- import io.github.kenneycode.funrenderer.common.RenderChain
12- import io.github.kenneycode.funrenderer.io.Input
13- import io.github.kenneycode.funrenderer.io.Texture
14- import io.github.kenneycode.funrenderer.renderer.OES2RGBARenderer
15- import io.github.kenneycode.funrenderer.renderer.ScreenRenderer
7+ import androidx.appcompat.app.AppCompatActivity
8+ import io.github.kenneycode.fusion.common.DataKeys
9+ import io.github.kenneycode.fusion.framebuffer.FrameBuffer
10+ import io.github.kenneycode.fusion.framebuffer.FrameBufferCache
11+ import io.github.kenneycode.fusion.process.RenderChain
12+ import io.github.kenneycode.fusion.renderer.DisplayRenderer
13+ import io.github.kenneycode.fusion.renderer.OES2RGBARenderer
14+ import io.github.kenneycode.fusion.util.GLUtil
1615import io.github.kenneycode.videostudio.VideoDecoder
16+ import io.github.kenneycode.videostudio.demo.R
1717import kotlinx.android.synthetic.main.activity_sample_common.*
1818import javax.microedition.khronos.egl.EGLConfig
1919import javax.microedition.khronos.opengles.GL10
@@ -40,8 +40,10 @@ class SampleVideoDecoder : AppCompatActivity() {
4040
4141 private lateinit var surfaceTexture: SurfaceTexture
4242 private lateinit var renderChain: RenderChain
43- private lateinit var input: Input
43+ private lateinit var input: FrameBuffer
4444 private var oesTexture = 0
45+ private var surfaceWidth = 0
46+ private var surfaceHeight = 0
4547 private val videoDecoder = VideoDecoder ()
4648 private var hasNewFrame = false
4749
@@ -51,51 +53,52 @@ class SampleVideoDecoder : AppCompatActivity() {
5153 if (hasNewFrame) {
5254 hasNewFrame = false
5355 surfaceTexture.updateTexImage()
54- val stMatrix = FloatArray (16 )
55- surfaceTexture.getTransformMatrix(stMatrix)
56- val data = mutableMapOf<String , Any >()
57- data[Keys .ST_MATRIX ] = stMatrix
58- renderChain.render(input, data)
56+ val stMatrix = FloatArray (16 ).apply {
57+ surfaceTexture.getTransformMatrix(this )
58+ }
59+ val data = mutableMapOf<String , Any >().apply {
60+ put(DataKeys .ST_MATRIX , stMatrix)
61+ put(DataKeys .KEY_DISPLAY_WIDTH , surfaceWidth)
62+ put(DataKeys .KEY_DISPLAY_HEIGHT , surfaceHeight)
63+ }
64+ renderChain.setInput(input)
65+ renderChain.update(data)
66+ renderChain.render()
5967 Thread .sleep(40 )
6068 videoDecoder.decode()
6169 }
6270 }
6371
6472 override fun onSurfaceChanged (gl : GL10 ? , width : Int , height : Int ) {
65- input = Texture (oesTexture, width, height, false )
73+ surfaceWidth = width
74+ surfaceHeight = height
75+ input = FrameBufferCache .obtainFrameBuffer().apply {
76+ this .texture = oesTexture
77+ this .width = videoDecoder.getVideoWidth()
78+ this .height = videoDecoder.getVideoHeight()
79+ this .hasExternalTexture = true
80+ this .retain = true
81+ }
6682 }
6783
6884 override fun onSurfaceCreated (gl : GL10 ? , config : EGLConfig ? ) {
69-
70- renderChain = RenderChain .create()
71- .addRenderer(OES2RGBARenderer ())
72- .addRenderer(ScreenRenderer ())
73- renderChain.init ()
74-
75- oesTexture = createOESTexture()
76- surfaceTexture = SurfaceTexture (oesTexture)
77- surfaceTexture.setOnFrameAvailableListener {
78- hasNewFrame = true
79- glSurfaceView.requestRender()
85+ renderChain = RenderChain (OES2RGBARenderer ()).apply {
86+ addNextRenderer(DisplayRenderer ())
87+ init ()
8088 }
81- videoDecoder.init (" /sdcard/2ae0840bf9e995adc1a382f78458cafb.mp4" , surfaceTexture)
89+ oesTexture = GLUtil .createOESTexture()
90+ surfaceTexture = SurfaceTexture (oesTexture).apply {
91+ setOnFrameAvailableListener {
92+ hasNewFrame = true
93+ glSurfaceView.requestRender()
94+ }
95+ }
96+ videoDecoder.init (" /sdcard/v1.mp4" , surfaceTexture)
8297 videoDecoder.decode()
8398 }
8499
85100 })
86101 glSurfaceView.renderMode = GLSurfaceView .RENDERMODE_WHEN_DIRTY
87102 }
88103
89- fun createOESTexture () : Int {
90- val textures = IntArray (1 )
91- GLES30 .glGenTextures(textures.size, textures, 0 )
92- GLES30 .glBindTexture(GLES11Ext .GL_TEXTURE_EXTERNAL_OES , textures[0 ])
93- GLES30 .glTexParameteri(GLES11Ext .GL_TEXTURE_EXTERNAL_OES , GLES30 .GL_TEXTURE_WRAP_S , GLES30 .GL_CLAMP_TO_EDGE )
94- GLES30 .glTexParameteri(GLES11Ext .GL_TEXTURE_EXTERNAL_OES , GLES30 .GL_TEXTURE_WRAP_T , GLES30 .GL_CLAMP_TO_EDGE )
95- GLES30 .glTexParameteri(GLES11Ext .GL_TEXTURE_EXTERNAL_OES , GLES30 .GL_TEXTURE_MIN_FILTER , GLES30 .GL_LINEAR )
96- GLES30 .glTexParameteri(GLES11Ext .GL_TEXTURE_EXTERNAL_OES , GLES30 .GL_TEXTURE_MAG_FILTER , GLES30 .GL_LINEAR )
97- GLES30 .glBindTexture(GLES30 .GL_TEXTURE_2D , 0 )
98- return return textures[0 ]
99- }
100-
101104}
0 commit comments