From 9de581f832226239beb0aafacfffc85e50bbf718 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Fri, 1 Jul 2016 22:05:11 +0900 Subject: [PATCH] audio: Check returning values of write (android) --- audio/internal/driver/driver_android.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/audio/internal/driver/driver_android.go b/audio/internal/driver/driver_android.go index 7cce818b1..daf6e8d65 100644 --- a/audio/internal/driver/driver_android.go +++ b/audio/internal/driver/driver_android.go @@ -148,7 +148,17 @@ static char* writeToAudioTrack(uintptr_t java_vm, uintptr_t jni_env, break; } - // TODO: Check the result. + switch (result) { + case -3: // ERROR_INVALID_OPERATION + return "invalid operation"; + case -2: // ERROR_BAD_VALUE + return "bad value"; + case -1: // ERROR + return "error"; + } + if (result < 0) { + return "unknown error"; + } return NULL; } @@ -221,6 +231,8 @@ func (p *Player) loop() { msg = C.writeToAudioTrack(C.uintptr_t(vm), C.uintptr_t(env), p.audioTrack, C.int(p.bytesPerSample), unsafe.Pointer(&bufInShorts[0]), C.int(len(bufInShorts))) + default: + panic("not reach") } if msg != nil { return errors.New(C.GoString(msg))