diff --git a/apps/OboeTester/app/src/main/cpp/NativeAudioContext.cpp b/apps/OboeTester/app/src/main/cpp/NativeAudioContext.cpp index cd5639dd3..eb9462a95 100644 --- a/apps/OboeTester/app/src/main/cpp/NativeAudioContext.cpp +++ b/apps/OboeTester/app/src/main/cpp/NativeAudioContext.cpp @@ -299,6 +299,15 @@ oboe::Result ActivityContext::start() { return result; } +oboe::Result ActivityContext::flush() { + oboe::Result result = oboe::Result::OK; + for (auto entry : mOboeStreams) { + std::shared_ptr oboeStream = entry.second; + result = oboeStream->requestFlush(); + } + return result; +} + int32_t ActivityContext::saveWaveFile(const char *filename) { if (mRecording == nullptr) { LOGW("ActivityContext::saveWaveFile(%s) but no recording!", filename); diff --git a/apps/OboeTester/app/src/main/cpp/NativeAudioContext.h b/apps/OboeTester/app/src/main/cpp/NativeAudioContext.h index a2180a929..0575d7d96 100644 --- a/apps/OboeTester/app/src/main/cpp/NativeAudioContext.h +++ b/apps/OboeTester/app/src/main/cpp/NativeAudioContext.h @@ -141,6 +141,8 @@ class ActivityContext { oboe::Result pause(); + oboe::Result flush(); + oboe::Result stopAllStreams(); virtual oboe::Result stop() { diff --git a/apps/OboeTester/app/src/main/cpp/jni-bridge.cpp b/apps/OboeTester/app/src/main/cpp/jni-bridge.cpp index b46b8e63f..a98f8f72d 100644 --- a/apps/OboeTester/app/src/main/cpp/jni-bridge.cpp +++ b/apps/OboeTester/app/src/main/cpp/jni-bridge.cpp @@ -181,6 +181,11 @@ Java_com_mobileer_oboetester_TestAudioActivity_pauseNative(JNIEnv *env, jobject) return (jint) engine.getCurrentActivity()->pause(); } +JNIEXPORT jint JNICALL +Java_com_mobileer_oboetester_TestAudioActivity_flushNative(JNIEnv *env, jobject) { + return (jint) engine.getCurrentActivity()->flush(); +} + JNIEXPORT jint JNICALL Java_com_mobileer_oboetester_TestAudioActivity_stopNative(JNIEnv *env, jobject) { return (jint) engine.getCurrentActivity()->stop(); diff --git a/apps/OboeTester/app/src/main/java/com/mobileer/oboetester/TestAudioActivity.java b/apps/OboeTester/app/src/main/java/com/mobileer/oboetester/TestAudioActivity.java index 43ce25c9b..b4f707dc0 100644 --- a/apps/OboeTester/app/src/main/java/com/mobileer/oboetester/TestAudioActivity.java +++ b/apps/OboeTester/app/src/main/java/com/mobileer/oboetester/TestAudioActivity.java @@ -62,10 +62,11 @@ abstract class TestAudioActivity extends Activity { public static final int AUDIO_STATE_OPEN = 0; public static final int AUDIO_STATE_STARTED = 1; public static final int AUDIO_STATE_PAUSED = 2; - public static final int AUDIO_STATE_STOPPED = 3; - public static final int AUDIO_STATE_RELEASED = 4; - public static final int AUDIO_STATE_CLOSING = 5; - public static final int AUDIO_STATE_CLOSED = 6; + public static final int AUDIO_STATE_FLUSHED = 3; + public static final int AUDIO_STATE_STOPPED = 4; + public static final int AUDIO_STATE_RELEASED = 5; + public static final int AUDIO_STATE_CLOSING = 6; + public static final int AUDIO_STATE_CLOSED = 7; public static final int COLOR_ACTIVE = 0xFFD0D0A0; public static final int COLOR_IDLE = 0xFFD0D0D0; @@ -89,6 +90,7 @@ abstract class TestAudioActivity extends Activity { private Button mOpenButton; private Button mStartButton; private Button mPauseButton; + private Button mFlushButton; private Button mStopButton; private Button mReleaseButton; private Button mCloseButton; @@ -325,6 +327,7 @@ protected void updateEnabledWidgets() { mOpenButton.setBackgroundColor(mAudioState == AUDIO_STATE_OPEN ? COLOR_ACTIVE : COLOR_IDLE); mStartButton.setBackgroundColor(mAudioState == AUDIO_STATE_STARTED ? COLOR_ACTIVE : COLOR_IDLE); mPauseButton.setBackgroundColor(mAudioState == AUDIO_STATE_PAUSED ? COLOR_ACTIVE : COLOR_IDLE); + mFlushButton.setBackgroundColor(mAudioState == AUDIO_STATE_FLUSHED ? COLOR_ACTIVE : COLOR_IDLE); mStopButton.setBackgroundColor(mAudioState == AUDIO_STATE_STOPPED ? COLOR_ACTIVE : COLOR_IDLE); mReleaseButton.setBackgroundColor(mAudioState == AUDIO_STATE_RELEASED ? COLOR_ACTIVE : COLOR_IDLE); mCloseButton.setBackgroundColor(mAudioState == AUDIO_STATE_CLOSED ? COLOR_ACTIVE : COLOR_IDLE); @@ -425,6 +428,7 @@ protected void findAudioCommon() { if (mOpenButton != null) { mStartButton = (Button) findViewById(R.id.button_start); mPauseButton = (Button) findViewById(R.id.button_pause); + mFlushButton = (Button) findViewById(R.id.button_flush); mStopButton = (Button) findViewById(R.id.button_stop); mReleaseButton = (Button) findViewById(R.id.button_release); mCloseButton = (Button) findViewById(R.id.button_close); @@ -546,6 +550,10 @@ public void pauseAudio(View view) { keepScreenOn(false); } + public void flushAudio(View view) { + flushAudio(); + } + public void closeAudio(View view) { closeAudio(); } @@ -637,6 +645,8 @@ private void openStreamContext(StreamContext streamContext) throws IOException { private native int pauseNative(); + private native int flushNative(); + private native int stopNative(); private native int releaseNative(); @@ -683,6 +693,16 @@ public void pauseAudio() { } } + public void flushAudio() { + int result = flushNative(); + if (result != 0) { + showErrorToast("flush failed with " + result); + } else { + mAudioState = AUDIO_STATE_FLUSHED; + updateEnabledWidgets(); + } + } + public void stopAudio() { int result = stopNative(); if (result != 0) { diff --git a/apps/OboeTester/app/src/main/res/layout/merge_audio_common.xml b/apps/OboeTester/app/src/main/res/layout/merge_audio_common.xml index a34d40c4d..ef0ee5c3f 100644 --- a/apps/OboeTester/app/src/main/res/layout/merge_audio_common.xml +++ b/apps/OboeTester/app/src/main/res/layout/merge_audio_common.xml @@ -62,6 +62,17 @@ android:text="@string/pauseAudio" android:textSize="12sp" /> +