void VDUIListViewW32::AddColumn(const wchar_t *name, int width, int affinity) { VDASSERT(affinity >= 0); VDASSERT(width >= 0); if (VDIsWindowsNT()) { LVCOLUMNW lvcw={0}; lvcw.mask = LVCF_TEXT | LVCF_WIDTH; lvcw.pszText = (LPWSTR)name; lvcw.cx = width; SendMessageW(mhwnd, LVM_INSERTCOLUMNW, mColumns.size(), (LPARAM)&lvcw); } else { LVCOLUMNA lvca={0}; VDStringA nameA(VDTextWToA(name)); lvca.mask = LVCF_TEXT | LVCF_WIDTH; lvca.pszText = (LPSTR)nameA.c_str(); lvca.cx = width; SendMessageA(mhwnd, LVM_INSERTCOLUMNA, mColumns.size(), (LPARAM)&lvca); } mColumns.push_back(Column()); Column& col = mColumns.back(); col.mWidth = width; col.mAffinity = affinity; mTotalWidth += width; mTotalAffinity += affinity; OnResize(); }
void VDAVIReadIndex::AddChunk(sint64 bytePos, uint32 sizeAndKeyFrameFlag) { SectorEntry *sec = &mSectors.back(); // Note: Some (perhaps broken) AVI files have chunks out of order in the index. In // that case, we must force a new sector. if ((uint64)(bytePos - sec->mByteOffset) >= (uint64)0x100000000 || mSampleCount - sec->mChunkOffset >= 0x10000) { sec = &mSectors.push_back(); sec->mByteOffset = bytePos; sec->mSampleOffset = mSampleCount; sec->mChunkOffset = mChunkCount; sec->mbOneSamplePerChunk = true; ++mSectorCount; } if (mIndex.empty() || mBlockOffset >= kBlockSize) { IndexEntry *newBlock = new IndexEntry[kBlockSize]; try { mIndex.push_back(newBlock); } catch(...) { delete[] newBlock; throw; } mBlockOffset = 0; } if ((sint32)sizeAndKeyFrameFlag < 0) mPrevKey = mChunkCount; IndexEntry& ient = mIndex.back()[mBlockOffset++]; ient.mByteOffset = (uint32)bytePos - (uint32)sec->mByteOffset; ient.mSampleOffset = (uint32)mSampleCount - (uint32)sec->mSampleOffset; ient.mSizeAndKeyFrameFlag = sizeAndKeyFrameFlag; ient.mPrevKeyDistance = VDClampToUint16(mChunkCount - mPrevKey); ient.mUnused0 = 0; VDASSERT(ient.mByteOffset + sec->mByteOffset == bytePos); VDASSERT(ient.mSampleOffset + sec->mSampleOffset == mSampleCount); uint32 chunkSize = sizeAndKeyFrameFlag & 0x7FFFFFFF; if (mSampleSize) { uint32 roundedUpSize = chunkSize + (mSampleSize - 1); uint32 sampleCountInChunk = roundedUpSize / mSampleSize; if (chunkSize % mSampleSize) mbVBR = true; mSampleCount += sampleCountInChunk; if (sampleCountInChunk != 1) sec->mbOneSamplePerChunk = false; } else ++mSampleCount; ++mChunkCount; mByteCount += chunkSize; }
void FilterAddBuiltin(const FilterDefinition *pfd) { VDASSERT(!pfd->stringProc || pfd->stringProc2); VDASSERT(!pfd->copyProc || pfd->copyProc2); vdautoptr<FilterDefinitionInstance> fdi(new FilterDefinitionInstance(NULL)); fdi->Assign(*pfd, sizeof(FilterDefinition)); g_filterDefs.AddTail(fdi.release()); }
void VDScriptInterpreter::ExecuteLine(const char *s) { int t; mErrorExtraToken.clear(); TokenBegin(s); while(t = Token()) { if (isExprFirstToken(t)) { TokenUnput(t); VDASSERT(mStack.empty()); ParseExpression(); VDASSERT(!mStack.empty()); VDScriptValue& val = mStack.back(); mStack.pop_back(); VDASSERT(mStack.empty()); if (Token() != ';') SCRIPT_ERROR(SEMICOLON_EXPECTED); } else if (t == TOK_DECLARE) { do { t = Token(); if (t != TOK_IDENT) SCRIPT_ERROR(IDENTIFIER_EXPECTED); VariableTableEntry *vte = vartbl.Declare(szIdent); t = Token(); if (t == '=') { ParseExpression(); VDASSERT(!mStack.empty()); vte->v = mStack.back(); mStack.pop_back(); t = Token(); } } while(t == ','); if (t != ';') SCRIPT_ERROR(SEMICOLON_EXPECTED); } else SCRIPT_ERROR(PARSE_ERROR); } VDASSERT(mStack.empty()); GC(); }
bool BitBltFromRGBToRGB(int w, int h, BYTE* dst, int dstpitch, int dbpp, BYTE* src, int srcpitch, int sbpp) { VDPixmap srcbm = { (char *)src + srcpitch * (h - 1), NULL, w, h, -srcpitch }; switch(sbpp) { case 8: srcbm.format = nsVDPixmap::kPixFormat_Pal8; break; case 16: srcbm.format = nsVDPixmap::kPixFormat_RGB565; break; case 24: srcbm.format = nsVDPixmap::kPixFormat_RGB888; break; case 32: srcbm.format = nsVDPixmap::kPixFormat_XRGB8888; break; default: VDASSERT(false); } VDPixmap dstpxm = { (char *)dst + dstpitch * (h - 1), NULL, w, h, -dstpitch }; switch(dbpp) { case 8: dstpxm.format = nsVDPixmap::kPixFormat_Pal8; break; case 16: dstpxm.format = nsVDPixmap::kPixFormat_RGB565; break; case 24: dstpxm.format = nsVDPixmap::kPixFormat_RGB888; break; case 32: dstpxm.format = nsVDPixmap::kPixFormat_XRGB8888; break; default: VDASSERT(false); } return VDPixmapBlt(dstpxm, srcbm); }
bool BitBltFromRGBToRGBStretch(int dstw, int dsth, BYTE* dst, int dstpitch, int dbpp, int srcw, int srch, BYTE* src, int srcpitch, int sbpp) { VDPixmap srcbm = { src + srcpitch * (srch - 1), nullptr, srcw, srch, -srcpitch }; switch (sbpp) { case 8: srcbm.format = nsVDPixmap::kPixFormat_Pal8; break; case 16: srcbm.format = nsVDPixmap::kPixFormat_RGB565; break; case 24: srcbm.format = nsVDPixmap::kPixFormat_RGB888; break; case 32: srcbm.format = nsVDPixmap::kPixFormat_XRGB8888; break; default: VDASSERT(false); } VDPixmap dstpxm = { dst + dstpitch * (dsth - 1), nullptr, dstw, dsth, -dstpitch }; switch (dbpp) { case 8: dstpxm.format = nsVDPixmap::kPixFormat_Pal8; break; case 16: dstpxm.format = nsVDPixmap::kPixFormat_RGB565; break; case 24: dstpxm.format = nsVDPixmap::kPixFormat_RGB888; break; case 32: dstpxm.format = nsVDPixmap::kPixFormat_XRGB8888; break; default: VDASSERT(false); } return VDPixmapStretchBltBilinear(dstpxm, srcbm); }
void VDDestroyFunctionThunk(VDFunctionThunk *pFnThunk) { // validate thunk #if defined(_M_IX86) VDASSERT(((const uint8 *)pFnThunk)[0] == 0xB9 || ((const uint8 *)pFnThunk)[0] == 0xE8); VDFreeThunkMemory(pFnThunk, 16); #elif defined(_M_AMD64) VDFreeThunkMemory(pFnThunk, 44); #else VDASSERT(false); #endif }
void VDStringW::reserve_slow(size_type n, size_type current_capacity) { VDASSERT(current_capacity == (size_type)(mpEOS - mpBegin)); VDASSERT(n > current_capacity); size_type current_size = (size_type)(mpEnd - mpBegin); value_type *s = new value_type[n + 1]; memcpy(s, mpBegin, (current_size + 1) * sizeof(value_type)); if (mpBegin != sNull) delete[] mpBegin; mpBegin = s; mpEnd = s + current_size; mpEOS = s + n; }
bool VDMPEGCache::Read(void *pData, int64 bytepos, int len, int offset) { VDASSERTPTR(this); VDASSERTPTR(pData); VDASSERT(bytepos != 0); VDASSERT(len > 0); if (mpCacheMemory) { int nBlocks = mCacheBlocks.size(); for(int i=0; i<nBlocks; ++i) { if (mCacheBlocks[i].pos == bytepos) { ++mNextAgeValue; // VDDEBUG2("Cache hit : %16I64x + %-5d (%5d)\n", bytepos, offset, len); while(len > 0) { VDASSERT(i>=0); int blen = mCacheBlocks[i].len - offset; if (blen > len) blen = len; VDASSERT(blen > 0); memcpy(pData, mpCacheMemory + mBlockSize * i + offset, blen); pData = (char *)pData + blen; len -= blen; mCacheBlocks[i].age = mNextAgeValue; i = mCacheBlocks[i].next; offset = 0; } VDASSERT(!len); return true; } } } // VDDEBUG2("Cache miss : %16I64x + %-5d (%5d)\n", bytepos, offset, len); return false; }
bool VDVideoDisplayMinidriverOpenGL::Update(UpdateMode mode) { if (!mGL.IsInited()) return false; if (!mSource.pixmap.data) return false; if (HDC hdc = GetDC(mhwndOGL)) { if (mGL.Begin(hdc)) { VDASSERT(mGL.glGetError() == GL_NO_ERROR); if (mSource.bInterlaced) { uint32 fieldmode = (mode & kModeFieldMask); if (fieldmode == kModeAllFields || fieldmode == kModeEvenField) { VDPixmap evenFieldSrc(mSource.pixmap); evenFieldSrc.h = (evenFieldSrc.h+1) >> 1; evenFieldSrc.pitch += evenFieldSrc.pitch; Upload(evenFieldSrc, mTexPattern[0]); } if (fieldmode == kModeAllFields || fieldmode == kModeOddField) { VDPixmap oddFieldSrc(mSource.pixmap); oddFieldSrc.data = (char *)oddFieldSrc.data + oddFieldSrc.pitch; oddFieldSrc.h = (oddFieldSrc.h+1) >> 1; oddFieldSrc.pitch += oddFieldSrc.pitch; Upload(oddFieldSrc, mTexPattern[1]); }
VDStreamInterleaver::Action VDStreamInterleaver::GetNextAction(int& streamID, sint32& samples) { const int nStreams = mStreams.size(); if (!mActiveStreams) return kActionFinish; for(;;) { if (!mNextStream) { Action act = PushStreams(); if (act != kActionWrite) return act; } for(; mNextStream<nStreams; ++mNextStream) { Stream& streaminfo = mStreams[mNextStream]; if (!mbInterleavingEnabled && mNextStream > mNonIntStream) break; if (streaminfo.mSamplesToWrite > 0) { samples = streaminfo.mSamplesToWrite; if (samples > streaminfo.mMaxPush) samples = streaminfo.mMaxPush; streaminfo.mSamplesToWrite -= samples; streamID = mNextStream; VDASSERT(samples < 2147483647); streaminfo.mSamplesWrittenToSegment += samples; return kActionWrite; } } mNextStream = 0; } }
bool VDAudioOutputWaveOutW32::Flush() { if (mCurState == kStateOpened) { if (!Start()) return false; } if (mBlockWriteOffset <= 0) return true; WAVEHDR& hdr = mHeaders[mBlockTail]; hdr.dwBufferLength = mBlockWriteOffset; hdr.dwFlags &= ~WHDR_DONE; MMRESULT res = waveOutWrite(mhWaveOut, &hdr, sizeof hdr); mBytesQueued += mBlockWriteOffset; mBlockWriteOffset = 0; if (res != MMSYSERR_NOERROR) return false; ++mBlockTail; if (mBlockTail >= mBlockCount) mBlockTail = 0; ++mBlocksPending; VDASSERT(mBlocksPending <= mBlockCount); return true; }
int VDUIComboBoxW32::GetItemCount() { LRESULT lr = SendMessage(mhwnd, CB_GETCOUNT, 0, 0); VDASSERT(lr != CB_ERR); return (lr == CB_ERR) ? 0 : (int)lr; }
uint32 VDAudioFilterGain::Run() { VDAudioFilterPin& pin = *mpContext->mpInputs[0]; const VDXWaveFormat& format = *pin.mpFormat; // compute output samples int samples = mpContext->mCommonSamples; sint16 *dst = (sint16 *)mpContext->mpOutputs[0]->mpBuffer; if (!samples) { if (pin.mbEnded && !mpContext->mInputSamples) return kVFARun_Finished; return 0; } // read buffer unsigned count = format.mChannels * samples; int actual_samples = mpContext->mpInputs[0]->Read(dst, samples, false, kVFARead_PCM16); VDASSERT(actual_samples == samples); for(unsigned i=0; i<count; ++i) { sint32 v = ((sint32)dst[i] * mScale16 + 0x800080) >> 8; if ((uint32)v >= 0x10000) v = ~v >> 31; dst[i] = (sint16)(v - 0x8000); } mpContext->mpOutputs[0]->mSamplesWritten = samples; return 0; }
bool VDRegistryProviderMemory::Key::RemoveKey(const char *name) { if (!name) name = ""; // look up the subkey KeyMap::iterator it(mKeyMap.find_as(name)); // fail if not found if (it != mKeyMap.end()) return false; // can't delete key if it has subkeys Key& key = it->second; if (!key.mKeyList.empty()) return false; // if the key is open, we have to condemn it and delete it later if (key.mRefCount) { key.mbCondemned = true; return true; } // delete the key mKeyMap.erase(it); KeyList::iterator it2(std::find(mKeyList.begin(), mKeyList.end(), &*it)); VDASSERT(it2 != mKeyList.end()); mKeyList.erase(it2); return true; }
int VDUIListBoxW32::GetItemCount() { LRESULT lr = SendMessage(mhwnd, LB_GETCOUNT, 0, 0); VDASSERT(lr != LB_ERR); return lr == LB_ERR ? 0 : (int)lr; }
void VDUIOptionW32::SetValue(int i) { VDASSERT(!mpBaseOption); if (i >= mnItems) i = mnItems - 1; if (i < 0) i = 0; if (mnSelected != i) { mnSelected = i; mpBase->ProcessValueChange(this, mID); if (mhwnd) { // change me SendMessage(mhwnd, BM_SETCHECK, (i==0) ? BST_CHECKED : BST_UNCHECKED, 0); // change others for(IVDUIWindow *win = this; win; win = mpParent->GetNextChild(win)) { VDUIOptionW32 *opt = vdpoly_cast<VDUIOptionW32 *>(win); if (opt && opt->mpBaseOption == this) SendMessage(opt->mhwnd, BM_SETCHECK, opt->mID - mID == i ? BST_CHECKED : BST_UNCHECKED, 0); } } } }
bool VDThread::ThreadStart() { VDASSERT(!isThreadAttached()); if (!isThreadAttached()) mhThread = (void *)_beginthreadex(NULL, 0, StaticThreadStart, this, 0, &mThreadID); return mhThread != 0; }
void VDFilterFrameBufferAccel::Init(VDFilterAccelEngine *accelEngine, uint32 width, uint32 height, uint32 borderWidth, uint32 borderHeight) { VDASSERT(width && height); mpAccelEngine = accelEngine; mWidth = width; mHeight = height; mBorderWidth = borderWidth; mBorderHeight = borderHeight; }
void VDScriptInterpreter::ConvertToRvalue() { VDASSERT(!mStack.empty()); VDScriptValue& val = mStack.back(); if (val.isVarLV()) val = val.asVarLV()->v; }
void VDEventBase::Remove(VDDelegate& dbase) { VDASSERT(dbase.mpPrev != &dbase); VDDelegateNode *next = dbase.mpNext; VDDelegateNode *prev = dbase.mpPrev; prev->mpNext = next; next->mpPrev = prev; dbase.mpPrev = dbase.mpNext = &dbase; }
void VDEventBase::Add(VDDelegate& dbase) { VDDelegateNode *next = mAnchor.mpNext; VDASSERT(dbase.mpPrev == &dbase); mAnchor.mpNext = &dbase; dbase.mpPrev = &mAnchor; dbase.mpNext = next; next->mpPrev = &dbase; }
const FilterDefinition& FilterDefinitionInstance::Attach() { VDASSERT(mAPIVersion); if (mpExtModule) mpExtModule->Lock(); ++mRefCount; return mDef; }
void VDStringW::resize_slow(size_type n, size_type current_size) { VDASSERT(n > current_size); size_type current_capacity = (size_type)(mpEOS - mpBegin); if (n > current_capacity) reserve_slow(n, current_capacity); mpEnd = mpBegin + n; *mpEnd = 0; }
bool VDAudioOutputDirectSoundW32::WriteAudio(uint32 offset, const void *data, uint32 bytes) { VDASSERT(offset < mDSBufferSize); VDASSERT(mDSBufferSize - offset >= bytes); LPVOID p1, p2; DWORD tc1, tc2; HRESULT hr = mpDSBuffer->Lock(offset, bytes, &p1, &tc1, &p2, &tc2, 0); if (FAILED(hr)) return false; memcpy(p1, data, tc1); data = (char *)data + tc1; memcpy(p2, data, tc2); data = (char *)data + tc2; mpDSBuffer->Unlock(p1, tc1, p2, tc2); return true; }
void VDStringA::resize_slow(size_type n, size_type current_size, value_type c) { VDASSERT(n > current_size); size_type current_capacity = (size_type)(mpEOS - mpBegin); if (n > current_capacity) reserve_slow(n, current_capacity); memset(mpBegin + current_size, c, n - current_size); mpEnd = mpBegin + n; *mpEnd = 0; }
void VDShutdownThunkAllocator() { while(g_VDJITAllocatorLock.xchg(1)) ::Sleep(1); VDASSERT(g_pVDJITAllocator); if (!g_pVDJITAllocator->Release()) g_pVDJITAllocator = NULL; VDVERIFY(1 == g_VDJITAllocatorLock.xchg(0)); }
void VDMPEGCache::Write(const void *pData, int64 bytepos, int len) { VDASSERTPTR(this); VDASSERTPTR(pData); VDASSERT(bytepos != 0); VDASSERT(len > 0); if (!mpCacheMemory || (size_t)len > mCacheBlocks.size()*mBlockSize) return; // VDDEBUG2("Cache store: %16I64x + (%5d)\n", bytepos, len); ++mNextAgeValue; int victim = Evict(), next_victim; while(len > 0) { int blen = mBlockSize>len ? mBlockSize : len; len -= blen; // Age must be set before next evict to avoid getting the same block // twice mCacheBlocks[victim].age = mNextAgeValue; next_victim = -1; if (len) next_victim = Evict(); memcpy(mpCacheMemory + mBlockSize*victim, pData, blen); mCacheBlocks[victim].pos = bytepos; mCacheBlocks[victim].len = blen; mCacheBlocks[victim].next = next_victim; // Only write out a non-zero byte position for the first block. bytepos = 0; pData = (char *)pData + blen; victim = next_victim; } }
bool VDThread::ThreadStart() { VDASSERT(!isThreadAttached()); if (!isThreadAttached()) { mhThread = (void *)_beginthreadex(NULL, 0, StaticThreadStart, this, 0, &mThreadID); if (mhThread && mThreadPriority != INT_MIN) ::SetThreadPriority(mhThread, mThreadPriority); } return mhThread != 0; }
void VDJITAllocator::Free(void *p, size_t len) { VDASSERT(p); VDASSERT(len < 0x10000); FreeChunks::iterator cur(mFreeChunks.lower_bound(p)); if (cur != mFreeChunks.end() && (char *)p + len == cur->first) { len += cur->second; if (mNextChunk == cur) ++mNextChunk; cur = mFreeChunks.erase(cur); } if (cur != mFreeChunks.begin()) { FreeChunks::iterator prev(cur); --prev; if ((char *)prev->first + prev->second == p) { p = prev->first; len += prev->second; if (mNextChunk == prev) ++mNextChunk; mFreeChunks.erase(prev); } } uintptr start = (size_t)p; uintptr end = start + len; if (!((start | end) & (mAllocationGranularity - 1))) { Allocations::iterator it(mAllocations.find(p)); if (it != mAllocations.end()) { VirtualFree((void *)start, 0, MEM_RELEASE); mAllocations.erase(it); return; } } mFreeChunks.insert(FreeChunks::value_type((void *)start, end-start)); }