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

每一个音频设备,都是一个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;
523
524     /**
         * Audio Flinger通过此函数查看该audio_hw_device的实现支持哪些设备。
         * 蓝牙A2DP未提供此函数实现,也许就是表示啥都支持
         */
536     uint32_t (*get_supported_devices)(const struct audio_hw_device *dev);
537
538     /**
         * 检查该音频接口是否已初始化
         * 蓝牙似乎没检查,啥都没做,直接返回 0(success)
541      */
542     int (*init_check)(const struct audio_hw_device *dev);
543
544     /**
         * 设置在某一个设备上话音数据音量,范围 0.0 - 1.0 
         */
545     int (*set_voice_volume)(struct audio_hw_device *dev, float volume);
546
547     /**
         * 设置该设备下所有实体的音量大小,这个就不止是话音数据了
         * 范围 0.0 - 1.0
551      */
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);
562
563     /**
         * 设置音频状态,主要为:
         * AUDIO_MODE_NORMAL    正常
         * AUDIO_MODE_RINGTONE  铃音
         * AUDIO_MODE_IN_CALL   通话
567      */
568     int (*set_mode)(struct audio_hw_device *dev, audio_mode_t mode);
569
570     /* 设置麦克风静音 */
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);
573
574     /* 设置/获取 全局音频参数 */
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);
583
584     /*  
         * 获取输入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 string
587      */
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);
606
607     void (*close_output_stream)(struct audio_hw_device *dev,
608                                 struct audio_stream_out* stream_out);
609
584     /*  
         * 关键的接口,用于创建并打开音频硬件输入流
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);
619
620     void (*close_input_stream)(struct audio_hw_device *dev,
621                                struct audio_stream_in *stream_in);
622
623     /*
         * 打印当前音频的状态
         * 蓝牙实现了,但啥也没做
         */
624     int (*dump)(const struct audio_hw_device *dev, int fd);
625
626     /*
         * 后面的接口,蓝牙都没用,不看了
         */
630     int (*set_master_mute)(struct audio_hw_device *dev, bool mute);
639     int (*get_master_mute)(struct audio_hw_device *dev, bool *mute);
640
648     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;
  • 2
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值