简体   繁体   中英

Low fps `onPreviewFrame` in HTC m8

I'm using camera.setPreviewCallbackWithBuffer(...) to get my frames - doing it in separate frame. (I'm aware of the new camera2 api - but i want to stick for now with this one)

I have issues regarding fps of the previews frame in my cellphone.

I've checked the fps at the onPreviewFrame(...) method and i get around 25 fps in many devices, including using GenyMotion emulator. But in my HTC M8 i get maximum 11 fps.

In my onPreviewFrame(...) I removed all my frame processing code and left the fps computing only (3 simple lines) so no code in there is doing this slowing down. (and it is working good in other devices - so it must be camera settings - I think)

I've tried

  • setPreviewSize(320,240)
  • setRecordHint(true)
  • setPreviewFpsRange(30000,30000)

(everything been double checked with the supported values of the camera)

Nothing help with my HTC M8 - android 6.

What do i need to set to make it faster?

The problem with HTC for some reason that we need to provide them more than one buffer when using camera.setPreviewCallbackWithBuffer(..)

for example

camera.setPreviewCallbackWithBuffer(new Camera.PreviewCallback() {
       @Override
       public void onPreviewFrame(byte[] data, Camera camera) {

           // Do what ever here

          camera.addCallbackBuffer(data);
      }
});

int bitsPetPixel = ImageFormat.getBitsPerPixel(cameraPreviewFormat);
double bytesPerPixel = bitsPetPixel / 8.0;
int frameSize = (int) (cameraPreviewSize.getWidth() * cameraPreviewSize.getHeight() * bytesPerPixel);

byte[][] framesData = new byte[10][];
for (int i = 0; i < framesData.length; i++) {
     framesData[i] = new byte[frameSize];
}

// Providing more than one buffer did the trick
// For the demo it is 10
for (int i = 0; i < framesData.length; i++) {
   camera.addCallbackBuffer(framesData[i]);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM