What is the alternative to use createInputSurface() on API 17 and below

若如初见. 提交于 2019-12-12 03:22:05

问题


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?

here is a piece of my code:

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

Thanks for any help.


回答1:


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

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.

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.



来源:https://stackoverflow.com/questions/28720056/what-is-the-alternative-to-use-createinputsurface-on-api-17-and-below

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!