int parse_up(char *qstrp, char *up, char *phon, char *name, char *last) { Dlog("parse_up"); char noalice[] = "Alice doesn't live here anymore!\n"; char havealice[] = "now lives here\n"; char upalice[] = "up2date\n"; int upbit = UPDATE; DEBUGfunch(parse_up); DEBUGd(upbit); DEBUGd(LOOKUP); /* if (phon == NULL) { Dlog("phoc is null"); Dmsg(upbit should be set to 1 now); upbit = LOOKUP; DEBUGd(upbit); } */ upbit = waz(up); DEBUGd(upbit); char myphon[] = "5143169147"; char *myphonp = myphon; if(upbit == LOOKUP) phon = myphonp; if (!(isfield(up, phon, name, last))) return -1; Dlog("after isfield"); char buf[MAX_QUERYS_LEN] = {0}; char *bufp = buf; qstrp = mk_btreel(qstrp, delim, upbit, phon, name, last); send_recv_2pbk_skt(qstrp, bufp); switch (upbit) { case LOOKUP: if ((buf[0] - '0') == 0) printf("%s", noalice); //tnode *retnode = l2node(bufp, delim); else printf("%s\n", bufp); break; case UPDATE: if ((buf[0] - '0') == 0) printf("%s %s %s", name, last, havealice); else printf("%s %s %s %s", name, last, phon, upalice); break; default: break; } return 0; }
/** * 完成与内存有关的初始化工作, 包括分配栈空间, 初始化注册表, 预分配 * 某些字符串资源(保留关键字等) */ static void f_luaopen (lua_State *L, void *ud) { Dlog("luaopen begin."); global_State *g = G(L); UNUSED(ud); stack_init(L, L); /* init stack */ init_registry(L, g); Dlog("ini size of string table with size %d", MINSTRTABSIZE); luaS_resize(L, MINSTRTABSIZE); /* initial size of string table */ luaT_init(L); luaX_init(L); /* pre-create memory-error message */ g->memerrmsg = luaS_newliteral(L, MEMERRMSG); luaC_fix(L, obj2gco(g->memerrmsg)); /* it should never be collected */ g->gcrunning = 1; /* allow gc */ g->version = lua_version(NULL); luai_userstateopen(L); Dlog("luaopen end."); }
HRESULT CGraphConnector::SetAllocatorProperties( int RequestedSize ) { if( m_pInputPin->IsConnected() ) { ALLOCATOR_PROPERTIES props; ALLOCATOR_PROPERTIES propsActual; HRESULT hr; IMemAllocator *InputAllocator; hr = m_pInputPin->GetAllocator( &InputAllocator ); if( hr != S_OK || InputAllocator == NULL ) { Dlog("Could not set allocator properties 1\n"); return S_FALSE; } hr = InputAllocator->GetProperties( &props ); if( hr != S_OK || props.cBuffers == 0 || props.cbBuffer == 0 ) { Dlog("Could not set allocator properties 2\n"); return S_FALSE; } //more like a hack. I found some http input stream that was sending larger then agreed media buffers //If we reject the too large packet then input will DC. If we pass on the large packet then probably the next PIN will DC. Hope for the best //video stream packet can be for VBR anything. For CBR the rule is to be 3xbitrate if( ( m_mMediaType.majortype == MEDIATYPE_Video || m_mMediaType.majortype == MEDIATYPE_Stream ) && props.cbBuffer < 1024 * 8 ) //less then 8k ? probably size is not set. We need to know the size props.cbBuffer = 1024 * 8 * 1024; //8 Mbit ? I really hope this will be enough props.cbBuffer = max( props.cbBuffer * 2, RequestedSize ); if( CONNECTOR_BUFFERS_UNTIL_LOCK > props.cBuffers ) props.cBuffers = CONNECTOR_BUFFERS_UNTIL_LOCK; hr = m_pAllocator->SetProperties( &props, &propsActual ); if( hr != S_OK ) { Dlog1("Could not set allocator properties 4 %p\n",this); return S_FALSE; } hr = m_pAllocator->Commit(); m_bBufferDecided = TRUE; } }
HRESULT CGraphConnector::GetAllocatorProperties( ALLOCATOR_PROPERTIES* pProperties ) { pProperties->cbAlign = 1; pProperties->cBuffers = 1; pProperties->cbBuffer = 1; //try to fetch latest still connected input PIN properties if( m_pInputPin->IsConnected() == true ) { HRESULT hr; IMemAllocator *InputAllocator; hr = m_pInputPin->GetAllocator( &InputAllocator ); if( hr != S_OK || InputAllocator == NULL ) { Dlog("Could not set allocator properties 1\n"); return S_FALSE; } hr = InputAllocator->GetProperties( pProperties ); if( hr != S_OK ) { Dlog("Could not set allocator properties 2\n"); return S_FALSE; } //try to fetch buffer properties from input. Update it, even if we already had a previous connection // GetAllocatorProperties function is called when the filters are getting connected //SetAllocatorProperties(); } //if right now input PIN is not connected then try to fetch our memorized properties else if( m_bBufferDecided == TRUE ) { m_pAllocator->GetProperties( pProperties ); } else { return S_FALSE; } return S_OK; }
/** * 创建主线程 和 gloable_state, 初始化其结构; 接着开始进行分配内存, 若分配 * 内存出错, 则 close 该 lua_state (以确保释放已分配的内存), 并返回 NULL. * * luaL_newstate 函数封装了这个函数,lauxlib.c 中提供了一个 lua_Alloc 函数 */ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) { int i; lua_State *L; global_State *g; LG *l = cast(LG *, (*f)(ud, NULL, LUA_TTHREAD, sizeof(LG))); if (l == NULL) return NULL; L = &l->l.l; g = &l->g; L->next = NULL; L->tt = LUA_TTHREAD; g->currentwhite = bitmask(WHITE0BIT); L->marked = luaC_white(g); preinit_thread(L, g); g->frealloc = f; g->ud = ud; g->mainthread = L; g->seed = makeseed(L); g->gcrunning = 0; /* no GC while building state */ g->GCestimate = 0; g->strt.size = g->strt.nuse = 0; g->strt.hash = NULL; setnilvalue(&g->l_registry); luaZ_initbuffer(L, &g->buff); g->panic = NULL; g->version = NULL; g->gcstate = GCSpause; g->gckind = KGC_NORMAL; g->allgc = g->finobj = g->tobefnz = g->fixedgc = NULL; g->sweepgc = NULL; g->gray = g->grayagain = NULL; g->weak = g->ephemeron = g->allweak = NULL; g->twups = NULL; g->totalbytes = sizeof(LG); g->GCdebt = 0; g->gcfinnum = 0; g->gcpause = LUAI_GCPAUSE; g->gcstepmul = LUAI_GCMUL; for (i=0; i < LUA_NUMTAGS; i++) g->mt[i] = NULL; if (luaD_rawrunprotected(L, f_luaopen, NULL) != LUA_OK) { /* memory allocation error: free partial state */ Dlog("lua state init error, free partial state.") close_state(L); L = NULL; } return L; }
char * mk_btreel(char *l, char *delim, int op, char *phon, char *name, char *last) { Dlog("mk_btreel"); switch (op) { case LOOKUP: l = strcpy(l, "1"); break; case UPDATE: l = strcpy(l, "3"); break; default: break; } l = strcat(l, delim); l = strcat(l, phon); l = strcat(l, delim); l = strcat(l, name); l = strcat(l, delim); l = strcat(l, last); return l; }
STDMETHODIMP CGraphConnector::Receive(IMediaSample *pSample) { //!!!make sure to be after buffer fetch or it will deadlock ! //!!!do not use Autolock // CAutoLock lock( &m_QueueLock ); #ifdef DEBUGGING_IN_TESTBENCH LONGLONG start,end; pSample->GetTime( &start, &end ); DlogVideo6("%d)Video input sample size %d for connector %p, queued %d, start %d, end %d\n", PacketCounterIn++, pSample->GetActualDataLength(), this, m_pSampleQueue[0].size(),(int)start,(int)end ); DlogAudio6("%d)Audio input sample size %d for connector %p, queued %d, start %d, end %d\n", PacketCounterIn++, pSample->GetActualDataLength(), this, m_pSampleQueue[0].size(),(int)start,(int)end ); #endif IMediaSample *pLocalSample = NULL; if( m_nAllocatorType == GCAT_USE_FROM_INPUT ) { pLocalSample = pSample; pLocalSample->AddRef(); } else if( m_nAllocatorType == GCAT_USE_INTERNAL ) { if( m_nAllocatorType == GCAT_USE_INTERNAL && m_bBufferDecided == FALSE ) SetAllocatorProperties(); if( m_bBufferDecided == FALSE ) { Dlog("Error : Could not set allocator properties 5\n"); return S_FALSE; } //!!! this can deadlock until fetchbuffer will release some buffers. Make sure to be outside of our list lock ! int RetryCount = 1; HRESULT hr; do{ hr = m_pAllocator->GetBuffer( &pLocalSample, NULL, NULL, 0 ); if( FAILED(hr) ) { Dlog("Error : Could not get free buffer to store sample! Should we block ?\n"); return hr; } // copy the input sample content into the local sample hr = CopySample( pSample, pLocalSample ); if ( hr != S_OK ) { pLocalSample->Release(); pLocalSample = NULL; HRESULT hr1 = IncreaseBufferSizeRuntime( pSample->GetActualDataLength() * 2 + 1024 ); if( hr1 != S_OK ) Dlog1("Error : Could not resize buffer pool, buffer sizes to %d\n", pSample->GetActualDataLength() + 1024); RetryCount--; } }while( hr != S_OK && RetryCount >= 0 ); if( hr != S_OK ) { Dlog("Error : Could not copy input into output buffer\n"); return S_OK; } } #ifdef DEBUGGING_IN_TESTBENCH /* DumpSampleInfo( pSample, this, " Connector input(from src) " ); if( pLocalSample != pSample ) DumpSampleInfo( pLocalSample, this, " Connector input(local pooled) " ); Dlog("Graph Connector received a media packet % d \n", PacketCounterIn++); */ #endif m_QueueLock.Lock(); if( m_Type == GCB_THROW_PACKET_UNLESS_OUTPUT_CONNECTED ) { for( int i=0;i<m_nNumOutputs;i++) if( m_pOutputPin[i]->IsConnected() == TRUE ) { pLocalSample->AddRef(); m_pSampleQueue[i].push_front( pLocalSample ); } } else if( m_Type == GCB_KEEP_PACKET_UNTIL_PUSHED ) { for( int i=0;i<m_nNumOutputs;i++) { pLocalSample->AddRef(); m_pSampleQueue[i].push_front( pLocalSample ); } } pLocalSample->Release(); m_QueueLock.Unlock(); return S_OK; }