diff options
author | Jean-Michel Trivi <jmtrivi@google.com> | 2012-04-17 11:27:28 -0700 |
---|---|---|
committer | Jean-Michel Trivi <jmtrivi@google.com> | 2012-04-19 09:13:22 -0700 |
commit | 997592b3ce5492e500aebb87066bbeab6c4e4599 (patch) | |
tree | ca26a18db9fe00b80efc4eb472559f69f48f6605 /media/tests/MediaFrameworkTest/src | |
parent | e1123e7f36723a8b888501c9a22a589297849ca2 (diff) | |
download | frameworks_base-997592b3ce5492e500aebb87066bbeab6c4e4599.zip frameworks_base-997592b3ce5492e500aebb87066bbeab6c4e4599.tar.gz frameworks_base-997592b3ce5492e500aebb87066bbeab6c4e4599.tar.bz2 |
Add functional tests for Visualizer volume scaling mode
Add test to set/get the volume scaling mode.
Add test to verify that volume decreases diminish the commputed
energy.
Change-Id: I0a5d45d064a46a18e5c4b9d7a304c9572f100cdf
Diffstat (limited to 'media/tests/MediaFrameworkTest/src')
-rw-r--r-- | media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/MediaVisualizerTest.java | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/MediaVisualizerTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/MediaVisualizerTest.java index b0bf654..abf85d7 100644 --- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/MediaVisualizerTest.java +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/MediaVisualizerTest.java @@ -188,6 +188,37 @@ public class MediaVisualizerTest extends ActivityInstrumentationTestCase2<MediaF assertTrue(msg, result); } + //Test case 1.2: check scaling mode + @LargeTest + public void test1_2ScalingMode() throws Exception { + boolean result = false; + String msg = "test1_2ScalingMode()"; + getVisualizer(0); + try { + int res = mVisualizer.setScalingMode(Visualizer.SCALING_MODE_AS_PLAYED); + assertEquals(msg + ": setting SCALING_MODE_AS_PLAYED failed", + res, Visualizer.SUCCESS); + int mode = mVisualizer.getScalingMode(); + assertEquals(msg + ": setting SCALING_MODE_AS_PLAYED didn't stick", + mode, Visualizer.SCALING_MODE_AS_PLAYED); + + res = mVisualizer.setScalingMode(Visualizer.SCALING_MODE_NORMALIZED); + assertEquals(msg + ": setting SCALING_MODE_NORMALIZED failed", + res, Visualizer.SUCCESS); + mode = mVisualizer.getScalingMode(); + assertEquals(msg + ": setting SCALING_MODE_NORMALIZED didn't stick", + mode, Visualizer.SCALING_MODE_NORMALIZED); + + result = true; + } catch (IllegalStateException e) { + msg = msg.concat("IllegalStateException"); + loge(msg, "set/get parameter() called in wrong state: " + e); + } finally { + releaseVisualizer(); + } + assertTrue(msg, result); + } + //----------------------------------------------------------------- // 2 - check capture //---------------------------------- @@ -403,6 +434,91 @@ public class MediaVisualizerTest extends ActivityInstrumentationTestCase2<MediaF assertTrue(msg, result); } + //Test case 2.2: test capture in polling mode with volume scaling + @LargeTest + public void test2_2PollingCaptureVolumeScaling() throws Exception { + // test that when playing a sound, the energy measured with Visualizer in + // SCALING_MODE_AS_PLAYED mode decreases when lowering the volume + boolean result = false; + String msg = "test2_2PollingCaptureVolumeScaling()"; + AudioEffect vc = null; + MediaPlayer mp = null; + AudioManager am = (AudioManager) getActivity().getSystemService(Context.AUDIO_SERVICE); + int ringerMode = am.getRingerMode(); + am.setRingerMode(AudioManager.RINGER_MODE_NORMAL); + final int volMax = am.getStreamMaxVolume(AudioManager.STREAM_MUSIC); + am.setStreamVolume(AudioManager.STREAM_MUSIC, volMax, 0); + + try { + // test setup not related to tested functionality: + // creating a volume controller on output mix ensures that ro.audio.silent mutes + // audio after the effects and not before + vc = new AudioEffect( + AudioEffect.EFFECT_TYPE_NULL, + VOLUME_EFFECT_UUID, + 0, + 0); + vc.setEnabled(true); + + mp = new MediaPlayer(); + mp.setDataSource(MediaNames.SINE_200_1000); + mp.setAudioStreamType(AudioManager.STREAM_MUSIC); + getVisualizer(mp.getAudioSessionId()); + + // verify we successfully set the Visualizer in SCALING_MODE_AS_PLAYED mode + mVisualizer.setScalingMode(Visualizer.SCALING_MODE_AS_PLAYED); + assertTrue(msg + " get volume scaling doesn't return SCALING_MODE_AS_PLAYED", + mVisualizer.getScalingMode() == Visualizer.SCALING_MODE_AS_PLAYED); + mVisualizer.setEnabled(true); + mp.prepare(); + mp.start(); + Thread.sleep(500); + + // check capture on sound with music volume at max + byte[] data = new byte[mVisualizer.getCaptureSize()]; + mVisualizer.getWaveForm(data); + int energyAtVolMax = computeEnergy(data, true); + assertTrue(msg +": getWaveForm reads insufficient level", + energyAtVolMax > 0); + log(msg, " engergy at max volume = "+energyAtVolMax); + + // check capture on sound with music volume lowered from max + am.setStreamVolume(AudioManager.STREAM_MUSIC, (volMax * 2) / 3, 0); + Thread.sleep(500); + mVisualizer.getWaveForm(data); + int energyAtLowerVol = computeEnergy(data, true); + assertTrue(msg +": getWaveForm at lower volume reads insufficient level", + energyAtLowerVol > 0); + log(msg, "energy at lower volume = "+energyAtLowerVol); + assertTrue(msg +": getWaveForm didn't report lower energy when volume decreases", + energyAtVolMax > energyAtLowerVol); + + result = true; + } catch (IllegalArgumentException e) { + msg = msg.concat(": IllegalArgumentException"); + loge(msg, " hit exception " + e); + } catch (UnsupportedOperationException e) { + msg = msg.concat(": UnsupportedOperationException"); + loge(msg, " hit exception " + e); + } catch (IllegalStateException e) { + msg = msg.concat("IllegalStateException"); + loge(msg, " hit exception " + e); + } catch (InterruptedException e) { + loge(msg, " sleep() interrupted"); + } + finally { + releaseVisualizer(); + if (mp != null) { + mp.release(); + } + if (vc != null) { + vc.release(); + } + am.setRingerMode(ringerMode); + } + assertTrue(msg, result); + } + //----------------------------------------------------------------- // private methods //---------------------------------- |