HAL การควบคุมเสียง

HAL การควบคุมเสียงเปิดตัวใน Android 9 เพื่อ รองรับกรณีการใช้งานด้านเสียงที่เกี่ยวข้องกับยานยนต์ สำหรับ Android 14, HAL การควบคุมเสียงรองรับสิ่งต่อไปนี้

  • เฟดเสียงและสมดุล
  • คำขอโฟกัสเสียงแบบ HAL
  • การปิดเสียงและการลดเสียงของอุปกรณ์
  • การเปลี่ยนแปลงค่าเกนอุปกรณ์เสียง
  • การเปลี่ยนแปลงการกำหนดค่าพอร์ตเสียง

รูปที่ 1 แสดงภาพรวมระดับสูงของสถาปัตยกรรมบริการระบบเสียงสำหรับรถยนต์ใน ซึ่งบริการเครื่องเสียงรถยนต์จะสื่อสารกับ HAL การควบคุมเสียง

กำหนดค่าเสียงแบบหลายโซน

รูปที่ 1 กำหนดค่าเสียงแบบหลายโซน

เสียงเบาลงและสมดุล

การควบคุมเสียง HIDL HAL เวอร์ชัน 1 เปิดตัวใน Android 9 เพื่อรองรับการจางลงและความสมดุลของเสียงในการใช้งานในรถยนต์ กรณี ต่างจากเอฟเฟกต์เสียงทั่วไปที่มีใน Android ทำให้แอประบบสามารถตั้งค่าสมดุลเสียงและค่อยๆ ดังขึ้นได้ CarAudioManager API:

class CarAudioManager {
       /**
       *   Adjust the relative volume in the front vs back of the vehicle cabin.
       *
       *   @param value in the range -1.0 to 1.0 for fully toward the back through
       *   fully toward the front. 0.0 means evenly balanced.
       */
       @SystemApi
       @RequiresPermission(Car.PERMISSION_CAR_CONTROL_AUDIO_VOLUME)
       public void setFadeTowardFront(float value);

       /**
       *   Adjust the relative volume on the left vs right side of the vehicle cabin.
       *
       *   @param value in the range -1.0 to 1.0 for fully toward the left through
       *   fully toward the right. 0.0 means evenly balanced.
       */
       @SystemApi
       @RequiresPermission(Car.PERMISSION_CAR_CONTROL_AUDIO_VOLUME)
       public void setBalanceTowardRight(float value);
}

เมื่อมีการเรียก API เหล่านี้ จะมีการเรียก API HAL สำหรับการควบคุมเสียงที่เกี่ยวข้อง จากบริการระบบเสียงในรถ

interface IAudioControl {
       /**
       *   Control the right/left balance setting of the car speakers.
       */
       oneway setBalanceTowardRight(float value);

       /**
       *   Control the fore/aft fade setting of the car speakers.
       */
       oneway setFadeTowardFront(float value);
}

API นี้มีอยู่ใน HAL การควบคุมเสียงทุกเวอร์ชัน รวมถึง อินเทอร์เฟซ AIDL HAL

คำขอโฟกัสเสียงจาก HAL

AAOS ก็คล้ายกับ Android ซึ่งต้องอาศัยการมีส่วนร่วมอย่างต่อเนื่องของแอปกับเสียง โฟกัสเพื่อจัดการการเล่นเสียงในรถยนต์ ระบบจะใช้ข้อมูลโฟกัสเพื่อจัดการ ซึ่งจะควบคุมเสียงและการลดเสียง ดังนั้น ในการต่อยอดเพิ่มเติม เสียงที่ชัดเจน และเพื่อให้การผสานรวมเสียง ของรถยนต์โดยเฉพาะได้ดีขึ้น ประสบการณ์บน Android มีการนำแอตทริบิวต์เสียงต่อไปนี้มาใช้ Android 11

  • EMERGENCY
  • SAFETY
  • VEHICLE_STATUS
  • ANNOUNCEMENT

