android - Issue with Nexus 6P : configure 60 fps preview session using camera 2 api -
i try implement high speed capture session click on button. here state callback:
private cameradevice.statecallback mcameradevicestatecallback = new cameradevice.statecallback() { @override public void onopened(cameradevice cameradevice) { mcameradevice = cameradevice; startpreview(); } @override public void ondisconnected(cameradevice cameradevice) { mcameraopencloselock.release(); cameradevice.close(); mcameradevice = null; } @override public void onerror(cameradevice cameradevice, int error) { mcameraopencloselock.release(); cameradevice.close(); mcameradevice = null; } };
open camera method:
private void opencamera() throws cameraaccessexception { cameramanager manager = (cameramanager) context.getsystemservice(context.camera_service); try { mcameracharacteristics = manager.getcameracharacteristics(string.valueof(currentcamid)); } catch (cameraaccessexception e) { e.printstacktrace(); } manager.opencamera(string.valueof(currentcamid), mcameradevicestatecallback, mhandler); }
called when started preview , onclick event
private void createcapturesession(list<surface> surfaces) throws cameraaccessexception { if(mpreviewsession!=null){ mpreviewsession.close(); mpreviewsession = null; } if (!ishighspeed) { log.d(log_tag, "createcapturesession ishighspeed" +ishighspeed ); mcameradevice.createcapturesession(surfaces, new cameracapturesession.statecallback() { @override public void onconfigured(cameracapturesession cameracapturesession) { log.i(log_tag, "cameracapturesession onconfigured :" + cameracapturesession.hashcode()); mpreviewsession = cameracapturesession; updatepreview(); } @override public void onconfigurefailed(cameracapturesession cameracapturesession) { } }, mhandler); } else { if (build.version.sdk_int >= build.version_codes.m) { log.d(log_tag, "createcapturesession ishighspeed" +ishighspeed ); mcameradevice.createconstrainedhighspeedcapturesession(surfaces, new cameracapturesession.statecallback() { @override public void onconfigured(cameracapturesession cameracapturesession) { log.i(log_tag, "cameracapturesession onconfigured :" + cameracapturesession.hashcode()); if (build.version.sdk_int >= build.version_codes.m) { mpreviewsession = cameracapturesession; } updatepreview(); } @override public void onconfigurefailed(cameracapturesession cameracapturesession) { log.e(log_tag, "failed"); } }, mhandler); } } }
update preview called above
private void updatepreview() { try { list<capturerequest> capturelist = null; if (android.os.build.version.sdk_int >= android.os.build.version_codes.m && ishighspeed) { streamconfigurationmap map = mcameracharacteristics.get(cameracharacteristics.scaler_stream_configuration_map); range<integer>[] highspeedvideofpsranges = map.gethighspeedvideofpsranges(); mpreviewbuilder.set(capturerequest.control_ae_target_fps_range, highspeedvideofpsranges[3]);//hardcode, 3 highest size nexus6p capturelist = ((cameraconstrainedhighspeedcapturesession) mpreviewsession).createhighspeedrequestlist(mpreviewbuilder.build()); mpreviewsession.setrepeatingburst(capturelist, new cameracapturesession.capturecallback() { @override public void oncapturestarted(cameracapturesession session, capturerequest request, long timestamp, long framenumber) { super.oncapturestarted(session, request, timestamp, framenumber); } }, mhandler); } else { mpreviewsession.setrepeatingrequest(mpreviewbuilder.build(), null, mhandler); } } catch (exception e) { e.printstacktrace(); } }
the first time went right, but, when try start app again there error while open camera device, error code 1 in callback. without running high fps good. escape issue device must rebooted, mystified me
releasingcamera:
@override public void oncampause() { // super.oncampause(); stoppreview(); closecamera(); stopbackgroundthread(); } private void closepreviewsession() { if (mpreviewsession != null) { mpreviewsession.close(); mpreviewsession = null; } } private void closecamera() { try { mcameraopencloselock.acquire(); if (null != mcamera) { mcamera.close(); mcamera = null; } } catch (interruptedexception e) { throw new runtimeexception("interrupted while trying lock camera closing."); } { mcameraopencloselock.release(); } } private void stopbackgroundthread() { if (mcamerathread != null) { mcamerathread.quitsafely(); try { mcamerathread.join(); mcamerathread = null; mcamerahandler = null; } catch (interruptedexception e) { e.printstacktrace(); } } }`
here background thread camera:
private void initcamerathread() { log.e(tag, "init camera thread begin."); mcamerathread = new handlerthread("camera handler thread"); mcamerathread.start(); mhandler = new handler(mcamerathread.getlooper()); log.e(tag, "nit camera thread done"); }
Comments
Post a Comment