1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/media/directshow/DirectShowUtils.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,115 @@ 1.4 +/* vim:set ts=2 sw=2 sts=2 et cindent: */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef _DirectShowUtils_h_ 1.10 +#define _DirectShowUtils_h_ 1.11 + 1.12 +#include <stdint.h> 1.13 +#include "dshow.h" 1.14 +#include "DShowTools.h" 1.15 +#include "prlog.h" 1.16 + 1.17 +namespace mozilla { 1.18 + 1.19 +// Win32 "Event" wrapper. Must be paired with a CriticalSection to create a 1.20 +// Java-style "monitor". 1.21 +class Signal { 1.22 +public: 1.23 + 1.24 + Signal(CriticalSection* aLock) 1.25 + : mLock(aLock) 1.26 + { 1.27 + CriticalSectionAutoEnter lock(*mLock); 1.28 + mEvent = CreateEvent(nullptr, FALSE, FALSE, nullptr); 1.29 + } 1.30 + 1.31 + ~Signal() { 1.32 + CriticalSectionAutoEnter lock(*mLock); 1.33 + CloseHandle(mEvent); 1.34 + } 1.35 + 1.36 + // Lock must be held. 1.37 + void Notify() { 1.38 + SetEvent(mEvent); 1.39 + } 1.40 + 1.41 + // Lock must be held. Check the wait condition before waiting! 1.42 + HRESULT Wait() { 1.43 + mLock->Leave(); 1.44 + DWORD result = WaitForSingleObject(mEvent, INFINITE); 1.45 + mLock->Enter(); 1.46 + return result == WAIT_OBJECT_0 ? S_OK : E_FAIL; 1.47 + } 1.48 + 1.49 +private: 1.50 + CriticalSection* mLock; 1.51 + HANDLE mEvent; 1.52 +}; 1.53 + 1.54 +HRESULT 1.55 +AddGraphToRunningObjectTable(IUnknown *aUnkGraph, DWORD *aOutRotRegister); 1.56 + 1.57 +void 1.58 +RemoveGraphFromRunningObjectTable(DWORD aRotRegister); 1.59 + 1.60 +const char* 1.61 +GetGraphNotifyString(long evCode); 1.62 + 1.63 +// Creates a filter and adds it to a graph. 1.64 +HRESULT 1.65 +CreateAndAddFilter(IGraphBuilder* aGraph, 1.66 + REFGUID aFilterClsId, 1.67 + LPCWSTR aFilterName, 1.68 + IBaseFilter **aOutFilter); 1.69 + 1.70 +HRESULT 1.71 +AddMP3DMOWrapperFilter(IGraphBuilder* aGraph, 1.72 + IBaseFilter **aOutFilter); 1.73 + 1.74 +// Connects the output pin on aOutputFilter to an input pin on 1.75 +// aInputFilter, in aGraph. 1.76 +HRESULT 1.77 +ConnectFilters(IGraphBuilder* aGraph, 1.78 + IBaseFilter* aOutputFilter, 1.79 + IBaseFilter* aInputFilter); 1.80 + 1.81 +HRESULT 1.82 +MatchUnconnectedPin(IPin* aPin, 1.83 + PIN_DIRECTION aPinDir, 1.84 + bool *aOutMatches); 1.85 + 1.86 +// Converts from microseconds to DirectShow "Reference Time" 1.87 +// (hundreds of nanoseconds). 1.88 +inline int64_t 1.89 +UsecsToRefTime(const int64_t aUsecs) 1.90 +{ 1.91 + return aUsecs * 10; 1.92 +} 1.93 + 1.94 +// Converts from DirectShow "Reference Time" (hundreds of nanoseconds) 1.95 +// to microseconds. 1.96 +inline int64_t 1.97 +RefTimeToUsecs(const int64_t hRefTime) 1.98 +{ 1.99 + return hRefTime / 10; 1.100 +} 1.101 + 1.102 +// Converts from DirectShow "Reference Time" (hundreds of nanoseconds) 1.103 +// to seconds. 1.104 +inline double 1.105 +RefTimeToSeconds(const REFERENCE_TIME aRefTime) 1.106 +{ 1.107 + return double(aRefTime) / 10000000; 1.108 +} 1.109 + 1.110 + 1.111 +#if defined(PR_LOGGING) 1.112 +const char* 1.113 +GetDirectShowGuidName(const GUID& aGuid); 1.114 +#endif 1.115 + 1.116 +} // namespace mozilla 1.117 + 1.118 +#endif