0

I built tinyalsa lib using the sources from tinyalsa-ndk and wrapped it with JNI calls and I'm trying to use it in my code.

I used Swig to generate Java wrappers (and modified output to comply with my package) My native method declaration is:

public final static native long mixer_open(long jarg);

My JNI wrapper call is inside a wrapper class TinyAlsa.java under the root pacakge (for the example I'll use com.Example.App):

public static SWIGTYPE_p_mixer mixer_open(long card) 
{
    long cPtr = TinyAlsaJNI.mixer_open(card);
    return (cPtr == 0) ? null : new SWIGTYPE_p_mixer(cPtr, false);
}

and my wrapper c method is:

SWIGEXPORT jlong JNICALL Java_com_Example_App_Native_TinyAlsaJNI_mixer_1open(JNIEnv *jenv, jclass jcls, jlong jarg1) 
{
    jlong jresult = 0 ;
    unsigned int arg1 ;
    struct mixer *result = 0 ;

    (void)jenv;
    (void)jcls;
    arg1 = (unsigned int)jarg1; 
    result = (struct mixer *)mixer_open(arg1);
    *(struct mixer **)&jresult = result; 
    return jresult;
}

The tinalsa library is loaded OK without exceptions but calls such as mixer_open(0) returns null pointers.
However If I execute the compiled tinymix mixer is open and mixer controls are listed as should.
Am I missing something? How can I make it work from my code?

Oren
  • 937
  • 1
  • 10
  • 34
  • Code would probably make it easier to tell what you're missing – Gabe Sechan Feb 04 '15 at 00:09
  • Deleted my answer as I realize I misread your code. But you are overcomplicating the return- just change it to return (long long)mixer_open(arg1); You may be missing some init code, I'd put a log or breakpoint in this function to see if open itself is returning NULL. If so, you are missing some sort of init function. – Gabe Sechan Feb 04 '15 at 01:04
  • The c code is generated using Swig. I suspect it indeed over complicates things, but - as this code eventually access mixer info which is most likely not permitted without root, I'm trying to figure whether I should do something else to make it work (besides calling su before calling alsa methods), if the code itself is not the problem.. – Oren Feb 04 '15 at 01:09

0 Answers0