讲解SurfaceTexture BufferQueue has been abandoned在Android开发中,当使用SurfaceTexture类来管理和处理图像数据时,有时可能会遇到BufferQueue...检查SurfaceTexture状态确保SurfaceTexture对象在使用期间没有被意外释放或销毁。...销毁和重建SurfaceTexture如果以上方法无效,你可以尝试销毁当前的SurfaceTexture对象,并在需要时重新创建一个新的对象。...javaCopy code// 在SurfaceTexture数据可用时请求新的图像帧@Overridepublic void onFrameAvailable(SurfaceTexture surfaceTexture...SurfaceTexture类主要用于以下两个方面:相机预览:通过SurfaceTexture,应用程序可以获取相机预览数据帧并对其进行处理。
,然后把camera的预览数据设置显示到SurfaceTexture中,这样就可以在OpenGL中拿到摄像头数据并显示了。...主要步骤 1.OpenGL ES生成纹理 2.OpenGL ES创建SurfaceTexture并绑定 3.OpenGL ES摄像头预览 比如美颜相机那些,处理摄像头数据展示出来,为了提高预览的效率...= new SurfaceTexture(cameraRenderTextureId); surfaceTexture.setOnFrameAvailableListener(this)...= null) { //这里相机拿到surfaceTexture绑定 onSurfaceListener.onSurfaceCreate(surfaceTexture...: camera.setPreviewTexture(surfaceTexture); 预览画面,先通过fbo处理,然后拿到fbo的纹理id渲染即可: @Override public void
SurfaceTexture.OnFrameAvailableListener用于通知TextureView内容流有新图像到来。...SurfaceTextureListener接口用于让TextureView的使用者知道SurfaceTexture已准备好,这样就可以把SurfaceTexture交给相应的内容源。...surfaceTexture, int i, int i2) { Surface surface = new Surface(surfaceTexture); try...surfaceTexture, int i, int i2) { } @Override public boolean onSurfaceTextureDestroyed(SurfaceTexture...SurfaceTexture surfaceTexture) { } } 对应的activity_main.xml <LinearLayout xmlns:android="http://schemas.android.com
把帧数据绘制(缓冲)到Camera的SurfaceTexture中。...Tip:这里会有两个SurfaceTexture,一个时我们自己初始化给Camera的SurfaceTexture,一个是TextureView提供的SurfaceTexture。...= cameraWrapper.surfaceTexture) { cameraWrapper.surfaceTexture?....class ScreenTextureWrapper(override var surfaceTexture: SurfaceTexture?...= surfaceTexture) { egl = Egl() egl!!.initEGL(surfaceTexture!!
1、OpenGL生成纹理 2、纹理绑定到SurfaceTexture上 3、用SurfaceTexture做参数创建Surface 4、MediaCodec解码的视频就往Surface发送,就显示出画面了...sTexture, v_texPosition); } VideoRender.java import android.content.Context; import android.graphics.SurfaceTexture...surfaceTexture; private Surface surface; private OnSurfaceCreateListener onSurfaceCreateListener...surfaceTexture) { if (onRenderListener !...= new SurfaceTexture(textureId_mediacodec); surface = new Surface(surfaceTexture); surfaceTexture.setOnFrameAvailableListener
{ private lateinit var mRenderer: MyRenderer override fun onFrameAvailable(surfaceTexture: SurfaceTexture...= SurfaceTexture(textureId) surfaceTexture?....创建纹理id并创建SurfaceTexture,SurfaceTexture在打开相机方法中用到,用于预览相机。...{ private lateinit var mRenderer: MyRenderer override fun onFrameAvailable(surfaceTexture: SurfaceTexture...和SurfaceTexture变量,在这2个回调中都调用打开相机方法,在打开相机方法中判断相机权限和SurfaceTexture是否都已经准备完成,是则打开,不是则返回,代码如下: override fun
在CameraGLView主类中创建SurfaceTexture对象,并将纹理绑定其上 而通过SurfaceTexture作为入参可以创建SurfaceHolder,一条路就通了。...= new SurfaceTexture(textureId); surfaceTexture.setOnFrameAvailableListener(this);...public SurfaceTextureEntry createSurfaceTexture() { SurfaceTexture surfaceTexture = new SurfaceTexture...surfaceTexture) { this.id = id; this.surfaceTexture = surfaceTexture; if (VERSION.SDK_INT...); } } public SurfaceTexture surfaceTexture() { return this.surfaceTexture;
Camera#setPreviewDisplay方法设置SurfaceHolder给相机,通常在使用SurfaceView作为预览控件时使用; 通过Camera#setPreviewTexture方法设置SurfaceTexture...设置给Camera即可 camera.setPreviewTexture(surfaceTexture); 方式三、使用GLSurfaceView 使用GLSurfaceVIew作为预览UI控件时,将相机预览数据转化为纹理数据...surfaceTexture) { glSurfaceView.requestRender(); } 除了上面三种方式外,还有一种比较鸡肋的方案来实时显示预览 方式四、利用buffer...最开始设想的挺好的,实际验证的时候发现不向Camera设置SurfaceHolder或SurfaceTexture,单独注册setPreviewCallback接口是不回调数据的。。。...所以这个方案就比较鸡肋了,需要自己构造一个SurfaceTexture设置给Camera,以便让Camera能回调每一帧预览数据给注册方 DEMO // git branch -a // remotes
05 SurfaceTexture 与 Surface SurfaceView 是 Surface + View 的结合体,而 SurfaceTexture 是 Surface + GL Texture...的结合体,SurfaceTexture 可以将 Surface 中最近的图像数据更新到 GL Texture 中。...通过 setOnFrameAvailableListener(listener) 可以向 SurfaceTexture 注册监听事件,当 Surface 有新的图像可用时,调用 SurfaceTexture...绑定 SurfaceTexture surfaceTexture = new SurfaceTexture(texId); // step:3 注册监听事件 surfaceTexture.setOnFrameAvailableListener...(SurfaceTexture surfaceTexture) { // request render } }); 06 MediaCodec
我们要用SurfaceTexture 创建一个Surface,然后将这个Surface作为MediaPlayer的输出表面。...SurfaceTexture的主要作用就是,从视频流和相机数据流获取新一帧的数据,获取新数据调用的方法是updateTexImage。...然后在onSurfaceCreated的最后加上如下代码: surfaceTexture = new SurfaceTexture(textureId); surfaceTexture.setOnFrameAvailableListener...();//获取新数据 surfaceTexture.getTransformMatrix(mSTMatrix);//让新的纹理和纹理坐标系能够正确的对应,mSTMatrix...= new SurfaceTexture(textureId); surfaceTexture.setOnFrameAvailableListener(this);//监听是否有新的一帧数据到来
如果是available状态,则直接打开camera,否则设置surfaceTexture监听 if (mTextureView.isAvailable()) { openCamera...TextureView.SurfaceTextureListener() { @Override public void onSurfaceTextureAvailable(SurfaceTexture...openCamera( width, height); } @Override public void onSurfaceTextureSizeChanged(SurfaceTexture...configureTransform(width, height); } @Override public boolean onSurfaceTextureDestroyed(SurfaceTexture...{ return true; } @Override public void onSurfaceTextureUpdated(SurfaceTexture
生成: SurfaceTexture surfaceTexture = new SurfaceTexture(textureId); surfaceTexture.setOnFrameAvailableListener...(new OnFrameAvailableListener() { @Override public void onFrameAvailable(SurfaceTexture surfaceTexture...) { } }, handler); Surface surface = new Surface(surfaceTexture); 这里简单介绍下SurfaceTexture 。...SurfaceTexture 可以用来捕获视频流中的图像帧,当 SurfaceTexture 中有数据更新时,会触发onFrameAvailable 回调,此时可以调用 updateTexImage 方法从视频流数据中更新当前数据帧...@Override public void onFrameAvailable(SurfaceTexture surfaceTexture) { dealTextureFrame(); } private
来作为预览的画面 * * @param surfaceTexture */ void setPreviewTexture(SurfaceTexture surfaceTexture...因为使用我们期望将Camera中得到的数据传递到纹理上,所以需要setPreviewTexture(SurfaceTexture texture)。让这个SurfaceTexture来承载。...@Override public void setPreviewTexture(SurfaceTexture surfaceTexture) { if (mCamera !...---- SurfaceTexture 可以从图像流中捕获帧作为OpenGL ES纹理。 直接使用创建的纹理,来创建SurfaceTexture就可以了。...() { @Override public void onFrameAvailable(SurfaceTexture surfaceTexture) {
纹理创建成功后返回纹理id,然后创建SurfaceTexture->Surface,将Surface设置给MediaPlayer,代码如下: override fun onSurfaceCreated(...textureId = GLTools.createOESTextureId() var surfaceTexture = SurfaceTexture(textureId)...{ override fun onFrameAvailable(surfaceTexture: SurfaceTexture?)...{ glSurfaceView.queueEvent { surfaceTexture?....textureId = GLTools.createOESTextureId() var surfaceTexture = SurfaceTexture(textureId)
image.png 以相机作为输入源 设置SurfaceTexture 主要就是通过setPreviewTexture方法,将我们包含有Oes纹理的SurfaceTexture作为输入。...() { @Override public void onFrameAvailable(SurfaceTexture surfaceTexture) {...整体流程 将视频输入到Surface.png 配置SurfaceTexture image.png 设置SurfaceTexture 同样,我们首先先关注如何将整体的解码流程和Surface联系到一起...()); 将收到的SurfaceTexture转成Surface //使用Surface包裹住SurfaceTexture mOutputSurface = new Surface(surfaceTexture...() { @Override public void onFrameAvailable(SurfaceTexture surfaceTexture) {
在第二章中,我们通过一个Camera SurfaceTexture纹理,把摄像头数据绘制到这个纹理上,同时TextureView的SurfaceTexture纹理通过id与第一个纹理关联起来,从而把摄像头画面直接绘制到屏幕上...TextureView的SurfaceTexture纹理,也就是手机屏幕上。...从数据流方向来看,Camer SurfaceTexture从Camera中读取数据缓存到自己的FBO中,然后离屏FBO通过Camer SurfaceTexture的ID读取Camera FBO中的数据缓存到自己的内存中...在前两章的基础上,我们已经有了Camera SurfaceTexture和TextureView SurfaceTexture,现在我们需要再加入一层离屏FBO。...= cameraWrapper.surfaceTexture) { cameraSurfaceTexture?.
surfaceTexture, int width,int height) { System.out.println("onSurfaceTextureAvailable onSurfaceTextureAvailable..."); surface=new Surface(surfaceTexture); new PlayerVideo().start();//开启一个线程去播放视频 } @Override public...void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width,int height) { System.out.println...surfaceTexture) { System.out.println("onSurfaceTextureDestroyed onSurfaceTextureDestroyed"); surfaceTexture...surfaceTexture) { // System.out.println("onSurfaceTextureUpdated onSurfaceTextureUpdated"); } private
surfaceTexture // We configure the size of default buffer to be the size of camera preview we want. texture...eglCreateWindowSurface(mEglDisplay, mEglConfig[0], textureView.surfaceTexture, null) // 6....= SurfaceTexture(oesId) val surface = Surface(surfaceTexture) mCameraDevice!!....to texture surfaceTexture!!....updateTexImage() // Update matrix surfaceTexture!!.
gl, int width, int height); void onDrawFrame(GL10 gl); } onSurfaceCreated 是当渲染线程启动的时候,surfacetexture...被创建,这个surfacetexture设置到播放器中,之后会在这个surfacetexture上渲染数据。...onDrawFrame绘制操作,将surfacetexture设置进播放器之后,codec中的surface会不断地被填充新的视频帧,在onDrawFrame中将视频帧surfaceTexture.updateTexImage...surfaceTexture = Assertions.checkNotNull(this.surfaceTexture); surfaceTexture.updateTexImage...(); long lastFrameTimestampNs = surfaceTexture.getTimestamp(); Long frameTimestampUs
高阶黑科技 此时我们要介绍一个平时用的少的类,SurfaceTexture。...void setPreviewSurface(Surface surface) throws IOException; public native final void setPreviewTexture(SurfaceTexture...surfaceTexture) throws IOException; 当用SurfaceTexture作为预览的输出流承载的时候,其实是不需要一个可见的View的。...Log.e(TAG, "initiate Camera failed"); e.printStackTrace(); } return c; } 然后我们需要设置一个SurfaceTexture..., mTexture = new SurfaceTexture(0); try { mCamera.setPreviewTexture(mTexture); mCamera.startPreview
领取专属 10元无门槛券
手把手带您无忧上云