Skip to content

Commit 6c114fc

Browse files
committed
Rewrite DirectShow capture with native COM APIs
Replaces videoInput library with direct DirectShow implementation using native COM interfaces. Provides full Mode support with automatic format enumeration and negotiation.
1 parent 4280f92 commit 6c114fc

File tree

5 files changed

+1100
-2901
lines changed

5 files changed

+1100
-2901
lines changed

docs/htmlsrc/guides/dependencies/index.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ <h1>3rd Party Dependencies</h1>
5151
<tr><td><a href="http://www.glfw.org/">GLFW</a></td><td>3.2.1</td><td><a href="http://www.glfw.org/license.html">zlib</a></td><td>Linux windowing</td></tr>
5252
<tr><td><a href="https://github.com/nothings/stb">stb_image</a></td><td>2.02</td><td>Public domain</td><td>Linux & Android image read/write</td></tr>
5353
<tr><td><a href="https://gstreamer.freedesktop.org/">GStreamer</a></td><td>&lt;system&gt;</td><td><a href="https://gstreamer.freedesktop.org/documentation/frequently-asked-questions/licensing.html">LGPL</a></td><td>Linux video capture and playback</td></tr>
54-
<tr><td><a href="https://github.com/ofTheo/videoInput">videoInput</a></td><td>0.1995</td><td>Public Domain</td><td>Windows desktop video capture</td></tr>
5554
<tr><td><a href="https://github.com/MSOpenTech/angle">ANGLE</a></td><td></td><td><a href="https://github.com/MSOpenTech/angle/blob/ms-master/LICENSE">BSD</a></td><td>Windows OpenGL emulation</td></tr>
5655
<tr><td><a href="https://github.com/nemtrif/utfcpp">utf8cpp</a></td><td></td><td><a href="https://github.com/nemtrif/utfcpp/blob/master/source/utf8.h">Boost</a></td><td>Unicode UTF-8 conversion</td></tr>
5756
</table>
Lines changed: 56 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
/*
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
45
56
Redistribution and use in source and binary forms, with or without modification, are permitted provided that
67
the following conditions are met:
78
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.
1213
1314
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
1415
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
@@ -18,59 +19,84 @@
1819
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
1920
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2021
POSSIBILITY OF SUCH DAMAGE.
21-
*/
22+
*/
2223

2324
#pragma once
2425

2526
#include "cinder/Cinder.h"
2627
#include "cinder/Capture.h"
2728
#include "cinder/Surface.h"
28-
#include "msw/videoInput/videoInput.h"
29+
#include <memory>
30+
#include <atomic>
31+
#include <Windows.h>
2932

3033
namespace cinder {
3134

3235
class CaptureImplDirectShow {
33-
public:
36+
public:
3437
class Device;
38+
friend class SampleGrabberCallback;
3539

3640
CaptureImplDirectShow( int32_t width, int32_t height, const Capture::DeviceRef device );
41+
CaptureImplDirectShow( const Capture::DeviceRef& device, const Capture::Mode& mode );
3742
~CaptureImplDirectShow();
3843

3944
void start();
4045
void stop();
4146

42-
bool isCapturing();
43-
bool checkNewFrame() const;
47+
bool isCapturing();
48+
bool checkNewFrame() const;
4449

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; }
4752

48-
Surface8uRef getSurface() const;
53+
Surface8uRef getSurface() const;
4954

5055
const Capture::DeviceRef getDevice() const { return mDevice; }
5156

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 );
5361

5462
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;
6378
};
6479

65-
protected:
80+
protected:
6681
int mDeviceID;
6782
bool mIsCapturing;
68-
std::unique_ptr<class SurfaceCache> mSurfaceCache;
83+
std::unique_ptr<class SurfaceCache> mSurfaceCache;
6984

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;
7488

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+
};
76101

102+
} // namespace cinder

0 commit comments

Comments
 (0)