นอกจากการเปลี่ยนแปลงนี้แล้ว มีการเพิ่มกลไกสำหรับเสียงที่มีที่มาจาก ภายนอก Android เพื่อเข้าร่วมในคำขอโฟกัสเสียง ดังนั้น เสียง HIDL ควบคุม HAL เวอร์ชัน 2 เพื่อช่วยให้คำขอโฟกัสที่เกิดขึ้น จากภายนอก Android:

interface IAudioControl {
       /**
       *   Registers focus listener to be used by HAL for requesting and
       *   abandoning audio focus.
       *   @param listener the listener interface
       *   @return closeHandle A handle to unregister observer.
       */
       registerFocusListener(IFocusListener listener)
       generates (ICloseHandle closeHandle);

       /**
       *   Notifies HAL of changes in audio focus status for focuses requested
       *   or abandoned by the HAL.
       *
       *   @param usage The audio usage associated with the focus change
       *   @param zoneId The identifier for the audio zone that the HAL is
       *   playing the stream in
       *   @param focusChange the AudioFocusChange that has occurred
       */
       oneway onAudioFocusChange(bitfield<AudioUsage> usage, int32_t zoneId,
       bitfield<AudioFocusChange> focusChange);
}

โดย IFocusListener มีความหมายดังนี้

interface IFocusListener {
       /**
       *   Called whenever HAL is requesting focus as it is starting to play
       *   audio of a given usage in a specified zone.
       *
       *   @param usage The audio usage associated with the focus request
       *    {@code AttributeUsage}
       *   @param zoneId The identifier for the audio zone where the HAL is
       *    requesting focus
       *   @param focusGain The AudioFocusChange associated with this request.
       */
       oneway requestAudioFocus(bitfield<AudioUsage> usage,
       int32_t zoneId, bitfield<AudioFocusChange> focusGain);
       /**
       *   Called whenever HAL is abandoning focus as it is finished playing audio
       *   of a given usage in a specific zone.
       *
       *   @param usage The audio usage for which the HAL is abandoning focus
       *    {@code AttributeUsage}
       *   @param zoneId The identifier for the audio zone that the HAL
       *    abandoning focus
       */
       oneway abandonAudioFocus(bitfield<AudioUsage> usage, int32_t zoneId);
}

คุณใช้ API ข้างต้นเพื่อขอและยกเลิกการโฟกัสเสียงจาก HAL ได้ ตามลำดับ บริการเครื่องเสียงรถยนต์จะพิจารณาการโฟกัสเสียงเพื่อตอบสนองต่อการดำเนินการดังกล่าว และส่งต่อผลลัพธ์แบบไม่พร้อมกันไปยัง IAudioControl#onAudioFocusChange วิธี

นอกจากนี้ API นี้ยังใช้เพื่อตรวจสอบการเปลี่ยนแปลงสำหรับคำขอโฟกัสเสียงที่ มาจาก HAL การควบคุมเสียง โดยทั่วไป การโฟกัสเสียงขณะยืน คำขอจาก HAL จะถือว่าใช้งานอยู่ ซึ่งแตกต่างจากการโฟกัสเสียง จาก Android ซึ่งเล่นเฉพาะแทร็กเสียงที่เกี่ยวข้องและใช้งานอยู่ ถือว่าใช้งานอยู่

ย้ายข้อมูล HIDL ไปยัง HAL การควบคุมเสียง AIDL

เมื่อมีการถือกำเนิดของ AIDL และการย้ายข้อมูลที่จำเป็นใน Android 12 (หากต้องการเรียนรู้เพิ่มเติม โปรดดู AIDL สำหรับ HAL) HAL การควบคุมเสียงเดิมคือ ย้ายข้อมูลไปยัง AIDL แล้ว สำหรับ API การควบคุมเสียง HIDL เวอร์ชัน 2 ที่มีอยู่ การย้ายข้อมูล จำเป็นต้องอัปเดตเมธอดที่มีอยู่เล็กน้อย:

