//
//  YCKVideoEngine.h
//  YCKCall
//
//  Created by 徐家骏 on 2019/4/24.
//  Copyright © 2019 徐家骏. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <YCKSdwan/YCKSdwan.h>
#import "YCKGlobalDefs.h"  //不知道为啥在pch里面有了，这儿还要这句才行。。。
#import "YCKVideoFrameContext.h"
#import "YCKGLView.h"

NS_ASSUME_NONNULL_BEGIN

@protocol YCKVideoEngineDelegate <NSObject>

- (void)onRemoteVideoFrameReady:(CVImageBufferRef)image withContext:(YCKVideoFrameContext *)frameContext from:(int64_t)from;
- (void)onLocalVideoFrameReady:(CVImageBufferRef)image withContext:(YCKVideoFrameContext *)frameContext;
- (void)onStopAcceptVideo:(BOOL)stopped;

@end

@interface YCKVideoEngine : NSObject<YCKTransportSessionVideoDelegate>

@property (nonatomic, weak)  id<YCKVideoEngineDelegate>    delegate;
@property (nonatomic, strong, nullable) YCKTransportSession *transportSession;  //CALL MANAGER里面会持有，这儿weak即可，以后engine改为非单例时，可以在dealloc中释放 //后改为strong，因为会引起crash
@property (nonatomic, strong)         NSOrderedSet        *activeParticipants;
@property (nonatomic)   YCKCallMode      mode;
@property (atomic)      BOOL             isAppStateBackground;
/// 图像是否自动跟随设备自动旋转。默认 YES。
@property (nonatomic, getter = isAutoRotate) BOOL autoRotate;

+ (instancetype)sharedInstance;
- (void)StartPreview;
- (void)Start;
- (void)Stop;

- (YCKVideoCameraPosition) getCameraPosition;
- (void) setCameraPosition:(YCKVideoCameraPosition)position;
- (uint32_t) getVideoMaxBitrate;
- (void) setVideoMaxBitrate:(uint32_t)bitrate;
- (int32_t) getVideoFramerate;
- (void) setVideoFramerate:(int32_t)framerate;
- (YCKCallVideoPreset) getVideoPreset;
- (void) setVideoPreset:(YCKCallVideoPreset)preset;
- (void) setVideoPreferredMode:(YCKCallVideoPreferredMode) preferredMode;
- (void) setCameraOn:(BOOL)on;
- (BOOL) isCameraOn;
- (void) setVideoCodecH264Preferred:(BOOL)h264Preferred;
- (BOOL) isH264Preferred;
- (BOOL) isGreenCurtainOn;
- (void) setGreenCurtain:(BOOL)on;
- (void) setGreenCurtainBackground:(UIImage *)image;

- (void)registerGLView:(YCKGLView *)glview forUid:(int64_t)uid; //这个是给YCKGlView用的，用来建立view和uid的联系
- (void)unRegisterGLView:(YCKGLView *)glview forUid:(int64_t)uid;
- (void)registerGLView:(YCKGLView *)glview forTempUid:(int64_t)uid; //这个是给切换视频流后，新流没来之前临时拉取原视频流。
- (void)unRegisterGLView:(YCKGLView *)glview forTempUid:(int64_t)uid;
- (UIDeviceOrientation) currentDeviceOrientation;

//用于视频画面的水平、垂直镜像及透视变换
#pragma mark - perspective transform
- (BOOL)isMirrorHorizontalUid:(int64_t)uid;
- (BOOL)isMirrorVerticalUid:(int64_t)uid;
- (void)setMirrorHorizontal:(BOOL)mirrored uid:(int64_t)uid;
- (void)setMirrorVertical:(BOOL)mirrored uid:(int64_t)uid;
- (BOOL)getBaseRect:(CGFloat *)x0 :(CGFloat *)y0 :(CGFloat *)x1 :(CGFloat *)y1 :(CGFloat *)x2 :(CGFloat *)y2 :(CGFloat *)x3 :(CGFloat *)y3 uid:(int64_t)uid autoDetection:(BOOL)enabled;
- (void)setBaseRect:(CGFloat)x0 :(CGFloat)y0 :(CGFloat)x1 :(CGFloat)y1 :(CGFloat)x2 :(CGFloat)y2 :(CGFloat)x3 :(CGFloat)y3 uid:(int64_t)uid;
- (void)getPerspectiveRect:(CGFloat *)x0 :(CGFloat *)y0 :(CGFloat *)x1 :(CGFloat *)y1 :(CGFloat *)x2 :(CGFloat *)y2 :(CGFloat *)x3 :(CGFloat *)y3 uid:(int64_t)uid;
- (void)setPerspectiveRect:(CGFloat)x0 :(CGFloat)y0 :(CGFloat)x1 :(CGFloat)y1 :(CGFloat)x2 :(CGFloat)y2 :(CGFloat)x3 :(CGFloat)y3 uid:(int64_t)uid;
- (void)autoPerspectiveTransform:(int64_t)uid;
- (void)confirmVideoTransformUid:(int64_t)uid;
- (void)cancelVideoTransformUid:(int64_t)uid;
- (void)resetVideoTransformUid:(int64_t)uid;

- (void)sendVideoTransformCommandUid:(int64_t)uid op:(NSString *)op;
- (void)onReceivedVideoTransformCommand:(NSData *)data from:(int64_t)from;
@end

NS_ASSUME_NONNULL_END
