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 INT nSampleCredits;
105 wStream* sampleRespBuffer;
106
107 H264_CONTEXT* h264;
108
109#if defined(WITH_INPUT_FORMAT_MJPG)
110 AVCodecContext* avContext;
111 AVPacket* avInputPkt;
112 AVFrame* avOutFrame;
113#endif
114
115#if defined(WITH_INPUT_FORMAT_H264)
116 size_t h264FrameMaxSize;
117 BYTE* h264Frame;
118#endif
119
120 /* sws_scale */
121 struct SwsContext* sws;
122
124
125static INLINE CAM_MEDIA_FORMAT streamInputFormat(CameraDeviceStream* stream)
126{
127 return stream->formats.inputFormat;
128}
129static INLINE CAM_MEDIA_FORMAT streamOutputFormat(CameraDeviceStream* stream)
130{
131 return stream->formats.outputFormat;
132}
133
134typedef struct
135{
136 IWTSListener* listener;
137 GENERIC_LISTENER_CALLBACK* hlistener;
138 CameraPlugin* ecam;
139 ICamHal* ihal; /* HAL interface, same as used by CameraPlugin */
140 char deviceId[32];
141 CameraDeviceStream streams[ECAM_DEVICE_MAX_STREAMS];
142
144
149typedef UINT (*ICamHalEnumCallback)(CameraPlugin* ecam, GENERIC_CHANNEL_CALLBACK* hchannel,
150 const char* deviceId, const char* deviceName);
151
152/* may run in context of different thread */
153typedef UINT (*ICamHalSampleCapturedCallback)(CameraDevice* dev, int streamIndex,
154 const BYTE* sample, size_t size);
155
157{
158 UINT(*Enumerate)
159 (ICamHal* ihal, ICamHalEnumCallback callback, CameraPlugin* ecam,
160 GENERIC_CHANNEL_CALLBACK* hchannel);
161 INT16(*GetMediaTypeDescriptions)
162 (ICamHal* ihal, const char* deviceId, int streamIndex,
163 const CAM_MEDIA_FORMAT_INFO* supportedFormats, size_t nSupportedFormats,
164 CAM_MEDIA_TYPE_DESCRIPTION* mediaTypes, size_t* nMediaTypes);
165 UINT(*StartStream)
166 (ICamHal* ihal, CameraDevice* dev, int streamIndex, const CAM_MEDIA_TYPE_DESCRIPTION* mediaType,
167 ICamHalSampleCapturedCallback callback);
168 UINT (*StopStream)(ICamHal* ihal, const char* deviceId, int streamIndex);
169 UINT (*Free)(ICamHal* hal);
170};
171
172typedef UINT (*PREGISTERCAMERAHAL)(IWTSPlugin* plugin, ICamHal* hal);
173
174typedef struct
175{
176 IWTSPlugin* plugin;
177 PREGISTERCAMERAHAL pRegisterCameraHal;
178 CameraPlugin* ecam;
179 const ADDIN_ARGV* args;
180
182
184
185/* entry point called by addin manager */
186typedef UINT(VCAPITYPE* PFREERDP_CAMERA_HAL_ENTRY)(PFREERDP_CAMERA_HAL_ENTRY_POINTS pEntryPoints);
187
188/* common functions */
189UINT ecam_channel_send_generic_msg(CameraPlugin* ecam, GENERIC_CHANNEL_CALLBACK* hchannel,
190 CAM_MSG_ID msg);
191UINT ecam_channel_send_error_response(CameraPlugin* ecam, GENERIC_CHANNEL_CALLBACK* hchannel,
192 CAM_ERROR_CODE code);
193UINT ecam_channel_write(CameraPlugin* ecam, GENERIC_CHANNEL_CALLBACK* hchannel, CAM_MSG_ID msg,
194 wStream* out, BOOL freeStream);
195
196/* ecam device interface */
197void ecam_dev_destroy(CameraDevice* dev);
198
199WINPR_ATTR_MALLOC(ecam_dev_destroy, 1)
200CameraDevice* ecam_dev_create(CameraPlugin* ecam, const char* deviceId, const char* deviceName);
201
202/* video encoding interface */
203BOOL ecam_encoder_context_init(CameraDeviceStream* stream);
204BOOL ecam_encoder_context_free(CameraDeviceStream* stream);
205BOOL ecam_encoder_compress(CameraDeviceStream* stream, const BYTE* srcData, size_t srcSize,
206 BYTE** ppDstData, size_t* pDstSize);
207UINT32 h264_get_max_bitrate(UINT32 height);
208
209#endif /* FREERDP_CLIENT_CAMERA_H */
Definition camera.h:175