void on_connect (uv_stream_t* server_handle, int status) { CHECK (status, "connect"); int r; assert ( (uv_tcp_t*) server_handle == &server); client_t* client = malloc (sizeof (client_t) ); client->request_num = request_num; LOGF ("[ %5d ] new connection", request_num++); uv_tcp_init (uv_loop, &client->handle); http_parser_init (&client->parser, HTTP_REQUEST); client->parser.data = client; client->handle.data = client; r = uv_accept (server_handle, (uv_stream_t*) &client->handle); CHECK (r, "accept"); uv_read_start ( (uv_stream_t*) &client->handle, on_alloc, on_read); }
/* Called for IOCTL_VIDEO_MAP_VIDEO_MEMORY. * Maps FrameBuffer and video RAM to a caller's virtual adress space. */ BOOLEAN VBoxMPMapVideoMemory(PVBOXMP_DEVEXT pExt, PVIDEO_MEMORY pRequestedAddress, PVIDEO_MEMORY_INFORMATION pMapInfo, PSTATUS_BLOCK pStatus) { PHYSICAL_ADDRESS framebuffer; ULONG inIoSpace = 0; LOGF(("framebuffer offset %#x", pExt->ulFrameBufferOffset)); framebuffer.QuadPart = VBoxCommonFromDeviceExt(pExt)->phVRAM.QuadPart + pExt->ulFrameBufferOffset; pMapInfo->VideoRamBase = pRequestedAddress->RequestedVirtualAddress; VBOXMPIOCTL_HIDE(pRequestedAddress); pMapInfo->VideoRamLength = pExt->pPrimary->u.primary.ulMaxFrameBufferSize; pStatus->Status = VideoPortMapMemory(pExt, framebuffer, &pMapInfo->VideoRamLength, &inIoSpace, &pMapInfo->VideoRamBase); if (NO_ERROR == pStatus->Status) { pMapInfo->FrameBufferBase = (PUCHAR)pMapInfo->VideoRamBase; pMapInfo->FrameBufferLength = VBoxMPXpdmCurrentVideoMode(pExt)->VisScreenHeight* VBoxMPXpdmCurrentVideoMode(pExt)->ScreenStride; pStatus->Information = sizeof(VIDEO_MEMORY_INFORMATION); /* Save the new framebuffer size */ pExt->ulFrameBufferSize = pMapInfo->FrameBufferLength; HGSMIAreaInitialize(&pExt->areaDisplay, pMapInfo->FrameBufferBase, pMapInfo->FrameBufferLength, pExt->ulFrameBufferOffset); } VBOXMPIOCTL_UNHIDE(); LOGF_LEAVE(); return NO_ERROR == pStatus->Status; }
static void repeat_1_cb(uv_timer_t* handle, int status) { int r; ASSERT(handle == &repeat_1); ASSERT(status == 0); ASSERT(uv_timer_get_repeat((uv_timer_t*)handle) == 50); LOGF("repeat_1_cb called after %ld ms\n", (long int)(uv_now(uv_default_loop()) - start_time)); repeat_1_cb_called++; r = uv_timer_again(&repeat_2); ASSERT(r == 0); if (uv_now(uv_default_loop()) >= start_time + 500) { uv_close((uv_handle_t*)handle, close_cb); /* We're not calling uv_timer_again on repeat_2 any more, so after this */ /* timer_2_cb is expected. */ repeat_2_cb_allowed = 1; return; } }
void test_peer_does_not_have (void *context, void *peer_context, void *key_context, const sync_key_t *key){ struct test_peer *state = (struct test_peer *)context; struct test_peer *peer = (struct test_peer *)peer_context; struct test_key *test_key = (struct test_key *)key_context; LOGF("%s - %s does not have %s that we need to send", state->name, peer->name, alloca_sync_key(key)); assert(sync_key_exists(state->state, key)==1); assert(sync_key_exists(peer->state, key)==0); assert(test_key->initial_peer); struct test_transfer *transfer = allocate(sizeof(struct test_transfer)); transfer->src = state; transfer->dest = peer; transfer->key = test_key; transfer->delay_till = packets_sent + 10; if (transfer_tail){ transfer_tail->next = transfer; }else{ transfer_head = transfer; } transfer_tail = transfer; }
/* Ugly tokenizer :3 */ char *token() { char c; c = getchar(); while ((c != EOF) && (strchr(skip_chars, c) != NULL)) { c = getchar(); if (c == '#') { while ((c != EOF) && (c != '\n')) c = getchar(); LOGF("skip comment to EOL"); } } if (c == EOF) return NULL; char buf[256], *cur = buf; while ((c != EOF) && (strchr(skip_chars, c) == NULL)) { *(cur++) = c; c = getchar(); } *cur = 0; //LOGF("token=%s", buf); // you should care about freeing memory :3 return strdup(buf); }
static spx_int64_t seek_backwards(spx_ogg_sync_state *oy, spx_ogg_page *og, spx_int64_t wantedpos) { spx_int64_t crofs; spx_int64_t *curoffset=&crofs; *curoffset=ci->curpos; spx_int64_t begin=*curoffset; spx_int64_t end=begin; spx_int64_t ret; spx_int64_t offset=-1; spx_int64_t avgpagelen=-1; spx_int64_t lastgranule=-1; short time = -1; while (offset == -1) { begin -= SEEK_CHUNKSIZE; if (begin < 0) { if (time < 0) { begin = 0; time++; } else { LOGF("Can't seek that early:%lld\n",begin); return -3; /* too early */ } } *curoffset = begin; ci->seek_buffer(*curoffset); spx_ogg_sync_reset(oy); lastgranule = -1; while (*curoffset < end) { ret = get_next_page(oy,og,end-*curoffset); if (ret > 0) { if (lastgranule != -1) { if (avgpagelen < 0) avgpagelen = (spx_ogg_page_granulepos(og)-lastgranule); else avgpagelen=((spx_ogg_page_granulepos(og)-lastgranule) + avgpagelen) / 2; } lastgranule=spx_ogg_page_granulepos(og); if ((lastgranule - (avgpagelen/4)) < wantedpos && (lastgranule + avgpagelen + (avgpagelen/4)) > wantedpos) { /*wanted offset found Yeay!*/ /*LOGF("GnPagefound:%d,%d,%d,%d\n",ret, lastgranule,wantedpos,avgpagelen);*/ return ret; } else if (lastgranule > wantedpos) { /*too late, seek more*/ if (offset != -1) { LOGF("Toolate, returnanyway:%lld,%lld,%lld,%lld\n", ret,lastgranule,wantedpos,avgpagelen); return ret; } break; } else{ /*if (spx_ogg_page_granulepos(&og)<wantedpos)*/ /*too early*/ offset = ret; continue; } } else if (ret == -3) return(-3); else if (ret<=0) break; else if (*curoffset < end) { /*this should not be possible*/ //LOGF("Seek:get_earlier_page:Offset:not_cached by granule:"\"%d,%d,%d,%d,%d\n",*curoffset,end,begin,wantedpos,curpos); offset=ret; } } } return -1; }
static int speex_seek_page_granule(spx_int64_t pos, spx_int64_t curpos, spx_ogg_sync_state *oy, spx_int64_t headerssize) { /* TODO: Someone may want to try to implement seek to packet, instead of just to page (should be more accurate, not be any faster) */ spx_int64_t crofs; spx_int64_t *curbyteoffset = &crofs; *curbyteoffset = ci->curpos; spx_int64_t curoffset; curoffset = *curbyteoffset; spx_int64_t offset = 0; spx_ogg_page og = {0,0,0,0}; spx_int64_t avgpagelen = -1; spx_int64_t lastgranule = -1; if(abs(pos-curpos)>10000 && headerssize>0 && curoffset-headerssize>10000) { /* if seeking for more that 10sec, headersize is known & more than 10kb is played, try to guess a place to seek from the number of bytes playe for this position, this works best when the bitrate is relativly constant. */ curoffset = (((*curbyteoffset-headerssize) * pos)/curpos)*98/100; if (curoffset < 0) curoffset=0; //spx_int64_t toffset=curoffset; ci->seek_buffer(curoffset); spx_ogg_sync_reset(oy); offset = get_next_page(oy,&og,-1); if (offset < 0) { /* could not find new page,use old offset */ LOGF("Seek/guess/fault:%lld->-<-%d,%lld:%lld,%d,%ld,%d\n", curpos,0,pos,offset,0, ci->curpos,/*stream_length*/0); curoffset = *curbyteoffset; ci->seek_buffer(curoffset); spx_ogg_sync_reset(oy); } else { if (spx_ogg_page_granulepos(&og) == 0 && pos > 5000) { LOGF("SEEK/guess/fault:%lld->-<-%lld,%lld:%lld,%d,%ld,%d\n", curpos,spx_ogg_page_granulepos(&og),pos, offset,0,ci->curpos,/*stream_length*/0); curoffset = *curbyteoffset; ci->seek_buffer(curoffset); spx_ogg_sync_reset(oy); } else { curoffset = offset; curpos = spx_ogg_page_granulepos(&og); } } } /* which way do we want to seek? */ if (curpos > pos) { /* backwards */ offset = seek_backwards(oy,&og,pos); if (offset > 0) { *curbyteoffset = curoffset; return 1; } } else { /* forwards */ while ( (offset = get_next_page(oy,&og,-1)) > 0) { if (lastgranule != -1) { if (avgpagelen < 0) avgpagelen = (spx_ogg_page_granulepos(&og) - lastgranule); else avgpagelen = ((spx_ogg_page_granulepos(&og) - lastgranule) + avgpagelen) / 2; } lastgranule = spx_ogg_page_granulepos(&og); if ( ((lastgranule - (avgpagelen/4)) < pos && ( lastgranule + avgpagelen + (avgpagelen / 4)) > pos) || lastgranule > pos) { /*wanted offset found Yeay!*/ *curbyteoffset = offset; return offset; } } } ci->seek_buffer(*curbyteoffset); spx_ogg_sync_reset(oy); LOGF("Seek failed:%lld\n", offset); return -1; }
//------------------------------------------------------------------------ void TcpServer::listen() { if (espconn_accept(_conn) != ESPCONN_OK) { LOGF("ERR : espconn_accept"); } espconn_regist_connectcb(_conn, connectCb); }
struct worker * worker_start(EV_P_ struct session *session) { struct worker *w; pid_t pid; int stdin_fds [2] = {-1, -1}; int stdout_fds[2] = {-1, -1}; int stderr_fds[2] = {-1, -1}; int msgin_fds [2] = {-1, -1}; int msgout_fds[2] = {-1, -1}; #if WORKER_TIMINGS uint64_t _start = now_us(); #endif if ((w = calloc(1, sizeof(*w))) == NULL) { goto fail; } w->session = session; writeq_init(&w->stdin_writeq); writeq_init(&w->msgin_writeq); if (pipe(stdin_fds ) < 0 || pipe(stdout_fds) < 0 || pipe(stderr_fds) < 0 || pipe(msgin_fds ) < 0 || pipe(msgout_fds) < 0) { LOG_ERRNO("pipe()"); goto fail; } maxfd_update(stdin_fds [0]); maxfd_update(stdin_fds [1]); maxfd_update(stdout_fds[0]); maxfd_update(stdout_fds[1]); maxfd_update(stderr_fds[0]); maxfd_update(stderr_fds[1]); maxfd_update(msgin_fds [0]); maxfd_update(msgin_fds [1]); maxfd_update(msgout_fds[0]); maxfd_update(msgout_fds[1]); pid = fork(); if (pid < 0) { LOG_ERRNO("fork()"); goto fail; } if (pid == 0) { /* child. */ if (dup2(stdin_fds [0], 0) < 0 || dup2(stdout_fds[1], 1) < 0 || dup2(stderr_fds[1], 2) < 0 || dup2(msgin_fds [0], 3) < 0 || dup2(msgout_fds[1], 4) < 0) { exit(EXIT_FAILURE); } maxfd_closeall(5); pyenv_child_after_fork(); exit(EXIT_SUCCESS); } else { /* parent. */ close(stdin_fds [0]); close(stdout_fds[1]); close(stderr_fds[1]); close(msgin_fds [0]); close(msgout_fds[1]); set_fd_nonblocking(stdin_fds [1]); set_fd_nonblocking(stdout_fds[0]); set_fd_nonblocking(stderr_fds[0]); set_fd_nonblocking(msgin_fds [1]); set_fd_nonblocking(msgout_fds[0]); ev_child_init(&w->child_watcher, worker_exited_cb, pid, 0); ev_child_start(EV_A_ &w->child_watcher); ev_io_init(&w->stdin_w , worker_write_stdin_cb, stdin_fds [1], EV_WRITE); ev_io_init(&w->stdout_w, worker_read_stdout_cb, stdout_fds[0], EV_READ); ev_io_init(&w->stderr_w, worker_read_stderr_cb, stderr_fds[0], EV_READ); ev_io_init(&w->msgin_w , worker_write_msgin_cb, msgin_fds [1], EV_WRITE); ev_io_init(&w->msgout_w, worker_read_msgout_cb, msgout_fds[0], EV_READ); ev_io_start(EV_A_ &w->stdout_w); ev_io_start(EV_A_ &w->stderr_w); ev_io_start(EV_A_ &w->msgout_w); LOGF(3, "=== %d: worker started, fds=[%d, %d, %d, %d, %d]\n", worker_pid(w), stdin_fds[1], stdout_fds[0], stderr_fds[0], msgin_fds[1], msgout_fds[0]); w->f_alive = true; } #if WORKER_TIMINGS worker_start_time += now_us() - _start; worker_start_calls++; #endif return w; fail: close(stdin_fds [0]); close(stdin_fds [1]); close(stdout_fds[0]); close(stdout_fds[1]); close(stderr_fds[0]); close(stderr_fds[1]); close(msgin_fds [0]); close(msgin_fds [1]); close(msgout_fds[0]); close(msgout_fds[1]); free(w); return NULL; }
/*! ** @brief Get the full DAG of the local socket. ** ** @param sockfd An Xsocket of type SOCK_STREAM ** @param dag A sockaddr to hold the returned DAG. ** @param len On input contans the size of the sockaddr, ** on output contains sizeof(sockaddr_x). ** ** @returns 0 on success ** @returns -1 on failure with errno set ** @returns errno = EFAULT if dag is NULL ** @returns errno = EOPNOTSUPP if sockfd is not of type XSSOCK_STREAM ** @returns errno = ENOTCONN if sockfd is not in a connected state ** */ int Xgetsockname(int sockfd, struct sockaddr *addr, socklen_t *addrlen) { int rc; int flags; char buf[MAXBUFLEN]; if (!addr || !addrlen) { LOG("pointer is null!\n"); errno = EFAULT; return -1; } if (*addrlen < sizeof(sockaddr_x)) { errno = EINVAL; return -1; } if (validateSocket(sockfd, XSOCK_STREAM, EOPNOTSUPP) < 0) { LOG("Xgetsockname is only valid with stream sockets."); return -1; } if (connState(sockfd) != CONNECTED) { LOGF("Socket %d is not connected", sockfd); errno = ENOTCONN; return -1; } xia::XSocketMsg xsm; xsm.set_type(xia::XGETSOCKNAME); flags = Xfcntl(sockfd, F_GETFL); fcntl(sockfd, F_SETFL, flags & ~O_NONBLOCK); // send the protobuf containing the user data to click if ((rc = click_send(sockfd, &xsm)) < 0) { LOGF("Error talking to Click: %s", strerror(errno)); fcntl(sockfd, F_SETFL, flags); return -1; } // get the dag // FIXME: loop here till done or error if ((rc = click_reply(sockfd, xia::XGETSOCKNAME, buf, sizeof(buf))) < 0) { LOGF("Error retrieving status from Click: %s", strerror(errno)); fcntl(sockfd, F_SETFL, flags); return -1; } fcntl(sockfd, F_SETFL, flags); xsm.Clear(); xsm.ParseFromString(buf); if (xsm.type() != xia::XGETSOCKNAME) { LOGF("error: expected %d, got %d\n", xia::XGETPEERNAME, xsm.type()); return -1; } xia::X_GetSockname_Msg *msg = xsm.mutable_x_getsockname(); Graph g(msg->dag().c_str()); g.fill_sockaddr((sockaddr_x*)addr); *addrlen = sizeof(sockaddr_x); return 0; }
void vrdpDrvStrokePath(SURFOBJ *pso, PATHOBJ *ppo, CLIPOBJ *pco, XFORMOBJ *pxo, BRUSHOBJ *pbo, POINTL *pptlBrushOrg, LINEATTRS *plineattrs, MIX mix) { PVBOXDISPDEV pDev = (PVBOXDISPDEV)pso->dhpdev; /* * StrokePath operation is supported by RDP_ORDER_POLYGON/POLYLINE/ELLIPSE. */ VRDPCLIPRECTS clipRects; int clipResult; RECTFX rcfxBounds; RECTL rclBoundsOrdered; LOGF(("pso = %p, ppo = %p, pco = %p, pxo = %p, pbo = %p, pptlBrushOrg = %p, plineattrs = %p, mix = 0x%08X", pso, ppo, pco, pxo, pbo, pptlBrushOrg, plineattrs, mix)); LOGF(("ppo: fl = 0x%08X, cCurves = %d", ppo->fl, ppo->cCurves)); PATHOBJ_vGetBounds(ppo, &rcfxBounds); rclBoundsOrdered.left = FXTOLFLOOR(rcfxBounds.xLeft); rclBoundsOrdered.right = FXTOLCEILING(rcfxBounds.xRight); rclBoundsOrdered.top = FXTOLFLOOR(rcfxBounds.yTop); rclBoundsOrdered.bottom = FXTOLCEILING(rcfxBounds.yBottom); vrdpOrderRect(&rclBoundsOrdered); LOG(("ppo: bounds %x-%x, %x-%x, %d-%d %d-%d", rcfxBounds.xLeft, rcfxBounds.xRight, rcfxBounds.yTop, rcfxBounds.yBottom, rclBoundsOrdered.left, rclBoundsOrdered.right, rclBoundsOrdered.top, rclBoundsOrdered.bottom)); clipResult = vrdpGetIntersectingClipRects(&clipRects, pso, &rclBoundsOrdered, pco, NULL); if (clipResult == VRDP_CLIP_NO_INTERSECTION) { /* Do nothing. The operation does not affect anything. */ LOG(("VRDP_CLIP_NO_INTERSECTION!!!")); dumpPCO (&rclBoundsOrdered, pco); } else if (clipResult == VRDP_CLIP_TOO_MANY_RECTS) { /* A very complex clip. Better to emulate it. */ LOG(("VRDP_CLIP_TOO_MANY_RECTS!!!")); dumpPCO (&rclBoundsOrdered, pco); vrdpReportDirtyRects(pDev, &clipRects); } else if (pbo->iSolidColor == 0xFFFFFFFF) { /* Not solid brushes are not supported. */ vrdpReportDirtyRects(pDev, &clipRects); } else if (ppo->fl & PO_ELLIPSE) { if (VBoxVBVAOrderSupported(&pDev->vbvaCtx, VRDE_ORDER_ELLIPSE)) { VRDEORDERELLIPSE order; order.pt1.x = (int16_t)FXTOLROUND(rcfxBounds.xLeft + 4); order.pt1.y = (int16_t)FXTOLROUND(rcfxBounds.yTop + 4); order.pt2.x = (int16_t)FXTOLROUND(rcfxBounds.xRight - 4); order.pt2.y = (int16_t)FXTOLROUND(rcfxBounds.yBottom - 4); order.mix = (uint8_t)(mix & 0x1F); order.fillMode = 0; order.rgb = vrdpColor2RGB(pso, pbo->iSolidColor); vrdpReportOrderGeneric(pDev, &clipRects, &order, sizeof (order), VRDE_ORDER_ELLIPSE); } else { WARN(("ELLIPSE not supported")); vrdpReportDirtyRects (pDev, &clipRects); } } else if ( (ppo->fl & PO_BEZIERS) == 0 && (plineattrs->fl & LA_GEOMETRIC) == 0 && plineattrs->pstyle == NULL) { unsigned i; PATHDATA pd; BOOL bMore; VRDEORDERPOLYLINE order; VRDEORDERPOINT ptStart; VRDEORDERBOUNDS bounds; order.rgb = vrdpColor2RGB(pso, pbo->iSolidColor); order.mix = (uint8_t)(mix & 0x1F); PATHOBJ_vEnumStart(ppo); order.points.c = 0; do { POINTFIX *pptfx; VRDEORDERPOINT pt; bMore = PATHOBJ_bEnum (ppo, &pd); LOG(("pd: flags = 0x%08X, count = %d", pd.flags, pd.count)); pptfx = &pd.pptfx[0]; if (pd.flags & PD_BEGINSUBPATH) { /* Setup first point. Start a new order. */ LOG(("BEGINSUBPATH")); Assert(order.points.c == 0); vrdpPointFX2Point(pptfx, &ptStart); order.ptStart = ptStart; pt = ptStart; bounds.pt1 = bounds.pt2 = ptStart; pptfx++; i = 1; } else { LOG(("Continue order")); i = 0; } for (; i < pd.count; i++, pptfx++) { LOG(("pd: %2d: %x,%x %d,%d", i, pptfx->x, pptfx->y, FXTOLROUND(pptfx->x), FXTOLROUND(pptfx->y))); vrdpPointFX2Point (pptfx, &pt); vrdpPolyPointsAdd (&order.points, &pt); vrdpExtendOrderBounds (&bounds, &pt); if (order.points.c == RT_ELEMENTS(order.points.a)) { /* Flush the order and start a new order. */ LOG(("Report order, points overflow.")); vrdpReportOrderGenericBounds(pDev, &clipRects, &bounds, &order, sizeof (order), VRDE_ORDER_POLYLINE); order.points.c = 0; order.ptStart = pt; bounds.pt1 = bounds.pt2 = pt; } } if (pd.flags & PD_CLOSEFIGURE) { /* Encode the start point as the end point. */ LOG(("Report order, CLOSEFIGURE")); if ( ptStart.x != pt.x || ptStart.y != pt.y) { Assert(order.points.c < RT_ELEMENTS(order.points.a)); vrdpPolyPointsAdd (&order.points, &ptStart); vrdpExtendOrderBounds (&bounds, &ptStart); } } if (pd.flags & PD_ENDSUBPATH) { /* Finish the order. */ LOG(("Report order, ENDSUBPATH")); if (order.points.c > 0) { vrdpReportOrderGenericBounds(pDev, &clipRects, &bounds, &order, sizeof (order), VRDE_ORDER_POLYLINE); } order.points.c = 0; } } while (bMore); } else { /* Not supported. */ WARN(("not supported: ppo->fl = %08X, plineattrs->fl = %08X, plineattrs->pstyle = %08X", ppo->fl, plineattrs->fl, plineattrs->pstyle)); vrdpReportDirtyRects(pDev, &clipRects); } return; }
static BOOL ssbCopy(SSB *pSSB, SURFOBJ *pso, RECTL *prcl, BOOL bToScreen) { BYTE *pSrc; BYTE *pDst; LONG lDeltaSrc; LONG lDeltaDst; ULONG cWidth; ULONG cHeight; int cbPixel = format2BytesPerPixel(pso); LOGF(("pSSB = %p, pso = %p, prcl = %p, bToScreen = %d", pSSB, pso, prcl, bToScreen)); if (cbPixel == 0) { WARN(("unsupported pixel format!!!")); return FALSE; } cWidth = prcl->right - prcl->left; cHeight = prcl->bottom - prcl->top; if (bToScreen) { if (pSSB->pBuffer == NULL) { WARN(("source buffer is NULL!!!")); return FALSE; } pSrc = pSSB->pBuffer; lDeltaSrc = cWidth * cbPixel; pDst = (BYTE *)pso->pvScan0 + pso->lDelta * prcl->top + cbPixel * prcl->left; lDeltaDst = pso->lDelta; } else { if (pSSB->pBuffer != NULL) { WARN(("source buffer is not NULL!!!")); return FALSE; } pSSB->pBuffer = (BYTE *)EngAllocMem (0, cWidth * cHeight * cbPixel, MEM_ALLOC_TAG); if (pSSB->pBuffer == NULL) { WARN(("Failed to allocate buffer!!!")); return FALSE; } pDst = pSSB->pBuffer; lDeltaDst = cWidth * cbPixel; pSrc = (BYTE *)pso->pvScan0 + pso->lDelta * prcl->top + cbPixel * prcl->left; lDeltaSrc = pso->lDelta; } LOG(("cHeight = %d, pDst = %p, pSrc = %p, lDeltaSrc = %d, lDeltaDst = %d", cHeight, pDst, pSrc, lDeltaSrc, lDeltaDst)); while (cHeight--) { memcpy (pDst, pSrc, cWidth * cbPixel); pDst += lDeltaDst; pSrc += lDeltaSrc; } LOGF(("completed.")); return TRUE; }
/* this is called for each file to process */ enum codec_status codec_run(void) { size_t n; demux_res_t demux_res; stream_t input_stream; uint32_t samplesdone; uint32_t elapsedtime = 0; int samplesdecoded; unsigned int i; unsigned char* buffer; alac_file alac; intptr_t param; /* Clean and initialize decoder structures */ memset(&demux_res , 0, sizeof(demux_res)); if (codec_init()) { LOGF("ALAC: Error initialising codec\n"); return CODEC_ERROR; } ci->configure(DSP_SET_FREQUENCY, ci->id3->frequency); codec_set_replaygain(ci->id3); ci->seek_buffer(0); stream_create(&input_stream,ci); /* Read from ci->id3->offset before calling qtmovie_read. */ samplesdone = (uint32_t)(((uint64_t)(ci->id3->offset) * ci->id3->frequency) / (ci->id3->bitrate*128)); /* if qtmovie_read returns successfully, the stream is up to * the movie data, which can be used directly by the decoder */ if (!qtmovie_read(&input_stream, &demux_res)) { LOGF("ALAC: Error initialising file\n"); return CODEC_ERROR; } /* initialise the sound converter */ alac_set_info(&alac, demux_res.codecdata); /* Set i for first frame, seek to desired sample position for resuming. */ i=0; if (samplesdone > 0) { if (m4a_seek(&demux_res, &input_stream, samplesdone, &samplesdone, (int*) &i)) { elapsedtime = (samplesdone * 10) / (ci->id3->frequency / 100); ci->set_elapsed(elapsedtime); } else { samplesdone = 0; } } ci->set_elapsed(elapsedtime); /* The main decoding loop */ while (i < demux_res.num_sample_byte_sizes) { enum codec_command_action action = ci->get_command(¶m); if (action == CODEC_ACTION_HALT) break; /* Request the required number of bytes from the input buffer */ buffer=ci->request_buffer(&n, ALAC_BYTE_BUFFER_SIZE); /* Deal with any pending seek requests */ if (action == CODEC_ACTION_SEEK_TIME) { if (m4a_seek(&demux_res, &input_stream, (param/10) * (ci->id3->frequency/100), &samplesdone, (int *)&i)) { elapsedtime=(samplesdone*10)/(ci->id3->frequency/100); } ci->set_elapsed(elapsedtime); ci->seek_complete(); } /* Request the required number of bytes from the input buffer */ buffer=ci->request_buffer(&n, ALAC_BYTE_BUFFER_SIZE); /* Decode one block - returned samples will be host-endian */ samplesdecoded=alac_decode_frame(&alac, buffer, outputbuffer, ci->yield); ci->yield(); /* Advance codec buffer by amount of consumed bytes */ ci->advance_buffer(alac.bytes_consumed); /* Output the audio */ ci->pcmbuf_insert(outputbuffer[0], outputbuffer[1], samplesdecoded); /* Update the elapsed-time indicator */ samplesdone+=samplesdecoded; elapsedtime=(samplesdone*10)/(ci->id3->frequency/100); ci->set_elapsed(elapsedtime); i++; } LOGF("ALAC: Decoded %lu samples\n",(unsigned long)samplesdone); return CODEC_OK; }
ULONG APIENTRY VBoxDispDrvEscape(SURFOBJ *pso, ULONG iEsc, ULONG cjIn, PVOID pvIn, ULONG cjOut, PVOID pvOut) { PVBOXDISPDEV pDev = (PVBOXDISPDEV)pso->dhpdev; LOGF_ENTER(); switch (iEsc) { #ifdef VBOX_WITH_CROGL case OPENGL_GETINFO: { if (pvOut && cjOut >= sizeof(OPENGL_INFO)) { POPENGL_INFO pInfo = (POPENGL_INFO)pvOut; pInfo->dwVersion = 2; pInfo->dwDriverVersion = 1; pInfo->szDriverName[0] = 'V'; pInfo->szDriverName[1] = 'B'; pInfo->szDriverName[2] = 'o'; pInfo->szDriverName[3] = 'x'; pInfo->szDriverName[4] = 'O'; pInfo->szDriverName[5] = 'G'; pInfo->szDriverName[6] = 'L'; pInfo->szDriverName[7] = 0; LOG(("OPENGL_GETINFO ok")); return cjOut; } else { WARN(("OPENGL_GETINFO invalid parms")); return 0; } } case QUERYESCSUPPORT: { if (pvIn && cjIn == sizeof(DWORD)) { DWORD nEscapeQuery = *(DWORD *)pvIn; if (nEscapeQuery==OPENGL_GETINFO) { LOG(("QUERYESCSUPPORT OPENGL_GETINFO")); return 1; } else { LOG(("QUERYESCSUPPORT unsupported query %d", nEscapeQuery)); return 0; } } else { WARN(("QUERYESCSUPPORT invalid parms")); return 0; } } #endif case VBOXESC_ISVRDPACTIVE: { if (pDev && pDev->vbvaCtx.pVBVA && pDev->vbvaCtx.pVBVA->hostFlags.u32HostEvents&VBVA_F_MODE_VRDP) { LOGF(("VBOXESC_ISVRDPACTIVE: 1")); return 1; } LOGF(("VBOXESC_ISVRDPACTIVE: 0")); return 0; } case VBOXESC_SETVISIBLEREGION: { LOGF(("VBOXESC_SETVISIBLEREGION")); LPRGNDATA lpRgnData = (LPRGNDATA)pvIn; DWORD cRects; if ( cjIn >= sizeof(RGNDATAHEADER) && pvIn && lpRgnData->rdh.dwSize == sizeof(RGNDATAHEADER) && lpRgnData->rdh.iType == RDH_RECTANGLES && (cRects = lpRgnData->rdh.nCount) <= _1M && cjIn == cRects * (uint64_t)sizeof(RECT) + sizeof(RGNDATAHEADER)) { /** @todo this whole conversion thing could maybe be skipped * since RTRECT matches the RECT layout. */ #if 0 AssertCompile(sizeof(RTRECT) == sizeof(RECT)); AssertCompileMembersSameSizeAndOffset(RTRECT, xLeft, RECT, left); AssertCompileMembersSameSizeAndOffset(RTRECT, xBottom, RECT, bottom); AssertCompileMembersSameSizeAndOffset(RTRECT, xRight, RECT, right); AssertCompileMembersSameSizeAndOffset(RTRECT, xTop, RECT, top); rc = VBoxDispMPSetVisibleRegion(pDev->hDriver, (PRTRECT)&lpRgnData->Buffer[0], cRects); VBOX_WARNRC(rc); #else DWORD i; PRTRECT pRTRect; int rc; RECT *pRect = (RECT *)&lpRgnData->Buffer; pRTRect = (PRTRECT) EngAllocMem(0, cRects*sizeof(RTRECT), MEM_ALLOC_TAG); if (!pRTRect) { WARN(("failed to allocate %d bytes", cRects*sizeof(RTRECT))); break; } for (i = 0; i < cRects; ++i) { LOG(("New visible rectangle (%d,%d) (%d,%d)", pRect[i].left, pRect[i].bottom, pRect[i].right, pRect[i].top)); pRTRect[i].xLeft = pRect[i].left; pRTRect[i].yBottom = pRect[i].bottom; pRTRect[i].xRight = pRect[i].right; pRTRect[i].yTop = pRect[i].top; } rc = VBoxDispMPSetVisibleRegion(pDev->hDriver, pRTRect, cRects); VBOX_WARNRC(rc); EngFreeMem(pRTRect); #endif if (RT_SUCCESS(rc)) { LOGF_LEAVE(); return 1; } } else { if (pvIn) { WARN(("check failed rdh.dwSize=%x iType=%d size=%d expected size=%d", lpRgnData->rdh.dwSize, lpRgnData->rdh.iType, cjIn, lpRgnData->rdh.nCount * sizeof(RECT) + sizeof(RGNDATAHEADER))); } } break; } default: { LOG(("unsupported iEsc %#x", iEsc)); } } LOGF_LEAVE(); return 0; }
/* Called to reset device to default mode or to mode specified with dhpdev */ BOOL APIENTRY VBoxDispDrvAssertMode(DHPDEV dhpdev, BOOL bEnable) { PVBOXDISPDEV pDev = (PVBOXDISPDEV) dhpdev; DWORD dwrc; int rc; LOGF_ENTER(); if (!bEnable) { LOGF(("!bEnable")); #ifdef VBOX_WITH_VIDEOHWACCEL /* tells we can not process host commands any more and ensures that * we've completed processing of the host VHWA commands */ VBoxDispVHWADisable(pDev); #endif /* disable VBVA */ if (pDev->hgsmi.bSupported) { VBoxVBVADisable(&pDev->vbvaCtx, &pDev->hgsmi.ctx, -1); } /* reset the device to default mode */ rc = VBoxDispMPResetDevice(pDev->hDriver); VBOX_WARNRC_RETV(rc, FALSE); } else { LOGF(("bEnable")); /* switch device to previous pDev mode */ rc = VBoxDispMPSetCurrentMode(pDev->hDriver, pDev->mode.ulIndex); VBOX_WARNRC_RETV(rc, NULL); /* enable VBVA */ if (pDev->hgsmi.bSupported) { if (pDev->mode.ulBitsPerPel==16 || pDev->mode.ulBitsPerPel==24 || pDev->mode.ulBitsPerPel==32) { VBVABUFFER *pVBVA = (VBVABUFFER *)((uint8_t *)pDev->memInfo.VideoRamBase+pDev->layout.offVBVABuffer); pDev->hgsmi.bSupported = VBoxVBVAEnable(&pDev->vbvaCtx, &pDev->hgsmi.ctx, pVBVA, -1); LogRel(("VBoxDisp[%d]: VBVA %senabled\n", pDev->iDevice, pDev->hgsmi.bSupported? "":"not ")); } } /* inform host */ if (pDev->hgsmi.bSupported) { VBoxHGSMIProcessDisplayInfo(&pDev->hgsmi.ctx, pDev->iDevice, pDev->orgDev.x, pDev->orgDev.y, 0, abs(pDev->mode.lScanlineStride), pDev->mode.ulWidth, pDev->mode.ulHeight, (uint16_t)pDev->mode.ulBitsPerPel, VBVA_SCREEN_F_ACTIVE); } #ifdef VBOX_WITH_VIDEOHWACCEL /* tells we can process host commands */ VBoxDispVHWAEnable(pDev); #endif /* Associate back GDI bitmap residing in our framebuffer memory with GDI's handle to our device */ dwrc = EngAssociateSurface((HSURF)pDev->surface.hBitmap, pDev->hDevGDI, 0); if (dwrc != NO_ERROR) { WARN(("EngAssociateSurface on bitmap failed with %#x", dwrc)); return FALSE; } /* Associate device managed surface with GDI's handle to our device */ dwrc = EngAssociateSurface(pDev->surface.hSurface, pDev->hDevGDI, pDev->flDrawingHooks); if (dwrc != NO_ERROR) { WARN(("EngAssociateSurface on surface failed with %#x", dwrc)); return FALSE; } } LOGF_LEAVE(); return TRUE; }
void vrdpAdjustRect(SURFOBJ *pso, RECTL *prcl) { int x; int y; int w; int h; LOGF(("%d-%d %d-%d on %dx%d\n", prcl->left, prcl->right, prcl->top, prcl->bottom, pso->sizlBitmap.cx, pso->sizlBitmap.cy)); if (prcl->left <= prcl->right) { x = prcl->left; w = prcl->right - prcl->left; } else { WARN(("Inverse X coordinates")); x = prcl->right; w = prcl->left - prcl->right; } if (prcl->top <= prcl->bottom) { y = prcl->top; h = prcl->bottom - prcl->top; } else { WARN(("Inverse Y coordinates")); y = prcl->bottom; h = prcl->top - prcl->bottom; } Assert(w >= 0 && h >= 0); /* Correct negative x and y coordinates. */ if (x < 0) { x += w; /* Compute xRight which is also the new width. */ w = (x < 0)? 0: x; x = 0; } if (y < 0) { y += h; /* Compute xBottom, which is also the new height. */ h = (y < 0)? 0: y; y = 0; } /* Also check if coords are greater than the display resolution. */ if (x + w > pso->sizlBitmap.cx) { w = pso->sizlBitmap.cx > x? pso->sizlBitmap.cx - x: 0; } if (y + h > pso->sizlBitmap.cy) { h = pso->sizlBitmap.cy > y? pso->sizlBitmap.cy - y: 0; } prcl->left = x; prcl->top = y; prcl->right = x + w; prcl->bottom = y + h; LOGF(("result %d-%d %d-%d", prcl->left, prcl->right, prcl->top, prcl->bottom)); }
static int vrdpGetIntersectingClipRects(VRDPCLIPRECTS *pClipRects, SURFOBJ *pso, RECTL *prcl, CLIPOBJ *pco, POINTL *pptlSrc) { BOOL bTooManyRects = FALSE; LOGF(("pso = %p, pptlSrc = %p", pso, pptlSrc)); pso = getSurfObj(pso); pClipRects->rclDstOrig = *prcl; pClipRects->rclDst = *prcl; pClipRects->rects.c = 0; vrdpAdjustRect(pso, &pClipRects->rclDst); if (pco && (pco->iDComplexity != DC_TRIVIAL)) { ULONG iDirection = CD_ANY; if (pptlSrc) { /* Operation is performed on the same (screen) surface and enumeration direction * must take into account the position of source and target rectangles. */ if (pptlSrc->x <= prcl->left) { if (pptlSrc->y <= prcl->top) { iDirection = CD_LEFTUP; } else { iDirection = CD_LEFTDOWN; } } else { if (pptlSrc->y <= prcl->top) { iDirection = CD_RIGHTUP; } else { iDirection = CD_RIGHTDOWN; } } } /* Clip the target rect by entire clipping region. Obtain the effective target. */ vrdpIntersectRects(&pClipRects->rclDst, &pClipRects->rclDst, &pco->rclBounds); /* Enumerate rectangles. Try to get all rectangles at once and if there is not * enough space (too many rectangles) fail with the bTooManyRects condition. */ CLIPOBJ_cEnumStart(pco, FALSE, CT_RECTANGLES, iDirection, 0); bTooManyRects = CLIPOBJ_bEnum(pco, sizeof(pClipRects->rects), &pClipRects->rects.c); if (!bTooManyRects) { RECTL *prclClipSrc = &pClipRects->rects.arcl[0]; RECTL *prclClipDst = prclClipSrc; ULONG cRects = pClipRects->rects.c; LOGF(("%d rects", cRects)); if (cRects > 0) { for (; cRects != 0; cRects--, prclClipSrc++) { vrdpIntersectRects(prclClipDst, prclClipSrc, &pClipRects->rclDst); if (vrdpIsRectEmpty(prclClipDst)) { pClipRects->rects.c--; } else { prclClipDst++; } } } if (pClipRects->rects.c == 0) { pClipRects->rclDst.left = pClipRects->rclDst.right = 0; } LOGF(("%d rects remains", pClipRects->rects.c)); } } if (vrdpIsRectEmpty(&pClipRects->rclDst)) { return VRDP_CLIP_NO_INTERSECTION; } if (bTooManyRects) { pClipRects->rects.c = 0; return VRDP_CLIP_TOO_MANY_RECTS; } return VRDP_CLIP_OK; }
ULONG_PTR APIENTRY VBoxDispDrvSaveScreenBits(SURFOBJ *pso, ULONG iMode, ULONG_PTR ident, RECTL *prcl) { ULONG_PTR rc = 0; /* 0 means the function failure for every iMode. */ RECTL rcl; SSB *pSSB; SURFOBJ *psoOrg = pso; BOOL bCallVBVA = FALSE; PVBOXDISPDEV pDev = (PVBOXDISPDEV) pso->dhpdev; LOGF(("%p, %d, %d, %d,%d %d,%d", pso, iMode, ident, prcl->left, prcl->top, prcl->right, prcl->bottom)); if (!pDev) { return rc; } pso = getSurfObj(pso); /* Order the rectangle. */ if (prcl->left <= prcl->right) { rcl.left = prcl->left; rcl.right = prcl->right; } else { rcl.left = prcl->right; rcl.right = prcl->left; } if (prcl->top <= prcl->bottom) { rcl.top = prcl->top; rcl.bottom = prcl->bottom; } else { rcl.top = prcl->bottom; rcl.bottom = prcl->top; } /* Implementation of the save/restore is a bit complicated because RDP * requires "the sequencing of saves and restores is such that they * behave as a last-in, first-out stack.". */ switch (iMode) { case SS_SAVE: { LOG(("SS_SAVE %d", pDev->cSSB)); if (pDev->cSSB >= RT_ELEMENTS(pDev->aSSB)) { /* All slots are already in use. Fail. */ WARN(("no more slots %d!!!", pDev->cSSB)); break; } /* Get pointer to the slot where bits will be saved. */ pSSB = &pDev->aSSB[pDev->cSSB]; /* Allocate memory for screen bits and copy them to the buffer. */ if (ssbCopy(pSSB, pso, &rcl, FALSE /* bToScreen */)) { /* Bits where successfully copied. Increase the active slot number * and call VBVA levels, 'ident' is also assigned, the VBVA level * will use it even for the SS_SAVE. */ ident = rc = pSSB->ident = ++pDev->cSSB; bCallVBVA = TRUE; } } break; case SS_RESTORE: { LOG(("SS_RESTORE")); if (pDev->cSSB == 0 || ident == 0 || ident > pDev->cSSB) { WARN(("no slot: pDev->cSSB = %d!!!", pDev->cSSB)); break; } if (ident < pDev->cSSB) { ssbDiscardUpperSlots(pDev, ident); } Assert(ident == pDev->cSSB); Assert(ident != 0); pSSB = &pDev->aSSB[ident - 1]; ssbCopy(pSSB, pso, &rcl, TRUE /* bToScreen */); /* Bits must be discarded. */ ssbDiscardTopSlot (pDev); rc = TRUE; bCallVBVA = TRUE; } break; case SS_FREE: { LOG(("SS_FREE")); if (pDev->cSSB == 0 || ident == 0 || ident > pDev->cSSB) { WARN(("no slot: pDev->cSSB = %d!!!", pDev->cSSB)); break; } if (ident < pDev->cSSB) { ssbDiscardUpperSlots(pDev, ident); } Assert(ident == pDev->cSSB); Assert(ident != 0); /* Bits must be discarded. */ ssbDiscardTopSlot(pDev); rc = TRUE; } break; } /* Now call the VBVA/VRDP levels. */ if (bCallVBVA) { LOG(("calling VBVA")); VBVA_OPERATION(psoOrg, SaveScreenBits, (psoOrg, iMode, ident, &rcl)); } LOGF(("return %d", rc)); return rc; }
int worker_process(epdata_t *epd, int thread_at) { //printf("worker_process\n"); working_at_fd = epd->fd; //network_send_error(epd, 503, "Lua Error: main function not found !!!");return 0; //network_send(epd, "aaa", 3);network_be_end(epd);return 0; if(epd->ssl && !epd->ssl_verify) { network_send_error(epd, 400, "No required SSL certificate was send"); return 0; } lua_State *L = epd->L; if(!L) { epd->L = new_lua_thread(_L); if(!epd->L) { network_send_error(epd, 503, "Lua Error: Thread pool full !!!"); return 0; } lua_pushlightuserdata(epd->L, epd); lua_setglobal(epd->L, "__epd__"); L = epd->L; } lua_getglobal(L, "process"); update_timeout(epd->timeout_ptr, STEP_PROCESS_TIMEOUT + 100); int init_tables = 0; char *pt1 = NULL, *pt2 = NULL, *t1 = NULL, *t2 = NULL, *t3 = NULL; int is_form_post = 0; char *cookies = NULL; pt1 = epd->headers; int i = 0; epd->uri = NULL; epd->host = NULL; epd->query = NULL; epd->http_ver = NULL; epd->referer = NULL; epd->user_agent = NULL; epd->if_modified_since = NULL; //epd->start_time = longtime(); while(t1 = strtok_r(pt1, "\n", &pt1)) { if(++i == 1) { /// first line t2 = strtok_r(t1, " ", &t1); t3 = strtok_r(t1, " ", &t1); epd->http_ver = strtok_r(t1, " ", &t1); if(!epd->http_ver) { return 1; } else { if(init_tables == 0) { lua_newtable(L); //headers } } int len = strlen(epd->http_ver); if(epd->http_ver[len - 1] == 13) { // CR == 13 epd->http_ver[len - 1] = '\0'; } if(t2 && t3) { for(t1 = t2 ; *t1 ; *t1 = toupper(*t1), t1++); epd->method = t2; lua_pushstring(L, t2); lua_setfield(L, -2, "method"); t1 = strtok_r(t3, "?", &t3); t2 = strtok_r(t3, "?", &t3); epd->uri = t1; lua_pushstring(L, t1); lua_setfield(L, -2, "uri"); if(t2) { epd->query = (t2 - 1); epd->query[0] = '?'; lua_pushstring(L, epd->query); lua_setfield(L, -2, "query"); } } continue; } t2 = strtok_r(t1, ":", &t1); if(t2) { if(t2[0] == '\r') { break; } for(t3 = t2; *t3; ++t3) { *t3 = *t3 >= 'A' && *t3 <= 'Z' ? *t3 | 0x60 : *t3; } t3 = t2 + strlen(t2) + 1; //strtok_r ( t1, ":", &t1 ) if(t3) { int len = strlen(t3); if(t3[len - 1] == 13) { /// 13 == CR t3[len - 1] = '\0'; len -= 1; } if(len < 1) { break; } lua_pushstring(L, t3 + (t3[0] == ' ' ? 1 : 0)); lua_setfield(L, -2, t2); /// check content-type if(t2[0] == 'h' && epd->host == NULL && strcmp(t2, "host") == 0) { char *_t = strstr(t3, ":"); if(_t) { _t[0] = '\0'; } epd->host = t3 + (t3[0] == ' ' ? 1 : 0); } else if(t2[1] == 'o' && strcmp(t2, "content-type") == 0) { if(stristr(t3, "x-www-form-urlencoded", len)) { is_form_post = 1; } else if(stristr(t3, "multipart/form-data", len)) { epd->boundary = (char *)stristr(t3, "boundary=", len - 2); if(epd->boundary) { epd->boundary += 9; } } } else if(!cookies && t2[1] == 'o' && strcmp(t2, "cookie") == 0) { cookies = t3 + (t3[0] == ' ' ? 1 : 0); } else if(!epd->user_agent && t2[1] == 's' && strcmp(t2, "user-agent") == 0) { epd->user_agent = t3 + (t3[0] == ' ' ? 1 : 0); } else if(!epd->referer && t2[1] == 'e' && strcmp(t2, "referer") == 0) { epd->referer = t3 + (t3[0] == ' ' ? 1 : 0); } else if(!epd->if_modified_since && t2[1] == 'f' && strcmp(t2, "if-modified-since") == 0) { epd->if_modified_since = t3 + (t3[0] == ' ' ? 1 : 0); } } } } char *client_ip = inet_ntoa(epd->client_addr); lua_pushstring(L, client_ip); lua_setfield(L, -2, "remote-addr"); int l = sizeof(struct sockaddr); struct sockaddr_in addr; getsockname(epd->fd, (struct sockaddr *) &addr, &l); lua_pushstring(L, inet_ntoa(addr.sin_addr)); lua_setfield(L, -2, "server-addr"); lua_setglobal(L, "headers"); lua_newtable(L); /// _GET if(epd->query) { /// parse query string /?a=1&b=2 char *last = NULL; int plen = 0; int qlen = strlen(epd->query) - 1; t1 = (char *)strsplit(epd->query + 1, qlen, "&", &last, &plen); char kk[256] = {0}; while(t1) { char *last2 = NULL; int plen2 = 0; int plen3 = 0; t2 = (char *)strsplit(t1, plen, "=", &last2, &plen2); t3 = (char *)strsplit(t1, plen, "=", &last2, &plen3); if(t2 && plen2 > 0 && plen3 > 0 && plen2 <= 4096 && plen3 <= 4096) { size_t dlen; u_char *p; u_char *src, *dst; p = (u_char *)&buf_4096; p[0] = '\0'; dst = p; dlen = urldecode(&p, (u_char **)&t3, plen3, RAW_UNESCAPE_URL); lua_pushlstring(L, (char *) p, dlen); p[0] = '\0'; dst = p; dlen = urldecode(&dst, (u_char **)&t2, plen2, RAW_UNESCAPE_URL); p[dlen] = '\0'; lua_setfield(L, -2, p); } t1 = (char *)strsplit(epd->query + 1, qlen, "&", &last, &plen); } } lua_setglobal(L, "_GET"); lua_newtable(L); /// _COOKIE if(cookies) { while(t1 = strtok_r(cookies, ";", &cookies)) { t2 = strtok_r(t1, "=", &t1); t3 = strtok_r(t1, "=", &t1); if(t2 && t3 && strlen(t2) > 0 && strlen(t3) > 0) { size_t len, dlen; u_char *p; u_char *src, *dst; len = strlen(t3); p = malloc(len); p[0] = '\0'; dst = p; dlen = urldecode(&dst, (u_char **)&t3, len, RAW_UNESCAPE_URL); lua_pushlstring(L, (char *) p, dlen); len = strlen(t2); if(len > 4096) { free(p); p = malloc(len); } p[0] = '\0'; dst = p; dlen = urldecode(&dst, (u_char **)&t2, len, RAW_UNESCAPE_URL); p[dlen] = '\0'; lua_setfield(L, -2, p + (p[0] == ' ' ? 1 : 0)); free(p); } } } lua_setglobal(L, "_COOKIE"); lua_pushnil(L); lua_setglobal(L, "__body_buf"); epd->vhost_root = get_vhost_root(epd->host, &epd->vhost_root_len); memcpy(buf_4096, epd->vhost_root, epd->vhost_root_len + 1); sprintf(buf_4096 + epd->vhost_root_len + 1, "?.lua;%s/lua-libs/?.lua;", process_chdir); lua_pushstring(L, buf_4096); lua_getglobal(L, "package"); lua_insert(L, -2); //-1 bufres -2 package lua_setfield(L, -2, "path"); //-1: path -2: package lua_pop(L, 1); //void lua_pushlstring(L, epd->vhost_root, epd->vhost_root_len); /// host root lua_setglobal(L, "__root"); lua_pushstring(L, epd->vhost_root + epd->vhost_root_len); /// index-route.lua file epd->iov[0].iov_base = NULL; epd->iov[0].iov_len = 0; epd->iov[1].iov_base = NULL; epd->iov[1].iov_len = 0; lua_routed = 0; if(lua_resume(L, 1) == LUA_ERRRUN && lua_isstring(L, -1)) { LOGF(ERR, "Lua:error %s", lua_tostring(L, -1)); network_send_error(epd, 503, lua_tostring(L, -1)); lua_pop(L, 1); } return 0; }
/* this is the codec entry point */ enum codec_status codec_main(void) { struct ape_ctx_t ape_ctx; uint32_t samplesdone; uint32_t elapsedtime; size_t bytesleft; int retval; uint32_t currentframe; uint32_t newfilepos; uint32_t samplestoskip; int nblocks; int bytesconsumed; unsigned char* inbuffer; uint32_t blockstodecode; int res; int firstbyte; size_t resume_offset; /* Generic codec initialisation */ ci->configure(DSP_SET_SAMPLE_DEPTH, APE_OUTPUT_DEPTH-1); next_track: retval = CODEC_OK; if (codec_init()) { LOGF("APE: Error initialising codec\n"); retval = CODEC_ERROR; goto exit; } if (codec_wait_taginfo() != 0) goto done; /* Remember the resume position - when the codec is opened, the playback engine will reset it. */ resume_offset = ci->id3->offset; inbuffer = ci->request_buffer(&bytesleft, INPUT_CHUNKSIZE); /* Read the file headers to populate the ape_ctx struct */ if (ape_parseheaderbuf(inbuffer,&ape_ctx) < 0) { LOGF("APE: Error reading header\n"); retval = CODEC_ERROR; goto exit; } /* Initialise the seektable for this file */ ape_ctx.seektable = seektablebuf; ape_ctx.numseekpoints = MIN(MAX_SEEKPOINTS,ape_ctx.numseekpoints); ci->advance_buffer(ape_ctx.seektablefilepos); /* The seektable may be bigger than the guard buffer (32KB), so we do a read() */ ci->read_filebuf(ape_ctx.seektable, ape_ctx.numseekpoints * sizeof(uint32_t)); #ifdef ROCKBOX_BIG_ENDIAN /* Byte-swap the little-endian seekpoints */ { uint32_t i; for(i = 0; i < ape_ctx.numseekpoints; i++) ape_ctx.seektable[i] = swap32(ape_ctx.seektable[i]); } #endif /* Now advance the file position to the first frame */ ci->advance_buffer(ape_ctx.firstframe - (ape_ctx.seektablefilepos + ape_ctx.numseekpoints * sizeof(uint32_t))); ci->configure(DSP_SWITCH_FREQUENCY, ape_ctx.samplerate); ci->configure(DSP_SET_STEREO_MODE, ape_ctx.channels == 1 ? STEREO_MONO : STEREO_NONINTERLEAVED); codec_set_replaygain(ci->id3); /* The main decoding loop */ if (resume_offset) { /* The resume offset is a value in bytes - we need to turn it into a frame number and samplestoskip value */ ape_resume(&ape_ctx, resume_offset, ¤tframe, &samplesdone, &samplestoskip, &firstbyte); } else { currentframe = 0; samplesdone = 0; samplestoskip = 0; firstbyte = 3; /* Take account of the little-endian 32-bit byte ordering */ } /* Initialise the buffer */ inbuffer = ci->request_buffer(&bytesleft, INPUT_CHUNKSIZE); /* The main decoding loop - we decode the frames a small chunk at a time */ while (currentframe < ape_ctx.totalframes) { frame_start: /* Calculate how many blocks there are in this frame */ if (currentframe == (ape_ctx.totalframes - 1)) nblocks = ape_ctx.finalframeblocks; else nblocks = ape_ctx.blocksperframe; ape_ctx.currentframeblocks = nblocks; /* Initialise the frame decoder */ init_frame_decoder(&ape_ctx, inbuffer, &firstbyte, &bytesconsumed); ci->advance_buffer(bytesconsumed); inbuffer = ci->request_buffer(&bytesleft, INPUT_CHUNKSIZE); /* Decode the frame a chunk at a time */ while (nblocks > 0) { ci->yield(); if (ci->stop_codec || ci->new_track) { goto done; } /* Deal with any pending seek requests */ if (ci->seek_time) { if (ape_calc_seekpos(&ape_ctx, ((ci->seek_time-1)/10) * (ci->id3->frequency/100), ¤tframe, &newfilepos, &samplestoskip)) { samplesdone = currentframe * ape_ctx.blocksperframe; /* APE's bytestream is weird... */ firstbyte = 3 - (newfilepos & 3); newfilepos &= ~3; ci->seek_buffer(newfilepos); inbuffer = ci->request_buffer(&bytesleft, INPUT_CHUNKSIZE); ci->seek_complete(); goto frame_start; /* Sorry... */ } ci->seek_complete(); } blockstodecode = MIN(BLOCKS_PER_LOOP, nblocks); if ((res = decode_chunk(&ape_ctx, inbuffer, &firstbyte, &bytesconsumed, decoded0, decoded1, blockstodecode)) < 0) { /* Frame decoding error, abort */ LOGF("APE: Frame %lu, error %d\n",(unsigned long)currentframe,res); retval = CODEC_ERROR; goto done; } ci->yield(); if (samplestoskip > 0) { if (samplestoskip < blockstodecode) { ci->pcmbuf_insert(decoded0 + samplestoskip, decoded1 + samplestoskip, blockstodecode - samplestoskip); samplestoskip = 0; } else { samplestoskip -= blockstodecode; } } else { ci->pcmbuf_insert(decoded0, decoded1, blockstodecode); } samplesdone += blockstodecode; if (!samplestoskip) { /* Update the elapsed-time indicator */ elapsedtime = (samplesdone*10)/(ape_ctx.samplerate/100); ci->set_elapsed(elapsedtime); } ci->advance_buffer(bytesconsumed); inbuffer = ci->request_buffer(&bytesleft, INPUT_CHUNKSIZE); /* Decrement the block count */ nblocks -= blockstodecode; } currentframe++; } done: LOGF("APE: Decoded %lu samples\n",(unsigned long)samplesdone); if (ci->request_next_track()) goto next_track; exit: return retval; }
void apu_inspect(struct APU* apu) { LOGF("TODO: apu_inspect(struct APU*) %p", (void*)apu); }
int VBoxVbvaEnable(PVBOXMP_DEVEXT pExt, BOOLEAN bEnable, VBVAENABLERESULT *pResult) { int rc = VINF_SUCCESS; LOGF_ENTER(); VMMDevMemory *pVMMDevMemory = NULL; rc = VbglQueryVMMDevMemory (&pVMMDevMemory); if (RT_FAILURE(rc)) { WARN(("VbglQueryVMMDevMemory rc = %#xrc", rc)); LOGF_LEAVE(); return rc; } if (pExt->iDevice>0) { PVBOXMP_DEVEXT pPrimary = pExt->pPrimary; LOGF(("skipping non-primary display %d", pExt->iDevice)); if (bEnable && pPrimary->u.primary.ulVbvaEnabled && pVMMDevMemory) { pResult->pVbvaMemory = &pVMMDevMemory->vbvaMemory; pResult->pfnFlush = VBoxVbvaFlush; pResult->pvFlush = pExt; } else { VideoPortZeroMemory(&pResult, sizeof(VBVAENABLERESULT)); } LOGF_LEAVE(); return rc; } /* Allocate the memory block for VMMDevReq_VideoAccelFlush request. */ if (pExt->u.primary.pvReqFlush == NULL) { VMMDevVideoAccelFlush *req = NULL; rc = VbglGRAlloc((VMMDevRequestHeader **)&req, sizeof(VMMDevVideoAccelFlush), VMMDevReq_VideoAccelFlush); if (RT_SUCCESS(rc)) { pExt->u.primary.pvReqFlush = req; } else { WARN(("VbglGRAlloc(VMMDevVideoAccelFlush) rc = %#xrc", rc)); LOGF_LEAVE(); return rc; } } ULONG ulEnabled = 0; VMMDevVideoAccelEnable *req = NULL; rc = VbglGRAlloc((VMMDevRequestHeader **)&req, sizeof(VMMDevVideoAccelEnable), VMMDevReq_VideoAccelEnable); if (RT_SUCCESS(rc)) { req->u32Enable = bEnable; req->cbRingBuffer = VBVA_RING_BUFFER_SIZE; req->fu32Status = 0; rc = VbglGRPerform(&req->header); if (RT_SUCCESS(rc)) { if (req->fu32Status & VBVA_F_STATUS_ACCEPTED) { LOG(("accepted")); /* Initialize the result information and VBVA memory. */ if (req->fu32Status & VBVA_F_STATUS_ENABLED) { pResult->pVbvaMemory = &pVMMDevMemory->vbvaMemory; pResult->pfnFlush = VBoxVbvaFlush; pResult->pvFlush = pExt; ulEnabled = 1; } else { VideoPortZeroMemory(&pResult, sizeof(VBVAENABLERESULT)); } } else { LOG(("rejected")); /* Disable VBVA for old hosts. */ req->u32Enable = 0; req->cbRingBuffer = VBVA_RING_BUFFER_SIZE; req->fu32Status = 0; VbglGRPerform(&req->header); rc = VERR_NOT_SUPPORTED; } } else { WARN(("rc = %#xrc", rc)); } VbglGRFree(&req->header); } else { WARN(("VbglGRAlloc(VMMDevVideoAccelEnable) rc = %#xrc", rc)); } pExt->u.primary.ulVbvaEnabled = ulEnabled; LOGF_LEAVE(); return rc; }
void Tcp::disconnect() { int erc = espconn_disconnect(_conn); LOGF(" espconn_disconnect() == %d ",erc); _connected = false; }
/* this is the codec entry point */ enum codec_status codec_main(void) { uint32_t elapsedtime; int retval; asf_waveformatex_t wfx; /* Holds the stream properties */ size_t resume_offset; int res; /* Return values from asf_read_packet() and decode_packet() */ uint8_t* audiobuf; /* Pointer to the payload of one wma pro packet */ int audiobufsize; /* Payload size */ int packetlength = 0; /* Logical packet size (minus the header size) */ int outlen = 0; /* Number of bytes written to the output buffer */ int pktcnt = 0; /* Count of the packets played */ /* Generic codec initialisation */ ci->configure(DSP_SET_SAMPLE_DEPTH, 31); next_track: retval = CODEC_OK; /* Wait for the metadata to be read */ if (codec_wait_taginfo() != 0) goto done; /* Remember the resume position */ resume_offset = ci->id3->offset; restart_track: retval = CODEC_OK; if (codec_init()) { LOGF("(WMA Voice) Error: Error initialising codec\n"); retval = CODEC_ERROR; goto done; } /* Copy the format metadata we've stored in the id3 TOC field. This saves us from parsing it again here. */ memcpy(&wfx, ci->id3->toc, sizeof(wfx)); memset(&avctx, 0, sizeof(AVCodecContext)); memset(&avpkt, 0, sizeof(AVPacket)); ci->configure(DSP_SWITCH_FREQUENCY, wfx.rate); ci->configure(DSP_SET_STEREO_MODE, wfx.channels == 1 ? STEREO_MONO : STEREO_INTERLEAVED); codec_set_replaygain(ci->id3); /* Initialise the AVCodecContext */ init_codec_ctx(&avctx, &wfx); if (wmavoice_decode_init(&avctx) < 0) { LOGF("(WMA Voice) Error: Unsupported or corrupt file\n"); retval = CODEC_ERROR; goto done; } /* Now advance the file position to the first frame */ ci->seek_buffer(ci->id3->first_frame_offset); elapsedtime = 0; resume_offset = 0; /* The main decoding loop */ while (pktcnt < wfx.numpackets) { ci->yield(); if (ci->stop_codec || ci->new_track) { goto done; } /* Deal with any pending seek requests */ if (ci->seek_time){ if (ci->seek_time == 1) { ci->seek_complete(); goto restart_track; /* Pretend you never saw this... */ } elapsedtime = asf_seek(ci->seek_time, &wfx); if (elapsedtime < 1){ ci->seek_complete(); goto next_track; } ci->set_elapsed(elapsedtime); ci->seek_complete(); } new_packet: res = asf_read_packet(&audiobuf, &audiobufsize, &packetlength, &wfx); if (res < 0) { LOGF("(WMA Voice) read_packet error %d\n",res); goto done; } else { avpkt.data = audiobuf; avpkt.size = audiobufsize; pktcnt++; while(avpkt.size > 0) { /* wmavoice_decode_packet checks for the output buffer size to avoid overflows */ outlen = BUFSIZE*sizeof(int32_t); res = wmavoice_decode_packet(&avctx, decoded, &outlen, &avpkt); if(res < 0) { LOGF("(WMA Voice) Error: decode_packet returned %d", res); if(res == ERROR_WMAPRO_IN_WMAVOICE){ /* Just skip this packet */ ci->advance_buffer(packetlength); goto new_packet; } else goto done; } avpkt.data += res; avpkt.size -= res; if(outlen) { ci->yield (); outlen /= sizeof(int32_t); ci->pcmbuf_insert(decoded, NULL, outlen); elapsedtime += outlen*10/(wfx.rate/100); ci->set_elapsed(elapsedtime); ci->yield (); } } } /* Advance to the next logical packet */ ci->advance_buffer(packetlength); } done: if (ci->request_next_track()) goto next_track; return retval; }
int run_test(const char* test, int timeout, int benchmark_output, int test_count) { char errmsg[1024] = "no error"; process_info_t processes[1024]; process_info_t *main_proc; task_entry_t* task; int process_count; int result; int status; int i; status = 255; main_proc = NULL; process_count = 0; #ifndef _WIN32 /* Clean up stale socket from previous run. */ remove(TEST_PIPENAME); #endif /* If it's a helper the user asks for, start it directly. */ for (task = TASKS; task->main; task++) { if (task->is_helper && strcmp(test, task->process_name) == 0) { return task->main(); } } /* Start the helpers first. */ for (task = TASKS; task->main; task++) { if (strcmp(test, task->task_name) != 0) { continue; } /* Skip the test itself. */ if (!task->is_helper) { continue; } if (process_start(task->task_name, task->process_name, &processes[process_count], 1 /* is_helper */) == -1) { snprintf(errmsg, sizeof errmsg, "Process `%s` failed to start.", task->process_name); goto out; } process_count++; } /* Give the helpers time to settle. Race-y, fix this. */ uv_sleep(250); /* Now start the test itself. */ for (task = TASKS; task->main; task++) { if (strcmp(test, task->task_name) != 0) { continue; } if (task->is_helper) { continue; } if (process_start(task->task_name, task->process_name, &processes[process_count], 0 /* !is_helper */) == -1) { snprintf(errmsg, sizeof errmsg, "Process `%s` failed to start.", task->process_name); goto out; } main_proc = &processes[process_count]; process_count++; break; } if (main_proc == NULL) { snprintf(errmsg, sizeof errmsg, "No test with that name: %s", test); goto out; } result = process_wait(main_proc, 1, timeout); if (result == -1) { FATAL("process_wait failed"); } else if (result == -2) { /* Don't have to clean up the process, process_wait() has killed it. */ snprintf(errmsg, sizeof errmsg, "timeout"); goto out; } status = process_reap(main_proc); if (status != 0) { snprintf(errmsg, sizeof errmsg, "exit code %d", status); goto out; } if (benchmark_output) { /* Give the helpers time to clean up their act. */ uv_sleep(1000); } out: /* Reap running processes except the main process, it's already dead. */ for (i = 0; i < process_count - 1; i++) { process_terminate(&processes[i]); } if (process_count > 0 && process_wait(processes, process_count - 1, -1) < 0) { FATAL("process_wait failed"); } /* Show error and output from processes if the test failed. */ if (status != 0 || task->show_output) { if (tap_output) { LOGF("not ok %d - %s\n#", test_count, test); } else if (status != 0) { LOGF("\n`%s` failed: %s\n", test, errmsg); } else { LOGF("\n"); } for (i = 0; i < process_count; i++) { switch (process_output_size(&processes[i])) { case -1: LOGF("Output from process `%s`: (unavailable)\n", process_get_name(&processes[i])); break; case 0: LOGF("Output from process `%s`: (no output)\n", process_get_name(&processes[i])); break; default: LOGF("Output from process `%s`:\n", process_get_name(&processes[i])); process_copy_output(&processes[i], fileno(stderr)); break; } } if (!tap_output) { LOG("=============================================================\n"); } /* In benchmark mode show concise output from the main process. */ } else if (benchmark_output) { switch (process_output_size(main_proc)) { case -1: LOGF("%s: (unavailable)\n", test); break; case 0: LOGF("%s: (no output)\n", test); break; default: for (i = 0; i < process_count; i++) { process_copy_output(&processes[i], fileno(stderr)); } break; } } else if (tap_output) { LOGF("ok %d - %s\n", test_count, test); } /* Clean up all process handles. */ for (i = 0; i < process_count; i++) { process_cleanup(&processes[i]); } return status; }
Result HcdChannelSendWaitOne(struct UsbDevice *device, struct UsbPipeAddress *pipe, u8 channel, void* buffer, u32 bufferLength, u32 bufferOffset, struct UsbDeviceRequest *request) { Result result; u32 timeout, tries, globalTries, actualTries; for (globalTries = 0, actualTries = 0; globalTries < 3 && actualTries < 10; globalTries++, actualTries++) { SetReg(&Host->Channel[channel].Interrupt); WriteThroughReg(&Host->Channel[channel].Interrupt); ReadBackReg(&Host->Channel[channel].TransferSize); ReadBackReg(&Host->Channel[channel].SplitControl); HcdTransmitChannel(channel, (u8*)buffer + bufferOffset); timeout = 0; do { if (timeout++ == RequestTimeout) { LOGF("HCD: Request to %s has timed out.\n", UsbGetDescription(device)); device->Error = ConnectionError; return ErrorTimeout; } ReadBackReg(&Host->Channel[channel].Interrupt); if (!Host->Channel[channel].Interrupt.Halt) MicroDelay(10); else break; } while (true); ReadBackReg(&Host->Channel[channel].TransferSize); if (Host->Channel[channel].SplitControl.SplitEnable) { if (Host->Channel[channel].Interrupt.Acknowledgement) { for (tries = 0; tries < 3; tries++) { SetReg(&Host->Channel[channel].Interrupt); WriteThroughReg(&Host->Channel[channel].Interrupt); ReadBackReg(&Host->Channel[channel].SplitControl); Host->Channel[channel].SplitControl.CompleteSplit = true; WriteThroughReg(&Host->Channel[channel].SplitControl); Host->Channel[channel].Characteristic.Enable = true; Host->Channel[channel].Characteristic.Disable = false; WriteThroughReg(&Host->Channel[channel].Characteristic); timeout = 0; do { if (timeout++ == RequestTimeout) { LOGF("HCD: Request split completion to %s has timed out.\n", UsbGetDescription(device)); device->Error = ConnectionError; return ErrorTimeout; } ReadBackReg(&Host->Channel[channel].Interrupt); if (!Host->Channel[channel].Interrupt.Halt) MicroDelay(100); else break; } while (true); if (!Host->Channel[channel].Interrupt.NotYet) break; } if (tries == 3) { MicroDelay(25000); continue; } else if (Host->Channel[channel].Interrupt.NegativeAcknowledgement) { globalTries--; MicroDelay(25000); continue; } else if (Host->Channel[channel].Interrupt.TransactionError) { MicroDelay(25000); continue; } if ((result = HcdChannelInterruptToError(device, Host->Channel[channel].Interrupt, false)) != OK) { LOG_DEBUGF("HCD: Control message to %#x: %02x%02x%02x%02x %02x%02x%02x%02x.\n", *(u32*)pipe, ((u8*)request)[0], ((u8*)request)[1], ((u8*)request)[2], ((u8*)request)[3], ((u8*)request)[4], ((u8*)request)[5], ((u8*)request)[6], ((u8*)request)[7]); LOGF("HCD: Request split completion to %s failed.\n", UsbGetDescription(device)); return result; } } else if (Host->Channel[channel].Interrupt.NegativeAcknowledgement) { globalTries--; MicroDelay(25000); continue; } else if (Host->Channel[channel].Interrupt.TransactionError) { MicroDelay(25000); continue; } } else { if ((result = HcdChannelInterruptToError(device, Host->Channel[channel].Interrupt, !Host->Channel[channel].SplitControl.SplitEnable)) != OK) { LOG_DEBUGF("HCD: Control message to %#x: %02x%02x%02x%02x %02x%02x%02x%02x.\n", *(u32*)pipe, ((u8*)request)[0], ((u8*)request)[1], ((u8*)request)[2], ((u8*)request)[3], ((u8*)request)[4], ((u8*)request)[5], ((u8*)request)[6], ((u8*)request)[7]); LOGF("HCD: Request to %s failed.\n", UsbGetDescription(device)); return ErrorRetry; } } break; } if (globalTries == 3 || actualTries == 10) { LOGF("HCD: Request to %s has failed 3 times.\n", UsbGetDescription(device)); if ((result = HcdChannelInterruptToError(device, Host->Channel[channel].Interrupt, !Host->Channel[channel].SplitControl.SplitEnable)) != OK) { LOG_DEBUGF("HCD: Control message to %#x: %02x%02x%02x%02x %02x%02x%02x%02x.\n", *(u32*)pipe, ((u8*)request)[0], ((u8*)request)[1], ((u8*)request)[2], ((u8*)request)[3], ((u8*)request)[4], ((u8*)request)[5], ((u8*)request)[6], ((u8*)request)[7]); LOGF("HCD: Request to %s failed.\n", UsbGetDescription(device)); return result; } device->Error = ConnectionError; return ErrorTimeout; } return OK; }
/* this is called for each file to process */ enum codec_status codec_run(void) { int error = CODEC_ERROR; SpeexBits bits; int eof = 0; spx_ogg_sync_state oy; spx_ogg_page og; spx_ogg_packet op; spx_ogg_stream_state os; spx_int64_t page_granule = 0; spx_int64_t cur_granule = 0; int enh_enabled = 1; int nframes = 2; int eos = 0; SpeexStereoState *stereo; int channels = -1; int samplerate = ci->id3->frequency; int extra_headers = 0; int stream_init = 0; /* rockbox: comment 'set but unused' variables int page_nb_packets; */ int frame_size; int packet_count = 0; int lookahead; int headerssize = 0; unsigned long strtoffset = ci->id3->offset; void *st = NULL; int j = 0; intptr_t param; memset(&bits, 0, sizeof(bits)); memset(&oy, 0, sizeof(oy)); /* Ogg handling still uses mallocs, so reset the malloc buffer per track */ if (codec_init()) { goto exit; } ci->seek_buffer(0); ci->set_elapsed(0); stereo = speex_stereo_state_init(); spx_ogg_sync_init(&oy); spx_ogg_alloc_buffer(&oy,2*CHUNKSIZE); codec_set_replaygain(ci->id3); eof = 0; while (!eof) { enum codec_command_action action = ci->get_command(¶m); if (action == CODEC_ACTION_HALT) break; /*seek (seeks to the page before the position) */ if (action == CODEC_ACTION_SEEK_TIME) { if(samplerate!=0&&packet_count>1){ LOGF("Speex seek page:%lld,%lld,%ld,%lld,%d\n", ((spx_int64_t)param/1000) * (spx_int64_t)samplerate, page_granule, param, (page_granule/samplerate)*1000, samplerate); speex_seek_page_granule(((spx_int64_t)param/1000) * (spx_int64_t)samplerate, page_granule, &oy, headerssize); } ci->set_elapsed(param); ci->seek_complete(); } next_page: /*Get the ogg buffer for writing*/ if(get_more_data(&oy)<1){/*read error*/ goto done; } /* Loop for all complete pages we got (most likely only one) */ while (spx_ogg_sync_pageout(&oy, &og) == 1) { int packet_no; if (stream_init == 0) { spx_ogg_stream_init(&os, spx_ogg_page_serialno(&og)); stream_init = 1; } /* Add page to the bitstream */ spx_ogg_stream_pagein(&os, &og); page_granule = spx_ogg_page_granulepos(&og); /* page_nb_packets = spx_ogg_page_packets(&og); */ cur_granule = page_granule; /* Extract all available packets */ packet_no=0; while (!eos && spx_ogg_stream_packetout(&os, &op)==1){ /* If first packet, process as Speex header */ if (packet_count==0){ st = process_header(&op, enh_enabled, &frame_size, &samplerate, &nframes, &channels, stereo, &extra_headers); speex_decoder_ctl(st, SPEEX_GET_LOOKAHEAD, &lookahead); if (!nframes) nframes=1; if (!st){ goto done; } ci->configure(DSP_SET_FREQUENCY, ci->id3->frequency); ci->configure(DSP_SET_SAMPLE_DEPTH, 16); if (channels == 2) { ci->configure(DSP_SET_STEREO_MODE, STEREO_INTERLEAVED); } else if (channels == 1) { ci->configure(DSP_SET_STEREO_MODE, STEREO_MONO); } /* Speex header in its own page, add the whole page headersize */ headerssize += og.header_len+og.body_len; } else if (packet_count<=1+extra_headers){ /* add packet to headersize */ headerssize += op.bytes; /* Ignore extra headers */ } else { if (packet_count <= 2+extra_headers) { if (strtoffset) { ci->seek_buffer(strtoffset); spx_ogg_sync_reset(&oy); packet_count++; goto next_page; } } packet_no++; if (op.e_o_s) /* End of stream condition */ eos=1; /* Set Speex bitstream to point to Ogg packet */ speex_bits_set_bit_buffer(&bits, (char *)op.packet, op.bytes); for (j = 0; j != nframes; j++){ int ret; /* Decode frame */ ret = speex_decode_int(st, &bits, output); if (ret == -1) break; if (ret == -2) break; if (speex_bits_remaining(&bits) < 0) break; if (channels == 2) speex_decode_stereo_int(output, frame_size, stereo); if (frame_size > 0) { spx_int16_t *frame_start = output + lookahead; if (channels == 2) frame_start += lookahead; ci->pcmbuf_insert(frame_start, NULL, frame_size - lookahead); lookahead = 0; /* 2 bytes/sample */ cur_granule += frame_size / 2; ci->set_offset((long) ci->curpos); ci->set_elapsed((samplerate == 0) ? 0 : cur_granule * 1000 / samplerate); } } } packet_count++; } } } error = CODEC_OK; done: /* Clean things up for the next track */ speex_bits_destroy(&bits); if (st) speex_decoder_destroy(st); if (stream_init) spx_ogg_stream_destroy(&os); spx_ogg_sync_destroy(&oy); exit: return error; }
Result HcdSumbitControlMessage(struct UsbDevice *device, struct UsbPipeAddress pipe, void* buffer, u32 bufferLength, struct UsbDeviceRequest *request) { Result result; struct UsbPipeAddress tempPipe; if (pipe.Device == RootHubDeviceNumber) { return HcdProcessRootHubMessage(device, pipe, buffer, bufferLength, request); } device->Error = Processing; device->LastTransfer = 0; // Setup tempPipe.Speed = pipe.Speed; tempPipe.Device = pipe.Device; tempPipe.EndPoint = pipe.EndPoint; tempPipe.MaxSize = pipe.MaxSize; tempPipe.Type = Control; tempPipe.Direction = Out; if ((result = HcdChannelSendWait(device, &tempPipe, 0, request, 8, request, Setup)) != OK) { LOGF("HCD: Could not send SETUP to %s.\n", UsbGetDescription(device)); return OK; } // Data if (buffer != NULL) { if (pipe.Direction == Out) { MemoryCopy(databuffer, buffer, bufferLength); } tempPipe.Speed = pipe.Speed; tempPipe.Device = pipe.Device; tempPipe.EndPoint = pipe.EndPoint; tempPipe.MaxSize = pipe.MaxSize; tempPipe.Type = Control; tempPipe.Direction = pipe.Direction; if ((result = HcdChannelSendWait(device, &tempPipe, 0, databuffer, bufferLength, request, Data1)) != OK) { LOGF("HCD: Could not send DATA to %s.\n", UsbGetDescription(device)); return OK; } ReadBackReg(&Host->Channel[0].TransferSize); if (pipe.Direction == In) { if (Host->Channel[0].TransferSize.TransferSize <= bufferLength) device->LastTransfer = bufferLength - Host->Channel[0].TransferSize.TransferSize; else{ LOG_DEBUGF("HCD: Weird transfer.. %d/%d bytes received.\n", Host->Channel[0].TransferSize.TransferSize, bufferLength); LOG_DEBUGF("HCD: Message %02x%02x%02x%02x %02x%02x%02x%02x %02x%02x%02x%02x %02x%02x%02x%02x ...\n", ((u8*)databuffer)[0x0],((u8*)databuffer)[0x1],((u8*)databuffer)[0x2],((u8*)databuffer)[0x3], ((u8*)databuffer)[0x4],((u8*)databuffer)[0x5],((u8*)databuffer)[0x6],((u8*)databuffer)[0x7], ((u8*)databuffer)[0x8],((u8*)databuffer)[0x9],((u8*)databuffer)[0xa],((u8*)databuffer)[0xb], ((u8*)databuffer)[0xc],((u8*)databuffer)[0xd],((u8*)databuffer)[0xe],((u8*)databuffer)[0xf]); device->LastTransfer = bufferLength; } MemoryCopy(buffer, databuffer, device->LastTransfer); } else { device->LastTransfer = bufferLength; } } // Status tempPipe.Speed = pipe.Speed; tempPipe.Device = pipe.Device; tempPipe.EndPoint = pipe.EndPoint; tempPipe.MaxSize = pipe.MaxSize; tempPipe.Type = Control; tempPipe.Direction = ((bufferLength == 0) || pipe.Direction == Out) ? In : Out; if ((result = HcdChannelSendWait(device, &tempPipe, 0, databuffer, 0, request, Data1)) != OK) { LOGF("HCD: Could not send STATUS to %s.\n", UsbGetDescription(device)); return OK; } ReadBackReg(&Host->Channel[0].TransferSize); if (Host->Channel[0].TransferSize.TransferSize != 0) LOG_DEBUGF("HCD: Warning non zero status transfer! %d.\n", Host->Channel[0].TransferSize.TransferSize); device->Error = NoError; return OK; }
static void periodic_task() { nrk_sig_mask_t wait_mask, func_wait_mask; nrk_time_t next_event, func_next_event; periodic_func_t **funcp; periodic_func_t *func; nrk_time_t now, sleep_time; int8_t rc; funcp = &functions[0]; while (*funcp) { func = *funcp; LOG("init: "); LOGF(func->name); LOGNL(); if (func->init) func->init(); funcp++; } rc = nrk_signal_register(func_signal); if (rc == NRK_ERROR) ABORT("reg sig: func\r\n"); while (1) { LOG("awake\r\n"); TIME_CLEAR(next_event); wait_mask = SIG(func_signal); funcp = &functions[0]; while (*funcp) { func = *funcp; TIME_CLEAR(func_next_event); func_wait_mask = 0; if (func->enabled || func->enabled != func->last_enabled) { LOG("proc: "); LOGF(func->name); LOGNL(); ASSERT(func->proc); func->proc(func->enabled, &func_next_event, &func_wait_mask); } func->last_enabled = func->enabled; wait_mask |= func_wait_mask; if (IS_VALID_TIME(func_next_event) && (!IS_VALID_TIME(next_event) || time_cmp(&func_next_event, &next_event) < 0)) { next_event = func_next_event; } funcp++; } if (IS_VALID_TIME(next_event)) { nrk_time_get(&now); rc = nrk_time_sub(&sleep_time, next_event, now); if (rc != NRK_OK) { LOG("next event in the past\r\n"); continue; } LOG("sleeping for: "); LOGP("%lu ms\r\n", TIME_TO_MS(sleep_time)); nrk_set_next_wakeup(sleep_time); wait_mask |= SIG(nrk_wakeup_signal); } LOG("waiting\r\n"); nrk_event_wait( wait_mask ); } ABORT("periodic task exited\r\n"); }
BOOL vrdpDrvRealizeBrush(BRUSHOBJ *pbo, SURFOBJ *psoTarget, SURFOBJ *psoPattern, SURFOBJ *psoMask, XLATEOBJ *pxlo, ULONG iHatch) { BOOL bRc = FALSE; LOGF(("psoMask = %p, iHatch = %d", psoMask, iHatch)); VBoxDispDumpPSO(psoPattern, "psoPattern"); if (psoPattern && psoPattern->sizlBitmap.cx == 8 && psoPattern->sizlBitmap.cy == 8 && psoPattern->iBitmapFormat == 1 ) { uint32_t cbBrush = sizeof (VRDPBRUSH); VRDPBRUSH *pBrush = (VRDPBRUSH *)BRUSHOBJ_pvAllocRbrush (pbo, cbBrush); LOG(("pattern pBrush = %p, size = %d", pBrush, cbBrush)); if (pBrush) { int i; uint8_t *pu8Bits = (uint8_t *)psoPattern->pvScan0; for (i = 0; i < 8; i++) { pBrush->u.pat.au8Pattern[i] = *pu8Bits; pu8Bits += psoPattern->lDelta; } /* Obtain RGB values for the brush fore and background colors: * "should translate color zero through the XLATEOBJ to get the foreground color for the brush." */ pBrush->u.pat.rgbFG = vrdpColor2RGB (psoTarget, pxlo->pulXlate[0]); pBrush->u.pat.rgbBG = vrdpColor2RGB (psoTarget, pxlo->pulXlate[1]); pBrush->fPattern = TRUE; bRc = TRUE; } } #if 0 else if (psoPattern) { /* Color brushes and brushes >8x8 are cached and MEMBLT order generated. */ uint32_t cbBrush = sizeof (VRDPBRUSH) + psoTarget->sizlBitmap.cx * sizeof (uint32_t) * psoTarget->sizlBitmap.cy; ??? target VRDPBRUSH *pBrush = (VRDPBRUSH *)BRUSHOBJ_pvAllocRbrush (pbo, cbBrush); LOG(("bitmap pBrush = %p, size = %d", pBrush, cbBrush)); if (pBrush) { /* Byte per pattern pixel. */ uint32_t cbSrcBPP = format2BytesPerPixel(psoPattern); /* Source bits scanline pointer. */ uint8_t *pu8BitsSrcScanLine = (uint8_t *)psoPattern->pvScan0; /* Target RGB pixel pointer. */ uint32_t *pu32BitsDst = &pBrush->u.bitmap.au32Bits[0]; int y; for (y = 0; y < psoTarget->sizlBitmap.cy; y++, pu8BitsSrcScanLine += psoPattern->lDelta) { uint8_t *pu8BitsSrc = pu8BitsSrcScanLine; int x; for (x = 0; x < psoTarget->sizlBitmap.cx; x++, pu8BitsSrc += cbSrcBPP) { uint32_t color = 0; memcpy (&color, pu8BitsSrc, cbSrcBPP); if (pxlo) { color = XLATEOBJ_iXlate (pxlo, color); } *pu32BitsDst++ = vrdpColor2RGB (psoTarget, color); /* LOG(("%08X", pu32BitsDst[-1])); */ } } pBrush->u.bitmap.w = (uint16_t)psoTarget->sizlBitmap.cx; pBrush->u.bitmap.h = (uint16_t)psoTarget->sizlBitmap.cy; pBrush->fPattern = FALSE; bRc = TRUE; } }