Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cast byte[] to serializable Object; communicate with audio device #1

Open
chenym250 opened this issue Jul 11, 2017 · 1 comment
Open

Comments

@chenym250
Copy link

I want to be able to send binary audio data remotely to a pepper robot. While I was able to do so using Naoqi's sendRemoteBufferToOutput() method with qi framework and C++ SDK (2.5.5), I can't find a simple way to call that method in Java.

In C++, sendRemoteBufferToOutput() accepts an ALValue constructed from a binary buffer (ALValue.setBinary()); in Java it's even more ambiguous. According to jnaoqi's API, it accepts merely an Object. I tried passing a byte array or a list of bytes or a byteBuffer, none of which works, and I constantly get this error:
qimessaging.jni: Cannot serialize return value: Unable to convert JObject in AnyValue

(Additionally, when I was using qimessaging's API I got this error:
qimessaging.remoteobject: no promise found for req id:162 obj: 60 func: 2 type: Reply)

I looked into old documentations, and in version 1.14 there is a binding class for ALValue, called Variant, that I can't find in the new API. Qimessaging seemed to support customizable serializers, but I don't think it was included in the 2.5.5 release. So I ran out of ideas. Another way I can think of now is to wrap either ALValue or my entire C++ application in JNI, but I'd like to know the right way to call sendRemoteBufferToOutput() in Java before going that route.

In conclusion, my issue is: is it possible to pass a byte buffer to sendRemoteBufferToOutput() in Java?

@chenym250
Copy link
Author

chenym250 commented Jul 21, 2017

In case someone who may have encountered the same issue finds this post in the future, I was able to bypass this issue by encoding the raw data into a Base64 string and passing the string to a simple service hosted on the robot (written in Python or C++), which would then decode the string and call sendRemoteBufferToOutput() function via qimessaging's Python (or C++) API.

opennao pushed a commit that referenced this issue Sep 24, 2019
In libqi, we can specify the "future callback type".

This influences the execution of callbacks: if the type is
Sync, then the callback is executed synchronously during setValue(…) or
then(…)/andThen(…). Otherwise, it is executed asynchronously.

For example:

    Promise<String> promise = new Promise<>(FutureCallbackType.Sync);
    System.out.println("#0");
    promise.getFuture().andThen(new QiCallback<String>() {
        @OverRide
        public void onResult(String result) {
            // executed in the same thread
            System.out.println("#2");
        }
    });
    System.out.println("#1");
    promise.setValue("hello");
    System.out.println("#3");

This code sample prints:

    #0
    #1
    #2
    #3

Change-Id: I732a76070a7ec67b58c1e666f0e538571689fede
Reviewed-on: http://gerrit.aldebaran.lan/72640
Reviewed-by: rvimont <[email protected]>
Tested-by: gerrit
Reviewed-by: epinault <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant