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#if defined(WITH_INPUT_FORMAT_MJPG)
29#include <libavcodec/avcodec.h>
30#endif
31
32#include <libswscale/swscale.h>
33#include <libavutil/imgutils.h>
34
35#include <winpr/wlog.h>
36#include <winpr/wtypes.h>
37
38#include <freerdp/api.h>
39#include <freerdp/types.h>
40
41#include <freerdp/client/channels.h>
42#include <freerdp/channels/log.h>
43#include <freerdp/channels/rdpecam.h>
44#include <freerdp/codecs.h>
45#include <freerdp/primitives.h>
46
47#define ECAM_PROTO_VERSION 0x02
48/* currently supporting 1 stream per device */
49#define ECAM_DEVICE_MAX_STREAMS 1
50#define ECAM_MAX_MEDIA_TYPE_DESCRIPTORS 256
51
52/* Allow to send up to that many unsolicited samples.
53 * For example, to support 30 fps with 250 ms round trip
54 * ECAM_MAX_SAMPLE_CREDITS has to be at least 8.
55 */
56#define ECAM_MAX_SAMPLE_CREDITS 8
57
58/* Having this hardcoded allows to preallocate and reuse buffer
59 * for sample responses. Excessive size is to make sure any sample
60 * will fit in, even with highest resolution.
61 */
62#define ECAM_SAMPLE_RESPONSE_BUFFER_SIZE (1024ULL * 4050ULL)
63
64/* Special format addition for CAM_MEDIA_FORMAT enum formats
65 * used to support H264 stream muxed in MJPG container stream.
66 * The value picked not to overlap with enum values
67 */
68#define CAM_MEDIA_FORMAT_MJPG_H264 0x0401
69
70typedef struct s_ICamHal ICamHal;
71
72typedef struct
73{
74 IWTSPlugin iface;
75 IWTSListener* listener;
77
78 /* HAL interface */
79 ICamHal* ihal;
80 char* subsystem;
81
82 BOOL initialized;
83 BOOL attached;
84
85 UINT32 version;
86 wHashTable* devices;
87
89
90typedef struct
91{
92 CAM_MEDIA_FORMAT inputFormat; /* camera side */
93 CAM_MEDIA_FORMAT outputFormat; /* network side */
94
96
97typedef struct
98{
99 BOOL streaming;
100 CAM_MEDIA_FORMAT_INFO formats;
101 CAM_MEDIA_TYPE_DESCRIPTION currMediaType;
102
103 GENERIC_CHANNEL_CALLBACK* hSampleReqChannel;
104 CRITICAL_SECTION lock;
105 volatile LONG samplesRequested;
106 wStream* pendingSample;
107 volatile BOOL haveSample;
108 wStream* sampleRespBuffer;
109
110 H264_CONTEXT* h264;
111
112#if defined(WITH_INPUT_FORMAT_MJPG)
113 AVCodecContext* avContext;
114 AVPacket* avInputPkt;
115 AVFrame* avOutFrame;
116#endif
117
118#if defined(WITH_INPUT_FORMAT_H264)
119 size_t h264FrameMaxSize;
120 BYTE* h264Frame;
121#endif
122
123 /* sws_scale */
124 uint32_t swsWidth;
125 uint32_t swsHeight;
126 struct SwsContext* sws;
127
129
130static inline CAM_MEDIA_FORMAT streamInputFormat(CameraDeviceStream* stream)
131{
132 return stream->formats.inputFormat;
133}
134static inline CAM_MEDIA_FORMAT streamOutputFormat(CameraDeviceStream* stream)
135{
136 return stream->formats.outputFormat;
137}
138
139typedef struct
140{
141 IWTSListener* listener;
142 GENERIC_LISTENER_CALLBACK* hlistener;
143 CameraPlugin* ecam;
144 ICamHal* ihal; /* HAL interface, same as used by CameraPlugin */
145 char deviceId[32];
146 CameraDeviceStream streams[ECAM_DEVICE_MAX_STREAMS];
147
149
154typedef UINT (*ICamHalEnumCallback)(CameraPlugin* ecam, GENERIC_CHANNEL_CALLBACK* hchannel,
155 const char* deviceId, const char* deviceName);
156
157/* may run in context of different thread */
158typedef UINT (*ICamHalSampleCapturedCallback)(CameraDevice* dev, int streamIndex,
159 const BYTE* sample, size_t size);
160
163{
172 UINT(*Enumerate)
173 (ICamHal* ihal, ICamHalEnumCallback callback, CameraPlugin* ecam,
174 GENERIC_CHANNEL_CALLBACK* hchannel);
175
184 BOOL (*Activate)(ICamHal* ihal, const char* deviceId, UINT32* errorCode);
185
194 BOOL (*Deactivate)(ICamHal* ihal, const char* deviceId, UINT32* errorCode);
195
207 INT16(*GetMediaTypeDescriptions)
208 (ICamHal* ihal, const char* deviceId, int streamIndex,
209 const CAM_MEDIA_FORMAT_INFO* supportedFormats, size_t nSupportedFormats,
210 CAM_MEDIA_TYPE_DESCRIPTION* mediaTypes, size_t* nMediaTypes);
211
221 UINT(*StartStream)
222 (ICamHal* ihal, CameraDevice* dev, int streamIndex, const CAM_MEDIA_TYPE_DESCRIPTION* mediaType,
223 ICamHalSampleCapturedCallback callback);
224
232 UINT (*StopStream)(ICamHal* ihal, const char* deviceId, int streamIndex);
233
239 UINT (*Free)(ICamHal* ihal);
240};
241
242typedef UINT (*PREGISTERCAMERAHAL)(IWTSPlugin* plugin, ICamHal* hal);
243
244typedef struct
245{
246 IWTSPlugin* plugin;
247 PREGISTERCAMERAHAL pRegisterCameraHal;
248 CameraPlugin* ecam;
249 const ADDIN_ARGV* args;
250
252
254
255/* entry point called by addin manager */
256typedef UINT(VCAPITYPE* PFREERDP_CAMERA_HAL_ENTRY)(PFREERDP_CAMERA_HAL_ENTRY_POINTS pEntryPoints);
257
258/* common functions */
259UINT ecam_channel_send_generic_msg(CameraPlugin* ecam, GENERIC_CHANNEL_CALLBACK* hchannel,
260 CAM_MSG_ID msg);
261UINT ecam_channel_send_error_response(CameraPlugin* ecam, GENERIC_CHANNEL_CALLBACK* hchannel,
262 CAM_ERROR_CODE code);
263UINT ecam_channel_write(CameraPlugin* ecam, GENERIC_CHANNEL_CALLBACK* hchannel, CAM_MSG_ID msg,
264 wStream* out, BOOL freeStream);
265
266/* ecam device interface */
267void ecam_dev_destroy(CameraDevice* dev);
268
269WINPR_ATTR_MALLOC(ecam_dev_destroy, 1)
270WINPR_ATTR_NODISCARD
271CameraDevice* ecam_dev_create(CameraPlugin* ecam, const char* deviceId, const char* deviceName);
272
273/* video encoding interface */
274BOOL ecam_encoder_context_init(CameraDeviceStream* stream);
275BOOL ecam_encoder_context_free(CameraDeviceStream* stream);
276BOOL ecam_encoder_compress(CameraDeviceStream* stream, const BYTE* srcData, size_t srcSize,
277 BYTE** ppDstData, size_t* pDstSize);
278UINT32 h264_get_max_bitrate(UINT32 height);
279
280#endif /* FREERDP_CLIENT_CAMERA_H */
Definition camera.h:245
interface to implement for the camera HAL
Definition camera.h:163
UINT(* StopStream)(ICamHal *ihal, const char *deviceId, int streamIndex)
Definition camera.h:232
BOOL(* Activate)(ICamHal *ihal, const char *deviceId, UINT32 *errorCode)
Definition camera.h:184
ICamHal * ihal
Definition camera.h:173
BOOL(* Deactivate)(ICamHal *ihal, const char *deviceId, UINT32 *errorCode)
Definition camera.h:194
UINT(* Free)(ICamHal *ihal)
Definition camera.h:239