void set_tcp(JNIEnv *env,jobject packet,char *pointer,jbyteArray data,struct ip *ip) { struct tcphdr *tcp=(struct tcphdr *)(pointer); jint length=(*env)->GetArrayLength(env,data); tcp->th_sport=htons((jshort)GetIntField(TCPPacket,packet,"src_port")); tcp->th_dport=htons((jshort)GetIntField(TCPPacket,packet,"dst_port")); tcp->th_seq=htonl((unsigned long)GetLongField(TCPPacket,packet,"sequence")); tcp->th_ack=htonl((unsigned long)GetLongField(TCPPacket,packet,"ack_num")); tcp->th_off=5; // updated by Damien Daspit 5/7/01 tcp->th_flags=(GetBooleanField(TCPPacket,packet,"rsv1")<<7)+ (GetBooleanField(TCPPacket,packet,"rsv2")<<6)+ (GetBooleanField(TCPPacket,packet,"urg")<<5)+ (GetBooleanField(TCPPacket,packet,"ack")<<4)+ (GetBooleanField(TCPPacket,packet,"psh")<<3)+ (GetBooleanField(TCPPacket,packet,"rst")<<2)+ (GetBooleanField(TCPPacket,packet,"syn")<<1)+ (GetBooleanField(TCPPacket,packet,"fin")); // ******************************* tcp->th_win=htons((jshort)GetIntField(TCPPacket,packet,"window")); tcp->th_urp=htons(GetShortField(TCPPacket,packet,"urgent_pointer")); if(length+IPv4HDRLEN+TCPHDRLEN>MAX_PACKET_SIZE) length=MAX_PACKET_SIZE-IPv4HDRLEN-TCPHDRLEN; // updated by Damien Daspit 5/15/01 (*env)->GetByteArrayRegion(env,data,0, length, (u_char *)(pointer+TCPHDRLEN)); tcp->th_sum=0; tcp->th_sum=in_cksum2(ip,htons((u_short)length+TCPHDRLEN),(u_short *)tcp,length+TCPHDRLEN); }
ActivityState* ActivityState::create(ANativeActivity* activity) { JOP_ASSERT(ns_instance == nullptr, "There must only be one ActivityState!"); ns_instance.reset(new ActivityState); ns_instance->nativeActivity = activity; ANativeActivity_setWindowFlags(activity, AWINDOW_FLAG_KEEP_SCREEN_ON, AWINDOW_FLAG_KEEP_SCREEN_ON); Thread::attachJavaThread(activity->vm, activity->env); // Get the screen size { auto env = Thread::getCurrentJavaEnv(); if (!env) { JOP_DEBUG_ERROR("No current java environment, function \"" << __func__ << "\""); return get(); } jclass activityClass = env->GetObjectClass(activity->clazz); jclass displayMetricsClass = env->FindClass("android/util/DisplayMetrics"); jmethodID displayMetricsInit = env->GetMethodID(displayMetricsClass, "<init>", "()V"); jobject displayMetricsObject = env->NewObject(displayMetricsClass, displayMetricsInit); jmethodID getWindowManagerMethod = env->GetMethodID(activityClass, "getWindowManager", "()Landroid/view/WindowManager;"); jobject windowManagerObject = env->CallObjectMethod(activity->clazz, getWindowManagerMethod); jclass windowManagerClass = env->FindClass("android/view/WindowManager"); jmethodID getDefaultDisplayMethod = env->GetMethodID(windowManagerClass, "getDefaultDisplay", "()Landroid/view/Display;"); jobject displayObject = env->CallObjectMethod(windowManagerObject, getDefaultDisplayMethod); jclass displayClass = env->FindClass("android/view/Display"); jmethodID getMetricsMethod = env->GetMethodID(displayClass, "getMetrics", "(Landroid/util/DisplayMetrics;)V"); env->CallVoidMethod(displayObject, getMetricsMethod, displayMetricsObject); jfieldID pixelsWidth = env->GetFieldID(displayMetricsClass, "widthPixels", "I"); jfieldID pixelsHeight = env->GetFieldID(displayMetricsClass, "heightPixels", "I"); ns_instance->screenSize.x = env->GetIntField(displayMetricsObject, pixelsWidth); ns_instance->screenSize.y = env->GetIntField(displayMetricsObject, pixelsHeight); //jmethodID getRefreshRateMethod = env->GetMethodID(displayClass, "getRefreshRate", "(Landroid/view/Display;)F"); ns_instance->screenRefreshRate = 60;//env->CallFloatMethod(displayObject, getRefreshRateMethod); env->DeleteLocalRef(activityClass); env->DeleteLocalRef(displayMetricsObject); env->DeleteLocalRef(windowManagerObject); env->DeleteLocalRef(windowManagerClass); env->DeleteLocalRef(displayObject); env->DeleteLocalRef(displayClass); } return get(); }
GIntBig HFAEntry::GetBigIntField( const char *pszFieldPath, CPLErr *peErr ) { char szFullFieldPath[1024]; snprintf( szFullFieldPath, sizeof(szFullFieldPath), "%s[0]", pszFieldPath ); const GUInt32 nLower = GetIntField( szFullFieldPath, peErr ); if( peErr != NULL && *peErr != CE_None ) return 0; snprintf( szFullFieldPath, sizeof(szFullFieldPath), "%s[1]", pszFieldPath ); const GUInt32 nUpper = GetIntField( szFullFieldPath, peErr ); if( peErr != NULL && *peErr != CE_None ) return 0; return nLower + (static_cast<GIntBig>(nUpper) << 32); }
GIntBig HFAEntry::GetBigIntField( const char *pszFieldPath, CPLErr *peErr ) { GUInt32 nLower, nUpper; char szFullFieldPath[1024]; sprintf( szFullFieldPath, "%s[0]", pszFieldPath ); nLower = GetIntField( szFullFieldPath, peErr ); if( peErr != NULL && *peErr != CE_None ) return 0; sprintf( szFullFieldPath, "%s[1]", pszFieldPath ); nUpper = GetIntField( szFullFieldPath, peErr ); if( peErr != NULL && *peErr != CE_None ) return 0; return nLower + (((GIntBig) nUpper) << 32); }
pattern* createCPattern(JNIEnv *env, jobject jpat) { if (jpat == NULL) return NULL; pattern* rv = (pattern*) malloc(sizeof(pattern)); rv->bit_length = GetIntField(env, jpat, "bit_length"); rv->length = GetIntField(env, jpat, "length"); rv->r_flag = (char)GetCharField(env, jpat, "r_flag"); jbyteArray jdata = (jbyteArray)GetObjectField(env, jpat, "bytes", "[B"); jbyte* jdataArray = (*env)->GetByteArrayElements(env, jdata, NULL); rv->bytes = (unsigned char*) malloc((*env)->GetArrayLength(env, jdata)); memcpy((void*)rv->bytes, (void*)jdataArray, (*env)->GetArrayLength(env, jdata)); (*env)->ReleaseByteArrayElements(env, jdata, jdataArray, JNI_ABORT); jobject nextPat = GetObjectField(env, jpat, "next", "Lsage/SFIRTuner$Pattern;"); rv->next = NULL; if (nextPat != NULL) rv->next = createCPattern(env, nextPat); return rv; }
JNIEXPORT void JNICALL Java_jpcap_JpcapWriter_writePacket(JNIEnv *env,jobject obj,jobject packet){ jbyteArray header,body; int hlen,blen; struct pcap_pkthdr hdr; char buf[MAX_PACKET_SIZE]; hdr.ts.tv_sec=(long)GetLongField(Packet,packet,"sec"); hdr.ts.tv_usec=(long)GetLongField(Packet,packet,"usec"); hdr.caplen=GetIntField(Packet,packet,"caplen"); hdr.len=GetIntField(Packet,packet,"len"); header=GetObjectField(Packet,packet,"[B","header"); body=GetObjectField(Packet,packet,"[B","data"); hlen=(*env)->GetArrayLength(env,header); blen=(*env)->GetArrayLength(env,body); (*env)->GetByteArrayRegion(env,header,0,hlen,buf); (*env)->GetByteArrayRegion(env,body,0,blen,(char *)(buf+hlen)); pcap_dump((u_char *)pdt,&hdr,buf); }
JNIEXPORT jboolean JNICALL Java_com_sun_media_renderer_video_XLibRenderer_xlibSetComponent(JNIEnv *env, jobject blitter, jobject component) { XWindowAttributes xwa; int error; XlibBlitter *xblitter = (XlibBlitter*) GetIntField(env, blitter, "blitter"); if (xblitter->display) { freeDisplay(*xblitter); } if (xblitter->surface) { (*env)->DeleteGlobalRef(env, xblitter->surface); xblitter->surface = NULL; } if ( jawt == 1 && xblitter->awtObj != 0) { freeJAWT(env, xblitter); xblitter->awtObj = 0; xblitter->drawingSurface = 0; } xblitter->component = component; getComponentInfo(env, xblitter); awtLock(env, xblitter); xblitter->screen = DefaultScreen(xblitter->display); XGetWindowAttributes(xblitter->display, xblitter->xid, &xwa); xblitter->visual = xwa.visual; xblitter->depth = xwa.depth; xblitter->bitsPerPixel = (xwa.depth == 8)? 8 : ((xwa.depth < 24)? 16 : 32); xblitter->gc = XCreateGC(xblitter->display, xblitter->xid, 0, 0); xblitter->shmAvailable = XQueryExtension(xblitter->display, "MIT-SHM", &(xblitter->shmOpcode), &(xblitter->shmComplete), &error); awtUnlock(env, xblitter); return 1; }
JNIEXPORT jboolean JNICALL Java_com_sun_media_renderer_video_XLibRenderer_xlibSetInputFormat(JNIEnv *env, jobject blitter, jint width, jint height, jint stride) { XlibBlitter *xblitter = (XlibBlitter*) GetIntField(env, blitter, "blitter"); /* awtLock(env, xblitter); bitsPerPixel = (xblitter->depth == 8) ? 8 : 32; if (xblitter->scaledData) free(xblitter->scaledData); if (xblitter->ximage) XDestroyImage(xblitter->ximage); xblitter->ximage = XCreateImage(xblitter->display, xblitter->visual, xblitter->depth, ZPixmap, 0, (char *)data, width, height, bitsPerPixel, stride * (bitsPerPixel >> 3)); */ xblitter->inWidth = width; xblitter->inHeight = height; xblitter->inStride = stride; /* if (aes == 4) (*env)->ReleaseIntArrayElements(env, (jintArray)dataArray, data, 0); else (*env)->ReleaseByteArrayElements(env, (jbyteArray)dataArray, data, 0); if (xblitter->ximage == 0) printf("Couldn't create X Image \n"); else printf("Created X Image \n"); awtUnlock(env, xblitter); */ return 1; }
// read HTK subnet definition and create corresponding subnet GramSubN::GramSubN(Source *src) { char nbuf[132],vbuf[132],buf[32],*ptr,ntype,del; int i,n,st,en,nl=0, nn=0; float prob; Boolean isOk = TRUE; try{ name = "!!MAIN!!"; // if sublat it will be overwritten with HTK name entry = NULL; exit = NULL; refcount = 0; // read the header info while((ptr=GetNextFieldName(nbuf,&del,src))) { if (nbuf[0]=='\n') { if (nl != 0 && nn != 0) break; } else if (strlen(ptr)==1) { ntype=*ptr; switch(ntype) { case 'N': nn=GetIntField('N',del,vbuf,src); break; case 'L': nl=GetIntField('L',del,vbuf,src); break; default: GetFieldValue(0,src); break; } } else { if (strcmp(ptr,"SUBLAT") == 0) GetFieldValue(vbuf,src),name=vbuf; else GetFieldValue(NULL,src); } } if (feof(src->f)) return; // No main network // read the node and link defs vector<GramNode *> nodemap(nn); string nodename,tag; NodeKind kind; for (i=0; i<nn; i++) nodemap[i] = NULL; do { if ((ptr=GetNextFieldName(nbuf,&del,src)) == NULL) break; /* Recognised line types have only one character names */ if (strlen(ptr)==1) ntype=*ptr; else ntype=0; if (ntype == '.') { ptr = NULL; break; } switch(ntype) { case '\n': break; case 'I': n=GetIntField('I',del,vbuf,src); if (n < 0 || n >= nn){ HRError(10723,"AGram: node %d is missing",n); throw ATK_Error(10723); } if (nodemap[n] != NULL){ HRError(10724,"AGram: multiple defs for node %d",n); throw ATK_Error(10724); } nodename=""; tag=""; kind = UnknNode; while((ptr=GetNextFieldName(nbuf,&del,src)) != NULL) { if (nbuf[0]=='\n') break; else { if (strlen(ptr)>=1) ntype=*ptr; else ntype=0; switch(ntype) { case 'W': GetFieldValue(vbuf,src); if (strcmp(vbuf,"!NULL")==0) kind = NullNode; else { nodename = vbuf; kind = WordNode; } break; case 's': GetFieldValue(vbuf,src); tag = vbuf; break; case 'L': GetFieldValue(vbuf,src); nodename = vbuf; kind = CallNode; break; default: GetFieldValue(0,src); break; } } } if (kind == UnknNode){ HRError(10725,"AGram: node %d not fully defined",n); throw ATK_Error(10725); } if (kind==NullNode) {sprintf(buf,"%d",n); nodename=buf;} nodemap[n] = new GramNode(kind,nodename,tag); nodes.push_back(nodemap[n]); break; case 'J': n=GetIntField('I',del,vbuf,src); if (n<0 || n>=nl){ HRError(10726,"AGram: link %d is not possible",n); throw ATK_Error(10726); } st = en = -1; prob=0.0; while ((ptr=GetNextFieldName(nbuf,&del,src))) { if (nbuf[0]=='\n') break; else { if (strlen(ptr)>=1) ntype=*ptr; else ntype=0; switch(ntype) { case 'S': st=GetIntField('S',del,vbuf,src); if (st<0 || st>=nn){ HRError(10727,"AGram: start node %d out of range",st); throw ATK_Error(10727); } break; case 'E': en=GetIntField('E',del,vbuf,src); if (en<0 || en>=nn){ HRError(10727,"AGram: end node %d out of range",en); throw ATK_Error(10727); } break; case 'l': prob=float(GetFltField('l',del,vbuf,src)); break; default: GetFieldValue(0,src); break; } } } if (st<0 || en <0){ HRError(10728,"AGram: incomplete link spec (%d to %d)",st,en); throw ATK_Error(10728); } if (nodemap[st]==NULL){ HRError(10729,"AGram: start node %d undefined",st); throw ATK_Error(10729); } if (nodemap[en]==NULL){ HRError(10729,"AGram: end node %d undefined",en); throw ATK_Error(10729); } AddLink(nodemap[st],nodemap[en],prob); break; default: GetFieldValue(0,src); while ((ptr=GetNextFieldName(nbuf,&del,src))) { if (nbuf[0]=='\n') break; else GetFieldValue(0,src); } break; } }while(ptr != NULL); // set end points SetEnds(); // finally check that all is well n = IsBroken(TRUE); if (n != 0){ switch(n){ case 1: HRError(10729,"AGram: entry/exit node missing"); break; case 2: HRError(10729,"AGram: entry node has predecessors"); break; case 3: HRError(10729,"AGram: exit node has successors"); break; case 4: HRError(10729,"AGram: no path from entry to exit"); break; case 5: HRError(10729,"AGram: unreachable nodes"); break; } throw ATK_Error(10729); } } catch (ATK_Error e){ HRError(e.i,"AGram: error detected in subnet %s",name.c_str()); throw e; } }
JNIEXPORT jboolean JNICALL Java_com_sun_media_renderer_video_XLibRenderer_xlibSetOutputSize(JNIEnv *env, jobject blitter, jint outWidth, jint outHeight) { /* We assume that this function is called only if there is a size change */ XlibBlitter *xblitter = (XlibBlitter*) GetIntField(env, blitter, "blitter"); int inWidth = xblitter->inWidth; int inHeight = xblitter->inHeight; int stride = xblitter->inStride; awtLock(env, xblitter); /* Get rid of the old image and arrays */ if (xblitter->ximage) { /* Clean up shared memory */ if (xblitter->shmActive) { destroySharedMemory(xblitter); } xblitter->ximage->data = NULL; XDestroyImage(xblitter->ximage); } if (xblitter->scaledData) { free(xblitter->scaledData); xblitter->scaledData = NULL; } if (xblitter->xincs) { free(xblitter->xincs); xblitter->xincs = NULL; } if (xblitter->yincs) { free(xblitter->yincs); xblitter->yincs = NULL; } xblitter->outWidth = outWidth; xblitter->outHeight = outHeight; if ( outWidth != xblitter->inWidth || outHeight != xblitter->inHeight) { /* We need to scale */ xblitter->xincs = (char *) malloc(outWidth * sizeof(char)); xblitter->yincs = (char *) malloc(outHeight * sizeof(char)); { int x, y, oldValue, newValue, xtotal; oldValue = 0; xtotal = 0; for (x = 1; x < xblitter->outWidth; x++) { newValue = (int)((double)(x * xblitter->inWidth) / outWidth); xblitter->xincs[x-1] = newValue - oldValue; xtotal += newValue - oldValue; oldValue = newValue; } xblitter->xincs[x - 1] = xblitter->inStride - xtotal; oldValue = 0; for (y = 1; y < xblitter->outHeight; y++) { newValue = (int)((double)(y * inHeight) / outHeight); xblitter->yincs[y-1] = newValue - oldValue; oldValue = newValue; } } stride = outWidth; } else { /* No scaling required */ xblitter->xincs = NULL; xblitter->yincs = NULL; xblitter->scaledData = NULL; } /* Try to allocate a shared memory image */ if (xblitter->shmAvailable) { createSharedMemory(xblitter, outWidth, outHeight); } /* If a shared memory image could not be created and we need to scale, use XLib */ if (xblitter->shmActive == 0) { if ( outWidth != xblitter->inWidth || outHeight != xblitter->inHeight) { xblitter->scaledData = (void *) malloc(outWidth * outHeight * (xblitter->bitsPerPixel >> 3)); } xblitter->ximage = XCreateImage(xblitter->display, xblitter->visual, xblitter->depth, ZPixmap, 0, (char *)0, outWidth, outHeight, xblitter->bitsPerPixel, stride * (xblitter->bitsPerPixel >> 3)); }