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 struct SwsContext* sws;
125
127
128static inline CAM_MEDIA_FORMAT streamInputFormat(CameraDeviceStream* stream)
129{
130 return stream->formats.inputFormat;
131}
132static inline CAM_MEDIA_FORMAT streamOutputFormat(CameraDeviceStream* stream)
133{
134 return stream->formats.outputFormat;
135}
136
137typedef struct
138{
139 IWTSListener* listener;
140 GENERIC_LISTENER_CALLBACK* hlistener;
141 CameraPlugin* ecam;
142 ICamHal* ihal; /* HAL interface, same as used by CameraPlugin */
143 char deviceId[32];
144 CameraDeviceStream streams[ECAM_DEVICE_MAX_STREAMS];
145
147
152typedef UINT (*ICamHalEnumCallback)(CameraPlugin* ecam, GENERIC_CHANNEL_CALLBACK* hchannel,
153 const char* deviceId, const char* deviceName);
154
155/* may run in context of different thread */
156typedef UINT (*ICamHalSampleCapturedCallback)(CameraDevice* dev, int streamIndex,
157 const BYTE* sample, size_t size);
158
161{
170 UINT(*Enumerate)
171 (ICamHal* ihal, ICamHalEnumCallback callback, CameraPlugin* ecam,
172 GENERIC_CHANNEL_CALLBACK* hchannel);
173
182 BOOL (*Activate)(ICamHal* ihal, const char* deviceId, UINT32* errorCode);
183
192 BOOL (*Deactivate)(ICamHal* ihal, const char* deviceId, UINT32* errorCode);
193
205 INT16(*GetMediaTypeDescriptions)
206 (ICamHal* ihal, const char* deviceId, int streamIndex,
207 const CAM_MEDIA_FORMAT_INFO* supportedFormats, size_t nSupportedFormats,
208 CAM_MEDIA_TYPE_DESCRIPTION* mediaTypes, size_t* nMediaTypes);
209
219 UINT(*StartStream)
220 (ICamHal* ihal, CameraDevice* dev, int streamIndex, const CAM_MEDIA_TYPE_DESCRIPTION* mediaType,
221 ICamHalSampleCapturedCallback callback);
222
230 UINT (*StopStream)(ICamHal* ihal, const char* deviceId, int streamIndex);
231
237 UINT (*Free)(ICamHal* ihal);
238};
239
240typedef UINT (*PREGISTERCAMERAHAL)(IWTSPlugin* plugin, ICamHal* hal);
241
242typedef struct
243{
244 IWTSPlugin* plugin;
245 PREGISTERCAMERAHAL pRegisterCameraHal;
246 CameraPlugin* ecam;
247 const ADDIN_ARGV* args;
248
250
252
253/* entry point called by addin manager */
254typedef UINT(VCAPITYPE* PFREERDP_CAMERA_HAL_ENTRY)(PFREERDP_CAMERA_HAL_ENTRY_POINTS pEntryPoints);
255
256/* common functions */
257UINT ecam_channel_send_generic_msg(CameraPlugin* ecam, GENERIC_CHANNEL_CALLBACK* hchannel,
258 CAM_MSG_ID msg);
259UINT ecam_channel_send_error_response(CameraPlugin* ecam, GENERIC_CHANNEL_CALLBACK* hchannel,
260 CAM_ERROR_CODE code);
261UINT ecam_channel_write(CameraPlugin* ecam, GENERIC_CHANNEL_CALLBACK* hchannel, CAM_MSG_ID msg,
262 wStream* out, BOOL freeStream);
263
264/* ecam device interface */
265void ecam_dev_destroy(CameraDevice* dev);
266
267WINPR_ATTR_MALLOC(ecam_dev_destroy, 1)
268CameraDevice* ecam_dev_create(CameraPlugin* ecam, const char* deviceId, const char* deviceName);
269
270/* video encoding interface */
271BOOL ecam_encoder_context_init(CameraDeviceStream* stream);
272BOOL ecam_encoder_context_free(CameraDeviceStream* stream);
273BOOL ecam_encoder_compress(CameraDeviceStream* stream, const BYTE* srcData, size_t srcSize,
274 BYTE** ppDstData, size_t* pDstSize);
275UINT32 h264_get_max_bitrate(UINT32 height);
276
277#endif /* FREERDP_CLIENT_CAMERA_H */
Definition camera.h:243
interface to implement for the camera HAL
Definition camera.h:161
UINT(* StopStream)(ICamHal *ihal, const char *deviceId, int streamIndex)
Definition camera.h:230
BOOL(* Activate)(ICamHal *ihal, const char *deviceId, UINT32 *errorCode)
Definition camera.h:182
ICamHal * ihal
Definition camera.h:171
BOOL(* Deactivate)(ICamHal *ihal, const char *deviceId, UINT32 *errorCode)
Definition camera.h:192
UINT(* Free)(ICamHal *ihal)
Definition camera.h:237