src/media/audio/audio_core/audio_admin_unittest.cc
// Test to verify that Mute overrides Duck, and both override None.
Test to verify that Mute overrides Duck, and both override None.
Test to verify that Mute overrides Duck and both override None .
TEST_F(AudioAdminTest, PriorityActionsApplied) {
  StreamVolumeManager stream_volume_manager(dispatcher());
  MockPolicyActionReporter policy_action_reporter([](auto _usage, auto _policy_action) {});
  MockActivityDispatcher mock_activity_dispatcher;
  AudioAdmin admin(kTestBehaviorGain, &stream_volume_manager, &policy_action_reporter,
                   &mock_activity_dispatcher, dispatcher());
  test::NullAudioRenderer r1, r2, r3;
  test::NullAudioCapturer c1;
  admin.SetInteraction(
      fuchsia::media::Usage::WithRenderUsage(fuchsia::media::AudioRenderUsage::SYSTEM_AGENT),
      fuchsia::media::Usage::WithRenderUsage(fuchsia::media::AudioRenderUsage::INTERRUPTION),
      fuchsia::media::Behavior::DUCK);
  admin.SetInteraction(
      fuchsia::media::Usage::WithRenderUsage(fuchsia::media::AudioRenderUsage::SYSTEM_AGENT),
      fuchsia::media::Usage::WithRenderUsage(fuchsia::media::AudioRenderUsage::COMMUNICATION),
      fuchsia::media::Behavior::DUCK);
  admin.SetInteraction(
      fuchsia::media::Usage::WithCaptureUsage(fuchsia::media::AudioCaptureUsage::SYSTEM_AGENT),
      fuchsia::media::Usage::WithRenderUsage(fuchsia::media::AudioRenderUsage::COMMUNICATION),
      fuchsia::media::Behavior::MUTE);
  const float kStreamGain = 1.0;
  stream_volume_manager.SetUsageGain(
      fuchsia::media::Usage::WithRenderUsage(fuchsia::media::AudioRenderUsage::INTERRUPTION),
      kStreamGain);
  stream_volume_manager.SetUsageGain(
      fuchsia::media::Usage::WithRenderUsage(fuchsia::media::AudioRenderUsage::COMMUNICATION),
      kStreamGain);
  admin.UpdateRendererState(fuchsia::media::AudioRenderUsage::INTERRUPTION, true, &r1);
  RunLoopUntilIdle();
  EXPECT_EQ(
      kStreamGain + kNoneGain,
      stream_volume_manager.GetUsageGainSettings().GetAdjustedUsageGain(
          fuchsia::media::Usage::WithRenderUsage(fuchsia::media::AudioRenderUsage::INTERRUPTION)));
  admin.UpdateRendererState(fuchsia::media::AudioRenderUsage::COMMUNICATION, true, &r2);
  RunLoopUntilIdle();
  EXPECT_EQ(
      kStreamGain + kNoneGain,
      stream_volume_manager.GetUsageGainSettings().GetAdjustedUsageGain(
          fuchsia::media::Usage::WithRenderUsage(fuchsia::media::AudioRenderUsage::COMMUNICATION)));
  admin.UpdateCapturerState(fuchsia::media::AudioCaptureUsage::SYSTEM_AGENT, true, &c1);
  RunLoopUntilIdle();
  EXPECT_EQ(
      kStreamGain + kNoneGain,
      stream_volume_manager.GetUsageGainSettings().GetAdjustedUsageGain(
          fuchsia::media::Usage::WithRenderUsage(fuchsia::media::AudioRenderUsage::INTERRUPTION)));
  EXPECT_EQ(
      kStreamGain + kMuteGain,
      stream_volume_manager.GetUsageGainSettings().GetAdjustedUsageGain(
          fuchsia::media::Usage::WithRenderUsage(fuchsia::media::AudioRenderUsage::COMMUNICATION)));
  admin.UpdateRendererState(fuchsia::media::AudioRenderUsage::SYSTEM_AGENT, true, &r3);
  RunLoopUntilIdle();
  EXPECT_EQ(
      kStreamGain + kDuckGain,
      stream_volume_manager.GetUsageGainSettings().GetAdjustedUsageGain(
          fuchsia::media::Usage::WithRenderUsage(fuchsia::media::AudioRenderUsage::INTERRUPTION)));
  EXPECT_EQ(
      kStreamGain + kMuteGain,
      stream_volume_manager.GetUsageGainSettings().GetAdjustedUsageGain(
          fuchsia::media::Usage::WithRenderUsage(fuchsia::media::AudioRenderUsage::COMMUNICATION)));
}
TEST_F ( AudioAdminTest , PriorityActionsApplied ) { StreamVolumeManager stream_volume_manager ( dispatcher ( ) ) ; MockPolicyActionReporter policy_action_reporter ( [ ] ( auto _usage , auto _policy_action ) { } ) ; MockActivityDispatcher mock_activity_dispatcher ; AudioAdmin admin ( kTestBehaviorGain , & stream_volume_manager , & policy_action_reporter , & mock_activity_dispatcher , dispatcher ( ) ) ; test :: NullAudioRenderer r1 , r2 , r3 ; test :: NullAudioCapturer c1 ; admin . SetInteraction ( fuchsia :: media :: Usage :: WithRenderUsage ( fuchsia :: media :: AudioRenderUsage :: SYSTEM_AGENT ) , fuchsia :: media :: Usage :: WithRenderUsage ( fuchsia :: media :: AudioRenderUsage :: INTERRUPTION ) , fuchsia :: media :: Behavior :: DUCK ) ; admin . SetInteraction ( fuchsia :: media :: Usage :: WithRenderUsage ( fuchsia :: media :: AudioRenderUsage :: SYSTEM_AGENT ) , fuchsia :: media :: Usage :: WithRenderUsage ( fuchsia :: media :: AudioRenderUsage :: COMMUNICATION ) , fuchsia :: media :: Behavior :: DUCK ) ; admin . SetInteraction ( fuchsia :: media :: Usage :: WithCaptureUsage ( fuchsia :: media :: AudioCaptureUsage :: SYSTEM_AGENT ) , fuchsia :: media :: Usage :: WithRenderUsage ( fuchsia :: media :: AudioRenderUsage :: COMMUNICATION ) , fuchsia :: media :: Behavior :: MUTE ) ; const float kStreamGain = 1.0 ; stream_volume_manager . SetUsageGain ( fuchsia :: media :: Usage :: WithRenderUsage ( fuchsia :: media :: AudioRenderUsage :: INTERRUPTION ) , kStreamGain ) ; stream_volume_manager . SetUsageGain ( fuchsia :: media :: Usage :: WithRenderUsage ( fuchsia :: media :: AudioRenderUsage :: COMMUNICATION ) , kStreamGain ) ; admin . UpdateRendererState ( fuchsia :: media :: AudioRenderUsage :: INTERRUPTION , true , & r1 ) ; RunLoopUntilIdle ( ) ; EXPECT_EQ ( kStreamGain + kNoneGain , stream_volume_manager . GetUsageGainSettings ( ) . GetAdjustedUsageGain ( fuchsia :: media :: Usage :: WithRenderUsage ( fuchsia :: media :: AudioRenderUsage :: INTERRUPTION ) ) ) ; admin . UpdateRendererState ( fuchsia :: media :: AudioRenderUsage :: COMMUNICATION , true , & r2 ) ; RunLoopUntilIdle ( ) ; EXPECT_EQ ( kStreamGain + kNoneGain , stream_volume_manager . GetUsageGainSettings ( ) . GetAdjustedUsageGain ( fuchsia :: media :: Usage :: WithRenderUsage ( fuchsia :: media :: AudioRenderUsage :: COMMUNICATION ) ) ) ; admin . UpdateCapturerState ( fuchsia :: media :: AudioCaptureUsage :: SYSTEM_AGENT , true , & c1 ) ; RunLoopUntilIdle ( ) ; EXPECT_EQ ( kStreamGain + kNoneGain , stream_volume_manager . GetUsageGainSettings ( ) . GetAdjustedUsageGain ( fuchsia :: media :: Usage :: WithRenderUsage ( fuchsia :: media :: AudioRenderUsage :: INTERRUPTION ) ) ) ; EXPECT_EQ ( kStreamGain + kMuteGain , stream_volume_manager . GetUsageGainSettings ( ) . GetAdjustedUsageGain ( fuchsia :: media :: Usage :: WithRenderUsage ( fuchsia :: media :: AudioRenderUsage :: COMMUNICATION ) ) ) ; admin . UpdateRendererState ( fuchsia :: media :: AudioRenderUsage :: SYSTEM_AGENT , true , & r3 ) ; RunLoopUntilIdle ( ) ; EXPECT_EQ ( kStreamGain + kDuckGain , stream_volume_manager . GetUsageGainSettings ( ) . GetAdjustedUsageGain ( fuchsia :: media :: Usage :: WithRenderUsage ( fuchsia :: media :: AudioRenderUsage :: INTERRUPTION ) ) ) ; EXPECT_EQ ( kStreamGain + kMuteGain , stream_volume_manager . GetUsageGainSettings ( ) . GetAdjustedUsageGain ( fuchsia :: media :: Usage :: WithRenderUsage ( fuchsia :: media :: AudioRenderUsage :: COMMUNICATION ) ) ) ; }
Test to verify that Mute overrides Duck, and both override None.
Test to verify that Mute overrides Duck and both override None .
// Interruption should duck when SystemAgent(render) is active. // Communication(render) should duck when SystemAgent(render) is active. // Communication(render) should mute when SystemAgent(capture) is active. // Set an initial stream volume. // Create Interruption active stream. // Create Communication active stream. // SystemAgent capturer becomes active; Interruption should not change, Communication should mute. // SystemAgent renderer becomes active; Interruption should duck, Communication should remain // muted.