JNIEXPORT jint JNICALL Java_com_example_audiotest_module_NSWrapper_nsInit (JNIEnv *env, jobject thiz, jint samplerate) { if((mSamplerate == samplerate) && (NULL != hNsHandle)){ return 0; } if(NULL != hNsHandle){ ns_destroy(); } if(pthread_mutex_init(&ns_process_lock, NULL) != 0) { //printf("\n mutex init failed\n"); __android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, "create mutex for ns_process_lock failed." ); return -1; } else{ __android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, "create mutex for ns_process_lock success." ); } int status = WebRtcNsx_Create(&hNsHandle); if(0 == status){ __android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, "WebRtcNs_Create success, status=%d", status); status = WebRtcNsx_Init(hNsHandle, samplerate); if(0 == status){ mSamplerate = samplerate; // The input and output signals should always be 10ms (80 or 160 samples). if(samplerate == 8000){ NS_PROC_SAMPLE = 80; } else{ NS_PROC_SAMPLE = 160; } __android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, "WebRtcNs_Init success status=%d, samplerate=%d, NS_PROC_SAMPLE=%d", status, samplerate, NS_PROC_SAMPLE); } else{ ns_destroy(); __android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, "WebRtcNs_Init failed, status=%d", status); } } else{ pthread_mutex_destroy(&ns_process_lock); __android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, "WebRtcNs_Create failed, status=%d", status); } return status; }
static ns_t *ns_fromjson (JSON o) { ns_t *ns = xzmalloc (sizeof (*ns)); if (!Jget_nodeset (o, "ok", &ns->ok) || !Jget_nodeset (o, "unknown", &ns->unknown) || !Jget_nodeset (o, "slow", &ns->slow) || !Jget_nodeset (o, "fail", &ns->fail)) { ns_destroy (ns); return NULL; } return ns; }
int main (int argc, char *argv[]) { flux_t h; int ch; bool uopt = false; bool dopt = false; fmt_t fmt = FMT_RANGED; ns_t *ns; log_init ("flux-up"); while ((ch = getopt_long (argc, argv, OPTIONS, longopts, NULL)) != -1) { switch (ch) { case 'c': /* --comma */ fmt = FMT_COMMA; break; case 'n': /* --newline */ fmt = FMT_NEWLINE; break; case 'u': /* --up */ uopt = true; break; case 'd': /* --down */ dopt = true; break; default: usage (); break; } } if (optind != argc) usage (); if (!(h = flux_open (NULL, 0))) err_exit ("flux_open"); if (!(ns = ns_fromkvs (h))) ns = ns_guess (h); if (dopt) ns_print_down (ns, fmt); else if (uopt) ns_print_up (ns, fmt); else ns_print_all (ns, fmt); ns_destroy (ns); flux_close (h); log_fini (); return 0; }
static ns_t *ns_fromjson (const char *json_str) { ns_t *ns = xzmalloc (sizeof (*ns)); JSON o = NULL; if (!(o = Jfromstr (json_str)) || !Jget_nodeset (o, "ok", &ns->ok) || !Jget_nodeset (o, "unknown", &ns->unknown) || !Jget_nodeset (o, "slow", &ns->slow) || !Jget_nodeset (o, "fail", &ns->fail)) { ns_destroy (ns); ns = NULL; } Jput (o); return ns; }
JNIEXPORT jint JNICALL Java_com_example_audiotest_module_NSWrapper_nsDestroy (JNIEnv *env, jobject thiz) { return ns_destroy(); }