interface IAudioControl {
       /**
       *   Notifies HAL of changes in audio focus status for focuses requested
       *   or abandoned by the HAL.
       *
       *   @param usage The audio usage associated with the focus change
       *        {@code AttributeUsage}. See {@code audioUsage} in
       *        audio_policy_configuration.xsd for the list of allowed values.
       *   @param zoneId The identifier for the audio zone that the HAL is
       *        playing the stream in
       *   @param focusChange the AudioFocusChange that has occurred.
       */
       oneway void onAudioFocusChange(in String usage, in int zoneId,
              in AudioFocusChange focusChange);
       /**
       *   Registers focus listener to be used by HAL for requesting and
       *   abandoning audio focus.
       *   @param listener the listener interface.
       */
       oneway void registerFocusListener(in IFocusListener listener);
       /**
       *   Control the right/left balance setting of the car speakers.
       */
       oneway void setBalanceTowardRight(in float value);
       /**
       *   Control the fore/aft fade setting of the car speakers.
       */
       oneway void setFadeTowardFront(in float value);
}

และ IFocusListener ที่เกี่ยวข้อง

       interface IFocusListener {
       /**
       *   Called whenever HAL is abandoning focus as it is finished playing audio
       *   of a given usage in a specific zone.
       *
       *   @param usage The audio usage for which the HAL is abandoning focus
       *        {@code AttributeUsage}. See {@code audioUsage} in
       *        audio_policy_configuration.xsd for the list of allowed values.
       *   @param zoneId The identifier for the audio zone that the HAL
       *        abandoning focus
       */
       oneway void abandonAudioFocus(in String usage, in int zoneId);
       /**
       *   Called whenever HAL is requesting focus as it is starting to play audio
       *        of a given usage in a specified zone.
       *
       *   @param usage The audio usage associated with the focus request
       *        {@code AttributeUsage}. See {@code audioUsage} in
       *        audio_policy_configuration.xsd for the list of allowed values.
       *   @param zoneId The identifier for the audio zone where the HAL is
       *        requesting focus
       *   @param focusGain The AudioFocusChange associated with this request.
       */
       oneway void requestAudioFocus(in String usage, in int zoneId,
              in AudioFocusChange focusGain);
}

การปิดเสียงกลุ่มวอลุ่ม

Android 12 เปิดตัวการปิดเสียงกลุ่มระดับเสียงเพื่อให้ทำสิ่งต่อไปนี้ได้ การควบคุมการปิดเสียงที่ครอบคลุมมากขึ้นระหว่างการโต้ตอบด้วยเสียงของผู้ใช้ ช่วงเวลานี้ ทำให้ HAL การควบคุมเสียงสามารถรับปิดเสียงเหตุการณ์ที่รถยนต์ดักไว้ บริการเสียง

OEM ต้องตั้งค่าการกำหนดค่า audioUseCarVolumeGroupMuting เพื่อเปิดใช้ฟีเจอร์นี้ ถึง true ในบริการรถ config.xml:

<!-- Configuration to enable muting of individual volume groups.
If this is set to false, muting of individual volume groups is disabled,
instead muting will toggle master mute. If this is set to true, car volume
group muting is enabled and each individual volume group can be muted separately. -->
<bool name="audioUseCarVolumeGroupMuting">true</bool>

ต้องเขียนทับการกำหนดค่าก่อนที่จะเป็น Android 13 ที่มีการวางซ้อนทรัพยากรรันไทม์สำหรับ packages/services/Car/service/res/values/config.xml (หากต้องการดูข้อมูลเพิ่มเติม โปรดดูที่ การปรับแต่งบิลด์ด้วยทรัพยากร การวางซ้อน) จาก Android 13 คุณสามารถใช้การวางซ้อนทรัพยากรรันไทม์เพื่อเปลี่ยน การกำหนดค่า ดูข้อมูลเพิ่มเติมได้ที่เปลี่ยนมูลค่าทรัพยากรของแอป ที่รันไทม์

