我的收藏

Android 9 CEC架构

2020-04-19  本文已影响0人  龙遁流

vendor\amlogic\common\frameworks\services\hdmicec
hardware\amlogic\hdmi_cec
vendor/amlogic/common/interfaces/hdmicec/1.0/Android.bp
Pie\vendor\amlogic\common\frameworks\core\jni\hdmi_cec

【CEC Linux驱动】
common\drivers\amlogic\cec

可选 AMLOGIC_M8B_CEC AMLOGIC_AO_CEC 两种类型

/sys/class/hdmirx/hdmirx0/cec

【CEC 驱动封装层】
Pie\vendor\amlogic\common\frameworks\services\hdmicec\libhdmi_cec
生成 libhdmi_cec_static.so,打开/dev/cec驱动,封装CEC命令操作

hdmi_device_t 代表一个hdmi设备,包括设备类型,逻辑地址,CEC相关设置等,作用是记录CEC的状态信息


class HdmiCecControl : public HdmiCecBase
{
init <== 初始化
openCecDevice <== 打开 /dev/cec,ioctl 设置驱动,记录CEC设备信息
closeCecDevice <== 关闭 /dev/cec 驱动
HdmiCecControl::cec_process_func <== 通过 ioctl 设置参数,执行动作
threadLoop <== readMessage (从CEC驱动中读取消息==> 通过CEC驱动read消息),
messageValidateAndHandle(消费消息,
post到MsgHandler::handleMessage ==> HdmiCecControl::send 或 HdmiCecControl::cec_process_func 处理掉),
post给 HdmiCecEventListener

sendMessage\sendExtMessage ==> HdmiCecControl::send ==> 通过CEC驱动write发送消息

setEventObserver === 将 HdmiCecEventListener 设置
}

【CEC 服务层】
Pie\vendor\amlogic\common\frameworks\services\hdmicec\server
生成 hdmicecd 可执行文件,hdmicecd.rc 启动文件,启动/vendor/bin/hdmicecd


main_hdmicec.cpp
main === 创建 DroidHdmiCec ,注册服务 DroidHdmiCec::registerAsService()


class DroidHdmiCec : public IDroidHdmiCEC, public HdmiCecEventListener
{
构造函数 === 创建 HdmiCecControl,cecControl->setEventObserver(this HdmiCecEventListener)
setCallback === 把 IDroidHdmiCecCallback 设置给 mClients

openCecDevice === cecControl->openCecDevice
closeCecDevice === cecControl->closeCecDevice
cec_process_func == cecControl->cec_process_func
sendMessage === cecControl->sendMessage

onEventUpdate == 将 hdmi_cec_event_t 通知给Client。mClients[i]->notifyCallback

HdmiCecControl* cecControl
IDroidHdmiCecCallback mClients
}

【CEC 客户端层】
Pie\vendor\amlogic\common\frameworks\services\hdmicec\binder
生成 libhdmicec.so


HdmiCecBase.h 定义了 HdmiCecBase 和 HdmiCecEventListener
HdmiCecHidlClient.h 定义了 HdmiCecHidlClient HdmiCecHidlCallback


HdmiCecHidlClient
{
connect === 构造 HdmiCecHidlClient
构造 === 通过 getHdmiCecService 获取 hdmicec [hdmicec.setCallback(callback)]
getHdmiCecService === IDroidHdmiCEC::tryGetService

openCecDevice === hdmicec->openCecDevice
closeCecDevice === hdmicec->closeCecDevice
cec_process_func === hdmicec->cec_process_func
sendMessage === hdmicec->sendMessage

setEventObserver == 设置 mEventListener

HdmiCecHidlCallback* callback
IDroidHdmiCEC* hdmicec
HdmiCecEventListener * mEventListener
}


class HdmiCecHidlCallback : public IDroidHdmiCecCallback
{
构造 === 传入 HdmiCecHidlClient
notifyCallback === 传入 CecEvent, mEventListener ==> HdmiCecEventListener

HdmiCecHidlClient *cecClient
}


HdmiCecEventListener
{
onEventUpdate(hdmi_cec_event_t)
}

【CEC jni层】
Pie\vendor\amlogic\common\frameworks\core\jni\hdmi_cec
生成 libhdmicec_jni.so

【CEC java层】
Pie\vendor\amlogic\common\frameworks\core\java\com\droidlogic
通过 /sys/class/xxx 文件访问CEC驱动

【】
Pie\hardware\amlogic\hdmi_cec
生成 hdmi_cec.amlogic.so,使用HdmiCecHidlClient 访问cec服务

aml_cec_hal_t{
hdmi_cec_device_t 入口参数,上层传递
HdmiCecHidlClient,
event_callback_t,
fd}

struct hdmi_cec_module <= .common.methods <= struct hw_module_methods_t.open <= open_cec()

open_cec() ==do==> (HdmiCecHidlClient <==create== HdmiCecHidlClient::connect),
(HdmiCecHidlClient <==set== HdmiCecCallback,
(fd <==set== HdmiCecHidlClient::openCecDevice),
(hdmi_cec_device_t.funcxxx <==set== cec_process_func)

cec_close ==do==> (HdmiCecHidlClient::closeCecDevice)

cec_process_func ==do==> (HdmiCecHidlClient::xxx_process_func)

class HdmiCecCallback : public HdmiCecEventListener
{
onEventUpdate(hdmi_cec_event_t) <== 执行event_callback_t()
}

【设置应用】
Pie\vendor\amlogic\common\apps\DroidTvSettings\src\com\droidlogic\tv\settings
Pie\vendor\amlogic\common\frameworks\core\java\com\droidlogic\app

【CEC语言设置流程】
HdmiCecControl::init-->mCecDevice.isPlaybackDeviceType = true
HdmiCecControl::openCecDevice--> mCecDevice.mTvOsdName = 0; GET_MENU_LANGUAGE-->驱动send CEC_MESSAGE_GET_MENU_LANGUAGE
--> readMessage-->CEC_MESSAGE_SET_MENU_LANGUAGE-->persist.vendor.sys.cec.set_menu_language-->handleSetMenuLanguage
--> mEventListener->onEventUpdate

./vendor/amlogic/common/frameworks/core/res/src/com/droidlogic/BootComplete.java:44://import com.droidlogic.HdmiCecExtend;

register_event_callback

Pie/bionic/libc/include\dlfcn.h
Pie\hardware\libhardware\include\hardware\hardware.h
Pie\hardware\libhardware\hardware.c
Pie\frameworks\base\services\core\java\com\android\server\hdmi\HdmiControlService.java
Pie\hardware\interfaces\tv\cec\1.0
Pie\hardware\libhardware\include\hardware\hdmi_cec.h
Pie/frameworks/base/services/java/com/android/server/SystemServer.java
Pie\frameworks\base\services\core\jni\com_android_server_hdmi_HdmiCecController.cpp

sys/class/cec/dbg_en

上一篇下一篇

猜你喜欢

热点阅读