src/media/audio/audio_core/audio_admin_unittest.cc
// Test to verify that a muted active stream's policy is not applied.
Test to verify that a muted active stream's policy is not applied.
Test to verify that a muted active stream ' s policy is not applied .
TEST_F(AudioAdminTest, IgnoreMutedActiveStreamPolicy) {
  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;
  test::NullAudioCapturer c1;
  admin.SetInteraction(
      fuchsia::media::Usage::WithRenderUsage(fuchsia::media::AudioRenderUsage::COMMUNICATION),
      fuchsia::media::Usage::WithRenderUsage(fuchsia::media::AudioRenderUsage::MEDIA),
      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::MEDIA), kStreamGain);
  stream_volume_manager.SetUsageGain(
      fuchsia::media::Usage::WithRenderUsage(fuchsia::media::AudioRenderUsage::COMMUNICATION),
      kStreamGain);
  admin.UpdateRendererState(fuchsia::media::AudioRenderUsage::MEDIA, true, &r1);
  RunLoopUntilIdle();
  EXPECT_EQ(kStreamGain + kNoneGain,
            stream_volume_manager.GetUsageGainSettings().GetAdjustedUsageGain(
                fuchsia::media::Usage::WithRenderUsage(fuchsia::media::AudioRenderUsage::MEDIA)));
  admin.UpdateRendererState(fuchsia::media::AudioRenderUsage::COMMUNICATION, true, &r2);
  RunLoopUntilIdle();
  EXPECT_EQ(kStreamGain + kDuckGain,
            stream_volume_manager.GetUsageGainSettings().GetAdjustedUsageGain(
                fuchsia::media::Usage::WithRenderUsage(fuchsia::media::AudioRenderUsage::MEDIA)));
  admin.UpdateCapturerState(fuchsia::media::AudioCaptureUsage::SYSTEM_AGENT, true, &c1);
  RunLoopUntilIdle();
  EXPECT_EQ(
      kStreamGain + kMuteGain,
      stream_volume_manager.GetUsageGainSettings().GetAdjustedUsageGain(
          fuchsia::media::Usage::WithRenderUsage(fuchsia::media::AudioRenderUsage::COMMUNICATION)));
  EXPECT_EQ(kStreamGain + kNoneGain,
            stream_volume_manager.GetUsageGainSettings().GetAdjustedUsageGain(
                fuchsia::media::Usage::WithRenderUsage(fuchsia::media::AudioRenderUsage::MEDIA)));
}
TEST_F ( AudioAdminTest , IgnoreMutedActiveStreamPolicy ) { 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 ; test :: NullAudioCapturer c1 ; admin . SetInteraction ( fuchsia :: media :: Usage :: WithRenderUsage ( fuchsia :: media :: AudioRenderUsage :: COMMUNICATION ) , fuchsia :: media :: Usage :: WithRenderUsage ( fuchsia :: media :: AudioRenderUsage :: MEDIA ) , 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 :: MEDIA ) , kStreamGain ) ; stream_volume_manager . SetUsageGain ( fuchsia :: media :: Usage :: WithRenderUsage ( fuchsia :: media :: AudioRenderUsage :: COMMUNICATION ) , kStreamGain ) ; admin . UpdateRendererState ( fuchsia :: media :: AudioRenderUsage :: MEDIA , true , & r1 ) ; RunLoopUntilIdle ( ) ; EXPECT_EQ ( kStreamGain + kNoneGain , stream_volume_manager . GetUsageGainSettings ( ) . GetAdjustedUsageGain ( fuchsia :: media :: Usage :: WithRenderUsage ( fuchsia :: media :: AudioRenderUsage :: MEDIA ) ) ) ; admin . UpdateRendererState ( fuchsia :: media :: AudioRenderUsage :: COMMUNICATION , true , & r2 ) ; RunLoopUntilIdle ( ) ; EXPECT_EQ ( kStreamGain + kDuckGain , stream_volume_manager . GetUsageGainSettings ( ) . GetAdjustedUsageGain ( fuchsia :: media :: Usage :: WithRenderUsage ( fuchsia :: media :: AudioRenderUsage :: MEDIA ) ) ) ; admin . UpdateCapturerState ( fuchsia :: media :: AudioCaptureUsage :: SYSTEM_AGENT , true , & c1 ) ; RunLoopUntilIdle ( ) ; EXPECT_EQ ( kStreamGain + kMuteGain , stream_volume_manager . GetUsageGainSettings ( ) . GetAdjustedUsageGain ( fuchsia :: media :: Usage :: WithRenderUsage ( fuchsia :: media :: AudioRenderUsage :: COMMUNICATION ) ) ) ; EXPECT_EQ ( kStreamGain + kNoneGain , stream_volume_manager . GetUsageGainSettings ( ) . GetAdjustedUsageGain ( fuchsia :: media :: Usage :: WithRenderUsage ( fuchsia :: media :: AudioRenderUsage :: MEDIA ) ) ) ; }
Test to verify that a muted active stream's policy is not applied.
Test to verify that a muted active stream ' s policy is not applied .
// Media should duck when Communication(render) is active. // Communication(render) should mute when SystemAgent(capture) is active. // Set an initial stream volume. // Create Media active stream. // Communication renderer becomes active; Media should duck. // SystemAgent capturer becomes active; Communication should mute, so its policy should no longer // apply to Media.