Android: setPreviewCallbackWithBuffer, buffer in the queue and no callbacks

If you want to process Camera preview frames on Android, you need to acquire them with setPreviewCallback or setPreviewOneShotCallback or setPreviewCallbackWithBuffer on the Camera.

setPreviewCallback works as advertised, but slows the camera to just few frames per second. For better camera FPS, use setPreviewCallbackWithBuffer (it can re-use the same buffer without allocating it every frame). Just add the same buffer to the queue after it is processed in Camera.PreviewCallback. If the queue is empty, the preview frames are skipped (and it may improve FPS too, so it is a good thing).

My problem was that even if I had the buffer in the queue, the callback didn't run. However, if I called setPreviewCallbackWithBuffer some seconds later (not in onResume of the activity), the entire thing worked as intended.

I suppose, it has something to do with the surface for the preview not being ready when I call the setPreviewCallbackWithBuffer. This bug may be related: http://code.google.com/p/android/issues/detail?id=13966

My workaround is:

  • onResume of the activity, do setPreviewOneShotCallback; and the callback will happen when the camera is ready;
  • in the callback method, when it is called the first time, allocate the buffer and setPreviewCallbackWithBuffer;
  • after every callback addCallbackBuffer to the Camera.
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值