แอประบบสามารถตรวจสอบว่าฟีเจอร์นี้เปิดใช้อยู่หรือไม่โดยใช้ CarAudioManager#isAudioFeatureEnabled API พารามิเตอร์ที่ส่งผ่านต้องเป็น ค่าคงที่ CarAudioManager.AUDIO_FEATURE_VOLUME_GROUP_MUTING เมธอดจะแสดง true หากฟีเจอร์นี้เปิดใช้ในอุปกรณ์ มิเช่นนั้นให้false

นอกจากการเปิดใช้ฟีเจอร์ audioUseCarVolumeGroupMuting แล้ว AIDL HAL การควบคุมเสียงต้องใช้กลไกการปิดเสียงกลุ่มระดับเสียง ดังนี้

interface IAudioControl {
       /**
       *   Notifies HAL of changes in output devices that the HAL should apply
       *   muting to.
       *
       *   This will be called in response to changes in audio mute state for each
       *   volume group and will include a {@link MutingInfo} object per audio
       *   zone that experienced a mute state event.
       *
       *   @param mutingInfos an array of {@link MutingInfo} objects for the audio
       *   zones where audio mute state has changed.
       */
       oneway void onDevicesToMuteChange(in MutingInfo[] mutingInfos);
}

เมื่อการปิดเสียงมีข้อมูลการปิดเสียงที่เกี่ยวข้องของระบบเสียง ให้ทำดังนี้

parcelable MutingInfo {
       /**
       *   ID of the associated audio zone
       */
       int zoneId;
       /**
       *   List of addresses for audio output devices that should be muted.
       */
       String[] deviceAddressesToMute;
       /**
       *   List of addresses for audio output devices that were previously be
       *   muted and should now be unmuted.
       */
       String[] deviceAddressesToUnmute;
}

AAOS มีกลไก 2 อย่างในการปิดเสียง โดยขึ้นอยู่กับปัจจัยต่อไปนี้

  • เหตุการณ์สําคัญที่ใช้เสียง KEYCODE_VOLUME_MUTE

  • การโทรไปยังบริการเครื่องเสียงรถยนต์โดยใช้ API ปิดเสียงของโปรแกรมจัดการเสียงรถยนต์โดยตรง CarAudioManager#setVolumeGroupMute

เมื่อเปิดใช้ กลไกทั้ง 2 แบบจะทริกเกอร์การปิดเสียงการโทรไปยัง HAL การควบคุมเสียง

การลดเสียงในรถ

Android 12 เปิดตัวการลดเสียงในรถเพื่อเพิ่มประสิทธิภาพการควบคุมการเชื่อมต่อพร้อมกัน การเล่นสตรีมเสียง วิธีนี้ช่วยให้ OEM ใช้การลดความซับซ้อนของตัวเองได้ ตามการกำหนดค่าเสียงทางกายภาพของรถยนต์และการเล่นในปัจจุบัน ดังที่บริการเครื่องเสียงติดรถยนต์กำหนด

กลไกการลดเสียงจะอิงตามการเปลี่ยนแปลงของสแต็กโฟกัสเสียง เมื่อใดก็ตามที่ มีการเปลี่ยนโฟกัสเกิดขึ้น (ไม่ว่าจะเป็นคำขอโฟกัสหรือการละทิ้งโฟกัส) เสียง โดยแจ้งให้ทราบถึง HAL การควบคุม คล้ายกับกลุ่มระดับเสียงของรถยนต์ ซึ่งเป็นการสนับสนุนการปิดเสียงรถยนต์ คุณเปิดใช้การลดเสียงได้ด้วยแฟล็กการกำหนดค่า audioUseHalDuckingSignals ดังนี้

<!-- Configuration to enable IAudioControl#onDevicesToDuckChange API to
inform HAL when to duck. If this is set to true, the API will receive signals
indicating which output devices to duck as well as what usages are currently
holding focus. If set to false, the API will not be called. -->
<bool name="audioUseHalDuckingSignals">true</bool>

