首页 > 学院 > 开发设计 > 正文

蓝牙音频A2DP(二) -- audio_hw_device结构体

2019-11-06 09:36:46
字体:
来源:转载
供稿:网友

每一个音频设备,都是一个audio_hw_device结构体的实现,那么对于audio_hw_device的理解,能够更好的理解音频设备可以做什么,怎么做。

看下audio_hw_device的结构体定义(hardware/libhardware/include/hardware/audio.h,英文就不写了,随便翻译一下):

516 struct audio_hw_device {517 /** * 音频设备的通用方法,就是记录下版本好,TAG这些基本信息的, * 虽然没啥用,但是每个audio_hw_device都必须以此开头 */522 struct hw_device_t common;523524 /** * Audio Flinger通过此函数查看该audio_hw_device的实现支持哪些设备。 * 蓝牙A2DP未提供此函数实现,也许就是表示啥都支持 */536 uint32_t (*get_supported_devices)(const struct audio_hw_device *dev);537538 /** * 检查该音频接口是否已初始化 * 蓝牙似乎没检查,啥都没做,直接返回 0(success)541 */542 int (*init_check)(const struct audio_hw_device *dev);543544 /** * 设置在某一个设备上话音数据音量,范围 0.0 - 1.0 */545 int (*set_voice_volume)(struct audio_hw_device *dev, float volume);546547 /** * 设置该设备下所有实体的音量大小,这个就不止是话音数据了 * 范围 0.0 - 1.0551 */552 int (*set_master_volume)(struct audio_hw_device *dev, float volume); /** * 获取当前整体音量大小,如果HAL支持这个功能,那么Audio Flinger就要 * 通过该方法去读取值,并在Audio Service启动的时候,以该值为初始值 * 当然,也可以不支持,不支持的设置为NULL * 蓝牙A2DP不支持该方法,将道理的话,PRimary支持就够了 */561 int (*get_master_volume)(struct audio_hw_device *dev, float *volume);562563 /** * 设置音频状态,主要为: * AUDIO_MODE_NORMAL 正常 * AUDIO_MODE_RINGTONE 铃音 * AUDIO_MODE_IN_CALL 通话567 */568 int (*set_mode)(struct audio_hw_device *dev, audio_mode_t mode);569570 /* 设置麦克风静音 */571 int (*set_mic_mute)(struct audio_hw_device *dev, bool state);572 int (*get_mic_mute)(const struct audio_hw_device *dev, bool *state);573574 /* 设置/获取 全局音频参数 */575 int (*set_parameters)(struct audio_hw_device *dev, const char *kv_pairs);581 char * (*get_parameters)(const struct audio_hw_device *dev,582 const char *keys);583584 /* * 获取输入buff的长度 * 蓝牙A2DP不支持该功能,就不纠结到底是啥子长度了587 */588 size_t (*get_input_buffer_size)(const struct audio_hw_device *dev,589 const struct audio_config *config);584 /* * 关键的接口,用于创建并打开音频硬件输出流 * 不同的音频设备的address是不一样的 * Bluetooth: use MAC address of the device "00:11:22:AA:BB:CC" * USB: use ALSA card and device number "card=X;device=Y" * other: a number or other string587 */599 int (*open_output_stream)(struct audio_hw_device *dev,600 audio_io_handle_t handle,601 audio_devices_t devices,602 audio_output_flags_t flags,603 struct audio_config *config,604 struct audio_stream_out **stream_out,605 const char *address);606607 void (*close_output_stream)(struct audio_hw_device *dev,608 struct audio_stream_out* stream_out);609584 /* * 关键的接口,用于创建并打开音频硬件输入流587 */611 int (*open_input_stream)(struct audio_hw_device *dev,612 audio_io_handle_t handle,613 audio_devices_t devices,614 struct audio_config *config,615 struct audio_stream_in **stream_in,616 audio_input_flags_t flags,617 const char *address,618 audio_source_t source);619620 void (*close_input_stream)(struct audio_hw_device *dev,621 struct audio_stream_in *stream_in);622623 /* * 打印当前音频的状态 * 蓝牙实现了,但啥也没做 */624 int (*dump)(const struct audio_hw_device *dev, int fd);625626 /* * 后面的接口,蓝牙都没用,不看了 */630 int (*set_master_mute)(struct audio_hw_device *dev, bool mute);639 int (*get_master_mute)(struct audio_hw_device *dev, bool *mute);640648 int (*create_audio_patch)(struct audio_hw_device *dev,649 unsigned int num_sources,650 const struct audio_port_config *sources,651 unsigned int num_sinks,652 const struct audio_port_config *sinks,653 audio_patch_handle_t *handle);656 int (*release_audio_patch)(struct audio_hw_device *dev,657 audio_patch_handle_t handle);665 int (*get_audio_port)(struct audio_hw_device *dev,666 struct audio_port *port);669 int (*set_audio_port_config)(struct audio_hw_device *dev,670 const struct audio_port_config *config);从audio的结构体以及蓝牙A2DP对其的实现可以看出,蓝牙音频的主要功能都是包含在output stream 和input stream。 adev->device.open_output_stream = adev_open_output_stream; adev->device.close_output_stream = adev_close_output_stream; adev->device.open_input_stream = adev_open_input_stream; adev->device.close_input_stream = adev_close_input_stream;
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表