2025-04-30

audio_policy.conf文件分析,不同的Android產品在音頻的設計上通常是存在差異的,而這些差異可以同過Audio的配置文件audio_policy.conf來獲得。在Android系統中音頻配置文件存放路徑有兩處,存放地址可以從AudioPolicyManagerBase.cpp文件中知道:

 #define AUDIO_POLICY_VENDOR_CONFIG_FILE  "/vendor/etc/audio_policy.conf"
 #define AUDIO_POLICY_CONFIG_FILE         "/system/etc/audio_policy.conf"

  在AudioPolicyManager.cpp文件中可以知道系統會首先加載vendor/etc目錄下的configure文件,再加載system/etc目錄下的configure文件。若這兩者加載都發生錯誤的話,系統會加載default配置文件,並命名為primary module,從這可以看出,音頻系統中一定必須存在的module就是primary瞭。

1     if (loadAudioPolicyConfig(AUDIO_POLICY_VENDOR_CONFIG_FILE) != NO_ERROR) {
2         if (loadAudioPolicyConfig(AUDIO_POLICY_CONFIG_FILE) != NO_ERROR) {
3             ALOGE("could not load audio policy configuration file, setting defaults");
4             defaultAudioPolicyConfig();
5         }
6     }

 

  1 # Global configuration section: lists input and output devices always present on the device
  2 # as well as the output device selected by default.
  3 # Devices are designated by a string that corresponds to the enum in audio.h
  4 
  5 global_configuration {
  6   attached_output_devices AUDIO_DEVICE_OUT_SPEAKER
  7   default_output_device AUDIO_DEVICE_OUT_SPEAKER
  8   attached_input_devices AUDIO_DEVICE_IN_BUILTIN_MIC|AUDIO_DEVICE_IN_VOICE_CALL|AUDIO_DEVICE_IN_REMOTE_SUBMIX
  9   custom_properties {
 10     voice_volume_applied_after_mixing_in_call true
 11     voice_volume_applied_after_mixing_in_communication false
 12     in_call_music_attenuation_dB 6
 13     }
 14 }
 15 
 16 # audio hardware module section: contains descriptors for all audio hw modules present on the
 17 # device. Each hw module node is named after the corresponding hw module library base name.
 18 # For instance, "primary" corresponds to audio.primary..so.
 19 # The "primary" module is mandatory and must include at least one output with
 20 # AUDIO_OUTPUT_FLAG_PRIMARY flag.
 21 # Each module descriptor contains one or more output profile descriptors and zero or more
 22 # input profile descriptors. Each profile lists all the parameters supported by a given output
 23 # or input stream category.
 24 # The "channel_masks", "formats", "devices" and "flags" are specified using strings corresponding
 25 # to enums in audio.h and audio_policy.h. They are concatenated by use of "|" without space or "\n".
 26 
 27 audio_hw_modules {
 28   primary {
 29     outputs {
 30       primary {
 31         sampling_rates 48000
 32         channel_masks AUDIO_CHANNEL_OUT_STEREO
 33         formats AUDIO_FORMAT_PCM_16_BIT
 34         devices AUDIO_DEVICE_OUT_SPEAKER|AUDIO_DEVICE_OUT_WIRED_HEADSET|AUDIO_DEVICE_OUT_WIRED_HEADPHONE|AUDIO_DEVICE_OUT_ALL_SCO
 35         flags AUDIO_OUTPUT_FLAG_PRIMARY
 36       }
 37       deep_buffer {
 38         sampling_rates 48000
 39         channel_masks AUDIO_CHANNEL_OUT_STEREO
 40         formats AUDIO_FORMAT_PCM_16_BIT
 41         devices AUDIO_DEVICE_OUT_SPEAKER|AUDIO_DEVICE_OUT_WIRED_HEADSET|AUDIO_DEVICE_OUT_WIRED_HEADPHONE
 42         flags AUDIO_OUTPUT_FLAG_DEEP_BUFFER
 43       }
 44     }
 45     inputs {
 46       primary {
 47         sampling_rates 8000|11025|12000|16000|22050|24000|32000|44100|48000
 48         channel_masks AUDIO_CHANNEL_IN_MONO|AUDIO_CHANNEL_IN_STEREO
 49         formats AUDIO_FORMAT_PCM_16_BIT
 50         devices AUDIO_DEVICE_IN_BUILTIN_MIC|AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET|AUDIO_DEVICE_IN_WIRED_HEADSET|AUDIO_DEVICE_IN_VOICE_CALL
 51       }
 52     }
 53   }
 54   a2dp {
 55     outputs {
 56       a2dp {
 57         sampling_rates 44100
 58         channel_masks AUDIO_CHANNEL_OUT_STEREO
 59         formats AUDIO_FORMAT_PCM_16_BIT
 60         devices AUDIO_DEVICE_OUT_ALL_A2DP
 61       }
 62     }
 63   }
 64   hdmi {
 65     outputs {
 66      hdmi_stereo {
 67         sampling_rates 48000
 68         channel_masks AUDIO_CHANNEL_OUT_STEREO
 69         formats AUDIO_FORMAT_PCM_16_BIT
 70         devices AUDIO_DEVICE_OUT_AUX_DIGITAL
 71       }
 72       hdmi_multi {
 73         sampling_rates 32000|44100|48000|88200|96000
 74        # channel_masks AUDIO_CHANNEL_OUT_5POINT1
 75         channel_masks dynamic
 76         formats AUDIO_FORMAT_PCM_16_BIT
 77         devices AUDIO_DEVICE_OUT_AUX_DIGITAL
 78         flags AUDIO_OUTPUT_FLAG_DIRECT
 79       }
 80     }
 81   }
 82   r_submix {
 83     outputs {
 84       submix {
 85         sampling_rates 48000
 86         channel_masks AUDIO_CHANNEL_OUT_STEREO
 87         formats AUDIO_FORMAT_PCM_16_BIT
 88         devices AUDIO_DEVICE_OUT_REMOTE_SUBMIX
 89       }
 90     }
 91     inputs {
 92       submix {
 93         sampling_rates 48000
 94         channel_masks AUDIO_CHANNEL_IN_STEREO
 95         formats AUDIO_FORMAT_PCM_16_BIT
 96         devices AUDIO_DEVICE_IN_REMOTE_SUBMIX
 97       }
 98     }
 99   }
100   hs_usb {
101     outputs {
102        usb_dgtl {
103          sampling_rates 44100|48000
104          channel_masks AUDIO_CHANNEL_OUT_STEREO
105          formats AUDIO_FORMAT_PCM_16_BIT
106          devices AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET
107         }
108     }
109   }
110   usb {
111     outputs {
112       usb_accessory {
113         sampling_rates 44100
114         channel_masks AUDIO_CHANNEL_OUT_STEREO
115         formats AUDIO_FORMAT_PCM_16_BIT
116         devices AUDIO_DEVICE_OUT_USB_ACCESSORY
117       }
118 #      usb_device {
119 #        sampling_rates 44100
120 #        channel_masks AUDIO_CHANNEL_OUT_STEREO
121 #        formats AUDIO_FORMAT_PCM_16_BIT
122 #        devices AUDIO_DEVICE_OUT_USB_DEVICE
123 #      }
124     }
125   } }

  從audio_policy.conf文件中可以發現,系統包含瞭primary、a2dp、usb等音頻接口,對應著系統中的audio…so。每個音頻接口中又包含瞭若幹個outputs & inputs,並且每個output or input又包含瞭若幹個devices,且還有采樣頻率,聲道數等信息。這些devices信息、采樣頻率信息 & 聲道信息等都會保存在各自module的IOProfile中。按上文中audio_policy.conf配置文件所描述,系統最後會生成6個modules(eg.primary,a2dp,hdmi,r_submix,hs_usb & usb)以及7個outputs。以AUDIO_DEVICE_OUT_SPEAKER為例,該device會定義在primary模塊中outputs所屬的IOProfile1中,其它設備依次類推。

  根據audio_policy.conf文件可以簡化Audio module的架構,如下圖1所示:

bubuko.com,佈佈扣

圖1

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *