Fri, 16 Jan 2015 04:50:19 +0100
Replace accessor implementation with direct member state manipulation, by
request https://trac.torproject.org/projects/tor/ticket/9701#comment:32
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef WMFUtils_h
8 #define WMFUtils_h
10 #include "WMF.h"
11 #include "nsString.h"
12 #include "nsRect.h"
13 #include "VideoUtils.h"
15 // Various utilities shared by WMF backend files.
17 namespace mozilla {
19 nsCString
20 GetGUIDName(const GUID& guid);
22 // Returns true if the reader has a stream with the specified index.
23 // Index can be a specific index, or one of:
24 // MF_SOURCE_READER_FIRST_VIDEO_STREAM
25 // MF_SOURCE_READER_FIRST_AUDIO_STREAM
26 bool
27 SourceReaderHasStream(IMFSourceReader* aReader, const DWORD aIndex);
29 // Auto manages the lifecycle of a PROPVARIANT.
30 class AutoPropVar {
31 public:
32 AutoPropVar() {
33 PropVariantInit(&mVar);
34 }
35 ~AutoPropVar() {
36 PropVariantClear(&mVar);
37 }
38 operator PROPVARIANT&() {
39 return mVar;
40 }
41 PROPVARIANT* operator->() {
42 return &mVar;
43 }
44 PROPVARIANT* operator&() {
45 return &mVar;
46 }
47 private:
48 PROPVARIANT mVar;
49 };
51 // Converts from microseconds to hundreds of nanoseconds.
52 // We use microseconds for our timestamps, whereas WMF uses
53 // hundreds of nanoseconds.
54 inline int64_t
55 UsecsToHNs(int64_t aUsecs) {
56 return aUsecs * 10;
57 }
59 // Converts from hundreds of nanoseconds to microseconds.
60 // We use microseconds for our timestamps, whereas WMF uses
61 // hundreds of nanoseconds.
62 inline int64_t
63 HNsToUsecs(int64_t hNanoSecs) {
64 return hNanoSecs / 10;
65 }
67 // Assigns aUnknown to *aInterface, and AddRef's it.
68 // Helper for MSCOM QueryInterface implementations.
69 HRESULT
70 DoGetInterface(IUnknown* aUnknown, void** aInterface);
72 HRESULT
73 HNsToFrames(int64_t aHNs, uint32_t aRate, int64_t* aOutFrames);
75 HRESULT
76 FramesToUsecs(int64_t aSamples, uint32_t aRate, int64_t* aOutUsecs);
78 HRESULT
79 GetDefaultStride(IMFMediaType *aType, uint32_t* aOutStride);
81 int32_t
82 MFOffsetToInt32(const MFOffset& aOffset);
84 // Gets the sub-region of the video frame that should be displayed.
85 // See: http://msdn.microsoft.com/en-us/library/windows/desktop/bb530115(v=vs.85).aspx
86 HRESULT
87 GetPictureRegion(IMFMediaType* aMediaType, nsIntRect& aOutPictureRegion);
89 // Returns the duration of a IMFSample in microseconds.
90 // Returns -1 on failure.
91 int64_t
92 GetSampleDuration(IMFSample* aSample);
94 // Returns the presentation time of a IMFSample in microseconds.
95 // Returns -1 on failure.
96 int64_t
97 GetSampleTime(IMFSample* aSample);
99 inline bool
100 IsFlagSet(DWORD flags, DWORD pattern) {
101 return (flags & pattern) == pattern;
102 }
104 } // namespace mozilla
106 #endif