Esempio n. 1
0
HRESULT FttpSchemeHandler::WhenCreateMediaSource(IMFAsyncResult *result) {
  MF_OBJECT_TYPE type;
  auto hr = source_creator->EndCreateObject(result, &type, &source);
  caller_result->SetStatus(hr);
  MFInvokeCallback(caller_result.Get());
  return S_OK;
}
Esempio n. 2
0
HRESULT CGeometricSchemeHandler::OnSourceOpen(_In_ IMFAsyncResult *pResult)
{
    ComPtr<IUnknown> spState = pResult->GetStateNoAddRef();
    if (!spState)
    {
        return MF_E_UNEXPECTED;
    }
    ComPtr<IMFAsyncResult> spSavedResult;
    HRESULT hr = S_OK;

    hr = spState.As(&spSavedResult);
    if (FAILED(hr))
    {
        return hr;
    }

    ComPtr<IUnknown> spunkSource;
    ComPtr<IMFMediaSource> spSource;
    hr = spSavedResult->GetObject(&spunkSource);

    if (SUCCEEDED(hr))
    {
        hr = spunkSource.As(&spSource);
        if (SUCCEEDED(hr))
        {
            CGeometricMediaSource *pSource = static_cast<CGeometricMediaSource *>(spSource.Get());
            hr = pSource->EndOpen(pResult);
        }
    }

    spSavedResult->SetStatus(hr);    
    hr = MFInvokeCallback(spSavedResult.Get());

    return hr;
}
HRESULT HDCoreByteStreamHandler::Invoke(IMFAsyncResult* pAsyncResult)
{
	std::lock_guard<decltype(_mutex)> lock(_mutex);

	if (_mediaSource == nullptr)
		return E_UNEXPECTED;

	_openResult->SetStatus(pAsyncResult->GetStatus());
	return MFInvokeCallback(_openResult.Get()); //Notify to System...
}
Esempio n. 4
0
HRESULT FttpSchemeHandler::WhenCreateByteStream(IMFAsyncResult*result) {
  auto hr = MFEndCreateFile(result, &http_stream);
  assert(!source_creator);
  if (SUCCEEDED(hr)) hr = BeginCreateMediaSource();

  if (FAILED(hr)) {
    caller_result->SetStatus(hr);
    hr = MFInvokeCallback(caller_result.Get());
  }
  return S_OK;
}
Esempio n. 5
0
//create bytestream
//create media-source
HRESULT FttpSchemeHandler::BeginCreateObject(LPCWSTR url,
                                             DWORD flags,
                                             IPropertyStore* ,  // not used
                                             IUnknown**cancel_cookie,
                                             IMFAsyncCallback*callback,
                                             IUnknown*s) {
  if(cancel_cookie)
    *cancel_cookie = nullptr;

  if ((flags & MF_RESOLUTION_WRITE) || !(flags & MF_RESOLUTION_MEDIASOURCE))
    return E_INVALIDARG;
  if (caller_result)
    return E_FAIL;  // only one session allowed

  uri = fttp_resolver().resolve(url);
  auto hr = uri.validate() ? S_OK : E_INVALID_PROTOCOL_FORMAT;

  IMFSchemeHandlerPtr pthis(this);

  if (SUCCEEDED(hr)) hr = MFCreateAsyncResult(nullptr, callback, s, &caller_result);
  if (SUCCEEDED(hr) && uri.type == fttp_type::url)
    scatter_tar_file_handler().async_check(uri.true_url).then([this, pthis](scheme_check_result result) {
      assert(!http_stream && !source_creator);
      content_type = result.content_type;
      CopyMemory(magic, result.maigic, sizeof(magic));
      HRESULT hr = result.error; // (result.error < 0) ? (result.error | make_sure_negativei32) : S_OK;
      if (SUCCEEDED(hr) && (http_stream || source_creator)) hr = E_FAIL;
      if (SUCCEEDED(hr)) 
        hr = MakeAndInitialize<ProgressiveHttpStream, IMFByteStream>(&http_stream, result.url.c_str(), result.content_length);
      if (SUCCEEDED(hr)) hr = BeginCreateMediaSource();

      if (FAILED(hr)) {
        caller_result->SetStatus(hr);
        hr = MFInvokeCallback(caller_result.Get());
      }
    });
  else if (SUCCEEDED(hr)) {
    auto fp = uri.true_url;
    hr = MFBeginCreateFile(MF_ACCESSMODE_READ, MF_OPENMODE_FAIL_IF_NOT_EXIST, MF_FILEFLAGS_NONE, fp.c_str(), &when_create_bytestream, nullptr, nullptr);
  } 
  return hr;
}
/** 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;
}
Esempio n. 7
0
void MFStream::doRead()
{
    bool readDone = true;
    IUnknown *pUnk = NULL;
    HRESULT    hr = m_currentReadResult->GetObject(&pUnk);
    if (SUCCEEDED(hr)) {
        //do actual read
        AsyncReadState *state =  static_cast<AsyncReadState*>(pUnk);
        ULONG cbRead;
        Read(state->pb(), state->cb() - state->bytesRead(), &cbRead);
        pUnk->Release();

        state->setBytesRead(cbRead + state->bytesRead());
        if (state->cb() > state->bytesRead() && !m_stream->atEnd()) {
            readDone = false;
        }
    }

    if (readDone) {
        //now inform the original caller
        m_currentReadResult->SetStatus(hr);
        MFInvokeCallback(m_currentReadResult);
    }
}
Esempio n. 8
0
			/// <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;
			}