Audiopolicyservice and Hal Interface

Source: Internet
Author: User

Here is the main talk about Serivce and Hal interface relationship, two important data structure, mainly android4.4, different schemes can have some different, 5.1 is also a little differently. The Audiopolicymanager is not in the HAL layer and moves directly below the framework.
hw_module_t (There are members through Methods->open, here by the way hw_methods_t)
hw_device_t (with direct close member)
These two members in the hardware.h, it is necessary to remember the membership relationship

structhw_module_t;structhw_module_methods_t;structhw_device_t;/*** Every hardware module must has 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 structhw_module_t {/** tag must is 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 have * 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 modul     E implementation. * For example, Surfaceflinger are responsible for making sure that * it knows what to manage different versions of the G     Ralloc-module API, * and Audioflinger must know how to does the same for Audio-module API.     * * The module API version should include a major and a minor component. * For example, version 1.0 could is represented as 0x0100.     This format * implies that versions 0x0100-0x01ff is all api-compatible. * In the future, Libhardware would expose a hw_get_module_version () * (or equivalent) function that would take min Imum/maximum supported * Versions as ArguMents and would is 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 is supplied here for temporary * source code compatibility.     They'll is removed in the next version.     * All clients must convert to the new version format. */    /** * The API version of the HAL module interface.     This was 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 in this value for version information.     * * Presently, 0 is the only valid value. */uint16_t hal_api_version;#define Version_minor hal_api_version    /** Identifier of module * /    Const Char*id;/** Name of this module * /    Const Char*name;/** Author/owner/implementor of the module * *    Const Char*author;/** Modules Methods * *    structHw_module_methods_t* methods;/** module ' s DSO * /    void* DSO;/** padding to bytes, reserved for future use */uint32_t reserved[ +-7];} **hw_module_t**;typedef struct**hw_module_methods_t** {/** Open A specific device * /    int(*open) (Const structhw_module_t* module,Const Char* ID,structhw_device_t** device);//This open method associates the module with the device, and the other methods are related to device. } **hw_module_methods_t**;/*** Every device data structure must begin with hw_device_t* followed by module specific public methods and attribute s.*/typedef struct**hw_device_t** {/** tag must is initialized to Hardware_device_tag * /uint32_t tag;/** * Version of the module-specific device API.     This value was 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 being useful when a device interface changes on an incompatible the-it is still necessary-support Older implementations at the same * time.     One such example is the Camera 2.0 API.     * * This field was interpreted by the module user and was ignored by the * HAL interface itself. */uint32_t version;/** Reference to the module this device belongs to * /    structhw_module_t* module;/** padding reserved for future use */uint32_t reserved[ A];/** Close This device * /    int(*close) (structhw_device_t* device);} **hw_device_t**;

In 4.4, the Audioflingerservice constructor (framework/av/service/audioflinger/audioflingerservice.cpp)
1.1,

hw_get_module(AUDIO_POLICY_HARDWARE_MODULE_ID, &module);

First, by Hw_get_module this method, get the module of the HAL layer

2.2,
Audio_policy_dev_open (module, &mpaudiopolicydev);
Here corresponds to the open method of the HAL layer hw_module_t
Audio_policy.h

440staticinlineint audio_policy_dev_open(const hw_module_t* module,441                                     struct audio_policy_device** device)442 {443     return module->methods->open(module, AUDIO_POLICY_INTERFACE,444                                  (hw_device_t**)device);445 }

This open is the corresponding AUDIO_POLIC.C open

310 Static intDefault_ap_dev_open (Consthw_module_t* module,Const Char* Name,311hw_device_t** device)312{313     structDefault_ap_device *dev;314 315*device = NULL; the 317     if(strcmp(name, audio_policy_interface)! =0)318         return-einval;319  thedev = (structDefault_ap_device *)calloc(1,sizeof(*dev));321     if(!dev)322         return-enomem;323 324Dev->device.common.tag = Hardware_device_tag;325Dev->device.common.version =0;326Dev->device.common.module = (hw_module_t *) module;327Dev->device.common.close = Default_ap_dev_close;328Dev->device.create_audio_policy = Create_default_ap;329Dev->device.destroy_audio_policy = Destroy_default_ap; the 331*device = &dev->device.common;332 333     return 0;334}335 336 Static structhw_module_methods_t Default_ap_module_methods = {337. open = Default_ap_dev_open,338};

This create brings out a bunch of methods that provide the upper call to the HAL to implement itself.

1.3

this,                                               &mpAudioPolicy);

This create_audio_policy is a 4.2-finger default_ap_dev_open, to see the implementation of this function.

Static intCreate_default_ap (Const structAudio_policy_device *device,structAudio_policy_service_ops *aps_ops,void*service,structAudio_policy **ap) {structDefault_ap_device *dev;structDefault_audio_policy *dap;intRet *ap = NULL;if(!service | |!aps_ops)return-einval; DAP = (structDefault_audio_policy *)calloc(1,sizeof(*DAP));if(!DAP)return -enomem;    Dap->policy.set_device_connection_state = ap_set_device_connection_state;    Dap->policy.get_device_connection_state = ap_get_device_connection_state;    Dap->policy.set_phone_state = ap_set_phone_state;    Dap->policy.set_ringer_mode = Ap_set_ringer_mode;    Dap->policy.set_force_use = Ap_set_force_use;    Dap->policy.get_force_use = Ap_get_force_use;    dap->policy.set_can_mute_enforced_audible = ap_set_can_mute_enforced_audible;    Dap->policy.init_check = Ap_init_check;    Dap->policy.get_output = Ap_get_output;    Dap->policy.start_output = Ap_start_output;    Dap->policy.stop_output = Ap_stop_output;    Dap->policy.release_output = Ap_release_output;    Dap->policy.get_input = Ap_get_input;    Dap->policy.start_input = Ap_start_input;    Dap->policy.stop_input = Ap_stop_input;    Dap->policy.release_input = Ap_release_input;    Dap->policy.init_stream_volume = Ap_init_stream_volume; Dap->policy.set_streaM_volume_index = Ap_set_stream_volume_index;    Dap->policy.get_stream_volume_index = Ap_get_stream_volume_index;    Dap->policy.set_stream_volume_index_for_device = Ap_set_stream_volume_index_for_device;    Dap->policy.get_stream_volume_index_for_device = Ap_get_stream_volume_index_for_device;    Dap->policy.get_strategy_for_stream = Ap_get_strategy_for_stream;    Dap->policy.get_devices_for_stream = Ap_get_devices_for_stream;    Dap->policy.get_output_for_effect = Ap_get_output_for_effect;    Dap->policy.register_effect = Ap_register_effect;    Dap->policy.unregister_effect = Ap_unregister_effect;    dap->policy.set_effect_enabled = ap_set_effect_enabled;    Dap->policy.is_stream_active = ap_is_stream_active;    Dap->policy.dump = Ap_dump;    dap->policy.is_offload_supported = ap_is_offload_supported;    Dap->service = Service;    Dap->aps_ops = Aps_ops;     *ap = &dap->policy;return 0;}

1.4

 rc = mpAudioPolicy->init_check(mpAudioPolicy);    "couldn‘t init_check the audio policy (%s)", strerror(-rc));    if (rc)        return;

Init_check call, HAL is not implemented.

The above four steps basically show the interaction between the framework layer and the HAL layer.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Audiopolicyservice and Hal Interface

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.