Skip to content

Commit

Permalink
OboeTester: Add error codes
Browse files Browse the repository at this point in the history
  • Loading branch information
robertwu1 committed Jul 19, 2023
1 parent ecbb917 commit eec21f9
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,25 @@ public class StreamConfiguration {
public static final int INPUT_PRESET_UNPROCESSED = 9; // must match Oboe
public static final int INPUT_PRESET_VOICE_PERFORMANCE = 10; // must match Oboe

public static final int ERROR_DISCONNECTED = -899; // must match Oboe
public static final int ERROR_BASE = -900;
public static final int ERROR_DISCONNECTED = -899;
public static final int ERROR_ILLEGAL_ARGUMENT = -898;
public static final int ERROR_INTERNAL = -896;
public static final int ERROR_INVALID_STATE = -895;
public static final int ERROR_INVALID_HANDLE = -892;
public static final int ERROR_UNIMPLEMENTED = -890;
public static final int ERROR_UNAVAILABLE = -889;
public static final int ERROR_NO_FREE_HANDLES = -888;
public static final int ERROR_NO_MEMORY = -887;
public static final int ERROR_NULL = -886;
public static final int ERROR_TIMEOUT = -885;
public static final int ERROR_WOULD_BLOCK = -884;
public static final int ERROR_INVALID_FORMAT = -883;
public static final int ERROR_OUT_OF_RANGE = -882;
public static final int ERROR_NO_SERVICE = -881;
public static final int ERROR_INVALID_RATE = -880;
public static final int ERROR_CLOSED = -869;
public static final int ERROR_OK = 0;

public static final int USAGE_MEDIA = 1;
public static final int USAGE_VOICE_COMMUNICATION = 2;
Expand Down Expand Up @@ -763,4 +781,49 @@ public int getHardwareFormat() {
public void setHardwareFormat(int hardwareFormat) {
this.mHardwareFormat = hardwareFormat;
}

static String convertErrorToText(int error) {
switch (error) {
case ERROR_BASE:
return "ErrorBase";
case ERROR_DISCONNECTED:
return "ErrorDisconnected";
case ERROR_ILLEGAL_ARGUMENT:
return "ErrorIllegalArgument";
case ERROR_INTERNAL:
return "ErrorInternal";
case ERROR_INVALID_STATE:
return "ErrorInvalidState";
case ERROR_INVALID_HANDLE:
return "ErrorInvalidHandle";
case ERROR_UNIMPLEMENTED:
return "ErrorUnimplemented";
case ERROR_UNAVAILABLE:
return "ErrorUnavailable";
case ERROR_NO_FREE_HANDLES:
return "ErrorNoFreeHandles";
case ERROR_NO_MEMORY:
return "ErrorNoMemory";
case ERROR_NULL:
return "ErrorNull";
case ERROR_TIMEOUT:
return "ErrorTimeout";
case ERROR_WOULD_BLOCK:
return "ErrorWouldBlock";
case ERROR_INVALID_FORMAT:
return "ErrorInvalidFormat";
case ERROR_OUT_OF_RANGE:
return "ErrorOutOfRange";
case ERROR_NO_SERVICE:
return "ErrorNoService";
case ERROR_INVALID_RATE:
return "ErrorInvalidRate";
case ERROR_CLOSED:
return "ErrorClosed";
case ERROR_OK:
return "ErrorOk";
default:
return "?=" + error;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -663,8 +663,8 @@ public void startAudio() throws IOException {
Log.i(TAG, "startAudio() called =========================");
int result = startNative();
if (result != 0) {
showErrorToast("Start failed with " + result);
throw new IOException("startNative returned " + result);
showErrorToast("Start failed with " + StreamConfiguration.convertErrorToText(result));
throw new IOException("startNative returned " + StreamConfiguration.convertErrorToText(result));
} else {
onStartAllContexts();
for (StreamContext streamContext : mStreamContexts) {
Expand All @@ -679,7 +679,7 @@ public void startAudio() throws IOException {
}

protected void toastPauseError(int result) {
showErrorToast("Pause failed with " + result);
showErrorToast("Pause failed with " + StreamConfiguration.convertErrorToText(result));
}

public void pauseAudio() {
Expand All @@ -696,7 +696,7 @@ public void pauseAudio() {
public void flushAudio() {
int result = flushNative();
if (result != 0) {
showErrorToast("flush failed with " + result);
showErrorToast("flush failed with " + StreamConfiguration.convertErrorToText(result));
} else {
mAudioState = AUDIO_STATE_FLUSHED;
updateEnabledWidgets();
Expand All @@ -706,7 +706,7 @@ public void flushAudio() {
public void stopAudio() {
int result = stopNative();
if (result != 0) {
showErrorToast("Stop failed with " + result);
showErrorToast("Stop failed with " + StreamConfiguration.convertErrorToText(result));
} else {
mAudioState = AUDIO_STATE_STOPPED;
updateEnabledWidgets();
Expand All @@ -717,7 +717,7 @@ public void stopAudio() {
public void releaseAudio() {
int result = releaseNative();
if (result != 0) {
showErrorToast("release failed with " + result);
showErrorToast("release failed with " + StreamConfiguration.convertErrorToText(result));
} else {
mAudioState = AUDIO_STATE_RELEASED;
updateEnabledWidgets();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public void stopAudio() {

@Override
protected void toastPauseError(int result) {
showToast("Pause not implemented. Returned " + result);
showToast("Pause not implemented. Returned " + StreamConfiguration.convertErrorToText(result));
}

protected int saveWaveFile(File file) {
Expand Down

0 comments on commit eec21f9

Please sign in to comment.