//-------------------------------------------------------------------
// Name: DeliverSample
// Description: Delivers a sample by sending an MEMediaSample event.
//-------------------------------------------------------------------
HRESULT WavStream::DeliverSample(IMFSample *pSample)
{
    HRESULT hr = S_OK;

    // Send the MEMediaSample event with the new sample.
    hr = QueueEventWithIUnknown(this, MEMediaSample, hr, pSample); 

    // See if we reached the end of the stream.
    if (SUCCEEDED(hr))
    {   
        hr = CheckEndOfStream();    // This method sends MEEndOfStream if needed.
    }

    return hr;
}
// Sends a message to the video presenter.
HRESULT STDMETHODCALLTYPE EVRCustomPresenter::ProcessMessage(MFVP_MESSAGE_TYPE eMessage, ULONG_PTR ulParam)
{
  // Albert: Don't produce so much log output
  //Log("EVRCustomPresenter::ProcessMessage");

  HRESULT hr = S_OK;

  CAutoLock lock(this);

  hr = CheckShutdown();
  CHECK_HR(hr, "EVRCustomPresenter::ProcessMessage presenter is shutdown");

  switch (eMessage)
  {
    // Flush all pending samples.
    case MFVP_MESSAGE_FLUSH:
      Log("ProcessMessage: MFVP_MESSAGE_FLUSH");
      hr = Flush();
    break;

    // Renegotiate the media type with the mixer.
    case MFVP_MESSAGE_INVALIDATEMEDIATYPE:
      Log("ProcessMessage: MFVP_MESSAGE_INVALIDATEMEDIATYPE");
      hr = RenegotiateMediaType();
    break;

    // The mixer received a new input sample. 
    case MFVP_MESSAGE_PROCESSINPUTNOTIFY:
      // Albert: Don't produce so much log output
      //Log("ProcessMessage: MFVP_MESSAGE_PROCESSINPUTNOTIFY");
      hr = ProcessInputNotify();
    break;

    // Streaming is about to start.
    case MFVP_MESSAGE_BEGINSTREAMING:
      Log("ProcessMessage: MFVP_MESSAGE_BEGINSTREAMING");
      hr = BeginStreaming();
    break;

    // Streaming has ended. (The EVR has stopped.)
    case MFVP_MESSAGE_ENDSTREAMING:
      Log("ProcessMessage: MFVP_MESSAGE_ENDSTREAMING");
      hr = EndStreaming();
    break;

    // All input streams have ended.
    case MFVP_MESSAGE_ENDOFSTREAM:
      Log("ProcessMessage: MFVP_MESSAGE_ENDOFSTREAM");
      // Set the end of stream flag. 
      m_bEndStreaming = TRUE; 
      // Check if it's time to send the EC_COMPLETE event to the EVR.
      hr = CheckEndOfStream();
    break;

    // Frame-stepping is starting.
    case MFVP_MESSAGE_STEP:
      Log("ProcessMessage: MFVP_MESSAGE_STEP");
      hr = PrepareFrameStep(LODWORD(ulParam));
    break;

    // Cancels frame-stepping.
    case MFVP_MESSAGE_CANCELSTEP:
      Log("ProcessMessage: MFVP_MESSAGE_CANCELSTEP");
      hr = CancelFrameStep();
    break;

    // Unknown message. (This case should never occur.)
    default:
      Log("ProcessMessage: Unknown Message");
      hr = E_INVALIDARG;
    break;
  }

  return hr;
}