michael@0: /* vim:set ts=2 sw=2 sts=2 et cindent: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef _DirectShowUtils_h_ michael@0: #define _DirectShowUtils_h_ michael@0: michael@0: #include michael@0: #include "dshow.h" michael@0: #include "DShowTools.h" michael@0: #include "prlog.h" michael@0: michael@0: namespace mozilla { michael@0: michael@0: // Win32 "Event" wrapper. Must be paired with a CriticalSection to create a michael@0: // Java-style "monitor". michael@0: class Signal { michael@0: public: michael@0: michael@0: Signal(CriticalSection* aLock) michael@0: : mLock(aLock) michael@0: { michael@0: CriticalSectionAutoEnter lock(*mLock); michael@0: mEvent = CreateEvent(nullptr, FALSE, FALSE, nullptr); michael@0: } michael@0: michael@0: ~Signal() { michael@0: CriticalSectionAutoEnter lock(*mLock); michael@0: CloseHandle(mEvent); michael@0: } michael@0: michael@0: // Lock must be held. michael@0: void Notify() { michael@0: SetEvent(mEvent); michael@0: } michael@0: michael@0: // Lock must be held. Check the wait condition before waiting! michael@0: HRESULT Wait() { michael@0: mLock->Leave(); michael@0: DWORD result = WaitForSingleObject(mEvent, INFINITE); michael@0: mLock->Enter(); michael@0: return result == WAIT_OBJECT_0 ? S_OK : E_FAIL; michael@0: } michael@0: michael@0: private: michael@0: CriticalSection* mLock; michael@0: HANDLE mEvent; michael@0: }; michael@0: michael@0: HRESULT michael@0: AddGraphToRunningObjectTable(IUnknown *aUnkGraph, DWORD *aOutRotRegister); michael@0: michael@0: void michael@0: RemoveGraphFromRunningObjectTable(DWORD aRotRegister); michael@0: michael@0: const char* michael@0: GetGraphNotifyString(long evCode); michael@0: michael@0: // Creates a filter and adds it to a graph. michael@0: HRESULT michael@0: CreateAndAddFilter(IGraphBuilder* aGraph, michael@0: REFGUID aFilterClsId, michael@0: LPCWSTR aFilterName, michael@0: IBaseFilter **aOutFilter); michael@0: michael@0: HRESULT michael@0: AddMP3DMOWrapperFilter(IGraphBuilder* aGraph, michael@0: IBaseFilter **aOutFilter); michael@0: michael@0: // Connects the output pin on aOutputFilter to an input pin on michael@0: // aInputFilter, in aGraph. michael@0: HRESULT michael@0: ConnectFilters(IGraphBuilder* aGraph, michael@0: IBaseFilter* aOutputFilter, michael@0: IBaseFilter* aInputFilter); michael@0: michael@0: HRESULT michael@0: MatchUnconnectedPin(IPin* aPin, michael@0: PIN_DIRECTION aPinDir, michael@0: bool *aOutMatches); michael@0: michael@0: // Converts from microseconds to DirectShow "Reference Time" michael@0: // (hundreds of nanoseconds). michael@0: inline int64_t michael@0: UsecsToRefTime(const int64_t aUsecs) michael@0: { michael@0: return aUsecs * 10; michael@0: } michael@0: michael@0: // Converts from DirectShow "Reference Time" (hundreds of nanoseconds) michael@0: // to microseconds. michael@0: inline int64_t michael@0: RefTimeToUsecs(const int64_t hRefTime) michael@0: { michael@0: return hRefTime / 10; michael@0: } michael@0: michael@0: // Converts from DirectShow "Reference Time" (hundreds of nanoseconds) michael@0: // to seconds. michael@0: inline double michael@0: RefTimeToSeconds(const REFERENCE_TIME aRefTime) michael@0: { michael@0: return double(aRefTime) / 10000000; michael@0: } michael@0: michael@0: michael@0: #if defined(PR_LOGGING) michael@0: const char* michael@0: GetDirectShowGuidName(const GUID& aGuid); michael@0: #endif michael@0: michael@0: } // namespace mozilla michael@0: michael@0: #endif