หากต้องการเปิดใช้ฟีเจอร์ดังกล่าว HAL การควบคุมเสียง AIDL จะต้องติดตั้งใช้งาน ลอจิกด้วยสัญญาณที่ได้รับจากบริการเครื่องเสียงรถยนต์

interface IAudioControl {
       /**
       *   Notifies HAL of changes in output devices that the HAL should apply
       *   ducking to.
       *
       *   This will be called in response to changes in audio focus, and will
       *   include a {@link DuckingInfo} object per audio zone that experienced
       *   a change in audo focus.
       *
       *   @param duckingInfos an array of {@link DuckingInfo} objects for the
       *   audio zones where audio focus has changed.
       */
       oneway void onDevicesToDuckChange(in DuckingInfo[] duckingInfos);
}

ข้อมูลระบบเสียงที่เกี่ยวข้องมีอยู่ในการลดเสียง ข้อมูล:

parcelable DuckingInfo {
       /**
       *   ID of the associated audio zone
       */
       int zoneId;
       /**
       *   List of addresses for audio output devices that should be ducked.
       */
       String[] deviceAddressesToDuck;
       /**
       *   List of addresses for audio output devices that were previously be
       *   ducked and should now be unducked.
       */
       String[] deviceAddressesToUnduck;
       /**
       *   List of usages currently holding focus for this audio zone.
       */
       String[] usagesHoldingFocus;
}

นอกเหนือจากข้อมูลการกำหนดค่าระบบเสียงในรถที่อยู่ในที่อยู่ของอุปกรณ์ ข้อมูลยังรวมถึงข้อมูลว่าเสียงใด โฟกัสของการใช้ฟีเจอร์ ข้อมูลนี้มีวัตถุประสงค์เพื่อให้ ระบบเสียงที่มีการใช้งานแอตทริบิวต์เสียง

ซึ่งจำเป็นต้องใช้เนื่องจากในการกำหนดค่าเครื่องเสียงรถยนต์ ให้กับอุปกรณ์เครื่องเดียวได้ แต่ไม่ชัดเจนว่าการใช้งานใดที่ใช้งานอยู่

การควบคุมเสียง AIDL HAL 2.0

หากต้องการอัปเดต API และอำนวยความสะดวกให้กับฟังก์ชันใหม่ HAL การควบคุมเสียง AIDL อัปเดตเป็นเวอร์ชัน 2.0 ใน Android 13 ดังนี้

  • โฟกัสเสียงด้วย PlaybackTrackMetadata
  • เสียงที่ได้รับ Callback

ข้อมูลเมตาของการเล่นกำหนดไว้ใน android.hardware.audio.common ดังนี้

parcelable PlaybackTrackMetadata {
       AudioUsage usage = INVALID;
       AudioContentType contentType = UNKNOWN;
       float gain;
       AudioChannelLayout channelMask;
       AudioDevice sourceDevice;
       String[] tags;
}

ฟังก์ชันอื่นๆ ทั้งหมดจากการควบคุมเสียง AIDL เวอร์ชัน 1.0 จะยังคงอยู่และ ข้อยกเว้นเกี่ยวข้องกับวิธีการเปลี่ยนโฟกัสเสียง ตามที่อธิบายไว้ใน เมื่อเปลี่ยนวิธีโฟกัสเสียง

โฟกัสการควบคุมเสียงพร้อมข้อมูลเมตาของแทร็กการเล่น

หากต้องการเปิดเผยข้อมูลเพิ่มเติมต่อระบบเสียงภายใต้ HAL การอัปเดตจะเปิดเผย PlaybackTrackMetadata โดยเราได้ขยาย HAL การควบคุมเสียงด้วย วิธีการใหม่:

