蓝牙音频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, floa
static void adev_close_input_stream(struct audio_hw_device *dev, 608 struct audio_stream_in *stream) 609 { 610 struct legacy_audio_device *ladev = to_ladev(dev); 611 struct legacy_stream_in *in = 612 reinterpret_cast<struct legacy_stream_in *>(stream); 613 614 ladev->hwif->closeInputStream(in->legacy_in); 615 free(in); 616 } 617 618 static int adev_dump(const struct audio_hw_device *dev, int fd) 619 { 620 const struct legacy_audio_device *ladev = to_cladev(dev); 621 Vector<String16> args; 622 623 return ladev->hwif->dumpState(fd, args); 624 } 625 626 static int legacy_adev_close(hw_device_t* device) 627 { 628 struct audio_hw_device *hwdev = 629 reinterpret_cast<struct audio_hw_device *>(device); 630 struct legacy_audio_device *ladev = to_ladev(hwdev); 631 632 if (!ladev) 633 return 0; 634 635 if (ladev->hwif) 636 delete ladev->hwif; 637 638 free(ladev); 639 return 0; 640 } 641 642 static int legacy_adev_open(const hw_module_t* module, const char* name, 643 hw_device_t** device) 644 { 645 struct legacy_audio_device *ladev; 646 int ret; 647 648 if (strcmp(name, AUDIO_HARDWARE_INTERFACE) != 0) 649 return -EINVAL; 650 651 ladev = (struct legacy_audio_device *)calloc(1, sizeof(*ladev)); 652 if (!ladev) 653 return -ENOMEM; 654 655 ladev->device.common.tag = HARDWARE_DEVICE_TAG; 656 ladev->device.common.version = AUDIO_DEVICE_API_VERSION_2_0; 657 ladev->device.common.module = const_cast<hw_module_t*>(module); 658 ladev->device.common.close = legacy_adev_close; 659 660 ladev->device.init_check = adev_init_check; 661 ladev->device.set_voice_volume = adev_set_voice_volume; 662 ladev->device.set_master_volume = adev_set_master_volume; 663 ladev->device.get_master_volume = adev_get_master_volume; 664 ladev->device.set_mode = adev_set_mode; 665 ladev->device.set_mic_mute = adev_set_mic_mute; 666 ladev->device.get_mic_mute = adev_get_mic_mute; 667 ladev->device.set_parameters = adev_set_parameters; 668 ladev->device.get_parameters = adev_get_parameters; 669 ladev->device.get_input_buffer_size = adev_get_input_buffer_size; 670 ladev->device.open_output_stream = adev_open_output_stream; 671 ladev->device.close_output_stream = adev_close_output_stream; 672 ladev->device.open_input_stream = adev_open_input_stream; 673 ladev->device.close_input_stream = adev_close_input_stream; 674 ladev->device.dump = adev_dump; 675 676 ladev->hwif = createAudioHardware(); 677 if (!ladev->hwif) { 678 ret = -EIO; 679 goto err_create_audio_hw; 680 } 681 682 *device = &ladev->device.common; 683 684 return 0; 685 686 err_create_audio_hw: 687 free(ladev); 688 return ret; 689 } 690 691 static struct hw_module_methods_t legacy_audio_module_methods = { 692 open: legacy_adev_open 693 }; 694 695 struct legacy_audio_module HAL_MODULE_INFO_SYM = { 696 module: { 697 common: { 698 tag: HARDWARE_MODULE_TAG, 699 module_api_version: AUDIO_MODULE_API_VERSION_0_1, 700 hal_api_version: HARDWARE_HAL_API_VERSION, 701 id: AUDIO_HARDWARE_MODULE_ID, 702 name: "LEGACY Audio HW HAL", 703 author: "The Android Open Source Project", 704 methods: &legacy_audio_module_methods, 705 dso : NULL, 706 reserved : {0}, 707 }, 708 }, 709 }; 710 711 }; // extern "C" 712 713 }; // namespace android_audio_legacy 714
最新发布
07-15
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值