Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
qq_26386469
GSYVideoPlayer
提交
09d53b1a
G
GSYVideoPlayer
项目概览
qq_26386469
/
GSYVideoPlayer
与 Fork 源项目一致
从无法访问的项目Fork
通知
5
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
GSYVideoPlayer
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
09d53b1a
编写于
9月 21, 2017
作者:
G
guoshuyu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
修改gl render,增加顶层效果渲染支持
上级
5e26180f
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
359 addition
and
275 deletion
+359
-275
app/src/main/java/com/example/gsyvideoplayer/DetailFilterActivity.java
...java/com/example/gsyvideoplayer/DetailFilterActivity.java
+44
-0
app/src/main/res/layout/activity_detail_filter.xml
app/src/main/res/layout/activity_detail_filter.xml
+8
-1
gsyVideoPlayer-java/src/main/java/com/shuyu/gsyvideoplayer/GSYRenderView.java
...src/main/java/com/shuyu/gsyvideoplayer/GSYRenderView.java
+5
-1
gsyVideoPlayer-java/src/main/java/com/shuyu/gsyvideoplayer/GSYVideoGLView.java
...rc/main/java/com/shuyu/gsyvideoplayer/GSYVideoGLView.java
+8
-270
gsyVideoPlayer-java/src/main/java/com/shuyu/gsyvideoplayer/GSYVideoGLViewSimpleRender.java
.../com/shuyu/gsyvideoplayer/GSYVideoGLViewSimpleRender.java
+279
-0
gsyVideoPlayer-java/src/main/java/com/shuyu/gsyvideoplayer/video/base/GSYTextureRenderView.java
...shuyu/gsyvideoplayer/video/base/GSYTextureRenderView.java
+13
-1
gsyVideoPlayer/build.gradle
gsyVideoPlayer/build.gradle
+2
-2
未找到文件。
app/src/main/java/com/example/gsyvideoplayer/DetailFilterActivity.java
浏览文件 @
09d53b1a
package
com.example.gsyvideoplayer
;
import
android.graphics.Color
;
import
android.opengl.Matrix
;
import
android.os.Bundle
;
import
android.support.v4.widget.NestedScrollView
;
import
android.view.View
;
...
...
@@ -45,6 +46,9 @@ import com.shuyu.gsyvideoplayer.listener.LockClickListener;
import
com.shuyu.gsyvideoplayer.utils.GSYVideoType
;
import
com.shuyu.gsyvideoplayer.video.base.GSYBaseVideoPlayer
;
import
java.util.Timer
;
import
java.util.TimerTask
;
import
butterknife.BindView
;
import
butterknife.ButterKnife
;
...
...
@@ -71,6 +75,10 @@ public class DetailFilterActivity extends GSYBaseActivityDetail {
@BindView
(
R
.
id
.
jump
)
Button
jump
;
@BindView
(
R
.
id
.
change_anima
)
Button
anima
;
private
int
type
=
0
;
private
int
backupRendType
;
...
...
@@ -79,6 +87,12 @@ public class DetailFilterActivity extends GSYBaseActivityDetail {
private
String
url
=
"http://baobab.wdjcdn.com/14564977406580.mp4"
;
private
Timer
timer
=
new
Timer
();
private
TaskLocal
mTimerTask
;
private
int
percentage
=
1
;
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
...
...
@@ -118,6 +132,15 @@ public class DetailFilterActivity extends GSYBaseActivityDetail {
//startActivity(new Intent(DetailControlActivity.this, MainActivity.class));
}
});
anima
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
v
)
{
cancelTask
();
mTimerTask
=
new
TaskLocal
();
timer
.
schedule
(
mTimerTask
,
0
,
50
);
}
});
}
@Override
...
...
@@ -152,6 +175,27 @@ public class DetailFilterActivity extends GSYBaseActivityDetail {
protected
void
onDestroy
()
{
super
.
onDestroy
();
GSYVideoType
.
setRenderType
(
backupRendType
);
cancelTask
();
}
private
void
cancelTask
()
{
if
(
mTimerTask
!=
null
)
{
mTimerTask
.
cancel
();
mTimerTask
=
null
;
}
}
private
class
TaskLocal
extends
TimerTask
{
@Override
public
void
run
()
{
float
[]
transform
=
new
float
[
16
];
Matrix
.
setRotateM
(
transform
,
0
,
360
*
percentage
/
100
,
0
,
0
,
1.0f
);
detailPlayer
.
setMatrixGL
(
transform
);
percentage
++;
if
(
percentage
>
100
)
{
percentage
=
1
;
}
}
}
private
void
loadCover
(
ImageView
imageView
,
String
url
)
{
...
...
app/src/main/res/layout/activity_detail_filter.xml
浏览文件 @
09d53b1a
...
...
@@ -46,13 +46,20 @@
android:layout_margin=
"10dp"
android:text=
"切换效果"
/>
<Button
android:id=
"@+id/change_anima"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_margin=
"10dp"
android:layout_toRightOf=
"@+id/change_filter"
android:text=
"GL动画"
/>
<Button
android:id=
"@+id/jump"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_margin=
"10dp"
android:layout_toRightOf=
"@+id/change_
filter
"
android:layout_toRightOf=
"@+id/change_
anima
"
android:text=
"跳转"
/>
</RelativeLayout>
...
...
gsyVideoPlayer-java/src/main/java/com/shuyu/gsyvideoplayer/GSYRenderView.java
浏览文件 @
09d53b1a
...
...
@@ -152,7 +152,7 @@ public class GSYRenderView {
/**
* 添加播放的view
*/
public
void
addGLView
(
Context
context
,
ViewGroup
textureViewContainer
,
int
rotate
,
GSYVideoGLView
.
onGSYSurfaceListener
gsySurfaceListener
,
GSYVideoGLView
.
ShaderInterface
effect
)
{
public
void
addGLView
(
Context
context
,
ViewGroup
textureViewContainer
,
int
rotate
,
GSYVideoGLView
.
onGSYSurfaceListener
gsySurfaceListener
,
GSYVideoGLView
.
ShaderInterface
effect
,
float
[]
transform
)
{
if
(
textureViewContainer
.
getChildCount
()
>
0
)
{
textureViewContainer
.
removeAllViews
();
}
...
...
@@ -163,6 +163,10 @@ public class GSYRenderView {
mShowView
=
gsyVideoGLView
;
if
(
transform
!=
null
&&
transform
.
length
==
16
)
{
gsyVideoGLView
.
setMVPMatrix
(
transform
);
}
int
params
=
getTextureParams
();
if
(
textureViewContainer
instanceof
RelativeLayout
)
{
...
...
gsyVideoPlayer-java/src/main/java/com/shuyu/gsyvideoplayer/GSYVideoGLView.java
浏览文件 @
09d53b1a
...
...
@@ -2,24 +2,13 @@ package com.shuyu.gsyvideoplayer;
import
android.annotation.SuppressLint
;
import
android.content.Context
;
import
android.graphics.SurfaceTexture
;
import
android.opengl.GLES20
;
import
android.opengl.GLSurfaceView
;
import
android.opengl.Matrix
;
import
android.util.AttributeSet
;
import
android.util.Log
;
import
android.view.Surface
;
import
com.shuyu.gsyvideoplayer.utils.MeasureHelper
;
import
com.shuyu.gsyvideoplayer.effect.NoEffect
;
import
java.nio.ByteBuffer
;
import
java.nio.ByteOrder
;
import
java.nio.FloatBuffer
;
import
javax.microedition.khronos.egl.EGLConfig
;
import
javax.microedition.khronos.opengles.GL10
;
/**
* 在videffects的基础上调整的
...
...
@@ -31,7 +20,7 @@ public class GSYVideoGLView extends GLSurfaceView {
private
static
final
String
TAG
=
GSYVideoGLView
.
class
.
getName
();
private
Video
Render
mRenderer
;
private
GSYVideoGLViewSimple
Render
mRenderer
;
private
Context
mContext
;
...
...
@@ -62,7 +51,7 @@ public class GSYVideoGLView extends GLSurfaceView {
private
void
init
(
Context
context
)
{
mContext
=
context
;
setEGLContextClientVersion
(
2
);
mRenderer
=
new
Video
Render
();
mRenderer
=
new
GSYVideoGLViewSimple
Render
();
measureHelper
=
new
MeasureHelper
(
this
);
setRenderer
(
mRenderer
);
mRenderer
.
setSurfaceView
(
GSYVideoGLView
.
this
);
...
...
@@ -80,6 +69,12 @@ public class GSYVideoGLView extends GLSurfaceView {
}
}
public
void
setMVPMatrix
(
float
[]
MVPMatrix
)
{
if
(
MVPMatrix
!=
null
)
{
mRenderer
.
setMVPMatrix
(
MVPMatrix
);
}
}
@Override
protected
void
onMeasure
(
int
widthMeasureSpec
,
int
heightMeasureSpec
)
{
if
(
GSYVideoManager
.
instance
().
getMediaPlayer
()
!=
null
)
{
...
...
@@ -111,261 +106,4 @@ public class GSYVideoGLView extends GLSurfaceView {
return
measureHelper
.
getMeasuredWidth
();
}
private
static
class
VideoRender
implements
Renderer
,
SurfaceTexture
.
OnFrameAvailableListener
{
private
static
String
TAG
=
VideoRender
.
class
.
getName
();
private
static
final
int
FLOAT_SIZE_BYTES
=
4
;
private
static
final
int
TRIANGLE_VERTICES_DATA_STRIDE_BYTES
=
5
*
FLOAT_SIZE_BYTES
;
private
static
final
int
TRIANGLE_VERTICES_DATA_POS_OFFSET
=
0
;
private
static
final
int
TRIANGLE_VERTICES_DATA_UV_OFFSET
=
3
;
private
static
final
int
GL_TEXTURE_EXTERNAL_OES
=
0x8D65
;
private
final
float
[]
mTriangleVerticesData
=
{
// X, Y, Z, U, V
-
1.0f
,
-
1.0f
,
0
,
0
.
f
,
0
.
f
,
1.0f
,
-
1.0f
,
0
,
1
.
f
,
0
.
f
,
-
1.0f
,
1.0f
,
0
,
0
.
f
,
1
.
f
,
1.0f
,
1.0f
,
0
,
1
.
f
,
1
.
f
,};
private
FloatBuffer
mTriangleVertices
;
private
final
String
mVertexShader
=
"uniform mat4 uMVPMatrix;\n"
+
"uniform mat4 uSTMatrix;\n"
+
"attribute vec4 aPosition;\n"
+
"attribute vec4 aTextureCoord;\n"
+
"varying vec2 vTextureCoord;\n"
+
"void main() {\n"
+
" gl_Position = uMVPMatrix * aPosition;\n"
+
" vTextureCoord = (uSTMatrix * aTextureCoord).xy;\n"
+
"}\n"
;
private
float
[]
mMVPMatrix
=
new
float
[
16
];
private
float
[]
mSTMatrix
=
new
float
[
16
];
private
int
mProgram
;
private
int
mTextureID
[]
=
new
int
[
2
];
private
int
muMVPMatrixHandle
;
private
int
muSTMatrixHandle
;
private
int
maPositionHandle
;
private
int
maTextureHandle
;
private
boolean
updateSurface
=
false
;
private
SurfaceTexture
mSurface
;
private
onGSYSurfaceListener
mGSYSurfaceListener
;
private
ShaderInterface
mEffect
=
new
NoEffect
();
private
GLSurfaceView
mSurfaceView
;
public
void
setEffect
(
ShaderInterface
shaderEffect
)
{
if
(
shaderEffect
!=
null
)
mEffect
=
shaderEffect
;
}
public
VideoRender
()
{
mTriangleVertices
=
ByteBuffer
.
allocateDirect
(
mTriangleVerticesData
.
length
*
FLOAT_SIZE_BYTES
)
.
order
(
ByteOrder
.
nativeOrder
()).
asFloatBuffer
();
mTriangleVertices
.
put
(
mTriangleVerticesData
).
position
(
0
);
Matrix
.
setIdentityM
(
mSTMatrix
,
0
);
}
public
void
setGSYSurfaceListener
(
onGSYSurfaceListener
onSurfaceListener
)
{
this
.
mGSYSurfaceListener
=
onSurfaceListener
;
}
public
void
setSurfaceView
(
GLSurfaceView
surfaceView
)
{
this
.
mSurfaceView
=
surfaceView
;
}
@Override
public
void
onDrawFrame
(
GL10
glUnused
)
{
synchronized
(
this
)
{
if
(
updateSurface
)
{
mSurface
.
updateTexImage
();
mSurface
.
getTransformMatrix
(
mSTMatrix
);
updateSurface
=
false
;
}
}
mProgram
=
createProgram
(
mVertexShader
,
mEffect
.
getShader
(
mSurfaceView
));
GLES20
.
glClearColor
(
0.0f
,
1.0f
,
0.0f
,
1.0f
);
GLES20
.
glClear
(
GLES20
.
GL_DEPTH_BUFFER_BIT
|
GLES20
.
GL_COLOR_BUFFER_BIT
);
GLES20
.
glUseProgram
(
mProgram
);
checkGlError
(
"glUseProgram"
);
GLES20
.
glActiveTexture
(
GLES20
.
GL_TEXTURE0
);
GLES20
.
glBindTexture
(
GL_TEXTURE_EXTERNAL_OES
,
mTextureID
[
0
]);
mTriangleVertices
.
position
(
TRIANGLE_VERTICES_DATA_POS_OFFSET
);
GLES20
.
glVertexAttribPointer
(
maPositionHandle
,
3
,
GLES20
.
GL_FLOAT
,
false
,
TRIANGLE_VERTICES_DATA_STRIDE_BYTES
,
mTriangleVertices
);
checkGlError
(
"glVertexAttribPointer maPosition"
);
GLES20
.
glEnableVertexAttribArray
(
maPositionHandle
);
checkGlError
(
"glEnableVertexAttribArray maPositionHandle"
);
mTriangleVertices
.
position
(
TRIANGLE_VERTICES_DATA_UV_OFFSET
);
GLES20
.
glVertexAttribPointer
(
maTextureHandle
,
3
,
GLES20
.
GL_FLOAT
,
false
,
TRIANGLE_VERTICES_DATA_STRIDE_BYTES
,
mTriangleVertices
);
checkGlError
(
"glVertexAttribPointer maTextureHandle"
);
GLES20
.
glEnableVertexAttribArray
(
maTextureHandle
);
checkGlError
(
"glEnableVertexAttribArray maTextureHandle"
);
Matrix
.
setIdentityM
(
mMVPMatrix
,
0
);
GLES20
.
glUniformMatrix4fv
(
muMVPMatrixHandle
,
1
,
false
,
mMVPMatrix
,
0
);
GLES20
.
glUniformMatrix4fv
(
muSTMatrixHandle
,
1
,
false
,
mSTMatrix
,
0
);
GLES20
.
glDrawArrays
(
GLES20
.
GL_TRIANGLE_STRIP
,
0
,
4
);
checkGlError
(
"glDrawArrays"
);
GLES20
.
glFinish
();
}
@Override
public
void
onSurfaceChanged
(
GL10
glUnused
,
int
width
,
int
height
)
{
GLES20
.
glViewport
(
0
,
0
,
width
,
height
);
}
@Override
public
void
onSurfaceCreated
(
GL10
glUnused
,
EGLConfig
config
)
{
mProgram
=
createProgram
(
mVertexShader
,
mEffect
.
getShader
(
mSurfaceView
));
if
(
mProgram
==
0
)
{
return
;
}
maPositionHandle
=
GLES20
.
glGetAttribLocation
(
mProgram
,
"aPosition"
);
checkGlError
(
"glGetAttribLocation aPosition"
);
if
(
maPositionHandle
==
-
1
)
{
throw
new
RuntimeException
(
"Could not get attrib location for aPosition"
);
}
maTextureHandle
=
GLES20
.
glGetAttribLocation
(
mProgram
,
"aTextureCoord"
);
checkGlError
(
"glGetAttribLocation aTextureCoord"
);
if
(
maTextureHandle
==
-
1
)
{
throw
new
RuntimeException
(
"Could not get attrib location for aTextureCoord"
);
}
muMVPMatrixHandle
=
GLES20
.
glGetUniformLocation
(
mProgram
,
"uMVPMatrix"
);
checkGlError
(
"glGetUniformLocation uMVPMatrix"
);
if
(
muMVPMatrixHandle
==
-
1
)
{
throw
new
RuntimeException
(
"Could not get attrib location for uMVPMatrix"
);
}
muSTMatrixHandle
=
GLES20
.
glGetUniformLocation
(
mProgram
,
"uSTMatrix"
);
checkGlError
(
"glGetUniformLocation uSTMatrix"
);
if
(
muSTMatrixHandle
==
-
1
)
{
throw
new
RuntimeException
(
"Could not get attrib location for uSTMatrix"
);
}
// int[] textures = new int[1];
GLES20
.
glGenTextures
(
2
,
mTextureID
,
0
);
// GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureID[0]);
// mTextureID = textures[0];
GLES20
.
glBindTexture
(
GL_TEXTURE_EXTERNAL_OES
,
mTextureID
[
0
]);
checkGlError
(
"glBindTexture mTextureID"
);
// GLES20.glTexParameterf(GL_TEXTURE_EXTERNAL_OES,
// GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
// GLES20.glTexParameterf(GL_TEXTURE_EXTERNAL_OES,
// GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
GLES20
.
glTexParameteri
(
GLES20
.
GL_TEXTURE_2D
,
GLES20
.
GL_TEXTURE_MIN_FILTER
,
GLES20
.
GL_LINEAR
);
GLES20
.
glTexParameteri
(
GLES20
.
GL_TEXTURE_2D
,
GLES20
.
GL_TEXTURE_MAG_FILTER
,
GLES20
.
GL_LINEAR
);
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
);
/*
* Create the SurfaceTexture that will feed this textureID, and pass
* it to the MediaPlayer
*/
mSurface
=
new
SurfaceTexture
(
mTextureID
[
0
]);
mSurface
.
setOnFrameAvailableListener
(
this
);
Surface
surface
=
new
Surface
(
mSurface
);
if
(
mGSYSurfaceListener
!=
null
)
{
mGSYSurfaceListener
.
onSurfaceAvailable
(
surface
);
}
//surface.release();
}
@Override
synchronized
public
void
onFrameAvailable
(
SurfaceTexture
surface
)
{
updateSurface
=
true
;
}
private
int
loadShader
(
int
shaderType
,
String
source
)
{
int
shader
=
GLES20
.
glCreateShader
(
shaderType
);
if
(
shader
!=
0
)
{
GLES20
.
glShaderSource
(
shader
,
source
);
GLES20
.
glCompileShader
(
shader
);
int
[]
compiled
=
new
int
[
1
];
GLES20
.
glGetShaderiv
(
shader
,
GLES20
.
GL_COMPILE_STATUS
,
compiled
,
0
);
if
(
compiled
[
0
]
==
0
)
{
Log
.
e
(
TAG
,
"Could not compile shader "
+
shaderType
+
":"
);
Log
.
e
(
TAG
,
GLES20
.
glGetShaderInfoLog
(
shader
));
GLES20
.
glDeleteShader
(
shader
);
shader
=
0
;
}
}
return
shader
;
}
private
int
createProgram
(
String
vertexSource
,
String
fragmentSource
)
{
int
vertexShader
=
loadShader
(
GLES20
.
GL_VERTEX_SHADER
,
vertexSource
);
if
(
vertexShader
==
0
)
{
return
0
;
}
int
pixelShader
=
loadShader
(
GLES20
.
GL_FRAGMENT_SHADER
,
fragmentSource
);
if
(
pixelShader
==
0
)
{
return
0
;
}
int
program
=
GLES20
.
glCreateProgram
();
if
(
program
!=
0
)
{
GLES20
.
glAttachShader
(
program
,
vertexShader
);
checkGlError
(
"glAttachShader"
);
GLES20
.
glAttachShader
(
program
,
pixelShader
);
checkGlError
(
"glAttachShader"
);
GLES20
.
glLinkProgram
(
program
);
int
[]
linkStatus
=
new
int
[
1
];
GLES20
.
glGetProgramiv
(
program
,
GLES20
.
GL_LINK_STATUS
,
linkStatus
,
0
);
if
(
linkStatus
[
0
]
!=
GLES20
.
GL_TRUE
)
{
Log
.
e
(
TAG
,
"Could not link program: "
);
Log
.
e
(
TAG
,
GLES20
.
glGetProgramInfoLog
(
program
));
GLES20
.
glDeleteProgram
(
program
);
program
=
0
;
}
}
return
program
;
}
private
void
checkGlError
(
String
op
)
{
int
error
;
while
((
error
=
GLES20
.
glGetError
())
!=
GLES20
.
GL_NO_ERROR
)
{
Log
.
e
(
TAG
,
op
+
": glError "
+
error
);
throw
new
RuntimeException
(
op
+
": glError "
+
error
);
}
}
}
}
gsyVideoPlayer-java/src/main/java/com/shuyu/gsyvideoplayer/GSYVideoGLViewSimpleRender.java
0 → 100644
浏览文件 @
09d53b1a
package
com.shuyu.gsyvideoplayer
;
import
android.annotation.SuppressLint
;
import
android.graphics.SurfaceTexture
;
import
android.opengl.GLES20
;
import
android.opengl.GLSurfaceView
;
import
android.opengl.Matrix
;
import
android.util.Log
;
import
android.view.Surface
;
import
com.shuyu.gsyvideoplayer.effect.NoEffect
;
import
java.nio.ByteBuffer
;
import
java.nio.ByteOrder
;
import
java.nio.FloatBuffer
;
import
javax.microedition.khronos.egl.EGLConfig
;
import
javax.microedition.khronos.opengles.GL10
;
/**
* 在videffects的基础上调整的
* <p>
* 原 @author sheraz.khilji
*/
@SuppressLint
(
"ViewConstructor"
)
public
class
GSYVideoGLViewSimpleRender
implements
GLSurfaceView
.
Renderer
,
SurfaceTexture
.
OnFrameAvailableListener
{
private
static
String
TAG
=
GSYVideoGLViewSimpleRender
.
class
.
getName
();
private
static
final
int
FLOAT_SIZE_BYTES
=
4
;
private
static
final
int
TRIANGLE_VERTICES_DATA_STRIDE_BYTES
=
5
*
FLOAT_SIZE_BYTES
;
private
static
final
int
TRIANGLE_VERTICES_DATA_POS_OFFSET
=
0
;
private
static
final
int
TRIANGLE_VERTICES_DATA_UV_OFFSET
=
3
;
private
static
final
int
GL_TEXTURE_EXTERNAL_OES
=
0x8D65
;
private
final
float
[]
mTriangleVerticesData
=
{
// X, Y, Z, U, V
-
1.0f
,
-
1.0f
,
0
,
0
.
f
,
0
.
f
,
1.0f
,
-
1.0f
,
0
,
1
.
f
,
0
.
f
,
-
1.0f
,
1.0f
,
0
,
0
.
f
,
1
.
f
,
1.0f
,
1.0f
,
0
,
1
.
f
,
1
.
f
,};
private
FloatBuffer
mTriangleVertices
;
private
final
String
mVertexShader
=
"uniform mat4 uMVPMatrix;\n"
+
"uniform mat4 uSTMatrix;\n"
+
"attribute vec4 aPosition;\n"
+
"attribute vec4 aTextureCoord;\n"
+
"varying vec2 vTextureCoord;\n"
+
"void main() {\n"
+
" gl_Position = uMVPMatrix * aPosition;\n"
+
" vTextureCoord = (uSTMatrix * aTextureCoord).xy;\n"
+
"}\n"
;
private
float
[]
mMVPMatrix
=
new
float
[
16
];
private
float
[]
mSTMatrix
=
new
float
[
16
];
private
int
mProgram
;
private
int
mTextureID
[]
=
new
int
[
2
];
private
int
muMVPMatrixHandle
;
private
int
muSTMatrixHandle
;
private
int
maPositionHandle
;
private
int
maTextureHandle
;
private
boolean
updateSurface
=
false
;
private
boolean
mChangeMVPMatrix
=
false
;
private
SurfaceTexture
mSurface
;
private
GSYVideoGLView
.
onGSYSurfaceListener
mGSYSurfaceListener
;
private
GSYVideoGLView
.
ShaderInterface
mEffect
=
new
NoEffect
();
private
GLSurfaceView
mSurfaceView
;
public
void
setEffect
(
GSYVideoGLView
.
ShaderInterface
shaderEffect
)
{
if
(
shaderEffect
!=
null
)
mEffect
=
shaderEffect
;
}
public
GSYVideoGLViewSimpleRender
()
{
mTriangleVertices
=
ByteBuffer
.
allocateDirect
(
mTriangleVerticesData
.
length
*
FLOAT_SIZE_BYTES
)
.
order
(
ByteOrder
.
nativeOrder
()).
asFloatBuffer
();
mTriangleVertices
.
put
(
mTriangleVerticesData
).
position
(
0
);
Matrix
.
setIdentityM
(
mSTMatrix
,
0
);
Matrix
.
setIdentityM
(
mMVPMatrix
,
0
);
}
public
void
setGSYSurfaceListener
(
GSYVideoGLView
.
onGSYSurfaceListener
onSurfaceListener
)
{
this
.
mGSYSurfaceListener
=
onSurfaceListener
;
}
public
void
setSurfaceView
(
GLSurfaceView
surfaceView
)
{
this
.
mSurfaceView
=
surfaceView
;
}
public
void
setMVPMatrix
(
float
[]
MVPMatrix
)
{
this
.
mMVPMatrix
=
MVPMatrix
;
mChangeMVPMatrix
=
true
;
}
@Override
public
void
onDrawFrame
(
GL10
glUnused
)
{
synchronized
(
this
)
{
if
(
updateSurface
)
{
mSurface
.
updateTexImage
();
mSurface
.
getTransformMatrix
(
mSTMatrix
);
updateSurface
=
false
;
}
}
mProgram
=
createProgram
(
mVertexShader
,
mEffect
.
getShader
(
mSurfaceView
));
GLES20
.
glClearColor
(
0.0f
,
0.0f
,
0.0f
,
1.0f
);
GLES20
.
glClear
(
GLES20
.
GL_DEPTH_BUFFER_BIT
|
GLES20
.
GL_COLOR_BUFFER_BIT
);
GLES20
.
glUseProgram
(
mProgram
);
checkGlError
(
"glUseProgram"
);
GLES20
.
glActiveTexture
(
GLES20
.
GL_TEXTURE0
);
GLES20
.
glBindTexture
(
GL_TEXTURE_EXTERNAL_OES
,
mTextureID
[
0
]);
mTriangleVertices
.
position
(
TRIANGLE_VERTICES_DATA_POS_OFFSET
);
GLES20
.
glVertexAttribPointer
(
maPositionHandle
,
3
,
GLES20
.
GL_FLOAT
,
false
,
TRIANGLE_VERTICES_DATA_STRIDE_BYTES
,
mTriangleVertices
);
checkGlError
(
"glVertexAttribPointer maPosition"
);
GLES20
.
glEnableVertexAttribArray
(
maPositionHandle
);
checkGlError
(
"glEnableVertexAttribArray maPositionHandle"
);
mTriangleVertices
.
position
(
TRIANGLE_VERTICES_DATA_UV_OFFSET
);
GLES20
.
glVertexAttribPointer
(
maTextureHandle
,
3
,
GLES20
.
GL_FLOAT
,
false
,
TRIANGLE_VERTICES_DATA_STRIDE_BYTES
,
mTriangleVertices
);
checkGlError
(
"glVertexAttribPointer maTextureHandle"
);
GLES20
.
glEnableVertexAttribArray
(
maTextureHandle
);
checkGlError
(
"glEnableVertexAttribArray maTextureHandle"
);
GLES20
.
glUniformMatrix4fv
(
muMVPMatrixHandle
,
1
,
false
,
mMVPMatrix
,
0
);
GLES20
.
glUniformMatrix4fv
(
muSTMatrixHandle
,
1
,
false
,
mSTMatrix
,
0
);
GLES20
.
glDrawArrays
(
GLES20
.
GL_TRIANGLE_STRIP
,
0
,
4
);
checkGlError
(
"glDrawArrays"
);
GLES20
.
glFinish
();
}
@Override
public
void
onSurfaceChanged
(
GL10
glUnused
,
int
width
,
int
height
)
{
GLES20
.
glViewport
(
0
,
0
,
width
,
height
);
}
@Override
public
void
onSurfaceCreated
(
GL10
glUnused
,
EGLConfig
config
)
{
mProgram
=
createProgram
(
mVertexShader
,
mEffect
.
getShader
(
mSurfaceView
));
if
(
mProgram
==
0
)
{
return
;
}
maPositionHandle
=
GLES20
.
glGetAttribLocation
(
mProgram
,
"aPosition"
);
checkGlError
(
"glGetAttribLocation aPosition"
);
if
(
maPositionHandle
==
-
1
)
{
throw
new
RuntimeException
(
"Could not get attrib location for aPosition"
);
}
maTextureHandle
=
GLES20
.
glGetAttribLocation
(
mProgram
,
"aTextureCoord"
);
checkGlError
(
"glGetAttribLocation aTextureCoord"
);
if
(
maTextureHandle
==
-
1
)
{
throw
new
RuntimeException
(
"Could not get attrib location for aTextureCoord"
);
}
muMVPMatrixHandle
=
GLES20
.
glGetUniformLocation
(
mProgram
,
"uMVPMatrix"
);
checkGlError
(
"glGetUniformLocation uMVPMatrix"
);
if
(
muMVPMatrixHandle
==
-
1
)
{
throw
new
RuntimeException
(
"Could not get attrib location for uMVPMatrix"
);
}
muSTMatrixHandle
=
GLES20
.
glGetUniformLocation
(
mProgram
,
"uSTMatrix"
);
checkGlError
(
"glGetUniformLocation uSTMatrix"
);
if
(
muSTMatrixHandle
==
-
1
)
{
throw
new
RuntimeException
(
"Could not get attrib location for uSTMatrix"
);
}
GLES20
.
glGenTextures
(
2
,
mTextureID
,
0
);
GLES20
.
glBindTexture
(
GL_TEXTURE_EXTERNAL_OES
,
mTextureID
[
0
]);
checkGlError
(
"glBindTexture mTextureID"
);
GLES20
.
glTexParameteri
(
GLES20
.
GL_TEXTURE_2D
,
GLES20
.
GL_TEXTURE_MIN_FILTER
,
GLES20
.
GL_LINEAR
);
GLES20
.
glTexParameteri
(
GLES20
.
GL_TEXTURE_2D
,
GLES20
.
GL_TEXTURE_MAG_FILTER
,
GLES20
.
GL_LINEAR
);
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
);
mSurface
=
new
SurfaceTexture
(
mTextureID
[
0
]);
mSurface
.
setOnFrameAvailableListener
(
this
);
Surface
surface
=
new
Surface
(
mSurface
);
if
(
mGSYSurfaceListener
!=
null
)
{
mGSYSurfaceListener
.
onSurfaceAvailable
(
surface
);
}
}
@Override
synchronized
public
void
onFrameAvailable
(
SurfaceTexture
surface
)
{
updateSurface
=
true
;
}
private
int
loadShader
(
int
shaderType
,
String
source
)
{
int
shader
=
GLES20
.
glCreateShader
(
shaderType
);
if
(
shader
!=
0
)
{
GLES20
.
glShaderSource
(
shader
,
source
);
GLES20
.
glCompileShader
(
shader
);
int
[]
compiled
=
new
int
[
1
];
GLES20
.
glGetShaderiv
(
shader
,
GLES20
.
GL_COMPILE_STATUS
,
compiled
,
0
);
if
(
compiled
[
0
]
==
0
)
{
Log
.
e
(
TAG
,
"Could not compile shader "
+
shaderType
+
":"
);
Log
.
e
(
TAG
,
GLES20
.
glGetShaderInfoLog
(
shader
));
GLES20
.
glDeleteShader
(
shader
);
shader
=
0
;
}
}
return
shader
;
}
private
int
createProgram
(
String
vertexSource
,
String
fragmentSource
)
{
int
vertexShader
=
loadShader
(
GLES20
.
GL_VERTEX_SHADER
,
vertexSource
);
if
(
vertexShader
==
0
)
{
return
0
;
}
int
pixelShader
=
loadShader
(
GLES20
.
GL_FRAGMENT_SHADER
,
fragmentSource
);
if
(
pixelShader
==
0
)
{
return
0
;
}
int
program
=
GLES20
.
glCreateProgram
();
if
(
program
!=
0
)
{
GLES20
.
glAttachShader
(
program
,
vertexShader
);
checkGlError
(
"glAttachShader"
);
GLES20
.
glAttachShader
(
program
,
pixelShader
);
checkGlError
(
"glAttachShader"
);
GLES20
.
glLinkProgram
(
program
);
int
[]
linkStatus
=
new
int
[
1
];
GLES20
.
glGetProgramiv
(
program
,
GLES20
.
GL_LINK_STATUS
,
linkStatus
,
0
);
if
(
linkStatus
[
0
]
!=
GLES20
.
GL_TRUE
)
{
Log
.
e
(
TAG
,
"Could not link program: "
);
Log
.
e
(
TAG
,
GLES20
.
glGetProgramInfoLog
(
program
));
GLES20
.
glDeleteProgram
(
program
);
program
=
0
;
}
}
return
program
;
}
private
void
checkGlError
(
String
op
)
{
int
error
;
while
((
error
=
GLES20
.
glGetError
())
!=
GLES20
.
GL_NO_ERROR
)
{
Log
.
e
(
TAG
,
op
+
": glError "
+
error
);
throw
new
RuntimeException
(
op
+
": glError "
+
error
);
}
}
}
gsyVideoPlayer-java/src/main/java/com/shuyu/gsyvideoplayer/video/base/GSYTextureRenderView.java
浏览文件 @
09d53b1a
...
...
@@ -41,6 +41,8 @@ public abstract class GSYTextureRenderView extends FrameLayout implements Textur
//滤镜
protected
GSYVideoGLView
.
ShaderInterface
mEffectFilter
=
new
NoEffect
();
protected
float
[]
mMatrixGL
=
null
;
//画面选择角度
protected
int
mRotate
;
...
...
@@ -133,7 +135,7 @@ public abstract class GSYTextureRenderView extends FrameLayout implements Textur
mTextureView
.
addSurfaceView
(
getContext
(),
mTextureViewContainer
,
mRotate
,
this
);
return
;
}
else
if
(
GSYVideoType
.
getRenderType
()
==
GSYVideoType
.
GLSURFACE
)
{
mTextureView
.
addGLView
(
getContext
(),
mTextureViewContainer
,
mRotate
,
this
,
mEffectFilter
);
mTextureView
.
addGLView
(
getContext
(),
mTextureViewContainer
,
mRotate
,
this
,
mEffectFilter
,
mMatrixGL
);
return
;
}
mTextureView
.
addTextureView
(
getContext
(),
mTextureViewContainer
,
mRotate
,
this
);
...
...
@@ -210,4 +212,14 @@ public abstract class GSYTextureRenderView extends FrameLayout implements Textur
gsyVideoGLView
.
setEffect
(
effectFilter
);
}
}
public
void
setMatrixGL
(
float
[]
matrixGL
)
{
this
.
mMatrixGL
=
matrixGL
;
if
(
mTextureView
!=
null
&&
mTextureView
.
getShowView
()
instanceof
GSYVideoGLView
&&
mMatrixGL
!=
null
&&
mMatrixGL
.
length
==
16
)
{
GSYVideoGLView
gsyVideoGLView
=
(
GSYVideoGLView
)
mTextureView
.
getShowView
();
gsyVideoGLView
.
setMVPMatrix
(
mMatrixGL
);
}
}
}
gsyVideoPlayer/build.gradle
浏览文件 @
09d53b1a
...
...
@@ -31,7 +31,7 @@ android {
dependencies
{
compile
fileTree
(
dir:
'libs'
,
include:
[
'*.jar'
])
//
compile project(':gsyVideoPlayer-java')
compile
project
(
':gsyVideoPlayer-java'
)
//compile project(':gsyVideoPlayer-armv5')
//compile project(':gsyVideoPlayer-armv7a')
//compile project(':gsyVideoPlayer-armv64')
...
...
@@ -41,7 +41,7 @@ dependencies {
//更多配置版so,增加了concat,rtsp,mpeg,crypto
//compile project(':gsyVideoPlayer-ex_so')
compile
'com.shuyu:gsyVideoPlayer-java:2.0.8'
//
compile 'com.shuyu:gsyVideoPlayer-java:2.0.8'
compile
'com.shuyu:gsyVideoPlayer-armv5:2.0.8'
compile
'com.shuyu:gsyVideoPlayer-armv7a:2.0.8'
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录