Android 显示要textureview的字节数组帧流
我试图显示通过网络接收到的帧流,并将其显示到TextureView。我的管道如下:Android 显示要textureview的字节数组帧流,android,opengl-es,android-ndk,gstreamer,textureview,Android,Opengl Es,Android Ndk,Gstreamer,Textureview,我试图显示通过网络接收到的帧流,并将其显示到TextureView。我的管道如下: 使用GStreamer接收视频。我正在使用NDK。Gstreamer代码是用C编写的。我使用JNI回调将appsink中接收到的各个帧从C发送到Java。我不想使用NDK中的ANativeWindow来显示到曲面,就像GStreamer教程-3示例应用程序中所做的那样 在Java中,这些帧被添加到ArrayBlockingQueue中。从该队列中提取一个单独的线程 以下是来自pullFromQueue线程的回调,
@DebugLog
private void pullFromQueueMethod() {
try {
long start = System.currentTimeMillis();
byte frame[] = framesQueue.take();
}
从这里开始,我想使用OpenGL改变亮度、对比度,并将着色器应用于各个帧。性能是我最关心的问题,因此我无法将字节[]转换为位图,然后显示到SurfaceView。我已经试过了,Nexus 5上的768x576帧需要将近50毫秒
令人惊讶的是,我在任何地方都找不到这样的例子。所有示例都使用Camera或MediaPlayer内置函数将其预览指向曲面/纹理。例如:camera.setPreviewTexture(surfaceTexture)代码>。这将输出链接到SurfaceTexture,因此您不必处理显示单个帧(不必处理字节数组)
到目前为止我所做的尝试:
public class CameraActivity extends AppCompatActivity implements TextureView.SurfaceTextureListener {
int textureId = -1;
SurfaceTexture surfaceTexture;
TextureView textureView;
...
protected void onCreate(Bundle savedInstanceState) {
textureView = new TextureView(this);
textureView.setSurfaceTextureListener(this);
}
private void pullFromQueueMethod() {
try {
long start = System.currentTimeMillis();
byte frame[] = framesQueue.take();
if (textureId == -1){
textureId = GlUtil.createImageTexture(frame);
surfaceTexture = new SurfaceTexture(textureId);
textureView.setSurfaceTexture(surfaceTexture);
} else {
GlUtil.updateImageTexture(textureId); // self defined method that doesn't create a new texture, but calls GLES20.glTexImage2D() to update that texture
}
surfaceTexture.updateTexImage();
/* What do I do from here? Is this the right approach? */
}
}
在StackOverflow上看到了答案。建议使用Grafika的createImageTexture()
。收到纹理句柄后,如何将其传递给SurfaceTexture并不断更新?以下是我迄今为止实现的部分代码:
public class CameraActivity extends AppCompatActivity implements TextureView.SurfaceTextureListener {
int textureId = -1;
SurfaceTexture surfaceTexture;
TextureView textureView;
...
protected void onCreate(Bundle savedInstanceState) {
textureView = new TextureView(this);
textureView.setSurfaceTextureListener(this);
}
private void pullFromQueueMethod() {
try {
long start = System.currentTimeMillis();
byte frame[] = framesQueue.take();
if (textureId == -1){
textureId = GlUtil.createImageTexture(frame);
surfaceTexture = new SurfaceTexture(textureId);
textureView.setSurfaceTexture(surfaceTexture);
} else {
GlUtil.updateImageTexture(textureId); // self defined method that doesn't create a new texture, but calls GLES20.glTexImage2D() to update that texture
}
surfaceTexture.updateTexImage();
/* What do I do from here? Is this the right approach? */
}
}
总而言之。我真正需要的是一种高效的方式来显示帧流(字节数组)。我如何做到这一点?又是我,你能发布你的答案吗?我要投赞成票!我已经提出了解决办法