Ejemplo n.º 1
0
void play_movie( HWND hwnd )
{
    IGraphBuilder *pGraph;
    IMediaControl *pMediaControl;
    IMediaEvent   *pEvent;
    IBasicVideo   *pBasic;
    IVideoWindow    *pVidWin = NULL;
    RECT grc;
    long width, height;

    CoInitialize(NULL);
    
    // Create the filter graph manager and query for interfaces.
    CoCreateInstance( 
	CLSID_FilterGraph, 
	NULL, 
	CLSCTX_INPROC_SERVER, 
	IID_IGraphBuilder, 
	(void **)&pGraph);
    
    pGraph->QueryInterface(IID_IVideoWindow, (void **)&pVidWin);

    pGraph->QueryInterface(IID_IMediaControl, (void **)&pMediaControl);
    pGraph->QueryInterface(IID_IMediaEvent, (void **)&pEvent);
    pGraph->QueryInterface(IID_IBasicVideo, (void**)&pBasic );

    // Build the graph. IMPORTANT: Change string to a file on your system.
    pGraph->RenderFile(L"e:\\alpha\\running.avi", NULL);

    pBasic->GetVideoSize( &width, &height );  
    printf( "video frames are %d x %d\n", width, height );

    pVidWin->put_Owner((OAHWND)hwnd);
    pVidWin->put_WindowStyle(WS_CHILD | WS_CLIPSIBLINGS);

    GetClientRect( hwnd, &grc );
    pVidWin->SetWindowPosition(10, 10, width, height);
    printf( "window is %d x %d\n", grc.right, grc.bottom );

    // Run the graph.
    pMediaControl->Run();

    // Wait for completion. 
    long evCode;
    pEvent->WaitForCompletion(INFINITE, &evCode);

    pVidWin->put_Visible(OAFALSE);
    pVidWin->put_Owner(NULL);
    
    // Clean up.
    pBasic->Release();
    pVidWin->Release();
    pMediaControl->Release();
    pEvent->Release();
    pGraph->Release();
    CoUninitialize();
}
Ejemplo n.º 2
0
void video_set_source_region(int id, long x, long y, long w, long h) {
	get_video(videoStruct, id);
	IBasicVideo *pBasicVideo;
	videoStruct->pGraph->QueryInterface(IID_IBasicVideo,
	 (LPVOID *)&pBasicVideo);
	
	pBasicVideo->SetSourcePosition(x, y, w, h);

	// release
	pBasicVideo->Release();
}
Ejemplo n.º 3
0
double video_get_frame_time(int id) {
	get_videor(videoStruct, id, -1);
	IBasicVideo *pBasicVideo;
	videoStruct->pGraph->QueryInterface(IID_IBasicVideo,
	 (LPVOID *)&pBasicVideo);

	// obtain average time between frames
	REFTIME frametime;
	pBasicVideo->get_AvgTimePerFrame(&frametime);

	// release
	pBasicVideo->Release();
	
	return frametime;
}
Ejemplo n.º 4
0
long video_get_height(int id) {
	get_videor(videoStruct, id, -1);
	IBasicVideo *pBasicVideo;
	videoStruct->pGraph->QueryInterface(IID_IBasicVideo,
	 (LPVOID *)&pBasicVideo);

	// obtain height
	long height;
	pBasicVideo->get_VideoHeight(&height);

	// release
	pBasicVideo->Release();
	
	return height;
}
Ejemplo n.º 5
0
long video_get_width(int id) {
	get_videor(videoStruct, id, -1);
	IBasicVideo *pBasicVideo;
	videoStruct->pGraph->QueryInterface(IID_IBasicVideo,
	 (LPVOID *)&pBasicVideo);

	// obtain width
	long width;
	pBasicVideo->get_VideoWidth(&width);

	// release
	pBasicVideo->Release();
	
	return width;
}
Ejemplo n.º 6
0
/*
 * Class:     sage_DShowMediaPlayer
 * Method:    getVideoDimensions0
 * Signature: (J)Ljava/awt/Dimension;
 */
