Esempio n. 1
1
void playNormalVideo()
{
	IGraphBuilder *pGraphBuilder;
	IMediaControl *pMediaControl;
	IMediaEvent *pMediaEvent;
	long eventCode;

	CoInitialize(NULL);

	CoCreateInstance(CLSID_FilterGraph,
		NULL,
		CLSCTX_INPROC,
		IID_IGraphBuilder,
		(LPVOID *)&pGraphBuilder);

	pGraphBuilder->QueryInterface(IID_IMediaControl,
		(LPVOID *)&pMediaControl);

	pGraphBuilder->QueryInterface(IID_IMediaEvent,
		(LPVOID *)&pMediaEvent);

	pMediaControl->RenderFile(L"Rscreen_shortFinger.avi");

	pMediaControl->Run();

	FILTER_STATE fs;
	HRESULT hr = pMediaControl->GetState(100, (OAFilterState*)&fs);

	// The first argument is timeout value.
	// If you change the "-1" part into "2",
	// WaitForCompletion will timeout after 2 seconds.
	pMediaEvent->WaitForCompletion(-1, &eventCode);
	switch (eventCode) {
	 case 0:
		 printf("timeout\n");
		 break;
	 case EC_COMPLETE:
		 printf("complete\n");
		 break;
	 case EC_ERRORABORT:
		 printf("errorabort\n");
		 break;
	 case EC_USERABORT:
		 printf("userabort\n");
		 break;
	}

	hr = pMediaControl->GetState(100, (OAFilterState*)&fs);
	pMediaControl->Run();
	hr = pMediaControl->GetState(100, (OAFilterState*)&fs);
	pMediaEvent->WaitForCompletion(-1, &eventCode);

	pMediaControl->Release();
	pGraphBuilder->Release();
	CoUninitialize();
}
Esempio n. 2
0
void Video::on_graph_notify()
{
	IMediaEvent *pME;
	LONG lEventCode;
        LONG_PTR lParam1, lParam2;
	HRESULT hr;

	if( (hr=pGraph->QueryInterface(IID_IMediaEvent, (void **) &pME)) == 0)
	{
		if( (hr=pME->GetEvent(&lEventCode, &lParam1, &lParam2, 0)) == 0)
		{
			switch(lEventCode)
			{
			case EC_COMPLETE:
				stop();
				break;

			case EC_USERABORT:
			case EC_ERRORABORT:
				abort();
				break;
			}
		}
		pME->Release();
	}

	if( hr && !skip_on_fail_flag)
		err.run("video.on_graph_notify error %d", hr);
}
Esempio n. 3
0
void Video::init()
{
	IMediaEvent *pME;
	HRESULT hr;

	init_success = 0;
	hwnd = NULL;
	if( ( hr = CoCreateInstance(CLSID_FilterGraph,     // CLSID of object
								NULL,                         // Outer unknown
								CLSCTX_INPROC_SERVER,         // Type of server
								IID_IGraphBuilder,            // Interface wanted
								(void **) &pGraph)            // Returned object
								) == 0 )
	{
		// We use this to find out events sent by the filtergraph
		if( (hr = pGraph->QueryInterface(IID_IMediaEvent, (void **) &pME)) == 0)
		{
			if( (hr = pME->GetEventHandle( (OAEVENT*) &hGraphNotifyEvent)) == 0)
			{
				init_success = 1;
				state = STOPPED;
			}
			pME->Release();
		}
	}

	if( hr && !skip_on_fail_flag)
	{
		err.run("video.init error %ld", hr );
	}
}
//------------------------------------------------------------------------------
// Name: WaitForCompletion()
// Desc: Desc: Waits for a media event that signifies completion or cancellation
//       of a task.
//
// pGraph: Pointer to the Filter Graph Manager's IGraphBuilder interface.
//------------------------------------------------------------------------------
LONG WaitForCompletion( IGraphBuilder *pGraph )
{
    HRESULT hr;
    LONG lEvCode = 0;
    IMediaEvent *pEvent;

    pGraph->QueryInterface(IID_IMediaEvent, (void **) &pEvent);

    do
    {
        MSG Message;

        // Pump queued Windows messages
        while(PeekMessage(&Message, NULL, 0, 0, TRUE))
        {
            TranslateMessage(&Message);
            DispatchMessage(&Message);
        }

        // Wait 10ms for an event
        hr = pEvent->WaitForCompletion(10, &lEvCode);

    } while(lEvCode == 0);

    pEvent->Release();
    return lEvCode;
}
Esempio n. 5
0
void video_start(int id, bool loop) {
	get_video(videoStruct, id);
	IMediaControl *pControl = NULL;
    IMediaEvent   *pEvent = NULL;
    HRESULT hr = videoStruct->pGraph->QueryInterface(IID_IMediaControl, (void **)&pControl);
    hr = videoStruct->pGraph->QueryInterface(IID_IMediaEvent, (void **)&pEvent);
	
	// Run the graph.
    hr = pControl->Run();
    while (SUCCEEDED(hr)) {
        if (SUCCEEDED(hr)) {
            // Wait for completion.
            long evCode;
            pEvent->WaitForCompletion(INFINITE, &evCode);
        } else {
			MessageBox(NULL, "Failed to run the COM control.", "ERROR", MB_ICONERROR | MB_OK);
			// Don't return so pointers can be released.
		}
		
		if (loop) {
			video_set_seek(id, 0);
		} else {
			break;
		}
    } 
	if (FAILED(hr)) {
		MessageBox(NULL, "Failed to render the Filter Graph Manager.", "ERROR", MB_ICONERROR | MB_OK);
		// Don't return so pointers can be released.
    }

    pControl->Release();
	pEvent->Release();
}
Esempio n. 6
0
void main()
{
	int option;
    IGraphBuilder *pGraph = NULL;  //Creem l'apuntador al graf de filtres
	IMediaControl *pControl = NULL; //creem l'apuntador a un controlador per ayurar i iniciar el graf 
	IMediaEvent *pEvent = NULL; // apunta a l'objecte necessari per obtenir events del filter graph manager
	//IBaseFilter *pGrabberF = NULL;
    //ISampleGrabber *pGrabber = NULL;

	HRESULT hr = CoInitialize(NULL); // Inicialitzem la llibreria COM
	if ( FAILED(hr) ){
		printf("ERROR - Could not initialize COM library");
        return;
	}
	// Create the filter graph manager and query for interfaces.
    hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void **)&pGraph);
    if (FAILED(hr))
    {
        printf("ERROR - Could not create the Filter Graph Manager.");
        return;
    }
	
    hr = pGraph->QueryInterface(IID_IMediaControl, (void **)&pControl);
    hr = pGraph->QueryInterface(IID_IMediaEvent, (void **)&pEvent);

    // Build the graph. IMPORTANT: Change this string to a file on your system.
	cout<<"introduce 1:chicken 2:futbol 3: video futbol audio chicken: \n";
	cin>>option;
	switch(option)
	{
		case 1: hr = pGraph->RenderFile(L"C:\\Users\\Victor\\Downloads\\chicken.wmv", NULL);
			
			break;
		case 2: hr = pGraph->RenderFile(L"C:\\Users\\Victor\\Downloads\\futbol.mpg", NULL);
			break;
		case 3:  // Create the Sample Grabber filter.
  			break;
	}

    if (SUCCEEDED(hr))
    {
        // Run the graph.
        hr = pControl->Run();
        if (SUCCEEDED(hr))
        {
            // Wait for completion.
            long evCode;
            pEvent->WaitForCompletion(INFINITE, &evCode);

            // Note: Do not use INFINITE in a real application, because it
            // can block indefinitely.
        }
    }
    pControl->Release();
    pEvent->Release();
    pGraph->Release();
    CoUninitialize();

}
Esempio n. 7
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();
}
Esempio n. 8
0
CHogVideo::~CHogVideo()
{
    // Wait for completion.
    this->UnHog();

    if (m_pEvent)
    {
        long evCode;
        IMediaEvent *pEvent = (IMediaEvent*)m_pEvent;
        pEvent->WaitForCompletion(INFINITE, &evCode);
    }

    // Clean up.
    this->Cleanup();
}
Esempio n. 9
0
void Video::PlayMovie(string path)
{
	IGraphBuilder *pGraph = NULL;
    IMediaControl *pControl = NULL;
    IMediaEvent   *pEvent = NULL;
	IVideoWindow  *pVideo = NULL;
	
    // Initialize the COM library.
    CoInitialize(NULL);

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

	// Build the graph
	int len;
	int slength = (int)path.length() + 1;
	len = MultiByteToWideChar(CP_ACP, 0, path.c_str(), slength, 0, 0);
	 wchar_t* buf = new wchar_t[len];
	MultiByteToWideChar(CP_ACP, 0, path.c_str(), slength, buf, len);
	 std::wstring r(buf);
	delete[] buf;

	pGraph->RenderFile(LPCWSTR(r.c_str()), NULL);

	// set the owner window
	pGraph->QueryInterface(IID_IVideoWindow, (void **) &pVideo);	
	pVideo->put_Owner((OAHWND)window);
	pVideo->put_WindowStyle( WS_CHILD );
	pVideo->put_Left(0);
	pVideo->put_Top(0);
	

    pGraph->QueryInterface(IID_IMediaControl, (void **)&pControl);
    pGraph->QueryInterface(IID_IMediaEvent, (void **)&pEvent);

	pControl->Run();
	long evCode;
	pEvent->WaitForCompletion(-1, &evCode);
	
	// release controls
    pControl->Release();
    pEvent->Release();
    pGraph->Release();
	pVideo->Release();
    CoUninitialize();
}
Esempio n. 10
0
HRESULT CDShowControl::CreateWmvPlayGraph(HWND hWnd, CString fileName)
{
	IMediaControl *pControl = NULL;
	IMediaEvent   *pEvent = NULL;

	HRESULT hr = S_OK;
	hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER,
		IID_IGraphBuilder, (void **)&m_moviePlayGraph);

	hr = m_moviePlayGraph->QueryInterface(IID_IMediaControl, (void **)&pControl);
	hr = m_moviePlayGraph->QueryInterface(IID_IMediaEvent, (void **)&pEvent);

	hr = pControl->RenderFile(fileName.AllocSysString());
	//    hr = pControl->Run();

	CComQIPtr<IVideoWindow>pVW(m_moviePlayGraph);
	if (pVW != NULL)
	{
		CComQIPtr<IBasicVideo> pBV(m_moviePlayGraph);
		CRect rect,videoRect;
		RETURNIF(pVW->put_Owner((OAHWND)hWnd));
		RETURNIF(pVW->put_WindowStyle(WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS));
		RETURNIF(pVW->put_MessageDrain((long)hWnd));

		CRect ClientRect;
		::GetClientRect(hWnd, &ClientRect);
		pVW->SetWindowPosition(0, 0, ClientRect.Width(), ClientRect.Height());
		pVW->put_AutoShow(OATRUE);
		pVW->put_Visible(OATRUE);
	}

	hr = pControl->Run();

	pControl->Release();
	pEvent->Release();

	return S_OK;
}
Esempio n. 11
0
void CHogVideo::Cleanup()
{
    this->UnHog();

    if (m_pEvent)
    {
        IMediaEvent *pEvent = (IMediaEvent*)m_pEvent;
        pEvent->Release();
        m_pEvent = NULL;
    }

    if (m_pVideoWindow)
    {
        IVideoWindow *pVideoWindow = (IVideoWindow*)m_pVideoWindow;
        pVideoWindow->Release();
        m_pVideoWindow = NULL;
    }

    if (m_pMediaControl)
    {
        IMediaControl *pMediaControl = (IMediaControl*)m_pMediaControl;
        pMediaControl->Release();
        m_pMediaControl = NULL;
    }

    if (m_pGraph)
    {
        IGraphBuilder *pGraph = (IGraphBuilder*)m_pGraph;
        pGraph->Release();
        m_pGraph = NULL;
    }

    if (m_bCOMInitialized)
    {
        CoUninitialize();
        m_bCOMInitialized = false;
    }
}
Esempio n. 12
0
void AudioPlayer::NotificationProc(PVOID dwUser)
{
    AudioPlayer* pThis = (AudioPlayer*)dwUser;

    IMediaEvent* pEvent = NULL;
    HANDLE hEvents[2];//hEvents[0] == The Exit event.  hEvents[1] means there is a media event.
    HRESULT hr;
    DWORD dwResult;
    long lEvent;
    long lParam1;
    long lParam2;

    if(FAILED(hr = pThis->pControl->QueryInterface(IID_IMediaEvent, (PVOID*)&pEvent)))
    {
        odsf(L"AudioPlayer::NotificationProc", L"Could not obtain an IMediaEvent object");
        return;
    }

    if(FAILED(hr = pEvent->GetEventHandle((OAEVENT*)&hEvents[1])))
    {
        odsf(L"AudioPlayer::NotificationProc", L"Could not get event handle");
        return;
    }

    hEvents[0] = pThis->hExitEvent;

    while(1)
    {
        dwResult = WaitForMultipleObjects(2, hEvents, FALSE, INFINITE) - WAIT_OBJECT_0;

        switch(dwResult)
        {
        case 0:
            {
                // We are supposed to exit.
                SAFE_RELEASE(pEvent);
                return;
            }
        case 1:
            {
                // We have events in the queue.  Let's handle them.
                if(FAILED(hr = pEvent->GetEvent(&lEvent, &lParam1, &lParam2, 0)))
                {
                    odsf(L"AudioPlayer::NotificationProc", L"Could not get event data");
                    break;
                }

                // Handle the event.
                switch(lEvent)
                {
                    //case EC_SYSTEMBASE: { odsf(L"AudioPlayer::NotificationProc", L"Event: EC_SYSTEMBASE"); break;}
                    //case EC_USER: { odsf(L"AudioPlayer::NotificationProc", L"Event: EC_USER"); break;}
                    case EC_COMPLETE:
                        {
                            pThis->bPlaying = TRUE;
                            pThis->bUseLastPosition = TRUE;
                            pThis->GetLength(&pThis->dwLastPosition, 0);
                            //odsf(L"AudioPlayer::NotificationProc", L"Event: EC_COMPLETE");
                            pThis->_SendMessage(CCM_COMPLETE);
                            break;
                        }
/*                    case EC_USERABORT: { odsf(L"AudioPlayer::NotificationProc", L"Event: EC_USERABORT"); break;}
                    case EC_ERRORABORT: { odsf(L"AudioPlayer::NotificationProc", L"Event: EC_ERRORABORT"); break;}
                    case EC_TIME: { odsf(L"AudioPlayer::NotificationProc", L"Event: EC_TIME"); break;}
                    case EC_REPAINT: { odsf(L"AudioPlayer::NotificationProc", L"Event: EC_REPAINT"); break;}
                    case EC_STREAM_ERROR_STOPPED: { odsf(L"AudioPlayer::NotificationProc", L"Event: EC_STREAM_ERROR_STOPPED"); break;}
                    case EC_STREAM_ERROR_STILLPLAYING: { odsf(L"AudioPlayer::NotificationProc", L"Event: EC_STREAM_ERROR_STILLPLAYING"); break;}
                    case EC_ERROR_STILLPLAYING: { odsf(L"AudioPlayer::NotificationProc", L"Event: EC_ERROR_STILLPLAYING"); break;}
                    case EC_PALETTE_CHANGED: { odsf(L"AudioPlayer::NotificationProc", L"Event: EC_PALETTE_CHANGED"); break;}
                    case EC_VIDEO_SIZE_CHANGED: { odsf(L"AudioPlayer::NotificationProc", L"Event: EC_VIDEO_SIZE_CHANGED"); break;}
                    case EC_QUALITY_CHANGE: { odsf(L"AudioPlayer::NotificationProc", L"Event: EC_QUALITY_CHANGE"); break;}
                    case EC_SHUTTING_DOWN: { odsf(L"AudioPlayer::NotificationProc", L"Event: EC_SHUTTING_DOWN"); break;}
                    case EC_CLOCK_CHANGED: { odsf(L"AudioPlayer::NotificationProc", L"Event: EC_CLOCK_CHANGED"); break;}
                    //case EC_PAUSED: { odsf(L"AudioPlayer::NotificationProc", L"Event: EC_PAUSED"); break;}
                    case EC_OPENING_FILE	: { odsf(L"AudioPlayer::NotificationProc", L"Event: EC_OPENING_FILE	"); break;}
                    //case EC_BUFFERING_DATA: { odsf(L"AudioPlayer::NotificationProc", L"Event: EC_BUFFERING_DATA"); break;}
                    case EC_FULLSCREEN_LOST: { odsf(L"AudioPlayer::NotificationProc", L"Event: EC_FULLSCREEN_LOST"); break;}
                    case EC_ACTIVATE: { odsf(L"AudioPlayer::NotificationProc", L"Event: EC_ACTIVATE"); break;}
                    case EC_NEED_RESTART: { odsf(L"AudioPlayer::NotificationProc", L"Event: EC_NEED_RESTART"); break;}
                    case EC_WINDOW_DESTROYED: { odsf(L"AudioPlayer::NotificationProc", L"Event: EC_WINDOW_DESTROYED"); break;}
                    case EC_DISPLAY_CHANGED: { odsf(L"AudioPlayer::NotificationProc", L"Event: EC_DISPLAY_CHANGED"); break;}
                    case EC_STARVATION: { odsf(L"AudioPlayer::NotificationProc", L"Event: EC_STARVATION"); break;}
                    case EC_OLE_EVENT			: { odsf(L"AudioPlayer::NotificationProc", L"Event: EC_OLE_EVENT"); break;}
                    case EC_NOTIFY_WINDOW: { odsf(L"AudioPlayer::NotificationProc", L"Event: EC_NOTIFY_WINDOW"); break;}
                    case EC_STREAM_CONTROL_STOPPED	: { odsf(L"AudioPlayer::NotificationProc", L"Event: EC_STREAM_CONTROL_STOPPED"); break;}
                    case EC_STREAM_CONTROL_STARTED	: { odsf(L"AudioPlayer::NotificationProc", L"Event: EC_STREAM_CONTROL_STARTED"); break;}
                    case EC_END_OF_SEGMENT: { odsf(L"AudioPlayer::NotificationProc", L"Event: EC_END_OF_SEGMENT"); break;}
                    case EC_SEGMENT_STARTED: { odsf(L"AudioPlayer::NotificationProc", L"Event: EC_SEGMENT_STARTED"); break;}
                    case EC_LENGTH_CHANGED: { odsf(L"AudioPlayer::NotificationProc", L"Event: EC_LENGTH_CHANGED"); break;}
                    case EC_TIMECODE_AVAILABLE: { odsf(L"AudioPlayer::NotificationProc", L"Event: EC_TIMECODE_AVAILABLE"); break;}
                    case EC_EXTDEVICE_MODE_CHANGE: { odsf(L"AudioPlayer::NotificationProc", L"Event: EC_EXTDEVICE_MODE_CHANGE"); break;}
*/
                }

                break;
            }
        }// switch(dwResult)
    }// while(1)

    return;
}
int _tmain(int argc, _TCHAR* argv[])
{
	IGraphBuilder *pGraph = NULL;
    IMediaControl *pControl = NULL;
    IMediaEvent   *pEvent = NULL; 
	//Get some param--------------
	HRESULT hr1;
	IBasicVideo *pVideo=NULL;
	IBasicAudio *pAudio=NULL;
	IVideoWindow *pWindow=NULL;
	IMediaSeeking *pSeeking=NULL;
	
	
    // Init COM
    HRESULT hr = CoInitialize(NULL);
    if (FAILED(hr)){
        printf("Error - Can't init COM.");
        return -1;
    }

	// Create FilterGraph
   hr=CoCreateInstance(CLSID_FilterGraph, NULL,CLSCTX_INPROC_SERVER,IID_IGraphBuilder, (void **)&pGraph);
    if (FAILED(hr)){
        printf("Error - Can't create Filter Graph.");
        return -1;
    }
   //  Query Interface
    hr = pGraph->QueryInterface(IID_IMediaControl, (void **)&pControl);
    hr = pGraph->QueryInterface(IID_IMediaEvent, (void **)&pEvent);
	// RenderFile
    hr = pGraph->RenderFile(L"cuc_ieschool.mov", NULL);
	if (FAILED(hr)){
		printf("Error - Can't Render File.");
		return -1;
	}
#if OUTPUT_INFO
	//Get some information----------
	long video_w=0,video_h=0,video_bitrate=0,audio_volume=0;
	long long duration_1=0,position_1=0;
	REFTIME avgtimeperframe=0;
	float framerate=0,duration_sec=0,progress=0,position_sec=0;
	//Video
	hr1=pGraph->QueryInterface(IID_IBasicVideo, (void **)&pVideo);
	pVideo->get_VideoWidth(&video_w);
	pVideo->get_VideoHeight(&video_h);
	pVideo->get_AvgTimePerFrame(&avgtimeperframe);
	framerate=1/avgtimeperframe;
	//pVideo->get_BitRate(&video_bitrate);
	//Audio
	hr1=pGraph->QueryInterface(IID_IBasicAudio, (void **)&pAudio);
	//Mute
	//pAudio->put_Volume(-10000);
	printf("Some Information:\n");
	printf("Video Resolution:\t%dx%d\n",video_w,video_h);
	printf("Video Framerate:\t%.3f\n",framerate);
	//Window
	hr1=pGraph->QueryInterface(IID_IVideoWindow, (void **)&pWindow);
	pWindow->put_Caption(L"Simplest DirectShow Player");
	//pWindow->put_Width(480);
	//pWindow->put_Height(272);
	//Seek
	hr1=pGraph->QueryInterface(IID_IMediaSeeking, (void **)&pSeeking);
	pSeeking->GetDuration(&duration_1);
	//time unit:100ns=0.0000001s
	duration_sec=(float)duration_1/10000000.0;
	printf("Duration:\t%.2f s\n",duration_sec);
	//pSeeking->SetPositions();
	//PlayBack Rate
	//pSeeking->SetRate(2.0);

	//Show Filter in FilterGpagh
	show_filters_in_filtergraph(pGraph);
	//----------------------
#endif

	printf("Progress Info\n");
	printf("Position\tProgress\n");
    if (SUCCEEDED(hr)){
        // Run
        hr = pControl->Run();
        if (SUCCEEDED(hr)){
			long evCode=0;
			//pEvent->WaitForCompletion(INFINITE, &evCode);
			while(evCode!=EC_COMPLETE){
				//Info
#if OUTPUT_INFO
				pSeeking->GetCurrentPosition(&position_1);
				position_sec=(float)position_1/10000000.0;
				progress=position_sec*100/duration_sec;
				printf("%7.2fs\t%5.2f%%\n",position_sec,progress);
#endif
				//1000ms
				pEvent->WaitForCompletion(1000, &evCode);
			}
        }
    }
	// Release resource
    pControl->Release();
    pEvent->Release();
    pGraph->Release();
    CoUninitialize();
	return 0;
}
Esempio n. 14
0
int JukeboxDS::player()
{
    if( FAILED(CoInitialize(NULL)) )
		return -1;

	IGraphBuilder *	pGB = NULL;
	IMediaControl *	pMC = NULL;
	IBasicAudio *	pBA = NULL;
	IMediaEvent *	pME = NULL;

	while( m_Active )
	{
		// check the state of the music, if stopped move onto the next file
		if ( pME != NULL )
		{
			long eventCode;
			if ( pME->WaitForCompletion( 0, &eventCode ) == S_OK )
				nextTrack();		// current song has ended, next track
		}

		// check for a volume change
		if ( m_UpdateVolume.signaled() )
		{
			m_UpdateVolume.clear();
			if ( pBA != NULL )
			{
				// set the volume
				long pv = (100 - m_Volume) * -100;
				pBA->put_Volume( pv );
			}
		}

		if (! m_TrackEvent.wait( 250 ) )
		{
			AutoLock lock( &m_Lock );

			if ( m_PlayLists.isValid( m_ActiveList ) && m_PlayLists[ m_ActiveList ].files.isValid( m_CurrentTrack ) )
			{
				// get the filename of the current track
				CharString file = m_PlayLists[ m_ActiveList ].files[ m_CurrentTrack ];

				// release the previous interfaces
				RELEASEQI( pGB );
				RELEASEQI( pMC );
				RELEASEQI( pBA );
				RELEASEQI( pME );

				// Create DirectShow Graph
				if ( FAILED( CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC, IID_IGraphBuilder, (void **)&pGB) ) )
					return -1;
				try {
					// load the first file
					if ( FAILED( pGB->RenderFile( String( file ), NULL ) ) )
						return -1;
				}
				catch( ... )
				{
					// driver failure, don't crash the game due to a bad codec..
					return -1;
				}
				// Get the IMediaControl Interface
				if ( FAILED( pGB->QueryInterface(IID_IMediaControl, (void **)&pMC ) ) )
					return -1;
				// Get the IBasicAudio interface
				if ( FAILED( pGB->QueryInterface(IID_IBasicAudio, (void **)&pBA) ) )
					return -1;
				// Get the IBasicAudio interface
				if ( FAILED( pGB->QueryInterface(IID_IMediaEvent, (void **)&pME) ) )
					return -1;
				// set the volume
				long pv = (100 - m_Volume) * -100;
				pBA->put_Volume( pv );
				// play the music
				pMC->Run();
			}
		}
	}

	RELEASEQI( pGB );
	RELEASEQI( pMC );
	RELEASEQI( pBA );
	RELEASEQI( pME );

	CoUninitialize();

	return 0;
}
Esempio n. 15
0
int main(int argc, char* argv[])
{
    ICaptureGraphBuilder2   *pCaptureGraphBuilder = NULL;
    IGraphBuilder           *pGraphBuilder = NULL;
    IBaseFilter             *pSource = NULL;
    IBaseFilter             *pMux = NULL;
    IBaseFilter             *pVideoCompressor = NULL;
    IBaseFilter             *pAudioCompressor = NULL;

    IAMStreamConfig         *pAMStreamConfig = NULL;
    IAMVideoCompression     *pAMVideoCompression = NULL;

    IMediaControl           *pControl = NULL;
    IMediaSeeking           *pSeek = NULL;
    IMediaEvent             *pEvent = NULL;

    HRESULT hr;

    DWORD pdwRegister=0;
    CoInitialize(NULL);

    // Create the capture graph builder.
    CoCreateInstance(CLSID_CaptureGraphBuilder2, NULL, CLSCTX_INPROC,
                     IID_ICaptureGraphBuilder2, (void **)&pCaptureGraphBuilder);

    // Make the rendering section of the graph.
    pCaptureGraphBuilder->SetOutputFileName(
        &MEDIASUBTYPE_Avi,  // File type.
        L"C:\\STDIUE1.avi",  // File name.
        &pMux,              // pointer to the multiplexer.
        NULL);              // pointer to the file writer.

    // Load the source file.
    pCaptureGraphBuilder->GetFiltergraph(&pGraphBuilder);
    pGraphBuilder->AddSourceFilter(L"C:\\Program Files\\Microsoft Money\\Media\\STDIUE1.avi", L"Source Filter", &pSource);

    // Add the compressor filter.
    CoCreateInstance(CLSID_AVICo, NULL, CLSCTX_INPROC,
                     IID_IBaseFilter, (void **)&pVideoCompressor);
    pGraphBuilder->AddFilter(pVideoCompressor, L"Video Compressor");

    // Render the video stream, through the compressor.
    pCaptureGraphBuilder->RenderStream(
        NULL,       // Output pin category
        NULL,       // Media type
        pSource,       // Source filter
        pVideoCompressor,     // Compressor filter
        pMux);      // Sink filter (the AVI Mux)

    /* CoCreateInstance(CLSID_GSM, NULL, CLSCTX_INPROC,
             IID_IBaseFilter, (void **)&pAudioCompressor);
     pGraphBuilder->AddFilter(pAudioCompressor, L"Audio Compressor");*/

    // Render the audio stream.
    pCaptureGraphBuilder->RenderStream(
        NULL,
        NULL,
        pSource,
        pAudioCompressor,
        pMux);

    // Compress at 100k/second data rate.
    AM_MEDIA_TYPE *pmt;
    pCaptureGraphBuilder->FindInterface(NULL, NULL, pVideoCompressor, IID_IAMStreamConfig, (void **)&pAMStreamConfig);

    pAMStreamConfig->GetFormat(&pmt);

    if (pmt->formattype == FORMAT_VideoInfo)
    {

        ((VIDEOINFOHEADER *)(pmt->pbFormat))->dwBitRate = 100000;

        pAMStreamConfig->SetFormat(pmt);
    }


    // Request key frames every four frames.
    pAMStreamConfig->QueryInterface(IID_IAMVideoCompression, (void **)&pAMVideoCompression);
    pAMVideoCompression->put_KeyFrameRate(4);
    pAMVideoCompression->Release();
    pAMStreamConfig->Release();

    // Run the graph.

    pGraphBuilder->QueryInterface(IID_IMediaControl, (void **)&pControl);
    pGraphBuilder->QueryInterface(IID_IMediaEvent, (void **)&pEvent);

    hr = pMux->QueryInterface(IID_IMediaSeeking, (void**)&pSeek);


    pControl->Run();
    printf("Recompressing... \n");

    long evCode;
    if (SUCCEEDED(hr))
    {
        REFERENCE_TIME rtTotal, rtNow = 0;
        pSeek->GetDuration(&rtTotal);
        while ((pEvent->WaitForCompletion(1000, &evCode)) == E_ABORT)
        {
            pSeek->GetCurrentPosition(&rtNow);
            printf("%d%%\n", (rtNow * 100)/rtTotal);
        }
        pSeek->Release();
    }
    else  // Cannot update the progress.
    {
        pEvent->WaitForCompletion(INFINITE, &evCode);
    }
    pControl->Stop();
    printf("All done\n");

    pSource->Release();
    pMux->Release();
    pVideoCompressor->Release();
    pAudioCompressor->Release ();
    pControl->Release();
    pEvent->Release();
    pCaptureGraphBuilder->Release();
    pGraphBuilder->Release();
    CoUninitialize();

    return 0;
}
Esempio n. 16
0
int _tmain(int argc, _TCHAR* argv[])
{

	int y;
	cin>>y;
	//
	IGraphBuilder* locGraphBuilder = NULL;
	IMediaControl* locMediaControl = NULL;
	IBaseFilter* locDemuxer = NULL;
	ICustomSource* locCustomSourceSetter = NULL;
	HRESULT locHR = S_FALSE;;
	CoInitialize(NULL);
	locHR = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void **)&locGraphBuilder);

	locHR = CoCreateInstance(CLSID_OggDemuxPacketSourceFilter, NULL, CLSCTX_INPROC_SERVER, IID_IBaseFilter, (void**)&locDemuxer);

	locGraphBuilder->AddFilter(locDemuxer, L"Custom Ogg Source");
	locDemuxer->QueryInterface(IID_ICustomSource, (void**)&locCustomSourceSetter);


	CustomSourceClass* locCustomFileSourceInterface = new CustomSourceClass;
	locCustomFileSourceInterface->open("D:\\testfile.ogg");
	
	locCustomSourceSetter->setCustomSourceAndLoad(locCustomFileSourceInterface);

	//Do not release, it's not really a COM interface
	//locCustomSourceSetter->Release();

	IEnumPins* locPinEnum = NULL;

	locDemuxer->EnumPins(&locPinEnum);

	

	IPin* locPin = NULL;
	ULONG locHowMany = 0;
	while (locPinEnum->Next(1, &locPin, &locHowMany) == S_OK) {
		locHR = locGraphBuilder->Render(locPin);
		locPin->Release();
		locPin = NULL;
	}






	//locHR = locGraphBuilder->RenderFile(L"g:\\a.ogg", NULL);

	locHR = locGraphBuilder->QueryInterface(IID_IMediaControl, (void**)&locMediaControl);


	locHR = locMediaControl->Run();

	IMediaEvent* locMediaEvent = NULL;
	locHR = locGraphBuilder->QueryInterface(IID_IMediaEvent, (void**)&locMediaEvent);
	
	HANDLE  hEvent; 
	long    evCode, param1, param2;
	BOOLEAN bDone = FALSE;
	HRESULT hr = S_OK;
	hr = locMediaEvent->GetEventHandle((OAEVENT*)&hEvent);
	if (FAILED(hr))
	{
	    /* Insert failure-handling code here. */
	}
	while(!bDone) 
	{
	    if (WAIT_OBJECT_0 == WaitForSingleObject(hEvent, 100))
	    { 
			while (hr = locMediaEvent->GetEvent(&evCode, &param1, &param2, 0), SUCCEEDED(hr)) 
			{
	            //printf("Event code: %#04x\n Params: %d, %d\n", evCode, param1, param2);
				cout<<"Event : "<<evCode<<" Params : "<<param1<<", "<<param2<<endl;
				locMediaEvent->FreeEventParams(evCode, param1, param2);
				bDone = (EC_COMPLETE == evCode);
			}
		}
	} 

	cout<<"Finished..."<<endl;
	int x;
	cin>>x;
	locMediaControl->Release();
	locGraphBuilder->Release();
	CoUninitialize();

	return 0;
}