content/media/directshow/DirectShowUtils.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* vim:set ts=2 sw=2 sts=2 et cindent: */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #ifndef _DirectShowUtils_h_
michael@0 7 #define _DirectShowUtils_h_
michael@0 8
michael@0 9 #include <stdint.h>
michael@0 10 #include "dshow.h"
michael@0 11 #include "DShowTools.h"
michael@0 12 #include "prlog.h"
michael@0 13
michael@0 14 namespace mozilla {
michael@0 15
michael@0 16 // Win32 "Event" wrapper. Must be paired with a CriticalSection to create a
michael@0 17 // Java-style "monitor".
michael@0 18 class Signal {
michael@0 19 public:
michael@0 20
michael@0 21 Signal(CriticalSection* aLock)
michael@0 22 : mLock(aLock)
michael@0 23 {
michael@0 24 CriticalSectionAutoEnter lock(*mLock);
michael@0 25 mEvent = CreateEvent(nullptr, FALSE, FALSE, nullptr);
michael@0 26 }
michael@0 27
michael@0 28 ~Signal() {
michael@0 29 CriticalSectionAutoEnter lock(*mLock);
michael@0 30 CloseHandle(mEvent);
michael@0 31 }
michael@0 32
michael@0 33 // Lock must be held.
michael@0 34 void Notify() {
michael@0 35 SetEvent(mEvent);
michael@0 36 }
michael@0 37
michael@0 38 // Lock must be held. Check the wait condition before waiting!
michael@0 39 HRESULT Wait() {
michael@0 40 mLock->Leave();
michael@0 41 DWORD result = WaitForSingleObject(mEvent, INFINITE);
michael@0 42 mLock->Enter();
michael@0 43 return result == WAIT_OBJECT_0 ? S_OK : E_FAIL;
michael@0 44 }
michael@0 45
michael@0 46 private:
michael@0 47 CriticalSection* mLock;
michael@0 48 HANDLE mEvent;
michael@0 49 };
michael@0 50
michael@0 51 HRESULT
michael@0 52 AddGraphToRunningObjectTable(IUnknown *aUnkGraph, DWORD *aOutRotRegister);
michael@0 53
michael@0 54 void
michael@0 55 RemoveGraphFromRunningObjectTable(DWORD aRotRegister);
michael@0 56
michael@0 57 const char*
michael@0 58 GetGraphNotifyString(long evCode);
michael@0 59
michael@0 60 // Creates a filter and adds it to a graph.
michael@0 61 HRESULT
michael@0 62 CreateAndAddFilter(IGraphBuilder* aGraph,
michael@0 63 REFGUID aFilterClsId,
michael@0 64 LPCWSTR aFilterName,
michael@0 65 IBaseFilter **aOutFilter);
michael@0 66
michael@0 67 HRESULT
michael@0 68 AddMP3DMOWrapperFilter(IGraphBuilder* aGraph,
michael@0 69 IBaseFilter **aOutFilter);
michael@0 70
michael@0 71 // Connects the output pin on aOutputFilter to an input pin on
michael@0 72 // aInputFilter, in aGraph.
michael@0 73 HRESULT
michael@0 74 ConnectFilters(IGraphBuilder* aGraph,
michael@0 75 IBaseFilter* aOutputFilter,
michael@0 76 IBaseFilter* aInputFilter);
michael@0 77
michael@0 78 HRESULT
michael@0 79 MatchUnconnectedPin(IPin* aPin,
michael@0 80 PIN_DIRECTION aPinDir,
michael@0 81 bool *aOutMatches);
michael@0 82
michael@0 83 // Converts from microseconds to DirectShow "Reference Time"
michael@0 84 // (hundreds of nanoseconds).
michael@0 85 inline int64_t
michael@0 86 UsecsToRefTime(const int64_t aUsecs)
michael@0 87 {
michael@0 88 return aUsecs * 10;
michael@0 89 }
michael@0 90
michael@0 91 // Converts from DirectShow "Reference Time" (hundreds of nanoseconds)
michael@0 92 // to microseconds.
michael@0 93 inline int64_t
michael@0 94 RefTimeToUsecs(const int64_t hRefTime)
michael@0 95 {
michael@0 96 return hRefTime / 10;
michael@0 97 }
michael@0 98
michael@0 99 // Converts from DirectShow "Reference Time" (hundreds of nanoseconds)
michael@0 100 // to seconds.
michael@0 101 inline double
michael@0 102 RefTimeToSeconds(const REFERENCE_TIME aRefTime)
michael@0 103 {
michael@0 104 return double(aRefTime) / 10000000;
michael@0 105 }
michael@0 106
michael@0 107
michael@0 108 #if defined(PR_LOGGING)
michael@0 109 const char*
michael@0 110 GetDirectShowGuidName(const GUID& aGuid);
michael@0 111 #endif
michael@0 112
michael@0 113 } // namespace mozilla
michael@0 114
michael@0 115 #endif

mercurial