Template:AVO Sample of copy stream

From AVObjects Knowledge Base
(Difference between revisions)
Jump to: navigation, search
 
(2 intermediate revisions by one user not shown)
Line 1: Line 1:
 
===Copy stream===
 
===Copy stream===
 
<source lang=cpp>
 
<source lang=cpp>
 +
//BYTE* pbBuffer - pointer to frame buffer
 +
//DWORD cbBuffer - size of frane buffer in bytes
 +
//int nStream - index of stream
 +
 
HRESULT hr = S_OK;
 
HRESULT hr = S_OK;
 
//Alloc memory for frames
 
DWORD cbBuffer = 0x100000;
 
BYTE* pbBuffer = malloc(cbBuffer);
 
if (pbBuffer == NULL)
 
  return E_OUTOFMEMORY;
 
 
 
while(1)
 
while(1)
 
{
 
{
Line 23: Line 20:
 
   DWORD dwFlags = 0;
 
   DWORD dwFlags = 0;
 
   
 
   
   hr = spSource->GetFrame(nStream, pbBuffer, cbBuffer, &cbActual, &dwFlags, &tS, &tE, NULL);
+
   hr = spSource->GetFrame(nStream, pbBuffer, cbBuffer,
 +
    &cbActual, &dwFlags, &tS, &tE, NULL);
 
   if (hr == S_OK)
 
   if (hr == S_OK)
 
   {
 
   {
     hr = spDest->PutFrame(nStream, m_pbBuffer, cbActual, dwFlags, tS, tE, NULL);
+
     hr = spDest->PutFrame(nStream, m_pbBuffer, cbActual,  
 +
        dwFlags, tS, tE, NULL);
 
   }
 
   }
 
   else if (hr == HRESULT_FROM_WIN32(ERROR_HANDLE_EOF))
 
   else if (hr == HRESULT_FROM_WIN32(ERROR_HANDLE_EOF))

Latest revision as of 08:49, 11 July 2014

Copy stream

//BYTE* pbBuffer - pointer to frame buffer
//DWORD cbBuffer - size of frane buffer in bytes
//int nStream - index of stream
 
HRESULT hr = S_OK;
while(1)
{
  hr = spDest->CanPutFrame(nStream, INFINITE);
  if ( hr != S_OK )
     return hr;
 
  hr = spSource->CanGetFrame(nStream, INFINITE);
  if (hr != S_OK)
    return hr;
 
  DWORD cbActual = 0;
  REFERENCE_TIME tS = 0, tE = 0;
  DWORD dwFlags = 0;
 
  hr = spSource->GetFrame(nStream, pbBuffer, cbBuffer,
    &cbActual, &dwFlags, &tS, &tE, NULL);
  if (hr == S_OK)
  {
     hr = spDest->PutFrame(nStream, m_pbBuffer, cbActual, 
        dwFlags, tS, tE, NULL);
  }
  else if (hr == HRESULT_FROM_WIN32(ERROR_HANDLE_EOF))
  {
     // EOS, put empty frame to dest
     hr = spDest->PutFrame(nStream, NULL, 0, 0, 0, 0, NULL);
     if (hr == S_OK)
        return hr;
  }  
  if (FAILED(hr))
    return hr;
}
Personal tools