Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the process of taking pictures with android7 camera?

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

Today, I would like to share with you the relevant knowledge of the android7 camera photography process. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article. Let's take a look at it.

There is another important part of the Camera process, namely data flow.

In Camera API 1, the data flow is mainly through the function callback, according to the bottom-up direction, layer by layer return to the Applications.

Because the part of the data flow is relatively simple, I combine it with the control flow of Camera and cut in from the takePicture () method to track a more complete Camera process.

Location: frameworks/av/services/camera/libcameraservice/device1/CameraHardwareInterface.h

SetCallback ():

Set the notify callback, which is used to notify that the data has been updated.

Set data callback and dataTimestamp callback, corresponding to function pointers mDataCb and mDataCvTimestamp.

Notice that when you set mDevice- > ops to the callback function, you pass in a function such as _ _ data_cb instead of the function pointer you set earlier. In this file, _ _ data_cb is implemented, and the callback function is encapsulated.

/ * * Set the notification and data callbacks * /

Void setCallbacks (notify_callback notify_cb

Data_callback data_cb

Data_callback_timestamp data_cb_timestamp

Void* user)

{

MNotifyCb = notify_cb

MDataCb = data_cb

MDataCbTimestamp = data_cb_timestamp

MCbUser = user

ALOGV ("s (s)", _ _ FUNCTION__, mName.string ())

If (mDevice- > ops- > set_callbacks) {

MDevice- > ops- > set_callbacks (mDevice

_ _ notify_cb

_ _ data_cb

_ _ data_cb_timestamp

_ _ get_memory

This)

}

}

_ _ data_cb ():

The original callback function is encapsulated simply, and a judgment is added to prevent the array from crossing the bounds.

Static void _ data_cb (int32_t msg_type

Const camera_memory_t * data, unsigned int index

Camera_frame_metadata_t * metadata

Void * user)

{

ALOGV ("% s", _ _ FUNCTION__)

CameraHardwareInterface * _ _ this =

Static_cast (user)

Sp mem (static_cast (data- > handle))

If (index > = mem- > mNumBufs) {

ALOGE ("% s: invalid buffer index d, max allowed is d", _ _ FUNCTION__

Index, mem- > mNumBufs)

Return

}

_ _ this- > mDataCb (msg_type, mem- > mBuffers [index], metadata, _ _ this- > mCbUser)

}

Location: frameworks/base/core/jni/android_hardware_Camera.cpp

TakePicture ():

Get the camera instance that has been opened and call its takePicture () interface.

Note that in this function, there are some additional operations for RAW_IMAGE:

If the callback of RAW is set, check if the corresponding Buffer can be found in the context.

If the Buffer cannot be found, remove the CAMERA_MSG_RAW_IMAGE information and replace it with CAMERA_MSG_RAW_IMAGE_NOTIFY.

After replacement, you will only get the message of notification, but there is no corresponding image data.

Static void android_hardware_Camera_takePicture (JNIEnv * env, jobject thiz, jint msgType)

{

ALOGV ("takePicture")

JNICameraContext* context

/ / previous analysis, https://my.oschina.net/u/920274/blog/5034592

Sp camera = get_native_camera (env, thiz, & context)

If (camera = = 0) return

/ *

* When CAMERA_MSG_RAW_IMAGE is requested, if the raw image callback

* buffer is available, CAMERA_MSG_RAW_IMAGE is enabled to get the

* notification _ and_ the data; otherwise, CAMERA_MSG_RAW_IMAGE_NOTIFY

* is enabled to receive the callback notification but no data.

*

* Note that CAMERA_MSG_RAW_IMAGE_NOTIFY is not exposed to the

* Java application.

, /

If (msgType & CAMERA_MSG_RAW_IMAGE) {

ALOGV ("Enable raw image callback buffer")

If (! context- > isRawImageCallbackBufferAvailable ()) {

ALOGV ("Enable raw image notification, since no callback buffer exists")

MsgType & = ~ CAMERA_MSG_RAW_IMAGE

MsgType | = CAMERA_MSG_RAW_IMAGE_NOTIFY

}

}

If (camera- > takePicture (msgType)! = NO_ERROR) {

JniThrowRuntimeException (env, "takePicture failed")

Return

}

}

After calling camera- > takePicture (msgType), go to the following place.

Location: frameworks/av/camera/Camera.cpp

TakePicture ():

Get an ICamera and call its takePicture interface.

Here it is called directly in the way of return, which is relatively simple.

/ / take a picture

Status_t Camera::takePicture (int msgType)

{

ALOGV ("takePicture: 0x%x", msgType)

/ / https://my.oschina.net/u/920274/blog/5034592 has analysis

Sp c = mCamera

If (c = = 0) return NO_INIT

Return c-> takePicture (msgType)

}

And then jump to

Location: frameworks/av/camera/ICamera.cpp

TakePicture ():

Using the Binder mechanism to send the corresponding instructions to the server.

What is actually called is the CameraClient::takePicture () function.

