From db6028508c8eb31a0de1dcdfc410ddfe6df7c5ad Mon Sep 17 00:00:00 2001 From: Xia Wang Date: Tue, 27 Sep 2011 16:00:20 -0700 Subject: Reorganize media framework functional tests. Group tests into sub-packages Change-Id: I878e14487142de495fc646037d5d0b51e39341bd --- .../MediaFrameworkTestRunner.java | 35 +- .../functional/MediaAudioEffectTest.java | 1532 ----------- .../functional/MediaAudioManagerTest.java | 70 - .../functional/MediaAudioTrackTest.java | 1253 --------- .../functional/MediaBassBoostTest.java | 289 -- .../functional/MediaEnvReverbTest.java | 523 ---- .../functional/MediaEqualizerTest.java | 352 --- .../functional/MediaItemThumbnailTest.java | 956 ------- .../functional/MediaPlayerApiTest.java | 426 --- .../functional/MediaPresetReverbTest.java | 368 --- .../functional/MediaPropertiesTest.java | 774 ------ .../functional/MediaRecorderTest.java | 302 --- .../functional/MediaVirtualizerTest.java | 294 -- .../functional/MediaVisualizerTest.java | 505 ---- .../functional/SimTonesTest.java | 73 - .../functional/VideoEditorAPITest.java | 2802 -------------------- .../functional/VideoEditorExportTest.java | 820 ------ .../functional/VideoEditorPreviewTest.java | 1139 -------- .../functional/audio/MediaAudioEffectTest.java | 1531 +++++++++++ .../functional/audio/MediaAudioManagerTest.java | 70 + .../functional/audio/MediaAudioTrackTest.java | 1252 +++++++++ .../functional/audio/MediaBassBoostTest.java | 289 ++ .../functional/audio/MediaEnvReverbTest.java | 523 ++++ .../functional/audio/MediaEqualizerTest.java | 352 +++ .../functional/audio/MediaPresetReverbTest.java | 368 +++ .../functional/audio/MediaVirtualizerTest.java | 294 ++ .../functional/audio/MediaVisualizerTest.java | 504 ++++ .../functional/audio/SimTonesTest.java | 73 + .../mediaplayback/MediaPlayerApiTest.java | 426 +++ .../mediarecorder/MediaRecorderTest.java | 302 +++ .../videoeditor/MediaItemThumbnailTest.java | 956 +++++++ .../videoeditor/MediaPropertiesTest.java | 774 ++++++ .../functional/videoeditor/VideoEditorAPITest.java | 2802 ++++++++++++++++++++ .../videoeditor/VideoEditorExportTest.java | 820 ++++++ .../videoeditor/VideoEditorPreviewTest.java | 1139 ++++++++ 35 files changed, 12492 insertions(+), 12496 deletions(-) delete mode 100644 media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaAudioEffectTest.java delete mode 100644 media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaAudioManagerTest.java delete mode 100644 media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaAudioTrackTest.java delete mode 100644 media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaBassBoostTest.java delete mode 100644 media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaEnvReverbTest.java delete mode 100644 media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaEqualizerTest.java delete mode 100755 media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaItemThumbnailTest.java delete mode 100644 media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaPlayerApiTest.java delete mode 100644 media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaPresetReverbTest.java delete mode 100755 media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaPropertiesTest.java delete mode 100644 media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaRecorderTest.java delete mode 100644 media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaVirtualizerTest.java delete mode 100644 media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaVisualizerTest.java delete mode 100644 media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/SimTonesTest.java delete mode 100644 media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/VideoEditorAPITest.java delete mode 100755 media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/VideoEditorExportTest.java delete mode 100644 media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/VideoEditorPreviewTest.java create mode 100644 media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/MediaAudioEffectTest.java create mode 100644 media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/MediaAudioManagerTest.java create mode 100644 media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/MediaAudioTrackTest.java create mode 100644 media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/MediaBassBoostTest.java create mode 100644 media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/MediaEnvReverbTest.java create mode 100644 media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/MediaEqualizerTest.java create mode 100644 media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/MediaPresetReverbTest.java create mode 100644 media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/MediaVirtualizerTest.java create mode 100644 media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/MediaVisualizerTest.java create mode 100644 media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/SimTonesTest.java create mode 100644 media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/mediaplayback/MediaPlayerApiTest.java create mode 100644 media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/mediarecorder/MediaRecorderTest.java create mode 100755 media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/videoeditor/MediaItemThumbnailTest.java create mode 100755 media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/videoeditor/MediaPropertiesTest.java create mode 100644 media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/videoeditor/VideoEditorAPITest.java create mode 100755 media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/videoeditor/VideoEditorExportTest.java create mode 100644 media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/videoeditor/VideoEditorPreviewTest.java diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaFrameworkTestRunner.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaFrameworkTestRunner.java index f3cf0f7..3fb2da0 100755 --- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaFrameworkTestRunner.java +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaFrameworkTestRunner.java @@ -17,27 +17,26 @@ package com.android.mediaframeworktest; import com.android.mediaframeworktest.functional.CameraTest; -import com.android.mediaframeworktest.functional.MediaAudioTrackTest; import com.android.mediaframeworktest.functional.MediaMetadataTest; import com.android.mediaframeworktest.functional.MediaMimeTest; -import com.android.mediaframeworktest.functional.MediaPlayerApiTest; -import com.android.mediaframeworktest.functional.MediaRecorderTest; -import com.android.mediaframeworktest.functional.SimTonesTest; import com.android.mediaframeworktest.functional.MediaPlayerInvokeTest; -import com.android.mediaframeworktest.functional.MediaAudioManagerTest; -import com.android.mediaframeworktest.functional.MediaAudioEffectTest; -import com.android.mediaframeworktest.functional.MediaBassBoostTest; -import com.android.mediaframeworktest.functional.MediaEnvReverbTest; -import com.android.mediaframeworktest.functional.MediaEqualizerTest; -import com.android.mediaframeworktest.functional.MediaPresetReverbTest; -import com.android.mediaframeworktest.functional.MediaVirtualizerTest; -import com.android.mediaframeworktest.functional.MediaVisualizerTest; -/*import for VideoEditor Test cases*/ -import com.android.mediaframeworktest.functional.MediaItemThumbnailTest; -import com.android.mediaframeworktest.functional.MediaPropertiesTest; -import com.android.mediaframeworktest.functional.VideoEditorAPITest; -import com.android.mediaframeworktest.functional.VideoEditorExportTest; -import com.android.mediaframeworktest.functional.VideoEditorPreviewTest; +import com.android.mediaframeworktest.functional.mediaplayback.MediaPlayerApiTest; +import com.android.mediaframeworktest.functional.mediarecorder.MediaRecorderTest; +import com.android.mediaframeworktest.functional.audio.SimTonesTest; +import com.android.mediaframeworktest.functional.audio.MediaAudioTrackTest; +import com.android.mediaframeworktest.functional.audio.MediaAudioManagerTest; +import com.android.mediaframeworktest.functional.audio.MediaAudioEffectTest; +import com.android.mediaframeworktest.functional.audio.MediaBassBoostTest; +import com.android.mediaframeworktest.functional.audio.MediaEnvReverbTest; +import com.android.mediaframeworktest.functional.audio.MediaEqualizerTest; +import com.android.mediaframeworktest.functional.audio.MediaPresetReverbTest; +import com.android.mediaframeworktest.functional.audio.MediaVirtualizerTest; +import com.android.mediaframeworktest.functional.audio.MediaVisualizerTest; +import com.android.mediaframeworktest.functional.videoeditor.MediaItemThumbnailTest; +import com.android.mediaframeworktest.functional.videoeditor.MediaPropertiesTest; +import com.android.mediaframeworktest.functional.videoeditor.VideoEditorAPITest; +import com.android.mediaframeworktest.functional.videoeditor.VideoEditorExportTest; +import com.android.mediaframeworktest.functional.videoeditor.VideoEditorPreviewTest; import junit.framework.TestSuite; import android.test.InstrumentationTestRunner; diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaAudioEffectTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaAudioEffectTest.java deleted file mode 100644 index 1511cd7..0000000 --- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaAudioEffectTest.java +++ /dev/null @@ -1,1532 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.mediaframeworktest.functional; - -import com.android.mediaframeworktest.MediaFrameworkTest; -import com.android.mediaframeworktest.MediaNames; -import android.content.res.AssetFileDescriptor; -import android.media.audiofx.AudioEffect; -import android.media.AudioFormat; -import android.media.AudioManager; -import android.media.AudioTrack; -import android.media.AudioRecord; -import android.media.audiofx.EnvironmentalReverb; -import android.media.audiofx.Equalizer; -import android.media.MediaPlayer; -import android.media.MediaRecorder; - -import android.os.Looper; -import android.test.suitebuilder.annotation.LargeTest; -import android.test.suitebuilder.annotation.MediumTest; -import android.test.suitebuilder.annotation.Suppress; -import android.test.ActivityInstrumentationTestCase2; -import android.util.Log; - -import java.nio.ByteOrder; -import java.nio.ByteBuffer; -import java.util.UUID; - -/** - * Junit / Instrumentation test case for the media AudioTrack api - - */ -public class MediaAudioEffectTest extends ActivityInstrumentationTestCase2 { - private String TAG = "MediaAudioEffectTest"; - - private AudioEffect mEffect = null; - private boolean mHasControl = false; - private boolean mIsEnabled = false; - private int mParameterChanged = -1; - private MediaPlayer mMediaPlayer = null; - private boolean mInitialized = false; - private Looper mLooper = null; - private int mError = 0; - private final Object lock = new Object(); - private final static int SAMPLING_RATE = 44100; - - public MediaAudioEffectTest() { - super("com.android.mediaframeworktest", MediaFrameworkTest.class); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - } - - @Override - protected void tearDown() throws Exception { - super.tearDown(); - } - - private static void assumeTrue(String message, boolean cond) { - assertTrue("(assume)"+message, cond); - } - - private void log(String testName, String message) { - Log.v(TAG, "["+testName+"] "+message); - } - - private void loge(String testName, String message) { - Log.e(TAG, "["+testName+"] "+message); - } - - //----------------------------------------------------------------- - // AUDIOEFFECT TESTS: - //---------------------------------- - - //----------------------------------------------------------------- - // 0 - static methods - //---------------------------------- - - //Test case 0.0: test queryEffects() and available effects - @LargeTest - public void test0_0QueryEffects() throws Exception { - - AudioEffect.Descriptor[] desc = AudioEffect.queryEffects(); - - assertTrue("test0_0QueryEffects: number of effects < 4: "+desc.length, (desc.length >= 4)); - - boolean hasEQ = false; - boolean hasBassBoost = false; - boolean hasVirtualizer = false; - boolean hasEnvReverb = false; - - for (int i = 0; i < desc.length; i++) { - if (desc[i].type.equals(AudioEffect.EFFECT_TYPE_EQUALIZER)) { - hasEQ = true; - } if (desc[i].type.equals(AudioEffect.EFFECT_TYPE_BASS_BOOST)) { - hasBassBoost = true; - } else if (desc[i].type.equals(AudioEffect.EFFECT_TYPE_VIRTUALIZER)) { - hasVirtualizer = true; - } - else if (desc[i].type.equals(AudioEffect.EFFECT_TYPE_ENV_REVERB)) { - hasEnvReverb = true; - } - } - assertTrue("test0_0QueryEffects: equalizer not found", hasEQ); - assertTrue("test0_0QueryEffects: bass boost not found", hasBassBoost); - assertTrue("test0_0QueryEffects: virtualizer not found", hasVirtualizer); - assertTrue("test0_0QueryEffects: environmental reverb not found", hasEnvReverb); - } - - //----------------------------------------------------------------- - // 1 - constructor - //---------------------------------- - - private AudioRecord getAudioRecord() { - AudioRecord ar = null; - try { - ar = new AudioRecord(MediaRecorder.AudioSource.DEFAULT, - SAMPLING_RATE, - AudioFormat.CHANNEL_CONFIGURATION_MONO, - AudioFormat.ENCODING_PCM_16BIT, - AudioRecord.getMinBufferSize(SAMPLING_RATE, - AudioFormat.CHANNEL_CONFIGURATION_MONO, - AudioFormat.ENCODING_PCM_16BIT) * 10); - assertNotNull("Could not create AudioRecord", ar); - assertEquals("AudioRecord not initialized", - AudioRecord.STATE_INITIALIZED, ar.getState()); - } catch (IllegalArgumentException e) { - fail("AudioRecord invalid parameter"); - } - return ar; - } - - //Test case 1.0: test constructor from effect type and get effect ID - @LargeTest - public void test1_0ConstructorFromType() throws Exception { - boolean result = true; - String msg = "test1_0ConstructorFromType()"; - AudioEffect.Descriptor[] desc = AudioEffect.queryEffects(); - assertTrue(msg+": no effects found", (desc.length != 0)); - try { - int sessionId; - AudioRecord ar = null; - if (AudioEffect.EFFECT_PRE_PROCESSING.equals(desc[0].connectMode)) { - ar = getAudioRecord(); - sessionId = ar.getAudioSessionId(); - } else { - sessionId = 0; - } - - AudioEffect effect = new AudioEffect(desc[0].type, - AudioEffect.EFFECT_TYPE_NULL, - 0, - sessionId); - assertNotNull(msg + ": could not create AudioEffect", effect); - try { - assertTrue(msg +": invalid effect ID", (effect.getId() != 0)); - } catch (IllegalStateException e) { - msg = msg.concat(": AudioEffect not initialized"); - result = false; - } finally { - effect.release(); - if (ar != null) { - ar.release(); - } - } - } catch (IllegalArgumentException e) { - msg = msg.concat(": Effect not found: "+desc[0].name); - result = false; - } catch (UnsupportedOperationException e) { - msg = msg.concat(": Effect library not loaded"); - result = false; - } - assertTrue(msg, result); - } - - //Test case 1.1: test constructor from effect uuid - @LargeTest - public void test1_1ConstructorFromUuid() throws Exception { - boolean result = true; - String msg = "test1_1ConstructorFromUuid()"; - AudioEffect.Descriptor[] desc = AudioEffect.queryEffects(); - assertTrue(msg+"no effects found", (desc.length != 0)); - try { - int sessionId; - AudioRecord ar = null; - if (AudioEffect.EFFECT_PRE_PROCESSING.equals(desc[0].connectMode)) { - ar = getAudioRecord(); - sessionId = ar.getAudioSessionId(); - } else { - sessionId = 0; - } - AudioEffect effect = new AudioEffect(AudioEffect.EFFECT_TYPE_NULL, - desc[0].uuid, - 0, - sessionId); - assertNotNull(msg + ": could not create AudioEffect", effect); - effect.release(); - if (ar != null) { - ar.release(); - } - } catch (IllegalArgumentException e) { - msg = msg.concat(": Effect not found: "+desc[0].name); - result = false; - } catch (UnsupportedOperationException e) { - msg = msg.concat(": Effect library not loaded"); - result = false; - } - assertTrue(msg, result); - } - - //Test case 1.2: test constructor failure from unknown type - @LargeTest - public void test1_2ConstructorUnknownType() throws Exception { - boolean result = false; - String msg = "test1_2ConstructorUnknownType()"; - - try { - AudioEffect effect = new AudioEffect(UUID.randomUUID(), - AudioEffect.EFFECT_TYPE_NULL, - 0, - 0); - msg = msg.concat(": could create random AudioEffect"); - if (effect != null) { - effect.release(); - } - } catch (IllegalArgumentException e) { - result = true; - } catch (UnsupportedOperationException e) { - msg = msg.concat(": Effect library not loaded"); - } - assertTrue(msg, result); - } - - //Test case 1.3: test getEnabled() failure when called on released effect - @LargeTest - public void test1_3GetEnabledAfterRelease() throws Exception { - boolean result = false; - String msg = "test1_3GetEnabledAfterRelease()"; - - try { - AudioEffect effect = new AudioEffect(AudioEffect.EFFECT_TYPE_EQUALIZER, - AudioEffect.EFFECT_TYPE_NULL, - 0, - 0); - assertNotNull(msg + ": could not create AudioEffect", effect); - effect.release(); - try { - effect.getEnabled(); - } catch (IllegalStateException e) { - result = true; - } - } catch (IllegalArgumentException e) { - msg = msg.concat(": Equalizer not found"); - } catch (UnsupportedOperationException e) { - msg = msg.concat(": Effect library not loaded"); - } - assertTrue(msg, result); - } - - //Test case 1.4: test contructor on mediaPlayer audio session - @LargeTest - public void test1_4InsertOnMediaPlayer() throws Exception { - boolean result = false; - String msg = "test1_4InsertOnMediaPlayer()"; - - try { - MediaPlayer mp = new MediaPlayer(); - mp.setDataSource(MediaNames.SHORTMP3); - - AudioEffect effect = new AudioEffect(AudioEffect.EFFECT_TYPE_EQUALIZER, - AudioEffect.EFFECT_TYPE_NULL, - 0, - mp.getAudioSessionId()); - assertNotNull(msg + ": could not create AudioEffect", effect); - try { - loge(msg, ": effect.setEnabled"); - effect.setEnabled(true); - } catch (IllegalStateException e) { - msg = msg.concat(": AudioEffect not initialized"); - } - - result = true; - effect.release(); - mp.release(); - } catch (IllegalArgumentException e) { - msg = msg.concat(": Equalizer not found"); - loge(msg, ": Equalizer not found"); - } catch (UnsupportedOperationException e) { - msg = msg.concat(": Effect library not loaded"); - loge(msg, ": Effect library not loaded"); - } catch (Exception e){ - loge(msg, "Could not create media player:" + e); - } - assertTrue(msg, result); - } - - //Test case 1.5: test auxiliary effect attachement on MediaPlayer - @LargeTest - public void test1_5AuxiliaryOnMediaPlayer() throws Exception { - boolean result = false; - String msg = "test1_5AuxiliaryOnMediaPlayer()"; - - try { - MediaPlayer mp = new MediaPlayer(); - mp.setDataSource(MediaNames.SHORTMP3); - - AudioEffect effect = new AudioEffect(AudioEffect.EFFECT_TYPE_ENV_REVERB, - AudioEffect.EFFECT_TYPE_NULL, - 0, - 0); - assertNotNull(msg + ": could not create AudioEffect", effect); - mp.attachAuxEffect(effect.getId()); - mp.setAuxEffectSendLevel(1.0f); - result = true; - effect.release(); - mp.release(); - } catch (IllegalArgumentException e) { - msg = msg.concat(": Equalizer not found"); - loge(msg, ": Equalizer not found"); - } catch (UnsupportedOperationException e) { - msg = msg.concat(": Effect library not loaded"); - loge(msg, ": Effect library not loaded"); - } catch (Exception e){ - loge(msg, "Could not create media player:" + e); - } - assertTrue(msg, result); - } - - //Test case 1.6: test auxiliary effect attachement failure before setDatasource - @LargeTest - public void test1_6AuxiliaryOnMediaPlayerFailure() throws Exception { - boolean result = false; - String msg = "test1_6AuxiliaryOnMediaPlayerFailure()"; - - try { - createMediaPlayerLooper(); - synchronized(lock) { - try { - lock.wait(1000); - } catch(Exception e) { - Log.e(TAG, "Looper creation: wait was interrupted."); - } - } - assertTrue(mInitialized); // mMediaPlayer has been initialized? - mError = 0; - - AudioEffect effect = new AudioEffect(AudioEffect.EFFECT_TYPE_ENV_REVERB, - AudioEffect.EFFECT_TYPE_NULL, - 0, - 0); - assertNotNull(msg + ": could not create AudioEffect", effect); - synchronized(lock) { - try { - mMediaPlayer.attachAuxEffect(effect.getId()); - lock.wait(1000); - } catch(Exception e) { - Log.e(TAG, "Attach effect: wait was interrupted."); - } - } - assertTrue(msg + ": no error on attachAuxEffect", mError != 0); - result = true; - effect.release(); - terminateMediaPlayerLooper(); - } catch (IllegalArgumentException e) { - msg = msg.concat(": Equalizer not found"); - loge(msg, ": Equalizer not found"); - } catch (UnsupportedOperationException e) { - msg = msg.concat(": Effect library not loaded"); - loge(msg, ": Effect library not loaded"); - } catch (Exception e){ - loge(msg, "Could not create media player:" + e); - } - assertTrue(msg, result); - } - - - //Test case 1.7: test auxiliary effect attachement on AudioTrack - @LargeTest - public void test1_7AuxiliaryOnAudioTrack() throws Exception { - boolean result = false; - String msg = "test1_7AuxiliaryOnAudioTrack()"; - - try { - AudioTrack track = new AudioTrack( - AudioManager.STREAM_MUSIC, - 44100, - AudioFormat.CHANNEL_OUT_MONO, - AudioFormat.ENCODING_PCM_16BIT, - AudioTrack.getMinBufferSize(44100, - AudioFormat.CHANNEL_OUT_MONO, - AudioFormat.ENCODING_PCM_16BIT), - AudioTrack.MODE_STREAM); - assertNotNull(msg + ": could not create AudioTrack", track); - AudioEffect effect = new AudioEffect(AudioEffect.EFFECT_TYPE_ENV_REVERB, - AudioEffect.EFFECT_TYPE_NULL, - 0, - 0); - - track.attachAuxEffect(effect.getId()); - track.setAuxEffectSendLevel(1.0f); - result = true; - effect.release(); - track.release(); - } catch (IllegalArgumentException e) { - msg = msg.concat(": Equalizer not found"); - loge(msg, ": Equalizer not found"); - } catch (UnsupportedOperationException e) { - msg = msg.concat(": Effect library not loaded"); - loge(msg, ": Effect library not loaded"); - } - assertTrue(msg, result); - } - - //----------------------------------------------------------------- - // 2 - enable/ disable - //---------------------------------- - - - //Test case 2.0: test setEnabled() and getEnabled() in valid state - @LargeTest - public void test2_0SetEnabledGetEnabled() throws Exception { - boolean result = false; - String msg = "test2_0SetEnabledGetEnabled()"; - - try { - AudioEffect effect = new AudioEffect(AudioEffect.EFFECT_TYPE_EQUALIZER, - AudioEffect.EFFECT_TYPE_NULL, - 0, - 0); - assertNotNull(msg + ": could not create AudioEffect", effect); - try { - effect.setEnabled(true); - assertTrue(msg + ": invalid state from getEnabled", effect.getEnabled()); - effect.setEnabled(false); - assertFalse(msg + ": invalid state to getEnabled", effect.getEnabled()); - result = true; - } catch (IllegalStateException e) { - msg = msg.concat(": setEnabled() in wrong state"); - } finally { - effect.release(); - } - } catch (IllegalArgumentException e) { - msg = msg.concat(": Equalizer not found"); - loge(msg, ": Equalizer not found"); - } catch (UnsupportedOperationException e) { - msg = msg.concat(": Effect library not loaded"); - loge(msg, ": Effect library not loaded"); - } - assertTrue(msg, result); - } - - //Test case 2.1: test setEnabled() throws exception after release - @LargeTest - public void test2_1SetEnabledAfterRelease() throws Exception { - boolean result = false; - String msg = "test2_1SetEnabledAfterRelease()"; - - try { - AudioEffect effect = new AudioEffect(AudioEffect.EFFECT_TYPE_EQUALIZER, - AudioEffect.EFFECT_TYPE_NULL, - 0, - 0); - assertNotNull(msg + ": could not create AudioEffect", effect); - effect.release(); - try { - effect.setEnabled(true); - } catch (IllegalStateException e) { - result = true; - } - } catch (IllegalArgumentException e) { - msg = msg.concat(": Equalizer not found"); - loge(msg, ": Equalizer not found"); - } catch (UnsupportedOperationException e) { - msg = msg.concat(": Effect library not loaded"); - loge(msg, ": Effect library not loaded"); - } - assertTrue(msg, result); - } - - //----------------------------------------------------------------- - // 3 - set parameters - //---------------------------------- - - //Test case 3.0: test setParameter(byte[], byte[]) - @LargeTest - public void test3_0SetParameterByteArrayByteArray() throws Exception { - boolean result = false; - String msg = "test3_0SetParameterByteArrayByteArray()"; - AudioEffect effect = null; - try { - effect = new AudioEffect(AudioEffect.EFFECT_TYPE_EQUALIZER, - AudioEffect.EFFECT_TYPE_NULL, - 0, - 0); - assertNotNull(msg + ": could not create AudioEffect", effect); - byte[] param = intToByteArray(Equalizer.PARAM_CURRENT_PRESET); - byte[] value = shortToByteArray((short)0); - if (effect.setParameter(param, value) == AudioEffect.SUCCESS) { - result = true; - } - } catch (IllegalArgumentException e) { - msg = msg.concat(": Bad parameter value"); - loge(msg, "Bad parameter value"); - } catch (UnsupportedOperationException e) { - msg = msg.concat(": setParameter() rejected"); - loge(msg, "setParameter() rejected"); - } catch (IllegalStateException e) { - msg = msg.concat("setParameter() called in wrong state"); - loge(msg, "setParameter() called in wrong state"); - } finally { - if (effect != null) { - effect.release(); - } - } - assertTrue(msg, result); - } - - //Test case 3.1: test setParameter(int, int) - @LargeTest - public void test3_1SetParameterIntInt() throws Exception { - boolean result = false; - String msg = "test3_1SetParameterIntInt()"; - AudioEffect effect = null; - try { - effect = new AudioEffect(AudioEffect.EFFECT_TYPE_ENV_REVERB, - AudioEffect.EFFECT_TYPE_NULL, - 0, - 0); - assertNotNull(msg + ": could not create AudioEffect", effect); - if (effect.setParameter(EnvironmentalReverb.PARAM_DECAY_TIME, 0) - == AudioEffect.SUCCESS) { - result = true; - } - } catch (IllegalArgumentException e) { - msg = msg.concat(": Bad parameter value"); - loge(msg, "Bad parameter value"); - } catch (UnsupportedOperationException e) { - msg = msg.concat(": setParameter() rejected"); - loge(msg, "setParameter() rejected"); - } catch (IllegalStateException e) { - msg = msg.concat("setParameter() called in wrong state"); - loge(msg, "setParameter() called in wrong state"); - } finally { - if (effect != null) { - effect.release(); - } - } - assertTrue(msg, result); - } - - //Test case 3.2: test setParameter(int, short) - @LargeTest - public void test3_2SetParameterIntShort() throws Exception { - boolean result = false; - String msg = "test3_2SetParameterIntShort()"; - AudioEffect effect = null; - try { - effect = new AudioEffect(AudioEffect.EFFECT_TYPE_EQUALIZER, - AudioEffect.EFFECT_TYPE_NULL, - 0, - 0); - assertNotNull(msg + ": could not create AudioEffect", effect); - if (effect.setParameter(Equalizer.PARAM_CURRENT_PRESET, (short)0) - == AudioEffect.SUCCESS) { - result = true; - } - } catch (IllegalArgumentException e) { - msg = msg.concat(": Bad parameter value"); - loge(msg, "Bad parameter value"); - } catch (UnsupportedOperationException e) { - msg = msg.concat(": setParameter() rejected"); - loge(msg, "setParameter() rejected"); - } catch (IllegalStateException e) { - msg = msg.concat("setParameter() called in wrong state"); - loge(msg, "setParameter() called in wrong state"); - } finally { - if (effect != null) { - effect.release(); - } - } - assertTrue(msg, result); - } - - //Test case 3.3: test setParameter(int, byte[]) - @LargeTest - public void test3_3SetParameterIntByteArray() throws Exception { - boolean result = false; - String msg = "test3_3SetParameterIntByteArray()"; - AudioEffect effect = null; - try { - effect = new AudioEffect(AudioEffect.EFFECT_TYPE_EQUALIZER, - AudioEffect.EFFECT_TYPE_NULL, - 0, - 0); - assertNotNull(msg + ": could not create AudioEffect", effect); - byte[] value = shortToByteArray((short)0); - if (effect.setParameter(Equalizer.PARAM_CURRENT_PRESET, value) - == AudioEffect.SUCCESS) { - result = true; - } - } catch (IllegalArgumentException e) { - msg = msg.concat(": Bad parameter value"); - loge(msg, "Bad parameter value"); - } catch (UnsupportedOperationException e) { - msg = msg.concat(": setParameter() rejected"); - loge(msg, "setParameter() rejected"); - } catch (IllegalStateException e) { - msg = msg.concat("setParameter() called in wrong state"); - loge(msg, "setParameter() called in wrong state"); - } finally { - if (effect != null) { - effect.release(); - } - } - assertTrue(msg, result); - } - - //Test case 3.4: test setParameter(int[], int[]) - @LargeTest - public void test3_4SetParameterIntArrayIntArray() throws Exception { - boolean result = false; - String msg = "test3_4SetParameterIntArrayIntArray()"; - AudioEffect effect = null; - try { - effect = new AudioEffect(AudioEffect.EFFECT_TYPE_ENV_REVERB, - AudioEffect.EFFECT_TYPE_NULL, - 0, - 0); - assertNotNull(msg + ": could not create AudioEffect", effect); - int[] param = new int[1]; - int[] value = new int[1]; - param[0] = EnvironmentalReverb.PARAM_DECAY_TIME; - value[0] = 0; - if (effect.setParameter(param, value) - == AudioEffect.SUCCESS) { - result = true; - } - } catch (IllegalArgumentException e) { - msg = msg.concat(": Bad parameter value"); - loge(msg, "Bad parameter value"); - } catch (UnsupportedOperationException e) { - msg = msg.concat(": setParameter() rejected"); - loge(msg, "setParameter() rejected"); - } catch (IllegalStateException e) { - msg = msg.concat("setParameter() called in wrong state"); - loge(msg, "setParameter() called in wrong state"); - } finally { - if (effect != null) { - effect.release(); - } - } - assertTrue(msg, result); - } - - //Test case 3.5: test setParameter(int[], short[]) - @LargeTest - public void test3_5SetParameterIntArrayShortArray() throws Exception { - boolean result = false; - String msg = "test3_5SetParameterIntArrayShortArray()"; - AudioEffect effect = null; - try { - effect = new AudioEffect(AudioEffect.EFFECT_TYPE_EQUALIZER, - AudioEffect.EFFECT_TYPE_NULL, - 0, - 0); - assertNotNull(msg + ": could not create AudioEffect", effect); - int[] param = new int[1]; - short[] value = new short[1]; - param[0] = Equalizer.PARAM_CURRENT_PRESET; - value[0] = (short)0; - if (effect.setParameter(param, value) - == AudioEffect.SUCCESS) { - result = true; - } - } catch (IllegalArgumentException e) { - msg = msg.concat(": Bad parameter value"); - loge(msg, "Bad parameter value"); - } catch (UnsupportedOperationException e) { - msg = msg.concat(": setParameter() rejected"); - loge(msg, "setParameter() rejected"); - } catch (IllegalStateException e) { - msg = msg.concat("setParameter() called in wrong state"); - loge(msg, "setParameter() called in wrong state"); - } finally { - if (effect != null) { - effect.release(); - } - } - assertTrue(msg, result); - } - - //Test case 3.6: test setParameter(int[], byte[]) - @LargeTest - public void test3_6SetParameterIntArrayByteArray() throws Exception { - boolean result = false; - String msg = "test3_6SetParameterIntArrayByteArray()"; - AudioEffect effect = null; - try { - effect = new AudioEffect(AudioEffect.EFFECT_TYPE_EQUALIZER, - AudioEffect.EFFECT_TYPE_NULL, - 0, - 0); - assertNotNull(msg + ": could not create AudioEffect", effect); - int[] param = new int[1]; - byte[] value = shortToByteArray((short)0); - param[0] = Equalizer.PARAM_CURRENT_PRESET; - if (effect.setParameter(param, value) - == AudioEffect.SUCCESS) { - result = true; - } - } catch (IllegalArgumentException e) { - msg = msg.concat(": Bad parameter value"); - loge(msg, "Bad parameter value"); - } catch (UnsupportedOperationException e) { - msg = msg.concat(": setParameter() rejected"); - loge(msg, "setParameter() rejected"); - } catch (IllegalStateException e) { - msg = msg.concat("setParameter() called in wrong state"); - loge(msg, "setParameter() called in wrong state"); - } finally { - if (effect != null) { - effect.release(); - } - } - assertTrue(msg, result); - } - - //Test case 3.7: test setParameter() throws exception after release() - @LargeTest - public void test3_7SetParameterAfterRelease() throws Exception { - boolean result = false; - String msg = "test3_7SetParameterAfterRelease()"; - AudioEffect effect = null; - try { - effect = new AudioEffect(AudioEffect.EFFECT_TYPE_EQUALIZER, - AudioEffect.EFFECT_TYPE_NULL, - 0, - 0); - assertNotNull(msg + ": could not create AudioEffect", effect); - effect.release(); - effect.setParameter(Equalizer.PARAM_CURRENT_PRESET, (short)0); - } catch (IllegalArgumentException e) { - msg = msg.concat(": Bad parameter value"); - loge(msg, "Bad parameter value"); - } catch (UnsupportedOperationException e) { - msg = msg.concat(": setParameter() rejected"); - loge(msg, "setParameter() rejected"); - } catch (IllegalStateException e) { - result = true; - } finally { - if (effect != null) { - effect.release(); - } - } - assertTrue(msg, result); - } - - //----------------------------------------------------------------- - // 4 - get parameters - //---------------------------------- - - //Test case 4.0: test getParameter(byte[], byte[]) - @LargeTest - public void test4_0GetParameterByteArrayByteArray() throws Exception { - boolean result = false; - String msg = "test4_0GetParameterByteArrayByteArray()"; - AudioEffect effect = null; - try { - effect = new AudioEffect(AudioEffect.EFFECT_TYPE_EQUALIZER, - AudioEffect.EFFECT_TYPE_NULL, - 0, - 0); - assertNotNull(msg + ": could not create AudioEffect", effect); - byte[] param = intToByteArray(Equalizer.PARAM_CURRENT_PRESET); - byte[] value = new byte[2]; - if (!AudioEffect.isError(effect.getParameter(param, value))) { - result = true; - } - } catch (IllegalArgumentException e) { - msg = msg.concat(": Bad parameter value"); - loge(msg, "Bad parameter value"); - } catch (UnsupportedOperationException e) { - msg = msg.concat(": getParameter() rejected"); - loge(msg, "getParameter() rejected"); - } catch (IllegalStateException e) { - msg = msg.concat("getParameter() called in wrong state"); - loge(msg, "getParameter() called in wrong state"); - } finally { - if (effect != null) { - effect.release(); - } - } - assertTrue(msg, result); - } - - //Test case 4.1: test getParameter(int, int[]) - @LargeTest - public void test4_1GetParameterIntIntArray() throws Exception { - boolean result = false; - String msg = "test4_1GetParameterIntIntArray()"; - AudioEffect effect = null; - try { - effect = new AudioEffect(AudioEffect.EFFECT_TYPE_ENV_REVERB, - AudioEffect.EFFECT_TYPE_NULL, - 0, - 0); - assertNotNull(msg + ": could not create AudioEffect", effect); - int[] value = new int[1]; - if (!AudioEffect.isError( - effect.getParameter(EnvironmentalReverb.PARAM_DECAY_TIME, value))) { - result = true; - } - } catch (IllegalArgumentException e) { - msg = msg.concat(": Bad parameter value"); - loge(msg, "Bad parameter value"); - } catch (UnsupportedOperationException e) { - msg = msg.concat(": getParameter() rejected"); - loge(msg, "getParameter() rejected"); - } catch (IllegalStateException e) { - msg = msg.concat("getParameter() called in wrong state"); - loge(msg, "getParameter() called in wrong state"); - } finally { - if (effect != null) { - effect.release(); - } - } - assertTrue(msg, result); - } - - //Test case 4.2: test getParameter(int, short[]) - @LargeTest - public void test4_2GetParameterIntShortArray() throws Exception { - boolean result = false; - String msg = "test4_2GetParameterIntShortArray()"; - AudioEffect effect = null; - try { - effect = new AudioEffect(AudioEffect.EFFECT_TYPE_EQUALIZER, - AudioEffect.EFFECT_TYPE_NULL, - 0, - 0); - assertNotNull(msg + ": could not create AudioEffect", effect); - short[] value = new short[1]; - if (!AudioEffect.isError(effect.getParameter(Equalizer.PARAM_CURRENT_PRESET, value))) { - result = true; - } - } catch (IllegalArgumentException e) { - msg = msg.concat(": Bad parameter value"); - loge(msg, "Bad parameter value"); - } catch (UnsupportedOperationException e) { - msg = msg.concat(": getParameter() rejected"); - loge(msg, "getParameter() rejected"); - } catch (IllegalStateException e) { - msg = msg.concat("getParameter() called in wrong state"); - loge(msg, "getParameter() called in wrong state"); - } finally { - if (effect != null) { - effect.release(); - } - } - assertTrue(msg, result); - } - - //Test case 4.3: test getParameter(int, byte[]) - @LargeTest - public void test4_3GetParameterIntByteArray() throws Exception { - boolean result = false; - String msg = "test4_3GetParameterIntByteArray()"; - AudioEffect effect = null; - try { - effect = new AudioEffect(AudioEffect.EFFECT_TYPE_EQUALIZER, - AudioEffect.EFFECT_TYPE_NULL, - 0, - 0); - assertNotNull(msg + ": could not create AudioEffect", effect); - byte[] value = new byte[2]; - if (!AudioEffect.isError(effect.getParameter(Equalizer.PARAM_CURRENT_PRESET, value))) { - result = true; - } - } catch (IllegalArgumentException e) { - msg = msg.concat(": Bad parameter value"); - loge(msg, "Bad parameter value"); - } catch (UnsupportedOperationException e) { - msg = msg.concat(": getParameter() rejected"); - loge(msg, "getParameter() rejected"); - } catch (IllegalStateException e) { - msg = msg.concat("getParameter() called in wrong state"); - loge(msg, "getParameter() called in wrong state"); - } finally { - if (effect != null) { - effect.release(); - } - } - assertTrue(msg, result); - } - - //Test case 4.4: test getParameter(int[], int[]) - @LargeTest - public void test4_4GetParameterIntArrayIntArray() throws Exception { - boolean result = false; - String msg = "test4_4GetParameterIntArrayIntArray()"; - AudioEffect effect = null; - try { - effect = new AudioEffect(AudioEffect.EFFECT_TYPE_ENV_REVERB, - AudioEffect.EFFECT_TYPE_NULL, - 0, - 0); - assertNotNull(msg + ": could not create AudioEffect", effect); - int[] param = new int[1]; - int[] value = new int[1]; - param[0] = EnvironmentalReverb.PARAM_DECAY_TIME; - if (!AudioEffect.isError(effect.getParameter(param, value))) { - result = true; - } - } catch (IllegalArgumentException e) { - msg = msg.concat(": Bad parameter value"); - loge(msg, "Bad parameter value"); - } catch (UnsupportedOperationException e) { - msg = msg.concat(": getParameter() rejected"); - loge(msg, "getParameter() rejected"); - } catch (IllegalStateException e) { - msg = msg.concat("getParameter() called in wrong state"); - loge(msg, "getParameter() called in wrong state"); - } finally { - if (effect != null) { - effect.release(); - } - } - assertTrue(msg, result); - } - - //Test case 4.5: test getParameter(int[], short[]) - @LargeTest - public void test4_5GetParameterIntArrayShortArray() throws Exception { - boolean result = false; - String msg = "test4_5GetParameterIntArrayShortArray()"; - AudioEffect effect = null; - try { - effect = new AudioEffect(AudioEffect.EFFECT_TYPE_EQUALIZER, - AudioEffect.EFFECT_TYPE_NULL, - 0, - 0); - assertNotNull(msg + ": could not create AudioEffect", effect); - int[] param = new int[1]; - short[] value = new short[1]; - param[0] = Equalizer.PARAM_CURRENT_PRESET; - if (!AudioEffect.isError(effect.getParameter(param, value))) { - result = true; - } - } catch (IllegalArgumentException e) { - msg = msg.concat(": Bad parameter value"); - loge(msg, "Bad parameter value"); - } catch (UnsupportedOperationException e) { - msg = msg.concat(": getParameter() rejected"); - loge(msg, "getParameter() rejected"); - } catch (IllegalStateException e) { - msg = msg.concat("getParameter() called in wrong state"); - loge(msg, "getParameter() called in wrong state"); - } finally { - if (effect != null) { - effect.release(); - } - } - assertTrue(msg, result); - } - - //Test case 4.6: test getParameter(int[], byte[]) - @LargeTest - public void test4_6GetParameterIntArrayByteArray() throws Exception { - boolean result = false; - String msg = "test4_6GetParameterIntArrayByteArray()"; - AudioEffect effect = null; - try { - effect = new AudioEffect(AudioEffect.EFFECT_TYPE_EQUALIZER, - AudioEffect.EFFECT_TYPE_NULL, - 0, - 0); - assertNotNull(msg + ": could not create AudioEffect", effect); - int[] param = new int[1]; - byte[] value = new byte[2]; - param[0] = Equalizer.PARAM_CURRENT_PRESET; - if (!AudioEffect.isError(effect.getParameter(param, value))) { - result = true; - } - } catch (IllegalArgumentException e) { - msg = msg.concat(": Bad parameter value"); - loge(msg, "Bad parameter value"); - } catch (UnsupportedOperationException e) { - msg = msg.concat(": getParameter() rejected"); - loge(msg, "getParameter() rejected"); - } catch (IllegalStateException e) { - msg = msg.concat("getParameter() called in wrong state"); - loge(msg, "getParameter() called in wrong state"); - } finally { - if (effect != null) { - effect.release(); - } - } - assertTrue(msg, result); - } - - //Test case 4.7: test getParameter() throws exception after release() - @LargeTest - public void test4_7GetParameterAfterRelease() throws Exception { - boolean result = false; - String msg = "test4_7GetParameterAfterRelease()"; - AudioEffect effect = null; - try { - effect = new AudioEffect(AudioEffect.EFFECT_TYPE_EQUALIZER, - AudioEffect.EFFECT_TYPE_NULL, - 0, - 0); - assertNotNull(msg + ": could not create AudioEffect", effect); - effect.release(); - short[] value = new short[1]; - effect.getParameter(Equalizer.PARAM_CURRENT_PRESET, value); - } catch (IllegalArgumentException e) { - msg = msg.concat(": Bad parameter value"); - loge(msg, "Bad parameter value"); - } catch (UnsupportedOperationException e) { - msg = msg.concat(": getParameter() rejected"); - loge(msg, "getParameter() rejected"); - } catch (IllegalStateException e) { - result = true; - } finally { - if (effect != null) { - effect.release(); - } - } - assertTrue(msg, result); - } - - //----------------------------------------------------------------- - // 5 priority and listeners - //---------------------------------- - - //Test case 5.0: test control passed to higher priority client - @LargeTest - public void test5_0setEnabledLowerPriority() throws Exception { - boolean result = false; - String msg = "test5_0setEnabledLowerPriority()"; - AudioEffect effect1 = null; - AudioEffect effect2 = null; - try { - effect1 = new AudioEffect(AudioEffect.EFFECT_TYPE_EQUALIZER, - AudioEffect.EFFECT_TYPE_NULL, - 0, - 0); - effect2 = new AudioEffect(AudioEffect.EFFECT_TYPE_EQUALIZER, - AudioEffect.EFFECT_TYPE_NULL, - 1, - 0); - - assertNotNull(msg + ": could not create AudioEffect", effect1); - assertNotNull(msg + ": could not create AudioEffect", effect2); - - assertTrue(msg + ": Effect2 does not have control", effect2.hasControl()); - assertFalse(msg + ": Effect1 has control", effect1.hasControl()); - assertTrue(msg + ": Effect1 can enable", - effect1.setEnabled(true) == AudioEffect.ERROR_INVALID_OPERATION); - assertFalse(msg + ": Effect1 has enabled", effect2.getEnabled()); - result = true; - } catch (IllegalArgumentException e) { - msg = msg.concat(": Effect not found"); - result = false; - } catch (UnsupportedOperationException e) { - msg = msg.concat(": Effect library not loaded"); - result = false; - } finally { - if (effect1 != null) { - effect1.release(); - } - if (effect2 != null) { - effect2.release(); - } - } - assertTrue(msg, result); - } - - //Test case 5.1: test control passed to higher priority client - @LargeTest - public void test5_1setParameterLowerPriority() throws Exception { - boolean result = false; - String msg = "test5_1setParameterLowerPriority()"; - AudioEffect effect1 = null; - AudioEffect effect2 = null; - try { - effect1 = new AudioEffect(AudioEffect.EFFECT_TYPE_EQUALIZER, - AudioEffect.EFFECT_TYPE_NULL, - 0, - 0); - effect2 = new AudioEffect(AudioEffect.EFFECT_TYPE_EQUALIZER, - AudioEffect.EFFECT_TYPE_NULL, - 1, - 0); - - assertNotNull(msg + ": could not create AudioEffect", effect1); - assertNotNull(msg + ": could not create AudioEffect", effect2); - - int status = effect2.setParameter(Equalizer.PARAM_CURRENT_PRESET, (short)0); - assertEquals(msg + ": Effect2 setParameter failed", - AudioEffect.SUCCESS, status); - - status = effect1.setParameter(Equalizer.PARAM_CURRENT_PRESET, (short)1); - assertEquals(msg + ": Effect1 setParameter did not fail", - AudioEffect.ERROR_INVALID_OPERATION, status); - - short[] value = new short[1]; - status = effect2.getParameter(Equalizer.PARAM_CURRENT_PRESET, value); - assertFalse(msg + ": Effect2 getParameter failed", - AudioEffect.isError(status)); - assertEquals(msg + ": Effect1 changed parameter", - (short)0, value[0]); - - result = true; - } catch (IllegalArgumentException e) { - msg = msg.concat(": Effect not found"); - result = false; - } catch (UnsupportedOperationException e) { - msg = msg.concat(": Effect library not loaded"); - result = false; - } finally { - if (effect1 != null) { - effect1.release(); - } - if (effect2 != null) { - effect2.release(); - } - } - assertTrue(msg, result); - } - - //Test case 5.2: test control status listener - @LargeTest - public void test5_2ControlStatusListener() throws Exception { - boolean result = false; - String msg = "test5_2ControlStatusListener()"; - mEffect = null; - AudioEffect effect2 = null; - try { - mHasControl = true; - createListenerLooper(true, false, false); - synchronized(lock) { - try { - lock.wait(1000); - } catch(Exception e) { - Log.e(TAG, "Looper creation: wait was interrupted."); - } - } - assertTrue(mInitialized); - synchronized(lock) { - try { - effect2 = new AudioEffect(AudioEffect.EFFECT_TYPE_EQUALIZER, - AudioEffect.EFFECT_TYPE_NULL, - 1, - 0); - assertNotNull(msg + ": could not create AudioEffect", effect2); - lock.wait(1000); - } catch(Exception e) { - Log.e(TAG, "Create second effect: wait was interrupted."); - } - } - assertFalse(msg + ": effect control not lost by effect1", mHasControl); - result = true; - } catch (IllegalArgumentException e) { - msg = msg.concat(": Equalizer not found"); - loge(msg, ": Equalizer not found"); - } catch (UnsupportedOperationException e) { - msg = msg.concat(": Effect library not loaded"); - loge(msg, ": Effect library not loaded"); - } catch (Exception e){ - loge(msg, "Could not create media player:" + e); - } finally { - terminateListenerLooper(); - if (effect2 != null) { - effect2.release(); - } - } - assertTrue(msg, result); - } - - //Test case 5.3: test enable status listener - @LargeTest - public void test5_3EnableStatusListener() throws Exception { - boolean result = false; - String msg = "test5_3EnableStatusListener()"; - mEffect = null; - AudioEffect effect2 = null; - try { - createListenerLooper(false, true, false); - synchronized(lock) { - try { - lock.wait(1000); - } catch(Exception e) { - Log.e(TAG, "Looper creation: wait was interrupted."); - } - } - assertTrue(mInitialized); - mEffect.setEnabled(true); - mIsEnabled = true; - effect2 = new AudioEffect(AudioEffect.EFFECT_TYPE_EQUALIZER, - AudioEffect.EFFECT_TYPE_NULL, - 1, - 0); - assertNotNull(msg + ": could not create AudioEffect", effect2); - assertTrue(msg + ": effect not enabled", effect2.getEnabled()); - synchronized(lock) { - try { - effect2.setEnabled(false); - lock.wait(1000); - } catch(Exception e) { - Log.e(TAG, "Create second effect: wait was interrupted."); - } - } - assertFalse(msg + ": enable status not updated", mIsEnabled); - result = true; - } catch (IllegalArgumentException e) { - msg = msg.concat(": Equalizer not found"); - loge(msg, ": Equalizer not found"); - } catch (UnsupportedOperationException e) { - msg = msg.concat(": Effect library not loaded"); - loge(msg, ": Effect library not loaded"); - } catch (Exception e){ - loge(msg, "Could not create media player:" + e); - } finally { - terminateListenerLooper(); - if (effect2 != null) { - effect2.release(); - } - } - assertTrue(msg, result); - } - - //Test case 5.4: test parameter changed listener - @LargeTest - public void test5_4ParameterChangedListener() throws Exception { - boolean result = false; - String msg = "test5_4ParameterChangedListener()"; - mEffect = null; - AudioEffect effect2 = null; - try { - createListenerLooper(false, false, true); - synchronized(lock) { - try { - lock.wait(1000); - } catch(Exception e) { - Log.e(TAG, "Looper creation: wait was interrupted."); - } - } - assertTrue(mInitialized); - effect2 = new AudioEffect(AudioEffect.EFFECT_TYPE_EQUALIZER, - AudioEffect.EFFECT_TYPE_NULL, - 1, - 0); - assertNotNull(msg + ": could not create AudioEffect", effect2); - synchronized(lock) { - try { - mParameterChanged = -1; - effect2.setParameter(Equalizer.PARAM_CURRENT_PRESET, (short)0); - lock.wait(1000); - } catch(Exception e) { - Log.e(TAG, "Create second effect: wait was interrupted."); - } - } - assertEquals(msg + ": parameter change not received", - Equalizer.PARAM_CURRENT_PRESET, mParameterChanged); - result = true; - } catch (IllegalArgumentException e) { - msg = msg.concat(": Equalizer not found"); - loge(msg, ": Equalizer not found"); - } catch (UnsupportedOperationException e) { - msg = msg.concat(": Effect library not loaded"); - loge(msg, ": Effect library not loaded"); - } catch (Exception e){ - loge(msg, "Could not create media player:" + e); - } finally { - terminateListenerLooper(); - if (effect2 != null) { - effect2.release(); - } - } - assertTrue(msg, result); - } - - //----------------------------------------------------------------- - // 6 command method - //---------------------------------- - - - //Test case 6.0: test command method - @LargeTest - public void test6_0Command() throws Exception { - boolean result = false; - String msg = "test6_0Command()"; - AudioEffect effect = null; - try { - effect = new AudioEffect(AudioEffect.EFFECT_TYPE_EQUALIZER, - AudioEffect.EFFECT_TYPE_NULL, - 0, - 0); - assertNotNull(msg + ": could not create AudioEffect", effect); - try { - byte[] cmd = new byte[0]; - byte[] reply = new byte[4]; - int status = effect.command(3, cmd, reply); - assertFalse(msg + ": command failed", AudioEffect.isError(status)); - assertTrue(msg + ": effect not enabled", effect.getEnabled()); - result = true; - } catch (IllegalStateException e) { - msg = msg.concat(": command in illegal state"); - } - } catch (IllegalArgumentException e) { - msg = msg.concat(": Equalizer not found"); - loge(msg, ": Equalizer not found"); - } catch (UnsupportedOperationException e) { - msg = msg.concat(": Effect library not loaded"); - loge(msg, ": Effect library not loaded"); - } catch (Exception e){ - loge(msg, "Could not create media player:" + e); - } finally { - if (effect != null) { - effect.release(); - } - } - assertTrue(msg, result); - } - - //----------------------------------------------------------------- - // private methods - //---------------------------------- - - /* - * Initializes the message looper so that the MediaPlayer object can - * receive the callback messages. - */ - private void createMediaPlayerLooper() { - new Thread() { - @Override - public void run() { - // Set up a looper to be used by mMediaPlayer. - Looper.prepare(); - - // Save the looper so that we can terminate this thread - // after we are done with it. - mLooper = Looper.myLooper(); - - mMediaPlayer = new MediaPlayer(); - mMediaPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() { - public boolean onError(MediaPlayer player, int what, int extra) { - synchronized(lock) { - mError = what; - lock.notify(); - } - return true; - } - }); - mMediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { - public void onCompletion(MediaPlayer player) { - synchronized(lock) { - lock.notify(); - } - } - }); - synchronized(lock) { - mInitialized = true; - lock.notify(); - } - Looper.loop(); // Blocks forever until Looper.quit() is called. - } - }.start(); - } - /* - * Terminates the message looper thread. - */ - private void terminateMediaPlayerLooper() { - if (mLooper != null) { - mLooper.quit(); - mLooper = null; - } - if (mMediaPlayer != null) { - mMediaPlayer.release(); - } - } - - /* - * Initializes the message looper fro effect listener - */ - class ListenerThread extends Thread { - boolean mControl; - boolean mEnable; - boolean mParameter; - - public ListenerThread(boolean control, boolean enable, boolean parameter) { - super(); - mControl = control; - mEnable = enable; - mParameter = parameter; - } - } - private void createListenerLooper(boolean control, boolean enable, boolean parameter) { - - new ListenerThread(control, enable, parameter) { - @Override - public void run() { - // Set up a looper to be used by mEffect. - Looper.prepare(); - - // Save the looper so that we can terminate this thread - // after we are done with it. - mLooper = Looper.myLooper(); - - mEffect = new AudioEffect(AudioEffect.EFFECT_TYPE_EQUALIZER, - AudioEffect.EFFECT_TYPE_NULL, - 0, - 0); - assertNotNull("could not create AudioEffect", mEffect); - - if (mControl) { - mEffect.setControlStatusListener(new AudioEffect.OnControlStatusChangeListener() { - public void onControlStatusChange(AudioEffect effect, boolean controlGranted) { - synchronized(lock) { - if (effect == mEffect) { - mHasControl = controlGranted; - lock.notify(); - } - } - } - }); - } - if (mEnable) { - mEffect.setEnableStatusListener(new AudioEffect.OnEnableStatusChangeListener() { - public void onEnableStatusChange(AudioEffect effect, boolean enabled) { - synchronized(lock) { - if (effect == mEffect) { - mIsEnabled = enabled; - lock.notify(); - } - } - } - }); - } - if (mParameter) { - mEffect.setParameterListener(new AudioEffect.OnParameterChangeListener() { - public void onParameterChange(AudioEffect effect, int status, byte[] param, - byte[] value) { - synchronized(lock) { - if (effect == mEffect) { - mParameterChanged = byteArrayToInt(param); - lock.notify(); - } - } - } - }); - } - - synchronized(lock) { - mInitialized = true; - lock.notify(); - } - Looper.loop(); // Blocks forever until Looper.quit() is called. - } - }.start(); - } - /* - * Terminates the listener looper thread. - */ - private void terminateListenerLooper() { - if (mEffect != null) { - mEffect.release(); - mEffect = null; - } - if (mLooper != null) { - mLooper.quit(); - mLooper = null; - } - } - - protected int byteArrayToInt(byte[] valueBuf) { - return byteArrayToInt(valueBuf, 0); - - } - - protected int byteArrayToInt(byte[] valueBuf, int offset) { - ByteBuffer converter = ByteBuffer.wrap(valueBuf); - converter.order(ByteOrder.nativeOrder()); - return converter.getInt(offset); - - } - - protected byte[] intToByteArray(int value) { - ByteBuffer converter = ByteBuffer.allocate(4); - converter.order(ByteOrder.nativeOrder()); - converter.putInt(value); - return converter.array(); - } - - protected short byteArrayToShort(byte[] valueBuf) { - return byteArrayToShort(valueBuf, 0); - } - - protected short byteArrayToShort(byte[] valueBuf, int offset) { - ByteBuffer converter = ByteBuffer.wrap(valueBuf); - converter.order(ByteOrder.nativeOrder()); - return converter.getShort(offset); - - } - - protected byte[] shortToByteArray(short value) { - ByteBuffer converter = ByteBuffer.allocate(2); - converter.order(ByteOrder.nativeOrder()); - short sValue = (short) value; - converter.putShort(sValue); - return converter.array(); - } - -} - diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaAudioManagerTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaAudioManagerTest.java deleted file mode 100644 index 644444a..0000000 --- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaAudioManagerTest.java +++ /dev/null @@ -1,70 +0,0 @@ - /* - * Copyright (C) 2010 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -package com.android.mediaframeworktest.functional; - -import com.android.mediaframeworktest.MediaFrameworkTest; -import android.content.Context; -import android.media.AudioManager; -import android.test.ActivityInstrumentationTestCase2; -import android.test.suitebuilder.annotation.MediumTest; - -/** - * Junit / Instrumentation test case for the media AudioManager api - */ - -public class MediaAudioManagerTest extends ActivityInstrumentationTestCase2 { - - private String TAG = "MediaAudioManagerTest"; - private AudioManager mAudioManager; - private int[] ringtoneMode = {AudioManager.RINGER_MODE_NORMAL, - AudioManager.RINGER_MODE_SILENT, AudioManager.RINGER_MODE_VIBRATE}; - - public MediaAudioManagerTest() { - super("com.android.mediaframeworktest", MediaFrameworkTest.class); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - mAudioManager = (AudioManager) getActivity().getSystemService(Context.AUDIO_SERVICE); - } - - @Override - protected void tearDown() throws Exception { - super.tearDown(); - } - - public boolean validateSetRingTone(int i) { - int getRingtone = mAudioManager.getRingerMode(); - if (i != getRingtone) - return false; - else - return true; - } - - // Test case 1: Simple test case to validate the set ringtone mode - @MediumTest - public void testSetRingtoneMode() throws Exception { - boolean result = false; - - for (int i = 0; i < ringtoneMode.length; i++) { - mAudioManager.setRingerMode(ringtoneMode[i]); - result = validateSetRingTone(ringtoneMode[i]); - assertTrue("SetRingtoneMode : " + ringtoneMode[i], result); - } - } - } \ No newline at end of file diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaAudioTrackTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaAudioTrackTest.java deleted file mode 100644 index cea3a5a..0000000 --- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaAudioTrackTest.java +++ /dev/null @@ -1,1253 +0,0 @@ -/* - * Copyright (C) 2009 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.mediaframeworktest.functional; - -import com.android.mediaframeworktest.MediaFrameworkTest; -import com.android.mediaframeworktest.MediaNames; - -import android.media.AudioFormat; -import android.media.AudioManager; -import android.media.AudioTrack; -import android.test.ActivityInstrumentationTestCase2; -import android.util.Log; -import android.test.suitebuilder.annotation.LargeTest; -import android.test.suitebuilder.annotation.MediumTest; -import android.test.suitebuilder.annotation.Suppress; - -/** - * Junit / Instrumentation test case for the media AudioTrack api - - */ -public class MediaAudioTrackTest extends ActivityInstrumentationTestCase2 { - private String TAG = "MediaAudioTrackTest"; - - public MediaAudioTrackTest() { - super("com.android.mediaframeworktest", MediaFrameworkTest.class); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - } - - @Override - protected void tearDown() throws Exception { - super.tearDown(); - } - - private static void assumeTrue(String message, boolean cond) { - assertTrue("(assume)"+message, cond); - } - - private void log(String testName, String message) { - Log.v(TAG, "["+testName+"] "+message); - } - - private void loge(String testName, String message) { - Log.e(TAG, "["+testName+"] "+message); - } - - //----------------------------------------------------------------- - // private class to hold test reslts - public class TestResults { - public boolean mResult = false; - public String mResultLog = ""; - public TestResults(boolean b, String s) { mResult = b; mResultLog = s; } - } - - //----------------------------------------------------------------- - // generic test methods - public TestResults constructorTestMultiSampleRate( - // parameters tested by this method - int _inTest_streamType, int _inTest_mode, - int _inTest_config, int _inTest_format, - // parameter-dependent expected results - int _expected_stateForMode) { - - int[] testSampleRates = {8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000}; - String failedRates = "Failure for rate(s): "; - boolean localRes, finalRes = true; - - for (int i = 0 ; i < testSampleRates.length ; i++) { - //Log.v("MediaAudioTrackTest", "[ constructorTestMultiSampleRate ] testing "+ testSampleRates[i]); - AudioTrack track = null; - try { - track = new AudioTrack( - _inTest_streamType, - testSampleRates[i], - _inTest_config, - _inTest_format, - AudioTrack.getMinBufferSize(testSampleRates[i], - _inTest_config, _inTest_format), - _inTest_mode); - } catch(IllegalArgumentException iae) { - Log.e("MediaAudioTrackTest", "[ constructorTestMultiSampleRate ] exception at SR " - + testSampleRates[i]+": \n" + iae); - localRes = false; - } - if (track != null) { - localRes = (track.getState() == _expected_stateForMode); - track.release(); - } - else { - localRes = false; - } - - if (!localRes) { - //log the error for the test runner - failedRates += Integer.toString(testSampleRates[i]) + "Hz "; - //log the error for logcat - log("constructorTestMultiSampleRate", "failed to construct " - +"AudioTrack(streamType="+_inTest_streamType - +", sampleRateInHz=" + testSampleRates[i] - +", channelConfig=" + _inTest_config - +", audioFormat=" + _inTest_format - +", bufferSizeInBytes=" + AudioTrack.getMinBufferSize(testSampleRates[i], - _inTest_config, AudioFormat.ENCODING_PCM_16BIT) - +", mode="+ _inTest_mode ); - //mark test as failed - finalRes = false; - } - } - return new TestResults(finalRes, failedRates); - } - - //----------------------------------------------------------------- - // AUDIOTRACK TESTS: - //---------------------------------- - - //----------------------------------------------------------------- - // AudioTrack constructor and AudioTrack.getMinBufferSize(...) for 16bit PCM - //---------------------------------- - - //Test case 1: constructor for streaming AudioTrack, mono, 16bit at misc valid sample rates - @LargeTest - public void testConstructorMono16MusicStream() throws Exception { - - TestResults res = constructorTestMultiSampleRate( - AudioManager.STREAM_MUSIC, AudioTrack.MODE_STREAM, - AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_16BIT, - AudioTrack.STATE_INITIALIZED); - - assertTrue("testConstructorMono16MusicStream: " + res.mResultLog, res.mResult); - } - - - //Test case 2: constructor for streaming AudioTrack, stereo, 16bit at misc valid sample rates - @LargeTest - public void testConstructorStereo16MusicStream() throws Exception { - - TestResults res = constructorTestMultiSampleRate( - AudioManager.STREAM_MUSIC, AudioTrack.MODE_STREAM, - AudioFormat.CHANNEL_OUT_STEREO, AudioFormat.ENCODING_PCM_16BIT, - AudioTrack.STATE_INITIALIZED); - - assertTrue("testConstructorStereo16MusicStream: " + res.mResultLog, res.mResult); - } - - - //Test case 3: constructor for static AudioTrack, mono, 16bit at misc valid sample rates - @LargeTest - public void testConstructorMono16MusicStatic() throws Exception { - - TestResults res = constructorTestMultiSampleRate( - AudioManager.STREAM_MUSIC, AudioTrack.MODE_STATIC, - AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_16BIT, - AudioTrack.STATE_NO_STATIC_DATA); - - assertTrue("testConstructorMono16MusicStatic: " + res.mResultLog, res.mResult); - } - - - //Test case 4: constructor for static AudioTrack, stereo, 16bit at misc valid sample rates - @LargeTest - public void testConstructorStereo16MusicStatic() throws Exception { - - TestResults res = constructorTestMultiSampleRate( - AudioManager.STREAM_MUSIC, AudioTrack.MODE_STATIC, - AudioFormat.CHANNEL_OUT_STEREO, AudioFormat.ENCODING_PCM_16BIT, - AudioTrack.STATE_NO_STATIC_DATA); - - assertTrue("testConstructorStereo16MusicStatic: " + res.mResultLog, res.mResult); - } - - - //----------------------------------------------------------------- - // AudioTrack constructor and AudioTrack.getMinBufferSize(...) for 8bit PCM - //---------------------------------- - - //Test case 1: constructor for streaming AudioTrack, mono, 8bit at misc valid sample rates - @LargeTest - public void testConstructorMono8MusicStream() throws Exception { - - TestResults res = constructorTestMultiSampleRate( - AudioManager.STREAM_MUSIC, AudioTrack.MODE_STREAM, - AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_8BIT, - AudioTrack.STATE_INITIALIZED); - - assertTrue("testConstructorMono8MusicStream: " + res.mResultLog, res.mResult); - } - - //Test case 2: constructor for streaming AudioTrack, stereo, 8bit at misc valid sample rates - @LargeTest - public void testConstructorStereo8MusicStream() throws Exception { - - TestResults res = constructorTestMultiSampleRate( - AudioManager.STREAM_MUSIC, AudioTrack.MODE_STREAM, - AudioFormat.CHANNEL_OUT_STEREO, AudioFormat.ENCODING_PCM_8BIT, - AudioTrack.STATE_INITIALIZED); - - assertTrue("testConstructorStereo8MusicStream: " + res.mResultLog, res.mResult); - } - - //Test case 3: constructor for static AudioTrack, mono, 8bit at misc valid sample rates - @LargeTest - public void testConstructorMono8MusicStatic() throws Exception { - - TestResults res = constructorTestMultiSampleRate( - AudioManager.STREAM_MUSIC, AudioTrack.MODE_STATIC, - AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_8BIT, - AudioTrack.STATE_NO_STATIC_DATA); - - assertTrue("testConstructorMono8MusicStatic: " + res.mResultLog, res.mResult); - } - - //Test case 4: constructor for static AudioTrack, stereo, 8bit at misc valid sample rates - @LargeTest - public void testConstructorStereo8MusicStatic() throws Exception { - - TestResults res = constructorTestMultiSampleRate( - AudioManager.STREAM_MUSIC, AudioTrack.MODE_STATIC, - AudioFormat.CHANNEL_OUT_STEREO, AudioFormat.ENCODING_PCM_8BIT, - AudioTrack.STATE_NO_STATIC_DATA); - - assertTrue("testConstructorStereo8MusicStatic: " + res.mResultLog, res.mResult); - } - - - //----------------------------------------------------------------- - // AudioTrack constructor for all stream types - //---------------------------------- - - //Test case 1: constructor for all stream types - @LargeTest - public void testConstructorStreamType() throws Exception { - // constants for test - final int TYPE_TEST_SR = 22050; - final int TYPE_TEST_CONF = AudioFormat.CHANNEL_OUT_STEREO; - final int TYPE_TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; - final int TYPE_TEST_MODE = AudioTrack.MODE_STREAM; - final int[] STREAM_TYPES = { AudioManager.STREAM_ALARM, AudioManager.STREAM_BLUETOOTH_SCO, - AudioManager.STREAM_MUSIC, AudioManager.STREAM_NOTIFICATION, - AudioManager.STREAM_RING, AudioManager.STREAM_SYSTEM, - AudioManager.STREAM_VOICE_CALL, AudioManager.STREAM_DTMF, }; - final String[] STREAM_NAMES = { "STREAM_ALARM", "STREAM_BLUETOOTH_SCO", "STREAM_MUSIC", - "STREAM_NOTIFICATION", "STREAM_RING", "STREAM_SYSTEM", "STREAM_VOICE_CALL", "STREAM_DTMF" }; - - boolean localTestRes = true; - AudioTrack track = null; - // test: loop constructor on all stream types - for (int i = 0 ; i < STREAM_TYPES.length ; i++) - { - try { - //-------- initialization -------------- - track = new AudioTrack(STREAM_TYPES[i], - TYPE_TEST_SR, TYPE_TEST_CONF, TYPE_TEST_FORMAT, - AudioTrack.getMinBufferSize(TYPE_TEST_SR, TYPE_TEST_CONF, TYPE_TEST_FORMAT), - TYPE_TEST_MODE); - } catch (IllegalArgumentException iae) { - loge("testConstructorStreamType", "exception for stream type " - + STREAM_NAMES[i] + ": "+ iae); - localTestRes = false; - } - //-------- test -------------- - if (track != null) { - if (track.getState() != AudioTrack.STATE_INITIALIZED) { - localTestRes = false; - Log.e("MediaAudioTrackTest", - "[ testConstructorStreamType ] failed for stream type "+STREAM_NAMES[i]); - } - //-------- tear down -------------- - track.release(); - } - else { - localTestRes = false; - } - } - - assertTrue("testConstructorStreamType", localTestRes); - } - - - //----------------------------------------------------------------- - // Playback head position - //---------------------------------- - - //Test case 1: getPlaybackHeadPosition() at 0 after initialization - @LargeTest - public void testPlaybackHeadPositionAfterInit() throws Exception { - // constants for test - final String TEST_NAME = "testPlaybackHeadPositionAfterInit"; - final int TEST_SR = 22050; - final int TEST_CONF = AudioFormat.CHANNEL_OUT_STEREO; - final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; - final int TEST_MODE = AudioTrack.MODE_STREAM; - final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; - - //-------- initialization -------------- - AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, - AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT), TEST_MODE); - //-------- test -------------- - assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED); - assertTrue(TEST_NAME, track.getPlaybackHeadPosition() == 0); - //-------- tear down -------------- - track.release(); - } - - //Test case 2: getPlaybackHeadPosition() increases after play() - @LargeTest - public void testPlaybackHeadPositionIncrease() throws Exception { - // constants for test - final String TEST_NAME = "testPlaybackHeadPositionIncrease"; - final int TEST_SR = 22050; - final int TEST_CONF = AudioFormat.CHANNEL_OUT_STEREO; - final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; - final int TEST_MODE = AudioTrack.MODE_STREAM; - final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; - - //-------- initialization -------------- - int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); - AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, - minBuffSize, TEST_MODE); - byte data[] = new byte[minBuffSize/2]; - //-------- test -------------- - assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED); - track.write(data, 0, data.length); - track.write(data, 0, data.length); - track.play(); - Thread.sleep(100); - log(TEST_NAME, "position ="+ track.getPlaybackHeadPosition()); - assertTrue(TEST_NAME, track.getPlaybackHeadPosition() > 0); - //-------- tear down -------------- - track.release(); - } - - //Test case 3: getPlaybackHeadPosition() is 0 after flush(); - @LargeTest - public void testPlaybackHeadPositionAfterFlush() throws Exception { - // constants for test - final String TEST_NAME = "testPlaybackHeadPositionAfterFlush"; - final int TEST_SR = 22050; - final int TEST_CONF = AudioFormat.CHANNEL_OUT_STEREO; - final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; - final int TEST_MODE = AudioTrack.MODE_STREAM; - final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; - - //-------- initialization -------------- - int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); - AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, - minBuffSize, TEST_MODE); - byte data[] = new byte[minBuffSize/2]; - //-------- test -------------- - assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED); - track.write(data, 0, data.length); - track.write(data, 0, data.length); - track.play(); - Thread.sleep(100); - track.stop(); - track.flush(); - log(TEST_NAME, "position ="+ track.getPlaybackHeadPosition()); - assertTrue(TEST_NAME, track.getPlaybackHeadPosition() == 0); - //-------- tear down -------------- - track.release(); - } - - //Test case 3: getPlaybackHeadPosition() is 0 after stop(); - @LargeTest - public void testPlaybackHeadPositionAfterStop() throws Exception { - // constants for test - final String TEST_NAME = "testPlaybackHeadPositionAfterStop"; - final int TEST_SR = 22050; - final int TEST_CONF = AudioFormat.CHANNEL_OUT_STEREO; - final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; - final int TEST_MODE = AudioTrack.MODE_STREAM; - final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; - - //-------- initialization -------------- - int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); - AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, - minBuffSize, TEST_MODE); - byte data[] = new byte[minBuffSize/2]; - //-------- test -------------- - assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED); - track.write(data, 0, data.length); - track.write(data, 0, data.length); - track.play(); - Thread.sleep(100); - track.stop(); - Thread.sleep(100); // TODO: what is a sensible value? - int pos = track.getPlaybackHeadPosition(); - log(TEST_NAME, "position ="+ pos); - assertTrue(TEST_NAME, pos == 0); - //-------- tear down -------------- - track.release(); - } - - //Test case 4: getPlaybackHeadPosition() is > 0 after play(); pause(); - @LargeTest - public void testPlaybackHeadPositionAfterPause() throws Exception { - // constants for test - final String TEST_NAME = "testPlaybackHeadPositionAfterPause"; - final int TEST_SR = 22050; - final int TEST_CONF = AudioFormat.CHANNEL_OUT_STEREO; - final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; - final int TEST_MODE = AudioTrack.MODE_STREAM; - final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; - - //-------- initialization -------------- - int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); - AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, - minBuffSize, TEST_MODE); - byte data[] = new byte[minBuffSize/2]; - //-------- test -------------- - assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED); - track.write(data, 0, data.length); - track.write(data, 0, data.length); - track.play(); - Thread.sleep(100); - track.pause(); - int pos = track.getPlaybackHeadPosition(); - log(TEST_NAME, "position ="+ pos); - assertTrue(TEST_NAME, pos > 0); - //-------- tear down -------------- - track.release(); - } - - - //----------------------------------------------------------------- - // Playback properties - //---------------------------------- - - //Test case 1: setStereoVolume() with max volume returns SUCCESS - @LargeTest - public void testSetStereoVolumeMax() throws Exception { - // constants for test - final String TEST_NAME = "testSetStereoVolumeMax"; - final int TEST_SR = 22050; - final int TEST_CONF = AudioFormat.CHANNEL_OUT_STEREO; - final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; - final int TEST_MODE = AudioTrack.MODE_STREAM; - final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; - - //-------- initialization -------------- - int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); - AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, - minBuffSize, TEST_MODE); - byte data[] = new byte[minBuffSize/2]; - //-------- test -------------- - track.write(data, 0, data.length); - track.write(data, 0, data.length); - track.play(); - float maxVol = AudioTrack.getMaxVolume(); - assertTrue(TEST_NAME, track.setStereoVolume(maxVol, maxVol) == AudioTrack.SUCCESS); - //-------- tear down -------------- - track.release(); - } - - //Test case 2: setStereoVolume() with min volume returns SUCCESS - @LargeTest - public void testSetStereoVolumeMin() throws Exception { - // constants for test - final String TEST_NAME = "testSetStereoVolumeMin"; - final int TEST_SR = 22050; - final int TEST_CONF = AudioFormat.CHANNEL_OUT_STEREO; - final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; - final int TEST_MODE = AudioTrack.MODE_STREAM; - final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; - - //-------- initialization -------------- - int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); - AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, - minBuffSize, TEST_MODE); - byte data[] = new byte[minBuffSize/2]; - //-------- test -------------- - track.write(data, 0, data.length); - track.write(data, 0, data.length); - track.play(); - float minVol = AudioTrack.getMinVolume(); - assertTrue(TEST_NAME, track.setStereoVolume(minVol, minVol) == AudioTrack.SUCCESS); - //-------- tear down -------------- - track.release(); - } - - //Test case 3: setStereoVolume() with mid volume returns SUCCESS - @LargeTest - public void testSetStereoVolumeMid() throws Exception { - // constants for test - final String TEST_NAME = "testSetStereoVolumeMid"; - final int TEST_SR = 22050; - final int TEST_CONF = AudioFormat.CHANNEL_OUT_STEREO; - final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; - final int TEST_MODE = AudioTrack.MODE_STREAM; - final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; - - //-------- initialization -------------- - int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); - AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, - minBuffSize, TEST_MODE); - byte data[] = new byte[minBuffSize/2]; - //-------- test -------------- - track.write(data, 0, data.length); - track.write(data, 0, data.length); - track.play(); - float midVol = (AudioTrack.getMaxVolume() - AudioTrack.getMinVolume()) / 2; - assertTrue(TEST_NAME, track.setStereoVolume(midVol, midVol) == AudioTrack.SUCCESS); - //-------- tear down -------------- - track.release(); - } - - //Test case 4: setPlaybackRate() with half the content rate returns SUCCESS - @LargeTest - public void testSetPlaybackRate() throws Exception { - // constants for test - final String TEST_NAME = "testSetPlaybackRate"; - final int TEST_SR = 22050; - final int TEST_CONF = AudioFormat.CHANNEL_OUT_STEREO; - final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; - final int TEST_MODE = AudioTrack.MODE_STREAM; - final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; - - //-------- initialization -------------- - int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); - AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, - minBuffSize, TEST_MODE); - byte data[] = new byte[minBuffSize/2]; - //-------- test -------------- - track.write(data, 0, data.length); - track.write(data, 0, data.length); - assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED); - track.play(); - assertTrue(TEST_NAME, track.setPlaybackRate((int)(TEST_SR/2)) == AudioTrack.SUCCESS); - //-------- tear down -------------- - track.release(); - } - - //Test case 5: setPlaybackRate(0) returns bad value error - @LargeTest - public void testSetPlaybackRateZero() throws Exception { - // constants for test - final String TEST_NAME = "testSetPlaybackRateZero"; - final int TEST_SR = 22050; - final int TEST_CONF = AudioFormat.CHANNEL_OUT_STEREO; - final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; - final int TEST_MODE = AudioTrack.MODE_STREAM; - final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; - - //-------- initialization -------------- - int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); - AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, - minBuffSize, TEST_MODE); - //-------- test -------------- - assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED); - assertTrue(TEST_NAME, track.setPlaybackRate(0) == AudioTrack.ERROR_BAD_VALUE); - //-------- tear down -------------- - track.release(); - } - - //Test case 6: setPlaybackRate() accepts values twice the output sample rate - @LargeTest - public void testSetPlaybackRateTwiceOutputSR() throws Exception { - // constants for test - final String TEST_NAME = "testSetPlaybackRateTwiceOutputSR"; - final int TEST_SR = 22050; - final int TEST_CONF = AudioFormat.CHANNEL_OUT_STEREO; - final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; - final int TEST_MODE = AudioTrack.MODE_STREAM; - final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; - - //-------- initialization -------------- - int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); - AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, - minBuffSize, TEST_MODE); - byte data[] = new byte[minBuffSize/2]; - int outputSR = AudioTrack.getNativeOutputSampleRate(TEST_STREAM_TYPE); - //-------- test -------------- - track.write(data, 0, data.length); - track.write(data, 0, data.length); - assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED); - track.play(); - assertTrue(TEST_NAME, track.setPlaybackRate(2*outputSR) == AudioTrack.SUCCESS); - //-------- tear down -------------- - track.release(); - } - - //Test case 7: setPlaybackRate() and retrieve value, should be the same for half the content SR - @LargeTest - public void testSetGetPlaybackRate() throws Exception { - // constants for test - final String TEST_NAME = "testSetGetPlaybackRate"; - final int TEST_SR = 22050; - final int TEST_CONF = AudioFormat.CHANNEL_OUT_STEREO; - final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; - final int TEST_MODE = AudioTrack.MODE_STREAM; - final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; - - //-------- initialization -------------- - int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); - AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, - minBuffSize, TEST_MODE); - byte data[] = new byte[minBuffSize/2]; - //-------- test -------------- - track.write(data, 0, data.length); - track.write(data, 0, data.length); - assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED); - track.play(); - track.setPlaybackRate((int)(TEST_SR/2)); - assertTrue(TEST_NAME, track.getPlaybackRate() == (int)(TEST_SR/2)); - //-------- tear down -------------- - track.release(); - } - - //Test case 8: setPlaybackRate() invalid operation if track not initialized - @LargeTest - public void testSetPlaybackRateUninit() throws Exception { - // constants for test - final String TEST_NAME = "testSetPlaybackRateUninit"; - final int TEST_SR = 22050; - final int TEST_CONF = AudioFormat.CHANNEL_OUT_MONO; - final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; - final int TEST_MODE = AudioTrack.MODE_STATIC; - final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; - - //-------- initialization -------------- - int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); - AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, - minBuffSize, TEST_MODE); - //-------- test -------------- - assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_NO_STATIC_DATA); - assertTrue(TEST_NAME, - track.setPlaybackRate(TEST_SR/2) == AudioTrack.ERROR_INVALID_OPERATION); - //-------- tear down -------------- - track.release(); - } - - //----------------------------------------------------------------- - // Playback progress - //---------------------------------- - - //Test case 1: setPlaybackHeadPosition() on playing track - @LargeTest - public void testSetPlaybackHeadPositionPlaying() throws Exception { - // constants for test - final String TEST_NAME = "testSetPlaybackHeadPositionPlaying"; - final int TEST_SR = 22050; - final int TEST_CONF = AudioFormat.CHANNEL_OUT_MONO; - final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; - final int TEST_MODE = AudioTrack.MODE_STREAM; - final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; - - //-------- initialization -------------- - int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); - AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, - 2*minBuffSize, TEST_MODE); - byte data[] = new byte[minBuffSize]; - //-------- test -------------- - assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED); - track.write(data, 0, data.length); - track.write(data, 0, data.length); - track.play(); - assertTrue(TEST_NAME, - track.setPlaybackHeadPosition(10) == AudioTrack.ERROR_INVALID_OPERATION); - //-------- tear down -------------- - track.release(); - } - - //Test case 2: setPlaybackHeadPosition() on stopped track - @LargeTest - public void testSetPlaybackHeadPositionStopped() throws Exception { - // constants for test - final String TEST_NAME = "testSetPlaybackHeadPositionStopped"; - final int TEST_SR = 22050; - final int TEST_CONF = AudioFormat.CHANNEL_OUT_MONO; - final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; - final int TEST_MODE = AudioTrack.MODE_STREAM; - final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; - - //-------- initialization -------------- - int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); - AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, - 2*minBuffSize, TEST_MODE); - byte data[] = new byte[minBuffSize]; - //-------- test -------------- - assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED); - track.write(data, 0, data.length); - track.write(data, 0, data.length); - track.play(); - track.stop(); - assumeTrue(TEST_NAME, track.getPlayState() == AudioTrack.PLAYSTATE_STOPPED); - assertTrue(TEST_NAME, track.setPlaybackHeadPosition(10) == AudioTrack.SUCCESS); - //-------- tear down -------------- - track.release(); - } - - //Test case 3: setPlaybackHeadPosition() on paused track - @LargeTest - public void testSetPlaybackHeadPositionPaused() throws Exception { - // constants for test - final String TEST_NAME = "testSetPlaybackHeadPositionPaused"; - final int TEST_SR = 22050; - final int TEST_CONF = AudioFormat.CHANNEL_OUT_MONO; - final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; - final int TEST_MODE = AudioTrack.MODE_STREAM; - final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; - - //-------- initialization -------------- - int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); - AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, - 2*minBuffSize, TEST_MODE); - byte data[] = new byte[minBuffSize]; - //-------- test -------------- - assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED); - track.write(data, 0, data.length); - track.write(data, 0, data.length); - track.play(); - track.pause(); - assumeTrue(TEST_NAME, track.getPlayState() == AudioTrack.PLAYSTATE_PAUSED); - assertTrue(TEST_NAME, track.setPlaybackHeadPosition(10) == AudioTrack.SUCCESS); - //-------- tear down -------------- - track.release(); - } - - //Test case 4: setPlaybackHeadPosition() beyond what has been written - @LargeTest - public void testSetPlaybackHeadPositionTooFar() throws Exception { - // constants for test - final String TEST_NAME = "testSetPlaybackHeadPositionTooFar"; - final int TEST_SR = 22050; - final int TEST_CONF = AudioFormat.CHANNEL_OUT_MONO; - final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; - final int TEST_MODE = AudioTrack.MODE_STREAM; - final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; - - //-------- initialization -------------- - int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); - AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, - 2*minBuffSize, TEST_MODE); - byte data[] = new byte[minBuffSize]; - // make up a frame index that's beyond what has been written: go from buffer size to frame - // count (given the audio track properties), and add 77. - int frameIndexTooFar = (2*minBuffSize/2) + 77; - //-------- test -------------- - assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED); - track.write(data, 0, data.length); - track.write(data, 0, data.length); - track.play(); - track.stop(); - assumeTrue(TEST_NAME, track.getPlayState() == AudioTrack.PLAYSTATE_STOPPED); - assertTrue(TEST_NAME, track.setPlaybackHeadPosition(frameIndexTooFar) == AudioTrack.ERROR_BAD_VALUE); - //-------- tear down -------------- - track.release(); - } - - - //Test case 5: setLoopPoints() fails for MODE_STREAM - @LargeTest - public void testSetLoopPointsStream() throws Exception { - // constants for test - final String TEST_NAME = "testSetLoopPointsStream"; - final int TEST_SR = 22050; - final int TEST_CONF = AudioFormat.CHANNEL_OUT_MONO; - final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; - final int TEST_MODE = AudioTrack.MODE_STREAM; - final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; - - //-------- initialization -------------- - int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); - AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, - 2*minBuffSize, TEST_MODE); - byte data[] = new byte[minBuffSize]; - //-------- test -------------- - track.write(data, 0, data.length); - assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED); - assertTrue(TEST_NAME, track.setLoopPoints(2, 50, 2) == AudioTrack.ERROR_INVALID_OPERATION); - //-------- tear down -------------- - track.release(); - } - - //Test case 6: setLoopPoints() fails start > end - @LargeTest - public void testSetLoopPointsStartAfterEnd() throws Exception { - // constants for test - final String TEST_NAME = "testSetLoopPointsStartAfterEnd"; - final int TEST_SR = 22050; - final int TEST_CONF = AudioFormat.CHANNEL_OUT_MONO; - final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; - final int TEST_MODE = AudioTrack.MODE_STATIC; - final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; - - //-------- initialization -------------- - int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); - AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, - minBuffSize, TEST_MODE); - byte data[] = new byte[minBuffSize]; - //-------- test -------------- - track.write(data, 0, data.length); - assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED); - assertTrue(TEST_NAME, track.setLoopPoints(50, 0, 2) == AudioTrack.ERROR_BAD_VALUE); - //-------- tear down -------------- - track.release(); - } - - //Test case 6: setLoopPoints() success - @LargeTest - public void testSetLoopPointsSuccess() throws Exception { - // constants for test - final String TEST_NAME = "testSetLoopPointsSuccess"; - final int TEST_SR = 22050; - final int TEST_CONF = AudioFormat.CHANNEL_OUT_MONO; - final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; - final int TEST_MODE = AudioTrack.MODE_STATIC; - final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; - - //-------- initialization -------------- - int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); - AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, - minBuffSize, TEST_MODE); - byte data[] = new byte[minBuffSize]; - //-------- test -------------- - track.write(data, 0, data.length); - assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED); - assertTrue(TEST_NAME, track.setLoopPoints(0, 50, 2) == AudioTrack.SUCCESS); - //-------- tear down -------------- - track.release(); - } - - //Test case 7: setLoopPoints() fails with loop length bigger than content - @LargeTest - public void testSetLoopPointsLoopTooLong() throws Exception { - // constants for test - final String TEST_NAME = "testSetLoopPointsLoopTooLong"; - final int TEST_SR = 22050; - final int TEST_CONF = AudioFormat.CHANNEL_OUT_MONO; - final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; - final int TEST_MODE = AudioTrack.MODE_STATIC; - final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; - - //-------- initialization -------------- - int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); - AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, - minBuffSize, TEST_MODE); - byte data[] = new byte[minBuffSize]; - int dataSizeInFrames = minBuffSize/2; - //-------- test -------------- - assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_NO_STATIC_DATA); - track.write(data, 0, data.length); - assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED); - assertTrue(TEST_NAME, - track.setLoopPoints(10, dataSizeInFrames+20, 2) == AudioTrack.ERROR_BAD_VALUE); - //-------- tear down -------------- - track.release(); - } - //Test case 8: setLoopPoints() fails with start beyond what can be written for the track - @LargeTest - public void testSetLoopPointsStartTooFar() throws Exception { - // constants for test - final String TEST_NAME = "testSetLoopPointsStartTooFar"; - final int TEST_SR = 22050; - final int TEST_CONF = AudioFormat.CHANNEL_OUT_MONO; - final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; - final int TEST_MODE = AudioTrack.MODE_STATIC; - final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; - - //-------- initialization -------------- - int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); - AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, - minBuffSize, TEST_MODE); - byte data[] = new byte[minBuffSize]; - int dataSizeInFrames = minBuffSize/2;//16bit data - //-------- test -------------- - assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_NO_STATIC_DATA); - track.write(data, 0, data.length); - assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED); - assertTrue(TEST_NAME, - track.setLoopPoints(dataSizeInFrames+20, dataSizeInFrames+50, 2) - == AudioTrack.ERROR_BAD_VALUE); - //-------- tear down -------------- - track.release(); - } - - //Test case 9: setLoopPoints() fails with end beyond what can be written for the track - @LargeTest - public void testSetLoopPointsEndTooFar() throws Exception { - // constants for test - final String TEST_NAME = "testSetLoopPointsEndTooFar"; - final int TEST_SR = 22050; - final int TEST_CONF = AudioFormat.CHANNEL_OUT_MONO; - final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; - final int TEST_MODE = AudioTrack.MODE_STATIC; - final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; - - //-------- initialization -------------- - int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); - AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, - minBuffSize, TEST_MODE); - byte data[] = new byte[minBuffSize]; - int dataSizeInFrames = minBuffSize/2;//16bit data - //-------- test -------------- - assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_NO_STATIC_DATA); - track.write(data, 0, data.length); - assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED); - assertTrue(TEST_NAME, - track.setLoopPoints(dataSizeInFrames-10, dataSizeInFrames+50, 2) - == AudioTrack.ERROR_BAD_VALUE); - //-------- tear down -------------- - track.release(); - } - - - //----------------------------------------------------------------- - // Audio data supply - //---------------------------------- - - //Test case 1: write() fails when supplying less data (bytes) than declared - @LargeTest - public void testWriteByteOffsetTooBig() throws Exception { - // constants for test - final String TEST_NAME = "testWriteByteOffsetTooBig"; - final int TEST_SR = 22050; - final int TEST_CONF = AudioFormat.CHANNEL_OUT_MONO; - final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; - final int TEST_MODE = AudioTrack.MODE_STREAM; - final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; - - //-------- initialization -------------- - int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); - AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, - 2*minBuffSize, TEST_MODE); - byte data[] = new byte[minBuffSize]; - //-------- test -------------- - assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED); - assertTrue(TEST_NAME, - track.write(data, 10, data.length) == AudioTrack.ERROR_BAD_VALUE); - //-------- tear down -------------- - track.release(); - } - - //Test case 2: write() fails when supplying less data (shorts) than declared - @LargeTest - public void testWriteShortOffsetTooBig() throws Exception { - // constants for test - final String TEST_NAME = "testWriteShortOffsetTooBig"; - final int TEST_SR = 22050; - final int TEST_CONF = AudioFormat.CHANNEL_OUT_MONO; - final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; - final int TEST_MODE = AudioTrack.MODE_STREAM; - final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; - - //-------- initialization -------------- - int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); - AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, - 2*minBuffSize, TEST_MODE); - short data[] = new short[minBuffSize/2]; - //-------- test -------------- - assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED); - assertTrue(TEST_NAME, - track.write(data, 10, data.length) == AudioTrack.ERROR_BAD_VALUE); - //-------- tear down -------------- - track.release(); - } - - //Test case 3: write() fails when supplying less data (bytes) than declared - @LargeTest - public void testWriteByteSizeTooBig() throws Exception { - // constants for test - final String TEST_NAME = "testWriteByteSizeTooBig"; - final int TEST_SR = 22050; - final int TEST_CONF = AudioFormat.CHANNEL_OUT_MONO; - final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; - final int TEST_MODE = AudioTrack.MODE_STREAM; - final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; - - //-------- initialization -------------- - int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); - AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, - 2*minBuffSize, TEST_MODE); - byte data[] = new byte[minBuffSize]; - //-------- test -------------- - assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED); - assertTrue(TEST_NAME, - track.write(data, 0, data.length + 10) == AudioTrack.ERROR_BAD_VALUE); - //-------- tear down -------------- - track.release(); - } - - //Test case 4: write() fails when supplying less data (shorts) than declared - @LargeTest - public void testWriteShortSizeTooBig() throws Exception { - // constants for test - final String TEST_NAME = "testWriteShortSizeTooBig"; - final int TEST_SR = 22050; - final int TEST_CONF = AudioFormat.CHANNEL_OUT_MONO; - final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; - final int TEST_MODE = AudioTrack.MODE_STREAM; - final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; - - //-------- initialization -------------- - int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); - AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, - 2*minBuffSize, TEST_MODE); - short data[] = new short[minBuffSize/2]; - //-------- test -------------- - assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED); - assertTrue(TEST_NAME, - track.write(data, 0, data.length + 10) == AudioTrack.ERROR_BAD_VALUE); - //-------- tear down -------------- - track.release(); - } - - //Test case 5: write() fails with negative offset - @LargeTest - public void testWriteByteNegativeOffset() throws Exception { - // constants for test - final String TEST_NAME = "testWriteByteNegativeOffset"; - final int TEST_SR = 22050; - final int TEST_CONF = AudioFormat.CHANNEL_OUT_MONO; - final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; - final int TEST_MODE = AudioTrack.MODE_STREAM; - final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; - - //-------- initialization -------------- - int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); - AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, - 2*minBuffSize, TEST_MODE); - byte data[] = new byte[minBuffSize]; - //-------- test -------------- - assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED); - assertTrue(TEST_NAME, - track.write(data, -10, data.length - 10) == AudioTrack.ERROR_BAD_VALUE); - //-------- tear down -------------- - track.release(); - } - - //Test case 6: write() fails with negative offset - @LargeTest - public void testWriteShortNegativeOffset() throws Exception { - // constants for test - final String TEST_NAME = "testWriteShortNegativeOffset"; - final int TEST_SR = 22050; - final int TEST_CONF = AudioFormat.CHANNEL_OUT_MONO; - final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; - final int TEST_MODE = AudioTrack.MODE_STREAM; - final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; - - //-------- initialization -------------- - int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); - AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, - 2*minBuffSize, TEST_MODE); - short data[] = new short[minBuffSize/2]; - //-------- test -------------- - assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED); - assertTrue(TEST_NAME, - track.write(data, -10, data.length - 10) == AudioTrack.ERROR_BAD_VALUE); - //-------- tear down -------------- - track.release(); - } - - //Test case 7: write() fails with negative size - @LargeTest - public void testWriteByteNegativeSize() throws Exception { - // constants for test - final String TEST_NAME = "testWriteByteNegativeSize"; - final int TEST_SR = 22050; - final int TEST_CONF = AudioFormat.CHANNEL_OUT_MONO; - final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; - final int TEST_MODE = AudioTrack.MODE_STREAM; - final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; - - //-------- initialization -------------- - int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); - AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, - 2*minBuffSize, TEST_MODE); - byte data[] = new byte[minBuffSize]; - //-------- test -------------- - assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED); - assertTrue(TEST_NAME, - track.write(data, 0, -10) == AudioTrack.ERROR_BAD_VALUE); - //-------- tear down -------------- - track.release(); - } - - //Test case 8: write() fails with negative size - @LargeTest - public void testWriteShortNegativeSize() throws Exception { - // constants for test - final String TEST_NAME = "testWriteShortNegativeSize"; - final int TEST_SR = 22050; - final int TEST_CONF = AudioFormat.CHANNEL_OUT_MONO; - final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; - final int TEST_MODE = AudioTrack.MODE_STREAM; - final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; - - //-------- initialization -------------- - int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); - AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, - 2*minBuffSize, TEST_MODE); - short data[] = new short[minBuffSize/2]; - //-------- test -------------- - assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED); - assertTrue(TEST_NAME, - track.write(data, 0, -10) == AudioTrack.ERROR_BAD_VALUE); - //-------- tear down -------------- - track.release(); - } - - //Test case 9: write() succeeds and returns the size that was written for 16bit - @LargeTest - public void testWriteByte() throws Exception { - // constants for test - final String TEST_NAME = "testWriteByte"; - final int TEST_SR = 22050; - final int TEST_CONF = AudioFormat.CHANNEL_OUT_MONO; - final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; - final int TEST_MODE = AudioTrack.MODE_STREAM; - final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; - - //-------- initialization -------------- - int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); - AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, - 2*minBuffSize, TEST_MODE); - byte data[] = new byte[minBuffSize]; - //-------- test -------------- - assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED); - assertTrue(TEST_NAME, - track.write(data, 0, data.length) == data.length); - //-------- tear down -------------- - track.release(); - } - - //Test case 10: write() succeeds and returns the size that was written for 16bit - @LargeTest - public void testWriteShort() throws Exception { - // constants for test - final String TEST_NAME = "testWriteShort"; - final int TEST_SR = 22050; - final int TEST_CONF = AudioFormat.CHANNEL_OUT_MONO; - final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; - final int TEST_MODE = AudioTrack.MODE_STREAM; - final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; - - //-------- initialization -------------- - int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); - AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, - 2*minBuffSize, TEST_MODE); - short data[] = new short[minBuffSize/2]; - //-------- test -------------- - assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED); - assertTrue(TEST_NAME, - track.write(data, 0, data.length) == data.length); - //-------- tear down -------------- - track.release(); - } - - //Test case 11: write() succeeds and returns the size that was written for 8bit - @LargeTest - public void testWriteByte8bit() throws Exception { - // constants for test - final String TEST_NAME = "testWriteByte8bit"; - final int TEST_SR = 22050; - final int TEST_CONF = AudioFormat.CHANNEL_OUT_MONO; - final int TEST_FORMAT = AudioFormat.ENCODING_PCM_8BIT; - final int TEST_MODE = AudioTrack.MODE_STREAM; - final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; - - //-------- initialization -------------- - int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); - AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, - 2*minBuffSize, TEST_MODE); - byte data[] = new byte[minBuffSize]; - //-------- test -------------- - assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED); - assertTrue(TEST_NAME, - track.write(data, 0, data.length) == data.length); - //-------- tear down -------------- - track.release(); - } - - //Test case 12: write() succeeds and returns the size that was written for 8bit - @LargeTest - public void testWriteShort8bit() throws Exception { - // constants for test - final String TEST_NAME = "testWriteShort8bit"; - final int TEST_SR = 22050; - final int TEST_CONF = AudioFormat.CHANNEL_OUT_MONO; - final int TEST_FORMAT = AudioFormat.ENCODING_PCM_8BIT; - final int TEST_MODE = AudioTrack.MODE_STREAM; - final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; - - //-------- initialization -------------- - int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); - AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, - 2*minBuffSize, TEST_MODE); - short data[] = new short[minBuffSize/2]; - //-------- test -------------- - assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED); - assertTrue(TEST_NAME, - track.write(data, 0, data.length) == data.length); - //-------- tear down -------------- - track.release(); - } - - //----------------------------------------------------------------- - // Getters - //---------------------------------- - - //Test case 1: getMinBufferSize() return ERROR_BAD_VALUE if SR < 4000 - @LargeTest - public void testGetMinBufferSizeTooLowSR() throws Exception { - // constant for test - final String TEST_NAME = "testGetMinBufferSizeTooLowSR"; - final int TEST_SR = 3999; - final int TEST_CONF = AudioFormat.CHANNEL_OUT_MONO; - final int TEST_FORMAT = AudioFormat.ENCODING_PCM_8BIT; - final int TEST_MODE = AudioTrack.MODE_STREAM; - final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; - - //-------- initialization & test -------------- - assertTrue(TEST_NAME, - AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT) - == AudioTrack.ERROR_BAD_VALUE); - } - - //Test case 2: getMinBufferSize() return ERROR_BAD_VALUE if SR > 48000 - @LargeTest - public void testGetMinBufferSizeTooHighSR() throws Exception { - // constant for testg - final String TEST_NAME = "testGetMinBufferSizeTooHighSR"; - final int TEST_SR = 48001; - final int TEST_CONF = AudioFormat.CHANNEL_OUT_MONO; - final int TEST_FORMAT = AudioFormat.ENCODING_PCM_8BIT; - final int TEST_MODE = AudioTrack.MODE_STREAM; - final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; - - //-------- initialization & test -------------- - assertTrue(TEST_NAME, - AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT) - == AudioTrack.ERROR_BAD_VALUE); - } - -} - diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaBassBoostTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaBassBoostTest.java deleted file mode 100644 index aa5c4d7..0000000 --- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaBassBoostTest.java +++ /dev/null @@ -1,289 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.mediaframeworktest.functional; - -import com.android.mediaframeworktest.MediaFrameworkTest; -import com.android.mediaframeworktest.MediaNames; -import android.content.Context; -import android.content.res.AssetFileDescriptor; -import android.media.audiofx.AudioEffect; -import android.media.AudioManager; -import android.media.audiofx.BassBoost; -import android.media.audiofx.Visualizer; -import android.media.MediaPlayer; - -import android.os.Looper; -import android.test.suitebuilder.annotation.LargeTest; -import android.test.suitebuilder.annotation.MediumTest; -import android.test.suitebuilder.annotation.Suppress; -import android.test.ActivityInstrumentationTestCase2; -import android.util.Log; - -import java.nio.ByteOrder; -import java.nio.ByteBuffer; -import java.util.UUID; - -/** - * Junit / Instrumentation test case for the media AudioTrack api - - */ -public class MediaBassBoostTest extends ActivityInstrumentationTestCase2 { - private String TAG = "MediaBassBoostTest"; - private final static int MIN_ENERGY_RATIO_2 = 3; - private final static short TEST_STRENGTH = 500; - private final static int TEST_VOLUME = 4; - - private BassBoost mBassBoost = null; - private int mSession = -1; - - public MediaBassBoostTest() { - super("com.android.mediaframeworktest", MediaFrameworkTest.class); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - } - - @Override - protected void tearDown() throws Exception { - super.tearDown(); - releaseBassBoost(); - } - - private static void assumeTrue(String message, boolean cond) { - assertTrue("(assume)"+message, cond); - } - - private void log(String testName, String message) { - Log.v(TAG, "["+testName+"] "+message); - } - - private void loge(String testName, String message) { - Log.e(TAG, "["+testName+"] "+message); - } - - //----------------------------------------------------------------- - // BASS BOOST TESTS: - //---------------------------------- - - - //----------------------------------------------------------------- - // 0 - constructor - //---------------------------------- - - //Test case 0.0: test constructor and release - @LargeTest - public void test0_0ConstructorAndRelease() throws Exception { - boolean result = false; - String msg = "test1_0ConstructorAndRelease()"; - BassBoost bb = null; - try { - bb = new BassBoost(0, 0); - assertNotNull(msg + ": could not create BassBoost", bb); - try { - assertTrue(msg +": invalid effect ID", (bb.getId() != 0)); - } catch (IllegalStateException e) { - msg = msg.concat(": BassBoost not initialized"); - } - result = true; - } catch (IllegalArgumentException e) { - msg = msg.concat(": BassBoost not found"); - } catch (UnsupportedOperationException e) { - msg = msg.concat(": Effect library not loaded"); - } finally { - if (bb != null) { - bb.release(); - } - } - assertTrue(msg, result); - } - - //----------------------------------------------------------------- - // 1 - get/set parameters - //---------------------------------- - - //Test case 1.0: test strength - @LargeTest - public void test1_0Strength() throws Exception { - boolean result = false; - String msg = "test1_0Strength()"; - getBassBoost(0); - try { - if (mBassBoost.getStrengthSupported()) { - mBassBoost.setStrength((short)TEST_STRENGTH); - short strength = mBassBoost.getRoundedStrength(); - // allow 10% difference between set strength and rounded strength - assertTrue(msg +": got incorrect strength", - ((float)strength > (float)TEST_STRENGTH * 0.9f) && - ((float)strength < (float)TEST_STRENGTH * 1.1f)); - } else { - short strength = mBassBoost.getRoundedStrength(); - assertTrue(msg +": got incorrect strength", strength >= 0 && strength <= 1000); - } - result = true; - } catch (IllegalArgumentException e) { - msg = msg.concat(": Bad parameter value"); - loge(msg, "Bad parameter value"); - } catch (UnsupportedOperationException e) { - msg = msg.concat(": get parameter() rejected"); - loge(msg, "get parameter() rejected"); - } catch (IllegalStateException e) { - msg = msg.concat("get parameter() called in wrong state"); - loge(msg, "get parameter() called in wrong state"); - } finally { - releaseBassBoost(); - } - assertTrue(msg, result); - } - - //Test case 1.1: test properties - @LargeTest - public void test1_1Properties() throws Exception { - boolean result = false; - String msg = "test1_1Properties()"; - getBassBoost(0); - try { - BassBoost.Settings settings = mBassBoost.getProperties(); - String str = settings.toString(); - settings = new BassBoost.Settings(str); - mBassBoost.setProperties(settings); - result = true; - } catch (IllegalArgumentException e) { - msg = msg.concat(": Bad parameter value"); - loge(msg, "Bad parameter value"); - } catch (UnsupportedOperationException e) { - msg = msg.concat(": get parameter() rejected"); - loge(msg, "get parameter() rejected"); - } catch (IllegalStateException e) { - msg = msg.concat("get parameter() called in wrong state"); - loge(msg, "get parameter() called in wrong state"); - } finally { - releaseBassBoost(); - } - assertTrue(msg, result); - } - - //----------------------------------------------------------------- - // 2 - Effect action - //---------------------------------- - - //Test case 2.0: test actual bass boost influence on sound - @LargeTest - public void test2_0SoundModification() throws Exception { - boolean result = false; - String msg = "test2_0SoundModification()"; - EnergyProbe probe = null; - AudioEffect vc = null; - MediaPlayer mp = null; - AudioManager am = (AudioManager) getActivity().getSystemService(Context.AUDIO_SERVICE); - int volume = am.getStreamMaxVolume(AudioManager.STREAM_MUSIC); - am.setStreamVolume(AudioManager.STREAM_MUSIC, - TEST_VOLUME, - 0); - - try { - probe = new EnergyProbe(0); - // 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, - UUID.fromString("119341a0-8469-11df-81f9-0002a5d5c51b"), - 0, - 0); - vc.setEnabled(true); - - mp = new MediaPlayer(); - mp.setDataSource(MediaNames.SINE_200_1000); - mp.setAudioStreamType(AudioManager.STREAM_MUSIC); - getBassBoost(mp.getAudioSessionId()); - mp.prepare(); - mp.start(); - Thread.sleep(200); - // measure reference energy around 1kHz - int refEnergy200 = probe.capture(200); - int refEnergy1000 = probe.capture(1000); - mBassBoost.setStrength((short)1000); - mBassBoost.setEnabled(true); - Thread.sleep(500); - // measure energy around 1kHz with band level at min - int energy200 = probe.capture(200); - int energy1000 = probe.capture(1000); - // verify that the energy ration between low and high frequencies is at least - // MIN_ENERGY_RATIO_2 times higher with bassboost on. - assertTrue(msg + ": bass boost has no effect", - ((float)energy200/(float)energy1000) > - (MIN_ENERGY_RATIO_2 * ((float)refEnergy200/(float)refEnergy1000))); - result = true; - } catch (IllegalArgumentException e) { - msg = msg.concat(": Bad parameter value"); - loge(msg, "Bad parameter value"); - } catch (UnsupportedOperationException e) { - msg = msg.concat(": get parameter() rejected"); - loge(msg, "get parameter() rejected"); - } catch (IllegalStateException e) { - msg = msg.concat("get parameter() called in wrong state"); - loge(msg, "get parameter() called in wrong state"); - } catch (InterruptedException e) { - loge(msg, "sleep() interrupted"); - } - finally { - releaseBassBoost(); - if (mp != null) { - mp.release(); - } - if (vc != null) { - vc.release(); - } - if (probe != null) { - probe.release(); - } - am.setStreamVolume(AudioManager.STREAM_MUSIC, volume, 0); - } - assertTrue(msg, result); - } - //----------------------------------------------------------------- - // private methods - //---------------------------------- - - private void getBassBoost(int session) { - if (mBassBoost == null || session != mSession) { - if (session != mSession && mBassBoost != null) { - mBassBoost.release(); - mBassBoost = null; - } - try { - mBassBoost = new BassBoost(0, session); - mSession = session; - } catch (IllegalArgumentException e) { - Log.e(TAG, "getBassBoost() BassBoost not found exception: "+e); - } catch (UnsupportedOperationException e) { - Log.e(TAG, "getBassBoost() Effect library not loaded exception: "+e); - } - } - assertNotNull("could not create mBassBoost", mBassBoost); - } - - private void releaseBassBoost() { - if (mBassBoost != null) { - mBassBoost.release(); - mBassBoost = null; - } - } - -} - diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaEnvReverbTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaEnvReverbTest.java deleted file mode 100644 index ba202a7..0000000 --- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaEnvReverbTest.java +++ /dev/null @@ -1,523 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.mediaframeworktest.functional; - -import com.android.mediaframeworktest.MediaFrameworkTest; -import com.android.mediaframeworktest.MediaNames; -import android.content.Context; -import android.content.res.AssetFileDescriptor; -import android.media.audiofx.AudioEffect; -import android.media.AudioManager; -import android.media.audiofx.EnvironmentalReverb; -import android.media.audiofx.Visualizer; -import android.media.MediaPlayer; - -import android.os.Looper; -import android.test.suitebuilder.annotation.LargeTest; -import android.test.suitebuilder.annotation.MediumTest; -import android.test.suitebuilder.annotation.Suppress; -import android.test.ActivityInstrumentationTestCase2; -import android.util.Log; - -import java.nio.ByteOrder; -import java.nio.ByteBuffer; -import java.util.UUID; - -/** - * Junit / Instrumentation test case for the media AudioTrack api - - */ -public class MediaEnvReverbTest extends ActivityInstrumentationTestCase2 { - private String TAG = "MediaEnvReverbTest"; - // allow +/- 100 millibel difference between set and get gains - private final static int MILLIBEL_TOLERANCE = 100; - // allow +/- 5% tolerance between set and get delays - private final static float DELAY_TOLERANCE = 1.05f; - // allow +/- 5% tolerance between set and get ratios - private final static float RATIO_TOLERANCE = 1.05f; - - private EnvironmentalReverb mReverb = null; - private int mSession = -1; - - public MediaEnvReverbTest() { - super("com.android.mediaframeworktest", MediaFrameworkTest.class); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - } - - @Override - protected void tearDown() throws Exception { - super.tearDown(); - releaseReverb(); - } - - private static void assumeTrue(String message, boolean cond) { - assertTrue("(assume)"+message, cond); - } - - private void log(String testName, String message) { - Log.v(TAG, "["+testName+"] "+message); - } - - private void loge(String testName, String message) { - Log.e(TAG, "["+testName+"] "+message); - } - - //----------------------------------------------------------------- - // ENVIRONMENTAL REVEB TESTS: - //---------------------------------- - - - //----------------------------------------------------------------- - // 0 - constructor - //---------------------------------- - - //Test case 0.0: test constructor and release - @LargeTest - public void test0_0ConstructorAndRelease() throws Exception { - boolean result = false; - String msg = "test1_0ConstructorAndRelease()"; - EnvironmentalReverb reverb = null; - try { - reverb = new EnvironmentalReverb(0, 0); - assertNotNull(msg + ": could not create EnvironmentalReverb", reverb); - try { - assertTrue(msg +": invalid effect ID", (reverb.getId() != 0)); - } catch (IllegalStateException e) { - msg = msg.concat(": EnvironmentalReverb not initialized"); - } - result = true; - } catch (IllegalArgumentException e) { - msg = msg.concat(": EnvironmentalReverb not found"); - } catch (UnsupportedOperationException e) { - msg = msg.concat(": Effect library not loaded"); - } finally { - if (reverb != null) { - reverb.release(); - } - } - assertTrue(msg, result); - } - - //----------------------------------------------------------------- - // 1 - get/set parameters - //---------------------------------- - - //Test case 1.0: test room level and room HF level - @LargeTest - public void test1_0Room() throws Exception { - boolean result = false; - String msg = "test1_0Room()"; - getReverb(0); - try { - mReverb.setRoomLevel((short)0); - short level = mReverb.getRoomLevel(); - assertTrue(msg +": got incorrect room level", - (level > (0 - MILLIBEL_TOLERANCE)) && - (level < (0 + MILLIBEL_TOLERANCE))); - - mReverb.setRoomHFLevel((short)-6); - level = mReverb.getRoomHFLevel(); - assertTrue(msg +": got incorrect room HF level", - (level > (-6 - MILLIBEL_TOLERANCE)) && - (level < (-6 + MILLIBEL_TOLERANCE))); - - result = true; - } catch (IllegalArgumentException e) { - msg = msg.concat(": Bad parameter value"); - loge(msg, "Bad parameter value"); - } catch (UnsupportedOperationException e) { - msg = msg.concat(": get parameter() rejected"); - loge(msg, "get parameter() rejected"); - } catch (IllegalStateException e) { - msg = msg.concat("get parameter() called in wrong state"); - loge(msg, "get parameter() called in wrong state"); - } finally { - releaseReverb(); - } - assertTrue(msg, result); - } - - //Test case 1.1: test decay time and ratio - @LargeTest - public void test1_1Decay() throws Exception { - boolean result = false; - String msg = "test1_1Decay()"; - getReverb(0); - try { - mReverb.setDecayTime(500); - int time = mReverb.getDecayTime(); - assertTrue(msg +": got incorrect decay time", - ((float)time > (float)(500 / DELAY_TOLERANCE)) && - ((float)time < (float)(500 * DELAY_TOLERANCE))); - - mReverb.setDecayHFRatio((short)1000); - short ratio = mReverb.getDecayHFRatio(); - assertTrue(msg +": got incorrect decay HF ratio", - ((float)ratio > (float)(1000 / RATIO_TOLERANCE)) && - ((float)ratio < (float)(1000 * RATIO_TOLERANCE))); - - result = true; - } catch (IllegalArgumentException e) { - msg = msg.concat(": Bad parameter value"); - loge(msg, "Bad parameter value"); - } catch (UnsupportedOperationException e) { - msg = msg.concat(": get parameter() rejected"); - loge(msg, "get parameter() rejected"); - } catch (IllegalStateException e) { - msg = msg.concat("get parameter() called in wrong state"); - loge(msg, "get parameter() called in wrong state"); - } finally { - releaseReverb(); - } - assertTrue(msg, result); - } - - //Test case 1.2: test reflections - @LargeTest - public void test1_2Reflections() throws Exception { - // TODO: uncomment when early reflections are implemented -// boolean result = false; -// String msg = "test1_2Reflections()"; -// getReverb(0); -// try { -// mReverb.setReflectionsLevel((short)0); -// short level = mReverb.getReflectionsLevel(); -// assertTrue(msg +": got incorrect reflections level", -// (level > (0 - MILLIBEL_TOLERANCE)) && -// (level < (0 + MILLIBEL_TOLERANCE))); -// -// mReverb.setReflectionsDelay(30); -// int delay = mReverb.getReflectionsDelay(); -// assertTrue(msg +": got incorrect reflections delay", -// ((float)delay > (float)(30 / DELAY_TOLERANCE)) && -// ((float)delay < (float)(30 * DELAY_TOLERANCE))); -// -// result = true; -// } catch (IllegalArgumentException e) { -// msg = msg.concat(": Bad parameter value"); -// loge(msg, "Bad parameter value"); -// } catch (UnsupportedOperationException e) { -// msg = msg.concat(": get parameter() rejected"); -// loge(msg, "get parameter() rejected"); -// } catch (IllegalStateException e) { -// msg = msg.concat("get parameter() called in wrong state"); -// loge(msg, "get parameter() called in wrong state"); -// } finally { -// releaseReverb(); -// } -// assertTrue(msg, result); - } - - //Test case 1.3: test reverb - @LargeTest - public void test1_3Reverb() throws Exception { - boolean result = false; - String msg = "test1_3Reverb()"; - getReverb(0); - try { - mReverb.setReverbLevel((short)0); - short level = mReverb.getReverbLevel(); - assertTrue(msg +": got incorrect reverb level", - (level > (0 - MILLIBEL_TOLERANCE)) && - (level < (0 + MILLIBEL_TOLERANCE))); - - // TODO: change delay when early reflections are implemented - mReverb.setReverbDelay(0); - int delay = mReverb.getReverbDelay(); - assertTrue(msg +": got incorrect reverb delay", delay < 5); - - result = true; - } catch (IllegalArgumentException e) { - msg = msg.concat(": Bad parameter value"); - loge(msg, "Bad parameter value"); - } catch (UnsupportedOperationException e) { - msg = msg.concat(": get parameter() rejected"); - loge(msg, "get parameter() rejected"); - } catch (IllegalStateException e) { - msg = msg.concat("get parameter() called in wrong state"); - loge(msg, "get parameter() called in wrong state"); - } finally { - releaseReverb(); - } - assertTrue(msg, result); - } - - //Test case 1.4: test diffusion and density - @LargeTest - public void test1_4DiffusionAndDensity() throws Exception { - boolean result = false; - String msg = "test1_4DiffusionAndDensity()"; - getReverb(0); - try { - mReverb.setDiffusion((short)500); - short diffusion = mReverb.getDiffusion(); - assertTrue(msg +": got incorrect diffusion", - ((float)diffusion > (float)(500 / RATIO_TOLERANCE)) && - ((float)diffusion < (float)(500 * RATIO_TOLERANCE))); - - mReverb.setDensity((short)500); - short density = mReverb.getDensity(); - assertTrue(msg +": got incorrect density", - ((float)density > (float)(500 / RATIO_TOLERANCE)) && - ((float)density < (float)(500 * RATIO_TOLERANCE))); - - result = true; - } catch (IllegalArgumentException e) { - msg = msg.concat(": Bad parameter value"); - loge(msg, "Bad parameter value"); - } catch (UnsupportedOperationException e) { - msg = msg.concat(": get parameter() rejected"); - loge(msg, "get parameter() rejected"); - } catch (IllegalStateException e) { - msg = msg.concat("get parameter() called in wrong state"); - loge(msg, "get parameter() called in wrong state"); - } finally { - releaseReverb(); - } - assertTrue(msg, result); - } - - //Test case 1.5: test properties - @LargeTest - public void test1_5Properties() throws Exception { - boolean result = false; - String msg = "test1_5Properties()"; - getReverb(0); - try { - EnvironmentalReverb.Settings settings = mReverb.getProperties(); - short newRoomLevel = 0; - if (settings.roomLevel == 0) { - newRoomLevel = -1000; - } - String str = settings.toString(); - settings = new EnvironmentalReverb.Settings(str); - settings.roomLevel = newRoomLevel; - mReverb.setProperties(settings); - settings = mReverb.getProperties(); - assertTrue(msg +": setProperties failed", - (settings.roomLevel > (newRoomLevel - MILLIBEL_TOLERANCE)) && - (settings.roomLevel < (newRoomLevel + MILLIBEL_TOLERANCE))); - result = true; - } catch (IllegalArgumentException e) { - msg = msg.concat(": Bad parameter value"); - loge(msg, "Bad parameter value"); - } catch (UnsupportedOperationException e) { - msg = msg.concat(": get parameter() rejected"); - loge(msg, "get parameter() rejected"); - } catch (IllegalStateException e) { - msg = msg.concat("get parameter() called in wrong state"); - loge(msg, "get parameter() called in wrong state"); - } finally { - releaseReverb(); - } - assertTrue(msg, result); - } - - //----------------------------------------------------------------- - // 2 - Effect action - //---------------------------------- - - //Test case 2.0: test actual auxiliary reverb influence on sound - @LargeTest - public void test2_0AuxiliarySoundModification() throws Exception { - boolean result = false; - String msg = "test2_0AuxiliarySoundModification()"; - EnergyProbe probe = null; - AudioEffect vc = null; - MediaPlayer mp = null; - AudioManager am = (AudioManager) getActivity().getSystemService(Context.AUDIO_SERVICE); - int volume = am.getStreamMaxVolume(AudioManager.STREAM_MUSIC); - am.setStreamVolume(AudioManager.STREAM_MUSIC, - am.getStreamMaxVolume(AudioManager.STREAM_MUSIC), - 0); - getReverb(0); - try { - probe = new EnergyProbe(0); - // 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, - UUID.fromString("119341a0-8469-11df-81f9-0002a5d5c51b"), - 0, - 0); - vc.setEnabled(true); - - mp = new MediaPlayer(); - mp.setDataSource(MediaNames.SINE_200_1000); - mp.setAudioStreamType(AudioManager.STREAM_MUSIC); - mp.attachAuxEffect(mReverb.getId()); - mp.setAuxEffectSendLevel(1.0f); - mReverb.setRoomLevel((short)0); - mReverb.setReverbLevel((short)0); - mReverb.setDecayTime(2000); - mReverb.setEnabled(true); - mp.prepare(); - mp.start(); - Thread.sleep(1000); - mp.stop(); - Thread.sleep(300); - // measure energy around 1kHz after media player was stopped for 300 ms - int energy1000 = probe.capture(1000); - assertTrue(msg + ": reverb has no effect", energy1000 > 0); - result = true; - } catch (IllegalArgumentException e) { - msg = msg.concat(": Bad parameter value"); - loge(msg, "Bad parameter value"); - } catch (UnsupportedOperationException e) { - msg = msg.concat(": get parameter() rejected"); - loge(msg, "get parameter() rejected"); - } catch (IllegalStateException e) { - msg = msg.concat("get parameter() called in wrong state"); - loge(msg, "get parameter() called in wrong state"); - } catch (InterruptedException e) { - loge(msg, "sleep() interrupted"); - } - finally { - releaseReverb(); - if (mp != null) { - mp.release(); - } - if (vc != null) { - vc.release(); - } - if (probe != null) { - probe.release(); - } - am.setStreamVolume(AudioManager.STREAM_MUSIC, volume, 0); - } - assertTrue(msg, result); - } - - //Test case 2.1: test actual insert reverb influence on sound - @LargeTest - public void test2_1InsertSoundModification() throws Exception { - boolean result = false; - String msg = "test2_1InsertSoundModification()"; - EnergyProbe probe = null; - AudioEffect vc = null; - MediaPlayer mp = null; - AudioEffect rvb = null; - AudioManager am = (AudioManager) getActivity().getSystemService(Context.AUDIO_SERVICE); - int volume = am.getStreamMaxVolume(AudioManager.STREAM_MUSIC); - am.setStreamVolume(AudioManager.STREAM_MUSIC, - am.getStreamMaxVolume(AudioManager.STREAM_MUSIC), - 0); - try { - // 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, - UUID.fromString("119341a0-8469-11df-81f9-0002a5d5c51b"), - 0, - 0); - vc.setEnabled(true); - - mp = new MediaPlayer(); - mp.setDataSource(MediaNames.SINE_200_1000); - mp.setAudioStreamType(AudioManager.STREAM_MUSIC); - - // create reverb with UUID instead of EnvironmentalReverb constructor otherwise an - // auxiliary reverb will be chosen by the effect framework as we are on session 0 - rvb = new AudioEffect( - AudioEffect.EFFECT_TYPE_NULL, - UUID.fromString("c7a511a0-a3bb-11df-860e-0002a5d5c51b"), - 0, - 0); - - rvb.setParameter(EnvironmentalReverb.PARAM_ROOM_LEVEL, (short)0); - rvb.setParameter(EnvironmentalReverb.PARAM_REVERB_LEVEL, (short)0); - rvb.setParameter(EnvironmentalReverb.PARAM_DECAY_TIME, 2000); - rvb.setEnabled(true); - - // create probe after reverb so that it is chained behind the reverb in the - // effect chain - probe = new EnergyProbe(0); - - mp.prepare(); - mp.start(); - Thread.sleep(1000); - mp.stop(); - Thread.sleep(300); - // measure energy around 1kHz after media player was stopped for 300 ms - int energy1000 = probe.capture(1000); - assertTrue(msg + ": reverb has no effect", energy1000 > 0); - result = true; - } catch (IllegalArgumentException e) { - msg = msg.concat(": Bad parameter value"); - loge(msg, "Bad parameter value"); - } catch (UnsupportedOperationException e) { - msg = msg.concat(": get parameter() rejected"); - loge(msg, "get parameter() rejected"); - } catch (IllegalStateException e) { - msg = msg.concat("get parameter() called in wrong state"); - loge(msg, "get parameter() called in wrong state"); - } catch (InterruptedException e) { - loge(msg, "sleep() interrupted"); - } - finally { - if (mp != null) { - mp.release(); - } - if (vc != null) { - vc.release(); - } - if (rvb != null) { - rvb.release(); - } - if (probe != null) { - probe.release(); - } - am.setStreamVolume(AudioManager.STREAM_MUSIC, volume, 0); - } - assertTrue(msg, result); - } - - //----------------------------------------------------------------- - // private methods - //---------------------------------- - - private void getReverb(int session) { - if (mReverb == null || session != mSession) { - if (session != mSession && mReverb != null) { - mReverb.release(); - mReverb = null; - } - try { - mReverb = new EnvironmentalReverb(0, session); - mSession = session; - } catch (IllegalArgumentException e) { - Log.e(TAG, "getReverb() EnvironmentalReverb not found exception: "+e); - } catch (UnsupportedOperationException e) { - Log.e(TAG, "getReverb() Effect library not loaded exception: "+e); - } - } - assertNotNull("could not create mReverb", mReverb); - } - - private void releaseReverb() { - if (mReverb != null) { - mReverb.release(); - mReverb = null; - } - } - -} - diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaEqualizerTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaEqualizerTest.java deleted file mode 100644 index 9146fb8..0000000 --- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaEqualizerTest.java +++ /dev/null @@ -1,352 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.mediaframeworktest.functional; - -import com.android.mediaframeworktest.MediaFrameworkTest; -import com.android.mediaframeworktest.MediaNames; -import android.content.Context; -import android.content.res.AssetFileDescriptor; -import android.media.audiofx.AudioEffect; -import android.media.AudioManager; -import android.media.audiofx.Equalizer; -import android.media.audiofx.Visualizer; -import android.media.MediaPlayer; - -import android.os.Looper; -import android.test.suitebuilder.annotation.LargeTest; -import android.test.suitebuilder.annotation.MediumTest; -import android.test.suitebuilder.annotation.Suppress; -import android.test.ActivityInstrumentationTestCase2; -import android.util.Log; - -import java.nio.ByteOrder; -import java.nio.ByteBuffer; -import java.util.UUID; - -/** - * Junit / Instrumentation test case for the media AudioTrack api - - */ -public class MediaEqualizerTest extends ActivityInstrumentationTestCase2 { - private String TAG = "MediaEqualizerTest"; - private final static int MIN_NUMBER_OF_BANDS = 4; - private final static int MIN_BAND_LEVEL = -1500; - private final static int MAX_BAND_LEVEL = 1500; - private final static int TEST_FREQUENCY_MILLIHERTZ = 1000000; - private final static int MIN_NUMBER_OF_PRESETS = 4; - private final static int TEST_VOLUME = 4; - private Equalizer mEqualizer = null; - private int mSession = -1; - - public MediaEqualizerTest() { - super("com.android.mediaframeworktest", MediaFrameworkTest.class); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - } - - @Override - protected void tearDown() throws Exception { - super.tearDown(); - releaseEqualizer(); - } - - private static void assumeTrue(String message, boolean cond) { - assertTrue("(assume)"+message, cond); - } - - private void log(String testName, String message) { - Log.v(TAG, "["+testName+"] "+message); - } - - private void loge(String testName, String message) { - Log.e(TAG, "["+testName+"] "+message); - } - - //----------------------------------------------------------------- - // EQUALIZER TESTS: - //---------------------------------- - - - //----------------------------------------------------------------- - // 0 - constructor - //---------------------------------- - - //Test case 0.0: test constructor and release - @LargeTest - public void test0_0ConstructorAndRelease() throws Exception { - boolean result = false; - String msg = "test1_0ConstructorAndRelease()"; - Equalizer eq = null; - try { - eq = new Equalizer(0, 0); - assertNotNull(msg + ": could not create Equalizer", eq); - try { - assertTrue(msg +": invalid effect ID", (eq.getId() != 0)); - } catch (IllegalStateException e) { - msg = msg.concat(": Equalizer not initialized"); - } - result = true; - } catch (IllegalArgumentException e) { - msg = msg.concat(": Equalizer not found"); - } catch (UnsupportedOperationException e) { - msg = msg.concat(": Effect library not loaded"); - } finally { - if (eq != null) { - eq.release(); - } - } - assertTrue(msg, result); - } - - - //----------------------------------------------------------------- - // 1 - get/set parameters - //---------------------------------- - - //Test case 1.0: test setBandLevel() and getBandLevel() - @LargeTest - public void test1_0BandLevel() throws Exception { - boolean result = false; - String msg = "test1_0BandLevel()"; - getEqualizer(0); - try { - short numBands = mEqualizer.getNumberOfBands(); - assertTrue(msg + ": not enough bands", numBands >= MIN_NUMBER_OF_BANDS); - - short[] levelRange = mEqualizer.getBandLevelRange(); - assertTrue(msg + ": min level too high", levelRange[0] <= MIN_BAND_LEVEL); - assertTrue(msg + ": max level too low", levelRange[1] >= MAX_BAND_LEVEL); - - mEqualizer.setBandLevel((short)0, levelRange[1]); - short level = mEqualizer.getBandLevel((short)0); - // 10% margin on actual level compared to requested level - assertTrue(msg + ": setBandLevel failed", - ((float)level > (float)levelRange[1] * 0.9f) && - ((float)level < (float)levelRange[1] * 1.1f)); - result = true; - } catch (IllegalArgumentException e) { - msg = msg.concat(": Bad parameter value"); - loge(msg, "Bad parameter value"); - } catch (UnsupportedOperationException e) { - msg = msg.concat(": get parameter() rejected"); - loge(msg, "get parameter() rejected"); - } catch (IllegalStateException e) { - msg = msg.concat("get parameter() called in wrong state"); - loge(msg, "get parameter() called in wrong state"); - } finally { - releaseEqualizer(); - } - assertTrue(msg, result); - } - - //Test case 1.1: test band frequency - @LargeTest - public void test1_1BandFrequency() throws Exception { - boolean result = false; - String msg = "test1_1BandFrequency()"; - getEqualizer(0); - try { - short band = mEqualizer.getBand(TEST_FREQUENCY_MILLIHERTZ); - assertTrue(msg + ": getBand failed", band >= 0); - int[] freqRange = mEqualizer.getBandFreqRange(band); - assertTrue(msg + ": getBandFreqRange failed", - (freqRange[0] <= TEST_FREQUENCY_MILLIHERTZ) && - (freqRange[1] >= TEST_FREQUENCY_MILLIHERTZ)); - int freq = mEqualizer.getCenterFreq(band); - assertTrue(msg + ": getCenterFreq failed", - (freqRange[0] <= freq) && (freqRange[1] >= freq)); - result = true; - } catch (IllegalArgumentException e) { - msg = msg.concat(": Bad parameter value"); - loge(msg, "Bad parameter value"); - } catch (UnsupportedOperationException e) { - msg = msg.concat(": get parameter() rejected"); - loge(msg, "get parameter() rejected"); - } catch (IllegalStateException e) { - msg = msg.concat("get parameter() called in wrong state"); - loge(msg, "get parameter() called in wrong state"); - } finally { - releaseEqualizer(); - } - assertTrue(msg, result); - } - - //Test case 1.2: test presets - @LargeTest - public void test1_2Presets() throws Exception { - boolean result = false; - String msg = "test1_2Presets()"; - getEqualizer(0); - try { - short numPresets = mEqualizer.getNumberOfPresets(); - assertTrue(msg + ": getNumberOfPresets failed", numPresets >= MIN_NUMBER_OF_PRESETS); - mEqualizer.usePreset((short)(numPresets - 1)); - short preset = mEqualizer.getCurrentPreset(); - assertEquals(msg + ": usePreset failed", preset, (short)(numPresets - 1)); - String name = mEqualizer.getPresetName(preset); - assertNotNull(msg + ": getPresetName failed", name); - result = true; - } catch (IllegalArgumentException e) { - msg = msg.concat(": Bad parameter value"); - loge(msg, "Bad parameter value"); - } catch (UnsupportedOperationException e) { - msg = msg.concat(": get parameter() rejected"); - loge(msg, "get parameter() rejected"); - } catch (IllegalStateException e) { - msg = msg.concat("get parameter() called in wrong state"); - loge(msg, "get parameter() called in wrong state"); - } finally { - releaseEqualizer(); - } - assertTrue(msg, result); - } - - //Test case 1.3: test properties - @LargeTest - public void test1_3Properties() throws Exception { - boolean result = false; - String msg = "test1_3Properties()"; - getEqualizer(0); - try { - Equalizer.Settings settings = mEqualizer.getProperties(); - String str = settings.toString(); - settings = new Equalizer.Settings(str); - mEqualizer.setProperties(settings); - result = true; - } catch (IllegalArgumentException e) { - msg = msg.concat(": Bad parameter value"); - loge(msg, "Bad parameter value"); - } catch (UnsupportedOperationException e) { - msg = msg.concat(": get parameter() rejected"); - loge(msg, "get parameter() rejected"); - } catch (IllegalStateException e) { - msg = msg.concat("get parameter() called in wrong state"); - loge(msg, "get parameter() called in wrong state"); - } finally { - releaseEqualizer(); - } - assertTrue(msg, result); - } - - //----------------------------------------------------------------- - // 2 - Effect action - //---------------------------------- - - //Test case 2.0: test that the equalizer actually alters the sound - @LargeTest - public void test2_0SoundModification() throws Exception { - boolean result = false; - String msg = "test2_0SoundModification()"; - EnergyProbe probe = null; - AudioEffect vc = null; - MediaPlayer mp = null; - AudioManager am = (AudioManager) getActivity().getSystemService(Context.AUDIO_SERVICE); - int volume = am.getStreamMaxVolume(AudioManager.STREAM_MUSIC); - am.setStreamVolume(AudioManager.STREAM_MUSIC, - TEST_VOLUME, - 0); - try { - probe = new EnergyProbe(0); - // 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, - UUID.fromString("119341a0-8469-11df-81f9-0002a5d5c51b"), - 0, - 0); - vc.setEnabled(true); - - mp = new MediaPlayer(); - mp.setDataSource(MediaNames.SINE_200_1000); - mp.setAudioStreamType(AudioManager.STREAM_MUSIC); - getEqualizer(mp.getAudioSessionId()); - mp.prepare(); - mp.start(); - Thread.sleep(500); - // measure reference energy around 1kHz - int refEnergy = probe.capture(1000); - short band = mEqualizer.getBand(1000000); - short[] levelRange = mEqualizer.getBandLevelRange(); - mEqualizer.setBandLevel(band, levelRange[0]); - mEqualizer.setEnabled(true); - Thread.sleep(500); - // measure energy around 1kHz with band level at min - int energy = probe.capture(1000); - assertTrue(msg + ": equalizer has no effect at 1kHz", energy < refEnergy/4); - result = true; - } catch (IllegalArgumentException e) { - msg = msg.concat(": Bad parameter value"); - loge(msg, "Bad parameter value"); - } catch (UnsupportedOperationException e) { - msg = msg.concat(": get parameter() rejected"); - loge(msg, "get parameter() rejected"); - } catch (IllegalStateException e) { - msg = msg.concat("get parameter() called in wrong state"); - loge(msg, "get parameter() called in wrong state"); - } catch (InterruptedException e) { - loge(msg, "sleep() interrupted"); - } - finally { - releaseEqualizer(); - if (mp != null) { - mp.release(); - } - if (vc != null) { - vc.release(); - } - if (probe != null) { - probe.release(); - } - am.setStreamVolume(AudioManager.STREAM_MUSIC, volume, 0); - } - assertTrue(msg, result); - } - - //----------------------------------------------------------------- - // private methods - //---------------------------------- - - private void getEqualizer(int session) { - if (mEqualizer == null || session != mSession) { - if (session != mSession && mEqualizer != null) { - mEqualizer.release(); - mEqualizer = null; - } - try { - mEqualizer = new Equalizer(0, session); - mSession = session; - } catch (IllegalArgumentException e) { - Log.e(TAG, "getEqualizer() Equalizer not found exception: "+e); - } catch (UnsupportedOperationException e) { - Log.e(TAG, "getEqualizer() Effect library not loaded exception: "+e); - } - } - assertNotNull("could not create mEqualizer", mEqualizer); - } - - private void releaseEqualizer() { - if (mEqualizer != null) { - mEqualizer.release(); - mEqualizer = null; - } - } - -} - diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaItemThumbnailTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaItemThumbnailTest.java deleted file mode 100755 index d5b67aa..0000000 --- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaItemThumbnailTest.java +++ /dev/null @@ -1,956 +0,0 @@ -/* - * Copyright (C) 2011 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -package com.android.mediaframeworktest.functional; - -import java.io.File; -import java.io.IOException; - -import android.graphics.Bitmap; -import android.media.videoeditor.MediaImageItem; -import android.media.videoeditor.MediaItem; -import android.media.videoeditor.MediaVideoItem; -import android.media.videoeditor.VideoEditor; -import android.os.Environment; -import android.test.ActivityInstrumentationTestCase; -import android.test.suitebuilder.annotation.LargeTest; -import com.android.mediaframeworktest.MediaFrameworkTest; -import com.android.mediaframeworktest.VideoEditorHelper; - -public class MediaItemThumbnailTest extends - ActivityInstrumentationTestCase { - private final String TAG = "MediaItemThumbailTest"; - - private final String PROJECT_LOCATION = VideoEditorHelper.PROJECT_LOCATION_COMMON; - - private final String INPUT_FILE_PATH = VideoEditorHelper.INPUT_FILE_PATH_COMMON; - - private VideoEditor mVideoEditor; - - private VideoEditorHelper mVideoEditorHelper; - - public MediaItemThumbnailTest() { - super("com.android.mediaframeworktest", MediaFrameworkTest.class); - } - - @Override - protected void setUp() throws Exception { - // setup for each test case. - super.setUp(); - mVideoEditorHelper = new VideoEditorHelper(); - // Create a random String which will be used as project path, where all - // project related files will be stored. - final String projectPath = mVideoEditorHelper. - createRandomFile(PROJECT_LOCATION); - mVideoEditor = mVideoEditorHelper.createVideoEditor(projectPath); - } - - @Override - protected void tearDown() throws Exception { - mVideoEditorHelper.destroyVideoEditor(mVideoEditor); - // Clean the directory created as project path - mVideoEditorHelper.deleteProject(new File(mVideoEditor.getPath())); - System.gc(); - super.tearDown(); - } - - protected void validateThumbnail(Bitmap thumbNailBmp, int outWidth, - int outHeight) throws Exception { - assertNotNull("Thumbnail Retrived is Null", thumbNailBmp); - assertEquals("Thumbnail Height", outHeight, thumbNailBmp.getHeight()); - assertEquals("Thumbnail Width", outWidth, thumbNailBmp.getWidth()); - thumbNailBmp.recycle(); - } - - // ----------------------------------------------------------------- - // THUMBNAIL - // ----------------------------------------------------------------- - /** - * To test thumbnail / frame extraction on H.263 QCIF. - */ - // TODO : TC_TN_001 - @LargeTest - public void testThumbnailForH263QCIF() throws Exception { - final String videoItemFilename = INPUT_FILE_PATH - + "H263_profile0_176x144_15fps_256kbps_AACLC_32kHz_128kbps_s_0_26.3gp"; - final int atTime = 0; - final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; - final MediaVideoItem mediaVideoItem = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", - videoItemFilename, renderingMode); - - final int outWidth = (mediaVideoItem.getWidth() / 2); - final int outHeight = mediaVideoItem.getHeight(); - - final Bitmap thumbNailBmp = mediaVideoItem.getThumbnail(outWidth, - outHeight, atTime); - validateThumbnail(thumbNailBmp, outWidth, outHeight); - } - - /** - * To test thumbnail / frame extraction on MPEG4 VGA . - */ - // TODO : TC_TN_002 - @LargeTest - public void testThumbnailForMPEG4VGA() throws Exception { - final String videoItemFilename = INPUT_FILE_PATH + - "MPEG4_SP_640x480_30fps_512Kbps_0_23.3gp"; - final int atTime = 0; - final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; - final MediaVideoItem mediaVideoItem = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", - videoItemFilename, renderingMode); - final int outWidth = (mediaVideoItem.getWidth() / 2); - final int outHeight = mediaVideoItem.getHeight(); - final Bitmap thumbNailBmp = mediaVideoItem.getThumbnail(outWidth, - outHeight, atTime); - validateThumbnail(thumbNailBmp, outWidth, outHeight); - } - - /** - * To test thumbnail / frame extraction on MPEG4 NTSC. - */ - // TODO : TC_TN_003 - @LargeTest - public void testThumbnailForMPEG4NTSC() throws Exception { - final String videoItemFilename = INPUT_FILE_PATH - + "MPEG4_SP_720x480_30fps_280kbps_AACLC_48kHz_96kbps_s_0_21.mp4"; - final int atTime = 0; - final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; - final MediaVideoItem mediaVideoItem = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", - videoItemFilename, renderingMode); - final int outWidth = mediaVideoItem.getWidth() / 2; - final int outHeight = mediaVideoItem.getHeight() / 2; - final Bitmap thumbNailBmp = mediaVideoItem.getThumbnail(outWidth, - outHeight, atTime); - validateThumbnail(thumbNailBmp, outWidth, outHeight); - } - - /** - * To test thumbnail / frame extraction on MPEG4 WVGA. - */ - // TODO : TC_TN_004 - @LargeTest - public void testThumbnailForMPEG4WVGA() throws Exception { - - final String videoItemFilename = INPUT_FILE_PATH - + "MPEG4_SP_800x480_515kbps_15fps_AMR_NB_8KHz_12.2kbps_m_0_26.mp4"; - final int atTime = 0; - final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; - final MediaVideoItem mediaVideoItem = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", - videoItemFilename, renderingMode); - final int outWidth = mediaVideoItem.getWidth() * 2; - final int outHeight = mediaVideoItem.getHeight(); - final Bitmap thumbNailBmp = mediaVideoItem.getThumbnail(outWidth, - outHeight, atTime); - validateThumbnail(thumbNailBmp, outWidth, outHeight); - } - - /** - * To test thumbnail / frame extraction on MPEG4 QCIF. - */ - // TODO : TC_TN_005 - @LargeTest - public void testThumbnailForMPEG4QCIF() throws Exception { - final String videoItemFilename = INPUT_FILE_PATH - + "MPEG4_SP_176x144_30fps_256kbps_AACLC_44.1kHz_96kbps_s_1_17.3gp"; - final int atTime = 0; - final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; - - final MediaVideoItem mediaVideoItem = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", - videoItemFilename, renderingMode); - final int outWidth = mediaVideoItem.getWidth(); - final int outHeight = mediaVideoItem.getHeight() * 2; - final Bitmap thumbNailBmp = mediaVideoItem.getThumbnail(outWidth, - outHeight, atTime); - validateThumbnail(thumbNailBmp, outWidth, outHeight); - } - - /** - * To test thumbnail / frame extraction on H264 QCIF. - */ - // TODO : TC_TN_006 - @LargeTest - public void testThumbnailForH264QCIF() throws Exception { - final String videoItemFilename = INPUT_FILE_PATH - + "H264_BP_176x144_15fps_144kbps_AMRNB_8kHz_12.2kbps_m_1_17.3gp"; - - final int atTime = 0; - final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; - final MediaVideoItem mediaVideoItem = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", - videoItemFilename, renderingMode); - final int outWidth = mediaVideoItem.getWidth() * 2; - final int outHeight = mediaVideoItem.getHeight() * 2; - final Bitmap thumbNailBmp = mediaVideoItem.getThumbnail(outWidth, - outHeight, atTime); - validateThumbnail(thumbNailBmp, outWidth, outHeight); - } - - /** - * To test thumbnail / frame extraction on H264 VGA. - */ - // TODO : TC_TN_007 - @LargeTest - public void testThumbnailForH264VGA() throws Exception { - final String videoItemFilename = INPUT_FILE_PATH + - "H264_BP_640x480_30fps_192kbps_1_5.mp4"; - final int outWidth = 32; - final int outHeight = 32; - final int atTime = 0; - - final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; - final MediaVideoItem mediaVideoItem = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", - videoItemFilename, renderingMode); - - final Bitmap thumbNailBmp = mediaVideoItem.getThumbnail(outWidth, - outHeight, atTime); - validateThumbnail(thumbNailBmp, outWidth, outHeight); - } - /** - * To test thumbnail / frame extraction on H264 WVGA. - */ - // TODO : TC_TN_008 - @LargeTest - public void testThumbnailForH264WVGA() throws Exception { - final String videoItemFilename = INPUT_FILE_PATH + - "H264_BP_800x480_15fps_512kbps_AACLC_24KHz_38Kbps_s_1_17.mp4"; - final int outWidth = 64; - final int outHeight = 64; - final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; - final MediaVideoItem mediaVideoItem = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", - videoItemFilename, renderingMode); - final long atTime = mediaVideoItem.getDuration() / 2; - final Bitmap thumbNailBmp = mediaVideoItem.getThumbnail(outWidth, - outHeight, atTime); - validateThumbnail(thumbNailBmp, outWidth, outHeight); - } - - /** - * To test thumbnail / frame extraction on H264 854x480. - */ - // TODO : TC_TN_009 - @LargeTest - public void testThumbnailForH264854_480() throws Exception { - final String videoItemFilename = INPUT_FILE_PATH - + "MPEG4_SP_854x480_15fps_256kbps_AACLC_16khz_48kbps_s_0_26.mp4"; - final int outWidth = 128; - final int outHeight = 128; - final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; - MediaVideoItem mediaVideoItem = null; - mediaVideoItem = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", - videoItemFilename, renderingMode); - final long atTime = mediaVideoItem.getDuration() - 1000; - final Bitmap thumbNailBmp = mediaVideoItem.getThumbnail(outWidth, - outHeight, atTime); - validateThumbnail(thumbNailBmp, outWidth, outHeight); - } - - /** - * To test thumbnail / frame extraction on H264 960x720. - */ - // TODO : TC_TN_010 - @LargeTest - public void testThumbnailForH264HD960() throws Exception { - final String videoItemFilename = INPUT_FILE_PATH + - "H264_BP_960x720_25fps_800kbps_AACLC_48Khz_192Kbps_s_1_17.mp4"; - final int outWidth = 75; - final int outHeight = 75; - - final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; - final MediaVideoItem mediaVideoItem = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", - videoItemFilename, renderingMode); - final long atTime = mediaVideoItem.getDuration() - 1000; - final Bitmap thumbNailBmp = mediaVideoItem.getThumbnail(outWidth, - outHeight, atTime); - validateThumbnail(thumbNailBmp, outWidth, outHeight); - } - - /** - * To test thumbnail / frame extraction on H264 1080x720 . - */ - // TODO : TC_TN_011 - @LargeTest - public void testThumbnailForH264HD1080() throws Exception { - final String videoItemFilename = INPUT_FILE_PATH + - "H264_BP_1080x720_30fps_800kbps_1_17.mp4"; - final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; - final MediaVideoItem mediaVideoItem = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", - videoItemFilename, renderingMode); - final int outWidth = mediaVideoItem.getWidth() / 2; - final int outHeight = mediaVideoItem.getHeight() / 2; - final long atTime = mediaVideoItem.getDuration() / 4; - final Bitmap thumbNailBmp = mediaVideoItem.getThumbnail(outWidth, - outHeight, atTime); - validateThumbnail(thumbNailBmp, outWidth, outHeight); - } - - /** - * Check the thumbnail / frame extraction precision at 0,100 and 200 ms - */ - // TODO : TC_TN_012 - @LargeTest - public void testThumbnailForH264VGADifferentDuration() throws Exception { - final String videoItemFilename = INPUT_FILE_PATH + - "H264_BP_640x480_30fps_256kbps_1_17.mp4"; - final int atTime = 0; - final int atTime1 = 100; - final int atTime2 = 200; - final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; - - final MediaVideoItem mediaVideoItem = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", - videoItemFilename, renderingMode); - final int outWidth = mediaVideoItem.getWidth(); - final int outHeight = mediaVideoItem.getHeight(); - - final Bitmap thumbNailBmp = mediaVideoItem.getThumbnail(outWidth, - outHeight, atTime); - validateThumbnail(thumbNailBmp, outWidth, outHeight); - - // get Thumbnail @ 100ms - final Bitmap thumbNailBmpAt100 = - mediaVideoItem.getThumbnail(outWidth, outHeight, atTime1); - validateThumbnail(thumbNailBmpAt100, outWidth, outHeight); - - // get Thumbnail @ 200ms - final Bitmap thumbNailBmpAt200 = mediaVideoItem.getThumbnail( - outWidth, outHeight, atTime2); - validateThumbnail(thumbNailBmpAt200, outWidth, outHeight); - } - - /** - *Check the thumbnail / frame extraction precision at - * FileDuration,FileDuration/2 + 100 andFileDuration/2 + 200 ms - */ - // TODO : TC_TN_013 - @LargeTest - public void testThumbnailForMP4VGA() throws Exception { - final String videoItemFilename = INPUT_FILE_PATH + - "MPEG4_SP_640x480_15fps_256kbps_0_30.mp4"; - final MediaVideoItem mediaVideoItem = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", - videoItemFilename, MediaItem.RENDERING_MODE_BLACK_BORDER); - - final int outWidth = mediaVideoItem.getWidth(); - final int outHeight = mediaVideoItem.getHeight(); - final long atTime = mediaVideoItem.getDuration() / 2; - final long atTime1 = atTime + 100; - final long atTime2 = atTime + 200; - - // get Thumbnail @ duration/2 - final Bitmap thumbNailBmp = mediaVideoItem.getThumbnail(outWidth, - outHeight, atTime); - validateThumbnail(thumbNailBmp, outWidth, outHeight); - - // get Thumbnail @ duration/2 + 100ms - final Bitmap thumbNailBmpAt100 = mediaVideoItem.getThumbnail( - outWidth, outHeight, atTime1); - validateThumbnail(thumbNailBmpAt100, outWidth, outHeight); - - // get Thumbnail @ duration/2 + 200ms - final Bitmap thumbNailBmpAt200 = mediaVideoItem.getThumbnail( - outWidth, outHeight, atTime2); - validateThumbnail(thumbNailBmpAt200, outWidth, outHeight); - } - - /** - * Check the thumbnail / frame extraction on JPEG file - */ - // TODO : TC_TN_014 - @LargeTest - public void testThumbnailForImage() throws Exception { - final String imageItemFilename = INPUT_FILE_PATH + "IMG_640x480.jpg"; - final int mediaDuration = 1000; - final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; - boolean flagForException = false; - int outWidth = 0; - int outHeight = 0; - - final MediaImageItem mii = mVideoEditorHelper.createMediaItem( - mVideoEditor, "m1", imageItemFilename, mediaDuration, renderingMode); - assertNotNull("Media Image Item is Null", mii); - outWidth = mii.getWidth() / 2; - outHeight = mii.getHeight() / 2; - - final Bitmap thumbNailBmp = mii.getThumbnail(outWidth, - outHeight, mediaDuration); - validateThumbnail(thumbNailBmp, outWidth, outHeight); - } - /** - *To test ThumbnailList for H263 QCIF - */ - // TODO : TC_TN_015 - @LargeTest - public void testThumbnailListH263QCIF() throws Exception { - final String videoItemFilename = INPUT_FILE_PATH - + "H263_profile0_176x144_15fps_256kbps_AACLC_32kHz_128kbps_s_1_17.3gp"; - final int startTime = 0; - final int tnCount = 10; - final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; - final MediaVideoItem mediaVideoItem = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", - videoItemFilename, renderingMode); - - final int outWidth = mediaVideoItem.getWidth() / 4; - final int outHeight = mediaVideoItem.getHeight() / 4; - final long endTime = mediaVideoItem.getDuration() / 2; - - final Bitmap thumbNailBmp[] = mediaVideoItem.getThumbnailList( - outWidth, outHeight, startTime, endTime, tnCount); - assertNotNull("Thumbnail Retrived is Null", thumbNailBmp); - assertEquals("Thumbnail Count", tnCount, thumbNailBmp.length); - - for (int i = 0; i < thumbNailBmp.length; i++) { - validateThumbnail(thumbNailBmp[i], outWidth, outHeight); - thumbNailBmp[i] = null; - } - } - - /** - *To test ThumbnailList for MPEG4 QCIF - */ - // TODO : TC_TN_016 - @LargeTest - public void testThumbnailListMPEG4QCIF() throws Exception { - final String videoItemFilename = INPUT_FILE_PATH - + "MPEG4_SP_176x144_30fps_256kbps_AACLC_44.1kHz_96kbps_s_1_17.3gp"; - final int tnCount = 10; - final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; - - final MediaVideoItem mediaVideoItem = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", - videoItemFilename, renderingMode); - - final int outWidth = mediaVideoItem.getWidth() / 2; - final int outHeight = mediaVideoItem.getHeight() / 2; - final long startTime = mediaVideoItem.getDuration() / 2; - final long endTime = mediaVideoItem.getDuration(); - - final Bitmap thumbNailBmp[] = mediaVideoItem.getThumbnailList( - outWidth, outHeight, startTime, endTime, tnCount); - - assertNotNull("Thumbnail Retrived is Null", thumbNailBmp); - assertEquals("Thumbnail Count", tnCount, thumbNailBmp.length); - for (int i = 0; i < thumbNailBmp.length; i++) { - validateThumbnail(thumbNailBmp[i], outWidth, outHeight); - thumbNailBmp[i] = null; - } - } - - /** - *To test ThumbnailList for H264 VGA - */ - // TODO : TC_TN_017 - @LargeTest - public void testThumbnailListH264VGA() throws Exception { - final String videoItemFilename = INPUT_FILE_PATH + - "H264_BP_640x480_30fps_256kbps_1_17.mp4"; - final int tnCount = 10; - final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; - final MediaVideoItem mediaVideoItem = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", - videoItemFilename, renderingMode); - - final int outWidth = mediaVideoItem.getWidth() / 2; - final int outHeight = mediaVideoItem.getHeight() / 2; - final long startTime = mediaVideoItem.getDuration() / 3; - final long endTime = mediaVideoItem.getDuration() / 2; - - final Bitmap thumbNailBmp[] = mediaVideoItem.getThumbnailList( - outWidth, outHeight, startTime, endTime, tnCount); - assertNotNull("Thumbnail Retrived is Null", thumbNailBmp); - assertEquals("Thumbnail Count", tnCount, thumbNailBmp.length); - for (int i = 0; i < thumbNailBmp.length; i++) { - validateThumbnail(thumbNailBmp[i], outWidth, outHeight); - thumbNailBmp[i] = null; - } - } - - /** - *To test ThumbnailList for H264 WVGA - */ - // TODO : TC_TN_018 - @LargeTest - public void testThumbnailListH264WVGA() throws Exception { - final String videoItemFilename = INPUT_FILE_PATH + - "H264_BP_800x480_15fps_512kbps_AACLC_24KHz_38Kbps_s_1_17.mp4"; - final int tnCount = 10; - final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; - final MediaVideoItem mediaVideoItem = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", - videoItemFilename, renderingMode); - - final int outWidth = mediaVideoItem.getWidth() / 2; - final int outHeight = mediaVideoItem.getHeight() / 2; - final long startTime = mediaVideoItem.getDuration() / 3; - final long endTime = mediaVideoItem.getDuration() / 2; - - final Bitmap thumbNailBmp[] = mediaVideoItem.getThumbnailList( - outWidth, outHeight, startTime, endTime, tnCount); - assertNotNull("Thumbnail Retrived is Null", thumbNailBmp); - assertEquals("Thumbnail Count", tnCount, thumbNailBmp.length); - for (int i = 0; i < thumbNailBmp.length; i++) { - validateThumbnail(thumbNailBmp[i], outWidth, outHeight); - thumbNailBmp[i] = null; - } - } - - /** - *To test ThumbnailList for H264 VGA ,Time exceeding file duration - */ - // TODO : TC_TN_019 - @LargeTest - public void testThumbnailH264VGAExceedingFileDuration() throws Exception { - final String videoItemFilename = INPUT_FILE_PATH + - "H264_BP_640x480_30fps_256kbps_1_17.mp4"; - boolean flagForException = false; - int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; - - try { - final MediaVideoItem mediaVideoItem = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", - videoItemFilename, renderingMode); - final int outWidth = mediaVideoItem.getWidth() / 2; - final int outHeight = mediaVideoItem.getHeight() / 2; - final long atTime = mediaVideoItem.getDuration() + 2000; - mediaVideoItem.getThumbnail(outWidth, outHeight, atTime); - } catch (IllegalArgumentException e) { - flagForException = true; - } - assertTrue("Exception in Extracting thumbanil with Invalid Time", - flagForException); - } - - /** - *To test ThumbnailList for VGA Image - */ - // TODO : TC_TN_020 - @LargeTest - public void testThumbnailListVGAImage() throws Exception { - final String imageItemFilename = INPUT_FILE_PATH + "IMG_640x480.jpg"; - final int imageItemDuration = 10000; - final int startTime = 0; - final int endTime = 0; - final int tnCount = 10; - final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; - - final MediaImageItem mediaImageItem = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", - imageItemFilename, imageItemDuration, renderingMode); - final int outWidth = mediaImageItem.getWidth() / 2; - final int outHeight = mediaImageItem.getHeight() / 2; - - final Bitmap thumbNailBmp[] = mediaImageItem.getThumbnailList - (outWidth, outHeight, startTime, endTime, tnCount); - assertNotNull("Thumbnail Retrived is Null", thumbNailBmp); - assertEquals("Thumbnail Count", tnCount, thumbNailBmp.length); - for (int i = 0; i < thumbNailBmp.length; i++) { - validateThumbnail(thumbNailBmp[i], outWidth, outHeight); - thumbNailBmp[i] = null; - } - } - - /** - *To test ThumbnailList for Invalid file path - */ - // TODO : TC_TN_021 - @LargeTest - public void testThumbnailForInvalidFilePath() throws Exception { - final String imageItemFileName = INPUT_FILE_PATH + "/sdcard/abc.jpg"; - final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; - boolean flagForException = false; - try{ - final MediaImageItem mii = new MediaImageItem(mVideoEditor, "m1", - imageItemFileName, 3000, renderingMode); - } catch (IllegalArgumentException e) { - flagForException = true; - } catch (IOException e) { - flagForException = true; - } - assertTrue(" Invalid File Path", flagForException); - } - - /** - * To test thumbnail / frame extraction with setBoundaries - */ - // TODO : TC_TN_022 - @LargeTest - public void testThumbnailForMPEG4WVGAWithSetBoundaries() throws Exception { - final String videoItemFilename = INPUT_FILE_PATH + - "MPEG4_SP_800x480_515kbps_15fps_AMR_NB_8KHz_12.2kbps_m_0_26.mp4"; - final int atTime = 10000; - final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; - final MediaVideoItem mediaVideoItem = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", - videoItemFilename, renderingMode); - - mediaVideoItem.setExtractBoundaries(1000, - (mediaVideoItem.getDuration() - 21000)); - - final int outWidth = (mediaVideoItem.getWidth() / 2); - final int outHeight = (mediaVideoItem.getHeight() / 2); - final Bitmap thumbNailBmp = mediaVideoItem.getThumbnail(outWidth, - outHeight, atTime); - validateThumbnail(thumbNailBmp, outWidth, outHeight); - } - - /** - *To test ThumbnailList for H264 WVGA with setExtractboundaries - */ - // TODO : TC_TN_023 - @LargeTest - public void testThumbnailListForH264WVGAWithSetBoundaries() throws Exception { - final String videoItemFilename = INPUT_FILE_PATH + - "H264_BP_800x480_15fps_512kbps_1_17.mp4"; - final int thumbNailStartTime = 10000; - final int thumbNailEndTime = 12000; - final int tnCount = 10; - final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; - final MediaVideoItem mediaVideoItem = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", - videoItemFilename, renderingMode); - - final int outWidth = (mediaVideoItem.getWidth() / 2); - final int outHeight = (mediaVideoItem.getHeight() / 2); - - mediaVideoItem.setExtractBoundaries(10000, 12000); - - final Bitmap thumbNailBmp[] = mediaVideoItem.getThumbnailList - (outWidth, outHeight, thumbNailStartTime, thumbNailEndTime, - tnCount); - assertNotNull("Thumbnail Retrived is Null", thumbNailBmp); - assertTrue("Thumbnail Size", (thumbNailBmp.length > 0) ? true : false); - for (int i = 0; i < thumbNailBmp.length; i++) { - validateThumbnail(thumbNailBmp[i], outWidth, outHeight); - thumbNailBmp[i] = null; - } - } - - /** - *To test ThumbnailList for H264 WVGA with count > frame available - */ - // TODO : TC_TN_024 - @LargeTest - public void testThumbnailListForH264WVGAWithCount() throws Exception { - final String videoItemFilename = INPUT_FILE_PATH + - "H264_BP_800x480_15fps_512kbps_AACLC_24KHz_38Kbps_s_1_17.mp4"; - final int tnCount = 70; - final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; - final MediaVideoItem mediaVideoItem = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", - videoItemFilename, renderingMode); - - final int outWidth = (mediaVideoItem.getWidth() / 2); - final int outHeight = (mediaVideoItem.getHeight() / 2); - final long thumbNailStartTime = mediaVideoItem.getDuration() / 2; - final long thumbNailEndTime = thumbNailStartTime + 4000; - Bitmap thumbNailBmp[] = null; - boolean flagForException = false; - try{ - thumbNailBmp = mediaVideoItem.getThumbnailList(outWidth, outHeight, - thumbNailStartTime, thumbNailEndTime, tnCount); - }catch (Exception e){ - assertTrue("Unable to get Thumbnail list", flagForException); - } - if (thumbNailBmp.length <= tnCount) { - flagForException = true; - } - assertTrue("Thumbnail count more than asked", flagForException); - } - - /** - *To test ThumbnailList for H264 WVGA with startTime > End Time - */ - // TODO : TC_TN_025 - @LargeTest - public void testThumbnailListH264WVGAWithStartGreaterEnd() throws Exception { - final String videoItemFilename = INPUT_FILE_PATH + - "H264_BP_800x480_15fps_512kbps_AACLC_24KHz_38Kbps_s_1_17.mp4"; - final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; - final int tnCount = 10; - boolean flagForException = false; - final MediaVideoItem mediaVideoItem = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", - videoItemFilename, renderingMode); - final int outWidth = (mediaVideoItem.getWidth() / 2); - final int outHeight = (mediaVideoItem.getHeight() / 2); - final long thumbNailStartTime = mediaVideoItem.getDuration() / 2; - final long thumbNailEndTime = thumbNailStartTime - 1000; - try{ - mediaVideoItem.getThumbnailList(outWidth, outHeight, - thumbNailStartTime, thumbNailEndTime, tnCount); - } catch (IllegalArgumentException e) { - flagForException = true; - } - assertTrue("Thumbnail Extraction where start time > end time", - flagForException); - } - - /** - *To test ThumbnailList TC_TN_026 for H264 WVGA with startTime = End Time - */ - // TODO : TC_TN_026 - @LargeTest - public void testThumbnailListH264WVGAWithStartEqualEnd() throws Exception { - final String videoItemFilename = INPUT_FILE_PATH + - "H264_BP_800x480_15fps_512kbps_AACLC_24KHz_38Kbps_s_1_17.mp4"; - final int tnCount = 1; - final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; - - final MediaVideoItem mediaVideoItem = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", - videoItemFilename, renderingMode); - final int outWidth = (mediaVideoItem.getWidth() / 2); - final int outHeight = (mediaVideoItem.getHeight() / 2); - final long thumbNailStartTime = mediaVideoItem.getDuration() / 2; - final long thumbNailEndTime = thumbNailStartTime; - final Bitmap thumbNailBmp[] = mediaVideoItem.getThumbnailList(outWidth, - outHeight, thumbNailStartTime, thumbNailEndTime, tnCount); - assertNotNull("Thumbnail Retrived is Null", thumbNailBmp); - assertEquals("Thumbnail Count", tnCount, thumbNailBmp.length); - for (int i = 0; i < thumbNailBmp.length; i++) { - validateThumbnail(thumbNailBmp[i], outWidth, outHeight); - thumbNailBmp[i] = null; - } - } - - /** - *To test ThumbnailList TC_TN_027 for file where video duration is less - * than file duration. - */ - // TODO : TC_TN_027 - @LargeTest - public void testThumbnailForVideoDurationLessFileDuration() throws Exception { - final String videoItemFilename = INPUT_FILE_PATH - + "H264_BP_640x480_15fps_1200Kbps_AACLC_48KHz_64kps_m_0_27.3gp"; - final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; - final MediaVideoItem mediaVideoItem = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", - videoItemFilename, renderingMode); - final int outWidth = (mediaVideoItem.getWidth() / 2); - final int outHeight = (mediaVideoItem.getHeight() / 2); - final long atTime = mediaVideoItem.getDuration() - 2000; - final Bitmap thumbNailBmp = mediaVideoItem.getThumbnail (outWidth, - outHeight, atTime); - validateThumbnail(thumbNailBmp, outWidth, outHeight); - - } - - /** - *To test ThumbnailList TC_TN_028 for file which has video part corrupted - */ - // TODO : TC_TN_028 - @LargeTest - public void testThumbnailWithCorruptedVideoPart() throws Exception { - final String videoItemFilename = INPUT_FILE_PATH + - "corrupted_H264_BP_640x480_12.5fps_256kbps_AACLC_16khz_24kbps_s_0_26.mp4"; - final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; - boolean flagForException = false; - - try { - final MediaVideoItem mediaVideoItem = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", - videoItemFilename, renderingMode); - final int outWidth = mediaVideoItem.getWidth(); - final int outHeight = mediaVideoItem.getHeight() * 2; - final Bitmap thumbNailBmp = mediaVideoItem.getThumbnail - (outWidth, outHeight, mediaVideoItem.getDuration()/2); - } catch (IllegalArgumentException e) { - flagForException = true; - } - assertTrue("Corrupted File cannot be read", flagForException); - } - - /** - * Check the thumbnail / frame list extraction for Height as Negative Value - */ - // TODO : TC_TN_029 - @LargeTest - public void testThumbnailWithNegativeHeight() throws Exception { - final String videoItemFilename = INPUT_FILE_PATH - + "MPEG4_SP_176x144_30fps_256kbps_AACLC_44.1kHz_96kbps_s_1_17.3gp"; - final int tnCount = 10; - final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; - boolean flagForException = false; - try { - final MediaVideoItem mediaVideoItem = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", - videoItemFilename, renderingMode); - final int outWidth = (mediaVideoItem.getWidth() / 2); - final int outHeight = -1; - final long thumbNailStartTime = - mediaVideoItem.getBoundaryBeginTime()/2; - final long thumbNailEndTime = mediaVideoItem.getBoundaryEndTime(); - mediaVideoItem.getThumbnailList(outWidth, outHeight, - thumbNailStartTime, thumbNailEndTime, tnCount); - } catch (IllegalArgumentException e) { - flagForException = true; - } - assertTrue("Thumbnail List with negative Height", flagForException); - } - - /** - * Check the thumbnail for Height as Zero - */ - // TODO : TC_TN_030 - @LargeTest - public void testThumbnailWithHeightAsZero() throws Exception { - final String videoItemFilename = INPUT_FILE_PATH - + "MPEG4_SP_176x144_30fps_256kbps_AACLC_44.1kHz_96kbps_s_1_17.3gp"; - final int atTime = 100; - final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; - boolean flagForException = false; - try { - final MediaVideoItem mediaVideoItem = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", - videoItemFilename, renderingMode); - final int outWidth = (mediaVideoItem.getWidth() / 2); - final int outHeight = -1; - mediaVideoItem.getThumbnail(outWidth, outHeight, atTime); - } catch (IllegalArgumentException e) { - flagForException = true; - } - assertTrue("Thumbnail List with Zero Height", flagForException); - } - - /** - * Check the thumbnail for Height = 10 - */ - // TODO : TC_TN_031 - @LargeTest - public void testThumbnailWithHeight() throws Exception { - final String videoItemFilename = INPUT_FILE_PATH - + "MPEG4_SP_176x144_30fps_256kbps_AACLC_44.1kHz_96kbps_s_1_17.3gp"; - final int atTime = 1000; - final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; - final MediaVideoItem mediaVideoItem = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", - videoItemFilename, renderingMode); - final int outWidth = (mediaVideoItem.getWidth() / 2); - final int outHeight = 10; - final Bitmap thumbNailBmp = mediaVideoItem.getThumbnail (outWidth, - outHeight, atTime); - validateThumbnail(thumbNailBmp, outWidth, outHeight); - } - - /** - * Check the thumbnail / frame list extraction for Width as Negative Value - */ - // TODO : TC_TN_032 - @LargeTest - public void testThumbnailWithNegativeWidth() throws Exception { - final String videoItemFilename = INPUT_FILE_PATH - + "MPEG4_SP_176x144_30fps_256kbps_AACLC_44.1kHz_96kbps_s_1_17.3gp"; - final int tnCount = 10; - final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; - boolean flagForException = false; - try { - final MediaVideoItem mediaVideoItem = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", - videoItemFilename, renderingMode); - final int outWidth = -1; - final int outHeight = mediaVideoItem.getHeight(); - final long thumbNailStartTime = - mediaVideoItem.getBoundaryBeginTime()/2; - final long thumbNailEndTime = mediaVideoItem.getBoundaryEndTime(); - mediaVideoItem.getThumbnailList(outWidth, outHeight, thumbNailStartTime, - thumbNailEndTime, tnCount); - } catch (IllegalArgumentException e) { - flagForException = true; - } - assertTrue("Thumbnail List with negative Height", flagForException); - } - - /** - * Check the thumbnail / frame list extraction for Width zero - */ - // TODO : TC_TN_033 - @LargeTest - public void testThumbnailWithWidthAsZero() throws Exception { - final String videoItemFilename = INPUT_FILE_PATH - + "MPEG4_SP_176x144_30fps_256kbps_AACLC_44.1kHz_96kbps_s_1_17.3gp"; - final int atTime = 1000; - final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; - boolean flagForException = false; - try { - final MediaVideoItem mediaVideoItem = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", - videoItemFilename, renderingMode); - final int outWidth = 0; - final int outHeight = mediaVideoItem.getHeight() / 2; - mediaVideoItem.getThumbnail(outWidth, outHeight, atTime); - } catch (IllegalArgumentException e) { - flagForException = true; - } - assertTrue("Thumbnail List with Zero Width", flagForException); - } - - /** - * Check the thumbnail for Width = 10 - */ - // TODO : TC_TN_034 - @LargeTest - public void testThumbnailWithWidth() throws Exception { - final String videoItemFilename = INPUT_FILE_PATH - + "MPEG4_SP_176x144_30fps_256kbps_AACLC_44.1kHz_96kbps_s_1_17.3gp"; - final int atTime = 1000; - final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; - final MediaVideoItem mediaVideoItem = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", - videoItemFilename, renderingMode); - final int outWidth = 10; - final int outHeight = mediaVideoItem.getHeight(); - final Bitmap thumbNailBmp = mediaVideoItem.getThumbnail (outWidth, - outHeight, atTime); - validateThumbnail(thumbNailBmp, outWidth, outHeight); - } - - /** - * To test thumbnail / frame extraction on MPEG4 (time beyond file duration). - */ - // TODO : TC_TN_035 - @LargeTest - public void testThumbnailMPEG4withMorethanFileDuration() throws Exception { - final String videoItemFilename = INPUT_FILE_PATH - + "MPEG4_SP_176x144_30fps_256kbps_AACLC_44.1kHz_96kbps_s_1_17.3gp"; - boolean flagForException = false; - final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; - final MediaVideoItem mediaVideoItem = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", - videoItemFilename, renderingMode); - final int outWidth = mediaVideoItem.getWidth()/2; - final int outHeight = mediaVideoItem.getHeight()/2; - final long atTime = mediaVideoItem.getDuration() + 100; - try{ - final Bitmap thumbNailBmp = mediaVideoItem.getThumbnail (outWidth, - outHeight, atTime); - } catch (IllegalArgumentException e) { - flagForException = true; - } - assertTrue("Thumbnail duration is more than file duration", - flagForException); - } -} diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaPlayerApiTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaPlayerApiTest.java deleted file mode 100644 index 57d5368..0000000 --- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaPlayerApiTest.java +++ /dev/null @@ -1,426 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.mediaframeworktest.functional; - -import com.android.mediaframeworktest.MediaFrameworkTest; -import com.android.mediaframeworktest.MediaNames; -import com.android.mediaframeworktest.MediaProfileReader; - -import android.content.Context; -import android.test.ActivityInstrumentationTestCase; -import android.util.Log; -import android.test.suitebuilder.annotation.LargeTest; -import android.test.suitebuilder.annotation.MediumTest; -import android.test.suitebuilder.annotation.Suppress; - -import java.io.File; - -/** - * Junit / Instrumentation test case for the media player api - - */ -public class MediaPlayerApiTest extends ActivityInstrumentationTestCase { - private boolean duratoinWithinTolerence = false; - private String TAG = "MediaPlayerApiTest"; - private boolean isWMAEnable = false; - private boolean isWMVEnable = false; - - Context mContext; - - public MediaPlayerApiTest() { - super("com.android.mediaframeworktest", MediaFrameworkTest.class); - isWMAEnable = MediaProfileReader.getWMAEnable(); - isWMVEnable = MediaProfileReader.getWMVEnable(); - } - - protected void setUp() throws Exception { - super.setUp(); - - } - - public boolean verifyDuration(int duration, int expectedDuration){ - if ((duration > expectedDuration * 1.1) || (duration < expectedDuration * 0.9)) - return false; - else - return true; - } - - - - //Audio - //Wait for PV bugs for MP3 duration - @MediumTest - public void testMP3CBRGetDuration() throws Exception { - int duration = CodecTest.getDuration(MediaNames.MP3CBR); - duratoinWithinTolerence = verifyDuration(duration, MediaNames.MP3CBR_LENGTH); - assertTrue("MP3CBR getDuration", duratoinWithinTolerence); - } - - @MediumTest - public void testMP3VBRGetDuration() throws Exception { - int duration = CodecTest.getDuration(MediaNames.MP3VBR); - Log.v(TAG, "getDuration"); - duratoinWithinTolerence = verifyDuration(duration, MediaNames.MP3VBR_LENGTH); - assertTrue("MP3VBR getDuration", duratoinWithinTolerence); - } - - @MediumTest - public void testMIDIGetDuration() throws Exception { - int duration = CodecTest.getDuration(MediaNames.MIDI); - duratoinWithinTolerence = verifyDuration(duration, MediaNames.MIDI_LENGTH); - assertTrue("MIDI getDuration", duratoinWithinTolerence); - } - - @MediumTest - public void testAMRGetDuration() throws Exception { - int duration = CodecTest.getDuration(MediaNames.AMR); - duratoinWithinTolerence = verifyDuration(duration, MediaNames.AMR_LENGTH); - assertTrue("AMR getDuration", duratoinWithinTolerence); - } - - /* - public void testOGGGetDuration() throws Exception { - int duration = CodecTest.getDuration(MediaNames.OGG); - duratoinWithinTolerence = verifyDuration(duration, MediaNames.OGG_LENGTH); - assertTrue("OGG getDuration", duratoinWithinTolerence); - }*/ - - - //Test cases for GetCurrentPosition - @LargeTest - public void testMP3CBRGetCurrentPosition() throws Exception { - boolean currentPosition = CodecTest.getCurrentPosition(MediaNames.MP3CBR); - assertTrue("MP3CBR GetCurrentPosition", currentPosition); - } - - @LargeTest - public void testMP3VBRGetCurrentPosition() throws Exception { - boolean currentPosition = CodecTest.getCurrentPosition(MediaNames.MP3VBR); - assertTrue("MP3VBR GetCurrentPosition", currentPosition); - } - - @LargeTest - public void testMIDIGetCurrentPosition() throws Exception { - boolean currentPosition = CodecTest.getCurrentPosition(MediaNames.MIDI); - assertTrue("MIDI GetCurrentPosition", currentPosition); - } - - @LargeTest - public void testAMRGetCurrentPosition() throws Exception { - boolean currentPosition = CodecTest.getCurrentPosition(MediaNames.AMR); - assertTrue("AMR GetCurrentPosition", currentPosition); - } - - /* - public void testOGGGetCurrentPosition() throws Exception { - boolean currentPosition = CodecTest.getCurrentPosition(MediaNames.OGG); - assertTrue("OGG GetCurrentPosition", currentPosition); - */ - - //Test cases for pause - @LargeTest - public void testMP3CBRPause() throws Exception { - boolean isPaused = CodecTest.pause(MediaNames.MP3CBR); - assertTrue("MP3CBR Pause", isPaused); - } - - @LargeTest - public void testMP3VBRPause() throws Exception { - boolean isPaused = CodecTest.pause(MediaNames.MP3VBR); - assertTrue("MP3VBR Pause", isPaused); - } - - @LargeTest - public void testMIDIPause() throws Exception { - boolean isPaused = CodecTest.pause(MediaNames.MIDI); - assertTrue("MIDI Pause", isPaused); - } - - @LargeTest - public void testAMRPause() throws Exception { - boolean isPaused = CodecTest.pause(MediaNames.AMR); - assertTrue("AMR Pause", isPaused); - } - - /* - public void testOGGPause() throws Exception { - boolean isPaused = CodecTest.pause(MediaNames.OGG); - assertTrue("OGG Pause", isPaused); - }*/ - - @MediumTest - public void testMP3CBRPrepareStopRelease() throws Exception { - CodecTest.prepareStopRelease(MediaNames.MP3CBR); - assertTrue("MP3CBR prepareStopRelease", true); - } - - @MediumTest - public void testMIDIPrepareStopRelease() throws Exception { - CodecTest.prepareStopRelease(MediaNames.MIDI); - assertTrue("MIDI prepareStopRelease", true); - } - - //One test case for seek before start - @MediumTest - public void testMP3CBRSeekBeforeStart() throws Exception { - boolean seekBeforePlay = CodecTest.seektoBeforeStart(MediaNames.MP3CBR); - assertTrue("MP3CBR SeekBeforePlay", seekBeforePlay); - } - - //Skip test - Bug# 1120249 - /* - public void testMP3CBRpreparePauseRelease() throws Exception { - CodecTest.preparePauseRelease(MediaNames.MP3CBR); - assertTrue("MP3CBR preparePauseRelease", true); - } - - public void testMIDIpreparePauseRelease() throws Exception { - CodecTest.preparePauseRelease(MediaNames.MIDI); - assertTrue("MIDI preparePauseRelease", true); - } - */ - - - //Test cases for setLooping - @LargeTest - public void testMP3CBRSetLooping() throws Exception { - boolean isLoop = CodecTest.setLooping(MediaNames.MP3CBR); - assertTrue("MP3CBR setLooping", isLoop); - } - - @LargeTest - public void testMP3VBRSetLooping() throws Exception { - boolean isLoop = CodecTest.setLooping(MediaNames.MP3VBR); - Log.v(TAG, "setLooping"); - assertTrue("MP3VBR setLooping", isLoop); - } - - @LargeTest - public void testMIDISetLooping() throws Exception { - boolean isLoop = CodecTest.setLooping(MediaNames.MIDI); - assertTrue("MIDI setLooping", isLoop); - } - - @LargeTest - public void testAMRSetLooping() throws Exception { - boolean isLoop = CodecTest.setLooping(MediaNames.AMR); - assertTrue("AMR setLooping", isLoop); - } - - /* - public void testOGGSetLooping() throws Exception { - boolean isLoop = CodecTest.setLooping(MediaNames.OGG); - assertTrue("OGG setLooping", isLoop); - } */ - - //Test cases for seekTo - @LargeTest - public void testMP3CBRSeekTo() throws Exception { - boolean isLoop = CodecTest.seekTo(MediaNames.MP3CBR); - assertTrue("MP3CBR seekTo", isLoop); - } - - @LargeTest - public void testMP3VBRSeekTo() throws Exception { - boolean isLoop = CodecTest.seekTo(MediaNames.MP3VBR); - Log.v(TAG, "seekTo"); - assertTrue("MP3VBR seekTo", isLoop); - } - - @LargeTest - public void testMIDISeekTo() throws Exception { - boolean isLoop = CodecTest.seekTo(MediaNames.MIDI); - assertTrue("MIDI seekTo", isLoop); - } - - @LargeTest - public void testAMRSeekTo() throws Exception { - boolean isLoop = CodecTest.seekTo(MediaNames.AMR); - assertTrue("AMR seekTo", isLoop); - } - - /* - public void testOGGSeekTo() throws Exception { - boolean isLoop = CodecTest.seekTo(MediaNames.OGG); - assertTrue("OGG seekTo", isLoop); - }*/ - - - //Jump to the end of the files - @LargeTest - public void testMP3CBRSeekToEnd() throws Exception { - boolean isEnd = CodecTest.seekToEnd(MediaNames.MP3CBR); - assertTrue("MP3CBR seekToEnd", isEnd); - } - - @LargeTest - public void testMP3VBRSeekToEnd() throws Exception { - boolean isEnd = CodecTest.seekToEnd(MediaNames.MP3VBR); - Log.v(TAG, "seekTo"); - assertTrue("MP3VBR seekToEnd", isEnd); - } - - @LargeTest - public void testMIDISeekToEnd() throws Exception { - boolean isEnd = CodecTest.seekToEnd(MediaNames.MIDI); - assertTrue("MIDI seekToEnd", isEnd); - } - - @LargeTest - public void testAMRSeekToEnd() throws Exception { - boolean isEnd = CodecTest.seekToEnd(MediaNames.AMR); - assertTrue("AMR seekToEnd", isEnd); - } - - /* - public void testOGGSeekToEnd() throws Exception { - boolean isEnd = CodecTest.seekToEnd(MediaNames.OGG); - assertTrue("OGG seekToEnd", isEnd); - }*/ - - @LargeTest - public void testWAVSeekToEnd() throws Exception { - boolean isEnd = CodecTest.seekToEnd(MediaNames.WAV); - assertTrue("WAV seekToEnd", isEnd); - } - - @MediumTest - public void testLargeVideoHeigth() throws Exception { - int height = 0; - height = CodecTest.videoHeight(MediaNames.VIDEO_LARGE_SIZE_3GP); - Log.v(TAG, "Video height = " + height); - assertEquals("streaming video height", 240, height); - } - - @MediumTest - public void testLargeVideoWidth() throws Exception { - int width = 0; - width = CodecTest.videoWidth(MediaNames.VIDEO_LARGE_SIZE_3GP); - Log.v(TAG, "Video width = " + width); - assertEquals("streaming video width", 320, width); - } - - @LargeTest - public void testVideoMP4SeekTo() throws Exception { - boolean isSeek = CodecTest.videoSeekTo(MediaNames.VIDEO_MP4); - assertTrue("Local MP4 SeekTo", isSeek); - } - - @LargeTest - public void testVideoH263AACSeekTo() throws Exception { - boolean isSeek = CodecTest.videoSeekTo(MediaNames.VIDEO_H263_AAC); - assertTrue("H263AAC SeekTo", isSeek); - } - - @LargeTest - public void testVideoH263AMRSeekTo() throws Exception { - boolean isSeek = CodecTest.videoSeekTo(MediaNames.VIDEO_H263_AMR); - assertTrue("H263AMR SeekTo", isSeek); - } - - @LargeTest - public void testVideoH264AACSeekTo() throws Exception { - boolean isSeek = CodecTest.videoSeekTo(MediaNames.VIDEO_H264_AAC); - assertTrue("H264AAC SeekTo", isSeek); - } - - @LargeTest - public void testVideoH264AMRSeekTo() throws Exception { - boolean isSeek = CodecTest.videoSeekTo(MediaNames.VIDEO_H264_AMR); - assertTrue("H264AMR SeekTo", isSeek); - } - - @LargeTest - public void testVideoWebmSeekTo() throws Exception { - boolean isSeek = CodecTest.videoSeekTo(MediaNames.VIDEO_WEBM); - assertTrue("WEBM SeekTo", isSeek); - } - - @LargeTest - public void testSoundRecord() throws Exception { - boolean isRecordered = CodecTest.mediaRecorderRecord(MediaNames.RECORDER_OUTPUT); - assertTrue("Recorder", isRecordered); - } - - @LargeTest - public void testGetThumbnail() throws Exception { - boolean getThumbnail = CodecTest.getThumbnail(MediaNames.VIDEO_H264_AAC, MediaNames.GOLDEN_THUMBNAIL_OUTPUT); - assertTrue("Get Thumbnail", getThumbnail); - } - - //Play a mid file which the duration is around 210 seconds - @LargeTest - public void testMidiResources() throws Exception { - boolean midiResources = CodecTest.resourcesPlayback(MediaFrameworkTest.midiafd,16000); - assertTrue("Play midi from resources", midiResources); - } - - @LargeTest - public void testMp3Resources() throws Exception { - boolean mp3Resources = CodecTest.resourcesPlayback(MediaFrameworkTest.mp3afd,25000); - assertTrue("Play mp3 from resources", mp3Resources); - } - - @MediumTest - public void testPrepareAsyncReset() throws Exception { - //assertTrue(MediaFrameworkTest.checkStreamingServer()); - boolean isReset = CodecTest.prepareAsyncReset(MediaNames.STREAM_MP3); - assertTrue("PrepareAsync Reset", isReset); - } - - @MediumTest - public void testIsLooping() throws Exception { - boolean isLooping = CodecTest.isLooping(MediaNames.AMR); - assertTrue("isLooping", isLooping); - } - - @MediumTest - public void testIsLoopingAfterReset() throws Exception { - boolean isLooping = CodecTest.isLoopingAfterReset(MediaNames.AMR); - assertTrue("isLooping after reset", isLooping); - } - - @LargeTest - public void testLocalMp3PrepareAsyncCallback() throws Exception { - boolean onPrepareSuccess = - CodecTest.prepareAsyncCallback(MediaNames.MP3CBR, false); - assertTrue("LocalMp3prepareAsyncCallback", onPrepareSuccess); - } - - @LargeTest - public void testLocalH263AMRPrepareAsyncCallback() throws Exception { - boolean onPrepareSuccess = - CodecTest.prepareAsyncCallback(MediaNames.VIDEO_H263_AMR, false); - assertTrue("testLocalH263AMRPrepareAsyncCallback", onPrepareSuccess); - } - - @LargeTest - public void testStreamPrepareAsyncCallback() throws Exception { - //assertTrue(MediaFrameworkTest.checkStreamingServer()); - boolean onPrepareSuccess = - CodecTest.prepareAsyncCallback(MediaNames.STREAM_H264_480_360_1411k, false); - assertTrue("StreamH264PrepareAsyncCallback", onPrepareSuccess); - } - - @LargeTest - public void testStreamPrepareAsyncCallbackReset() throws Exception { - //assertTrue(MediaFrameworkTest.checkStreamingServer()); - boolean onPrepareSuccess = - CodecTest.prepareAsyncCallback(MediaNames.STREAM_H264_480_360_1411k, true); - assertTrue("StreamH264PrepareAsyncCallback", onPrepareSuccess); - } -} diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaPresetReverbTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaPresetReverbTest.java deleted file mode 100644 index 242e6bb..0000000 --- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaPresetReverbTest.java +++ /dev/null @@ -1,368 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.mediaframeworktest.functional; - -import com.android.mediaframeworktest.MediaFrameworkTest; -import com.android.mediaframeworktest.MediaNames; -import android.content.Context; -import android.content.res.AssetFileDescriptor; -import android.media.audiofx.AudioEffect; -import android.media.AudioManager; -import android.media.audiofx.PresetReverb; -import android.media.audiofx.Visualizer; -import android.media.MediaPlayer; - -import android.os.Looper; -import android.test.suitebuilder.annotation.LargeTest; -import android.test.suitebuilder.annotation.MediumTest; -import android.test.suitebuilder.annotation.Suppress; -import android.test.ActivityInstrumentationTestCase2; -import android.util.Log; - -import java.nio.ByteOrder; -import java.nio.ByteBuffer; -import java.util.UUID; - -/** - * Junit / Instrumentation test case for the media AudioTrack api - - */ -public class MediaPresetReverbTest extends ActivityInstrumentationTestCase2 { - private String TAG = "MediaPresetReverbTest"; - - private PresetReverb mReverb = null; - private int mSession = -1; - - public MediaPresetReverbTest() { - super("com.android.mediaframeworktest", MediaFrameworkTest.class); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - } - - @Override - protected void tearDown() throws Exception { - super.tearDown(); - releaseReverb(); - } - - private static void assumeTrue(String message, boolean cond) { - assertTrue("(assume)"+message, cond); - } - - private void log(String testName, String message) { - Log.v(TAG, "["+testName+"] "+message); - } - - private void loge(String testName, String message) { - Log.e(TAG, "["+testName+"] "+message); - } - - //----------------------------------------------------------------- - // PRESET REVEB TESTS: - //---------------------------------- - - - //----------------------------------------------------------------- - // 0 - constructor - //---------------------------------- - - //Test case 0.0: test constructor and release - @LargeTest - public void test0_0ConstructorAndRelease() throws Exception { - boolean result = false; - String msg = "test1_0ConstructorAndRelease()"; - PresetReverb reverb = null; - try { - reverb = new PresetReverb(0, 0); - assertNotNull(msg + ": could not create PresetReverb", reverb); - try { - assertTrue(msg +": invalid effect ID", (reverb.getId() != 0)); - } catch (IllegalStateException e) { - msg = msg.concat(": PresetReverb not initialized"); - } - result = true; - } catch (IllegalArgumentException e) { - msg = msg.concat(": PresetReverb not found"); - } catch (UnsupportedOperationException e) { - msg = msg.concat(": Effect library not loaded"); - } finally { - if (reverb != null) { - reverb.release(); - } - } - assertTrue(msg, result); - } - - //----------------------------------------------------------------- - // 1 - get/set parameters - //---------------------------------- - - //Test case 1.0: test preset - @LargeTest - public void test1_0Preset() throws Exception { - boolean result = false; - String msg = "test1_0Preset()"; - getReverb(0); - try { - mReverb.setPreset((short)PresetReverb.PRESET_LARGEROOM); - short preset = mReverb.getPreset(); - assertEquals(msg +": got incorrect preset", - (short)PresetReverb.PRESET_LARGEROOM, - preset); - result = true; - } catch (IllegalArgumentException e) { - msg = msg.concat(": Bad parameter value"); - loge(msg, "Bad parameter value"); - } catch (UnsupportedOperationException e) { - msg = msg.concat(": get parameter() rejected"); - loge(msg, "get parameter() rejected"); - } catch (IllegalStateException e) { - msg = msg.concat("get parameter() called in wrong state"); - loge(msg, "get parameter() called in wrong state"); - } finally { - releaseReverb(); - } - assertTrue(msg, result); - } - - //Test case 1.1: test properties - @LargeTest - public void test1_1Properties() throws Exception { - boolean result = false; - String msg = "test1_1Properties()"; - getReverb(0); - try { - PresetReverb.Settings settings = mReverb.getProperties(); - short newPreset = (short)PresetReverb.PRESET_LARGEROOM; - if (settings.preset == (short)PresetReverb.PRESET_LARGEROOM) { - newPreset = (short)PresetReverb.PRESET_SMALLROOM; - } - String str = settings.toString(); - settings = new PresetReverb.Settings(str); - settings.preset = newPreset; - mReverb.setProperties(settings); - settings = mReverb.getProperties(); - assertEquals(msg +": setProperties failed", newPreset, settings.preset); - result = true; - } catch (IllegalArgumentException e) { - msg = msg.concat(": Bad parameter value"); - loge(msg, "Bad parameter value"); - } catch (UnsupportedOperationException e) { - msg = msg.concat(": get parameter() rejected"); - loge(msg, "get parameter() rejected"); - } catch (IllegalStateException e) { - msg = msg.concat("get parameter() called in wrong state"); - loge(msg, "get parameter() called in wrong state"); - } finally { - releaseReverb(); - } - assertTrue(msg, result); - } - - //----------------------------------------------------------------- - // 2 - Effect action - //---------------------------------- - - //Test case 2.0: test actual auxiliary reverb influence on sound - @LargeTest - public void test2_0AuxiliarySoundModification() throws Exception { - boolean result = false; - String msg = "test2_0AuxiliarySoundModification()"; - EnergyProbe probe = null; - AudioEffect vc = null; - MediaPlayer mp = null; - AudioManager am = (AudioManager) getActivity().getSystemService(Context.AUDIO_SERVICE); - int volume = am.getStreamMaxVolume(AudioManager.STREAM_MUSIC); - am.setStreamVolume(AudioManager.STREAM_MUSIC, - am.getStreamMaxVolume(AudioManager.STREAM_MUSIC), - 0); - getReverb(0); - try { - probe = new EnergyProbe(0); - // 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, - UUID.fromString("119341a0-8469-11df-81f9-0002a5d5c51b"), - 0, - 0); - vc.setEnabled(true); - - mp = new MediaPlayer(); - mp.setDataSource(MediaNames.SINE_200_1000); - mp.setAudioStreamType(AudioManager.STREAM_MUSIC); - mp.attachAuxEffect(mReverb.getId()); - mp.setAuxEffectSendLevel(1.0f); - mReverb.setPreset((short)PresetReverb.PRESET_PLATE); - mReverb.setEnabled(true); - mp.prepare(); - mp.start(); - Thread.sleep(1000); - mp.stop(); - Thread.sleep(200); - // measure energy around 1kHz after media player was stopped for 200 ms - int energy1000 = probe.capture(1000); - assertTrue(msg + ": reverb has no effect", energy1000 > 0); - result = true; - } catch (IllegalArgumentException e) { - msg = msg.concat(": Bad parameter value"); - loge(msg, "Bad parameter value"); - } catch (UnsupportedOperationException e) { - msg = msg.concat(": get parameter() rejected"); - loge(msg, "get parameter() rejected"); - } catch (IllegalStateException e) { - msg = msg.concat("get parameter() called in wrong state"); - loge(msg, "get parameter() called in wrong state"); - } catch (InterruptedException e) { - loge(msg, "sleep() interrupted"); - } - finally { - releaseReverb(); - if (mp != null) { - mp.release(); - } - if (vc != null) { - vc.release(); - } - if (probe != null) { - probe.release(); - } - am.setStreamVolume(AudioManager.STREAM_MUSIC, volume, 0); - } - assertTrue(msg, result); - } - - //Test case 2.1: test actual insert reverb influence on sound - @LargeTest - public void test2_1InsertSoundModification() throws Exception { - boolean result = false; - String msg = "test2_1InsertSoundModification()"; - EnergyProbe probe = null; - AudioEffect vc = null; - MediaPlayer mp = null; - AudioEffect rvb = null; - AudioManager am = (AudioManager) getActivity().getSystemService(Context.AUDIO_SERVICE); - int volume = am.getStreamMaxVolume(AudioManager.STREAM_MUSIC); - am.setStreamVolume(AudioManager.STREAM_MUSIC, - am.getStreamMaxVolume(AudioManager.STREAM_MUSIC), - 0); - try { - // 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, - UUID.fromString("119341a0-8469-11df-81f9-0002a5d5c51b"), - 0, - 0); - vc.setEnabled(true); - - mp = new MediaPlayer(); - mp.setDataSource(MediaNames.SINE_200_1000); - mp.setAudioStreamType(AudioManager.STREAM_MUSIC); - getReverb(mp.getAudioSessionId()); - mReverb.setPreset((short)PresetReverb.PRESET_PLATE); - mReverb.setEnabled(true); - - // create reverb with UUID instead of PresetReverb constructor otherwise an auxiliary - // reverb will be chosen by the effect framework as we are on session 0 - rvb = new AudioEffect( - AudioEffect.EFFECT_TYPE_NULL, - UUID.fromString("172cdf00-a3bc-11df-a72f-0002a5d5c51b"), - 0, - 0); - - rvb.setParameter(PresetReverb.PARAM_PRESET, PresetReverb.PRESET_PLATE); - rvb.setEnabled(true); - - // create probe after reverb so that it is chained behind the reverb in the - // effect chain - probe = new EnergyProbe(0); - - mp.prepare(); - mp.start(); - Thread.sleep(1000); - mp.stop(); - Thread.sleep(200); - // measure energy around 1kHz after media player was stopped for 200 ms - int energy1000 = probe.capture(1000); - assertTrue(msg + ": reverb has no effect", energy1000 > 0); - result = true; - } catch (IllegalArgumentException e) { - msg = msg.concat(": Bad parameter value"); - loge(msg, "Bad parameter value"); - } catch (UnsupportedOperationException e) { - msg = msg.concat(": get parameter() rejected"); - loge(msg, "get parameter() rejected"); - } catch (IllegalStateException e) { - msg = msg.concat("get parameter() called in wrong state"); - loge(msg, "get parameter() called in wrong state"); - } catch (InterruptedException e) { - loge(msg, "sleep() interrupted"); - } - finally { - releaseReverb(); - if (mp != null) { - mp.release(); - } - if (vc != null) { - vc.release(); - } - if (rvb != null) { - rvb.release(); - } - if (probe != null) { - probe.release(); - } - am.setStreamVolume(AudioManager.STREAM_MUSIC, volume, 0); - } - assertTrue(msg, result); - } - - //----------------------------------------------------------------- - // private methods - //---------------------------------- - - private void getReverb(int session) { - if (mReverb == null || session != mSession) { - if (session != mSession && mReverb != null) { - mReverb.release(); - mReverb = null; - } - try { - mReverb = new PresetReverb(0, session); - mSession = session; - } catch (IllegalArgumentException e) { - Log.e(TAG, "getReverb() PresetReverb not found exception: "+e); - } catch (UnsupportedOperationException e) { - Log.e(TAG, "getReverb() Effect library not loaded exception: "+e); - } - } - assertNotNull("could not create mReverb", mReverb); - } - - private void releaseReverb() { - if (mReverb != null) { - mReverb.release(); - mReverb = null; - } - } - -} - diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaPropertiesTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaPropertiesTest.java deleted file mode 100755 index 0ad6760..0000000 --- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaPropertiesTest.java +++ /dev/null @@ -1,774 +0,0 @@ -/* - * Copyright (C) 2011 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.mediaframeworktest.functional; - -import java.io.File; -import java.io.IOException; - -import android.media.videoeditor.AudioTrack; -import android.media.videoeditor.MediaImageItem; -import android.media.videoeditor.MediaItem; -import android.media.videoeditor.MediaProperties; -import android.media.videoeditor.MediaVideoItem; -import android.media.videoeditor.VideoEditor; -import android.os.Environment; -import android.test.ActivityInstrumentationTestCase; -import android.test.suitebuilder.annotation.LargeTest; -import com.android.mediaframeworktest.MediaFrameworkTest; -import com.android.mediaframeworktest.VideoEditorHelper; -import com.android.mediaframeworktest.MediaProfileReader; - -public class MediaPropertiesTest extends - ActivityInstrumentationTestCase { - private final String TAG = "MediaPropertiesTest"; - - private final String PROJECT_LOCATION = VideoEditorHelper.PROJECT_LOCATION_COMMON; - - private final String INPUT_FILE_PATH = VideoEditorHelper.INPUT_FILE_PATH_COMMON; - - private VideoEditor mVideoEditor; - - private VideoEditorHelper mVideoEditorHelper; - - public MediaPropertiesTest() { - super("com.android.mediaframeworktest", MediaFrameworkTest.class); - } - - @Override - protected void setUp() throws Exception { - // setup for each test case. - super.setUp(); - mVideoEditorHelper = new VideoEditorHelper(); - // Create a random String which will be used as project path, - // where all project related files will be stored. - final String projectPath = mVideoEditorHelper. - createRandomFile(PROJECT_LOCATION); - mVideoEditor = mVideoEditorHelper.createVideoEditor(projectPath); - } - - @Override - protected void tearDown() throws Exception { - mVideoEditorHelper.destroyVideoEditor(mVideoEditor); - // Clean the directory created as project path - mVideoEditorHelper.deleteProject(new File(mVideoEditor.getPath())); - System.gc(); - super.tearDown(); - } - - protected void validateVideoProperties(int aspectRatio, int fileType, - int videoCodecType, int duration, int videoBitrate, int fps, - int videoProfile, int videoLevel, int width, int height, int audioCodecType, - int audioSamplingFrequency, int audioChannel, int audioBitrate, - MediaVideoItem mvi) throws Exception { - assertEquals("Aspect Ratio Mismatch", aspectRatio, mvi.getAspectRatio()); - assertEquals("File Type Mismatch", fileType, mvi.getFileType()); - assertEquals("VideoCodec Mismatch", videoCodecType, mvi.getVideoType()); - - assertTrue("Video duration Mismatch", mVideoEditorHelper.checkRange ( - duration, mvi.getDuration(), 10)); - assertEquals("Video Profile " + mvi.getVideoProfile(), videoProfile, - mvi.getVideoProfile()); - assertEquals("Video Level " + mvi.getVideoLevel(), videoLevel, - mvi.getVideoLevel()); - assertEquals("Video height " + mvi.getHeight(), height, mvi.getHeight()); - assertEquals("Video width " + mvi.getWidth(), width, mvi.getWidth()); - /** Check FPS with 10% range */ - assertTrue("fps Mismatch" + mvi.getFps(), - mVideoEditorHelper.checkRange(fps, mvi.getFps(), 10)); - - assertEquals("AudioType Mismatch ", audioCodecType, mvi.getAudioType()); - assertEquals("Audio Sampling " + mvi.getAudioSamplingFrequency(), - audioSamplingFrequency, mvi.getAudioSamplingFrequency()); - // PV SW AAC codec always returns number of channels as Stereo. - // So we do not assert for number of audio channels for AAC_LC - if ( audioCodecType != MediaProperties.ACODEC_AAC_LC ) { - assertEquals("Audio Channels " + mvi.getAudioChannels(), audioChannel, - mvi.getAudioChannels()); - } - } - - protected void validateAudioProperties(int audioCodecType, int duration, - int audioSamplingFrequency, int audioChannel, int audioBitrate, - AudioTrack aT) throws Exception { - assertEquals("AudioType Mismatch ", audioCodecType, aT.getAudioType()); - assertTrue("Video duration Mismatch", mVideoEditorHelper.checkRange ( - duration, aT.getDuration(), 10)); - assertEquals("Audio Sampling " + aT.getAudioSamplingFrequency(), - audioSamplingFrequency, aT.getAudioSamplingFrequency()); - // PV SW AAC codec always returns number of channels as Stereo. - // So we do not assert for number of audio channels for AAC_LC - if ( audioCodecType != MediaProperties.ACODEC_AAC_LC ) { - assertEquals("Audio Channels " + aT.getAudioChannels(), audioChannel, - aT.getAudioChannels()); - } - } - - protected void validateImageProperties(int aspectRatio, int fileType, - int width, int height, MediaImageItem mii) - throws Exception { - assertEquals("Aspect Ratio Mismatch", aspectRatio, mii.getAspectRatio()); - assertEquals("File Type Mismatch", fileType, mii.getFileType()); - assertEquals("Image height " + mii.getHeight(), height, mii.getHeight()); - assertEquals("Image width " + mii.getWidth(), width, mii.getWidth()); - } - - - /** - *To test Media Properties for file MPEG4 854 x 480 - */ - // TODO : Remove TC_MP_001 - @LargeTest - public void testPropertiesMPEG4854_480() throws Exception { - final String videoItemFilename = INPUT_FILE_PATH - + "MPEG4_SP_854x480_15fps_256kbps_AACLC_16khz_48kbps_s_0_26.mp4"; - final int aspectRatio = MediaProperties.ASPECT_RATIO_16_9; - final int fileType = MediaProperties.FILE_MP4; - final int videoCodecType = MediaProperties.VCODEC_MPEG4; - final int duration = 26933; - final int videoBitrate = 319000; - final int audioBitrate = 48000; - final int fps = 15; - final int audioCodecType = MediaProperties.ACODEC_AAC_LC; - final int audioSamplingFrequency = 16000; - final int audioChannel = 2; - final int videoProfile = MediaProperties.MPEG4Profile.MPEG4ProfileSimple; - final int videoLevel = MediaProperties.MPEG4Level.MPEG4Level1; - final int width = 854; - final int height = MediaProperties.HEIGHT_480; - - final MediaVideoItem mvi = mVideoEditorHelper.createMediaItem - (mVideoEditor, "m1", videoItemFilename, - MediaItem.RENDERING_MODE_BLACK_BORDER); - - validateVideoProperties(aspectRatio, fileType, videoCodecType, duration, - videoBitrate, fps, videoProfile, videoLevel, width, height, audioCodecType, - audioSamplingFrequency, audioChannel, audioBitrate, mvi); - } - - - /** - *To test Media Properties for file MPEG4 WVGA - */ - // TODO : Remove TC_MP_002 - @LargeTest - public void testPropertiesMPEGWVGA() throws Exception { - final String videoItemFilename = INPUT_FILE_PATH - + "MPEG4_SP_800x480_515kbps_15fps_AMR_NB_8KHz_12.2kbps_m_0_26.mp4"; - final int aspectRatio = MediaProperties.ASPECT_RATIO_5_3; - final int fileType = MediaProperties.FILE_MP4; - final int videoCodecType = MediaProperties.VCODEC_MPEG4; - final int duration = 26933; - final int videoBitrate = 384000; - final int audioBitrate = 12800; - final int fps = 15; - final int audioCodecType = MediaProperties.ACODEC_AMRNB; - final int audioSamplingFrequency = 8000; - final int audioChannel = 1; - final int videoProfile = MediaProperties.MPEG4Profile.MPEG4ProfileSimple; - final int videoLevel = MediaProperties.MPEG4Level.MPEG4Level1; - final int width = 800; - final int height = MediaProperties.HEIGHT_480; - final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; - - final MediaVideoItem mvi = mVideoEditorHelper.createMediaItem - (mVideoEditor, "m1", videoItemFilename, renderingMode); - - validateVideoProperties(aspectRatio, fileType, videoCodecType, duration, - videoBitrate, fps, videoProfile, videoLevel, width, height, audioCodecType, - audioSamplingFrequency, audioChannel, audioBitrate, mvi); - } - - /** - *To test media properties for MPEG4 720x480 (NTSC) + AAC file. - */ - // TODO : Remove TC_MP_003 - @LargeTest - public void testPropertiesMPEGNTSC() throws Exception { - final String videoItemFilename = INPUT_FILE_PATH - + "MPEG4_SP_720x480_30fps_280kbps_AACLC_48kHz_161kbps_s_0_26.mp4"; - final int aspectRatio = MediaProperties.ASPECT_RATIO_3_2; - final int fileType = MediaProperties.FILE_MP4; - final int videoCodecType = MediaProperties.VCODEC_MPEG4; - final int duration = 26866; - final int videoBitrate = 403000; - final int audioBitrate = 160000; - final int fps = 30; - final int audioCodecType = MediaProperties.ACODEC_AAC_LC; - final int audioSamplingFrequency = 48000; - final int audioChannel = 2; - final int videoProfile = MediaProperties.MPEG4Profile.MPEG4ProfileSimple; - final int videoLevel = MediaProperties.MPEG4Level.MPEG4Level1; - final int width = 720; - final int height = MediaProperties.HEIGHT_480; - final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; - - final MediaVideoItem mvi = mVideoEditorHelper.createMediaItem - (mVideoEditor, "m1", videoItemFilename, renderingMode); - - validateVideoProperties(aspectRatio, fileType, videoCodecType, duration, - videoBitrate, fps, videoProfile, videoLevel, width, height, audioCodecType, - audioSamplingFrequency, audioChannel, audioBitrate, mvi); - } - - /** - *To test Media Properties for file MPEG4 VGA - */ - // TODO : Remove TC_MP_004 - @LargeTest - public void testPropertiesMPEGVGA() throws Exception { - final String videoItemFilename = INPUT_FILE_PATH - + "MPEG4_SP_640x480_15fps_512kbps_AACLC_48khz_132kbps_s_0_26.mp4"; - final int aspectRatio = MediaProperties.ASPECT_RATIO_4_3; - final int fileType = MediaProperties.FILE_MP4; - final int videoCodecType = MediaProperties.VCODEC_MPEG4; - final int duration = 26933; - final int videoBitrate = 533000; - final int audioBitrate = 128000; - final int fps = 15; - final int audioCodecType = MediaProperties.ACODEC_AAC_LC; - final int audioSamplingFrequency = 48000; - final int audioChannel = 2; - final int videoProfile = MediaProperties.MPEG4Profile.MPEG4ProfileSimple; - final int videoLevel = MediaProperties.MPEG4Level.MPEG4Level1; - final int width = 640; - final int height = MediaProperties.HEIGHT_480; - final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; - - final MediaVideoItem mvi = mVideoEditorHelper.createMediaItem - (mVideoEditor, "m1", videoItemFilename, renderingMode); - - validateVideoProperties(aspectRatio, fileType, videoCodecType, duration, - videoBitrate, fps, videoProfile, videoLevel, width, height, audioCodecType, - audioSamplingFrequency, audioChannel, audioBitrate, mvi); - } - - /** - *To test Media Properties for file MPEG4 QCIF - */ - // TODO : Remove TC_MP_005 - @LargeTest - public void testPropertiesMPEGQCIF() throws Exception { - final String videoItemFilename = INPUT_FILE_PATH - + "MPEG4_SP_176x144_12fps_92kbps_AMRNB_8KHz_12.2kbps_m_0_27.3gp"; - final int aspectRatio = MediaProperties.ASPECT_RATIO_11_9; - final int fileType = MediaProperties.FILE_3GP; - final int videoCodecType = MediaProperties.VCODEC_MPEG4; - final int duration = 27000; - final int videoBitrate = 384000; - final int audioBitrate = 12200; - final int fps = 12; - final int audioCodecType = MediaProperties.ACODEC_AMRNB; - final int audioSamplingFrequency = 8000; - final int audioChannel = 1; - final int videoProfile = MediaProperties.MPEG4Profile.MPEG4ProfileSimple; - final int videoLevel = MediaProperties.MPEG4Level.MPEG4Level1; - final int width = 176; - final int height = MediaProperties.HEIGHT_144; - final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; - - final MediaVideoItem mvi = mVideoEditorHelper.createMediaItem - (mVideoEditor, "m1", videoItemFilename, renderingMode); - - validateVideoProperties(aspectRatio, fileType, videoCodecType, duration, - videoBitrate, fps, videoProfile, videoLevel, width, height, audioCodecType, - audioSamplingFrequency, audioChannel, audioBitrate, mvi); - } - - /** - *To To test media properties for H263 176x144 (QCIF) + AAC (mono) file. - */ - // TODO : Remove TC_MP_006 - @LargeTest - public void testPropertiesH263QCIF() throws Exception { - final String videoItemFilename = INPUT_FILE_PATH - + "H263_profile0_176x144_15fps_256kbps_AACLC_16kHz_32kbps_m_0_26.3gp"; - final int aspectRatio = MediaProperties.ASPECT_RATIO_11_9; - final int fileType = MediaProperties.FILE_3GP; - final int videoCodecType = MediaProperties.VCODEC_H263; - final int duration = 26933; - final int videoBitrate = 384000; - final int audioBitrate = 64000; - final int fps = 15; - final int audioCodecType = MediaProperties.ACODEC_AAC_LC; - final int audioSamplingFrequency = 16000; - final int audioChannel = 1; - final int videoProfile = MediaProperties.H263Profile.H263ProfileBaseline; - final int videoLevel = MediaProperties.H263Level.H263Level10; - final int width = 176; - final int height = MediaProperties.HEIGHT_144; - final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; - final MediaVideoItem mvi = mVideoEditorHelper.createMediaItem - (mVideoEditor, "m1", videoItemFilename, renderingMode); - - validateVideoProperties(aspectRatio, fileType, videoCodecType, duration, - videoBitrate, fps, videoProfile, videoLevel, width, height, audioCodecType, - audioSamplingFrequency, audioChannel, audioBitrate, mvi); - } - - /** - *To test Media Properties for file H264 VGA - */ - // TODO : Remove TC_MP_007 - @LargeTest - public void testPropertiesH264VGA() throws Exception { - final String videoItemFilename = INPUT_FILE_PATH - + "H264_BP_640x480_15fps_1200Kbps_AACLC_48KHz_64kps_m_0_27.3gp"; - final int aspectRatio = MediaProperties.ASPECT_RATIO_4_3; - final int fileType = MediaProperties.FILE_3GP; - final int videoCodecType = MediaProperties.VCODEC_H264; - final int duration = 77600; - final int videoBitrate = 745000; - final int audioBitrate = 64000; - final int fps = 15; - final int audioCodecType = MediaProperties.ACODEC_AAC_LC; - final int audioSamplingFrequency = 48000; - final int audioChannel = 2; - final int videoProfile = MediaProperties.H264Profile.H264ProfileBaseline; - final int videoLevel = MediaProperties.H264Level.H264Level13; - final int width = 640; - final int height = MediaProperties.HEIGHT_480; - final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; - final MediaVideoItem mvi = mVideoEditorHelper.createMediaItem - (mVideoEditor, "m1", videoItemFilename, renderingMode); - - validateVideoProperties(aspectRatio, fileType, videoCodecType, duration, - videoBitrate, fps, videoProfile, videoLevel, width, height, audioCodecType, - audioSamplingFrequency, audioChannel, audioBitrate, mvi); - } - - /** - *To test Media Properties for file H264 NTSC - */ - // TODO : Remove TC_MP_008 - @LargeTest - public void testPropertiesH264NTSC() throws Exception { - final String videoItemFilename = INPUT_FILE_PATH - + "H264_BP_720x480_25fps_256kbps_AMRNB_8khz_12.2kbps_m_0_26.mp4"; - final int aspectRatio = MediaProperties.ASPECT_RATIO_3_2; - final int fileType = MediaProperties.FILE_MP4; - final int videoCodecType = MediaProperties.VCODEC_H264; - final int duration = 26880; - final int videoBitrate = 244000; - final int audioBitrate = 12200; - final int fps = 25; - final int audioCodecType = MediaProperties.ACODEC_AMRNB; - final int audioSamplingFrequency = 8000; - final int audioChannel = 1; - final int videoProfile = MediaProperties.H264Profile.H264ProfileBaseline; - final int videoLevel = MediaProperties.H264Level.H264Level13; - final int width = 720; - final int height = MediaProperties.HEIGHT_480; - final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; - - final MediaVideoItem mvi = mVideoEditorHelper.createMediaItem - (mVideoEditor, "m1", videoItemFilename, renderingMode); - - validateVideoProperties(aspectRatio, fileType, videoCodecType, duration, - videoBitrate, fps, videoProfile, videoLevel, width, height, audioCodecType, - audioSamplingFrequency, audioChannel, audioBitrate, mvi); - } - - /** - *To test media properties for H264 800x480 (WVGA) + AAC file. - */ - // TODO : Remove TC_MP_009 - @LargeTest - public void testPropertiesH264WVGA() throws Exception { - final String videoItemFilename = INPUT_FILE_PATH + - "H264_BP_800x480_15fps_512kbps_AACLC_24KHz_38Kbps_s_1_17.mp4"; - final int aspectRatio = MediaProperties.ASPECT_RATIO_5_3; - final int fileType = MediaProperties.FILE_MP4; - final int videoCodecType = MediaProperties.VCODEC_H264; - final int duration = 77466; - final int videoBitrate = 528000; - final int audioBitrate = 38000; - final int fps = 15; - final int audioCodecType = MediaProperties.ACODEC_AAC_LC; - final int audioSamplingFrequency = 24000; - final int audioChannel = 2; - final int videoProfile = MediaProperties.H264Profile.H264ProfileBaseline; - final int videoLevel = MediaProperties.H264Level.H264Level13; - final int width = 800; - final int height = MediaProperties.HEIGHT_480; - final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; - - final MediaVideoItem mvi = mVideoEditorHelper.createMediaItem - (mVideoEditor, "m1", videoItemFilename, renderingMode); - - validateVideoProperties(aspectRatio, fileType, videoCodecType, duration, - videoBitrate, fps, videoProfile, videoLevel, width, height, audioCodecType, - audioSamplingFrequency, audioChannel, audioBitrate, mvi); - } - - /** - *To test Media Properties for file H264 HD1280 - */ - // TODO : Remove TC_MP_010 - @LargeTest - public void testPropertiesH264HD1280() throws Exception { - final String videoItemFilename = INPUT_FILE_PATH - + "H264_BP_1280x720_15fps_512kbps_AACLC_16khz_48kbps_s_1_17.mp4"; - final int aspectRatio = MediaProperties.ASPECT_RATIO_16_9; - final int fileType = MediaProperties.FILE_MP4; - final int videoCodecType = MediaProperties.VCODEC_H264; - final int duration = 77600; - final int videoBitrate = 606000; - final int audioBitrate = 48000; - final int fps = 15; - final int audioCodecType = MediaProperties.ACODEC_AAC_LC; - final int audioSamplingFrequency = 16000; - final int audioChannel = 2; - final int videoProfile = MediaProperties.H264Profile.H264ProfileBaseline; - final int videoLevel = MediaProperties.H264Level.H264Level13; - final int width = 1280; - final int height = MediaProperties.HEIGHT_720; - final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; - - final MediaVideoItem mvi = mVideoEditorHelper.createMediaItem - (mVideoEditor, "m1", videoItemFilename, renderingMode); - - validateVideoProperties(aspectRatio, fileType, videoCodecType, duration, - videoBitrate, fps, videoProfile, videoLevel, width, height, audioCodecType, - audioSamplingFrequency, audioChannel, audioBitrate, mvi); - } - - /** - *To test media properties for H264 1080x720 + AAC file - */ - // TODO : Remove TC_MP_011 - @LargeTest - public void testPropertiesH264HD1080WithAudio() throws Exception { - final String videoItemFilename = INPUT_FILE_PATH - + "H264_BP_1080x720_30fps_12Mbps_AACLC_44.1khz_64kbps_s_1_17.mp4"; - final int aspectRatio = MediaProperties.ASPECT_RATIO_3_2; - final int fileType = MediaProperties.FILE_MP4; - final int videoCodecType = MediaProperties.VCODEC_H264; - final int duration = 77500; - final int videoBitrate = 1190000; - final int audioBitrate = 64000; - final int fps = 10; - final int audioCodecType = MediaProperties.ACODEC_AAC_LC; - final int audioSamplingFrequency = 44100; - final int audioChannel = 2; - final int videoProfile = MediaProperties.H264Profile.H264ProfileBaseline; - final int videoLevel = MediaProperties.H264Level.H264Level13; - final int width = 1080; - final int height = MediaProperties.HEIGHT_720; - final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; - - final MediaVideoItem mvi = mVideoEditorHelper.createMediaItem - (mVideoEditor, "m1", videoItemFilename, renderingMode); - - validateVideoProperties(aspectRatio, fileType, videoCodecType, duration, - videoBitrate, fps, videoProfile, videoLevel, width, height, audioCodecType, - audioSamplingFrequency, audioChannel, audioBitrate, mvi); - } - - /** - *To test Media Properties for file WMV - Unsupported type - */ - // TODO : Remove TC_MP_012 - @LargeTest - public void testPropertiesWMVFile() throws Exception { - final String videoItemFilename = INPUT_FILE_PATH + - "WMV_V7_640x480_15fps_512Kbps_wma_V9_44khz_48Kbps_s_1_30.wmv"; - boolean flagForException = false; - if (MediaProfileReader.getWMVEnable() == false) { - flagForException = true; - } else { - try { - new MediaVideoItem(mVideoEditor, "m1", videoItemFilename, - MediaItem.RENDERING_MODE_BLACK_BORDER); - } catch (IllegalArgumentException e) { - flagForException = true; - } catch (IOException e) { - flagForException = true; - } - } - assertTrue("Media Properties for a WMV File -- Unsupported file type", - flagForException); - } - - /** - *To test media properties for H.264 Main/Advanced profile. - */ - // TODO : Remove TC_MP_013 - @LargeTest - public void testPropertiesH264MainLineProfile() throws Exception { - final String videoItemFilename = INPUT_FILE_PATH - + "H264_MP_960x720_25fps_800kbps_AACLC_48Khz_192Kbps_s_1_17.mp4"; - final int aspectRatio = MediaProperties.ASPECT_RATIO_4_3; - final int videoCodecType = MediaProperties.VCODEC_H264; - final int fileType = MediaProperties.FILE_MP4; - final int duration = 77500; - final int videoBitrate = 800000; - final int audioBitrate = 192000; - final int fps = 25; - final int audioCodecType = MediaProperties.ACODEC_AAC_LC; - final int audioSamplingFrequency = 48000; - final int audioChannel = 2; - final int videoProfile = MediaProperties.H264Profile.H264ProfileMain; - final int videoLevel = MediaProperties.H264Level.H264Level31; - final int width = 960; - final int height = MediaProperties.HEIGHT_720; - final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; - - final MediaVideoItem mvi = mVideoEditorHelper.createMediaItem - (mVideoEditor, "m1", videoItemFilename, renderingMode); - - validateVideoProperties(aspectRatio, fileType, videoCodecType, duration, - videoBitrate, fps, videoProfile, videoLevel, width, height, audioCodecType, - audioSamplingFrequency, audioChannel, audioBitrate, mvi); - - } - - /** - *To test Media Properties for non existing file. - */ - // TODO : Remove TC_MP_014 - @LargeTest - public void testPropertiesForNonExsitingFile() throws Exception { - final String videoItemFilename = INPUT_FILE_PATH + "abc.3gp"; - boolean flagForException = false; - - try { - new MediaVideoItem(mVideoEditor, "m1", videoItemFilename, - MediaItem.RENDERING_MODE_BLACK_BORDER); - } catch (IllegalArgumentException e) { - flagForException = true; - } catch (IOException e) { - flagForException = true; - } - assertTrue("Media Properties for non exsisting file", flagForException); - } - - /** - *To test Media Properties for file H264 HD1080 - */ - // TODO : Remove TC_MP_015 - @LargeTest - public void testPropertiesH264HD1080WithoutAudio() throws Exception { - final String videoItemFilename = INPUT_FILE_PATH + - "H264_BP_1080x720_30fps_800kbps_1_17.mp4"; - final int aspectRatio = MediaProperties.ASPECT_RATIO_3_2; - final int fileType = MediaProperties.FILE_MP4; - final int videoCodecType = MediaProperties.VCODEC_H264; - final int duration = 77366; - final int videoBitrate = 859000; - final int audioBitrate = 0; - final int fps = 30; - final int audioCodecType = -1; - final int audioSamplingFrequency = 0; - final int audioChannel = 0; - final int videoProfile = MediaProperties.H264Profile.H264ProfileBaseline; - final int videoLevel = MediaProperties.H264Level.H264Level13; - final int width = 1080; - final int height = MediaProperties.HEIGHT_720; - final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; - - final MediaVideoItem mvi = mVideoEditorHelper.createMediaItem - (mVideoEditor, "m1", videoItemFilename, renderingMode); - - validateVideoProperties(aspectRatio, fileType, videoCodecType, duration, - videoBitrate, fps, videoProfile, videoLevel, width, height, audioCodecType, - audioSamplingFrequency, audioChannel, audioBitrate, mvi); - } - - /** - *To test Media Properties for Image file of JPEG Type - */ - // TODO : Remove TC_MP_016 - @LargeTest - public void testPropertiesVGAImage() throws Exception { - final String imageItemFilename = INPUT_FILE_PATH + "IMG_640x480.jpg"; - final int imageItemDuration = 10000; - final int aspectRatio = MediaProperties.ASPECT_RATIO_4_3; - final int fileType = MediaProperties.FILE_JPEG; - final int width = 640; - final int height = MediaProperties.HEIGHT_480; - final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; - - final MediaImageItem mii = mVideoEditorHelper.createMediaItem - (mVideoEditor, "m1", imageItemFilename, imageItemDuration, - renderingMode); - validateImageProperties(aspectRatio, fileType, width, height, mii); - } - - /** - *To test Media Properties for Image file of PNG Type - */ - // TODO : Remove TC_MP_017 - @LargeTest - public void testPropertiesPNG() throws Exception { - final String imageItemFilename = INPUT_FILE_PATH + "IMG_640x480.png"; - final int imageItemDuration = 10000; - final int aspectRatio = MediaProperties.ASPECT_RATIO_4_3; - final int fileType = MediaProperties.FILE_PNG; - final int width = 640; - final int height = 480; - final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; - final MediaImageItem mii = mVideoEditorHelper.createMediaItem - (mVideoEditor, "m1", imageItemFilename, imageItemDuration, - renderingMode); - validateImageProperties(aspectRatio, fileType, width, height, mii); - } - - /** - *To test Media Properties for file GIF - Unsupported type - */ - // TODO : Remove TC_MP_018 - @LargeTest - public void testPropertiesGIFFile() throws Exception { - - final String imageItemFilename = INPUT_FILE_PATH + "IMG_640x480.gif"; - final int imageItemDuration = 10000; - final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; - boolean flagForException = false; - try { - new MediaImageItem(mVideoEditor, "m1", imageItemFilename, - imageItemDuration, renderingMode); - } catch (IllegalArgumentException e) { - flagForException = true; - } - assertTrue("Media Properties for a GIF File -- Unsupported file type", - flagForException); - } - - /** - *To test Media Properties for file Text file named as 3GP - */ - // TODO : Remove TC_MP_019 - @LargeTest - public void testPropertiesofDirtyFile() throws Exception { - - final String videoItemFilename = INPUT_FILE_PATH + - "Text_FileRenamedTo3gp.3gp"; - boolean flagForException = false; - - try { - new MediaVideoItem(mVideoEditor, "m1", videoItemFilename, - MediaItem.RENDERING_MODE_BLACK_BORDER); - } catch (IllegalArgumentException e) { - flagForException = true; - } - assertTrue("Media Properties for a Dirty File ", - flagForException); - } - - /** - *To test Media Properties for file name as NULL - */ - // TODO : Remove TC_MP_020 - @LargeTest - public void testPropertieNULLFile() throws Exception { - final String videoItemFilename = null; - boolean flagForException = false; - final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; - try { - new MediaVideoItem(mVideoEditor, "m1", videoItemFilename, - renderingMode); - } catch (IllegalArgumentException e) { - flagForException = true; - } - assertTrue("Media Properties for NULL File ", - flagForException); - } - - /** - *To test Media Properties for file which is of type MPEG2 - */ - // TODO : Remove TC_MP_021 - @LargeTest - public void testPropertiesMPEG2File() throws Exception { - final String videoItemFilename = INPUT_FILE_PATH + - "MPEG2_640x480_30fps_192kbps_1_5.mp4"; - boolean flagForException = false; - final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; - try { - new MediaVideoItem(mVideoEditor, "m1", videoItemFilename, - renderingMode); - } catch (IllegalArgumentException e) { - flagForException = true; - } - assertTrue("Media Properties for a MPEG2 File --Unsupported file type", - flagForException); - } - - /** - *To test Media Properties TC_MP_023 for file without Video only Audio - */ - // TODO : Remove TC_MP_023 - @LargeTest - public void testProperties3GPWithoutVideoMediaItem() throws Exception { - final String audioFilename = INPUT_FILE_PATH + - "AACLC_48KHz_256Kbps_s_1_17.3gp"; - boolean flagForException = false; - final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; - try { - new MediaVideoItem(mVideoEditor, "m1", audioFilename, - renderingMode); - } catch (IllegalArgumentException e) { - flagForException = true; - } - assertTrue("Exception in Creaing Media Video item object without video", - flagForException); - } - - /** - *To test media properties for Audio Track file. (No Video, AAC Audio) - */ - // TODO : Remove TC_MP_024 - @LargeTest - public void testProperties3GPWithoutVideoAudioTrack() throws Exception { - - final String audioFilename = INPUT_FILE_PATH + - "AACLC_44.1kHz_256kbps_s_1_17.mp4"; - final int duration = 77554; - final int audioBitrate = 384000; - final int audioCodecType = MediaProperties.ACODEC_AAC_LC; - final int audioSamplingFrequency = 44100; - final int audioChannel = 2; - - final AudioTrack audioTrack = mVideoEditorHelper.createAudio - (mVideoEditor, "a1", audioFilename); - - validateAudioProperties(audioCodecType, duration, audioSamplingFrequency, - audioChannel, audioBitrate, audioTrack); - } - - /** - *To test media properties for Audio Track file. MP3 file - */ - // TODO : Remove TC_MP_025 - @LargeTest - public void testPropertiesMP3AudioTrack() throws Exception { - - final String audioFilename = INPUT_FILE_PATH + - "MP3_48KHz_128kbps_s_1_17.mp3"; - final int duration = 77640; - final int audioBitrate = 128000; - final int audioCodecType = MediaProperties.ACODEC_MP3; - final int audioSamplingFrequency = 48000; - final int audioChannel = 2; - - final AudioTrack audioTrack = mVideoEditorHelper.createAudio - (mVideoEditor, "a1", audioFilename); - - validateAudioProperties(audioCodecType, duration, audioSamplingFrequency, - audioChannel, audioBitrate, audioTrack); - } -} diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaRecorderTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaRecorderTest.java deleted file mode 100644 index 796b52c..0000000 --- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaRecorderTest.java +++ /dev/null @@ -1,302 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.mediaframeworktest.functional; - -import com.android.mediaframeworktest.MediaFrameworkTest; -import com.android.mediaframeworktest.MediaNames; - -import java.io.*; - -import android.content.Context; -import android.hardware.Camera; -import android.media.MediaPlayer; -import android.media.MediaRecorder; -import android.media.EncoderCapabilities; -import android.media.EncoderCapabilities.VideoEncoderCap; -import android.media.EncoderCapabilities.AudioEncoderCap; -import android.test.ActivityInstrumentationTestCase2; -import android.util.Log; -import android.view.SurfaceHolder; -import android.view.SurfaceView; -import com.android.mediaframeworktest.MediaProfileReader; - -import android.test.suitebuilder.annotation.LargeTest; -import android.test.suitebuilder.annotation.Suppress; -import java.util.List; - - -/** - * Junit / Instrumentation test case for the media recorder api - */ -public class MediaRecorderTest extends ActivityInstrumentationTestCase2 { - private String TAG = "MediaRecorderTest"; - private int mOutputDuration =0; - private int mOutputVideoWidth = 0; - private int mOutputVideoHeight= 0 ; - - private SurfaceHolder mSurfaceHolder = null; - private MediaRecorder mRecorder; - - private int MIN_VIDEO_FPS = 5; - - Context mContext; - Camera mCamera; - - public MediaRecorderTest() { - super("com.android.mediaframeworktest", MediaFrameworkTest.class); - - } - - protected void setUp() throws Exception { - getActivity(); - mRecorder = new MediaRecorder(); - super.setUp(); - } - - private void recordVideo(int frameRate, int width, int height, - int videoFormat, int outFormat, String outFile, boolean videoOnly) { - Log.v(TAG,"startPreviewAndPrepareRecording"); - try { - if (!videoOnly) { - Log.v(TAG, "setAudioSource"); - mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); - } - mRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA); - mRecorder.setOutputFormat(outFormat); - Log.v(TAG, "output format " + outFormat); - mRecorder.setOutputFile(outFile); - mRecorder.setVideoFrameRate(frameRate); - mRecorder.setVideoSize(width, height); - Log.v(TAG, "setEncoder"); - mRecorder.setVideoEncoder(videoFormat); - if (!videoOnly) { - mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); - } - mSurfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder(); - Log.v(TAG, "setPreview"); - mRecorder.setPreviewDisplay(mSurfaceHolder.getSurface()); - Log.v(TAG, "prepare"); - mRecorder.prepare(); - Log.v(TAG, "start"); - mRecorder.start(); - Thread.sleep(MediaNames.RECORDED_TIME); - Log.v(TAG, "stop"); - mRecorder.stop(); - mRecorder.release(); - } catch (Exception e) { - Log.v("record video failed ", e.toString()); - mRecorder.release(); - } - } - - private boolean recordVideoWithPara(VideoEncoderCap videoCap, AudioEncoderCap audioCap, boolean highQuality){ - boolean recordSuccess = false; - int videoEncoder = videoCap.mCodec; - int audioEncoder = audioCap.mCodec; - int videoWidth = highQuality? videoCap.mMaxFrameWidth: videoCap.mMinFrameWidth; - int videoHeight = highQuality? videoCap.mMaxFrameHeight: videoCap.mMinFrameHeight; - int videoFps = highQuality? videoCap.mMaxFrameRate: videoCap.mMinFrameRate; - int videoBitrate = highQuality? videoCap.mMaxBitRate: videoCap.mMinBitRate; - int audioBitrate = highQuality? audioCap.mMaxBitRate: audioCap.mMinBitRate; - int audioChannels = highQuality? audioCap.mMaxChannels: audioCap.mMinChannels ; - int audioSamplingRate = highQuality? audioCap.mMaxSampleRate: audioCap.mMinSampleRate; - - if (videoFps < MIN_VIDEO_FPS) { - videoFps = MIN_VIDEO_FPS; - } - mSurfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder(); - String filename = ("/sdcard/" + videoEncoder + "_" + audioEncoder + "_" + highQuality + ".3gp"); - try { - Log.v(TAG, "video encoder : " + videoEncoder); - Log.v(TAG, "audio encoder : " + audioEncoder); - Log.v(TAG, "quality : " + (highQuality?"high": "low")); - Log.v(TAG, "encoder : " + MediaProfileReader.getVideoCodecName(videoEncoder)); - Log.v(TAG, "audio : " + MediaProfileReader.getAudioCodecName(audioEncoder)); - Log.v(TAG, "videoWidth : " + videoWidth); - Log.v(TAG, "videoHeight : " + videoHeight); - Log.v(TAG, "videoFPS : " + videoFps); - Log.v(TAG, "videobitrate : " + videoBitrate); - Log.v(TAG, "audioBitrate : " + audioBitrate); - Log.v(TAG, "audioChannel : " + audioChannels); - Log.v(TAG, "AudioSampleRate : " + audioSamplingRate); - - MediaRecorder mMediaRecorder = new MediaRecorder(); - mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); - mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA); - mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); - mMediaRecorder.setOutputFile(filename); - mMediaRecorder.setVideoFrameRate(videoFps); - mMediaRecorder.setVideoSize(videoWidth, videoHeight); - mMediaRecorder.setVideoEncodingBitRate(videoBitrate); - mMediaRecorder.setAudioEncodingBitRate(audioBitrate); - mMediaRecorder.setAudioChannels(audioChannels); - mMediaRecorder.setAudioSamplingRate(audioSamplingRate); - mMediaRecorder.setVideoEncoder(videoEncoder); - mMediaRecorder.setAudioEncoder(audioEncoder); - mMediaRecorder.setPreviewDisplay(mSurfaceHolder.getSurface()); - mMediaRecorder.prepare(); - mMediaRecorder.start(); - Thread.sleep(MediaNames.RECORDED_TIME); - mMediaRecorder.stop(); - mMediaRecorder.release(); - recordSuccess = validateVideo(filename, videoWidth, videoHeight); - } catch (Exception e) { - Log.v(TAG, e.toString()); - return false; - } - return recordSuccess; - } - - private boolean invalidRecordSetting(int frameRate, int width, int height, - int videoFormat, int outFormat, String outFile, boolean videoOnly) { - try { - if (!videoOnly) { - Log.v(TAG, "setAudioSource"); - mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); - } - mRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA); - mRecorder.setOutputFormat(outFormat); - Log.v(TAG, "output format " + outFormat); - mRecorder.setOutputFile(outFile); - mRecorder.setVideoFrameRate(frameRate); - mRecorder.setVideoSize(width, height); - Log.v(TAG, "setEncoder"); - mRecorder.setVideoEncoder(videoFormat); - if (!videoOnly) { - mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); - } - mSurfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder(); - Log.v(TAG, "setPreview"); - mRecorder.setPreviewDisplay(mSurfaceHolder.getSurface()); - Log.v(TAG, "prepare"); - mRecorder.prepare(); - Log.v(TAG, "start"); - mRecorder.start(); - Thread.sleep(MediaNames.RECORDED_TIME); - Log.v(TAG, "stop"); - mRecorder.stop(); - mRecorder.release(); - } catch (Exception e) { - Log.v("record video failed ", e.toString()); - mRecorder.release(); - Log.v(TAG, "reset and release"); - return true; - } - return false; - } - - private void getOutputVideoProperty(String outputFilePath) { - MediaPlayer mediaPlayer = new MediaPlayer(); - try { - mediaPlayer.setDataSource(outputFilePath); - Log.v(TAG, "file Path = " + outputFilePath); - mediaPlayer.setDisplay(MediaFrameworkTest.mSurfaceView.getHolder()); - Log.v(TAG, "before player prepare"); - mediaPlayer.prepare(); - Log.v(TAG, "before getduration"); - mOutputDuration = mediaPlayer.getDuration(); - Log.v(TAG, "get video dimension"); - Thread.sleep(1000); - mOutputVideoHeight = mediaPlayer.getVideoHeight(); - mOutputVideoWidth = mediaPlayer.getVideoWidth(); - mediaPlayer.release(); - } catch (Exception e) { - Log.v(TAG, e.toString()); - mediaPlayer.release(); - } - } - - private boolean validateVideo(String filePath, int width, int height) { - boolean validVideo = false; - getOutputVideoProperty(filePath); - if (mOutputVideoWidth == width && mOutputVideoHeight == height && - mOutputDuration > MediaNames.VALID_VIDEO_DURATION ) { - validVideo = true; - } - Log.v(TAG, "width = " + mOutputVideoWidth + " height = " + mOutputVideoHeight + " Duration = " + mOutputDuration); - return validVideo; - } - - @LargeTest - /* - * This test case set the camera in portrait mode. - * Verification: validate the video dimension and the duration. - */ - public void testPortraitH263() throws Exception { - boolean videoRecordedResult = false; - try { - mCamera = Camera.open(); - Camera.Parameters parameters = mCamera.getParameters(); - parameters.setPreviewSize(352, 288); - parameters.set("orientation", "portrait"); - mCamera.setParameters(parameters); - mCamera.unlock(); - mRecorder.setCamera(mCamera); - Thread.sleep(1000); - int codec = MediaRecorder.VideoEncoder.H263; - int frameRate = MediaProfileReader.getMaxFrameRateForCodec(codec); - recordVideo(frameRate, 352, 288, codec, - MediaRecorder.OutputFormat.THREE_GPP, - MediaNames.RECORDED_PORTRAIT_H263, true); - mCamera.lock(); - mCamera.release(); - videoRecordedResult = - validateVideo(MediaNames.RECORDED_PORTRAIT_H263, 352, 288); - } catch (Exception e) { - Log.v(TAG, e.toString()); - } - assertTrue("PortraitH263", videoRecordedResult); - } - - @LargeTest - public void testInvalidVideoPath() throws Exception { - boolean isTestInvalidVideoPathSuccessful = false; - isTestInvalidVideoPathSuccessful = invalidRecordSetting(15, 176, 144, MediaRecorder.VideoEncoder.H263, - MediaRecorder.OutputFormat.THREE_GPP, MediaNames.INVALD_VIDEO_PATH, false); - assertTrue("Invalid outputFile Path", isTestInvalidVideoPathSuccessful); - } - - @LargeTest - //test cases for the new codec - public void testDeviceSpecificCodec() throws Exception { - int noOfFailure = 0; - boolean recordSuccess = false; - String deviceType = MediaProfileReader.getDeviceType(); - Log.v(TAG, "deviceType = " + deviceType); - List videoEncoders = MediaProfileReader.getVideoEncoders(); - List audioEncoders = MediaProfileReader.getAudioEncoders(); - for (int k = 0; k < 2; k++) { - for (VideoEncoderCap videoEncoder: videoEncoders) { - for (AudioEncoderCap audioEncoder: audioEncoders) { - if (k == 0) { - recordSuccess = recordVideoWithPara(videoEncoder, audioEncoder, true); - } else { - recordSuccess = recordVideoWithPara(videoEncoder, audioEncoder, false); - } - if (!recordSuccess) { - Log.v(TAG, "testDeviceSpecificCodec failed"); - Log.v(TAG, "Encoder = " + videoEncoder.mCodec + "Audio Encoder = " + audioEncoder.mCodec); - noOfFailure++; - } - } - } - } - if (noOfFailure != 0) { - assertTrue("testDeviceSpecificCodec", false); - } - } -} diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaVirtualizerTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaVirtualizerTest.java deleted file mode 100644 index 7a35429..0000000 --- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaVirtualizerTest.java +++ /dev/null @@ -1,294 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.mediaframeworktest.functional; - -import com.android.mediaframeworktest.MediaFrameworkTest; -import com.android.mediaframeworktest.MediaNames; -import android.content.Context; -import android.content.res.AssetFileDescriptor; -import android.media.audiofx.AudioEffect; -import android.media.AudioManager; -import android.media.audiofx.Virtualizer; -import android.media.audiofx.Visualizer; -import android.media.MediaPlayer; - -import android.os.Looper; -import android.test.suitebuilder.annotation.LargeTest; -import android.test.suitebuilder.annotation.MediumTest; -import android.test.suitebuilder.annotation.Suppress; -import android.test.ActivityInstrumentationTestCase2; -import android.util.Log; - -import java.nio.ByteOrder; -import java.nio.ByteBuffer; -import java.util.UUID; - -/** - * Junit / Instrumentation test case for the media AudioTrack api - - */ -public class MediaVirtualizerTest extends ActivityInstrumentationTestCase2 { - private String TAG = "MediaVirtualizerTest"; - private final static int MIN_ENERGY_RATIO_2 = 3; - private final static short TEST_STRENGTH = 500; - private final static int TEST_VOLUME = 4; - - private Virtualizer mVirtualizer = null; - private int mSession = -1; - - public MediaVirtualizerTest() { - super("com.android.mediaframeworktest", MediaFrameworkTest.class); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - } - - @Override - protected void tearDown() throws Exception { - super.tearDown(); - releaseVirtualizer(); - } - - private static void assumeTrue(String message, boolean cond) { - assertTrue("(assume)"+message, cond); - } - - private void log(String testName, String message) { - Log.v(TAG, "["+testName+"] "+message); - } - - private void loge(String testName, String message) { - Log.e(TAG, "["+testName+"] "+message); - } - - //----------------------------------------------------------------- - // VIRTUALIZER TESTS: - //---------------------------------- - - - //----------------------------------------------------------------- - // 0 - constructor - //---------------------------------- - - //Test case 0.0: test constructor and release - @LargeTest - public void test0_0ConstructorAndRelease() throws Exception { - boolean result = false; - String msg = "test1_0ConstructorAndRelease()"; - Virtualizer virtualizer = null; - try { - virtualizer = new Virtualizer(0, 0); - assertNotNull(msg + ": could not create Virtualizer", virtualizer); - try { - assertTrue(msg +": invalid effect ID", (virtualizer.getId() != 0)); - } catch (IllegalStateException e) { - msg = msg.concat(": Virtualizer not initialized"); - } - result = true; - } catch (IllegalArgumentException e) { - msg = msg.concat(": Virtualizer not found"); - } catch (UnsupportedOperationException e) { - msg = msg.concat(": Effect library not loaded"); - } finally { - if (virtualizer != null) { - virtualizer.release(); - } - } - assertTrue(msg, result); - } - - - //----------------------------------------------------------------- - // 1 - get/set parameters - //---------------------------------- - - //Test case 1.0: test strength - @LargeTest - public void test1_0Strength() throws Exception { - boolean result = false; - String msg = "test1_0Strength()"; - getVirtualizer(0); - try { - if (mVirtualizer.getStrengthSupported()) { - mVirtualizer.setStrength((short)TEST_STRENGTH); - short strength = mVirtualizer.getRoundedStrength(); - // allow 10% difference between set strength and rounded strength - assertTrue(msg +": got incorrect strength", - ((float)strength > (float)TEST_STRENGTH * 0.9f) && - ((float)strength < (float)TEST_STRENGTH * 1.1f)); - } else { - short strength = mVirtualizer.getRoundedStrength(); - assertTrue(msg +": got incorrect strength", strength >= 0 && strength <= 1000); - } - result = true; - } catch (IllegalArgumentException e) { - msg = msg.concat(": Bad parameter value"); - loge(msg, "Bad parameter value"); - } catch (UnsupportedOperationException e) { - msg = msg.concat(": get parameter() rejected"); - loge(msg, "get parameter() rejected"); - } catch (IllegalStateException e) { - msg = msg.concat("get parameter() called in wrong state"); - loge(msg, "get parameter() called in wrong state"); - } finally { - releaseVirtualizer(); - } - assertTrue(msg, result); - } - - //Test case 1.1: test properties - @LargeTest - public void test1_1Properties() throws Exception { - boolean result = false; - String msg = "test1_1Properties()"; - getVirtualizer(0); - try { - Virtualizer.Settings settings = mVirtualizer.getProperties(); - String str = settings.toString(); - settings = new Virtualizer.Settings(str); - mVirtualizer.setProperties(settings); - result = true; - } catch (IllegalArgumentException e) { - msg = msg.concat(": Bad parameter value"); - loge(msg, "Bad parameter value"); - } catch (UnsupportedOperationException e) { - msg = msg.concat(": get parameter() rejected"); - loge(msg, "get parameter() rejected"); - } catch (IllegalStateException e) { - msg = msg.concat("get parameter() called in wrong state"); - loge(msg, "get parameter() called in wrong state"); - } finally { - releaseVirtualizer(); - } - assertTrue(msg, result); - } - - //----------------------------------------------------------------- - // 2 - Effect action - //---------------------------------- - - //Test case 2.0: test actual virtualizer influence on sound - @LargeTest - public void test2_0SoundModification() throws Exception { - boolean result = false; - String msg = "test2_0SoundModification()"; - EnergyProbe probe = null; - AudioEffect vc = null; - MediaPlayer mp = null; - AudioManager am = (AudioManager) getActivity().getSystemService(Context.AUDIO_SERVICE); - int volume = am.getStreamMaxVolume(AudioManager.STREAM_MUSIC); - am.setStreamVolume(AudioManager.STREAM_MUSIC, - TEST_VOLUME, - 0); - - try { - probe = new EnergyProbe(0); - // 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, - UUID.fromString("119341a0-8469-11df-81f9-0002a5d5c51b"), - 0, - 0); - vc.setEnabled(true); - - mp = new MediaPlayer(); - mp.setDataSource(MediaNames.SINE_200_1000); - mp.setAudioStreamType(AudioManager.STREAM_MUSIC); - getVirtualizer(mp.getAudioSessionId()); - mp.prepare(); - mp.start(); - Thread.sleep(200); - // measure reference energy around 1kHz - int refEnergy200 = probe.capture(200); - int refEnergy1000 = probe.capture(1000); - mVirtualizer.setStrength((short)1000); - mVirtualizer.setEnabled(true); - Thread.sleep(500); - // measure energy around 1kHz with band level at min - int energy200 = probe.capture(200); - int energy1000 = probe.capture(1000); - // verify that the energy ration between low and high frequencies is at least - // MIN_ENERGY_RATIO_2 times higher with virtualizer on. - // NOTE: this is what is observed with current virtualizer implementation and the test - // audio file but is not the primary effect of the virtualizer. A better way would - // be to have a stereo PCM capture and check that a strongly paned input is centered - // when output. However, we cannot capture stereo with the visualizer. - assertTrue(msg + ": virtiualizer has no effect", - ((float)energy200/(float)energy1000) > - (MIN_ENERGY_RATIO_2 * ((float)refEnergy200/(float)refEnergy1000))); - result = true; - } catch (IllegalArgumentException e) { - msg = msg.concat(": Bad parameter value"); - loge(msg, "Bad parameter value"); - } catch (UnsupportedOperationException e) { - msg = msg.concat(": get parameter() rejected"); - loge(msg, "get parameter() rejected"); - } catch (IllegalStateException e) { - msg = msg.concat("get parameter() called in wrong state"); - loge(msg, "get parameter() called in wrong state"); - } catch (InterruptedException e) { - loge(msg, "sleep() interrupted"); - } - finally { - releaseVirtualizer(); - if (mp != null) { - mp.release(); - } - if (vc != null) { - vc.release(); - } - if (probe != null) { - probe.release(); - } - am.setStreamVolume(AudioManager.STREAM_MUSIC, volume, 0); - } - assertTrue(msg, result); - } - //----------------------------------------------------------------- - // private methods - //---------------------------------- - - private void getVirtualizer(int session) { - if (mVirtualizer == null || session != mSession) { - if (session != mSession && mVirtualizer != null) { - mVirtualizer.release(); - mVirtualizer = null; - } - try { - mVirtualizer = new Virtualizer(0, session); - mSession = session; - } catch (IllegalArgumentException e) { - Log.e(TAG, "getVirtualizer() Virtualizer not found exception: "+e); - } catch (UnsupportedOperationException e) { - Log.e(TAG, "getVirtualizer() Effect library not loaded exception: "+e); - } - } - assertNotNull("could not create mVirtualizer", mVirtualizer); - } - - private void releaseVirtualizer() { - if (mVirtualizer != null) { - mVirtualizer.release(); - mVirtualizer = null; - } - } - -} - diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaVisualizerTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaVisualizerTest.java deleted file mode 100644 index 542ca8d..0000000 --- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaVisualizerTest.java +++ /dev/null @@ -1,505 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.mediaframeworktest.functional; - -import com.android.mediaframeworktest.MediaFrameworkTest; -import com.android.mediaframeworktest.MediaNames; -import android.content.Context; -import android.content.res.AssetFileDescriptor; -import android.media.audiofx.AudioEffect; -import android.media.AudioManager; -import android.media.audiofx.Visualizer; -import android.media.MediaPlayer; - -import android.os.Looper; -import android.test.suitebuilder.annotation.LargeTest; -import android.test.suitebuilder.annotation.MediumTest; -import android.test.suitebuilder.annotation.Suppress; -import android.test.ActivityInstrumentationTestCase2; -import android.util.Log; - -import java.nio.ByteOrder; -import java.nio.ByteBuffer; -import java.util.UUID; - -/** - * Junit / Instrumentation test case for the media AudioTrack api - - */ -public class MediaVisualizerTest extends ActivityInstrumentationTestCase2 { - private String TAG = "MediaVisualizerTest"; - private final static int MIN_CAPTURE_RATE_MAX = 20000; - private final static int MIN_SAMPLING_RATE = 8000000; - private final static int MAX_SAMPLING_RATE = 48000000; - private final static int MIN_CAPTURE_SIZE_MAX = 1024; - private final static int MAX_CAPTURE_SIZE_MIN = 128; - - private Visualizer mVisualizer = null; - private int mSession = -1; - private boolean mInitialized = false; - private Looper mLooper = null; - private final Object lock = new Object(); - private byte[] mWaveform = null; - private byte[] mFft = null; - private boolean mCaptureWaveform = false; - private boolean mCaptureFft = false; - - public MediaVisualizerTest() { - super("com.android.mediaframeworktest", MediaFrameworkTest.class); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - } - - @Override - protected void tearDown() throws Exception { - super.tearDown(); - releaseVisualizer(); - } - - private static void assumeTrue(String message, boolean cond) { - assertTrue("(assume)"+message, cond); - } - - private void log(String testName, String message) { - Log.v(TAG, "["+testName+"] "+message); - } - - private void loge(String testName, String message) { - Log.e(TAG, "["+testName+"] "+message); - } - - //----------------------------------------------------------------- - // VISUALIZER TESTS: - //---------------------------------- - - - //----------------------------------------------------------------- - // 0 - constructor - //---------------------------------- - - //Test case 0.0: test constructor and release - @LargeTest - public void test0_0ConstructorAndRelease() throws Exception { - boolean result = false; - String msg = "test1_0ConstructorAndRelease()"; - Visualizer visualizer = null; - try { - visualizer = new Visualizer(0); - assertNotNull(msg + ": could not create Visualizer", visualizer); - result = true; - } catch (IllegalArgumentException e) { - msg = msg.concat(": Visualizer not found"); - } catch (UnsupportedOperationException e) { - msg = msg.concat(": Effect library not loaded"); - } finally { - if (visualizer != null) { - visualizer.release(); - } - } - assertTrue(msg, result); - } - - - //----------------------------------------------------------------- - // 1 - get/set parameters - //---------------------------------- - - //Test case 1.0: check capture rate and sampling rate - @LargeTest - public void test1_0CaptureRates() throws Exception { - boolean result = false; - String msg = "test1_0CaptureRates()"; - getVisualizer(0); - try { - int captureRate = mVisualizer.getMaxCaptureRate(); - assertTrue(msg +": insufficient max capture rate", - captureRate >= MIN_CAPTURE_RATE_MAX); - int samplingRate = mVisualizer.getSamplingRate(); - assertTrue(msg +": invalid sampling rate", - samplingRate >= MIN_SAMPLING_RATE && samplingRate <= MAX_SAMPLING_RATE); - result = true; - } catch (IllegalArgumentException e) { - msg = msg.concat(": Bad parameter value"); - loge(msg, "Bad parameter value"); - } catch (UnsupportedOperationException e) { - msg = msg.concat(": get parameter() rejected"); - loge(msg, "get parameter() rejected"); - } catch (IllegalStateException e) { - msg = msg.concat("get parameter() called in wrong state"); - loge(msg, "get parameter() called in wrong state"); - } finally { - releaseVisualizer(); - } - assertTrue(msg, result); - } - - //Test case 1.1: check capture size - @LargeTest - public void test1_1CaptureSize() throws Exception { - boolean result = false; - String msg = "test1_1CaptureSize()"; - getVisualizer(0); - try { - int[] range = mVisualizer.getCaptureSizeRange(); - assertTrue(msg +": insufficient min capture size", - range[0] <= MAX_CAPTURE_SIZE_MIN); - assertTrue(msg +": insufficient min capture size", - range[1] >= MIN_CAPTURE_SIZE_MAX); - mVisualizer.setCaptureSize(range[0]); - assertEquals(msg +": insufficient min capture size", - range[0], mVisualizer.getCaptureSize()); - mVisualizer.setCaptureSize(range[1]); - assertEquals(msg +": insufficient min capture size", - range[1], mVisualizer.getCaptureSize()); - result = true; - } catch (IllegalArgumentException e) { - msg = msg.concat(": Bad parameter value"); - loge(msg, "Bad parameter value"); - } catch (UnsupportedOperationException e) { - msg = msg.concat(": get parameter() rejected"); - loge(msg, "get parameter() rejected"); - } catch (IllegalStateException e) { - msg = msg.concat("get parameter() called in wrong state"); - loge(msg, "get parameter() called in wrong state"); - } finally { - releaseVisualizer(); - } - assertTrue(msg, result); - } - - //----------------------------------------------------------------- - // 2 - check capture - //---------------------------------- - - //Test case 2.0: test capture in polling mode - @LargeTest - public void test2_0PollingCapture() throws Exception { - boolean result = false; - String msg = "test2_0PollingCapture()"; - AudioEffect vc = null; - MediaPlayer mp = null; - AudioManager am = (AudioManager) getActivity().getSystemService(Context.AUDIO_SERVICE); - int volume = am.getStreamMaxVolume(AudioManager.STREAM_MUSIC); - am.setStreamVolume(AudioManager.STREAM_MUSIC, - am.getStreamMaxVolume(AudioManager.STREAM_MUSIC), - 0); - - try { - // 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, - UUID.fromString("119341a0-8469-11df-81f9-0002a5d5c51b"), - 0, - 0); - vc.setEnabled(true); - - mp = new MediaPlayer(); - mp.setDataSource(MediaNames.SINE_200_1000); - mp.setAudioStreamType(AudioManager.STREAM_MUSIC); - getVisualizer(mp.getAudioSessionId()); - mVisualizer.setEnabled(true); - // check capture on silence - byte[] data = new byte[mVisualizer.getCaptureSize()]; - mVisualizer.getWaveForm(data); - int energy = computeEnergy(data, true); - assertEquals(msg +": getWaveForm reports energy for silence", - 0, energy); - mVisualizer.getFft(data); - energy = computeEnergy(data, false); - assertEquals(msg +": getFft reports energy for silence", - 0, energy); - mp.prepare(); - mp.start(); - Thread.sleep(500); - // check capture on sound - mVisualizer.getWaveForm(data); - energy = computeEnergy(data, true); - assertTrue(msg +": getWaveForm reads insufficient level", - energy > 0); - mVisualizer.getFft(data); - energy = computeEnergy(data, false); - assertTrue(msg +": getFft reads insufficient level", - energy > 0); - result = true; - } catch (IllegalArgumentException e) { - msg = msg.concat(": Bad parameter value"); - loge(msg, "Bad parameter value"); - } catch (UnsupportedOperationException e) { - msg = msg.concat(": get parameter() rejected"); - loge(msg, "get parameter() rejected"); - } catch (IllegalStateException e) { - msg = msg.concat("get parameter() called in wrong state"); - loge(msg, "get parameter() called in wrong state"); - } catch (InterruptedException e) { - loge(msg, "sleep() interrupted"); - } - finally { - releaseVisualizer(); - if (mp != null) { - mp.release(); - } - if (vc != null) { - vc.release(); - } - am.setStreamVolume(AudioManager.STREAM_MUSIC, volume, 0); - } - assertTrue(msg, result); - } - - //Test case 2.1: test capture with listener - @LargeTest - public void test2_1ListenerCapture() throws Exception { - boolean result = false; - String msg = "test2_1ListenerCapture()"; - AudioEffect vc = null; - MediaPlayer mp = null; - AudioManager am = (AudioManager) getActivity().getSystemService(Context.AUDIO_SERVICE); - int volume = am.getStreamMaxVolume(AudioManager.STREAM_MUSIC); - am.setStreamVolume(AudioManager.STREAM_MUSIC, - am.getStreamMaxVolume(AudioManager.STREAM_MUSIC), - 0); - - try { - // 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, - UUID.fromString("119341a0-8469-11df-81f9-0002a5d5c51b"), - 0, - 0); - vc.setEnabled(true); - - mp = new MediaPlayer(); - mp.setDataSource(MediaNames.SINE_200_1000); - mp.setAudioStreamType(AudioManager.STREAM_MUSIC); - - getVisualizer(mp.getAudioSessionId()); - createListenerLooper(); - synchronized(lock) { - try { - lock.wait(1000); - } catch(Exception e) { - Log.e(TAG, "Looper creation: wait was interrupted."); - } - } - assertTrue(mInitialized); - - mVisualizer.setEnabled(true); - - // check capture on silence - synchronized(lock) { - try { - mCaptureWaveform = true; - lock.wait(1000); - mCaptureWaveform = false; - } catch(Exception e) { - Log.e(TAG, "Capture waveform: wait was interrupted."); - } - } - assertNotNull(msg +": waveform capture failed", mWaveform); - int energy = computeEnergy(mWaveform, true); - assertEquals(msg +": getWaveForm reports energy for silence", - 0, energy); - - synchronized(lock) { - try { - mCaptureFft = true; - lock.wait(1000); - mCaptureFft = false; - } catch(Exception e) { - Log.e(TAG, "Capture FFT: wait was interrupted."); - } - } - assertNotNull(msg +": FFT capture failed", mFft); - energy = computeEnergy(mFft, false); - assertEquals(msg +": getFft reports energy for silence", - 0, energy); - - mp.prepare(); - mp.start(); - Thread.sleep(500); - - // check capture on sound - synchronized(lock) { - try { - mCaptureWaveform = true; - lock.wait(1000); - mCaptureWaveform = false; - } catch(Exception e) { - Log.e(TAG, "Capture waveform: wait was interrupted."); - } - } - assertNotNull(msg +": waveform capture failed", mWaveform); - energy = computeEnergy(mWaveform, true); - assertTrue(msg +": getWaveForm reads insufficient level", - energy > 0); - - synchronized(lock) { - try { - mCaptureFft = true; - lock.wait(1000); - mCaptureFft = false; - } catch(Exception e) { - Log.e(TAG, "Capture FFT: wait was interrupted."); - } - } - assertNotNull(msg +": FFT capture failed", mFft); - energy = computeEnergy(mFft, false); - assertTrue(msg +": getFft reads insufficient level", - energy > 0); - - result = true; - } catch (IllegalArgumentException e) { - msg = msg.concat(": Bad parameter value"); - loge(msg, "Bad parameter value"); - } catch (UnsupportedOperationException e) { - msg = msg.concat(": get parameter() rejected"); - loge(msg, "get parameter() rejected"); - } catch (IllegalStateException e) { - msg = msg.concat("get parameter() called in wrong state"); - loge(msg, "get parameter() called in wrong state"); - } catch (InterruptedException e) { - loge(msg, "sleep() interrupted"); - } - finally { - terminateListenerLooper(); - releaseVisualizer(); - if (mp != null) { - mp.release(); - } - if (vc != null) { - vc.release(); - } - am.setStreamVolume(AudioManager.STREAM_MUSIC, volume, 0); - } - assertTrue(msg, result); - } - - //----------------------------------------------------------------- - // private methods - //---------------------------------- - - private int computeEnergy(byte[] data, boolean unsigned) { - int energy = 0; - if (data.length != 0) { - for (int i = 0; i < data.length; i++) { - int tmp; - // convert from unsigned 8 bit to signed 16 bit - if (unsigned) { - tmp = ((int)data[i] & 0xFF) - 128; - } else { - tmp = (int)data[i]; - } - energy += tmp*tmp; - } - energy /= data.length; - } - return energy; - } - - private void getVisualizer(int session) { - if (mVisualizer == null || session != mSession) { - if (session != mSession && mVisualizer != null) { - mVisualizer.release(); - mVisualizer = null; - } - try { - mVisualizer = new Visualizer(session); - mSession = session; - } catch (IllegalArgumentException e) { - Log.e(TAG, "getVisualizer() Visualizer not found exception: "+e); - } catch (UnsupportedOperationException e) { - Log.e(TAG, "getVisualizer() Effect library not loaded exception: "+e); - } - } - assertNotNull("could not create mVisualizer", mVisualizer); - } - - private void releaseVisualizer() { - if (mVisualizer != null) { - mVisualizer.release(); - mVisualizer = null; - } - } - - private void createListenerLooper() { - - new Thread() { - @Override - public void run() { - // Set up a looper to be used by mEffect. - Looper.prepare(); - - // Save the looper so that we can terminate this thread - // after we are done with it. - mLooper = Looper.myLooper(); - - if (mVisualizer != null) { - mVisualizer.setDataCaptureListener(new Visualizer.OnDataCaptureListener() { - public void onWaveFormDataCapture( - Visualizer visualizer, byte[] waveform, int samplingRate) { - synchronized(lock) { - if (visualizer == mVisualizer) { - if (mCaptureWaveform) { - mWaveform = waveform; - lock.notify(); - } - } - } - } - - public void onFftDataCapture( - Visualizer visualizer, byte[] fft, int samplingRate) { - synchronized(lock) { - if (visualizer == mVisualizer) { - if (mCaptureFft) { - mFft = fft; - lock.notify(); - } - } - } - } - }, - 10000, - true, - true); - } - - synchronized(lock) { - mInitialized = true; - lock.notify(); - } - Looper.loop(); // Blocks forever until Looper.quit() is called. - } - }.start(); - } - /* - * Terminates the listener looper thread. - */ - private void terminateListenerLooper() { - if (mLooper != null) { - mLooper.quit(); - mLooper = null; - } - } - -} - diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/SimTonesTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/SimTonesTest.java deleted file mode 100644 index 241f8d6..0000000 --- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/SimTonesTest.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.mediaframeworktest.functional; - -// import android.content.Resources; -import com.android.mediaframeworktest.MediaFrameworkTest; - -import android.content.Context; -import android.test.ActivityInstrumentationTestCase; -import android.test.suitebuilder.annotation.LargeTest; - -/** - * Junit / Instrumentation test case for the SIM tone generator - * - */ -public class SimTonesTest extends ActivityInstrumentationTestCase { - private String TAG = "SimTonesTest"; - - Context mContext; - - public SimTonesTest() { - super("com.android.mediaframeworktest", MediaFrameworkTest.class); - } - - protected void setUp() throws Exception { - super.setUp(); - } - - @LargeTest - public void testDtmfTones() throws Exception { - boolean result = TonesAutoTest.tonesDtmfTest(); - assertTrue("DTMF Tones", result); - } - - @LargeTest - public void testSupervisoryTones() throws Exception { - boolean result = TonesAutoTest.tonesSupervisoryTest(); - assertTrue("Supervisory Tones", result); - } - - @LargeTest - public void testProprietaryTones() throws Exception { - boolean result = TonesAutoTest.tonesProprietaryTest(); - assertTrue("Proprietary Tones", result); - } - - @LargeTest - public void testSimultaneousTones() throws Exception { - boolean result = TonesAutoTest.tonesSimultaneousTest(); - assertTrue("Simultaneous Tones", result); - } - - @LargeTest - public void testStressTones() throws Exception { - boolean result = TonesAutoTest.tonesStressTest(); - assertTrue("Stress Tones", result); - } -} - diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/VideoEditorAPITest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/VideoEditorAPITest.java deleted file mode 100644 index 2a02b58..0000000 --- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/VideoEditorAPITest.java +++ /dev/null @@ -1,2802 +0,0 @@ -/* - * Copyright (C) 2011 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.mediaframeworktest.functional; - -import java.io.File; -import java.util.List; - -import android.graphics.Bitmap; -import android.graphics.Rect; -import android.media.videoeditor.AudioTrack; -import android.media.videoeditor.EffectColor; -import android.media.videoeditor.EffectKenBurns; -import android.media.videoeditor.ExtractAudioWaveformProgressListener; -import android.media.videoeditor.MediaImageItem; -import android.media.videoeditor.MediaItem; -import android.media.videoeditor.MediaProperties; -import android.media.videoeditor.MediaVideoItem; -import android.media.videoeditor.OverlayFrame; -import android.media.videoeditor.Transition; -import android.media.videoeditor.TransitionAlpha; -import android.media.videoeditor.TransitionCrossfade; -import android.media.videoeditor.TransitionFadeBlack; -import android.media.videoeditor.TransitionSliding; -import android.media.videoeditor.VideoEditor; -import android.os.Environment; -import android.test.ActivityInstrumentationTestCase; -import android.media.videoeditor.VideoEditor.MediaProcessingProgressListener; - -import android.util.Log; -import java.lang.annotation.Annotation; - -import com.android.mediaframeworktest.MediaFrameworkTest; -import android.test.suitebuilder.annotation.LargeTest; -import com.android.mediaframeworktest.VideoEditorHelper; - -public class VideoEditorAPITest extends - ActivityInstrumentationTestCase { - private final String TAG = "VideoEditorTest"; - - private final String PROJECT_LOCATION = VideoEditorHelper.PROJECT_LOCATION_COMMON; - - private final String INPUT_FILE_PATH = VideoEditorHelper.INPUT_FILE_PATH_COMMON; - - private final String PROJECT_CLASS_NAME = - "android.media.videoeditor.VideoEditorImpl"; - private VideoEditor mVideoEditor; - private VideoEditorHelper mVideoEditorHelper; - - public VideoEditorAPITest() { - super("com.android.mediaframeworktest", MediaFrameworkTest.class); - } - - @Override - protected void setUp() throws Exception { - // setup for each test case. - super.setUp(); - mVideoEditorHelper = new VideoEditorHelper(); - // Create a random String which will be used as project path, where all - // project related files will be stored. - final String projectPath = mVideoEditorHelper. - createRandomFile(PROJECT_LOCATION); - mVideoEditor = mVideoEditorHelper.createVideoEditor(projectPath); - } - - @Override - protected void tearDown() throws Exception { - mVideoEditorHelper.destroyVideoEditor(mVideoEditor); - // Clean the directory created as project path - mVideoEditorHelper.deleteProject(new File(mVideoEditor.getPath())); - System.gc(); - super.tearDown(); - } - - /** - * To Test Creation of Media Video Item. - */ - // TODO : remove TC_API_001 - @LargeTest - public void testMediaVideoItem() throws Exception { - final String videoItemFileName = INPUT_FILE_PATH - + "H263_profile0_176x144_15fps_256kbps_AACLC_32kHz_128kbps_s_0_26.3gp"; - final int videoItemRenderingMode = - MediaItem.RENDERING_MODE_BLACK_BORDER; - - final MediaVideoItem mediaVideoItem1 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "mediaVideoItem1", - videoItemFileName, videoItemRenderingMode); - - assertTrue("Media Video ID", - mediaVideoItem1.getId().equals("mediaVideoItem1")); - assertTrue("Media Video Filename", - mediaVideoItem1.getFilename().equals(videoItemFileName)); - assertEquals("Media Video Rendering Mode", - videoItemRenderingMode, mediaVideoItem1.getRenderingMode()); - assertEquals("Media Video Item Duration", mediaVideoItem1.getDuration(), - mediaVideoItem1.getTimelineDuration()); - assertEquals("Media Video Overlay", 0, - mediaVideoItem1.getAllOverlays().size()); - assertEquals("Media Video Effect", 0, - mediaVideoItem1.getAllEffects().size()); - assertNull("Media Video Begin transition", - mediaVideoItem1.getBeginTransition()); - assertNull("Media Video End transition", - mediaVideoItem1.getEndTransition()); - mediaVideoItem1.setExtractBoundaries(1000,11000); - boolean flagForException = false; - if (mediaVideoItem1.getDuration() != - mediaVideoItem1.getTimelineDuration()) { - flagForException = true; - } - assertTrue("Media Video Item Duration & Timeline are same", - flagForException ); - } - - /** - * To test creation of Media Video Item with Set Extract Boundaries With Get - * the Begin and End Time. - */ - // TODO : remove TC_API_002 - @LargeTest - public void testMediaVideoItemExtractBoundaries() throws Exception { - final String videoItemFileName = INPUT_FILE_PATH - + "H263_profile0_176x144_15fps_256kbps_AACLC_32kHz_128kbps_s_0_26.3gp"; - final int videoItemRenderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; - boolean flagForException = false; - final MediaVideoItem mediaVideoItem1 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "mediaVideoItem1", - videoItemFileName, videoItemRenderingMode); - mVideoEditor.addMediaItem(mediaVideoItem1); - - mediaVideoItem1.setExtractBoundaries(1000, 11000); - assertEquals("Media Item Duration = StoryBoard Duration", - mediaVideoItem1.getTimelineDuration(), mVideoEditor.getDuration()); - try { - mediaVideoItem1.setExtractBoundaries(0, 100000000); - } catch (IllegalArgumentException e) { - flagForException = true; - } - assertTrue("Set Extract with Invalid Values endTime > FileDuration", - flagForException); - - flagForException = false; - try { - mediaVideoItem1.setExtractBoundaries(100000000, 11000); - } catch (IllegalArgumentException e) { - flagForException = true; - } - assertTrue("Set Extract with Invalid Values startTime > endTime", - flagForException); - - flagForException = false; - try { - mediaVideoItem1.setExtractBoundaries(0, 0); - } catch (IllegalArgumentException e) { - flagForException = true; - } - assertTrue("Set Extract with Invalid Values startTime = endTime", - flagForException); - - mediaVideoItem1.setExtractBoundaries(1000, 10000); - assertTrue("Media Item Duration is still the same", - (mediaVideoItem1.getTimelineDuration() == - (mediaVideoItem1.getBoundaryEndTime()- - mediaVideoItem1.getBoundaryBeginTime())) ? true : false); - - mediaVideoItem1.setExtractBoundaries(1,mediaVideoItem1.getDuration()-1); - assertEquals("Media Item Start Time", 1, - mediaVideoItem1.getBoundaryBeginTime()); - assertEquals("Media Item End Time", (mediaVideoItem1.getDuration() - 1), - mediaVideoItem1.getBoundaryEndTime()); - - mediaVideoItem1.setExtractBoundaries(1, mediaVideoItem1.getDuration()); - assertEquals("Media Item Duration = StoryBoard Duration", - mediaVideoItem1.getTimelineDuration(), mVideoEditor.getDuration()); - - mediaVideoItem1.setExtractBoundaries(0,mediaVideoItem1.getDuration()/2); - assertEquals("Media Item Duration = StoryBoard Duration", - mediaVideoItem1.getTimelineDuration(), mVideoEditor.getDuration()); - - mediaVideoItem1.setExtractBoundaries(0, -1); - assertEquals("Media Item Duration = StoryBoard Duration", - mediaVideoItem1.getTimelineDuration(), mVideoEditor.getDuration()); - } - - /** - * To test creation of Media Video Item with Set and Get rendering Mode - */ - // TODO : remove TC_API_003 - @LargeTest - public void testMediaVideoItemRenderingModes() throws Exception { - final String videoItemFileName = INPUT_FILE_PATH - + "H263_profile0_176x144_15fps_256kbps_AACLC_32kHz_128kbps_s_0_26.3gp"; - final int videoItemRenderingMode= MediaItem.RENDERING_MODE_BLACK_BORDER; - boolean flagForException = false; - final MediaVideoItem mediaVideoItem1 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "mediaVideoItem1", - videoItemFileName, videoItemRenderingMode); - mVideoEditor.addMediaItem(mediaVideoItem1); - mediaVideoItem1.setRenderingMode(MediaItem.RENDERING_MODE_CROPPING); - assertEquals("MediaVideo Item rendering Mode", - MediaItem.RENDERING_MODE_CROPPING, - mediaVideoItem1.getRenderingMode()); - try { - mediaVideoItem1.setRenderingMode( - MediaItem.RENDERING_MODE_CROPPING + 911); - } catch (IllegalArgumentException e) { - flagForException = true; - } - assertTrue("Media Item Invalid rendering Mode", flagForException); - flagForException = false; - try { - mediaVideoItem1.setRenderingMode( - MediaItem.RENDERING_MODE_BLACK_BORDER - 11); - } catch (IllegalArgumentException e) { - flagForException = true; - } - assertTrue("Media Item Invalid rendering Mode", flagForException); - assertEquals("MediaVideo Item rendering Mode", - MediaItem.RENDERING_MODE_CROPPING, - mediaVideoItem1.getRenderingMode()); - mediaVideoItem1.setRenderingMode(MediaItem.RENDERING_MODE_STRETCH); - assertEquals("MediaVideo Item rendering Mode", - MediaItem.RENDERING_MODE_STRETCH, - mediaVideoItem1.getRenderingMode()); - } - - /** Test Case TC_API_004 is removed */ - - /** - * To Test the Media Video API : Set Audio Volume, Get Audio Volume and Mute - */ - // TODO : remove TC_API_005 - @LargeTest - public void testMediaVideoItemAudioFeatures() throws Exception { - final String videoItemFileName = INPUT_FILE_PATH - + "H263_profile0_176x144_15fps_256kbps_AACLC_32kHz_128kbps_s_0_26.3gp"; - final int videoItemRenderingMode =MediaItem.RENDERING_MODE_BLACK_BORDER; - boolean flagForException = false; - final MediaVideoItem mediaVideoItem1 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "mediaVideoItem1", - videoItemFileName, videoItemRenderingMode); - mVideoEditor.addMediaItem(mediaVideoItem1); - mediaVideoItem1.setVolume(77); - assertEquals("Updated Volume is 77", 77, mediaVideoItem1.getVolume()); - - mediaVideoItem1.setMute(true); - assertTrue("Audio must be Muted", mediaVideoItem1.isMuted()); - - mediaVideoItem1.setVolume(78); - assertEquals("Updated Volume is 78", 78, mediaVideoItem1.getVolume()); - assertTrue("Audio must be Muted", mediaVideoItem1.isMuted()); - - try { - mediaVideoItem1.setVolume(1000); - } catch (IllegalArgumentException e) { - flagForException = true; - } - assertTrue("Invalid Set Volume", flagForException); - - mediaVideoItem1.setMute(false); - assertFalse("Audio must be Un-Muted", mediaVideoItem1.isMuted()); - - mediaVideoItem1.setVolume(0); - assertFalse("Audio must be Un-Muted", mediaVideoItem1.isMuted()); - - flagForException = false; - try { - mediaVideoItem1.setVolume(-1); - } catch (IllegalArgumentException e) { - flagForException = true; - } - assertTrue("Invalid Set Volume", flagForException); - - mediaVideoItem1.setVolume(100); - assertEquals("MediaItem Volume", 100, mediaVideoItem1.getVolume()); - try { - mediaVideoItem1.setVolume(101); - } catch (IllegalArgumentException e) { - flagForException = true; - } - assertTrue("Invalid Set Volume", flagForException); - assertEquals("MediaItem Volume", 100, mediaVideoItem1.getVolume()); - } - - /** - * To Test the Media Video API : GetWaveFormData and - * extractAudioWaveFormData - */ - - // TODO : remove TC_API_006 - @LargeTest - public void testMediaVideoItemGetWaveformData() throws Exception { - - final String videoItemFileName = INPUT_FILE_PATH - + "H263_profile0_176x144_15fps_256kbps_AACLC_32kHz_128kbps_s_0_26.3gp"; - final int videoItemRenderingMode =MediaItem.RENDERING_MODE_BLACK_BORDER; - final MediaVideoItem mediaVideoItem1 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "mediaVideoItem1", - videoItemFileName, videoItemRenderingMode); - mVideoEditor.addMediaItem(mediaVideoItem1); - - assertNull("WaveForm data", mediaVideoItem1.getWaveformData()); - final int[] progressWaveform = new int[105]; - - mediaVideoItem1.extractAudioWaveform(new - ExtractAudioWaveformProgressListener() { - int i = 0; - public void onProgress(int progress) { - Log.i("WaveformData","progress=" +progress); - progressWaveform[i++] = progress; - } - }); - assertTrue("Progress of WaveForm data", mVideoEditorHelper - .checkProgressCBValues(progressWaveform)); - assertNotNull("WaveForm data", mediaVideoItem1.getWaveformData()); - assertTrue("WaveForm Frame Duration", - (mediaVideoItem1.getWaveformData().getFrameDuration() > 0? - true : false)); - assertTrue("WaveForm Frame Count", - (mediaVideoItem1.getWaveformData().getFramesCount() > 0 ? - true : false)); - assertTrue("WaveForm Gain", - (mediaVideoItem1.getWaveformData().getFrameGains().length > 0 ? - true : false)); - - } - - /** - * To Test the Media Video API : Get Effect, GetAllEffects, remove Effect - */ - - // TODO : remove TC_API_007 - @LargeTest - public void testMediaVideoItemEffect() throws Exception { - final String videoItemFileName = INPUT_FILE_PATH - + "H263_profile0_176x144_15fps_256kbps_AACLC_32kHz_128kbps_s_0_26.3gp"; - final int videoItemRenderingMode =MediaItem.RENDERING_MODE_BLACK_BORDER; - final MediaVideoItem mediaVideoItem1 = mVideoEditorHelper. - createMediaItem(mVideoEditor, "mediaVideoItem1", videoItemFileName, - videoItemRenderingMode); - mVideoEditor.addMediaItem(mediaVideoItem1); - - assertTrue("Effect List Size", - (mediaVideoItem1.getAllEffects().size() == 0) ? true : false); - assertNull("Effect Item by ID", mediaVideoItem1.getEffect("xyx")); - - final EffectColor effectColor = mVideoEditorHelper.createEffectItem( - mediaVideoItem1, "Effecton MVi1", 0, 4000, EffectColor.TYPE_GRADIENT, - EffectColor.GRAY); - mediaVideoItem1.addEffect(effectColor); - - assertTrue("Effect List Size", (mediaVideoItem1. - getAllEffects().size() == 1) ? true : false); - assertEquals("Effect Item by Valid ID", effectColor, - mediaVideoItem1.getEffect(effectColor.getId())); - assertNull("Effect Item by Invalid ID", - mediaVideoItem1.getEffect("xyz")); - assertNull("Effect Item by Invalid ID", - mediaVideoItem1.removeEffect("effectId")); - assertTrue("Effect List Size", - (mediaVideoItem1.getAllEffects().size() == 1) ? true : false); - assertEquals("Effect Removed", effectColor, - mediaVideoItem1.removeEffect(effectColor.getId())); - assertTrue("Effect List Size", - (mediaVideoItem1.getAllEffects().size() == 0) ? true : false); - assertNull("Effect Item by ID", mediaVideoItem1.getEffect("effectId")); - } - - /** - * To Test the Media Video API : Get Before and after transition - */ - - // TODO : remove TC_API_008 - @LargeTest - public void testMediaVideoItemTransitions() throws Exception { - final String videoItemFileName = INPUT_FILE_PATH - + "H263_profile0_176x144_15fps_256kbps_AACLC_32kHz_128kbps_s_0_26.3gp"; - final int videoItemRenderingMode =MediaItem.RENDERING_MODE_BLACK_BORDER; - final MediaVideoItem mediaVideoItem1 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "mediaVideoItem1", - videoItemFileName, videoItemRenderingMode); - mVideoEditor.addMediaItem(mediaVideoItem1); - assertNull("Begin Transition", mediaVideoItem1.getBeginTransition()); - assertNull("End Transition", mediaVideoItem1.getEndTransition()); - - TransitionFadeBlack transition1 = - mVideoEditorHelper.createTFadeBlack("transition1", mediaVideoItem1, - null, 0, Transition.BEHAVIOR_SPEED_UP); - mVideoEditor.addTransition(transition1); - assertEquals("Begin transition", transition1, - mediaVideoItem1.getEndTransition()); - - assertNotNull("End Transition", mediaVideoItem1.getEndTransition()); - assertTrue(mediaVideoItem1. - getEndTransition().getId().equals(transition1.getId())); - assertTrue(mediaVideoItem1.getEndTransition().getDuration() == - transition1.getDuration() ? true : false); - assertTrue(mediaVideoItem1.getEndTransition().getBehavior() == - transition1.getBehavior() ? true : false); - - TransitionFadeBlack transition2 = mVideoEditorHelper.createTFadeBlack( - "transition2", null,mediaVideoItem1, 0, Transition.BEHAVIOR_LINEAR); - mVideoEditor.addTransition(transition2); - assertNotNull("Begin transition", mediaVideoItem1.getBeginTransition()); - assertEquals("End Transition", transition2, - mediaVideoItem1.getBeginTransition()); - assertTrue(mediaVideoItem1. - getBeginTransition().getId().equals(transition2.getId())); - assertTrue(mediaVideoItem1. getBeginTransition().getDuration() == - transition2.getDuration() ? true : false); - assertTrue(mediaVideoItem1.getBeginTransition().getBehavior() == - transition2.getBehavior() ? true : false); - } - - /** - * To Test the Media Video API : Get All Overlay, Get Overlay and remove Overlay - * - */ - - // TODO : remove TC_API_009 - @LargeTest - public void testMediaVideoItemOverlays() throws Exception { - final String videoItemFileName = INPUT_FILE_PATH - + "H263_profile0_176x144_15fps_256kbps_AACLC_32kHz_128kbps_s_0_26.3gp"; - final String overlayItemFileName = INPUT_FILE_PATH + - "IMG_176x144_Overlay1.png"; - final int videoItemRenderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; - final MediaVideoItem mediaVideoItem1 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "mediaVideoItem1", - videoItemFileName, videoItemRenderingMode); - mVideoEditor.addMediaItem(mediaVideoItem1); - - assertTrue("Overlay List Size", - (mediaVideoItem1.getAllOverlays().size() == 0) ? true : false); - assertNull("Overlay Item by ID", mediaVideoItem1.getOverlay("xyz")); - - final Bitmap mBitmap = mVideoEditorHelper.getBitmap(overlayItemFileName, - 176, 144); - final OverlayFrame overlayFrame = mVideoEditorHelper.createOverlay( - mediaVideoItem1, "overlayId", mBitmap, 5000, 5000); - mediaVideoItem1.addOverlay(overlayFrame); - - assertTrue("Overlay List Size", - (mediaVideoItem1.getAllOverlays().size() == 1) ? true : false); - assertEquals("Overlay Item by Valid ID", overlayFrame, mediaVideoItem1 - .getOverlay(overlayFrame.getId())); - assertNull("Overlay Item by Invalid ID", - mediaVideoItem1.getOverlay("xyz")); - assertNull("Overlay Item by Invalid ID", - mediaVideoItem1.removeOverlay("xyz")); - assertTrue("Overlay List Size", - (mediaVideoItem1.getAllOverlays().size() == 1) ? true : false); - assertEquals("Overlay Removed", overlayFrame, - mediaVideoItem1.removeOverlay(overlayFrame.getId())); - assertTrue("Overlay List Size", - (mediaVideoItem1.getAllOverlays().size() == 0) ? true : false); - assertNull("Overlay Item by ID",mediaVideoItem1.getOverlay("effectId")); - } - - /** - * To Test Creation of Media Image Item. - */ - // TODO : remove TC_API_010 - @LargeTest - public void testMediaImageItem() throws Exception { - final String imageItemFileName = INPUT_FILE_PATH + "IMG_1600x1200.jpg"; - final int imageItemRenderingMode =MediaItem.RENDERING_MODE_BLACK_BORDER; - final MediaImageItem mediaImageItem1 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "mediaImageItem1", - imageItemFileName, 5000, imageItemRenderingMode); - assertTrue("Media Image ID", - mediaImageItem1.getId().equals("mediaImageItem1")); - assertTrue("Media IMage Filename", - mediaImageItem1.getFilename().equals(imageItemFileName)); - assertEquals("Media Image Rendering Mode", - imageItemRenderingMode, mediaImageItem1.getRenderingMode()); - assertEquals("Media Image Item Duration", mediaImageItem1.getDuration(), - mediaImageItem1.getTimelineDuration()); - assertEquals("Media Image Overlay", 0, - mediaImageItem1.getAllOverlays().size()); - assertEquals("Media Image Effect", 0, - mediaImageItem1.getAllEffects().size()); - assertNull("Media Image Begin transition", - mediaImageItem1.getBeginTransition()); - assertNull("Media Image End transition", - mediaImageItem1.getEndTransition()); - assertEquals("Media Image Scaled Height", MediaProperties.HEIGHT_720, - mediaImageItem1.getScaledHeight()); - assertEquals("Media Image Scaled Width", 960, - mediaImageItem1.getScaledWidth()); - assertEquals("Media Image Aspect Ratio", MediaProperties.ASPECT_RATIO_4_3, - mediaImageItem1.getAspectRatio()); - assertNotNull("Media Image Thumbnail", - mediaImageItem1.getThumbnail(960, MediaProperties.HEIGHT_720, 2000)); - } - - /** - * To Test the Media Image API : Get and Set rendering Mode - */ - // TODO : remove TC_API_011 - @LargeTest - public void testMediaImageItemRenderingModes() throws Exception { - final String imageItemFileName = INPUT_FILE_PATH + "IMG_1600x1200.jpg"; - final int imageItemRenderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; - boolean flagForException = false; - final MediaImageItem mediaImageItem1 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "mediaImageItem1", - imageItemFileName, imageItemRenderingMode, 5000); - mVideoEditor.addMediaItem(mediaImageItem1); - - mediaImageItem1.setRenderingMode(MediaItem.RENDERING_MODE_CROPPING); - assertEquals("MediaVideo Item rendering Mode", - MediaItem.RENDERING_MODE_CROPPING, mediaImageItem1.getRenderingMode()); - try { - mediaImageItem1.setRenderingMode( - MediaItem.RENDERING_MODE_CROPPING + 911); - } catch (IllegalArgumentException e) { - flagForException = true; - } - assertTrue("Media Item Invalid rendering Mode", flagForException); - - flagForException = false; - try { - mediaImageItem1.setRenderingMode( - MediaItem.RENDERING_MODE_BLACK_BORDER - 11); - } catch (IllegalArgumentException e) { - flagForException = true; - } - assertTrue("Media Item Invalid rendering Mode", flagForException); - - assertEquals("MediaVideo Item rendering Mode", - MediaItem.RENDERING_MODE_CROPPING, - mediaImageItem1.getRenderingMode()); - mediaImageItem1.setRenderingMode(MediaItem.RENDERING_MODE_STRETCH); - assertEquals("MediaVideo Item rendering Mode", - MediaItem.RENDERING_MODE_STRETCH, - mediaImageItem1.getRenderingMode()); - } - - /** - * To Test the Media Image API : GetHeight and GetWidth - */ - // TODO : remove TC_API_012 - @LargeTest - public void testMediaImageItemHeightWidth() throws Exception { - final String imageItemFileName = INPUT_FILE_PATH + "IMG_640x480.jpg"; - final int imageItemRenderingMode =MediaItem.RENDERING_MODE_BLACK_BORDER; - final MediaImageItem mediaImageItem1 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "mediaImageItem1", - imageItemFileName, imageItemRenderingMode, 5000); - mVideoEditor.addMediaItem(mediaImageItem1); - - assertEquals("Image Height = Image Scaled Height", - mediaImageItem1.getScaledHeight(), mediaImageItem1.getHeight()); - assertEquals("Image Width = Image Scaled Width", - mediaImageItem1.getScaledWidth(), mediaImageItem1.getWidth()); - } - - - -/** This Test Case can be removed as this is already checked in TC 010 */ - /** - * To Test the Media Image API : Scaled Height and Scaled GetWidth - */ - // TODO : remove TC_API_013 - @LargeTest - public void testMediaImageItemScaledHeightWidth() throws Exception { - final String imageItemFileName = INPUT_FILE_PATH + "IMG_1600x1200.jpg"; - final int imageItemRenderingMode =MediaItem.RENDERING_MODE_BLACK_BORDER; - - final MediaImageItem mediaImageItem1 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "mediaImageItem1", - imageItemFileName, imageItemRenderingMode, 5000); - mVideoEditor.addMediaItem(mediaImageItem1); - - assertNotSame("Image Height = Image Scaled Height", - mediaImageItem1.getScaledHeight(), mediaImageItem1.getHeight()); - assertNotSame("Image Width = Image Scaled Width", - mediaImageItem1.getScaledWidth(), mediaImageItem1.getWidth()); - } - - /** - * To Test the Media Image API : Get Effect, GetAllEffects, remove Effect - */ - - // TODO : remove TC_API_014 - @LargeTest - public void testMediaImageItemEffect() throws Exception { - final String imageItemFileName = INPUT_FILE_PATH + "IMG_1600x1200.jpg"; - final int imageItemRenderingMode =MediaItem.RENDERING_MODE_BLACK_BORDER; - final MediaImageItem mediaImageItem1 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "mediaImageItem1", - imageItemFileName, 5000, imageItemRenderingMode); - mVideoEditor.addMediaItem(mediaImageItem1); - - assertTrue("Effect List Size", - (mediaImageItem1.getAllEffects().size() == 0) ? true : false); - assertNull("Effect Item by ID", mediaImageItem1.getEffect("xyx")); - - final EffectColor effectColor = - mVideoEditorHelper.createEffectItem(mediaImageItem1, - "Effecton MVi1", 0, 4000, EffectColor.TYPE_GRADIENT, EffectColor.GRAY); - mediaImageItem1.addEffect(effectColor); - - assertTrue("Effect List Size", - (mediaImageItem1.getAllEffects().size() == 1) ? true : false); - assertEquals("Effect Item by Valid ID", - effectColor, mediaImageItem1.getEffect(effectColor.getId())); - assertNull("Effect Item by Invalid ID", - mediaImageItem1.getEffect("xyz")); - assertNull("Effect Item by Invalid ID", - mediaImageItem1.removeEffect("effectId")); - assertTrue("Effect List Size", - (mediaImageItem1.getAllEffects().size() == 1) ? true : false); - assertEquals("Effect Removed", effectColor, - mediaImageItem1.removeEffect(effectColor.getId())); - assertTrue("Effect List Size", - (mediaImageItem1.getAllEffects().size() == 0) ? true : false); - assertNull("Effect Item by ID", mediaImageItem1.getEffect("effectId")); - } - - /** - * To Test the Media Image API : Get Before and after transition - */ - - // TODO : remove TC_API_015 - @LargeTest - public void testMediaImageItemTransitions() throws Exception { - final String imageItemFileName = INPUT_FILE_PATH + "IMG_1600x1200.jpg"; - final int imageItemRenderingMode =MediaItem.RENDERING_MODE_BLACK_BORDER; - final MediaImageItem mediaImageItem1 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "mediaImageItem1", - imageItemFileName, 5000, imageItemRenderingMode); - mVideoEditor.addMediaItem(mediaImageItem1); - - assertNull("Begin Transition", mediaImageItem1.getBeginTransition()); - assertNull("End Transition", mediaImageItem1.getEndTransition()); - - TransitionFadeBlack transition1 = - mVideoEditorHelper.createTFadeBlack("transition1", mediaImageItem1, - null, 0, Transition.BEHAVIOR_SPEED_UP); - mVideoEditor.addTransition(transition1); - - assertEquals("Begin transition", transition1, - mediaImageItem1.getEndTransition()); - assertNotNull("End Transition", mediaImageItem1.getEndTransition()); - assertTrue(mediaImageItem1.getEndTransition().getId().equals - (transition1.getId())); - assertTrue(mediaImageItem1.getEndTransition().getDuration() == - transition1.getDuration() ? true : false); - assertTrue(mediaImageItem1.getEndTransition().getBehavior() == - transition1.getBehavior() ? true : false); - - TransitionFadeBlack transition2 = mVideoEditorHelper.createTFadeBlack( - "transition2",null, mediaImageItem1, 0, Transition.BEHAVIOR_SPEED_UP); - mVideoEditor.addTransition(transition2); - - assertNotNull("Begin transition", mediaImageItem1.getBeginTransition()); - assertEquals("End Transition", transition2, - mediaImageItem1.getBeginTransition()); - assertTrue(mediaImageItem1.getBeginTransition().getId().equals( - transition2.getId())); - assertTrue(mediaImageItem1.getBeginTransition().getDuration() == - transition2.getDuration() ? true : false); - assertTrue(mediaImageItem1.getBeginTransition().getBehavior() == - transition2.getBehavior() ? true : false); - } - - /** - * To Test the Media Image API : Get All Overlay, Get Overlay and remove - * Overlay - */ - - // TODO : remove TC_API_016 - @LargeTest - public void testMediaImageItemOverlays() throws Exception { - final String imageItemFileName = INPUT_FILE_PATH + "IMG_640x480.jpg"; - final String overlayItemFileName = INPUT_FILE_PATH + - "IMG_640x480_Overlay1.png"; - final int imageItemRenderingMode =MediaItem.RENDERING_MODE_BLACK_BORDER; - final MediaImageItem mediaImageItem1 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "mediaImageItem1", - imageItemFileName, 12000, imageItemRenderingMode); - mVideoEditor.addMediaItem(mediaImageItem1); - - assertTrue("Overlay List Size", - (mediaImageItem1.getAllOverlays().size() == 0) ? true : false); - assertNull("Overlay Item by ID", mediaImageItem1.getOverlay("xyz")); - final Bitmap mBitmap = mVideoEditorHelper.getBitmap(overlayItemFileName, - 640, 480); - final OverlayFrame overlayFrame = - mVideoEditorHelper.createOverlay(mediaImageItem1, "overlayId", - mBitmap, 5000, 5000); - mediaImageItem1.addOverlay(overlayFrame); - - assertTrue("Overlay List Size", - (mediaImageItem1.getAllOverlays().size() == 1) ? true : false); - assertEquals("Overlay Item by Valid ID", overlayFrame, mediaImageItem1 - .getOverlay(overlayFrame.getId())); - assertNull("Overlay Item by Invalid ID", - mediaImageItem1.getOverlay("xyz")); - assertNull("Remove Overlay Item by Invalid ID", - mediaImageItem1.removeOverlay("xyz")); - assertTrue("Overlay List Size", - (mediaImageItem1.getAllOverlays().size() == 1) ? true : false); - assertEquals("Overlay Removed", - overlayFrame, mediaImageItem1.removeOverlay(overlayFrame.getId())); - assertTrue("Overlay List Size", - (mediaImageItem1.getAllOverlays().size() == 0) ? true : false); - assertNull("Overlay Item by ID", - mediaImageItem1.getOverlay("effectId")); - } - - /** - * To test creation of Audio Track - */ - - // TODO : remove TC_API_017 - @LargeTest - public void testAudioTrack() throws Exception { - final String audioFileName = INPUT_FILE_PATH + - "AACLC_48KHz_256Kbps_s_1_17.3gp"; - final AudioTrack audioTrack = mVideoEditorHelper.createAudio( - mVideoEditor, "audioTrack", audioFileName); - mVideoEditor.addAudioTrack(audioTrack); - - assertEquals("Audio Track Item Duration", audioTrack.getDuration(), - audioTrack.getTimelineDuration()); - assertEquals("Audio Track Start Time", 0, audioTrack.getStartTime()); - assertFalse("Audio Track is Looping", audioTrack.isLooping()); - audioTrack.getVolume(); - assertFalse("Audio Track Ducking is Disabled", - audioTrack.isDuckingEnabled()); - assertTrue("Audio Track Filename", - audioTrack.getFilename().equals(audioFileName)); - assertEquals("Audio Ducking Threshold", 0, - audioTrack.getDuckingThreshhold()); - assertFalse("Audio Track Mute", audioTrack.isMuted()); - audioTrack.getDuckedTrackVolume(); - } - - /** - * To test creation of Audio Track with set extract boundaries - */ - // TODO : remove TC_API_018 - @LargeTest - public void testAudioTrackExtractBoundaries() throws Exception { - final String audioFileName = INPUT_FILE_PATH + - "AACLC_48KHz_256Kbps_s_1_17.3gp"; - boolean flagForException = false; - final AudioTrack audioTrack = mVideoEditorHelper.createAudio( - mVideoEditor, "audioTrack", audioFileName); - mVideoEditor.addAudioTrack(audioTrack); - - audioTrack.setExtractBoundaries(1000, 5000); - assertEquals("Audio Track Start time", 1000, - audioTrack.getBoundaryBeginTime()); - assertEquals("Audio Track End time", 5000, - audioTrack.getBoundaryEndTime()); - try { - audioTrack.setExtractBoundaries(0, 100000000); - } catch (IllegalArgumentException e) { - flagForException = true; - } - assertTrue("Audio Track With endTime > FileDuration", flagForException); - flagForException = false; - try { - audioTrack.setExtractBoundaries(100000000, 5000); - } catch (IllegalArgumentException e) { - flagForException = true; - } - assertTrue("Audio Track With startTime > FileDuration", - flagForException); - flagForException = false; - try { - audioTrack.setExtractBoundaries(0, 0); - } catch (IllegalArgumentException e) { - flagForException = true; - } - /* This is under discussion. Hence, checked for False */ - assertFalse("Audio Track With startTime = endTime", flagForException); - assertEquals("Audio Track Start time", 0, - audioTrack.getBoundaryBeginTime()); - assertEquals("Audio Track End time", 0, - audioTrack.getBoundaryEndTime()); - assertEquals("Audio Track Start time",0, - audioTrack.getBoundaryBeginTime()); - assertEquals("Audio Track End time", (audioTrack.getTimelineDuration()), - audioTrack.getBoundaryEndTime()); - audioTrack.setExtractBoundaries(0, audioTrack.getDuration() / 2); - assertEquals("Audio Track Start time",0, - audioTrack.getBoundaryBeginTime()); - assertEquals("Audio Track End time", (audioTrack.getDuration() / 2), - audioTrack.getBoundaryEndTime()); - audioTrack.setExtractBoundaries(1, audioTrack.getDuration() - 1); - assertEquals("Audio Track Start time", 1, - audioTrack.getBoundaryBeginTime()); - assertEquals("Audio Track End time", (audioTrack.getDuration() - 1), - audioTrack.getBoundaryEndTime()); - - flagForException = false; - try { - audioTrack.setExtractBoundaries(0, -1); - } catch (IllegalArgumentException e) { - flagForException = true; - } - assertTrue ("Audio Track end time < 0",flagForException); - } - - /** - * To test creation of Audio Track with set Start Time and Get Time - */ - // TODO : remove TC_API_019 - @LargeTest - public void testAudioTrackSetGetTime() throws Exception { - final String audioFileName = INPUT_FILE_PATH + - "AACLC_48KHz_256Kbps_s_1_17.3gp"; - boolean flagForException = false; - final AudioTrack audioTrack = mVideoEditorHelper.createAudio( - mVideoEditor, "audioTrack", audioFileName); - mVideoEditor.addAudioTrack(audioTrack); - /** set StartTime API is removed and start time is always 0 */ - assertEquals("Audio Track Start Time", 0, audioTrack.getStartTime()); - } - - /** - * To Test the Audio Track API: Enable Ducking - */ - // TODO : remove TC_API_020 - @LargeTest - public void testAudioTrackEnableDucking() throws Exception { - final String audioFileName = INPUT_FILE_PATH + - "AACLC_48KHz_256Kbps_s_1_17.3gp"; - boolean flagForException = false; - final AudioTrack audioTrack = mVideoEditorHelper.createAudio( - mVideoEditor, "audioTrack", audioFileName); - mVideoEditor.addAudioTrack(audioTrack); - - assertFalse("Audio Ducking Disabled by default", - audioTrack.isDuckingEnabled()); - audioTrack.enableDucking(45, 70); - assertTrue("Audio Ducking Enabled", audioTrack.isDuckingEnabled()); - assertEquals("Audio Ducking Threshold", 45, - audioTrack.getDuckingThreshhold()); - assertEquals("Audio Ducking Volume", 70, - audioTrack.getDuckedTrackVolume()); - audioTrack.enableDucking(85, 70); - assertEquals("Audio Ducking Threshold", 85, - audioTrack.getDuckingThreshhold()); - assertEquals("Audio Ducking Volume", 70, - audioTrack.getDuckedTrackVolume()); - try { - audioTrack.enableDucking(91, 70); - } catch (IllegalArgumentException e) { - flagForException = true; - } - assertTrue("Enable ducking threshold > 90", flagForException); - flagForException = false; - try { - audioTrack.enableDucking(90, 101); - } catch (IllegalArgumentException e) { - flagForException = true; - } - assertTrue("Enable ducking volume > 100", flagForException); - flagForException = false; - try { - audioTrack.enableDucking(91, 101); - } catch (IllegalArgumentException e) { - flagForException = true; - } - assertTrue("Enable ducking volume > 100 and threshold > 91", - flagForException); - flagForException = false; - try { - audioTrack.enableDucking(-1, 100); - } catch (IllegalArgumentException e) { - flagForException = true; - } - assertTrue("Enable ducking threshold < 0", flagForException); - flagForException = false; - try { - audioTrack.enableDucking(1, -1); - } catch (IllegalArgumentException e) { - flagForException = true; - } - assertTrue("Enable ducking lowVolume < 0", flagForException); - flagForException = false; - try { - audioTrack.enableDucking(0, 50); - } catch (IllegalArgumentException e) { - flagForException = true; - } - assertFalse("Enable ducking threshold = 0", flagForException); - } - - /** - * To Test the Audio Track API: Looping - */ - // TODO : remove TC_API_021 - @LargeTest - public void testAudioTrackLooping() throws Exception { - final String audioFileName = INPUT_FILE_PATH + - "AACLC_48KHz_256Kbps_s_1_17.3gp"; - final AudioTrack audioTrack = mVideoEditorHelper.createAudio( - mVideoEditor, "audioTrack", audioFileName); - mVideoEditor.addAudioTrack(audioTrack); - assertFalse("Audio Looping", audioTrack.isLooping()); - audioTrack.enableLoop(); - assertTrue("Audio Looping", audioTrack.isLooping()); - audioTrack.disableLoop(); - assertFalse("Audio Looping", audioTrack.isLooping()); - } - - /** - * To Test the Audio Track API:Extract waveform data - */ - // TODO : remove TC_API_022 - - @LargeTest - public void testAudioTrackWaveFormData() throws Exception { - /** Image item is added as dummy as Audio track cannot be added without - * a media item in the story board - */ - final String imageItemFileName = INPUT_FILE_PATH + "IMG_640x480.jpg"; - final int imageItemRenderingMode =MediaItem.RENDERING_MODE_BLACK_BORDER; - final MediaImageItem mediaImageItem = - mVideoEditorHelper.createMediaItem(mVideoEditor, "mediaImageItem1", - imageItemFileName, 5000, imageItemRenderingMode); - mVideoEditor.addMediaItem(mediaImageItem); - - final String audioFileName = INPUT_FILE_PATH + - "AACLC_48KHz_256Kbps_s_1_17.3gp"; - final AudioTrack audioTrack = mVideoEditorHelper.createAudio( - mVideoEditor, "audioTrack", audioFileName); - - mVideoEditor.addAudioTrack(audioTrack); - assertNull("WaveForm data", audioTrack.getWaveformData()); - - final int[] progressUpdate = new int[105]; - mVideoEditor.generatePreview(new MediaProcessingProgressListener() { - int i = 0; - public void onProgress(Object item, int action, int progress) { - progressUpdate[i++] = progress; - } - }); - - final int[] progressWaveform = new int[105]; - - audioTrack.extractAudioWaveform( - new ExtractAudioWaveformProgressListener() { - int i = 0; - public void onProgress(int progress) { - Log.i("AudioWaveformData","progress=" +progress); - progressWaveform[i++] = progress; - } - }); - assertTrue("Progress of WaveForm data", mVideoEditorHelper - .checkProgressCBValues(progressWaveform)); - assertNotNull("WaveForm data", audioTrack.getWaveformData()); - assertTrue("WaveForm Frame Duration", - (audioTrack.getWaveformData().getFrameDuration() > 0 ? - true : false)); - assertTrue("WaveForm Frame Count", - (audioTrack.getWaveformData().getFramesCount() > 0 ? true : false)); - assertTrue("WaveForm Gain", - (audioTrack.getWaveformData().getFrameGains().length > 0 ? - true : false)); - } - - /** - * To Test the Audio Track API: Mute - */ - // TODO : remove TC_API_023 - @LargeTest - public void testAudioTrackMute() throws Exception { - final String audioFileName = INPUT_FILE_PATH + - "AACLC_48KHz_256Kbps_s_1_17.3gp"; - final AudioTrack audioTrack = mVideoEditorHelper.createAudio( - mVideoEditor, "audioTrack", audioFileName); - assertFalse("Audio Track UnMute", audioTrack.isMuted()); - audioTrack.setMute(true); - assertTrue("Audio Track Mute", audioTrack.isMuted()); - audioTrack.setMute(false); - assertFalse("Audio Track UnMute", audioTrack.isMuted()); - } - - /** - * To Test the Audio Track API: Get Volume and Set Volume - */ - // TODO : remove TC_API_024 - @LargeTest - public void testAudioTrackGetSetVolume() throws Exception { - final String audioFileName = INPUT_FILE_PATH + - "AACLC_48KHz_256Kbps_s_1_17.3gp"; - boolean flagForException = false; - final AudioTrack audioTrack = mVideoEditorHelper.createAudio( - mVideoEditor, "audioTrack", audioFileName); - audioTrack.setVolume(0); - assertEquals("Audio Volume", 0, audioTrack.getVolume()); - assertFalse("Audio Track UnMute", audioTrack.isMuted()); - audioTrack.setVolume(45); - assertEquals("Audio Volume", 45, audioTrack.getVolume()); - assertFalse("Audio Track UnMute", audioTrack.isMuted()); - try { - audioTrack.setVolume(-1); - } catch (IllegalArgumentException e) { - flagForException = true; - } - assertTrue("Volume = -1", flagForException); - assertEquals("Audio Volume", 45, audioTrack.getVolume()); - flagForException = false; - try { - audioTrack.setVolume(101); - } catch (IllegalArgumentException e) { - flagForException = true; - } - assertTrue("Volume = 101", flagForException); - flagForException = false; - try { - audioTrack.setVolume(1000); - } catch (IllegalArgumentException e) { - flagForException = true; - } - assertTrue("Volume = 10000", flagForException); - assertEquals("Audio Volume", 45, audioTrack.getVolume()); - } - - /** - * To test Effect Color. - */ - // TODO : remove TC_API_025 - @LargeTest - public void testAllEffects() throws Exception { - final String videoItemFileName = INPUT_FILE_PATH + - "MPEG4_SP_640x480_30fps_512Kbps_0_27.mp4"; - boolean flagForException = false; - final MediaVideoItem mediaVideoItem1 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "mediaVideoItem1", - videoItemFileName, MediaItem.RENDERING_MODE_BLACK_BORDER); - mVideoEditor.addMediaItem(mediaVideoItem1); - - final EffectColor effectColor1 = mVideoEditorHelper.createEffectItem( - mediaVideoItem1, "effect1", 1000, 1000, EffectColor.TYPE_COLOR, - EffectColor.PINK); - mediaVideoItem1.addEffect(effectColor1); - - assertEquals("Associated Media Item", mediaVideoItem1, - effectColor1.getMediaItem()); - assertTrue("Effect Id", effectColor1.getId().equals("effect1")); - assertEquals("Effect StartTime", 1000, effectColor1.getStartTime()); - assertEquals("Effect EndTime", 1000, effectColor1.getDuration()); - assertEquals("Effect Type", EffectColor.TYPE_COLOR, - effectColor1.getType()); - assertEquals("Effect Color", EffectColor.PINK, effectColor1.getColor()); - - final EffectColor effectColor2 = mVideoEditorHelper.createEffectItem( - mediaVideoItem1, "effect2", 2000, 1000, EffectColor.TYPE_COLOR, - EffectColor.GRAY); - mediaVideoItem1.addEffect(effectColor2); - - assertEquals("Associated Media Item", mediaVideoItem1, - effectColor2.getMediaItem()); - assertTrue("Effect Id", effectColor2.getId().equals("effect2")); - assertEquals("Effect StartTime", 2000, effectColor2.getStartTime()); - assertEquals("Effect EndTime", 1000, effectColor2.getDuration()); - assertEquals("Effect Type", EffectColor.TYPE_COLOR, - effectColor2.getType()); - assertEquals("Effect Color", EffectColor.GRAY, effectColor2.getColor()); - - final EffectColor effectColor3 = mVideoEditorHelper.createEffectItem( - mediaVideoItem1, "effect3", 3000, 1000, EffectColor.TYPE_COLOR, - EffectColor.GREEN); - mediaVideoItem1.addEffect(effectColor3); - - assertEquals("Associated Media Item", mediaVideoItem1, - effectColor3.getMediaItem()); - assertTrue("Effect Id", effectColor3.getId().equals("effect3")); - assertEquals("Effect StartTime", 3000, effectColor3.getStartTime()); - assertEquals("Effect EndTime", 1000, effectColor3.getDuration()); - assertEquals("Effect Type", EffectColor.TYPE_COLOR, - effectColor3.getType()); - assertEquals("Effect Color", EffectColor.GREEN, effectColor3.getColor()); - - final EffectColor effectColor4 = mVideoEditorHelper.createEffectItem( - mediaVideoItem1, "effect4", 4000, 1000, EffectColor.TYPE_GRADIENT, - EffectColor.PINK); - mediaVideoItem1.addEffect(effectColor4); - - assertEquals("Associated Media Item", mediaVideoItem1, - effectColor4.getMediaItem()); - assertTrue("Effect Id", effectColor4.getId().equals("effect4")); - assertEquals("Effect StartTime", 4000, effectColor4.getStartTime()); - assertEquals("Effect EndTime", 1000, effectColor4.getDuration()); - assertEquals("Effect Type", EffectColor.TYPE_GRADIENT, - effectColor4.getType()); - assertEquals("Effect Color", EffectColor.PINK, effectColor4.getColor()); - - final EffectColor effectColor5 = mVideoEditorHelper.createEffectItem( - mediaVideoItem1, "effect5", 5000, 1000, - EffectColor.TYPE_GRADIENT, EffectColor.GRAY); - mediaVideoItem1.addEffect(effectColor5); - - assertEquals("Associated Media Item", mediaVideoItem1, - effectColor5.getMediaItem()); - assertTrue("Effect Id", effectColor5.getId().equals("effect5")); - assertEquals("Effect StartTime", 5000, effectColor5.getStartTime()); - assertEquals("Effect EndTime", 1000, effectColor5.getDuration()); - assertEquals("Effect Type", EffectColor.TYPE_GRADIENT, - effectColor5.getType()); - assertEquals("Effect Color", EffectColor.GRAY, effectColor5.getColor()); - - final EffectColor effectColor6 = mVideoEditorHelper.createEffectItem( - mediaVideoItem1, "effect6", 6000, 1000, - EffectColor.TYPE_GRADIENT, EffectColor.GREEN); - mediaVideoItem1.addEffect(effectColor6); - - assertEquals("Associated Media Item", mediaVideoItem1, - effectColor6.getMediaItem()); - assertTrue("Effect Id", effectColor6.getId().equals("effect6")); - assertEquals("Effect StartTime", 6000, effectColor6.getStartTime()); - assertEquals("Effect EndTime", 1000, effectColor6.getDuration()); - assertEquals("Effect Type", - EffectColor.TYPE_GRADIENT, effectColor6.getType()); - assertEquals("Effect Color", - EffectColor.GREEN, effectColor6.getColor()); - - final EffectColor effectColor7 = mVideoEditorHelper.createEffectItem( - mediaVideoItem1, "effect7", 7000, 1000, - EffectColor.TYPE_FIFTIES, 0); - mediaVideoItem1.addEffect(effectColor7); - - assertEquals("Associated Media Item", mediaVideoItem1, - effectColor7.getMediaItem()); - assertTrue("Effect Id", effectColor7.getId().equals("effect7")); - assertEquals("Effect StartTime", 7000, effectColor7.getStartTime()); - assertEquals("Effect EndTime", 1000, effectColor7.getDuration()); - assertEquals("Effect Type", EffectColor.TYPE_FIFTIES, - effectColor7.getType()); - assertEquals("Effect Color", -1, effectColor7.getColor()); - - final EffectColor effectColor8 = mVideoEditorHelper.createEffectItem( - mediaVideoItem1, "effect8", 8000, 1000, EffectColor.TYPE_SEPIA, 0); - mediaVideoItem1.addEffect(effectColor8); - - assertEquals("Associated Media Item", mediaVideoItem1, - effectColor8.getMediaItem()); - assertTrue("Effect Id", effectColor8.getId().equals("effect8")); - assertEquals("Effect StartTime", 8000, effectColor8.getStartTime()); - assertEquals("Effect EndTime", 1000, effectColor8.getDuration()); - assertEquals("Effect Type", EffectColor.TYPE_SEPIA, - effectColor8.getType()); - assertEquals("Effect Color", -1, effectColor8.getColor()); - - final EffectColor effectColor9 = mVideoEditorHelper.createEffectItem( - mediaVideoItem1, "effect9", 9000, 1000, - EffectColor.TYPE_NEGATIVE, 0); - mediaVideoItem1.addEffect(effectColor9); - - assertEquals("Associated Media Item", mediaVideoItem1, - effectColor9.getMediaItem()); - assertTrue("Effect Id", effectColor9.getId().equals("effect9")); - assertEquals("Effect StartTime", 9000, effectColor9.getStartTime()); - assertEquals("Effect EndTime", 1000, effectColor9.getDuration()); - assertEquals("Effect Type", EffectColor.TYPE_NEGATIVE, - effectColor9.getType()); - assertEquals("Effect Color", -1, effectColor9.getColor()); - try { - mVideoEditorHelper.createEffectItem(mediaVideoItem1, "effect9", - 9000, 1000, EffectColor.TYPE_COLOR - 1, 0); - } catch (IllegalArgumentException e) { - flagForException = true; - } - assertTrue("Effect type Invalid", flagForException); - flagForException = false; - try { - mVideoEditorHelper.createEffectItem(mediaVideoItem1, "effect9", - 9000, 1000, EffectColor.TYPE_FIFTIES + 1, 0); - } catch (IllegalArgumentException e) { - flagForException = true; - } - assertTrue("Effect type Invalid", flagForException); - try { - mVideoEditorHelper.createEffectItem(mediaVideoItem1, "effect10", - 10000, 1000, EffectColor.TYPE_FIFTIES + - EffectColor.TYPE_GRADIENT, 0); - } catch (IllegalArgumentException e) { - flagForException = true; - } - assertTrue("Effect type Invalid", flagForException); - } - - /** - * To test Effect Color : Set duration and Get Duration - */ - // TODO : remove TC_API_026 - @LargeTest - public void testEffectSetgetDuration() throws Exception { - final String videoItemFileName = INPUT_FILE_PATH + - "MPEG4_SP_640x480_30fps_512Kbps_0_27.mp4"; - final int videoItemRenderingMode =MediaItem.RENDERING_MODE_BLACK_BORDER; - boolean flagForException = false; - final MediaVideoItem mediaVideoItem1 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "mediaVideoItem1", - videoItemFileName, videoItemRenderingMode); - mVideoEditor.addMediaItem(mediaVideoItem1); - - final EffectColor effectColor1 = mVideoEditorHelper.createEffectItem( - mediaVideoItem1, "effect1", 1000, 2000, - EffectColor.TYPE_COLOR, EffectColor.PINK); - mediaVideoItem1.addEffect(effectColor1); - - effectColor1.setDuration(5000); - assertEquals("Updated Effect Duration", 5000, - effectColor1.getDuration()); - try { - effectColor1.setDuration(mediaVideoItem1.getDuration() + 1000); - } catch (IllegalArgumentException e) { - flagForException = true; - } - assertTrue("Effect Color duration > mediaVideoItemDuration", - flagForException); - assertEquals("Effect Duration", 5000, effectColor1.getDuration()); - flagForException = false; - try { - effectColor1.setDuration(-1); - } catch (IllegalArgumentException e) { - flagForException = true; - } - assertTrue("Effect Color duration = -1", flagForException); - } - - /** - * To test Effect Color : UNDEFINED color param value - */ - // TODO : remove TC_API_027 - @LargeTest - public void testEffectUndefinedColorParam() throws Exception { - final String videoItemFileName = INPUT_FILE_PATH + - "MPEG4_SP_640x480_30fps_512Kbps_0_27.mp4"; - final int videoItemRenderingMode =MediaItem.RENDERING_MODE_BLACK_BORDER; - boolean flagForException = false; - final MediaVideoItem mediaVideoItem1 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "mediaVideoItem1", - videoItemFileName, videoItemRenderingMode); - mVideoEditor.addMediaItem(mediaVideoItem1); - try{ - mVideoEditorHelper.createEffectItem(mediaVideoItem1, "effect1", 1000, - 2000, EffectColor.TYPE_COLOR, 0xabcdabcd); - }catch (IllegalArgumentException e){ - flagForException = true; - } - assertTrue("Invalid Effect added",flagForException); - } - - /** - * To test Effect Color : with Invalid StartTime and Duration - */ - // TODO : remove TC_API_028 - @LargeTest - public void testEffectInvalidStartTimeAndDuration() throws Exception { - final String videoItemFileName = INPUT_FILE_PATH + - "H264_BP_640x480_15fps_1200Kbps_AACLC_48KHz_32kbps_m_1_17.3gp"; - final int videoItemRenderingMode =MediaItem.RENDERING_MODE_BLACK_BORDER; - boolean flagForException = false; - final MediaVideoItem mediaVideoItem1 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "mediaVideoItem1", - videoItemFileName, videoItemRenderingMode); - mVideoEditor.addMediaItem(mediaVideoItem1); - - try { - mVideoEditorHelper.createEffectItem(mediaVideoItem1, "effect1", - 400000000, 2000, EffectColor.TYPE_COLOR, EffectColor.GREEN); - } catch (IllegalArgumentException e) { - flagForException = true; - } - assertTrue("Effect with invalid StartTime", flagForException); - - flagForException = false; - try { - mVideoEditorHelper.createEffectItem(mediaVideoItem1, "effect1", -1, - 2000, EffectColor.TYPE_COLOR, EffectColor.GREEN); - } catch (IllegalArgumentException e) { - flagForException = true; - } - assertTrue("Effect with invalid StartTime", flagForException); - - flagForException = false; - try { - mVideoEditorHelper.createEffectItem(mediaVideoItem1, "effect1", - 2000, -1, EffectColor.TYPE_COLOR, EffectColor.GREEN); - } catch (IllegalArgumentException e) { - flagForException = true; - } - assertTrue("Effect with invalid Duration", flagForException); - } - - - /** Test cases 29, 30, 31, 32 and 33 are removed */ - - - /** - * To test Effect : with NULL Media Item - */ - // TODO : remove TC_API_034 - @LargeTest - public void testEffectNullMediaItem() throws Exception { - boolean flagForException = false; - try { - mVideoEditorHelper.createEffectItem(null, "effect1", 1000, 4000, - EffectColor.TYPE_COLOR, EffectColor.GREEN); - } catch (IllegalArgumentException e) { - flagForException = true; - } - assertTrue("Effect with null MediaItem", flagForException); - } - - /** - * To test Effect : KenBurn Effect - */ - // TODO : remove TC_API_035 - @LargeTest - public void testEffectKenBurn() throws Exception { - // Test ken burn effect using a JPEG file. - testEffectKenBurn(INPUT_FILE_PATH + "IMG_640x480.jpg", - "mediaImageItem1"); - - // Test ken burn effect using a PNG file - testEffectKenBurn(INPUT_FILE_PATH + "IMG_640x480.png", - "mediaImageItem2"); - } - - private void testEffectKenBurn(final String imageItemFileName, - final String MediaId) throws Exception { - final int imageItemRenderingMode =MediaItem.RENDERING_MODE_BLACK_BORDER; - final MediaImageItem mediaImageItem = - mVideoEditorHelper.createMediaItem(mVideoEditor, MediaId, - imageItemFileName, 5000, imageItemRenderingMode); - mVideoEditor.addMediaItem(mediaImageItem); - - final Rect startRect = new Rect((mediaImageItem.getHeight() / 3), - (mediaImageItem.getWidth() / 3), (mediaImageItem.getHeight() / 2), - (mediaImageItem.getWidth() / 2)); - final Rect endRect = new Rect(0, 0, mediaImageItem.getWidth(), - mediaImageItem.getHeight()); - - final EffectKenBurns kbEffectOnMediaItem = new EffectKenBurns( - mediaImageItem, "KBOnM2", startRect, endRect, 500, 3000); - - assertNotNull("EffectKenBurns: " + imageItemFileName, - kbEffectOnMediaItem); - - mediaImageItem.addEffect(kbEffectOnMediaItem); - assertEquals("KenBurn Start Rect: " + imageItemFileName, startRect, - kbEffectOnMediaItem.getStartRect()); - - assertEquals("KenBurn End Rect: " + imageItemFileName, endRect, - kbEffectOnMediaItem.getEndRect()); - } - - /** - * To test KenBurnEffect : Set StartRect and EndRect - */ - - // TODO : remove TC_API_036 - @LargeTest - public void testEffectKenBurnSet() throws Exception { - final String imageItemFileName = INPUT_FILE_PATH + "IMG_640x480.jpg"; - final int imageItemRenderingMode =MediaItem.RENDERING_MODE_BLACK_BORDER; - boolean flagForException = false; - final MediaImageItem mediaImageItem = - mVideoEditorHelper.createMediaItem(mVideoEditor, "mediaImageItem1", - imageItemFileName, 5000, imageItemRenderingMode); - mVideoEditor.addMediaItem(mediaImageItem); - - final Rect startRect = new Rect((mediaImageItem.getHeight() / 3), - (mediaImageItem.getWidth() / 3), (mediaImageItem.getHeight() / 2), - (mediaImageItem.getWidth() / 2)); - final Rect endRect = new Rect(0, 0, mediaImageItem.getWidth(), - mediaImageItem.getHeight()); - - EffectKenBurns kbEffectOnMediaItem=null; - kbEffectOnMediaItem = new EffectKenBurns(mediaImageItem, "KBOnM2", - startRect, endRect, 500, 3000); - - assertNotNull("EffectKenBurns", kbEffectOnMediaItem); - mediaImageItem.addEffect(kbEffectOnMediaItem); - assertEquals("KenBurn Start Rect", startRect, - kbEffectOnMediaItem.getStartRect()); - assertEquals("KenBurn End Rect", endRect, - kbEffectOnMediaItem.getEndRect()); - - final Rect startRect1 = new Rect((mediaImageItem.getHeight() / 5), - (mediaImageItem.getWidth() / 5), (mediaImageItem.getHeight() / 4), - (mediaImageItem.getWidth() / 4)); - final Rect endRect1 = new Rect(10, 10, mediaImageItem.getWidth() / 4, - mediaImageItem.getHeight() / 4); - - /* Added newly to take care of removal set APIs */ - kbEffectOnMediaItem = new EffectKenBurns(mediaImageItem, "KBOnM2_changed", - startRect1, endRect1, 500, 3000); - - assertEquals("KenBurn Start Rect", startRect1, - kbEffectOnMediaItem.getStartRect()); - assertEquals("KenBurn End Rect", endRect1, - kbEffectOnMediaItem.getEndRect()); - - final Rect zeroRect = new Rect(0, 0, 0, 0); - try { - kbEffectOnMediaItem = new EffectKenBurns(mediaImageItem, "KBOnM2_zeroStart", - zeroRect, endRect, 500, 3000); - - } catch (IllegalArgumentException e) { - flagForException = true; - } - assertTrue("Invalid Start Rect", flagForException); - - flagForException = false; - try { - kbEffectOnMediaItem = new EffectKenBurns(mediaImageItem, "KBOnM2_zeroEnd", - startRect, zeroRect, 500, 3000); - } catch (IllegalArgumentException e) { - flagForException = true; - } - assertTrue("Invalid End Rect", flagForException); - } - - /** - * To test Transition : Fade To Black with all behavior - * SPEED_UP/SPEED_DOWN/LINEAR/MIDDLE_SLOW/MIDDLE_FAST - */ - - // TODO : remove TC_API_037 - @LargeTest - public void testTransitionFadeBlack() throws Exception { - - final String videoItemFilename1 = INPUT_FILE_PATH + - "H264_BP_640x480_30fps_256kbps_1_17.mp4"; - final String videoItemFilename2 = INPUT_FILE_PATH + - "H263_profile0_176x144_15fps_128kbps_1_35.3gp"; - final String imageItemFilename1 = INPUT_FILE_PATH + "IMG_1600x1200.jpg"; - final String videoItemFilename3 = INPUT_FILE_PATH + - "H264_BP_640x480_30fps_192kbps_1_5.mp4"; - final String videoItemFilename4 = INPUT_FILE_PATH + - "MPEG4_SP_640x480_15fps_256kbps_0_30.mp4"; - final String videoItemFilename5 = INPUT_FILE_PATH + - "H263_profile0_176x144_10fps_96kbps_0_25.3gp"; - boolean flagForException = false; - - final MediaVideoItem mediaVideoItem1 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", - videoItemFilename1, MediaItem.RENDERING_MODE_BLACK_BORDER); - mediaVideoItem1.setExtractBoundaries(0, 15000); - mVideoEditor.addMediaItem(mediaVideoItem1); - - final MediaVideoItem mediaVideoItem2 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m2", - videoItemFilename2, MediaItem.RENDERING_MODE_BLACK_BORDER); - mediaVideoItem2.setExtractBoundaries(0, 15000); - mVideoEditor.addMediaItem(mediaVideoItem2); - - final TransitionFadeBlack transition1And2 = mVideoEditorHelper - .createTFadeBlack("transition1And2", mediaVideoItem1, - mediaVideoItem2, 3000, Transition.BEHAVIOR_SPEED_UP); - mVideoEditor.addTransition(transition1And2); - - assertTrue("Transition ID", - transition1And2.getId().equals("transition1And2")); - assertEquals("Transtion After Media item", - mediaVideoItem1, transition1And2.getAfterMediaItem()); - assertEquals("Transtion Before Media item", mediaVideoItem2, - transition1And2.getBeforeMediaItem()); - assertEquals("Transtion Duration", 3000, transition1And2.getDuration()); - assertEquals("Transtion Behavior", Transition.BEHAVIOR_SPEED_UP, - transition1And2.getBehavior()); - - final MediaImageItem mediaImageItem3 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m3", - imageItemFilename1, 15000, MediaItem.RENDERING_MODE_BLACK_BORDER); - mVideoEditor.addMediaItem(mediaImageItem3); - - final TransitionFadeBlack transition2And3 = - mVideoEditorHelper.createTFadeBlack("transition2And3", mediaVideoItem2, - mediaImageItem3, 1000, Transition.BEHAVIOR_SPEED_DOWN); - mVideoEditor.addTransition(transition2And3); - - assertTrue("Transition ID", - transition2And3.getId().equals("transition2And3")); - assertEquals("Transtion After Media item", mediaVideoItem2, - transition2And3.getAfterMediaItem()); - assertEquals("Transtion Before Media item", mediaImageItem3, - transition2And3.getBeforeMediaItem()); - assertEquals("Transtion Duration", 1000, transition2And3.getDuration()); - assertEquals("Transtion Behavior", Transition.BEHAVIOR_SPEED_DOWN, - transition2And3.getBehavior()); - - final MediaVideoItem mediaVideoItem4 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m4", - videoItemFilename3, MediaItem.RENDERING_MODE_BLACK_BORDER); - mediaVideoItem4.setExtractBoundaries(0, 20000); - mVideoEditor.addMediaItem(mediaVideoItem4); - - final TransitionFadeBlack transition3And4 = - mVideoEditorHelper.createTFadeBlack("transition3And4", mediaImageItem3, - mediaVideoItem4, 5000, Transition.BEHAVIOR_LINEAR); - mVideoEditor.addTransition(transition3And4); - - assertTrue("Transition ID", - transition3And4.getId().equals("transition3And4")); - assertEquals("Transtion After Media item", mediaImageItem3, - transition3And4.getAfterMediaItem()); - assertEquals("Transtion Before Media item", mediaVideoItem4, - transition3And4.getBeforeMediaItem()); - assertEquals("Transtion Duration", 5000, transition3And4.getDuration()); - assertEquals("Transtion Behavior", Transition.BEHAVIOR_LINEAR, - transition3And4.getBehavior()); - - final MediaVideoItem mediaVideoItem5 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m5", - videoItemFilename4, MediaItem.RENDERING_MODE_BLACK_BORDER); - mVideoEditor.addMediaItem(mediaVideoItem5); - - final TransitionFadeBlack transition4And5 = - mVideoEditorHelper.createTFadeBlack("transition4And5", mediaVideoItem4, - mediaVideoItem5, 8000, Transition.BEHAVIOR_MIDDLE_FAST); - mVideoEditor.addTransition(transition4And5); - - assertTrue("Transition ID", - transition4And5.getId().equals("transition4And5")); - assertEquals("Transtion After Media item", mediaVideoItem4, - transition4And5.getAfterMediaItem()); - assertEquals("Transtion Before Media item", mediaVideoItem5, - transition4And5.getBeforeMediaItem()); - assertEquals("Transtion Duration", 8000, transition4And5.getDuration()); - assertEquals("Transtion Behavior", Transition.BEHAVIOR_MIDDLE_FAST, - transition4And5.getBehavior()); - - final MediaVideoItem mediaVideoItem6 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m6", - videoItemFilename5, MediaItem.RENDERING_MODE_BLACK_BORDER); - mediaVideoItem6.setExtractBoundaries(0, 20000); - mVideoEditor.addMediaItem(mediaVideoItem6); - - final TransitionFadeBlack transition5And6 = - mVideoEditorHelper.createTFadeBlack("transition5And6", mediaVideoItem5, - mediaVideoItem6, 2000, Transition.BEHAVIOR_MIDDLE_SLOW); - mVideoEditor.addTransition(transition5And6); - - assertTrue("Transition ID", - transition5And6.getId().equals("transition5And6")); - assertEquals("Transtion After Media item", mediaVideoItem5, - transition5And6.getAfterMediaItem()); - assertEquals("Transtion Before Media item", mediaVideoItem6, - transition5And6.getBeforeMediaItem()); - assertEquals("Transtion Duration", 2000, transition5And6.getDuration()); - assertEquals("Transtion Behavior", Transition.BEHAVIOR_MIDDLE_SLOW, - transition5And6.getBehavior()); - flagForException = false; - try { - mVideoEditorHelper.createTFadeBlack("transitiond6", mediaVideoItem5, - mediaVideoItem6, 2000, Transition.BEHAVIOR_SPEED_UP - 1); - } catch (IllegalArgumentException e) { - flagForException = true; - } - assertTrue("Transition FadeBlack with Invalid behavior", flagForException); - flagForException = false; - try { - mVideoEditorHelper.createTFadeBlack("transitiond6", mediaVideoItem5, - mediaVideoItem6, 2000, Transition.BEHAVIOR_MIDDLE_FAST + 1); - } catch (IllegalArgumentException e) { - flagForException = true; - } - assertTrue("Transition FadeBlack with Invalid behavior", flagForException); - } - - /** - * To test Transition : CrossFade with all behavior - * SPEED_UP/SPEED_DOWN/LINEAR/MIDDLE_SLOW/MIDDLE_FAST - */ - - // TODO : remove TC_API_038 - @LargeTest - public void testTransitionCrossFade() throws Exception { - - final String videoItemFilename1 = INPUT_FILE_PATH + - "H264_BP_640x480_30fps_256kbps_1_17.mp4"; - final String videoItemFilename2 = INPUT_FILE_PATH + - "H263_profile0_176x144_15fps_128kbps_1_35.3gp"; - final String imageItemFilename1 = INPUT_FILE_PATH + "IMG_1600x1200.jpg"; - final String videoItemFilename3 = INPUT_FILE_PATH + - "H264_BP_640x480_30fps_192kbps_1_5.mp4"; - final String videoItemFilename4 = INPUT_FILE_PATH + - "MPEG4_SP_640x480_15fps_256kbps_0_30.mp4"; - final String videoItemFilename5 = INPUT_FILE_PATH + - "H263_profile0_176x144_10fps_96kbps_0_25.3gp"; - boolean flagForException = false; - final MediaVideoItem mediaVideoItem1 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", - videoItemFilename1, MediaItem.RENDERING_MODE_BLACK_BORDER); - mediaVideoItem1.setExtractBoundaries(0, 15000); - mVideoEditor.addMediaItem(mediaVideoItem1); - - final MediaVideoItem mediaVideoItem2 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m2", - videoItemFilename2, MediaItem.RENDERING_MODE_BLACK_BORDER); - mediaVideoItem2.setExtractBoundaries(0, 15000); - mVideoEditor.addMediaItem(mediaVideoItem2); - - final TransitionCrossfade transition1And2 = - mVideoEditorHelper.createTCrossFade("transition1And2", mediaVideoItem1, - mediaVideoItem2, 3000, Transition.BEHAVIOR_SPEED_UP); - mVideoEditor.addTransition(transition1And2); - - assertTrue("Transition ID", - transition1And2.getId().equals("transition1And2")); - assertEquals("Transtion After Media item", mediaVideoItem1, - transition1And2.getAfterMediaItem()); - assertEquals("Transtion Before Media item", mediaVideoItem2, - transition1And2.getBeforeMediaItem()); - assertEquals("Transtion Duration", 3000, transition1And2.getDuration()); - assertEquals("Transtion Behavior", Transition.BEHAVIOR_SPEED_UP, - transition1And2.getBehavior()); - - final MediaImageItem mediaImageItem3 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m3", - imageItemFilename1, 15000, MediaItem.RENDERING_MODE_BLACK_BORDER); - mVideoEditor.addMediaItem(mediaImageItem3); - - final TransitionCrossfade transition2And3 = - mVideoEditorHelper.createTCrossFade("transition2And3", mediaVideoItem2, - mediaImageItem3, 1000, Transition.BEHAVIOR_SPEED_DOWN); - mVideoEditor.addTransition(transition2And3); - - assertTrue("Transition ID", - transition2And3.getId().equals("transition2And3")); - assertEquals("Transtion After Media item", mediaVideoItem2, - transition2And3.getAfterMediaItem()); - assertEquals("Transtion Before Media item", mediaImageItem3, - transition2And3.getBeforeMediaItem()); - assertEquals("Transtion Duration", 1000, transition2And3.getDuration()); - assertEquals("Transtion Behavior", Transition.BEHAVIOR_SPEED_DOWN, - transition2And3.getBehavior()); - - final MediaVideoItem mediaVideoItem4 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m4", - videoItemFilename3, MediaItem.RENDERING_MODE_BLACK_BORDER); - mediaVideoItem4.setExtractBoundaries(0, 18000); - mVideoEditor.addMediaItem(mediaVideoItem4); - - final TransitionCrossfade transition3And4 = - mVideoEditorHelper.createTCrossFade("transition3And4", mediaImageItem3, - mediaVideoItem4, 5000, Transition.BEHAVIOR_LINEAR); - mVideoEditor.addTransition(transition3And4); - - assertTrue("Transition ID", - transition3And4.getId().equals("transition3And4")); - assertEquals("Transtion After Media item", mediaImageItem3, - transition3And4.getAfterMediaItem()); - assertEquals("Transtion Before Media item", mediaVideoItem4, - transition3And4.getBeforeMediaItem()); - assertEquals("Transtion Duration", 5000, transition3And4.getDuration()); - assertEquals("Transtion Behavior", Transition.BEHAVIOR_LINEAR, - transition3And4.getBehavior()); - - final MediaVideoItem mediaVideoItem5 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m5", - videoItemFilename4, MediaItem.RENDERING_MODE_BLACK_BORDER); - mVideoEditor.addMediaItem(mediaVideoItem5); - - final TransitionCrossfade transition4And5 = - mVideoEditorHelper.createTCrossFade("transition4And5", mediaVideoItem4, - mediaVideoItem5, 8000, Transition.BEHAVIOR_MIDDLE_FAST); - mVideoEditor.addTransition(transition4And5); - - assertTrue("Transition ID", - transition4And5.getId().equals("transition4And5")); - assertEquals("Transtion After Media item", mediaVideoItem4, - transition4And5.getAfterMediaItem()); - assertEquals("Transtion Before Media item", mediaVideoItem5, - transition4And5.getBeforeMediaItem()); - assertEquals("Transtion Duration", 8000, transition4And5.getDuration()); - assertEquals("Transtion Behavior", Transition.BEHAVIOR_MIDDLE_FAST, - transition4And5.getBehavior()); - - final MediaVideoItem mediaVideoItem6 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m6", - videoItemFilename5, MediaItem.RENDERING_MODE_BLACK_BORDER); - mediaVideoItem6.setExtractBoundaries(0, 20000); - mVideoEditor.addMediaItem(mediaVideoItem6); - - final TransitionCrossfade transition5And6 = - mVideoEditorHelper.createTCrossFade("transition5And6", mediaVideoItem5, - mediaVideoItem6, 2000, Transition.BEHAVIOR_MIDDLE_SLOW); - mVideoEditor.addTransition(transition5And6); - - assertTrue("Transition ID", - transition5And6.getId().equals("transition5And6")); - assertEquals("Transtion After Media item", mediaVideoItem5, - transition5And6.getAfterMediaItem()); - assertEquals("Transtion Before Media item", mediaVideoItem6, - transition5And6.getBeforeMediaItem()); - assertEquals("Transtion Duration", 2000, transition5And6.getDuration()); - assertEquals("Transtion Behavior", Transition.BEHAVIOR_MIDDLE_SLOW, - transition5And6.getBehavior()); - - flagForException = false; - try { - mVideoEditorHelper.createTCrossFade("transitiond6", mediaVideoItem5, - mediaVideoItem6, 2000, Transition.BEHAVIOR_SPEED_UP - 1); - } catch (IllegalArgumentException e) { - flagForException = true; - } - assertTrue("Transition FadeBlack with Invalid behavior", flagForException); - flagForException = false; - try { - mVideoEditorHelper.createTCrossFade("transitiond6", mediaVideoItem5, - mediaVideoItem6, 2000, Transition.BEHAVIOR_MIDDLE_FAST + 1); - } catch (IllegalArgumentException e) { - flagForException = true; - } - assertTrue("Transition FadeBlack with Invalid behavior", flagForException); - } - - /** - * To test Transition : Sliding with all behavior - * SPEED_UP/SPEED_DOWN/LINEAR/MIDDLE_SLOW/MIDDLE_FAST and Direction = - * DIRECTION_RIGHT_OUT_LEFT_IN - * ,DIRECTION_LEFT_OUT_RIGHT_IN,DIRECTION_TOP_OUT_BOTTOM_IN - * ,DIRECTION_BOTTOM_OUT_TOP_IN - */ - - // TODO : remove TC_API_039 - @LargeTest - public void testTransitionSliding() throws Exception { - final String videoItemFilename1 = INPUT_FILE_PATH + - "H264_BP_640x480_30fps_256kbps_1_17.mp4"; - final String videoItemFilename2 = INPUT_FILE_PATH + - "H263_profile0_176x144_15fps_128kbps_1_35.3gp"; - final String imageItemFilename1 = INPUT_FILE_PATH + - "IMG_1600x1200.jpg"; - final String videoItemFilename3 = INPUT_FILE_PATH + - "H264_BP_640x480_30fps_192kbps_1_5.mp4"; - final String videoItemFilename4 = INPUT_FILE_PATH + - "MPEG4_SP_640x480_15fps_256kbps_0_30.mp4"; - final String videoItemFilename5 = INPUT_FILE_PATH + - "H263_profile0_176x144_10fps_96kbps_0_25.3gp"; - boolean flagForException = false; - - final MediaVideoItem mediaVideoItem1 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", - videoItemFilename1, MediaItem.RENDERING_MODE_BLACK_BORDER); - mediaVideoItem1.setExtractBoundaries(0, 15000); - mVideoEditor.addMediaItem(mediaVideoItem1); - - final MediaVideoItem mediaVideoItem2 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m2", - videoItemFilename2, MediaItem.RENDERING_MODE_BLACK_BORDER); - mediaVideoItem2.setExtractBoundaries(0, 15000); - mVideoEditor.addMediaItem(mediaVideoItem2); - - final TransitionSliding transition1And2 = - mVideoEditorHelper.createTSliding("transition1And2", mediaVideoItem1, - mediaVideoItem2, 3000, Transition.BEHAVIOR_SPEED_UP, - TransitionSliding.DIRECTION_RIGHT_OUT_LEFT_IN); - mVideoEditor.addTransition(transition1And2); - - assertTrue("Transition ID", - transition1And2.getId().equals("transition1And2")); - assertEquals("Transtion After Media item", mediaVideoItem1, - transition1And2.getAfterMediaItem()); - assertEquals("Transtion Before Media item", mediaVideoItem2, - transition1And2.getBeforeMediaItem()); - assertEquals("Transtion Duration", 3000, transition1And2.getDuration()); - assertEquals("Transtion Behavior", Transition.BEHAVIOR_SPEED_UP, - transition1And2.getBehavior()); - assertEquals("Transition Sliding", - TransitionSliding.DIRECTION_RIGHT_OUT_LEFT_IN, - transition1And2.getDirection()); - - final MediaImageItem mediaImageItem3 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m3", - imageItemFilename1, 15000, MediaItem.RENDERING_MODE_BLACK_BORDER); - mVideoEditor.addMediaItem(mediaImageItem3); - - final TransitionSliding transition2And3 = - mVideoEditorHelper.createTSliding("transition2And3", - mediaVideoItem2, mediaImageItem3, 1000, - Transition.BEHAVIOR_SPEED_DOWN, - TransitionSliding.DIRECTION_LEFT_OUT_RIGHT_IN); - mVideoEditor.addTransition(transition2And3); - - assertTrue("Transition ID", - transition2And3.getId().equals("transition2And3")); - assertEquals("Transtion After Media item", mediaVideoItem2, - transition2And3.getAfterMediaItem()); - assertEquals("Transtion Before Media item", mediaImageItem3, - transition2And3.getBeforeMediaItem()); - assertEquals("Transtion Duration", 1000, transition2And3.getDuration()); - assertEquals("Transtion Behavior", Transition.BEHAVIOR_SPEED_DOWN, - transition2And3.getBehavior()); - assertEquals("Transition Sliding", - TransitionSliding.DIRECTION_LEFT_OUT_RIGHT_IN, - transition2And3.getDirection()); - - final MediaVideoItem mediaVideoItem4 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m4", - videoItemFilename3, MediaItem.RENDERING_MODE_BLACK_BORDER); - mediaVideoItem4.setExtractBoundaries(0, 18000); - mVideoEditor.addMediaItem(mediaVideoItem4); - - final TransitionSliding transition3And4 = - mVideoEditorHelper.createTSliding("transition3And4", mediaImageItem3, - mediaVideoItem4, 5000, Transition.BEHAVIOR_LINEAR, - TransitionSliding.DIRECTION_TOP_OUT_BOTTOM_IN); - mVideoEditor.addTransition(transition3And4); - - assertTrue("Transition ID", - transition3And4.getId().equals("transition3And4")); - assertEquals("Transtion After Media item", mediaImageItem3, - transition3And4.getAfterMediaItem()); - assertEquals("Transtion Before Media item", mediaVideoItem4, - transition3And4.getBeforeMediaItem()); - assertEquals("Transtion Duration", 5000, transition3And4.getDuration()); - assertEquals("Transtion Behavior", Transition.BEHAVIOR_LINEAR, - transition3And4.getBehavior()); - assertEquals("Transition Sliding", - TransitionSliding.DIRECTION_TOP_OUT_BOTTOM_IN, - transition3And4.getDirection()); - - final MediaVideoItem mediaVideoItem5 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m5", - videoItemFilename4, MediaItem.RENDERING_MODE_BLACK_BORDER); - mVideoEditor.addMediaItem(mediaVideoItem5); - - final TransitionSliding transition4And5 = - mVideoEditorHelper.createTSliding("transition4And5", mediaVideoItem4, - mediaVideoItem5, 8000, Transition.BEHAVIOR_MIDDLE_FAST, - TransitionSliding.DIRECTION_BOTTOM_OUT_TOP_IN); - mVideoEditor.addTransition(transition4And5); - - assertTrue("Transition ID", - transition4And5.getId().equals("transition4And5")); - assertEquals("Transtion After Media item", mediaVideoItem4, - transition4And5.getAfterMediaItem()); - assertEquals("Transtion Before Media item", mediaVideoItem5, - transition4And5.getBeforeMediaItem()); - assertEquals("Transtion Duration", 8000, transition4And5.getDuration()); - assertEquals("Transtion Behavior", Transition.BEHAVIOR_MIDDLE_FAST, - transition4And5.getBehavior()); - assertEquals("Transition Sliding", - TransitionSliding.DIRECTION_BOTTOM_OUT_TOP_IN, - transition4And5.getDirection()); - - final MediaVideoItem mediaVideoItem6 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m6", - videoItemFilename5, MediaItem.RENDERING_MODE_BLACK_BORDER); - mediaVideoItem6.setExtractBoundaries(0, 20000); - mVideoEditor.addMediaItem(mediaVideoItem6); - - final TransitionSliding transition5And6 = - mVideoEditorHelper.createTSliding("transition5And6", mediaVideoItem5, - mediaVideoItem6, 2000, Transition.BEHAVIOR_MIDDLE_SLOW, - TransitionSliding.DIRECTION_RIGHT_OUT_LEFT_IN); - mVideoEditor.addTransition(transition5And6); - - assertTrue("Transition ID", - transition5And6.getId().equals("transition5And6")); - assertEquals("Transtion After Media item", mediaVideoItem5, - transition5And6.getAfterMediaItem()); - assertEquals("Transtion Before Media item", mediaVideoItem6, - transition5And6.getBeforeMediaItem()); - assertEquals("Transtion Duration", 2000, transition5And6.getDuration()); - assertEquals("Transtion Behavior", Transition.BEHAVIOR_MIDDLE_SLOW, - transition5And6.getBehavior()); - assertEquals("Transition Sliding", - TransitionSliding.DIRECTION_RIGHT_OUT_LEFT_IN, - transition5And6.getDirection()); - - flagForException = false; - try { - mVideoEditorHelper.createTSliding("transitiond6", mediaVideoItem5, - mediaVideoItem6, 2000, Transition.BEHAVIOR_MIDDLE_SLOW, - TransitionSliding.DIRECTION_RIGHT_OUT_LEFT_IN - 1); - } catch (IllegalArgumentException e) { - flagForException = true; - } - assertTrue("Transition Sliding with Invalid Direction", flagForException); - flagForException = false; - try { - mVideoEditorHelper.createTSliding("transitiond6", mediaVideoItem5, - mediaVideoItem6, 2000, Transition.BEHAVIOR_MIDDLE_FAST + 1, - TransitionSliding.DIRECTION_BOTTOM_OUT_TOP_IN + 1); - } catch (IllegalArgumentException e) { - flagForException = true; - } - assertTrue("Transition Sliding with Invalid behavior", flagForException); - flagForException = false; - try { - mVideoEditorHelper.createTSliding("transitiond6", mediaVideoItem5, - mediaVideoItem6, 2000, Transition.BEHAVIOR_SPEED_UP - 1, - TransitionSliding.DIRECTION_RIGHT_OUT_LEFT_IN); - } catch (IllegalArgumentException e) { - flagForException = true; - } - assertTrue("Transition Sliding with Invalid behavior", flagForException); - flagForException = false; - try { - mVideoEditorHelper.createTSliding("transitiond6", mediaVideoItem5, - mediaVideoItem6, 2000, Transition.BEHAVIOR_MIDDLE_FAST + 1, - TransitionSliding.DIRECTION_RIGHT_OUT_LEFT_IN); - } catch (IllegalArgumentException e) { - flagForException = true; - } - assertTrue("Transition Sliding with Invalid behavior", flagForException); - } - - /** - * To test Transition : Alpha with all behavior - * SPEED_UP/SPEED_DOWN/LINEAR/MIDDLE_SLOW/MIDDLE_FAST - */ - - // TODO : remove TC_API_040 - @LargeTest - public void testTransitionAlpha() throws Exception { - - final String videoItemFilename1 = INPUT_FILE_PATH + - "H264_BP_640x480_30fps_256kbps_1_17.mp4"; - final String videoItemFilename2 = INPUT_FILE_PATH + - "H263_profile0_176x144_15fps_128kbps_1_35.3gp"; - final String imageItemFilename1 = INPUT_FILE_PATH + - "IMG_640x480.jpg"; - final String videoItemFilename3 = INPUT_FILE_PATH + - "H264_BP_640x480_30fps_192kbps_1_5.mp4"; - final String videoItemFilename4 = INPUT_FILE_PATH + - "MPEG4_SP_640x480_15fps_256kbps_0_30.mp4"; - final String videoItemFilename5 = INPUT_FILE_PATH + - "H263_profile0_176x144_10fps_96kbps_0_25.3gp"; - final String maskFilename = INPUT_FILE_PATH + - "TransitionSpiral_QVGA.jpg"; - boolean flagForException = false; - final MediaVideoItem mediaVideoItem1 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", - videoItemFilename1, MediaItem.RENDERING_MODE_BLACK_BORDER); - mediaVideoItem1.setExtractBoundaries(0, 15000); - mVideoEditor.addMediaItem(mediaVideoItem1); - - final MediaVideoItem mediaVideoItem2 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m2", - videoItemFilename2, MediaItem.RENDERING_MODE_BLACK_BORDER); - mediaVideoItem2.setExtractBoundaries(0, 15000); - mVideoEditor.addMediaItem(mediaVideoItem2); - - final TransitionAlpha transition1And2 = - mVideoEditorHelper.createTAlpha("transition1And2", mediaVideoItem1, - mediaVideoItem2, 3000, Transition.BEHAVIOR_SPEED_UP, maskFilename, - 10, false); - mVideoEditor.addTransition(transition1And2); - - assertTrue("Transition ID", - transition1And2.getId().equals("transition1And2")); - assertEquals("Transtion After Media item", mediaVideoItem1, - transition1And2.getAfterMediaItem()); - assertEquals("Transtion Before Media item", mediaVideoItem2, - transition1And2.getBeforeMediaItem()); - assertEquals("Transtion Duration", 3000, transition1And2.getDuration()); - assertEquals("Transtion Behavior", Transition.BEHAVIOR_SPEED_UP, - transition1And2.getBehavior()); - assertTrue("Transition maskFile", - transition1And2.getMaskFilename().equals(maskFilename)); - assertEquals("Transition BlendingPercent", 10, - transition1And2.getBlendingPercent()); - assertFalse("Transition Invert", transition1And2.isInvert()); - - final MediaImageItem mediaImageItem3 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m3", - imageItemFilename1, 15000, MediaItem.RENDERING_MODE_BLACK_BORDER); - mVideoEditor.addMediaItem(mediaImageItem3); - - final TransitionAlpha transition2And3 = - mVideoEditorHelper.createTAlpha("transition2And3", mediaVideoItem2, - mediaImageItem3, 1000, Transition.BEHAVIOR_SPEED_DOWN, - maskFilename, 30, false); - mVideoEditor.addTransition(transition2And3); - - assertTrue("Transition ID", - transition2And3.getId().equals("transition2And3")); - assertEquals("Transtion After Media item", mediaVideoItem2, - transition2And3.getAfterMediaItem()); - assertEquals("Transtion Before Media item", mediaImageItem3, - transition2And3.getBeforeMediaItem()); - assertEquals("Transtion Duration", 1000, transition2And3.getDuration()); - assertEquals("Transtion Behavior", Transition.BEHAVIOR_SPEED_DOWN, - transition2And3.getBehavior()); - assertTrue("Transition maskFile", - transition2And3.getMaskFilename().equals(maskFilename)); - assertEquals("Transition BlendingPercent", 30, - transition2And3.getBlendingPercent()); - assertFalse("Transition Invert", transition2And3.isInvert()); - - final MediaVideoItem mediaVideoItem4 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m4", - videoItemFilename3, MediaItem.RENDERING_MODE_BLACK_BORDER); - mediaVideoItem4.setExtractBoundaries(0, 18000); - mVideoEditor.addMediaItem(mediaVideoItem4); - - final TransitionAlpha transition3And4 = - mVideoEditorHelper.createTAlpha("transition3And4", mediaImageItem3, - mediaVideoItem4, 5000, Transition.BEHAVIOR_LINEAR, maskFilename, - 50, false); - mVideoEditor.addTransition(transition3And4); - - assertTrue("Transition ID", - transition3And4.getId().equals("transition3And4")); - assertEquals("Transtion After Media item", mediaImageItem3, - transition3And4.getAfterMediaItem()); - assertEquals("Transtion Before Media item", mediaVideoItem4, - transition3And4.getBeforeMediaItem()); - assertEquals("Transtion Duration", 5000, transition3And4.getDuration()); - assertEquals("Transtion Behavior", Transition.BEHAVIOR_LINEAR, - transition3And4.getBehavior()); - assertTrue("Transition maskFile", - transition3And4.getMaskFilename().equals(maskFilename)); - assertEquals("Transition BlendingPercent", 50, - transition3And4.getBlendingPercent()); - assertFalse("Transition Invert", transition3And4.isInvert()); - - final MediaVideoItem mediaVideoItem5 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m5", - videoItemFilename4, MediaItem.RENDERING_MODE_BLACK_BORDER); - mVideoEditor.addMediaItem(mediaVideoItem5); - - final TransitionAlpha transition4And5 = - mVideoEditorHelper.createTAlpha("transition4And5", mediaVideoItem4, - mediaVideoItem5, 8000, Transition.BEHAVIOR_MIDDLE_FAST, - maskFilename, 70, true); - mVideoEditor.addTransition(transition4And5); - - assertTrue("Transition ID", - transition4And5.getId().equals("transition4And5")); - assertEquals("Transtion After Media item", mediaVideoItem4, - transition4And5.getAfterMediaItem()); - assertEquals("Transtion Before Media item", mediaVideoItem5, - transition4And5.getBeforeMediaItem()); - assertEquals("Transtion Duration", 8000, transition4And5.getDuration()); - assertEquals("Transtion Behavior", Transition.BEHAVIOR_MIDDLE_FAST, - transition4And5.getBehavior()); - assertTrue("Transition maskFile", - transition4And5.getMaskFilename().equals(maskFilename)); - assertEquals("Transition BlendingPercent", 70, - transition4And5.getBlendingPercent()); - assertTrue("Transition Invert", transition4And5.isInvert()); - - final MediaVideoItem mediaVideoItem6 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m6", - videoItemFilename5, MediaItem.RENDERING_MODE_BLACK_BORDER); - mediaVideoItem6.setExtractBoundaries(0, 20000); - mVideoEditor.addMediaItem(mediaVideoItem6); - - try { - mVideoEditorHelper.createTAlpha("transition5And6", mediaVideoItem5, - mediaVideoItem6, 2000, Transition.BEHAVIOR_MIDDLE_SLOW, - INPUT_FILE_PATH + "imDummyFile.jpg", 70, - true); - } catch (IllegalArgumentException e) { - flagForException = true; - } - assertTrue("MaskFile is not exsisting", flagForException); - flagForException = false; - try { - mVideoEditorHelper.createTAlpha("transition5And6", null, null, 2000, - Transition.BEHAVIOR_MIDDLE_SLOW, maskFilename, 101, true); - } catch (IllegalArgumentException e) { - flagForException = true; - } - assertTrue("Invalid Blending Percent", flagForException); - - flagForException = false; - try { - mVideoEditorHelper.createTAlpha("transitiond6", mediaVideoItem4, - mediaVideoItem5, 2000, Transition.BEHAVIOR_SPEED_UP - 1, - maskFilename, 30, false); - } catch (IllegalArgumentException e) { - flagForException = true; - } - assertTrue("Transition FadeBlack with Invalid behavior", flagForException); - flagForException = false; - try { - mVideoEditorHelper.createTAlpha("transitiond6", mediaVideoItem4, - mediaVideoItem5, 2000, Transition.BEHAVIOR_MIDDLE_FAST + 1, - maskFilename, 30, false); - } catch (IllegalArgumentException e) { - flagForException = true; - } - assertTrue("Transition FadeBlack with Invalid behavior", flagForException); - } - - /** - * To test Frame Overlay for Media Video Item - */ - - // TODO : remove TC_API_041 - @LargeTest - public void testFrameOverlayVideoItem() throws Exception { - final String videoItemFilename1 = INPUT_FILE_PATH + - "H263_profile0_176x144_10fps_256kbps_0_25.3gp"; - final String overlayFile1 = INPUT_FILE_PATH + "IMG_176x144_Overlay1.png"; - final String overlayFile2 = INPUT_FILE_PATH + "IMG_176x144_Overlay2.png"; - final MediaVideoItem mediaVideoItem1 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", - videoItemFilename1, MediaItem.RENDERING_MODE_BLACK_BORDER); - mVideoEditor.addMediaItem(mediaVideoItem1); - - final Bitmap mBitmap1 = mVideoEditorHelper.getBitmap(overlayFile1, - 176, 144); - final OverlayFrame overlayFrame1 = mVideoEditorHelper.createOverlay( - mediaVideoItem1, "overlayId1", mBitmap1, 5000, 5000); - mediaVideoItem1.addOverlay(overlayFrame1); - - assertEquals("Overlay : Media Item", mediaVideoItem1, - overlayFrame1.getMediaItem()); - assertTrue("Overlay Id", overlayFrame1.getId().equals("overlayId1")); - assertEquals("Overlay Bitmap", mBitmap1, overlayFrame1.getBitmap()); - assertEquals("Overlay Start Time", 5000, overlayFrame1.getStartTime()); - assertEquals("Overlay Duration", 5000, overlayFrame1.getDuration()); - - Bitmap upddateBmp = mVideoEditorHelper.getBitmap(overlayFile2, 176, 144); - overlayFrame1.setBitmap(upddateBmp); - assertEquals("Overlay Update Bitmap", upddateBmp, overlayFrame1.getBitmap()); - upddateBmp.recycle(); - } - - /** - * To test Frame Overlay for Media Video Item : Set duration and Get - * Duration - */ - - // TODO : remove TC_API_042 - @LargeTest - public void testFrameOverlaySetAndGet() throws Exception { - final String videoItemFilename1 = INPUT_FILE_PATH + - "MPEG4_SP_640x480_30fps_512Kbps_0_27.mp4"; - final String overlayFile1 = INPUT_FILE_PATH + "IMG_640x480_Overlay1.png"; - boolean flagForException = false; - - final Bitmap mBitmap = mVideoEditorHelper.getBitmap(overlayFile1, - 640, 480); - - final MediaVideoItem mediaVideoItem1 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", - videoItemFilename1, MediaItem.RENDERING_MODE_BLACK_BORDER); - mVideoEditor.addMediaItem(mediaVideoItem1); - - final OverlayFrame overlayFrame1 = mVideoEditorHelper.createOverlay( - mediaVideoItem1, "overlayId1", mBitmap, 5000, 5000); - mediaVideoItem1.addOverlay(overlayFrame1); - overlayFrame1.setDuration(5000); - - assertEquals("Overlay Duration", 5000, overlayFrame1.getDuration()); - try { - overlayFrame1.setDuration(mediaVideoItem1.getDuration() + 10000); - } catch (IllegalArgumentException e) { - flagForException = true; - } - assertTrue("Overlay Duration > MediaVideo Item Duration", - flagForException); - - assertEquals("Overlay Duration", 5000, overlayFrame1.getDuration()); - flagForException = false; - - try { - overlayFrame1.setDuration(-1); - } catch (IllegalArgumentException e) { - flagForException = true; - } - assertTrue("Overlay Duration = -1", flagForException); - } - - /** - * To test Frame Overlay for Media Video Item : Set duration and Get - * Duration - */ - - // TODO : remove TC_API_043 - @LargeTest - public void testFrameOverlayInvalidTime() throws Exception { - final String videoItemFilename1 = INPUT_FILE_PATH + - "MPEG4_SP_640x480_15fps_1200kbps_AACLC_48khz_64kbps_m_1_17.3gp"; - final String overlayFile1 = INPUT_FILE_PATH + "IMG_640x480_Overlay1.png"; - boolean flagForException = false; - - final MediaVideoItem mediaVideoItem1 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", - videoItemFilename1, MediaItem.RENDERING_MODE_BLACK_BORDER); - mVideoEditor.addMediaItem(mediaVideoItem1); - - try { - final Bitmap mBitmap = mVideoEditorHelper.getBitmap(overlayFile1, - 640, 480); - mVideoEditorHelper.createOverlay(mediaVideoItem1, "overlayId1", - mBitmap, 400000000, 2000); - } catch (IllegalArgumentException e) { - flagForException = true; - } - assertTrue("Overlay With Invalid Start Time", flagForException); - - flagForException = false; - try { - final Bitmap mBitmap = mVideoEditorHelper.getBitmap(overlayFile1, - 640, 480); - mVideoEditorHelper.createOverlay(mediaVideoItem1, "overlayId2", - mBitmap, -1, 2000); - } catch (IllegalArgumentException e) { - flagForException = true; - } - assertTrue("Overlay With Invalid Start Time", flagForException); - - flagForException = false; - try { - final Bitmap mBitmap = mVideoEditorHelper.getBitmap(overlayFile1, - 640, 480); - mVideoEditorHelper.createOverlay(mediaVideoItem1, "overlayId3", - mBitmap, 2000, -1); - } catch (IllegalArgumentException e) { - flagForException = true; - } - assertTrue("Overlay With Invalid Start Time", flagForException); - } - - /** - * To test Frame Overlay for Media Image Item - */ - // TODO : remove TC_API_045 - @LargeTest - public void testFrameOverlayImageItem() throws Exception { - final String imageItemFilename1 = INPUT_FILE_PATH + "IMG_640x480.jpg"; - final String overlayFile1 = INPUT_FILE_PATH + "IMG_640x480_Overlay1.png"; - final String overlayFile2 = INPUT_FILE_PATH + "IMG_640x480_Overlay2.png"; - - final MediaImageItem mediaImageItem1 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", - imageItemFilename1, 10000, MediaItem.RENDERING_MODE_BLACK_BORDER); - mVideoEditor.addMediaItem(mediaImageItem1); - - final Bitmap mBitmap = mVideoEditorHelper.getBitmap(overlayFile1, 640, - 480); - final OverlayFrame overlayFrame1 = mVideoEditorHelper.createOverlay( - mediaImageItem1, "overlayId1", mBitmap, 5000, 5000); - mediaImageItem1.addOverlay(overlayFrame1); - - assertEquals("Overlay : Media Item", mediaImageItem1, - overlayFrame1.getMediaItem()); - assertTrue("Overlay Id", overlayFrame1.getId().equals("overlayId1")); - assertEquals("Overlay Bitmap",mBitmap ,overlayFrame1.getBitmap()); - assertEquals("Overlay Start Time", 5000, overlayFrame1.getStartTime()); - assertEquals("Overlay Duration", 5000, overlayFrame1.getDuration()); - Bitmap upddateBmp = mVideoEditorHelper.getBitmap(overlayFile2, 640, 480); - - overlayFrame1.setBitmap(upddateBmp); - assertEquals("Overlay Update Bitmap", upddateBmp, overlayFrame1.getBitmap()); - upddateBmp.recycle(); - } - - /** - * To test Frame Overlay for Media Image Item : Set duration and Get - * Duration - */ - - // TODO : remove TC_API_046 - @LargeTest - public void testFrameOverlaySetAndGetImage() throws Exception { - final String videoItemFilename1 = INPUT_FILE_PATH + "IMG_640x480.jpg"; - final String overlayFile1 = INPUT_FILE_PATH + "IMG_640x480_Overlay1.png"; - boolean flagForException = false; - - final MediaImageItem mediaImageItem1 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", - videoItemFilename1, 10000, MediaItem.RENDERING_MODE_BLACK_BORDER); - mVideoEditor.addMediaItem(mediaImageItem1); - - final Bitmap mBitmap = mVideoEditorHelper.getBitmap(overlayFile1, - 640, 480); - final OverlayFrame overlayFrame1 = mVideoEditorHelper.createOverlay( - mediaImageItem1, "overlayId1", mBitmap, 5000, 5000); - mediaImageItem1.addOverlay(overlayFrame1); - - overlayFrame1.setDuration(5000); - assertEquals("Overlay Duration", 5000, overlayFrame1.getDuration()); - - try { - overlayFrame1.setDuration(mediaImageItem1.getDuration() + 10000); - } catch (IllegalArgumentException e) { - flagForException = true; - } - assertTrue("Overlay Duration > Media Item Duration", flagForException); - assertEquals("Overlay Duration", 5000, overlayFrame1.getDuration()); - - flagForException = false; - try { - overlayFrame1.setDuration(-1); - } catch (IllegalArgumentException e) { - flagForException = true; - } - assertTrue("Overlay Duration = -1", flagForException); - } - - /** - * To test Frame Overlay for Media Image Item :Invalid StartTime and - * Duration - */ - - // TODO : remove TC_API_047 - @LargeTest - public void testFrameOverlayInvalidTimeImage() throws Exception { - final String videoItemFilename1 = INPUT_FILE_PATH + "IMG_640x480.jpg"; - final String overlayFile1 = INPUT_FILE_PATH + "IMG_640x480_Overlay1.png"; - boolean flagForException = false; - - final MediaImageItem mediaImageItem1 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", - videoItemFilename1, 10000, MediaItem.RENDERING_MODE_BLACK_BORDER); - mVideoEditor.addMediaItem(mediaImageItem1); - - try { - final Bitmap mBitmap = mVideoEditorHelper.getBitmap(overlayFile1, - 640, 480); - mVideoEditorHelper.createOverlay(mediaImageItem1, "overlayId1", - mBitmap, 400000000, 2000); - } catch (IllegalArgumentException e) { - flagForException = true; - } - assertTrue("Overlay With Invalid Start Time", flagForException); - - flagForException = false; - try { - final Bitmap mBitmap = mVideoEditorHelper.getBitmap(overlayFile1, - 640, 480); - mVideoEditorHelper.createOverlay(mediaImageItem1, "overlayId2", - mBitmap, -1, 2000); - } catch (IllegalArgumentException e) { - flagForException = true; - } - assertTrue("Overlay With Invalid Start Time", flagForException); - - flagForException = false; - try { - final Bitmap mBitmap = mVideoEditorHelper.getBitmap(overlayFile1, - 640, 480); - mVideoEditorHelper.createOverlay(mediaImageItem1, "overlayId3", - mBitmap, 2000, -1); - } catch (IllegalArgumentException e) { - flagForException = true; - } - assertTrue("Overlay With Invalid Start Time", flagForException); - } - - /** - * To Test Frame Overlay Media Image Item :JPG File - */ - - // TODO : remove TC_API_048 - @LargeTest - public void testFrameOverlayJPGImage() throws Exception { - - final String imageItemFilename = INPUT_FILE_PATH + "IMG_640x480.jpg"; - final String overlayFile1 = INPUT_FILE_PATH + "IMG_640x480_Overlay1.png"; - boolean flagForException = false; - final MediaImageItem mediaImageItem1 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", - imageItemFilename, 10000, MediaItem.RENDERING_MODE_BLACK_BORDER); - mVideoEditor.addMediaItem(mediaImageItem1); - final Bitmap mBitmap = mVideoEditorHelper.getBitmap(overlayFile1, 640, - 480); - mVideoEditorHelper.createOverlay(mediaImageItem1, "overlayId1", - mBitmap, 5000, 5000); - } - - /** - * To test Video Editor API - * - * @throws Exception - */ - // TODO : remove TC_API_049 - @LargeTest - public void testVideoEditorAPI() throws Exception { - - final String videoItemFileName1 = INPUT_FILE_PATH - + "MPEG4_SP_720x480_30fps_280kbps_AACLC_48kHz_96kbps_s_0_21.mp4"; - final String videoItemFileName2 = INPUT_FILE_PATH + - "MPEG4_SP_640x480_15fps_1200kbps_AACLC_48khz_64kbps_m_1_17.3gp"; - final String videoItemFileName3 = INPUT_FILE_PATH - + "MPEG4_SP_640x480_15fps_512kbps_AACLC_48khz_132kbps_s_0_26.mp4"; - final String imageItemFileName1 = INPUT_FILE_PATH + "IMG_640x480.jpg"; - final String imageItemFileName2 = INPUT_FILE_PATH + "IMG_176x144.jpg"; - final String audioFilename1 = INPUT_FILE_PATH + - "AMRNB_8KHz_12.2Kbps_m_1_17.3gp"; - final String audioFilename2 = INPUT_FILE_PATH + - "AACLC_48KHz_256Kbps_s_1_17.3gp"; - final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; - boolean flagForException = false; - TransitionCrossfade transition2And4; - - final MediaVideoItem mediaVideoItem1 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", - videoItemFileName1, renderingMode); - mediaVideoItem1.setExtractBoundaries(0, 10000); - mVideoEditor.addMediaItem(mediaVideoItem1); - - final MediaVideoItem mediaVideoItem2 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m2", - videoItemFileName2, renderingMode); - mediaVideoItem2.setExtractBoundaries(mediaVideoItem2.getDuration() / 4, - mediaVideoItem2.getDuration() / 2); - mVideoEditor.addMediaItem(mediaVideoItem2); - - final MediaVideoItem mediaVideoItem3 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m3", - videoItemFileName3, renderingMode); - mediaVideoItem3.setExtractBoundaries(mediaVideoItem3.getDuration() / 2, - mediaVideoItem3.getDuration()); - mVideoEditor.addMediaItem(mediaVideoItem3); - - final MediaImageItem mediaImageItem1 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m4", - imageItemFileName1, 5000, renderingMode); - - final MediaImageItem mediaImageItem2 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m5", - imageItemFileName2, 5000, renderingMode); - - List mediaList = mVideoEditor.getAllMediaItems(); - assertEquals("Media Item List Size", 3, mediaList.size()); - - mVideoEditor.insertMediaItem(mediaImageItem1, mediaVideoItem2.getId()); - mediaList = mVideoEditor.getAllMediaItems(); - assertEquals("Media Item List Size", 4, mediaList.size()); - assertEquals("Media item 1", mediaVideoItem1, mediaList.get(0)); - assertEquals("Media item 2", mediaVideoItem2, mediaList.get(1)); - assertEquals("Media item 4", mediaImageItem1, mediaList.get(2)); - assertEquals("Media item 3", mediaVideoItem3, mediaList.get(3)); - - mVideoEditor.insertMediaItem(mediaImageItem2, mediaImageItem1.getId()); - mediaList = mVideoEditor.getAllMediaItems(); - assertEquals("Media Item List Size", 5, mediaList.size()); - assertEquals("Media item 1", mediaVideoItem1, mediaList.get(0)); - assertEquals("Media item 2", mediaVideoItem2, mediaList.get(1)); - assertEquals("Media item 4", mediaImageItem1, mediaList.get(2)); - assertEquals("Media item 5", mediaImageItem2, mediaList.get(3)); - assertEquals("Media item 3", mediaVideoItem3, mediaList.get(4)); - - mVideoEditor.moveMediaItem(mediaVideoItem1.getId(), mediaImageItem2.getId()); - mediaList = mVideoEditor.getAllMediaItems(); - assertEquals("Media Item List Size", 5, mediaList.size()); - assertEquals("Media item 2", mediaVideoItem2, mediaList.get(0)); - assertEquals("Media item 4", mediaImageItem1, mediaList.get(1)); - assertEquals("Media item 5", mediaImageItem2, mediaList.get(2)); - assertEquals("Media item 1", mediaVideoItem1, mediaList.get(3)); - assertEquals("Media item 3", mediaVideoItem3, mediaList.get(4)); - - assertEquals("Media Item 1", mediaVideoItem1, - mVideoEditor.getMediaItem(mediaVideoItem1.getId())); - - flagForException = false; - transition2And4 = null; - try{ - transition2And4 = mVideoEditorHelper.createTCrossFade( - "transition2And4", mediaVideoItem2, mediaImageItem1, 2000, - Transition.BEHAVIOR_MIDDLE_FAST); - mVideoEditor.addTransition(transition2And4); - } - catch (IllegalArgumentException e) { - flagForException = true; - } - assertFalse("Transition2and4 cannot be created", flagForException); - - - TransitionCrossfade transition1And3 = null; - flagForException = false; - try{ - transition1And3 = mVideoEditorHelper.createTCrossFade( - "transition1And3", mediaVideoItem1, mediaVideoItem2, 5000, - Transition.BEHAVIOR_MIDDLE_FAST); - mVideoEditor.addTransition(transition1And3); - }catch (IllegalArgumentException e) { - flagForException = true; - } - assertTrue("Transition1and3 cannot be created", flagForException); - - List transitionList = mVideoEditor.getAllTransitions(); - assertEquals("Transition List", 1, transitionList.size()); - - assertEquals("Transition 2", transition2And4, - mVideoEditor.getTransition(transition2And4.getId())); - - final AudioTrack audioTrack = mVideoEditorHelper.createAudio( - mVideoEditor, "audioTrack", audioFilename1); - mVideoEditor.addAudioTrack(audioTrack); - - List audioList = mVideoEditor.getAllAudioTracks(); - assertEquals("Audio List", 1, audioList.size()); - - final AudioTrack audioTrack1 = mVideoEditorHelper.createAudio( - mVideoEditor, "audioTrack1", audioFilename2); - flagForException = false; - try { - mVideoEditor.addAudioTrack(audioTrack1); - } catch (IllegalArgumentException e) { - flagForException = true; - } - assertTrue("Audio Track support is 1 ", flagForException); - - flagForException = false; - try { - mVideoEditor.insertAudioTrack(audioTrack1,"audioTrack"); - } catch (IllegalArgumentException e) { - flagForException = true; - } - assertTrue("Audio Track supports is 1 ", flagForException); - - assertEquals("Removing AudioTrack", audioTrack, - mVideoEditor.removeAudioTrack(audioTrack.getId())); - - assertEquals("Removing transition", transition2And4, - mVideoEditor.removeTransition(transition2And4.getId())); - - assertEquals("Removing Media Item", mediaVideoItem2, - mVideoEditor.removeMediaItem(mediaVideoItem2.getId())); - - mVideoEditor.setAspectRatio(MediaProperties.ASPECT_RATIO_16_9); - assertEquals("Check Aspect Ratio", MediaProperties.ASPECT_RATIO_16_9, - mVideoEditor.getAspectRatio()); - - long storyBoardDuration = mediaVideoItem1.getTimelineDuration() - + mediaVideoItem3.getTimelineDuration() - + mediaImageItem1.getDuration() - + mediaImageItem2.getDuration(); - assertEquals("Story Board Duration", storyBoardDuration, - mVideoEditor.getDuration()); - } - - /** - * To add Audio Track Greater than MediaItem Duration - * - * @throws Exception - */ - // TODO : remove TC_API_050 - @LargeTest - public void testVideoLessThanAudio() throws Exception { - final String videoItemFileName1 = INPUT_FILE_PATH - + "MPEG4_SP_720x480_30fps_280kbps_AACLC_48kHz_96kbps_s_0_21.mp4"; - final String audioTrackFilename = INPUT_FILE_PATH + - "AACLC_48KHz_256Kbps_s_1_17.3gp"; - final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; - - final MediaVideoItem mediaVideoItem1 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", - videoItemFileName1, renderingMode); - mVideoEditor.addMediaItem(mediaVideoItem1); - final AudioTrack audioTrack = mVideoEditorHelper.createAudio( - mVideoEditor, "audioTrackId", audioTrackFilename); - mVideoEditor.addAudioTrack(audioTrack); - assertEquals("Storyboard = mediaItem Duration", - mediaVideoItem1.getDuration(), mVideoEditor.getDuration()); - assertTrue("Audio Duration > mediaItem Duration", - (audioTrack.getDuration() > mediaVideoItem1.getDuration() ? - true : false)); - } - - /** - * To test Video Editor API with 1080 P - * - * @throws Exception - */ - // TODO : remove TC_API_051 - @LargeTest - public void testVideoContentHD() throws Exception { - final String videoItemFileName1 = INPUT_FILE_PATH - + "H264_BP_1920x1080_30fps_1200Kbps_1_10.mp4"; - final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; - final MediaVideoItem mediaVideoItem1; - // 1080p resolution is supported on some devices - // but not on other devices. - // So this test case is not generic and - // hence we always assert true - boolean flagForException = true; - try { - mediaVideoItem1 = mVideoEditorHelper.createMediaItem(mVideoEditor, - "m1", videoItemFileName1, renderingMode); - } catch (IllegalArgumentException e) { - } - assertTrue("VideoContent 1920x1080", flagForException); - } - - - /** - * To test: Remove audio track - * - * @throws Exception - */ - // TODO : remove TC_API_052 - @LargeTest - public void testRemoveAudioTrack() throws Exception { - final String audioFileName = INPUT_FILE_PATH + - "AACLC_48KHz_256Kbps_s_1_17.3gp"; - boolean flagForException = false; - - final AudioTrack audioTrack = mVideoEditorHelper.createAudio( - mVideoEditor, "audioTrack1", audioFileName); - mVideoEditor.addAudioTrack(audioTrack); - - assertEquals("Audio Track Item Duration", audioTrack.getDuration(), - audioTrack.getTimelineDuration()); - assertTrue("Audio Track ID", audioTrack.getId().equals("audioTrack1")); - assertNotNull("Remove Audio Track", - mVideoEditor.removeAudioTrack("audioTrack1")); - try{ - mVideoEditor.removeAudioTrack("audioTrack1"); - }catch (IllegalArgumentException e){ - flagForException = true; - } - assertTrue("Remove Audio Track not possible", flagForException); - } - - /** - * To test: Disable ducking - * - * @throws Exception - */ - // TODO : remove TC_API_053 - @LargeTest - public void testAudioDuckingDisable() throws Exception { - final String audioFileName = INPUT_FILE_PATH + - "AACLC_48KHz_256Kbps_s_1_17.3gp"; - final AudioTrack audioTrack = mVideoEditorHelper.createAudio( - mVideoEditor, "audioTrack", audioFileName); - mVideoEditor.addAudioTrack(audioTrack); - - audioTrack.disableDucking(); - assertFalse("Audio Track Ducking is Disabled", - audioTrack.isDuckingEnabled()); - } - - - // TODO : remove TC_API_054 - /** This test case is added with Test case ID TC_API_010 */ - - /** - * To test: Need a basic test case for the get value for TransitionAlpha - * ( ie. getBlendingPercent, getMaskFilename, isInvert) - * - * @throws Exception - */ - // TODO : remove TC_API_055 - @LargeTest - public void testTransitionAlphaBasic() throws Exception { - - final String videoItemFilename1 = INPUT_FILE_PATH + - "H264_BP_640x480_30fps_256kbps_1_17.mp4"; - final String maskFilename = INPUT_FILE_PATH + "IMG_640x480_Overlay1.png"; - boolean flagForException = false; - - final MediaVideoItem mediaVideoItem1 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", - videoItemFilename1, MediaItem.RENDERING_MODE_BLACK_BORDER); - mediaVideoItem1.setExtractBoundaries(0, 15000); - - final MediaImageItem mediaImageItem = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m2", maskFilename, - 10000, MediaItem.RENDERING_MODE_BLACK_BORDER); - mediaImageItem.setDuration(15000); - - mVideoEditor.addMediaItem(mediaVideoItem1); - mVideoEditor.addMediaItem(mediaImageItem); - final TransitionAlpha transition1And2 = - mVideoEditorHelper.createTAlpha("transition1And2", mediaVideoItem1, - mediaImageItem, 3000, Transition.BEHAVIOR_SPEED_UP, - maskFilename, 10, false); - mVideoEditor.addTransition(transition1And2); - assertTrue("Transition maskFile", - transition1And2.getMaskFilename().equals(maskFilename)); - assertEquals("Transition BlendingPercent", 10, - transition1And2.getBlendingPercent()); - assertFalse("Transition Invert", transition1And2.isInvert()); - } - - /** - * To test: NULL arguments to the Video Editor APIs - * - * @throws Exception - */ - // TODO : remove TC_API_056 - @LargeTest - public void testNullAPIs() throws Exception { - - final String videoItemFilename1 = INPUT_FILE_PATH + - "H264_BP_640x480_30fps_256kbps_1_17.mp4"; - final String maskFilename = INPUT_FILE_PATH + - "IMG_640x480_Overlay1.png"; - final String audioFileName = INPUT_FILE_PATH + - "AACLC_48KHz_256Kbps_s_1_17.3gp"; - boolean flagForException = false; - - try { - mVideoEditor.addAudioTrack(null); - } catch(IllegalArgumentException e) { - flagForException = true; - } - assertTrue("Video Editor with null Audio Track", flagForException); - flagForException = false; - try { - mVideoEditor.addMediaItem(null); - } catch(IllegalArgumentException e) { - flagForException = true; - } - assertTrue("Video Editor with NULL Image Item ", flagForException); - flagForException = false; - try { - mVideoEditor.addMediaItem(null); - } catch(IllegalArgumentException e) { - flagForException = true; - } - assertTrue("Video Editor with NULL Video Item ", flagForException); - - MediaVideoItem mediaVideoItem1 = null; - try { - mediaVideoItem1 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", - videoItemFilename1, MediaItem.RENDERING_MODE_BLACK_BORDER); - } catch (IllegalArgumentException e) { - assertTrue("Cannot Create Video Item", false); - } - mediaVideoItem1.setExtractBoundaries(0, 15000); - mVideoEditor.addMediaItem(mediaVideoItem1); - flagForException = false; - try { - mediaVideoItem1.addEffect(null); - } catch(IllegalArgumentException e) { - flagForException = true; - } - assertTrue("Video with null effect ", flagForException); - flagForException = false; - try { - mediaVideoItem1.addOverlay(null); - } catch(IllegalArgumentException e) { - flagForException = true; - } - assertTrue("Video with null overlay ", flagForException); - - final MediaImageItem mediaImageItem = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m2", maskFilename, - 10000, MediaItem.RENDERING_MODE_BLACK_BORDER); - mediaImageItem.setDuration(15000); - mVideoEditor.addMediaItem(mediaImageItem); - flagForException = false; - try { - mediaImageItem.addEffect(null); - } catch(IllegalArgumentException e) { - flagForException = true; - } - assertTrue("Image with null effect ", flagForException); - flagForException = false; - try { - mediaImageItem.addOverlay(null); - } catch(IllegalArgumentException e) { - flagForException = true; - } - assertTrue("Image with null overlay ", flagForException); - - final AudioTrack audioTrack = mVideoEditorHelper.createAudio( - mVideoEditor, "audioTrack", audioFileName); - mVideoEditor.addAudioTrack(audioTrack); - - flagForException = false; - try { - mVideoEditor.addTransition(null); - } catch(IllegalArgumentException e) { - flagForException = true; - } - assertTrue("Added null transition ", flagForException); - - flagForException = false; - try { - mVideoEditor.addTransition(null); - } catch(IllegalArgumentException e) { - flagForException = true; - } - assertTrue("Added null transition ", flagForException); - - } -} diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/VideoEditorExportTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/VideoEditorExportTest.java deleted file mode 100755 index e1b337d..0000000 --- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/VideoEditorExportTest.java +++ /dev/null @@ -1,820 +0,0 @@ -/* - * Copyright (C) 2011 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.mediaframeworktest.functional; - -import java.io.File; - -import android.graphics.Bitmap; -import android.graphics.Rect; -import android.media.videoeditor.AudioTrack; -import android.media.videoeditor.EffectColor; -import android.media.videoeditor.EffectKenBurns; -import android.media.videoeditor.MediaImageItem; -import android.media.videoeditor.MediaItem; -import android.media.videoeditor.MediaProperties; -import android.media.videoeditor.MediaVideoItem; -import android.media.videoeditor.OverlayFrame; -import android.media.videoeditor.Transition; -import android.media.videoeditor.TransitionAlpha; -import android.media.videoeditor.TransitionCrossfade; -import android.media.videoeditor.TransitionFadeBlack; -import android.media.videoeditor.TransitionSliding; -import android.media.videoeditor.VideoEditor; -import android.media.videoeditor.VideoEditor.ExportProgressListener; -import android.media.videoeditor.VideoEditor.MediaProcessingProgressListener; -import android.os.Environment; -import android.test.ActivityInstrumentationTestCase; - - -import android.util.Log; - -import com.android.mediaframeworktest.MediaFrameworkTest; -import android.test.suitebuilder.annotation.LargeTest; -import android.test.suitebuilder.annotation.Suppress; -import com.android.mediaframeworktest.VideoEditorHelper; - -public class VideoEditorExportTest extends - ActivityInstrumentationTestCase { - private final String TAG = "TransitionTest"; - - private final String PROJECT_LOCATION = VideoEditorHelper.PROJECT_LOCATION_COMMON; - - private final String INPUT_FILE_PATH = VideoEditorHelper.INPUT_FILE_PATH_COMMON; - - private VideoEditor mVideoEditor; - - private VideoEditorHelper mVideoEditorHelper; - - // Declares the annotation for Preview Test Cases - public @interface TransitionTests { - } - - public VideoEditorExportTest() { - super("com.android.mediaframeworktest", MediaFrameworkTest.class); - } - - @Override - protected void setUp() throws Exception { - // setup for each test case. - super.setUp(); - mVideoEditorHelper = new VideoEditorHelper(); - // Create a random String which will be used as project path, where all - // project related files will be stored. - final String projectPath = - mVideoEditorHelper.createRandomFile(PROJECT_LOCATION); - mVideoEditor = mVideoEditorHelper.createVideoEditor(projectPath); - } - - @Override - protected void tearDown() throws Exception { - mVideoEditorHelper.destroyVideoEditor(mVideoEditor); - // Clean the directory created as project path - mVideoEditorHelper.deleteProject(new File(mVideoEditor.getPath())); - System.gc(); - super.tearDown(); - } - - /** - * To Test export : Merge and Trim different types of Video and Image files - */ - // TODO :remove TC_EXP_001 - @LargeTest - public void testExportMergeTrim() throws Exception { - final String videoItemFilename1 = INPUT_FILE_PATH - + "H263_profile0_176x144_15fps_256kbps_AACLC_32kHz_128kbps_s_0_26.3gp"; - final String imageItemFilename1 = INPUT_FILE_PATH + "IMG_1600x1200.jpg"; - final String videoItemFilename2 = INPUT_FILE_PATH - + "H264_BP_640x480_12.5fps_256kbps_AACLC_16khz_24kbps_s_0_26.mp4"; - final String videoItemFilename3 = INPUT_FILE_PATH - + "MPEG4_SP_720x480_30fps_280kbps_AACLC_48kHz_96kbps_s_0_21.mp4"; - final String imageItemFilename2 = INPUT_FILE_PATH + "IMG_176x144.jpg"; - final String imageItemFilename3 = INPUT_FILE_PATH + "IMG_640x480.jpg"; - final String outFilename = mVideoEditorHelper - .createRandomFile(mVideoEditor.getPath() + "/") - + ".3gp"; - - final MediaVideoItem mediaVideoItem1 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", - videoItemFilename1, MediaItem.RENDERING_MODE_BLACK_BORDER); - mediaVideoItem1.setExtractBoundaries(2000, 7000); - mVideoEditor.addMediaItem(mediaVideoItem1); - - final MediaImageItem mediaImageItem2 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m2", - imageItemFilename1, 3000, MediaItem.RENDERING_MODE_BLACK_BORDER); - mVideoEditor.addMediaItem(mediaImageItem2); - - final MediaVideoItem mediaVideoItem3 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m3", - videoItemFilename2, MediaItem.RENDERING_MODE_BLACK_BORDER); - mediaVideoItem3.setExtractBoundaries(0, 2000); - mVideoEditor.addMediaItem(mediaVideoItem3); - - final MediaVideoItem mediaVideoItem4 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m4", - videoItemFilename3, MediaItem.RENDERING_MODE_BLACK_BORDER); - mediaVideoItem4.setExtractBoundaries(mediaVideoItem4.getDuration()-5000, - mediaVideoItem4.getDuration()); - mVideoEditor.addMediaItem(mediaVideoItem4); - - final MediaImageItem mediaImageItem5 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m5", - imageItemFilename2, 4000, MediaItem.RENDERING_MODE_BLACK_BORDER); - mVideoEditor.addMediaItem(mediaImageItem5); - - final MediaImageItem mediaImageItem6 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m6", - imageItemFilename3, 2000, MediaItem.RENDERING_MODE_BLACK_BORDER); - mVideoEditor.addMediaItem(mediaImageItem6); - - mVideoEditor.generatePreview(new MediaProcessingProgressListener() { - public void onProgress(Object item, int action, int progress) { - } - }); - - try { - final int[] progressUpdate = new int[100]; - mVideoEditor.export(outFilename, MediaProperties.HEIGHT_720, - MediaProperties.BITRATE_800K, new ExportProgressListener() { - int i = 0; - public void onProgress(VideoEditor ve, String outFileName, - int progress) { - progressUpdate[i++] = progress; - } - }); - mVideoEditorHelper.checkProgressCBValues(progressUpdate); - } catch (Exception e) { - assertTrue("Error in Export" + e.toString(), false); - } - final long storyBoardDuration = mediaVideoItem1.getTimelineDuration() - + mediaImageItem2.getDuration() + mediaVideoItem3.getTimelineDuration() - + mediaVideoItem4.getTimelineDuration() + mediaImageItem5.getDuration() - + mediaImageItem6.getDuration(); - mVideoEditorHelper.validateExport(mVideoEditor, outFilename, - MediaProperties.HEIGHT_720, 0, storyBoardDuration, - MediaProperties.VCODEC_H264, MediaProperties.ACODEC_AAC_LC); - mVideoEditorHelper.checkDeleteExistingFile(outFilename); - } - - /** - *To Test export : With Effect and Overlays on Different Media Items - */ - // TODO :remove TC_EXP_002 - @LargeTest - public void testExportEffectOverlay() throws Exception { - final String videoItemFilename1 = INPUT_FILE_PATH - + "H263_profile0_176x144_15fps_256kbps_AACLC_32kHz_128kbps_s_0_26.3gp"; - final String imageItemFilename1 = INPUT_FILE_PATH + "IMG_1600x1200.jpg"; - final String videoItemFilename2 = INPUT_FILE_PATH - + "H264_BP_640x480_15fps_1200Kbps_AACLC_48KHz_64kps_m_0_27.3gp"; - final String videoItemFilename3 = INPUT_FILE_PATH - + "MPEG4_SP_720x480_30fps_280kbps_AACLC_48kHz_96kbps_s_0_21.mp4"; - final String imageItemFilename2 = INPUT_FILE_PATH + "IMG_176x144.jpg"; - final String imageItemFilename3 = INPUT_FILE_PATH + "IMG_640x480.jpg"; - final String outFilename = mVideoEditorHelper - .createRandomFile(mVideoEditor.getPath() + "/") + ".3gp"; - - final String overlayFile = INPUT_FILE_PATH + "IMG_640x480_Overlay1.png"; - - final MediaVideoItem mediaVideoItem1 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", - videoItemFilename1, MediaItem.RENDERING_MODE_BLACK_BORDER); - mediaVideoItem1.setExtractBoundaries(2000, 7000); - mVideoEditor.addMediaItem(mediaVideoItem1); - - final EffectColor effectPink = - mVideoEditorHelper.createEffectItem(mediaVideoItem1, "effectPink", - 0, 2000, EffectColor.TYPE_COLOR, EffectColor.PINK); - mediaVideoItem1.addEffect(effectPink); - - final EffectColor effectNegative = - mVideoEditorHelper.createEffectItem(mediaVideoItem1, "effectNegative", - 3000, 4000, EffectColor.TYPE_NEGATIVE, 0); - mediaVideoItem1.addEffect(effectNegative); - - final MediaImageItem mediaImageItem2 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m2", - imageItemFilename1, 3000, MediaItem.RENDERING_MODE_BLACK_BORDER); - mVideoEditor.addMediaItem(mediaImageItem2); - - final EffectColor effectFifties = - mVideoEditorHelper.createEffectItem(mediaImageItem2, "effectFifties", - 0, 3000, EffectColor.TYPE_FIFTIES, 0); - mediaImageItem2.addEffect(effectFifties); - - final MediaVideoItem mediaVideoItem3 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m3", - videoItemFilename2, MediaItem.RENDERING_MODE_BLACK_BORDER); - mVideoEditor.addMediaItem(mediaVideoItem3); - mediaVideoItem3.setExtractBoundaries(0, 8000); - - final Bitmap mBitmap = mVideoEditorHelper.getBitmap(overlayFile, - 640, 480); - final OverlayFrame overlayFrame = - mVideoEditorHelper.createOverlay(mediaVideoItem3, "overlay", - mBitmap, 2000, 5000); - mediaVideoItem3.addOverlay(overlayFrame); - - final EffectColor effectGreen = - mVideoEditorHelper.createEffectItem(mediaVideoItem3, "effectGreen", - 0, 2000, EffectColor.TYPE_COLOR, EffectColor.GREEN); - mediaVideoItem3.addEffect(effectGreen); - - final MediaVideoItem mediaVideoItem4 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m4", - videoItemFilename3, MediaItem.RENDERING_MODE_BLACK_BORDER); - mediaVideoItem4.setExtractBoundaries(mediaVideoItem4.getDuration()-5000, - mediaVideoItem4.getDuration()); - mVideoEditor.addMediaItem(mediaVideoItem4); - - final EffectColor effectSepia = - mVideoEditorHelper.createEffectItem(mediaVideoItem4, "effectSepia", - 0, 2000, EffectColor.TYPE_SEPIA, 0); - mediaVideoItem4.addEffect(effectSepia); - - final MediaImageItem mediaImageItem5 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m5", - imageItemFilename2, 4000, MediaItem.RENDERING_MODE_BLACK_BORDER); - mVideoEditor.addMediaItem(mediaImageItem5); - - final EffectColor effectGray = - mVideoEditorHelper.createEffectItem(mediaImageItem5, "effectGray", - 0, 2000, EffectColor.TYPE_COLOR, EffectColor.GRAY); - mediaImageItem5.addEffect(effectGray); - - final MediaImageItem mediaImageItem6 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m6", - imageItemFilename3, 2000, MediaItem.RENDERING_MODE_BLACK_BORDER); - mVideoEditor.addMediaItem(mediaImageItem6); - - final EffectColor effectGradient = - mVideoEditorHelper.createEffectItem(mediaImageItem6, - "effectGradient", 0, 2000, EffectColor.TYPE_GRADIENT, - EffectColor.PINK); - mediaImageItem6.addEffect(effectGradient); - - mVideoEditor.generatePreview(new MediaProcessingProgressListener() { - public void onProgress(Object item, int action, int progress) { - } - }); - - try { - final int[] progressUpdate = new int[100]; - mVideoEditor.export(outFilename, MediaProperties.HEIGHT_720, - MediaProperties.BITRATE_800K, new ExportProgressListener() { - int i = 0; - public void onProgress(VideoEditor ve, String outFileName, - int progress) { - progressUpdate[i++] = progress; - } - }); - mVideoEditorHelper.checkProgressCBValues(progressUpdate); - } catch (Exception e) { - assertTrue("Error in Export" + e.toString(), false); - } - final long storyBoardDuration = mediaVideoItem1.getTimelineDuration() - + mediaImageItem2.getDuration() - + mediaVideoItem3.getTimelineDuration() - + mediaVideoItem4.getTimelineDuration() - + mediaImageItem5.getDuration() - + mediaImageItem6.getDuration(); - mVideoEditorHelper.validateExport(mVideoEditor, outFilename, - MediaProperties.HEIGHT_720, 0, storyBoardDuration, - MediaProperties.VCODEC_H264, MediaProperties.ACODEC_AAC_LC); - mVideoEditorHelper.checkDeleteExistingFile(outFilename); - } - - /** - * To test export : with Image with KenBurnEffect - */ - // TODO : remove TC_EXP_003 - @LargeTest - public void testExportEffectKenBurn() throws Exception { - final String imageItemFileName = INPUT_FILE_PATH + "IMG_640x480.jpg"; - final int imageItemRenderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; - final String outFilename = mVideoEditorHelper - .createRandomFile(mVideoEditor.getPath() + "/") + ".3gp"; - - final MediaImageItem mediaImageItem = - mVideoEditorHelper.createMediaItem(mVideoEditor, "mediaImageItem1", - imageItemFileName, 5000, imageItemRenderingMode); - mVideoEditor.addMediaItem(mediaImageItem); - - final Rect startRect = new Rect((mediaImageItem.getHeight() / 3), - (mediaImageItem.getWidth() / 3), (mediaImageItem.getHeight() / 2), - (mediaImageItem.getWidth() / 2)); - - final Rect endRect = new Rect(0, 0, mediaImageItem.getWidth(), - mediaImageItem.getHeight()); - - final EffectKenBurns kbEffectOnMediaItem = new EffectKenBurns( - mediaImageItem, "KBOnM2", startRect, endRect, 500, 3000); - assertNotNull("EffectKenBurns", kbEffectOnMediaItem); - mediaImageItem.addEffect(kbEffectOnMediaItem); - - assertEquals("KenBurn Start Rect", startRect, - kbEffectOnMediaItem.getStartRect()); - assertEquals("KenBurn End Rect", endRect, - kbEffectOnMediaItem.getEndRect()); - - mVideoEditor.generatePreview(new MediaProcessingProgressListener() { - public void onProgress(Object item, int action, int progress) { - } - }); - - try { - final int[] progressUpdate = new int[100]; - mVideoEditor.export(outFilename, MediaProperties.HEIGHT_720, - MediaProperties.BITRATE_800K, new ExportProgressListener() { - int i = 0; - public void onProgress(VideoEditor ve, String outFileName, - int progress) { - progressUpdate[i++] = progress; - } - }); - mVideoEditorHelper.checkProgressCBValues(progressUpdate); - } catch (Exception e) { - assertTrue("Error in Export" + e.toString(), false); - } - mVideoEditorHelper.validateExport(mVideoEditor, outFilename, - MediaProperties.HEIGHT_720, 0, mediaImageItem.getDuration(), - MediaProperties.VCODEC_H264, MediaProperties.ACODEC_AAC_LC); - mVideoEditorHelper.checkDeleteExistingFile(outFilename); - } - - /** - * To Test Export : With Video and Image and An Audio BackGround Track - */ - // TODO : remove TC_EXP_004 - @LargeTest - public void testExportAudio() throws Exception { - final String videoItemFileName = INPUT_FILE_PATH - + "H263_profile0_176x144_15fps_256kbps_AACLC_32kHz_128kbps_s_0_26.3gp"; - final String imageItemFileName = INPUT_FILE_PATH + "IMG_1600x1200.jpg"; - final String outFilename = mVideoEditorHelper - .createRandomFile(mVideoEditor.getPath() + "/") + ".3gp"; - final String audioTrackFilename = INPUT_FILE_PATH + - "AMRNB_8KHz_12.2Kbps_m_1_17.3gp"; - - final MediaVideoItem mediaVideoItem = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", - videoItemFileName, MediaItem.RENDERING_MODE_BLACK_BORDER); - mediaVideoItem.setExtractBoundaries(0, 10000); - mVideoEditor.addMediaItem(mediaVideoItem); - - final MediaImageItem mediaImageItem = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m2", - imageItemFileName, 5000, MediaItem.RENDERING_MODE_BLACK_BORDER); - mVideoEditor.addMediaItem(mediaImageItem); - - final AudioTrack audioTrack = mVideoEditorHelper.createAudio( - mVideoEditor, "a1", audioTrackFilename); - audioTrack.setExtractBoundaries(2000, 5000); - mVideoEditor.addAudioTrack(audioTrack); - - audioTrack.disableDucking(); - audioTrack.enableLoop(); - audioTrack.setVolume(75); - - mVideoEditor.generatePreview(new MediaProcessingProgressListener() { - public void onProgress(Object item, int action, int progress) { - } - }); - - try { - final int[] progressUpdate = new int[100]; - mVideoEditor.export(outFilename, MediaProperties.HEIGHT_720, - MediaProperties.BITRATE_800K, new ExportProgressListener() { - int i = 0; - public void onProgress(VideoEditor ve, String outFileName, - int progress) { - progressUpdate[i++] = progress; - } - }); - mVideoEditorHelper.checkProgressCBValues(progressUpdate); - } catch (Exception e) { - assertTrue("Error in Export" + e.toString(), false); - } - mVideoEditorHelper.validateExport(mVideoEditor, outFilename, - MediaProperties.HEIGHT_720, 0, (mediaVideoItem.getTimelineDuration() + - mediaImageItem.getDuration()), - MediaProperties.VCODEC_H264, MediaProperties.ACODEC_AAC_LC); - - mVideoEditorHelper.checkDeleteExistingFile(outFilename); - } - - /** - *To Test export : With Transition on Different Media Items - */ - // TODO :remove TC_EXP_005 - @LargeTest - public void testExportTransition() throws Exception { - final String videoItemFilename1 = INPUT_FILE_PATH - + "H263_profile0_176x144_15fps_256kbps_AACLC_32kHz_128kbps_s_0_26.3gp"; - final String imageItemFilename1 = INPUT_FILE_PATH + "IMG_1600x1200.jpg"; - final String videoItemFilename2 = INPUT_FILE_PATH - + "H264_BP_640x480_12.5fps_256kbps_AACLC_16khz_24kbps_s_0_26.mp4"; - final String videoItemFilename3 = INPUT_FILE_PATH + - "MPEG4_SP_720x480_30fps_280kbps_AACLC_48kHz_96kbps_s_0_21.mp4"; - - final String imageItemFilename2 = INPUT_FILE_PATH + "IMG_176x144.jpg"; - final String imageItemFilename3 = INPUT_FILE_PATH + "IMG_640x480.jpg"; - final String outFilename = mVideoEditorHelper - .createRandomFile(mVideoEditor.getPath() + "/") + ".3gp"; - final String maskFilename = INPUT_FILE_PATH + - "TransitionSpiral_QVGA.jpg"; - - final MediaVideoItem mediaItem1 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", - videoItemFilename1, MediaItem.RENDERING_MODE_BLACK_BORDER); - mediaItem1.setExtractBoundaries(2000, 7000); - mVideoEditor.addMediaItem(mediaItem1); - - final TransitionAlpha transition1 = - mVideoEditorHelper.createTAlpha("transition1", null, mediaItem1, - 2000, Transition.BEHAVIOR_LINEAR, maskFilename, 50, true); - mVideoEditor.addTransition(transition1); - - final MediaImageItem mediaItem2 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m2", - imageItemFilename1, 8000, MediaItem.RENDERING_MODE_BLACK_BORDER); - mVideoEditor.addMediaItem(mediaItem2); - - final MediaVideoItem mediaItem3 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m3", - videoItemFilename2, MediaItem.RENDERING_MODE_BLACK_BORDER); - mediaItem3.setExtractBoundaries(0, 8000); - mVideoEditor.addMediaItem(mediaItem3); - - final TransitionSliding transition2And3 = - mVideoEditorHelper.createTSliding("transition2", mediaItem2, - mediaItem3, 4000, Transition.BEHAVIOR_MIDDLE_FAST, - TransitionSliding.DIRECTION_RIGHT_OUT_LEFT_IN); - mVideoEditor.addTransition(transition2And3); - - final MediaVideoItem mediaItem4 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m4", - videoItemFilename3, MediaItem.RENDERING_MODE_BLACK_BORDER); - mVideoEditor.addMediaItem(mediaItem4); - mediaItem4.setExtractBoundaries(0, 8000); - - final TransitionCrossfade transition3And4 = - mVideoEditorHelper.createTCrossFade("transition3", mediaItem3, - mediaItem4, 3500, Transition.BEHAVIOR_MIDDLE_SLOW); - mVideoEditor.addTransition(transition3And4); - - final MediaImageItem mediaItem5 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m5", - imageItemFilename2, 7000, MediaItem.RENDERING_MODE_BLACK_BORDER); - mVideoEditor.addMediaItem(mediaItem5); - - final TransitionFadeBlack transition4And5 = - mVideoEditorHelper.createTFadeBlack("transition4", mediaItem4, - mediaItem5, 3500, Transition.BEHAVIOR_SPEED_DOWN); - mVideoEditor.addTransition(transition4And5); - - final MediaImageItem mediaItem6 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m6", - imageItemFilename3, 3000, MediaItem.RENDERING_MODE_BLACK_BORDER); - mVideoEditor.addMediaItem(mediaItem6); - - final TransitionSliding transition5And6 = - mVideoEditorHelper.createTSliding("transition5", mediaItem5, - mediaItem6, 1000/*4000*/, Transition.BEHAVIOR_SPEED_UP, - TransitionSliding.DIRECTION_LEFT_OUT_RIGHT_IN); - mVideoEditor.addTransition(transition5And6); - - final TransitionSliding transition6 = - mVideoEditorHelper.createTSliding("transition6", mediaItem6, null, - 1000 /*4000*/, Transition.BEHAVIOR_SPEED_UP, - TransitionSliding.DIRECTION_TOP_OUT_BOTTOM_IN); - mVideoEditor.addTransition(transition6); - - mVideoEditor.generatePreview(new MediaProcessingProgressListener() { - public void onProgress(Object item, int action, int progress) { - } - }); - - try { - final int[] progressUpdate = new int[100]; - mVideoEditor.export(outFilename, MediaProperties.HEIGHT_720, - MediaProperties.BITRATE_800K, new ExportProgressListener() { - int i = 0; - public void onProgress(VideoEditor ve, String outFileName, - int progress) { - progressUpdate[i++] = progress; - } - }); - mVideoEditorHelper.checkProgressCBValues(progressUpdate); - } catch (Exception e) { - assertTrue("Error in Export" + e.toString(), false); - } - final long storyBoardDuration = mediaItem1.getTimelineDuration() - + mediaItem2.getTimelineDuration() - + mediaItem3.getTimelineDuration() - transition2And3.getDuration() - + mediaItem4.getTimelineDuration() - transition3And4.getDuration() - + mediaItem5.getTimelineDuration() - transition4And5.getDuration() - + mediaItem6.getTimelineDuration() - transition5And6.getDuration(); - mVideoEditorHelper.validateExport(mVideoEditor, outFilename, - MediaProperties.HEIGHT_720, 0, storyBoardDuration, - MediaProperties.VCODEC_H264, MediaProperties.ACODEC_AAC_LC); - mVideoEditorHelper.checkDeleteExistingFile(outFilename); - } - - /** - * To Test Export : Without any Media Items in the story Board - * - * @throws Exception - */ - // TODO :remove TC_EXP_006 - @LargeTest - public void testExportWithoutMediaItems() throws Exception { - boolean flagForException = false; - try { - final int[] progressUpdate = new int[100]; - mVideoEditor.export("/sdcard/Test.3gp", MediaProperties.HEIGHT_720, - MediaProperties.BITRATE_800K, new ExportProgressListener() { - int i = 0; - public void onProgress(VideoEditor ve, String outFileName, - int progress) { - progressUpdate[i++] = progress; - } - }); - mVideoEditorHelper.checkProgressCBValues(progressUpdate); - } catch (IllegalStateException e) { - flagForException = true; - } - assertTrue("Export without any MediaItems", flagForException); - } - - /** - * To Test Export : With Media Items add and removed in the story Board - * - * @throws Exception - */ - // TODO :remove TC_EXP_007 - @LargeTest - public void testExportWithoutMediaItemsAddRemove() throws Exception { - final String videoItemFilename1 = INPUT_FILE_PATH + - "H263_profile0_176x144_15fps_256kbps_AACLC_32kHz_128kbps_s_1_17.3gp"; - final String imageItemFilename1 = INPUT_FILE_PATH + "IMG_640x480.jpg"; - final String maskFilename = INPUT_FILE_PATH + "TransitionSpiral_QVGA.jpg"; - boolean flagForException = false; - - final MediaVideoItem mediaItem1 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", - videoItemFilename1, MediaItem.RENDERING_MODE_BLACK_BORDER); - mediaItem1.setExtractBoundaries(0, 15000); - mVideoEditor.addMediaItem(mediaItem1); - - final MediaImageItem mediaItem2 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m2", - imageItemFilename1, 15000, - MediaItem.RENDERING_MODE_BLACK_BORDER); - mVideoEditor.addMediaItem(mediaItem2); - - final TransitionAlpha transition1 = - mVideoEditorHelper.createTAlpha("transition1", mediaItem1, mediaItem2, - 3000, Transition.BEHAVIOR_LINEAR, maskFilename, 50, false); - mVideoEditor.addTransition(transition1); - - final EffectColor effectColor = - mVideoEditorHelper.createEffectItem(mediaItem2, "effect", 12000, - 3000, EffectColor.TYPE_COLOR, EffectColor.PINK); - mediaItem2.addEffect(effectColor); - - mVideoEditor.removeMediaItem(mediaItem1.getId()); - mVideoEditor.removeMediaItem(mediaItem2.getId()); - try { - final int[] progressUpdate = new int[100]; - mVideoEditor.export("/sdcard/Test.3gp", MediaProperties.HEIGHT_720, - MediaProperties.BITRATE_800K, new ExportProgressListener() { - int i = 0; - public void onProgress(VideoEditor ve, String outFileName, - int progress) { - progressUpdate[i++] = progress; - } - }); - mVideoEditorHelper.checkProgressCBValues(progressUpdate); - } catch (IllegalStateException e) { - flagForException = true; - } - assertTrue("Export with MediaItem added and removed", flagForException); - } - - /** - * To Test Export : With Video and Image : MMS use case - * - * @throws Exception - */ - // TODO :remove TC_EXP_008 - @LargeTest - public void testExportMMS() throws Exception { - final String videoItemFilename1 = INPUT_FILE_PATH - + "H263_profile0_176x144_15fps_256kbps_AACLC_32kHz_128kbps_s_1_17.3gp"; - final String imageItemFilename1 = INPUT_FILE_PATH + "IMG_1600x1200.jpg"; - final String videoItemFilename2 = INPUT_FILE_PATH - + "H264_BP_640x480_12.5fps_256kbps_AACLC_16khz_24kbps_s_0_26.mp4"; - final String maskFilename = INPUT_FILE_PATH + "TransitionSpiral_QVGA.jpg"; - final String outFilename = mVideoEditorHelper - .createRandomFile(mVideoEditor.getPath() + "/") + ".3gp"; - - final MediaVideoItem mediaItem1 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", - videoItemFilename1, MediaItem.RENDERING_MODE_BLACK_BORDER); - mediaItem1.setExtractBoundaries(2000, 7000); - mVideoEditor.addMediaItem(mediaItem1); - - final TransitionAlpha transition1 = - mVideoEditorHelper.createTAlpha("transition1", null, mediaItem1, - 2000, Transition.BEHAVIOR_LINEAR, maskFilename, 50, true); - mVideoEditor.addTransition(transition1); - - final MediaImageItem mediaItem2 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m2", - imageItemFilename1, 8000, MediaItem.RENDERING_MODE_BLACK_BORDER); - mVideoEditor.addMediaItem(mediaItem2); - - final MediaVideoItem mediaItem3 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m3", - videoItemFilename2, MediaItem.RENDERING_MODE_BLACK_BORDER); - mediaItem3.setExtractBoundaries(0, 8000); - mVideoEditor.addMediaItem(mediaItem3); - - final TransitionSliding transition2And3 = - mVideoEditorHelper.createTSliding("transition2", mediaItem2, - mediaItem3, 4000, Transition.BEHAVIOR_MIDDLE_FAST, - TransitionSliding.DIRECTION_RIGHT_OUT_LEFT_IN); - mVideoEditor.addTransition(transition2And3); - - final TransitionCrossfade transition3 = - mVideoEditorHelper.createTCrossFade("transition3", mediaItem3, null, - 3500, Transition.BEHAVIOR_MIDDLE_SLOW); - mVideoEditor.addTransition(transition3); - - final EffectColor effectColor = - mVideoEditorHelper.createEffectItem(mediaItem2, "effect", 0, - 3000, EffectColor.TYPE_COLOR, EffectColor.PINK); - mediaItem2.addEffect(effectColor); - - mVideoEditor.setAspectRatio(MediaProperties.ASPECT_RATIO_11_9); - - try { - final int[] progressUpdate = new int[100]; - mVideoEditor.export(outFilename, MediaProperties.HEIGHT_144, - MediaProperties.BITRATE_800K, new ExportProgressListener() { - int i = 0; - public void onProgress(VideoEditor ve, String outFileName, - int progress) { - progressUpdate[i++] = progress; - } - }); - mVideoEditorHelper.checkProgressCBValues(progressUpdate); - } catch (Exception e) { - assertTrue("Error in Export" + e.toString(), false); - } - final long storyBoardDuration = mediaItem1.getTimelineDuration() - + mediaItem2.getTimelineDuration() + mediaItem3.getTimelineDuration() - - transition2And3.getDuration(); - - mVideoEditorHelper.validateExport(mVideoEditor, outFilename, - MediaProperties.HEIGHT_144, 0, storyBoardDuration, - MediaProperties.VCODEC_H264, MediaProperties.ACODEC_AAC_LC); - mVideoEditorHelper.checkDeleteExistingFile(outFilename); - } - - /** - * To Test Export :Media Item having duration of 1 Hour - * - * @throws Exception - */ - @Suppress - @LargeTest - public void testExportDuration1Hour() throws Exception { - final String videoItemFilename1 = INPUT_FILE_PATH + - "H264_BP_640x480_15fps_384kbps_60_0.mp4"; - final String outFilename = mVideoEditorHelper.createRandomFile( - mVideoEditor.getPath() + "/") + ".3gp"; - - final MediaVideoItem mediaItem1 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", - videoItemFilename1, MediaItem.RENDERING_MODE_BLACK_BORDER); - mVideoEditor.addMediaItem(mediaItem1); - try { - final int[] progressUpdate = new int[100]; - mVideoEditor.export(outFilename, MediaProperties.HEIGHT_144, - MediaProperties.BITRATE_800K, new ExportProgressListener() { - int i = 0; - public void onProgress(VideoEditor ve, String outFileName, - int progress) { - progressUpdate[i++] = progress; - } - }); - mVideoEditorHelper.checkProgressCBValues(progressUpdate); - }catch (Exception e) { - assertTrue("Error in Export" + e.toString(), false); - } - mVideoEditorHelper.validateExport(mVideoEditor, outFilename, - MediaProperties.HEIGHT_720, 0, mediaItem1.getDuration(), - MediaProperties.VCODEC_H264, MediaProperties.ACODEC_AAC_LC); - mVideoEditorHelper.checkDeleteExistingFile(outFilename); - } - - /** - * To Test Export : Storage location having very less space (Less than 100 - * KB) - * - * @throws Exception - */ - @LargeTest - public void testExportWithStorageFull() throws Exception { - final String videoItemFilename1 = INPUT_FILE_PATH - + "H264_BP_640x480_12.5fps_256kbps_AACLC_16khz_24kbps_s_0_26.mp4"; - final String outFilename = mVideoEditorHelper - .createRandomFile(mVideoEditor.getPath() + "/") + ".3gp"; - boolean flagForException = false; - - mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", videoItemFilename1, - MediaItem.RENDERING_MODE_BLACK_BORDER); - try { - final int[] progressUpdate = new int[100]; - mVideoEditor.export(outFilename, MediaProperties.HEIGHT_144, - MediaProperties.BITRATE_800K, new ExportProgressListener() { - int i = 0; - public void onProgress(VideoEditor ve, String outFileName, - int progress) { - progressUpdate[i++] = progress; - } - }); - mVideoEditorHelper.checkProgressCBValues(progressUpdate); - } catch (Exception e) { - flagForException = true; - } - assertTrue("Error in exporting file due to lack of storage space", - flagForException); - } - - /** - * To Test Export :Two Media Items added - * - * @throws Exception - */ - @LargeTest - public void testExportTwoVideos() throws Exception { - final String videoItemFileName = INPUT_FILE_PATH - + "H263_profile0_176x144_15fps_256kbps_AACLC_32kHz_128kbps_s_1_17.3gp"; - final String videoItemFileName1 = INPUT_FILE_PATH + - "H264_BP_640x480_12.5fps_256kbps_AACLC_16khz_24kbps_s_0_26.mp4"; - final String outFilename = mVideoEditorHelper - .createRandomFile(mVideoEditor.getPath() + "/") + ".3gp"; - - final MediaVideoItem mediaVideoItem = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", - videoItemFileName, MediaItem.RENDERING_MODE_BLACK_BORDER); - mVideoEditor.addMediaItem(mediaVideoItem); - - final MediaVideoItem mediaVideoItem1 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m2", - videoItemFileName1, MediaItem.RENDERING_MODE_BLACK_BORDER); - mVideoEditor.addMediaItem(mediaVideoItem1); - - mVideoEditor.generatePreview(new MediaProcessingProgressListener() { - public void onProgress(Object item, int action, int progress) { - } - }); - - try { - final int[] progressUpdate = new int[100]; - mVideoEditor.export(outFilename, MediaProperties.HEIGHT_720, - MediaProperties.BITRATE_800K, new ExportProgressListener() { - int i = 0; - public void onProgress(VideoEditor ve, String outFileName, - int progress) { - progressUpdate[i++] = progress; - } - }); - mVideoEditorHelper.checkProgressCBValues(progressUpdate); - } catch (Exception e) { - assertTrue("Error in Export" + e.toString(), false); - } - mVideoEditorHelper.validateExport(mVideoEditor, outFilename, - MediaProperties.HEIGHT_720, 0, - (mediaVideoItem.getDuration()+ mediaVideoItem1.getDuration()), - MediaProperties.VCODEC_H264, MediaProperties.ACODEC_AAC_LC); - mVideoEditorHelper.checkDeleteExistingFile(outFilename); - } -} diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/VideoEditorPreviewTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/VideoEditorPreviewTest.java deleted file mode 100644 index 9a7f4f2..0000000 --- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/VideoEditorPreviewTest.java +++ /dev/null @@ -1,1139 +0,0 @@ -/* - * Copyright (C) 2011 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.mediaframeworktest.functional; - -import java.io.File; -import java.io.IOException; -import java.util.List; -import java.util.concurrent.Semaphore; - -import android.graphics.Bitmap; -import android.graphics.Rect; -import android.media.videoeditor.AudioTrack; -import android.media.videoeditor.Effect; -import android.media.videoeditor.EffectColor; -import android.media.videoeditor.EffectKenBurns; -import android.media.videoeditor.MediaImageItem; -import android.media.videoeditor.MediaItem; -import android.media.videoeditor.MediaProperties; -import android.media.videoeditor.MediaVideoItem; -import android.media.videoeditor.Overlay; -import android.media.videoeditor.OverlayFrame; -import android.media.videoeditor.Transition; -import android.media.videoeditor.TransitionAlpha; -import android.media.videoeditor.TransitionCrossfade; -import android.media.videoeditor.TransitionFadeBlack; -import android.media.videoeditor.TransitionSliding; -import android.media.videoeditor.VideoEditor; -import android.media.videoeditor.VideoEditor.ExportProgressListener; -import android.media.videoeditor.VideoEditor.MediaProcessingProgressListener; -import android.media.videoeditor.VideoEditor.PreviewProgressListener; -import android.media.videoeditor.VideoEditor.OverlayData; -import android.os.Environment; -import android.test.ActivityInstrumentationTestCase; -import android.view.SurfaceHolder; - - -import com.android.mediaframeworktest.MediaFrameworkTest; -import android.test.suitebuilder.annotation.LargeTest; -import com.android.mediaframeworktest.VideoEditorHelper; - -import android.os.Handler; -import android.os.Looper; -import android.os.Message; - -import java.util.concurrent.TimeUnit; - -import android.util.Log; - -public class VideoEditorPreviewTest extends - ActivityInstrumentationTestCase { - private final String TAG = "VideoEditorTest"; - - private final String PROJECT_LOCATION = VideoEditorHelper.PROJECT_LOCATION_COMMON; - - private final String INPUT_FILE_PATH = VideoEditorHelper.INPUT_FILE_PATH_COMMON; - - private final String PROJECT_CLASS_NAME = - "android.media.videoeditor.VideoEditorImpl"; - - private VideoEditor mVideoEditor; - - private VideoEditorHelper mVideoEditorHelper; - - private class EventHandler extends Handler { - public EventHandler( Looper lp) - { - super(lp); - } - public void handleMessage(Message msg) - { - switch (msg.what) - { - default: - MediaFrameworkTest.testInvalidateOverlay(); - } - } - } - private EventHandler mEventHandler; - - private boolean previewStart; - private boolean previewStop; - - /* Minimum waiting time for Semaphore to wait for release */ - private final long minWaitingTime = 3000; - - // Declares the annotation for Preview Test Cases - public @interface Preview { - } - - public VideoEditorPreviewTest() { - super("com.android.mediaframeworktest", MediaFrameworkTest.class); - - Looper looper; - if ((looper = Looper.myLooper()) != null) { - mEventHandler = new EventHandler(looper); - - } else { - //Handle error when looper can not be created. - ; - } - } - - @Override - protected void setUp() throws Exception { - // setup for each test case. - super.setUp(); - mVideoEditorHelper = new VideoEditorHelper(); - // Create a random String which will be used as project path, where all - // project related files will be stored. - final String projectPath = - mVideoEditorHelper.createRandomFile(PROJECT_LOCATION); - mVideoEditor = mVideoEditorHelper.createVideoEditor(projectPath); - } - - @Override - protected void tearDown() throws Exception { - mVideoEditorHelper.destroyVideoEditor(mVideoEditor); - // Clean the directory created as project path - mVideoEditorHelper.deleteProject(new File(mVideoEditor.getPath())); - System.gc(); - super.tearDown(); - } - - protected void setPreviewStart() { - previewStart = true; - } - protected void setPreviewStop() { - previewStop = true; - } - - protected void validatePreviewProgress(int startMs, int endMs, - boolean loop, long duration) throws Exception { - - final int[] progressUpdate = new int[100]; - final Semaphore blockTillPreviewCompletes = new Semaphore(1); - previewStart = false; - previewStop = false; - mVideoEditor.generatePreview(new MediaProcessingProgressListener() { - int i = 0; - public void onProgress(Object item, int action, int progress) { - progressUpdate[i++] = progress; - } - }); - mVideoEditorHelper.checkProgressCBValues(progressUpdate); - final SurfaceHolder surfaceHolder = - MediaFrameworkTest.mSurfaceView.getHolder(); - - long waitingTime = minWaitingTime; - if (endMs == -1) { - waitingTime += duration; - } - else { - waitingTime += (endMs - startMs); - } - blockTillPreviewCompletes.acquire(); - try { - mVideoEditor.startPreview(surfaceHolder, startMs, endMs, loop, 1, - new PreviewProgressListener() { - public void onProgress(VideoEditor videoEditor, long timeMs, - OverlayData overlayData) { - - if ( overlayData != null) { - if(overlayData.needsRendering()) { - overlayData.renderOverlay(MediaFrameworkTest.mDestBitmap); - mEventHandler.sendMessage(mEventHandler.obtainMessage(1, 2, 3)); - } - } - } - public void onStart(VideoEditor videoEditor) { - setPreviewStart(); - } - public void onStop(VideoEditor videoEditor) { - setPreviewStop(); - blockTillPreviewCompletes.release(); - } - }); - } catch (Exception e) { - blockTillPreviewCompletes.release(); - } - blockTillPreviewCompletes.tryAcquire(waitingTime, TimeUnit.MILLISECONDS); - - mVideoEditor.stopPreview(); - assertTrue("Preview Failed to start", previewStart); - assertTrue("Preview Failed to stop", previewStop); - - blockTillPreviewCompletes.release(); - } - - // ----------------------------------------------------------------- - // Preview - // ----------------------------------------------------------------- - - /** - *To test Preview : FULL Preview of current work (beginning till end) - */ - // TODO : remove TC_PRV_001 - @LargeTest - public void testPreviewTheStoryBoard() throws Exception { - final String videoItemFileName1 = INPUT_FILE_PATH - + "MPEG4_SP_720x480_30fps_280kbps_AACLC_48kHz_96kbps_s_0_21.mp4"; - final String videoItemFileName2 = INPUT_FILE_PATH - + "MPEG4_SP_640x480_15fps_256kbps_0_30.mp4"; - final String videoItemFileName3 = INPUT_FILE_PATH - + "H263_profile0_176x144_15fps_256kbps_AACLC_32kHz_128kbps_s_1_17.3gp"; - previewStart = false; - previewStop = false; - final MediaVideoItem mediaVideoItem1 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "mediaVideoItem1", - videoItemFileName1, MediaItem.RENDERING_MODE_BLACK_BORDER); - mediaVideoItem1.setExtractBoundaries(0, 10000); - mVideoEditor.addMediaItem(mediaVideoItem1); - - final MediaVideoItem mediaVideoItem2 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "mediaVideoItem2", - videoItemFileName2, MediaItem.RENDERING_MODE_BLACK_BORDER); - mVideoEditor.addMediaItem(mediaVideoItem2); - mediaVideoItem2.setExtractBoundaries(0, 10000); - - final MediaVideoItem mediaVideoItem3 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "mediaVideoItem3", - videoItemFileName3, MediaItem.RENDERING_MODE_BLACK_BORDER); - mediaVideoItem3.setExtractBoundaries(0, 10000); - - mVideoEditor.insertMediaItem(mediaVideoItem3, mediaVideoItem1.getId()); - List mediaList = mVideoEditor.getAllMediaItems(); - assertEquals("Media Item 1", mediaVideoItem1, mediaList.get(0)); - assertEquals("Media Item 3", mediaVideoItem3, mediaList.get(1)); - assertEquals("Media Item 2", mediaVideoItem2, mediaList.get(2)); - - mediaVideoItem1.setRenderingMode(MediaItem.RENDERING_MODE_BLACK_BORDER); - assertEquals("Media Item 1 Rendering Mode", - MediaItem.RENDERING_MODE_BLACK_BORDER, - mediaVideoItem1.getRenderingMode()); - - mediaVideoItem2.setRenderingMode(MediaItem.RENDERING_MODE_BLACK_BORDER); - assertEquals("Media Item 2 Rendering Mode", - MediaItem.RENDERING_MODE_BLACK_BORDER, - mediaVideoItem2.getRenderingMode()); - - mediaVideoItem3.setRenderingMode(MediaItem.RENDERING_MODE_STRETCH); - assertEquals("Media Item 3 Rendering Mode", - MediaItem.RENDERING_MODE_STRETCH, - mediaVideoItem3.getRenderingMode()); - - mVideoEditor.setAspectRatio(MediaProperties.ASPECT_RATIO_5_3); - assertEquals("Aspect Ratio", MediaProperties.ASPECT_RATIO_5_3, - mVideoEditor.getAspectRatio()); - - validatePreviewProgress(0, -1, false, mVideoEditor.getDuration()); - } - - /** - * To test Preview : Preview of start + 10 sec till end of story board - */ - // TODO : remove TC_PRV_002 - @LargeTest - public void testPreviewTheStoryBoardFromDuration() throws Exception { - final String videoItemFileName1 = INPUT_FILE_PATH - + "MPEG4_SP_720x480_30fps_280kbps_AACLC_48kHz_96kbps_s_0_21.mp4"; - final String videoItemFileName2 = INPUT_FILE_PATH + - "MPEG4_SP_640x480_15fps_256kbps_0_30.mp4"; - final String videoItemFileName3 = INPUT_FILE_PATH - + "H263_profile0_176x144_15fps_256kbps_AACLC_32kHz_128kbps_s_1_17.3gp"; - final Semaphore blockTillPreviewCompletes = new Semaphore(1); - previewStart = false; - previewStop = false; - final MediaVideoItem mediaVideoItem1 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "mediaVideoItem1", - videoItemFileName1, MediaItem.RENDERING_MODE_BLACK_BORDER); - mediaVideoItem1.setExtractBoundaries(0, 10000); - mVideoEditor.addMediaItem(mediaVideoItem1); - - final MediaVideoItem mediaVideoItem2 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "mediaVideoItem2", - videoItemFileName2, MediaItem.RENDERING_MODE_BLACK_BORDER); - mediaVideoItem2.setExtractBoundaries(0, 10000); - mVideoEditor.addMediaItem(mediaVideoItem2); - - final MediaVideoItem mediaVideoItem3 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "mediaVideoItem3", - videoItemFileName3, MediaItem.RENDERING_MODE_BLACK_BORDER); - mediaVideoItem3.setExtractBoundaries(0, 10000); - - mVideoEditor.insertMediaItem(mediaVideoItem3, mediaVideoItem1.getId()); - - List mediaList = mVideoEditor.getAllMediaItems(); - assertEquals("Media Item 1", mediaVideoItem1, mediaList.get(0)); - assertEquals("Media Item 3", mediaVideoItem3, mediaList.get(1)); - assertEquals("Media Item 2", mediaVideoItem2, mediaList.get(2)); - mediaVideoItem1.setRenderingMode(MediaItem.RENDERING_MODE_BLACK_BORDER); - - assertEquals("Media Item 1 Rendering Mode", - MediaItem.RENDERING_MODE_BLACK_BORDER, - mediaVideoItem1.getRenderingMode()); - mediaVideoItem2.setRenderingMode(MediaItem.RENDERING_MODE_BLACK_BORDER); - - assertEquals("Media Item 2 Rendering Mode", - MediaItem.RENDERING_MODE_BLACK_BORDER, - mediaVideoItem2.getRenderingMode()); - mediaVideoItem3.setRenderingMode(MediaItem.RENDERING_MODE_STRETCH); - - assertEquals("Media Item 3 Rendering Mode", - MediaItem.RENDERING_MODE_STRETCH, - mediaVideoItem3.getRenderingMode()); - - mVideoEditor.setAspectRatio(MediaProperties.ASPECT_RATIO_5_3); - assertEquals("Aspect Ratio", MediaProperties.ASPECT_RATIO_5_3, - mVideoEditor.getAspectRatio()); - - validatePreviewProgress(10000, -1, false, mVideoEditor.getDuration()); - } - - /** - * To test Preview : Preview of current Effects applied - */ - // TODO : remove TC_PRV_003 - @LargeTest - public void testPreviewOfEffects() throws Exception { - final String videoItemFileName1 = INPUT_FILE_PATH + - "H264_BP_640x480_30fps_256kbps_1_17.mp4"; - - final Semaphore blockTillPreviewCompletes = new Semaphore(1); - previewStart = false; - previewStop = false; - final MediaVideoItem mediaVideoItem1 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "mediaVideoItem1", - videoItemFileName1, MediaItem.RENDERING_MODE_BLACK_BORDER); - mVideoEditor.addMediaItem(mediaVideoItem1); - - final EffectColor effectNegative = - mVideoEditorHelper.createEffectItem(mediaVideoItem1, - "effectNegative", 0, 2000, EffectColor.TYPE_NEGATIVE, 0); - mediaVideoItem1.addEffect(effectNegative); - - final EffectColor effectGreen = - mVideoEditorHelper.createEffectItem(mediaVideoItem1, "effectGreen", - 2000, 3000, EffectColor.TYPE_COLOR, EffectColor.GREEN); - mediaVideoItem1.addEffect(effectGreen); - - final EffectColor effectFifties = - mVideoEditorHelper.createEffectItem(mediaVideoItem1, - "effectFifties", 5000, 4000, EffectColor.TYPE_FIFTIES, 0); - mediaVideoItem1.addEffect(effectFifties); - - List effectList = mediaVideoItem1.getAllEffects(); - assertEquals("Effect List Size", 3, effectList.size()); - assertEquals("Effect negative", effectNegative, effectList.get(0)); - assertEquals("Effect Green", effectGreen, effectList.get(1)); - assertEquals("Effect Fifties", effectFifties, effectList.get(2)); - - mVideoEditor.setAspectRatio(MediaProperties.ASPECT_RATIO_4_3); - assertEquals("Aspect Ratio", MediaProperties.ASPECT_RATIO_4_3, - mVideoEditor.getAspectRatio()); - - final long storyboardDuration = mVideoEditor.getDuration() ; - validatePreviewProgress(0, (int)(storyboardDuration/2), false, (storyboardDuration/2)); - - assertEquals("Removing Effect : Negative", effectNegative, - mediaVideoItem1.removeEffect(effectNegative.getId())); - - effectList = mediaVideoItem1.getAllEffects(); - - assertEquals("Effect List Size", 2, effectList.size()); - assertEquals("Effect Green", effectGreen, effectList.get(0)); - assertEquals("Effect Fifties", effectFifties, effectList.get(1)); - - validatePreviewProgress(0, -1, false, mVideoEditor.getDuration()); - } - - /** - *To test Preview : Preview of current Transitions applied (with multiple - * generatePreview) - */ - // TODO : remove TC_PRV_004 - @LargeTest - public void testPreviewWithTransition() throws Exception { - - final String videoItemFileName1 = INPUT_FILE_PATH + - "H263_profile0_176x144_10fps_96kbps_0_25.3gp"; - final String imageItemFileName1 = INPUT_FILE_PATH + - "IMG_1600x1200.jpg"; - final String videoItemFileName2 = INPUT_FILE_PATH + - "MPEG4_SP_800x480_515kbps_15fps_AMR_NB_8KHz_12.2kbps_m_0_26.mp4"; - final String maskFilename = INPUT_FILE_PATH + - "TransitionSpiral_QVGA.jpg"; - previewStart = false; - previewStop = false; - - final Semaphore blockTillPreviewCompletes = new Semaphore(1); - - final MediaVideoItem mediaVideoItem1 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", - videoItemFileName1, MediaItem.RENDERING_MODE_BLACK_BORDER); - mediaVideoItem1.setExtractBoundaries(0, 10000); - mVideoEditor.addMediaItem(mediaVideoItem1); - - final MediaImageItem mediaImageItem1 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m2", - imageItemFileName1, 10000, MediaItem.RENDERING_MODE_BLACK_BORDER); - mVideoEditor.addMediaItem(mediaImageItem1); - - final MediaVideoItem mediaVideoItem2 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m3", - videoItemFileName2, MediaItem.RENDERING_MODE_BLACK_BORDER); - mediaVideoItem2.setExtractBoundaries(0, 10000); - mVideoEditor.addMediaItem(mediaVideoItem2); - - final TransitionCrossfade transition1And2CrossFade = - mVideoEditorHelper.createTCrossFade("transition_1_2_CF", - mediaVideoItem1, mediaImageItem1, 2000, - Transition.BEHAVIOR_MIDDLE_FAST); - mVideoEditor.addTransition(transition1And2CrossFade); - - final TransitionAlpha transition2And3Alpha = - mVideoEditorHelper.createTAlpha("transition_2_3", mediaImageItem1, - mediaVideoItem2, 4000, Transition.BEHAVIOR_SPEED_UP, - maskFilename, 50, true); - mVideoEditor.addTransition(transition2And3Alpha); - - final TransitionFadeBlack transition1FadeBlack = - mVideoEditorHelper.createTFadeBlack("transition_1FB", null, - mediaVideoItem1, 2000, Transition.BEHAVIOR_MIDDLE_FAST); - mVideoEditor.addTransition(transition1FadeBlack); - - List transitionList = mVideoEditor.getAllTransitions(); - assertEquals("Transition List Size", 3, transitionList.size()); - assertEquals("Transition 1", transition1And2CrossFade, - transitionList.get(0)); - assertEquals("Transition 2", transition2And3Alpha, transitionList.get(1)); - assertEquals("Transition 3", transition1FadeBlack, transitionList.get(2)); - - mVideoEditor.setAspectRatio(MediaProperties.ASPECT_RATIO_3_2); - - final int[] progressValues = new int[300]; - mVideoEditor.generatePreview(new MediaProcessingProgressListener() { - int i = 0; - - public void onProgress(Object item, int action, int progress) { - if (item instanceof TransitionCrossfade) { - progressValues[i] = progress; - assertEquals("Object", item, transition1And2CrossFade); - assertEquals("Action", action, - MediaProcessingProgressListener.ACTION_ENCODE); - } else if (item instanceof TransitionAlpha) { - progressValues[i] = progress; - assertEquals("Object", item, transition2And3Alpha); - assertEquals("Action", action, - MediaProcessingProgressListener.ACTION_ENCODE); - } else if (item instanceof TransitionFadeBlack) { - progressValues[i] = progress; - assertEquals("Object", item, transition1FadeBlack); - assertEquals("Action", action, - MediaProcessingProgressListener.ACTION_ENCODE); - } - i++; - } - }); - - mVideoEditorHelper.checkProgressCBValues(progressValues); - final SurfaceHolder surfaceHolder = - MediaFrameworkTest.mSurfaceView.getHolder(); - /* As transition takes more time buffer of 10 sec is added */ - long waitingTime = minWaitingTime + 10000 + 10000; - - blockTillPreviewCompletes.acquire(); - try { - mVideoEditor.startPreview(surfaceHolder, 0, 10000, false, 1, - new PreviewProgressListener() { - public void onProgress(VideoEditor videoEditor, long timeMs, - OverlayData overlayData) { - } - public void onStart(VideoEditor videoEditor) { - setPreviewStart(); - } - public void onStop(VideoEditor videoEditor) { - setPreviewStop(); - blockTillPreviewCompletes.release(); - } - }); - } catch (Exception e) { - blockTillPreviewCompletes.release(); - } - blockTillPreviewCompletes.tryAcquire(waitingTime, TimeUnit.MILLISECONDS); - mVideoEditor.stopPreview(); - blockTillPreviewCompletes.release(); - assertTrue("Preview Failed to start", previewStart); - assertTrue("Preview Failed to stop", previewStop); - - assertEquals("Removing Transition " + transition1And2CrossFade.getId(), - transition1And2CrossFade, - mVideoEditor.removeTransition(transition1And2CrossFade.getId())); - transitionList = mVideoEditor.getAllTransitions(); - assertEquals("Transition List Size", 2, transitionList.size()); - assertEquals("Transition 1", transition2And3Alpha, transitionList.get(0)); - assertEquals("Transition 2", transition1FadeBlack, transitionList.get(1)); - - validatePreviewProgress(0, -1, false, mVideoEditor.getDuration()); - - - final TransitionSliding transition1And2Sliding = - mVideoEditorHelper.createTSliding("transition_1_2Sliding", - mediaVideoItem1, mediaImageItem1, 4000, - Transition.BEHAVIOR_MIDDLE_FAST, - TransitionSliding.DIRECTION_LEFT_OUT_RIGHT_IN); - mVideoEditor.addTransition(transition1And2Sliding); - - transitionList = mVideoEditor.getAllTransitions(); - assertEquals("Transition List Size", 3, transitionList.size()); - assertEquals("Transition 1", transition2And3Alpha, transitionList.get(0)); - assertEquals("Transition 2", transition1FadeBlack, transitionList.get(1)); - assertEquals("Transition 3", transition1And2Sliding, - transitionList.get(2)); - - validatePreviewProgress(5000, -1, false, (mVideoEditor.getDuration())); - - } - - /** - * To test Preview : Preview of current Overlay applied - */ - // TODO : remove TC_PRV_005 - @LargeTest - public void testPreviewWithOverlay() throws Exception { - final String videoItemFileName = INPUT_FILE_PATH - + "MPEG4_SP_640x480_15fps_1200kbps_AACLC_48khz_64kbps_m_1_17.3gp"; - final String overlayFilename1 = INPUT_FILE_PATH + - "IMG_640x480_Overlay1.png"; - final String overlayFilename2 = INPUT_FILE_PATH + - "IMG_640x480_Overlay2.png"; - final int previewFrom = 5000; - final int previewTo = 10000; - final boolean previewLoop = false; - final int previewCallbackFrameCount = 1; - final int setAspectRatio = MediaProperties.ASPECT_RATIO_4_3; - final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; - final Semaphore blockTillPreviewCompletes = new Semaphore(1); - previewStart = false; - previewStop = false; - boolean flagForException = false; - final MediaVideoItem mediaVideoItem = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", - videoItemFileName, renderingMode); - mVideoEditor.addMediaItem(mediaVideoItem); - mediaVideoItem.setExtractBoundaries(0, 10000); - - final Bitmap mBitmap1 = mVideoEditorHelper.getBitmap(overlayFilename1, - 640, 480); - final OverlayFrame overlayOnMvi1 = - mVideoEditorHelper.createOverlay(mediaVideoItem, "OverlayOnMvi1", - mBitmap1, 0, 5000); - mediaVideoItem.addOverlay(overlayOnMvi1); - - final Bitmap mBitmap2 = mVideoEditorHelper.getBitmap(overlayFilename2, - 640, 480); - final OverlayFrame overlayOnMvi2 = - mVideoEditorHelper.createOverlay(mediaVideoItem, "OverlayOnMvi2", - mBitmap2, 5000, 9000); - mediaVideoItem.addOverlay(overlayOnMvi2); - - List overlayList = mediaVideoItem.getAllOverlays(); - assertEquals("Overlay Size", 2, overlayList.size()); - assertEquals("Overlay 1", overlayOnMvi1, overlayList.get(0)); - assertEquals("Overlay 2", overlayOnMvi2, overlayList.get(1)); - - mVideoEditor.setAspectRatio(setAspectRatio); - - validatePreviewProgress(0 /* previewFrom */, -1, previewLoop, - mVideoEditor.getDuration()); - } - - /** - * To test Preview : Preview of current Trim applied (with default aspect - * ratio) - */ - // TODO : remove TC_PRV_006 - @LargeTest - public void testPreviewWithTrim() throws Exception { - final String videoItemFileName = INPUT_FILE_PATH + - "H264_BP_640x480_30fps_192kbps_1_5.mp4"; - final MediaVideoItem mediaVideoItem = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", - videoItemFileName, MediaItem.RENDERING_MODE_CROPPING); - final Semaphore blockTillPreviewCompletes = new Semaphore(1); - boolean flagForException = false; - previewStart = false; - previewStop = false; - mediaVideoItem.setExtractBoundaries(mediaVideoItem.getDuration() / 2, - mediaVideoItem.getDuration()); - mVideoEditor.addMediaItem(mediaVideoItem); - - validatePreviewProgress(1000, -1, false, mVideoEditor.getDuration()); - } - - /** - * To test Preview : Preview of current work having Overlay and Effect - * applied - */ - - // TODO : remove TC_PRV_007 - @LargeTest - public void testPreviewWithOverlayEffectKenBurn() throws Exception { - - final String videoItemFileName = INPUT_FILE_PATH + - "H264_BP_640x480_30fps_192kbps_1_5.mp4"; - final String imageItemFileName = INPUT_FILE_PATH + "IMG_640x480.jpg"; - final String videoItemFileName1 = INPUT_FILE_PATH + - "MPEG4_SP_640x480_15fps_512kbps_AACLC_48khz_132kbps_s_0_26.mp4"; - final String overlayFilename = INPUT_FILE_PATH + - "IMG_640x480_Overlay1.png"; - final Semaphore blockTillPreviewCompletes = new Semaphore(1); - previewStart = false; - previewStop = false; - final MediaVideoItem mediaVideoItem1 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", - videoItemFileName, MediaItem.RENDERING_MODE_BLACK_BORDER); - mVideoEditor.addMediaItem(mediaVideoItem1); - - final MediaImageItem mediaImageItem2 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m2", - imageItemFileName, 10000, MediaItem.RENDERING_MODE_BLACK_BORDER); - mVideoEditor.addMediaItem(mediaImageItem2); - - final MediaVideoItem mediaVideoItem3 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m3", - videoItemFileName1, MediaItem.RENDERING_MODE_BLACK_BORDER); - mVideoEditor.addMediaItem(mediaVideoItem3); - - final EffectColor effectColor = - mVideoEditorHelper.createEffectItem(mediaVideoItem1, "Effect1", - 1000, 3000, EffectColor.TYPE_COLOR, EffectColor.GREEN); - mediaVideoItem1.addEffect(effectColor); - - final Rect startRect = new Rect((mediaImageItem2.getHeight() / 3), - (mediaImageItem2.getWidth() / 3), (mediaImageItem2.getHeight() / 2), - (mediaImageItem2.getWidth() / 2)); - final Rect endRect = new Rect(0, 0, mediaImageItem2.getWidth(), - mediaImageItem2.getHeight()); - - final EffectKenBurns kbeffectOnMI2 = new EffectKenBurns(mediaImageItem2, - "KBOnM2", startRect, endRect, 0, 10000); - assertNotNull("EffectKenBurns", kbeffectOnMI2); - mediaImageItem2.addEffect(kbeffectOnMI2); - - final Bitmap mBitmap = mVideoEditorHelper.getBitmap(overlayFilename, - 640, 480); - final OverlayFrame overlayFrame = - mVideoEditorHelper.createOverlay(mediaVideoItem3, "OverlayID", - mBitmap, (mediaImageItem2.getDuration() / 4), - (mediaVideoItem3.getDuration() / 3)); - mediaVideoItem3.addOverlay(overlayFrame); - - validatePreviewProgress(5000, -1, false, mVideoEditor.getDuration()); - } - - /** - *To test Preview : Export during preview - */ - // TODO : remove TC_PRV_008 - @LargeTest - public void testPreviewDuringExport() throws Exception { - final String videoItemFileName = INPUT_FILE_PATH + - "H264_BP_640x480_30fps_192kbps_1_5.mp4"; - final Semaphore blockTillPreviewCompletes = new Semaphore(1); - previewStart = false; - previewStop = false; - - final MediaVideoItem mediaVideoItem1 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", - videoItemFileName, MediaItem.RENDERING_MODE_BLACK_BORDER); - mediaVideoItem1.setExtractBoundaries(0, 20000); - mVideoEditor.addMediaItem(mediaVideoItem1); - - mVideoEditor.generatePreview(new MediaProcessingProgressListener() { - public void onProgress(Object item, int action, int progress) { - } - }); - - long waitingTime = minWaitingTime + mVideoEditor.getDuration(); - - - blockTillPreviewCompletes.acquire(); - final String fileName = mVideoEditor.getPath() + "\test.3gp"; - final int height = MediaProperties.HEIGHT_480; - final int bitrate = MediaProperties.BITRATE_512K; - - try { - mVideoEditor.export(fileName, height, bitrate, - new ExportProgressListener() { - public void onProgress(VideoEditor ve, - String outFileName,int progress) { - - } - }); - } catch (IOException e) { - assertTrue("UnExpected Error in Export" + - e.toString(), false); - } - - final SurfaceHolder surfaceHolder = - MediaFrameworkTest.mSurfaceView.getHolder(); - try { - - mVideoEditor.startPreview(surfaceHolder, 5000, -1, false, 1, - new PreviewProgressListener() { - - public void onProgress(VideoEditor videoEditor, long timeMs, - OverlayData overlayData) { - } - public void onStart(VideoEditor videoEditor) { - setPreviewStart(); - } - public void onStop(VideoEditor videoEditor) { - setPreviewStop(); - blockTillPreviewCompletes.release(); - } - }); - - } catch (Exception e) { - blockTillPreviewCompletes.release(); - } - blockTillPreviewCompletes.tryAcquire(waitingTime, TimeUnit.MILLISECONDS); - mVideoEditor.stopPreview(); - assertTrue("Preview Failed to start", previewStart); - assertTrue("Preview Failed to stop", previewStop); - blockTillPreviewCompletes.release(); - } - - /** - * To test Preview : Preview of current Effects applied (with from time > - * total duration) - */ - // TODO : remove TC_PRV_009 - @LargeTest - public void testPreviewWithDurationGreaterThanMediaDuration() - throws Exception { - final String videoItemFileName = INPUT_FILE_PATH + - "H264_BP_640x480_30fps_192kbps_1_5.mp4"; - final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; - boolean flagForException = false; - final Semaphore blockTillPreviewCompletes = new Semaphore(1); - - final MediaVideoItem mediaVideoItem1 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", - videoItemFileName, renderingMode); - try { - mediaVideoItem1.setExtractBoundaries(0, 20000); - } catch (Exception e) { - assertTrue("Exception during setExtract Boundaries", false); - } - mVideoEditor.addMediaItem(mediaVideoItem1); - final SurfaceHolder surfaceHolder = - MediaFrameworkTest.mSurfaceView.getHolder(); - long waitingTime = minWaitingTime + (mVideoEditor.getDuration() - 30000); - if(waitingTime < 0) - { - waitingTime = minWaitingTime; - } - - blockTillPreviewCompletes.acquire(); - try { - mVideoEditor.startPreview(surfaceHolder, 30000, -1, true, 1, - new PreviewProgressListener() { - public void onProgress(VideoEditor videoEditor, long timeMs, - OverlayData overlayData) { - } - public void onStart(VideoEditor videoEditor) { - setPreviewStart(); - } - public void onStop(VideoEditor videoEditor) { - setPreviewStop(); - blockTillPreviewCompletes.release(); - } - }); - - } catch (IllegalArgumentException e) { - blockTillPreviewCompletes.release(); - flagForException = true; - } - blockTillPreviewCompletes.tryAcquire(waitingTime, TimeUnit.MILLISECONDS); - assertTrue("Expected Error in Preview", flagForException); - mVideoEditor.stopPreview(); - blockTillPreviewCompletes.release(); - } - - /** - * To test Preview : Preview of current Effects applied (with Render Preview - * Frame) - */ - // TODO : remove TC_PRV_010 - @LargeTest - public void testPreviewWithRenderPreviewFrame() throws Exception { - final String videoItemFileName = INPUT_FILE_PATH + - "H264_BP_640x480_30fps_256kbps_1_17.mp4"; - final Semaphore blockTillPreviewCompletes = new Semaphore(1); - boolean flagForException = false; - OverlayData overlayData1 = new OverlayData(); - previewStart = false; - previewStop = false; - - final String overlayFilename1 = INPUT_FILE_PATH + - "IMG_640x480_Overlay1.png"; - - final MediaVideoItem mediaVideoItem = - mVideoEditorHelper.createMediaItem(mVideoEditor, - "m1", videoItemFileName, MediaItem.RENDERING_MODE_BLACK_BORDER); - mVideoEditor.addMediaItem(mediaVideoItem); - - final EffectColor effectPink = - mVideoEditorHelper.createEffectItem(mediaVideoItem, - "effectNegativeOnMvi", 1000, 3000, EffectColor.TYPE_COLOR, - EffectColor.PINK); - mediaVideoItem.addEffect(effectPink); - - mVideoEditor.generatePreview(new MediaProcessingProgressListener() { - public void onProgress(Object item, int action, int progress) { - } - }); - final SurfaceHolder surfaceHolder = - MediaFrameworkTest.mSurfaceView.getHolder(); - - assertEquals("Render preview Frame at 5 Sec", 5000, - mVideoEditor.renderPreviewFrame(surfaceHolder, 5000, - overlayData1)); - - assertEquals("Render preview Frame at 7 Sec", 7000, - mVideoEditor.renderPreviewFrame(surfaceHolder, 7000, - overlayData1)); - - validatePreviewProgress(5000, -1, false, mVideoEditor.getDuration()); - } - - /** - * To test Preview : Preview of current work from selected jump location - * till end with Audio Track - */ - // TODO : remove TC_PRV_011 - @LargeTest - public void testPreviewWithEndAudioTrack() throws Exception { - final String imageItemFilename1 = INPUT_FILE_PATH + "IMG_1600x1200.jpg"; - final String videoItemFileName = INPUT_FILE_PATH + - "H264_BP_640x480_30fps_256kbps_1_17.mp4"; - final String imageItemFilename2 = INPUT_FILE_PATH + "IMG_640x480.jpg"; - final String audioFilename = INPUT_FILE_PATH + - "AMRNB_8KHz_12.2Kbps_m_1_17.3gp"; - - boolean flagForException = false; - previewStart = false; - previewStop = false; - final MediaImageItem mediaImageItem1 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", - imageItemFilename1, 7000, MediaItem.RENDERING_MODE_BLACK_BORDER); - mVideoEditor.addMediaItem(mediaImageItem1); - - final MediaVideoItem mediaVideoItem = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m2", - videoItemFileName, MediaItem.RENDERING_MODE_BLACK_BORDER); - mediaVideoItem.setExtractBoundaries(1000, 8000); - mVideoEditor.addMediaItem(mediaVideoItem); - - final MediaImageItem mediaImageItem2 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m3", - imageItemFilename2, 7000, MediaItem.RENDERING_MODE_BLACK_BORDER); - mVideoEditor.addMediaItem(mediaImageItem2); - - final AudioTrack audioTrack = - mVideoEditorHelper.createAudio(mVideoEditor, "a1", audioFilename); - mVideoEditor.addAudioTrack(audioTrack); - - List audioList = mVideoEditor.getAllAudioTracks(); - assertEquals("Audio Track List size", 1, audioList.size()); - assertEquals("Audio Track", audioTrack, audioList.get(0)); - mVideoEditor.setAspectRatio(MediaProperties.ASPECT_RATIO_4_3); - - validatePreviewProgress(10000, -1, false, mVideoEditor.getDuration()); - } - - /** - * To test render Preview Frame - */ - // TODO : remove TC_PRV_012 - @LargeTest - public void testRenderPreviewFrame() throws Exception { - final String videoItemFileName1 = INPUT_FILE_PATH - + "H264_BP_1080x720_30fps_800kbps_1_17.mp4"; - final String videoItemFileName2 = INPUT_FILE_PATH - + "MPEG4_SP_800x480_515kbps_15fps_AMR_NB_8KHz_12.2kbps_m_0_26.mp4"; - final String videoItemFileName3 = INPUT_FILE_PATH - + "H264_BP_640x480_30fps_256kbps_1_17.mp4"; - final String imageItemFilename1 = INPUT_FILE_PATH - + "IMG_1600x1200.jpg"; - final String imageItemFilename2 = INPUT_FILE_PATH - + "IMG_176x144.jpg"; - final String audioFilename = INPUT_FILE_PATH - + "AMRNB_8KHz_12.2Kbps_m_1_17.3gp"; - OverlayData overlayData1 = new OverlayData(); - previewStart = false; - previewStop = false; - final MediaVideoItem mediaVideoItem1 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", - videoItemFileName1, MediaItem.RENDERING_MODE_BLACK_BORDER); - mediaVideoItem1.setExtractBoundaries(0, 10000); - mVideoEditor.addMediaItem(mediaVideoItem1); - - final MediaVideoItem mediaVideoItem2 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m2", - videoItemFileName2, MediaItem.RENDERING_MODE_BLACK_BORDER); - mediaVideoItem1.setExtractBoundaries(mediaVideoItem2.getDuration() / 4, - mediaVideoItem2.getDuration() / 2); - mVideoEditor.addMediaItem(mediaVideoItem2); - - final MediaVideoItem mediaVideoItem3 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m3", - videoItemFileName3, MediaItem.RENDERING_MODE_BLACK_BORDER); - mediaVideoItem1.setExtractBoundaries(mediaVideoItem2.getDuration() / 2, - mediaVideoItem2.getDuration()); - mVideoEditor.addMediaItem(mediaVideoItem3); - - final MediaImageItem mediaImageItem4 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m4", - imageItemFilename1, 5000, MediaItem.RENDERING_MODE_BLACK_BORDER); - - final MediaImageItem mediaImageItem5 = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m5", - imageItemFilename2, 5000, MediaItem.RENDERING_MODE_BLACK_BORDER); - - List mediaList = mVideoEditor.getAllMediaItems(); - assertEquals("Media Item List Size", 3, mediaList.size()); - - mVideoEditor.insertMediaItem(mediaImageItem4, mediaVideoItem2.getId()); - mediaList = mVideoEditor.getAllMediaItems(); - assertEquals("Media Item List Size", 4, mediaList.size()); - assertEquals("Media item 1", mediaVideoItem1, mediaList.get(0)); - assertEquals("Media item 2", mediaVideoItem2, mediaList.get(1)); - assertEquals("Media item 4", mediaImageItem4, mediaList.get(2)); - assertEquals("Media item 3", mediaVideoItem3, mediaList.get(3)); - - mVideoEditor.insertMediaItem(mediaImageItem5, mediaImageItem4.getId()); - mediaList = mVideoEditor.getAllMediaItems(); - assertEquals("Media Item List Size", 5, mediaList.size()); - assertEquals("Media item 1", mediaVideoItem1, mediaList.get(0)); - assertEquals("Media item 2", mediaVideoItem2, mediaList.get(1)); - assertEquals("Media item 4", mediaImageItem4, mediaList.get(2)); - assertEquals("Media item 5", mediaImageItem5, mediaList.get(3)); - assertEquals("Media item 3", mediaVideoItem3, mediaList.get(4)); - - mVideoEditor.moveMediaItem(mediaVideoItem1.getId(), - mediaImageItem5.getId()); - mediaList = mVideoEditor.getAllMediaItems(); - assertEquals("Media Item List Size", 5, mediaList.size()); - assertEquals("Media item 2", mediaVideoItem2, mediaList.get(0)); - assertEquals("Media item 4", mediaImageItem4, mediaList.get(1)); - assertEquals("Media item 5", mediaImageItem5, mediaList.get(2)); - assertEquals("Media item 1", mediaVideoItem1, mediaList.get(3)); - assertEquals("Media item 3", mediaVideoItem3, mediaList.get(4)); - - final TransitionCrossfade transition2And4CrossFade = - mVideoEditorHelper.createTCrossFade("transition2And4CrossFade", - mediaVideoItem2, mediaImageItem4, 2000, - Transition.BEHAVIOR_MIDDLE_FAST); - mVideoEditor.addTransition(transition2And4CrossFade); - - final TransitionCrossfade transition1And3CrossFade = - mVideoEditorHelper.createTCrossFade("transition1And3CrossFade", - mediaVideoItem1, mediaVideoItem3, 5000, - Transition.BEHAVIOR_MIDDLE_FAST); - mVideoEditor.addTransition(transition1And3CrossFade); - - final AudioTrack audioTrack = - mVideoEditorHelper.createAudio(mVideoEditor, "a1", audioFilename); - audioTrack.setExtractBoundaries(0, 2000); - mVideoEditor.addAudioTrack(audioTrack); - - audioTrack.enableLoop(); - - mVideoEditor.generatePreview(new MediaProcessingProgressListener() { - public void onProgress(Object item, int action, int progress) { - } - }); - - final SurfaceHolder surfaceHolder = - MediaFrameworkTest.mSurfaceView.getHolder(); - - mVideoEditor.renderPreviewFrame(surfaceHolder, mVideoEditor.getDuration()/4, overlayData1); - Thread.sleep(1000); - mVideoEditor.renderPreviewFrame(surfaceHolder, mVideoEditor.getDuration()/2, overlayData1); - Thread.sleep(1000); - mVideoEditor.renderPreviewFrame(surfaceHolder, mVideoEditor.getDuration(), overlayData1); - - } - - /** - * To Test Preview : Without any Media Items in the story Board - */ - // TODO : remove TC_PRV_013 - @LargeTest - public void testStartPreviewWithoutMediaItems() throws Exception { - boolean flagForException = false; - - final SurfaceHolder surfaceHolder = - MediaFrameworkTest.mSurfaceView.getHolder(); - try{ - mVideoEditor.startPreview(surfaceHolder, 0, -1, false, 1, - new PreviewProgressListener() { - public void onProgress(VideoEditor videoEditor, long timeMs, - OverlayData overlayData) { - } - public void onStart(VideoEditor videoEditor) { - setPreviewStart(); - } - public void onStop(VideoEditor videoEditor) { - setPreviewStop(); - } - }); - }catch (IllegalArgumentException e) { - flagForException = true; - } - assertTrue("Preview without Media Items", flagForException); - } - - /** - * To Test Preview : Add Media and Remove Media Item (Without any Media - * Items in the story Board) - */ - // TODO : remove TC_PRV_014 - @LargeTest - public void testStartPreviewAddRemoveMediaItems() throws Exception { - final String videoItemFilename1 = INPUT_FILE_PATH - + "H263_profile0_176x144_15fps_256kbps_AACLC_32kHz_128kbps_s_0_26.3gp"; - final String imageItemFilename1 = INPUT_FILE_PATH + "IMG_1600x1200.jpg"; - final String alphaFilename = INPUT_FILE_PATH + - "TransitionSpiral_QVGA.jpg"; - boolean flagForException = false; - - final MediaVideoItem mediaVideoItem = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", - videoItemFilename1, MediaItem.RENDERING_MODE_BLACK_BORDER); - mediaVideoItem.setExtractBoundaries(0, 15000); - mVideoEditor.addMediaItem(mediaVideoItem); - - final MediaImageItem mediaImageItem = - mVideoEditorHelper.createMediaItem(mVideoEditor, "m2", - imageItemFilename1, 15000, MediaItem.RENDERING_MODE_BLACK_BORDER); - mVideoEditor.addMediaItem(mediaImageItem); - - final TransitionAlpha transition1And2 = - mVideoEditorHelper.createTAlpha("transition", mediaVideoItem, - mediaImageItem, 3000, Transition.BEHAVIOR_SPEED_UP, - alphaFilename, 10, false); - mVideoEditor.addTransition(transition1And2); - - final EffectColor effectColor = - mVideoEditorHelper.createEffectItem(mediaImageItem, "effect", 5000, - 3000, EffectColor.TYPE_COLOR, EffectColor.PINK); - mediaImageItem.addEffect(effectColor); - - assertEquals("removing Media item 1", mediaVideoItem, - mVideoEditor.removeMediaItem(mediaVideoItem.getId())); - assertEquals("removing Media item 2", mediaImageItem, - mVideoEditor.removeMediaItem(mediaImageItem.getId())); - - try{ - mVideoEditor.generatePreview(new MediaProcessingProgressListener() { - public void onProgress(Object item, int action, int progress) { - } - }); - final SurfaceHolder surfaceHolder = - MediaFrameworkTest.mSurfaceView.getHolder(); - mVideoEditor.startPreview(surfaceHolder, 0, -1, false, 1, - new PreviewProgressListener() { - public void onProgress(VideoEditor videoEditor, long timeMs, - OverlayData overlayData) { - } - public void onStart(VideoEditor videoEditor) { - setPreviewStart(); - } - public void onStop(VideoEditor videoEditor) { - setPreviewStop(); - } - }); - }catch (IllegalArgumentException e) { - flagForException = true; - } - assertTrue("Preview with removed Media Items", flagForException); - - } - - /** - * To test Preview : Preview of current Effects applied (with Render Preview - * Frame) - */ - // TODO : remove TC_PRV_015 - @LargeTest - public void testPreviewWithRenderPreviewFrameWithoutGenerate() throws Exception { - final String videoItemFileName = INPUT_FILE_PATH + - "H264_BP_640x480_30fps_256kbps_1_17.mp4"; - boolean flagForException = false; - long duration = 0; - OverlayData overlayData1 = new OverlayData(); - - final MediaVideoItem mediaVideoItem = - mVideoEditorHelper.createMediaItem(mVideoEditor, - "m1", videoItemFileName, MediaItem.RENDERING_MODE_BLACK_BORDER); - mVideoEditor.addMediaItem(mediaVideoItem); - - final SurfaceHolder surfaceHolder = - MediaFrameworkTest.mSurfaceView.getHolder(); - duration = mVideoEditor.getDuration(); - /* RenderPreviewFrame returns -1 to indicate last frame */ - try { - mVideoEditor.renderPreviewFrame(surfaceHolder, duration, - overlayData1); - } catch ( IllegalStateException e) { - flagForException = true; - } - assertTrue (" Render Preview Frame without generate", flagForException); - duration = mVideoEditor.getDuration() + 1000; - try { - mVideoEditor.renderPreviewFrame(surfaceHolder, duration, - overlayData1); - } catch ( IllegalArgumentException e) { - flagForException = true; - } - assertTrue (" Preview time greater than duration", flagForException); - } -} diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/MediaAudioEffectTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/MediaAudioEffectTest.java new file mode 100644 index 0000000..ab78714 --- /dev/null +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/MediaAudioEffectTest.java @@ -0,0 +1,1531 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.mediaframeworktest.functional.audio; + +import com.android.mediaframeworktest.MediaFrameworkTest; +import com.android.mediaframeworktest.MediaNames; +import android.content.res.AssetFileDescriptor; +import android.media.audiofx.AudioEffect; +import android.media.AudioFormat; +import android.media.AudioManager; +import android.media.AudioTrack; +import android.media.AudioRecord; +import android.media.audiofx.EnvironmentalReverb; +import android.media.audiofx.Equalizer; +import android.media.MediaPlayer; +import android.media.MediaRecorder; + +import android.os.Looper; +import android.test.suitebuilder.annotation.LargeTest; +import android.test.suitebuilder.annotation.MediumTest; +import android.test.suitebuilder.annotation.Suppress; +import android.test.ActivityInstrumentationTestCase2; +import android.util.Log; + +import java.nio.ByteOrder; +import java.nio.ByteBuffer; +import java.util.UUID; + +/** + * Junit / Instrumentation test case for the media AudioTrack api + + */ +public class MediaAudioEffectTest extends ActivityInstrumentationTestCase2 { + private String TAG = "MediaAudioEffectTest"; + + private AudioEffect mEffect = null; + private boolean mHasControl = false; + private boolean mIsEnabled = false; + private int mParameterChanged = -1; + private MediaPlayer mMediaPlayer = null; + private boolean mInitialized = false; + private Looper mLooper = null; + private int mError = 0; + private final Object lock = new Object(); + private final static int SAMPLING_RATE = 44100; + + public MediaAudioEffectTest() { + super("com.android.mediaframeworktest", MediaFrameworkTest.class); + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + } + + @Override + protected void tearDown() throws Exception { + super.tearDown(); + } + + private static void assumeTrue(String message, boolean cond) { + assertTrue("(assume)"+message, cond); + } + + private void log(String testName, String message) { + Log.v(TAG, "["+testName+"] "+message); + } + + private void loge(String testName, String message) { + Log.e(TAG, "["+testName+"] "+message); + } + + //----------------------------------------------------------------- + // AUDIOEFFECT TESTS: + //---------------------------------- + + //----------------------------------------------------------------- + // 0 - static methods + //---------------------------------- + + //Test case 0.0: test queryEffects() and available effects + @LargeTest + public void test0_0QueryEffects() throws Exception { + + AudioEffect.Descriptor[] desc = AudioEffect.queryEffects(); + + assertTrue("test0_0QueryEffects: number of effects < 4: "+desc.length, (desc.length >= 4)); + + boolean hasEQ = false; + boolean hasBassBoost = false; + boolean hasVirtualizer = false; + boolean hasEnvReverb = false; + + for (int i = 0; i < desc.length; i++) { + if (desc[i].type.equals(AudioEffect.EFFECT_TYPE_EQUALIZER)) { + hasEQ = true; + } if (desc[i].type.equals(AudioEffect.EFFECT_TYPE_BASS_BOOST)) { + hasBassBoost = true; + } else if (desc[i].type.equals(AudioEffect.EFFECT_TYPE_VIRTUALIZER)) { + hasVirtualizer = true; + } + else if (desc[i].type.equals(AudioEffect.EFFECT_TYPE_ENV_REVERB)) { + hasEnvReverb = true; + } + } + assertTrue("test0_0QueryEffects: equalizer not found", hasEQ); + assertTrue("test0_0QueryEffects: bass boost not found", hasBassBoost); + assertTrue("test0_0QueryEffects: virtualizer not found", hasVirtualizer); + assertTrue("test0_0QueryEffects: environmental reverb not found", hasEnvReverb); + } + + //----------------------------------------------------------------- + // 1 - constructor + //---------------------------------- + + private AudioRecord getAudioRecord() { + AudioRecord ar = null; + try { + ar = new AudioRecord(MediaRecorder.AudioSource.DEFAULT, + SAMPLING_RATE, + AudioFormat.CHANNEL_CONFIGURATION_MONO, + AudioFormat.ENCODING_PCM_16BIT, + AudioRecord.getMinBufferSize(SAMPLING_RATE, + AudioFormat.CHANNEL_CONFIGURATION_MONO, + AudioFormat.ENCODING_PCM_16BIT) * 10); + assertNotNull("Could not create AudioRecord", ar); + assertEquals("AudioRecord not initialized", + AudioRecord.STATE_INITIALIZED, ar.getState()); + } catch (IllegalArgumentException e) { + fail("AudioRecord invalid parameter"); + } + return ar; + } + + //Test case 1.0: test constructor from effect type and get effect ID + @LargeTest + public void test1_0ConstructorFromType() throws Exception { + boolean result = true; + String msg = "test1_0ConstructorFromType()"; + AudioEffect.Descriptor[] desc = AudioEffect.queryEffects(); + assertTrue(msg+": no effects found", (desc.length != 0)); + try { + int sessionId; + AudioRecord ar = null; + if (AudioEffect.EFFECT_PRE_PROCESSING.equals(desc[0].connectMode)) { + ar = getAudioRecord(); + sessionId = ar.getAudioSessionId(); + } else { + sessionId = 0; + } + + AudioEffect effect = new AudioEffect(desc[0].type, + AudioEffect.EFFECT_TYPE_NULL, + 0, + sessionId); + assertNotNull(msg + ": could not create AudioEffect", effect); + try { + assertTrue(msg +": invalid effect ID", (effect.getId() != 0)); + } catch (IllegalStateException e) { + msg = msg.concat(": AudioEffect not initialized"); + result = false; + } finally { + effect.release(); + if (ar != null) { + ar.release(); + } + } + } catch (IllegalArgumentException e) { + msg = msg.concat(": Effect not found: "+desc[0].name); + result = false; + } catch (UnsupportedOperationException e) { + msg = msg.concat(": Effect library not loaded"); + result = false; + } + assertTrue(msg, result); + } + + //Test case 1.1: test constructor from effect uuid + @LargeTest + public void test1_1ConstructorFromUuid() throws Exception { + boolean result = true; + String msg = "test1_1ConstructorFromUuid()"; + AudioEffect.Descriptor[] desc = AudioEffect.queryEffects(); + assertTrue(msg+"no effects found", (desc.length != 0)); + try { + int sessionId; + AudioRecord ar = null; + if (AudioEffect.EFFECT_PRE_PROCESSING.equals(desc[0].connectMode)) { + ar = getAudioRecord(); + sessionId = ar.getAudioSessionId(); + } else { + sessionId = 0; + } + AudioEffect effect = new AudioEffect(AudioEffect.EFFECT_TYPE_NULL, + desc[0].uuid, + 0, + sessionId); + assertNotNull(msg + ": could not create AudioEffect", effect); + effect.release(); + if (ar != null) { + ar.release(); + } + } catch (IllegalArgumentException e) { + msg = msg.concat(": Effect not found: "+desc[0].name); + result = false; + } catch (UnsupportedOperationException e) { + msg = msg.concat(": Effect library not loaded"); + result = false; + } + assertTrue(msg, result); + } + + //Test case 1.2: test constructor failure from unknown type + @LargeTest + public void test1_2ConstructorUnknownType() throws Exception { + boolean result = false; + String msg = "test1_2ConstructorUnknownType()"; + + try { + AudioEffect effect = new AudioEffect(UUID.randomUUID(), + AudioEffect.EFFECT_TYPE_NULL, + 0, + 0); + msg = msg.concat(": could create random AudioEffect"); + if (effect != null) { + effect.release(); + } + } catch (IllegalArgumentException e) { + result = true; + } catch (UnsupportedOperationException e) { + msg = msg.concat(": Effect library not loaded"); + } + assertTrue(msg, result); + } + + //Test case 1.3: test getEnabled() failure when called on released effect + @LargeTest + public void test1_3GetEnabledAfterRelease() throws Exception { + boolean result = false; + String msg = "test1_3GetEnabledAfterRelease()"; + + try { + AudioEffect effect = new AudioEffect(AudioEffect.EFFECT_TYPE_EQUALIZER, + AudioEffect.EFFECT_TYPE_NULL, + 0, + 0); + assertNotNull(msg + ": could not create AudioEffect", effect); + effect.release(); + try { + effect.getEnabled(); + } catch (IllegalStateException e) { + result = true; + } + } catch (IllegalArgumentException e) { + msg = msg.concat(": Equalizer not found"); + } catch (UnsupportedOperationException e) { + msg = msg.concat(": Effect library not loaded"); + } + assertTrue(msg, result); + } + + //Test case 1.4: test contructor on mediaPlayer audio session + @LargeTest + public void test1_4InsertOnMediaPlayer() throws Exception { + boolean result = false; + String msg = "test1_4InsertOnMediaPlayer()"; + + try { + MediaPlayer mp = new MediaPlayer(); + mp.setDataSource(MediaNames.SHORTMP3); + + AudioEffect effect = new AudioEffect(AudioEffect.EFFECT_TYPE_EQUALIZER, + AudioEffect.EFFECT_TYPE_NULL, + 0, + mp.getAudioSessionId()); + assertNotNull(msg + ": could not create AudioEffect", effect); + try { + loge(msg, ": effect.setEnabled"); + effect.setEnabled(true); + } catch (IllegalStateException e) { + msg = msg.concat(": AudioEffect not initialized"); + } + + result = true; + effect.release(); + mp.release(); + } catch (IllegalArgumentException e) { + msg = msg.concat(": Equalizer not found"); + loge(msg, ": Equalizer not found"); + } catch (UnsupportedOperationException e) { + msg = msg.concat(": Effect library not loaded"); + loge(msg, ": Effect library not loaded"); + } catch (Exception e){ + loge(msg, "Could not create media player:" + e); + } + assertTrue(msg, result); + } + + //Test case 1.5: test auxiliary effect attachement on MediaPlayer + @LargeTest + public void test1_5AuxiliaryOnMediaPlayer() throws Exception { + boolean result = false; + String msg = "test1_5AuxiliaryOnMediaPlayer()"; + + try { + MediaPlayer mp = new MediaPlayer(); + mp.setDataSource(MediaNames.SHORTMP3); + + AudioEffect effect = new AudioEffect(AudioEffect.EFFECT_TYPE_ENV_REVERB, + AudioEffect.EFFECT_TYPE_NULL, + 0, + 0); + assertNotNull(msg + ": could not create AudioEffect", effect); + mp.attachAuxEffect(effect.getId()); + mp.setAuxEffectSendLevel(1.0f); + result = true; + effect.release(); + mp.release(); + } catch (IllegalArgumentException e) { + msg = msg.concat(": Equalizer not found"); + loge(msg, ": Equalizer not found"); + } catch (UnsupportedOperationException e) { + msg = msg.concat(": Effect library not loaded"); + loge(msg, ": Effect library not loaded"); + } catch (Exception e){ + loge(msg, "Could not create media player:" + e); + } + assertTrue(msg, result); + } + + //Test case 1.6: test auxiliary effect attachement failure before setDatasource + @LargeTest + public void test1_6AuxiliaryOnMediaPlayerFailure() throws Exception { + boolean result = false; + String msg = "test1_6AuxiliaryOnMediaPlayerFailure()"; + + try { + createMediaPlayerLooper(); + synchronized(lock) { + try { + lock.wait(1000); + } catch(Exception e) { + Log.e(TAG, "Looper creation: wait was interrupted."); + } + } + assertTrue(mInitialized); // mMediaPlayer has been initialized? + mError = 0; + + AudioEffect effect = new AudioEffect(AudioEffect.EFFECT_TYPE_ENV_REVERB, + AudioEffect.EFFECT_TYPE_NULL, + 0, + 0); + assertNotNull(msg + ": could not create AudioEffect", effect); + synchronized(lock) { + try { + mMediaPlayer.attachAuxEffect(effect.getId()); + lock.wait(1000); + } catch(Exception e) { + Log.e(TAG, "Attach effect: wait was interrupted."); + } + } + assertTrue(msg + ": no error on attachAuxEffect", mError != 0); + result = true; + effect.release(); + terminateMediaPlayerLooper(); + } catch (IllegalArgumentException e) { + msg = msg.concat(": Equalizer not found"); + loge(msg, ": Equalizer not found"); + } catch (UnsupportedOperationException e) { + msg = msg.concat(": Effect library not loaded"); + loge(msg, ": Effect library not loaded"); + } catch (Exception e){ + loge(msg, "Could not create media player:" + e); + } + assertTrue(msg, result); + } + + + //Test case 1.7: test auxiliary effect attachement on AudioTrack + @LargeTest + public void test1_7AuxiliaryOnAudioTrack() throws Exception { + boolean result = false; + String msg = "test1_7AuxiliaryOnAudioTrack()"; + + try { + AudioTrack track = new AudioTrack( + AudioManager.STREAM_MUSIC, + 44100, + AudioFormat.CHANNEL_OUT_MONO, + AudioFormat.ENCODING_PCM_16BIT, + AudioTrack.getMinBufferSize(44100, + AudioFormat.CHANNEL_OUT_MONO, + AudioFormat.ENCODING_PCM_16BIT), + AudioTrack.MODE_STREAM); + assertNotNull(msg + ": could not create AudioTrack", track); + AudioEffect effect = new AudioEffect(AudioEffect.EFFECT_TYPE_ENV_REVERB, + AudioEffect.EFFECT_TYPE_NULL, + 0, + 0); + + track.attachAuxEffect(effect.getId()); + track.setAuxEffectSendLevel(1.0f); + result = true; + effect.release(); + track.release(); + } catch (IllegalArgumentException e) { + msg = msg.concat(": Equalizer not found"); + loge(msg, ": Equalizer not found"); + } catch (UnsupportedOperationException e) { + msg = msg.concat(": Effect library not loaded"); + loge(msg, ": Effect library not loaded"); + } + assertTrue(msg, result); + } + + //----------------------------------------------------------------- + // 2 - enable/ disable + //---------------------------------- + + + //Test case 2.0: test setEnabled() and getEnabled() in valid state + @LargeTest + public void test2_0SetEnabledGetEnabled() throws Exception { + boolean result = false; + String msg = "test2_0SetEnabledGetEnabled()"; + + try { + AudioEffect effect = new AudioEffect(AudioEffect.EFFECT_TYPE_EQUALIZER, + AudioEffect.EFFECT_TYPE_NULL, + 0, + 0); + assertNotNull(msg + ": could not create AudioEffect", effect); + try { + effect.setEnabled(true); + assertTrue(msg + ": invalid state from getEnabled", effect.getEnabled()); + effect.setEnabled(false); + assertFalse(msg + ": invalid state to getEnabled", effect.getEnabled()); + result = true; + } catch (IllegalStateException e) { + msg = msg.concat(": setEnabled() in wrong state"); + } finally { + effect.release(); + } + } catch (IllegalArgumentException e) { + msg = msg.concat(": Equalizer not found"); + loge(msg, ": Equalizer not found"); + } catch (UnsupportedOperationException e) { + msg = msg.concat(": Effect library not loaded"); + loge(msg, ": Effect library not loaded"); + } + assertTrue(msg, result); + } + + //Test case 2.1: test setEnabled() throws exception after release + @LargeTest + public void test2_1SetEnabledAfterRelease() throws Exception { + boolean result = false; + String msg = "test2_1SetEnabledAfterRelease()"; + + try { + AudioEffect effect = new AudioEffect(AudioEffect.EFFECT_TYPE_EQUALIZER, + AudioEffect.EFFECT_TYPE_NULL, + 0, + 0); + assertNotNull(msg + ": could not create AudioEffect", effect); + effect.release(); + try { + effect.setEnabled(true); + } catch (IllegalStateException e) { + result = true; + } + } catch (IllegalArgumentException e) { + msg = msg.concat(": Equalizer not found"); + loge(msg, ": Equalizer not found"); + } catch (UnsupportedOperationException e) { + msg = msg.concat(": Effect library not loaded"); + loge(msg, ": Effect library not loaded"); + } + assertTrue(msg, result); + } + + //----------------------------------------------------------------- + // 3 - set parameters + //---------------------------------- + + //Test case 3.0: test setParameter(byte[], byte[]) + @LargeTest + public void test3_0SetParameterByteArrayByteArray() throws Exception { + boolean result = false; + String msg = "test3_0SetParameterByteArrayByteArray()"; + AudioEffect effect = null; + try { + effect = new AudioEffect(AudioEffect.EFFECT_TYPE_EQUALIZER, + AudioEffect.EFFECT_TYPE_NULL, + 0, + 0); + assertNotNull(msg + ": could not create AudioEffect", effect); + byte[] param = intToByteArray(Equalizer.PARAM_CURRENT_PRESET); + byte[] value = shortToByteArray((short)0); + if (effect.setParameter(param, value) == AudioEffect.SUCCESS) { + result = true; + } + } catch (IllegalArgumentException e) { + msg = msg.concat(": Bad parameter value"); + loge(msg, "Bad parameter value"); + } catch (UnsupportedOperationException e) { + msg = msg.concat(": setParameter() rejected"); + loge(msg, "setParameter() rejected"); + } catch (IllegalStateException e) { + msg = msg.concat("setParameter() called in wrong state"); + loge(msg, "setParameter() called in wrong state"); + } finally { + if (effect != null) { + effect.release(); + } + } + assertTrue(msg, result); + } + + //Test case 3.1: test setParameter(int, int) + @LargeTest + public void test3_1SetParameterIntInt() throws Exception { + boolean result = false; + String msg = "test3_1SetParameterIntInt()"; + AudioEffect effect = null; + try { + effect = new AudioEffect(AudioEffect.EFFECT_TYPE_ENV_REVERB, + AudioEffect.EFFECT_TYPE_NULL, + 0, + 0); + assertNotNull(msg + ": could not create AudioEffect", effect); + if (effect.setParameter(EnvironmentalReverb.PARAM_DECAY_TIME, 0) + == AudioEffect.SUCCESS) { + result = true; + } + } catch (IllegalArgumentException e) { + msg = msg.concat(": Bad parameter value"); + loge(msg, "Bad parameter value"); + } catch (UnsupportedOperationException e) { + msg = msg.concat(": setParameter() rejected"); + loge(msg, "setParameter() rejected"); + } catch (IllegalStateException e) { + msg = msg.concat("setParameter() called in wrong state"); + loge(msg, "setParameter() called in wrong state"); + } finally { + if (effect != null) { + effect.release(); + } + } + assertTrue(msg, result); + } + + //Test case 3.2: test setParameter(int, short) + @LargeTest + public void test3_2SetParameterIntShort() throws Exception { + boolean result = false; + String msg = "test3_2SetParameterIntShort()"; + AudioEffect effect = null; + try { + effect = new AudioEffect(AudioEffect.EFFECT_TYPE_EQUALIZER, + AudioEffect.EFFECT_TYPE_NULL, + 0, + 0); + assertNotNull(msg + ": could not create AudioEffect", effect); + if (effect.setParameter(Equalizer.PARAM_CURRENT_PRESET, (short)0) + == AudioEffect.SUCCESS) { + result = true; + } + } catch (IllegalArgumentException e) { + msg = msg.concat(": Bad parameter value"); + loge(msg, "Bad parameter value"); + } catch (UnsupportedOperationException e) { + msg = msg.concat(": setParameter() rejected"); + loge(msg, "setParameter() rejected"); + } catch (IllegalStateException e) { + msg = msg.concat("setParameter() called in wrong state"); + loge(msg, "setParameter() called in wrong state"); + } finally { + if (effect != null) { + effect.release(); + } + } + assertTrue(msg, result); + } + + //Test case 3.3: test setParameter(int, byte[]) + @LargeTest + public void test3_3SetParameterIntByteArray() throws Exception { + boolean result = false; + String msg = "test3_3SetParameterIntByteArray()"; + AudioEffect effect = null; + try { + effect = new AudioEffect(AudioEffect.EFFECT_TYPE_EQUALIZER, + AudioEffect.EFFECT_TYPE_NULL, + 0, + 0); + assertNotNull(msg + ": could not create AudioEffect", effect); + byte[] value = shortToByteArray((short)0); + if (effect.setParameter(Equalizer.PARAM_CURRENT_PRESET, value) + == AudioEffect.SUCCESS) { + result = true; + } + } catch (IllegalArgumentException e) { + msg = msg.concat(": Bad parameter value"); + loge(msg, "Bad parameter value"); + } catch (UnsupportedOperationException e) { + msg = msg.concat(": setParameter() rejected"); + loge(msg, "setParameter() rejected"); + } catch (IllegalStateException e) { + msg = msg.concat("setParameter() called in wrong state"); + loge(msg, "setParameter() called in wrong state"); + } finally { + if (effect != null) { + effect.release(); + } + } + assertTrue(msg, result); + } + + //Test case 3.4: test setParameter(int[], int[]) + @LargeTest + public void test3_4SetParameterIntArrayIntArray() throws Exception { + boolean result = false; + String msg = "test3_4SetParameterIntArrayIntArray()"; + AudioEffect effect = null; + try { + effect = new AudioEffect(AudioEffect.EFFECT_TYPE_ENV_REVERB, + AudioEffect.EFFECT_TYPE_NULL, + 0, + 0); + assertNotNull(msg + ": could not create AudioEffect", effect); + int[] param = new int[1]; + int[] value = new int[1]; + param[0] = EnvironmentalReverb.PARAM_DECAY_TIME; + value[0] = 0; + if (effect.setParameter(param, value) + == AudioEffect.SUCCESS) { + result = true; + } + } catch (IllegalArgumentException e) { + msg = msg.concat(": Bad parameter value"); + loge(msg, "Bad parameter value"); + } catch (UnsupportedOperationException e) { + msg = msg.concat(": setParameter() rejected"); + loge(msg, "setParameter() rejected"); + } catch (IllegalStateException e) { + msg = msg.concat("setParameter() called in wrong state"); + loge(msg, "setParameter() called in wrong state"); + } finally { + if (effect != null) { + effect.release(); + } + } + assertTrue(msg, result); + } + + //Test case 3.5: test setParameter(int[], short[]) + @LargeTest + public void test3_5SetParameterIntArrayShortArray() throws Exception { + boolean result = false; + String msg = "test3_5SetParameterIntArrayShortArray()"; + AudioEffect effect = null; + try { + effect = new AudioEffect(AudioEffect.EFFECT_TYPE_EQUALIZER, + AudioEffect.EFFECT_TYPE_NULL, + 0, + 0); + assertNotNull(msg + ": could not create AudioEffect", effect); + int[] param = new int[1]; + short[] value = new short[1]; + param[0] = Equalizer.PARAM_CURRENT_PRESET; + value[0] = (short)0; + if (effect.setParameter(param, value) + == AudioEffect.SUCCESS) { + result = true; + } + } catch (IllegalArgumentException e) { + msg = msg.concat(": Bad parameter value"); + loge(msg, "Bad parameter value"); + } catch (UnsupportedOperationException e) { + msg = msg.concat(": setParameter() rejected"); + loge(msg, "setParameter() rejected"); + } catch (IllegalStateException e) { + msg = msg.concat("setParameter() called in wrong state"); + loge(msg, "setParameter() called in wrong state"); + } finally { + if (effect != null) { + effect.release(); + } + } + assertTrue(msg, result); + } + + //Test case 3.6: test setParameter(int[], byte[]) + @LargeTest + public void test3_6SetParameterIntArrayByteArray() throws Exception { + boolean result = false; + String msg = "test3_6SetParameterIntArrayByteArray()"; + AudioEffect effect = null; + try { + effect = new AudioEffect(AudioEffect.EFFECT_TYPE_EQUALIZER, + AudioEffect.EFFECT_TYPE_NULL, + 0, + 0); + assertNotNull(msg + ": could not create AudioEffect", effect); + int[] param = new int[1]; + byte[] value = shortToByteArray((short)0); + param[0] = Equalizer.PARAM_CURRENT_PRESET; + if (effect.setParameter(param, value) + == AudioEffect.SUCCESS) { + result = true; + } + } catch (IllegalArgumentException e) { + msg = msg.concat(": Bad parameter value"); + loge(msg, "Bad parameter value"); + } catch (UnsupportedOperationException e) { + msg = msg.concat(": setParameter() rejected"); + loge(msg, "setParameter() rejected"); + } catch (IllegalStateException e) { + msg = msg.concat("setParameter() called in wrong state"); + loge(msg, "setParameter() called in wrong state"); + } finally { + if (effect != null) { + effect.release(); + } + } + assertTrue(msg, result); + } + + //Test case 3.7: test setParameter() throws exception after release() + @LargeTest + public void test3_7SetParameterAfterRelease() throws Exception { + boolean result = false; + String msg = "test3_7SetParameterAfterRelease()"; + AudioEffect effect = null; + try { + effect = new AudioEffect(AudioEffect.EFFECT_TYPE_EQUALIZER, + AudioEffect.EFFECT_TYPE_NULL, + 0, + 0); + assertNotNull(msg + ": could not create AudioEffect", effect); + effect.release(); + effect.setParameter(Equalizer.PARAM_CURRENT_PRESET, (short)0); + } catch (IllegalArgumentException e) { + msg = msg.concat(": Bad parameter value"); + loge(msg, "Bad parameter value"); + } catch (UnsupportedOperationException e) { + msg = msg.concat(": setParameter() rejected"); + loge(msg, "setParameter() rejected"); + } catch (IllegalStateException e) { + result = true; + } finally { + if (effect != null) { + effect.release(); + } + } + assertTrue(msg, result); + } + + //----------------------------------------------------------------- + // 4 - get parameters + //---------------------------------- + + //Test case 4.0: test getParameter(byte[], byte[]) + @LargeTest + public void test4_0GetParameterByteArrayByteArray() throws Exception { + boolean result = false; + String msg = "test4_0GetParameterByteArrayByteArray()"; + AudioEffect effect = null; + try { + effect = new AudioEffect(AudioEffect.EFFECT_TYPE_EQUALIZER, + AudioEffect.EFFECT_TYPE_NULL, + 0, + 0); + assertNotNull(msg + ": could not create AudioEffect", effect); + byte[] param = intToByteArray(Equalizer.PARAM_CURRENT_PRESET); + byte[] value = new byte[2]; + if (!AudioEffect.isError(effect.getParameter(param, value))) { + result = true; + } + } catch (IllegalArgumentException e) { + msg = msg.concat(": Bad parameter value"); + loge(msg, "Bad parameter value"); + } catch (UnsupportedOperationException e) { + msg = msg.concat(": getParameter() rejected"); + loge(msg, "getParameter() rejected"); + } catch (IllegalStateException e) { + msg = msg.concat("getParameter() called in wrong state"); + loge(msg, "getParameter() called in wrong state"); + } finally { + if (effect != null) { + effect.release(); + } + } + assertTrue(msg, result); + } + + //Test case 4.1: test getParameter(int, int[]) + @LargeTest + public void test4_1GetParameterIntIntArray() throws Exception { + boolean result = false; + String msg = "test4_1GetParameterIntIntArray()"; + AudioEffect effect = null; + try { + effect = new AudioEffect(AudioEffect.EFFECT_TYPE_ENV_REVERB, + AudioEffect.EFFECT_TYPE_NULL, + 0, + 0); + assertNotNull(msg + ": could not create AudioEffect", effect); + int[] value = new int[1]; + if (!AudioEffect.isError( + effect.getParameter(EnvironmentalReverb.PARAM_DECAY_TIME, value))) { + result = true; + } + } catch (IllegalArgumentException e) { + msg = msg.concat(": Bad parameter value"); + loge(msg, "Bad parameter value"); + } catch (UnsupportedOperationException e) { + msg = msg.concat(": getParameter() rejected"); + loge(msg, "getParameter() rejected"); + } catch (IllegalStateException e) { + msg = msg.concat("getParameter() called in wrong state"); + loge(msg, "getParameter() called in wrong state"); + } finally { + if (effect != null) { + effect.release(); + } + } + assertTrue(msg, result); + } + + //Test case 4.2: test getParameter(int, short[]) + @LargeTest + public void test4_2GetParameterIntShortArray() throws Exception { + boolean result = false; + String msg = "test4_2GetParameterIntShortArray()"; + AudioEffect effect = null; + try { + effect = new AudioEffect(AudioEffect.EFFECT_TYPE_EQUALIZER, + AudioEffect.EFFECT_TYPE_NULL, + 0, + 0); + assertNotNull(msg + ": could not create AudioEffect", effect); + short[] value = new short[1]; + if (!AudioEffect.isError(effect.getParameter(Equalizer.PARAM_CURRENT_PRESET, value))) { + result = true; + } + } catch (IllegalArgumentException e) { + msg = msg.concat(": Bad parameter value"); + loge(msg, "Bad parameter value"); + } catch (UnsupportedOperationException e) { + msg = msg.concat(": getParameter() rejected"); + loge(msg, "getParameter() rejected"); + } catch (IllegalStateException e) { + msg = msg.concat("getParameter() called in wrong state"); + loge(msg, "getParameter() called in wrong state"); + } finally { + if (effect != null) { + effect.release(); + } + } + assertTrue(msg, result); + } + + //Test case 4.3: test getParameter(int, byte[]) + @LargeTest + public void test4_3GetParameterIntByteArray() throws Exception { + boolean result = false; + String msg = "test4_3GetParameterIntByteArray()"; + AudioEffect effect = null; + try { + effect = new AudioEffect(AudioEffect.EFFECT_TYPE_EQUALIZER, + AudioEffect.EFFECT_TYPE_NULL, + 0, + 0); + assertNotNull(msg + ": could not create AudioEffect", effect); + byte[] value = new byte[2]; + if (!AudioEffect.isError(effect.getParameter(Equalizer.PARAM_CURRENT_PRESET, value))) { + result = true; + } + } catch (IllegalArgumentException e) { + msg = msg.concat(": Bad parameter value"); + loge(msg, "Bad parameter value"); + } catch (UnsupportedOperationException e) { + msg = msg.concat(": getParameter() rejected"); + loge(msg, "getParameter() rejected"); + } catch (IllegalStateException e) { + msg = msg.concat("getParameter() called in wrong state"); + loge(msg, "getParameter() called in wrong state"); + } finally { + if (effect != null) { + effect.release(); + } + } + assertTrue(msg, result); + } + + //Test case 4.4: test getParameter(int[], int[]) + @LargeTest + public void test4_4GetParameterIntArrayIntArray() throws Exception { + boolean result = false; + String msg = "test4_4GetParameterIntArrayIntArray()"; + AudioEffect effect = null; + try { + effect = new AudioEffect(AudioEffect.EFFECT_TYPE_ENV_REVERB, + AudioEffect.EFFECT_TYPE_NULL, + 0, + 0); + assertNotNull(msg + ": could not create AudioEffect", effect); + int[] param = new int[1]; + int[] value = new int[1]; + param[0] = EnvironmentalReverb.PARAM_DECAY_TIME; + if (!AudioEffect.isError(effect.getParameter(param, value))) { + result = true; + } + } catch (IllegalArgumentException e) { + msg = msg.concat(": Bad parameter value"); + loge(msg, "Bad parameter value"); + } catch (UnsupportedOperationException e) { + msg = msg.concat(": getParameter() rejected"); + loge(msg, "getParameter() rejected"); + } catch (IllegalStateException e) { + msg = msg.concat("getParameter() called in wrong state"); + loge(msg, "getParameter() called in wrong state"); + } finally { + if (effect != null) { + effect.release(); + } + } + assertTrue(msg, result); + } + + //Test case 4.5: test getParameter(int[], short[]) + @LargeTest + public void test4_5GetParameterIntArrayShortArray() throws Exception { + boolean result = false; + String msg = "test4_5GetParameterIntArrayShortArray()"; + AudioEffect effect = null; + try { + effect = new AudioEffect(AudioEffect.EFFECT_TYPE_EQUALIZER, + AudioEffect.EFFECT_TYPE_NULL, + 0, + 0); + assertNotNull(msg + ": could not create AudioEffect", effect); + int[] param = new int[1]; + short[] value = new short[1]; + param[0] = Equalizer.PARAM_CURRENT_PRESET; + if (!AudioEffect.isError(effect.getParameter(param, value))) { + result = true; + } + } catch (IllegalArgumentException e) { + msg = msg.concat(": Bad parameter value"); + loge(msg, "Bad parameter value"); + } catch (UnsupportedOperationException e) { + msg = msg.concat(": getParameter() rejected"); + loge(msg, "getParameter() rejected"); + } catch (IllegalStateException e) { + msg = msg.concat("getParameter() called in wrong state"); + loge(msg, "getParameter() called in wrong state"); + } finally { + if (effect != null) { + effect.release(); + } + } + assertTrue(msg, result); + } + + //Test case 4.6: test getParameter(int[], byte[]) + @LargeTest + public void test4_6GetParameterIntArrayByteArray() throws Exception { + boolean result = false; + String msg = "test4_6GetParameterIntArrayByteArray()"; + AudioEffect effect = null; + try { + effect = new AudioEffect(AudioEffect.EFFECT_TYPE_EQUALIZER, + AudioEffect.EFFECT_TYPE_NULL, + 0, + 0); + assertNotNull(msg + ": could not create AudioEffect", effect); + int[] param = new int[1]; + byte[] value = new byte[2]; + param[0] = Equalizer.PARAM_CURRENT_PRESET; + if (!AudioEffect.isError(effect.getParameter(param, value))) { + result = true; + } + } catch (IllegalArgumentException e) { + msg = msg.concat(": Bad parameter value"); + loge(msg, "Bad parameter value"); + } catch (UnsupportedOperationException e) { + msg = msg.concat(": getParameter() rejected"); + loge(msg, "getParameter() rejected"); + } catch (IllegalStateException e) { + msg = msg.concat("getParameter() called in wrong state"); + loge(msg, "getParameter() called in wrong state"); + } finally { + if (effect != null) { + effect.release(); + } + } + assertTrue(msg, result); + } + + //Test case 4.7: test getParameter() throws exception after release() + @LargeTest + public void test4_7GetParameterAfterRelease() throws Exception { + boolean result = false; + String msg = "test4_7GetParameterAfterRelease()"; + AudioEffect effect = null; + try { + effect = new AudioEffect(AudioEffect.EFFECT_TYPE_EQUALIZER, + AudioEffect.EFFECT_TYPE_NULL, + 0, + 0); + assertNotNull(msg + ": could not create AudioEffect", effect); + effect.release(); + short[] value = new short[1]; + effect.getParameter(Equalizer.PARAM_CURRENT_PRESET, value); + } catch (IllegalArgumentException e) { + msg = msg.concat(": Bad parameter value"); + loge(msg, "Bad parameter value"); + } catch (UnsupportedOperationException e) { + msg = msg.concat(": getParameter() rejected"); + loge(msg, "getParameter() rejected"); + } catch (IllegalStateException e) { + result = true; + } finally { + if (effect != null) { + effect.release(); + } + } + assertTrue(msg, result); + } + + //----------------------------------------------------------------- + // 5 priority and listeners + //---------------------------------- + + //Test case 5.0: test control passed to higher priority client + @LargeTest + public void test5_0setEnabledLowerPriority() throws Exception { + boolean result = false; + String msg = "test5_0setEnabledLowerPriority()"; + AudioEffect effect1 = null; + AudioEffect effect2 = null; + try { + effect1 = new AudioEffect(AudioEffect.EFFECT_TYPE_EQUALIZER, + AudioEffect.EFFECT_TYPE_NULL, + 0, + 0); + effect2 = new AudioEffect(AudioEffect.EFFECT_TYPE_EQUALIZER, + AudioEffect.EFFECT_TYPE_NULL, + 1, + 0); + + assertNotNull(msg + ": could not create AudioEffect", effect1); + assertNotNull(msg + ": could not create AudioEffect", effect2); + + assertTrue(msg + ": Effect2 does not have control", effect2.hasControl()); + assertFalse(msg + ": Effect1 has control", effect1.hasControl()); + assertTrue(msg + ": Effect1 can enable", + effect1.setEnabled(true) == AudioEffect.ERROR_INVALID_OPERATION); + assertFalse(msg + ": Effect1 has enabled", effect2.getEnabled()); + result = true; + } catch (IllegalArgumentException e) { + msg = msg.concat(": Effect not found"); + result = false; + } catch (UnsupportedOperationException e) { + msg = msg.concat(": Effect library not loaded"); + result = false; + } finally { + if (effect1 != null) { + effect1.release(); + } + if (effect2 != null) { + effect2.release(); + } + } + assertTrue(msg, result); + } + + //Test case 5.1: test control passed to higher priority client + @LargeTest + public void test5_1setParameterLowerPriority() throws Exception { + boolean result = false; + String msg = "test5_1setParameterLowerPriority()"; + AudioEffect effect1 = null; + AudioEffect effect2 = null; + try { + effect1 = new AudioEffect(AudioEffect.EFFECT_TYPE_EQUALIZER, + AudioEffect.EFFECT_TYPE_NULL, + 0, + 0); + effect2 = new AudioEffect(AudioEffect.EFFECT_TYPE_EQUALIZER, + AudioEffect.EFFECT_TYPE_NULL, + 1, + 0); + + assertNotNull(msg + ": could not create AudioEffect", effect1); + assertNotNull(msg + ": could not create AudioEffect", effect2); + + int status = effect2.setParameter(Equalizer.PARAM_CURRENT_PRESET, (short)0); + assertEquals(msg + ": Effect2 setParameter failed", + AudioEffect.SUCCESS, status); + + status = effect1.setParameter(Equalizer.PARAM_CURRENT_PRESET, (short)1); + assertEquals(msg + ": Effect1 setParameter did not fail", + AudioEffect.ERROR_INVALID_OPERATION, status); + + short[] value = new short[1]; + status = effect2.getParameter(Equalizer.PARAM_CURRENT_PRESET, value); + assertFalse(msg + ": Effect2 getParameter failed", + AudioEffect.isError(status)); + assertEquals(msg + ": Effect1 changed parameter", + (short)0, value[0]); + + result = true; + } catch (IllegalArgumentException e) { + msg = msg.concat(": Effect not found"); + result = false; + } catch (UnsupportedOperationException e) { + msg = msg.concat(": Effect library not loaded"); + result = false; + } finally { + if (effect1 != null) { + effect1.release(); + } + if (effect2 != null) { + effect2.release(); + } + } + assertTrue(msg, result); + } + + //Test case 5.2: test control status listener + @LargeTest + public void test5_2ControlStatusListener() throws Exception { + boolean result = false; + String msg = "test5_2ControlStatusListener()"; + mEffect = null; + AudioEffect effect2 = null; + try { + mHasControl = true; + createListenerLooper(true, false, false); + synchronized(lock) { + try { + lock.wait(1000); + } catch(Exception e) { + Log.e(TAG, "Looper creation: wait was interrupted."); + } + } + assertTrue(mInitialized); + synchronized(lock) { + try { + effect2 = new AudioEffect(AudioEffect.EFFECT_TYPE_EQUALIZER, + AudioEffect.EFFECT_TYPE_NULL, + 1, + 0); + assertNotNull(msg + ": could not create AudioEffect", effect2); + lock.wait(1000); + } catch(Exception e) { + Log.e(TAG, "Create second effect: wait was interrupted."); + } + } + assertFalse(msg + ": effect control not lost by effect1", mHasControl); + result = true; + } catch (IllegalArgumentException e) { + msg = msg.concat(": Equalizer not found"); + loge(msg, ": Equalizer not found"); + } catch (UnsupportedOperationException e) { + msg = msg.concat(": Effect library not loaded"); + loge(msg, ": Effect library not loaded"); + } catch (Exception e){ + loge(msg, "Could not create media player:" + e); + } finally { + terminateListenerLooper(); + if (effect2 != null) { + effect2.release(); + } + } + assertTrue(msg, result); + } + + //Test case 5.3: test enable status listener + @LargeTest + public void test5_3EnableStatusListener() throws Exception { + boolean result = false; + String msg = "test5_3EnableStatusListener()"; + mEffect = null; + AudioEffect effect2 = null; + try { + createListenerLooper(false, true, false); + synchronized(lock) { + try { + lock.wait(1000); + } catch(Exception e) { + Log.e(TAG, "Looper creation: wait was interrupted."); + } + } + assertTrue(mInitialized); + mEffect.setEnabled(true); + mIsEnabled = true; + effect2 = new AudioEffect(AudioEffect.EFFECT_TYPE_EQUALIZER, + AudioEffect.EFFECT_TYPE_NULL, + 1, + 0); + assertNotNull(msg + ": could not create AudioEffect", effect2); + assertTrue(msg + ": effect not enabled", effect2.getEnabled()); + synchronized(lock) { + try { + effect2.setEnabled(false); + lock.wait(1000); + } catch(Exception e) { + Log.e(TAG, "Create second effect: wait was interrupted."); + } + } + assertFalse(msg + ": enable status not updated", mIsEnabled); + result = true; + } catch (IllegalArgumentException e) { + msg = msg.concat(": Equalizer not found"); + loge(msg, ": Equalizer not found"); + } catch (UnsupportedOperationException e) { + msg = msg.concat(": Effect library not loaded"); + loge(msg, ": Effect library not loaded"); + } catch (Exception e){ + loge(msg, "Could not create media player:" + e); + } finally { + terminateListenerLooper(); + if (effect2 != null) { + effect2.release(); + } + } + assertTrue(msg, result); + } + + //Test case 5.4: test parameter changed listener + @LargeTest + public void test5_4ParameterChangedListener() throws Exception { + boolean result = false; + String msg = "test5_4ParameterChangedListener()"; + mEffect = null; + AudioEffect effect2 = null; + try { + createListenerLooper(false, false, true); + synchronized(lock) { + try { + lock.wait(1000); + } catch(Exception e) { + Log.e(TAG, "Looper creation: wait was interrupted."); + } + } + assertTrue(mInitialized); + effect2 = new AudioEffect(AudioEffect.EFFECT_TYPE_EQUALIZER, + AudioEffect.EFFECT_TYPE_NULL, + 1, + 0); + assertNotNull(msg + ": could not create AudioEffect", effect2); + synchronized(lock) { + try { + mParameterChanged = -1; + effect2.setParameter(Equalizer.PARAM_CURRENT_PRESET, (short)0); + lock.wait(1000); + } catch(Exception e) { + Log.e(TAG, "Create second effect: wait was interrupted."); + } + } + assertEquals(msg + ": parameter change not received", + Equalizer.PARAM_CURRENT_PRESET, mParameterChanged); + result = true; + } catch (IllegalArgumentException e) { + msg = msg.concat(": Equalizer not found"); + loge(msg, ": Equalizer not found"); + } catch (UnsupportedOperationException e) { + msg = msg.concat(": Effect library not loaded"); + loge(msg, ": Effect library not loaded"); + } catch (Exception e){ + loge(msg, "Could not create media player:" + e); + } finally { + terminateListenerLooper(); + if (effect2 != null) { + effect2.release(); + } + } + assertTrue(msg, result); + } + + //----------------------------------------------------------------- + // 6 command method + //---------------------------------- + + + //Test case 6.0: test command method + @LargeTest + public void test6_0Command() throws Exception { + boolean result = false; + String msg = "test6_0Command()"; + AudioEffect effect = null; + try { + effect = new AudioEffect(AudioEffect.EFFECT_TYPE_EQUALIZER, + AudioEffect.EFFECT_TYPE_NULL, + 0, + 0); + assertNotNull(msg + ": could not create AudioEffect", effect); + try { + byte[] cmd = new byte[0]; + byte[] reply = new byte[4]; + int status = effect.command(3, cmd, reply); + assertFalse(msg + ": command failed", AudioEffect.isError(status)); + assertTrue(msg + ": effect not enabled", effect.getEnabled()); + result = true; + } catch (IllegalStateException e) { + msg = msg.concat(": command in illegal state"); + } + } catch (IllegalArgumentException e) { + msg = msg.concat(": Equalizer not found"); + loge(msg, ": Equalizer not found"); + } catch (UnsupportedOperationException e) { + msg = msg.concat(": Effect library not loaded"); + loge(msg, ": Effect library not loaded"); + } catch (Exception e){ + loge(msg, "Could not create media player:" + e); + } finally { + if (effect != null) { + effect.release(); + } + } + assertTrue(msg, result); + } + + //----------------------------------------------------------------- + // private methods + //---------------------------------- + + /* + * Initializes the message looper so that the MediaPlayer object can + * receive the callback messages. + */ + private void createMediaPlayerLooper() { + new Thread() { + @Override + public void run() { + // Set up a looper to be used by mMediaPlayer. + Looper.prepare(); + + // Save the looper so that we can terminate this thread + // after we are done with it. + mLooper = Looper.myLooper(); + + mMediaPlayer = new MediaPlayer(); + mMediaPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() { + public boolean onError(MediaPlayer player, int what, int extra) { + synchronized(lock) { + mError = what; + lock.notify(); + } + return true; + } + }); + mMediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { + public void onCompletion(MediaPlayer player) { + synchronized(lock) { + lock.notify(); + } + } + }); + synchronized(lock) { + mInitialized = true; + lock.notify(); + } + Looper.loop(); // Blocks forever until Looper.quit() is called. + } + }.start(); + } + /* + * Terminates the message looper thread. + */ + private void terminateMediaPlayerLooper() { + if (mLooper != null) { + mLooper.quit(); + mLooper = null; + } + if (mMediaPlayer != null) { + mMediaPlayer.release(); + } + } + + /* + * Initializes the message looper fro effect listener + */ + class ListenerThread extends Thread { + boolean mControl; + boolean mEnable; + boolean mParameter; + + public ListenerThread(boolean control, boolean enable, boolean parameter) { + super(); + mControl = control; + mEnable = enable; + mParameter = parameter; + } + } + private void createListenerLooper(boolean control, boolean enable, boolean parameter) { + + new ListenerThread(control, enable, parameter) { + @Override + public void run() { + // Set up a looper to be used by mEffect. + Looper.prepare(); + + // Save the looper so that we can terminate this thread + // after we are done with it. + mLooper = Looper.myLooper(); + + mEffect = new AudioEffect(AudioEffect.EFFECT_TYPE_EQUALIZER, + AudioEffect.EFFECT_TYPE_NULL, + 0, + 0); + assertNotNull("could not create AudioEffect", mEffect); + + if (mControl) { + mEffect.setControlStatusListener(new AudioEffect.OnControlStatusChangeListener() { + public void onControlStatusChange(AudioEffect effect, boolean controlGranted) { + synchronized(lock) { + if (effect == mEffect) { + mHasControl = controlGranted; + lock.notify(); + } + } + } + }); + } + if (mEnable) { + mEffect.setEnableStatusListener(new AudioEffect.OnEnableStatusChangeListener() { + public void onEnableStatusChange(AudioEffect effect, boolean enabled) { + synchronized(lock) { + if (effect == mEffect) { + mIsEnabled = enabled; + lock.notify(); + } + } + } + }); + } + if (mParameter) { + mEffect.setParameterListener(new AudioEffect.OnParameterChangeListener() { + public void onParameterChange(AudioEffect effect, int status, byte[] param, + byte[] value) { + synchronized(lock) { + if (effect == mEffect) { + mParameterChanged = byteArrayToInt(param); + lock.notify(); + } + } + } + }); + } + + synchronized(lock) { + mInitialized = true; + lock.notify(); + } + Looper.loop(); // Blocks forever until Looper.quit() is called. + } + }.start(); + } + /* + * Terminates the listener looper thread. + */ + private void terminateListenerLooper() { + if (mEffect != null) { + mEffect.release(); + mEffect = null; + } + if (mLooper != null) { + mLooper.quit(); + mLooper = null; + } + } + + protected int byteArrayToInt(byte[] valueBuf) { + return byteArrayToInt(valueBuf, 0); + + } + + protected int byteArrayToInt(byte[] valueBuf, int offset) { + ByteBuffer converter = ByteBuffer.wrap(valueBuf); + converter.order(ByteOrder.nativeOrder()); + return converter.getInt(offset); + + } + + protected byte[] intToByteArray(int value) { + ByteBuffer converter = ByteBuffer.allocate(4); + converter.order(ByteOrder.nativeOrder()); + converter.putInt(value); + return converter.array(); + } + + protected short byteArrayToShort(byte[] valueBuf) { + return byteArrayToShort(valueBuf, 0); + } + + protected short byteArrayToShort(byte[] valueBuf, int offset) { + ByteBuffer converter = ByteBuffer.wrap(valueBuf); + converter.order(ByteOrder.nativeOrder()); + return converter.getShort(offset); + + } + + protected byte[] shortToByteArray(short value) { + ByteBuffer converter = ByteBuffer.allocate(2); + converter.order(ByteOrder.nativeOrder()); + short sValue = (short) value; + converter.putShort(sValue); + return converter.array(); + } + +} diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/MediaAudioManagerTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/MediaAudioManagerTest.java new file mode 100644 index 0000000..c9087d1 --- /dev/null +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/MediaAudioManagerTest.java @@ -0,0 +1,70 @@ + /* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package com.android.mediaframeworktest.functional.audio; + +import com.android.mediaframeworktest.MediaFrameworkTest; +import android.content.Context; +import android.media.AudioManager; +import android.test.ActivityInstrumentationTestCase2; +import android.test.suitebuilder.annotation.MediumTest; + +/** + * Junit / Instrumentation test case for the media AudioManager api + */ + +public class MediaAudioManagerTest extends ActivityInstrumentationTestCase2 { + + private String TAG = "MediaAudioManagerTest"; + private AudioManager mAudioManager; + private int[] ringtoneMode = {AudioManager.RINGER_MODE_NORMAL, + AudioManager.RINGER_MODE_SILENT, AudioManager.RINGER_MODE_VIBRATE}; + + public MediaAudioManagerTest() { + super("com.android.mediaframeworktest", MediaFrameworkTest.class); + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + mAudioManager = (AudioManager) getActivity().getSystemService(Context.AUDIO_SERVICE); + } + + @Override + protected void tearDown() throws Exception { + super.tearDown(); + } + + public boolean validateSetRingTone(int i) { + int getRingtone = mAudioManager.getRingerMode(); + if (i != getRingtone) + return false; + else + return true; + } + + // Test case 1: Simple test case to validate the set ringtone mode + @MediumTest + public void testSetRingtoneMode() throws Exception { + boolean result = false; + + for (int i = 0; i < ringtoneMode.length; i++) { + mAudioManager.setRingerMode(ringtoneMode[i]); + result = validateSetRingTone(ringtoneMode[i]); + assertTrue("SetRingtoneMode : " + ringtoneMode[i], result); + } + } + } diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/MediaAudioTrackTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/MediaAudioTrackTest.java new file mode 100644 index 0000000..e884aba --- /dev/null +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/MediaAudioTrackTest.java @@ -0,0 +1,1252 @@ +/* + * Copyright (C) 2009 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.mediaframeworktest.functional.audio; + +import com.android.mediaframeworktest.MediaFrameworkTest; +import com.android.mediaframeworktest.MediaNames; + +import android.media.AudioFormat; +import android.media.AudioManager; +import android.media.AudioTrack; +import android.test.ActivityInstrumentationTestCase2; +import android.util.Log; +import android.test.suitebuilder.annotation.LargeTest; +import android.test.suitebuilder.annotation.MediumTest; +import android.test.suitebuilder.annotation.Suppress; + +/** + * Junit / Instrumentation test case for the media AudioTrack api + + */ +public class MediaAudioTrackTest extends ActivityInstrumentationTestCase2 { + private String TAG = "MediaAudioTrackTest"; + + public MediaAudioTrackTest() { + super("com.android.mediaframeworktest", MediaFrameworkTest.class); + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + } + + @Override + protected void tearDown() throws Exception { + super.tearDown(); + } + + private static void assumeTrue(String message, boolean cond) { + assertTrue("(assume)"+message, cond); + } + + private void log(String testName, String message) { + Log.v(TAG, "["+testName+"] "+message); + } + + private void loge(String testName, String message) { + Log.e(TAG, "["+testName+"] "+message); + } + + //----------------------------------------------------------------- + // private class to hold test reslts + public class TestResults { + public boolean mResult = false; + public String mResultLog = ""; + public TestResults(boolean b, String s) { mResult = b; mResultLog = s; } + } + + //----------------------------------------------------------------- + // generic test methods + public TestResults constructorTestMultiSampleRate( + // parameters tested by this method + int _inTest_streamType, int _inTest_mode, + int _inTest_config, int _inTest_format, + // parameter-dependent expected results + int _expected_stateForMode) { + + int[] testSampleRates = {8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000}; + String failedRates = "Failure for rate(s): "; + boolean localRes, finalRes = true; + + for (int i = 0 ; i < testSampleRates.length ; i++) { + //Log.v("MediaAudioTrackTest", "[ constructorTestMultiSampleRate ] testing "+ testSampleRates[i]); + AudioTrack track = null; + try { + track = new AudioTrack( + _inTest_streamType, + testSampleRates[i], + _inTest_config, + _inTest_format, + AudioTrack.getMinBufferSize(testSampleRates[i], + _inTest_config, _inTest_format), + _inTest_mode); + } catch(IllegalArgumentException iae) { + Log.e("MediaAudioTrackTest", "[ constructorTestMultiSampleRate ] exception at SR " + + testSampleRates[i]+": \n" + iae); + localRes = false; + } + if (track != null) { + localRes = (track.getState() == _expected_stateForMode); + track.release(); + } + else { + localRes = false; + } + + if (!localRes) { + //log the error for the test runner + failedRates += Integer.toString(testSampleRates[i]) + "Hz "; + //log the error for logcat + log("constructorTestMultiSampleRate", "failed to construct " + +"AudioTrack(streamType="+_inTest_streamType + +", sampleRateInHz=" + testSampleRates[i] + +", channelConfig=" + _inTest_config + +", audioFormat=" + _inTest_format + +", bufferSizeInBytes=" + AudioTrack.getMinBufferSize(testSampleRates[i], + _inTest_config, AudioFormat.ENCODING_PCM_16BIT) + +", mode="+ _inTest_mode ); + //mark test as failed + finalRes = false; + } + } + return new TestResults(finalRes, failedRates); + } + + //----------------------------------------------------------------- + // AUDIOTRACK TESTS: + //---------------------------------- + + //----------------------------------------------------------------- + // AudioTrack constructor and AudioTrack.getMinBufferSize(...) for 16bit PCM + //---------------------------------- + + //Test case 1: constructor for streaming AudioTrack, mono, 16bit at misc valid sample rates + @LargeTest + public void testConstructorMono16MusicStream() throws Exception { + + TestResults res = constructorTestMultiSampleRate( + AudioManager.STREAM_MUSIC, AudioTrack.MODE_STREAM, + AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_16BIT, + AudioTrack.STATE_INITIALIZED); + + assertTrue("testConstructorMono16MusicStream: " + res.mResultLog, res.mResult); + } + + + //Test case 2: constructor for streaming AudioTrack, stereo, 16bit at misc valid sample rates + @LargeTest + public void testConstructorStereo16MusicStream() throws Exception { + + TestResults res = constructorTestMultiSampleRate( + AudioManager.STREAM_MUSIC, AudioTrack.MODE_STREAM, + AudioFormat.CHANNEL_OUT_STEREO, AudioFormat.ENCODING_PCM_16BIT, + AudioTrack.STATE_INITIALIZED); + + assertTrue("testConstructorStereo16MusicStream: " + res.mResultLog, res.mResult); + } + + + //Test case 3: constructor for static AudioTrack, mono, 16bit at misc valid sample rates + @LargeTest + public void testConstructorMono16MusicStatic() throws Exception { + + TestResults res = constructorTestMultiSampleRate( + AudioManager.STREAM_MUSIC, AudioTrack.MODE_STATIC, + AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_16BIT, + AudioTrack.STATE_NO_STATIC_DATA); + + assertTrue("testConstructorMono16MusicStatic: " + res.mResultLog, res.mResult); + } + + + //Test case 4: constructor for static AudioTrack, stereo, 16bit at misc valid sample rates + @LargeTest + public void testConstructorStereo16MusicStatic() throws Exception { + + TestResults res = constructorTestMultiSampleRate( + AudioManager.STREAM_MUSIC, AudioTrack.MODE_STATIC, + AudioFormat.CHANNEL_OUT_STEREO, AudioFormat.ENCODING_PCM_16BIT, + AudioTrack.STATE_NO_STATIC_DATA); + + assertTrue("testConstructorStereo16MusicStatic: " + res.mResultLog, res.mResult); + } + + + //----------------------------------------------------------------- + // AudioTrack constructor and AudioTrack.getMinBufferSize(...) for 8bit PCM + //---------------------------------- + + //Test case 1: constructor for streaming AudioTrack, mono, 8bit at misc valid sample rates + @LargeTest + public void testConstructorMono8MusicStream() throws Exception { + + TestResults res = constructorTestMultiSampleRate( + AudioManager.STREAM_MUSIC, AudioTrack.MODE_STREAM, + AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_8BIT, + AudioTrack.STATE_INITIALIZED); + + assertTrue("testConstructorMono8MusicStream: " + res.mResultLog, res.mResult); + } + + //Test case 2: constructor for streaming AudioTrack, stereo, 8bit at misc valid sample rates + @LargeTest + public void testConstructorStereo8MusicStream() throws Exception { + + TestResults res = constructorTestMultiSampleRate( + AudioManager.STREAM_MUSIC, AudioTrack.MODE_STREAM, + AudioFormat.CHANNEL_OUT_STEREO, AudioFormat.ENCODING_PCM_8BIT, + AudioTrack.STATE_INITIALIZED); + + assertTrue("testConstructorStereo8MusicStream: " + res.mResultLog, res.mResult); + } + + //Test case 3: constructor for static AudioTrack, mono, 8bit at misc valid sample rates + @LargeTest + public void testConstructorMono8MusicStatic() throws Exception { + + TestResults res = constructorTestMultiSampleRate( + AudioManager.STREAM_MUSIC, AudioTrack.MODE_STATIC, + AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_8BIT, + AudioTrack.STATE_NO_STATIC_DATA); + + assertTrue("testConstructorMono8MusicStatic: " + res.mResultLog, res.mResult); + } + + //Test case 4: constructor for static AudioTrack, stereo, 8bit at misc valid sample rates + @LargeTest + public void testConstructorStereo8MusicStatic() throws Exception { + + TestResults res = constructorTestMultiSampleRate( + AudioManager.STREAM_MUSIC, AudioTrack.MODE_STATIC, + AudioFormat.CHANNEL_OUT_STEREO, AudioFormat.ENCODING_PCM_8BIT, + AudioTrack.STATE_NO_STATIC_DATA); + + assertTrue("testConstructorStereo8MusicStatic: " + res.mResultLog, res.mResult); + } + + + //----------------------------------------------------------------- + // AudioTrack constructor for all stream types + //---------------------------------- + + //Test case 1: constructor for all stream types + @LargeTest + public void testConstructorStreamType() throws Exception { + // constants for test + final int TYPE_TEST_SR = 22050; + final int TYPE_TEST_CONF = AudioFormat.CHANNEL_OUT_STEREO; + final int TYPE_TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; + final int TYPE_TEST_MODE = AudioTrack.MODE_STREAM; + final int[] STREAM_TYPES = { AudioManager.STREAM_ALARM, AudioManager.STREAM_BLUETOOTH_SCO, + AudioManager.STREAM_MUSIC, AudioManager.STREAM_NOTIFICATION, + AudioManager.STREAM_RING, AudioManager.STREAM_SYSTEM, + AudioManager.STREAM_VOICE_CALL, AudioManager.STREAM_DTMF, }; + final String[] STREAM_NAMES = { "STREAM_ALARM", "STREAM_BLUETOOTH_SCO", "STREAM_MUSIC", + "STREAM_NOTIFICATION", "STREAM_RING", "STREAM_SYSTEM", "STREAM_VOICE_CALL", "STREAM_DTMF" }; + + boolean localTestRes = true; + AudioTrack track = null; + // test: loop constructor on all stream types + for (int i = 0 ; i < STREAM_TYPES.length ; i++) + { + try { + //-------- initialization -------------- + track = new AudioTrack(STREAM_TYPES[i], + TYPE_TEST_SR, TYPE_TEST_CONF, TYPE_TEST_FORMAT, + AudioTrack.getMinBufferSize(TYPE_TEST_SR, TYPE_TEST_CONF, TYPE_TEST_FORMAT), + TYPE_TEST_MODE); + } catch (IllegalArgumentException iae) { + loge("testConstructorStreamType", "exception for stream type " + + STREAM_NAMES[i] + ": "+ iae); + localTestRes = false; + } + //-------- test -------------- + if (track != null) { + if (track.getState() != AudioTrack.STATE_INITIALIZED) { + localTestRes = false; + Log.e("MediaAudioTrackTest", + "[ testConstructorStreamType ] failed for stream type "+STREAM_NAMES[i]); + } + //-------- tear down -------------- + track.release(); + } + else { + localTestRes = false; + } + } + + assertTrue("testConstructorStreamType", localTestRes); + } + + + //----------------------------------------------------------------- + // Playback head position + //---------------------------------- + + //Test case 1: getPlaybackHeadPosition() at 0 after initialization + @LargeTest + public void testPlaybackHeadPositionAfterInit() throws Exception { + // constants for test + final String TEST_NAME = "testPlaybackHeadPositionAfterInit"; + final int TEST_SR = 22050; + final int TEST_CONF = AudioFormat.CHANNEL_OUT_STEREO; + final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; + final int TEST_MODE = AudioTrack.MODE_STREAM; + final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; + + //-------- initialization -------------- + AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, + AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT), TEST_MODE); + //-------- test -------------- + assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED); + assertTrue(TEST_NAME, track.getPlaybackHeadPosition() == 0); + //-------- tear down -------------- + track.release(); + } + + //Test case 2: getPlaybackHeadPosition() increases after play() + @LargeTest + public void testPlaybackHeadPositionIncrease() throws Exception { + // constants for test + final String TEST_NAME = "testPlaybackHeadPositionIncrease"; + final int TEST_SR = 22050; + final int TEST_CONF = AudioFormat.CHANNEL_OUT_STEREO; + final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; + final int TEST_MODE = AudioTrack.MODE_STREAM; + final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; + + //-------- initialization -------------- + int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); + AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, + minBuffSize, TEST_MODE); + byte data[] = new byte[minBuffSize/2]; + //-------- test -------------- + assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED); + track.write(data, 0, data.length); + track.write(data, 0, data.length); + track.play(); + Thread.sleep(100); + log(TEST_NAME, "position ="+ track.getPlaybackHeadPosition()); + assertTrue(TEST_NAME, track.getPlaybackHeadPosition() > 0); + //-------- tear down -------------- + track.release(); + } + + //Test case 3: getPlaybackHeadPosition() is 0 after flush(); + @LargeTest + public void testPlaybackHeadPositionAfterFlush() throws Exception { + // constants for test + final String TEST_NAME = "testPlaybackHeadPositionAfterFlush"; + final int TEST_SR = 22050; + final int TEST_CONF = AudioFormat.CHANNEL_OUT_STEREO; + final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; + final int TEST_MODE = AudioTrack.MODE_STREAM; + final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; + + //-------- initialization -------------- + int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); + AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, + minBuffSize, TEST_MODE); + byte data[] = new byte[minBuffSize/2]; + //-------- test -------------- + assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED); + track.write(data, 0, data.length); + track.write(data, 0, data.length); + track.play(); + Thread.sleep(100); + track.stop(); + track.flush(); + log(TEST_NAME, "position ="+ track.getPlaybackHeadPosition()); + assertTrue(TEST_NAME, track.getPlaybackHeadPosition() == 0); + //-------- tear down -------------- + track.release(); + } + + //Test case 3: getPlaybackHeadPosition() is 0 after stop(); + @LargeTest + public void testPlaybackHeadPositionAfterStop() throws Exception { + // constants for test + final String TEST_NAME = "testPlaybackHeadPositionAfterStop"; + final int TEST_SR = 22050; + final int TEST_CONF = AudioFormat.CHANNEL_OUT_STEREO; + final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; + final int TEST_MODE = AudioTrack.MODE_STREAM; + final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; + + //-------- initialization -------------- + int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); + AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, + minBuffSize, TEST_MODE); + byte data[] = new byte[minBuffSize/2]; + //-------- test -------------- + assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED); + track.write(data, 0, data.length); + track.write(data, 0, data.length); + track.play(); + Thread.sleep(100); + track.stop(); + Thread.sleep(100); // TODO: what is a sensible value? + int pos = track.getPlaybackHeadPosition(); + log(TEST_NAME, "position ="+ pos); + assertTrue(TEST_NAME, pos == 0); + //-------- tear down -------------- + track.release(); + } + + //Test case 4: getPlaybackHeadPosition() is > 0 after play(); pause(); + @LargeTest + public void testPlaybackHeadPositionAfterPause() throws Exception { + // constants for test + final String TEST_NAME = "testPlaybackHeadPositionAfterPause"; + final int TEST_SR = 22050; + final int TEST_CONF = AudioFormat.CHANNEL_OUT_STEREO; + final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; + final int TEST_MODE = AudioTrack.MODE_STREAM; + final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; + + //-------- initialization -------------- + int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); + AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, + minBuffSize, TEST_MODE); + byte data[] = new byte[minBuffSize/2]; + //-------- test -------------- + assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED); + track.write(data, 0, data.length); + track.write(data, 0, data.length); + track.play(); + Thread.sleep(100); + track.pause(); + int pos = track.getPlaybackHeadPosition(); + log(TEST_NAME, "position ="+ pos); + assertTrue(TEST_NAME, pos > 0); + //-------- tear down -------------- + track.release(); + } + + + //----------------------------------------------------------------- + // Playback properties + //---------------------------------- + + //Test case 1: setStereoVolume() with max volume returns SUCCESS + @LargeTest + public void testSetStereoVolumeMax() throws Exception { + // constants for test + final String TEST_NAME = "testSetStereoVolumeMax"; + final int TEST_SR = 22050; + final int TEST_CONF = AudioFormat.CHANNEL_OUT_STEREO; + final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; + final int TEST_MODE = AudioTrack.MODE_STREAM; + final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; + + //-------- initialization -------------- + int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); + AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, + minBuffSize, TEST_MODE); + byte data[] = new byte[minBuffSize/2]; + //-------- test -------------- + track.write(data, 0, data.length); + track.write(data, 0, data.length); + track.play(); + float maxVol = AudioTrack.getMaxVolume(); + assertTrue(TEST_NAME, track.setStereoVolume(maxVol, maxVol) == AudioTrack.SUCCESS); + //-------- tear down -------------- + track.release(); + } + + //Test case 2: setStereoVolume() with min volume returns SUCCESS + @LargeTest + public void testSetStereoVolumeMin() throws Exception { + // constants for test + final String TEST_NAME = "testSetStereoVolumeMin"; + final int TEST_SR = 22050; + final int TEST_CONF = AudioFormat.CHANNEL_OUT_STEREO; + final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; + final int TEST_MODE = AudioTrack.MODE_STREAM; + final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; + + //-------- initialization -------------- + int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); + AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, + minBuffSize, TEST_MODE); + byte data[] = new byte[minBuffSize/2]; + //-------- test -------------- + track.write(data, 0, data.length); + track.write(data, 0, data.length); + track.play(); + float minVol = AudioTrack.getMinVolume(); + assertTrue(TEST_NAME, track.setStereoVolume(minVol, minVol) == AudioTrack.SUCCESS); + //-------- tear down -------------- + track.release(); + } + + //Test case 3: setStereoVolume() with mid volume returns SUCCESS + @LargeTest + public void testSetStereoVolumeMid() throws Exception { + // constants for test + final String TEST_NAME = "testSetStereoVolumeMid"; + final int TEST_SR = 22050; + final int TEST_CONF = AudioFormat.CHANNEL_OUT_STEREO; + final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; + final int TEST_MODE = AudioTrack.MODE_STREAM; + final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; + + //-------- initialization -------------- + int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); + AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, + minBuffSize, TEST_MODE); + byte data[] = new byte[minBuffSize/2]; + //-------- test -------------- + track.write(data, 0, data.length); + track.write(data, 0, data.length); + track.play(); + float midVol = (AudioTrack.getMaxVolume() - AudioTrack.getMinVolume()) / 2; + assertTrue(TEST_NAME, track.setStereoVolume(midVol, midVol) == AudioTrack.SUCCESS); + //-------- tear down -------------- + track.release(); + } + + //Test case 4: setPlaybackRate() with half the content rate returns SUCCESS + @LargeTest + public void testSetPlaybackRate() throws Exception { + // constants for test + final String TEST_NAME = "testSetPlaybackRate"; + final int TEST_SR = 22050; + final int TEST_CONF = AudioFormat.CHANNEL_OUT_STEREO; + final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; + final int TEST_MODE = AudioTrack.MODE_STREAM; + final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; + + //-------- initialization -------------- + int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); + AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, + minBuffSize, TEST_MODE); + byte data[] = new byte[minBuffSize/2]; + //-------- test -------------- + track.write(data, 0, data.length); + track.write(data, 0, data.length); + assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED); + track.play(); + assertTrue(TEST_NAME, track.setPlaybackRate((int)(TEST_SR/2)) == AudioTrack.SUCCESS); + //-------- tear down -------------- + track.release(); + } + + //Test case 5: setPlaybackRate(0) returns bad value error + @LargeTest + public void testSetPlaybackRateZero() throws Exception { + // constants for test + final String TEST_NAME = "testSetPlaybackRateZero"; + final int TEST_SR = 22050; + final int TEST_CONF = AudioFormat.CHANNEL_OUT_STEREO; + final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; + final int TEST_MODE = AudioTrack.MODE_STREAM; + final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; + + //-------- initialization -------------- + int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); + AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, + minBuffSize, TEST_MODE); + //-------- test -------------- + assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED); + assertTrue(TEST_NAME, track.setPlaybackRate(0) == AudioTrack.ERROR_BAD_VALUE); + //-------- tear down -------------- + track.release(); + } + + //Test case 6: setPlaybackRate() accepts values twice the output sample rate + @LargeTest + public void testSetPlaybackRateTwiceOutputSR() throws Exception { + // constants for test + final String TEST_NAME = "testSetPlaybackRateTwiceOutputSR"; + final int TEST_SR = 22050; + final int TEST_CONF = AudioFormat.CHANNEL_OUT_STEREO; + final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; + final int TEST_MODE = AudioTrack.MODE_STREAM; + final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; + + //-------- initialization -------------- + int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); + AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, + minBuffSize, TEST_MODE); + byte data[] = new byte[minBuffSize/2]; + int outputSR = AudioTrack.getNativeOutputSampleRate(TEST_STREAM_TYPE); + //-------- test -------------- + track.write(data, 0, data.length); + track.write(data, 0, data.length); + assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED); + track.play(); + assertTrue(TEST_NAME, track.setPlaybackRate(2*outputSR) == AudioTrack.SUCCESS); + //-------- tear down -------------- + track.release(); + } + + //Test case 7: setPlaybackRate() and retrieve value, should be the same for half the content SR + @LargeTest + public void testSetGetPlaybackRate() throws Exception { + // constants for test + final String TEST_NAME = "testSetGetPlaybackRate"; + final int TEST_SR = 22050; + final int TEST_CONF = AudioFormat.CHANNEL_OUT_STEREO; + final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; + final int TEST_MODE = AudioTrack.MODE_STREAM; + final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; + + //-------- initialization -------------- + int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); + AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, + minBuffSize, TEST_MODE); + byte data[] = new byte[minBuffSize/2]; + //-------- test -------------- + track.write(data, 0, data.length); + track.write(data, 0, data.length); + assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED); + track.play(); + track.setPlaybackRate((int)(TEST_SR/2)); + assertTrue(TEST_NAME, track.getPlaybackRate() == (int)(TEST_SR/2)); + //-------- tear down -------------- + track.release(); + } + + //Test case 8: setPlaybackRate() invalid operation if track not initialized + @LargeTest + public void testSetPlaybackRateUninit() throws Exception { + // constants for test + final String TEST_NAME = "testSetPlaybackRateUninit"; + final int TEST_SR = 22050; + final int TEST_CONF = AudioFormat.CHANNEL_OUT_MONO; + final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; + final int TEST_MODE = AudioTrack.MODE_STATIC; + final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; + + //-------- initialization -------------- + int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); + AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, + minBuffSize, TEST_MODE); + //-------- test -------------- + assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_NO_STATIC_DATA); + assertTrue(TEST_NAME, + track.setPlaybackRate(TEST_SR/2) == AudioTrack.ERROR_INVALID_OPERATION); + //-------- tear down -------------- + track.release(); + } + + //----------------------------------------------------------------- + // Playback progress + //---------------------------------- + + //Test case 1: setPlaybackHeadPosition() on playing track + @LargeTest + public void testSetPlaybackHeadPositionPlaying() throws Exception { + // constants for test + final String TEST_NAME = "testSetPlaybackHeadPositionPlaying"; + final int TEST_SR = 22050; + final int TEST_CONF = AudioFormat.CHANNEL_OUT_MONO; + final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; + final int TEST_MODE = AudioTrack.MODE_STREAM; + final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; + + //-------- initialization -------------- + int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); + AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, + 2*minBuffSize, TEST_MODE); + byte data[] = new byte[minBuffSize]; + //-------- test -------------- + assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED); + track.write(data, 0, data.length); + track.write(data, 0, data.length); + track.play(); + assertTrue(TEST_NAME, + track.setPlaybackHeadPosition(10) == AudioTrack.ERROR_INVALID_OPERATION); + //-------- tear down -------------- + track.release(); + } + + //Test case 2: setPlaybackHeadPosition() on stopped track + @LargeTest + public void testSetPlaybackHeadPositionStopped() throws Exception { + // constants for test + final String TEST_NAME = "testSetPlaybackHeadPositionStopped"; + final int TEST_SR = 22050; + final int TEST_CONF = AudioFormat.CHANNEL_OUT_MONO; + final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; + final int TEST_MODE = AudioTrack.MODE_STREAM; + final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; + + //-------- initialization -------------- + int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); + AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, + 2*minBuffSize, TEST_MODE); + byte data[] = new byte[minBuffSize]; + //-------- test -------------- + assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED); + track.write(data, 0, data.length); + track.write(data, 0, data.length); + track.play(); + track.stop(); + assumeTrue(TEST_NAME, track.getPlayState() == AudioTrack.PLAYSTATE_STOPPED); + assertTrue(TEST_NAME, track.setPlaybackHeadPosition(10) == AudioTrack.SUCCESS); + //-------- tear down -------------- + track.release(); + } + + //Test case 3: setPlaybackHeadPosition() on paused track + @LargeTest + public void testSetPlaybackHeadPositionPaused() throws Exception { + // constants for test + final String TEST_NAME = "testSetPlaybackHeadPositionPaused"; + final int TEST_SR = 22050; + final int TEST_CONF = AudioFormat.CHANNEL_OUT_MONO; + final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; + final int TEST_MODE = AudioTrack.MODE_STREAM; + final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; + + //-------- initialization -------------- + int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); + AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, + 2*minBuffSize, TEST_MODE); + byte data[] = new byte[minBuffSize]; + //-------- test -------------- + assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED); + track.write(data, 0, data.length); + track.write(data, 0, data.length); + track.play(); + track.pause(); + assumeTrue(TEST_NAME, track.getPlayState() == AudioTrack.PLAYSTATE_PAUSED); + assertTrue(TEST_NAME, track.setPlaybackHeadPosition(10) == AudioTrack.SUCCESS); + //-------- tear down -------------- + track.release(); + } + + //Test case 4: setPlaybackHeadPosition() beyond what has been written + @LargeTest + public void testSetPlaybackHeadPositionTooFar() throws Exception { + // constants for test + final String TEST_NAME = "testSetPlaybackHeadPositionTooFar"; + final int TEST_SR = 22050; + final int TEST_CONF = AudioFormat.CHANNEL_OUT_MONO; + final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; + final int TEST_MODE = AudioTrack.MODE_STREAM; + final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; + + //-------- initialization -------------- + int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); + AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, + 2*minBuffSize, TEST_MODE); + byte data[] = new byte[minBuffSize]; + // make up a frame index that's beyond what has been written: go from buffer size to frame + // count (given the audio track properties), and add 77. + int frameIndexTooFar = (2*minBuffSize/2) + 77; + //-------- test -------------- + assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED); + track.write(data, 0, data.length); + track.write(data, 0, data.length); + track.play(); + track.stop(); + assumeTrue(TEST_NAME, track.getPlayState() == AudioTrack.PLAYSTATE_STOPPED); + assertTrue(TEST_NAME, track.setPlaybackHeadPosition(frameIndexTooFar) == AudioTrack.ERROR_BAD_VALUE); + //-------- tear down -------------- + track.release(); + } + + + //Test case 5: setLoopPoints() fails for MODE_STREAM + @LargeTest + public void testSetLoopPointsStream() throws Exception { + // constants for test + final String TEST_NAME = "testSetLoopPointsStream"; + final int TEST_SR = 22050; + final int TEST_CONF = AudioFormat.CHANNEL_OUT_MONO; + final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; + final int TEST_MODE = AudioTrack.MODE_STREAM; + final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; + + //-------- initialization -------------- + int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); + AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, + 2*minBuffSize, TEST_MODE); + byte data[] = new byte[minBuffSize]; + //-------- test -------------- + track.write(data, 0, data.length); + assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED); + assertTrue(TEST_NAME, track.setLoopPoints(2, 50, 2) == AudioTrack.ERROR_INVALID_OPERATION); + //-------- tear down -------------- + track.release(); + } + + //Test case 6: setLoopPoints() fails start > end + @LargeTest + public void testSetLoopPointsStartAfterEnd() throws Exception { + // constants for test + final String TEST_NAME = "testSetLoopPointsStartAfterEnd"; + final int TEST_SR = 22050; + final int TEST_CONF = AudioFormat.CHANNEL_OUT_MONO; + final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; + final int TEST_MODE = AudioTrack.MODE_STATIC; + final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; + + //-------- initialization -------------- + int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); + AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, + minBuffSize, TEST_MODE); + byte data[] = new byte[minBuffSize]; + //-------- test -------------- + track.write(data, 0, data.length); + assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED); + assertTrue(TEST_NAME, track.setLoopPoints(50, 0, 2) == AudioTrack.ERROR_BAD_VALUE); + //-------- tear down -------------- + track.release(); + } + + //Test case 6: setLoopPoints() success + @LargeTest + public void testSetLoopPointsSuccess() throws Exception { + // constants for test + final String TEST_NAME = "testSetLoopPointsSuccess"; + final int TEST_SR = 22050; + final int TEST_CONF = AudioFormat.CHANNEL_OUT_MONO; + final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; + final int TEST_MODE = AudioTrack.MODE_STATIC; + final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; + + //-------- initialization -------------- + int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); + AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, + minBuffSize, TEST_MODE); + byte data[] = new byte[minBuffSize]; + //-------- test -------------- + track.write(data, 0, data.length); + assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED); + assertTrue(TEST_NAME, track.setLoopPoints(0, 50, 2) == AudioTrack.SUCCESS); + //-------- tear down -------------- + track.release(); + } + + //Test case 7: setLoopPoints() fails with loop length bigger than content + @LargeTest + public void testSetLoopPointsLoopTooLong() throws Exception { + // constants for test + final String TEST_NAME = "testSetLoopPointsLoopTooLong"; + final int TEST_SR = 22050; + final int TEST_CONF = AudioFormat.CHANNEL_OUT_MONO; + final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; + final int TEST_MODE = AudioTrack.MODE_STATIC; + final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; + + //-------- initialization -------------- + int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); + AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, + minBuffSize, TEST_MODE); + byte data[] = new byte[minBuffSize]; + int dataSizeInFrames = minBuffSize/2; + //-------- test -------------- + assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_NO_STATIC_DATA); + track.write(data, 0, data.length); + assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED); + assertTrue(TEST_NAME, + track.setLoopPoints(10, dataSizeInFrames+20, 2) == AudioTrack.ERROR_BAD_VALUE); + //-------- tear down -------------- + track.release(); + } + //Test case 8: setLoopPoints() fails with start beyond what can be written for the track + @LargeTest + public void testSetLoopPointsStartTooFar() throws Exception { + // constants for test + final String TEST_NAME = "testSetLoopPointsStartTooFar"; + final int TEST_SR = 22050; + final int TEST_CONF = AudioFormat.CHANNEL_OUT_MONO; + final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; + final int TEST_MODE = AudioTrack.MODE_STATIC; + final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; + + //-------- initialization -------------- + int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); + AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, + minBuffSize, TEST_MODE); + byte data[] = new byte[minBuffSize]; + int dataSizeInFrames = minBuffSize/2;//16bit data + //-------- test -------------- + assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_NO_STATIC_DATA); + track.write(data, 0, data.length); + assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED); + assertTrue(TEST_NAME, + track.setLoopPoints(dataSizeInFrames+20, dataSizeInFrames+50, 2) + == AudioTrack.ERROR_BAD_VALUE); + //-------- tear down -------------- + track.release(); + } + + //Test case 9: setLoopPoints() fails with end beyond what can be written for the track + @LargeTest + public void testSetLoopPointsEndTooFar() throws Exception { + // constants for test + final String TEST_NAME = "testSetLoopPointsEndTooFar"; + final int TEST_SR = 22050; + final int TEST_CONF = AudioFormat.CHANNEL_OUT_MONO; + final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; + final int TEST_MODE = AudioTrack.MODE_STATIC; + final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; + + //-------- initialization -------------- + int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); + AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, + minBuffSize, TEST_MODE); + byte data[] = new byte[minBuffSize]; + int dataSizeInFrames = minBuffSize/2;//16bit data + //-------- test -------------- + assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_NO_STATIC_DATA); + track.write(data, 0, data.length); + assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED); + assertTrue(TEST_NAME, + track.setLoopPoints(dataSizeInFrames-10, dataSizeInFrames+50, 2) + == AudioTrack.ERROR_BAD_VALUE); + //-------- tear down -------------- + track.release(); + } + + + //----------------------------------------------------------------- + // Audio data supply + //---------------------------------- + + //Test case 1: write() fails when supplying less data (bytes) than declared + @LargeTest + public void testWriteByteOffsetTooBig() throws Exception { + // constants for test + final String TEST_NAME = "testWriteByteOffsetTooBig"; + final int TEST_SR = 22050; + final int TEST_CONF = AudioFormat.CHANNEL_OUT_MONO; + final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; + final int TEST_MODE = AudioTrack.MODE_STREAM; + final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; + + //-------- initialization -------------- + int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); + AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, + 2*minBuffSize, TEST_MODE); + byte data[] = new byte[minBuffSize]; + //-------- test -------------- + assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED); + assertTrue(TEST_NAME, + track.write(data, 10, data.length) == AudioTrack.ERROR_BAD_VALUE); + //-------- tear down -------------- + track.release(); + } + + //Test case 2: write() fails when supplying less data (shorts) than declared + @LargeTest + public void testWriteShortOffsetTooBig() throws Exception { + // constants for test + final String TEST_NAME = "testWriteShortOffsetTooBig"; + final int TEST_SR = 22050; + final int TEST_CONF = AudioFormat.CHANNEL_OUT_MONO; + final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; + final int TEST_MODE = AudioTrack.MODE_STREAM; + final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; + + //-------- initialization -------------- + int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); + AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, + 2*minBuffSize, TEST_MODE); + short data[] = new short[minBuffSize/2]; + //-------- test -------------- + assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED); + assertTrue(TEST_NAME, + track.write(data, 10, data.length) == AudioTrack.ERROR_BAD_VALUE); + //-------- tear down -------------- + track.release(); + } + + //Test case 3: write() fails when supplying less data (bytes) than declared + @LargeTest + public void testWriteByteSizeTooBig() throws Exception { + // constants for test + final String TEST_NAME = "testWriteByteSizeTooBig"; + final int TEST_SR = 22050; + final int TEST_CONF = AudioFormat.CHANNEL_OUT_MONO; + final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; + final int TEST_MODE = AudioTrack.MODE_STREAM; + final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; + + //-------- initialization -------------- + int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); + AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, + 2*minBuffSize, TEST_MODE); + byte data[] = new byte[minBuffSize]; + //-------- test -------------- + assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED); + assertTrue(TEST_NAME, + track.write(data, 0, data.length + 10) == AudioTrack.ERROR_BAD_VALUE); + //-------- tear down -------------- + track.release(); + } + + //Test case 4: write() fails when supplying less data (shorts) than declared + @LargeTest + public void testWriteShortSizeTooBig() throws Exception { + // constants for test + final String TEST_NAME = "testWriteShortSizeTooBig"; + final int TEST_SR = 22050; + final int TEST_CONF = AudioFormat.CHANNEL_OUT_MONO; + final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; + final int TEST_MODE = AudioTrack.MODE_STREAM; + final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; + + //-------- initialization -------------- + int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); + AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, + 2*minBuffSize, TEST_MODE); + short data[] = new short[minBuffSize/2]; + //-------- test -------------- + assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED); + assertTrue(TEST_NAME, + track.write(data, 0, data.length + 10) == AudioTrack.ERROR_BAD_VALUE); + //-------- tear down -------------- + track.release(); + } + + //Test case 5: write() fails with negative offset + @LargeTest + public void testWriteByteNegativeOffset() throws Exception { + // constants for test + final String TEST_NAME = "testWriteByteNegativeOffset"; + final int TEST_SR = 22050; + final int TEST_CONF = AudioFormat.CHANNEL_OUT_MONO; + final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; + final int TEST_MODE = AudioTrack.MODE_STREAM; + final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; + + //-------- initialization -------------- + int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); + AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, + 2*minBuffSize, TEST_MODE); + byte data[] = new byte[minBuffSize]; + //-------- test -------------- + assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED); + assertTrue(TEST_NAME, + track.write(data, -10, data.length - 10) == AudioTrack.ERROR_BAD_VALUE); + //-------- tear down -------------- + track.release(); + } + + //Test case 6: write() fails with negative offset + @LargeTest + public void testWriteShortNegativeOffset() throws Exception { + // constants for test + final String TEST_NAME = "testWriteShortNegativeOffset"; + final int TEST_SR = 22050; + final int TEST_CONF = AudioFormat.CHANNEL_OUT_MONO; + final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; + final int TEST_MODE = AudioTrack.MODE_STREAM; + final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; + + //-------- initialization -------------- + int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); + AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, + 2*minBuffSize, TEST_MODE); + short data[] = new short[minBuffSize/2]; + //-------- test -------------- + assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED); + assertTrue(TEST_NAME, + track.write(data, -10, data.length - 10) == AudioTrack.ERROR_BAD_VALUE); + //-------- tear down -------------- + track.release(); + } + + //Test case 7: write() fails with negative size + @LargeTest + public void testWriteByteNegativeSize() throws Exception { + // constants for test + final String TEST_NAME = "testWriteByteNegativeSize"; + final int TEST_SR = 22050; + final int TEST_CONF = AudioFormat.CHANNEL_OUT_MONO; + final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; + final int TEST_MODE = AudioTrack.MODE_STREAM; + final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; + + //-------- initialization -------------- + int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); + AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, + 2*minBuffSize, TEST_MODE); + byte data[] = new byte[minBuffSize]; + //-------- test -------------- + assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED); + assertTrue(TEST_NAME, + track.write(data, 0, -10) == AudioTrack.ERROR_BAD_VALUE); + //-------- tear down -------------- + track.release(); + } + + //Test case 8: write() fails with negative size + @LargeTest + public void testWriteShortNegativeSize() throws Exception { + // constants for test + final String TEST_NAME = "testWriteShortNegativeSize"; + final int TEST_SR = 22050; + final int TEST_CONF = AudioFormat.CHANNEL_OUT_MONO; + final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; + final int TEST_MODE = AudioTrack.MODE_STREAM; + final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; + + //-------- initialization -------------- + int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); + AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, + 2*minBuffSize, TEST_MODE); + short data[] = new short[minBuffSize/2]; + //-------- test -------------- + assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED); + assertTrue(TEST_NAME, + track.write(data, 0, -10) == AudioTrack.ERROR_BAD_VALUE); + //-------- tear down -------------- + track.release(); + } + + //Test case 9: write() succeeds and returns the size that was written for 16bit + @LargeTest + public void testWriteByte() throws Exception { + // constants for test + final String TEST_NAME = "testWriteByte"; + final int TEST_SR = 22050; + final int TEST_CONF = AudioFormat.CHANNEL_OUT_MONO; + final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; + final int TEST_MODE = AudioTrack.MODE_STREAM; + final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; + + //-------- initialization -------------- + int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); + AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, + 2*minBuffSize, TEST_MODE); + byte data[] = new byte[minBuffSize]; + //-------- test -------------- + assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED); + assertTrue(TEST_NAME, + track.write(data, 0, data.length) == data.length); + //-------- tear down -------------- + track.release(); + } + + //Test case 10: write() succeeds and returns the size that was written for 16bit + @LargeTest + public void testWriteShort() throws Exception { + // constants for test + final String TEST_NAME = "testWriteShort"; + final int TEST_SR = 22050; + final int TEST_CONF = AudioFormat.CHANNEL_OUT_MONO; + final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; + final int TEST_MODE = AudioTrack.MODE_STREAM; + final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; + + //-------- initialization -------------- + int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); + AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, + 2*minBuffSize, TEST_MODE); + short data[] = new short[minBuffSize/2]; + //-------- test -------------- + assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED); + assertTrue(TEST_NAME, + track.write(data, 0, data.length) == data.length); + //-------- tear down -------------- + track.release(); + } + + //Test case 11: write() succeeds and returns the size that was written for 8bit + @LargeTest + public void testWriteByte8bit() throws Exception { + // constants for test + final String TEST_NAME = "testWriteByte8bit"; + final int TEST_SR = 22050; + final int TEST_CONF = AudioFormat.CHANNEL_OUT_MONO; + final int TEST_FORMAT = AudioFormat.ENCODING_PCM_8BIT; + final int TEST_MODE = AudioTrack.MODE_STREAM; + final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; + + //-------- initialization -------------- + int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); + AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, + 2*minBuffSize, TEST_MODE); + byte data[] = new byte[minBuffSize]; + //-------- test -------------- + assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED); + assertTrue(TEST_NAME, + track.write(data, 0, data.length) == data.length); + //-------- tear down -------------- + track.release(); + } + + //Test case 12: write() succeeds and returns the size that was written for 8bit + @LargeTest + public void testWriteShort8bit() throws Exception { + // constants for test + final String TEST_NAME = "testWriteShort8bit"; + final int TEST_SR = 22050; + final int TEST_CONF = AudioFormat.CHANNEL_OUT_MONO; + final int TEST_FORMAT = AudioFormat.ENCODING_PCM_8BIT; + final int TEST_MODE = AudioTrack.MODE_STREAM; + final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; + + //-------- initialization -------------- + int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); + AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, + 2*minBuffSize, TEST_MODE); + short data[] = new short[minBuffSize/2]; + //-------- test -------------- + assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED); + assertTrue(TEST_NAME, + track.write(data, 0, data.length) == data.length); + //-------- tear down -------------- + track.release(); + } + + //----------------------------------------------------------------- + // Getters + //---------------------------------- + + //Test case 1: getMinBufferSize() return ERROR_BAD_VALUE if SR < 4000 + @LargeTest + public void testGetMinBufferSizeTooLowSR() throws Exception { + // constant for test + final String TEST_NAME = "testGetMinBufferSizeTooLowSR"; + final int TEST_SR = 3999; + final int TEST_CONF = AudioFormat.CHANNEL_OUT_MONO; + final int TEST_FORMAT = AudioFormat.ENCODING_PCM_8BIT; + final int TEST_MODE = AudioTrack.MODE_STREAM; + final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; + + //-------- initialization & test -------------- + assertTrue(TEST_NAME, + AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT) + == AudioTrack.ERROR_BAD_VALUE); + } + + //Test case 2: getMinBufferSize() return ERROR_BAD_VALUE if SR > 48000 + @LargeTest + public void testGetMinBufferSizeTooHighSR() throws Exception { + // constant for testg + final String TEST_NAME = "testGetMinBufferSizeTooHighSR"; + final int TEST_SR = 48001; + final int TEST_CONF = AudioFormat.CHANNEL_OUT_MONO; + final int TEST_FORMAT = AudioFormat.ENCODING_PCM_8BIT; + final int TEST_MODE = AudioTrack.MODE_STREAM; + final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; + + //-------- initialization & test -------------- + assertTrue(TEST_NAME, + AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT) + == AudioTrack.ERROR_BAD_VALUE); + } + +} diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/MediaBassBoostTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/MediaBassBoostTest.java new file mode 100644 index 0000000..6dbc8f2 --- /dev/null +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/MediaBassBoostTest.java @@ -0,0 +1,289 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.mediaframeworktest.functional.audio; + +import com.android.mediaframeworktest.MediaFrameworkTest; +import com.android.mediaframeworktest.MediaNames; +import com.android.mediaframeworktest.functional.EnergyProbe; +import android.content.Context; +import android.content.res.AssetFileDescriptor; +import android.media.audiofx.AudioEffect; +import android.media.AudioManager; +import android.media.audiofx.BassBoost; +import android.media.audiofx.Visualizer; +import android.media.MediaPlayer; + +import android.os.Looper; +import android.test.suitebuilder.annotation.LargeTest; +import android.test.suitebuilder.annotation.MediumTest; +import android.test.suitebuilder.annotation.Suppress; +import android.test.ActivityInstrumentationTestCase2; +import android.util.Log; + +import java.nio.ByteOrder; +import java.nio.ByteBuffer; +import java.util.UUID; + +/** + * Junit / Instrumentation test case for the media AudioTrack api + + */ +public class MediaBassBoostTest extends ActivityInstrumentationTestCase2 { + private String TAG = "MediaBassBoostTest"; + private final static int MIN_ENERGY_RATIO_2 = 3; + private final static short TEST_STRENGTH = 500; + private final static int TEST_VOLUME = 4; + + private BassBoost mBassBoost = null; + private int mSession = -1; + + public MediaBassBoostTest() { + super("com.android.mediaframeworktest", MediaFrameworkTest.class); + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + } + + @Override + protected void tearDown() throws Exception { + super.tearDown(); + releaseBassBoost(); + } + + private static void assumeTrue(String message, boolean cond) { + assertTrue("(assume)"+message, cond); + } + + private void log(String testName, String message) { + Log.v(TAG, "["+testName+"] "+message); + } + + private void loge(String testName, String message) { + Log.e(TAG, "["+testName+"] "+message); + } + + //----------------------------------------------------------------- + // BASS BOOST TESTS: + //---------------------------------- + + + //----------------------------------------------------------------- + // 0 - constructor + //---------------------------------- + + //Test case 0.0: test constructor and release + @LargeTest + public void test0_0ConstructorAndRelease() throws Exception { + boolean result = false; + String msg = "test1_0ConstructorAndRelease()"; + BassBoost bb = null; + try { + bb = new BassBoost(0, 0); + assertNotNull(msg + ": could not create BassBoost", bb); + try { + assertTrue(msg +": invalid effect ID", (bb.getId() != 0)); + } catch (IllegalStateException e) { + msg = msg.concat(": BassBoost not initialized"); + } + result = true; + } catch (IllegalArgumentException e) { + msg = msg.concat(": BassBoost not found"); + } catch (UnsupportedOperationException e) { + msg = msg.concat(": Effect library not loaded"); + } finally { + if (bb != null) { + bb.release(); + } + } + assertTrue(msg, result); + } + + //----------------------------------------------------------------- + // 1 - get/set parameters + //---------------------------------- + + //Test case 1.0: test strength + @LargeTest + public void test1_0Strength() throws Exception { + boolean result = false; + String msg = "test1_0Strength()"; + getBassBoost(0); + try { + if (mBassBoost.getStrengthSupported()) { + mBassBoost.setStrength((short)TEST_STRENGTH); + short strength = mBassBoost.getRoundedStrength(); + // allow 10% difference between set strength and rounded strength + assertTrue(msg +": got incorrect strength", + ((float)strength > (float)TEST_STRENGTH * 0.9f) && + ((float)strength < (float)TEST_STRENGTH * 1.1f)); + } else { + short strength = mBassBoost.getRoundedStrength(); + assertTrue(msg +": got incorrect strength", strength >= 0 && strength <= 1000); + } + result = true; + } catch (IllegalArgumentException e) { + msg = msg.concat(": Bad parameter value"); + loge(msg, "Bad parameter value"); + } catch (UnsupportedOperationException e) { + msg = msg.concat(": get parameter() rejected"); + loge(msg, "get parameter() rejected"); + } catch (IllegalStateException e) { + msg = msg.concat("get parameter() called in wrong state"); + loge(msg, "get parameter() called in wrong state"); + } finally { + releaseBassBoost(); + } + assertTrue(msg, result); + } + + //Test case 1.1: test properties + @LargeTest + public void test1_1Properties() throws Exception { + boolean result = false; + String msg = "test1_1Properties()"; + getBassBoost(0); + try { + BassBoost.Settings settings = mBassBoost.getProperties(); + String str = settings.toString(); + settings = new BassBoost.Settings(str); + mBassBoost.setProperties(settings); + result = true; + } catch (IllegalArgumentException e) { + msg = msg.concat(": Bad parameter value"); + loge(msg, "Bad parameter value"); + } catch (UnsupportedOperationException e) { + msg = msg.concat(": get parameter() rejected"); + loge(msg, "get parameter() rejected"); + } catch (IllegalStateException e) { + msg = msg.concat("get parameter() called in wrong state"); + loge(msg, "get parameter() called in wrong state"); + } finally { + releaseBassBoost(); + } + assertTrue(msg, result); + } + + //----------------------------------------------------------------- + // 2 - Effect action + //---------------------------------- + + //Test case 2.0: test actual bass boost influence on sound + @LargeTest + public void test2_0SoundModification() throws Exception { + boolean result = false; + String msg = "test2_0SoundModification()"; + EnergyProbe probe = null; + AudioEffect vc = null; + MediaPlayer mp = null; + AudioManager am = (AudioManager) getActivity().getSystemService(Context.AUDIO_SERVICE); + int volume = am.getStreamMaxVolume(AudioManager.STREAM_MUSIC); + am.setStreamVolume(AudioManager.STREAM_MUSIC, + TEST_VOLUME, + 0); + + try { + probe = new EnergyProbe(0); + // 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, + UUID.fromString("119341a0-8469-11df-81f9-0002a5d5c51b"), + 0, + 0); + vc.setEnabled(true); + + mp = new MediaPlayer(); + mp.setDataSource(MediaNames.SINE_200_1000); + mp.setAudioStreamType(AudioManager.STREAM_MUSIC); + getBassBoost(mp.getAudioSessionId()); + mp.prepare(); + mp.start(); + Thread.sleep(200); + // measure reference energy around 1kHz + int refEnergy200 = probe.capture(200); + int refEnergy1000 = probe.capture(1000); + mBassBoost.setStrength((short)1000); + mBassBoost.setEnabled(true); + Thread.sleep(500); + // measure energy around 1kHz with band level at min + int energy200 = probe.capture(200); + int energy1000 = probe.capture(1000); + // verify that the energy ration between low and high frequencies is at least + // MIN_ENERGY_RATIO_2 times higher with bassboost on. + assertTrue(msg + ": bass boost has no effect", + ((float)energy200/(float)energy1000) > + (MIN_ENERGY_RATIO_2 * ((float)refEnergy200/(float)refEnergy1000))); + result = true; + } catch (IllegalArgumentException e) { + msg = msg.concat(": Bad parameter value"); + loge(msg, "Bad parameter value"); + } catch (UnsupportedOperationException e) { + msg = msg.concat(": get parameter() rejected"); + loge(msg, "get parameter() rejected"); + } catch (IllegalStateException e) { + msg = msg.concat("get parameter() called in wrong state"); + loge(msg, "get parameter() called in wrong state"); + } catch (InterruptedException e) { + loge(msg, "sleep() interrupted"); + } + finally { + releaseBassBoost(); + if (mp != null) { + mp.release(); + } + if (vc != null) { + vc.release(); + } + if (probe != null) { + probe.release(); + } + am.setStreamVolume(AudioManager.STREAM_MUSIC, volume, 0); + } + assertTrue(msg, result); + } + //----------------------------------------------------------------- + // private methods + //---------------------------------- + + private void getBassBoost(int session) { + if (mBassBoost == null || session != mSession) { + if (session != mSession && mBassBoost != null) { + mBassBoost.release(); + mBassBoost = null; + } + try { + mBassBoost = new BassBoost(0, session); + mSession = session; + } catch (IllegalArgumentException e) { + Log.e(TAG, "getBassBoost() BassBoost not found exception: "+e); + } catch (UnsupportedOperationException e) { + Log.e(TAG, "getBassBoost() Effect library not loaded exception: "+e); + } + } + assertNotNull("could not create mBassBoost", mBassBoost); + } + + private void releaseBassBoost() { + if (mBassBoost != null) { + mBassBoost.release(); + mBassBoost = null; + } + } + +} diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/MediaEnvReverbTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/MediaEnvReverbTest.java new file mode 100644 index 0000000..2c0124f --- /dev/null +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/MediaEnvReverbTest.java @@ -0,0 +1,523 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.mediaframeworktest.functional.audio; + +import com.android.mediaframeworktest.MediaFrameworkTest; +import com.android.mediaframeworktest.MediaNames; +import com.android.mediaframeworktest.functional.EnergyProbe; +import android.content.Context; +import android.content.res.AssetFileDescriptor; +import android.media.audiofx.AudioEffect; +import android.media.AudioManager; +import android.media.audiofx.EnvironmentalReverb; +import android.media.audiofx.Visualizer; +import android.media.MediaPlayer; + +import android.os.Looper; +import android.test.suitebuilder.annotation.LargeTest; +import android.test.suitebuilder.annotation.MediumTest; +import android.test.suitebuilder.annotation.Suppress; +import android.test.ActivityInstrumentationTestCase2; +import android.util.Log; + +import java.nio.ByteOrder; +import java.nio.ByteBuffer; +import java.util.UUID; + +/** + * Junit / Instrumentation test case for the media AudioTrack api + + */ +public class MediaEnvReverbTest extends ActivityInstrumentationTestCase2 { + private String TAG = "MediaEnvReverbTest"; + // allow +/- 100 millibel difference between set and get gains + private final static int MILLIBEL_TOLERANCE = 100; + // allow +/- 5% tolerance between set and get delays + private final static float DELAY_TOLERANCE = 1.05f; + // allow +/- 5% tolerance between set and get ratios + private final static float RATIO_TOLERANCE = 1.05f; + + private EnvironmentalReverb mReverb = null; + private int mSession = -1; + + public MediaEnvReverbTest() { + super("com.android.mediaframeworktest", MediaFrameworkTest.class); + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + } + + @Override + protected void tearDown() throws Exception { + super.tearDown(); + releaseReverb(); + } + + private static void assumeTrue(String message, boolean cond) { + assertTrue("(assume)"+message, cond); + } + + private void log(String testName, String message) { + Log.v(TAG, "["+testName+"] "+message); + } + + private void loge(String testName, String message) { + Log.e(TAG, "["+testName+"] "+message); + } + + //----------------------------------------------------------------- + // ENVIRONMENTAL REVEB TESTS: + //---------------------------------- + + + //----------------------------------------------------------------- + // 0 - constructor + //---------------------------------- + + //Test case 0.0: test constructor and release + @LargeTest + public void test0_0ConstructorAndRelease() throws Exception { + boolean result = false; + String msg = "test1_0ConstructorAndRelease()"; + EnvironmentalReverb reverb = null; + try { + reverb = new EnvironmentalReverb(0, 0); + assertNotNull(msg + ": could not create EnvironmentalReverb", reverb); + try { + assertTrue(msg +": invalid effect ID", (reverb.getId() != 0)); + } catch (IllegalStateException e) { + msg = msg.concat(": EnvironmentalReverb not initialized"); + } + result = true; + } catch (IllegalArgumentException e) { + msg = msg.concat(": EnvironmentalReverb not found"); + } catch (UnsupportedOperationException e) { + msg = msg.concat(": Effect library not loaded"); + } finally { + if (reverb != null) { + reverb.release(); + } + } + assertTrue(msg, result); + } + + //----------------------------------------------------------------- + // 1 - get/set parameters + //---------------------------------- + + //Test case 1.0: test room level and room HF level + @LargeTest + public void test1_0Room() throws Exception { + boolean result = false; + String msg = "test1_0Room()"; + getReverb(0); + try { + mReverb.setRoomLevel((short)0); + short level = mReverb.getRoomLevel(); + assertTrue(msg +": got incorrect room level", + (level > (0 - MILLIBEL_TOLERANCE)) && + (level < (0 + MILLIBEL_TOLERANCE))); + + mReverb.setRoomHFLevel((short)-6); + level = mReverb.getRoomHFLevel(); + assertTrue(msg +": got incorrect room HF level", + (level > (-6 - MILLIBEL_TOLERANCE)) && + (level < (-6 + MILLIBEL_TOLERANCE))); + + result = true; + } catch (IllegalArgumentException e) { + msg = msg.concat(": Bad parameter value"); + loge(msg, "Bad parameter value"); + } catch (UnsupportedOperationException e) { + msg = msg.concat(": get parameter() rejected"); + loge(msg, "get parameter() rejected"); + } catch (IllegalStateException e) { + msg = msg.concat("get parameter() called in wrong state"); + loge(msg, "get parameter() called in wrong state"); + } finally { + releaseReverb(); + } + assertTrue(msg, result); + } + + //Test case 1.1: test decay time and ratio + @LargeTest + public void test1_1Decay() throws Exception { + boolean result = false; + String msg = "test1_1Decay()"; + getReverb(0); + try { + mReverb.setDecayTime(500); + int time = mReverb.getDecayTime(); + assertTrue(msg +": got incorrect decay time", + ((float)time > (float)(500 / DELAY_TOLERANCE)) && + ((float)time < (float)(500 * DELAY_TOLERANCE))); + + mReverb.setDecayHFRatio((short)1000); + short ratio = mReverb.getDecayHFRatio(); + assertTrue(msg +": got incorrect decay HF ratio", + ((float)ratio > (float)(1000 / RATIO_TOLERANCE)) && + ((float)ratio < (float)(1000 * RATIO_TOLERANCE))); + + result = true; + } catch (IllegalArgumentException e) { + msg = msg.concat(": Bad parameter value"); + loge(msg, "Bad parameter value"); + } catch (UnsupportedOperationException e) { + msg = msg.concat(": get parameter() rejected"); + loge(msg, "get parameter() rejected"); + } catch (IllegalStateException e) { + msg = msg.concat("get parameter() called in wrong state"); + loge(msg, "get parameter() called in wrong state"); + } finally { + releaseReverb(); + } + assertTrue(msg, result); + } + + //Test case 1.2: test reflections + @LargeTest + public void test1_2Reflections() throws Exception { + // TODO: uncomment when early reflections are implemented +// boolean result = false; +// String msg = "test1_2Reflections()"; +// getReverb(0); +// try { +// mReverb.setReflectionsLevel((short)0); +// short level = mReverb.getReflectionsLevel(); +// assertTrue(msg +": got incorrect reflections level", +// (level > (0 - MILLIBEL_TOLERANCE)) && +// (level < (0 + MILLIBEL_TOLERANCE))); +// +// mReverb.setReflectionsDelay(30); +// int delay = mReverb.getReflectionsDelay(); +// assertTrue(msg +": got incorrect reflections delay", +// ((float)delay > (float)(30 / DELAY_TOLERANCE)) && +// ((float)delay < (float)(30 * DELAY_TOLERANCE))); +// +// result = true; +// } catch (IllegalArgumentException e) { +// msg = msg.concat(": Bad parameter value"); +// loge(msg, "Bad parameter value"); +// } catch (UnsupportedOperationException e) { +// msg = msg.concat(": get parameter() rejected"); +// loge(msg, "get parameter() rejected"); +// } catch (IllegalStateException e) { +// msg = msg.concat("get parameter() called in wrong state"); +// loge(msg, "get parameter() called in wrong state"); +// } finally { +// releaseReverb(); +// } +// assertTrue(msg, result); + } + + //Test case 1.3: test reverb + @LargeTest + public void test1_3Reverb() throws Exception { + boolean result = false; + String msg = "test1_3Reverb()"; + getReverb(0); + try { + mReverb.setReverbLevel((short)0); + short level = mReverb.getReverbLevel(); + assertTrue(msg +": got incorrect reverb level", + (level > (0 - MILLIBEL_TOLERANCE)) && + (level < (0 + MILLIBEL_TOLERANCE))); + + // TODO: change delay when early reflections are implemented + mReverb.setReverbDelay(0); + int delay = mReverb.getReverbDelay(); + assertTrue(msg +": got incorrect reverb delay", delay < 5); + + result = true; + } catch (IllegalArgumentException e) { + msg = msg.concat(": Bad parameter value"); + loge(msg, "Bad parameter value"); + } catch (UnsupportedOperationException e) { + msg = msg.concat(": get parameter() rejected"); + loge(msg, "get parameter() rejected"); + } catch (IllegalStateException e) { + msg = msg.concat("get parameter() called in wrong state"); + loge(msg, "get parameter() called in wrong state"); + } finally { + releaseReverb(); + } + assertTrue(msg, result); + } + + //Test case 1.4: test diffusion and density + @LargeTest + public void test1_4DiffusionAndDensity() throws Exception { + boolean result = false; + String msg = "test1_4DiffusionAndDensity()"; + getReverb(0); + try { + mReverb.setDiffusion((short)500); + short diffusion = mReverb.getDiffusion(); + assertTrue(msg +": got incorrect diffusion", + ((float)diffusion > (float)(500 / RATIO_TOLERANCE)) && + ((float)diffusion < (float)(500 * RATIO_TOLERANCE))); + + mReverb.setDensity((short)500); + short density = mReverb.getDensity(); + assertTrue(msg +": got incorrect density", + ((float)density > (float)(500 / RATIO_TOLERANCE)) && + ((float)density < (float)(500 * RATIO_TOLERANCE))); + + result = true; + } catch (IllegalArgumentException e) { + msg = msg.concat(": Bad parameter value"); + loge(msg, "Bad parameter value"); + } catch (UnsupportedOperationException e) { + msg = msg.concat(": get parameter() rejected"); + loge(msg, "get parameter() rejected"); + } catch (IllegalStateException e) { + msg = msg.concat("get parameter() called in wrong state"); + loge(msg, "get parameter() called in wrong state"); + } finally { + releaseReverb(); + } + assertTrue(msg, result); + } + + //Test case 1.5: test properties + @LargeTest + public void test1_5Properties() throws Exception { + boolean result = false; + String msg = "test1_5Properties()"; + getReverb(0); + try { + EnvironmentalReverb.Settings settings = mReverb.getProperties(); + short newRoomLevel = 0; + if (settings.roomLevel == 0) { + newRoomLevel = -1000; + } + String str = settings.toString(); + settings = new EnvironmentalReverb.Settings(str); + settings.roomLevel = newRoomLevel; + mReverb.setProperties(settings); + settings = mReverb.getProperties(); + assertTrue(msg +": setProperties failed", + (settings.roomLevel > (newRoomLevel - MILLIBEL_TOLERANCE)) && + (settings.roomLevel < (newRoomLevel + MILLIBEL_TOLERANCE))); + result = true; + } catch (IllegalArgumentException e) { + msg = msg.concat(": Bad parameter value"); + loge(msg, "Bad parameter value"); + } catch (UnsupportedOperationException e) { + msg = msg.concat(": get parameter() rejected"); + loge(msg, "get parameter() rejected"); + } catch (IllegalStateException e) { + msg = msg.concat("get parameter() called in wrong state"); + loge(msg, "get parameter() called in wrong state"); + } finally { + releaseReverb(); + } + assertTrue(msg, result); + } + + //----------------------------------------------------------------- + // 2 - Effect action + //---------------------------------- + + //Test case 2.0: test actual auxiliary reverb influence on sound + @LargeTest + public void test2_0AuxiliarySoundModification() throws Exception { + boolean result = false; + String msg = "test2_0AuxiliarySoundModification()"; + EnergyProbe probe = null; + AudioEffect vc = null; + MediaPlayer mp = null; + AudioManager am = (AudioManager) getActivity().getSystemService(Context.AUDIO_SERVICE); + int volume = am.getStreamMaxVolume(AudioManager.STREAM_MUSIC); + am.setStreamVolume(AudioManager.STREAM_MUSIC, + am.getStreamMaxVolume(AudioManager.STREAM_MUSIC), + 0); + getReverb(0); + try { + probe = new EnergyProbe(0); + // 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, + UUID.fromString("119341a0-8469-11df-81f9-0002a5d5c51b"), + 0, + 0); + vc.setEnabled(true); + + mp = new MediaPlayer(); + mp.setDataSource(MediaNames.SINE_200_1000); + mp.setAudioStreamType(AudioManager.STREAM_MUSIC); + mp.attachAuxEffect(mReverb.getId()); + mp.setAuxEffectSendLevel(1.0f); + mReverb.setRoomLevel((short)0); + mReverb.setReverbLevel((short)0); + mReverb.setDecayTime(2000); + mReverb.setEnabled(true); + mp.prepare(); + mp.start(); + Thread.sleep(1000); + mp.stop(); + Thread.sleep(300); + // measure energy around 1kHz after media player was stopped for 300 ms + int energy1000 = probe.capture(1000); + assertTrue(msg + ": reverb has no effect", energy1000 > 0); + result = true; + } catch (IllegalArgumentException e) { + msg = msg.concat(": Bad parameter value"); + loge(msg, "Bad parameter value"); + } catch (UnsupportedOperationException e) { + msg = msg.concat(": get parameter() rejected"); + loge(msg, "get parameter() rejected"); + } catch (IllegalStateException e) { + msg = msg.concat("get parameter() called in wrong state"); + loge(msg, "get parameter() called in wrong state"); + } catch (InterruptedException e) { + loge(msg, "sleep() interrupted"); + } + finally { + releaseReverb(); + if (mp != null) { + mp.release(); + } + if (vc != null) { + vc.release(); + } + if (probe != null) { + probe.release(); + } + am.setStreamVolume(AudioManager.STREAM_MUSIC, volume, 0); + } + assertTrue(msg, result); + } + + //Test case 2.1: test actual insert reverb influence on sound + @LargeTest + public void test2_1InsertSoundModification() throws Exception { + boolean result = false; + String msg = "test2_1InsertSoundModification()"; + EnergyProbe probe = null; + AudioEffect vc = null; + MediaPlayer mp = null; + AudioEffect rvb = null; + AudioManager am = (AudioManager) getActivity().getSystemService(Context.AUDIO_SERVICE); + int volume = am.getStreamMaxVolume(AudioManager.STREAM_MUSIC); + am.setStreamVolume(AudioManager.STREAM_MUSIC, + am.getStreamMaxVolume(AudioManager.STREAM_MUSIC), + 0); + try { + // 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, + UUID.fromString("119341a0-8469-11df-81f9-0002a5d5c51b"), + 0, + 0); + vc.setEnabled(true); + + mp = new MediaPlayer(); + mp.setDataSource(MediaNames.SINE_200_1000); + mp.setAudioStreamType(AudioManager.STREAM_MUSIC); + + // create reverb with UUID instead of EnvironmentalReverb constructor otherwise an + // auxiliary reverb will be chosen by the effect framework as we are on session 0 + rvb = new AudioEffect( + AudioEffect.EFFECT_TYPE_NULL, + UUID.fromString("c7a511a0-a3bb-11df-860e-0002a5d5c51b"), + 0, + 0); + + rvb.setParameter(EnvironmentalReverb.PARAM_ROOM_LEVEL, (short)0); + rvb.setParameter(EnvironmentalReverb.PARAM_REVERB_LEVEL, (short)0); + rvb.setParameter(EnvironmentalReverb.PARAM_DECAY_TIME, 2000); + rvb.setEnabled(true); + + // create probe after reverb so that it is chained behind the reverb in the + // effect chain + probe = new EnergyProbe(0); + + mp.prepare(); + mp.start(); + Thread.sleep(1000); + mp.stop(); + Thread.sleep(300); + // measure energy around 1kHz after media player was stopped for 300 ms + int energy1000 = probe.capture(1000); + assertTrue(msg + ": reverb has no effect", energy1000 > 0); + result = true; + } catch (IllegalArgumentException e) { + msg = msg.concat(": Bad parameter value"); + loge(msg, "Bad parameter value"); + } catch (UnsupportedOperationException e) { + msg = msg.concat(": get parameter() rejected"); + loge(msg, "get parameter() rejected"); + } catch (IllegalStateException e) { + msg = msg.concat("get parameter() called in wrong state"); + loge(msg, "get parameter() called in wrong state"); + } catch (InterruptedException e) { + loge(msg, "sleep() interrupted"); + } + finally { + if (mp != null) { + mp.release(); + } + if (vc != null) { + vc.release(); + } + if (rvb != null) { + rvb.release(); + } + if (probe != null) { + probe.release(); + } + am.setStreamVolume(AudioManager.STREAM_MUSIC, volume, 0); + } + assertTrue(msg, result); + } + + //----------------------------------------------------------------- + // private methods + //---------------------------------- + + private void getReverb(int session) { + if (mReverb == null || session != mSession) { + if (session != mSession && mReverb != null) { + mReverb.release(); + mReverb = null; + } + try { + mReverb = new EnvironmentalReverb(0, session); + mSession = session; + } catch (IllegalArgumentException e) { + Log.e(TAG, "getReverb() EnvironmentalReverb not found exception: "+e); + } catch (UnsupportedOperationException e) { + Log.e(TAG, "getReverb() Effect library not loaded exception: "+e); + } + } + assertNotNull("could not create mReverb", mReverb); + } + + private void releaseReverb() { + if (mReverb != null) { + mReverb.release(); + mReverb = null; + } + } + +} diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/MediaEqualizerTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/MediaEqualizerTest.java new file mode 100644 index 0000000..1acc611 --- /dev/null +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/MediaEqualizerTest.java @@ -0,0 +1,352 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.mediaframeworktest.functional.audio; + +import com.android.mediaframeworktest.MediaFrameworkTest; +import com.android.mediaframeworktest.MediaNames; +import com.android.mediaframeworktest.functional.EnergyProbe; +import android.content.Context; +import android.content.res.AssetFileDescriptor; +import android.media.audiofx.AudioEffect; +import android.media.AudioManager; +import android.media.audiofx.Equalizer; +import android.media.audiofx.Visualizer; +import android.media.MediaPlayer; + +import android.os.Looper; +import android.test.suitebuilder.annotation.LargeTest; +import android.test.suitebuilder.annotation.MediumTest; +import android.test.suitebuilder.annotation.Suppress; +import android.test.ActivityInstrumentationTestCase2; +import android.util.Log; + +import java.nio.ByteOrder; +import java.nio.ByteBuffer; +import java.util.UUID; + +/** + * Junit / Instrumentation test case for the media AudioTrack api + + */ +public class MediaEqualizerTest extends ActivityInstrumentationTestCase2 { + private String TAG = "MediaEqualizerTest"; + private final static int MIN_NUMBER_OF_BANDS = 4; + private final static int MIN_BAND_LEVEL = -1500; + private final static int MAX_BAND_LEVEL = 1500; + private final static int TEST_FREQUENCY_MILLIHERTZ = 1000000; + private final static int MIN_NUMBER_OF_PRESETS = 4; + private final static int TEST_VOLUME = 4; + private Equalizer mEqualizer = null; + private int mSession = -1; + + public MediaEqualizerTest() { + super("com.android.mediaframeworktest", MediaFrameworkTest.class); + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + } + + @Override + protected void tearDown() throws Exception { + super.tearDown(); + releaseEqualizer(); + } + + private static void assumeTrue(String message, boolean cond) { + assertTrue("(assume)"+message, cond); + } + + private void log(String testName, String message) { + Log.v(TAG, "["+testName+"] "+message); + } + + private void loge(String testName, String message) { + Log.e(TAG, "["+testName+"] "+message); + } + + //----------------------------------------------------------------- + // EQUALIZER TESTS: + //---------------------------------- + + + //----------------------------------------------------------------- + // 0 - constructor + //---------------------------------- + + //Test case 0.0: test constructor and release + @LargeTest + public void test0_0ConstructorAndRelease() throws Exception { + boolean result = false; + String msg = "test1_0ConstructorAndRelease()"; + Equalizer eq = null; + try { + eq = new Equalizer(0, 0); + assertNotNull(msg + ": could not create Equalizer", eq); + try { + assertTrue(msg +": invalid effect ID", (eq.getId() != 0)); + } catch (IllegalStateException e) { + msg = msg.concat(": Equalizer not initialized"); + } + result = true; + } catch (IllegalArgumentException e) { + msg = msg.concat(": Equalizer not found"); + } catch (UnsupportedOperationException e) { + msg = msg.concat(": Effect library not loaded"); + } finally { + if (eq != null) { + eq.release(); + } + } + assertTrue(msg, result); + } + + + //----------------------------------------------------------------- + // 1 - get/set parameters + //---------------------------------- + + //Test case 1.0: test setBandLevel() and getBandLevel() + @LargeTest + public void test1_0BandLevel() throws Exception { + boolean result = false; + String msg = "test1_0BandLevel()"; + getEqualizer(0); + try { + short numBands = mEqualizer.getNumberOfBands(); + assertTrue(msg + ": not enough bands", numBands >= MIN_NUMBER_OF_BANDS); + + short[] levelRange = mEqualizer.getBandLevelRange(); + assertTrue(msg + ": min level too high", levelRange[0] <= MIN_BAND_LEVEL); + assertTrue(msg + ": max level too low", levelRange[1] >= MAX_BAND_LEVEL); + + mEqualizer.setBandLevel((short)0, levelRange[1]); + short level = mEqualizer.getBandLevel((short)0); + // 10% margin on actual level compared to requested level + assertTrue(msg + ": setBandLevel failed", + ((float)level > (float)levelRange[1] * 0.9f) && + ((float)level < (float)levelRange[1] * 1.1f)); + result = true; + } catch (IllegalArgumentException e) { + msg = msg.concat(": Bad parameter value"); + loge(msg, "Bad parameter value"); + } catch (UnsupportedOperationException e) { + msg = msg.concat(": get parameter() rejected"); + loge(msg, "get parameter() rejected"); + } catch (IllegalStateException e) { + msg = msg.concat("get parameter() called in wrong state"); + loge(msg, "get parameter() called in wrong state"); + } finally { + releaseEqualizer(); + } + assertTrue(msg, result); + } + + //Test case 1.1: test band frequency + @LargeTest + public void test1_1BandFrequency() throws Exception { + boolean result = false; + String msg = "test1_1BandFrequency()"; + getEqualizer(0); + try { + short band = mEqualizer.getBand(TEST_FREQUENCY_MILLIHERTZ); + assertTrue(msg + ": getBand failed", band >= 0); + int[] freqRange = mEqualizer.getBandFreqRange(band); + assertTrue(msg + ": getBandFreqRange failed", + (freqRange[0] <= TEST_FREQUENCY_MILLIHERTZ) && + (freqRange[1] >= TEST_FREQUENCY_MILLIHERTZ)); + int freq = mEqualizer.getCenterFreq(band); + assertTrue(msg + ": getCenterFreq failed", + (freqRange[0] <= freq) && (freqRange[1] >= freq)); + result = true; + } catch (IllegalArgumentException e) { + msg = msg.concat(": Bad parameter value"); + loge(msg, "Bad parameter value"); + } catch (UnsupportedOperationException e) { + msg = msg.concat(": get parameter() rejected"); + loge(msg, "get parameter() rejected"); + } catch (IllegalStateException e) { + msg = msg.concat("get parameter() called in wrong state"); + loge(msg, "get parameter() called in wrong state"); + } finally { + releaseEqualizer(); + } + assertTrue(msg, result); + } + + //Test case 1.2: test presets + @LargeTest + public void test1_2Presets() throws Exception { + boolean result = false; + String msg = "test1_2Presets()"; + getEqualizer(0); + try { + short numPresets = mEqualizer.getNumberOfPresets(); + assertTrue(msg + ": getNumberOfPresets failed", numPresets >= MIN_NUMBER_OF_PRESETS); + mEqualizer.usePreset((short)(numPresets - 1)); + short preset = mEqualizer.getCurrentPreset(); + assertEquals(msg + ": usePreset failed", preset, (short)(numPresets - 1)); + String name = mEqualizer.getPresetName(preset); + assertNotNull(msg + ": getPresetName failed", name); + result = true; + } catch (IllegalArgumentException e) { + msg = msg.concat(": Bad parameter value"); + loge(msg, "Bad parameter value"); + } catch (UnsupportedOperationException e) { + msg = msg.concat(": get parameter() rejected"); + loge(msg, "get parameter() rejected"); + } catch (IllegalStateException e) { + msg = msg.concat("get parameter() called in wrong state"); + loge(msg, "get parameter() called in wrong state"); + } finally { + releaseEqualizer(); + } + assertTrue(msg, result); + } + + //Test case 1.3: test properties + @LargeTest + public void test1_3Properties() throws Exception { + boolean result = false; + String msg = "test1_3Properties()"; + getEqualizer(0); + try { + Equalizer.Settings settings = mEqualizer.getProperties(); + String str = settings.toString(); + settings = new Equalizer.Settings(str); + mEqualizer.setProperties(settings); + result = true; + } catch (IllegalArgumentException e) { + msg = msg.concat(": Bad parameter value"); + loge(msg, "Bad parameter value"); + } catch (UnsupportedOperationException e) { + msg = msg.concat(": get parameter() rejected"); + loge(msg, "get parameter() rejected"); + } catch (IllegalStateException e) { + msg = msg.concat("get parameter() called in wrong state"); + loge(msg, "get parameter() called in wrong state"); + } finally { + releaseEqualizer(); + } + assertTrue(msg, result); + } + + //----------------------------------------------------------------- + // 2 - Effect action + //---------------------------------- + + //Test case 2.0: test that the equalizer actually alters the sound + @LargeTest + public void test2_0SoundModification() throws Exception { + boolean result = false; + String msg = "test2_0SoundModification()"; + EnergyProbe probe = null; + AudioEffect vc = null; + MediaPlayer mp = null; + AudioManager am = (AudioManager) getActivity().getSystemService(Context.AUDIO_SERVICE); + int volume = am.getStreamMaxVolume(AudioManager.STREAM_MUSIC); + am.setStreamVolume(AudioManager.STREAM_MUSIC, + TEST_VOLUME, + 0); + try { + probe = new EnergyProbe(0); + // 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, + UUID.fromString("119341a0-8469-11df-81f9-0002a5d5c51b"), + 0, + 0); + vc.setEnabled(true); + + mp = new MediaPlayer(); + mp.setDataSource(MediaNames.SINE_200_1000); + mp.setAudioStreamType(AudioManager.STREAM_MUSIC); + getEqualizer(mp.getAudioSessionId()); + mp.prepare(); + mp.start(); + Thread.sleep(500); + // measure reference energy around 1kHz + int refEnergy = probe.capture(1000); + short band = mEqualizer.getBand(1000000); + short[] levelRange = mEqualizer.getBandLevelRange(); + mEqualizer.setBandLevel(band, levelRange[0]); + mEqualizer.setEnabled(true); + Thread.sleep(500); + // measure energy around 1kHz with band level at min + int energy = probe.capture(1000); + assertTrue(msg + ": equalizer has no effect at 1kHz", energy < refEnergy/4); + result = true; + } catch (IllegalArgumentException e) { + msg = msg.concat(": Bad parameter value"); + loge(msg, "Bad parameter value"); + } catch (UnsupportedOperationException e) { + msg = msg.concat(": get parameter() rejected"); + loge(msg, "get parameter() rejected"); + } catch (IllegalStateException e) { + msg = msg.concat("get parameter() called in wrong state"); + loge(msg, "get parameter() called in wrong state"); + } catch (InterruptedException e) { + loge(msg, "sleep() interrupted"); + } + finally { + releaseEqualizer(); + if (mp != null) { + mp.release(); + } + if (vc != null) { + vc.release(); + } + if (probe != null) { + probe.release(); + } + am.setStreamVolume(AudioManager.STREAM_MUSIC, volume, 0); + } + assertTrue(msg, result); + } + + //----------------------------------------------------------------- + // private methods + //---------------------------------- + + private void getEqualizer(int session) { + if (mEqualizer == null || session != mSession) { + if (session != mSession && mEqualizer != null) { + mEqualizer.release(); + mEqualizer = null; + } + try { + mEqualizer = new Equalizer(0, session); + mSession = session; + } catch (IllegalArgumentException e) { + Log.e(TAG, "getEqualizer() Equalizer not found exception: "+e); + } catch (UnsupportedOperationException e) { + Log.e(TAG, "getEqualizer() Effect library not loaded exception: "+e); + } + } + assertNotNull("could not create mEqualizer", mEqualizer); + } + + private void releaseEqualizer() { + if (mEqualizer != null) { + mEqualizer.release(); + mEqualizer = null; + } + } + +} diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/MediaPresetReverbTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/MediaPresetReverbTest.java new file mode 100644 index 0000000..cac0904 --- /dev/null +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/MediaPresetReverbTest.java @@ -0,0 +1,368 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.mediaframeworktest.functional.audio; + +import com.android.mediaframeworktest.MediaFrameworkTest; +import com.android.mediaframeworktest.MediaNames; +import com.android.mediaframeworktest.functional.EnergyProbe; +import android.content.Context; +import android.content.res.AssetFileDescriptor; +import android.media.audiofx.AudioEffect; +import android.media.AudioManager; +import android.media.audiofx.PresetReverb; +import android.media.audiofx.Visualizer; +import android.media.MediaPlayer; + +import android.os.Looper; +import android.test.suitebuilder.annotation.LargeTest; +import android.test.suitebuilder.annotation.MediumTest; +import android.test.suitebuilder.annotation.Suppress; +import android.test.ActivityInstrumentationTestCase2; +import android.util.Log; + +import java.nio.ByteOrder; +import java.nio.ByteBuffer; +import java.util.UUID; + +/** + * Junit / Instrumentation test case for the media AudioTrack api + + */ +public class MediaPresetReverbTest extends ActivityInstrumentationTestCase2 { + private String TAG = "MediaPresetReverbTest"; + + private PresetReverb mReverb = null; + private int mSession = -1; + + public MediaPresetReverbTest() { + super("com.android.mediaframeworktest", MediaFrameworkTest.class); + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + } + + @Override + protected void tearDown() throws Exception { + super.tearDown(); + releaseReverb(); + } + + private static void assumeTrue(String message, boolean cond) { + assertTrue("(assume)"+message, cond); + } + + private void log(String testName, String message) { + Log.v(TAG, "["+testName+"] "+message); + } + + private void loge(String testName, String message) { + Log.e(TAG, "["+testName+"] "+message); + } + + //----------------------------------------------------------------- + // PRESET REVEB TESTS: + //---------------------------------- + + + //----------------------------------------------------------------- + // 0 - constructor + //---------------------------------- + + //Test case 0.0: test constructor and release + @LargeTest + public void test0_0ConstructorAndRelease() throws Exception { + boolean result = false; + String msg = "test1_0ConstructorAndRelease()"; + PresetReverb reverb = null; + try { + reverb = new PresetReverb(0, 0); + assertNotNull(msg + ": could not create PresetReverb", reverb); + try { + assertTrue(msg +": invalid effect ID", (reverb.getId() != 0)); + } catch (IllegalStateException e) { + msg = msg.concat(": PresetReverb not initialized"); + } + result = true; + } catch (IllegalArgumentException e) { + msg = msg.concat(": PresetReverb not found"); + } catch (UnsupportedOperationException e) { + msg = msg.concat(": Effect library not loaded"); + } finally { + if (reverb != null) { + reverb.release(); + } + } + assertTrue(msg, result); + } + + //----------------------------------------------------------------- + // 1 - get/set parameters + //---------------------------------- + + //Test case 1.0: test preset + @LargeTest + public void test1_0Preset() throws Exception { + boolean result = false; + String msg = "test1_0Preset()"; + getReverb(0); + try { + mReverb.setPreset((short)PresetReverb.PRESET_LARGEROOM); + short preset = mReverb.getPreset(); + assertEquals(msg +": got incorrect preset", + (short)PresetReverb.PRESET_LARGEROOM, + preset); + result = true; + } catch (IllegalArgumentException e) { + msg = msg.concat(": Bad parameter value"); + loge(msg, "Bad parameter value"); + } catch (UnsupportedOperationException e) { + msg = msg.concat(": get parameter() rejected"); + loge(msg, "get parameter() rejected"); + } catch (IllegalStateException e) { + msg = msg.concat("get parameter() called in wrong state"); + loge(msg, "get parameter() called in wrong state"); + } finally { + releaseReverb(); + } + assertTrue(msg, result); + } + + //Test case 1.1: test properties + @LargeTest + public void test1_1Properties() throws Exception { + boolean result = false; + String msg = "test1_1Properties()"; + getReverb(0); + try { + PresetReverb.Settings settings = mReverb.getProperties(); + short newPreset = (short)PresetReverb.PRESET_LARGEROOM; + if (settings.preset == (short)PresetReverb.PRESET_LARGEROOM) { + newPreset = (short)PresetReverb.PRESET_SMALLROOM; + } + String str = settings.toString(); + settings = new PresetReverb.Settings(str); + settings.preset = newPreset; + mReverb.setProperties(settings); + settings = mReverb.getProperties(); + assertEquals(msg +": setProperties failed", newPreset, settings.preset); + result = true; + } catch (IllegalArgumentException e) { + msg = msg.concat(": Bad parameter value"); + loge(msg, "Bad parameter value"); + } catch (UnsupportedOperationException e) { + msg = msg.concat(": get parameter() rejected"); + loge(msg, "get parameter() rejected"); + } catch (IllegalStateException e) { + msg = msg.concat("get parameter() called in wrong state"); + loge(msg, "get parameter() called in wrong state"); + } finally { + releaseReverb(); + } + assertTrue(msg, result); + } + + //----------------------------------------------------------------- + // 2 - Effect action + //---------------------------------- + + //Test case 2.0: test actual auxiliary reverb influence on sound + @LargeTest + public void test2_0AuxiliarySoundModification() throws Exception { + boolean result = false; + String msg = "test2_0AuxiliarySoundModification()"; + EnergyProbe probe = null; + AudioEffect vc = null; + MediaPlayer mp = null; + AudioManager am = (AudioManager) getActivity().getSystemService(Context.AUDIO_SERVICE); + int volume = am.getStreamMaxVolume(AudioManager.STREAM_MUSIC); + am.setStreamVolume(AudioManager.STREAM_MUSIC, + am.getStreamMaxVolume(AudioManager.STREAM_MUSIC), + 0); + getReverb(0); + try { + probe = new EnergyProbe(0); + // 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, + UUID.fromString("119341a0-8469-11df-81f9-0002a5d5c51b"), + 0, + 0); + vc.setEnabled(true); + + mp = new MediaPlayer(); + mp.setDataSource(MediaNames.SINE_200_1000); + mp.setAudioStreamType(AudioManager.STREAM_MUSIC); + mp.attachAuxEffect(mReverb.getId()); + mp.setAuxEffectSendLevel(1.0f); + mReverb.setPreset((short)PresetReverb.PRESET_PLATE); + mReverb.setEnabled(true); + mp.prepare(); + mp.start(); + Thread.sleep(1000); + mp.stop(); + Thread.sleep(200); + // measure energy around 1kHz after media player was stopped for 200 ms + int energy1000 = probe.capture(1000); + assertTrue(msg + ": reverb has no effect", energy1000 > 0); + result = true; + } catch (IllegalArgumentException e) { + msg = msg.concat(": Bad parameter value"); + loge(msg, "Bad parameter value"); + } catch (UnsupportedOperationException e) { + msg = msg.concat(": get parameter() rejected"); + loge(msg, "get parameter() rejected"); + } catch (IllegalStateException e) { + msg = msg.concat("get parameter() called in wrong state"); + loge(msg, "get parameter() called in wrong state"); + } catch (InterruptedException e) { + loge(msg, "sleep() interrupted"); + } + finally { + releaseReverb(); + if (mp != null) { + mp.release(); + } + if (vc != null) { + vc.release(); + } + if (probe != null) { + probe.release(); + } + am.setStreamVolume(AudioManager.STREAM_MUSIC, volume, 0); + } + assertTrue(msg, result); + } + + //Test case 2.1: test actual insert reverb influence on sound + @LargeTest + public void test2_1InsertSoundModification() throws Exception { + boolean result = false; + String msg = "test2_1InsertSoundModification()"; + EnergyProbe probe = null; + AudioEffect vc = null; + MediaPlayer mp = null; + AudioEffect rvb = null; + AudioManager am = (AudioManager) getActivity().getSystemService(Context.AUDIO_SERVICE); + int volume = am.getStreamMaxVolume(AudioManager.STREAM_MUSIC); + am.setStreamVolume(AudioManager.STREAM_MUSIC, + am.getStreamMaxVolume(AudioManager.STREAM_MUSIC), + 0); + try { + // 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, + UUID.fromString("119341a0-8469-11df-81f9-0002a5d5c51b"), + 0, + 0); + vc.setEnabled(true); + + mp = new MediaPlayer(); + mp.setDataSource(MediaNames.SINE_200_1000); + mp.setAudioStreamType(AudioManager.STREAM_MUSIC); + getReverb(mp.getAudioSessionId()); + mReverb.setPreset((short)PresetReverb.PRESET_PLATE); + mReverb.setEnabled(true); + + // create reverb with UUID instead of PresetReverb constructor otherwise an auxiliary + // reverb will be chosen by the effect framework as we are on session 0 + rvb = new AudioEffect( + AudioEffect.EFFECT_TYPE_NULL, + UUID.fromString("172cdf00-a3bc-11df-a72f-0002a5d5c51b"), + 0, + 0); + + rvb.setParameter(PresetReverb.PARAM_PRESET, PresetReverb.PRESET_PLATE); + rvb.setEnabled(true); + + // create probe after reverb so that it is chained behind the reverb in the + // effect chain + probe = new EnergyProbe(0); + + mp.prepare(); + mp.start(); + Thread.sleep(1000); + mp.stop(); + Thread.sleep(200); + // measure energy around 1kHz after media player was stopped for 200 ms + int energy1000 = probe.capture(1000); + assertTrue(msg + ": reverb has no effect", energy1000 > 0); + result = true; + } catch (IllegalArgumentException e) { + msg = msg.concat(": Bad parameter value"); + loge(msg, "Bad parameter value"); + } catch (UnsupportedOperationException e) { + msg = msg.concat(": get parameter() rejected"); + loge(msg, "get parameter() rejected"); + } catch (IllegalStateException e) { + msg = msg.concat("get parameter() called in wrong state"); + loge(msg, "get parameter() called in wrong state"); + } catch (InterruptedException e) { + loge(msg, "sleep() interrupted"); + } + finally { + releaseReverb(); + if (mp != null) { + mp.release(); + } + if (vc != null) { + vc.release(); + } + if (rvb != null) { + rvb.release(); + } + if (probe != null) { + probe.release(); + } + am.setStreamVolume(AudioManager.STREAM_MUSIC, volume, 0); + } + assertTrue(msg, result); + } + + //----------------------------------------------------------------- + // private methods + //---------------------------------- + + private void getReverb(int session) { + if (mReverb == null || session != mSession) { + if (session != mSession && mReverb != null) { + mReverb.release(); + mReverb = null; + } + try { + mReverb = new PresetReverb(0, session); + mSession = session; + } catch (IllegalArgumentException e) { + Log.e(TAG, "getReverb() PresetReverb not found exception: "+e); + } catch (UnsupportedOperationException e) { + Log.e(TAG, "getReverb() Effect library not loaded exception: "+e); + } + } + assertNotNull("could not create mReverb", mReverb); + } + + private void releaseReverb() { + if (mReverb != null) { + mReverb.release(); + mReverb = null; + } + } + +} diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/MediaVirtualizerTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/MediaVirtualizerTest.java new file mode 100644 index 0000000..d47f08f --- /dev/null +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/MediaVirtualizerTest.java @@ -0,0 +1,294 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.mediaframeworktest.functional.audio; + +import com.android.mediaframeworktest.MediaFrameworkTest; +import com.android.mediaframeworktest.MediaNames; +import com.android.mediaframeworktest.functional.EnergyProbe; +import android.content.Context; +import android.content.res.AssetFileDescriptor; +import android.media.audiofx.AudioEffect; +import android.media.AudioManager; +import android.media.audiofx.Virtualizer; +import android.media.audiofx.Visualizer; +import android.media.MediaPlayer; + +import android.os.Looper; +import android.test.suitebuilder.annotation.LargeTest; +import android.test.suitebuilder.annotation.MediumTest; +import android.test.suitebuilder.annotation.Suppress; +import android.test.ActivityInstrumentationTestCase2; +import android.util.Log; + +import java.nio.ByteOrder; +import java.nio.ByteBuffer; +import java.util.UUID; + +/** + * Junit / Instrumentation test case for the media AudioTrack api + + */ +public class MediaVirtualizerTest extends ActivityInstrumentationTestCase2 { + private String TAG = "MediaVirtualizerTest"; + private final static int MIN_ENERGY_RATIO_2 = 3; + private final static short TEST_STRENGTH = 500; + private final static int TEST_VOLUME = 4; + + private Virtualizer mVirtualizer = null; + private int mSession = -1; + + public MediaVirtualizerTest() { + super("com.android.mediaframeworktest", MediaFrameworkTest.class); + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + } + + @Override + protected void tearDown() throws Exception { + super.tearDown(); + releaseVirtualizer(); + } + + private static void assumeTrue(String message, boolean cond) { + assertTrue("(assume)"+message, cond); + } + + private void log(String testName, String message) { + Log.v(TAG, "["+testName+"] "+message); + } + + private void loge(String testName, String message) { + Log.e(TAG, "["+testName+"] "+message); + } + + //----------------------------------------------------------------- + // VIRTUALIZER TESTS: + //---------------------------------- + + + //----------------------------------------------------------------- + // 0 - constructor + //---------------------------------- + + //Test case 0.0: test constructor and release + @LargeTest + public void test0_0ConstructorAndRelease() throws Exception { + boolean result = false; + String msg = "test1_0ConstructorAndRelease()"; + Virtualizer virtualizer = null; + try { + virtualizer = new Virtualizer(0, 0); + assertNotNull(msg + ": could not create Virtualizer", virtualizer); + try { + assertTrue(msg +": invalid effect ID", (virtualizer.getId() != 0)); + } catch (IllegalStateException e) { + msg = msg.concat(": Virtualizer not initialized"); + } + result = true; + } catch (IllegalArgumentException e) { + msg = msg.concat(": Virtualizer not found"); + } catch (UnsupportedOperationException e) { + msg = msg.concat(": Effect library not loaded"); + } finally { + if (virtualizer != null) { + virtualizer.release(); + } + } + assertTrue(msg, result); + } + + + //----------------------------------------------------------------- + // 1 - get/set parameters + //---------------------------------- + + //Test case 1.0: test strength + @LargeTest + public void test1_0Strength() throws Exception { + boolean result = false; + String msg = "test1_0Strength()"; + getVirtualizer(0); + try { + if (mVirtualizer.getStrengthSupported()) { + mVirtualizer.setStrength((short)TEST_STRENGTH); + short strength = mVirtualizer.getRoundedStrength(); + // allow 10% difference between set strength and rounded strength + assertTrue(msg +": got incorrect strength", + ((float)strength > (float)TEST_STRENGTH * 0.9f) && + ((float)strength < (float)TEST_STRENGTH * 1.1f)); + } else { + short strength = mVirtualizer.getRoundedStrength(); + assertTrue(msg +": got incorrect strength", strength >= 0 && strength <= 1000); + } + result = true; + } catch (IllegalArgumentException e) { + msg = msg.concat(": Bad parameter value"); + loge(msg, "Bad parameter value"); + } catch (UnsupportedOperationException e) { + msg = msg.concat(": get parameter() rejected"); + loge(msg, "get parameter() rejected"); + } catch (IllegalStateException e) { + msg = msg.concat("get parameter() called in wrong state"); + loge(msg, "get parameter() called in wrong state"); + } finally { + releaseVirtualizer(); + } + assertTrue(msg, result); + } + + //Test case 1.1: test properties + @LargeTest + public void test1_1Properties() throws Exception { + boolean result = false; + String msg = "test1_1Properties()"; + getVirtualizer(0); + try { + Virtualizer.Settings settings = mVirtualizer.getProperties(); + String str = settings.toString(); + settings = new Virtualizer.Settings(str); + mVirtualizer.setProperties(settings); + result = true; + } catch (IllegalArgumentException e) { + msg = msg.concat(": Bad parameter value"); + loge(msg, "Bad parameter value"); + } catch (UnsupportedOperationException e) { + msg = msg.concat(": get parameter() rejected"); + loge(msg, "get parameter() rejected"); + } catch (IllegalStateException e) { + msg = msg.concat("get parameter() called in wrong state"); + loge(msg, "get parameter() called in wrong state"); + } finally { + releaseVirtualizer(); + } + assertTrue(msg, result); + } + + //----------------------------------------------------------------- + // 2 - Effect action + //---------------------------------- + + //Test case 2.0: test actual virtualizer influence on sound + @LargeTest + public void test2_0SoundModification() throws Exception { + boolean result = false; + String msg = "test2_0SoundModification()"; + EnergyProbe probe = null; + AudioEffect vc = null; + MediaPlayer mp = null; + AudioManager am = (AudioManager) getActivity().getSystemService(Context.AUDIO_SERVICE); + int volume = am.getStreamMaxVolume(AudioManager.STREAM_MUSIC); + am.setStreamVolume(AudioManager.STREAM_MUSIC, + TEST_VOLUME, + 0); + + try { + probe = new EnergyProbe(0); + // 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, + UUID.fromString("119341a0-8469-11df-81f9-0002a5d5c51b"), + 0, + 0); + vc.setEnabled(true); + + mp = new MediaPlayer(); + mp.setDataSource(MediaNames.SINE_200_1000); + mp.setAudioStreamType(AudioManager.STREAM_MUSIC); + getVirtualizer(mp.getAudioSessionId()); + mp.prepare(); + mp.start(); + Thread.sleep(200); + // measure reference energy around 1kHz + int refEnergy200 = probe.capture(200); + int refEnergy1000 = probe.capture(1000); + mVirtualizer.setStrength((short)1000); + mVirtualizer.setEnabled(true); + Thread.sleep(500); + // measure energy around 1kHz with band level at min + int energy200 = probe.capture(200); + int energy1000 = probe.capture(1000); + // verify that the energy ration between low and high frequencies is at least + // MIN_ENERGY_RATIO_2 times higher with virtualizer on. + // NOTE: this is what is observed with current virtualizer implementation and the test + // audio file but is not the primary effect of the virtualizer. A better way would + // be to have a stereo PCM capture and check that a strongly paned input is centered + // when output. However, we cannot capture stereo with the visualizer. + assertTrue(msg + ": virtiualizer has no effect", + ((float)energy200/(float)energy1000) > + (MIN_ENERGY_RATIO_2 * ((float)refEnergy200/(float)refEnergy1000))); + result = true; + } catch (IllegalArgumentException e) { + msg = msg.concat(": Bad parameter value"); + loge(msg, "Bad parameter value"); + } catch (UnsupportedOperationException e) { + msg = msg.concat(": get parameter() rejected"); + loge(msg, "get parameter() rejected"); + } catch (IllegalStateException e) { + msg = msg.concat("get parameter() called in wrong state"); + loge(msg, "get parameter() called in wrong state"); + } catch (InterruptedException e) { + loge(msg, "sleep() interrupted"); + } + finally { + releaseVirtualizer(); + if (mp != null) { + mp.release(); + } + if (vc != null) { + vc.release(); + } + if (probe != null) { + probe.release(); + } + am.setStreamVolume(AudioManager.STREAM_MUSIC, volume, 0); + } + assertTrue(msg, result); + } + //----------------------------------------------------------------- + // private methods + //---------------------------------- + + private void getVirtualizer(int session) { + if (mVirtualizer == null || session != mSession) { + if (session != mSession && mVirtualizer != null) { + mVirtualizer.release(); + mVirtualizer = null; + } + try { + mVirtualizer = new Virtualizer(0, session); + mSession = session; + } catch (IllegalArgumentException e) { + Log.e(TAG, "getVirtualizer() Virtualizer not found exception: "+e); + } catch (UnsupportedOperationException e) { + Log.e(TAG, "getVirtualizer() Effect library not loaded exception: "+e); + } + } + assertNotNull("could not create mVirtualizer", mVirtualizer); + } + + private void releaseVirtualizer() { + if (mVirtualizer != null) { + mVirtualizer.release(); + mVirtualizer = null; + } + } + +} 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 new file mode 100644 index 0000000..f264afa --- /dev/null +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/MediaVisualizerTest.java @@ -0,0 +1,504 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.mediaframeworktest.functional.audio; + +import com.android.mediaframeworktest.MediaFrameworkTest; +import com.android.mediaframeworktest.MediaNames; +import android.content.Context; +import android.content.res.AssetFileDescriptor; +import android.media.audiofx.AudioEffect; +import android.media.AudioManager; +import android.media.audiofx.Visualizer; +import android.media.MediaPlayer; + +import android.os.Looper; +import android.test.suitebuilder.annotation.LargeTest; +import android.test.suitebuilder.annotation.MediumTest; +import android.test.suitebuilder.annotation.Suppress; +import android.test.ActivityInstrumentationTestCase2; +import android.util.Log; + +import java.nio.ByteOrder; +import java.nio.ByteBuffer; +import java.util.UUID; + +/** + * Junit / Instrumentation test case for the media AudioTrack api + + */ +public class MediaVisualizerTest extends ActivityInstrumentationTestCase2 { + private String TAG = "MediaVisualizerTest"; + private final static int MIN_CAPTURE_RATE_MAX = 20000; + private final static int MIN_SAMPLING_RATE = 8000000; + private final static int MAX_SAMPLING_RATE = 48000000; + private final static int MIN_CAPTURE_SIZE_MAX = 1024; + private final static int MAX_CAPTURE_SIZE_MIN = 128; + + private Visualizer mVisualizer = null; + private int mSession = -1; + private boolean mInitialized = false; + private Looper mLooper = null; + private final Object lock = new Object(); + private byte[] mWaveform = null; + private byte[] mFft = null; + private boolean mCaptureWaveform = false; + private boolean mCaptureFft = false; + + public MediaVisualizerTest() { + super("com.android.mediaframeworktest", MediaFrameworkTest.class); + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + } + + @Override + protected void tearDown() throws Exception { + super.tearDown(); + releaseVisualizer(); + } + + private static void assumeTrue(String message, boolean cond) { + assertTrue("(assume)"+message, cond); + } + + private void log(String testName, String message) { + Log.v(TAG, "["+testName+"] "+message); + } + + private void loge(String testName, String message) { + Log.e(TAG, "["+testName+"] "+message); + } + + //----------------------------------------------------------------- + // VISUALIZER TESTS: + //---------------------------------- + + + //----------------------------------------------------------------- + // 0 - constructor + //---------------------------------- + + //Test case 0.0: test constructor and release + @LargeTest + public void test0_0ConstructorAndRelease() throws Exception { + boolean result = false; + String msg = "test1_0ConstructorAndRelease()"; + Visualizer visualizer = null; + try { + visualizer = new Visualizer(0); + assertNotNull(msg + ": could not create Visualizer", visualizer); + result = true; + } catch (IllegalArgumentException e) { + msg = msg.concat(": Visualizer not found"); + } catch (UnsupportedOperationException e) { + msg = msg.concat(": Effect library not loaded"); + } finally { + if (visualizer != null) { + visualizer.release(); + } + } + assertTrue(msg, result); + } + + + //----------------------------------------------------------------- + // 1 - get/set parameters + //---------------------------------- + + //Test case 1.0: check capture rate and sampling rate + @LargeTest + public void test1_0CaptureRates() throws Exception { + boolean result = false; + String msg = "test1_0CaptureRates()"; + getVisualizer(0); + try { + int captureRate = mVisualizer.getMaxCaptureRate(); + assertTrue(msg +": insufficient max capture rate", + captureRate >= MIN_CAPTURE_RATE_MAX); + int samplingRate = mVisualizer.getSamplingRate(); + assertTrue(msg +": invalid sampling rate", + samplingRate >= MIN_SAMPLING_RATE && samplingRate <= MAX_SAMPLING_RATE); + result = true; + } catch (IllegalArgumentException e) { + msg = msg.concat(": Bad parameter value"); + loge(msg, "Bad parameter value"); + } catch (UnsupportedOperationException e) { + msg = msg.concat(": get parameter() rejected"); + loge(msg, "get parameter() rejected"); + } catch (IllegalStateException e) { + msg = msg.concat("get parameter() called in wrong state"); + loge(msg, "get parameter() called in wrong state"); + } finally { + releaseVisualizer(); + } + assertTrue(msg, result); + } + + //Test case 1.1: check capture size + @LargeTest + public void test1_1CaptureSize() throws Exception { + boolean result = false; + String msg = "test1_1CaptureSize()"; + getVisualizer(0); + try { + int[] range = mVisualizer.getCaptureSizeRange(); + assertTrue(msg +": insufficient min capture size", + range[0] <= MAX_CAPTURE_SIZE_MIN); + assertTrue(msg +": insufficient min capture size", + range[1] >= MIN_CAPTURE_SIZE_MAX); + mVisualizer.setCaptureSize(range[0]); + assertEquals(msg +": insufficient min capture size", + range[0], mVisualizer.getCaptureSize()); + mVisualizer.setCaptureSize(range[1]); + assertEquals(msg +": insufficient min capture size", + range[1], mVisualizer.getCaptureSize()); + result = true; + } catch (IllegalArgumentException e) { + msg = msg.concat(": Bad parameter value"); + loge(msg, "Bad parameter value"); + } catch (UnsupportedOperationException e) { + msg = msg.concat(": get parameter() rejected"); + loge(msg, "get parameter() rejected"); + } catch (IllegalStateException e) { + msg = msg.concat("get parameter() called in wrong state"); + loge(msg, "get parameter() called in wrong state"); + } finally { + releaseVisualizer(); + } + assertTrue(msg, result); + } + + //----------------------------------------------------------------- + // 2 - check capture + //---------------------------------- + + //Test case 2.0: test capture in polling mode + @LargeTest + public void test2_0PollingCapture() throws Exception { + boolean result = false; + String msg = "test2_0PollingCapture()"; + AudioEffect vc = null; + MediaPlayer mp = null; + AudioManager am = (AudioManager) getActivity().getSystemService(Context.AUDIO_SERVICE); + int volume = am.getStreamMaxVolume(AudioManager.STREAM_MUSIC); + am.setStreamVolume(AudioManager.STREAM_MUSIC, + am.getStreamMaxVolume(AudioManager.STREAM_MUSIC), + 0); + + try { + // 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, + UUID.fromString("119341a0-8469-11df-81f9-0002a5d5c51b"), + 0, + 0); + vc.setEnabled(true); + + mp = new MediaPlayer(); + mp.setDataSource(MediaNames.SINE_200_1000); + mp.setAudioStreamType(AudioManager.STREAM_MUSIC); + getVisualizer(mp.getAudioSessionId()); + mVisualizer.setEnabled(true); + // check capture on silence + byte[] data = new byte[mVisualizer.getCaptureSize()]; + mVisualizer.getWaveForm(data); + int energy = computeEnergy(data, true); + assertEquals(msg +": getWaveForm reports energy for silence", + 0, energy); + mVisualizer.getFft(data); + energy = computeEnergy(data, false); + assertEquals(msg +": getFft reports energy for silence", + 0, energy); + mp.prepare(); + mp.start(); + Thread.sleep(500); + // check capture on sound + mVisualizer.getWaveForm(data); + energy = computeEnergy(data, true); + assertTrue(msg +": getWaveForm reads insufficient level", + energy > 0); + mVisualizer.getFft(data); + energy = computeEnergy(data, false); + assertTrue(msg +": getFft reads insufficient level", + energy > 0); + result = true; + } catch (IllegalArgumentException e) { + msg = msg.concat(": Bad parameter value"); + loge(msg, "Bad parameter value"); + } catch (UnsupportedOperationException e) { + msg = msg.concat(": get parameter() rejected"); + loge(msg, "get parameter() rejected"); + } catch (IllegalStateException e) { + msg = msg.concat("get parameter() called in wrong state"); + loge(msg, "get parameter() called in wrong state"); + } catch (InterruptedException e) { + loge(msg, "sleep() interrupted"); + } + finally { + releaseVisualizer(); + if (mp != null) { + mp.release(); + } + if (vc != null) { + vc.release(); + } + am.setStreamVolume(AudioManager.STREAM_MUSIC, volume, 0); + } + assertTrue(msg, result); + } + + //Test case 2.1: test capture with listener + @LargeTest + public void test2_1ListenerCapture() throws Exception { + boolean result = false; + String msg = "test2_1ListenerCapture()"; + AudioEffect vc = null; + MediaPlayer mp = null; + AudioManager am = (AudioManager) getActivity().getSystemService(Context.AUDIO_SERVICE); + int volume = am.getStreamMaxVolume(AudioManager.STREAM_MUSIC); + am.setStreamVolume(AudioManager.STREAM_MUSIC, + am.getStreamMaxVolume(AudioManager.STREAM_MUSIC), + 0); + + try { + // 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, + UUID.fromString("119341a0-8469-11df-81f9-0002a5d5c51b"), + 0, + 0); + vc.setEnabled(true); + + mp = new MediaPlayer(); + mp.setDataSource(MediaNames.SINE_200_1000); + mp.setAudioStreamType(AudioManager.STREAM_MUSIC); + + getVisualizer(mp.getAudioSessionId()); + createListenerLooper(); + synchronized(lock) { + try { + lock.wait(1000); + } catch(Exception e) { + Log.e(TAG, "Looper creation: wait was interrupted."); + } + } + assertTrue(mInitialized); + + mVisualizer.setEnabled(true); + + // check capture on silence + synchronized(lock) { + try { + mCaptureWaveform = true; + lock.wait(1000); + mCaptureWaveform = false; + } catch(Exception e) { + Log.e(TAG, "Capture waveform: wait was interrupted."); + } + } + assertNotNull(msg +": waveform capture failed", mWaveform); + int energy = computeEnergy(mWaveform, true); + assertEquals(msg +": getWaveForm reports energy for silence", + 0, energy); + + synchronized(lock) { + try { + mCaptureFft = true; + lock.wait(1000); + mCaptureFft = false; + } catch(Exception e) { + Log.e(TAG, "Capture FFT: wait was interrupted."); + } + } + assertNotNull(msg +": FFT capture failed", mFft); + energy = computeEnergy(mFft, false); + assertEquals(msg +": getFft reports energy for silence", + 0, energy); + + mp.prepare(); + mp.start(); + Thread.sleep(500); + + // check capture on sound + synchronized(lock) { + try { + mCaptureWaveform = true; + lock.wait(1000); + mCaptureWaveform = false; + } catch(Exception e) { + Log.e(TAG, "Capture waveform: wait was interrupted."); + } + } + assertNotNull(msg +": waveform capture failed", mWaveform); + energy = computeEnergy(mWaveform, true); + assertTrue(msg +": getWaveForm reads insufficient level", + energy > 0); + + synchronized(lock) { + try { + mCaptureFft = true; + lock.wait(1000); + mCaptureFft = false; + } catch(Exception e) { + Log.e(TAG, "Capture FFT: wait was interrupted."); + } + } + assertNotNull(msg +": FFT capture failed", mFft); + energy = computeEnergy(mFft, false); + assertTrue(msg +": getFft reads insufficient level", + energy > 0); + + result = true; + } catch (IllegalArgumentException e) { + msg = msg.concat(": Bad parameter value"); + loge(msg, "Bad parameter value"); + } catch (UnsupportedOperationException e) { + msg = msg.concat(": get parameter() rejected"); + loge(msg, "get parameter() rejected"); + } catch (IllegalStateException e) { + msg = msg.concat("get parameter() called in wrong state"); + loge(msg, "get parameter() called in wrong state"); + } catch (InterruptedException e) { + loge(msg, "sleep() interrupted"); + } + finally { + terminateListenerLooper(); + releaseVisualizer(); + if (mp != null) { + mp.release(); + } + if (vc != null) { + vc.release(); + } + am.setStreamVolume(AudioManager.STREAM_MUSIC, volume, 0); + } + assertTrue(msg, result); + } + + //----------------------------------------------------------------- + // private methods + //---------------------------------- + + private int computeEnergy(byte[] data, boolean unsigned) { + int energy = 0; + if (data.length != 0) { + for (int i = 0; i < data.length; i++) { + int tmp; + // convert from unsigned 8 bit to signed 16 bit + if (unsigned) { + tmp = ((int)data[i] & 0xFF) - 128; + } else { + tmp = (int)data[i]; + } + energy += tmp*tmp; + } + energy /= data.length; + } + return energy; + } + + private void getVisualizer(int session) { + if (mVisualizer == null || session != mSession) { + if (session != mSession && mVisualizer != null) { + mVisualizer.release(); + mVisualizer = null; + } + try { + mVisualizer = new Visualizer(session); + mSession = session; + } catch (IllegalArgumentException e) { + Log.e(TAG, "getVisualizer() Visualizer not found exception: "+e); + } catch (UnsupportedOperationException e) { + Log.e(TAG, "getVisualizer() Effect library not loaded exception: "+e); + } + } + assertNotNull("could not create mVisualizer", mVisualizer); + } + + private void releaseVisualizer() { + if (mVisualizer != null) { + mVisualizer.release(); + mVisualizer = null; + } + } + + private void createListenerLooper() { + + new Thread() { + @Override + public void run() { + // Set up a looper to be used by mEffect. + Looper.prepare(); + + // Save the looper so that we can terminate this thread + // after we are done with it. + mLooper = Looper.myLooper(); + + if (mVisualizer != null) { + mVisualizer.setDataCaptureListener(new Visualizer.OnDataCaptureListener() { + public void onWaveFormDataCapture( + Visualizer visualizer, byte[] waveform, int samplingRate) { + synchronized(lock) { + if (visualizer == mVisualizer) { + if (mCaptureWaveform) { + mWaveform = waveform; + lock.notify(); + } + } + } + } + + public void onFftDataCapture( + Visualizer visualizer, byte[] fft, int samplingRate) { + synchronized(lock) { + if (visualizer == mVisualizer) { + if (mCaptureFft) { + mFft = fft; + lock.notify(); + } + } + } + } + }, + 10000, + true, + true); + } + + synchronized(lock) { + mInitialized = true; + lock.notify(); + } + Looper.loop(); // Blocks forever until Looper.quit() is called. + } + }.start(); + } + /* + * Terminates the listener looper thread. + */ + private void terminateListenerLooper() { + if (mLooper != null) { + mLooper.quit(); + mLooper = null; + } + } + +} diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/SimTonesTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/SimTonesTest.java new file mode 100644 index 0000000..aaf992c --- /dev/null +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/audio/SimTonesTest.java @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.mediaframeworktest.functional.audio; + +// import android.content.Resources; +import com.android.mediaframeworktest.MediaFrameworkTest; +import com.android.mediaframeworktest.functional.TonesAutoTest; + +import android.content.Context; +import android.test.ActivityInstrumentationTestCase; +import android.test.suitebuilder.annotation.LargeTest; + +/** + * Junit / Instrumentation test case for the SIM tone generator + * + */ +public class SimTonesTest extends ActivityInstrumentationTestCase { + private String TAG = "SimTonesTest"; + + Context mContext; + + public SimTonesTest() { + super("com.android.mediaframeworktest", MediaFrameworkTest.class); + } + + protected void setUp() throws Exception { + super.setUp(); + } + + @LargeTest + public void testDtmfTones() throws Exception { + boolean result = TonesAutoTest.tonesDtmfTest(); + assertTrue("DTMF Tones", result); + } + + @LargeTest + public void testSupervisoryTones() throws Exception { + boolean result = TonesAutoTest.tonesSupervisoryTest(); + assertTrue("Supervisory Tones", result); + } + + @LargeTest + public void testProprietaryTones() throws Exception { + boolean result = TonesAutoTest.tonesProprietaryTest(); + assertTrue("Proprietary Tones", result); + } + + @LargeTest + public void testSimultaneousTones() throws Exception { + boolean result = TonesAutoTest.tonesSimultaneousTest(); + assertTrue("Simultaneous Tones", result); + } + + @LargeTest + public void testStressTones() throws Exception { + boolean result = TonesAutoTest.tonesStressTest(); + assertTrue("Stress Tones", result); + } +} diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/mediaplayback/MediaPlayerApiTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/mediaplayback/MediaPlayerApiTest.java new file mode 100644 index 0000000..c501d3f --- /dev/null +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/mediaplayback/MediaPlayerApiTest.java @@ -0,0 +1,426 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.mediaframeworktest.functional.mediaplayback; + +import com.android.mediaframeworktest.MediaFrameworkTest; +import com.android.mediaframeworktest.MediaNames; +import com.android.mediaframeworktest.MediaProfileReader; +import com.android.mediaframeworktest.functional.CodecTest; + +import android.content.Context; +import android.test.ActivityInstrumentationTestCase; +import android.util.Log; +import android.test.suitebuilder.annotation.LargeTest; +import android.test.suitebuilder.annotation.MediumTest; +import android.test.suitebuilder.annotation.Suppress; + +import java.io.File; + +/** + * Junit / Instrumentation test case for the media player api + */ +public class MediaPlayerApiTest extends ActivityInstrumentationTestCase { + private boolean duratoinWithinTolerence = false; + private String TAG = "MediaPlayerApiTest"; + private boolean isWMAEnable = false; + private boolean isWMVEnable = false; + + Context mContext; + + public MediaPlayerApiTest() { + super("com.android.mediaframeworktest", MediaFrameworkTest.class); + isWMAEnable = MediaProfileReader.getWMAEnable(); + isWMVEnable = MediaProfileReader.getWMVEnable(); + } + + protected void setUp() throws Exception { + super.setUp(); + + } + + public boolean verifyDuration(int duration, int expectedDuration){ + if ((duration > expectedDuration * 1.1) || (duration < expectedDuration * 0.9)) + return false; + else + return true; + } + + + + //Audio + //Wait for PV bugs for MP3 duration + @MediumTest + public void testMP3CBRGetDuration() throws Exception { + int duration = CodecTest.getDuration(MediaNames.MP3CBR); + duratoinWithinTolerence = verifyDuration(duration, MediaNames.MP3CBR_LENGTH); + assertTrue("MP3CBR getDuration", duratoinWithinTolerence); + } + + @MediumTest + public void testMP3VBRGetDuration() throws Exception { + int duration = CodecTest.getDuration(MediaNames.MP3VBR); + Log.v(TAG, "getDuration"); + duratoinWithinTolerence = verifyDuration(duration, MediaNames.MP3VBR_LENGTH); + assertTrue("MP3VBR getDuration", duratoinWithinTolerence); + } + + @MediumTest + public void testMIDIGetDuration() throws Exception { + int duration = CodecTest.getDuration(MediaNames.MIDI); + duratoinWithinTolerence = verifyDuration(duration, MediaNames.MIDI_LENGTH); + assertTrue("MIDI getDuration", duratoinWithinTolerence); + } + + @MediumTest + public void testAMRGetDuration() throws Exception { + int duration = CodecTest.getDuration(MediaNames.AMR); + duratoinWithinTolerence = verifyDuration(duration, MediaNames.AMR_LENGTH); + assertTrue("AMR getDuration", duratoinWithinTolerence); + } + + /* + public void testOGGGetDuration() throws Exception { + int duration = CodecTest.getDuration(MediaNames.OGG); + duratoinWithinTolerence = verifyDuration(duration, MediaNames.OGG_LENGTH); + assertTrue("OGG getDuration", duratoinWithinTolerence); + }*/ + + + //Test cases for GetCurrentPosition + @LargeTest + public void testMP3CBRGetCurrentPosition() throws Exception { + boolean currentPosition = CodecTest.getCurrentPosition(MediaNames.MP3CBR); + assertTrue("MP3CBR GetCurrentPosition", currentPosition); + } + + @LargeTest + public void testMP3VBRGetCurrentPosition() throws Exception { + boolean currentPosition = CodecTest.getCurrentPosition(MediaNames.MP3VBR); + assertTrue("MP3VBR GetCurrentPosition", currentPosition); + } + + @LargeTest + public void testMIDIGetCurrentPosition() throws Exception { + boolean currentPosition = CodecTest.getCurrentPosition(MediaNames.MIDI); + assertTrue("MIDI GetCurrentPosition", currentPosition); + } + + @LargeTest + public void testAMRGetCurrentPosition() throws Exception { + boolean currentPosition = CodecTest.getCurrentPosition(MediaNames.AMR); + assertTrue("AMR GetCurrentPosition", currentPosition); + } + + /* + public void testOGGGetCurrentPosition() throws Exception { + boolean currentPosition = CodecTest.getCurrentPosition(MediaNames.OGG); + assertTrue("OGG GetCurrentPosition", currentPosition); + */ + + //Test cases for pause + @LargeTest + public void testMP3CBRPause() throws Exception { + boolean isPaused = CodecTest.pause(MediaNames.MP3CBR); + assertTrue("MP3CBR Pause", isPaused); + } + + @LargeTest + public void testMP3VBRPause() throws Exception { + boolean isPaused = CodecTest.pause(MediaNames.MP3VBR); + assertTrue("MP3VBR Pause", isPaused); + } + + @LargeTest + public void testMIDIPause() throws Exception { + boolean isPaused = CodecTest.pause(MediaNames.MIDI); + assertTrue("MIDI Pause", isPaused); + } + + @LargeTest + public void testAMRPause() throws Exception { + boolean isPaused = CodecTest.pause(MediaNames.AMR); + assertTrue("AMR Pause", isPaused); + } + + /* + public void testOGGPause() throws Exception { + boolean isPaused = CodecTest.pause(MediaNames.OGG); + assertTrue("OGG Pause", isPaused); + }*/ + + @MediumTest + public void testMP3CBRPrepareStopRelease() throws Exception { + CodecTest.prepareStopRelease(MediaNames.MP3CBR); + assertTrue("MP3CBR prepareStopRelease", true); + } + + @MediumTest + public void testMIDIPrepareStopRelease() throws Exception { + CodecTest.prepareStopRelease(MediaNames.MIDI); + assertTrue("MIDI prepareStopRelease", true); + } + + //One test case for seek before start + @MediumTest + public void testMP3CBRSeekBeforeStart() throws Exception { + boolean seekBeforePlay = CodecTest.seektoBeforeStart(MediaNames.MP3CBR); + assertTrue("MP3CBR SeekBeforePlay", seekBeforePlay); + } + + //Skip test - Bug# 1120249 + /* + public void testMP3CBRpreparePauseRelease() throws Exception { + CodecTest.preparePauseRelease(MediaNames.MP3CBR); + assertTrue("MP3CBR preparePauseRelease", true); + } + + public void testMIDIpreparePauseRelease() throws Exception { + CodecTest.preparePauseRelease(MediaNames.MIDI); + assertTrue("MIDI preparePauseRelease", true); + } + */ + + + //Test cases for setLooping + @LargeTest + public void testMP3CBRSetLooping() throws Exception { + boolean isLoop = CodecTest.setLooping(MediaNames.MP3CBR); + assertTrue("MP3CBR setLooping", isLoop); + } + + @LargeTest + public void testMP3VBRSetLooping() throws Exception { + boolean isLoop = CodecTest.setLooping(MediaNames.MP3VBR); + Log.v(TAG, "setLooping"); + assertTrue("MP3VBR setLooping", isLoop); + } + + @LargeTest + public void testMIDISetLooping() throws Exception { + boolean isLoop = CodecTest.setLooping(MediaNames.MIDI); + assertTrue("MIDI setLooping", isLoop); + } + + @LargeTest + public void testAMRSetLooping() throws Exception { + boolean isLoop = CodecTest.setLooping(MediaNames.AMR); + assertTrue("AMR setLooping", isLoop); + } + + /* + public void testOGGSetLooping() throws Exception { + boolean isLoop = CodecTest.setLooping(MediaNames.OGG); + assertTrue("OGG setLooping", isLoop); + } */ + + //Test cases for seekTo + @LargeTest + public void testMP3CBRSeekTo() throws Exception { + boolean isLoop = CodecTest.seekTo(MediaNames.MP3CBR); + assertTrue("MP3CBR seekTo", isLoop); + } + + @LargeTest + public void testMP3VBRSeekTo() throws Exception { + boolean isLoop = CodecTest.seekTo(MediaNames.MP3VBR); + Log.v(TAG, "seekTo"); + assertTrue("MP3VBR seekTo", isLoop); + } + + @LargeTest + public void testMIDISeekTo() throws Exception { + boolean isLoop = CodecTest.seekTo(MediaNames.MIDI); + assertTrue("MIDI seekTo", isLoop); + } + + @LargeTest + public void testAMRSeekTo() throws Exception { + boolean isLoop = CodecTest.seekTo(MediaNames.AMR); + assertTrue("AMR seekTo", isLoop); + } + + /* + public void testOGGSeekTo() throws Exception { + boolean isLoop = CodecTest.seekTo(MediaNames.OGG); + assertTrue("OGG seekTo", isLoop); + }*/ + + + //Jump to the end of the files + @LargeTest + public void testMP3CBRSeekToEnd() throws Exception { + boolean isEnd = CodecTest.seekToEnd(MediaNames.MP3CBR); + assertTrue("MP3CBR seekToEnd", isEnd); + } + + @LargeTest + public void testMP3VBRSeekToEnd() throws Exception { + boolean isEnd = CodecTest.seekToEnd(MediaNames.MP3VBR); + Log.v(TAG, "seekTo"); + assertTrue("MP3VBR seekToEnd", isEnd); + } + + @LargeTest + public void testMIDISeekToEnd() throws Exception { + boolean isEnd = CodecTest.seekToEnd(MediaNames.MIDI); + assertTrue("MIDI seekToEnd", isEnd); + } + + @LargeTest + public void testAMRSeekToEnd() throws Exception { + boolean isEnd = CodecTest.seekToEnd(MediaNames.AMR); + assertTrue("AMR seekToEnd", isEnd); + } + + /* + public void testOGGSeekToEnd() throws Exception { + boolean isEnd = CodecTest.seekToEnd(MediaNames.OGG); + assertTrue("OGG seekToEnd", isEnd); + }*/ + + @LargeTest + public void testWAVSeekToEnd() throws Exception { + boolean isEnd = CodecTest.seekToEnd(MediaNames.WAV); + assertTrue("WAV seekToEnd", isEnd); + } + + @MediumTest + public void testLargeVideoHeigth() throws Exception { + int height = 0; + height = CodecTest.videoHeight(MediaNames.VIDEO_LARGE_SIZE_3GP); + Log.v(TAG, "Video height = " + height); + assertEquals("streaming video height", 240, height); + } + + @MediumTest + public void testLargeVideoWidth() throws Exception { + int width = 0; + width = CodecTest.videoWidth(MediaNames.VIDEO_LARGE_SIZE_3GP); + Log.v(TAG, "Video width = " + width); + assertEquals("streaming video width", 320, width); + } + + @LargeTest + public void testVideoMP4SeekTo() throws Exception { + boolean isSeek = CodecTest.videoSeekTo(MediaNames.VIDEO_MP4); + assertTrue("Local MP4 SeekTo", isSeek); + } + + @LargeTest + public void testVideoH263AACSeekTo() throws Exception { + boolean isSeek = CodecTest.videoSeekTo(MediaNames.VIDEO_H263_AAC); + assertTrue("H263AAC SeekTo", isSeek); + } + + @LargeTest + public void testVideoH263AMRSeekTo() throws Exception { + boolean isSeek = CodecTest.videoSeekTo(MediaNames.VIDEO_H263_AMR); + assertTrue("H263AMR SeekTo", isSeek); + } + + @LargeTest + public void testVideoH264AACSeekTo() throws Exception { + boolean isSeek = CodecTest.videoSeekTo(MediaNames.VIDEO_H264_AAC); + assertTrue("H264AAC SeekTo", isSeek); + } + + @LargeTest + public void testVideoH264AMRSeekTo() throws Exception { + boolean isSeek = CodecTest.videoSeekTo(MediaNames.VIDEO_H264_AMR); + assertTrue("H264AMR SeekTo", isSeek); + } + + @LargeTest + public void testVideoWebmSeekTo() throws Exception { + boolean isSeek = CodecTest.videoSeekTo(MediaNames.VIDEO_WEBM); + assertTrue("WEBM SeekTo", isSeek); + } + + @LargeTest + public void testSoundRecord() throws Exception { + boolean isRecordered = CodecTest.mediaRecorderRecord(MediaNames.RECORDER_OUTPUT); + assertTrue("Recorder", isRecordered); + } + + @LargeTest + public void testGetThumbnail() throws Exception { + boolean getThumbnail = CodecTest.getThumbnail(MediaNames.VIDEO_H264_AAC, MediaNames.GOLDEN_THUMBNAIL_OUTPUT); + assertTrue("Get Thumbnail", getThumbnail); + } + + //Play a mid file which the duration is around 210 seconds + @LargeTest + public void testMidiResources() throws Exception { + boolean midiResources = CodecTest.resourcesPlayback(MediaFrameworkTest.midiafd,16000); + assertTrue("Play midi from resources", midiResources); + } + + @LargeTest + public void testMp3Resources() throws Exception { + boolean mp3Resources = CodecTest.resourcesPlayback(MediaFrameworkTest.mp3afd,25000); + assertTrue("Play mp3 from resources", mp3Resources); + } + + @MediumTest + public void testPrepareAsyncReset() throws Exception { + //assertTrue(MediaFrameworkTest.checkStreamingServer()); + boolean isReset = CodecTest.prepareAsyncReset(MediaNames.STREAM_MP3); + assertTrue("PrepareAsync Reset", isReset); + } + + @MediumTest + public void testIsLooping() throws Exception { + boolean isLooping = CodecTest.isLooping(MediaNames.AMR); + assertTrue("isLooping", isLooping); + } + + @MediumTest + public void testIsLoopingAfterReset() throws Exception { + boolean isLooping = CodecTest.isLoopingAfterReset(MediaNames.AMR); + assertTrue("isLooping after reset", isLooping); + } + + @LargeTest + public void testLocalMp3PrepareAsyncCallback() throws Exception { + boolean onPrepareSuccess = + CodecTest.prepareAsyncCallback(MediaNames.MP3CBR, false); + assertTrue("LocalMp3prepareAsyncCallback", onPrepareSuccess); + } + + @LargeTest + public void testLocalH263AMRPrepareAsyncCallback() throws Exception { + boolean onPrepareSuccess = + CodecTest.prepareAsyncCallback(MediaNames.VIDEO_H263_AMR, false); + assertTrue("testLocalH263AMRPrepareAsyncCallback", onPrepareSuccess); + } + + @LargeTest + public void testStreamPrepareAsyncCallback() throws Exception { + //assertTrue(MediaFrameworkTest.checkStreamingServer()); + boolean onPrepareSuccess = + CodecTest.prepareAsyncCallback(MediaNames.STREAM_H264_480_360_1411k, false); + assertTrue("StreamH264PrepareAsyncCallback", onPrepareSuccess); + } + + @LargeTest + public void testStreamPrepareAsyncCallbackReset() throws Exception { + //assertTrue(MediaFrameworkTest.checkStreamingServer()); + boolean onPrepareSuccess = + CodecTest.prepareAsyncCallback(MediaNames.STREAM_H264_480_360_1411k, true); + assertTrue("StreamH264PrepareAsyncCallback", onPrepareSuccess); + } +} diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/mediarecorder/MediaRecorderTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/mediarecorder/MediaRecorderTest.java new file mode 100644 index 0000000..b5c8c8c --- /dev/null +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/mediarecorder/MediaRecorderTest.java @@ -0,0 +1,302 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.mediaframeworktest.functional.mediarecorder; + +import com.android.mediaframeworktest.MediaFrameworkTest; +import com.android.mediaframeworktest.MediaNames; + +import java.io.*; + +import android.content.Context; +import android.hardware.Camera; +import android.media.MediaPlayer; +import android.media.MediaRecorder; +import android.media.EncoderCapabilities; +import android.media.EncoderCapabilities.VideoEncoderCap; +import android.media.EncoderCapabilities.AudioEncoderCap; +import android.test.ActivityInstrumentationTestCase2; +import android.util.Log; +import android.view.SurfaceHolder; +import android.view.SurfaceView; +import com.android.mediaframeworktest.MediaProfileReader; + +import android.test.suitebuilder.annotation.LargeTest; +import android.test.suitebuilder.annotation.Suppress; +import java.util.List; + + +/** + * Junit / Instrumentation test case for the media recorder api + */ +public class MediaRecorderTest extends ActivityInstrumentationTestCase2 { + private String TAG = "MediaRecorderTest"; + private int mOutputDuration =0; + private int mOutputVideoWidth = 0; + private int mOutputVideoHeight= 0 ; + + private SurfaceHolder mSurfaceHolder = null; + private MediaRecorder mRecorder; + + private int MIN_VIDEO_FPS = 5; + + Context mContext; + Camera mCamera; + + public MediaRecorderTest() { + super("com.android.mediaframeworktest", MediaFrameworkTest.class); + + } + + protected void setUp() throws Exception { + getActivity(); + mRecorder = new MediaRecorder(); + super.setUp(); + } + + private void recordVideo(int frameRate, int width, int height, + int videoFormat, int outFormat, String outFile, boolean videoOnly) { + Log.v(TAG,"startPreviewAndPrepareRecording"); + try { + if (!videoOnly) { + Log.v(TAG, "setAudioSource"); + mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); + } + mRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA); + mRecorder.setOutputFormat(outFormat); + Log.v(TAG, "output format " + outFormat); + mRecorder.setOutputFile(outFile); + mRecorder.setVideoFrameRate(frameRate); + mRecorder.setVideoSize(width, height); + Log.v(TAG, "setEncoder"); + mRecorder.setVideoEncoder(videoFormat); + if (!videoOnly) { + mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); + } + mSurfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder(); + Log.v(TAG, "setPreview"); + mRecorder.setPreviewDisplay(mSurfaceHolder.getSurface()); + Log.v(TAG, "prepare"); + mRecorder.prepare(); + Log.v(TAG, "start"); + mRecorder.start(); + Thread.sleep(MediaNames.RECORDED_TIME); + Log.v(TAG, "stop"); + mRecorder.stop(); + mRecorder.release(); + } catch (Exception e) { + Log.v("record video failed ", e.toString()); + mRecorder.release(); + } + } + + private boolean recordVideoWithPara(VideoEncoderCap videoCap, AudioEncoderCap audioCap, boolean highQuality){ + boolean recordSuccess = false; + int videoEncoder = videoCap.mCodec; + int audioEncoder = audioCap.mCodec; + int videoWidth = highQuality? videoCap.mMaxFrameWidth: videoCap.mMinFrameWidth; + int videoHeight = highQuality? videoCap.mMaxFrameHeight: videoCap.mMinFrameHeight; + int videoFps = highQuality? videoCap.mMaxFrameRate: videoCap.mMinFrameRate; + int videoBitrate = highQuality? videoCap.mMaxBitRate: videoCap.mMinBitRate; + int audioBitrate = highQuality? audioCap.mMaxBitRate: audioCap.mMinBitRate; + int audioChannels = highQuality? audioCap.mMaxChannels: audioCap.mMinChannels ; + int audioSamplingRate = highQuality? audioCap.mMaxSampleRate: audioCap.mMinSampleRate; + + if (videoFps < MIN_VIDEO_FPS) { + videoFps = MIN_VIDEO_FPS; + } + mSurfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder(); + String filename = ("/sdcard/" + videoEncoder + "_" + audioEncoder + "_" + highQuality + ".3gp"); + try { + Log.v(TAG, "video encoder : " + videoEncoder); + Log.v(TAG, "audio encoder : " + audioEncoder); + Log.v(TAG, "quality : " + (highQuality?"high": "low")); + Log.v(TAG, "encoder : " + MediaProfileReader.getVideoCodecName(videoEncoder)); + Log.v(TAG, "audio : " + MediaProfileReader.getAudioCodecName(audioEncoder)); + Log.v(TAG, "videoWidth : " + videoWidth); + Log.v(TAG, "videoHeight : " + videoHeight); + Log.v(TAG, "videoFPS : " + videoFps); + Log.v(TAG, "videobitrate : " + videoBitrate); + Log.v(TAG, "audioBitrate : " + audioBitrate); + Log.v(TAG, "audioChannel : " + audioChannels); + Log.v(TAG, "AudioSampleRate : " + audioSamplingRate); + + MediaRecorder mMediaRecorder = new MediaRecorder(); + mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); + mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA); + mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); + mMediaRecorder.setOutputFile(filename); + mMediaRecorder.setVideoFrameRate(videoFps); + mMediaRecorder.setVideoSize(videoWidth, videoHeight); + mMediaRecorder.setVideoEncodingBitRate(videoBitrate); + mMediaRecorder.setAudioEncodingBitRate(audioBitrate); + mMediaRecorder.setAudioChannels(audioChannels); + mMediaRecorder.setAudioSamplingRate(audioSamplingRate); + mMediaRecorder.setVideoEncoder(videoEncoder); + mMediaRecorder.setAudioEncoder(audioEncoder); + mMediaRecorder.setPreviewDisplay(mSurfaceHolder.getSurface()); + mMediaRecorder.prepare(); + mMediaRecorder.start(); + Thread.sleep(MediaNames.RECORDED_TIME); + mMediaRecorder.stop(); + mMediaRecorder.release(); + recordSuccess = validateVideo(filename, videoWidth, videoHeight); + } catch (Exception e) { + Log.v(TAG, e.toString()); + return false; + } + return recordSuccess; + } + + private boolean invalidRecordSetting(int frameRate, int width, int height, + int videoFormat, int outFormat, String outFile, boolean videoOnly) { + try { + if (!videoOnly) { + Log.v(TAG, "setAudioSource"); + mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); + } + mRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA); + mRecorder.setOutputFormat(outFormat); + Log.v(TAG, "output format " + outFormat); + mRecorder.setOutputFile(outFile); + mRecorder.setVideoFrameRate(frameRate); + mRecorder.setVideoSize(width, height); + Log.v(TAG, "setEncoder"); + mRecorder.setVideoEncoder(videoFormat); + if (!videoOnly) { + mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); + } + mSurfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder(); + Log.v(TAG, "setPreview"); + mRecorder.setPreviewDisplay(mSurfaceHolder.getSurface()); + Log.v(TAG, "prepare"); + mRecorder.prepare(); + Log.v(TAG, "start"); + mRecorder.start(); + Thread.sleep(MediaNames.RECORDED_TIME); + Log.v(TAG, "stop"); + mRecorder.stop(); + mRecorder.release(); + } catch (Exception e) { + Log.v("record video failed ", e.toString()); + mRecorder.release(); + Log.v(TAG, "reset and release"); + return true; + } + return false; + } + + private void getOutputVideoProperty(String outputFilePath) { + MediaPlayer mediaPlayer = new MediaPlayer(); + try { + mediaPlayer.setDataSource(outputFilePath); + Log.v(TAG, "file Path = " + outputFilePath); + mediaPlayer.setDisplay(MediaFrameworkTest.mSurfaceView.getHolder()); + Log.v(TAG, "before player prepare"); + mediaPlayer.prepare(); + Log.v(TAG, "before getduration"); + mOutputDuration = mediaPlayer.getDuration(); + Log.v(TAG, "get video dimension"); + Thread.sleep(1000); + mOutputVideoHeight = mediaPlayer.getVideoHeight(); + mOutputVideoWidth = mediaPlayer.getVideoWidth(); + mediaPlayer.release(); + } catch (Exception e) { + Log.v(TAG, e.toString()); + mediaPlayer.release(); + } + } + + private boolean validateVideo(String filePath, int width, int height) { + boolean validVideo = false; + getOutputVideoProperty(filePath); + if (mOutputVideoWidth == width && mOutputVideoHeight == height && + mOutputDuration > MediaNames.VALID_VIDEO_DURATION ) { + validVideo = true; + } + Log.v(TAG, "width = " + mOutputVideoWidth + " height = " + mOutputVideoHeight + " Duration = " + mOutputDuration); + return validVideo; + } + + @LargeTest + /* + * This test case set the camera in portrait mode. + * Verification: validate the video dimension and the duration. + */ + public void testPortraitH263() throws Exception { + boolean videoRecordedResult = false; + try { + mCamera = Camera.open(); + Camera.Parameters parameters = mCamera.getParameters(); + parameters.setPreviewSize(352, 288); + parameters.set("orientation", "portrait"); + mCamera.setParameters(parameters); + mCamera.unlock(); + mRecorder.setCamera(mCamera); + Thread.sleep(1000); + int codec = MediaRecorder.VideoEncoder.H263; + int frameRate = MediaProfileReader.getMaxFrameRateForCodec(codec); + recordVideo(frameRate, 352, 288, codec, + MediaRecorder.OutputFormat.THREE_GPP, + MediaNames.RECORDED_PORTRAIT_H263, true); + mCamera.lock(); + mCamera.release(); + videoRecordedResult = + validateVideo(MediaNames.RECORDED_PORTRAIT_H263, 352, 288); + } catch (Exception e) { + Log.v(TAG, e.toString()); + } + assertTrue("PortraitH263", videoRecordedResult); + } + + @LargeTest + public void testInvalidVideoPath() throws Exception { + boolean isTestInvalidVideoPathSuccessful = false; + isTestInvalidVideoPathSuccessful = invalidRecordSetting(15, 176, 144, MediaRecorder.VideoEncoder.H263, + MediaRecorder.OutputFormat.THREE_GPP, MediaNames.INVALD_VIDEO_PATH, false); + assertTrue("Invalid outputFile Path", isTestInvalidVideoPathSuccessful); + } + + @LargeTest + //test cases for the new codec + public void testDeviceSpecificCodec() throws Exception { + int noOfFailure = 0; + boolean recordSuccess = false; + String deviceType = MediaProfileReader.getDeviceType(); + Log.v(TAG, "deviceType = " + deviceType); + List videoEncoders = MediaProfileReader.getVideoEncoders(); + List audioEncoders = MediaProfileReader.getAudioEncoders(); + for (int k = 0; k < 2; k++) { + for (VideoEncoderCap videoEncoder: videoEncoders) { + for (AudioEncoderCap audioEncoder: audioEncoders) { + if (k == 0) { + recordSuccess = recordVideoWithPara(videoEncoder, audioEncoder, true); + } else { + recordSuccess = recordVideoWithPara(videoEncoder, audioEncoder, false); + } + if (!recordSuccess) { + Log.v(TAG, "testDeviceSpecificCodec failed"); + Log.v(TAG, "Encoder = " + videoEncoder.mCodec + "Audio Encoder = " + audioEncoder.mCodec); + noOfFailure++; + } + } + } + } + if (noOfFailure != 0) { + assertTrue("testDeviceSpecificCodec", false); + } + } +} diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/videoeditor/MediaItemThumbnailTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/videoeditor/MediaItemThumbnailTest.java new file mode 100755 index 0000000..80a3bcd --- /dev/null +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/videoeditor/MediaItemThumbnailTest.java @@ -0,0 +1,956 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +package com.android.mediaframeworktest.functional.videoeditor; + +import java.io.File; +import java.io.IOException; + +import android.graphics.Bitmap; +import android.media.videoeditor.MediaImageItem; +import android.media.videoeditor.MediaItem; +import android.media.videoeditor.MediaVideoItem; +import android.media.videoeditor.VideoEditor; +import android.os.Environment; +import android.test.ActivityInstrumentationTestCase; +import android.test.suitebuilder.annotation.LargeTest; +import com.android.mediaframeworktest.MediaFrameworkTest; +import com.android.mediaframeworktest.VideoEditorHelper; + +public class MediaItemThumbnailTest extends + ActivityInstrumentationTestCase { + private final String TAG = "MediaItemThumbailTest"; + + private final String PROJECT_LOCATION = VideoEditorHelper.PROJECT_LOCATION_COMMON; + + private final String INPUT_FILE_PATH = VideoEditorHelper.INPUT_FILE_PATH_COMMON; + + private VideoEditor mVideoEditor; + + private VideoEditorHelper mVideoEditorHelper; + + public MediaItemThumbnailTest() { + super("com.android.mediaframeworktest", MediaFrameworkTest.class); + } + + @Override + protected void setUp() throws Exception { + // setup for each test case. + super.setUp(); + mVideoEditorHelper = new VideoEditorHelper(); + // Create a random String which will be used as project path, where all + // project related files will be stored. + final String projectPath = mVideoEditorHelper. + createRandomFile(PROJECT_LOCATION); + mVideoEditor = mVideoEditorHelper.createVideoEditor(projectPath); + } + + @Override + protected void tearDown() throws Exception { + mVideoEditorHelper.destroyVideoEditor(mVideoEditor); + // Clean the directory created as project path + mVideoEditorHelper.deleteProject(new File(mVideoEditor.getPath())); + System.gc(); + super.tearDown(); + } + + protected void validateThumbnail(Bitmap thumbNailBmp, int outWidth, + int outHeight) throws Exception { + assertNotNull("Thumbnail Retrived is Null", thumbNailBmp); + assertEquals("Thumbnail Height", outHeight, thumbNailBmp.getHeight()); + assertEquals("Thumbnail Width", outWidth, thumbNailBmp.getWidth()); + thumbNailBmp.recycle(); + } + + // ----------------------------------------------------------------- + // THUMBNAIL + // ----------------------------------------------------------------- + /** + * To test thumbnail / frame extraction on H.263 QCIF. + */ + // TODO : TC_TN_001 + @LargeTest + public void testThumbnailForH263QCIF() throws Exception { + final String videoItemFilename = INPUT_FILE_PATH + + "H263_profile0_176x144_15fps_256kbps_AACLC_32kHz_128kbps_s_0_26.3gp"; + final int atTime = 0; + final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; + final MediaVideoItem mediaVideoItem = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", + videoItemFilename, renderingMode); + + final int outWidth = (mediaVideoItem.getWidth() / 2); + final int outHeight = mediaVideoItem.getHeight(); + + final Bitmap thumbNailBmp = mediaVideoItem.getThumbnail(outWidth, + outHeight, atTime); + validateThumbnail(thumbNailBmp, outWidth, outHeight); + } + + /** + * To test thumbnail / frame extraction on MPEG4 VGA . + */ + // TODO : TC_TN_002 + @LargeTest + public void testThumbnailForMPEG4VGA() throws Exception { + final String videoItemFilename = INPUT_FILE_PATH + + "MPEG4_SP_640x480_30fps_512Kbps_0_23.3gp"; + final int atTime = 0; + final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; + final MediaVideoItem mediaVideoItem = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", + videoItemFilename, renderingMode); + final int outWidth = (mediaVideoItem.getWidth() / 2); + final int outHeight = mediaVideoItem.getHeight(); + final Bitmap thumbNailBmp = mediaVideoItem.getThumbnail(outWidth, + outHeight, atTime); + validateThumbnail(thumbNailBmp, outWidth, outHeight); + } + + /** + * To test thumbnail / frame extraction on MPEG4 NTSC. + */ + // TODO : TC_TN_003 + @LargeTest + public void testThumbnailForMPEG4NTSC() throws Exception { + final String videoItemFilename = INPUT_FILE_PATH + + "MPEG4_SP_720x480_30fps_280kbps_AACLC_48kHz_96kbps_s_0_21.mp4"; + final int atTime = 0; + final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; + final MediaVideoItem mediaVideoItem = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", + videoItemFilename, renderingMode); + final int outWidth = mediaVideoItem.getWidth() / 2; + final int outHeight = mediaVideoItem.getHeight() / 2; + final Bitmap thumbNailBmp = mediaVideoItem.getThumbnail(outWidth, + outHeight, atTime); + validateThumbnail(thumbNailBmp, outWidth, outHeight); + } + + /** + * To test thumbnail / frame extraction on MPEG4 WVGA. + */ + // TODO : TC_TN_004 + @LargeTest + public void testThumbnailForMPEG4WVGA() throws Exception { + + final String videoItemFilename = INPUT_FILE_PATH + + "MPEG4_SP_800x480_515kbps_15fps_AMR_NB_8KHz_12.2kbps_m_0_26.mp4"; + final int atTime = 0; + final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; + final MediaVideoItem mediaVideoItem = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", + videoItemFilename, renderingMode); + final int outWidth = mediaVideoItem.getWidth() * 2; + final int outHeight = mediaVideoItem.getHeight(); + final Bitmap thumbNailBmp = mediaVideoItem.getThumbnail(outWidth, + outHeight, atTime); + validateThumbnail(thumbNailBmp, outWidth, outHeight); + } + + /** + * To test thumbnail / frame extraction on MPEG4 QCIF. + */ + // TODO : TC_TN_005 + @LargeTest + public void testThumbnailForMPEG4QCIF() throws Exception { + final String videoItemFilename = INPUT_FILE_PATH + + "MPEG4_SP_176x144_30fps_256kbps_AACLC_44.1kHz_96kbps_s_1_17.3gp"; + final int atTime = 0; + final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; + + final MediaVideoItem mediaVideoItem = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", + videoItemFilename, renderingMode); + final int outWidth = mediaVideoItem.getWidth(); + final int outHeight = mediaVideoItem.getHeight() * 2; + final Bitmap thumbNailBmp = mediaVideoItem.getThumbnail(outWidth, + outHeight, atTime); + validateThumbnail(thumbNailBmp, outWidth, outHeight); + } + + /** + * To test thumbnail / frame extraction on H264 QCIF. + */ + // TODO : TC_TN_006 + @LargeTest + public void testThumbnailForH264QCIF() throws Exception { + final String videoItemFilename = INPUT_FILE_PATH + + "H264_BP_176x144_15fps_144kbps_AMRNB_8kHz_12.2kbps_m_1_17.3gp"; + + final int atTime = 0; + final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; + final MediaVideoItem mediaVideoItem = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", + videoItemFilename, renderingMode); + final int outWidth = mediaVideoItem.getWidth() * 2; + final int outHeight = mediaVideoItem.getHeight() * 2; + final Bitmap thumbNailBmp = mediaVideoItem.getThumbnail(outWidth, + outHeight, atTime); + validateThumbnail(thumbNailBmp, outWidth, outHeight); + } + + /** + * To test thumbnail / frame extraction on H264 VGA. + */ + // TODO : TC_TN_007 + @LargeTest + public void testThumbnailForH264VGA() throws Exception { + final String videoItemFilename = INPUT_FILE_PATH + + "H264_BP_640x480_30fps_192kbps_1_5.mp4"; + final int outWidth = 32; + final int outHeight = 32; + final int atTime = 0; + + final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; + final MediaVideoItem mediaVideoItem = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", + videoItemFilename, renderingMode); + + final Bitmap thumbNailBmp = mediaVideoItem.getThumbnail(outWidth, + outHeight, atTime); + validateThumbnail(thumbNailBmp, outWidth, outHeight); + } + /** + * To test thumbnail / frame extraction on H264 WVGA. + */ + // TODO : TC_TN_008 + @LargeTest + public void testThumbnailForH264WVGA() throws Exception { + final String videoItemFilename = INPUT_FILE_PATH + + "H264_BP_800x480_15fps_512kbps_AACLC_24KHz_38Kbps_s_1_17.mp4"; + final int outWidth = 64; + final int outHeight = 64; + final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; + final MediaVideoItem mediaVideoItem = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", + videoItemFilename, renderingMode); + final long atTime = mediaVideoItem.getDuration() / 2; + final Bitmap thumbNailBmp = mediaVideoItem.getThumbnail(outWidth, + outHeight, atTime); + validateThumbnail(thumbNailBmp, outWidth, outHeight); + } + + /** + * To test thumbnail / frame extraction on H264 854x480. + */ + // TODO : TC_TN_009 + @LargeTest + public void testThumbnailForH264854_480() throws Exception { + final String videoItemFilename = INPUT_FILE_PATH + + "MPEG4_SP_854x480_15fps_256kbps_AACLC_16khz_48kbps_s_0_26.mp4"; + final int outWidth = 128; + final int outHeight = 128; + final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; + MediaVideoItem mediaVideoItem = null; + mediaVideoItem = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", + videoItemFilename, renderingMode); + final long atTime = mediaVideoItem.getDuration() - 1000; + final Bitmap thumbNailBmp = mediaVideoItem.getThumbnail(outWidth, + outHeight, atTime); + validateThumbnail(thumbNailBmp, outWidth, outHeight); + } + + /** + * To test thumbnail / frame extraction on H264 960x720. + */ + // TODO : TC_TN_010 + @LargeTest + public void testThumbnailForH264HD960() throws Exception { + final String videoItemFilename = INPUT_FILE_PATH + + "H264_BP_960x720_25fps_800kbps_AACLC_48Khz_192Kbps_s_1_17.mp4"; + final int outWidth = 75; + final int outHeight = 75; + + final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; + final MediaVideoItem mediaVideoItem = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", + videoItemFilename, renderingMode); + final long atTime = mediaVideoItem.getDuration() - 1000; + final Bitmap thumbNailBmp = mediaVideoItem.getThumbnail(outWidth, + outHeight, atTime); + validateThumbnail(thumbNailBmp, outWidth, outHeight); + } + + /** + * To test thumbnail / frame extraction on H264 1080x720 . + */ + // TODO : TC_TN_011 + @LargeTest + public void testThumbnailForH264HD1080() throws Exception { + final String videoItemFilename = INPUT_FILE_PATH + + "H264_BP_1080x720_30fps_800kbps_1_17.mp4"; + final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; + final MediaVideoItem mediaVideoItem = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", + videoItemFilename, renderingMode); + final int outWidth = mediaVideoItem.getWidth() / 2; + final int outHeight = mediaVideoItem.getHeight() / 2; + final long atTime = mediaVideoItem.getDuration() / 4; + final Bitmap thumbNailBmp = mediaVideoItem.getThumbnail(outWidth, + outHeight, atTime); + validateThumbnail(thumbNailBmp, outWidth, outHeight); + } + + /** + * Check the thumbnail / frame extraction precision at 0,100 and 200 ms + */ + // TODO : TC_TN_012 + @LargeTest + public void testThumbnailForH264VGADifferentDuration() throws Exception { + final String videoItemFilename = INPUT_FILE_PATH + + "H264_BP_640x480_30fps_256kbps_1_17.mp4"; + final int atTime = 0; + final int atTime1 = 100; + final int atTime2 = 200; + final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; + + final MediaVideoItem mediaVideoItem = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", + videoItemFilename, renderingMode); + final int outWidth = mediaVideoItem.getWidth(); + final int outHeight = mediaVideoItem.getHeight(); + + final Bitmap thumbNailBmp = mediaVideoItem.getThumbnail(outWidth, + outHeight, atTime); + validateThumbnail(thumbNailBmp, outWidth, outHeight); + + // get Thumbnail @ 100ms + final Bitmap thumbNailBmpAt100 = + mediaVideoItem.getThumbnail(outWidth, outHeight, atTime1); + validateThumbnail(thumbNailBmpAt100, outWidth, outHeight); + + // get Thumbnail @ 200ms + final Bitmap thumbNailBmpAt200 = mediaVideoItem.getThumbnail( + outWidth, outHeight, atTime2); + validateThumbnail(thumbNailBmpAt200, outWidth, outHeight); + } + + /** + *Check the thumbnail / frame extraction precision at + * FileDuration,FileDuration/2 + 100 andFileDuration/2 + 200 ms + */ + // TODO : TC_TN_013 + @LargeTest + public void testThumbnailForMP4VGA() throws Exception { + final String videoItemFilename = INPUT_FILE_PATH + + "MPEG4_SP_640x480_15fps_256kbps_0_30.mp4"; + final MediaVideoItem mediaVideoItem = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", + videoItemFilename, MediaItem.RENDERING_MODE_BLACK_BORDER); + + final int outWidth = mediaVideoItem.getWidth(); + final int outHeight = mediaVideoItem.getHeight(); + final long atTime = mediaVideoItem.getDuration() / 2; + final long atTime1 = atTime + 100; + final long atTime2 = atTime + 200; + + // get Thumbnail @ duration/2 + final Bitmap thumbNailBmp = mediaVideoItem.getThumbnail(outWidth, + outHeight, atTime); + validateThumbnail(thumbNailBmp, outWidth, outHeight); + + // get Thumbnail @ duration/2 + 100ms + final Bitmap thumbNailBmpAt100 = mediaVideoItem.getThumbnail( + outWidth, outHeight, atTime1); + validateThumbnail(thumbNailBmpAt100, outWidth, outHeight); + + // get Thumbnail @ duration/2 + 200ms + final Bitmap thumbNailBmpAt200 = mediaVideoItem.getThumbnail( + outWidth, outHeight, atTime2); + validateThumbnail(thumbNailBmpAt200, outWidth, outHeight); + } + + /** + * Check the thumbnail / frame extraction on JPEG file + */ + // TODO : TC_TN_014 + @LargeTest + public void testThumbnailForImage() throws Exception { + final String imageItemFilename = INPUT_FILE_PATH + "IMG_640x480.jpg"; + final int mediaDuration = 1000; + final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; + boolean flagForException = false; + int outWidth = 0; + int outHeight = 0; + + final MediaImageItem mii = mVideoEditorHelper.createMediaItem( + mVideoEditor, "m1", imageItemFilename, mediaDuration, renderingMode); + assertNotNull("Media Image Item is Null", mii); + outWidth = mii.getWidth() / 2; + outHeight = mii.getHeight() / 2; + + final Bitmap thumbNailBmp = mii.getThumbnail(outWidth, + outHeight, mediaDuration); + validateThumbnail(thumbNailBmp, outWidth, outHeight); + } + /** + *To test ThumbnailList for H263 QCIF + */ + // TODO : TC_TN_015 + @LargeTest + public void testThumbnailListH263QCIF() throws Exception { + final String videoItemFilename = INPUT_FILE_PATH + + "H263_profile0_176x144_15fps_256kbps_AACLC_32kHz_128kbps_s_1_17.3gp"; + final int startTime = 0; + final int tnCount = 10; + final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; + final MediaVideoItem mediaVideoItem = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", + videoItemFilename, renderingMode); + + final int outWidth = mediaVideoItem.getWidth() / 4; + final int outHeight = mediaVideoItem.getHeight() / 4; + final long endTime = mediaVideoItem.getDuration() / 2; + + final Bitmap thumbNailBmp[] = mediaVideoItem.getThumbnailList( + outWidth, outHeight, startTime, endTime, tnCount); + assertNotNull("Thumbnail Retrived is Null", thumbNailBmp); + assertEquals("Thumbnail Count", tnCount, thumbNailBmp.length); + + for (int i = 0; i < thumbNailBmp.length; i++) { + validateThumbnail(thumbNailBmp[i], outWidth, outHeight); + thumbNailBmp[i] = null; + } + } + + /** + *To test ThumbnailList for MPEG4 QCIF + */ + // TODO : TC_TN_016 + @LargeTest + public void testThumbnailListMPEG4QCIF() throws Exception { + final String videoItemFilename = INPUT_FILE_PATH + + "MPEG4_SP_176x144_30fps_256kbps_AACLC_44.1kHz_96kbps_s_1_17.3gp"; + final int tnCount = 10; + final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; + + final MediaVideoItem mediaVideoItem = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", + videoItemFilename, renderingMode); + + final int outWidth = mediaVideoItem.getWidth() / 2; + final int outHeight = mediaVideoItem.getHeight() / 2; + final long startTime = mediaVideoItem.getDuration() / 2; + final long endTime = mediaVideoItem.getDuration(); + + final Bitmap thumbNailBmp[] = mediaVideoItem.getThumbnailList( + outWidth, outHeight, startTime, endTime, tnCount); + + assertNotNull("Thumbnail Retrived is Null", thumbNailBmp); + assertEquals("Thumbnail Count", tnCount, thumbNailBmp.length); + for (int i = 0; i < thumbNailBmp.length; i++) { + validateThumbnail(thumbNailBmp[i], outWidth, outHeight); + thumbNailBmp[i] = null; + } + } + + /** + *To test ThumbnailList for H264 VGA + */ + // TODO : TC_TN_017 + @LargeTest + public void testThumbnailListH264VGA() throws Exception { + final String videoItemFilename = INPUT_FILE_PATH + + "H264_BP_640x480_30fps_256kbps_1_17.mp4"; + final int tnCount = 10; + final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; + final MediaVideoItem mediaVideoItem = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", + videoItemFilename, renderingMode); + + final int outWidth = mediaVideoItem.getWidth() / 2; + final int outHeight = mediaVideoItem.getHeight() / 2; + final long startTime = mediaVideoItem.getDuration() / 3; + final long endTime = mediaVideoItem.getDuration() / 2; + + final Bitmap thumbNailBmp[] = mediaVideoItem.getThumbnailList( + outWidth, outHeight, startTime, endTime, tnCount); + assertNotNull("Thumbnail Retrived is Null", thumbNailBmp); + assertEquals("Thumbnail Count", tnCount, thumbNailBmp.length); + for (int i = 0; i < thumbNailBmp.length; i++) { + validateThumbnail(thumbNailBmp[i], outWidth, outHeight); + thumbNailBmp[i] = null; + } + } + + /** + *To test ThumbnailList for H264 WVGA + */ + // TODO : TC_TN_018 + @LargeTest + public void testThumbnailListH264WVGA() throws Exception { + final String videoItemFilename = INPUT_FILE_PATH + + "H264_BP_800x480_15fps_512kbps_AACLC_24KHz_38Kbps_s_1_17.mp4"; + final int tnCount = 10; + final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; + final MediaVideoItem mediaVideoItem = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", + videoItemFilename, renderingMode); + + final int outWidth = mediaVideoItem.getWidth() / 2; + final int outHeight = mediaVideoItem.getHeight() / 2; + final long startTime = mediaVideoItem.getDuration() / 3; + final long endTime = mediaVideoItem.getDuration() / 2; + + final Bitmap thumbNailBmp[] = mediaVideoItem.getThumbnailList( + outWidth, outHeight, startTime, endTime, tnCount); + assertNotNull("Thumbnail Retrived is Null", thumbNailBmp); + assertEquals("Thumbnail Count", tnCount, thumbNailBmp.length); + for (int i = 0; i < thumbNailBmp.length; i++) { + validateThumbnail(thumbNailBmp[i], outWidth, outHeight); + thumbNailBmp[i] = null; + } + } + + /** + *To test ThumbnailList for H264 VGA ,Time exceeding file duration + */ + // TODO : TC_TN_019 + @LargeTest + public void testThumbnailH264VGAExceedingFileDuration() throws Exception { + final String videoItemFilename = INPUT_FILE_PATH + + "H264_BP_640x480_30fps_256kbps_1_17.mp4"; + boolean flagForException = false; + int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; + + try { + final MediaVideoItem mediaVideoItem = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", + videoItemFilename, renderingMode); + final int outWidth = mediaVideoItem.getWidth() / 2; + final int outHeight = mediaVideoItem.getHeight() / 2; + final long atTime = mediaVideoItem.getDuration() + 2000; + mediaVideoItem.getThumbnail(outWidth, outHeight, atTime); + } catch (IllegalArgumentException e) { + flagForException = true; + } + assertTrue("Exception in Extracting thumbanil with Invalid Time", + flagForException); + } + + /** + *To test ThumbnailList for VGA Image + */ + // TODO : TC_TN_020 + @LargeTest + public void testThumbnailListVGAImage() throws Exception { + final String imageItemFilename = INPUT_FILE_PATH + "IMG_640x480.jpg"; + final int imageItemDuration = 10000; + final int startTime = 0; + final int endTime = 0; + final int tnCount = 10; + final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; + + final MediaImageItem mediaImageItem = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", + imageItemFilename, imageItemDuration, renderingMode); + final int outWidth = mediaImageItem.getWidth() / 2; + final int outHeight = mediaImageItem.getHeight() / 2; + + final Bitmap thumbNailBmp[] = mediaImageItem.getThumbnailList + (outWidth, outHeight, startTime, endTime, tnCount); + assertNotNull("Thumbnail Retrived is Null", thumbNailBmp); + assertEquals("Thumbnail Count", tnCount, thumbNailBmp.length); + for (int i = 0; i < thumbNailBmp.length; i++) { + validateThumbnail(thumbNailBmp[i], outWidth, outHeight); + thumbNailBmp[i] = null; + } + } + + /** + *To test ThumbnailList for Invalid file path + */ + // TODO : TC_TN_021 + @LargeTest + public void testThumbnailForInvalidFilePath() throws Exception { + final String imageItemFileName = INPUT_FILE_PATH + "/sdcard/abc.jpg"; + final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; + boolean flagForException = false; + try{ + final MediaImageItem mii = new MediaImageItem(mVideoEditor, "m1", + imageItemFileName, 3000, renderingMode); + } catch (IllegalArgumentException e) { + flagForException = true; + } catch (IOException e) { + flagForException = true; + } + assertTrue(" Invalid File Path", flagForException); + } + + /** + * To test thumbnail / frame extraction with setBoundaries + */ + // TODO : TC_TN_022 + @LargeTest + public void testThumbnailForMPEG4WVGAWithSetBoundaries() throws Exception { + final String videoItemFilename = INPUT_FILE_PATH + + "MPEG4_SP_800x480_515kbps_15fps_AMR_NB_8KHz_12.2kbps_m_0_26.mp4"; + final int atTime = 10000; + final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; + final MediaVideoItem mediaVideoItem = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", + videoItemFilename, renderingMode); + + mediaVideoItem.setExtractBoundaries(1000, + (mediaVideoItem.getDuration() - 21000)); + + final int outWidth = (mediaVideoItem.getWidth() / 2); + final int outHeight = (mediaVideoItem.getHeight() / 2); + final Bitmap thumbNailBmp = mediaVideoItem.getThumbnail(outWidth, + outHeight, atTime); + validateThumbnail(thumbNailBmp, outWidth, outHeight); + } + + /** + *To test ThumbnailList for H264 WVGA with setExtractboundaries + */ + // TODO : TC_TN_023 + @LargeTest + public void testThumbnailListForH264WVGAWithSetBoundaries() throws Exception { + final String videoItemFilename = INPUT_FILE_PATH + + "H264_BP_800x480_15fps_512kbps_1_17.mp4"; + final int thumbNailStartTime = 10000; + final int thumbNailEndTime = 12000; + final int tnCount = 10; + final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; + final MediaVideoItem mediaVideoItem = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", + videoItemFilename, renderingMode); + + final int outWidth = (mediaVideoItem.getWidth() / 2); + final int outHeight = (mediaVideoItem.getHeight() / 2); + + mediaVideoItem.setExtractBoundaries(10000, 12000); + + final Bitmap thumbNailBmp[] = mediaVideoItem.getThumbnailList + (outWidth, outHeight, thumbNailStartTime, thumbNailEndTime, + tnCount); + assertNotNull("Thumbnail Retrived is Null", thumbNailBmp); + assertTrue("Thumbnail Size", (thumbNailBmp.length > 0) ? true : false); + for (int i = 0; i < thumbNailBmp.length; i++) { + validateThumbnail(thumbNailBmp[i], outWidth, outHeight); + thumbNailBmp[i] = null; + } + } + + /** + *To test ThumbnailList for H264 WVGA with count > frame available + */ + // TODO : TC_TN_024 + @LargeTest + public void testThumbnailListForH264WVGAWithCount() throws Exception { + final String videoItemFilename = INPUT_FILE_PATH + + "H264_BP_800x480_15fps_512kbps_AACLC_24KHz_38Kbps_s_1_17.mp4"; + final int tnCount = 70; + final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; + final MediaVideoItem mediaVideoItem = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", + videoItemFilename, renderingMode); + + final int outWidth = (mediaVideoItem.getWidth() / 2); + final int outHeight = (mediaVideoItem.getHeight() / 2); + final long thumbNailStartTime = mediaVideoItem.getDuration() / 2; + final long thumbNailEndTime = thumbNailStartTime + 4000; + Bitmap thumbNailBmp[] = null; + boolean flagForException = false; + try{ + thumbNailBmp = mediaVideoItem.getThumbnailList(outWidth, outHeight, + thumbNailStartTime, thumbNailEndTime, tnCount); + }catch (Exception e){ + assertTrue("Unable to get Thumbnail list", flagForException); + } + if (thumbNailBmp.length <= tnCount) { + flagForException = true; + } + assertTrue("Thumbnail count more than asked", flagForException); + } + + /** + *To test ThumbnailList for H264 WVGA with startTime > End Time + */ + // TODO : TC_TN_025 + @LargeTest + public void testThumbnailListH264WVGAWithStartGreaterEnd() throws Exception { + final String videoItemFilename = INPUT_FILE_PATH + + "H264_BP_800x480_15fps_512kbps_AACLC_24KHz_38Kbps_s_1_17.mp4"; + final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; + final int tnCount = 10; + boolean flagForException = false; + final MediaVideoItem mediaVideoItem = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", + videoItemFilename, renderingMode); + final int outWidth = (mediaVideoItem.getWidth() / 2); + final int outHeight = (mediaVideoItem.getHeight() / 2); + final long thumbNailStartTime = mediaVideoItem.getDuration() / 2; + final long thumbNailEndTime = thumbNailStartTime - 1000; + try{ + mediaVideoItem.getThumbnailList(outWidth, outHeight, + thumbNailStartTime, thumbNailEndTime, tnCount); + } catch (IllegalArgumentException e) { + flagForException = true; + } + assertTrue("Thumbnail Extraction where start time > end time", + flagForException); + } + + /** + *To test ThumbnailList TC_TN_026 for H264 WVGA with startTime = End Time + */ + // TODO : TC_TN_026 + @LargeTest + public void testThumbnailListH264WVGAWithStartEqualEnd() throws Exception { + final String videoItemFilename = INPUT_FILE_PATH + + "H264_BP_800x480_15fps_512kbps_AACLC_24KHz_38Kbps_s_1_17.mp4"; + final int tnCount = 1; + final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; + + final MediaVideoItem mediaVideoItem = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", + videoItemFilename, renderingMode); + final int outWidth = (mediaVideoItem.getWidth() / 2); + final int outHeight = (mediaVideoItem.getHeight() / 2); + final long thumbNailStartTime = mediaVideoItem.getDuration() / 2; + final long thumbNailEndTime = thumbNailStartTime; + final Bitmap thumbNailBmp[] = mediaVideoItem.getThumbnailList(outWidth, + outHeight, thumbNailStartTime, thumbNailEndTime, tnCount); + assertNotNull("Thumbnail Retrived is Null", thumbNailBmp); + assertEquals("Thumbnail Count", tnCount, thumbNailBmp.length); + for (int i = 0; i < thumbNailBmp.length; i++) { + validateThumbnail(thumbNailBmp[i], outWidth, outHeight); + thumbNailBmp[i] = null; + } + } + + /** + *To test ThumbnailList TC_TN_027 for file where video duration is less + * than file duration. + */ + // TODO : TC_TN_027 + @LargeTest + public void testThumbnailForVideoDurationLessFileDuration() throws Exception { + final String videoItemFilename = INPUT_FILE_PATH + + "H264_BP_640x480_15fps_1200Kbps_AACLC_48KHz_64kps_m_0_27.3gp"; + final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; + final MediaVideoItem mediaVideoItem = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", + videoItemFilename, renderingMode); + final int outWidth = (mediaVideoItem.getWidth() / 2); + final int outHeight = (mediaVideoItem.getHeight() / 2); + final long atTime = mediaVideoItem.getDuration() - 2000; + final Bitmap thumbNailBmp = mediaVideoItem.getThumbnail (outWidth, + outHeight, atTime); + validateThumbnail(thumbNailBmp, outWidth, outHeight); + + } + + /** + *To test ThumbnailList TC_TN_028 for file which has video part corrupted + */ + // TODO : TC_TN_028 + @LargeTest + public void testThumbnailWithCorruptedVideoPart() throws Exception { + final String videoItemFilename = INPUT_FILE_PATH + + "corrupted_H264_BP_640x480_12.5fps_256kbps_AACLC_16khz_24kbps_s_0_26.mp4"; + final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; + boolean flagForException = false; + + try { + final MediaVideoItem mediaVideoItem = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", + videoItemFilename, renderingMode); + final int outWidth = mediaVideoItem.getWidth(); + final int outHeight = mediaVideoItem.getHeight() * 2; + final Bitmap thumbNailBmp = mediaVideoItem.getThumbnail + (outWidth, outHeight, mediaVideoItem.getDuration()/2); + } catch (IllegalArgumentException e) { + flagForException = true; + } + assertTrue("Corrupted File cannot be read", flagForException); + } + + /** + * Check the thumbnail / frame list extraction for Height as Negative Value + */ + // TODO : TC_TN_029 + @LargeTest + public void testThumbnailWithNegativeHeight() throws Exception { + final String videoItemFilename = INPUT_FILE_PATH + + "MPEG4_SP_176x144_30fps_256kbps_AACLC_44.1kHz_96kbps_s_1_17.3gp"; + final int tnCount = 10; + final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; + boolean flagForException = false; + try { + final MediaVideoItem mediaVideoItem = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", + videoItemFilename, renderingMode); + final int outWidth = (mediaVideoItem.getWidth() / 2); + final int outHeight = -1; + final long thumbNailStartTime = + mediaVideoItem.getBoundaryBeginTime()/2; + final long thumbNailEndTime = mediaVideoItem.getBoundaryEndTime(); + mediaVideoItem.getThumbnailList(outWidth, outHeight, + thumbNailStartTime, thumbNailEndTime, tnCount); + } catch (IllegalArgumentException e) { + flagForException = true; + } + assertTrue("Thumbnail List with negative Height", flagForException); + } + + /** + * Check the thumbnail for Height as Zero + */ + // TODO : TC_TN_030 + @LargeTest + public void testThumbnailWithHeightAsZero() throws Exception { + final String videoItemFilename = INPUT_FILE_PATH + + "MPEG4_SP_176x144_30fps_256kbps_AACLC_44.1kHz_96kbps_s_1_17.3gp"; + final int atTime = 100; + final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; + boolean flagForException = false; + try { + final MediaVideoItem mediaVideoItem = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", + videoItemFilename, renderingMode); + final int outWidth = (mediaVideoItem.getWidth() / 2); + final int outHeight = -1; + mediaVideoItem.getThumbnail(outWidth, outHeight, atTime); + } catch (IllegalArgumentException e) { + flagForException = true; + } + assertTrue("Thumbnail List with Zero Height", flagForException); + } + + /** + * Check the thumbnail for Height = 10 + */ + // TODO : TC_TN_031 + @LargeTest + public void testThumbnailWithHeight() throws Exception { + final String videoItemFilename = INPUT_FILE_PATH + + "MPEG4_SP_176x144_30fps_256kbps_AACLC_44.1kHz_96kbps_s_1_17.3gp"; + final int atTime = 1000; + final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; + final MediaVideoItem mediaVideoItem = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", + videoItemFilename, renderingMode); + final int outWidth = (mediaVideoItem.getWidth() / 2); + final int outHeight = 10; + final Bitmap thumbNailBmp = mediaVideoItem.getThumbnail (outWidth, + outHeight, atTime); + validateThumbnail(thumbNailBmp, outWidth, outHeight); + } + + /** + * Check the thumbnail / frame list extraction for Width as Negative Value + */ + // TODO : TC_TN_032 + @LargeTest + public void testThumbnailWithNegativeWidth() throws Exception { + final String videoItemFilename = INPUT_FILE_PATH + + "MPEG4_SP_176x144_30fps_256kbps_AACLC_44.1kHz_96kbps_s_1_17.3gp"; + final int tnCount = 10; + final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; + boolean flagForException = false; + try { + final MediaVideoItem mediaVideoItem = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", + videoItemFilename, renderingMode); + final int outWidth = -1; + final int outHeight = mediaVideoItem.getHeight(); + final long thumbNailStartTime = + mediaVideoItem.getBoundaryBeginTime()/2; + final long thumbNailEndTime = mediaVideoItem.getBoundaryEndTime(); + mediaVideoItem.getThumbnailList(outWidth, outHeight, thumbNailStartTime, + thumbNailEndTime, tnCount); + } catch (IllegalArgumentException e) { + flagForException = true; + } + assertTrue("Thumbnail List with negative Height", flagForException); + } + + /** + * Check the thumbnail / frame list extraction for Width zero + */ + // TODO : TC_TN_033 + @LargeTest + public void testThumbnailWithWidthAsZero() throws Exception { + final String videoItemFilename = INPUT_FILE_PATH + + "MPEG4_SP_176x144_30fps_256kbps_AACLC_44.1kHz_96kbps_s_1_17.3gp"; + final int atTime = 1000; + final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; + boolean flagForException = false; + try { + final MediaVideoItem mediaVideoItem = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", + videoItemFilename, renderingMode); + final int outWidth = 0; + final int outHeight = mediaVideoItem.getHeight() / 2; + mediaVideoItem.getThumbnail(outWidth, outHeight, atTime); + } catch (IllegalArgumentException e) { + flagForException = true; + } + assertTrue("Thumbnail List with Zero Width", flagForException); + } + + /** + * Check the thumbnail for Width = 10 + */ + // TODO : TC_TN_034 + @LargeTest + public void testThumbnailWithWidth() throws Exception { + final String videoItemFilename = INPUT_FILE_PATH + + "MPEG4_SP_176x144_30fps_256kbps_AACLC_44.1kHz_96kbps_s_1_17.3gp"; + final int atTime = 1000; + final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; + final MediaVideoItem mediaVideoItem = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", + videoItemFilename, renderingMode); + final int outWidth = 10; + final int outHeight = mediaVideoItem.getHeight(); + final Bitmap thumbNailBmp = mediaVideoItem.getThumbnail (outWidth, + outHeight, atTime); + validateThumbnail(thumbNailBmp, outWidth, outHeight); + } + + /** + * To test thumbnail / frame extraction on MPEG4 (time beyond file duration). + */ + // TODO : TC_TN_035 + @LargeTest + public void testThumbnailMPEG4withMorethanFileDuration() throws Exception { + final String videoItemFilename = INPUT_FILE_PATH + + "MPEG4_SP_176x144_30fps_256kbps_AACLC_44.1kHz_96kbps_s_1_17.3gp"; + boolean flagForException = false; + final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; + final MediaVideoItem mediaVideoItem = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", + videoItemFilename, renderingMode); + final int outWidth = mediaVideoItem.getWidth()/2; + final int outHeight = mediaVideoItem.getHeight()/2; + final long atTime = mediaVideoItem.getDuration() + 100; + try{ + final Bitmap thumbNailBmp = mediaVideoItem.getThumbnail (outWidth, + outHeight, atTime); + } catch (IllegalArgumentException e) { + flagForException = true; + } + assertTrue("Thumbnail duration is more than file duration", + flagForException); + } +} diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/videoeditor/MediaPropertiesTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/videoeditor/MediaPropertiesTest.java new file mode 100755 index 0000000..e2f6863 --- /dev/null +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/videoeditor/MediaPropertiesTest.java @@ -0,0 +1,774 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.mediaframeworktest.functional.videoeditor; + +import java.io.File; +import java.io.IOException; + +import android.media.videoeditor.AudioTrack; +import android.media.videoeditor.MediaImageItem; +import android.media.videoeditor.MediaItem; +import android.media.videoeditor.MediaProperties; +import android.media.videoeditor.MediaVideoItem; +import android.media.videoeditor.VideoEditor; +import android.os.Environment; +import android.test.ActivityInstrumentationTestCase; +import android.test.suitebuilder.annotation.LargeTest; +import com.android.mediaframeworktest.MediaFrameworkTest; +import com.android.mediaframeworktest.VideoEditorHelper; +import com.android.mediaframeworktest.MediaProfileReader; + +public class MediaPropertiesTest extends + ActivityInstrumentationTestCase { + private final String TAG = "MediaPropertiesTest"; + + private final String PROJECT_LOCATION = VideoEditorHelper.PROJECT_LOCATION_COMMON; + + private final String INPUT_FILE_PATH = VideoEditorHelper.INPUT_FILE_PATH_COMMON; + + private VideoEditor mVideoEditor; + + private VideoEditorHelper mVideoEditorHelper; + + public MediaPropertiesTest() { + super("com.android.mediaframeworktest", MediaFrameworkTest.class); + } + + @Override + protected void setUp() throws Exception { + // setup for each test case. + super.setUp(); + mVideoEditorHelper = new VideoEditorHelper(); + // Create a random String which will be used as project path, + // where all project related files will be stored. + final String projectPath = mVideoEditorHelper. + createRandomFile(PROJECT_LOCATION); + mVideoEditor = mVideoEditorHelper.createVideoEditor(projectPath); + } + + @Override + protected void tearDown() throws Exception { + mVideoEditorHelper.destroyVideoEditor(mVideoEditor); + // Clean the directory created as project path + mVideoEditorHelper.deleteProject(new File(mVideoEditor.getPath())); + System.gc(); + super.tearDown(); + } + + protected void validateVideoProperties(int aspectRatio, int fileType, + int videoCodecType, int duration, int videoBitrate, int fps, + int videoProfile, int videoLevel, int width, int height, int audioCodecType, + int audioSamplingFrequency, int audioChannel, int audioBitrate, + MediaVideoItem mvi) throws Exception { + assertEquals("Aspect Ratio Mismatch", aspectRatio, mvi.getAspectRatio()); + assertEquals("File Type Mismatch", fileType, mvi.getFileType()); + assertEquals("VideoCodec Mismatch", videoCodecType, mvi.getVideoType()); + + assertTrue("Video duration Mismatch", mVideoEditorHelper.checkRange ( + duration, mvi.getDuration(), 10)); + assertEquals("Video Profile " + mvi.getVideoProfile(), videoProfile, + mvi.getVideoProfile()); + assertEquals("Video Level " + mvi.getVideoLevel(), videoLevel, + mvi.getVideoLevel()); + assertEquals("Video height " + mvi.getHeight(), height, mvi.getHeight()); + assertEquals("Video width " + mvi.getWidth(), width, mvi.getWidth()); + /** Check FPS with 10% range */ + assertTrue("fps Mismatch" + mvi.getFps(), + mVideoEditorHelper.checkRange(fps, mvi.getFps(), 10)); + + assertEquals("AudioType Mismatch ", audioCodecType, mvi.getAudioType()); + assertEquals("Audio Sampling " + mvi.getAudioSamplingFrequency(), + audioSamplingFrequency, mvi.getAudioSamplingFrequency()); + // PV SW AAC codec always returns number of channels as Stereo. + // So we do not assert for number of audio channels for AAC_LC + if ( audioCodecType != MediaProperties.ACODEC_AAC_LC ) { + assertEquals("Audio Channels " + mvi.getAudioChannels(), audioChannel, + mvi.getAudioChannels()); + } + } + + protected void validateAudioProperties(int audioCodecType, int duration, + int audioSamplingFrequency, int audioChannel, int audioBitrate, + AudioTrack aT) throws Exception { + assertEquals("AudioType Mismatch ", audioCodecType, aT.getAudioType()); + assertTrue("Video duration Mismatch", mVideoEditorHelper.checkRange ( + duration, aT.getDuration(), 10)); + assertEquals("Audio Sampling " + aT.getAudioSamplingFrequency(), + audioSamplingFrequency, aT.getAudioSamplingFrequency()); + // PV SW AAC codec always returns number of channels as Stereo. + // So we do not assert for number of audio channels for AAC_LC + if ( audioCodecType != MediaProperties.ACODEC_AAC_LC ) { + assertEquals("Audio Channels " + aT.getAudioChannels(), audioChannel, + aT.getAudioChannels()); + } + } + + protected void validateImageProperties(int aspectRatio, int fileType, + int width, int height, MediaImageItem mii) + throws Exception { + assertEquals("Aspect Ratio Mismatch", aspectRatio, mii.getAspectRatio()); + assertEquals("File Type Mismatch", fileType, mii.getFileType()); + assertEquals("Image height " + mii.getHeight(), height, mii.getHeight()); + assertEquals("Image width " + mii.getWidth(), width, mii.getWidth()); + } + + + /** + *To test Media Properties for file MPEG4 854 x 480 + */ + // TODO : Remove TC_MP_001 + @LargeTest + public void testPropertiesMPEG4854_480() throws Exception { + final String videoItemFilename = INPUT_FILE_PATH + + "MPEG4_SP_854x480_15fps_256kbps_AACLC_16khz_48kbps_s_0_26.mp4"; + final int aspectRatio = MediaProperties.ASPECT_RATIO_16_9; + final int fileType = MediaProperties.FILE_MP4; + final int videoCodecType = MediaProperties.VCODEC_MPEG4; + final int duration = 26933; + final int videoBitrate = 319000; + final int audioBitrate = 48000; + final int fps = 15; + final int audioCodecType = MediaProperties.ACODEC_AAC_LC; + final int audioSamplingFrequency = 16000; + final int audioChannel = 2; + final int videoProfile = MediaProperties.MPEG4Profile.MPEG4ProfileSimple; + final int videoLevel = MediaProperties.MPEG4Level.MPEG4Level1; + final int width = 854; + final int height = MediaProperties.HEIGHT_480; + + final MediaVideoItem mvi = mVideoEditorHelper.createMediaItem + (mVideoEditor, "m1", videoItemFilename, + MediaItem.RENDERING_MODE_BLACK_BORDER); + + validateVideoProperties(aspectRatio, fileType, videoCodecType, duration, + videoBitrate, fps, videoProfile, videoLevel, width, height, audioCodecType, + audioSamplingFrequency, audioChannel, audioBitrate, mvi); + } + + + /** + *To test Media Properties for file MPEG4 WVGA + */ + // TODO : Remove TC_MP_002 + @LargeTest + public void testPropertiesMPEGWVGA() throws Exception { + final String videoItemFilename = INPUT_FILE_PATH + + "MPEG4_SP_800x480_515kbps_15fps_AMR_NB_8KHz_12.2kbps_m_0_26.mp4"; + final int aspectRatio = MediaProperties.ASPECT_RATIO_5_3; + final int fileType = MediaProperties.FILE_MP4; + final int videoCodecType = MediaProperties.VCODEC_MPEG4; + final int duration = 26933; + final int videoBitrate = 384000; + final int audioBitrate = 12800; + final int fps = 15; + final int audioCodecType = MediaProperties.ACODEC_AMRNB; + final int audioSamplingFrequency = 8000; + final int audioChannel = 1; + final int videoProfile = MediaProperties.MPEG4Profile.MPEG4ProfileSimple; + final int videoLevel = MediaProperties.MPEG4Level.MPEG4Level1; + final int width = 800; + final int height = MediaProperties.HEIGHT_480; + final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; + + final MediaVideoItem mvi = mVideoEditorHelper.createMediaItem + (mVideoEditor, "m1", videoItemFilename, renderingMode); + + validateVideoProperties(aspectRatio, fileType, videoCodecType, duration, + videoBitrate, fps, videoProfile, videoLevel, width, height, audioCodecType, + audioSamplingFrequency, audioChannel, audioBitrate, mvi); + } + + /** + *To test media properties for MPEG4 720x480 (NTSC) + AAC file. + */ + // TODO : Remove TC_MP_003 + @LargeTest + public void testPropertiesMPEGNTSC() throws Exception { + final String videoItemFilename = INPUT_FILE_PATH + + "MPEG4_SP_720x480_30fps_280kbps_AACLC_48kHz_161kbps_s_0_26.mp4"; + final int aspectRatio = MediaProperties.ASPECT_RATIO_3_2; + final int fileType = MediaProperties.FILE_MP4; + final int videoCodecType = MediaProperties.VCODEC_MPEG4; + final int duration = 26866; + final int videoBitrate = 403000; + final int audioBitrate = 160000; + final int fps = 30; + final int audioCodecType = MediaProperties.ACODEC_AAC_LC; + final int audioSamplingFrequency = 48000; + final int audioChannel = 2; + final int videoProfile = MediaProperties.MPEG4Profile.MPEG4ProfileSimple; + final int videoLevel = MediaProperties.MPEG4Level.MPEG4Level1; + final int width = 720; + final int height = MediaProperties.HEIGHT_480; + final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; + + final MediaVideoItem mvi = mVideoEditorHelper.createMediaItem + (mVideoEditor, "m1", videoItemFilename, renderingMode); + + validateVideoProperties(aspectRatio, fileType, videoCodecType, duration, + videoBitrate, fps, videoProfile, videoLevel, width, height, audioCodecType, + audioSamplingFrequency, audioChannel, audioBitrate, mvi); + } + + /** + *To test Media Properties for file MPEG4 VGA + */ + // TODO : Remove TC_MP_004 + @LargeTest + public void testPropertiesMPEGVGA() throws Exception { + final String videoItemFilename = INPUT_FILE_PATH + + "MPEG4_SP_640x480_15fps_512kbps_AACLC_48khz_132kbps_s_0_26.mp4"; + final int aspectRatio = MediaProperties.ASPECT_RATIO_4_3; + final int fileType = MediaProperties.FILE_MP4; + final int videoCodecType = MediaProperties.VCODEC_MPEG4; + final int duration = 26933; + final int videoBitrate = 533000; + final int audioBitrate = 128000; + final int fps = 15; + final int audioCodecType = MediaProperties.ACODEC_AAC_LC; + final int audioSamplingFrequency = 48000; + final int audioChannel = 2; + final int videoProfile = MediaProperties.MPEG4Profile.MPEG4ProfileSimple; + final int videoLevel = MediaProperties.MPEG4Level.MPEG4Level1; + final int width = 640; + final int height = MediaProperties.HEIGHT_480; + final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; + + final MediaVideoItem mvi = mVideoEditorHelper.createMediaItem + (mVideoEditor, "m1", videoItemFilename, renderingMode); + + validateVideoProperties(aspectRatio, fileType, videoCodecType, duration, + videoBitrate, fps, videoProfile, videoLevel, width, height, audioCodecType, + audioSamplingFrequency, audioChannel, audioBitrate, mvi); + } + + /** + *To test Media Properties for file MPEG4 QCIF + */ + // TODO : Remove TC_MP_005 + @LargeTest + public void testPropertiesMPEGQCIF() throws Exception { + final String videoItemFilename = INPUT_FILE_PATH + + "MPEG4_SP_176x144_12fps_92kbps_AMRNB_8KHz_12.2kbps_m_0_27.3gp"; + final int aspectRatio = MediaProperties.ASPECT_RATIO_11_9; + final int fileType = MediaProperties.FILE_3GP; + final int videoCodecType = MediaProperties.VCODEC_MPEG4; + final int duration = 27000; + final int videoBitrate = 384000; + final int audioBitrate = 12200; + final int fps = 12; + final int audioCodecType = MediaProperties.ACODEC_AMRNB; + final int audioSamplingFrequency = 8000; + final int audioChannel = 1; + final int videoProfile = MediaProperties.MPEG4Profile.MPEG4ProfileSimple; + final int videoLevel = MediaProperties.MPEG4Level.MPEG4Level1; + final int width = 176; + final int height = MediaProperties.HEIGHT_144; + final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; + + final MediaVideoItem mvi = mVideoEditorHelper.createMediaItem + (mVideoEditor, "m1", videoItemFilename, renderingMode); + + validateVideoProperties(aspectRatio, fileType, videoCodecType, duration, + videoBitrate, fps, videoProfile, videoLevel, width, height, audioCodecType, + audioSamplingFrequency, audioChannel, audioBitrate, mvi); + } + + /** + *To To test media properties for H263 176x144 (QCIF) + AAC (mono) file. + */ + // TODO : Remove TC_MP_006 + @LargeTest + public void testPropertiesH263QCIF() throws Exception { + final String videoItemFilename = INPUT_FILE_PATH + + "H263_profile0_176x144_15fps_256kbps_AACLC_16kHz_32kbps_m_0_26.3gp"; + final int aspectRatio = MediaProperties.ASPECT_RATIO_11_9; + final int fileType = MediaProperties.FILE_3GP; + final int videoCodecType = MediaProperties.VCODEC_H263; + final int duration = 26933; + final int videoBitrate = 384000; + final int audioBitrate = 64000; + final int fps = 15; + final int audioCodecType = MediaProperties.ACODEC_AAC_LC; + final int audioSamplingFrequency = 16000; + final int audioChannel = 1; + final int videoProfile = MediaProperties.H263Profile.H263ProfileBaseline; + final int videoLevel = MediaProperties.H263Level.H263Level10; + final int width = 176; + final int height = MediaProperties.HEIGHT_144; + final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; + final MediaVideoItem mvi = mVideoEditorHelper.createMediaItem + (mVideoEditor, "m1", videoItemFilename, renderingMode); + + validateVideoProperties(aspectRatio, fileType, videoCodecType, duration, + videoBitrate, fps, videoProfile, videoLevel, width, height, audioCodecType, + audioSamplingFrequency, audioChannel, audioBitrate, mvi); + } + + /** + *To test Media Properties for file H264 VGA + */ + // TODO : Remove TC_MP_007 + @LargeTest + public void testPropertiesH264VGA() throws Exception { + final String videoItemFilename = INPUT_FILE_PATH + + "H264_BP_640x480_15fps_1200Kbps_AACLC_48KHz_64kps_m_0_27.3gp"; + final int aspectRatio = MediaProperties.ASPECT_RATIO_4_3; + final int fileType = MediaProperties.FILE_3GP; + final int videoCodecType = MediaProperties.VCODEC_H264; + final int duration = 77600; + final int videoBitrate = 745000; + final int audioBitrate = 64000; + final int fps = 15; + final int audioCodecType = MediaProperties.ACODEC_AAC_LC; + final int audioSamplingFrequency = 48000; + final int audioChannel = 2; + final int videoProfile = MediaProperties.H264Profile.H264ProfileBaseline; + final int videoLevel = MediaProperties.H264Level.H264Level13; + final int width = 640; + final int height = MediaProperties.HEIGHT_480; + final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; + final MediaVideoItem mvi = mVideoEditorHelper.createMediaItem + (mVideoEditor, "m1", videoItemFilename, renderingMode); + + validateVideoProperties(aspectRatio, fileType, videoCodecType, duration, + videoBitrate, fps, videoProfile, videoLevel, width, height, audioCodecType, + audioSamplingFrequency, audioChannel, audioBitrate, mvi); + } + + /** + *To test Media Properties for file H264 NTSC + */ + // TODO : Remove TC_MP_008 + @LargeTest + public void testPropertiesH264NTSC() throws Exception { + final String videoItemFilename = INPUT_FILE_PATH + + "H264_BP_720x480_25fps_256kbps_AMRNB_8khz_12.2kbps_m_0_26.mp4"; + final int aspectRatio = MediaProperties.ASPECT_RATIO_3_2; + final int fileType = MediaProperties.FILE_MP4; + final int videoCodecType = MediaProperties.VCODEC_H264; + final int duration = 26880; + final int videoBitrate = 244000; + final int audioBitrate = 12200; + final int fps = 25; + final int audioCodecType = MediaProperties.ACODEC_AMRNB; + final int audioSamplingFrequency = 8000; + final int audioChannel = 1; + final int videoProfile = MediaProperties.H264Profile.H264ProfileBaseline; + final int videoLevel = MediaProperties.H264Level.H264Level13; + final int width = 720; + final int height = MediaProperties.HEIGHT_480; + final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; + + final MediaVideoItem mvi = mVideoEditorHelper.createMediaItem + (mVideoEditor, "m1", videoItemFilename, renderingMode); + + validateVideoProperties(aspectRatio, fileType, videoCodecType, duration, + videoBitrate, fps, videoProfile, videoLevel, width, height, audioCodecType, + audioSamplingFrequency, audioChannel, audioBitrate, mvi); + } + + /** + *To test media properties for H264 800x480 (WVGA) + AAC file. + */ + // TODO : Remove TC_MP_009 + @LargeTest + public void testPropertiesH264WVGA() throws Exception { + final String videoItemFilename = INPUT_FILE_PATH + + "H264_BP_800x480_15fps_512kbps_AACLC_24KHz_38Kbps_s_1_17.mp4"; + final int aspectRatio = MediaProperties.ASPECT_RATIO_5_3; + final int fileType = MediaProperties.FILE_MP4; + final int videoCodecType = MediaProperties.VCODEC_H264; + final int duration = 77466; + final int videoBitrate = 528000; + final int audioBitrate = 38000; + final int fps = 15; + final int audioCodecType = MediaProperties.ACODEC_AAC_LC; + final int audioSamplingFrequency = 24000; + final int audioChannel = 2; + final int videoProfile = MediaProperties.H264Profile.H264ProfileBaseline; + final int videoLevel = MediaProperties.H264Level.H264Level13; + final int width = 800; + final int height = MediaProperties.HEIGHT_480; + final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; + + final MediaVideoItem mvi = mVideoEditorHelper.createMediaItem + (mVideoEditor, "m1", videoItemFilename, renderingMode); + + validateVideoProperties(aspectRatio, fileType, videoCodecType, duration, + videoBitrate, fps, videoProfile, videoLevel, width, height, audioCodecType, + audioSamplingFrequency, audioChannel, audioBitrate, mvi); + } + + /** + *To test Media Properties for file H264 HD1280 + */ + // TODO : Remove TC_MP_010 + @LargeTest + public void testPropertiesH264HD1280() throws Exception { + final String videoItemFilename = INPUT_FILE_PATH + + "H264_BP_1280x720_15fps_512kbps_AACLC_16khz_48kbps_s_1_17.mp4"; + final int aspectRatio = MediaProperties.ASPECT_RATIO_16_9; + final int fileType = MediaProperties.FILE_MP4; + final int videoCodecType = MediaProperties.VCODEC_H264; + final int duration = 77600; + final int videoBitrate = 606000; + final int audioBitrate = 48000; + final int fps = 15; + final int audioCodecType = MediaProperties.ACODEC_AAC_LC; + final int audioSamplingFrequency = 16000; + final int audioChannel = 2; + final int videoProfile = MediaProperties.H264Profile.H264ProfileBaseline; + final int videoLevel = MediaProperties.H264Level.H264Level13; + final int width = 1280; + final int height = MediaProperties.HEIGHT_720; + final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; + + final MediaVideoItem mvi = mVideoEditorHelper.createMediaItem + (mVideoEditor, "m1", videoItemFilename, renderingMode); + + validateVideoProperties(aspectRatio, fileType, videoCodecType, duration, + videoBitrate, fps, videoProfile, videoLevel, width, height, audioCodecType, + audioSamplingFrequency, audioChannel, audioBitrate, mvi); + } + + /** + *To test media properties for H264 1080x720 + AAC file + */ + // TODO : Remove TC_MP_011 + @LargeTest + public void testPropertiesH264HD1080WithAudio() throws Exception { + final String videoItemFilename = INPUT_FILE_PATH + + "H264_BP_1080x720_30fps_12Mbps_AACLC_44.1khz_64kbps_s_1_17.mp4"; + final int aspectRatio = MediaProperties.ASPECT_RATIO_3_2; + final int fileType = MediaProperties.FILE_MP4; + final int videoCodecType = MediaProperties.VCODEC_H264; + final int duration = 77500; + final int videoBitrate = 1190000; + final int audioBitrate = 64000; + final int fps = 10; + final int audioCodecType = MediaProperties.ACODEC_AAC_LC; + final int audioSamplingFrequency = 44100; + final int audioChannel = 2; + final int videoProfile = MediaProperties.H264Profile.H264ProfileBaseline; + final int videoLevel = MediaProperties.H264Level.H264Level13; + final int width = 1080; + final int height = MediaProperties.HEIGHT_720; + final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; + + final MediaVideoItem mvi = mVideoEditorHelper.createMediaItem + (mVideoEditor, "m1", videoItemFilename, renderingMode); + + validateVideoProperties(aspectRatio, fileType, videoCodecType, duration, + videoBitrate, fps, videoProfile, videoLevel, width, height, audioCodecType, + audioSamplingFrequency, audioChannel, audioBitrate, mvi); + } + + /** + *To test Media Properties for file WMV - Unsupported type + */ + // TODO : Remove TC_MP_012 + @LargeTest + public void testPropertiesWMVFile() throws Exception { + final String videoItemFilename = INPUT_FILE_PATH + + "WMV_V7_640x480_15fps_512Kbps_wma_V9_44khz_48Kbps_s_1_30.wmv"; + boolean flagForException = false; + if (MediaProfileReader.getWMVEnable() == false) { + flagForException = true; + } else { + try { + new MediaVideoItem(mVideoEditor, "m1", videoItemFilename, + MediaItem.RENDERING_MODE_BLACK_BORDER); + } catch (IllegalArgumentException e) { + flagForException = true; + } catch (IOException e) { + flagForException = true; + } + } + assertTrue("Media Properties for a WMV File -- Unsupported file type", + flagForException); + } + + /** + *To test media properties for H.264 Main/Advanced profile. + */ + // TODO : Remove TC_MP_013 + @LargeTest + public void testPropertiesH264MainLineProfile() throws Exception { + final String videoItemFilename = INPUT_FILE_PATH + + "H264_MP_960x720_25fps_800kbps_AACLC_48Khz_192Kbps_s_1_17.mp4"; + final int aspectRatio = MediaProperties.ASPECT_RATIO_4_3; + final int videoCodecType = MediaProperties.VCODEC_H264; + final int fileType = MediaProperties.FILE_MP4; + final int duration = 77500; + final int videoBitrate = 800000; + final int audioBitrate = 192000; + final int fps = 25; + final int audioCodecType = MediaProperties.ACODEC_AAC_LC; + final int audioSamplingFrequency = 48000; + final int audioChannel = 2; + final int videoProfile = MediaProperties.H264Profile.H264ProfileMain; + final int videoLevel = MediaProperties.H264Level.H264Level31; + final int width = 960; + final int height = MediaProperties.HEIGHT_720; + final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; + + final MediaVideoItem mvi = mVideoEditorHelper.createMediaItem + (mVideoEditor, "m1", videoItemFilename, renderingMode); + + validateVideoProperties(aspectRatio, fileType, videoCodecType, duration, + videoBitrate, fps, videoProfile, videoLevel, width, height, audioCodecType, + audioSamplingFrequency, audioChannel, audioBitrate, mvi); + + } + + /** + *To test Media Properties for non existing file. + */ + // TODO : Remove TC_MP_014 + @LargeTest + public void testPropertiesForNonExsitingFile() throws Exception { + final String videoItemFilename = INPUT_FILE_PATH + "abc.3gp"; + boolean flagForException = false; + + try { + new MediaVideoItem(mVideoEditor, "m1", videoItemFilename, + MediaItem.RENDERING_MODE_BLACK_BORDER); + } catch (IllegalArgumentException e) { + flagForException = true; + } catch (IOException e) { + flagForException = true; + } + assertTrue("Media Properties for non exsisting file", flagForException); + } + + /** + *To test Media Properties for file H264 HD1080 + */ + // TODO : Remove TC_MP_015 + @LargeTest + public void testPropertiesH264HD1080WithoutAudio() throws Exception { + final String videoItemFilename = INPUT_FILE_PATH + + "H264_BP_1080x720_30fps_800kbps_1_17.mp4"; + final int aspectRatio = MediaProperties.ASPECT_RATIO_3_2; + final int fileType = MediaProperties.FILE_MP4; + final int videoCodecType = MediaProperties.VCODEC_H264; + final int duration = 77366; + final int videoBitrate = 859000; + final int audioBitrate = 0; + final int fps = 30; + final int audioCodecType = -1; + final int audioSamplingFrequency = 0; + final int audioChannel = 0; + final int videoProfile = MediaProperties.H264Profile.H264ProfileBaseline; + final int videoLevel = MediaProperties.H264Level.H264Level13; + final int width = 1080; + final int height = MediaProperties.HEIGHT_720; + final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; + + final MediaVideoItem mvi = mVideoEditorHelper.createMediaItem + (mVideoEditor, "m1", videoItemFilename, renderingMode); + + validateVideoProperties(aspectRatio, fileType, videoCodecType, duration, + videoBitrate, fps, videoProfile, videoLevel, width, height, audioCodecType, + audioSamplingFrequency, audioChannel, audioBitrate, mvi); + } + + /** + *To test Media Properties for Image file of JPEG Type + */ + // TODO : Remove TC_MP_016 + @LargeTest + public void testPropertiesVGAImage() throws Exception { + final String imageItemFilename = INPUT_FILE_PATH + "IMG_640x480.jpg"; + final int imageItemDuration = 10000; + final int aspectRatio = MediaProperties.ASPECT_RATIO_4_3; + final int fileType = MediaProperties.FILE_JPEG; + final int width = 640; + final int height = MediaProperties.HEIGHT_480; + final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; + + final MediaImageItem mii = mVideoEditorHelper.createMediaItem + (mVideoEditor, "m1", imageItemFilename, imageItemDuration, + renderingMode); + validateImageProperties(aspectRatio, fileType, width, height, mii); + } + + /** + *To test Media Properties for Image file of PNG Type + */ + // TODO : Remove TC_MP_017 + @LargeTest + public void testPropertiesPNG() throws Exception { + final String imageItemFilename = INPUT_FILE_PATH + "IMG_640x480.png"; + final int imageItemDuration = 10000; + final int aspectRatio = MediaProperties.ASPECT_RATIO_4_3; + final int fileType = MediaProperties.FILE_PNG; + final int width = 640; + final int height = 480; + final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; + final MediaImageItem mii = mVideoEditorHelper.createMediaItem + (mVideoEditor, "m1", imageItemFilename, imageItemDuration, + renderingMode); + validateImageProperties(aspectRatio, fileType, width, height, mii); + } + + /** + *To test Media Properties for file GIF - Unsupported type + */ + // TODO : Remove TC_MP_018 + @LargeTest + public void testPropertiesGIFFile() throws Exception { + + final String imageItemFilename = INPUT_FILE_PATH + "IMG_640x480.gif"; + final int imageItemDuration = 10000; + final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; + boolean flagForException = false; + try { + new MediaImageItem(mVideoEditor, "m1", imageItemFilename, + imageItemDuration, renderingMode); + } catch (IllegalArgumentException e) { + flagForException = true; + } + assertTrue("Media Properties for a GIF File -- Unsupported file type", + flagForException); + } + + /** + *To test Media Properties for file Text file named as 3GP + */ + // TODO : Remove TC_MP_019 + @LargeTest + public void testPropertiesofDirtyFile() throws Exception { + + final String videoItemFilename = INPUT_FILE_PATH + + "Text_FileRenamedTo3gp.3gp"; + boolean flagForException = false; + + try { + new MediaVideoItem(mVideoEditor, "m1", videoItemFilename, + MediaItem.RENDERING_MODE_BLACK_BORDER); + } catch (IllegalArgumentException e) { + flagForException = true; + } + assertTrue("Media Properties for a Dirty File ", + flagForException); + } + + /** + *To test Media Properties for file name as NULL + */ + // TODO : Remove TC_MP_020 + @LargeTest + public void testPropertieNULLFile() throws Exception { + final String videoItemFilename = null; + boolean flagForException = false; + final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; + try { + new MediaVideoItem(mVideoEditor, "m1", videoItemFilename, + renderingMode); + } catch (IllegalArgumentException e) { + flagForException = true; + } + assertTrue("Media Properties for NULL File ", + flagForException); + } + + /** + *To test Media Properties for file which is of type MPEG2 + */ + // TODO : Remove TC_MP_021 + @LargeTest + public void testPropertiesMPEG2File() throws Exception { + final String videoItemFilename = INPUT_FILE_PATH + + "MPEG2_640x480_30fps_192kbps_1_5.mp4"; + boolean flagForException = false; + final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; + try { + new MediaVideoItem(mVideoEditor, "m1", videoItemFilename, + renderingMode); + } catch (IllegalArgumentException e) { + flagForException = true; + } + assertTrue("Media Properties for a MPEG2 File --Unsupported file type", + flagForException); + } + + /** + *To test Media Properties TC_MP_023 for file without Video only Audio + */ + // TODO : Remove TC_MP_023 + @LargeTest + public void testProperties3GPWithoutVideoMediaItem() throws Exception { + final String audioFilename = INPUT_FILE_PATH + + "AACLC_48KHz_256Kbps_s_1_17.3gp"; + boolean flagForException = false; + final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; + try { + new MediaVideoItem(mVideoEditor, "m1", audioFilename, + renderingMode); + } catch (IllegalArgumentException e) { + flagForException = true; + } + assertTrue("Exception in Creaing Media Video item object without video", + flagForException); + } + + /** + *To test media properties for Audio Track file. (No Video, AAC Audio) + */ + // TODO : Remove TC_MP_024 + @LargeTest + public void testProperties3GPWithoutVideoAudioTrack() throws Exception { + + final String audioFilename = INPUT_FILE_PATH + + "AACLC_44.1kHz_256kbps_s_1_17.mp4"; + final int duration = 77554; + final int audioBitrate = 384000; + final int audioCodecType = MediaProperties.ACODEC_AAC_LC; + final int audioSamplingFrequency = 44100; + final int audioChannel = 2; + + final AudioTrack audioTrack = mVideoEditorHelper.createAudio + (mVideoEditor, "a1", audioFilename); + + validateAudioProperties(audioCodecType, duration, audioSamplingFrequency, + audioChannel, audioBitrate, audioTrack); + } + + /** + *To test media properties for Audio Track file. MP3 file + */ + // TODO : Remove TC_MP_025 + @LargeTest + public void testPropertiesMP3AudioTrack() throws Exception { + + final String audioFilename = INPUT_FILE_PATH + + "MP3_48KHz_128kbps_s_1_17.mp3"; + final int duration = 77640; + final int audioBitrate = 128000; + final int audioCodecType = MediaProperties.ACODEC_MP3; + final int audioSamplingFrequency = 48000; + final int audioChannel = 2; + + final AudioTrack audioTrack = mVideoEditorHelper.createAudio + (mVideoEditor, "a1", audioFilename); + + validateAudioProperties(audioCodecType, duration, audioSamplingFrequency, + audioChannel, audioBitrate, audioTrack); + } +} diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/videoeditor/VideoEditorAPITest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/videoeditor/VideoEditorAPITest.java new file mode 100644 index 0000000..b32d865 --- /dev/null +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/videoeditor/VideoEditorAPITest.java @@ -0,0 +1,2802 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.mediaframeworktest.functional.videoeditor; + +import java.io.File; +import java.util.List; + +import android.graphics.Bitmap; +import android.graphics.Rect; +import android.media.videoeditor.AudioTrack; +import android.media.videoeditor.EffectColor; +import android.media.videoeditor.EffectKenBurns; +import android.media.videoeditor.ExtractAudioWaveformProgressListener; +import android.media.videoeditor.MediaImageItem; +import android.media.videoeditor.MediaItem; +import android.media.videoeditor.MediaProperties; +import android.media.videoeditor.MediaVideoItem; +import android.media.videoeditor.OverlayFrame; +import android.media.videoeditor.Transition; +import android.media.videoeditor.TransitionAlpha; +import android.media.videoeditor.TransitionCrossfade; +import android.media.videoeditor.TransitionFadeBlack; +import android.media.videoeditor.TransitionSliding; +import android.media.videoeditor.VideoEditor; +import android.os.Environment; +import android.test.ActivityInstrumentationTestCase; +import android.media.videoeditor.VideoEditor.MediaProcessingProgressListener; + +import android.util.Log; +import java.lang.annotation.Annotation; + +import com.android.mediaframeworktest.MediaFrameworkTest; +import android.test.suitebuilder.annotation.LargeTest; +import com.android.mediaframeworktest.VideoEditorHelper; + +public class VideoEditorAPITest extends + ActivityInstrumentationTestCase { + private final String TAG = "VideoEditorTest"; + + private final String PROJECT_LOCATION = VideoEditorHelper.PROJECT_LOCATION_COMMON; + + private final String INPUT_FILE_PATH = VideoEditorHelper.INPUT_FILE_PATH_COMMON; + + private final String PROJECT_CLASS_NAME = + "android.media.videoeditor.VideoEditorImpl"; + private VideoEditor mVideoEditor; + private VideoEditorHelper mVideoEditorHelper; + + public VideoEditorAPITest() { + super("com.android.mediaframeworktest", MediaFrameworkTest.class); + } + + @Override + protected void setUp() throws Exception { + // setup for each test case. + super.setUp(); + mVideoEditorHelper = new VideoEditorHelper(); + // Create a random String which will be used as project path, where all + // project related files will be stored. + final String projectPath = mVideoEditorHelper. + createRandomFile(PROJECT_LOCATION); + mVideoEditor = mVideoEditorHelper.createVideoEditor(projectPath); + } + + @Override + protected void tearDown() throws Exception { + mVideoEditorHelper.destroyVideoEditor(mVideoEditor); + // Clean the directory created as project path + mVideoEditorHelper.deleteProject(new File(mVideoEditor.getPath())); + System.gc(); + super.tearDown(); + } + + /** + * To Test Creation of Media Video Item. + */ + // TODO : remove TC_API_001 + @LargeTest + public void testMediaVideoItem() throws Exception { + final String videoItemFileName = INPUT_FILE_PATH + + "H263_profile0_176x144_15fps_256kbps_AACLC_32kHz_128kbps_s_0_26.3gp"; + final int videoItemRenderingMode = + MediaItem.RENDERING_MODE_BLACK_BORDER; + + final MediaVideoItem mediaVideoItem1 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "mediaVideoItem1", + videoItemFileName, videoItemRenderingMode); + + assertTrue("Media Video ID", + mediaVideoItem1.getId().equals("mediaVideoItem1")); + assertTrue("Media Video Filename", + mediaVideoItem1.getFilename().equals(videoItemFileName)); + assertEquals("Media Video Rendering Mode", + videoItemRenderingMode, mediaVideoItem1.getRenderingMode()); + assertEquals("Media Video Item Duration", mediaVideoItem1.getDuration(), + mediaVideoItem1.getTimelineDuration()); + assertEquals("Media Video Overlay", 0, + mediaVideoItem1.getAllOverlays().size()); + assertEquals("Media Video Effect", 0, + mediaVideoItem1.getAllEffects().size()); + assertNull("Media Video Begin transition", + mediaVideoItem1.getBeginTransition()); + assertNull("Media Video End transition", + mediaVideoItem1.getEndTransition()); + mediaVideoItem1.setExtractBoundaries(1000,11000); + boolean flagForException = false; + if (mediaVideoItem1.getDuration() != + mediaVideoItem1.getTimelineDuration()) { + flagForException = true; + } + assertTrue("Media Video Item Duration & Timeline are same", + flagForException ); + } + + /** + * To test creation of Media Video Item with Set Extract Boundaries With Get + * the Begin and End Time. + */ + // TODO : remove TC_API_002 + @LargeTest + public void testMediaVideoItemExtractBoundaries() throws Exception { + final String videoItemFileName = INPUT_FILE_PATH + + "H263_profile0_176x144_15fps_256kbps_AACLC_32kHz_128kbps_s_0_26.3gp"; + final int videoItemRenderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; + boolean flagForException = false; + final MediaVideoItem mediaVideoItem1 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "mediaVideoItem1", + videoItemFileName, videoItemRenderingMode); + mVideoEditor.addMediaItem(mediaVideoItem1); + + mediaVideoItem1.setExtractBoundaries(1000, 11000); + assertEquals("Media Item Duration = StoryBoard Duration", + mediaVideoItem1.getTimelineDuration(), mVideoEditor.getDuration()); + try { + mediaVideoItem1.setExtractBoundaries(0, 100000000); + } catch (IllegalArgumentException e) { + flagForException = true; + } + assertTrue("Set Extract with Invalid Values endTime > FileDuration", + flagForException); + + flagForException = false; + try { + mediaVideoItem1.setExtractBoundaries(100000000, 11000); + } catch (IllegalArgumentException e) { + flagForException = true; + } + assertTrue("Set Extract with Invalid Values startTime > endTime", + flagForException); + + flagForException = false; + try { + mediaVideoItem1.setExtractBoundaries(0, 0); + } catch (IllegalArgumentException e) { + flagForException = true; + } + assertTrue("Set Extract with Invalid Values startTime = endTime", + flagForException); + + mediaVideoItem1.setExtractBoundaries(1000, 10000); + assertTrue("Media Item Duration is still the same", + (mediaVideoItem1.getTimelineDuration() == + (mediaVideoItem1.getBoundaryEndTime()- + mediaVideoItem1.getBoundaryBeginTime())) ? true : false); + + mediaVideoItem1.setExtractBoundaries(1,mediaVideoItem1.getDuration()-1); + assertEquals("Media Item Start Time", 1, + mediaVideoItem1.getBoundaryBeginTime()); + assertEquals("Media Item End Time", (mediaVideoItem1.getDuration() - 1), + mediaVideoItem1.getBoundaryEndTime()); + + mediaVideoItem1.setExtractBoundaries(1, mediaVideoItem1.getDuration()); + assertEquals("Media Item Duration = StoryBoard Duration", + mediaVideoItem1.getTimelineDuration(), mVideoEditor.getDuration()); + + mediaVideoItem1.setExtractBoundaries(0,mediaVideoItem1.getDuration()/2); + assertEquals("Media Item Duration = StoryBoard Duration", + mediaVideoItem1.getTimelineDuration(), mVideoEditor.getDuration()); + + mediaVideoItem1.setExtractBoundaries(0, -1); + assertEquals("Media Item Duration = StoryBoard Duration", + mediaVideoItem1.getTimelineDuration(), mVideoEditor.getDuration()); + } + + /** + * To test creation of Media Video Item with Set and Get rendering Mode + */ + // TODO : remove TC_API_003 + @LargeTest + public void testMediaVideoItemRenderingModes() throws Exception { + final String videoItemFileName = INPUT_FILE_PATH + + "H263_profile0_176x144_15fps_256kbps_AACLC_32kHz_128kbps_s_0_26.3gp"; + final int videoItemRenderingMode= MediaItem.RENDERING_MODE_BLACK_BORDER; + boolean flagForException = false; + final MediaVideoItem mediaVideoItem1 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "mediaVideoItem1", + videoItemFileName, videoItemRenderingMode); + mVideoEditor.addMediaItem(mediaVideoItem1); + mediaVideoItem1.setRenderingMode(MediaItem.RENDERING_MODE_CROPPING); + assertEquals("MediaVideo Item rendering Mode", + MediaItem.RENDERING_MODE_CROPPING, + mediaVideoItem1.getRenderingMode()); + try { + mediaVideoItem1.setRenderingMode( + MediaItem.RENDERING_MODE_CROPPING + 911); + } catch (IllegalArgumentException e) { + flagForException = true; + } + assertTrue("Media Item Invalid rendering Mode", flagForException); + flagForException = false; + try { + mediaVideoItem1.setRenderingMode( + MediaItem.RENDERING_MODE_BLACK_BORDER - 11); + } catch (IllegalArgumentException e) { + flagForException = true; + } + assertTrue("Media Item Invalid rendering Mode", flagForException); + assertEquals("MediaVideo Item rendering Mode", + MediaItem.RENDERING_MODE_CROPPING, + mediaVideoItem1.getRenderingMode()); + mediaVideoItem1.setRenderingMode(MediaItem.RENDERING_MODE_STRETCH); + assertEquals("MediaVideo Item rendering Mode", + MediaItem.RENDERING_MODE_STRETCH, + mediaVideoItem1.getRenderingMode()); + } + + /** Test Case TC_API_004 is removed */ + + /** + * To Test the Media Video API : Set Audio Volume, Get Audio Volume and Mute + */ + // TODO : remove TC_API_005 + @LargeTest + public void testMediaVideoItemAudioFeatures() throws Exception { + final String videoItemFileName = INPUT_FILE_PATH + + "H263_profile0_176x144_15fps_256kbps_AACLC_32kHz_128kbps_s_0_26.3gp"; + final int videoItemRenderingMode =MediaItem.RENDERING_MODE_BLACK_BORDER; + boolean flagForException = false; + final MediaVideoItem mediaVideoItem1 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "mediaVideoItem1", + videoItemFileName, videoItemRenderingMode); + mVideoEditor.addMediaItem(mediaVideoItem1); + mediaVideoItem1.setVolume(77); + assertEquals("Updated Volume is 77", 77, mediaVideoItem1.getVolume()); + + mediaVideoItem1.setMute(true); + assertTrue("Audio must be Muted", mediaVideoItem1.isMuted()); + + mediaVideoItem1.setVolume(78); + assertEquals("Updated Volume is 78", 78, mediaVideoItem1.getVolume()); + assertTrue("Audio must be Muted", mediaVideoItem1.isMuted()); + + try { + mediaVideoItem1.setVolume(1000); + } catch (IllegalArgumentException e) { + flagForException = true; + } + assertTrue("Invalid Set Volume", flagForException); + + mediaVideoItem1.setMute(false); + assertFalse("Audio must be Un-Muted", mediaVideoItem1.isMuted()); + + mediaVideoItem1.setVolume(0); + assertFalse("Audio must be Un-Muted", mediaVideoItem1.isMuted()); + + flagForException = false; + try { + mediaVideoItem1.setVolume(-1); + } catch (IllegalArgumentException e) { + flagForException = true; + } + assertTrue("Invalid Set Volume", flagForException); + + mediaVideoItem1.setVolume(100); + assertEquals("MediaItem Volume", 100, mediaVideoItem1.getVolume()); + try { + mediaVideoItem1.setVolume(101); + } catch (IllegalArgumentException e) { + flagForException = true; + } + assertTrue("Invalid Set Volume", flagForException); + assertEquals("MediaItem Volume", 100, mediaVideoItem1.getVolume()); + } + + /** + * To Test the Media Video API : GetWaveFormData and + * extractAudioWaveFormData + */ + + // TODO : remove TC_API_006 + @LargeTest + public void testMediaVideoItemGetWaveformData() throws Exception { + + final String videoItemFileName = INPUT_FILE_PATH + + "H263_profile0_176x144_15fps_256kbps_AACLC_32kHz_128kbps_s_0_26.3gp"; + final int videoItemRenderingMode =MediaItem.RENDERING_MODE_BLACK_BORDER; + final MediaVideoItem mediaVideoItem1 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "mediaVideoItem1", + videoItemFileName, videoItemRenderingMode); + mVideoEditor.addMediaItem(mediaVideoItem1); + + assertNull("WaveForm data", mediaVideoItem1.getWaveformData()); + final int[] progressWaveform = new int[105]; + + mediaVideoItem1.extractAudioWaveform(new + ExtractAudioWaveformProgressListener() { + int i = 0; + public void onProgress(int progress) { + Log.i("WaveformData","progress=" +progress); + progressWaveform[i++] = progress; + } + }); + assertTrue("Progress of WaveForm data", mVideoEditorHelper + .checkProgressCBValues(progressWaveform)); + assertNotNull("WaveForm data", mediaVideoItem1.getWaveformData()); + assertTrue("WaveForm Frame Duration", + (mediaVideoItem1.getWaveformData().getFrameDuration() > 0? + true : false)); + assertTrue("WaveForm Frame Count", + (mediaVideoItem1.getWaveformData().getFramesCount() > 0 ? + true : false)); + assertTrue("WaveForm Gain", + (mediaVideoItem1.getWaveformData().getFrameGains().length > 0 ? + true : false)); + + } + + /** + * To Test the Media Video API : Get Effect, GetAllEffects, remove Effect + */ + + // TODO : remove TC_API_007 + @LargeTest + public void testMediaVideoItemEffect() throws Exception { + final String videoItemFileName = INPUT_FILE_PATH + + "H263_profile0_176x144_15fps_256kbps_AACLC_32kHz_128kbps_s_0_26.3gp"; + final int videoItemRenderingMode =MediaItem.RENDERING_MODE_BLACK_BORDER; + final MediaVideoItem mediaVideoItem1 = mVideoEditorHelper. + createMediaItem(mVideoEditor, "mediaVideoItem1", videoItemFileName, + videoItemRenderingMode); + mVideoEditor.addMediaItem(mediaVideoItem1); + + assertTrue("Effect List Size", + (mediaVideoItem1.getAllEffects().size() == 0) ? true : false); + assertNull("Effect Item by ID", mediaVideoItem1.getEffect("xyx")); + + final EffectColor effectColor = mVideoEditorHelper.createEffectItem( + mediaVideoItem1, "Effecton MVi1", 0, 4000, EffectColor.TYPE_GRADIENT, + EffectColor.GRAY); + mediaVideoItem1.addEffect(effectColor); + + assertTrue("Effect List Size", (mediaVideoItem1. + getAllEffects().size() == 1) ? true : false); + assertEquals("Effect Item by Valid ID", effectColor, + mediaVideoItem1.getEffect(effectColor.getId())); + assertNull("Effect Item by Invalid ID", + mediaVideoItem1.getEffect("xyz")); + assertNull("Effect Item by Invalid ID", + mediaVideoItem1.removeEffect("effectId")); + assertTrue("Effect List Size", + (mediaVideoItem1.getAllEffects().size() == 1) ? true : false); + assertEquals("Effect Removed", effectColor, + mediaVideoItem1.removeEffect(effectColor.getId())); + assertTrue("Effect List Size", + (mediaVideoItem1.getAllEffects().size() == 0) ? true : false); + assertNull("Effect Item by ID", mediaVideoItem1.getEffect("effectId")); + } + + /** + * To Test the Media Video API : Get Before and after transition + */ + + // TODO : remove TC_API_008 + @LargeTest + public void testMediaVideoItemTransitions() throws Exception { + final String videoItemFileName = INPUT_FILE_PATH + + "H263_profile0_176x144_15fps_256kbps_AACLC_32kHz_128kbps_s_0_26.3gp"; + final int videoItemRenderingMode =MediaItem.RENDERING_MODE_BLACK_BORDER; + final MediaVideoItem mediaVideoItem1 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "mediaVideoItem1", + videoItemFileName, videoItemRenderingMode); + mVideoEditor.addMediaItem(mediaVideoItem1); + assertNull("Begin Transition", mediaVideoItem1.getBeginTransition()); + assertNull("End Transition", mediaVideoItem1.getEndTransition()); + + TransitionFadeBlack transition1 = + mVideoEditorHelper.createTFadeBlack("transition1", mediaVideoItem1, + null, 0, Transition.BEHAVIOR_SPEED_UP); + mVideoEditor.addTransition(transition1); + assertEquals("Begin transition", transition1, + mediaVideoItem1.getEndTransition()); + + assertNotNull("End Transition", mediaVideoItem1.getEndTransition()); + assertTrue(mediaVideoItem1. + getEndTransition().getId().equals(transition1.getId())); + assertTrue(mediaVideoItem1.getEndTransition().getDuration() == + transition1.getDuration() ? true : false); + assertTrue(mediaVideoItem1.getEndTransition().getBehavior() == + transition1.getBehavior() ? true : false); + + TransitionFadeBlack transition2 = mVideoEditorHelper.createTFadeBlack( + "transition2", null,mediaVideoItem1, 0, Transition.BEHAVIOR_LINEAR); + mVideoEditor.addTransition(transition2); + assertNotNull("Begin transition", mediaVideoItem1.getBeginTransition()); + assertEquals("End Transition", transition2, + mediaVideoItem1.getBeginTransition()); + assertTrue(mediaVideoItem1. + getBeginTransition().getId().equals(transition2.getId())); + assertTrue(mediaVideoItem1. getBeginTransition().getDuration() == + transition2.getDuration() ? true : false); + assertTrue(mediaVideoItem1.getBeginTransition().getBehavior() == + transition2.getBehavior() ? true : false); + } + + /** + * To Test the Media Video API : Get All Overlay, Get Overlay and remove Overlay + * + */ + + // TODO : remove TC_API_009 + @LargeTest + public void testMediaVideoItemOverlays() throws Exception { + final String videoItemFileName = INPUT_FILE_PATH + + "H263_profile0_176x144_15fps_256kbps_AACLC_32kHz_128kbps_s_0_26.3gp"; + final String overlayItemFileName = INPUT_FILE_PATH + + "IMG_176x144_Overlay1.png"; + final int videoItemRenderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; + final MediaVideoItem mediaVideoItem1 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "mediaVideoItem1", + videoItemFileName, videoItemRenderingMode); + mVideoEditor.addMediaItem(mediaVideoItem1); + + assertTrue("Overlay List Size", + (mediaVideoItem1.getAllOverlays().size() == 0) ? true : false); + assertNull("Overlay Item by ID", mediaVideoItem1.getOverlay("xyz")); + + final Bitmap mBitmap = mVideoEditorHelper.getBitmap(overlayItemFileName, + 176, 144); + final OverlayFrame overlayFrame = mVideoEditorHelper.createOverlay( + mediaVideoItem1, "overlayId", mBitmap, 5000, 5000); + mediaVideoItem1.addOverlay(overlayFrame); + + assertTrue("Overlay List Size", + (mediaVideoItem1.getAllOverlays().size() == 1) ? true : false); + assertEquals("Overlay Item by Valid ID", overlayFrame, mediaVideoItem1 + .getOverlay(overlayFrame.getId())); + assertNull("Overlay Item by Invalid ID", + mediaVideoItem1.getOverlay("xyz")); + assertNull("Overlay Item by Invalid ID", + mediaVideoItem1.removeOverlay("xyz")); + assertTrue("Overlay List Size", + (mediaVideoItem1.getAllOverlays().size() == 1) ? true : false); + assertEquals("Overlay Removed", overlayFrame, + mediaVideoItem1.removeOverlay(overlayFrame.getId())); + assertTrue("Overlay List Size", + (mediaVideoItem1.getAllOverlays().size() == 0) ? true : false); + assertNull("Overlay Item by ID",mediaVideoItem1.getOverlay("effectId")); + } + + /** + * To Test Creation of Media Image Item. + */ + // TODO : remove TC_API_010 + @LargeTest + public void testMediaImageItem() throws Exception { + final String imageItemFileName = INPUT_FILE_PATH + "IMG_1600x1200.jpg"; + final int imageItemRenderingMode =MediaItem.RENDERING_MODE_BLACK_BORDER; + final MediaImageItem mediaImageItem1 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "mediaImageItem1", + imageItemFileName, 5000, imageItemRenderingMode); + assertTrue("Media Image ID", + mediaImageItem1.getId().equals("mediaImageItem1")); + assertTrue("Media IMage Filename", + mediaImageItem1.getFilename().equals(imageItemFileName)); + assertEquals("Media Image Rendering Mode", + imageItemRenderingMode, mediaImageItem1.getRenderingMode()); + assertEquals("Media Image Item Duration", mediaImageItem1.getDuration(), + mediaImageItem1.getTimelineDuration()); + assertEquals("Media Image Overlay", 0, + mediaImageItem1.getAllOverlays().size()); + assertEquals("Media Image Effect", 0, + mediaImageItem1.getAllEffects().size()); + assertNull("Media Image Begin transition", + mediaImageItem1.getBeginTransition()); + assertNull("Media Image End transition", + mediaImageItem1.getEndTransition()); + assertEquals("Media Image Scaled Height", MediaProperties.HEIGHT_720, + mediaImageItem1.getScaledHeight()); + assertEquals("Media Image Scaled Width", 960, + mediaImageItem1.getScaledWidth()); + assertEquals("Media Image Aspect Ratio", MediaProperties.ASPECT_RATIO_4_3, + mediaImageItem1.getAspectRatio()); + assertNotNull("Media Image Thumbnail", + mediaImageItem1.getThumbnail(960, MediaProperties.HEIGHT_720, 2000)); + } + + /** + * To Test the Media Image API : Get and Set rendering Mode + */ + // TODO : remove TC_API_011 + @LargeTest + public void testMediaImageItemRenderingModes() throws Exception { + final String imageItemFileName = INPUT_FILE_PATH + "IMG_1600x1200.jpg"; + final int imageItemRenderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; + boolean flagForException = false; + final MediaImageItem mediaImageItem1 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "mediaImageItem1", + imageItemFileName, imageItemRenderingMode, 5000); + mVideoEditor.addMediaItem(mediaImageItem1); + + mediaImageItem1.setRenderingMode(MediaItem.RENDERING_MODE_CROPPING); + assertEquals("MediaVideo Item rendering Mode", + MediaItem.RENDERING_MODE_CROPPING, mediaImageItem1.getRenderingMode()); + try { + mediaImageItem1.setRenderingMode( + MediaItem.RENDERING_MODE_CROPPING + 911); + } catch (IllegalArgumentException e) { + flagForException = true; + } + assertTrue("Media Item Invalid rendering Mode", flagForException); + + flagForException = false; + try { + mediaImageItem1.setRenderingMode( + MediaItem.RENDERING_MODE_BLACK_BORDER - 11); + } catch (IllegalArgumentException e) { + flagForException = true; + } + assertTrue("Media Item Invalid rendering Mode", flagForException); + + assertEquals("MediaVideo Item rendering Mode", + MediaItem.RENDERING_MODE_CROPPING, + mediaImageItem1.getRenderingMode()); + mediaImageItem1.setRenderingMode(MediaItem.RENDERING_MODE_STRETCH); + assertEquals("MediaVideo Item rendering Mode", + MediaItem.RENDERING_MODE_STRETCH, + mediaImageItem1.getRenderingMode()); + } + + /** + * To Test the Media Image API : GetHeight and GetWidth + */ + // TODO : remove TC_API_012 + @LargeTest + public void testMediaImageItemHeightWidth() throws Exception { + final String imageItemFileName = INPUT_FILE_PATH + "IMG_640x480.jpg"; + final int imageItemRenderingMode =MediaItem.RENDERING_MODE_BLACK_BORDER; + final MediaImageItem mediaImageItem1 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "mediaImageItem1", + imageItemFileName, imageItemRenderingMode, 5000); + mVideoEditor.addMediaItem(mediaImageItem1); + + assertEquals("Image Height = Image Scaled Height", + mediaImageItem1.getScaledHeight(), mediaImageItem1.getHeight()); + assertEquals("Image Width = Image Scaled Width", + mediaImageItem1.getScaledWidth(), mediaImageItem1.getWidth()); + } + + + +/** This Test Case can be removed as this is already checked in TC 010 */ + /** + * To Test the Media Image API : Scaled Height and Scaled GetWidth + */ + // TODO : remove TC_API_013 + @LargeTest + public void testMediaImageItemScaledHeightWidth() throws Exception { + final String imageItemFileName = INPUT_FILE_PATH + "IMG_1600x1200.jpg"; + final int imageItemRenderingMode =MediaItem.RENDERING_MODE_BLACK_BORDER; + + final MediaImageItem mediaImageItem1 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "mediaImageItem1", + imageItemFileName, imageItemRenderingMode, 5000); + mVideoEditor.addMediaItem(mediaImageItem1); + + assertNotSame("Image Height = Image Scaled Height", + mediaImageItem1.getScaledHeight(), mediaImageItem1.getHeight()); + assertNotSame("Image Width = Image Scaled Width", + mediaImageItem1.getScaledWidth(), mediaImageItem1.getWidth()); + } + + /** + * To Test the Media Image API : Get Effect, GetAllEffects, remove Effect + */ + + // TODO : remove TC_API_014 + @LargeTest + public void testMediaImageItemEffect() throws Exception { + final String imageItemFileName = INPUT_FILE_PATH + "IMG_1600x1200.jpg"; + final int imageItemRenderingMode =MediaItem.RENDERING_MODE_BLACK_BORDER; + final MediaImageItem mediaImageItem1 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "mediaImageItem1", + imageItemFileName, 5000, imageItemRenderingMode); + mVideoEditor.addMediaItem(mediaImageItem1); + + assertTrue("Effect List Size", + (mediaImageItem1.getAllEffects().size() == 0) ? true : false); + assertNull("Effect Item by ID", mediaImageItem1.getEffect("xyx")); + + final EffectColor effectColor = + mVideoEditorHelper.createEffectItem(mediaImageItem1, + "Effecton MVi1", 0, 4000, EffectColor.TYPE_GRADIENT, EffectColor.GRAY); + mediaImageItem1.addEffect(effectColor); + + assertTrue("Effect List Size", + (mediaImageItem1.getAllEffects().size() == 1) ? true : false); + assertEquals("Effect Item by Valid ID", + effectColor, mediaImageItem1.getEffect(effectColor.getId())); + assertNull("Effect Item by Invalid ID", + mediaImageItem1.getEffect("xyz")); + assertNull("Effect Item by Invalid ID", + mediaImageItem1.removeEffect("effectId")); + assertTrue("Effect List Size", + (mediaImageItem1.getAllEffects().size() == 1) ? true : false); + assertEquals("Effect Removed", effectColor, + mediaImageItem1.removeEffect(effectColor.getId())); + assertTrue("Effect List Size", + (mediaImageItem1.getAllEffects().size() == 0) ? true : false); + assertNull("Effect Item by ID", mediaImageItem1.getEffect("effectId")); + } + + /** + * To Test the Media Image API : Get Before and after transition + */ + + // TODO : remove TC_API_015 + @LargeTest + public void testMediaImageItemTransitions() throws Exception { + final String imageItemFileName = INPUT_FILE_PATH + "IMG_1600x1200.jpg"; + final int imageItemRenderingMode =MediaItem.RENDERING_MODE_BLACK_BORDER; + final MediaImageItem mediaImageItem1 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "mediaImageItem1", + imageItemFileName, 5000, imageItemRenderingMode); + mVideoEditor.addMediaItem(mediaImageItem1); + + assertNull("Begin Transition", mediaImageItem1.getBeginTransition()); + assertNull("End Transition", mediaImageItem1.getEndTransition()); + + TransitionFadeBlack transition1 = + mVideoEditorHelper.createTFadeBlack("transition1", mediaImageItem1, + null, 0, Transition.BEHAVIOR_SPEED_UP); + mVideoEditor.addTransition(transition1); + + assertEquals("Begin transition", transition1, + mediaImageItem1.getEndTransition()); + assertNotNull("End Transition", mediaImageItem1.getEndTransition()); + assertTrue(mediaImageItem1.getEndTransition().getId().equals + (transition1.getId())); + assertTrue(mediaImageItem1.getEndTransition().getDuration() == + transition1.getDuration() ? true : false); + assertTrue(mediaImageItem1.getEndTransition().getBehavior() == + transition1.getBehavior() ? true : false); + + TransitionFadeBlack transition2 = mVideoEditorHelper.createTFadeBlack( + "transition2",null, mediaImageItem1, 0, Transition.BEHAVIOR_SPEED_UP); + mVideoEditor.addTransition(transition2); + + assertNotNull("Begin transition", mediaImageItem1.getBeginTransition()); + assertEquals("End Transition", transition2, + mediaImageItem1.getBeginTransition()); + assertTrue(mediaImageItem1.getBeginTransition().getId().equals( + transition2.getId())); + assertTrue(mediaImageItem1.getBeginTransition().getDuration() == + transition2.getDuration() ? true : false); + assertTrue(mediaImageItem1.getBeginTransition().getBehavior() == + transition2.getBehavior() ? true : false); + } + + /** + * To Test the Media Image API : Get All Overlay, Get Overlay and remove + * Overlay + */ + + // TODO : remove TC_API_016 + @LargeTest + public void testMediaImageItemOverlays() throws Exception { + final String imageItemFileName = INPUT_FILE_PATH + "IMG_640x480.jpg"; + final String overlayItemFileName = INPUT_FILE_PATH + + "IMG_640x480_Overlay1.png"; + final int imageItemRenderingMode =MediaItem.RENDERING_MODE_BLACK_BORDER; + final MediaImageItem mediaImageItem1 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "mediaImageItem1", + imageItemFileName, 12000, imageItemRenderingMode); + mVideoEditor.addMediaItem(mediaImageItem1); + + assertTrue("Overlay List Size", + (mediaImageItem1.getAllOverlays().size() == 0) ? true : false); + assertNull("Overlay Item by ID", mediaImageItem1.getOverlay("xyz")); + final Bitmap mBitmap = mVideoEditorHelper.getBitmap(overlayItemFileName, + 640, 480); + final OverlayFrame overlayFrame = + mVideoEditorHelper.createOverlay(mediaImageItem1, "overlayId", + mBitmap, 5000, 5000); + mediaImageItem1.addOverlay(overlayFrame); + + assertTrue("Overlay List Size", + (mediaImageItem1.getAllOverlays().size() == 1) ? true : false); + assertEquals("Overlay Item by Valid ID", overlayFrame, mediaImageItem1 + .getOverlay(overlayFrame.getId())); + assertNull("Overlay Item by Invalid ID", + mediaImageItem1.getOverlay("xyz")); + assertNull("Remove Overlay Item by Invalid ID", + mediaImageItem1.removeOverlay("xyz")); + assertTrue("Overlay List Size", + (mediaImageItem1.getAllOverlays().size() == 1) ? true : false); + assertEquals("Overlay Removed", + overlayFrame, mediaImageItem1.removeOverlay(overlayFrame.getId())); + assertTrue("Overlay List Size", + (mediaImageItem1.getAllOverlays().size() == 0) ? true : false); + assertNull("Overlay Item by ID", + mediaImageItem1.getOverlay("effectId")); + } + + /** + * To test creation of Audio Track + */ + + // TODO : remove TC_API_017 + @LargeTest + public void testAudioTrack() throws Exception { + final String audioFileName = INPUT_FILE_PATH + + "AACLC_48KHz_256Kbps_s_1_17.3gp"; + final AudioTrack audioTrack = mVideoEditorHelper.createAudio( + mVideoEditor, "audioTrack", audioFileName); + mVideoEditor.addAudioTrack(audioTrack); + + assertEquals("Audio Track Item Duration", audioTrack.getDuration(), + audioTrack.getTimelineDuration()); + assertEquals("Audio Track Start Time", 0, audioTrack.getStartTime()); + assertFalse("Audio Track is Looping", audioTrack.isLooping()); + audioTrack.getVolume(); + assertFalse("Audio Track Ducking is Disabled", + audioTrack.isDuckingEnabled()); + assertTrue("Audio Track Filename", + audioTrack.getFilename().equals(audioFileName)); + assertEquals("Audio Ducking Threshold", 0, + audioTrack.getDuckingThreshhold()); + assertFalse("Audio Track Mute", audioTrack.isMuted()); + audioTrack.getDuckedTrackVolume(); + } + + /** + * To test creation of Audio Track with set extract boundaries + */ + // TODO : remove TC_API_018 + @LargeTest + public void testAudioTrackExtractBoundaries() throws Exception { + final String audioFileName = INPUT_FILE_PATH + + "AACLC_48KHz_256Kbps_s_1_17.3gp"; + boolean flagForException = false; + final AudioTrack audioTrack = mVideoEditorHelper.createAudio( + mVideoEditor, "audioTrack", audioFileName); + mVideoEditor.addAudioTrack(audioTrack); + + audioTrack.setExtractBoundaries(1000, 5000); + assertEquals("Audio Track Start time", 1000, + audioTrack.getBoundaryBeginTime()); + assertEquals("Audio Track End time", 5000, + audioTrack.getBoundaryEndTime()); + try { + audioTrack.setExtractBoundaries(0, 100000000); + } catch (IllegalArgumentException e) { + flagForException = true; + } + assertTrue("Audio Track With endTime > FileDuration", flagForException); + flagForException = false; + try { + audioTrack.setExtractBoundaries(100000000, 5000); + } catch (IllegalArgumentException e) { + flagForException = true; + } + assertTrue("Audio Track With startTime > FileDuration", + flagForException); + flagForException = false; + try { + audioTrack.setExtractBoundaries(0, 0); + } catch (IllegalArgumentException e) { + flagForException = true; + } + /* This is under discussion. Hence, checked for False */ + assertFalse("Audio Track With startTime = endTime", flagForException); + assertEquals("Audio Track Start time", 0, + audioTrack.getBoundaryBeginTime()); + assertEquals("Audio Track End time", 0, + audioTrack.getBoundaryEndTime()); + assertEquals("Audio Track Start time",0, + audioTrack.getBoundaryBeginTime()); + assertEquals("Audio Track End time", (audioTrack.getTimelineDuration()), + audioTrack.getBoundaryEndTime()); + audioTrack.setExtractBoundaries(0, audioTrack.getDuration() / 2); + assertEquals("Audio Track Start time",0, + audioTrack.getBoundaryBeginTime()); + assertEquals("Audio Track End time", (audioTrack.getDuration() / 2), + audioTrack.getBoundaryEndTime()); + audioTrack.setExtractBoundaries(1, audioTrack.getDuration() - 1); + assertEquals("Audio Track Start time", 1, + audioTrack.getBoundaryBeginTime()); + assertEquals("Audio Track End time", (audioTrack.getDuration() - 1), + audioTrack.getBoundaryEndTime()); + + flagForException = false; + try { + audioTrack.setExtractBoundaries(0, -1); + } catch (IllegalArgumentException e) { + flagForException = true; + } + assertTrue ("Audio Track end time < 0",flagForException); + } + + /** + * To test creation of Audio Track with set Start Time and Get Time + */ + // TODO : remove TC_API_019 + @LargeTest + public void testAudioTrackSetGetTime() throws Exception { + final String audioFileName = INPUT_FILE_PATH + + "AACLC_48KHz_256Kbps_s_1_17.3gp"; + boolean flagForException = false; + final AudioTrack audioTrack = mVideoEditorHelper.createAudio( + mVideoEditor, "audioTrack", audioFileName); + mVideoEditor.addAudioTrack(audioTrack); + /** set StartTime API is removed and start time is always 0 */ + assertEquals("Audio Track Start Time", 0, audioTrack.getStartTime()); + } + + /** + * To Test the Audio Track API: Enable Ducking + */ + // TODO : remove TC_API_020 + @LargeTest + public void testAudioTrackEnableDucking() throws Exception { + final String audioFileName = INPUT_FILE_PATH + + "AACLC_48KHz_256Kbps_s_1_17.3gp"; + boolean flagForException = false; + final AudioTrack audioTrack = mVideoEditorHelper.createAudio( + mVideoEditor, "audioTrack", audioFileName); + mVideoEditor.addAudioTrack(audioTrack); + + assertFalse("Audio Ducking Disabled by default", + audioTrack.isDuckingEnabled()); + audioTrack.enableDucking(45, 70); + assertTrue("Audio Ducking Enabled", audioTrack.isDuckingEnabled()); + assertEquals("Audio Ducking Threshold", 45, + audioTrack.getDuckingThreshhold()); + assertEquals("Audio Ducking Volume", 70, + audioTrack.getDuckedTrackVolume()); + audioTrack.enableDucking(85, 70); + assertEquals("Audio Ducking Threshold", 85, + audioTrack.getDuckingThreshhold()); + assertEquals("Audio Ducking Volume", 70, + audioTrack.getDuckedTrackVolume()); + try { + audioTrack.enableDucking(91, 70); + } catch (IllegalArgumentException e) { + flagForException = true; + } + assertTrue("Enable ducking threshold > 90", flagForException); + flagForException = false; + try { + audioTrack.enableDucking(90, 101); + } catch (IllegalArgumentException e) { + flagForException = true; + } + assertTrue("Enable ducking volume > 100", flagForException); + flagForException = false; + try { + audioTrack.enableDucking(91, 101); + } catch (IllegalArgumentException e) { + flagForException = true; + } + assertTrue("Enable ducking volume > 100 and threshold > 91", + flagForException); + flagForException = false; + try { + audioTrack.enableDucking(-1, 100); + } catch (IllegalArgumentException e) { + flagForException = true; + } + assertTrue("Enable ducking threshold < 0", flagForException); + flagForException = false; + try { + audioTrack.enableDucking(1, -1); + } catch (IllegalArgumentException e) { + flagForException = true; + } + assertTrue("Enable ducking lowVolume < 0", flagForException); + flagForException = false; + try { + audioTrack.enableDucking(0, 50); + } catch (IllegalArgumentException e) { + flagForException = true; + } + assertFalse("Enable ducking threshold = 0", flagForException); + } + + /** + * To Test the Audio Track API: Looping + */ + // TODO : remove TC_API_021 + @LargeTest + public void testAudioTrackLooping() throws Exception { + final String audioFileName = INPUT_FILE_PATH + + "AACLC_48KHz_256Kbps_s_1_17.3gp"; + final AudioTrack audioTrack = mVideoEditorHelper.createAudio( + mVideoEditor, "audioTrack", audioFileName); + mVideoEditor.addAudioTrack(audioTrack); + assertFalse("Audio Looping", audioTrack.isLooping()); + audioTrack.enableLoop(); + assertTrue("Audio Looping", audioTrack.isLooping()); + audioTrack.disableLoop(); + assertFalse("Audio Looping", audioTrack.isLooping()); + } + + /** + * To Test the Audio Track API:Extract waveform data + */ + // TODO : remove TC_API_022 + + @LargeTest + public void testAudioTrackWaveFormData() throws Exception { + /** Image item is added as dummy as Audio track cannot be added without + * a media item in the story board + */ + final String imageItemFileName = INPUT_FILE_PATH + "IMG_640x480.jpg"; + final int imageItemRenderingMode =MediaItem.RENDERING_MODE_BLACK_BORDER; + final MediaImageItem mediaImageItem = + mVideoEditorHelper.createMediaItem(mVideoEditor, "mediaImageItem1", + imageItemFileName, 5000, imageItemRenderingMode); + mVideoEditor.addMediaItem(mediaImageItem); + + final String audioFileName = INPUT_FILE_PATH + + "AACLC_48KHz_256Kbps_s_1_17.3gp"; + final AudioTrack audioTrack = mVideoEditorHelper.createAudio( + mVideoEditor, "audioTrack", audioFileName); + + mVideoEditor.addAudioTrack(audioTrack); + assertNull("WaveForm data", audioTrack.getWaveformData()); + + final int[] progressUpdate = new int[105]; + mVideoEditor.generatePreview(new MediaProcessingProgressListener() { + int i = 0; + public void onProgress(Object item, int action, int progress) { + progressUpdate[i++] = progress; + } + }); + + final int[] progressWaveform = new int[105]; + + audioTrack.extractAudioWaveform( + new ExtractAudioWaveformProgressListener() { + int i = 0; + public void onProgress(int progress) { + Log.i("AudioWaveformData","progress=" +progress); + progressWaveform[i++] = progress; + } + }); + assertTrue("Progress of WaveForm data", mVideoEditorHelper + .checkProgressCBValues(progressWaveform)); + assertNotNull("WaveForm data", audioTrack.getWaveformData()); + assertTrue("WaveForm Frame Duration", + (audioTrack.getWaveformData().getFrameDuration() > 0 ? + true : false)); + assertTrue("WaveForm Frame Count", + (audioTrack.getWaveformData().getFramesCount() > 0 ? true : false)); + assertTrue("WaveForm Gain", + (audioTrack.getWaveformData().getFrameGains().length > 0 ? + true : false)); + } + + /** + * To Test the Audio Track API: Mute + */ + // TODO : remove TC_API_023 + @LargeTest + public void testAudioTrackMute() throws Exception { + final String audioFileName = INPUT_FILE_PATH + + "AACLC_48KHz_256Kbps_s_1_17.3gp"; + final AudioTrack audioTrack = mVideoEditorHelper.createAudio( + mVideoEditor, "audioTrack", audioFileName); + assertFalse("Audio Track UnMute", audioTrack.isMuted()); + audioTrack.setMute(true); + assertTrue("Audio Track Mute", audioTrack.isMuted()); + audioTrack.setMute(false); + assertFalse("Audio Track UnMute", audioTrack.isMuted()); + } + + /** + * To Test the Audio Track API: Get Volume and Set Volume + */ + // TODO : remove TC_API_024 + @LargeTest + public void testAudioTrackGetSetVolume() throws Exception { + final String audioFileName = INPUT_FILE_PATH + + "AACLC_48KHz_256Kbps_s_1_17.3gp"; + boolean flagForException = false; + final AudioTrack audioTrack = mVideoEditorHelper.createAudio( + mVideoEditor, "audioTrack", audioFileName); + audioTrack.setVolume(0); + assertEquals("Audio Volume", 0, audioTrack.getVolume()); + assertFalse("Audio Track UnMute", audioTrack.isMuted()); + audioTrack.setVolume(45); + assertEquals("Audio Volume", 45, audioTrack.getVolume()); + assertFalse("Audio Track UnMute", audioTrack.isMuted()); + try { + audioTrack.setVolume(-1); + } catch (IllegalArgumentException e) { + flagForException = true; + } + assertTrue("Volume = -1", flagForException); + assertEquals("Audio Volume", 45, audioTrack.getVolume()); + flagForException = false; + try { + audioTrack.setVolume(101); + } catch (IllegalArgumentException e) { + flagForException = true; + } + assertTrue("Volume = 101", flagForException); + flagForException = false; + try { + audioTrack.setVolume(1000); + } catch (IllegalArgumentException e) { + flagForException = true; + } + assertTrue("Volume = 10000", flagForException); + assertEquals("Audio Volume", 45, audioTrack.getVolume()); + } + + /** + * To test Effect Color. + */ + // TODO : remove TC_API_025 + @LargeTest + public void testAllEffects() throws Exception { + final String videoItemFileName = INPUT_FILE_PATH + + "MPEG4_SP_640x480_30fps_512Kbps_0_27.mp4"; + boolean flagForException = false; + final MediaVideoItem mediaVideoItem1 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "mediaVideoItem1", + videoItemFileName, MediaItem.RENDERING_MODE_BLACK_BORDER); + mVideoEditor.addMediaItem(mediaVideoItem1); + + final EffectColor effectColor1 = mVideoEditorHelper.createEffectItem( + mediaVideoItem1, "effect1", 1000, 1000, EffectColor.TYPE_COLOR, + EffectColor.PINK); + mediaVideoItem1.addEffect(effectColor1); + + assertEquals("Associated Media Item", mediaVideoItem1, + effectColor1.getMediaItem()); + assertTrue("Effect Id", effectColor1.getId().equals("effect1")); + assertEquals("Effect StartTime", 1000, effectColor1.getStartTime()); + assertEquals("Effect EndTime", 1000, effectColor1.getDuration()); + assertEquals("Effect Type", EffectColor.TYPE_COLOR, + effectColor1.getType()); + assertEquals("Effect Color", EffectColor.PINK, effectColor1.getColor()); + + final EffectColor effectColor2 = mVideoEditorHelper.createEffectItem( + mediaVideoItem1, "effect2", 2000, 1000, EffectColor.TYPE_COLOR, + EffectColor.GRAY); + mediaVideoItem1.addEffect(effectColor2); + + assertEquals("Associated Media Item", mediaVideoItem1, + effectColor2.getMediaItem()); + assertTrue("Effect Id", effectColor2.getId().equals("effect2")); + assertEquals("Effect StartTime", 2000, effectColor2.getStartTime()); + assertEquals("Effect EndTime", 1000, effectColor2.getDuration()); + assertEquals("Effect Type", EffectColor.TYPE_COLOR, + effectColor2.getType()); + assertEquals("Effect Color", EffectColor.GRAY, effectColor2.getColor()); + + final EffectColor effectColor3 = mVideoEditorHelper.createEffectItem( + mediaVideoItem1, "effect3", 3000, 1000, EffectColor.TYPE_COLOR, + EffectColor.GREEN); + mediaVideoItem1.addEffect(effectColor3); + + assertEquals("Associated Media Item", mediaVideoItem1, + effectColor3.getMediaItem()); + assertTrue("Effect Id", effectColor3.getId().equals("effect3")); + assertEquals("Effect StartTime", 3000, effectColor3.getStartTime()); + assertEquals("Effect EndTime", 1000, effectColor3.getDuration()); + assertEquals("Effect Type", EffectColor.TYPE_COLOR, + effectColor3.getType()); + assertEquals("Effect Color", EffectColor.GREEN, effectColor3.getColor()); + + final EffectColor effectColor4 = mVideoEditorHelper.createEffectItem( + mediaVideoItem1, "effect4", 4000, 1000, EffectColor.TYPE_GRADIENT, + EffectColor.PINK); + mediaVideoItem1.addEffect(effectColor4); + + assertEquals("Associated Media Item", mediaVideoItem1, + effectColor4.getMediaItem()); + assertTrue("Effect Id", effectColor4.getId().equals("effect4")); + assertEquals("Effect StartTime", 4000, effectColor4.getStartTime()); + assertEquals("Effect EndTime", 1000, effectColor4.getDuration()); + assertEquals("Effect Type", EffectColor.TYPE_GRADIENT, + effectColor4.getType()); + assertEquals("Effect Color", EffectColor.PINK, effectColor4.getColor()); + + final EffectColor effectColor5 = mVideoEditorHelper.createEffectItem( + mediaVideoItem1, "effect5", 5000, 1000, + EffectColor.TYPE_GRADIENT, EffectColor.GRAY); + mediaVideoItem1.addEffect(effectColor5); + + assertEquals("Associated Media Item", mediaVideoItem1, + effectColor5.getMediaItem()); + assertTrue("Effect Id", effectColor5.getId().equals("effect5")); + assertEquals("Effect StartTime", 5000, effectColor5.getStartTime()); + assertEquals("Effect EndTime", 1000, effectColor5.getDuration()); + assertEquals("Effect Type", EffectColor.TYPE_GRADIENT, + effectColor5.getType()); + assertEquals("Effect Color", EffectColor.GRAY, effectColor5.getColor()); + + final EffectColor effectColor6 = mVideoEditorHelper.createEffectItem( + mediaVideoItem1, "effect6", 6000, 1000, + EffectColor.TYPE_GRADIENT, EffectColor.GREEN); + mediaVideoItem1.addEffect(effectColor6); + + assertEquals("Associated Media Item", mediaVideoItem1, + effectColor6.getMediaItem()); + assertTrue("Effect Id", effectColor6.getId().equals("effect6")); + assertEquals("Effect StartTime", 6000, effectColor6.getStartTime()); + assertEquals("Effect EndTime", 1000, effectColor6.getDuration()); + assertEquals("Effect Type", + EffectColor.TYPE_GRADIENT, effectColor6.getType()); + assertEquals("Effect Color", + EffectColor.GREEN, effectColor6.getColor()); + + final EffectColor effectColor7 = mVideoEditorHelper.createEffectItem( + mediaVideoItem1, "effect7", 7000, 1000, + EffectColor.TYPE_FIFTIES, 0); + mediaVideoItem1.addEffect(effectColor7); + + assertEquals("Associated Media Item", mediaVideoItem1, + effectColor7.getMediaItem()); + assertTrue("Effect Id", effectColor7.getId().equals("effect7")); + assertEquals("Effect StartTime", 7000, effectColor7.getStartTime()); + assertEquals("Effect EndTime", 1000, effectColor7.getDuration()); + assertEquals("Effect Type", EffectColor.TYPE_FIFTIES, + effectColor7.getType()); + assertEquals("Effect Color", -1, effectColor7.getColor()); + + final EffectColor effectColor8 = mVideoEditorHelper.createEffectItem( + mediaVideoItem1, "effect8", 8000, 1000, EffectColor.TYPE_SEPIA, 0); + mediaVideoItem1.addEffect(effectColor8); + + assertEquals("Associated Media Item", mediaVideoItem1, + effectColor8.getMediaItem()); + assertTrue("Effect Id", effectColor8.getId().equals("effect8")); + assertEquals("Effect StartTime", 8000, effectColor8.getStartTime()); + assertEquals("Effect EndTime", 1000, effectColor8.getDuration()); + assertEquals("Effect Type", EffectColor.TYPE_SEPIA, + effectColor8.getType()); + assertEquals("Effect Color", -1, effectColor8.getColor()); + + final EffectColor effectColor9 = mVideoEditorHelper.createEffectItem( + mediaVideoItem1, "effect9", 9000, 1000, + EffectColor.TYPE_NEGATIVE, 0); + mediaVideoItem1.addEffect(effectColor9); + + assertEquals("Associated Media Item", mediaVideoItem1, + effectColor9.getMediaItem()); + assertTrue("Effect Id", effectColor9.getId().equals("effect9")); + assertEquals("Effect StartTime", 9000, effectColor9.getStartTime()); + assertEquals("Effect EndTime", 1000, effectColor9.getDuration()); + assertEquals("Effect Type", EffectColor.TYPE_NEGATIVE, + effectColor9.getType()); + assertEquals("Effect Color", -1, effectColor9.getColor()); + try { + mVideoEditorHelper.createEffectItem(mediaVideoItem1, "effect9", + 9000, 1000, EffectColor.TYPE_COLOR - 1, 0); + } catch (IllegalArgumentException e) { + flagForException = true; + } + assertTrue("Effect type Invalid", flagForException); + flagForException = false; + try { + mVideoEditorHelper.createEffectItem(mediaVideoItem1, "effect9", + 9000, 1000, EffectColor.TYPE_FIFTIES + 1, 0); + } catch (IllegalArgumentException e) { + flagForException = true; + } + assertTrue("Effect type Invalid", flagForException); + try { + mVideoEditorHelper.createEffectItem(mediaVideoItem1, "effect10", + 10000, 1000, EffectColor.TYPE_FIFTIES + + EffectColor.TYPE_GRADIENT, 0); + } catch (IllegalArgumentException e) { + flagForException = true; + } + assertTrue("Effect type Invalid", flagForException); + } + + /** + * To test Effect Color : Set duration and Get Duration + */ + // TODO : remove TC_API_026 + @LargeTest + public void testEffectSetgetDuration() throws Exception { + final String videoItemFileName = INPUT_FILE_PATH + + "MPEG4_SP_640x480_30fps_512Kbps_0_27.mp4"; + final int videoItemRenderingMode =MediaItem.RENDERING_MODE_BLACK_BORDER; + boolean flagForException = false; + final MediaVideoItem mediaVideoItem1 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "mediaVideoItem1", + videoItemFileName, videoItemRenderingMode); + mVideoEditor.addMediaItem(mediaVideoItem1); + + final EffectColor effectColor1 = mVideoEditorHelper.createEffectItem( + mediaVideoItem1, "effect1", 1000, 2000, + EffectColor.TYPE_COLOR, EffectColor.PINK); + mediaVideoItem1.addEffect(effectColor1); + + effectColor1.setDuration(5000); + assertEquals("Updated Effect Duration", 5000, + effectColor1.getDuration()); + try { + effectColor1.setDuration(mediaVideoItem1.getDuration() + 1000); + } catch (IllegalArgumentException e) { + flagForException = true; + } + assertTrue("Effect Color duration > mediaVideoItemDuration", + flagForException); + assertEquals("Effect Duration", 5000, effectColor1.getDuration()); + flagForException = false; + try { + effectColor1.setDuration(-1); + } catch (IllegalArgumentException e) { + flagForException = true; + } + assertTrue("Effect Color duration = -1", flagForException); + } + + /** + * To test Effect Color : UNDEFINED color param value + */ + // TODO : remove TC_API_027 + @LargeTest + public void testEffectUndefinedColorParam() throws Exception { + final String videoItemFileName = INPUT_FILE_PATH + + "MPEG4_SP_640x480_30fps_512Kbps_0_27.mp4"; + final int videoItemRenderingMode =MediaItem.RENDERING_MODE_BLACK_BORDER; + boolean flagForException = false; + final MediaVideoItem mediaVideoItem1 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "mediaVideoItem1", + videoItemFileName, videoItemRenderingMode); + mVideoEditor.addMediaItem(mediaVideoItem1); + try{ + mVideoEditorHelper.createEffectItem(mediaVideoItem1, "effect1", 1000, + 2000, EffectColor.TYPE_COLOR, 0xabcdabcd); + }catch (IllegalArgumentException e){ + flagForException = true; + } + assertTrue("Invalid Effect added",flagForException); + } + + /** + * To test Effect Color : with Invalid StartTime and Duration + */ + // TODO : remove TC_API_028 + @LargeTest + public void testEffectInvalidStartTimeAndDuration() throws Exception { + final String videoItemFileName = INPUT_FILE_PATH + + "H264_BP_640x480_15fps_1200Kbps_AACLC_48KHz_32kbps_m_1_17.3gp"; + final int videoItemRenderingMode =MediaItem.RENDERING_MODE_BLACK_BORDER; + boolean flagForException = false; + final MediaVideoItem mediaVideoItem1 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "mediaVideoItem1", + videoItemFileName, videoItemRenderingMode); + mVideoEditor.addMediaItem(mediaVideoItem1); + + try { + mVideoEditorHelper.createEffectItem(mediaVideoItem1, "effect1", + 400000000, 2000, EffectColor.TYPE_COLOR, EffectColor.GREEN); + } catch (IllegalArgumentException e) { + flagForException = true; + } + assertTrue("Effect with invalid StartTime", flagForException); + + flagForException = false; + try { + mVideoEditorHelper.createEffectItem(mediaVideoItem1, "effect1", -1, + 2000, EffectColor.TYPE_COLOR, EffectColor.GREEN); + } catch (IllegalArgumentException e) { + flagForException = true; + } + assertTrue("Effect with invalid StartTime", flagForException); + + flagForException = false; + try { + mVideoEditorHelper.createEffectItem(mediaVideoItem1, "effect1", + 2000, -1, EffectColor.TYPE_COLOR, EffectColor.GREEN); + } catch (IllegalArgumentException e) { + flagForException = true; + } + assertTrue("Effect with invalid Duration", flagForException); + } + + + /** Test cases 29, 30, 31, 32 and 33 are removed */ + + + /** + * To test Effect : with NULL Media Item + */ + // TODO : remove TC_API_034 + @LargeTest + public void testEffectNullMediaItem() throws Exception { + boolean flagForException = false; + try { + mVideoEditorHelper.createEffectItem(null, "effect1", 1000, 4000, + EffectColor.TYPE_COLOR, EffectColor.GREEN); + } catch (IllegalArgumentException e) { + flagForException = true; + } + assertTrue("Effect with null MediaItem", flagForException); + } + + /** + * To test Effect : KenBurn Effect + */ + // TODO : remove TC_API_035 + @LargeTest + public void testEffectKenBurn() throws Exception { + // Test ken burn effect using a JPEG file. + testEffectKenBurn(INPUT_FILE_PATH + "IMG_640x480.jpg", + "mediaImageItem1"); + + // Test ken burn effect using a PNG file + testEffectKenBurn(INPUT_FILE_PATH + "IMG_640x480.png", + "mediaImageItem2"); + } + + private void testEffectKenBurn(final String imageItemFileName, + final String MediaId) throws Exception { + final int imageItemRenderingMode =MediaItem.RENDERING_MODE_BLACK_BORDER; + final MediaImageItem mediaImageItem = + mVideoEditorHelper.createMediaItem(mVideoEditor, MediaId, + imageItemFileName, 5000, imageItemRenderingMode); + mVideoEditor.addMediaItem(mediaImageItem); + + final Rect startRect = new Rect((mediaImageItem.getHeight() / 3), + (mediaImageItem.getWidth() / 3), (mediaImageItem.getHeight() / 2), + (mediaImageItem.getWidth() / 2)); + final Rect endRect = new Rect(0, 0, mediaImageItem.getWidth(), + mediaImageItem.getHeight()); + + final EffectKenBurns kbEffectOnMediaItem = new EffectKenBurns( + mediaImageItem, "KBOnM2", startRect, endRect, 500, 3000); + + assertNotNull("EffectKenBurns: " + imageItemFileName, + kbEffectOnMediaItem); + + mediaImageItem.addEffect(kbEffectOnMediaItem); + assertEquals("KenBurn Start Rect: " + imageItemFileName, startRect, + kbEffectOnMediaItem.getStartRect()); + + assertEquals("KenBurn End Rect: " + imageItemFileName, endRect, + kbEffectOnMediaItem.getEndRect()); + } + + /** + * To test KenBurnEffect : Set StartRect and EndRect + */ + + // TODO : remove TC_API_036 + @LargeTest + public void testEffectKenBurnSet() throws Exception { + final String imageItemFileName = INPUT_FILE_PATH + "IMG_640x480.jpg"; + final int imageItemRenderingMode =MediaItem.RENDERING_MODE_BLACK_BORDER; + boolean flagForException = false; + final MediaImageItem mediaImageItem = + mVideoEditorHelper.createMediaItem(mVideoEditor, "mediaImageItem1", + imageItemFileName, 5000, imageItemRenderingMode); + mVideoEditor.addMediaItem(mediaImageItem); + + final Rect startRect = new Rect((mediaImageItem.getHeight() / 3), + (mediaImageItem.getWidth() / 3), (mediaImageItem.getHeight() / 2), + (mediaImageItem.getWidth() / 2)); + final Rect endRect = new Rect(0, 0, mediaImageItem.getWidth(), + mediaImageItem.getHeight()); + + EffectKenBurns kbEffectOnMediaItem=null; + kbEffectOnMediaItem = new EffectKenBurns(mediaImageItem, "KBOnM2", + startRect, endRect, 500, 3000); + + assertNotNull("EffectKenBurns", kbEffectOnMediaItem); + mediaImageItem.addEffect(kbEffectOnMediaItem); + assertEquals("KenBurn Start Rect", startRect, + kbEffectOnMediaItem.getStartRect()); + assertEquals("KenBurn End Rect", endRect, + kbEffectOnMediaItem.getEndRect()); + + final Rect startRect1 = new Rect((mediaImageItem.getHeight() / 5), + (mediaImageItem.getWidth() / 5), (mediaImageItem.getHeight() / 4), + (mediaImageItem.getWidth() / 4)); + final Rect endRect1 = new Rect(10, 10, mediaImageItem.getWidth() / 4, + mediaImageItem.getHeight() / 4); + + /* Added newly to take care of removal set APIs */ + kbEffectOnMediaItem = new EffectKenBurns(mediaImageItem, "KBOnM2_changed", + startRect1, endRect1, 500, 3000); + + assertEquals("KenBurn Start Rect", startRect1, + kbEffectOnMediaItem.getStartRect()); + assertEquals("KenBurn End Rect", endRect1, + kbEffectOnMediaItem.getEndRect()); + + final Rect zeroRect = new Rect(0, 0, 0, 0); + try { + kbEffectOnMediaItem = new EffectKenBurns(mediaImageItem, "KBOnM2_zeroStart", + zeroRect, endRect, 500, 3000); + + } catch (IllegalArgumentException e) { + flagForException = true; + } + assertTrue("Invalid Start Rect", flagForException); + + flagForException = false; + try { + kbEffectOnMediaItem = new EffectKenBurns(mediaImageItem, "KBOnM2_zeroEnd", + startRect, zeroRect, 500, 3000); + } catch (IllegalArgumentException e) { + flagForException = true; + } + assertTrue("Invalid End Rect", flagForException); + } + + /** + * To test Transition : Fade To Black with all behavior + * SPEED_UP/SPEED_DOWN/LINEAR/MIDDLE_SLOW/MIDDLE_FAST + */ + + // TODO : remove TC_API_037 + @LargeTest + public void testTransitionFadeBlack() throws Exception { + + final String videoItemFilename1 = INPUT_FILE_PATH + + "H264_BP_640x480_30fps_256kbps_1_17.mp4"; + final String videoItemFilename2 = INPUT_FILE_PATH + + "H263_profile0_176x144_15fps_128kbps_1_35.3gp"; + final String imageItemFilename1 = INPUT_FILE_PATH + "IMG_1600x1200.jpg"; + final String videoItemFilename3 = INPUT_FILE_PATH + + "H264_BP_640x480_30fps_192kbps_1_5.mp4"; + final String videoItemFilename4 = INPUT_FILE_PATH + + "MPEG4_SP_640x480_15fps_256kbps_0_30.mp4"; + final String videoItemFilename5 = INPUT_FILE_PATH + + "H263_profile0_176x144_10fps_96kbps_0_25.3gp"; + boolean flagForException = false; + + final MediaVideoItem mediaVideoItem1 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", + videoItemFilename1, MediaItem.RENDERING_MODE_BLACK_BORDER); + mediaVideoItem1.setExtractBoundaries(0, 15000); + mVideoEditor.addMediaItem(mediaVideoItem1); + + final MediaVideoItem mediaVideoItem2 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m2", + videoItemFilename2, MediaItem.RENDERING_MODE_BLACK_BORDER); + mediaVideoItem2.setExtractBoundaries(0, 15000); + mVideoEditor.addMediaItem(mediaVideoItem2); + + final TransitionFadeBlack transition1And2 = mVideoEditorHelper + .createTFadeBlack("transition1And2", mediaVideoItem1, + mediaVideoItem2, 3000, Transition.BEHAVIOR_SPEED_UP); + mVideoEditor.addTransition(transition1And2); + + assertTrue("Transition ID", + transition1And2.getId().equals("transition1And2")); + assertEquals("Transtion After Media item", + mediaVideoItem1, transition1And2.getAfterMediaItem()); + assertEquals("Transtion Before Media item", mediaVideoItem2, + transition1And2.getBeforeMediaItem()); + assertEquals("Transtion Duration", 3000, transition1And2.getDuration()); + assertEquals("Transtion Behavior", Transition.BEHAVIOR_SPEED_UP, + transition1And2.getBehavior()); + + final MediaImageItem mediaImageItem3 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m3", + imageItemFilename1, 15000, MediaItem.RENDERING_MODE_BLACK_BORDER); + mVideoEditor.addMediaItem(mediaImageItem3); + + final TransitionFadeBlack transition2And3 = + mVideoEditorHelper.createTFadeBlack("transition2And3", mediaVideoItem2, + mediaImageItem3, 1000, Transition.BEHAVIOR_SPEED_DOWN); + mVideoEditor.addTransition(transition2And3); + + assertTrue("Transition ID", + transition2And3.getId().equals("transition2And3")); + assertEquals("Transtion After Media item", mediaVideoItem2, + transition2And3.getAfterMediaItem()); + assertEquals("Transtion Before Media item", mediaImageItem3, + transition2And3.getBeforeMediaItem()); + assertEquals("Transtion Duration", 1000, transition2And3.getDuration()); + assertEquals("Transtion Behavior", Transition.BEHAVIOR_SPEED_DOWN, + transition2And3.getBehavior()); + + final MediaVideoItem mediaVideoItem4 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m4", + videoItemFilename3, MediaItem.RENDERING_MODE_BLACK_BORDER); + mediaVideoItem4.setExtractBoundaries(0, 20000); + mVideoEditor.addMediaItem(mediaVideoItem4); + + final TransitionFadeBlack transition3And4 = + mVideoEditorHelper.createTFadeBlack("transition3And4", mediaImageItem3, + mediaVideoItem4, 5000, Transition.BEHAVIOR_LINEAR); + mVideoEditor.addTransition(transition3And4); + + assertTrue("Transition ID", + transition3And4.getId().equals("transition3And4")); + assertEquals("Transtion After Media item", mediaImageItem3, + transition3And4.getAfterMediaItem()); + assertEquals("Transtion Before Media item", mediaVideoItem4, + transition3And4.getBeforeMediaItem()); + assertEquals("Transtion Duration", 5000, transition3And4.getDuration()); + assertEquals("Transtion Behavior", Transition.BEHAVIOR_LINEAR, + transition3And4.getBehavior()); + + final MediaVideoItem mediaVideoItem5 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m5", + videoItemFilename4, MediaItem.RENDERING_MODE_BLACK_BORDER); + mVideoEditor.addMediaItem(mediaVideoItem5); + + final TransitionFadeBlack transition4And5 = + mVideoEditorHelper.createTFadeBlack("transition4And5", mediaVideoItem4, + mediaVideoItem5, 8000, Transition.BEHAVIOR_MIDDLE_FAST); + mVideoEditor.addTransition(transition4And5); + + assertTrue("Transition ID", + transition4And5.getId().equals("transition4And5")); + assertEquals("Transtion After Media item", mediaVideoItem4, + transition4And5.getAfterMediaItem()); + assertEquals("Transtion Before Media item", mediaVideoItem5, + transition4And5.getBeforeMediaItem()); + assertEquals("Transtion Duration", 8000, transition4And5.getDuration()); + assertEquals("Transtion Behavior", Transition.BEHAVIOR_MIDDLE_FAST, + transition4And5.getBehavior()); + + final MediaVideoItem mediaVideoItem6 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m6", + videoItemFilename5, MediaItem.RENDERING_MODE_BLACK_BORDER); + mediaVideoItem6.setExtractBoundaries(0, 20000); + mVideoEditor.addMediaItem(mediaVideoItem6); + + final TransitionFadeBlack transition5And6 = + mVideoEditorHelper.createTFadeBlack("transition5And6", mediaVideoItem5, + mediaVideoItem6, 2000, Transition.BEHAVIOR_MIDDLE_SLOW); + mVideoEditor.addTransition(transition5And6); + + assertTrue("Transition ID", + transition5And6.getId().equals("transition5And6")); + assertEquals("Transtion After Media item", mediaVideoItem5, + transition5And6.getAfterMediaItem()); + assertEquals("Transtion Before Media item", mediaVideoItem6, + transition5And6.getBeforeMediaItem()); + assertEquals("Transtion Duration", 2000, transition5And6.getDuration()); + assertEquals("Transtion Behavior", Transition.BEHAVIOR_MIDDLE_SLOW, + transition5And6.getBehavior()); + flagForException = false; + try { + mVideoEditorHelper.createTFadeBlack("transitiond6", mediaVideoItem5, + mediaVideoItem6, 2000, Transition.BEHAVIOR_SPEED_UP - 1); + } catch (IllegalArgumentException e) { + flagForException = true; + } + assertTrue("Transition FadeBlack with Invalid behavior", flagForException); + flagForException = false; + try { + mVideoEditorHelper.createTFadeBlack("transitiond6", mediaVideoItem5, + mediaVideoItem6, 2000, Transition.BEHAVIOR_MIDDLE_FAST + 1); + } catch (IllegalArgumentException e) { + flagForException = true; + } + assertTrue("Transition FadeBlack with Invalid behavior", flagForException); + } + + /** + * To test Transition : CrossFade with all behavior + * SPEED_UP/SPEED_DOWN/LINEAR/MIDDLE_SLOW/MIDDLE_FAST + */ + + // TODO : remove TC_API_038 + @LargeTest + public void testTransitionCrossFade() throws Exception { + + final String videoItemFilename1 = INPUT_FILE_PATH + + "H264_BP_640x480_30fps_256kbps_1_17.mp4"; + final String videoItemFilename2 = INPUT_FILE_PATH + + "H263_profile0_176x144_15fps_128kbps_1_35.3gp"; + final String imageItemFilename1 = INPUT_FILE_PATH + "IMG_1600x1200.jpg"; + final String videoItemFilename3 = INPUT_FILE_PATH + + "H264_BP_640x480_30fps_192kbps_1_5.mp4"; + final String videoItemFilename4 = INPUT_FILE_PATH + + "MPEG4_SP_640x480_15fps_256kbps_0_30.mp4"; + final String videoItemFilename5 = INPUT_FILE_PATH + + "H263_profile0_176x144_10fps_96kbps_0_25.3gp"; + boolean flagForException = false; + final MediaVideoItem mediaVideoItem1 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", + videoItemFilename1, MediaItem.RENDERING_MODE_BLACK_BORDER); + mediaVideoItem1.setExtractBoundaries(0, 15000); + mVideoEditor.addMediaItem(mediaVideoItem1); + + final MediaVideoItem mediaVideoItem2 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m2", + videoItemFilename2, MediaItem.RENDERING_MODE_BLACK_BORDER); + mediaVideoItem2.setExtractBoundaries(0, 15000); + mVideoEditor.addMediaItem(mediaVideoItem2); + + final TransitionCrossfade transition1And2 = + mVideoEditorHelper.createTCrossFade("transition1And2", mediaVideoItem1, + mediaVideoItem2, 3000, Transition.BEHAVIOR_SPEED_UP); + mVideoEditor.addTransition(transition1And2); + + assertTrue("Transition ID", + transition1And2.getId().equals("transition1And2")); + assertEquals("Transtion After Media item", mediaVideoItem1, + transition1And2.getAfterMediaItem()); + assertEquals("Transtion Before Media item", mediaVideoItem2, + transition1And2.getBeforeMediaItem()); + assertEquals("Transtion Duration", 3000, transition1And2.getDuration()); + assertEquals("Transtion Behavior", Transition.BEHAVIOR_SPEED_UP, + transition1And2.getBehavior()); + + final MediaImageItem mediaImageItem3 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m3", + imageItemFilename1, 15000, MediaItem.RENDERING_MODE_BLACK_BORDER); + mVideoEditor.addMediaItem(mediaImageItem3); + + final TransitionCrossfade transition2And3 = + mVideoEditorHelper.createTCrossFade("transition2And3", mediaVideoItem2, + mediaImageItem3, 1000, Transition.BEHAVIOR_SPEED_DOWN); + mVideoEditor.addTransition(transition2And3); + + assertTrue("Transition ID", + transition2And3.getId().equals("transition2And3")); + assertEquals("Transtion After Media item", mediaVideoItem2, + transition2And3.getAfterMediaItem()); + assertEquals("Transtion Before Media item", mediaImageItem3, + transition2And3.getBeforeMediaItem()); + assertEquals("Transtion Duration", 1000, transition2And3.getDuration()); + assertEquals("Transtion Behavior", Transition.BEHAVIOR_SPEED_DOWN, + transition2And3.getBehavior()); + + final MediaVideoItem mediaVideoItem4 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m4", + videoItemFilename3, MediaItem.RENDERING_MODE_BLACK_BORDER); + mediaVideoItem4.setExtractBoundaries(0, 18000); + mVideoEditor.addMediaItem(mediaVideoItem4); + + final TransitionCrossfade transition3And4 = + mVideoEditorHelper.createTCrossFade("transition3And4", mediaImageItem3, + mediaVideoItem4, 5000, Transition.BEHAVIOR_LINEAR); + mVideoEditor.addTransition(transition3And4); + + assertTrue("Transition ID", + transition3And4.getId().equals("transition3And4")); + assertEquals("Transtion After Media item", mediaImageItem3, + transition3And4.getAfterMediaItem()); + assertEquals("Transtion Before Media item", mediaVideoItem4, + transition3And4.getBeforeMediaItem()); + assertEquals("Transtion Duration", 5000, transition3And4.getDuration()); + assertEquals("Transtion Behavior", Transition.BEHAVIOR_LINEAR, + transition3And4.getBehavior()); + + final MediaVideoItem mediaVideoItem5 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m5", + videoItemFilename4, MediaItem.RENDERING_MODE_BLACK_BORDER); + mVideoEditor.addMediaItem(mediaVideoItem5); + + final TransitionCrossfade transition4And5 = + mVideoEditorHelper.createTCrossFade("transition4And5", mediaVideoItem4, + mediaVideoItem5, 8000, Transition.BEHAVIOR_MIDDLE_FAST); + mVideoEditor.addTransition(transition4And5); + + assertTrue("Transition ID", + transition4And5.getId().equals("transition4And5")); + assertEquals("Transtion After Media item", mediaVideoItem4, + transition4And5.getAfterMediaItem()); + assertEquals("Transtion Before Media item", mediaVideoItem5, + transition4And5.getBeforeMediaItem()); + assertEquals("Transtion Duration", 8000, transition4And5.getDuration()); + assertEquals("Transtion Behavior", Transition.BEHAVIOR_MIDDLE_FAST, + transition4And5.getBehavior()); + + final MediaVideoItem mediaVideoItem6 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m6", + videoItemFilename5, MediaItem.RENDERING_MODE_BLACK_BORDER); + mediaVideoItem6.setExtractBoundaries(0, 20000); + mVideoEditor.addMediaItem(mediaVideoItem6); + + final TransitionCrossfade transition5And6 = + mVideoEditorHelper.createTCrossFade("transition5And6", mediaVideoItem5, + mediaVideoItem6, 2000, Transition.BEHAVIOR_MIDDLE_SLOW); + mVideoEditor.addTransition(transition5And6); + + assertTrue("Transition ID", + transition5And6.getId().equals("transition5And6")); + assertEquals("Transtion After Media item", mediaVideoItem5, + transition5And6.getAfterMediaItem()); + assertEquals("Transtion Before Media item", mediaVideoItem6, + transition5And6.getBeforeMediaItem()); + assertEquals("Transtion Duration", 2000, transition5And6.getDuration()); + assertEquals("Transtion Behavior", Transition.BEHAVIOR_MIDDLE_SLOW, + transition5And6.getBehavior()); + + flagForException = false; + try { + mVideoEditorHelper.createTCrossFade("transitiond6", mediaVideoItem5, + mediaVideoItem6, 2000, Transition.BEHAVIOR_SPEED_UP - 1); + } catch (IllegalArgumentException e) { + flagForException = true; + } + assertTrue("Transition FadeBlack with Invalid behavior", flagForException); + flagForException = false; + try { + mVideoEditorHelper.createTCrossFade("transitiond6", mediaVideoItem5, + mediaVideoItem6, 2000, Transition.BEHAVIOR_MIDDLE_FAST + 1); + } catch (IllegalArgumentException e) { + flagForException = true; + } + assertTrue("Transition FadeBlack with Invalid behavior", flagForException); + } + + /** + * To test Transition : Sliding with all behavior + * SPEED_UP/SPEED_DOWN/LINEAR/MIDDLE_SLOW/MIDDLE_FAST and Direction = + * DIRECTION_RIGHT_OUT_LEFT_IN + * ,DIRECTION_LEFT_OUT_RIGHT_IN,DIRECTION_TOP_OUT_BOTTOM_IN + * ,DIRECTION_BOTTOM_OUT_TOP_IN + */ + + // TODO : remove TC_API_039 + @LargeTest + public void testTransitionSliding() throws Exception { + final String videoItemFilename1 = INPUT_FILE_PATH + + "H264_BP_640x480_30fps_256kbps_1_17.mp4"; + final String videoItemFilename2 = INPUT_FILE_PATH + + "H263_profile0_176x144_15fps_128kbps_1_35.3gp"; + final String imageItemFilename1 = INPUT_FILE_PATH + + "IMG_1600x1200.jpg"; + final String videoItemFilename3 = INPUT_FILE_PATH + + "H264_BP_640x480_30fps_192kbps_1_5.mp4"; + final String videoItemFilename4 = INPUT_FILE_PATH + + "MPEG4_SP_640x480_15fps_256kbps_0_30.mp4"; + final String videoItemFilename5 = INPUT_FILE_PATH + + "H263_profile0_176x144_10fps_96kbps_0_25.3gp"; + boolean flagForException = false; + + final MediaVideoItem mediaVideoItem1 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", + videoItemFilename1, MediaItem.RENDERING_MODE_BLACK_BORDER); + mediaVideoItem1.setExtractBoundaries(0, 15000); + mVideoEditor.addMediaItem(mediaVideoItem1); + + final MediaVideoItem mediaVideoItem2 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m2", + videoItemFilename2, MediaItem.RENDERING_MODE_BLACK_BORDER); + mediaVideoItem2.setExtractBoundaries(0, 15000); + mVideoEditor.addMediaItem(mediaVideoItem2); + + final TransitionSliding transition1And2 = + mVideoEditorHelper.createTSliding("transition1And2", mediaVideoItem1, + mediaVideoItem2, 3000, Transition.BEHAVIOR_SPEED_UP, + TransitionSliding.DIRECTION_RIGHT_OUT_LEFT_IN); + mVideoEditor.addTransition(transition1And2); + + assertTrue("Transition ID", + transition1And2.getId().equals("transition1And2")); + assertEquals("Transtion After Media item", mediaVideoItem1, + transition1And2.getAfterMediaItem()); + assertEquals("Transtion Before Media item", mediaVideoItem2, + transition1And2.getBeforeMediaItem()); + assertEquals("Transtion Duration", 3000, transition1And2.getDuration()); + assertEquals("Transtion Behavior", Transition.BEHAVIOR_SPEED_UP, + transition1And2.getBehavior()); + assertEquals("Transition Sliding", + TransitionSliding.DIRECTION_RIGHT_OUT_LEFT_IN, + transition1And2.getDirection()); + + final MediaImageItem mediaImageItem3 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m3", + imageItemFilename1, 15000, MediaItem.RENDERING_MODE_BLACK_BORDER); + mVideoEditor.addMediaItem(mediaImageItem3); + + final TransitionSliding transition2And3 = + mVideoEditorHelper.createTSliding("transition2And3", + mediaVideoItem2, mediaImageItem3, 1000, + Transition.BEHAVIOR_SPEED_DOWN, + TransitionSliding.DIRECTION_LEFT_OUT_RIGHT_IN); + mVideoEditor.addTransition(transition2And3); + + assertTrue("Transition ID", + transition2And3.getId().equals("transition2And3")); + assertEquals("Transtion After Media item", mediaVideoItem2, + transition2And3.getAfterMediaItem()); + assertEquals("Transtion Before Media item", mediaImageItem3, + transition2And3.getBeforeMediaItem()); + assertEquals("Transtion Duration", 1000, transition2And3.getDuration()); + assertEquals("Transtion Behavior", Transition.BEHAVIOR_SPEED_DOWN, + transition2And3.getBehavior()); + assertEquals("Transition Sliding", + TransitionSliding.DIRECTION_LEFT_OUT_RIGHT_IN, + transition2And3.getDirection()); + + final MediaVideoItem mediaVideoItem4 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m4", + videoItemFilename3, MediaItem.RENDERING_MODE_BLACK_BORDER); + mediaVideoItem4.setExtractBoundaries(0, 18000); + mVideoEditor.addMediaItem(mediaVideoItem4); + + final TransitionSliding transition3And4 = + mVideoEditorHelper.createTSliding("transition3And4", mediaImageItem3, + mediaVideoItem4, 5000, Transition.BEHAVIOR_LINEAR, + TransitionSliding.DIRECTION_TOP_OUT_BOTTOM_IN); + mVideoEditor.addTransition(transition3And4); + + assertTrue("Transition ID", + transition3And4.getId().equals("transition3And4")); + assertEquals("Transtion After Media item", mediaImageItem3, + transition3And4.getAfterMediaItem()); + assertEquals("Transtion Before Media item", mediaVideoItem4, + transition3And4.getBeforeMediaItem()); + assertEquals("Transtion Duration", 5000, transition3And4.getDuration()); + assertEquals("Transtion Behavior", Transition.BEHAVIOR_LINEAR, + transition3And4.getBehavior()); + assertEquals("Transition Sliding", + TransitionSliding.DIRECTION_TOP_OUT_BOTTOM_IN, + transition3And4.getDirection()); + + final MediaVideoItem mediaVideoItem5 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m5", + videoItemFilename4, MediaItem.RENDERING_MODE_BLACK_BORDER); + mVideoEditor.addMediaItem(mediaVideoItem5); + + final TransitionSliding transition4And5 = + mVideoEditorHelper.createTSliding("transition4And5", mediaVideoItem4, + mediaVideoItem5, 8000, Transition.BEHAVIOR_MIDDLE_FAST, + TransitionSliding.DIRECTION_BOTTOM_OUT_TOP_IN); + mVideoEditor.addTransition(transition4And5); + + assertTrue("Transition ID", + transition4And5.getId().equals("transition4And5")); + assertEquals("Transtion After Media item", mediaVideoItem4, + transition4And5.getAfterMediaItem()); + assertEquals("Transtion Before Media item", mediaVideoItem5, + transition4And5.getBeforeMediaItem()); + assertEquals("Transtion Duration", 8000, transition4And5.getDuration()); + assertEquals("Transtion Behavior", Transition.BEHAVIOR_MIDDLE_FAST, + transition4And5.getBehavior()); + assertEquals("Transition Sliding", + TransitionSliding.DIRECTION_BOTTOM_OUT_TOP_IN, + transition4And5.getDirection()); + + final MediaVideoItem mediaVideoItem6 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m6", + videoItemFilename5, MediaItem.RENDERING_MODE_BLACK_BORDER); + mediaVideoItem6.setExtractBoundaries(0, 20000); + mVideoEditor.addMediaItem(mediaVideoItem6); + + final TransitionSliding transition5And6 = + mVideoEditorHelper.createTSliding("transition5And6", mediaVideoItem5, + mediaVideoItem6, 2000, Transition.BEHAVIOR_MIDDLE_SLOW, + TransitionSliding.DIRECTION_RIGHT_OUT_LEFT_IN); + mVideoEditor.addTransition(transition5And6); + + assertTrue("Transition ID", + transition5And6.getId().equals("transition5And6")); + assertEquals("Transtion After Media item", mediaVideoItem5, + transition5And6.getAfterMediaItem()); + assertEquals("Transtion Before Media item", mediaVideoItem6, + transition5And6.getBeforeMediaItem()); + assertEquals("Transtion Duration", 2000, transition5And6.getDuration()); + assertEquals("Transtion Behavior", Transition.BEHAVIOR_MIDDLE_SLOW, + transition5And6.getBehavior()); + assertEquals("Transition Sliding", + TransitionSliding.DIRECTION_RIGHT_OUT_LEFT_IN, + transition5And6.getDirection()); + + flagForException = false; + try { + mVideoEditorHelper.createTSliding("transitiond6", mediaVideoItem5, + mediaVideoItem6, 2000, Transition.BEHAVIOR_MIDDLE_SLOW, + TransitionSliding.DIRECTION_RIGHT_OUT_LEFT_IN - 1); + } catch (IllegalArgumentException e) { + flagForException = true; + } + assertTrue("Transition Sliding with Invalid Direction", flagForException); + flagForException = false; + try { + mVideoEditorHelper.createTSliding("transitiond6", mediaVideoItem5, + mediaVideoItem6, 2000, Transition.BEHAVIOR_MIDDLE_FAST + 1, + TransitionSliding.DIRECTION_BOTTOM_OUT_TOP_IN + 1); + } catch (IllegalArgumentException e) { + flagForException = true; + } + assertTrue("Transition Sliding with Invalid behavior", flagForException); + flagForException = false; + try { + mVideoEditorHelper.createTSliding("transitiond6", mediaVideoItem5, + mediaVideoItem6, 2000, Transition.BEHAVIOR_SPEED_UP - 1, + TransitionSliding.DIRECTION_RIGHT_OUT_LEFT_IN); + } catch (IllegalArgumentException e) { + flagForException = true; + } + assertTrue("Transition Sliding with Invalid behavior", flagForException); + flagForException = false; + try { + mVideoEditorHelper.createTSliding("transitiond6", mediaVideoItem5, + mediaVideoItem6, 2000, Transition.BEHAVIOR_MIDDLE_FAST + 1, + TransitionSliding.DIRECTION_RIGHT_OUT_LEFT_IN); + } catch (IllegalArgumentException e) { + flagForException = true; + } + assertTrue("Transition Sliding with Invalid behavior", flagForException); + } + + /** + * To test Transition : Alpha with all behavior + * SPEED_UP/SPEED_DOWN/LINEAR/MIDDLE_SLOW/MIDDLE_FAST + */ + + // TODO : remove TC_API_040 + @LargeTest + public void testTransitionAlpha() throws Exception { + + final String videoItemFilename1 = INPUT_FILE_PATH + + "H264_BP_640x480_30fps_256kbps_1_17.mp4"; + final String videoItemFilename2 = INPUT_FILE_PATH + + "H263_profile0_176x144_15fps_128kbps_1_35.3gp"; + final String imageItemFilename1 = INPUT_FILE_PATH + + "IMG_640x480.jpg"; + final String videoItemFilename3 = INPUT_FILE_PATH + + "H264_BP_640x480_30fps_192kbps_1_5.mp4"; + final String videoItemFilename4 = INPUT_FILE_PATH + + "MPEG4_SP_640x480_15fps_256kbps_0_30.mp4"; + final String videoItemFilename5 = INPUT_FILE_PATH + + "H263_profile0_176x144_10fps_96kbps_0_25.3gp"; + final String maskFilename = INPUT_FILE_PATH + + "TransitionSpiral_QVGA.jpg"; + boolean flagForException = false; + final MediaVideoItem mediaVideoItem1 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", + videoItemFilename1, MediaItem.RENDERING_MODE_BLACK_BORDER); + mediaVideoItem1.setExtractBoundaries(0, 15000); + mVideoEditor.addMediaItem(mediaVideoItem1); + + final MediaVideoItem mediaVideoItem2 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m2", + videoItemFilename2, MediaItem.RENDERING_MODE_BLACK_BORDER); + mediaVideoItem2.setExtractBoundaries(0, 15000); + mVideoEditor.addMediaItem(mediaVideoItem2); + + final TransitionAlpha transition1And2 = + mVideoEditorHelper.createTAlpha("transition1And2", mediaVideoItem1, + mediaVideoItem2, 3000, Transition.BEHAVIOR_SPEED_UP, maskFilename, + 10, false); + mVideoEditor.addTransition(transition1And2); + + assertTrue("Transition ID", + transition1And2.getId().equals("transition1And2")); + assertEquals("Transtion After Media item", mediaVideoItem1, + transition1And2.getAfterMediaItem()); + assertEquals("Transtion Before Media item", mediaVideoItem2, + transition1And2.getBeforeMediaItem()); + assertEquals("Transtion Duration", 3000, transition1And2.getDuration()); + assertEquals("Transtion Behavior", Transition.BEHAVIOR_SPEED_UP, + transition1And2.getBehavior()); + assertTrue("Transition maskFile", + transition1And2.getMaskFilename().equals(maskFilename)); + assertEquals("Transition BlendingPercent", 10, + transition1And2.getBlendingPercent()); + assertFalse("Transition Invert", transition1And2.isInvert()); + + final MediaImageItem mediaImageItem3 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m3", + imageItemFilename1, 15000, MediaItem.RENDERING_MODE_BLACK_BORDER); + mVideoEditor.addMediaItem(mediaImageItem3); + + final TransitionAlpha transition2And3 = + mVideoEditorHelper.createTAlpha("transition2And3", mediaVideoItem2, + mediaImageItem3, 1000, Transition.BEHAVIOR_SPEED_DOWN, + maskFilename, 30, false); + mVideoEditor.addTransition(transition2And3); + + assertTrue("Transition ID", + transition2And3.getId().equals("transition2And3")); + assertEquals("Transtion After Media item", mediaVideoItem2, + transition2And3.getAfterMediaItem()); + assertEquals("Transtion Before Media item", mediaImageItem3, + transition2And3.getBeforeMediaItem()); + assertEquals("Transtion Duration", 1000, transition2And3.getDuration()); + assertEquals("Transtion Behavior", Transition.BEHAVIOR_SPEED_DOWN, + transition2And3.getBehavior()); + assertTrue("Transition maskFile", + transition2And3.getMaskFilename().equals(maskFilename)); + assertEquals("Transition BlendingPercent", 30, + transition2And3.getBlendingPercent()); + assertFalse("Transition Invert", transition2And3.isInvert()); + + final MediaVideoItem mediaVideoItem4 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m4", + videoItemFilename3, MediaItem.RENDERING_MODE_BLACK_BORDER); + mediaVideoItem4.setExtractBoundaries(0, 18000); + mVideoEditor.addMediaItem(mediaVideoItem4); + + final TransitionAlpha transition3And4 = + mVideoEditorHelper.createTAlpha("transition3And4", mediaImageItem3, + mediaVideoItem4, 5000, Transition.BEHAVIOR_LINEAR, maskFilename, + 50, false); + mVideoEditor.addTransition(transition3And4); + + assertTrue("Transition ID", + transition3And4.getId().equals("transition3And4")); + assertEquals("Transtion After Media item", mediaImageItem3, + transition3And4.getAfterMediaItem()); + assertEquals("Transtion Before Media item", mediaVideoItem4, + transition3And4.getBeforeMediaItem()); + assertEquals("Transtion Duration", 5000, transition3And4.getDuration()); + assertEquals("Transtion Behavior", Transition.BEHAVIOR_LINEAR, + transition3And4.getBehavior()); + assertTrue("Transition maskFile", + transition3And4.getMaskFilename().equals(maskFilename)); + assertEquals("Transition BlendingPercent", 50, + transition3And4.getBlendingPercent()); + assertFalse("Transition Invert", transition3And4.isInvert()); + + final MediaVideoItem mediaVideoItem5 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m5", + videoItemFilename4, MediaItem.RENDERING_MODE_BLACK_BORDER); + mVideoEditor.addMediaItem(mediaVideoItem5); + + final TransitionAlpha transition4And5 = + mVideoEditorHelper.createTAlpha("transition4And5", mediaVideoItem4, + mediaVideoItem5, 8000, Transition.BEHAVIOR_MIDDLE_FAST, + maskFilename, 70, true); + mVideoEditor.addTransition(transition4And5); + + assertTrue("Transition ID", + transition4And5.getId().equals("transition4And5")); + assertEquals("Transtion After Media item", mediaVideoItem4, + transition4And5.getAfterMediaItem()); + assertEquals("Transtion Before Media item", mediaVideoItem5, + transition4And5.getBeforeMediaItem()); + assertEquals("Transtion Duration", 8000, transition4And5.getDuration()); + assertEquals("Transtion Behavior", Transition.BEHAVIOR_MIDDLE_FAST, + transition4And5.getBehavior()); + assertTrue("Transition maskFile", + transition4And5.getMaskFilename().equals(maskFilename)); + assertEquals("Transition BlendingPercent", 70, + transition4And5.getBlendingPercent()); + assertTrue("Transition Invert", transition4And5.isInvert()); + + final MediaVideoItem mediaVideoItem6 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m6", + videoItemFilename5, MediaItem.RENDERING_MODE_BLACK_BORDER); + mediaVideoItem6.setExtractBoundaries(0, 20000); + mVideoEditor.addMediaItem(mediaVideoItem6); + + try { + mVideoEditorHelper.createTAlpha("transition5And6", mediaVideoItem5, + mediaVideoItem6, 2000, Transition.BEHAVIOR_MIDDLE_SLOW, + INPUT_FILE_PATH + "imDummyFile.jpg", 70, + true); + } catch (IllegalArgumentException e) { + flagForException = true; + } + assertTrue("MaskFile is not exsisting", flagForException); + flagForException = false; + try { + mVideoEditorHelper.createTAlpha("transition5And6", null, null, 2000, + Transition.BEHAVIOR_MIDDLE_SLOW, maskFilename, 101, true); + } catch (IllegalArgumentException e) { + flagForException = true; + } + assertTrue("Invalid Blending Percent", flagForException); + + flagForException = false; + try { + mVideoEditorHelper.createTAlpha("transitiond6", mediaVideoItem4, + mediaVideoItem5, 2000, Transition.BEHAVIOR_SPEED_UP - 1, + maskFilename, 30, false); + } catch (IllegalArgumentException e) { + flagForException = true; + } + assertTrue("Transition FadeBlack with Invalid behavior", flagForException); + flagForException = false; + try { + mVideoEditorHelper.createTAlpha("transitiond6", mediaVideoItem4, + mediaVideoItem5, 2000, Transition.BEHAVIOR_MIDDLE_FAST + 1, + maskFilename, 30, false); + } catch (IllegalArgumentException e) { + flagForException = true; + } + assertTrue("Transition FadeBlack with Invalid behavior", flagForException); + } + + /** + * To test Frame Overlay for Media Video Item + */ + + // TODO : remove TC_API_041 + @LargeTest + public void testFrameOverlayVideoItem() throws Exception { + final String videoItemFilename1 = INPUT_FILE_PATH + + "H263_profile0_176x144_10fps_256kbps_0_25.3gp"; + final String overlayFile1 = INPUT_FILE_PATH + "IMG_176x144_Overlay1.png"; + final String overlayFile2 = INPUT_FILE_PATH + "IMG_176x144_Overlay2.png"; + final MediaVideoItem mediaVideoItem1 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", + videoItemFilename1, MediaItem.RENDERING_MODE_BLACK_BORDER); + mVideoEditor.addMediaItem(mediaVideoItem1); + + final Bitmap mBitmap1 = mVideoEditorHelper.getBitmap(overlayFile1, + 176, 144); + final OverlayFrame overlayFrame1 = mVideoEditorHelper.createOverlay( + mediaVideoItem1, "overlayId1", mBitmap1, 5000, 5000); + mediaVideoItem1.addOverlay(overlayFrame1); + + assertEquals("Overlay : Media Item", mediaVideoItem1, + overlayFrame1.getMediaItem()); + assertTrue("Overlay Id", overlayFrame1.getId().equals("overlayId1")); + assertEquals("Overlay Bitmap", mBitmap1, overlayFrame1.getBitmap()); + assertEquals("Overlay Start Time", 5000, overlayFrame1.getStartTime()); + assertEquals("Overlay Duration", 5000, overlayFrame1.getDuration()); + + Bitmap upddateBmp = mVideoEditorHelper.getBitmap(overlayFile2, 176, 144); + overlayFrame1.setBitmap(upddateBmp); + assertEquals("Overlay Update Bitmap", upddateBmp, overlayFrame1.getBitmap()); + upddateBmp.recycle(); + } + + /** + * To test Frame Overlay for Media Video Item : Set duration and Get + * Duration + */ + + // TODO : remove TC_API_042 + @LargeTest + public void testFrameOverlaySetAndGet() throws Exception { + final String videoItemFilename1 = INPUT_FILE_PATH + + "MPEG4_SP_640x480_30fps_512Kbps_0_27.mp4"; + final String overlayFile1 = INPUT_FILE_PATH + "IMG_640x480_Overlay1.png"; + boolean flagForException = false; + + final Bitmap mBitmap = mVideoEditorHelper.getBitmap(overlayFile1, + 640, 480); + + final MediaVideoItem mediaVideoItem1 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", + videoItemFilename1, MediaItem.RENDERING_MODE_BLACK_BORDER); + mVideoEditor.addMediaItem(mediaVideoItem1); + + final OverlayFrame overlayFrame1 = mVideoEditorHelper.createOverlay( + mediaVideoItem1, "overlayId1", mBitmap, 5000, 5000); + mediaVideoItem1.addOverlay(overlayFrame1); + overlayFrame1.setDuration(5000); + + assertEquals("Overlay Duration", 5000, overlayFrame1.getDuration()); + try { + overlayFrame1.setDuration(mediaVideoItem1.getDuration() + 10000); + } catch (IllegalArgumentException e) { + flagForException = true; + } + assertTrue("Overlay Duration > MediaVideo Item Duration", + flagForException); + + assertEquals("Overlay Duration", 5000, overlayFrame1.getDuration()); + flagForException = false; + + try { + overlayFrame1.setDuration(-1); + } catch (IllegalArgumentException e) { + flagForException = true; + } + assertTrue("Overlay Duration = -1", flagForException); + } + + /** + * To test Frame Overlay for Media Video Item : Set duration and Get + * Duration + */ + + // TODO : remove TC_API_043 + @LargeTest + public void testFrameOverlayInvalidTime() throws Exception { + final String videoItemFilename1 = INPUT_FILE_PATH + + "MPEG4_SP_640x480_15fps_1200kbps_AACLC_48khz_64kbps_m_1_17.3gp"; + final String overlayFile1 = INPUT_FILE_PATH + "IMG_640x480_Overlay1.png"; + boolean flagForException = false; + + final MediaVideoItem mediaVideoItem1 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", + videoItemFilename1, MediaItem.RENDERING_MODE_BLACK_BORDER); + mVideoEditor.addMediaItem(mediaVideoItem1); + + try { + final Bitmap mBitmap = mVideoEditorHelper.getBitmap(overlayFile1, + 640, 480); + mVideoEditorHelper.createOverlay(mediaVideoItem1, "overlayId1", + mBitmap, 400000000, 2000); + } catch (IllegalArgumentException e) { + flagForException = true; + } + assertTrue("Overlay With Invalid Start Time", flagForException); + + flagForException = false; + try { + final Bitmap mBitmap = mVideoEditorHelper.getBitmap(overlayFile1, + 640, 480); + mVideoEditorHelper.createOverlay(mediaVideoItem1, "overlayId2", + mBitmap, -1, 2000); + } catch (IllegalArgumentException e) { + flagForException = true; + } + assertTrue("Overlay With Invalid Start Time", flagForException); + + flagForException = false; + try { + final Bitmap mBitmap = mVideoEditorHelper.getBitmap(overlayFile1, + 640, 480); + mVideoEditorHelper.createOverlay(mediaVideoItem1, "overlayId3", + mBitmap, 2000, -1); + } catch (IllegalArgumentException e) { + flagForException = true; + } + assertTrue("Overlay With Invalid Start Time", flagForException); + } + + /** + * To test Frame Overlay for Media Image Item + */ + // TODO : remove TC_API_045 + @LargeTest + public void testFrameOverlayImageItem() throws Exception { + final String imageItemFilename1 = INPUT_FILE_PATH + "IMG_640x480.jpg"; + final String overlayFile1 = INPUT_FILE_PATH + "IMG_640x480_Overlay1.png"; + final String overlayFile2 = INPUT_FILE_PATH + "IMG_640x480_Overlay2.png"; + + final MediaImageItem mediaImageItem1 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", + imageItemFilename1, 10000, MediaItem.RENDERING_MODE_BLACK_BORDER); + mVideoEditor.addMediaItem(mediaImageItem1); + + final Bitmap mBitmap = mVideoEditorHelper.getBitmap(overlayFile1, 640, + 480); + final OverlayFrame overlayFrame1 = mVideoEditorHelper.createOverlay( + mediaImageItem1, "overlayId1", mBitmap, 5000, 5000); + mediaImageItem1.addOverlay(overlayFrame1); + + assertEquals("Overlay : Media Item", mediaImageItem1, + overlayFrame1.getMediaItem()); + assertTrue("Overlay Id", overlayFrame1.getId().equals("overlayId1")); + assertEquals("Overlay Bitmap",mBitmap ,overlayFrame1.getBitmap()); + assertEquals("Overlay Start Time", 5000, overlayFrame1.getStartTime()); + assertEquals("Overlay Duration", 5000, overlayFrame1.getDuration()); + Bitmap upddateBmp = mVideoEditorHelper.getBitmap(overlayFile2, 640, 480); + + overlayFrame1.setBitmap(upddateBmp); + assertEquals("Overlay Update Bitmap", upddateBmp, overlayFrame1.getBitmap()); + upddateBmp.recycle(); + } + + /** + * To test Frame Overlay for Media Image Item : Set duration and Get + * Duration + */ + + // TODO : remove TC_API_046 + @LargeTest + public void testFrameOverlaySetAndGetImage() throws Exception { + final String videoItemFilename1 = INPUT_FILE_PATH + "IMG_640x480.jpg"; + final String overlayFile1 = INPUT_FILE_PATH + "IMG_640x480_Overlay1.png"; + boolean flagForException = false; + + final MediaImageItem mediaImageItem1 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", + videoItemFilename1, 10000, MediaItem.RENDERING_MODE_BLACK_BORDER); + mVideoEditor.addMediaItem(mediaImageItem1); + + final Bitmap mBitmap = mVideoEditorHelper.getBitmap(overlayFile1, + 640, 480); + final OverlayFrame overlayFrame1 = mVideoEditorHelper.createOverlay( + mediaImageItem1, "overlayId1", mBitmap, 5000, 5000); + mediaImageItem1.addOverlay(overlayFrame1); + + overlayFrame1.setDuration(5000); + assertEquals("Overlay Duration", 5000, overlayFrame1.getDuration()); + + try { + overlayFrame1.setDuration(mediaImageItem1.getDuration() + 10000); + } catch (IllegalArgumentException e) { + flagForException = true; + } + assertTrue("Overlay Duration > Media Item Duration", flagForException); + assertEquals("Overlay Duration", 5000, overlayFrame1.getDuration()); + + flagForException = false; + try { + overlayFrame1.setDuration(-1); + } catch (IllegalArgumentException e) { + flagForException = true; + } + assertTrue("Overlay Duration = -1", flagForException); + } + + /** + * To test Frame Overlay for Media Image Item :Invalid StartTime and + * Duration + */ + + // TODO : remove TC_API_047 + @LargeTest + public void testFrameOverlayInvalidTimeImage() throws Exception { + final String videoItemFilename1 = INPUT_FILE_PATH + "IMG_640x480.jpg"; + final String overlayFile1 = INPUT_FILE_PATH + "IMG_640x480_Overlay1.png"; + boolean flagForException = false; + + final MediaImageItem mediaImageItem1 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", + videoItemFilename1, 10000, MediaItem.RENDERING_MODE_BLACK_BORDER); + mVideoEditor.addMediaItem(mediaImageItem1); + + try { + final Bitmap mBitmap = mVideoEditorHelper.getBitmap(overlayFile1, + 640, 480); + mVideoEditorHelper.createOverlay(mediaImageItem1, "overlayId1", + mBitmap, 400000000, 2000); + } catch (IllegalArgumentException e) { + flagForException = true; + } + assertTrue("Overlay With Invalid Start Time", flagForException); + + flagForException = false; + try { + final Bitmap mBitmap = mVideoEditorHelper.getBitmap(overlayFile1, + 640, 480); + mVideoEditorHelper.createOverlay(mediaImageItem1, "overlayId2", + mBitmap, -1, 2000); + } catch (IllegalArgumentException e) { + flagForException = true; + } + assertTrue("Overlay With Invalid Start Time", flagForException); + + flagForException = false; + try { + final Bitmap mBitmap = mVideoEditorHelper.getBitmap(overlayFile1, + 640, 480); + mVideoEditorHelper.createOverlay(mediaImageItem1, "overlayId3", + mBitmap, 2000, -1); + } catch (IllegalArgumentException e) { + flagForException = true; + } + assertTrue("Overlay With Invalid Start Time", flagForException); + } + + /** + * To Test Frame Overlay Media Image Item :JPG File + */ + + // TODO : remove TC_API_048 + @LargeTest + public void testFrameOverlayJPGImage() throws Exception { + + final String imageItemFilename = INPUT_FILE_PATH + "IMG_640x480.jpg"; + final String overlayFile1 = INPUT_FILE_PATH + "IMG_640x480_Overlay1.png"; + boolean flagForException = false; + final MediaImageItem mediaImageItem1 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", + imageItemFilename, 10000, MediaItem.RENDERING_MODE_BLACK_BORDER); + mVideoEditor.addMediaItem(mediaImageItem1); + final Bitmap mBitmap = mVideoEditorHelper.getBitmap(overlayFile1, 640, + 480); + mVideoEditorHelper.createOverlay(mediaImageItem1, "overlayId1", + mBitmap, 5000, 5000); + } + + /** + * To test Video Editor API + * + * @throws Exception + */ + // TODO : remove TC_API_049 + @LargeTest + public void testVideoEditorAPI() throws Exception { + + final String videoItemFileName1 = INPUT_FILE_PATH + + "MPEG4_SP_720x480_30fps_280kbps_AACLC_48kHz_96kbps_s_0_21.mp4"; + final String videoItemFileName2 = INPUT_FILE_PATH + + "MPEG4_SP_640x480_15fps_1200kbps_AACLC_48khz_64kbps_m_1_17.3gp"; + final String videoItemFileName3 = INPUT_FILE_PATH + + "MPEG4_SP_640x480_15fps_512kbps_AACLC_48khz_132kbps_s_0_26.mp4"; + final String imageItemFileName1 = INPUT_FILE_PATH + "IMG_640x480.jpg"; + final String imageItemFileName2 = INPUT_FILE_PATH + "IMG_176x144.jpg"; + final String audioFilename1 = INPUT_FILE_PATH + + "AMRNB_8KHz_12.2Kbps_m_1_17.3gp"; + final String audioFilename2 = INPUT_FILE_PATH + + "AACLC_48KHz_256Kbps_s_1_17.3gp"; + final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; + boolean flagForException = false; + TransitionCrossfade transition2And4; + + final MediaVideoItem mediaVideoItem1 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", + videoItemFileName1, renderingMode); + mediaVideoItem1.setExtractBoundaries(0, 10000); + mVideoEditor.addMediaItem(mediaVideoItem1); + + final MediaVideoItem mediaVideoItem2 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m2", + videoItemFileName2, renderingMode); + mediaVideoItem2.setExtractBoundaries(mediaVideoItem2.getDuration() / 4, + mediaVideoItem2.getDuration() / 2); + mVideoEditor.addMediaItem(mediaVideoItem2); + + final MediaVideoItem mediaVideoItem3 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m3", + videoItemFileName3, renderingMode); + mediaVideoItem3.setExtractBoundaries(mediaVideoItem3.getDuration() / 2, + mediaVideoItem3.getDuration()); + mVideoEditor.addMediaItem(mediaVideoItem3); + + final MediaImageItem mediaImageItem1 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m4", + imageItemFileName1, 5000, renderingMode); + + final MediaImageItem mediaImageItem2 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m5", + imageItemFileName2, 5000, renderingMode); + + List mediaList = mVideoEditor.getAllMediaItems(); + assertEquals("Media Item List Size", 3, mediaList.size()); + + mVideoEditor.insertMediaItem(mediaImageItem1, mediaVideoItem2.getId()); + mediaList = mVideoEditor.getAllMediaItems(); + assertEquals("Media Item List Size", 4, mediaList.size()); + assertEquals("Media item 1", mediaVideoItem1, mediaList.get(0)); + assertEquals("Media item 2", mediaVideoItem2, mediaList.get(1)); + assertEquals("Media item 4", mediaImageItem1, mediaList.get(2)); + assertEquals("Media item 3", mediaVideoItem3, mediaList.get(3)); + + mVideoEditor.insertMediaItem(mediaImageItem2, mediaImageItem1.getId()); + mediaList = mVideoEditor.getAllMediaItems(); + assertEquals("Media Item List Size", 5, mediaList.size()); + assertEquals("Media item 1", mediaVideoItem1, mediaList.get(0)); + assertEquals("Media item 2", mediaVideoItem2, mediaList.get(1)); + assertEquals("Media item 4", mediaImageItem1, mediaList.get(2)); + assertEquals("Media item 5", mediaImageItem2, mediaList.get(3)); + assertEquals("Media item 3", mediaVideoItem3, mediaList.get(4)); + + mVideoEditor.moveMediaItem(mediaVideoItem1.getId(), mediaImageItem2.getId()); + mediaList = mVideoEditor.getAllMediaItems(); + assertEquals("Media Item List Size", 5, mediaList.size()); + assertEquals("Media item 2", mediaVideoItem2, mediaList.get(0)); + assertEquals("Media item 4", mediaImageItem1, mediaList.get(1)); + assertEquals("Media item 5", mediaImageItem2, mediaList.get(2)); + assertEquals("Media item 1", mediaVideoItem1, mediaList.get(3)); + assertEquals("Media item 3", mediaVideoItem3, mediaList.get(4)); + + assertEquals("Media Item 1", mediaVideoItem1, + mVideoEditor.getMediaItem(mediaVideoItem1.getId())); + + flagForException = false; + transition2And4 = null; + try{ + transition2And4 = mVideoEditorHelper.createTCrossFade( + "transition2And4", mediaVideoItem2, mediaImageItem1, 2000, + Transition.BEHAVIOR_MIDDLE_FAST); + mVideoEditor.addTransition(transition2And4); + } + catch (IllegalArgumentException e) { + flagForException = true; + } + assertFalse("Transition2and4 cannot be created", flagForException); + + + TransitionCrossfade transition1And3 = null; + flagForException = false; + try{ + transition1And3 = mVideoEditorHelper.createTCrossFade( + "transition1And3", mediaVideoItem1, mediaVideoItem2, 5000, + Transition.BEHAVIOR_MIDDLE_FAST); + mVideoEditor.addTransition(transition1And3); + }catch (IllegalArgumentException e) { + flagForException = true; + } + assertTrue("Transition1and3 cannot be created", flagForException); + + List transitionList = mVideoEditor.getAllTransitions(); + assertEquals("Transition List", 1, transitionList.size()); + + assertEquals("Transition 2", transition2And4, + mVideoEditor.getTransition(transition2And4.getId())); + + final AudioTrack audioTrack = mVideoEditorHelper.createAudio( + mVideoEditor, "audioTrack", audioFilename1); + mVideoEditor.addAudioTrack(audioTrack); + + List audioList = mVideoEditor.getAllAudioTracks(); + assertEquals("Audio List", 1, audioList.size()); + + final AudioTrack audioTrack1 = mVideoEditorHelper.createAudio( + mVideoEditor, "audioTrack1", audioFilename2); + flagForException = false; + try { + mVideoEditor.addAudioTrack(audioTrack1); + } catch (IllegalArgumentException e) { + flagForException = true; + } + assertTrue("Audio Track support is 1 ", flagForException); + + flagForException = false; + try { + mVideoEditor.insertAudioTrack(audioTrack1,"audioTrack"); + } catch (IllegalArgumentException e) { + flagForException = true; + } + assertTrue("Audio Track supports is 1 ", flagForException); + + assertEquals("Removing AudioTrack", audioTrack, + mVideoEditor.removeAudioTrack(audioTrack.getId())); + + assertEquals("Removing transition", transition2And4, + mVideoEditor.removeTransition(transition2And4.getId())); + + assertEquals("Removing Media Item", mediaVideoItem2, + mVideoEditor.removeMediaItem(mediaVideoItem2.getId())); + + mVideoEditor.setAspectRatio(MediaProperties.ASPECT_RATIO_16_9); + assertEquals("Check Aspect Ratio", MediaProperties.ASPECT_RATIO_16_9, + mVideoEditor.getAspectRatio()); + + long storyBoardDuration = mediaVideoItem1.getTimelineDuration() + + mediaVideoItem3.getTimelineDuration() + + mediaImageItem1.getDuration() + + mediaImageItem2.getDuration(); + assertEquals("Story Board Duration", storyBoardDuration, + mVideoEditor.getDuration()); + } + + /** + * To add Audio Track Greater than MediaItem Duration + * + * @throws Exception + */ + // TODO : remove TC_API_050 + @LargeTest + public void testVideoLessThanAudio() throws Exception { + final String videoItemFileName1 = INPUT_FILE_PATH + + "MPEG4_SP_720x480_30fps_280kbps_AACLC_48kHz_96kbps_s_0_21.mp4"; + final String audioTrackFilename = INPUT_FILE_PATH + + "AACLC_48KHz_256Kbps_s_1_17.3gp"; + final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; + + final MediaVideoItem mediaVideoItem1 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", + videoItemFileName1, renderingMode); + mVideoEditor.addMediaItem(mediaVideoItem1); + final AudioTrack audioTrack = mVideoEditorHelper.createAudio( + mVideoEditor, "audioTrackId", audioTrackFilename); + mVideoEditor.addAudioTrack(audioTrack); + assertEquals("Storyboard = mediaItem Duration", + mediaVideoItem1.getDuration(), mVideoEditor.getDuration()); + assertTrue("Audio Duration > mediaItem Duration", + (audioTrack.getDuration() > mediaVideoItem1.getDuration() ? + true : false)); + } + + /** + * To test Video Editor API with 1080 P + * + * @throws Exception + */ + // TODO : remove TC_API_051 + @LargeTest + public void testVideoContentHD() throws Exception { + final String videoItemFileName1 = INPUT_FILE_PATH + + "H264_BP_1920x1080_30fps_1200Kbps_1_10.mp4"; + final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; + final MediaVideoItem mediaVideoItem1; + // 1080p resolution is supported on some devices + // but not on other devices. + // So this test case is not generic and + // hence we always assert true + boolean flagForException = true; + try { + mediaVideoItem1 = mVideoEditorHelper.createMediaItem(mVideoEditor, + "m1", videoItemFileName1, renderingMode); + } catch (IllegalArgumentException e) { + } + assertTrue("VideoContent 1920x1080", flagForException); + } + + + /** + * To test: Remove audio track + * + * @throws Exception + */ + // TODO : remove TC_API_052 + @LargeTest + public void testRemoveAudioTrack() throws Exception { + final String audioFileName = INPUT_FILE_PATH + + "AACLC_48KHz_256Kbps_s_1_17.3gp"; + boolean flagForException = false; + + final AudioTrack audioTrack = mVideoEditorHelper.createAudio( + mVideoEditor, "audioTrack1", audioFileName); + mVideoEditor.addAudioTrack(audioTrack); + + assertEquals("Audio Track Item Duration", audioTrack.getDuration(), + audioTrack.getTimelineDuration()); + assertTrue("Audio Track ID", audioTrack.getId().equals("audioTrack1")); + assertNotNull("Remove Audio Track", + mVideoEditor.removeAudioTrack("audioTrack1")); + try{ + mVideoEditor.removeAudioTrack("audioTrack1"); + }catch (IllegalArgumentException e){ + flagForException = true; + } + assertTrue("Remove Audio Track not possible", flagForException); + } + + /** + * To test: Disable ducking + * + * @throws Exception + */ + // TODO : remove TC_API_053 + @LargeTest + public void testAudioDuckingDisable() throws Exception { + final String audioFileName = INPUT_FILE_PATH + + "AACLC_48KHz_256Kbps_s_1_17.3gp"; + final AudioTrack audioTrack = mVideoEditorHelper.createAudio( + mVideoEditor, "audioTrack", audioFileName); + mVideoEditor.addAudioTrack(audioTrack); + + audioTrack.disableDucking(); + assertFalse("Audio Track Ducking is Disabled", + audioTrack.isDuckingEnabled()); + } + + + // TODO : remove TC_API_054 + /** This test case is added with Test case ID TC_API_010 */ + + /** + * To test: Need a basic test case for the get value for TransitionAlpha + * ( ie. getBlendingPercent, getMaskFilename, isInvert) + * + * @throws Exception + */ + // TODO : remove TC_API_055 + @LargeTest + public void testTransitionAlphaBasic() throws Exception { + + final String videoItemFilename1 = INPUT_FILE_PATH + + "H264_BP_640x480_30fps_256kbps_1_17.mp4"; + final String maskFilename = INPUT_FILE_PATH + "IMG_640x480_Overlay1.png"; + boolean flagForException = false; + + final MediaVideoItem mediaVideoItem1 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", + videoItemFilename1, MediaItem.RENDERING_MODE_BLACK_BORDER); + mediaVideoItem1.setExtractBoundaries(0, 15000); + + final MediaImageItem mediaImageItem = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m2", maskFilename, + 10000, MediaItem.RENDERING_MODE_BLACK_BORDER); + mediaImageItem.setDuration(15000); + + mVideoEditor.addMediaItem(mediaVideoItem1); + mVideoEditor.addMediaItem(mediaImageItem); + final TransitionAlpha transition1And2 = + mVideoEditorHelper.createTAlpha("transition1And2", mediaVideoItem1, + mediaImageItem, 3000, Transition.BEHAVIOR_SPEED_UP, + maskFilename, 10, false); + mVideoEditor.addTransition(transition1And2); + assertTrue("Transition maskFile", + transition1And2.getMaskFilename().equals(maskFilename)); + assertEquals("Transition BlendingPercent", 10, + transition1And2.getBlendingPercent()); + assertFalse("Transition Invert", transition1And2.isInvert()); + } + + /** + * To test: NULL arguments to the Video Editor APIs + * + * @throws Exception + */ + // TODO : remove TC_API_056 + @LargeTest + public void testNullAPIs() throws Exception { + + final String videoItemFilename1 = INPUT_FILE_PATH + + "H264_BP_640x480_30fps_256kbps_1_17.mp4"; + final String maskFilename = INPUT_FILE_PATH + + "IMG_640x480_Overlay1.png"; + final String audioFileName = INPUT_FILE_PATH + + "AACLC_48KHz_256Kbps_s_1_17.3gp"; + boolean flagForException = false; + + try { + mVideoEditor.addAudioTrack(null); + } catch(IllegalArgumentException e) { + flagForException = true; + } + assertTrue("Video Editor with null Audio Track", flagForException); + flagForException = false; + try { + mVideoEditor.addMediaItem(null); + } catch(IllegalArgumentException e) { + flagForException = true; + } + assertTrue("Video Editor with NULL Image Item ", flagForException); + flagForException = false; + try { + mVideoEditor.addMediaItem(null); + } catch(IllegalArgumentException e) { + flagForException = true; + } + assertTrue("Video Editor with NULL Video Item ", flagForException); + + MediaVideoItem mediaVideoItem1 = null; + try { + mediaVideoItem1 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", + videoItemFilename1, MediaItem.RENDERING_MODE_BLACK_BORDER); + } catch (IllegalArgumentException e) { + assertTrue("Cannot Create Video Item", false); + } + mediaVideoItem1.setExtractBoundaries(0, 15000); + mVideoEditor.addMediaItem(mediaVideoItem1); + flagForException = false; + try { + mediaVideoItem1.addEffect(null); + } catch(IllegalArgumentException e) { + flagForException = true; + } + assertTrue("Video with null effect ", flagForException); + flagForException = false; + try { + mediaVideoItem1.addOverlay(null); + } catch(IllegalArgumentException e) { + flagForException = true; + } + assertTrue("Video with null overlay ", flagForException); + + final MediaImageItem mediaImageItem = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m2", maskFilename, + 10000, MediaItem.RENDERING_MODE_BLACK_BORDER); + mediaImageItem.setDuration(15000); + mVideoEditor.addMediaItem(mediaImageItem); + flagForException = false; + try { + mediaImageItem.addEffect(null); + } catch(IllegalArgumentException e) { + flagForException = true; + } + assertTrue("Image with null effect ", flagForException); + flagForException = false; + try { + mediaImageItem.addOverlay(null); + } catch(IllegalArgumentException e) { + flagForException = true; + } + assertTrue("Image with null overlay ", flagForException); + + final AudioTrack audioTrack = mVideoEditorHelper.createAudio( + mVideoEditor, "audioTrack", audioFileName); + mVideoEditor.addAudioTrack(audioTrack); + + flagForException = false; + try { + mVideoEditor.addTransition(null); + } catch(IllegalArgumentException e) { + flagForException = true; + } + assertTrue("Added null transition ", flagForException); + + flagForException = false; + try { + mVideoEditor.addTransition(null); + } catch(IllegalArgumentException e) { + flagForException = true; + } + assertTrue("Added null transition ", flagForException); + + } +} diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/videoeditor/VideoEditorExportTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/videoeditor/VideoEditorExportTest.java new file mode 100755 index 0000000..57a1c75 --- /dev/null +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/videoeditor/VideoEditorExportTest.java @@ -0,0 +1,820 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.mediaframeworktest.functional.videoeditor; + +import java.io.File; + +import android.graphics.Bitmap; +import android.graphics.Rect; +import android.media.videoeditor.AudioTrack; +import android.media.videoeditor.EffectColor; +import android.media.videoeditor.EffectKenBurns; +import android.media.videoeditor.MediaImageItem; +import android.media.videoeditor.MediaItem; +import android.media.videoeditor.MediaProperties; +import android.media.videoeditor.MediaVideoItem; +import android.media.videoeditor.OverlayFrame; +import android.media.videoeditor.Transition; +import android.media.videoeditor.TransitionAlpha; +import android.media.videoeditor.TransitionCrossfade; +import android.media.videoeditor.TransitionFadeBlack; +import android.media.videoeditor.TransitionSliding; +import android.media.videoeditor.VideoEditor; +import android.media.videoeditor.VideoEditor.ExportProgressListener; +import android.media.videoeditor.VideoEditor.MediaProcessingProgressListener; +import android.os.Environment; +import android.test.ActivityInstrumentationTestCase; + + +import android.util.Log; + +import com.android.mediaframeworktest.MediaFrameworkTest; +import android.test.suitebuilder.annotation.LargeTest; +import android.test.suitebuilder.annotation.Suppress; +import com.android.mediaframeworktest.VideoEditorHelper; + +public class VideoEditorExportTest extends + ActivityInstrumentationTestCase { + private final String TAG = "TransitionTest"; + + private final String PROJECT_LOCATION = VideoEditorHelper.PROJECT_LOCATION_COMMON; + + private final String INPUT_FILE_PATH = VideoEditorHelper.INPUT_FILE_PATH_COMMON; + + private VideoEditor mVideoEditor; + + private VideoEditorHelper mVideoEditorHelper; + + // Declares the annotation for Preview Test Cases + public @interface TransitionTests { + } + + public VideoEditorExportTest() { + super("com.android.mediaframeworktest", MediaFrameworkTest.class); + } + + @Override + protected void setUp() throws Exception { + // setup for each test case. + super.setUp(); + mVideoEditorHelper = new VideoEditorHelper(); + // Create a random String which will be used as project path, where all + // project related files will be stored. + final String projectPath = + mVideoEditorHelper.createRandomFile(PROJECT_LOCATION); + mVideoEditor = mVideoEditorHelper.createVideoEditor(projectPath); + } + + @Override + protected void tearDown() throws Exception { + mVideoEditorHelper.destroyVideoEditor(mVideoEditor); + // Clean the directory created as project path + mVideoEditorHelper.deleteProject(new File(mVideoEditor.getPath())); + System.gc(); + super.tearDown(); + } + + /** + * To Test export : Merge and Trim different types of Video and Image files + */ + // TODO :remove TC_EXP_001 + @LargeTest + public void testExportMergeTrim() throws Exception { + final String videoItemFilename1 = INPUT_FILE_PATH + + "H263_profile0_176x144_15fps_256kbps_AACLC_32kHz_128kbps_s_0_26.3gp"; + final String imageItemFilename1 = INPUT_FILE_PATH + "IMG_1600x1200.jpg"; + final String videoItemFilename2 = INPUT_FILE_PATH + + "H264_BP_640x480_12.5fps_256kbps_AACLC_16khz_24kbps_s_0_26.mp4"; + final String videoItemFilename3 = INPUT_FILE_PATH + + "MPEG4_SP_720x480_30fps_280kbps_AACLC_48kHz_96kbps_s_0_21.mp4"; + final String imageItemFilename2 = INPUT_FILE_PATH + "IMG_176x144.jpg"; + final String imageItemFilename3 = INPUT_FILE_PATH + "IMG_640x480.jpg"; + final String outFilename = mVideoEditorHelper + .createRandomFile(mVideoEditor.getPath() + "/") + + ".3gp"; + + final MediaVideoItem mediaVideoItem1 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", + videoItemFilename1, MediaItem.RENDERING_MODE_BLACK_BORDER); + mediaVideoItem1.setExtractBoundaries(2000, 7000); + mVideoEditor.addMediaItem(mediaVideoItem1); + + final MediaImageItem mediaImageItem2 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m2", + imageItemFilename1, 3000, MediaItem.RENDERING_MODE_BLACK_BORDER); + mVideoEditor.addMediaItem(mediaImageItem2); + + final MediaVideoItem mediaVideoItem3 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m3", + videoItemFilename2, MediaItem.RENDERING_MODE_BLACK_BORDER); + mediaVideoItem3.setExtractBoundaries(0, 2000); + mVideoEditor.addMediaItem(mediaVideoItem3); + + final MediaVideoItem mediaVideoItem4 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m4", + videoItemFilename3, MediaItem.RENDERING_MODE_BLACK_BORDER); + mediaVideoItem4.setExtractBoundaries(mediaVideoItem4.getDuration()-5000, + mediaVideoItem4.getDuration()); + mVideoEditor.addMediaItem(mediaVideoItem4); + + final MediaImageItem mediaImageItem5 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m5", + imageItemFilename2, 4000, MediaItem.RENDERING_MODE_BLACK_BORDER); + mVideoEditor.addMediaItem(mediaImageItem5); + + final MediaImageItem mediaImageItem6 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m6", + imageItemFilename3, 2000, MediaItem.RENDERING_MODE_BLACK_BORDER); + mVideoEditor.addMediaItem(mediaImageItem6); + + mVideoEditor.generatePreview(new MediaProcessingProgressListener() { + public void onProgress(Object item, int action, int progress) { + } + }); + + try { + final int[] progressUpdate = new int[100]; + mVideoEditor.export(outFilename, MediaProperties.HEIGHT_720, + MediaProperties.BITRATE_800K, new ExportProgressListener() { + int i = 0; + public void onProgress(VideoEditor ve, String outFileName, + int progress) { + progressUpdate[i++] = progress; + } + }); + mVideoEditorHelper.checkProgressCBValues(progressUpdate); + } catch (Exception e) { + assertTrue("Error in Export" + e.toString(), false); + } + final long storyBoardDuration = mediaVideoItem1.getTimelineDuration() + + mediaImageItem2.getDuration() + mediaVideoItem3.getTimelineDuration() + + mediaVideoItem4.getTimelineDuration() + mediaImageItem5.getDuration() + + mediaImageItem6.getDuration(); + mVideoEditorHelper.validateExport(mVideoEditor, outFilename, + MediaProperties.HEIGHT_720, 0, storyBoardDuration, + MediaProperties.VCODEC_H264, MediaProperties.ACODEC_AAC_LC); + mVideoEditorHelper.checkDeleteExistingFile(outFilename); + } + + /** + *To Test export : With Effect and Overlays on Different Media Items + */ + // TODO :remove TC_EXP_002 + @LargeTest + public void testExportEffectOverlay() throws Exception { + final String videoItemFilename1 = INPUT_FILE_PATH + + "H263_profile0_176x144_15fps_256kbps_AACLC_32kHz_128kbps_s_0_26.3gp"; + final String imageItemFilename1 = INPUT_FILE_PATH + "IMG_1600x1200.jpg"; + final String videoItemFilename2 = INPUT_FILE_PATH + + "H264_BP_640x480_15fps_1200Kbps_AACLC_48KHz_64kps_m_0_27.3gp"; + final String videoItemFilename3 = INPUT_FILE_PATH + + "MPEG4_SP_720x480_30fps_280kbps_AACLC_48kHz_96kbps_s_0_21.mp4"; + final String imageItemFilename2 = INPUT_FILE_PATH + "IMG_176x144.jpg"; + final String imageItemFilename3 = INPUT_FILE_PATH + "IMG_640x480.jpg"; + final String outFilename = mVideoEditorHelper + .createRandomFile(mVideoEditor.getPath() + "/") + ".3gp"; + + final String overlayFile = INPUT_FILE_PATH + "IMG_640x480_Overlay1.png"; + + final MediaVideoItem mediaVideoItem1 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", + videoItemFilename1, MediaItem.RENDERING_MODE_BLACK_BORDER); + mediaVideoItem1.setExtractBoundaries(2000, 7000); + mVideoEditor.addMediaItem(mediaVideoItem1); + + final EffectColor effectPink = + mVideoEditorHelper.createEffectItem(mediaVideoItem1, "effectPink", + 0, 2000, EffectColor.TYPE_COLOR, EffectColor.PINK); + mediaVideoItem1.addEffect(effectPink); + + final EffectColor effectNegative = + mVideoEditorHelper.createEffectItem(mediaVideoItem1, "effectNegative", + 3000, 4000, EffectColor.TYPE_NEGATIVE, 0); + mediaVideoItem1.addEffect(effectNegative); + + final MediaImageItem mediaImageItem2 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m2", + imageItemFilename1, 3000, MediaItem.RENDERING_MODE_BLACK_BORDER); + mVideoEditor.addMediaItem(mediaImageItem2); + + final EffectColor effectFifties = + mVideoEditorHelper.createEffectItem(mediaImageItem2, "effectFifties", + 0, 3000, EffectColor.TYPE_FIFTIES, 0); + mediaImageItem2.addEffect(effectFifties); + + final MediaVideoItem mediaVideoItem3 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m3", + videoItemFilename2, MediaItem.RENDERING_MODE_BLACK_BORDER); + mVideoEditor.addMediaItem(mediaVideoItem3); + mediaVideoItem3.setExtractBoundaries(0, 8000); + + final Bitmap mBitmap = mVideoEditorHelper.getBitmap(overlayFile, + 640, 480); + final OverlayFrame overlayFrame = + mVideoEditorHelper.createOverlay(mediaVideoItem3, "overlay", + mBitmap, 2000, 5000); + mediaVideoItem3.addOverlay(overlayFrame); + + final EffectColor effectGreen = + mVideoEditorHelper.createEffectItem(mediaVideoItem3, "effectGreen", + 0, 2000, EffectColor.TYPE_COLOR, EffectColor.GREEN); + mediaVideoItem3.addEffect(effectGreen); + + final MediaVideoItem mediaVideoItem4 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m4", + videoItemFilename3, MediaItem.RENDERING_MODE_BLACK_BORDER); + mediaVideoItem4.setExtractBoundaries(mediaVideoItem4.getDuration()-5000, + mediaVideoItem4.getDuration()); + mVideoEditor.addMediaItem(mediaVideoItem4); + + final EffectColor effectSepia = + mVideoEditorHelper.createEffectItem(mediaVideoItem4, "effectSepia", + 0, 2000, EffectColor.TYPE_SEPIA, 0); + mediaVideoItem4.addEffect(effectSepia); + + final MediaImageItem mediaImageItem5 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m5", + imageItemFilename2, 4000, MediaItem.RENDERING_MODE_BLACK_BORDER); + mVideoEditor.addMediaItem(mediaImageItem5); + + final EffectColor effectGray = + mVideoEditorHelper.createEffectItem(mediaImageItem5, "effectGray", + 0, 2000, EffectColor.TYPE_COLOR, EffectColor.GRAY); + mediaImageItem5.addEffect(effectGray); + + final MediaImageItem mediaImageItem6 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m6", + imageItemFilename3, 2000, MediaItem.RENDERING_MODE_BLACK_BORDER); + mVideoEditor.addMediaItem(mediaImageItem6); + + final EffectColor effectGradient = + mVideoEditorHelper.createEffectItem(mediaImageItem6, + "effectGradient", 0, 2000, EffectColor.TYPE_GRADIENT, + EffectColor.PINK); + mediaImageItem6.addEffect(effectGradient); + + mVideoEditor.generatePreview(new MediaProcessingProgressListener() { + public void onProgress(Object item, int action, int progress) { + } + }); + + try { + final int[] progressUpdate = new int[100]; + mVideoEditor.export(outFilename, MediaProperties.HEIGHT_720, + MediaProperties.BITRATE_800K, new ExportProgressListener() { + int i = 0; + public void onProgress(VideoEditor ve, String outFileName, + int progress) { + progressUpdate[i++] = progress; + } + }); + mVideoEditorHelper.checkProgressCBValues(progressUpdate); + } catch (Exception e) { + assertTrue("Error in Export" + e.toString(), false); + } + final long storyBoardDuration = mediaVideoItem1.getTimelineDuration() + + mediaImageItem2.getDuration() + + mediaVideoItem3.getTimelineDuration() + + mediaVideoItem4.getTimelineDuration() + + mediaImageItem5.getDuration() + + mediaImageItem6.getDuration(); + mVideoEditorHelper.validateExport(mVideoEditor, outFilename, + MediaProperties.HEIGHT_720, 0, storyBoardDuration, + MediaProperties.VCODEC_H264, MediaProperties.ACODEC_AAC_LC); + mVideoEditorHelper.checkDeleteExistingFile(outFilename); + } + + /** + * To test export : with Image with KenBurnEffect + */ + // TODO : remove TC_EXP_003 + @LargeTest + public void testExportEffectKenBurn() throws Exception { + final String imageItemFileName = INPUT_FILE_PATH + "IMG_640x480.jpg"; + final int imageItemRenderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; + final String outFilename = mVideoEditorHelper + .createRandomFile(mVideoEditor.getPath() + "/") + ".3gp"; + + final MediaImageItem mediaImageItem = + mVideoEditorHelper.createMediaItem(mVideoEditor, "mediaImageItem1", + imageItemFileName, 5000, imageItemRenderingMode); + mVideoEditor.addMediaItem(mediaImageItem); + + final Rect startRect = new Rect((mediaImageItem.getHeight() / 3), + (mediaImageItem.getWidth() / 3), (mediaImageItem.getHeight() / 2), + (mediaImageItem.getWidth() / 2)); + + final Rect endRect = new Rect(0, 0, mediaImageItem.getWidth(), + mediaImageItem.getHeight()); + + final EffectKenBurns kbEffectOnMediaItem = new EffectKenBurns( + mediaImageItem, "KBOnM2", startRect, endRect, 500, 3000); + assertNotNull("EffectKenBurns", kbEffectOnMediaItem); + mediaImageItem.addEffect(kbEffectOnMediaItem); + + assertEquals("KenBurn Start Rect", startRect, + kbEffectOnMediaItem.getStartRect()); + assertEquals("KenBurn End Rect", endRect, + kbEffectOnMediaItem.getEndRect()); + + mVideoEditor.generatePreview(new MediaProcessingProgressListener() { + public void onProgress(Object item, int action, int progress) { + } + }); + + try { + final int[] progressUpdate = new int[100]; + mVideoEditor.export(outFilename, MediaProperties.HEIGHT_720, + MediaProperties.BITRATE_800K, new ExportProgressListener() { + int i = 0; + public void onProgress(VideoEditor ve, String outFileName, + int progress) { + progressUpdate[i++] = progress; + } + }); + mVideoEditorHelper.checkProgressCBValues(progressUpdate); + } catch (Exception e) { + assertTrue("Error in Export" + e.toString(), false); + } + mVideoEditorHelper.validateExport(mVideoEditor, outFilename, + MediaProperties.HEIGHT_720, 0, mediaImageItem.getDuration(), + MediaProperties.VCODEC_H264, MediaProperties.ACODEC_AAC_LC); + mVideoEditorHelper.checkDeleteExistingFile(outFilename); + } + + /** + * To Test Export : With Video and Image and An Audio BackGround Track + */ + // TODO : remove TC_EXP_004 + @LargeTest + public void testExportAudio() throws Exception { + final String videoItemFileName = INPUT_FILE_PATH + + "H263_profile0_176x144_15fps_256kbps_AACLC_32kHz_128kbps_s_0_26.3gp"; + final String imageItemFileName = INPUT_FILE_PATH + "IMG_1600x1200.jpg"; + final String outFilename = mVideoEditorHelper + .createRandomFile(mVideoEditor.getPath() + "/") + ".3gp"; + final String audioTrackFilename = INPUT_FILE_PATH + + "AMRNB_8KHz_12.2Kbps_m_1_17.3gp"; + + final MediaVideoItem mediaVideoItem = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", + videoItemFileName, MediaItem.RENDERING_MODE_BLACK_BORDER); + mediaVideoItem.setExtractBoundaries(0, 10000); + mVideoEditor.addMediaItem(mediaVideoItem); + + final MediaImageItem mediaImageItem = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m2", + imageItemFileName, 5000, MediaItem.RENDERING_MODE_BLACK_BORDER); + mVideoEditor.addMediaItem(mediaImageItem); + + final AudioTrack audioTrack = mVideoEditorHelper.createAudio( + mVideoEditor, "a1", audioTrackFilename); + audioTrack.setExtractBoundaries(2000, 5000); + mVideoEditor.addAudioTrack(audioTrack); + + audioTrack.disableDucking(); + audioTrack.enableLoop(); + audioTrack.setVolume(75); + + mVideoEditor.generatePreview(new MediaProcessingProgressListener() { + public void onProgress(Object item, int action, int progress) { + } + }); + + try { + final int[] progressUpdate = new int[100]; + mVideoEditor.export(outFilename, MediaProperties.HEIGHT_720, + MediaProperties.BITRATE_800K, new ExportProgressListener() { + int i = 0; + public void onProgress(VideoEditor ve, String outFileName, + int progress) { + progressUpdate[i++] = progress; + } + }); + mVideoEditorHelper.checkProgressCBValues(progressUpdate); + } catch (Exception e) { + assertTrue("Error in Export" + e.toString(), false); + } + mVideoEditorHelper.validateExport(mVideoEditor, outFilename, + MediaProperties.HEIGHT_720, 0, (mediaVideoItem.getTimelineDuration() + + mediaImageItem.getDuration()), + MediaProperties.VCODEC_H264, MediaProperties.ACODEC_AAC_LC); + + mVideoEditorHelper.checkDeleteExistingFile(outFilename); + } + + /** + *To Test export : With Transition on Different Media Items + */ + // TODO :remove TC_EXP_005 + @LargeTest + public void testExportTransition() throws Exception { + final String videoItemFilename1 = INPUT_FILE_PATH + + "H263_profile0_176x144_15fps_256kbps_AACLC_32kHz_128kbps_s_0_26.3gp"; + final String imageItemFilename1 = INPUT_FILE_PATH + "IMG_1600x1200.jpg"; + final String videoItemFilename2 = INPUT_FILE_PATH + + "H264_BP_640x480_12.5fps_256kbps_AACLC_16khz_24kbps_s_0_26.mp4"; + final String videoItemFilename3 = INPUT_FILE_PATH + + "MPEG4_SP_720x480_30fps_280kbps_AACLC_48kHz_96kbps_s_0_21.mp4"; + + final String imageItemFilename2 = INPUT_FILE_PATH + "IMG_176x144.jpg"; + final String imageItemFilename3 = INPUT_FILE_PATH + "IMG_640x480.jpg"; + final String outFilename = mVideoEditorHelper + .createRandomFile(mVideoEditor.getPath() + "/") + ".3gp"; + final String maskFilename = INPUT_FILE_PATH + + "TransitionSpiral_QVGA.jpg"; + + final MediaVideoItem mediaItem1 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", + videoItemFilename1, MediaItem.RENDERING_MODE_BLACK_BORDER); + mediaItem1.setExtractBoundaries(2000, 7000); + mVideoEditor.addMediaItem(mediaItem1); + + final TransitionAlpha transition1 = + mVideoEditorHelper.createTAlpha("transition1", null, mediaItem1, + 2000, Transition.BEHAVIOR_LINEAR, maskFilename, 50, true); + mVideoEditor.addTransition(transition1); + + final MediaImageItem mediaItem2 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m2", + imageItemFilename1, 8000, MediaItem.RENDERING_MODE_BLACK_BORDER); + mVideoEditor.addMediaItem(mediaItem2); + + final MediaVideoItem mediaItem3 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m3", + videoItemFilename2, MediaItem.RENDERING_MODE_BLACK_BORDER); + mediaItem3.setExtractBoundaries(0, 8000); + mVideoEditor.addMediaItem(mediaItem3); + + final TransitionSliding transition2And3 = + mVideoEditorHelper.createTSliding("transition2", mediaItem2, + mediaItem3, 4000, Transition.BEHAVIOR_MIDDLE_FAST, + TransitionSliding.DIRECTION_RIGHT_OUT_LEFT_IN); + mVideoEditor.addTransition(transition2And3); + + final MediaVideoItem mediaItem4 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m4", + videoItemFilename3, MediaItem.RENDERING_MODE_BLACK_BORDER); + mVideoEditor.addMediaItem(mediaItem4); + mediaItem4.setExtractBoundaries(0, 8000); + + final TransitionCrossfade transition3And4 = + mVideoEditorHelper.createTCrossFade("transition3", mediaItem3, + mediaItem4, 3500, Transition.BEHAVIOR_MIDDLE_SLOW); + mVideoEditor.addTransition(transition3And4); + + final MediaImageItem mediaItem5 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m5", + imageItemFilename2, 7000, MediaItem.RENDERING_MODE_BLACK_BORDER); + mVideoEditor.addMediaItem(mediaItem5); + + final TransitionFadeBlack transition4And5 = + mVideoEditorHelper.createTFadeBlack("transition4", mediaItem4, + mediaItem5, 3500, Transition.BEHAVIOR_SPEED_DOWN); + mVideoEditor.addTransition(transition4And5); + + final MediaImageItem mediaItem6 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m6", + imageItemFilename3, 3000, MediaItem.RENDERING_MODE_BLACK_BORDER); + mVideoEditor.addMediaItem(mediaItem6); + + final TransitionSliding transition5And6 = + mVideoEditorHelper.createTSliding("transition5", mediaItem5, + mediaItem6, 1000/*4000*/, Transition.BEHAVIOR_SPEED_UP, + TransitionSliding.DIRECTION_LEFT_OUT_RIGHT_IN); + mVideoEditor.addTransition(transition5And6); + + final TransitionSliding transition6 = + mVideoEditorHelper.createTSliding("transition6", mediaItem6, null, + 1000 /*4000*/, Transition.BEHAVIOR_SPEED_UP, + TransitionSliding.DIRECTION_TOP_OUT_BOTTOM_IN); + mVideoEditor.addTransition(transition6); + + mVideoEditor.generatePreview(new MediaProcessingProgressListener() { + public void onProgress(Object item, int action, int progress) { + } + }); + + try { + final int[] progressUpdate = new int[100]; + mVideoEditor.export(outFilename, MediaProperties.HEIGHT_720, + MediaProperties.BITRATE_800K, new ExportProgressListener() { + int i = 0; + public void onProgress(VideoEditor ve, String outFileName, + int progress) { + progressUpdate[i++] = progress; + } + }); + mVideoEditorHelper.checkProgressCBValues(progressUpdate); + } catch (Exception e) { + assertTrue("Error in Export" + e.toString(), false); + } + final long storyBoardDuration = mediaItem1.getTimelineDuration() + + mediaItem2.getTimelineDuration() + + mediaItem3.getTimelineDuration() - transition2And3.getDuration() + + mediaItem4.getTimelineDuration() - transition3And4.getDuration() + + mediaItem5.getTimelineDuration() - transition4And5.getDuration() + + mediaItem6.getTimelineDuration() - transition5And6.getDuration(); + mVideoEditorHelper.validateExport(mVideoEditor, outFilename, + MediaProperties.HEIGHT_720, 0, storyBoardDuration, + MediaProperties.VCODEC_H264, MediaProperties.ACODEC_AAC_LC); + mVideoEditorHelper.checkDeleteExistingFile(outFilename); + } + + /** + * To Test Export : Without any Media Items in the story Board + * + * @throws Exception + */ + // TODO :remove TC_EXP_006 + @LargeTest + public void testExportWithoutMediaItems() throws Exception { + boolean flagForException = false; + try { + final int[] progressUpdate = new int[100]; + mVideoEditor.export("/sdcard/Test.3gp", MediaProperties.HEIGHT_720, + MediaProperties.BITRATE_800K, new ExportProgressListener() { + int i = 0; + public void onProgress(VideoEditor ve, String outFileName, + int progress) { + progressUpdate[i++] = progress; + } + }); + mVideoEditorHelper.checkProgressCBValues(progressUpdate); + } catch (IllegalStateException e) { + flagForException = true; + } + assertTrue("Export without any MediaItems", flagForException); + } + + /** + * To Test Export : With Media Items add and removed in the story Board + * + * @throws Exception + */ + // TODO :remove TC_EXP_007 + @LargeTest + public void testExportWithoutMediaItemsAddRemove() throws Exception { + final String videoItemFilename1 = INPUT_FILE_PATH + + "H263_profile0_176x144_15fps_256kbps_AACLC_32kHz_128kbps_s_1_17.3gp"; + final String imageItemFilename1 = INPUT_FILE_PATH + "IMG_640x480.jpg"; + final String maskFilename = INPUT_FILE_PATH + "TransitionSpiral_QVGA.jpg"; + boolean flagForException = false; + + final MediaVideoItem mediaItem1 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", + videoItemFilename1, MediaItem.RENDERING_MODE_BLACK_BORDER); + mediaItem1.setExtractBoundaries(0, 15000); + mVideoEditor.addMediaItem(mediaItem1); + + final MediaImageItem mediaItem2 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m2", + imageItemFilename1, 15000, + MediaItem.RENDERING_MODE_BLACK_BORDER); + mVideoEditor.addMediaItem(mediaItem2); + + final TransitionAlpha transition1 = + mVideoEditorHelper.createTAlpha("transition1", mediaItem1, mediaItem2, + 3000, Transition.BEHAVIOR_LINEAR, maskFilename, 50, false); + mVideoEditor.addTransition(transition1); + + final EffectColor effectColor = + mVideoEditorHelper.createEffectItem(mediaItem2, "effect", 12000, + 3000, EffectColor.TYPE_COLOR, EffectColor.PINK); + mediaItem2.addEffect(effectColor); + + mVideoEditor.removeMediaItem(mediaItem1.getId()); + mVideoEditor.removeMediaItem(mediaItem2.getId()); + try { + final int[] progressUpdate = new int[100]; + mVideoEditor.export("/sdcard/Test.3gp", MediaProperties.HEIGHT_720, + MediaProperties.BITRATE_800K, new ExportProgressListener() { + int i = 0; + public void onProgress(VideoEditor ve, String outFileName, + int progress) { + progressUpdate[i++] = progress; + } + }); + mVideoEditorHelper.checkProgressCBValues(progressUpdate); + } catch (IllegalStateException e) { + flagForException = true; + } + assertTrue("Export with MediaItem added and removed", flagForException); + } + + /** + * To Test Export : With Video and Image : MMS use case + * + * @throws Exception + */ + // TODO :remove TC_EXP_008 + @LargeTest + public void testExportMMS() throws Exception { + final String videoItemFilename1 = INPUT_FILE_PATH + + "H263_profile0_176x144_15fps_256kbps_AACLC_32kHz_128kbps_s_1_17.3gp"; + final String imageItemFilename1 = INPUT_FILE_PATH + "IMG_1600x1200.jpg"; + final String videoItemFilename2 = INPUT_FILE_PATH + + "H264_BP_640x480_12.5fps_256kbps_AACLC_16khz_24kbps_s_0_26.mp4"; + final String maskFilename = INPUT_FILE_PATH + "TransitionSpiral_QVGA.jpg"; + final String outFilename = mVideoEditorHelper + .createRandomFile(mVideoEditor.getPath() + "/") + ".3gp"; + + final MediaVideoItem mediaItem1 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", + videoItemFilename1, MediaItem.RENDERING_MODE_BLACK_BORDER); + mediaItem1.setExtractBoundaries(2000, 7000); + mVideoEditor.addMediaItem(mediaItem1); + + final TransitionAlpha transition1 = + mVideoEditorHelper.createTAlpha("transition1", null, mediaItem1, + 2000, Transition.BEHAVIOR_LINEAR, maskFilename, 50, true); + mVideoEditor.addTransition(transition1); + + final MediaImageItem mediaItem2 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m2", + imageItemFilename1, 8000, MediaItem.RENDERING_MODE_BLACK_BORDER); + mVideoEditor.addMediaItem(mediaItem2); + + final MediaVideoItem mediaItem3 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m3", + videoItemFilename2, MediaItem.RENDERING_MODE_BLACK_BORDER); + mediaItem3.setExtractBoundaries(0, 8000); + mVideoEditor.addMediaItem(mediaItem3); + + final TransitionSliding transition2And3 = + mVideoEditorHelper.createTSliding("transition2", mediaItem2, + mediaItem3, 4000, Transition.BEHAVIOR_MIDDLE_FAST, + TransitionSliding.DIRECTION_RIGHT_OUT_LEFT_IN); + mVideoEditor.addTransition(transition2And3); + + final TransitionCrossfade transition3 = + mVideoEditorHelper.createTCrossFade("transition3", mediaItem3, null, + 3500, Transition.BEHAVIOR_MIDDLE_SLOW); + mVideoEditor.addTransition(transition3); + + final EffectColor effectColor = + mVideoEditorHelper.createEffectItem(mediaItem2, "effect", 0, + 3000, EffectColor.TYPE_COLOR, EffectColor.PINK); + mediaItem2.addEffect(effectColor); + + mVideoEditor.setAspectRatio(MediaProperties.ASPECT_RATIO_11_9); + + try { + final int[] progressUpdate = new int[100]; + mVideoEditor.export(outFilename, MediaProperties.HEIGHT_144, + MediaProperties.BITRATE_800K, new ExportProgressListener() { + int i = 0; + public void onProgress(VideoEditor ve, String outFileName, + int progress) { + progressUpdate[i++] = progress; + } + }); + mVideoEditorHelper.checkProgressCBValues(progressUpdate); + } catch (Exception e) { + assertTrue("Error in Export" + e.toString(), false); + } + final long storyBoardDuration = mediaItem1.getTimelineDuration() + + mediaItem2.getTimelineDuration() + mediaItem3.getTimelineDuration() + - transition2And3.getDuration(); + + mVideoEditorHelper.validateExport(mVideoEditor, outFilename, + MediaProperties.HEIGHT_144, 0, storyBoardDuration, + MediaProperties.VCODEC_H264, MediaProperties.ACODEC_AAC_LC); + mVideoEditorHelper.checkDeleteExistingFile(outFilename); + } + + /** + * To Test Export :Media Item having duration of 1 Hour + * + * @throws Exception + */ + @Suppress + @LargeTest + public void testExportDuration1Hour() throws Exception { + final String videoItemFilename1 = INPUT_FILE_PATH + + "H264_BP_640x480_15fps_384kbps_60_0.mp4"; + final String outFilename = mVideoEditorHelper.createRandomFile( + mVideoEditor.getPath() + "/") + ".3gp"; + + final MediaVideoItem mediaItem1 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", + videoItemFilename1, MediaItem.RENDERING_MODE_BLACK_BORDER); + mVideoEditor.addMediaItem(mediaItem1); + try { + final int[] progressUpdate = new int[100]; + mVideoEditor.export(outFilename, MediaProperties.HEIGHT_144, + MediaProperties.BITRATE_800K, new ExportProgressListener() { + int i = 0; + public void onProgress(VideoEditor ve, String outFileName, + int progress) { + progressUpdate[i++] = progress; + } + }); + mVideoEditorHelper.checkProgressCBValues(progressUpdate); + }catch (Exception e) { + assertTrue("Error in Export" + e.toString(), false); + } + mVideoEditorHelper.validateExport(mVideoEditor, outFilename, + MediaProperties.HEIGHT_720, 0, mediaItem1.getDuration(), + MediaProperties.VCODEC_H264, MediaProperties.ACODEC_AAC_LC); + mVideoEditorHelper.checkDeleteExistingFile(outFilename); + } + + /** + * To Test Export : Storage location having very less space (Less than 100 + * KB) + * + * @throws Exception + */ + @LargeTest + public void testExportWithStorageFull() throws Exception { + final String videoItemFilename1 = INPUT_FILE_PATH + + "H264_BP_640x480_12.5fps_256kbps_AACLC_16khz_24kbps_s_0_26.mp4"; + final String outFilename = mVideoEditorHelper + .createRandomFile(mVideoEditor.getPath() + "/") + ".3gp"; + boolean flagForException = false; + + mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", videoItemFilename1, + MediaItem.RENDERING_MODE_BLACK_BORDER); + try { + final int[] progressUpdate = new int[100]; + mVideoEditor.export(outFilename, MediaProperties.HEIGHT_144, + MediaProperties.BITRATE_800K, new ExportProgressListener() { + int i = 0; + public void onProgress(VideoEditor ve, String outFileName, + int progress) { + progressUpdate[i++] = progress; + } + }); + mVideoEditorHelper.checkProgressCBValues(progressUpdate); + } catch (Exception e) { + flagForException = true; + } + assertTrue("Error in exporting file due to lack of storage space", + flagForException); + } + + /** + * To Test Export :Two Media Items added + * + * @throws Exception + */ + @LargeTest + public void testExportTwoVideos() throws Exception { + final String videoItemFileName = INPUT_FILE_PATH + + "H263_profile0_176x144_15fps_256kbps_AACLC_32kHz_128kbps_s_1_17.3gp"; + final String videoItemFileName1 = INPUT_FILE_PATH + + "H264_BP_640x480_12.5fps_256kbps_AACLC_16khz_24kbps_s_0_26.mp4"; + final String outFilename = mVideoEditorHelper + .createRandomFile(mVideoEditor.getPath() + "/") + ".3gp"; + + final MediaVideoItem mediaVideoItem = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", + videoItemFileName, MediaItem.RENDERING_MODE_BLACK_BORDER); + mVideoEditor.addMediaItem(mediaVideoItem); + + final MediaVideoItem mediaVideoItem1 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m2", + videoItemFileName1, MediaItem.RENDERING_MODE_BLACK_BORDER); + mVideoEditor.addMediaItem(mediaVideoItem1); + + mVideoEditor.generatePreview(new MediaProcessingProgressListener() { + public void onProgress(Object item, int action, int progress) { + } + }); + + try { + final int[] progressUpdate = new int[100]; + mVideoEditor.export(outFilename, MediaProperties.HEIGHT_720, + MediaProperties.BITRATE_800K, new ExportProgressListener() { + int i = 0; + public void onProgress(VideoEditor ve, String outFileName, + int progress) { + progressUpdate[i++] = progress; + } + }); + mVideoEditorHelper.checkProgressCBValues(progressUpdate); + } catch (Exception e) { + assertTrue("Error in Export" + e.toString(), false); + } + mVideoEditorHelper.validateExport(mVideoEditor, outFilename, + MediaProperties.HEIGHT_720, 0, + (mediaVideoItem.getDuration()+ mediaVideoItem1.getDuration()), + MediaProperties.VCODEC_H264, MediaProperties.ACODEC_AAC_LC); + mVideoEditorHelper.checkDeleteExistingFile(outFilename); + } +} diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/videoeditor/VideoEditorPreviewTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/videoeditor/VideoEditorPreviewTest.java new file mode 100644 index 0000000..e848f5f --- /dev/null +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/videoeditor/VideoEditorPreviewTest.java @@ -0,0 +1,1139 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.mediaframeworktest.functional.videoeditor; + +import java.io.File; +import java.io.IOException; +import java.util.List; +import java.util.concurrent.Semaphore; + +import android.graphics.Bitmap; +import android.graphics.Rect; +import android.media.videoeditor.AudioTrack; +import android.media.videoeditor.Effect; +import android.media.videoeditor.EffectColor; +import android.media.videoeditor.EffectKenBurns; +import android.media.videoeditor.MediaImageItem; +import android.media.videoeditor.MediaItem; +import android.media.videoeditor.MediaProperties; +import android.media.videoeditor.MediaVideoItem; +import android.media.videoeditor.Overlay; +import android.media.videoeditor.OverlayFrame; +import android.media.videoeditor.Transition; +import android.media.videoeditor.TransitionAlpha; +import android.media.videoeditor.TransitionCrossfade; +import android.media.videoeditor.TransitionFadeBlack; +import android.media.videoeditor.TransitionSliding; +import android.media.videoeditor.VideoEditor; +import android.media.videoeditor.VideoEditor.ExportProgressListener; +import android.media.videoeditor.VideoEditor.MediaProcessingProgressListener; +import android.media.videoeditor.VideoEditor.PreviewProgressListener; +import android.media.videoeditor.VideoEditor.OverlayData; +import android.os.Environment; +import android.test.ActivityInstrumentationTestCase; +import android.view.SurfaceHolder; + + +import com.android.mediaframeworktest.MediaFrameworkTest; +import android.test.suitebuilder.annotation.LargeTest; +import com.android.mediaframeworktest.VideoEditorHelper; + +import android.os.Handler; +import android.os.Looper; +import android.os.Message; + +import java.util.concurrent.TimeUnit; + +import android.util.Log; + +public class VideoEditorPreviewTest extends + ActivityInstrumentationTestCase { + private final String TAG = "VideoEditorTest"; + + private final String PROJECT_LOCATION = VideoEditorHelper.PROJECT_LOCATION_COMMON; + + private final String INPUT_FILE_PATH = VideoEditorHelper.INPUT_FILE_PATH_COMMON; + + private final String PROJECT_CLASS_NAME = + "android.media.videoeditor.VideoEditorImpl"; + + private VideoEditor mVideoEditor; + + private VideoEditorHelper mVideoEditorHelper; + + private class EventHandler extends Handler { + public EventHandler( Looper lp) + { + super(lp); + } + public void handleMessage(Message msg) + { + switch (msg.what) + { + default: + MediaFrameworkTest.testInvalidateOverlay(); + } + } + } + private EventHandler mEventHandler; + + private boolean previewStart; + private boolean previewStop; + + /* Minimum waiting time for Semaphore to wait for release */ + private final long minWaitingTime = 3000; + + // Declares the annotation for Preview Test Cases + public @interface Preview { + } + + public VideoEditorPreviewTest() { + super("com.android.mediaframeworktest", MediaFrameworkTest.class); + + Looper looper; + if ((looper = Looper.myLooper()) != null) { + mEventHandler = new EventHandler(looper); + + } else { + //Handle error when looper can not be created. + ; + } + } + + @Override + protected void setUp() throws Exception { + // setup for each test case. + super.setUp(); + mVideoEditorHelper = new VideoEditorHelper(); + // Create a random String which will be used as project path, where all + // project related files will be stored. + final String projectPath = + mVideoEditorHelper.createRandomFile(PROJECT_LOCATION); + mVideoEditor = mVideoEditorHelper.createVideoEditor(projectPath); + } + + @Override + protected void tearDown() throws Exception { + mVideoEditorHelper.destroyVideoEditor(mVideoEditor); + // Clean the directory created as project path + mVideoEditorHelper.deleteProject(new File(mVideoEditor.getPath())); + System.gc(); + super.tearDown(); + } + + protected void setPreviewStart() { + previewStart = true; + } + protected void setPreviewStop() { + previewStop = true; + } + + protected void validatePreviewProgress(int startMs, int endMs, + boolean loop, long duration) throws Exception { + + final int[] progressUpdate = new int[100]; + final Semaphore blockTillPreviewCompletes = new Semaphore(1); + previewStart = false; + previewStop = false; + mVideoEditor.generatePreview(new MediaProcessingProgressListener() { + int i = 0; + public void onProgress(Object item, int action, int progress) { + progressUpdate[i++] = progress; + } + }); + mVideoEditorHelper.checkProgressCBValues(progressUpdate); + final SurfaceHolder surfaceHolder = + MediaFrameworkTest.mSurfaceView.getHolder(); + + long waitingTime = minWaitingTime; + if (endMs == -1) { + waitingTime += duration; + } + else { + waitingTime += (endMs - startMs); + } + blockTillPreviewCompletes.acquire(); + try { + mVideoEditor.startPreview(surfaceHolder, startMs, endMs, loop, 1, + new PreviewProgressListener() { + public void onProgress(VideoEditor videoEditor, long timeMs, + OverlayData overlayData) { + + if ( overlayData != null) { + if(overlayData.needsRendering()) { + overlayData.renderOverlay(MediaFrameworkTest.mDestBitmap); + mEventHandler.sendMessage(mEventHandler.obtainMessage(1, 2, 3)); + } + } + } + public void onStart(VideoEditor videoEditor) { + setPreviewStart(); + } + public void onStop(VideoEditor videoEditor) { + setPreviewStop(); + blockTillPreviewCompletes.release(); + } + }); + } catch (Exception e) { + blockTillPreviewCompletes.release(); + } + blockTillPreviewCompletes.tryAcquire(waitingTime, TimeUnit.MILLISECONDS); + + mVideoEditor.stopPreview(); + assertTrue("Preview Failed to start", previewStart); + assertTrue("Preview Failed to stop", previewStop); + + blockTillPreviewCompletes.release(); + } + + // ----------------------------------------------------------------- + // Preview + // ----------------------------------------------------------------- + + /** + *To test Preview : FULL Preview of current work (beginning till end) + */ + // TODO : remove TC_PRV_001 + @LargeTest + public void testPreviewTheStoryBoard() throws Exception { + final String videoItemFileName1 = INPUT_FILE_PATH + + "MPEG4_SP_720x480_30fps_280kbps_AACLC_48kHz_96kbps_s_0_21.mp4"; + final String videoItemFileName2 = INPUT_FILE_PATH + + "MPEG4_SP_640x480_15fps_256kbps_0_30.mp4"; + final String videoItemFileName3 = INPUT_FILE_PATH + + "H263_profile0_176x144_15fps_256kbps_AACLC_32kHz_128kbps_s_1_17.3gp"; + previewStart = false; + previewStop = false; + final MediaVideoItem mediaVideoItem1 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "mediaVideoItem1", + videoItemFileName1, MediaItem.RENDERING_MODE_BLACK_BORDER); + mediaVideoItem1.setExtractBoundaries(0, 10000); + mVideoEditor.addMediaItem(mediaVideoItem1); + + final MediaVideoItem mediaVideoItem2 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "mediaVideoItem2", + videoItemFileName2, MediaItem.RENDERING_MODE_BLACK_BORDER); + mVideoEditor.addMediaItem(mediaVideoItem2); + mediaVideoItem2.setExtractBoundaries(0, 10000); + + final MediaVideoItem mediaVideoItem3 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "mediaVideoItem3", + videoItemFileName3, MediaItem.RENDERING_MODE_BLACK_BORDER); + mediaVideoItem3.setExtractBoundaries(0, 10000); + + mVideoEditor.insertMediaItem(mediaVideoItem3, mediaVideoItem1.getId()); + List mediaList = mVideoEditor.getAllMediaItems(); + assertEquals("Media Item 1", mediaVideoItem1, mediaList.get(0)); + assertEquals("Media Item 3", mediaVideoItem3, mediaList.get(1)); + assertEquals("Media Item 2", mediaVideoItem2, mediaList.get(2)); + + mediaVideoItem1.setRenderingMode(MediaItem.RENDERING_MODE_BLACK_BORDER); + assertEquals("Media Item 1 Rendering Mode", + MediaItem.RENDERING_MODE_BLACK_BORDER, + mediaVideoItem1.getRenderingMode()); + + mediaVideoItem2.setRenderingMode(MediaItem.RENDERING_MODE_BLACK_BORDER); + assertEquals("Media Item 2 Rendering Mode", + MediaItem.RENDERING_MODE_BLACK_BORDER, + mediaVideoItem2.getRenderingMode()); + + mediaVideoItem3.setRenderingMode(MediaItem.RENDERING_MODE_STRETCH); + assertEquals("Media Item 3 Rendering Mode", + MediaItem.RENDERING_MODE_STRETCH, + mediaVideoItem3.getRenderingMode()); + + mVideoEditor.setAspectRatio(MediaProperties.ASPECT_RATIO_5_3); + assertEquals("Aspect Ratio", MediaProperties.ASPECT_RATIO_5_3, + mVideoEditor.getAspectRatio()); + + validatePreviewProgress(0, -1, false, mVideoEditor.getDuration()); + } + + /** + * To test Preview : Preview of start + 10 sec till end of story board + */ + // TODO : remove TC_PRV_002 + @LargeTest + public void testPreviewTheStoryBoardFromDuration() throws Exception { + final String videoItemFileName1 = INPUT_FILE_PATH + + "MPEG4_SP_720x480_30fps_280kbps_AACLC_48kHz_96kbps_s_0_21.mp4"; + final String videoItemFileName2 = INPUT_FILE_PATH + + "MPEG4_SP_640x480_15fps_256kbps_0_30.mp4"; + final String videoItemFileName3 = INPUT_FILE_PATH + + "H263_profile0_176x144_15fps_256kbps_AACLC_32kHz_128kbps_s_1_17.3gp"; + final Semaphore blockTillPreviewCompletes = new Semaphore(1); + previewStart = false; + previewStop = false; + final MediaVideoItem mediaVideoItem1 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "mediaVideoItem1", + videoItemFileName1, MediaItem.RENDERING_MODE_BLACK_BORDER); + mediaVideoItem1.setExtractBoundaries(0, 10000); + mVideoEditor.addMediaItem(mediaVideoItem1); + + final MediaVideoItem mediaVideoItem2 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "mediaVideoItem2", + videoItemFileName2, MediaItem.RENDERING_MODE_BLACK_BORDER); + mediaVideoItem2.setExtractBoundaries(0, 10000); + mVideoEditor.addMediaItem(mediaVideoItem2); + + final MediaVideoItem mediaVideoItem3 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "mediaVideoItem3", + videoItemFileName3, MediaItem.RENDERING_MODE_BLACK_BORDER); + mediaVideoItem3.setExtractBoundaries(0, 10000); + + mVideoEditor.insertMediaItem(mediaVideoItem3, mediaVideoItem1.getId()); + + List mediaList = mVideoEditor.getAllMediaItems(); + assertEquals("Media Item 1", mediaVideoItem1, mediaList.get(0)); + assertEquals("Media Item 3", mediaVideoItem3, mediaList.get(1)); + assertEquals("Media Item 2", mediaVideoItem2, mediaList.get(2)); + mediaVideoItem1.setRenderingMode(MediaItem.RENDERING_MODE_BLACK_BORDER); + + assertEquals("Media Item 1 Rendering Mode", + MediaItem.RENDERING_MODE_BLACK_BORDER, + mediaVideoItem1.getRenderingMode()); + mediaVideoItem2.setRenderingMode(MediaItem.RENDERING_MODE_BLACK_BORDER); + + assertEquals("Media Item 2 Rendering Mode", + MediaItem.RENDERING_MODE_BLACK_BORDER, + mediaVideoItem2.getRenderingMode()); + mediaVideoItem3.setRenderingMode(MediaItem.RENDERING_MODE_STRETCH); + + assertEquals("Media Item 3 Rendering Mode", + MediaItem.RENDERING_MODE_STRETCH, + mediaVideoItem3.getRenderingMode()); + + mVideoEditor.setAspectRatio(MediaProperties.ASPECT_RATIO_5_3); + assertEquals("Aspect Ratio", MediaProperties.ASPECT_RATIO_5_3, + mVideoEditor.getAspectRatio()); + + validatePreviewProgress(10000, -1, false, mVideoEditor.getDuration()); + } + + /** + * To test Preview : Preview of current Effects applied + */ + // TODO : remove TC_PRV_003 + @LargeTest + public void testPreviewOfEffects() throws Exception { + final String videoItemFileName1 = INPUT_FILE_PATH + + "H264_BP_640x480_30fps_256kbps_1_17.mp4"; + + final Semaphore blockTillPreviewCompletes = new Semaphore(1); + previewStart = false; + previewStop = false; + final MediaVideoItem mediaVideoItem1 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "mediaVideoItem1", + videoItemFileName1, MediaItem.RENDERING_MODE_BLACK_BORDER); + mVideoEditor.addMediaItem(mediaVideoItem1); + + final EffectColor effectNegative = + mVideoEditorHelper.createEffectItem(mediaVideoItem1, + "effectNegative", 0, 2000, EffectColor.TYPE_NEGATIVE, 0); + mediaVideoItem1.addEffect(effectNegative); + + final EffectColor effectGreen = + mVideoEditorHelper.createEffectItem(mediaVideoItem1, "effectGreen", + 2000, 3000, EffectColor.TYPE_COLOR, EffectColor.GREEN); + mediaVideoItem1.addEffect(effectGreen); + + final EffectColor effectFifties = + mVideoEditorHelper.createEffectItem(mediaVideoItem1, + "effectFifties", 5000, 4000, EffectColor.TYPE_FIFTIES, 0); + mediaVideoItem1.addEffect(effectFifties); + + List effectList = mediaVideoItem1.getAllEffects(); + assertEquals("Effect List Size", 3, effectList.size()); + assertEquals("Effect negative", effectNegative, effectList.get(0)); + assertEquals("Effect Green", effectGreen, effectList.get(1)); + assertEquals("Effect Fifties", effectFifties, effectList.get(2)); + + mVideoEditor.setAspectRatio(MediaProperties.ASPECT_RATIO_4_3); + assertEquals("Aspect Ratio", MediaProperties.ASPECT_RATIO_4_3, + mVideoEditor.getAspectRatio()); + + final long storyboardDuration = mVideoEditor.getDuration() ; + validatePreviewProgress(0, (int)(storyboardDuration/2), false, (storyboardDuration/2)); + + assertEquals("Removing Effect : Negative", effectNegative, + mediaVideoItem1.removeEffect(effectNegative.getId())); + + effectList = mediaVideoItem1.getAllEffects(); + + assertEquals("Effect List Size", 2, effectList.size()); + assertEquals("Effect Green", effectGreen, effectList.get(0)); + assertEquals("Effect Fifties", effectFifties, effectList.get(1)); + + validatePreviewProgress(0, -1, false, mVideoEditor.getDuration()); + } + + /** + *To test Preview : Preview of current Transitions applied (with multiple + * generatePreview) + */ + // TODO : remove TC_PRV_004 + @LargeTest + public void testPreviewWithTransition() throws Exception { + + final String videoItemFileName1 = INPUT_FILE_PATH + + "H263_profile0_176x144_10fps_96kbps_0_25.3gp"; + final String imageItemFileName1 = INPUT_FILE_PATH + + "IMG_1600x1200.jpg"; + final String videoItemFileName2 = INPUT_FILE_PATH + + "MPEG4_SP_800x480_515kbps_15fps_AMR_NB_8KHz_12.2kbps_m_0_26.mp4"; + final String maskFilename = INPUT_FILE_PATH + + "TransitionSpiral_QVGA.jpg"; + previewStart = false; + previewStop = false; + + final Semaphore blockTillPreviewCompletes = new Semaphore(1); + + final MediaVideoItem mediaVideoItem1 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", + videoItemFileName1, MediaItem.RENDERING_MODE_BLACK_BORDER); + mediaVideoItem1.setExtractBoundaries(0, 10000); + mVideoEditor.addMediaItem(mediaVideoItem1); + + final MediaImageItem mediaImageItem1 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m2", + imageItemFileName1, 10000, MediaItem.RENDERING_MODE_BLACK_BORDER); + mVideoEditor.addMediaItem(mediaImageItem1); + + final MediaVideoItem mediaVideoItem2 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m3", + videoItemFileName2, MediaItem.RENDERING_MODE_BLACK_BORDER); + mediaVideoItem2.setExtractBoundaries(0, 10000); + mVideoEditor.addMediaItem(mediaVideoItem2); + + final TransitionCrossfade transition1And2CrossFade = + mVideoEditorHelper.createTCrossFade("transition_1_2_CF", + mediaVideoItem1, mediaImageItem1, 2000, + Transition.BEHAVIOR_MIDDLE_FAST); + mVideoEditor.addTransition(transition1And2CrossFade); + + final TransitionAlpha transition2And3Alpha = + mVideoEditorHelper.createTAlpha("transition_2_3", mediaImageItem1, + mediaVideoItem2, 4000, Transition.BEHAVIOR_SPEED_UP, + maskFilename, 50, true); + mVideoEditor.addTransition(transition2And3Alpha); + + final TransitionFadeBlack transition1FadeBlack = + mVideoEditorHelper.createTFadeBlack("transition_1FB", null, + mediaVideoItem1, 2000, Transition.BEHAVIOR_MIDDLE_FAST); + mVideoEditor.addTransition(transition1FadeBlack); + + List transitionList = mVideoEditor.getAllTransitions(); + assertEquals("Transition List Size", 3, transitionList.size()); + assertEquals("Transition 1", transition1And2CrossFade, + transitionList.get(0)); + assertEquals("Transition 2", transition2And3Alpha, transitionList.get(1)); + assertEquals("Transition 3", transition1FadeBlack, transitionList.get(2)); + + mVideoEditor.setAspectRatio(MediaProperties.ASPECT_RATIO_3_2); + + final int[] progressValues = new int[300]; + mVideoEditor.generatePreview(new MediaProcessingProgressListener() { + int i = 0; + + public void onProgress(Object item, int action, int progress) { + if (item instanceof TransitionCrossfade) { + progressValues[i] = progress; + assertEquals("Object", item, transition1And2CrossFade); + assertEquals("Action", action, + MediaProcessingProgressListener.ACTION_ENCODE); + } else if (item instanceof TransitionAlpha) { + progressValues[i] = progress; + assertEquals("Object", item, transition2And3Alpha); + assertEquals("Action", action, + MediaProcessingProgressListener.ACTION_ENCODE); + } else if (item instanceof TransitionFadeBlack) { + progressValues[i] = progress; + assertEquals("Object", item, transition1FadeBlack); + assertEquals("Action", action, + MediaProcessingProgressListener.ACTION_ENCODE); + } + i++; + } + }); + + mVideoEditorHelper.checkProgressCBValues(progressValues); + final SurfaceHolder surfaceHolder = + MediaFrameworkTest.mSurfaceView.getHolder(); + /* As transition takes more time buffer of 10 sec is added */ + long waitingTime = minWaitingTime + 10000 + 10000; + + blockTillPreviewCompletes.acquire(); + try { + mVideoEditor.startPreview(surfaceHolder, 0, 10000, false, 1, + new PreviewProgressListener() { + public void onProgress(VideoEditor videoEditor, long timeMs, + OverlayData overlayData) { + } + public void onStart(VideoEditor videoEditor) { + setPreviewStart(); + } + public void onStop(VideoEditor videoEditor) { + setPreviewStop(); + blockTillPreviewCompletes.release(); + } + }); + } catch (Exception e) { + blockTillPreviewCompletes.release(); + } + blockTillPreviewCompletes.tryAcquire(waitingTime, TimeUnit.MILLISECONDS); + mVideoEditor.stopPreview(); + blockTillPreviewCompletes.release(); + assertTrue("Preview Failed to start", previewStart); + assertTrue("Preview Failed to stop", previewStop); + + assertEquals("Removing Transition " + transition1And2CrossFade.getId(), + transition1And2CrossFade, + mVideoEditor.removeTransition(transition1And2CrossFade.getId())); + transitionList = mVideoEditor.getAllTransitions(); + assertEquals("Transition List Size", 2, transitionList.size()); + assertEquals("Transition 1", transition2And3Alpha, transitionList.get(0)); + assertEquals("Transition 2", transition1FadeBlack, transitionList.get(1)); + + validatePreviewProgress(0, -1, false, mVideoEditor.getDuration()); + + + final TransitionSliding transition1And2Sliding = + mVideoEditorHelper.createTSliding("transition_1_2Sliding", + mediaVideoItem1, mediaImageItem1, 4000, + Transition.BEHAVIOR_MIDDLE_FAST, + TransitionSliding.DIRECTION_LEFT_OUT_RIGHT_IN); + mVideoEditor.addTransition(transition1And2Sliding); + + transitionList = mVideoEditor.getAllTransitions(); + assertEquals("Transition List Size", 3, transitionList.size()); + assertEquals("Transition 1", transition2And3Alpha, transitionList.get(0)); + assertEquals("Transition 2", transition1FadeBlack, transitionList.get(1)); + assertEquals("Transition 3", transition1And2Sliding, + transitionList.get(2)); + + validatePreviewProgress(5000, -1, false, (mVideoEditor.getDuration())); + + } + + /** + * To test Preview : Preview of current Overlay applied + */ + // TODO : remove TC_PRV_005 + @LargeTest + public void testPreviewWithOverlay() throws Exception { + final String videoItemFileName = INPUT_FILE_PATH + + "MPEG4_SP_640x480_15fps_1200kbps_AACLC_48khz_64kbps_m_1_17.3gp"; + final String overlayFilename1 = INPUT_FILE_PATH + + "IMG_640x480_Overlay1.png"; + final String overlayFilename2 = INPUT_FILE_PATH + + "IMG_640x480_Overlay2.png"; + final int previewFrom = 5000; + final int previewTo = 10000; + final boolean previewLoop = false; + final int previewCallbackFrameCount = 1; + final int setAspectRatio = MediaProperties.ASPECT_RATIO_4_3; + final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; + final Semaphore blockTillPreviewCompletes = new Semaphore(1); + previewStart = false; + previewStop = false; + boolean flagForException = false; + final MediaVideoItem mediaVideoItem = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", + videoItemFileName, renderingMode); + mVideoEditor.addMediaItem(mediaVideoItem); + mediaVideoItem.setExtractBoundaries(0, 10000); + + final Bitmap mBitmap1 = mVideoEditorHelper.getBitmap(overlayFilename1, + 640, 480); + final OverlayFrame overlayOnMvi1 = + mVideoEditorHelper.createOverlay(mediaVideoItem, "OverlayOnMvi1", + mBitmap1, 0, 5000); + mediaVideoItem.addOverlay(overlayOnMvi1); + + final Bitmap mBitmap2 = mVideoEditorHelper.getBitmap(overlayFilename2, + 640, 480); + final OverlayFrame overlayOnMvi2 = + mVideoEditorHelper.createOverlay(mediaVideoItem, "OverlayOnMvi2", + mBitmap2, 5000, 9000); + mediaVideoItem.addOverlay(overlayOnMvi2); + + List overlayList = mediaVideoItem.getAllOverlays(); + assertEquals("Overlay Size", 2, overlayList.size()); + assertEquals("Overlay 1", overlayOnMvi1, overlayList.get(0)); + assertEquals("Overlay 2", overlayOnMvi2, overlayList.get(1)); + + mVideoEditor.setAspectRatio(setAspectRatio); + + validatePreviewProgress(0 /* previewFrom */, -1, previewLoop, + mVideoEditor.getDuration()); + } + + /** + * To test Preview : Preview of current Trim applied (with default aspect + * ratio) + */ + // TODO : remove TC_PRV_006 + @LargeTest + public void testPreviewWithTrim() throws Exception { + final String videoItemFileName = INPUT_FILE_PATH + + "H264_BP_640x480_30fps_192kbps_1_5.mp4"; + final MediaVideoItem mediaVideoItem = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", + videoItemFileName, MediaItem.RENDERING_MODE_CROPPING); + final Semaphore blockTillPreviewCompletes = new Semaphore(1); + boolean flagForException = false; + previewStart = false; + previewStop = false; + mediaVideoItem.setExtractBoundaries(mediaVideoItem.getDuration() / 2, + mediaVideoItem.getDuration()); + mVideoEditor.addMediaItem(mediaVideoItem); + + validatePreviewProgress(1000, -1, false, mVideoEditor.getDuration()); + } + + /** + * To test Preview : Preview of current work having Overlay and Effect + * applied + */ + + // TODO : remove TC_PRV_007 + @LargeTest + public void testPreviewWithOverlayEffectKenBurn() throws Exception { + + final String videoItemFileName = INPUT_FILE_PATH + + "H264_BP_640x480_30fps_192kbps_1_5.mp4"; + final String imageItemFileName = INPUT_FILE_PATH + "IMG_640x480.jpg"; + final String videoItemFileName1 = INPUT_FILE_PATH + + "MPEG4_SP_640x480_15fps_512kbps_AACLC_48khz_132kbps_s_0_26.mp4"; + final String overlayFilename = INPUT_FILE_PATH + + "IMG_640x480_Overlay1.png"; + final Semaphore blockTillPreviewCompletes = new Semaphore(1); + previewStart = false; + previewStop = false; + final MediaVideoItem mediaVideoItem1 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", + videoItemFileName, MediaItem.RENDERING_MODE_BLACK_BORDER); + mVideoEditor.addMediaItem(mediaVideoItem1); + + final MediaImageItem mediaImageItem2 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m2", + imageItemFileName, 10000, MediaItem.RENDERING_MODE_BLACK_BORDER); + mVideoEditor.addMediaItem(mediaImageItem2); + + final MediaVideoItem mediaVideoItem3 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m3", + videoItemFileName1, MediaItem.RENDERING_MODE_BLACK_BORDER); + mVideoEditor.addMediaItem(mediaVideoItem3); + + final EffectColor effectColor = + mVideoEditorHelper.createEffectItem(mediaVideoItem1, "Effect1", + 1000, 3000, EffectColor.TYPE_COLOR, EffectColor.GREEN); + mediaVideoItem1.addEffect(effectColor); + + final Rect startRect = new Rect((mediaImageItem2.getHeight() / 3), + (mediaImageItem2.getWidth() / 3), (mediaImageItem2.getHeight() / 2), + (mediaImageItem2.getWidth() / 2)); + final Rect endRect = new Rect(0, 0, mediaImageItem2.getWidth(), + mediaImageItem2.getHeight()); + + final EffectKenBurns kbeffectOnMI2 = new EffectKenBurns(mediaImageItem2, + "KBOnM2", startRect, endRect, 0, 10000); + assertNotNull("EffectKenBurns", kbeffectOnMI2); + mediaImageItem2.addEffect(kbeffectOnMI2); + + final Bitmap mBitmap = mVideoEditorHelper.getBitmap(overlayFilename, + 640, 480); + final OverlayFrame overlayFrame = + mVideoEditorHelper.createOverlay(mediaVideoItem3, "OverlayID", + mBitmap, (mediaImageItem2.getDuration() / 4), + (mediaVideoItem3.getDuration() / 3)); + mediaVideoItem3.addOverlay(overlayFrame); + + validatePreviewProgress(5000, -1, false, mVideoEditor.getDuration()); + } + + /** + *To test Preview : Export during preview + */ + // TODO : remove TC_PRV_008 + @LargeTest + public void testPreviewDuringExport() throws Exception { + final String videoItemFileName = INPUT_FILE_PATH + + "H264_BP_640x480_30fps_192kbps_1_5.mp4"; + final Semaphore blockTillPreviewCompletes = new Semaphore(1); + previewStart = false; + previewStop = false; + + final MediaVideoItem mediaVideoItem1 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", + videoItemFileName, MediaItem.RENDERING_MODE_BLACK_BORDER); + mediaVideoItem1.setExtractBoundaries(0, 20000); + mVideoEditor.addMediaItem(mediaVideoItem1); + + mVideoEditor.generatePreview(new MediaProcessingProgressListener() { + public void onProgress(Object item, int action, int progress) { + } + }); + + long waitingTime = minWaitingTime + mVideoEditor.getDuration(); + + + blockTillPreviewCompletes.acquire(); + final String fileName = mVideoEditor.getPath() + "\test.3gp"; + final int height = MediaProperties.HEIGHT_480; + final int bitrate = MediaProperties.BITRATE_512K; + + try { + mVideoEditor.export(fileName, height, bitrate, + new ExportProgressListener() { + public void onProgress(VideoEditor ve, + String outFileName,int progress) { + + } + }); + } catch (IOException e) { + assertTrue("UnExpected Error in Export" + + e.toString(), false); + } + + final SurfaceHolder surfaceHolder = + MediaFrameworkTest.mSurfaceView.getHolder(); + try { + + mVideoEditor.startPreview(surfaceHolder, 5000, -1, false, 1, + new PreviewProgressListener() { + + public void onProgress(VideoEditor videoEditor, long timeMs, + OverlayData overlayData) { + } + public void onStart(VideoEditor videoEditor) { + setPreviewStart(); + } + public void onStop(VideoEditor videoEditor) { + setPreviewStop(); + blockTillPreviewCompletes.release(); + } + }); + + } catch (Exception e) { + blockTillPreviewCompletes.release(); + } + blockTillPreviewCompletes.tryAcquire(waitingTime, TimeUnit.MILLISECONDS); + mVideoEditor.stopPreview(); + assertTrue("Preview Failed to start", previewStart); + assertTrue("Preview Failed to stop", previewStop); + blockTillPreviewCompletes.release(); + } + + /** + * To test Preview : Preview of current Effects applied (with from time > + * total duration) + */ + // TODO : remove TC_PRV_009 + @LargeTest + public void testPreviewWithDurationGreaterThanMediaDuration() + throws Exception { + final String videoItemFileName = INPUT_FILE_PATH + + "H264_BP_640x480_30fps_192kbps_1_5.mp4"; + final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER; + boolean flagForException = false; + final Semaphore blockTillPreviewCompletes = new Semaphore(1); + + final MediaVideoItem mediaVideoItem1 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", + videoItemFileName, renderingMode); + try { + mediaVideoItem1.setExtractBoundaries(0, 20000); + } catch (Exception e) { + assertTrue("Exception during setExtract Boundaries", false); + } + mVideoEditor.addMediaItem(mediaVideoItem1); + final SurfaceHolder surfaceHolder = + MediaFrameworkTest.mSurfaceView.getHolder(); + long waitingTime = minWaitingTime + (mVideoEditor.getDuration() - 30000); + if(waitingTime < 0) + { + waitingTime = minWaitingTime; + } + + blockTillPreviewCompletes.acquire(); + try { + mVideoEditor.startPreview(surfaceHolder, 30000, -1, true, 1, + new PreviewProgressListener() { + public void onProgress(VideoEditor videoEditor, long timeMs, + OverlayData overlayData) { + } + public void onStart(VideoEditor videoEditor) { + setPreviewStart(); + } + public void onStop(VideoEditor videoEditor) { + setPreviewStop(); + blockTillPreviewCompletes.release(); + } + }); + + } catch (IllegalArgumentException e) { + blockTillPreviewCompletes.release(); + flagForException = true; + } + blockTillPreviewCompletes.tryAcquire(waitingTime, TimeUnit.MILLISECONDS); + assertTrue("Expected Error in Preview", flagForException); + mVideoEditor.stopPreview(); + blockTillPreviewCompletes.release(); + } + + /** + * To test Preview : Preview of current Effects applied (with Render Preview + * Frame) + */ + // TODO : remove TC_PRV_010 + @LargeTest + public void testPreviewWithRenderPreviewFrame() throws Exception { + final String videoItemFileName = INPUT_FILE_PATH + + "H264_BP_640x480_30fps_256kbps_1_17.mp4"; + final Semaphore blockTillPreviewCompletes = new Semaphore(1); + boolean flagForException = false; + OverlayData overlayData1 = new OverlayData(); + previewStart = false; + previewStop = false; + + final String overlayFilename1 = INPUT_FILE_PATH + + "IMG_640x480_Overlay1.png"; + + final MediaVideoItem mediaVideoItem = + mVideoEditorHelper.createMediaItem(mVideoEditor, + "m1", videoItemFileName, MediaItem.RENDERING_MODE_BLACK_BORDER); + mVideoEditor.addMediaItem(mediaVideoItem); + + final EffectColor effectPink = + mVideoEditorHelper.createEffectItem(mediaVideoItem, + "effectNegativeOnMvi", 1000, 3000, EffectColor.TYPE_COLOR, + EffectColor.PINK); + mediaVideoItem.addEffect(effectPink); + + mVideoEditor.generatePreview(new MediaProcessingProgressListener() { + public void onProgress(Object item, int action, int progress) { + } + }); + final SurfaceHolder surfaceHolder = + MediaFrameworkTest.mSurfaceView.getHolder(); + + assertEquals("Render preview Frame at 5 Sec", 5000, + mVideoEditor.renderPreviewFrame(surfaceHolder, 5000, + overlayData1)); + + assertEquals("Render preview Frame at 7 Sec", 7000, + mVideoEditor.renderPreviewFrame(surfaceHolder, 7000, + overlayData1)); + + validatePreviewProgress(5000, -1, false, mVideoEditor.getDuration()); + } + + /** + * To test Preview : Preview of current work from selected jump location + * till end with Audio Track + */ + // TODO : remove TC_PRV_011 + @LargeTest + public void testPreviewWithEndAudioTrack() throws Exception { + final String imageItemFilename1 = INPUT_FILE_PATH + "IMG_1600x1200.jpg"; + final String videoItemFileName = INPUT_FILE_PATH + + "H264_BP_640x480_30fps_256kbps_1_17.mp4"; + final String imageItemFilename2 = INPUT_FILE_PATH + "IMG_640x480.jpg"; + final String audioFilename = INPUT_FILE_PATH + + "AMRNB_8KHz_12.2Kbps_m_1_17.3gp"; + + boolean flagForException = false; + previewStart = false; + previewStop = false; + final MediaImageItem mediaImageItem1 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", + imageItemFilename1, 7000, MediaItem.RENDERING_MODE_BLACK_BORDER); + mVideoEditor.addMediaItem(mediaImageItem1); + + final MediaVideoItem mediaVideoItem = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m2", + videoItemFileName, MediaItem.RENDERING_MODE_BLACK_BORDER); + mediaVideoItem.setExtractBoundaries(1000, 8000); + mVideoEditor.addMediaItem(mediaVideoItem); + + final MediaImageItem mediaImageItem2 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m3", + imageItemFilename2, 7000, MediaItem.RENDERING_MODE_BLACK_BORDER); + mVideoEditor.addMediaItem(mediaImageItem2); + + final AudioTrack audioTrack = + mVideoEditorHelper.createAudio(mVideoEditor, "a1", audioFilename); + mVideoEditor.addAudioTrack(audioTrack); + + List audioList = mVideoEditor.getAllAudioTracks(); + assertEquals("Audio Track List size", 1, audioList.size()); + assertEquals("Audio Track", audioTrack, audioList.get(0)); + mVideoEditor.setAspectRatio(MediaProperties.ASPECT_RATIO_4_3); + + validatePreviewProgress(10000, -1, false, mVideoEditor.getDuration()); + } + + /** + * To test render Preview Frame + */ + // TODO : remove TC_PRV_012 + @LargeTest + public void testRenderPreviewFrame() throws Exception { + final String videoItemFileName1 = INPUT_FILE_PATH + + "H264_BP_1080x720_30fps_800kbps_1_17.mp4"; + final String videoItemFileName2 = INPUT_FILE_PATH + + "MPEG4_SP_800x480_515kbps_15fps_AMR_NB_8KHz_12.2kbps_m_0_26.mp4"; + final String videoItemFileName3 = INPUT_FILE_PATH + + "H264_BP_640x480_30fps_256kbps_1_17.mp4"; + final String imageItemFilename1 = INPUT_FILE_PATH + + "IMG_1600x1200.jpg"; + final String imageItemFilename2 = INPUT_FILE_PATH + + "IMG_176x144.jpg"; + final String audioFilename = INPUT_FILE_PATH + + "AMRNB_8KHz_12.2Kbps_m_1_17.3gp"; + OverlayData overlayData1 = new OverlayData(); + previewStart = false; + previewStop = false; + final MediaVideoItem mediaVideoItem1 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", + videoItemFileName1, MediaItem.RENDERING_MODE_BLACK_BORDER); + mediaVideoItem1.setExtractBoundaries(0, 10000); + mVideoEditor.addMediaItem(mediaVideoItem1); + + final MediaVideoItem mediaVideoItem2 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m2", + videoItemFileName2, MediaItem.RENDERING_MODE_BLACK_BORDER); + mediaVideoItem1.setExtractBoundaries(mediaVideoItem2.getDuration() / 4, + mediaVideoItem2.getDuration() / 2); + mVideoEditor.addMediaItem(mediaVideoItem2); + + final MediaVideoItem mediaVideoItem3 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m3", + videoItemFileName3, MediaItem.RENDERING_MODE_BLACK_BORDER); + mediaVideoItem1.setExtractBoundaries(mediaVideoItem2.getDuration() / 2, + mediaVideoItem2.getDuration()); + mVideoEditor.addMediaItem(mediaVideoItem3); + + final MediaImageItem mediaImageItem4 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m4", + imageItemFilename1, 5000, MediaItem.RENDERING_MODE_BLACK_BORDER); + + final MediaImageItem mediaImageItem5 = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m5", + imageItemFilename2, 5000, MediaItem.RENDERING_MODE_BLACK_BORDER); + + List mediaList = mVideoEditor.getAllMediaItems(); + assertEquals("Media Item List Size", 3, mediaList.size()); + + mVideoEditor.insertMediaItem(mediaImageItem4, mediaVideoItem2.getId()); + mediaList = mVideoEditor.getAllMediaItems(); + assertEquals("Media Item List Size", 4, mediaList.size()); + assertEquals("Media item 1", mediaVideoItem1, mediaList.get(0)); + assertEquals("Media item 2", mediaVideoItem2, mediaList.get(1)); + assertEquals("Media item 4", mediaImageItem4, mediaList.get(2)); + assertEquals("Media item 3", mediaVideoItem3, mediaList.get(3)); + + mVideoEditor.insertMediaItem(mediaImageItem5, mediaImageItem4.getId()); + mediaList = mVideoEditor.getAllMediaItems(); + assertEquals("Media Item List Size", 5, mediaList.size()); + assertEquals("Media item 1", mediaVideoItem1, mediaList.get(0)); + assertEquals("Media item 2", mediaVideoItem2, mediaList.get(1)); + assertEquals("Media item 4", mediaImageItem4, mediaList.get(2)); + assertEquals("Media item 5", mediaImageItem5, mediaList.get(3)); + assertEquals("Media item 3", mediaVideoItem3, mediaList.get(4)); + + mVideoEditor.moveMediaItem(mediaVideoItem1.getId(), + mediaImageItem5.getId()); + mediaList = mVideoEditor.getAllMediaItems(); + assertEquals("Media Item List Size", 5, mediaList.size()); + assertEquals("Media item 2", mediaVideoItem2, mediaList.get(0)); + assertEquals("Media item 4", mediaImageItem4, mediaList.get(1)); + assertEquals("Media item 5", mediaImageItem5, mediaList.get(2)); + assertEquals("Media item 1", mediaVideoItem1, mediaList.get(3)); + assertEquals("Media item 3", mediaVideoItem3, mediaList.get(4)); + + final TransitionCrossfade transition2And4CrossFade = + mVideoEditorHelper.createTCrossFade("transition2And4CrossFade", + mediaVideoItem2, mediaImageItem4, 2000, + Transition.BEHAVIOR_MIDDLE_FAST); + mVideoEditor.addTransition(transition2And4CrossFade); + + final TransitionCrossfade transition1And3CrossFade = + mVideoEditorHelper.createTCrossFade("transition1And3CrossFade", + mediaVideoItem1, mediaVideoItem3, 5000, + Transition.BEHAVIOR_MIDDLE_FAST); + mVideoEditor.addTransition(transition1And3CrossFade); + + final AudioTrack audioTrack = + mVideoEditorHelper.createAudio(mVideoEditor, "a1", audioFilename); + audioTrack.setExtractBoundaries(0, 2000); + mVideoEditor.addAudioTrack(audioTrack); + + audioTrack.enableLoop(); + + mVideoEditor.generatePreview(new MediaProcessingProgressListener() { + public void onProgress(Object item, int action, int progress) { + } + }); + + final SurfaceHolder surfaceHolder = + MediaFrameworkTest.mSurfaceView.getHolder(); + + mVideoEditor.renderPreviewFrame(surfaceHolder, mVideoEditor.getDuration()/4, overlayData1); + Thread.sleep(1000); + mVideoEditor.renderPreviewFrame(surfaceHolder, mVideoEditor.getDuration()/2, overlayData1); + Thread.sleep(1000); + mVideoEditor.renderPreviewFrame(surfaceHolder, mVideoEditor.getDuration(), overlayData1); + + } + + /** + * To Test Preview : Without any Media Items in the story Board + */ + // TODO : remove TC_PRV_013 + @LargeTest + public void testStartPreviewWithoutMediaItems() throws Exception { + boolean flagForException = false; + + final SurfaceHolder surfaceHolder = + MediaFrameworkTest.mSurfaceView.getHolder(); + try{ + mVideoEditor.startPreview(surfaceHolder, 0, -1, false, 1, + new PreviewProgressListener() { + public void onProgress(VideoEditor videoEditor, long timeMs, + OverlayData overlayData) { + } + public void onStart(VideoEditor videoEditor) { + setPreviewStart(); + } + public void onStop(VideoEditor videoEditor) { + setPreviewStop(); + } + }); + }catch (IllegalArgumentException e) { + flagForException = true; + } + assertTrue("Preview without Media Items", flagForException); + } + + /** + * To Test Preview : Add Media and Remove Media Item (Without any Media + * Items in the story Board) + */ + // TODO : remove TC_PRV_014 + @LargeTest + public void testStartPreviewAddRemoveMediaItems() throws Exception { + final String videoItemFilename1 = INPUT_FILE_PATH + + "H263_profile0_176x144_15fps_256kbps_AACLC_32kHz_128kbps_s_0_26.3gp"; + final String imageItemFilename1 = INPUT_FILE_PATH + "IMG_1600x1200.jpg"; + final String alphaFilename = INPUT_FILE_PATH + + "TransitionSpiral_QVGA.jpg"; + boolean flagForException = false; + + final MediaVideoItem mediaVideoItem = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", + videoItemFilename1, MediaItem.RENDERING_MODE_BLACK_BORDER); + mediaVideoItem.setExtractBoundaries(0, 15000); + mVideoEditor.addMediaItem(mediaVideoItem); + + final MediaImageItem mediaImageItem = + mVideoEditorHelper.createMediaItem(mVideoEditor, "m2", + imageItemFilename1, 15000, MediaItem.RENDERING_MODE_BLACK_BORDER); + mVideoEditor.addMediaItem(mediaImageItem); + + final TransitionAlpha transition1And2 = + mVideoEditorHelper.createTAlpha("transition", mediaVideoItem, + mediaImageItem, 3000, Transition.BEHAVIOR_SPEED_UP, + alphaFilename, 10, false); + mVideoEditor.addTransition(transition1And2); + + final EffectColor effectColor = + mVideoEditorHelper.createEffectItem(mediaImageItem, "effect", 5000, + 3000, EffectColor.TYPE_COLOR, EffectColor.PINK); + mediaImageItem.addEffect(effectColor); + + assertEquals("removing Media item 1", mediaVideoItem, + mVideoEditor.removeMediaItem(mediaVideoItem.getId())); + assertEquals("removing Media item 2", mediaImageItem, + mVideoEditor.removeMediaItem(mediaImageItem.getId())); + + try{ + mVideoEditor.generatePreview(new MediaProcessingProgressListener() { + public void onProgress(Object item, int action, int progress) { + } + }); + final SurfaceHolder surfaceHolder = + MediaFrameworkTest.mSurfaceView.getHolder(); + mVideoEditor.startPreview(surfaceHolder, 0, -1, false, 1, + new PreviewProgressListener() { + public void onProgress(VideoEditor videoEditor, long timeMs, + OverlayData overlayData) { + } + public void onStart(VideoEditor videoEditor) { + setPreviewStart(); + } + public void onStop(VideoEditor videoEditor) { + setPreviewStop(); + } + }); + }catch (IllegalArgumentException e) { + flagForException = true; + } + assertTrue("Preview with removed Media Items", flagForException); + + } + + /** + * To test Preview : Preview of current Effects applied (with Render Preview + * Frame) + */ + // TODO : remove TC_PRV_015 + @LargeTest + public void testPreviewWithRenderPreviewFrameWithoutGenerate() throws Exception { + final String videoItemFileName = INPUT_FILE_PATH + + "H264_BP_640x480_30fps_256kbps_1_17.mp4"; + boolean flagForException = false; + long duration = 0; + OverlayData overlayData1 = new OverlayData(); + + final MediaVideoItem mediaVideoItem = + mVideoEditorHelper.createMediaItem(mVideoEditor, + "m1", videoItemFileName, MediaItem.RENDERING_MODE_BLACK_BORDER); + mVideoEditor.addMediaItem(mediaVideoItem); + + final SurfaceHolder surfaceHolder = + MediaFrameworkTest.mSurfaceView.getHolder(); + duration = mVideoEditor.getDuration(); + /* RenderPreviewFrame returns -1 to indicate last frame */ + try { + mVideoEditor.renderPreviewFrame(surfaceHolder, duration, + overlayData1); + } catch ( IllegalStateException e) { + flagForException = true; + } + assertTrue (" Render Preview Frame without generate", flagForException); + duration = mVideoEditor.getDuration() + 1000; + try { + mVideoEditor.renderPreviewFrame(surfaceHolder, duration, + overlayData1); + } catch ( IllegalArgumentException e) { + flagForException = true; + } + assertTrue (" Preview time greater than duration", flagForException); + } +} -- cgit v1.1