1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/media/wmf/WMFUtils.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,106 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim:set ts=2 sw=2 sts=2 et cindent: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#ifndef WMFUtils_h 1.11 +#define WMFUtils_h 1.12 + 1.13 +#include "WMF.h" 1.14 +#include "nsString.h" 1.15 +#include "nsRect.h" 1.16 +#include "VideoUtils.h" 1.17 + 1.18 +// Various utilities shared by WMF backend files. 1.19 + 1.20 +namespace mozilla { 1.21 + 1.22 +nsCString 1.23 +GetGUIDName(const GUID& guid); 1.24 + 1.25 +// Returns true if the reader has a stream with the specified index. 1.26 +// Index can be a specific index, or one of: 1.27 +// MF_SOURCE_READER_FIRST_VIDEO_STREAM 1.28 +// MF_SOURCE_READER_FIRST_AUDIO_STREAM 1.29 +bool 1.30 +SourceReaderHasStream(IMFSourceReader* aReader, const DWORD aIndex); 1.31 + 1.32 +// Auto manages the lifecycle of a PROPVARIANT. 1.33 +class AutoPropVar { 1.34 +public: 1.35 + AutoPropVar() { 1.36 + PropVariantInit(&mVar); 1.37 + } 1.38 + ~AutoPropVar() { 1.39 + PropVariantClear(&mVar); 1.40 + } 1.41 + operator PROPVARIANT&() { 1.42 + return mVar; 1.43 + } 1.44 + PROPVARIANT* operator->() { 1.45 + return &mVar; 1.46 + } 1.47 + PROPVARIANT* operator&() { 1.48 + return &mVar; 1.49 + } 1.50 +private: 1.51 + PROPVARIANT mVar; 1.52 +}; 1.53 + 1.54 +// Converts from microseconds to hundreds of nanoseconds. 1.55 +// We use microseconds for our timestamps, whereas WMF uses 1.56 +// hundreds of nanoseconds. 1.57 +inline int64_t 1.58 +UsecsToHNs(int64_t aUsecs) { 1.59 + return aUsecs * 10; 1.60 +} 1.61 + 1.62 +// Converts from hundreds of nanoseconds to microseconds. 1.63 +// We use microseconds for our timestamps, whereas WMF uses 1.64 +// hundreds of nanoseconds. 1.65 +inline int64_t 1.66 +HNsToUsecs(int64_t hNanoSecs) { 1.67 + return hNanoSecs / 10; 1.68 +} 1.69 + 1.70 +// Assigns aUnknown to *aInterface, and AddRef's it. 1.71 +// Helper for MSCOM QueryInterface implementations. 1.72 +HRESULT 1.73 +DoGetInterface(IUnknown* aUnknown, void** aInterface); 1.74 + 1.75 +HRESULT 1.76 +HNsToFrames(int64_t aHNs, uint32_t aRate, int64_t* aOutFrames); 1.77 + 1.78 +HRESULT 1.79 +FramesToUsecs(int64_t aSamples, uint32_t aRate, int64_t* aOutUsecs); 1.80 + 1.81 +HRESULT 1.82 +GetDefaultStride(IMFMediaType *aType, uint32_t* aOutStride); 1.83 + 1.84 +int32_t 1.85 +MFOffsetToInt32(const MFOffset& aOffset); 1.86 + 1.87 +// Gets the sub-region of the video frame that should be displayed. 1.88 +// See: http://msdn.microsoft.com/en-us/library/windows/desktop/bb530115(v=vs.85).aspx 1.89 +HRESULT 1.90 +GetPictureRegion(IMFMediaType* aMediaType, nsIntRect& aOutPictureRegion); 1.91 + 1.92 +// Returns the duration of a IMFSample in microseconds. 1.93 +// Returns -1 on failure. 1.94 +int64_t 1.95 +GetSampleDuration(IMFSample* aSample); 1.96 + 1.97 +// Returns the presentation time of a IMFSample in microseconds. 1.98 +// Returns -1 on failure. 1.99 +int64_t 1.100 +GetSampleTime(IMFSample* aSample); 1.101 + 1.102 +inline bool 1.103 +IsFlagSet(DWORD flags, DWORD pattern) { 1.104 + return (flags & pattern) == pattern; 1.105 +} 1.106 + 1.107 +} // namespace mozilla 1.108 + 1.109 +#endif