CMIOHardwarePlugIn.h
11.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
/* akvirtualcamera, virtual camera for Mac and Windows.
* Copyright (C) 2024 Gonzalo Exequiel Pedone
*
* akvirtualcamera is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* akvirtualcamera is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with akvirtualcamera. If not, see <http://www.gnu.org/licenses/>.
*
* Web-Site: http://webcamoid.github.io/
*/
#ifndef COREMEDIAIO_CMIOHARDWAREPLUGIN_H
#define COREMEDIAIO_CMIOHARDWAREPLUGIN_H
#include <algorithm>
#include "../CoreFoundation/CFArray.h"
#include "../CoreFoundation/CFUUID.h"
#include "../CoreFoundation/CFType.h"
#include "../CoreMedia/CMSimpleQueue.h"
#include "../CoreMedia/CMSampleBuffer.h"
#include "../CoreMedia/CMVideoFormatDescription.h"
#include "CMIOHardware.h"
#include "CMIOHardwareDevice.h"
#include "CMIOHardwareStream.h"
#include "CMIOCOM.h"
struct CMIOHardwarePlugInInterface;
using CMIOHardwarePlugInRef = CMIOHardwarePlugInInterface **;
#define kCMIOHardwarePlugInTypeID CFUUIDGetConstantUUIDWithBytes(kCFAllocatorDefault, 0x30, 0x01, 0x0c, 0x1c, 0x93, 0xbf, 0x11, 0xd8, 0x8b, 0x5b, 0x00, 0x0a, 0x95, 0xaf, 0x9c, 0x6a)
#define kCMIOHardwarePlugInInterfaceID CFUUIDGetConstantUUIDWithBytes(kCFAllocatorDefault, 0xb8, 0x9d, 0xfa, 0xba, 0x93, 0xbf, 0x11, 0xd8, 0x8e, 0xa6, 0x00, 0x0a, 0x95, 0xaf, 0x9c, 0x6a)
struct CMIOHardwarePlugInInterface
{
void *_reserved;
HRESULT (STDMETHODCALLTYPE *QueryInterface)(void *self,
REFIID uuid,
LPVOID *interface);
ULONG (STDMETHODCALLTYPE *AddRef)(void *self);
ULONG (STDMETHODCALLTYPE *Release)(void *self);
OSStatus (*Initialize)(CMIOHardwarePlugInRef self);
OSStatus (*InitializeWithObjectID)(CMIOHardwarePlugInRef self,
CMIOObjectID objectID);
OSStatus (*Teardown)(CMIOHardwarePlugInRef self);
void (*ObjectShow)(CMIOHardwarePlugInRef self, CMIOObjectID objectID);
Boolean (*ObjectHasProperty)(CMIOHardwarePlugInRef self,
CMIOObjectID objectID,
const CMIOObjectPropertyAddress *address);
OSStatus (*ObjectIsPropertySettable)(CMIOHardwarePlugInRef self,
CMIOObjectID objectID,
const CMIOObjectPropertyAddress *address,
Boolean *isSettable);
OSStatus (*ObjectGetPropertyDataSize)(CMIOHardwarePlugInRef self,
CMIOObjectID objectID,
const CMIOObjectPropertyAddress *address,
UInt32 qualifierDataSize,
const void *qualifierData,
UInt32 *dataSize);
OSStatus (*ObjectGetPropertyData)(CMIOHardwarePlugInRef self,
CMIOObjectID objectID,
const CMIOObjectPropertyAddress *address,
UInt32 qualifierDataSize,
const void *qualifierData,
UInt32 dataSize,
UInt32 *dataUsed,
void *data);
OSStatus (*ObjectSetPropertyData)(CMIOHardwarePlugInRef self,
CMIOObjectID objectID,
const CMIOObjectPropertyAddress *address,
UInt32 qualifierDataSize,
const void *qualifierData,
UInt32 dataSize,
const void *data);
OSStatus (*DeviceSuspend)(CMIOHardwarePlugInRef self, CMIODeviceID device);
OSStatus (*DeviceResume)(CMIOHardwarePlugInRef self, CMIODeviceID device);
OSStatus (*DeviceStartStream)(CMIOHardwarePlugInRef self,
CMIODeviceID device,
CMIOStreamID stream);
OSStatus (*DeviceStopStream)(CMIOHardwarePlugInRef self,
CMIODeviceID device,
CMIOStreamID stream);
OSStatus (*DeviceProcessAVCCommand)(CMIOHardwarePlugInRef self,
CMIODeviceID device,
CMIODeviceAVCCommand *ioAVCCommand);
OSStatus (*DeviceProcessRS422Command)(CMIOHardwarePlugInRef self,
CMIODeviceID device,
CMIODeviceRS422Command *ioRS422Command);
OSStatus (*StreamCopyBufferQueue)(CMIOHardwarePlugInRef self,
CMIOStreamID stream,
CMIODeviceStreamQueueAlteredProc queueAlteredProc,
void *queueAlteredRefCon,
CMSimpleQueueRef *queue);
OSStatus (*StreamDeckPlay)(CMIOHardwarePlugInRef self, CMIOStreamID stream);
OSStatus (*StreamDeckStop)(CMIOHardwarePlugInRef self, CMIOStreamID stream);
OSStatus (*StreamDeckJog)(CMIOHardwarePlugInRef self,
CMIOStreamID stream,
SInt32 speed);
OSStatus (*StreamDeckCueTo)(CMIOHardwarePlugInRef self,
CMIOStreamID stream,
Float64 frameNumber,
Boolean playOnCue);
};
struct _CMIOObject
{
CMIOHardwarePlugInRef owningPlugIn;
CMIOObjectID owningObjectID;
CMIOClassID classID;
CMIOObjectID objectID;
bool published;
};
#define CMIO_MAX_OBJECTS (1024 * 1024)
static struct _CMIOGlobalObjectsType
{
UInt32 nobjects {0};
_CMIOObject objects[CMIO_MAX_OBJECTS];
} _CMIOGlobalObjects;
inline OSStatus CMIOObjectCreate(CMIOHardwarePlugInRef owningPlugIn,
CMIOObjectID owningObjectID,
CMIOClassID classID,
CMIOObjectID *objectID)
{
static UInt32 cmioNewObjectID = 0;
auto &object = _CMIOGlobalObjects.objects[_CMIOGlobalObjects.nobjects];
object.owningPlugIn = owningPlugIn;
object.owningObjectID = owningObjectID;
object.classID = classID;
object.objectID = cmioNewObjectID++;
object.published = false;
++_CMIOGlobalObjects.nobjects;
*objectID = object.objectID;
return noErr;
}
inline OSStatus CMIOObjectsPublishedAndDied(CMIOHardwarePlugInRef owningPlugIn,
CMIOObjectID owningObjectID,
UInt32 numberPublishedCMIOObjects,
const CMIOObjectID *publishedCMIOObjects,
UInt32 numberDeadCMIOObjects,
const CMIOObjectID *deadCMIOObjects)
{
_CMIOGlobalObjectsType newObjects;
newObjects.nobjects = 0;
for (size_t object = 0; object < _CMIOGlobalObjects.nobjects; ++object) {
auto obj = _CMIOGlobalObjects.objects + object;
if (obj->owningPlugIn == owningPlugIn && obj->owningObjectID == owningObjectID) {
// Publish the new objects
for (size_t i = 0; i < numberPublishedCMIOObjects; ++i)
if (obj->objectID == publishedCMIOObjects[i]) {
obj->published = true;
break;
}
// Remove the dead objects
bool isDead = false;
for (size_t i = 0; i < numberDeadCMIOObjects; ++i)
if (obj->objectID == deadCMIOObjects[i]) {
isDead = true;
break;
}
if (!isDead) {
memcpy(newObjects.objects + newObjects.nobjects, obj, sizeof(_CMIOObject));
++newObjects.nobjects;
}
} else {
memcpy(newObjects.objects + newObjects.nobjects, obj, sizeof(_CMIOObject));
++newObjects.nobjects;
}
}
memcpy(&_CMIOGlobalObjects, &newObjects, sizeof(_CMIOGlobalObjectsType));
return noErr;
}
inline OSStatus CMIOObjectPropertiesChanged(CMIOHardwarePlugInRef owningPlugIn,
CMIOObjectID objectID,
UInt32 numberAddresses,
const CMIOObjectPropertyAddress *addresses)
{
OSStatus status = noErr;
for (UInt32 address = 0; address < numberAddresses; ++address) {
auto propertyAddress = addresses + address;
if (!(*owningPlugIn)->ObjectHasProperty(owningPlugIn,
objectID,
propertyAddress))
break;
Boolean isSettable = false;
status = (*owningPlugIn)->ObjectIsPropertySettable(owningPlugIn,
objectID,
propertyAddress,
&isSettable);
if (status != noErr)
break;
if (!isSettable)
continue;
std::vector<uint8_t> qualifier;
UInt32 dataSize = 0;
status = (*owningPlugIn)->ObjectGetPropertyDataSize(owningPlugIn,
objectID,
propertyAddress,
UInt32(qualifier.size()),
qualifier.data(),
&dataSize);
if (status != noErr)
break;
UInt32 dataUsed = 0;
std::vector<uint8_t> data(dataSize);
status = (*owningPlugIn)->ObjectGetPropertyData(owningPlugIn,
objectID,
propertyAddress,
UInt32(qualifier.size()),
qualifier.data(),
data.size(),
&dataUsed,
data.data());
if (status != noErr)
break;
status = (*owningPlugIn)->ObjectSetPropertyData(owningPlugIn,
objectID,
propertyAddress,
UInt32(qualifier.size()),
qualifier.data(),
dataUsed,
data.data());
if (status != noErr)
break;
}
return status;
}
#endif // COREMEDIAIO_CMIOHARDWAREPLUGIN_H