diff --git a/modules/juce_core/native/juce_win32_ComSmartPtr.h b/modules/juce_core/native/juce_win32_ComSmartPtr.h index e03714b18b..d4373b9acd 100644 --- a/modules/juce_core/native/juce_win32_ComSmartPtr.h +++ b/modules/juce_core/native/juce_win32_ComSmartPtr.h @@ -103,14 +103,30 @@ private: #define JUCE_COMRESULT HRESULT __stdcall //============================================================================== +template +class ComBaseClassHelperBase : public ComClass +{ +public: + ComBaseClassHelperBase() : refCount (1) {} + virtual ~ComBaseClassHelperBase() {} + + ULONG __stdcall AddRef() { return ++refCount; } + ULONG __stdcall Release() { const ULONG r = --refCount; if (r == 0) delete this; return r; } + + void resetReferenceCount() noexcept { refCount = 0; } + +protected: + ULONG refCount; +}; + /** Handy base class for writing COM objects, providing ref-counting and a basic QueryInterface method. */ template -class ComBaseClassHelper : public ComClass +class ComBaseClassHelper : public ComBaseClassHelperBase { public: - ComBaseClassHelper() : refCount (1) {} - virtual ~ComBaseClassHelper() {} + ComBaseClassHelper() {} + ~ComBaseClassHelper() {} JUCE_COMRESULT QueryInterface (REFIID refId, void** result) { @@ -125,14 +141,6 @@ public: *result = 0; return E_NOINTERFACE; } - - ULONG __stdcall AddRef() { return ++refCount; } - ULONG __stdcall Release() { const ULONG r = --refCount; if (r == 0) delete this; return r; } - - void resetReferenceCount() noexcept { refCount = 0; } - -protected: - ULONG refCount; }; #endif // __JUCE_WIN32_COMSMARTPTR_JUCEHEADER__ diff --git a/modules/juce_video/juce_video.cpp b/modules/juce_video/juce_video.cpp index 1f05f38732..bd58751a64 100644 --- a/modules/juce_video/juce_video.cpp +++ b/modules/juce_video/juce_video.cpp @@ -77,23 +77,8 @@ #if JUCE_USE_CAMERA || JUCE_DIRECTSHOW /* If you're using the camera classes, you'll need access to a few DirectShow headers. - - These files are provided in the normal Windows SDK, but some Microsoft plonker - didn't realise that qedit.h doesn't actually compile without the rest of the DirectShow SDK.. - Microsoft's suggested fix for this is to hack their qedit.h file! See: - http://social.msdn.microsoft.com/Forums/en-US/windowssdk/thread/ed097d2c-3d68-4f48-8448-277eaaf68252 - .. which is a bit of a bodge, but a lot less hassle than installing the full DShow SDK. - - An alternative workaround is to create a dummy dxtrans.h file and put it in your include path. - The dummy file just needs to contain the following content: - #define __IDxtCompositor_INTERFACE_DEFINED__ - #define __IDxtAlphaSetter_INTERFACE_DEFINED__ - #define __IDxtJpeg_INTERFACE_DEFINED__ - #define __IDxtKey_INTERFACE_DEFINED__ - ..and that should be enough to convince qedit.h that you have the SDK! - */ + These files are provided in the normal Windows SDK. */ #include - #include #include #endif diff --git a/modules/juce_video/native/juce_win32_CameraDevice.cpp b/modules/juce_video/native/juce_win32_CameraDevice.cpp index 8bb9cdb828..d47ab0feca 100644 --- a/modules/juce_video/native/juce_win32_CameraDevice.cpp +++ b/modules/juce_video/native/juce_win32_CameraDevice.cpp @@ -23,6 +23,29 @@ ============================================================================== */ +interface ISampleGrabberCB : public IUnknown +{ + virtual STDMETHODIMP SampleCB (double, IMediaSample*) = 0; + virtual STDMETHODIMP BufferCB (double, BYTE*, long) = 0; +}; + +interface ISampleGrabber : public IUnknown +{ + virtual HRESULT STDMETHODCALLTYPE SetOneShot (BOOL) = 0; + virtual HRESULT STDMETHODCALLTYPE SetMediaType (const AM_MEDIA_TYPE*) = 0; + virtual HRESULT STDMETHODCALLTYPE GetConnectedMediaType (AM_MEDIA_TYPE*) = 0; + virtual HRESULT STDMETHODCALLTYPE SetBufferSamples (BOOL) = 0; + virtual HRESULT STDMETHODCALLTYPE GetCurrentBuffer (long*, long*) = 0; + virtual HRESULT STDMETHODCALLTYPE GetCurrentSample (IMediaSample**) = 0; + virtual HRESULT STDMETHODCALLTYPE SetCallback (ISampleGrabberCB*, long) = 0; +}; + +static const IID IID_ISampleGrabberCB = { 0x0579154A, 0x2B53, 0x4994, { 0xB0, 0xD0, 0xE7, 0x73, 0x14, 0x8E, 0xFF, 0x85 } }; +static const IID IID_ISampleGrabber = { 0x6B652FFF, 0x11FE, 0x4fce, { 0x92, 0xAD, 0x02, 0x66, 0xB5, 0xD7, 0xC7, 0x8F } }; +static const CLSID CLSID_SampleGrabber = { 0xC1F400A0, 0x3F08, 0x11d3, { 0x9F, 0x0B, 0x00, 0x60, 0x08, 0x03, 0x9E, 0x37 } }; +static const CLSID CLSID_NullRenderer = { 0xC1F400A4, 0x3F08, 0x11d3, { 0x9F, 0x0B, 0x00, 0x60, 0x08, 0x03, 0x9E, 0x37 } }; + +//============================================================================== class DShowCameraDeviceInteral : public ChangeBroadcaster { public: @@ -89,7 +112,7 @@ public: if (FAILED (hr)) return; - hr = sampleGrabberBase.QueryInterface (sampleGrabber); + hr = sampleGrabberBase.QueryInterface (IID_ISampleGrabber, sampleGrabber); if (FAILED (hr)) return; @@ -396,7 +419,6 @@ public: } } - //============================================================================== class DShowCaptureViewerComp : public Component, public ChangeListener @@ -656,20 +678,22 @@ private: } //============================================================================== - class GrabberCallback : public ComBaseClassHelper + class GrabberCallback : public ComBaseClassHelperBase { public: - GrabberCallback (DShowCameraDeviceInteral& owner_) - : owner (owner_) - { - } + GrabberCallback (DShowCameraDeviceInteral& owner_) : owner (owner_) {} - //============================================================================== - STDMETHODIMP SampleCB (double /*SampleTime*/, IMediaSample* /*pSample*/) + JUCE_COMRESULT QueryInterface (REFIID refId, void** result) { - return E_FAIL; + if (refId == IID_ISampleGrabberCB) { AddRef(); *result = dynamic_cast (this); return S_OK; } + if (refId == IID_IUnknown) { AddRef(); *result = dynamic_cast (this); return S_OK; } + + *result = nullptr; + return E_NOINTERFACE; } + STDMETHODIMP SampleCB (double /*SampleTime*/, IMediaSample* /*pSample*/) { return E_FAIL; } + STDMETHODIMP BufferCB (double time, BYTE* buffer, long bufferSize) { owner.handleFrame (time, buffer, bufferSize); @@ -679,8 +703,7 @@ private: private: DShowCameraDeviceInteral& owner; - GrabberCallback (const GrabberCallback&); - GrabberCallback& operator= (const GrabberCallback&); + JUCE_DECLARE_NON_COPYABLE (GrabberCallback); }; ComSmartPtr callback;