michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim:set ts=2 sw=2 sts=2 et cindent: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef WMFUtils_h michael@0: #define WMFUtils_h michael@0: michael@0: #include "WMF.h" michael@0: #include "nsString.h" michael@0: #include "nsRect.h" michael@0: #include "VideoUtils.h" michael@0: michael@0: // Various utilities shared by WMF backend files. michael@0: michael@0: namespace mozilla { michael@0: michael@0: nsCString michael@0: GetGUIDName(const GUID& guid); michael@0: michael@0: // Returns true if the reader has a stream with the specified index. michael@0: // Index can be a specific index, or one of: michael@0: // MF_SOURCE_READER_FIRST_VIDEO_STREAM michael@0: // MF_SOURCE_READER_FIRST_AUDIO_STREAM michael@0: bool michael@0: SourceReaderHasStream(IMFSourceReader* aReader, const DWORD aIndex); michael@0: michael@0: // Auto manages the lifecycle of a PROPVARIANT. michael@0: class AutoPropVar { michael@0: public: michael@0: AutoPropVar() { michael@0: PropVariantInit(&mVar); michael@0: } michael@0: ~AutoPropVar() { michael@0: PropVariantClear(&mVar); michael@0: } michael@0: operator PROPVARIANT&() { michael@0: return mVar; michael@0: } michael@0: PROPVARIANT* operator->() { michael@0: return &mVar; michael@0: } michael@0: PROPVARIANT* operator&() { michael@0: return &mVar; michael@0: } michael@0: private: michael@0: PROPVARIANT mVar; michael@0: }; michael@0: michael@0: // Converts from microseconds to hundreds of nanoseconds. michael@0: // We use microseconds for our timestamps, whereas WMF uses michael@0: // hundreds of nanoseconds. michael@0: inline int64_t michael@0: UsecsToHNs(int64_t aUsecs) { michael@0: return aUsecs * 10; michael@0: } michael@0: michael@0: // Converts from hundreds of nanoseconds to microseconds. michael@0: // We use microseconds for our timestamps, whereas WMF uses michael@0: // hundreds of nanoseconds. michael@0: inline int64_t michael@0: HNsToUsecs(int64_t hNanoSecs) { michael@0: return hNanoSecs / 10; michael@0: } michael@0: michael@0: // Assigns aUnknown to *aInterface, and AddRef's it. michael@0: // Helper for MSCOM QueryInterface implementations. michael@0: HRESULT michael@0: DoGetInterface(IUnknown* aUnknown, void** aInterface); michael@0: michael@0: HRESULT michael@0: HNsToFrames(int64_t aHNs, uint32_t aRate, int64_t* aOutFrames); michael@0: michael@0: HRESULT michael@0: FramesToUsecs(int64_t aSamples, uint32_t aRate, int64_t* aOutUsecs); michael@0: michael@0: HRESULT michael@0: GetDefaultStride(IMFMediaType *aType, uint32_t* aOutStride); michael@0: michael@0: int32_t michael@0: MFOffsetToInt32(const MFOffset& aOffset); michael@0: michael@0: // Gets the sub-region of the video frame that should be displayed. michael@0: // See: http://msdn.microsoft.com/en-us/library/windows/desktop/bb530115(v=vs.85).aspx michael@0: HRESULT michael@0: GetPictureRegion(IMFMediaType* aMediaType, nsIntRect& aOutPictureRegion); michael@0: michael@0: // Returns the duration of a IMFSample in microseconds. michael@0: // Returns -1 on failure. michael@0: int64_t michael@0: GetSampleDuration(IMFSample* aSample); michael@0: michael@0: // Returns the presentation time of a IMFSample in microseconds. michael@0: // Returns -1 on failure. michael@0: int64_t michael@0: GetSampleTime(IMFSample* aSample); michael@0: michael@0: inline bool michael@0: IsFlagSet(DWORD flags, DWORD pattern) { michael@0: return (flags & pattern) == pattern; michael@0: } michael@0: michael@0: } // namespace mozilla michael@0: michael@0: #endif