title: How to get data from directshow filter output pin?
body: <p>I have  direct show filter which takes an input and process it and give the result to outputpin.</p>
  
  <p>I want to write this filter output data to a file...And i want to do it in its filter class.So i want to get the output pin buffer data.</p>
  
  <p>Shortly how to reach final data of outputpin in its filter? How can i do it? </p>
  
  <p><strong>Not:</strong> The output pin is derived from CBaseOutputPin.This is an open source filter it "magically" :-) put wright data to its output pin which i can not figure out  how yet...</p>
  
  <p><strong>Update:</strong></p>
  
  <p>Here is the siutuation:</p>
  
  <pre><code>Media Source ----&gt;  GFilter ----&gt; FileWriter
  </code></pre>
  
  <p>I have source code of GFilter... I have no source code of FileWriter...What i want to make is make GFilter write its own data...I debug GFilter get some insight how its transform data but my attemp to write this data result with wrong data... So i deceide for now how to simply get data at its output pin...</p>
  
  <p><strong>Update[2]</strong></p>
  
  <p>In Filter outputpin somwhere the filter writer  pass the file writer pin to IStreamPtr variable...Everthing seems to written to a variable m_pIStream which is type of [IStreamPtr] </p>
  
  <pre><code>GFilterOutput::CompleteConnect(IPin *pReceivePin)
  {
  
  
      // make sure that this is the file writer, supporting
      // IStream, or we will not be able to write out the metadata
      // at stop time
      // m_pIStream  is IStreamPtr type
      m_pIStream = pReceivePin;
      if (m_pIStream == NULL)
      {
          return E_NOINTERFACE;
      }
      return CBaseOutputPin::CompleteConnect(pReceivePin);
  }
  </code></pre>
  
  <p>...</p>
  
  <pre><code>GFilterOutput::Replace(LONGLONG pos, const BYTE* pBuffer, long cBytes)
  {
       //OutputDebugStringA("DEBUG: Now at MuxOutput Replace");
  
      // all media content is written when the graph is running,
      // using IMemInputPin. On stop (during our stop, but after the
      // file writer has stopped), we switch to IStream for the metadata.
      // The in-memory index is updated after a successful call to this function, so
      // any data not written on completion of Stop will not be in the index.
      CAutoLock lock(&amp;m_csWrite);
  
      HRESULT hr = S_OK;
      if (m_bUseIStream)
      {
  
  
          IStreamPtr pStream = GetConnected();
          if (m_pIStream == NULL)
          {
              hr = E_NOINTERFACE;
          } else {
              LARGE_INTEGER liTo;
              liTo.QuadPart = pos;
              ULARGE_INTEGER uliUnused;
              hr = m_pIStream-&gt;Seek(liTo, STREAM_SEEK_SET, &amp;uliUnused);
              if (SUCCEEDED(hr))
              {
                  ULONG cActual;
                  hr = m_pIStream-&gt;Write(pBuffer, cBytes, &amp;cActual);
                  if (SUCCEEDED(hr) &amp;&amp; ((long)cActual != cBytes))
                  {
                      hr = E_FAIL;
                  }
              }
          }
      } else {
          // where the buffer boundaries lie is not important in this 
          // case, so break writes up into the buffers.
          while (cBytes &amp;&amp; (hr == S_OK))
          {
              IMediaSamplePtr pSample;
              hr = GetDeliveryBuffer(&amp;pSample, NULL, NULL, 0);
              if (SUCCEEDED(hr))
              {
                  long cThis = min(pSample-&gt;GetSize(), cBytes);
                  BYTE* pDest;
                  pSample-&gt;GetPointer(&amp;pDest);
                  CopyMemory(pDest, pBuffer,  cThis);
                  pSample-&gt;SetActualDataLength(cThis);
  
                  // time stamps indicate file position in bytes
                  LONGLONG tStart = pos;
                  LONGLONG tEnd = pos + cThis;
                  pSample-&gt;SetTime(&amp;tStart, &amp;tEnd);
                  hr = Deliver(pSample);
                  if (SUCCEEDED(hr))
                  {
                      pBuffer += cThis;
                      cBytes -= cThis;
                      pos += cThis;
                  }
              }
          }
      }
      return hr;
  }
  </code></pre>