STDMETHODIMP FWmfMediaByteStream::Invoke(IMFAsyncResult* AsyncResult) { // recover read state IUnknown* State = NULL; if (FAILED(AsyncResult->GetState(&State))) { return S_OK; } IMFAsyncResult* CallerResult = NULL; if (FAILED(State->QueryInterface(IID_PPV_ARGS(&CallerResult)))) { return S_OK; } IUnknown* Unknown = NULL; if ((CallerResult != NULL) && FAILED(CallerResult->GetObject(&Unknown))) { return S_OK; } FWmfMediaReadState* ReadState = static_cast<FWmfMediaReadState*>(Unknown); // perform the read ULONG cbRead; Read(ReadState->GetReadBuffer(), ReadState->GetReadBufferSize() - ReadState->GetBytesRead(), &cbRead); ReadState->AddBytesRead(cbRead); // notify caller if (CallerResult != NULL) { CallerResult->SetStatus(S_OK); ::MFInvokeCallback(CallerResult); } // clean up if (CallerResult != NULL) { CallerResult->Release(); } if (Unknown != NULL) { Unknown->Release(); } if (State != NULL) { State->Release(); } return S_OK; }
/** Asyncronous callback */ STDMETHODIMP FImfByteStream::Invoke( IMFAsyncResult* pResult ) { HRESULT HResult = S_OK; IUnknown* State = NULL; IUnknown* Unknown = NULL; IMFAsyncResult* CallerResult = NULL; AsyncReadState* Op = NULL; HResult = pResult->GetState( &State ); check( SUCCEEDED( HResult ) ); HResult = State->QueryInterface( IID_PPV_ARGS( &CallerResult ) ); check( SUCCEEDED( HResult ) ); HResult = CallerResult->GetObject( &Unknown ); check( SUCCEEDED( HResult ) ); Op = static_cast<AsyncReadState*>( Unknown ); /* Do actual read */ ULONG cbRead; Read( Op->GetBuffer( ), Op->GetCount( ) - Op->GetBytesRead( ), &cbRead ); Op->SetBytesRead( cbRead + Op->GetBytesRead( ) ); if( CallerResult ) { CallerResult->SetStatus( HResult ); MFInvokeCallback( CallerResult ); } if( State != NULL ) { State->Release( ); } if( Unknown != NULL ) { Unknown->Release( ); } if( CallerResult != NULL ){ CallerResult->Release( ); } return S_OK; }
/// <summary> /// Called when an asynchronous operation is completed. /// </summary> /// <param name="pAsyncResult">Pointer to the IMFAsyncResult interface. Pass this pointer to the asynchronous End... method to complete the asynchronous call.</param> /// <returns>The result of the operation.</returns> HRESULT ReadByteAsyncCallback::Invoke(IMFAsyncResult* pAsyncResult) { // Enter critical section. EnterCriticalSection(&_critsec); HRESULT hr = S_OK; ULONG pcbRead; IUnknown *pState = NULL; IUnknown *pUnk = NULL; IMFAsyncResult *pCallerResult = NULL; ReadByteContainer *pReader = NULL; // Get the asynchronous result object for the application callback. hr = pAsyncResult->GetState(&pState); if (FAILED(hr)) { goto done; } // Get the caller result interface. hr = pState->QueryInterface(IID_PPV_ARGS(&pCallerResult)); if (FAILED(hr)) { goto done; } // Get the object that holds the state information for the asynchronous method. hr = pCallerResult->GetObject(&pUnk); if (FAILED(hr)) { goto done; } // Get the reader byte container. pReader = static_cast<ReadByteContainer*>(pUnk); // Write the bytes. _byteStream->Read(pReader->_pb, pReader->_cb, &pcbRead); // Assign the number of bytes writen. pReader->_pcbRead = pcbRead; done: // Set the result. // Signal the application. if (pCallerResult) { pCallerResult->SetStatus(hr); MFInvokeCallback(pCallerResult); } // Clean-up. SafeRelease(&pState); SafeRelease(&pUnk); SafeRelease(&pCallerResult); // Leave critical section. LeaveCriticalSection(&_critsec); // Return the result. return hr; }