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