static jobject GetTable(JNIEnv *env, jobject obj) { vx_uint32 t,num; vx_target target = (vx_parameter)GetHandle(env, obj, TargetClass, handleName); vxQueryTarget(target, VX_TARGET_ATTRIBUTE_NUMKERNELS, &num, sizeof(num)); vx_target_kernel_t *table = (vx_target_kernel_t *)calloc(num, sizeof(vx_target_kernel_t)); jobjectArray tarray = 0; if (table) { jclass tclass = env->FindClass("org/khronos/openvx/Target$TargetKernel"); tarray = env->NewObjectArray(num, tclass, 0); jmethodID tcon = env->GetMethodID(tclass, "<init>", "("OBJECT(Target)")V"); jfieldID tfenum = env->GetFieldID(tclass, "enumeration", "I"); jfieldID tfname = env->GetFieldID(tclass, "name", "Ljava/lang/String;"); vxQueryTarget(target, VX_TARGET_ATTRIBUTE_KERNELTABLE, table, num*sizeof(vx_target_kernel_t)); for (t = 0; t < num; t++) { jobject tobj = env->NewObject(tclass, tcon); env->SetIntField(tobj, tfenum, table[t].enumeration); jstring tstr = env->NewStringUTF(table[t].name); env->SetObjectField(tobj, tfname, tstr); env->SetObjectArrayElement(tarray, t, tobj); } } return tarray; }
static VALUE Target_name(VALUE self) { vx_target target = (vx_target)DATA_PTR(self); const char name[VX_MAX_TARGET_NAME]; vxQueryTarget(target, VX_QUERY_TARGET_NAME, (void *)name, sizeof(name)); return rb_str_new2(name); }
static VALUE Target_index(VALUE self) { vx_target target = (vx_target)DATA_PTR(self); vx_uint32 index = 0; vxQueryTarget(target, VX_QUERY_TARGET_INDEX, &index, sizeof(index)); return INT2FIX(index); }
static VALUE OpenVX_targets_list(VALUE self) { vx_uint32 t,value = 0; vx_status status = VX_FAILURE; vx_char targetname[VX_MAX_TARGET_NAME]; vx_target target = 0; VALUE array; status = vxQueryContext(context, VX_QUERY_CONTEXT_NUMTARGETS, &value, sizeof(value)); REXT_PRINT("status = %d, targets = %d\n", status, value); if (status == VX_SUCCESS) { array = rb_ary_new2(value); for (t = 0; t < value; t++) { target = vxGetTargetByIndex(context, t); if (target) { status = vxQueryTarget(target, VX_QUERY_TARGET_NAME, targetname, sizeof(targetname)); if (status == VX_SUCCESS) rb_ary_push(array, rb_str_new2(targetname)); } } } return array; }
static jint GetIndex(JNIEnv *env, jobject obj) { vx_target t = (vx_target)GetHandle(env, obj, TargetClass, handleName); jint index; vxQueryTarget(t, VX_TARGET_ATTRIBUTE_INDEX, &index, sizeof(index)); return index; }
static VALUE Target_kernels_list(VALUE self) { vx_target target = (vx_target)DATA_PTR(self); vx_uint32 k,numk = 0; vx_target_kernel_t *table = NULL; vxQueryTarget(target, VX_QUERY_TARGET_NUMKERNELS, &numk, sizeof(numk)); VALUE array = rb_ary_new2(numk); table = (vx_target_kernel_t *)calloc(numk, sizeof(*table)); if (table) { vxQueryTarget(target, VX_QUERY_TARGET_KERNELTABLE, table, numk*sizeof(*table)); for (k = 0; k < numk; k++) { rb_ary_push(array, rb_str_new2(table[k].name)); } } return array; }
static jint GetNumKernels(JNIEnv *env, jobject obj) { vx_target t = (vx_target)GetHandle(env, obj, TargetClass, handleName); jint num = 0; vx_status status = vxQueryTarget(t, VX_TARGET_ATTRIBUTE_NUMKERNELS, &num, sizeof(num)); if (status != VX_SUCCESS) num = 0; return num; }
vx_bool vxFindAllTargetsOfKernelsByName(vx_context context, vx_char kname[VX_MAX_KERNEL_NAME], vx_char *targets[VX_MAX_TARGET_NAME]) { vx_bool ret = vx_false_e; vx_uint32 k = 0u, t = 0u, num_targets = 0u; vxQueryContext(context, VX_CONTEXT_ATTRIBUTE_TARGETS, &num_targets, sizeof(num_targets)); for (t = 0u; t < num_targets; t++) { vx_target target = vxGetTargetByIndex(context, t); vx_uint32 num_kernels = 0; /* clear out the name */ memset(targets[t], 0, VX_MAX_TARGET_NAME); if (vxQueryTarget(target, VX_TARGET_ATTRIBUTE_NUMKERNELS, &num_kernels, sizeof(num_kernels)) == VX_SUCCESS) { vx_size size = num_kernels * sizeof(vx_kernel_info_t); vx_kernel_info_t *kernels = malloc(size); if (vxQueryTarget(target, VX_TARGET_ATTRIBUTE_KERNELTABLE, kernels, size) == VX_SUCCESS) { for (k = 0u; k < num_kernels; k++) { /* target kernel names are allowed to have variant strings */ vx_char string[VX_MAX_KERNEL_NAME], *ker; strncpy(string, kernels[k].name, VX_MAX_KERNEL_NAME); ker = strtok(string, ":"); /* if it has any variants of this kernel it is ok */ if (strncmp(kname, ker, VX_MAX_KERNEL_NAME) == 0) { /* fill in the name if it has this kernel */ if (vxQueryTarget(target, VX_TARGET_ATTRIBUTE_NAME, targets[t], VX_MAX_TARGET_NAME) == VX_SUCCESS) { ret = vx_true_e; } break; } } } free(kernels); } } return ret; }
static jstring GetName(JNIEnv *env, jobject obj) { jstring name = 0; vx_char targetname[VX_MAX_TARGET_NAME]; memset(targetname, 0, sizeof(targetname)); vx_target t = (vx_target)GetHandle(env, obj, TargetClass, handleName); if (t) { vx_status status = vxQueryTarget(t, VX_TARGET_ATTRIBUTE_NAME, targetname, sizeof(targetname)); if (status != VX_SUCCESS) ALOGD("Failed to query target name! status=%d\n",status); } else ALOGD("Failed to retrieve correct target reference!\n"); return env->NewStringUTF(targetname); }
vx_target vxFindTarget(vx_context context, vx_char name[VX_MAX_TARGET_NAME]) { vx_uint32 t, targets; vx_target target = 0; vx_char targetName[VX_MAX_TARGET_NAME]; vxQueryContext(context, VX_CONTEXT_ATTRIBUTE_NUMTARGETS, &targets, sizeof(targets)); for (t = 0u; t < targets; t++) { target = vxGetTargetByIndex(context,t); vxQueryTarget(target, VX_TARGET_ATTRIBUTE_NAME, &targetName, VX_MAX_TARGET_NAME); if (strncmp(targetName, name, VX_MAX_TARGET_NAME) == 0) { break; } vxReleaseTarget(&target); target = 0; } return target; }
vx_bool vxCreateListOfAllTargets(vx_context context, vx_char **targets[], vx_uint32 *num_targets) { vx_bool ret = vx_false_e; vx_uint32 t = 0u; if (vxQueryContext(context, VX_CONTEXT_ATTRIBUTE_TARGETS, num_targets, sizeof(*num_targets)) == VX_SUCCESS) { *targets = (vx_char **)calloc(*num_targets, sizeof(vx_char *)); if (*targets) { for (t = 0u; t < *num_targets; t++) { vx_target target = vxGetTargetByIndex(context, t); (*targets)[t] = (vx_char *)calloc(VX_MAX_TARGET_NAME, sizeof(vx_char)); if ((*targets)[t]) { if (vxQueryTarget(target, VX_TARGET_ATTRIBUTE_NAME, (*targets)[t], VX_MAX_TARGET_NAME) == VX_SUCCESS) { ret = vx_true_e; } else { ret = vx_false_e; break; } } } if (ret == vx_false_e) { do { if (t > 0) free((*targets)[--t]); } while (t != 0); } } } return ret; }