自 2025 年 3 月 27 日起,我們建議您使用 android-latest-release 而非 aosp-main 建構及貢獻 AOSP。詳情請參閱「Android 開放原始碼計畫變更」。
  
         
       
     
  
  
  
    
  
  
  
    
    
      
    
    
      
      透過集合功能整理內容
    
    
      
      你可以依據偏好儲存及分類內容。
    
  
  
    
  
  
  
  
    
  
  
    
    
    
  
  audio_hw_device 結構體參考
 
  
   #include <
   
    audio.h
   
   >
  
 
 
  
   | 
    
    | 
  
  
   | 
    struct
    
     hw_device_t
    
     
    | 
   
    
     通用
    
     | 
  
  
   | 
     
    | 
  
  
   | 
    uint32_t(* 
    | 
   
    
     get_supported_devices
    
    )(const struct
    
     audio_hw_device
    
    *dev)
    | 
  
  
   | 
     
    | 
  
  
   | 
    int(* 
    | 
   
    
     init_check
    
    )(const struct
    
     audio_hw_device
    
    *dev)
    | 
  
  
   | 
     
    | 
  
  
   | 
    int(* 
    | 
   
    
     set_voice_volume
    
    )(struct
    
     audio_hw_device
    
    *dev, float volume)
    | 
  
  
   | 
     
    | 
  
  
   | 
    int(* 
    | 
   
    
     set_master_volume
    
    )(struct
    
     audio_hw_device
    
    *dev, float volume)
    | 
  
  
   | 
     
    | 
  
  
   | 
    int(* 
    | 
   
    
     get_master_volume
    
    )(struct
    
     audio_hw_device
    
    *dev, float *volume)
    | 
  
  
   | 
     
    | 
  
  
   | 
    int(* 
    | 
   
    
     set_mode
    
    )(struct
    
     audio_hw_device
    
    *dev, audio_mode_t mode)
    | 
  
  
   | 
     
    | 
  
  
   | 
    int(* 
    | 
   
    
     set_mic_mute
    
    )(struct
    
     audio_hw_device
    
    *dev, bool state)
    | 
  
  
   | 
     
    | 
  
  
   | 
    int(* 
    | 
   
    
     get_mic_mute
    
    )(const struct
    
     audio_hw_device
    
    *dev, bool *state)
    | 
  
  
   | 
     
    | 
  
  
   | 
    int(* 
    | 
   
    
     set_parameters
    
    )(struct
    
     audio_hw_device
    
    *dev, const char *kv_pairs)
    | 
  
  
   | 
     
    | 
  
  
   | 
    char *(* 
    | 
   
    
     get_parameters
    
    )(const struct
    
     audio_hw_device
    
    *dev, const char *keys)
    | 
  
  
   | 
     
    | 
  
  
   | 
    size_t(* 
    | 
   
    
     get_input_buffer_size
    
    )(const struct
    
     audio_hw_device
    
    *dev, const struct audio_config *config)
    | 
  
  
   | 
     
    | 
  
  
   | 
    int(* 
    | 
   
    
     open_output_stream
    
    )(struct
    
     audio_hw_device
    
    *dev, audio_io_handle_t handle, audio_devices_t devices, audio_output_flags_t flags, struct audio_config *config, struct
    
     audio_stream_out
    
    **stream_out, const char *address)
    | 
  
  
   | 
     
    | 
  
  
   | 
    void(* 
    | 
   
    
     close_output_stream
    
    )(struct
    
     audio_hw_device
    
    *dev, struct
    
     audio_stream_out
    
    *stream_out)
    | 
  
  
   | 
     
    | 
  
  
   | 
    int(* 
    | 
   
    
     open_input_stream
    
    )(struct
    
     audio_hw_device
    
    *dev, audio_io_handle_t handle, audio_devices_t devices, struct audio_config *config, struct
    
     audio_stream_in
    
    **stream_in, audio_input_flags_t flags, const char *address, audio_source_t source)
    | 
  
  
   | 
     
    | 
  
  
   | 
    void(* 
    | 
   
    
     close_input_stream
    
    )(struct
    
     audio_hw_device
    
    *dev, struct
    
     audio_stream_in
    
    *stream_in)
    | 
  
  
   | 
     
    | 
  
  
   | 
    int(* 
    | 
   
    
     dump
    
    )(const struct
    
     audio_hw_device
    
    *dev, int fd)
    | 
  
  
   | 
     
    | 
  
  
   | 
    int(* 
    | 
   
    
     set_master_mute
    
    )(struct
    
     audio_hw_device
    
    *dev, bool mute)
    | 
  
  
   | 
     
    | 
  
  
   | 
    int(* 
    | 
   
    
     get_master_mute
    
    )(struct
    
     audio_hw_device
    
    *dev, bool *mute)
    | 
  
  
   | 
     
    | 
  
  
   | 
    int(* 
    | 
   
    
     create_audio_patch
    
    )(struct
    
     audio_hw_device
    
    *dev, unsigned int num_sources, const struct audio_port_config *sources, unsigned int num_sinks, const struct audio_port_config *sinks, audio_patch_handle_t *handle)
    | 
  
  
   | 
     
    | 
  
  
   | 
    int(* 
    | 
   
    
     release_audio_patch
    
    )(struct
    
     audio_hw_device
    
    *dev, audio_patch_handle_t handle)
    | 
  
  
   | 
     
    | 
  
  
   | 
    int(* 
    | 
   
    
     get_audio_port
    
    )(struct
    
     audio_hw_device
    
    *dev, struct audio_port *port)
    | 
  
  
   | 
     
    | 
  
  
   | 
    int(* 
    | 
   
    
     set_audio_port_config
    
    )(struct
    
     audio_hw_device
    
    *dev, const struct audio_port_config *config)
    | 
  
  
   | 
     
    | 
  
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  
   
    
     | 
      int(* create_audio_patch)(struct
      
       audio_hw_device
      
      *dev, unsigned int num_sources, const struct audio_port_config *sources, unsigned int num_sinks, const struct audio_port_config *sinks, audio_patch_handle_t *handle)
      | 
    
   
   
  
  
 
 
 
 
 
 
  
   
    
     | 
      int(* get_audio_port)(struct
      
       audio_hw_device
      
      *dev, struct audio_port *port)
      | 
    
   
   
  
  
 
 
 
  
   
    
     | 
      size_t(* get_input_buffer_size)(const struct
      
       audio_hw_device
      
      *dev, const struct audio_config *config)
      | 
    
   
   
  
  
 
 
 
  
  
   
    如果 HAL 支援主音量控制,請取得 HAL 目前的主音量靜音狀態。服務啟動時,AudioFlinger 會從主要音訊 HAL 查詢這個值,並使用該值在所有 HAL 中設定初始主控靜音功能。不支援這個方法的 HAL 可能會將其設為空值。
   
    定義位於檔案 
     audio.h
     的 
     639
     行。
   
  
 
 
 
  
  
   
    如果 HAL 支援主音量控制,請取得 HAL 目前的主音量值。服務啟動時,AudioFlinger 會從主要音訊 HAL 查詢這個值,並使用該值在所有 HAL 中設定初始主音量。不支援這個方法的 HAL 可能會將其設為空值。
   
    定義位於檔案 
     audio.h
     的 
     561
     行。
   
  
 
 
 
 
 
 
  
   
    
     | 
      char*(* get_parameters)(const struct
      
       audio_hw_device
      
      *dev, const char *keys)
      | 
    
   
   
  
  
 
 
 
  
  
   
    由 Audio Flinger 用來列舉每個 
     audio_hw_device
     實作項目支援的裝置。
   
    傳回值是 audio_devices_t 的 1 個或多個值的位元遮罩
   
    注意:以 AUDIO_DEVICE_API_VERSION_2_0 為開頭的音訊 HAL 實作方式不會實作此函式。所有支援的裝置都應列在 audio_policy.conf 檔案中,且音訊政策管理員必須根據此檔案中的資訊選擇適當的音訊模組。
   
    定義位於檔案 
     audio.h
     的 
     536
     行。
   
  
 
 
 
  
  
   
    檢查音訊硬體介面是否已初始化。成功時會傳回 0,失敗時會傳回 -ENODEV。
   
    定義位於檔案 
     audio.h
     的 
     542
     行。
   
  
 
 
 
  
   
    
     | 
      int(* open_input_stream)(struct
      
       audio_hw_device
      
      *dev, audio_io_handle_t handle, audio_devices_t devices, struct audio_config *config, struct
      
       audio_stream_in
      
      **stream_in, audio_input_flags_t flags, const char *address, audio_source_t source)
      | 
    
   
   
  
  
 
 
 
  
   
    
     | 
      int(* open_output_stream)(struct
      
       audio_hw_device
      
      *dev, audio_io_handle_t handle, audio_devices_t devices, audio_output_flags_t flags, struct audio_config *config, struct
      
       audio_stream_out
      
      **stream_out, const char *address)
      | 
    
   
   
  
   
    這個方法會建立並開啟音訊硬體輸出串流。視需要使用「address」參數來指定「devices」音訊裝置類型。格式取決於裝置類型:
   
    - 
     藍牙裝置會使用裝置的 MAC 位址,格式為「00:11:22:AA:BB:CC」。
    
 
    - 
     USB 裝置會使用 ALSA 卡和裝置編號,格式為「card=X;device=Y」
 
    - 
     其他裝置可能會使用數字或任何其他字串。
    
 
   
   
    定義位於檔案 
     audio.h
     的 
     599
     行。
   
  
 
 
 
  
   
    
     | 
      int(* release_audio_patch)(struct
      
       audio_hw_device
      
      *dev, audio_patch_handle_t handle)
      | 
    
   
   
  
  
 
 
 
  
   
    
     | 
      int(* set_audio_port_config)(struct
      
       audio_hw_device
      
      *dev, const struct audio_port_config *config)
      | 
    
   
   
  
  
 
 
 
  
  
   
    設定所有音訊活動的音訊靜音狀態。如果傳回的值不是 0,則軟體混合器會模擬這項功能。
   
    定義位於檔案 
     audio.h
     的 
     630
     行。
   
  
 
 
 
  
  
   
    設定語音通話以外所有音訊活動的音量。範圍介於 0.0 和 1.0 之間。如果傳回的值不是 0,軟體混合器會模擬這項功能。
   
    定義位於檔案 
     audio.h
     的 
     552
     行。
   
  
 
 
 
 
 
 
  
  
   
    音訊模式變更時,系統會呼叫 set_mode。AUDIO_MODE_NORMAL 模式適用於標準音訊播放,AUDIO_MODE_RINGTONE 模式適用於播放鈴聲,而 AUDIO_MODE_IN_CALL 模式適用於通話中。
   
    定義位於檔案 
     audio.h
     的 
     568
     行。
   
  
 
 
 
 
 
 
  
  
   
    設定語音通話的音量。範圍介於 0.0 至 1.0 之間
   
   
    定義位於檔案 
     audio.h
     的 
     545
     行。
   
  
 
這個結構體的說明文件是由下列檔案產生:
 
  - 
   hardware/libhardware/include/hardware/
   
    audio.h
   
  
 
 
 
 
  
  
  
 
  
    
    
      
       
    
    
  
  
  這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
  上次更新時間:2025-07-27 (世界標準時間)。
  
  
  
    
      [null,null,["上次更新時間:2025-07-27 (世界標準時間)。"],[],[]]