AudioPolicyService与HAL接口

这里主要讲简练地讲了Serivce与HAL的接口关系,两个重要的数据结构,主要是android4.4,不同方案可以有一些不一样,5.1也有些不同。AudioPolicyManager不在HAL层,直接移到framework下面了。 hw_module_t(有通过methods->open成员,这里顺便再讲下hw_methods_t) hw_device_t(有直接close成员) 这两个成员在hardware.h中,有必要记住成员关系

struct hw_module_t;struct hw_module_methods_t;struct hw_device_t;/*** Every hardware module must have a data structure named HAL_MODULE_INFO_SYM* and the fields of this data structure must begin with hw_module_t* followed by module specific information.*/typedef struct hw_module_t {/** tag must be initialized to HARDWARE_MODULE_TAG */uint32_t tag;/*** The API version of the implemented module. The module owner is* responsible for updating the version when a module interface has* changed.** The derived modules such as gralloc and audio own and manage this field.* The module user must interpret the version field to decide whether or* not to inter-operate with the supplied module implementation.* For example, SurfaceFlinger is responsible for making sure that* it knows how to manage different versions of the gralloc-module API,* and AudioFlinger must know how to do the same for audio-module API.** The module API version should include a major and a minor component.* For example, version 1.0 could be represented as 0x0100. This format* implies that versions 0x0100-0x01ff are all API-compatible.** In the future, libhardware will expose a hw_get_module_version()* (or equivalent) function that will take minimum/maximum supported* versions as arguments and would be able to reject modules with* versions outside of the supplied range.*/uint16_t module_api_version;#define version_major module_api_version/*** version_major/version_minor defines are supplied here for temporary* source code compatibility. They will be removed in the next version.* ALL clients must convert to the new version format.*//*** The API version of the HAL module interface. This is meant to* version the hw_module_t, hw_module_methods_t, and hw_device_t* structures and definitions.** The HAL interface owns this field. Module users/implementations* must NOT rely on this value for version information.** Presently, 0 is the only valid value.*/uint16_t hal_api_version;*id;*name;*author;/** Modules methods */struct hw_module_methods_t* methods;/** module’s dso */void* dso;/** padding to 128 bytes, reserved for future use */uint32_t reserved[32-7];} **hw_module_t**;typedef struct **hw_module_methods_t** {hw_module_t* module, const char* id,struct hw_device_t** device);//这个open方法把module和device关联起来了,其它的方法都是与device相关的。} **hw_module_methods_t**;/*** Every device data structure must begin with hw_device_t* followed by module specific public methods and attributes.*/typedef struct **hw_device_t** {/** tag must be initialized to HARDWARE_DEVICE_TAG */uint32_t tag;/*** Version of the module-specific device API. This value is used by* the derived-module user to manage different device implementations.** The module user is responsible for checking the module_api_version* and device version fields to ensure that the user is capable of* communicating with the specific module implementation.** One module can support multiple devices with different versions. This* can be useful when a device interface changes in an incompatible way* but it is still necessary to support older implementations at the same* time. One such example is the Camera 2.0 API.** This field is interpreted by the module user and is ignored by the* HAL interface itself.*/uint32_t version;/** reference to the module this device belongs to */struct hw_module_t* module;/** padding reserved for future use */uint32_t reserved[12];/** Close this device */int (*close)(struct hw_device_t* device);} **hw_device_t**;

在4.4中,AudioFlingerService的构造函数(framework/av/service/audioflinger/AudioFlingerService.cpp) 1.1,

hw_get_module(AUDIO_POLICY_HARDWARE_MODULE_ID, &module);

先通过hw_get_module这个方法,拿到hal层的module

2.2, audio_policy_dev_open(module, &mpAudioPolicyDev); 这里对应到hal层hw_module_t的open方法 audio_policy.h

audio_policy_dev_open(const hw_module_t* module,441struct audio_policy_device** device)442 {443return module->methods->open(module, AUDIO_POLICY_INTERFACE,444(hw_device_t**)device);445 }以后我会去到很多很繁华或苍凉,

AudioPolicyService与HAL接口

相关文章:

你感兴趣的文章:

标签云: