summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
authorThe Android Open Source Project <initial-contribution@android.com>2009-02-20 07:38:31 -0800
committerThe Android Open Source Project <initial-contribution@android.com>2009-02-20 07:38:31 -0800
commit15ab3eae2ec3d73b3e8aa60b33ae41445bf83f4b (patch)
treed03d027a7ed97af616904e02a7b420babf40d44f /media
parent3001a035439d8134a7d70d796376d1dfbff3cdcd (diff)
downloadframeworks_base-15ab3eae2ec3d73b3e8aa60b33ae41445bf83f4b.zip
frameworks_base-15ab3eae2ec3d73b3e8aa60b33ae41445bf83f4b.tar.gz
frameworks_base-15ab3eae2ec3d73b3e8aa60b33ae41445bf83f4b.tar.bz2
auto import from //branches/cupcake/...@132569
Diffstat (limited to 'media')
-rw-r--r--media/libmedia/AudioRecord.cpp2
-rw-r--r--media/libmedia/ToneGenerator.cpp19
-rw-r--r--media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaAudioTrackTest.java125
-rw-r--r--media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/TonesAutoTest.java2
-rw-r--r--media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaRecorderPrepareStateUnitTest.java2
-rw-r--r--media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaRecorderSetOutputFileStateUnitTest.java20
-rw-r--r--media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaRecorderStateUnitTestTemplate.java7
7 files changed, 152 insertions, 25 deletions
diff --git a/media/libmedia/AudioRecord.cpp b/media/libmedia/AudioRecord.cpp
index 3d39181..e833c85 100644
--- a/media/libmedia/AudioRecord.cpp
+++ b/media/libmedia/AudioRecord.cpp
@@ -400,7 +400,7 @@ status_t AudioRecord::obtainBuffer(Buffer* audioBuffer, int32_t waitCount)
uint32_t u = cblk->user;
uint32_t bufferEnd = cblk->userBase + cblk->frameCount;
- if (u + framesReady > bufferEnd) {
+ if (u + framesReq > bufferEnd) {
framesReq = bufferEnd - u;
}
diff --git a/media/libmedia/ToneGenerator.cpp b/media/libmedia/ToneGenerator.cpp
index 7fafc56..5416629 100644
--- a/media/libmedia/ToneGenerator.cpp
+++ b/media/libmedia/ToneGenerator.cpp
@@ -175,27 +175,28 @@ bool ToneGenerator::startTone(int toneType) {
if (mState == TONE_INIT) {
if (prepareWave()) {
LOGV("Immediate start, time %d\n", (unsigned int)(systemTime()/1000000));
-
+ lResult = true;
mState = TONE_STARTING;
mLock.unlock();
mpAudioTrack->start();
mLock.lock();
if (mState == TONE_STARTING) {
+ LOGV("Wait for start callback");
if (mWaitCbkCond.waitRelative(mLock, seconds(1)) != NO_ERROR) {
LOGE("--- Immediate start timed out");
mState = TONE_IDLE;
+ lResult = false;
}
}
-
- if (mState == TONE_PLAYING)
- lResult = true;
+ } else {
+ mState == TONE_IDLE;
}
} else {
LOGV("Delayed start\n");
mState = TONE_RESTARTING;
if (mWaitCbkCond.waitRelative(mLock, seconds(1)) == NO_ERROR) {
- if (mState != TONE_INIT) {
+ if (mState != TONE_IDLE) {
lResult = true;
}
LOGV("cond received");
@@ -206,7 +207,8 @@ bool ToneGenerator::startTone(int toneType) {
}
mLock.unlock();
- LOGV("Tone started, time %d\n", (unsigned int)(systemTime()/1000000));
+ LOGV_IF(lResult, "Tone started, time %d\n", (unsigned int)(systemTime()/1000000));
+ LOGW_IF(!lResult, "Tone start failed!!!, time %d\n", (unsigned int)(systemTime()/1000000));
return lResult;
}
@@ -457,8 +459,11 @@ audioCallback_EndLoop:
if (lpToneGen->prepareWave()) {
lpToneGen->mState = TONE_STARTING;
} else {
- lpToneGen->mState = TONE_INIT;
+ LOGW("Cbk restarting prepareWave() failed\n");
+ lpToneGen->mState = TONE_IDLE;
lpToneGen->mpAudioTrack->stop();
+ // Force loop exit
+ lNumSmp = 0;
}
lSignal = true;
break;
diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaAudioTrackTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaAudioTrackTest.java
index ae6a834..b6a0848 100644
--- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaAudioTrackTest.java
+++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaAudioTrackTest.java
@@ -19,6 +19,8 @@ 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.content.Context;
import android.test.ActivityInstrumentationTestCase2;
@@ -47,12 +49,127 @@ public class MediaAudioTrackTest extends ActivityInstrumentationTestCase2<MediaF
protected void tearDown() throws Exception {
super.tearDown();
}
+
+ //-----------------------------------------------------------------
+ // 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,
+ // 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,
+ AudioFormat.ENCODING_PCM_16BIT,
+ AudioTrack.getMinBufferSize(testSampleRates[i],
+ _inTest_config, AudioFormat.ENCODING_PCM_16BIT),//testSampleRates[i]*4
+ _inTest_mode);
+ } catch(IllegalArgumentException iae) {
+ Log.e("MediaAudioTrackTest", "[ constructorTestMultiSampleRate ] exception at SR "
+ + testSampleRates[i]+": \n" + iae);
+ }
+ 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.e("MediaAudioTrackTest", "[ constructorTestMultiSampleRate ] failed to construct "
+ +"AudioTrack(streamType="+_inTest_streamType
+ +", sampleRateInHz=" + testSampleRates[i]
+ +", channelConfig=" + _inTest_config
+ +", audioFormat=AudioFormat.ENCODING_PCM_16BIT"
+ +", 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(...)
+ //----------------------------------
- //Test case 1: Set the invalid volume
+ //Test case 1: constructor for streaming AudioTrack, mono, 16bit at misc valid sample rates
+ @MediumTest
+ public void testConstructorMono16MusicStream() throws Exception {
+
+ TestResults res = constructorTestMultiSampleRate(
+ AudioManager.STREAM_MUSIC, AudioTrack.MODE_STREAM,
+ AudioFormat.CHANNEL_CONFIGURATION_MONO,
+ AudioTrack.STATE_INITIALIZED);
+
+ assertTrue("testConstructorMono16MusicStream: " + res.mResultLog, res.mResult);
+ }
+
+
+ //Test case 2: constructor for streaming AudioTrack, stereo, 16bit at misc valid sample rates
@MediumTest
- public void testGetMinVolume() throws Exception {
- //To Do: Create the test case for GetMinVolume
- assertTrue("testGetMinVolume", true);
+ public void testConstructorStereo16MusicStream() throws Exception {
+
+ TestResults res = constructorTestMultiSampleRate(
+ AudioManager.STREAM_MUSIC, AudioTrack.MODE_STREAM,
+ AudioFormat.CHANNEL_CONFIGURATION_STEREO,
+ AudioTrack.STATE_INITIALIZED);
+
+ assertTrue("testConstructorStereo16MusicStream: " + res.mResultLog, res.mResult);
+ }
+
+
+ //Test case 3: constructor for static AudioTrack, mono, 16bit at misc valid sample rates
+ @MediumTest
+ public void testConstructorMono16MusicStatic() throws Exception {
+
+ TestResults res = constructorTestMultiSampleRate(
+ AudioManager.STREAM_MUSIC, AudioTrack.MODE_STATIC,
+ AudioFormat.CHANNEL_CONFIGURATION_MONO,
+ 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
+ @MediumTest
+ public void testConstructorStereo16MusicStatic() throws Exception {
+
+ TestResults res = constructorTestMultiSampleRate(
+ AudioManager.STREAM_MUSIC, AudioTrack.MODE_STATIC,
+ AudioFormat.CHANNEL_CONFIGURATION_STEREO,
+ AudioTrack.STATE_NO_STATIC_DATA);
+
+ assertTrue("testConstructorStereo16MusicStatic: " + res.mResultLog, res.mResult);
}
}
diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/TonesAutoTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/TonesAutoTest.java
index 0209305..da18e74 100644
--- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/TonesAutoTest.java
+++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/TonesAutoTest.java
@@ -88,7 +88,7 @@ import android.media.AudioManager;
toneGen = new ToneGenerator(AudioManager.STREAM_MUSIC, 100);
- for (type = ToneGenerator.TONE_PROP_BEEP; type <= ToneGenerator.TONE_PROP_PROMPT; type++) {
+ for (type = ToneGenerator.TONE_PROP_BEEP; type <= ToneGenerator.TONE_PROP_BEEP2; type++) {
if (toneGen.startTone(type)) {
Thread.sleep(1000);
toneGen.stopTone();
diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaRecorderPrepareStateUnitTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaRecorderPrepareStateUnitTest.java
index dfd544a..134144d 100644
--- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaRecorderPrepareStateUnitTest.java
+++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaRecorderPrepareStateUnitTest.java
@@ -55,7 +55,7 @@ public class MediaRecorderPrepareStateUnitTest extends AndroidTestCase implement
try {
recorder.prepare();
} catch (IOException exception) {
- fail("recorder.prepare() failed");
+ throw new RuntimeException();
}
}
diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaRecorderSetOutputFileStateUnitTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaRecorderSetOutputFileStateUnitTest.java
index 50e235b..712a758 100644
--- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaRecorderSetOutputFileStateUnitTest.java
+++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaRecorderSetOutputFileStateUnitTest.java
@@ -29,24 +29,22 @@ public class MediaRecorderSetOutputFileStateUnitTest extends AndroidTestCase imp
private MediaRecorderStateUnitTestTemplate mTestTemplate = new MediaRecorderStateUnitTestTemplate();
/**
* 1. It is valid to call setOutputFile() in the following states:
- * {DataSourceConfigured}.
+ * {DataSourceConfigured, Initial, Initialized, Prepared, Recording, Error}.
* 2. It is invalid to call setOutputFile() in the following states:
- * {Initial, Initialized, Prepared, Recording, Error}
+ * {}
*
* @param stateErrors the MediaRecorderStateErrors to check against.
*/
public void checkStateErrors(MediaRecorderStateErrors stateErrors) {
// Valid states.
assertTrue(!stateErrors.errorInDataSourceConfiguredState);
-
- // Invalid states.
- assertTrue(stateErrors.errorInPreparedState);
- assertTrue(stateErrors.errorInRecordingState);
- assertTrue(stateErrors.errorInErrorState);
- assertTrue(stateErrors.errorInInitialState);
- assertTrue(stateErrors.errorInInitialStateAfterReset);
- assertTrue(stateErrors.errorInInitialStateAfterStop);
- assertTrue(stateErrors.errorInInitializedState);
+ assertTrue(!stateErrors.errorInPreparedState);
+ assertTrue(!stateErrors.errorInRecordingState);
+ assertTrue(!stateErrors.errorInErrorState);
+ assertTrue(!stateErrors.errorInInitialState);
+ assertTrue(!stateErrors.errorInInitialStateAfterReset);
+ assertTrue(!stateErrors.errorInInitialStateAfterStop);
+ assertTrue(!stateErrors.errorInInitializedState);
}
public void invokeMethodUnderTest(MediaRecorder recorder) {
diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaRecorderStateUnitTestTemplate.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaRecorderStateUnitTestTemplate.java
index f350467..9edc9aa 100644
--- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaRecorderStateUnitTestTemplate.java
+++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaRecorderStateUnitTestTemplate.java
@@ -90,9 +90,15 @@ class MediaRecorderStateUnitTestTemplate extends AndroidTestCase {
}
}
+ // FIXME:
+ // In the past, stop() == reset().
+ // However, this is no longer true. The plan is to have a STOPPED state.
+ // and from STOPPED state, start can be called without the need to
+ // do the recording configuration again.
private void setMediaRecorderToInitialStateAfterStop() {
try {
mMediaRecorder.reset();
+/*
mMediaRecorder.setAudioSource(AUDIO_SOURCE);
mMediaRecorder.setOutputFormat(OUTPUT_FORMAT);
mMediaRecorder.setAudioEncoder(AUDIO_ENCODER);
@@ -100,6 +106,7 @@ class MediaRecorderStateUnitTestTemplate extends AndroidTestCase {
mMediaRecorder.prepare();
mMediaRecorder.start();
mMediaRecorder.stop();
+*/
} catch(Exception e) {
fail("setMediaRecorderToInitialStateAfterReset: Exception " + e.getClass().getName() + " was thrown.");
}