在API 17及以下版本上使用createInputSurface()的替代方法是什么

编程入门 行业动态 更新时间:2024-10-27 16:24:31
本文介绍了在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的私有本机类( JB-MR1 中的源),该源在内部用于相同目的.如果您在Google周围搜索,可以找到一些直接使用libstagefright的人的示例(例如此),但是使用内部类不是建议使用此代码,因为您的代码可能无法在其他设备或早期/更高版本中使用.

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()的替代方法是什么

本文发布于:2023-11-27 01:30:32,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1636018.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:版本   方法   API   createInputSurface

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!