Quantcast
Channel: Media Foundation Development for Windows Desktop forum
Viewing all articles
Browse latest Browse all 1079

Media Foundation Using IMFSourceReader, IMFMediaSink, EVR

$
0
0
I'll open video file by  IMFSourceReader and want to show it on window by IMFMediaSink+EVR. I dont know where to get value for IMFPresentationClock. And i dont know how to start MediaSink. Or maybe i do all wrong? Can u help me? Sorry for my English.)

HRESULT Playback::StartVideo(LPCWSTR fileName)
{
	HRESULT hr;
	if (SUCCEEDED(hr))
		hr = MFCreateSourceReaderFromURL(fileName, NULL, &pReader);

	IMFMediaType *pType = NULL;
	if (SUCCEEDED(hr))
		hr = pReader->GetCurrentMediaType((DWORD)MF_SOURCE_READER_FIRST_VIDEO_STREAM, &pType);
	if (SUCCEEDED(hr))
		LogMediaType(pType);

	 IMFMediaSink *pSink;
	 IMFStreamSink *pStream;
	 IMFGetService *pService;
	 IMFVideoDisplayControl *pDisplayControl;
	 IMFPresentationClock *pClock;

	 hr = MFCreateVideoRenderer(
		 __uuidof(IMFMediaSink),
         (void**)&pSink
		 );
	 hr = pSink->AddStreamSink(1, pType, &pStream);
	 hr = pSink->GetPresentationClock(&pClock);
	 //Совсем не пойму что мне сделать с IMFPresentationClock

	 hr = pSink->QueryInterface(
		 __uuidof(IMFGetService),
         (void**)&pService
		 );
	 hr = pService->GetService(
		 MR_VIDEO_RENDER_SERVICE,
		 __uuidof(IMFVideoDisplayControl),
         (void**)&pDisplayControl
		 );
	 hr = pDisplayControl->SetVideoWindow(hWindow);

	IMFSample *pSample = NULL;
	size_t  cSamples = 0;
	bool quit = false;
	time_t time1, time2;
	char *t1 = new char[26], *t2 = new char[26];
	time(&time1);
	while (!quit)
	{
		DWORD streamIndex, flags;
		LONGLONG llTimeStamp;

		hr = pReader->ReadSample(
			MF_SOURCE_READER_FIRST_VIDEO_STREAM,// Stream index.
			0,									// Flags.&streamIndex,						// Receives the actual stream index. &flags,								// Receives status flags.&llTimeStamp,						// Receives the time stamp.&pSample							// Receives the sample or NULL.
			);

		if (FAILED(hr))
		{
			break;
		}

		if (flags & MF_SOURCE_READERF_ENDOFSTREAM)
		{
			quit = true;
			if (!pSample)
				break;
		}

		if (pSample)
		{
			++cSamples;
			hr = pStream->ProcessSample(pSample);
		}
		SafeRelease(&pSample);
	}
	time(&time2);
	ctime_s(t1, 26, &time1);
	ctime_s(t2, 26, &time2);
	double sec = difftime(time1, time2);

	SafeRelease(&pSample);
	SafeRelease(&pType);
	return hr;
}



Viewing all articles
Browse latest Browse all 1079

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>