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/. */
6 
7 #ifndef WMFUtils_h
8 #define WMFUtils_h
9 
10 #include "ImageTypes.h"
11 #include "TimeUnits.h"
12 #include "VideoUtils.h"
13 #include "WMF.h"
14 #include "mozilla/gfx/Rect.h"
15 #include "nsString.h"
16 
17 // Various utilities shared by WMF backend files.
18 
19 namespace mozilla {
20 
21 // Converts from microseconds to hundreds of nanoseconds.
22 // We use microseconds for our timestamps, whereas WMF uses
23 // hundreds of nanoseconds.
UsecsToHNs(int64_t aUsecs)24 inline int64_t UsecsToHNs(int64_t aUsecs) { return aUsecs * 10; }
25 
26 // Converts from hundreds of nanoseconds to microseconds.
27 // We use microseconds for our timestamps, whereas WMF uses
28 // hundreds of nanoseconds.
HNsToUsecs(int64_t hNanoSecs)29 inline int64_t HNsToUsecs(int64_t hNanoSecs) { return hNanoSecs / 10; }
30 
31 HRESULT HNsToFrames(int64_t aHNs, uint32_t aRate, int64_t* aOutFrames);
32 
33 HRESULT
34 GetDefaultStride(IMFMediaType* aType, uint32_t aWidth, uint32_t* aOutStride);
35 
36 Maybe<gfx::YUVColorSpace> GetYUVColorSpace(IMFMediaType* aType);
37 
38 int32_t MFOffsetToInt32(const MFOffset& aOffset);
39 
40 // Gets the sub-region of the video frame that should be displayed.
41 // See:
42 // http://msdn.microsoft.com/en-us/library/windows/desktop/bb530115(v=vs.85).aspx
43 HRESULT
44 GetPictureRegion(IMFMediaType* aMediaType, gfx::IntRect& aOutPictureRegion);
45 
46 // Returns the duration of a IMFSample in TimeUnit.
47 // Returns media::TimeUnit::Invalid() on failure.
48 media::TimeUnit GetSampleDuration(IMFSample* aSample);
49 
50 // Returns the presentation time of a IMFSample in TimeUnit.
51 // Returns media::TimeUnit::Invalid() on failure.
52 media::TimeUnit GetSampleTime(IMFSample* aSample);
53 
IsFlagSet(DWORD flags,DWORD pattern)54 inline bool IsFlagSet(DWORD flags, DWORD pattern) {
55   return (flags & pattern) == pattern;
56 }
57 
58 // Will return %ProgramW6432% value as per:
59 // https://msdn.microsoft.com/library/windows/desktop/aa384274.aspx
60 nsString GetProgramW6432Path();
61 
62 const char* MFTMessageTypeToStr(MFT_MESSAGE_TYPE aMsg);
63 
64 }  // namespace mozilla
65 
66 #endif
67