Android TextureView与VideoView性能 [英] Android TextureView vs VideoView Performance

查看:710
本文介绍了Android TextureView与VideoView性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要能够在屏幕上旋转视频,因此我创建了一个自定义的TextureView,它在MediaPlayer上提供了一个方便层,类似于VideoView的当前实现. 此Android博客帖子表示以下内容关于TextureView:

I need to be able to rotate a video on screen, so I created a custom TextureView which provides a convenience layer over a MediaPlayer similar to how the current implementation of VideoView does. This Android blog post says the following about TextureView:

由于SurfaceView的内容不在应用程序的窗口中,因此无法有效地对其进行转换(移动,缩放,旋转).这使得很难在ListView或ScrollView中使用SurfaceView. SurfaceView也无法与UI工具箱的某些功能正确交互,例如褪色边缘或View.setAlpha().

Because a SurfaceView’s content does not live in the application’s window, it cannot be transformed (moved, scaled, rotated) efficiently. This makes it difficult to use a SurfaceView inside a ListView or a ScrollView. SurfaceView also cannot interact properly with some features of the UI toolkit such as fading edges or View.setAlpha().

为解决这些问题,Android 4.0引入了一个名为TextureView的新小部件,该小部件依赖于硬件加速的2D渲染管道和SurfaceTexture. TextureView提供与SurfaceView相同的功能,但与SurfaceView不同,它的行为与常规视图相同.例如,您可以使用TextureView显示OpenGL场景或视频流. TextureView本身可以动画,滚动等.

To solve these problems, Android 4.0 introduces a new widget called TextureView that relies on the hardware accelerated 2D rendering pipeline and SurfaceTexture. TextureView offers the same capabilities as SurfaceView but, unlike SurfaceView, behaves as a regular view. You can for instance use a TextureView to display an OpenGL scene or a video stream. The TextureView itself can be animated, scrolled, etc.

但是,似乎TextureView正在努力播放视频.我正在测试的目标设备具有1.2Ghz Rockchip RK3066双核CPU,四核Mali-400 GPU(ARM)和1GB RAM.在该设备上使用VideoViews的相同代码效果很好,但是TextureViews要么"stutter",要么"stutter".播放时还是完全不显示(黑框,左上角带有白色正方形),具体取决于特定设备.使用Intel提供的x86设备",TextureViews在模拟器上的性能很好.

However, it looks like the TextureView is struggling to play the videos. The target device I'm testing it on has a 1.2Ghz Rockchip RK3066 Dual Core CPU, a Quad core Mali-400 GPU (ARM) and 1GB RAM. The same code using VideoViews on this device performs fine, but the TextureViews either "stutter" while playing or don't show up at all (black box with white squares in the top left), depending on the specific device. The TextureViews perform fine on the emulator using the Intel-provided x86 "device".

该性能是否达到预期,还是我应该在其他地方寻找问题所在?谢谢

Is this performance hit expected, or should I be looking elsewhere to find the problem? Thanks

推荐答案

是的,应该与TextureView一起使用.与直接在GPU中合成的SurfaceView不同(与管道直接将其渲染到放置SurfaceView的屏幕区域进行渲染),SurfaceView使TextureView导致视频经过常规的视图合成进行渲染.尽管TextureView渲染是硬件加速的,但它仍在通过更多的步骤来获得更大的灵活性,并且肯定会影响性能.另外,与SurfaceView不同,在UI线程上运行的任何代码都可能影响TextureView.

Yes, it is expected with TextureView. TextureView causes the video to go through normal view-compositing for rendering, unlike SurfaceView which is composited directly in the GPU (the decoding pipeline is rendering directly to the area of the screen where you place the SurfaceView). While the TextureView rendering is hardware-accelerated, it still is going through more steps for the additional flexibility, and there is a definite performance hit. Additionally, any code running on the UI-thread may affect TextureView unlike SurfaceView.

其他信息:

这篇关于Android TextureView与VideoView性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