void* wrap_malloc32 (unsigned size_int32) { int* wrap=(int*)malloc32(size_int32+WRAP_SIZE*2,-1); if (wrap==0) return 0; int* goods=wrap+WRAP_SIZE; return goods; }
void *calloc32(int num, int size) { register void *p; size *= num; if ((p = malloc32(size))) memset(p, 0, size); return (p); }
int main() { //---------- start nm program ------------ int fromHost=ncl_hostSync(0xC0DE6406); // send handshake to host if (fromHost!=0xC0DE0086){ // get handshake from host return -1; } // Get image parameters from host int width = ncl_hostSync(0); int height= ncl_hostSync(1); int size = width*height; int* intSrc=(int*)malloc32(size/4,HEAP_3); int* intDst=intSrc; free32(intSrc); CSobel sobel(width, height); // Check memory allocation if (sobel.isReady==false || intSrc ==0 ){ ncl_hostSync(0xDEADB00F); // send error to host return -1; } else ncl_hostSync(0x600DB00F); // send ok to host ncl_hostSync((int)extSrc); // Send source buffer address to host ncl_hostSync((int)extDst); // Send result buffer address to host clock_t t0,t1; int counter=0; // frame counter while(1){ // Start sobel in loop ncl_hostSync(counter); // Wait source buffer till is ready nmppsCopy_8u((nm8u*)extSrc,(nm8u*)intSrc,size); t0=clock(); sobel.filter((unsigned char*)intSrc,(unsigned char*)intDst); t1=clock(); nmppsCopy_8u((nm8u*)intDst,(nm8u*)extDst,size); ncl_hostSync(t1-t0); // Send elapsed time counter++; } ncl_hostSync(0xDEADB00F); free32(extSrc); free32(extDst); return 1; }
void *realloc32(void *p, int size) { register unsigned long *mem = p; unsigned int oldsize; mem--; oldsize = *mem+sizeof(long); mem++; unsigned long *newmem = malloc32(size); size += sizeof(long); oldsize = oldsize<size?oldsize:size; memcpy(newmem, mem, oldsize-sizeof(long)); mem--; free(mem); return (void *)newmem; }
__char_ptr_char_ptr32 to_ptr32_ptr32 (char **ptr64) { int argc; __char_ptr_char_ptr32 short_argv; for (argc=0; ptr64[argc]; argc++); short_argv = (__char_ptr_char_ptr32) malloc32 (sizeof (__char_ptr32) * (argc + 1)); for (argc=0; ptr64[argc]; argc++) short_argv[argc] = (__char_ptr32) strdup32 (ptr64[argc]); short_argv[argc] = (__char_ptr32) 0; return short_argv; }
/** Initialize transfer list structures. * * @param[in] instance Memory place to use. * @param[in] name Name of the new list. * @return Error code * * Allocates memory for internal ed_t structure. */ int endpoint_list_init(endpoint_list_t *instance, const char *name) { assert(instance); instance->name = name; instance->list_head = malloc32(sizeof(ed_t)); if (!instance->list_head) { usb_log_error("Failed to allocate list head.\n"); return ENOMEM; } instance->list_head_pa = addr_to_phys(instance->list_head); usb_log_debug2("Transfer list %s setup with ED: %p(0x%0" PRIx32 ")).\n", name, instance->list_head, instance->list_head_pa); ed_init(instance->list_head, NULL, NULL); list_initialize(&instance->endpoint_list); fibril_mutex_initialize(&instance->guard); return EOK; }
int VNCServer::SetSize(int width,int height) { Log("-VNCServer::SetSize [%d,%d]\n",width,height); //Check max size if (width*height>4096*3072) //Error return Error("-Size bigger than max size allowed (4096*3072)\n"); //Check that it is not same size than before if (width==screen->width && height==screen->height) //error return Error("-Settign same size, skiping\n"); //Lock use.WaitUnusedAndLock(); //Get old framebuffer char *old = (char*)screen->frameBuffer; //Alloc new framebuffer char *fb = (char*)malloc32(width*height*4); //Empty memset(fb,0xFF,width*height*4); //If we got and old one if (screen->frameBuffer) { //NUmber of bytes to copy DWORD n = screen->width*4; //which is bigger if (screen->width>width) //Old one biggerC than this one so cap it n = width*4; //Copy each line for (int i=0;i<height && i<screen->height; ++i) //Copy memcpy(fb+i*width*4,screen->frameBuffer+i*screen->width*4,n); //Free old one free(screen->frameBuffer); } //Set new framebuffer size screen->frameBuffer = fb; screen->width = width; screen->height = height; screen->paddedWidthInBytes = width*screen->depth/8; //Resize all viewers for (Clients::iterator it=clients.begin(); it!=clients.end(); ++it) //Check it is only sent to the viewer if in private mode if (!viewerId || it->first==viewerId) //Update it it->second->ResizeScreen(); //Unlock use.Unlock(); //OK return 1; }
VNCServer::VNCServer() { //NO editor or private viewer editorId = 0; viewerId = 0; //NO listener yet listener = NULL; //No height int width=0; int height=0; int bytesPerPixel = 4; int bitsPerSample = 8; //Alocate screen info screen = (rfbScreenInfo*)calloc(sizeof(rfbScreenInfo),1); //Set private data to use object to allow locking in static objects screen->screenData = (void*)&use; //Set default vaules screen->autoPort=FALSE; screen->clientHead=NULL; screen->pointerClient=NULL; screen->port=5900; screen->ipv6port=5900; screen->socketState=RFB_SOCKET_INIT; screen->inetdInitDone = FALSE; screen->inetdSock=-1; screen->udpSock=-1; screen->udpSockConnected=FALSE; screen->udpPort=0; screen->udpClient=NULL; screen->maxFd=0; screen->listenSock=-1; screen->listen6Sock=-1; screen->httpInitDone=FALSE; screen->httpEnableProxyConnect=FALSE; screen->httpPort=0; screen->http6Port=0; screen->httpDir=NULL; screen->httpListenSock=-1; screen->httpListen6Sock=-1; screen->httpSock=-1; screen->desktopName = "MCU"; screen->alwaysShared = TRUE; screen->neverShared = FALSE; screen->dontDisconnect = TRUE; screen->authPasswdData = NULL; screen->authPasswdFirstViewOnly = 1; screen->width = width; screen->height = height; screen->bitsPerPixel = screen->depth = 8*bytesPerPixel; screen->paddedWidthInBytes = width*bytesPerPixel; //Allocate memory for max usage screen->frameBuffer = (char*) malloc32(width*height*4); screen->passwordCheck = rfbDefaultPasswordCheck; screen->ignoreSIGPIPE = TRUE; /* disable progressive updating per default */ screen->progressiveSliceHeight = 0; screen->listenInterface = htonl(INADDR_ANY); screen->deferUpdateTime=0; screen->maxRectsPerUpdate=50; screen->handleEventsEagerly = FALSE; screen->protocolMajorVersion = rfbProtocolMajorVersion; screen->protocolMinorVersion = rfbProtocolMinorVersion; screen->permitFileTransfer = FALSE; screen->paddedWidthInBytes = width*bytesPerPixel; /* format */ rfbInitServerFormat(screen, bitsPerSample); /* cursor */ screen->cursorX=screen->cursorY=screen->underCursorBufferLen=0; screen->underCursorBuffer=NULL; screen->dontConvertRichCursorToXCursor = FALSE; screen->cursor = &myCursor; INIT_MUTEX(screen->cursorMutex); IF_PTHREADS(screen->backgroundLoop = FALSE); /* proc's and hook's */ screen->kbdAddEvent = onKeyboardEvent; screen->kbdReleaseAllKeys = rfbDoNothingWithClient; screen->ptrAddEvent = onMouseEvent; screen->setXCutText = rfbDefaultSetXCutText; screen->getCursorPtr = rfbDefaultGetCursorPtr; screen->setTranslateFunction = rfbSetTranslateFunction; screen->newClientHook = NULL; screen->displayHook = onDisplay; screen->displayFinishedHook = onDisplayFinished; screen->getKeyboardLedStateHook = NULL; screen->xvpHook = NULL; /* initialize client list and iterator mutex */ rfbClientListInit(screen); }
int Logo::Load(const char* fileName) { AVFormatContext *fctx = NULL; AVCodecContext *ctx = NULL; AVCodec *codec = NULL; AVFrame *logoRGB = NULL; AVFrame* logo = NULL; SwsContext *sws = NULL; AVPacket packet; int res = 0; int gotLogo = 0; int numpixels = 0; int size = 0; //Create context from file if(avformat_open_input(&fctx, fileName, NULL, NULL)<0) return Error("Couldn't open the logo image file [%s]\n",fileName); //Check it's ok if(avformat_find_stream_info(fctx,NULL)<0) { //Set error res = Error("Couldn't find stream information for the logo image file...\n"); //Free resources goto end; } //Get codec from file fromat if (!(ctx = fctx->streams[0]->codec)) { //Set errror res = Error("Context codec not valid\n"); //Free resources goto end; } //Get decoder for format if (!(codec = avcodec_find_decoder(ctx->codec_id))) { //Set errror res = Error("Couldn't find codec for the logo image file...\n"); //Free resources goto end; } //Only one thread ctx->thread_count = 1; //Open codec if (avcodec_open2(ctx, codec, NULL)<0) { //Set errror res = Error("Couldn't open codec for the logo image file...\n"); //Free resources goto end; } //Read logo frame if (av_read_frame(fctx, &packet)<0) { //Set errror res = Error("Couldn't read frame from the image file...\n"); //Free resources goto end; } //Alloc frame if (!(logoRGB = av_frame_alloc())) { //Set errror res = Error("Couldn't alloc frame\n"); //Free resources goto end; } //Use only one thread to avoid decoding on background and logo not displayed ctx->thread_count = 1; //Decode logo if (avcodec_decode_video2(ctx, logoRGB, &gotLogo, &packet)<0) { //Set errror res = Error("Couldn't decode logo\n"); //Free resources av_free_packet(&packet); goto end; } av_free_packet(&packet); //If it we don't have a logo if (!gotLogo) { //Set errror res = Error("No logo on file\n"); //Free resources goto end; } //Allocate new one if (!(logo = av_frame_alloc())) { //Set errror res = Error("Couldn't alloc frame\n"); //Free resources goto end; } //Get frame sizes width = ctx->width; height = ctx->height; // Create YUV rescaller cotext if (!(sws = sws_alloc_context())) { //Set errror res = Error("Couldn't alloc sws context\n"); // Exit goto end; } // Set property's of YUV rescaller context av_opt_set_defaults(sws); av_opt_set_int(sws, "srcw", width ,AV_OPT_SEARCH_CHILDREN); av_opt_set_int(sws, "srch", height ,AV_OPT_SEARCH_CHILDREN); av_opt_set_int(sws, "src_format", ctx->pix_fmt ,AV_OPT_SEARCH_CHILDREN); av_opt_set_int(sws, "dstw", width ,AV_OPT_SEARCH_CHILDREN); av_opt_set_int(sws, "dsth", height ,AV_OPT_SEARCH_CHILDREN); av_opt_set_int(sws, "dst_format", AV_PIX_FMT_YUV420P ,AV_OPT_SEARCH_CHILDREN); av_opt_set_int(sws, "sws_flags", SWS_FAST_BILINEAR ,AV_OPT_SEARCH_CHILDREN); // Init YUV rescaller context if (sws_init_context(sws, NULL, NULL) < 0) { //Set errror res = Error("Couldn't init sws context\n"); // Exit goto end; } //Check if we already had one if (frame) //Free memory free(frame); //Check if we already had one if (frameRGBA) //Free memory free(frameRGBA); //Get size with padding size = (((width/32+1)*32)*((height/32+1)*32)*3)/2+FF_INPUT_BUFFER_PADDING_SIZE+32; //And numer of pixels numpixels = width*height; //Allocate frame frame = (BYTE*)malloc32(size); /* size for YUV 420 */ frameRGBA = (BYTE*)malloc32(numpixels*4); //Alloc data logo->data[0] = frame; logo->data[1] = logo->data[0] + numpixels; logo->data[2] = logo->data[1] + numpixels / 4; //Set size for planes logo->linesize[0] = width; logo->linesize[1] = width/2; logo->linesize[2] = width/2; //Convert sws_scale(sws, logoRGB->data, logoRGB->linesize, 0, height, logo->data, logo->linesize); //Copy logo from rgbA to rgb for (int j=0;j<height;j++) for (int i=0;i<width;i++) //Copy line by line memcpy(frameRGBA+(width*j+i)*4,logoRGB->data[0]+logoRGB->linesize[0]*j+i*3,3); //Everything was ok res = 1; end: if (logo) av_free(logo); if (logoRGB) av_free(logoRGB); if (ctx) avcodec_close(ctx); if (sws) sws_freeContext(sws); if (fctx) avformat_close_input(&fctx); //Exit return res; }