niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef MODULES_VIDEO_CAPTURE_MAIN_SOURCE_WINDOWS_HELP_FUNCTIONS_DS_H_ |
| 12 | #define MODULES_VIDEO_CAPTURE_MAIN_SOURCE_WINDOWS_HELP_FUNCTIONS_DS_H_ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 13 | |
| 14 | #include <dshow.h> |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 15 | |
Tommi | 30e60d6 | 2019-03-12 09:59:05 +0100 | [diff] [blame] | 16 | #include <type_traits> |
| 17 | #include <utility> |
| 18 | |
| 19 | #include "api/scoped_refptr.h" |
| 20 | #include "rtc_base/ref_counter.h" |
| 21 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 22 | DEFINE_GUID(MEDIASUBTYPE_I420, |
| 23 | 0x30323449, |
| 24 | 0x0000, |
| 25 | 0x0010, |
| 26 | 0x80, |
| 27 | 0x00, |
| 28 | 0x00, |
| 29 | 0xAA, |
| 30 | 0x00, |
| 31 | 0x38, |
| 32 | 0x9B, |
| 33 | 0x71); |
| 34 | DEFINE_GUID(MEDIASUBTYPE_HDYC, |
| 35 | 0x43594448, |
| 36 | 0x0000, |
| 37 | 0x0010, |
| 38 | 0x80, |
| 39 | 0x00, |
| 40 | 0x00, |
| 41 | 0xAA, |
| 42 | 0x00, |
| 43 | 0x38, |
| 44 | 0x9B, |
| 45 | 0x71); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 46 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 47 | #define RELEASE_AND_CLEAR(p) \ |
| 48 | if (p) { \ |
| 49 | (p)->Release(); \ |
| 50 | (p) = NULL; \ |
| 51 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 52 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 53 | namespace webrtc { |
| 54 | namespace videocapturemodule { |
| 55 | LONGLONG GetMaxOfFrameArray(LONGLONG* maxFps, long size); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 56 | |
| 57 | IPin* GetInputPin(IBaseFilter* filter); |
tommi@webrtc.org | 8187877 | 2012-11-20 13:35:33 +0000 | [diff] [blame] | 58 | IPin* GetOutputPin(IBaseFilter* filter, REFGUID Category); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 59 | BOOL PinMatchesCategory(IPin* pPin, REFGUID Category); |
Tommi | 30e60d6 | 2019-03-12 09:59:05 +0100 | [diff] [blame] | 60 | void ResetMediaType(AM_MEDIA_TYPE* media_type); |
| 61 | void FreeMediaType(AM_MEDIA_TYPE* media_type); |
| 62 | HRESULT CopyMediaType(AM_MEDIA_TYPE* target, const AM_MEDIA_TYPE* source); |
| 63 | |
| 64 | // Helper function to make using scoped_refptr with COM interface pointers |
| 65 | // a little less awkward. rtc::scoped_refptr doesn't support the & operator |
| 66 | // or a way to receive values via an out ptr. |
| 67 | // The function is intentionally not called QueryInterface to make things less |
| 68 | // confusing for the compiler to figure out what the caller wants to do when |
| 69 | // called from within the context of a class that also implements COM |
| 70 | // interfaces. |
| 71 | template <class T> |
| 72 | HRESULT GetComInterface(IUnknown* object, rtc::scoped_refptr<T>* ptr) { |
| 73 | // This helper function is not meant to magically free ptr. If we do that |
| 74 | // we add code bloat to most places where it's not needed and make the code |
| 75 | // less readable since it's not clear at the call site that the pointer |
| 76 | // would get freed even inf QI() fails. |
| 77 | RTC_DCHECK(!ptr->get()); |
| 78 | void* new_ptr = nullptr; |
| 79 | HRESULT hr = object->QueryInterface(__uuidof(T), &new_ptr); |
| 80 | if (SUCCEEDED(hr)) |
| 81 | ptr->swap(reinterpret_cast<T**>(&new_ptr)); |
| 82 | return hr; |
| 83 | } |
| 84 | |
| 85 | // Provides a reference count implementation for COM (IUnknown derived) classes. |
| 86 | // The implementation uses atomics for managing the ref count. |
| 87 | template <class T> |
| 88 | class ComRefCount : public T { |
| 89 | public: |
| 90 | ComRefCount() {} |
| 91 | |
| 92 | template <class P0> |
| 93 | explicit ComRefCount(P0&& p0) : T(std::forward<P0>(p0)) {} |
| 94 | |
| 95 | STDMETHOD_(ULONG, AddRef)() override { |
| 96 | ref_count_.IncRef(); |
| 97 | return 1; |
| 98 | } |
| 99 | |
| 100 | STDMETHOD_(ULONG, Release)() override { |
| 101 | const auto status = ref_count_.DecRef(); |
| 102 | if (status == rtc::RefCountReleaseStatus::kDroppedLastRef) { |
| 103 | delete this; |
| 104 | return 0; |
| 105 | } |
| 106 | return 1; |
| 107 | } |
| 108 | |
| 109 | protected: |
| 110 | ~ComRefCount() {} |
| 111 | |
| 112 | private: |
| 113 | webrtc::webrtc_impl::RefCounter ref_count_{0}; |
| 114 | }; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 115 | |
pbos@webrtc.org | d900e8b | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 116 | } // namespace videocapturemodule |
| 117 | } // namespace webrtc |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 118 | #endif // MODULES_VIDEO_CAPTURE_MAIN_SOURCE_WINDOWS_HELP_FUNCTIONS_DS_H_ |