Skip to content

Commit ff92974

Browse files
committed
fix: fix audio feature switching sequence
The order of operations when disabling mono and noise reduction features was incorrect. Previously, the code would set properties and save configuration before handling device switching, which could cause issues when the default device was a virtual device. Now when disabling these features, the code first switches back to the physical device before applying the feature change to ensure proper device context. The changes ensure that when turning off mono audio or noise reduction, if the current default device is a virtual device created for these features, the system will switch back to the physical device first. This prevents audio routing issues and ensures the feature changes are applied to the correct device context. Log: Fixed audio device switching sequence when disabling mono and noise reduction features Influence: 1. Test enabling/disabling mono audio feature 2. Test enabling/disabling noise reduction feature 3. Verify audio device switching behavior 4. Check that audio continues working after feature toggling 5. Test configuration persistence after feature changes fix: 修复音频功能切换顺序 修复了在禁用单声道和降噪功能时的操作顺序问题。之前代码会在处理设备切换 之前设置属性和保存配置,这可能导致当默认设备是虚拟设备时出现问题。现在 当禁用这些功能时,代码会先切换回物理设备再应用功能更改,确保正确的设备上 下文。 修改确保在关闭单声道音频或降噪功能时,如果当前默认设备是为这些功能创建的 虚拟设备,系统会先切换回物理设备。这可以防止音频路由问题,并确保功能更改 应用于正确的设备上下文。 Log: 修复禁用单声道和降噪功能时的音频设备切换顺序 Influence: 1. 测试启用/禁用单声道音频功能 2. 测试启用/禁用降噪功能 3. 验证音频设备切换行为 4. 检查功能切换后音频是否继续正常工作 5. 测试功能更改后的配置持久性 PMS: BUG-354833 Change-Id: I2669ab9d7ccd091c7f66a611c9d7932e7dcb799c
1 parent 68757c2 commit ff92974

1 file changed

Lines changed: 19 additions & 11 deletions

File tree

audio1/audio.go

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1813,17 +1813,20 @@ func (a *Audio) setMono(enable bool) error {
18131813
if a.Mono == enable {
18141814
return nil
18151815
}
1816-
sink := a.getDefaultSink()
1817-
if sink != nil {
1818-
logger.Infof("set sink %v mono: %v", sink.Name, enable)
1819-
sink.setMono(enable)
1820-
}
1821-
18221816
a.setPropMono(enable)
18231817
err := a.audioDConfig.SetValue(dsgKeyMonoEnabled, enable)
18241818
if err != nil {
18251819
return dbusutil.ToError(errors.New("dconfig Cannot set value " + dsgKeyMonoEnabled))
18261820
}
1821+
sink := a.getDefaultSink()
1822+
if sink != nil {
1823+
logger.Infof("set sink %v mono: %v", sink.Name, enable)
1824+
// 如果是关闭单声道,且当前默认设备是单声道虚拟设备,则先将默认设备切换回物理设备
1825+
if !enable {
1826+
a.ctx.SetDefaultSink(sink.Name)
1827+
}
1828+
sink.setMono(enable)
1829+
}
18271830
return nil
18281831
}
18291832

@@ -1877,16 +1880,21 @@ func (a *Audio) setReduceNoise(enable bool) error {
18771880
if a.ReduceNoise == enable {
18781881
return nil
18791882
}
1883+
a.setPropReduceNoise(enable)
1884+
err := a.audioDConfig.SetValue(dsgKeyReduceNoiseEnabled, enable)
1885+
if err != nil {
1886+
return dbusutil.ToError(errors.New("dconfig Cannot set value " + dsgKeyReduceNoiseEnabled))
1887+
}
1888+
18801889
source := a.getDefaultSource()
18811890
if source != nil {
18821891
logger.Infof("set source <%s> reduce noise <%t>", source.Name, enable)
1892+
// 如果是关闭降噪,且当前默认设备是降噪虚拟设备,则先将默认设备切换回物理设备
1893+
if !enable {
1894+
a.ctx.SetDefaultSource(source.Name)
1895+
}
18831896
source.setReduceNoise(enable)
18841897
}
1885-
a.setPropReduceNoise(enable)
1886-
err := a.audioDConfig.SetValue(dsgKeyReduceNoiseEnabled, enable)
1887-
if err != nil {
1888-
return dbusutil.ToError(errors.New("dconfig Cannot set value " + dsgKeyMonoEnabled))
1889-
}
18901898
return nil
18911899
}
18921900

0 commit comments

Comments
 (0)