在API 17及以下版本上使用createInputSurface()的替代方法是什么 [英] What is the alternative to use createInputSurface() on API 17 and below

查看:442
本文介绍了在API 17及以下版本上使用createInputSurface()的替代方法是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于我的一个将照相机预览保存到缓冲区的应用程序,我正在使用Mediacodec.createInputSurface()函数,并且一切正常,就像我在使用API​​ 19及更高版本时一样. 现在,我希望相同的代码适用于api 17及以下版本以及不存在该api的其他一些设备. 有人可以告诉我可以使用什么替代方法来帮助我吗?

For one of my app which saves camera preview to a buffer, I am using the function Mediacodec.createInputSurface() and everything works fine as I was using API 19 and above. Now I want the same code to work for api 17 and below as well for some other devices where this api does not exist. Can someone help me by telling what alternative I can use?

这是我的一部分代码:

private Surface mInputSurface;
private MediaCodec mEncoder;
mInputSurface = mEncoder.createInputSurface();

感谢您的帮助.

推荐答案

API中没有其他选择.直到API 18(JB-MR2)才引入该功能.

There is no alternative in the API. That feature was not introduced until API 18 (JB-MR2).

您可以获得的最接近的是一个名为SurfaceMediaSource的私有本机类(),但是使用内部类不是建议使用此代码,因为您的代码可能无法在其他设备或早期/更高版本中使用.

The closest you can get is a private native class called SurfaceMediaSource (source in JB-MR1), which was used internally for the same purpose. If you google around you can find some examples of people who have used libstagefright directly (e.g. this), but using internal classes is not recommended as your code may not work on different devices or earlier/later releases.

API之前的18,您可以通过软件缓冲区移动数据.这需要颜色格式转换,因为相机和MediaCodec没有任何常见的颜色格式.您还必须应对API 16/17中的错误或损坏的MediaCodec实现.

Pre-API 18 you can move the data through software buffers. This requires a color format conversion, as the camera and MediaCodec don't have any color formats in common. You also have to contend with buggy or broken MediaCodec implementations in API 16/17.

这篇关于在API 17及以下版本上使用createInputSurface()的替代方法是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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