Skip to content

Commit

Permalink
Merge pull request opencv#3281 from a-wi:MSMF_remove_ATL_dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Pavlenko committed Oct 1, 2014
2 parents 5bd1815 + e3f1d72 commit 533fde6
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 34 deletions.
4 changes: 3 additions & 1 deletion modules/highgui/src/cap_msmf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
#include <stdarg.h>
#include <string.h>

#ifdef _MSC_VER
#pragma warning(disable:4503)
#pragma comment(lib, "mfplat")
#pragma comment(lib, "mf")
Expand All @@ -81,6 +82,7 @@
#if (WINVER >= 0x0602) // Available since Win 8
#pragma comment(lib, "MinCore_Downlevel")
#endif
#endif

#include <mferror.h>

Expand Down Expand Up @@ -260,7 +262,7 @@ __interface __declspec(uuid("00000000-0000-0000-C000-000000000046")) __abi_IUnkn
#include "ppltasks_winrt.h"
#endif
#else
#include <atlbase.h>
#include <comdef.h>
#endif

struct IMFMediaType;
Expand Down
113 changes: 80 additions & 33 deletions modules/highgui/src/cap_msmf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -600,27 +600,65 @@ hr = orig.As(&obj);
#define _ComPtr Microsoft::WRL::ComPtr
#else

#define _COM_SMARTPTR_DECLARE(T,var) T ## Ptr var

template <class T>
class ComPtr : public ATL::CComPtr<T>
class ComPtr
{
public:
ComPtr() throw()
{
}
ComPtr(int nNull) throw() :
CComPtr<T>((T*)nNull)
ComPtr(int nNull) throw()
{
assert(nNull == 0);
p = NULL;
}
ComPtr(T* lp) throw()
{
p = lp;
}
ComPtr(_In_ const ComPtr<T>& lp) throw()
{
p = lp.p;
}
virtual ~ComPtr()
{
}

T** operator&() throw()
{
assert(p == NULL);
return p.operator&();
}
T* operator->() const throw()
{
assert(p != NULL);
return p.operator->();
}
bool operator!() const throw()
{
return p.operator==(NULL);
}
bool operator==(_In_opt_ T* pT) const throw()
{
return p.operator==(pT);
}
// For comparison to NULL
bool operator==(int nNull) const
{
assert(nNull == 0);
return p.operator==(NULL);
}
ComPtr(T* lp) throw() :
CComPtr<T>(lp)

bool operator!=(_In_opt_ T* pT) const throw()
{
return p.operator!=(pT);
}
ComPtr(_In_ const CComPtr<T>& lp) throw() :
CComPtr<T>(lp.p)
operator bool()
{
return p.operator!=(NULL);
}
virtual ~ComPtr() {}

T* const* GetAddressOf() const throw()
{
Expand All @@ -634,35 +672,46 @@ class ComPtr : public ATL::CComPtr<T>

T** ReleaseAndGetAddressOf() throw()
{
InternalRelease();
p.Release();
return &p;
}

T* Get() const throw()
{
return p;
}
ComPtr& operator=(decltype(__nullptr)) throw()

// Attach to an existing interface (does not AddRef)
void Attach(_In_opt_ T* p2) throw()
{
InternalRelease();
return *this;
p.Attach(p2);
}
ComPtr& operator=(_In_ const int nNull) throw()
// Detach the interface (does not Release)
T* Detach() throw()
{
ASSERT(nNull == 0);
(void)nNull;
InternalRelease();
return *this;
return p.Detach();
}
unsigned long Reset()
_Check_return_ HRESULT CopyTo(_Deref_out_opt_ T** ppT) throw()
{
return InternalRelease();
assert(ppT != NULL);
if (ppT == NULL)
return E_POINTER;
*ppT = p;
if (p != NULL)
p->AddRef();
return S_OK;
}

void Reset()
{
p.Release();
}

// query for U interface
template<typename U>
HRESULT As(_Inout_ U** lp) const throw()
{
return p->QueryInterface(__uuidof(U), (void**)lp);
return p->QueryInterface(__uuidof(U), reinterpret_cast<void**>(lp));
}
// query for U interface
template<typename U>
Expand All @@ -671,19 +720,8 @@ class ComPtr : public ATL::CComPtr<T>
return p->QueryInterface(__uuidof(U), reinterpret_cast<void**>(lp->ReleaseAndGetAddressOf()));
}
private:
unsigned long InternalRelease() throw()
{
unsigned long ref = 0;
T* temp = p;

if (temp != nullptr)
{
p = nullptr;
ref = temp->Release();
}

return ref;
}
_COM_SMARTPTR_TYPEDEF(T, __uuidof(T));
_COM_SMARTPTR_DECLARE(T, p);
};

#define _ComPtr ComPtr
Expand Down Expand Up @@ -2262,6 +2300,11 @@ class MemDelete
// succeed but return a nullptr pointer. By default, the list does not allow nullptr
// pointers.

#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable: 4127) // constant expression
#endif

template <class T, bool NULLABLE = FALSE>
class ComPtrList : public List<T*>
{
Expand Down Expand Up @@ -2352,6 +2395,10 @@ class ComPtrList : public List<T*>
}
};

#ifdef _MSC_VER
#pragma warning(pop)
#endif

/* Be sure to declare webcam device capability in manifest
For better media capture support, add the following snippet with correct module name to the project manifest
(highgui needs DLL activation class factoryentry points):
Expand Down

0 comments on commit 533fde6

Please sign in to comment.