ZegoLiveRoom
video_capture.h
Go to the documentation of this file.
1#ifndef ZEGOVideoCapture_h
2#define ZEGOVideoCapture_h
3#include "video_format.h"
4namespace AVE {
5 enum {
9
11 };
12
14
16 public:
21 virtual int SetFrameRate(int framerate) = 0;
22
28 virtual int SetResolution(int width, int height) = 0;
29
34 virtual int SetFrontCam(int bFront) = 0;
35
40 virtual int SetView(void *view) = 0;
41
46 virtual int SetViewMode(int nMode) = 0;
47
52 virtual int SetViewRotation(int nRotation) = 0;
53
58 virtual int SetCaptureRotation(int nRotation) = 0;
59
63 virtual int StartPreview() = 0;
64
68 virtual int StopPreview() = 0;
69
74 virtual int EnableTorch(bool bEnable) = 0;
75
79 virtual int TakeSnapshot() = 0;
80
84 virtual int SetPowerlineFreq(unsigned int nFreq) { return 0; }
85 };
86
88 FILL_MODE_BLACKBAR, // * maintain aspect ratio, adds black bars if needed
89 FILL_MODE_CROP, // * crop video to fit view
90 FILL_MODE_STRETCH // * stretch video to fit view
91 };
92
95 FLIP_MODE_X = 1 << 0, // * 水平翻转,镜像
96 FLIP_MODE_Y = 1 << 1, // * 垂直翻转
97 };
98
99 // [top, left](bottom, right)
100 struct ROIRect {
102 top = left = bottom = right = 0;
103 level = 2;
104 }
105
106 int top;
107 int left;
109 int right;
110 int level; // [0~10]
111 };
112
114 public:
122 virtual void OnIncomingCapturedData(const char* data,
123 int length,
124 const VideoCaptureFormat& frame_format,
125 unsigned long long reference_time,
126 unsigned int reference_time_scale) = 0;
127
128 virtual void OnIncomingCapturedData2(unsigned char **ptrs,
129 int *lens,
130 const VideoCaptureFormat& frame_format,
131 unsigned long long reference_time,
132 unsigned int reference_time_scale) = 0;
133
134#if defined(_WIN32) || defined(WIN32) || defined(_MSC_VER)
142 virtual int OnIncomingD3DTexture(void* videoTex,
143 unsigned int rotate,
144 unsigned long long reference_time,
145 unsigned int reference_time_scale) {
146 return 0;
147 };
148#endif
149
152 virtual void OnTakeSnapshot(void* image) = 0;
153
156 virtual void SetFillMode(int mode) = 0;
157
161 virtual int SetROI(ROIRect* rects, int count) = 0;
162 };
163
165 public:
169 virtual void OnIncomingCapturedData(void* buffer,
170 double reference_time_ms) = 0;
171
174 virtual void SetFillMode(int mode) = 0;
177 virtual void SetRotation(int rotation) = 0;
178
182 virtual int SetROI(ROIRect* rects, int count) = 0;
183 };
184
186 public:
188 virtual void* GetSurfaceTexture() = 0;
189
194 virtual int SetROI(ROIRect* rects, int count, unsigned long long timestamp_ns) = 0;
197 virtual void SetFillMode(int mode) = 0;
202 virtual void SetTextureResolution(int width, int height) = 0;
203 };
204
206 public:
212 virtual void OnIncomingCapturedData(int texture_id, int width, int height, double reference_time_ms) = 0;
213
216 virtual void SetFillMode(int mode) = 0;
217
220 virtual void SetFlipMode(int mode) = 0;
221
224 virtual void SetTransformMatrix(float matrix[16]) = 0;
225
228 virtual void SetRotation(int rotation) = 0;
229
233 virtual int SetROI(ROIRect* rects, int count) = 0;
234
236 virtual void ResetTextureContext() = 0;
237 };
238
245 };
246
249 }
250
251 int width;
254 const char* media_side_info; // deprecated, use CEngine::SendMediaSideInfo instead
255 int media_side_info_size; // deprecated, use CEngine::SendMediaSideInfo instead
256
258 int rotation; // counterclockwise degree
259 };
260
262 public:
270 virtual void OnEncodedFrame(const char* data, int length,
271 const VideoCodecConfig& codec_config,
272 bool b_keyframe, double reference_time_ms) = 0;
273 };
274
287 };
288
290 public:
291 class Client {
292 public:
293 virtual ~Client() {}
294
297 virtual void Destroy() = 0;
298
299 virtual void SetStatusReason(bool is_closed, int reason) = 0;
300
308 virtual void* GetInterface() = 0;
309 };
310
311 public:
317 virtual void AllocateAndStart(Client* client) = 0;
318
323 virtual void StopAndDeAllocate() = 0;
324
329 virtual int StartCapture() = 0;
330
335 virtual int StopCapture() = 0;
336
341
346 virtual void* GetInterface() = 0;
347 };
348
350 public:
352 public:
353 virtual ~Client() {}
354 virtual void* GetInterface() {
355 return (VideoCaptureCallback*)this;
356 }
357 };
358
359 public :
360 virtual void AllocateAndStart(Client* client) = 0;
361
362 virtual void AllocateAndStart(VideoCaptureDeviceBase::Client* client) override {
363 this->AllocateAndStart((Client*)client);
364 }
365
368 }
369
370 virtual void* GetInterface() override {
371 return (SupportsVideoCapture*)this;
372 }
373 };
374
376 public:
382 virtual VideoCaptureDeviceBase* Create(const char* device_id) = 0;
383
388 virtual void Destroy(VideoCaptureDeviceBase *vc) = 0;
389 };
390
407 };
408
413 };
414
416 public:
417 virtual int DequeueInputBuffer(int width, int height, int stride) = 0;
418 virtual void* GetInputBuffer(int index) = 0;
419 virtual void QueueInputBuffer(int index, int width, int height, int stride, unsigned long long timestamp_100n) = 0;
420 virtual void QueueInputBufferWithDest(int index, int width, int height, int stride,
421 unsigned long long timestamp_100n, VideoBufferDestination dest) {
422 }
423 };
424
426 public:
427 virtual void OnProcess(void* buffer, int size, int width, int height, int stride, unsigned long long timestamp_100n) = 0;
428 virtual void OnProcessWithDest(void* buffer, int size, int width, int height, int stride,
429 unsigned long long timestamp_100n, VideoBufferDestination dest) {
430 }
431 };
432
434 public:
435 virtual void OnProcessMem(unsigned char **pData, int* dataLen, int width, int height, int stride[4], unsigned long long timestamp_100n) = 0;
436 virtual void OnProcessMemWithDest(unsigned char **pData, int* dataLen, int width, int height, int stride[4],
437 unsigned long long timestamp_100n, VideoBufferDestination dest) {
438 }
439 };
440
442 public:
443 class Client {
444 public:
445 virtual ~Client() {}
446 virtual void Destroy() = 0;
447
467 virtual void* GetInterface() = 0;
468 };
469
470 public:
476 virtual void AllocateAndStart(Client* client) = 0;
477
482 virtual void StopAndDeAllocate() = 0;
483
488
506 virtual void* GetInterface(VideoBufferType buffer_type = BUFFER_TYPE_UNKNOWN) = 0;
507 };
508
510 public:
512
516 virtual VideoFilter* Create() = 0;
517
521 virtual void Destroy(VideoFilter *vf) = 0;
522 };
523
525 public:
526 static Camera* Create();
527 static void Destroy(Camera* camera);
528
529 virtual void SetDeviceId(const char* device_id) = 0;
530 };
531}
532#endif /* ZEGOVideoCapture_h */
Definition: video_capture.h:524
static void Destroy(Camera *camera)
static Camera * Create()
virtual void SetDeviceId(const char *device_id)=0
Definition: video_capture.h:15
virtual int SetFrontCam(int bFront)=0
切换前后摄像头,移动端专用,PC端不需要实现
virtual int StopPreview()=0
停止预览
virtual int SetViewRotation(int nRotation)=0
设置采集预览的逆时针旋转角度
virtual int StartPreview()=0
启动预览
virtual int SetViewMode(int nMode)=0
设置采集预览模式
virtual int SetPowerlineFreq(unsigned int nFreq)
设置采集刷新率
Definition: video_capture.h:84
virtual int EnableTorch(bool bEnable)=0
打开闪光灯
virtual int SetCaptureRotation(int nRotation)=0
设置采集buffer的顺时针旋转角度
virtual int SetFrameRate(int framerate)=0
设置采集帧率
virtual int SetResolution(int width, int height)=0
设置采集分辨率,采集的分辨率最大不能超过1920*1080
virtual int SetView(void *view)=0
设置采集使用载体
virtual int TakeSnapshot()=0
对采集预览进行截图,完成后通过client的OnTakeSnapshot方法通知SDK
Definition: video_capture.h:415
virtual int DequeueInputBuffer(int width, int height, int stride)=0
virtual void QueueInputBuffer(int index, int width, int height, int stride, unsigned long long timestamp_100n)=0
virtual void * GetInputBuffer(int index)=0
virtual void QueueInputBufferWithDest(int index, int width, int height, int stride, unsigned long long timestamp_100n, VideoBufferDestination dest)
Definition: video_capture.h:420
Definition: video_capture.h:164
virtual void OnIncomingCapturedData(void *buffer, double reference_time_ms)=0
通知SDK采集到视频数据,SDK会同步拷贝数据,切换到内部线程进行编码,如果缓冲队列不够,SDK会自动丢帧
virtual void SetFillMode(int mode)=0
当时图像宽高和编码宽高的宽高比不一致时使用的填充模式,默认裁剪
virtual void SetRotation(int rotation)=0
用于修正图像的角度
virtual int SetROI(ROIRect *rects, int count)=0
设置编码器感兴趣的区域,优化图像主观体验
Definition: video_capture.h:113
virtual void OnIncomingCapturedData(const char *data, int length, const VideoCaptureFormat &frame_format, unsigned long long reference_time, unsigned int reference_time_scale)=0
通知SDK采集到视频数据,SDK会同步拷贝数据,切换到内部线程进行编码,如果缓冲队列不够,SDK会自动丢帧
virtual int OnIncomingD3DTexture(void *videoTex, unsigned int rotate, unsigned long long reference_time, unsigned int reference_time_scale)
通知SDK采集到纹理数据,SDK会同步拷贝数据,切换到内部线程进行编码,如果缓冲队列不够,SDK会自动丢帧
Definition: video_capture.h:142
virtual void OnTakeSnapshot(void *image)=0
通知SDK截图成功
virtual void OnIncomingCapturedData2(unsigned char **ptrs, int *lens, const VideoCaptureFormat &frame_format, unsigned long long reference_time, unsigned int reference_time_scale)=0
virtual void SetFillMode(int mode)=0
当时图像宽高和编码宽高的宽高比不一致时使用的填充模式,默认裁剪
virtual int SetROI(ROIRect *rects, int count)=0
设置编码器感兴趣的区域,优化图像主观体验
Definition: video_capture.h:351
virtual void * GetInterface()
获取不同采集方式对应的回调接口
Definition: video_capture.h:354
virtual ~Client()
Definition: video_capture.h:353
Definition: video_capture.h:291
virtual void * GetInterface()=0
获取不同采集方式对应的回调接口
virtual void Destroy()=0
通知SDK销毁采集回调
virtual ~Client()
Definition: video_capture.h:293
virtual void SetStatusReason(bool is_closed, int reason)=0
Definition: video_capture.h:289
virtual VideoPixelBufferType SupportBufferType()=0
获取采集callback的类型
virtual int StartCapture()=0
启动采集,采集的数据通过client对象的OnIncomingCapturedData通知SDK
virtual void * GetInterface()=0
检查是否支持SupportsVideoCapture接口
virtual void StopAndDeAllocate()=0
停止并且释放采集占用的资源,同时调用client的Destroy方法,这里的client指的是AllocateAndStart传递的client
virtual void AllocateAndStart(Client *client)=0
初始化采集使用的资源,例如启动线程,保存SDK传递的回调
virtual int StopCapture()=0
停止采集
Definition: video_capture.h:349
virtual VideoPixelBufferType SupportBufferType() override
获取采集callback的类型
Definition: video_capture.h:366
virtual void AllocateAndStart(Client *client)=0
virtual void * GetInterface() override
检查是否支持SupportsVideoCapture接口
Definition: video_capture.h:370
virtual void AllocateAndStart(VideoCaptureDeviceBase::Client *client) override
初始化采集使用的资源,例如启动线程,保存SDK传递的回调
Definition: video_capture.h:362
Definition: video_capture.h:261
virtual void OnEncodedFrame(const char *data, int length, const VideoCodecConfig &codec_config, bool b_keyframe, double reference_time_ms)=0
通知SDK采集到编码数据,SDK会切换到内部线程进行发送
Definition: video_capture.h:375
virtual VideoCaptureDeviceBase * Create(const char *device_id)=0
创建采集设备
virtual void Destroy(VideoCaptureDeviceBase *vc)=0
销毁采集设备
virtual ~VideoCaptureFactory()
Definition: video_capture.h:377
Definition: video_capture.h:185
virtual void * GetSurfaceTexture()=0
获取SurfaceTexture对应的jobject
virtual int SetROI(ROIRect *rects, int count, unsigned long long timestamp_ns)=0
设置编码器感兴趣的区域,优化图像主观体验
virtual void SetFillMode(int mode)=0
当图像宽高和编码宽高的宽高比不一致时使用的填充模式,默认裁剪
virtual void SetTextureResolution(int width, int height)=0
同步纹理的宽高,当纹理款高和编码宽高的宽高比不一致时按照填充模式填充
Definition: video_capture.h:205
virtual void SetTransformMatrix(float matrix[16])=0
transform可以包含旋转/翻转/缩放,SDK会先执行transform,再执行其他操作
virtual void SetFillMode(int mode)=0
当时图像宽高和编码宽高的宽高比不一致时使用的填充模式,默认裁剪
virtual void SetRotation(int rotation)=0
用于修正图像的角度,rotation在transform后执行,注意不要重复计算rotation
virtual int SetROI(ROIRect *rects, int count)=0
设置编码器感兴趣的区域,优化图像主观体验
virtual void ResetTextureContext()=0
通知SDK纹理相关的上下文发生变化,用来清除缓存的上下文状态,比如EglContext,必须和OnIncomingCapturedData在同一个线程调用,不保证线程安全
virtual void OnIncomingCapturedData(int texture_id, int width, int height, double reference_time_ms)=0
通知SDK采集到视频数据,SDK会同步绘制到FBO,切换到内部线程进行编码,如果缓冲队列不够,SDK会自动丢帧
virtual void SetFlipMode(int mode)=0
SDK默认垂直翻转,如果不需要,设置0,前处理的最后一步
Definition: video_capture.h:443
virtual ~Client()
Definition: video_capture.h:445
virtual void * GetInterface()=0
获取不同滤镜处理模型对应的接口
virtual void Destroy()=0
Definition: video_capture.h:425
virtual void OnProcess(void *buffer, int size, int width, int height, int stride, unsigned long long timestamp_100n)=0
virtual void OnProcessWithDest(void *buffer, int size, int width, int height, int stride, unsigned long long timestamp_100n, VideoBufferDestination dest)
Definition: video_capture.h:428
Definition: video_capture.h:509
virtual VideoFilter * Create()=0
创建滤镜
virtual ~VideoFilterFactory()
Definition: video_capture.h:511
virtual void Destroy(VideoFilter *vf)=0
销毁滤镜
Definition: video_capture.h:441
virtual void * GetInterface(VideoBufferType buffer_type=BUFFER_TYPE_UNKNOWN)=0
获取不同滤镜处理模型对应的接口
virtual void StopAndDeAllocate()=0
停止并且释放采集占用的资源,同时调用client的Destroy方法,这里的client指的是AllocateAndStart传递的client
virtual void AllocateAndStart(Client *client)=0
初始化采集使用的资源,例如启动线程,保存SDK传递的回调
virtual VideoBufferType SupportBufferType()=0
获取滤镜处理类型,SDK会根据此类型,使用对应的接口传输数据
Definition: video_capture.h:433
virtual void OnProcessMemWithDest(unsigned char **pData, int *dataLen, int width, int height, int stride[4], unsigned long long timestamp_100n, VideoBufferDestination dest)
Definition: video_capture.h:436
virtual void OnProcessMem(unsigned char **pData, int *dataLen, int width, int height, int stride[4], unsigned long long timestamp_100n)=0
Definition: audio_capture.h:4
VideoCodecType
Definition: video_capture.h:239
@ CODEC_TYPE_VP8
Definition: video_capture.h:242
@ CODEC_TYPE_HEVC_AVCC
Definition: video_capture.h:243
@ CODEC_TYPE_AVC_AVCC
Definition: video_capture.h:240
@ CODEC_TYPE_HEVC_ANNEXB
Definition: video_capture.h:244
@ CODEC_TYPE_AVC_ANNEXB
Definition: video_capture.h:241
VideoDataFormat VideoCaptureFormat
Definition: video_capture.h:13
@ VCAP_ERROR_NOERROR
Definition: video_capture.h:6
@ VCAP_ERROR_GENERIC_ERROR
Definition: video_capture.h:7
@ VCAP_ERROR_NOMEMORY
Definition: video_capture.h:8
@ VCAP_ERROR_INVALID_ACTIVE_D3D11_DEVICE
Definition: video_capture.h:10
VideoFlipMode
Definition: video_capture.h:93
@ FLIP_MODE_X
Definition: video_capture.h:95
@ FLIP_MODE_Y
Definition: video_capture.h:96
@ FLIP_MODE_NONE
Definition: video_capture.h:94
VideoBufferDestination
Definition: video_capture.h:409
@ BUFFER_TO_BOTH
Definition: video_capture.h:412
@ BUFFER_TO_PREVIEW
Definition: video_capture.h:410
@ BUFFER_TO_ENCODE
Definition: video_capture.h:411
VideoFillMode
Definition: video_capture.h:87
@ FILL_MODE_BLACKBAR
Definition: video_capture.h:88
@ FILL_MODE_CROP
Definition: video_capture.h:89
@ FILL_MODE_STRETCH
Definition: video_capture.h:90
VideoPixelBufferType
Definition: video_capture.h:275
@ PIXEL_BUFFER_TYPE_D3D12_TEXTURE
Definition: video_capture.h:286
@ PIXEL_BUFFER_TYPE_I422_MEM_FOR_HIGH422
Definition: video_capture.h:282
@ PIXEL_BUFFER_TYPE_D3D11_TEXTURE
Definition: video_capture.h:285
@ PIXEL_BUFFER_TYPE_ENCODED_FRAME
Definition: video_capture.h:281
@ PIXEL_BUFFER_TYPE_UNKNOWN
Definition: video_capture.h:276
@ PIXEL_BUFFER_TYPE_MEM
Definition: video_capture.h:277
@ PIXEL_BUFFER_TYPE_CV_PIXEL_BUFFER
Definition: video_capture.h:278
@ PIXEL_BUFFER_TYPE_D3D9_TEXTURE
Definition: video_capture.h:284
@ PIXEL_BUFFER_TYPE_SURFACE_TEXTURE
Definition: video_capture.h:279
@ PIXEL_BUFFER_TYPE_GL_TEXTURE_EXTERNAL_OES
Definition: video_capture.h:283
@ PIXEL_BUFFER_TYPE_GL_TEXTURE_2D
Definition: video_capture.h:280
VideoBufferType
Definition: video_capture.h:391
@ BUFFER_TYPE_UNKNOWN
Definition: video_capture.h:392
@ BUFFER_TYPE_SYNC_CM_SAMPLE_BUFFER
Definition: video_capture.h:403
@ BUFFER_TYPE_ASYNC_CM_SAMPLE_BUFFER
Definition: video_capture.h:402
@ BUFFER_TYPE_SYNC_GL_TEXTURE_2D
Definition: video_capture.h:398
@ BUFFER_TYPE_SYNC_I420_MEM
Definition: video_capture.h:405
@ BUFFER_TYPE_MEM
Definition: video_capture.h:393
@ BUFFER_TYPE_SYNC_NV12_PIXEL_BUFFER
Definition: video_capture.h:406
@ BUFFER_TYPE_SYNC_BGRA32_MEM
Definition: video_capture.h:404
@ BUFFER_TYPE_ASYNC_NV12_PIXEL_BUFFER
Definition: video_capture.h:401
@ BUFFER_TYPE_SYNC_PIXEL_BUFFER
Definition: video_capture.h:395
@ BUFFER_TYPE_ASYNC_I420_MEM
Definition: video_capture.h:399
@ BUFFER_TYPE_ASYNC_PIXEL_BUFFER
Definition: video_capture.h:394
@ BUFFER_TYPE_ASYNC_I420_PIXEL_BUFFER
Definition: video_capture.h:400
@ BUFFER_TYPE_HYBRID_MEM_GL_TEXTURE_2D
Definition: video_capture.h:397
@ BUFFER_TYPE_SURFACE_TEXTURE
Definition: video_capture.h:396
Definition: video_capture.h:100
int right
Definition: video_capture.h:109
int top
Definition: video_capture.h:106
int bottom
Definition: video_capture.h:108
ROIRect()
Definition: video_capture.h:101
int left
Definition: video_capture.h:107
int level
Definition: video_capture.h:110
Definition: video_capture.h:247
VideoCodecType codec_type
Definition: video_capture.h:253
VideoCodecConfig()
Definition: video_capture.h:248
int width
Definition: video_capture.h:251
int height
Definition: video_capture.h:252
const char * media_side_info
Definition: video_capture.h:254
bool is_external_clock
Definition: video_capture.h:257
int rotation
Definition: video_capture.h:258
int media_side_info_size
Definition: video_capture.h:255
Definition: video_format.h:26