interface IAudioControl {
       /**
       *   Notifies HAL of changes in audio focus status for focuses requested
       *   or abandoned by the HAL.
       *
       *   The HAL is not required to wait for a callback of AUDIOFOCUS_GAIN
       *   before playing audio, nor is it required to stop playing audio in the
       *   event of a AUDIOFOCUS_LOSS callback is received.
       *
       *   @param playbackMetaData The output stream metadata associated with
       *    the focus request
       *   @param zoneId The identifier for the audio zone that the HAL is
       *    playing the stream in
       *   @param focusChange the AudioFocusChange that has occurred.
       */
       oneway void onAudioFocusChangeWithMetaData(
       in PlaybackTrackMetadata playbackMetaData, in int zoneId,
       in AudioFocusChange focusChange);
}

และจะมีการทำการเปลี่ยนแปลงที่คล้ายกันและเกี่ยวข้องกับ IFocusListener ดังนี้

       /**
       *   Called to indicate that the audio output stream associated with
       *   {@link android.hardware.audio.common.PlaybackTrackMetadata} is
       *   abandoning focus as playback has stopped.
       *
       *   @param playbackMetaData The output stream metadata associated with
       *    the focus request
       *   @param zoneId The identifier for the audio zone that the HAL
       *    abandoning focus
       */
       oneway void abandonAudioFocusWithMetaData(
       in PlaybackTrackMetadata playbackMetaData, in int zoneId);
       /**
       *   Called to indicate that the audio output stream associated with
       *   {@link android.hardware.audio.common.PlaybackTrackMetadata} has taken
       *   the focus as playback is starting for the corresponding stream.
       *
       *   @param playbackMetaData The output stream metadata associated with
       *    the focus request
       *   @param zoneId The identifier for the audio zone that the HAL
       *    abandoning focus
       *   @param focusGain The focus type requested.
       */
       oneway void requestAudioFocusWithMetaData(
       in PlaybackTrackMetadata playbackMetaData, in int zoneId,
       in AudioFocusChange focusGain);
}

เมื่อเปลี่ยนวิธีโฟกัสเสียง

การดำเนินการที่มุ่งเน้นข้างต้นจะทำงานในลักษณะเดียวกับที่ได้อธิบายไว้ในเสียง คำขอโฟกัสจาก HAL เฉพาะข้อมูลเมตาของแทร็กเล่นเท่านั้นที่มีมากกว่า ข้อมูลพร้อมกับการใช้แอตทริบิวต์เสียง โดยทั่วไป ยกเว้นกรณีพิเศษ ข้อมูลที่ระบุโดยข้อมูลเมตาของแทร็กการเล่นเป็นสิ่งจำเป็น Android ที่อัปเดตแล้ว การควบคุม HAL ยังคงสามารถใช้วิธีการก่อนหน้านี้ได้

หากนักพัฒนาแอป HAL ตัดสินใจที่จะไม่รองรับ IAudioControl#onAudioFocusChangeWithMetaData เมธอดควรแสดงผลลัพธ์ มีข้อผิดพลาด UNKNOWN_TRANSACTION ตามที่อธิบายไว้ การใช้อินเทอร์เฟซที่มีเวอร์ชัน วิธีการ

บริการเสียงจะโทรหา onAudioFocusChangeWithMetaData ก่อน และ แล้วลองใหม่ด้วยเมธอด onAudioFocusChange หาก UNKNOWN_TRANSACTION ผลลัพธ์ความล้มเหลว

การลดเสียงในรถพร้อมข้อมูลเมตาของแทร็กการเล่น

HAL การควบคุมเสียง AIDL เวอร์ชัน 2.0 ได้เพิ่มข้อมูลเมตาของแทร็กการเล่นลงใน ข้อมูลการลดเสียง:

