มีการเปิดตัว HAL การควบคุมเสียงใน Android 9 เพื่อ รองรับกรณีการใช้งานเสียงที่เกี่ยวข้องกับยานยนต์ ตั้งแต่ Android 14 เป็นต้นไป HAL ของการควบคุมเสียงจะรองรับสิ่งต่อไปนี้
- เฟดและบาลานซ์
- คำขอโฟกัสเสียง HAL
- การปิดเสียงและการลดระดับเสียงของอุปกรณ์
- การเปลี่ยนแปลงอัตราขยายของอุปกรณ์เสียง
- การเปลี่ยนแปลงการกำหนดค่าพอร์ตเสียง
รูปที่ 1 แสดงภาพรวมระดับสูงของสถาปัตยกรรมบริการเสียงในรถยนต์ ซึ่งบริการเสียงในรถยนต์จะสื่อสารกับ HAL ควบคุมเสียง
รูปที่ 1 กำหนดค่าเสียงแบบหลายโซน
การจางเสียงและสมดุลเสียง
Android
9 ได้เปิดตัว HIDL Audio Control HAL เวอร์ชัน 1 เพื่อรองรับการเฟดและบาลานซ์เสียงในกรณีการใช้งานยานยนต์
นอกเหนือจากเอฟเฟกต์เสียงทั่วไปที่มีให้ใน 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 Audio Control 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 ไปยัง AIDL Audio Control HAL
เมื่อ 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
แล้ว HAL
การควบคุมเสียง AIDL ต้องใช้กลไกการปิดเสียงกลุ่มระดับเสียงด้วย
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 แบบที่แตกต่างกัน โดยอิงตามสิ่งต่อไปนี้
เหตุการณ์สำคัญที่ใช้ audio 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 Audio Control HAL 2.0
ใน Android 13 เราได้อัปเดต HAL การควบคุมเสียง AIDL เป็นเวอร์ชัน 2.0 เพื่ออัปเดต API และอำนวยความสะดวกในการใช้งานฟังก์ชันใหม่ๆ ดังนี้
- โฟกัสเสียงด้วย
PlaybackTrackMetadata
- การเรียกกลับของการเพิ่มเสียง
ข้อมูลเมตาการเล่นใน android.hardware.audio.common
มีการกำหนดดังนี้
parcelable PlaybackTrackMetadata {
AudioUsage usage = INVALID;
AudioContentType contentType = UNKNOWN;
float gain;
AudioChannelLayout channelMask;
AudioDevice sourceDevice;
String[] tags;
}
ฟังก์ชันอื่นๆ ทั้งหมดจากเวอร์ชัน 1.0 ของการควบคุมเสียง AIDL ยังคงอยู่และสามารถใช้ได้ ข้อยกเว้นเกี่ยวข้องกับวิธีการเปลี่ยนโฟกัสเสียงตามที่อธิบายไว้ในเกี่ยวกับวิธีการเปลี่ยนโฟกัสเสียง
โฟกัสการควบคุมเสียงด้วยข้อมูลเมตาของแทร็กการเล่น
หากต้องการแสดงข้อมูลเพิ่มเติมในระบบเสียงที่อยู่ใต้ 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 เฉพาะข้อมูลเมตาของแทร็กการเล่นเท่านั้นที่มีข้อมูลเพิ่มเติม พร้อมกับการใช้งานแอตทริบิวต์เสียง โดยทั่วไปแล้ว HAL การควบคุม Android ที่อัปเดตแล้วจะใช้วิธีการก่อนหน้าต่อไปได้ เว้นแต่จะต้องใช้ข้อมูลเพิ่มเติมที่ระบุโดยข้อมูลเมตาของแทร็กการเล่น
หากนักพัฒนา 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
จะยังคงมีข้อมูลที่จำเป็นจนกว่าจะมีการนำตัวเลือกนี้ออกอย่างเป็นทางการ
การเรียกกลับเพื่อปรับอัตราขยายเสียง
เราได้เพิ่มกลไกที่คุณใช้เพื่อสื่อสารการเปลี่ยนแปลง อัตราขยายเสียงจากระบบเสียงของรถยนต์ไปยังบริการเสียงของรถยนต์ เพื่อให้การเปลี่ยนแปลงเสียงด้านล่าง HAL มองเห็นได้ชัดเจนยิ่งขึ้นใน AAOS ใน Android 13 กลไกจะแสดงการเปลี่ยนแปลงดัชนีระดับเสียงเกนของเสียงพร้อมเหตุผลที่เกี่ยวข้องว่าทำไมจึงมีการเปลี่ยนเกน
- ข้อจำกัดที่ถูกบล็อกหรือปิดเสียง
- ข้อจำกัด
- ข้อจำกัดการลดทอน
การเปลี่ยนแปลงเหล่านี้จะแสดงข้อจำกัดเหล่านี้จากด้านล่าง HAL ไปยัง บริการเสียงในรถยนต์ และสุดท้ายไปยังแอป UI ของระบบเพื่อแจ้งให้ผู้ใช้ทราบ ส่วนหลัง ซึ่งเป็นการเปิดเผย UI ของระบบที่เป็นไปได้ ได้รับการขยายเพิ่มเติมใน Android 14 เพื่อให้แอป UI ของระบบรับข้อมูลนี้ได้ง่ายขึ้น ผ่านกลไกการเรียกกลับข้อมูลกลุ่มระดับเสียง
API ของ HAL สำหรับการควบคุมเสียงจะลงทะเบียนการเรียกกลับของอัตราขยายดังนี้
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 บริการเครื่องเสียงในรถยนต์จะลงทะเบียนการเรียกกลับของอัตราขยายกับ HAL การควบคุมเสียง เมื่อมีการเรียก API จาก HAL ควบคุมเสียง บริการเสียงในรถจะตอบกลับด้วยการดำเนินการที่เกี่ยวข้อง (เช่น บล็อก จำกัด หรือลดดัชนีเกน)
HAL จะกำหนดเวลาเรียกใช้ API โดยมีวัตถุประสงค์หลักเพื่อรายงานการเปลี่ยนแปลงสถานะดัชนีการรับ ระบบเสียงของรถยนต์ควรดำเนินการที่จำเป็นและใช้การเรียกกลับเพื่อรายงานข้อมูลไปยังบริการเสียงในรถยนต์เพื่อให้ผู้ใช้สามารถใช้งานได้ตามข้อกำหนดด้านกฎระเบียบ เช่น เพื่อแสดง UI แก่ผู้ใช้
AIDL Audio Control HAL 3.0
เราได้อัปเดต HAL ควบคุมเสียง AIDL ของ Android 14 เป็นเวอร์ชัน 3.0 เพื่ออัปเดต API ให้มีฟังก์ชันดัชนีการเพิ่มเสียงที่แข็งแกร่งยิ่งขึ้น
API ของ HAL การควบคุมเสียงช่วยให้บริการเสียงสามารถ
ตั้งค่าและยกเลิกการตั้งค่า 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 ของการควบคุมเสียง
ควรแทนที่การเรียกกลับการเปลี่ยนแปลงโมดูลที่มีอยู่
เมื่อมีการเรียก API
สำหรับ clearModuleChangeCallback
API การติดตั้งใช้งานควรล้าง
การเรียกกลับที่มีอยู่ หรือไม่ดำเนินการใดๆ หากไม่มีการเรียกกลับ แนวทางปฏิบัติที่ดีสำหรับการติดตั้งใช้งานการควบคุมเสียงคือการลงทะเบียนตัวสังเกตการสิ้นสุดสำหรับโค้ดเรียกกลับ
และล้างโค้ดเรียกกลับหากมีการเรียกใช้การสิ้นสุดของ Binder
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 สามารถใช้เพื่อเริ่มต้นการเพิ่มระดับเสียงสำหรับระบบเสียงได้ทันทีที่ลงทะเบียน
การเรียกกลับ สำหรับการเปลี่ยนแปลงอัตราขยายแบบไดนามิกอื่นๆ คุณสามารถเรียก API ได้ทุกเมื่อ ระบบจะใช้การเปลี่ยนแปลงที่เกี่ยวข้องและอัปเดตบริการเสียงในรถยนต์ตามนั้น