JNIEXPORT jobject JNICALL Java_sage_DShowMediaPlayer_getVideoDimensions0
  (JNIEnv *env, jobject jo, jlong dataPtr)
{
	if (!dataPtr) return NULL;
	CPlayerData* playData = (CPlayerData*) dataPtr;
	IGraphBuilder* pGraph = playData->GetGraph();
	if (!pGraph) return JNI_FALSE;
	IBasicVideo* pBV = NULL;
	HRESULT hr = pGraph->QueryInterface(IID_IBasicVideo, (void**)&pBV);
	if (SUCCEEDED(hr))
	{
		long nativeWidth, nativeHeight;
		hr = pBV->get_VideoWidth(&nativeWidth);
		if (FAILED(hr)) { SAFE_RELEASE(pBV); return NULL; }
		hr = pBV->get_VideoHeight(&nativeHeight);
		if (FAILED(hr)) { SAFE_RELEASE(pBV); return NULL; }
		static jclass dimClass = (jclass) env->NewGlobalRef(env->FindClass("java/awt/Dimension"));
		static jmethodID constMeth = env->GetMethodID(dimClass, "<init>", "(II)V");
		jobject dimObj = env->NewObject(dimClass, constMeth, nativeWidth, nativeHeight);
		SAFE_RELEASE(pBV);
		return dimObj;
	}
	return NULL;
}
Ejemplo n.º 7
0
void Video::play( char *fileName, DWORD )
{
	WCHAR wPath[100];
	HRESULT hr;
	IMediaControl *pMC;

	if(!init_success)
		return;

	MultiByteToWideChar( CP_ACP, 0, fileName, -1, wPath, 100 );

	if( (hr = pGraph->RenderFile(wPath, NULL)) == 0)
	{

		// use full screen video interface
		// try to change display mode
		IVideoWindow *iVideoWindow = NULL;
		if( (hr = pGraph->QueryInterface(IID_IVideoWindow, (void **) &iVideoWindow)) == 0)
		{
#ifdef CREATE_DUMMY_WINDOW
			if(hwnd)
			{
				HRESULT hr2 = iVideoWindow->put_MessageDrain((OAHWND) hwnd);
				hr2 = 0;
			}
#endif

#ifdef FULL_SCREEN_VIDEO
			IFilter *iFilter;
			if( pGraph->FindFilterByName(L"Video Renderer", &iFilter) == 0)
			{
				IBasicVideo *iBasicVideo;
				if( iFilter->QueryInterface(IID_IBasicVideo, (void **)&iBasicVideo) == 0)
				{
					IFullScreenVideo *iFullScreenVideo;
					IDirectDrawVideo *iDirectDrawVideo;
					if( iFilter->QueryInterface(IID_IFullScreenVideo, (void **)&iFullScreenVideo) == 0)
					{
						iFullScreenVideo->Release();
					}
					else if( iFilter->QueryInterface(IID_IDirectDrawVideo, (void **)&iDirectDrawVideo) == 0)
					{
						HRESULT hr2;
						hr2 = iDirectDrawVideo->UseWhenFullScreen(OATRUE);
						iDirectDrawVideo->Release();
					}

					iBasicVideo->Release();
				}
				iFilter->Release();
			}
			hr=iVideoWindow->put_FullScreenMode(OATRUE);
#endif

			/* // code to find all filter in the filter graph
			{
				IEnumFilters *iEnumFilters;
				pGraph->EnumFilters(&iEnumFilters);

				ULONG filterCount = 16;
				IFilter *iFilters[16];
				iEnumFilters->Next(filterCount, iFilters, &filterCount);

				for( ULONG j = 0; j < filterCount; ++j )
				{
					FILTER_INFO filterInfo;
					iFilters[j]->QueryFilterInfo(&filterInfo);
					filterInfo.pGraph->Release();
					iFilters[j]->Release();
				}

				iEnumFilters->Release();
			}*/

			iVideoWindow->HideCursor(OATRUE);
			iVideoWindow->put_Visible( OAFALSE );
			iVideoWindow->put_AutoShow( OAFALSE );
			LONG windowStyle;
			iVideoWindow->get_WindowStyle( &windowStyle);
			windowStyle &= ~WS_BORDER & ~WS_CAPTION & ~WS_SIZEBOX & ~WS_THICKFRAME &
				~WS_HSCROLL & ~WS_VSCROLL & ~WS_VISIBLE;
			iVideoWindow->put_WindowStyle( windowStyle);
		}
		else
			iVideoWindow = NULL;
		
		if( (hr = pGraph->QueryInterface(IID_IMediaControl, (void **) &pMC)) == 0)
		{
			pMC->Run();					// sometimes it returns 1, but still ok
			state = PLAYING;
			pMC->Release();
		}

		if( iVideoWindow )
		{
			iVideoWindow->put_Visible( OAFALSE );
			LONG windowStyle;
			iVideoWindow->get_WindowStyle( &windowStyle);
			windowStyle &= ~WS_BORDER & ~WS_CAPTION & ~WS_SIZEBOX & ~WS_THICKFRAME &
				~WS_HSCROLL & ~WS_VSCROLL & ~WS_VISIBLE;
			iVideoWindow->put_WindowStyle( windowStyle);

			LONG maxWidth;
			LONG maxHeight;
			hr=iVideoWindow->GetMaxIdealImageSize( &maxWidth, &maxHeight);
#ifdef FULL_SCREEN_VIDEO
#else
			iVideoWindow->put_BorderColor( RGB(0,0,0) );
			iVideoWindow->put_WindowState(SW_MAXIMIZE);

			IBaseFilter *iFilter;
			if( pGraph->FindFilterByName((const WCHAR *)L"Video Renderer", &iFilter) == 0)
			{
				IBasicVideo *iBasicVideo;
				if( iFilter->QueryInterface(IID_IBasicVideo, (void **)&iBasicVideo) == 0)
				{
					LONG screenWidth;
					LONG screenHeight;
					LONG videoWidth;
					LONG videoHeight;
					if( iVideoWindow->get_Width(&screenWidth) == 0 &&
						iVideoWindow->get_Height(&screenHeight) == 0 &&
						iBasicVideo->GetVideoSize(&videoWidth, &videoHeight) == 0)
					{
						// zoom in by 2 if possible
						if( screenWidth >= videoWidth * 2 &&
							screenHeight >= videoHeight * 2)
						{
							videoWidth *= 2;
							videoHeight *= 2;
						}

						// center the video client area
						iBasicVideo->SetDestinationPosition(
							(screenWidth-videoWidth)/2, (screenHeight-videoHeight)/2,
							videoWidth, videoHeight);
					}

					iBasicVideo->Release();
				}
				iFilter->Release();
			}
#endif
			iVideoWindow->HideCursor(OATRUE);
			iVideoWindow->SetWindowForeground(OATRUE);
		}

		if(iVideoWindow)
		{
			iVideoWindow->Release();
			iVideoWindow = NULL;
		}
	}

	if( hr && !skip_on_fail_flag)
		err.run("video.play error %d", hr );
}
Ejemplo n.º 8
0
HRESULT fsPartMediaPlayer::Open(HANDLE hFile, UINT64 uMaxAvail)
{
	HRESULT hr;

	Close ();

	
	m_stream.Attach (hFile, uMaxAvail);

	
	if (m_stream.Get_MediaType () == NULL)
		return E_FAIL;

	m_reader.Set_MediaType (m_stream.Get_MediaType ());

	

	RIF (CoCreateInstance (CLSID_FilterGraph, NULL, CLSCTX_INPROC,
		IID_IGraphBuilder, (void**) &m_pGB));

	IFilterGraph* pFG = NULL;
	RIF (m_pGB->QueryInterface (IID_IFilterGraph, (void**)&pFG));

	RIF (pFG->AddFilter (&m_reader, NULL));
	pFG->Release ();

	RIF (m_pGB->Render (m_reader.GetPin (0)));

	RIF (m_pGB->QueryInterface (IID_IMediaControl, (void**)&m_pMC));
	RIF (m_pGB->QueryInterface (IID_IMediaEventEx, (void**)&m_pME));
	RIF (m_pGB->QueryInterface (IID_IMediaSeeking, (void**)&m_pMS));
	
	m_pGB->QueryInterface (IID_IVideoWindow, (void**)&m_pVW);
	m_pGB->QueryInterface (IID_IBasicAudio, (void**)&m_pBA);

	IBasicVideo* pBV = NULL;
	m_pGB->QueryInterface (IID_IBasicVideo, (void**) &pBV);
	if (pBV != NULL)
	{
		long nW, nH;
		pBV->get_VideoWidth (&nW);
		pBV->get_VideoHeight (&nH);
		m_fVideoRatio = (double)nW / nH;
		pBV->Release ();
	}
	else
	{
		m_fVideoRatio = 1;
	}

	if (m_pVW)
	{
		if (FAILED (m_pVW->put_MessageDrain ((OAHWND)m_hOutWnd)))
		{
			SAFE_RELEASE (m_pVW);
		}
	}

	RIF (m_pME->SetNotifyWindow ((OAHWND)m_hOutWnd, WM_VIDEONOTIFY, LONG(this)));

	if (m_pVW)
	{
		m_pVW->put_Visible (OAFALSE);
		m_pVW->put_WindowStyle (WS_CHILD);
		m_pVW->put_Owner ((OAHWND)m_hOutWnd);

		AutoSize ();

		m_pVW->put_Visible (OATRUE);

		m_pVW->SetWindowForeground (-1);
	}

	m_state = VFPS_STOPPED;

	return S_OK;
}
Ejemplo n.º 9
0
HRESULT fsPartMediaPlayer::Open2(LPCSTR pszFile)
{
	HRESULT hr;

	Close ();

	RIF (CoCreateInstance (CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void**) &m_pGB));

	WCHAR wszFile [MAX_PATH];
	MultiByteToWideChar (CP_ACP, 0, pszFile, -1, wszFile, MAX_PATH);

	RIF (m_pGB->RenderFile (wszFile, NULL));

	RIF (m_pGB->QueryInterface (IID_IMediaControl, (void**) &m_pMC));
    RIF (m_pGB->QueryInterface (IID_IMediaEventEx, (void**) &m_pME));
    RIF (m_pGB->QueryInterface (IID_IMediaSeeking, (void**) &m_pMS));

	m_pGB->QueryInterface (IID_IVideoWindow, (void**) &m_pVW);

	IBasicVideo* pBV = NULL;
	m_pGB->QueryInterface (IID_IBasicVideo, (void**) &pBV);
	if (pBV != NULL)
	{
		long nW, nH;
		pBV->get_VideoWidth (&nW);
		pBV->get_VideoHeight (&nH);
		m_fVideoRatio = (double)nW / nH;
	}
	else
	{
		m_fVideoRatio = 1;
	}

    
    RIF (m_pGB->QueryInterface (IID_IBasicAudio, (void**) &m_pBA));

	BOOL bAudioOnly = m_pVW == NULL || pBV == NULL;

	if (pBV)
		pBV->Release ();

	if (bAudioOnly == FALSE)
	{
		long l;
		if (FAILED (m_pVW->get_Visible (&l)))
			bAudioOnly = TRUE;
	}

	

	if (m_pVW)
	{
		if (FAILED (m_pVW->put_MessageDrain ((OAHWND)m_hOutWnd)))
		{
			SAFE_RELEASE (m_pVW);
		}
	}

	RIF (m_pME->SetNotifyWindow ((OAHWND)m_hOutWnd, WM_VIDEONOTIFY, LONG(this)));

	if (m_pVW)
	{
		m_pVW->put_Visible (OAFALSE);
		m_pVW->put_WindowStyle (WS_CHILD);
		m_pVW->put_Owner ((OAHWND)m_hOutWnd);

		AutoSize ();

		m_pVW->put_Visible (OATRUE);

		m_pVW->SetWindowForeground (-1);
	}

	m_state = VFPS_STOPPED;

	return S_OK;
}
Ejemplo n.º 10
0
	virtual HRESULT SetVideoPosition(RECT *pSrc, RECT *pDst, BOOL hideMouse)
	{
		if (!m_pGraph) return E_FAIL;
		if (m_pVmrAllocator && pSrc && pDst)
		{
			// Update our VMR9 window positioning for mouse events to work (this may only
			// work on XP, I think it will still fail on 2K)
			m_pVmrAllocator->UpdateVideoPosition(pSrc, pDst);
			return S_OK;
		}

		IBasicVideo* pBV = NULL;
		HRESULT hr = m_pGraph->QueryInterface(IID_IBasicVideo, (void**)&pBV);
		if (SUCCEEDED(hr))
		{
	/*		long nativeWidth;
			hr = pBV->get_VideoWidth(&nativeWidth);
			if (FAILED(hr))
			{
				SAFE_RELEASE(pBV);
				// no video is present
				return;
			}
	*/
			long srcTop, srcLeft, srcWidth, srcHeight;
			pBV->GetSourcePosition(&srcLeft, &srcTop, &srcWidth, &srcHeight);
			pBV->GetDestinationPosition(&srcLeft, &srcTop, &srcWidth, &srcHeight);
			if (pSrc)
			{
				pBV->SetSourcePosition(pSrc->left, pSrc->top, pSrc->right - pSrc->left, pSrc->bottom - pSrc->top);
			}
			else
			{
				pBV->SetDefaultSourcePosition();
			}
			if (pDst)
			{
				pBV->SetDestinationPosition(pDst->left, pDst->top, pDst->right - pDst->left, pDst->bottom - pDst->top);
			}
			else
			{
				pBV->SetDefaultDestinationPosition();
			}
			SAFE_RELEASE(pBV);

			IVideoWindow* pVW = NULL;
			hr = m_pGraph->QueryInterface(IID_IVideoWindow, (void**)&pVW);
			if (SUCCEEDED(hr))
			{
				OAHWND vidWinHWND;
				hr = pVW->get_Owner(&vidWinHWND);
				if (SUCCEEDED(hr))
				{
					RECT grc;
					GetClientRect((HWND)vidWinHWND, &grc);
					pVW->SetWindowPosition(0, 0, grc.right, grc.bottom);
				}
				pVW->HideCursor(hideMouse == JNI_TRUE ? OATRUE : OAFALSE);
				SAFE_RELEASE(pVW);
			}
		}
		return S_OK;
	}