parcelable DuckingInfo {
       /**
       *   ID of the associated audio zone
       */
       int zoneId;
       /**
       *   List of addresses for audio output devices that should be ducked.
       */
       String[] deviceAddressesToDuck;
       /**
       *   List of addresses for audio output devices that were previously be
       *   ducked and should now be unducked.
       */
       String[] deviceAddressesToUnduck;
       /**
       *   List of usages currently holding focus for this audio zone.
       */
       String[] usagesHoldingFocus;
       /**
       *   List of output stream metadata associated with the current focus
       *   holder for this audio zone
       */
       @nullable PlaybackTrackMetadata[] playbackMetaDataHoldingFocus;
}

usagesHoldingFocus เลิกใช้งานแล้ว ตอนนี้นักพัฒนาซอฟต์แวร์ควรใช้ playbackMetaDataHoldingFocus เพื่อตรวจสอบการใช้แอตทริบิวต์เสียงและอื่นๆ ข้อมูลเสียง อย่างไรก็ตาม พารามิเตอร์ usagesHoldingFocus ยังคงมี ข้อมูลที่ต้องการจนกว่าตัวเลือกนี้จะถูกนำออกอย่างเป็นทางการ

Callback ของสัญญาณเสียงที่ได้รับ

เพื่อทำให้ AAOS ใน Android มองเห็นการเปลี่ยนแปลงเสียงที่ต่ำกว่า HAL ได้ชัดเจนขึ้น 13. เราเพิ่มกลไกที่คุณสามารถใช้ในการสื่อสาร เสียงได้รับการเปลี่ยนแปลงจากระบบเสียงของรถยนต์ไปยังบริการเครื่องเสียงรถยนต์ แสดงการเปลี่ยนแปลงของดัชนีระดับเสียงที่ได้รับ เนื่องจากเหตุผลที่เกี่ยวข้อง กำไรมีการเปลี่ยนแปลง

  • ข้อจำกัดที่ถูกบล็อกหรือปิดเสียง
  • ข้อจำกัด
  • การจำกัดการลดขนาดเล็ก

การเปลี่ยนแปลงเหล่านี้แสดงข้อจำกัดเหล่านี้จากระดับ HAL ด้านล่างไปยัง บริการเสียงรถยนต์ และสุดท้ายคือ ไปยังแอป UI ของระบบเพื่อแจ้งผู้ใช้ ส่วนหลัง การใช้ UI ของระบบที่เป็นไปได้ได้รับการขยายเพิ่มเติม Android 14 เพื่อให้แอป UI ของระบบเข้าถึงข้อมูลนี้ได้ง่ายยิ่งขึ้น ผ่านกลไกการเรียกกลับข้อมูลกลุ่มวอลุ่ม

HAL API สำหรับการควบคุมเสียงจะบันทึกการได้รับ Callback ดังนี้

interface IAudioControl {
       /**
       *   Registers callback to be used by HAL for reporting unexpected gain(s)
       *    changed and the reason(s) why.
       *
       *   @param callback The {@link IAudioGainCallback}.
       */
       oneway void registerGainCallback(in IAudioGainCallback callback);
}

IAudioGainCallback มีคำจำกัดความดังนี้

interface IAudioGainCallback {
       /**
       *   Used to indicate that one or more audio device port gains have changed,
       *   i.e. initiated by HAL, not by CarAudioService.
       *   This is the counter part of the
       *   {@link onDevicesToDuckChange}, {@link onDevicesToMuteChange} and,
       *   {@link setAudioDeviceGainsChanged} APIs.
       *
       *   @param reasons List of reasons that triggered the given gains changed.
       *   @param gains List of gains affected by the change.
       */
       void onAudioDeviceGainsChanged(in Reasons[] reasons,
       in AudioGainConfigInfo[] gains);
}

ตามที่ไฮไลต์ไว้ในเอกสารประกอบของ API การเรียก Yield จะมีการลงทะเบียนโดย ไปยังระบบควบคุมเสียง HAL เมื่อมีการเรียก API จาก HAL การควบคุมเสียง บริการเครื่องเสียงรถยนต์จะตอบสนองด้วยการทำงานที่เกี่ยวข้อง (เช่น การบล็อก ขีดจำกัด หรือแอตทริบิวต์การเพิ่มของดัชนี)

