AVObjects Library: Samples
From AVObjects Knowledge Base
(Difference between revisions)
m (moved Samples to AVObjects Library: Samples) |
Latest revision as of 11:28, 15 July 2014
This page is a copy of the original page on the AVObjects' web site and can also be viewed here.
TODO: Samples
HRESULT CMuxedPCM::ReadFrame(ULONGLONG ullFrame, BYTE* pbFrame, DWORD cbFrame, DWORD* pcbActual, LONG* plTempOffset/* = NULL*/, bool bReverse/* = false*/,DWORD nSkip /*= 0*/, bool bDirectRead/* = false*/) { ATLASSERT(pbFrame != NULL); if(pbFrame == NULL) return E_INVALIDARG; ATLASSERT(pcbActual != NULL); if(pcbActual == NULL) return E_INVALIDARG; DWORD cbFrameSize = GetFrameSize(); ATLASSERT(cbFrame >= cbFrameSize); if(cbFrame < cbFrameSize) return E_INVALIDARG; DWORD dwSourceCount = m_source.GetSize(); ATLASSERT(dwSourceCount > 0); if (dwSourceCount == 1) return m_source[0]->ReadFrame(ullFrame, pbFrame, cbFrame, pcbActual, plTempOffset, bReverse, nSkip, bDirectRead); CMType mt; HRESULT hr = FillMT(mt); if (hr != S_OK) return hr; ATLASSERT(mt.IsAudio()); const WAVEFORMATEX* pwf = mt; DWORD cbBuf = cbFrame / dwSourceCount; CMAlloc mem; if (!mem.Alloc(cbBuf)) return hr; BYTE* pbBuf = mem.Memory(); ATLASSERT(pbBuf); DWORD nBlockAlign = pwf->nBlockAlign / dwSourceCount; *pcbActual = 0; // ATLTRACE2(atlTraceGeneral, 2, _T("%s::ReadFrame(): ") // _T("MuxedReadStart: ullFrame = %I64u(0x%I64x), cbFrame = %d(0x%x)\n"), GetClassName(), ullFrame, ullFrame, // cbFrame, cbFrame); memset(pbFrame, 0, cbFrame); for(DWORD n = 0; n < dwSourceCount; n++) { DWORD cbActual = 0; hr = m_source[n]->ReadFrame(ullFrame, pbBuf, cbBuf, &cbActual, NULL, bReverse, nSkip, bDirectRead); if (hr != S_OK) return hr; if (cbActual > *pcbActual) *pcbActual = cbActual; BYTE* pbIn = pbBuf; BYTE* pbOut = pbFrame + nBlockAlign * n; BYTE* pbEnd = pbBuf + cbActual; for(; pbIn < pbEnd; pbIn += nBlockAlign, pbOut += pwf->nBlockAlign) { //DWORD cbLen = (pbIn + nBlockAlign >= pbEnd)? pbEnd - pbIn : nBlockAlign; memcpy(pbOut, pbIn, nBlockAlign); } } *pcbActual *= dwSourceCount; // ATLTRACE2(atlTraceGeneral, 2, _T("%s::ReadFrame(): ") // _T("MuxedReadAStop Actual: %d(0x%x)\n"), GetClassName(), *pcbActual, *pcbActual); // Debug_Dump(atlTraceGeneral, 2, *pcbActual, pbFrame); return S_OK; };