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); }
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[]) { 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, ¶m1, ¶m2, 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; }