/// <summary> /// Begins an asynchronous read operation from the stream. /// </summary> /// <param name="pb">Pointer to a buffer that receives the data. The caller must allocate the buffer. [in]</param> /// <param name="cb">Size of the buffer in bytes. [in]</param> /// <param name="pCallback">Pointer to the IMFAsyncCallback interface of a callback object. The caller must implement this interface. [in]</param> /// <param name="punkState">Pointer to the IUnknown interface of a state object, defined by the caller. This parameter can be NULL. /// You can use this object to hold state information. The object is returned to the caller when the callback is invoked. [in]</param> /// <returns>The result of the operation.</returns> HRESULT StoreByteStream::BeginRead( BYTE *pb, ULONG cb, IMFAsyncCallback *pCallback, IUnknown *punkState) { HRESULT hr = S_OK; // Create a new read byte container. ReadByteContainer* readBytes = new ReadByteContainer(pb, cb); ReadByteAsyncCallback* readCallback = new ReadByteAsyncCallback(this); // If not created. if (readBytes == NULL) { return E_OUTOFMEMORY; } // If not created. if (readCallback == NULL) { return E_OUTOFMEMORY; } IMFAsyncResult *pResult = NULL; readBytes->_readCallback = readCallback; // Creates an asynchronous result object. Use this function if you are implementing an asynchronous method. hr = MFCreateAsyncResult(readBytes, pCallback, punkState, &pResult); if (SUCCEEDED(hr)) { // Start a new work item thread. hr = MFPutWorkItem(MFASYNC_CALLBACK_QUEUE_STANDARD, readCallback, pResult); pResult->Release(); } // Return the result. return hr; }
/** Begins an asyncronous read */ STDMETHODIMP FImfByteStream::BeginRead( BYTE* pb, ULONG cb, IMFAsyncCallback* pCallback, IUnknown* punkState ) { HRESULT HResult = S_OK; if( !pCallback || !pb ) return E_INVALIDARG; IMFAsyncResult* Result = NULL; AsyncReadState* State = new( std::nothrow ) AsyncReadState( pb, cb ); if( State == NULL ) return E_OUTOFMEMORY; HResult = MFCreateAsyncResult( State, pCallback, punkState, &Result ); State->Release( ); if( SUCCEEDED( HResult ) ) { IsCurrentlyReading = true; HResult = MFPutWorkItem( MFASYNC_CALLBACK_QUEUE_STANDARD, this, Result ); Result->Release( ); } return HResult; }