KW_Widget * KW_CreateFrame(KW_GUI * gui, KW_Widget * parent, const KW_Rect * geometry) { KW_Frame * frame = AllocFrame(); KW_Widget * widget = KW_CreateWidget(gui, parent, KW_WIDGETTYPE_FRAME, geometry, PaintFrame, DestroyFrame, frame); KW_AddWidgetGeometryChangeHandler(widget, FrameGeometryChanged); RenderFrame(widget); return widget; }
void Video::OpenFile(const char name[],int row, int col){ V_fileStream=fopen(name,"rb"); if(!V_fileStream){ cout << "Erro ao abrir o arquivo aqui" << endl; } setNumberOfFrames(row,col); AllocFrame(); }
int VMFrameStack::Call(VMFunction *func, VMValue *params, int numparams, VMReturn *results, int numresults, VMException **trap) { bool allocated = false; try { if (func->Native) { return static_cast<VMNativeFunction *>(func)->NativeCall(this, params, numparams, results, numresults); } else { AllocFrame(static_cast<VMScriptFunction *>(func)); allocated = true; VMFillParams(params, TopFrame(), numparams); int numret = VMExec(this, static_cast<VMScriptFunction *>(func)->Code, results, numresults); PopFrame(); return numret; } } catch (VMException *exception) { if (allocated) { PopFrame(); } if (trap != NULL) { *trap = exception; return -1; } throw; } catch (...) { if (allocated) { PopFrame(); } throw; } }
ssize_t CamBufferingDeframer::Write(const void *buffer, size_t size) { uint8 *b; int l; int i, s, e; int which; fMinFrameSize = fDevice->MinRawFrameSize(); fMaxFrameSize = fDevice->MaxRawFrameSize(); IB.Write(buffer, size); b = (uint8 *)IB.Buffer(); l = IB.BufferLength(); PRINT((CH "(%p, %d), IB: %d" CT, buffer, size, IB.BufferLength())); if (l < (int)(fMinFrameSize + fSkipSOFTags + fSkipEOFTags)) return size; // not enough data anyway if (!fCurrentFrame) { BAutolock l(fLocker); if (fFrames.CountItems() < MAXFRAMEBUF) fCurrentFrame = AllocFrame(); else { PRINT((CH "DROPPED %d bytes! (too many queued frames)" CT, size)); return size; // drop XXX } } for (s = 0; (l - s > (int)fMinFrameSize) && ((i = FindSOF(b + s, l - fMinFrameSize - s, &which)) > -1); s++) { s += i; if ((int)(s + fSkipSOFTags + fMinFrameSize + fSkipEOFTags) > l) break; if (!fDevice->ValidateStartOfFrameTag(b + s, fSkipSOFTags)) continue; PRINT((CH ": SOF[%d] at offset %d" CT, which, s)); PRINT((CH ": SOF: ... %02x %02x %02x %02x %02x %02x" CT, b[s+6], b[s+7], b[s+8], b[s+9], b[s+10], b[s+11])); for (e = s + fSkipSOFTags + fMinFrameSize; ((e <= (int)(s + fSkipSOFTags + fMaxFrameSize)) && (e < l) && ((i = 0*FindEOF(b + e, l - e, &which)) > -1)); e++) { e += i; //PRINT((CH ": EOF[%d] at offset %d" CT, which, s)); if (!fDevice->ValidateEndOfFrameTag(b + e, fSkipEOFTags, e - s - fSkipSOFTags)) continue; PRINT((CH ": SOF= ... %02x %02x %02x %02x %02x %02x" CT, b[s+6], b[s+7], b[s+8], b[s+9], b[s+10], b[s+11])); // we have one! s += fSkipSOFTags; // fill it fCurrentFrame->Write(b + s, e - s); // queue it BAutolock f(fLocker); PRINT((CH ": Detaching a frame (%d bytes, %d to %d / %d)" CT, (size_t)fCurrentFrame->Position(), s, e, l)); fCurrentFrame->Seek(0LL, SEEK_SET); fFrames.AddItem(fCurrentFrame); release_sem(fFrameSem); // next Write() will allocate a new one fCurrentFrame = NULL; // discard the frame and everything before it. DiscardFromInput(e + fSkipEOFTags); return size; } } return size; }
ssize_t CamStreamingDeframer::Write(const void *buffer, size_t size) { int i = -1; int j; int end = size; int which; const uint8 *buf = (const uint8 *)buffer; int bufsize = size; bool detach = false; bool discard = false; //PRINT((CH "(%p, %d); state=%s framesz=%u queued=%u" CT, buffer, size, (fState==ST_SYNC)?"sync":"frame", (size_t)(fCurrentFrame?(fCurrentFrame->Position()):-1), (size_t)fInputBuff.Position())); if (!fCurrentFrame) { BAutolock l(fLocker); if (fFrames.CountItems() < MAXFRAMEBUF) fCurrentFrame = AllocFrame(); else { PRINT((CH "DROPPED %d bytes! (too many queued frames)" CT, size)); return size; // drop XXX } } // update in case resolution changed fMinFrameSize = fDevice->MinRawFrameSize(); fMaxFrameSize = fDevice->MaxRawFrameSize(); if (fInputBuff.Position()) { // residual data ? append to it fInputBuff.Write(buffer, size); // and use it as input buf buf = (uint8 *)fInputBuff.Buffer(); bufsize = fInputBuff.BufferLength(); end = bufsize; } // whole buffer belongs to a frame, simple if ((fState == ST_FRAME) && (fCurrentFrame->Position() + bufsize < fMinFrameSize)) { // no residual data, and fCurrentFrame->Write(buf, bufsize); fInputBuff.Seek(0LL, SEEK_SET); fInputBuff.SetSize(0); return size; } // waiting for a frame... if (fState == ST_SYNC) { i = 0; while ((j = FindSOF(buf+i, bufsize-i, &which)) > -1) { i += j; if (fDevice->ValidateStartOfFrameTag(buf+i, fSkipSOFTags)) break; i++; } // got one if (j >= 0) { PRINT((CH ": SOF[%d] at offset %d" CT, which, i)); //PRINT((CH ": SOF: ... %02x %02x %02x %02x %02x %02x" CT, buf[i+6], buf[i+7], buf[i+8], buf[i+9], buf[i+10], buf[i+11])); int start = i + fSkipSOFTags; buf += start; bufsize -= start; end = bufsize; fState = ST_FRAME; } } // check for end of frame if (fState == ST_FRAME) { #if 0 int j, k; i = -1; k = 0; while ((j = FindEOF(buf + k, bufsize - k, &which)) > -1) { k += j; //PRINT((CH "| EOF[%d] at offset %d; pos %Ld" CT, which, k, fCurrentFrame->Position())); if (fCurrentFrame->Position()+k >= fMinFrameSize) { i = k; break; } k++; if (k >= bufsize) break; } #endif #if 1 i = 0; if (fCurrentFrame->Position() < fMinFrameSize) { if (fCurrentFrame->Position() + bufsize >= fMinFrameSize) i = (fMinFrameSize - (size_t)fCurrentFrame->Position()); else i = bufsize; } PRINT((CH ": checking for EOF; bufsize=%d i=%d" CT, bufsize, i)); if (i + (int)fSkipEOFTags > bufsize) { // not enough room to check for EOF, leave it for next time end = i; i = -1; // don't detach yet } else { PRINT((CH ": EOF? %02x [%02x %02x %02x %02x] %02x" CT, buf[i-1], buf[i], buf[i+1], buf[i+2], buf[i+3], buf[i+4])); while ((j = FindEOF(buf + i, bufsize - i, &which)) > -1) { i += j; PRINT((CH "| EOF[%d] at offset %d; pos %Ld" CT, which, i, fCurrentFrame->Position())); if (fCurrentFrame->Position()+i >= fMaxFrameSize) { // too big: discard //i = -1; discard = true; break; } if (fDevice->ValidateEndOfFrameTag(buf+i, fSkipEOFTags, fCurrentFrame->Position()+i)) break; i++; if (i >= bufsize) { i = -1; break; } } if (j < 0) i = -1; } #endif if (i >= 0) { PRINT((CH ": EOF[%d] at offset %d" CT, which, i)); end = i; detach = true; } PRINT((CH ": writing %d bytes" CT, end)); if (end <= bufsize) fCurrentFrame->Write(buf, end); if (fCurrentFrame->Position() > fMaxFrameSize) { fCurrentFrame->SetSize(fMaxFrameSize); detach = true; } if (detach) { BAutolock f(fLocker); PRINT((CH ": Detaching a frame (%d bytes, end = %d, )" CT, (size_t)fCurrentFrame->Position(), end)); fCurrentFrame->Seek(0LL, SEEK_SET); if (discard) { delete fCurrentFrame; } else { fFrames.AddItem(fCurrentFrame); release_sem(fFrameSem); } fCurrentFrame = NULL; if (fFrames.CountItems() < MAXFRAMEBUF) { fCurrentFrame = AllocFrame(); } fState = ST_SYNC; } } // put the remainder in input buff, discarding old data #if 0 fInputBuff.Seek(0LL, SEEK_SET); if (bufsize - end > 0) fInputBuff.Write(buf+end, bufsize - end); #endif BMallocIO m; m.Write(buf+end, bufsize - end); fInputBuff.Seek(0LL, SEEK_SET); if (bufsize - end > 0) fInputBuff.Write(m.Buffer(), bufsize - end); fInputBuff.SetSize(bufsize - end); return size; }
int VMFrameStack::Call(VMFunction *func, VMValue *params, int numparams, VMReturn *results, int numresults, VMException **trap) { bool allocated = false; try { if (func->Native) { return static_cast<VMNativeFunction *>(func)->NativeCall(this, params, numparams, results, numresults); } else { AllocFrame(static_cast<VMScriptFunction *>(func)); allocated = true; VMFillParams(params, TopFrame(), numparams); int numret = VMExec(this, static_cast<VMScriptFunction *>(func)->Code, results, numresults); PopFrame(); return numret; } } catch (VMException *exception) { if (allocated) { PopFrame(); } if (trap != NULL) { *trap = exception; return -1; } throw; } catch (EVMAbortException exception) { if (allocated) { PopFrame(); } if (trap != nullptr) { *trap = nullptr; } Printf("VM execution aborted: "); switch (exception) { case X_READ_NIL: Printf("tried to read from address zero."); break; case X_WRITE_NIL: Printf("tried to write to address zero."); break; case X_TOO_MANY_TRIES: Printf("too many try-catch blocks."); break; case X_ARRAY_OUT_OF_BOUNDS: Printf("array access out of bounds."); break; case X_DIVISION_BY_ZERO: Printf("division by zero."); break; case X_BAD_SELF: Printf("invalid self pointer."); break; } Printf("\n"); return -1; } catch (...) { if (allocated) { PopFrame(); } throw; } }