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.

     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/. */
     6 #ifndef _DirectShowUtils_h_
     7 #define _DirectShowUtils_h_
     9 #include <stdint.h>
    10 #include "dshow.h"
    11 #include "DShowTools.h"
    12 #include "prlog.h"
    14 namespace mozilla {
    16 // Win32 "Event" wrapper. Must be paired with a CriticalSection to create a
    17 // Java-style "monitor".
    18 class Signal {
    19 public:
    21   Signal(CriticalSection* aLock)
    22     : mLock(aLock)
    23   {
    24     CriticalSectionAutoEnter lock(*mLock);
    25     mEvent = CreateEvent(nullptr, FALSE, FALSE, nullptr);
    26   }
    28   ~Signal() {
    29     CriticalSectionAutoEnter lock(*mLock);
    30     CloseHandle(mEvent);
    31   }
    33   // Lock must be held.
    34   void Notify() {
    35     SetEvent(mEvent);
    36   }
    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   }
    46 private:
    47   CriticalSection* mLock;
    48   HANDLE mEvent;
    49 };
    51 HRESULT
    52 AddGraphToRunningObjectTable(IUnknown *aUnkGraph, DWORD *aOutRotRegister);
    54 void
    55 RemoveGraphFromRunningObjectTable(DWORD aRotRegister);
    57 const char*
    58 GetGraphNotifyString(long evCode);
    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);
    67 HRESULT
    68 AddMP3DMOWrapperFilter(IGraphBuilder* aGraph,
    69                        IBaseFilter **aOutFilter);
    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);
    78 HRESULT
    79 MatchUnconnectedPin(IPin* aPin,
    80                     PIN_DIRECTION aPinDir,
    81                     bool *aOutMatches);
    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 }
    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 }
    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 }
   108 #if defined(PR_LOGGING)
   109 const char*
   110 GetDirectShowGuidName(const GUID& aGuid);
   111 #endif
   113 } // namespace mozilla
   115 #endif

mercurial