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.
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.