Skip to content

Commit f5dc562

Browse files
committed
update demo
1 parent 8b1c961 commit f5dc562

13 files changed

Lines changed: 198 additions & 82 deletions

File tree

.idea/codeStyles/Project.xml

Lines changed: 108 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 16 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ android {
1212
targetSdkVersion 28
1313
versionCode 1
1414
versionName "1.0"
15-
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
15+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1616
externalNativeBuild {
1717
cmake {
1818
cppFlags "-std=c++11 -frtti"
@@ -35,13 +35,11 @@ android {
3535
dependencies {
3636
implementation fileTree(dir: 'libs', include: ['*.jar'])
3737
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
38-
implementation 'com.android.support:appcompat-v7:28.0.0'
39-
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
4038
implementation project(path: ':libvideostudio')
41-
implementation 'com.github.kenneycode:GLKit:1.1.0'
4239
testImplementation 'junit:junit:4.12'
43-
implementation 'com.github.kenneycode:FunRenderer:1.2.0'
44-
implementation 'com.android.support:recyclerview-v7:28.0.0'
45-
androidTestImplementation 'com.android.support.test:runner:1.0.2'
46-
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
40+
implementation 'com.github.kenneycode:fusion:1.0.3'
41+
androidTestImplementation 'androidx.test:runner:1.1.0'
42+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
43+
implementation 'androidx.recyclerview:recyclerview:1.1.0'
44+
implementation 'androidx.appcompat:appcompat:1.1.0'
4745
}

app/src/androidTest/java/io/github/kenneycode/videostudio/ExampleInstrumentedTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package io.github.kenneycode.videostudio
22

3-
import android.support.test.InstrumentationRegistry
4-
import android.support.test.runner.AndroidJUnit4
3+
import androidx.test.platform.app.InstrumentationRegistry
4+
import androidx.test.ext.junit.runners.AndroidJUnit4
55

66
import org.junit.Test
77
import org.junit.runner.RunWith

app/src/main/AndroidManifest.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3-
package="io.github.kenneycode.videostudio.demo">
3+
package="io.github.kenneycode.videostudio.demo"
4+
xmlns:tools="http://schemas.android.com/tools">
45

56
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
67
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
@@ -19,7 +20,7 @@
1920
<category android:name="android.intent.category.LAUNCHER" />
2021
</intent-filter>
2122
</activity>
22-
<activity android:name=".SampleVideoDecoder" />
23+
<activity android:name=".samples.SampleVideoDecoder" />
2324
<activity android:name=".samples.SampleVideoEncoder" />
2425
</application>
2526

app/src/main/java/io/github/kenneycode/videostudio/demo/MainActivity.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
package io.github.kenneycode.videostudio.demo
22

33
import android.content.Intent
4-
import android.support.v7.app.AppCompatActivity
54
import android.os.Bundle
6-
import android.support.v7.widget.LinearLayoutManager
7-
import android.support.v7.widget.RecyclerView
85
import android.view.LayoutInflater
96
import android.view.View
107
import android.view.ViewGroup
118
import android.widget.Button
9+
import androidx.appcompat.app.AppCompatActivity
10+
import androidx.recyclerview.widget.LinearLayoutManager
11+
import androidx.recyclerview.widget.RecyclerView
12+
import io.github.kenneycode.videostudio.demo.samples.SampleVideoDecoder
1213
import io.github.kenneycode.videostudio.demo.samples.SampleVideoEncoder
1314
import kotlinx.android.synthetic.main.activity_main.*
1415

Lines changed: 44 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
package io.github.kenneycode.videostudio.demo
1+
package io.github.kenneycode.videostudio.demo.samples
22

33
import android.graphics.SurfaceTexture
4-
import android.opengl.GLES11Ext
5-
import android.opengl.GLES30
64
import android.opengl.GLSurfaceView
7-
import android.support.v7.app.AppCompatActivity
85
import android.os.Bundle
96
import 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
1615
import io.github.kenneycode.videostudio.VideoDecoder
16+
import io.github.kenneycode.videostudio.demo.R
1717
import kotlinx.android.synthetic.main.activity_sample_common.*
1818
import javax.microedition.khronos.egl.EGLConfig
1919
import 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
}

app/src/main/java/io/github/kenneycode/videostudio/demo/samples/SampleVideoEncoder.kt

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,8 @@ import android.graphics.Bitmap
44
import android.graphics.BitmapFactory
55
import android.graphics.Matrix
66
import android.os.Bundle
7-
import android.support.v4.app.Fragment
8-
import android.support.v7.app.AppCompatActivity
9-
import android.util.Log
10-
import android.view.LayoutInflater
11-
import android.view.View
12-
import android.view.ViewGroup
13-
import io.github.kenneycode.glkit.EGL
7+
import androidx.appcompat.app.AppCompatActivity
8+
import io.github.kenneycode.fusion.context.FusionEGL
149
import io.github.kenneycode.videostudio.GLUtil
1510
import io.github.kenneycode.videostudio.VideoEncoder
1611
import io.github.kenneycode.videostudio.demo.R
@@ -32,8 +27,8 @@ class SampleVideoEncoder : AppCompatActivity() {
3227
super.onCreate(savedInstanceState)
3328
setContentView(R.layout.activity_sample_common)
3429
Thread {
35-
val egl = EGL().apply {
36-
init()
30+
val egl = FusionEGL().apply {
31+
init(null)
3732
bind()
3833
}
3934
val bitmap = decodeBitmapFromAssets("test.png")

app/src/main/res/layout/activity_main.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
android:layout_width="match_parent"
55
android:layout_height="match_parent" >
66

7-
<android.support.v7.widget.RecyclerView
7+
<androidx.recyclerview.widget.RecyclerView
88
android:id="@+id/samples"
99
android:layout_width="match_parent"
1010
android:layout_height="match_parent" />

0 commit comments

Comments
 (0)