FreeRDP
Loading...
Searching...
No Matches
camera.h
1
20#ifndef FREERDP_CLIENT_CAMERA_H
21#define FREERDP_CLIENT_CAMERA_H
22
23#include <errno.h>
24#include <stdio.h>
25#include <stdlib.h>
26#include <string.h>
27
28#include <winpr/wlog.h>
29#include <winpr/wtypes.h>
30
31#include <freerdp/api.h>
32#include <freerdp/types.h>
33
34#include <freerdp/client/channels.h>
35#include <freerdp/channels/log.h>
36#include <freerdp/channels/rdpecam.h>
37#include <freerdp/codecs.h>
38#include <freerdp/codec/video.h>
39#include <freerdp/primitives.h>
40
41#define ECAM_PROTO_VERSION 0x02
42/* currently supporting 1 stream per device */
43#define ECAM_DEVICE_MAX_STREAMS 1
44#define ECAM_MAX_MEDIA_TYPE_DESCRIPTORS 256
45
46/* Allow to send up to that many unsolicited samples.
47 * For example, to support 30 fps with 250 ms round trip
48 * ECAM_MAX_SAMPLE_CREDITS has to be at least 8.
49 */
50#define ECAM_MAX_SAMPLE_CREDITS 8
51
52/* Having this hardcoded allows to preallocate and reuse buffer
53 * for sample responses. Excessive size is to make sure any sample
54 * will fit in, even with highest resolution.
55 */
56#define ECAM_SAMPLE_RESPONSE_BUFFER_SIZE (1024ULL * 4050ULL)
57
58typedef struct s_ICamHal ICamHal;
59
60typedef struct
61{
62 IWTSPlugin iface;
63 IWTSListener* listener;
65
66 /* HAL interface */
67 ICamHal* ihal;
68 char* subsystem;
69
70 BOOL initialized;
71 BOOL attached;
72
73 UINT32 version;
74 wHashTable* devices;
75
77
78typedef struct
79{
80 CAM_MEDIA_FORMAT inputFormat; /* camera side */
81 CAM_MEDIA_FORMAT outputFormat; /* network side */
82
84
85typedef struct
86{
87 BOOL streaming;
88 /* The protocol stream can remain active while the capture device is released. */
89 BOOL captureRunning;
91 CAM_MEDIA_TYPE_DESCRIPTION currMediaType;
92
93 GENERIC_CHANNEL_CALLBACK* hSampleReqChannel;
95 volatile LONG samplesRequested;
96 /* GetTickCount64() of the last SampleRequest, or of the stream start */
97 UINT64 lastSampleRequestTime;
98 wStream* pendingSample;
99 volatile BOOL haveSample;
100 wStream* sampleRespBuffer;
101
102 FREERDP_VIDEO_CONTEXT* video;
104
105/* Internal callback result asking a request-driven HAL to release the capture device. */
106#define ECAM_SAMPLE_CAPTURE_DRAINED 0x00010000u
107
108/* Release the capture device once the server stopped requesting samples for this long (ms).
109 * Windows requests samples one at a time, so a zero request count between two requests is
110 * normal and must not close the device. */
111#define ECAM_CAPTURE_IDLE_TIMEOUT_MS 2000ULL
112
113WINPR_ATTR_NODISCARD
114static inline CAM_MEDIA_FORMAT streamInputFormat(CameraDeviceStream* stream)
115{
116 return stream->formats.inputFormat;
117}
118
119WINPR_ATTR_NODISCARD
120static inline CAM_MEDIA_FORMAT streamOutputFormat(CameraDeviceStream* stream)
121{
122 return stream->formats.outputFormat;
123}
124
125typedef struct
126{
127 IWTSListener* listener;
128 GENERIC_LISTENER_CALLBACK* hlistener;
129 CameraPlugin* ecam;
130 ICamHal* ihal; /* HAL interface, same as used by CameraPlugin */
131 char deviceId[32];
132 CameraDeviceStream streams[ECAM_DEVICE_MAX_STREAMS];
133
135
140typedef UINT (*ICamHalEnumCallback)(CameraPlugin* ecam, GENERIC_CHANNEL_CALLBACK* hchannel,
141 const char* deviceId, const char* deviceName);
142
143/* may run in context of different thread */
144typedef UINT (*ICamHalSampleCapturedCallback)(CameraDevice* dev, size_t streamIndex,
145 const BYTE* sample, size_t size);
146
149{
150 /* The HAL can release capture when there are no sample requests and restart it later. */
151 BOOL RequestDrivenCapture;
152
161 WINPR_ATTR_NODISCARD UINT (*Enumerate)(ICamHal* ihal, ICamHalEnumCallback callback,
162 CameraPlugin* ecam, GENERIC_CHANNEL_CALLBACK* hchannel);
163
172 WINPR_ATTR_NODISCARD BOOL (*Activate)(ICamHal* ihal, const char* deviceId,
173 CAM_ERROR_CODE* errorCode);
174
183 WINPR_ATTR_NODISCARD BOOL (*Deactivate)(ICamHal* ihal, const char* deviceId,
184 CAM_ERROR_CODE* errorCode);
185
197 WINPR_ATTR_NODISCARD INT16 (*GetMediaTypeDescriptions)(
198 ICamHal* ihal, const char* deviceId, size_t streamIndex,
199 const CAM_MEDIA_FORMAT_INFO* supportedFormats, size_t nSupportedFormats,
200 CAM_MEDIA_TYPE_DESCRIPTION* mediaTypes, size_t* nMediaTypes);
201
211 WINPR_ATTR_NODISCARD CAM_ERROR_CODE (*StartStream)(ICamHal* ihal, CameraDevice* dev,
212 size_t streamIndex,
213 const CAM_MEDIA_TYPE_DESCRIPTION* mediaType,
214 ICamHalSampleCapturedCallback callback);
215
223 CAM_ERROR_CODE (*StopStream)(ICamHal* ihal, const char* deviceId, size_t streamIndex);
224
230 CAM_ERROR_CODE (*Free)(ICamHal* ihal);
231};
232
233typedef UINT (*PREGISTERCAMERAHAL)(IWTSPlugin* plugin, ICamHal* hal);
234
235typedef struct
236{
237 IWTSPlugin* plugin;
238 WINPR_ATTR_NODISCARD PREGISTERCAMERAHAL pRegisterCameraHal;
239 CameraPlugin* ecam;
240 const ADDIN_ARGV* args;
241
243
245
246/* entry point called by addin manager */
247typedef UINT(VCAPITYPE* PFREERDP_CAMERA_HAL_ENTRY)(PFREERDP_CAMERA_HAL_ENTRY_POINTS pEntryPoints);
248
249/* common functions */
250WINPR_ATTR_NODISCARD FREERDP_LOCAL UINT ecam_channel_send_generic_msg(
251 CameraPlugin* ecam, GENERIC_CHANNEL_CALLBACK* hchannel, CAM_MSG_ID msg);
252
253FREERDP_LOCAL UINT ecam_channel_send_error_response(CameraPlugin* ecam,
254 GENERIC_CHANNEL_CALLBACK* hchannel,
255 CAM_ERROR_CODE code);
256
257WINPR_ATTR_NODISCARD FREERDP_LOCAL UINT ecam_channel_write(CameraPlugin* ecam,
258 GENERIC_CHANNEL_CALLBACK* hchannel,
259 CAM_MSG_ID msg, wStream* out,
260 BOOL freeStream);
261
262/* ecam device interface */
263FREERDP_LOCAL void ecam_dev_destroy(CameraDevice* dev);
264
265WINPR_ATTR_MALLOC(ecam_dev_destroy, 1)
266WINPR_ATTR_NODISCARD
267FREERDP_LOCAL CameraDevice* ecam_dev_create(CameraPlugin* ecam, const char* deviceId,
268 const char* deviceName);
269
270/* video encoding interface */
271WINPR_ATTR_NODISCARD FREERDP_LOCAL BOOL ecam_encoder_context_init(CameraDeviceStream* stream);
272
273FREERDP_LOCAL BOOL ecam_encoder_context_free(CameraDeviceStream* stream);
274
275WINPR_ATTR_NODISCARD FREERDP_LOCAL BOOL ecam_encoder_compress(CameraDeviceStream* stream,
276 const BYTE* srcData, size_t srcSize,
277 wStream* output);
278
279WINPR_ATTR_NODISCARD FREERDP_LOCAL UINT32 h264_get_max_bitrate(UINT32 height);
280
281WINPR_ATTR_NODISCARD
282FREERDP_LOCAL FREERDP_VIDEO_FORMAT ecamToVideoFormat(CAM_MEDIA_FORMAT ecamFormat);
283
284#endif /* FREERDP_CLIENT_CAMERA_H */
Definition camera.h:236
interface to implement for the camera HAL
Definition camera.h:149
WINPR_ATTR_NODISCARD BOOL(* Deactivate)(ICamHal *ihal, const char *deviceId, CAM_ERROR_CODE *errorCode)
Definition camera.h:183
WINPR_ATTR_NODISCARD INT16(* GetMediaTypeDescriptions)(ICamHal *ihal, const char *deviceId, size_t streamIndex, const CAM_MEDIA_FORMAT_INFO *supportedFormats, size_t nSupportedFormats, CAM_MEDIA_TYPE_DESCRIPTION *mediaTypes, size_t *nMediaTypes)
Definition camera.h:197
WINPR_ATTR_NODISCARD UINT(* Enumerate)(ICamHal *ihal, ICamHalEnumCallback callback, CameraPlugin *ecam, GENERIC_CHANNEL_CALLBACK *hchannel)
Definition camera.h:161
WINPR_ATTR_NODISCARD BOOL(* Activate)(ICamHal *ihal, const char *deviceId, CAM_ERROR_CODE *errorCode)
Definition camera.h:172
CAM_ERROR_CODE(* StopStream)(ICamHal *ihal, const char *deviceId, size_t streamIndex)
Definition camera.h:223
WINPR_ATTR_NODISCARD CAM_ERROR_CODE(* StartStream)(ICamHal *ihal, CameraDevice *dev, size_t streamIndex, const CAM_MEDIA_TYPE_DESCRIPTION *mediaType, ICamHalSampleCapturedCallback callback)
Definition camera.h:211
CAM_ERROR_CODE(* Free)(ICamHal *ihal)
Definition camera.h:230