HAL จะกำหนดช่วงเวลาที่เรียกใช้ API โดยมีจุดประสงค์เพื่อรายงานการเปลี่ยนแปลง สถานะดัชนี เฉพาะสำหรับข้อกำหนดด้านกฎระเบียบ ระบบเสียงของรถยนต์ ดำเนินการตามที่จำเป็นและใช้การติดต่อกลับเพื่อรายงานข้อมูลไปยัง บริการระบบเสียงในรถ เพื่อให้ผู้ใช้สามารถฟังเพลงได้ เช่น หากต้องการแสดง UI ให้แก่ผู้ใช้

การควบคุมเสียง AIDL HAL 3.0

เวอร์ชัน HAL การควบคุมเสียงสำหรับ Android 14 AIDL คือ อัปเดตเป็นเวอร์ชัน 3.0 เพื่ออัปเดต API เพื่อมอบสัญญาณเสียงที่มีประสิทธิภาพมากขึ้น ฟังก์ชันดัชนี HAL API การควบคุมเสียงช่วยให้บริการเสียงสามารถ ตั้งค่าและยกเลิกการตั้งค่า IModuleChangeCallback:

interface IAudioControl {
       /**
       *   Sets callback with HAL for notifying changes to hardware module
       *   (that is: {@link android.hardware.audio.core.IModule}) configurations.
       *
       *   @param callback The {@link IModuleChangeCallback} interface to use
       *    use when new updates are available for
       */
       void setModuleChangeCallback(in IModuleChangeCallback callback);
       /**
       *   Clears module change callback
       */
       void clearModuleChangeCallback();
}

setModuleChangeCallback จะได้รับการจดทะเบียนโดยบริการเครื่องเสียงรถยนต์เมื่อ บริการเริ่มทำงานหรือเมื่อกู้คืนจากข้อผิดพลาด เช่น การควบคุมเสียง การแจ้งเตือนการเสียชีวิตจากแฟ้ม HAL ที่ได้รับจากบริการเสียงของรถยนต์ เสียง ควบคุมการใช้ HAL แทน Callback สำหรับการเปลี่ยนแปลงโมดูลที่มีอยู่ เมื่อมีการเรียก API

สำหรับ clearModuleChangeCallback API การใช้งานควรล้าง Callback ที่มีอยู่ หรือไม่ดำเนินการใดๆ หากไม่พบ ซึ่งเป็นแนวทางปฏิบัติที่ดีสำหรับ การใช้การควบคุมด้วยเสียงเพื่อลงทะเบียนผู้สังเกตการณ์เสียชีวิต และเพื่อล้าง Callback หากมีการทริกเกอร์การเสียชีวิตในแฟ้ม

IModuleChangeCallback มีคำจำกัดความดังนี้

oneway interface IModuleChangeCallback {
       /**
       *   Used to indicate that one or more {@link AudioPort} configs have
       *   changed. Implementations MUST return at least one AudioPort.
       *
       *   @param audioPorts list of {@link AudioPort} that are updated
       */
       void onAudioPortsChanged(in AudioPort[] audioPorts);
}

เมื่อบริการเสียงในรถยนต์จดทะเบียนการเปลี่ยนโมดูล พร้อมที่จะรับการเปลี่ยนแปลงพอร์ตเสียงผ่าน onAudioPortChanged API คุณสามารถใช้ API เพื่อเริ่มต้นการเพิ่มระดับเสียงสำหรับระบบเสียงทันทีที่ ลงทะเบียน Callback แล้ว สำหรับการเปลี่ยนแปลงค่าเกนแบบไดนามิกอื่นๆ สามารถเรียก API ตลอดเวลา ดำเนินการเปลี่ยนแปลงที่เกี่ยวข้องและอัปเดตบริการเครื่องเสียงในรถแล้ว ตามนั้น