jobject createJavaRemote(JNIEnv *env, remote* cremote) { if (cremote == NULL) return NULL; jclass remoteClass = (*env)->FindClass(env, "sage/SFIRTuner$Remote"); jmethodID remoteConst = (*env)->GetMethodID(env, remoteClass, "<init>", "()V"); jobject rv = (*env)->NewObject(env, remoteClass, remoteConst); SetObjectField(env, rv, "name", "Ljava/lang/String;", (*env)->NewStringUTF(env, (const char*)cremote->name)); SetLongField(env, rv, "carrier_freq", cremote->carrier_freq); SetLongField(env, rv, "bit_time", cremote->bit_time); if (cremote->command != NULL) SetObjectField(env, rv, "command", "Lsage/SFIRTuner$Command;", createJavaCmd(env, cremote->command)); if (cremote->next != NULL) SetObjectField(env, rv, "next", "Lsage/SFIRTuner$Remote;", createJavaRemote(env, cremote->next)); return rv; }
static void freeXilState(JNIEnv *env, jobject jxil, InstanceState *inst) { /* Debug Message */ PRINT("In freeXilState\n"); if (inst) { if (inst->rtvc_image) { xil_destroy(inst->rtvc_image); inst->rtvc_image = NULL; } freeXilImages(inst); if (inst->xil_state) { /* xil_close(inst->xil_state); */ inst->xil_state = NULL; } SetLongField(env, jxil, "peer", (int) 0); free(inst); } }
/* * Class: com_sun_media_protocol_sunvideo_XILCapture * Method: xilConnect * Signature: (II)Z */ JNIEXPORT jboolean JNICALL Java_com_sun_media_protocol_sunvideo_XILCapture_xilConnect(JNIEnv *env, jobject jxil, jint devnum, jint port) { XilDevice device; char *devname = NULL; char devnamestr[256]; /* Allocate a new structure */ InstanceState * inst = (InstanceState *) malloc(sizeof(InstanceState)); /* Store the pointer to the instance state in the java variable "peer" */ SetLongField(env, jxil, "peer", (int) inst); /* Debug message */ PRINT("In xilConnect\n"); /* Copy the parameters */ inst->port = (int) port; inst->xil_state = NULL; inst->rtvc_image = NULL; inst->scaled_image = NULL; inst->colored_image = NULL; inst->xil_cis = NULL; inst->scale = 1; inst->quality = 0; inst->do_cis = RAW; inst->cis_type = "Raw"; inst->skip = 0; inst->inWidth = 0; inst->inHeight = 0; inst->outWidth = 0; inst->outHeight = 0; inst->inStrideX = 0; inst->started = 0; inst->firstRawRead = 1; /* inst->xil_state = xil_open(); */ createXilState(); inst->xil_state = *jmf_xil_state; if (inst->xil_state == NULL) { fprintf(stderr, "SunVideo Capture unable to open xil library\n"); freeXilState(env, jxil, inst); return 0; } /* Debug Message */ PRINT("XILCapture open_xil() succeeded \n"); if (devnum > 0) { sprintf(devnamestr, "/dev/rtvc%d", devnum); devname = devnamestr; /* Debug Message */ PRINT("Attempting to open xil device "); PRINT(devname); PRINT("\n"); } if (! (device = xil_device_create(inst->xil_state, "SUNWrtvc"))) { /* Debug Message */ PRINT("Unable to create a xil device object\n"); freeXilState(env, jxil, inst); return 0; } /* Debug Message */ PRINT("XILCapture xil_device_create() succeeded \n"); xil_device_set_value(device, "DEVICE_NAME", devname); /* Debug Message */ PRINT("XILCapture xil_device_set_value() succeeded \n"); inst->rtvc_image = xil_create_from_device(inst->xil_state, "SUNWrtvc", device); /* Debug Message */ PRINT("XILCapture xil_create_from_device() completed \n"); xil_device_destroy(device); /* Debug Message */ PRINT("XILCapture xil_device_destroy() completed \n"); if (inst->rtvc_image == NULL) { /* Debug Message */ PRINT("Unable to open xil device\n"); freeXilState(env, jxil, inst); return 0; } tryPort(env, jxil, inst); return 1; }