Example #1
0
// IMFSchemeHandler methods
IFACEMETHODIMP CGeometricSchemeHandler::BeginCreateObject( 
    _In_ LPCWSTR pwszURL,
    _In_ DWORD dwFlags,
    _In_ IPropertyStore *pProps,
    _Out_opt_  IUnknown **ppIUnknownCancelCookie,
    _In_ IMFAsyncCallback *pCallback,
    _In_ IUnknown *punkState)
{
    if (pwszURL == nullptr || pCallback == nullptr)
    {
        return E_INVALIDARG;
    }

    if ((dwFlags & MF_RESOLUTION_MEDIASOURCE) == 0)
    {
        return E_INVALIDARG;
    }

    ComPtr<CGeometricMediaSource> spSource;
    ComPtr<IMFAsyncResult> spResult;
    HRESULT hr = CGeometricMediaSource::CreateInstance(&spSource);

    if (SUCCEEDED(hr))
    {
        ComPtr<IUnknown> spunkSource;
        hr = spSource.As(&spunkSource);
        if (SUCCEEDED(hr))
        {
            hr = MFCreateAsyncResult(spunkSource.Get(), pCallback, punkState, &spResult);
        }
    }

    if (SUCCEEDED(hr))
    {            
        hr = spSource->BeginOpen(pwszURL, &_OnSourceOpenCB, spResult.Get());
    }

    if (SUCCEEDED(hr) && ppIUnknownCancelCookie != nullptr)
    {
        *ppIUnknownCancelCookie = nullptr;
    }

    if (FAILED(hr))
    {
        spSource->Shutdown();
    }

    return hr;
}
Example #2
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;
}
Example #3
0
STDMETHODIMP MFStream::BeginRead(BYTE *pb, ULONG cb, IMFAsyncCallback *pCallback,
                       IUnknown *punkState)
{
    if (!pCallback || !pb)
        return E_INVALIDARG;

    Q_ASSERT(m_currentReadResult == NULL);

    AsyncReadState *state = new (std::nothrow) AsyncReadState(pb, cb);
    if (state == NULL)
        return E_OUTOFMEMORY;

    HRESULT hr = MFCreateAsyncResult(state, pCallback, punkState, &m_currentReadResult);
    state->Release();
    if (FAILED(hr))
        return hr;

    QCoreApplication::postEvent(this, new QEvent(QEvent::User));
    return hr;
}
Example #4
0
			/// <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;
}
HRESULT HDCoreByteStreamHandler::BeginCreateObject(IMFByteStream *pByteStream,LPCWSTR pwszURL,DWORD dwFlags,IPropertyStore *pProps,IUnknown **ppIUnknownCancelCookie,IMFAsyncCallback *pCallback,IUnknown *punkState)
{
#ifdef _DEBUG
	OutputDebugStringA("HDCoreByteStreamHandler->CreateObject...\n");
#endif

	std::lock_guard<decltype(_mutex)> lock(_mutex);

	if (pByteStream == nullptr ||
		pCallback == nullptr)
		return E_POINTER;

	if ((dwFlags & MF_RESOLUTION_MEDIASOURCE) == 0)
		return E_INVALIDARG;

	if (ppIUnknownCancelCookie)
		*ppIUnknownCancelCookie = nullptr;

	if (_openResult)
		return E_UNEXPECTED;

	double bufferTime = 5.0;
	if (pProps) {
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
		PROPVARIANT var;
		PropVariantInit(&var);
		PROPERTYKEY key;
		key.fmtid = MFNETSOURCE_BUFFERINGTIME;
		key.pid = 0;
		if (SUCCEEDED(pProps->GetValue(key,&var)))
		{
			if (var.vt = VT_I4 || var.vt == VT_UI4)
				bufferTime = (double)var.lVal / 1000.0;
			if (bufferTime <= 0.0)
				bufferTime = 5.0;
		}
		PropVariantClear(&var);
#endif
	}
	if (GlobalOptionGetDouble(kNetworkPacketBufferTime) > 0.9)
		bufferTime = GlobalOptionGetDouble(kNetworkPacketBufferTime);

	ComPtr<IMFByteStreamBuffering> pIsNetwork;
	HRESULT hrIsNetwork = pByteStream->QueryInterface(
		IID_PPV_ARGS(pIsNetwork.GetAddressOf()));

	auto source = HDMediaSource::CreateMediaSource(
		SUCCEEDED(hrIsNetwork) ? MF_SOURCE_STREAM_QUEUE_AUTO:
		MF_SOURCE_STREAM_QUEUE_FPS_AUTO);

	if (source == nullptr)
		return E_OUTOFMEMORY;

	if (SUCCEEDED(hrIsNetwork))
		source->SetNetworkPrerollTime(bufferTime);

	HRESULT hr = MFCreateAsyncResult(static_cast<IMFMediaSource*>(source.Get()),
		pCallback,punkState,
		_openResult.GetAddressOf());

	if (FAILED(hr))
		return hr;

	hr = source->OpenAsync(pByteStream,this);
	if (FAILED(hr))
		return hr;

	_mediaSource = source;
	return S_OK;
}