/ / take a picture-returns an IMemory (ref-counted mmap)

Status_t takePicture (int msgType)

{

ALOGV ("takePicture: 0x%x", msgType)

Parcel data, reply

Data.writeInterfaceToken (ICamera::getInterfaceDescriptor ())

Data.writeInt32 (msgType)

/ / the calls to this place will be analyzed later.

Remote ()-> transact (TAKE_PICTURE, data, & reply)

Status_t ret = reply.readInt32 ()

Return ret

}

Remote ()-> transact (TAKE_PICTURE, data, & reply)

Binder calls the CameraService::onTransact method of CameraService.cpp to the file

Status_t CameraService::onTransact (uint32_t code, const Parcel& data, Parcel* reply

Uint32_t flags) {

Const int pid = getCallingPid ()

Const int selfPid = getpid ()

/ / Permission checks

Switch (code) {

Case BnCameraService::CONNECT:

Case BnCameraService::CONNECT_DEVICE:

Case BnCameraService::CONNECT_LEGACY: {

If (pid! = selfPid) {

/ / we're called from a different process, do the real check

If (! checkCallingPermission (

String16 ("android.permission.CAMERA")) {

Const int uid = getCallingUid ()

ALOGE ("Permission Denial:"

"can't use the camera pid=%d, uid=%d", pid, uid)

Return PERMISSION_DENIED

}

}

Break

}

Case BnCameraService::NOTIFY_SYSTEM_EVENT: {

If (pid! = selfPid) {

/ / Ensure we're being called by system_server, or similar process with

/ / permissions to notify the camera service about system events

If (! checkCallingPermission (

String16 ("android.permission.CAMERA_SEND_SYSTEM_EVENTS")) {

Const int uid = getCallingUid ()

ALOGE ("Permission Denial: cannot send updates to camera service about system"

"events from pid=%d, uid=%d", pid, uid)

Return PERMISSION_DENIED

}

}

Break

}

}

Return BnCameraService::onTransact (code, data, reply, flags); / / then it will be called here

}

Continue down to the file ICameraService.cpp

Status_t BnCameraService::onTransact (

Uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)

{

Switch (code) {

. . .

. . .

Default:

Return BBinder::onTransact (code, data, reply, flags)

}

}

Continue to call to the file ICamera.cpp

Status_t BnCamera::onTransact (

Uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)

{

Switch (code) {

Case TAKE_PICTURE: {

ALOGV ("TAKE_PICTURE")

CHECK_INTERFACE (ICamera, data, reply)

Int msgType = data.readInt32 ()

Reply- > writeInt32 (takePicture (msgType))

Return NO_ERROR

} break

Default:

Return BBinder::onTransact (code, data, reply, flags)

}

}

TakePicture () under the file CameraClient.cpp is called because CameraClient inherits BnCamera

Keep looking at the file, CameraClient.cpp.

/ / take a picture-image is returned in callback

Status_t CameraClient::takePicture (int msgType) {

LOG1 ("takePicture (pid% d): 0x%x", getCallingPid (), msgType)

Mutex::Autolock lock (mLock)

Status_t result = checkPidAndHardware ()

If (result! = NO_ERROR) return result

If ((msgType & CAMERA_MSG_RAW_IMAGE) & &

(msgType & CAMERA_MSG_RAW_IMAGE_NOTIFY) {

ALOGE ("CAMERA_MSG_RAW_IMAGE and CAMERA_MSG_RAW_IMAGE_NOTIFY"

"cannot be both enabled")

Return BAD_VALUE

}

/ / We only accept picture related message types

/ / and ignore other types of messages for takePicture ().

Int picMsgType = msgType

& (CAMERA_MSG_SHUTTER |

CAMERA_MSG_POSTVIEW_FRAME |

CAMERA_MSG_RAW_IMAGE |

CAMERA_MSG_RAW_IMAGE_NOTIFY |

CAMERA_MSG_COMPRESSED_IMAGE)

EnableMsgType (picMsgType)

Return mHardware- > takePicture ()

}

Location: frameworks/av/services/camera/libcameraservice/device1/CameraHardwareInterface.h

TakePicture ():

Through the function pointer set in mDevice, the implementation logic of the takePicture operation corresponding to the specific platform in the HAL layer is called.

Next is the process related to the specific platform, this part of the content is not important to me, and there has been a more in-depth exploration in the previous note, so I will not continue to dig down here.

After the control flow reaches the HAL layer, the control instruction is sent to the Linux Drivers, which makes the specific Camera device execute the instruction and obtain the data.

/ * *

* Take a picture.

, /

Status_t takePicture ()

{

ALOGV ("s (s)", _ _ FUNCTION__, mName.string ())

If (mDevice- > ops- > take_picture)

Return mDevice- > ops- > take_picture (mDevice)

Return INVALID_OPERATION

}

Behind it is the data flow.

Because the data flow is implemented through the callback function, I analyze it from the bottom to the upper level when exploring its flow.

These are all the contents of the article "what is the process of taking pictures with android7 cameras?" Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report