首先,我设置一个预览纹理:
camera.setPreviewTexture(new SurfaceTexture(0));
然后,在开始预览之前,然后每次调用onPreviewFrame时,我设置回调缓冲区,如下所示:
camera.addCallbackBuffer(buffer); camera.setPreviewCallbackWithBuffer(this);
有用.有时,我使用camera.takePicture(null,null,callback)拍摄照片,这样会成功调用onPictureTaken.图像被保存.由于我想在拍摄照片后重新启动预览,因此我执行以下操作:
try { camera.setPreviewTexture(new SurfaceTexture(0)); camera.startPreview(); } ...
预览重新开始,一切似乎都很好.但是在我的Logcat中报告了以下错误,似乎在重新启动预览后:
E/BufferQueue﹕ [unnamed-5682-5] dequeueBuffer: min undequeued buffer count (2) exceeded (dequeued=5 undequeudCount=1)
我错过了什么吗?我应该在某些时候释放旧的纹理吗?
配置:三星Galaxy S4,三星Galaxy S5,Nexus 5,在Android KitKat上运行.
编辑:我不确定它是否链接,但过了一段时间,我的应用程序不再拍照,并且我的Logcat中持续显示以下消息:
E/LocSvc_api_v02( 318): I/---> locClientSendReq line 2332 QMI_LOC_INJECT_SENSOR_DATA_REQ_V02 E/gsiff_dmn( 318): I/loc_api_resp_ind_callback: Received LocAPI Resp ind = 77 E/LocSvc_api_v02( 318): D/loc_sync_process_ind:172]: loc_sync_array not in use E/LocSvc_utils_q( 318): D/msg_q_rcv: Received message 0xB899D940 rv = 0 E/gsiff_dmn( 318): I/gsiff_data_task: Handling message type = 4 E/gsiff_dmn( 318): I/gsiff_daemon_inject_sensor_data_handler: Sending Sensor Data to LocApi. opaque_id = 1226 E/LocSvc_api_v02( 318): I/---> locClientSendReq line 2332 QMI_LOC_INJECT_SENSOR_DATA_REQ_V02 E/gsiff_dmn( 318): I/loc_api_resp_ind_callback: Received LocAPI Resp ind = 77 E/LocSvc_api_v02( 318): D/loc_sync_process_ind:172]: loc_sync_array not in use E/mm-camera( 284): [cpp_hardware_process_frame:997] Too many cpp frames dropped!! E/mm-camera( 284): cpp_thread_handle_process_buf_event:224] get buffer fail. drop frame id:1845 identity:0x20002 W/QCamera2HWI( 269): [CHECK_BUF_LOCK] Too many preview buffer is locked by surfaceflinger : 29 E/mm-camera( 284): [cpp_hardware_process_frame:997] Too many cpp frames dropped!! E/mm-camera( 284): cpp_thread_handle_process_buf_event:224] get buffer fail. drop frame id:1846 identity:0x20002
编辑2:如果,而不是一个新的SurfaceTexture(0),我总是使用相同的SurfaceTexture(作为一个成员),那么一些错误消失,App继续工作.最小的未排队的缓冲区数超出了错误,并且通过surfaceflinger警告停留太多的预览缓冲区被锁定.
解决方法
您可以在Android文档中找到有关Camera类的信息:
The buffer queue will be cleared if this method [setPreviewCallbackWithBuffer] is called with a null callback,setPreviewCallback(Camera.PreviewCallback) is called,or setOneShotPreviewCallback(Camera.PreviewCallback) is called.
所以也许这是足够删除你的回调,当你拍照,然后重新启动它,当你重新启动预览.