Skip to content

Commit

Permalink
OboeTester: add flush button (#1850)
Browse files Browse the repository at this point in the history
  • Loading branch information
robertwu1 authored Jul 12, 2023
1 parent 3bd67fa commit e0b62d1
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 4 deletions.
9 changes: 9 additions & 0 deletions apps/OboeTester/app/src/main/cpp/NativeAudioContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<oboe::AudioStream> 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);
Expand Down
2 changes: 2 additions & 0 deletions apps/OboeTester/app/src/main/cpp/NativeAudioContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ class ActivityContext {

oboe::Result pause();

oboe::Result flush();

oboe::Result stopAllStreams();

virtual oboe::Result stop() {
Expand Down
5 changes: 5 additions & 0 deletions apps/OboeTester/app/src/main/cpp/jni-bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -546,6 +550,10 @@ public void pauseAudio(View view) {
keepScreenOn(false);
}

public void flushAudio(View view) {
flushAudio();
}

public void closeAudio(View view) {
closeAudio();
}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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) {
Expand Down
11 changes: 11 additions & 0 deletions apps/OboeTester/app/src/main/res/layout/merge_audio_common.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,17 @@
android:text="@string/pauseAudio"
android:textSize="12sp" />

<Button
android:id="@+id/button_flush"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:backgroundTint="@xml/button_color_selector"
android:backgroundTintMode="src_atop"
android:onClick="flushAudio"
android:text="@string/flushAudio"
android:textSize="12sp" />

<Button
android:id="@+id/button_stop"
android:layout_width="0dp"
Expand Down
1 change: 1 addition & 0 deletions apps/OboeTester/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<string name="openAudio">Open</string>
<string name="startAudio">Start</string>
<string name="pauseAudio">Pause</string>
<string name="flushAudio">Flush</string>
<string name="stopAudio">Stop</string>
<string name="releaseAudio">Release</string>
<string name="closeAudio">Close</string>
Expand Down

0 comments on commit e0b62d1

Please sign in to comment.