content/media/wmf/WMFUtils.h

Fri, 16 Jan 2015 04:50:19 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 04:50:19 +0100
branch
TOR_BUG_9701
changeset 13
44a2da4a2ab2
permissions
-rw-r--r--

Replace accessor implementation with direct member state manipulation, by
request https://trac.torproject.org/projects/tor/ticket/9701#comment:32

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

mercurial