This article is the source of their own reading a bit summary, transfer Please specify the source thank you.
Welcome to communicate with you. qq:1037701636 Email:gzzaigcn2[email protected]
Software: System Source Android5.1
Frontier:
How much of the previous blog summarizes the system architecture of camera HAL1 to HAL3, but these architectures are still in camera API1.0 standards for camera app development. And as CAMERA3, HAL3.0 and so on constantly updated, Google first in the framework to change the entire architecture to match the camera API1.0 processing logic, over time, Google directly to the camera API to a new upgrade, Removing the associated interface from the original Camera.java, instead of designing the camera API2 to exactly match the previously designed CAMERA3 and HAL3, the benefit is that the entire architecture looks simpler.
This article is a simple explanation of the API2.0 camera in the Framewrok layer of the processing logic, and contrast before API1.0 what he gave up, while adding what?
1. The new camera API2.0
In the API2.0 you can no longer see the previous Startpreview, Takepicture, autofocus and other standard operating interfaces, replaced by a large number of Capturerequest/captureresult related APIs have been involved, Google started using the Android5.0 version in API Level21 and deprecate the old Camera.java-related interfaces.
2. The emergence of Aidl technology in Cameraservice
Aidl is a way for the Android Java layer to implement the C/S architecture, with the help of the native binder mechanism, to establish an inter-process communication directly in the Java layer. In the camera API2.0 can see a lot of Adil processing in the Java layer, replace before API1.0 need to enter the native layer to complete the communication.
For Cameraservice, regardless of the architecture or approach, the following procedures should be met:
(1) cameraservice start-up;
(2) A client side connects to Cameraservice via Cameraservice Proxy and obtains a cameraclient proxy. Follow through Cameraclient Proxy direct and cameraservice to interact.
(3) client to provide callback entity interface to the service side, that is, each service side cameraclient need a callback proxy to complete the data, the callback of the message.
Regardless of how the Android upgrade, the camera module is basically in this mode of operation, but the specific implementation of the different way. In addition, the above-mentioned to C/s architecture is basically achieved through the binder IPC.
The traditional Cameraservice architecture is to request service to create a camera on the client under API1.0, which is a very obvious C/s architecture However, in the framework of the API2.0, the original camera in the client layer was left to the Java layer Cameradevice to maintain the interface Icameradeviceuser through aidl processing. Maintaining a camera proxy in the Java layer has the benefit of obviously a faster response:
Interface icameradeviceuser{ /** * Keep up-to-date with frameworks/av/include/camera/camera2/ ICameraDeviceUser.h * /Void disconnect (); INTs Here's status_t //non-negative value is the RequestID. Negative value was status_t int submitrequest (in Capturerequest request, Boolean streaming); int cancelrequest (int requestid); int deletestream (int streamid); Non-negative value is the stream ID. Negative value is status_t int createstream (int width, int height, int. format, in surface surface); int createdefaultrequest (int templateid, out camerametadatanative request); int Getcamerainfo (out camerametadatanative info); int Waituntilidle (); int flush ();}
The same we see Camerasevice in the Android Java layer at the Icameraservice.aidl file:
Interface icameraservice{/** * Keep up-to-date with frameworks/av/include/camera/icameraservice.h */int GE Tnumberofcameras (); Rest of ' int ' return values in this file is actually status_t int getcamerainfo (int cameraid, out camerainfo info); int Connect (icameraclient client, int cameraid, String clientpackagename, int cl Ientuid,//Container for a Icamera object out Binderholder device); int Connectpro (iprocameracallbacks callbacks, int cameraid, String clientpackagename, int Clientuid,//Container for an Iprocamerauser object Out Binderholder device); int Connectdevice (icameradevicecallbacks callbacks, int cameraid, String clientpackagename, int Clientuid,//Container for aN Icameradeviceuser object out binderholder device); int AddListener (Icameraservicelistener listener); int RemoveListener (Icameraservicelistener listener); int getcameracharacteristics (int cameraid, out camerametadatanative info);}
3.camera2client disappeared, Cameradeviceclient was born.
Cameradeviceclient can be said to replace the original API1.0 under the upgraded camera2client, in addition to API2.0 is not allowed the camera HAL Module version number is camera_device_api_version _1_0, as to choose whether to use the Camera2device or Camera3device to connect HAL3 mainly through the HAL camera_device_api_version to specify. Also, the VERSION in Hal must be above camera_device_api_version_2_0 to allow cameradeviceclient to be established.
4. Native the various stream creators who have disappeared
In the previous blog post, has been the emphasis on the camera2client under the various, Now it seems that these can only stay in the world of API1.0, with the passage of time the Android version of the upgrade may slowly fade away, also directly tell us that the implementation of HAL1.0 Camerahardwareinterface will no longer exist, of course, all depends on the manufacturer's implementation.
Here to highlight is in the camera2client under the Callbackprocessor, Frameprocessor, Streamingprocessor and other modules, Each module handles the processing and callbacks of different business and related underlying video image data, where processing of data is done by building cpuconsumer and surface architectures, It is more of a consumer to achieve the buffer queue and dequeue-related operations, the final implementation of the Camera3device standard processing logic.
In API2, in the framework layer, these modules will no longer be used, Instead they are the various consumer that appear in the Java layer in Android5.0, similar to the Surfaceview in the Java layer of Surfaceflinger in preview mode, which is created by creating different types of consumer and then building on the native layer Set up a bufferqueue and use this bufferqueue igraphicbufferconsumer to build Cpuconsumer, Add Igraphicbufferproducer to Cameradevice by CreateStream to a stream.
Of course, it seems that the mechanism of the two implementations is the same, it is necessary to create a stream, and the stream needs the corresponding Anativewindow type of surface to get the data from the HAL3. Once the data has been fetched and the surface is bound to the consumer, it can receive processing buffer through onframeavailable (). The following interface shows that under API2, a stream interface can be created with the AIDL implementation for different data processing modules only after you get one surface.
status_t cameradeviceclient::createstream (int width, int height, int format, const SP<IGRAPHICBUFF erproducer>& bufferproducer) {atrace_call (); ALOGV ("%s (w =%d, H =%d, F = 0x%x)", __function__, width, height, format); status_t Res; if (res = Checkpid (__function__)) = OK) return res; Mutex::autolock ICL (Mbinderserializationlock); if (Bufferproducer = = null) {Aloge ("%s:bufferproducer must not is null", __function__); return bad_value; } if (!mdevice.get ()) return dead_object; Don ' t create multiple streams for the same target surface {ssize_t index = Mstreammap.indexofkey (bufferprodu Cer->asbinder ()); if (Index! = name_not_found) {ALOGW ("%s:camera%d:buffer producer already have a stream for it" "(ID%zd)", __function__, Mcameraid, index); return already_exists; }} .... int32_t disallowedflags = Graphicbu .....Ffer::usage_hw_video_encoder | Gralloc_usage_renderscript; int32_t allowedflags = Graphicbuffer::usage_sw_read_mask | Graphicbuffer::usage_hw_texture | Graphicbuffer::usage_hw_composer; BOOL Flexibleconsumer = (Consumerusage & disallowedflags) = = 0 && (consumerusage & Allowedflags )! = 0; Sp<ibinder> Binder; Sp<anativewindow> ANW; if (bufferproducer! = 0) {binder = Bufferproducer->asbinder (); ANW = new Surface (Bufferproducer, useAsync);//innovate a local surface for product}//Todo:remove w,h,f since we are ignoring them ... res = Mdevice->createstream (anw, width, height, format, &streamid);//create stream return R es;}
under API2.0 can be seen in the Android Java layer provides different modules to handle different video image data, this process is very similar to the camera2client under the various processor module, The latter is the process of packaging data processing and then returning to the app, the former is directly from the Java layer of different modules to respond asynchronously and directly handle the arrival of different types of data streams, such as preview, Rrcord, still_capture, Video_snapshot, ZERO _shutter_lag and other modes of data flow will be Mediarecoder, Surfaceview, ImageReader and so on to directly deal with, overall efficiency will be better.
5. Frameprocessorbase still existsThis class is used by Frameprocessor to process 3A related information in the old version, mainly callback each frame Extraresult to the app, which is 3A related data information. This is the only module in API1 and API2 that requires manual callback, and the rest of the data flows are handled automatically by the above mentioned modules, which are implemented in the same way as described in section 2 (3), where each video frame data is returned using Icameradevicecallbacks:
Interface icameradevicecallbacks{ /** * Keep up-to-date with frameworks/av/include/camera/camera2/ ICameraDeviceCallbacks.h * /oneway void oncameraerror (int errorCode); oneway void Oncameraidle (); oneway void oncapturestarted (int requestid, long timestamp); oneway void onresultreceived (int requestid, in camerametadatanative result);
6 Summary, the whole API2 under the CAMERA3 structure diagram
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Overview of the new camera Fw/hal architecture under Android camera API2.0