|
1 | 1 | /* |
2 | | - Copyright (c) 2010, The Barbarian Group |
3 | | - All rights reserved. |
| 2 | + Copyright (c) 2025, The Cinder Project |
| 3 | +
|
| 4 | + This code is intended to be used with the Cinder C++ library, http://libcinder.org |
4 | 5 |
|
5 | 6 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that |
6 | 7 | the following conditions are met: |
7 | 8 |
|
8 | | - * Redistributions of source code must retain the above copyright notice, this list of conditions and |
9 | | - the following disclaimer. |
10 | | - * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and |
11 | | - the following disclaimer in the documentation and/or other materials provided with the distribution. |
| 9 | + * Redistributions of source code must retain the above copyright notice, this list of conditions and |
| 10 | + the following disclaimer. |
| 11 | + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and |
| 12 | + the following disclaimer in the documentation and/or other materials provided with the distribution. |
12 | 13 |
|
13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED |
14 | 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
|
18 | 19 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
19 | 20 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
20 | 21 | POSSIBILITY OF SUCH DAMAGE. |
21 | | -*/ |
| 22 | + */ |
22 | 23 |
|
23 | 24 | #pragma once |
24 | 25 |
|
25 | 26 | #include "cinder/Cinder.h" |
26 | 27 | #include "cinder/Capture.h" |
27 | 28 | #include "cinder/Surface.h" |
28 | | -#include "msw/videoInput/videoInput.h" |
| 29 | +#include <memory> |
| 30 | +#include <atomic> |
| 31 | +#include <Windows.h> |
29 | 32 |
|
30 | 33 | namespace cinder { |
31 | 34 |
|
32 | 35 | class CaptureImplDirectShow { |
33 | | - public: |
| 36 | + public: |
34 | 37 | class Device; |
| 38 | + friend class SampleGrabberCallback; |
35 | 39 |
|
36 | 40 | CaptureImplDirectShow( int32_t width, int32_t height, const Capture::DeviceRef device ); |
| 41 | + CaptureImplDirectShow( const Capture::DeviceRef& device, const Capture::Mode& mode ); |
37 | 42 | ~CaptureImplDirectShow(); |
38 | 43 |
|
39 | 44 | void start(); |
40 | 45 | void stop(); |
41 | 46 |
|
42 | | - bool isCapturing(); |
43 | | - bool checkNewFrame() const; |
| 47 | + bool isCapturing(); |
| 48 | + bool checkNewFrame() const; |
44 | 49 |
|
45 | | - int32_t getWidth() const { return mWidth; } |
46 | | - int32_t getHeight() const { return mHeight; } |
| 50 | + int32_t getWidth() const { return mWidth; } |
| 51 | + int32_t getHeight() const { return mHeight; } |
47 | 52 |
|
48 | | - Surface8uRef getSurface() const; |
| 53 | + Surface8uRef getSurface() const; |
49 | 54 |
|
50 | 55 | const Capture::DeviceRef getDevice() const { return mDevice; } |
51 | 56 |
|
52 | | - static const std::vector<Capture::DeviceRef>& getDevices( bool forceRefresh = false ); |
| 57 | + static const std::vector<Capture::DeviceRef>& getDevices( bool forceRefresh = false ); |
| 58 | + |
| 59 | + // Public method to update dimensions (used by DirectShow setup) |
| 60 | + void updateDimensions( int width, int height ); |
53 | 61 |
|
54 | 62 | class Device : public Capture::Device { |
55 | | - public: |
56 | | - bool checkAvailable() const; |
57 | | - bool isConnected() const; |
58 | | - Capture::DeviceIdentifier getUniqueId() const { return mUniqueId; } |
59 | | - |
60 | | - Device( const std::string &name, int uniqueId ) : Capture::Device(), mUniqueId( uniqueId ) { mName = name; } |
61 | | - protected: |
62 | | - int mUniqueId; |
| 63 | + public: |
| 64 | + bool checkAvailable() const; |
| 65 | + bool isConnected() const; |
| 66 | + Capture::DeviceIdentifier getUniqueId() const { return mUniqueId; } |
| 67 | + std::vector<Capture::Mode> getModes() const override; |
| 68 | + |
| 69 | + Device( const std::string& name, int uniqueId ) |
| 70 | + : Capture::Device() |
| 71 | + , mUniqueId( uniqueId ) |
| 72 | + { |
| 73 | + mName = name; |
| 74 | + } |
| 75 | + |
| 76 | + protected: |
| 77 | + int mUniqueId; |
63 | 78 | }; |
64 | 79 |
|
65 | | - protected: |
| 80 | + protected: |
66 | 81 | int mDeviceID; |
67 | 82 | bool mIsCapturing; |
68 | | - std::unique_ptr<class SurfaceCache> mSurfaceCache; |
| 83 | + std::unique_ptr<class SurfaceCache> mSurfaceCache; |
69 | 84 |
|
70 | | - int32_t mWidth, mHeight; |
71 | | - mutable Surface8uRef mCurrentFrame; |
72 | | - Capture::DeviceRef mDevice; |
73 | | -}; |
| 85 | + int32_t mWidth, mHeight; |
| 86 | + mutable Surface8uRef mCurrentFrame; |
| 87 | + Capture::DeviceRef mDevice; |
74 | 88 |
|
75 | | -} //namespace |
| 89 | + // New integrated DirectShow members (using void* to avoid forward declaration issues) |
| 90 | + void* mComInit; |
| 91 | + void* mDeviceContext; |
| 92 | + void* mCallback; |
| 93 | + std::unique_ptr<unsigned char[]> mPixelBuffer; |
| 94 | + |
| 95 | + mutable std::atomic<bool> mNewFrameAvailable; |
| 96 | + mutable CRITICAL_SECTION mCriticalSection; |
| 97 | + |
| 98 | + // Direct DirectShow setup methods |
| 99 | + bool setupDeviceDirect( int deviceId, int width, int height ); |
| 100 | +}; |
76 | 101 |
|
| 102 | +} // namespace cinder |
0 commit comments