7.
那么现在的关键就是
Client
类了·进一步跟进:
CameraService::Client::Client(const sp<CameraService>& cameraService,
const sp<ICameraClient>& cameraClient, pid_t clientPid)
{
…..
mCameraService = cameraService;
mCameraClient = cameraClient;
mClientPid = clientPid;
mHardware =
openCameraHardware();
}
将
cameraService
和
cameraClient
的实例分别赋值给了
Client
的类成员变量。
另外
openCameraHardware()
是值得注意的地方,也就是连接上层应用和底层驱动的关键,通过调用
openCameraHardware()
得到了一个
CameraHardwareInterface
实例对象,并赋值给自己的类成员:
`
sp<CameraHardwareInterface> mHardware;
对
hardware
的操作就是通过该对象完成的,所以说真正意义上的功能实现其实就是在这里,即
client
类的函数接口调用。
对于
hardware
的东东咱们暂时不去关注吧。
那么我们再次仔细研究下
Client
类的继承关系
(
这些继承关系很容易混乱,涉及到较多的多态类型转换
)
,这个其实往往都很关键:
Client
继承于
BnCamera
,而
BnCamera
则继承于
ICamera
,也就是说
Client
继承了
ICamera,
实现了
ICamera
中的函数。
进而发现,原来绕一个大圈,把最开始的图简化下:
8.
除此之外还有两个步骤或许需要去研究下:
先从单一函数去跟进,看具体一些
callback
的实现流程:
// callback from camera service
void Camera::notifyCallback(int32_t msgType, int32_t ext1, int32_t ext2)
{
sp<CameraListener> listener;
{
Mutex::Autolock _l(mLock);
listener = mListener;
}
if (listener != NULL) {
listener->notify(msgType, ext1, ext2);
}
}
这是
Camera
类中一个
callback
函数实现,但其本质在哪?先看
camera
类的继承关系:
通过以上的继承关系,继续跟进其父类
ICameraClient
:
class ICameraClient: public IInterface
{
public:
DECLARE_META_INTERFACE(CameraClient);
virtual void
notifyCallback(int32_t msgType, int32_t ext1, int32_t ext2) = 0;
virtual void
dataCallback(int32_t msgType, const sp<IMemory>& data) = 0;
virtual void dataCallbackTimestamp(nsecs_t timestamp, int32_t msgType, const
sp<IMemory>& data) = 0;
};
其中
notifyCallback()
又是纯虚函数
,
则同样说明实现在其子类
BpCameraClient
中:
// generic callback from camera service to app
void notifyCallback(int32_t msgType, int32_t ext1, int32_t ext2)
{
LOGV("notifyCallback");
Parcel data, reply;
data.writeInterfaceToken(ICameraClient::getInterfaceDescriptor());
data.writeInt32(msgType);
data.writeInt32(ext1);
data.writeInt32(ext2);
remote()->transact(NOTIFY_CALLBACK,data, &reply, IBinder::FLAG_ONEWAY);
}
然后通过
Binder
通讯调用到
BnCameraClient
中实现:
status_t BnCameraClient::onTransact(
uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
{
switch(code) {
case NOTIFY_CALLBACK: {
LOGV("NOTIFY_CALLBACK");
CHECK_INTERFACE(ICameraClient, data, reply);
int32_t msgType = data.readInt32();
int32_t ext1 = data.readInt32();
int32_t ext2 = data.readInt32();
notifyCallback(msgType, ext1, ext2);
return NO_ERROR;
} break;
….
}
进而调用到了
Camera.cpp
中的函数实现了,但或许你有疑问,这些
callback
是涉及到一些驱动的
callback
,哪怎么跟驱动联系起来那?
结合之前对
hardware
接口调用的类
Client
,进一步可以发现
callback
的处理同样是在
Client
类实例化的时候:
CameraService::Client::Client(const sp<CameraService>& cameraService,
const sp<ICameraClient>& cameraClient, pid_t clientPid)
{
…..
mHardware->setCallbacks(
notifyCallback
,
dataCallback,
dataCallbackTimestamp,
mCameraService.get());
…..
}
调用了
mHardware
将
callback
传入,但此处的
notifyCallback
并不是
camera.cpp
中的函数,而是
client
类的
notifyCallback
函数。
再继续看
client
类中的
notifyCallback
函数实现:
void CameraService::Client::notifyCallback(int32_t msgType, int32_t ext1,int32_t ext2, void* user)
{
…..
default:
sp<ICameraClient> c = client->mCameraClient;
if (c != NULL) {
c->notifyCallback(msgType, ext1, ext2);
}
break;
…..
}
通过得到
ICameraClient
实例进而调用到了具体的对象
Camera
的
notifyCallback()
函数。这个地方估计会遇见跟
ICameraService
函数调用一样的问题,
ICameraClient
函数调用所需要的函数实例在哪?
记得上述
ICameraService
讲到的
connect()
函数嘛?其中有一个参数不能被忽略掉的,就是
ICameraClient
,但它在真正传入的时候却是一个
ICameraClient
子类
camera
的实例对象。
CameraService:
sp<ICamera> CameraService::connect(const sp<ICameraClient>& cameraClient)
{
…..
// create a new Client object
client = new Client(this,
cameraClient
, callingPid);
…..
}
Client:
CameraService::Client::Client(const sp<CameraService>& cameraService,
const sp<ICameraClient>&
cameraClient
, pid_t clientPid)
{
….
mCameraService = cameraService;
mCameraClient =
cameraClient
;
….
}
这样就清楚了,其实
Client
在调用设置
callback
的调用最终还是调用到了
camera.cpp
中的
callback
函数,进而将具体内容通过
callback
反馈给上层应用做出相应的处理。
分享到:
相关推荐
三星方案Android Camera Framework介绍
android_camera_framework_stream 中文文档很详细
android_camera_framework_stream.pdf
android_camera_framework_stream汇编.pdf
android camera framework结构图
详细解释android平台camera 部分的框架接口。为实现camera的硬件抽象层提供参考
android_camera_framework_stream[汇编].pdf
Android Camera框架从整体上看是一个client/service的架构,有两个进程:一个是client进程,可以看成是AP端,主要包括JAVA 代码与一些native c/c++代码;另一个是service 进程,属于服务端,是native c/c++代码,...
因为工作中要使用 Android Camera2 API 来实现相机功能,但因为Camera2比较复杂,网上资料也比较乱,有一定入门门槛,所以花了几天时间系统研究了下,这个项目就是我研究的成果。 其中包括一个自己写的Camera2的Demo...
RTSP camera aims to establish an Android platform as a streaming server for the device's camera output. In order to register for receiving the camera stream, the Real-Time streaming protocol (RTSP) is...
android环境中camera framework学习总结
自己总结的Android Camera系统架构及源码分析,以framework和hal为主。
主要介绍了android Camera framework架构的开发流程及具体的实现方法
(精品)Android Camera分析(整理).pdf Android 的Camera架构介绍.pdf Camera模块解析驱动.pdf ...学习camera framework 总结.pdf Android框架下Camera的设计与实现.pdf android_Camera框架分析.pdf
由于工作中需要用到Camera1,所以花了两天时间研究了以下,使用Android Camera1 API实现了相机预览、拍照和录制视频的功能。 资源中有个MyCamera1Demo.apk可以直接安装运行,MyCamera1Demo.zip是Demo源码。 具体详见...
我自己写的Android CameraX Demo,实现了预览/拍照/录制视频/图片分析/对焦/切换摄像头等操作。 具体详见我的博客 : https://blog.csdn.net/EthanCo/article/details/125603671
android camera mirror 前置后置相机视频预览时左右镜像,实现镜子效果 基于以下网址实现的android studio项目源代码包,可以直接打开使用 https://blog.csdn.net/mbrose/article/details/80167781 代码做了一...
Android Camera2 API
Android Camera Imaging Test Suite / CTS Verifier Document version: 1.9 Document date: 31st May, 2016 ...The ITS is a framework for running tests on the images produced by an Android camera.
Android 5.0以上Google官方建议使用camera2 ,camera已废弃。在这里给大家下载官方demo.