//
//  NXLiveSession.h
//  NXLive
//
//  Created by Neuxnet on 2020/11/17.
//  Copyright © 2020 wangran. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <AVFoundation/AVFoundation.h>
#import "NXLiveStreamInfo.h"
#import "NXLiveDebug.h"

@class NXLiveSession;
@protocol NXLiveSessionDelegate <NSObject>
@optional
/// live status changed will callback
- (void)liveSession:(nullable NXLiveSession *)session liveStateDidChange:(NXLiveState)state;
/// live stream buffer count  callback
- (void)liveSession:(nullable NXLiveSession *)session liveBufferCount:(int)bufferCount;
/// live debug info callback
- (void)liveSession:(nullable NXLiveSession *)session debugInfo:(nullable NXLiveDebug *)debugInfo;
/// callback socket errorcode
- (void)liveSession:(nullable NXLiveSession *)session errorCode:(NXLiveSocketErrorCode)errorCode;
@end

NS_ASSUME_NONNULL_BEGIN

@interface NXLiveSession : NSObject

/** The delegate of the capture. captureData callback */
@property (nullable, nonatomic, weak) id<NXLiveSessionDelegate> delegate;

/** The runing control start capture or stop capture */
@property (nonatomic, assign) BOOL running;

/** The preview will show OpenGL ES view*/
@property (nonatomic, strong, null_resettable) UIView *preView;

/** The captureDevicePosition control cameraPosition, default front */
@property (nonatomic, assign) AVCaptureDevicePosition captureDevicePosition;

/** The  stream control upload and package */
@property (nullable, nonatomic, strong, readonly) NXLiveStreamInfo *streamInfo;

/** The status of the stream */
@property (nonatomic, assign, readonly) NXLiveState state;

/** The captureType control inner or outer audio and video */
@property (nonatomic, assign, readonly) NXLiveCaptureTypeMask captureType;

/** The showDebugInfo control streaminfo and uploadinfo(1s) */
@property (nonatomic, assign) BOOL showDebugInfo;

/** The reconnectInterval control reconnected timeinterval(重连间隔) */
@property (nonatomic, assign) NSUInteger reconnectInterval;

/** The reconnectCount control reconnect count(重连次数) */
@property (nonatomic, assign) NSUInteger reconnectCount;

/** The description for input audio, set when use pushAudio. include mSampleRate、mBitsPerChannel.
    Default 48KHZ sampleRate,  1 Channel*/
@property (nonatomic, assign) AudioStreamBasicDescription inputAudioASBD;

/** The frameRate for input video, set when use pushVideo. Default is 30*/
@property (nonatomic, assign) NSUInteger inputVideoFrameRate;

/** The adaptiveBitrate control auto adjust bitrate. Default is NO */
@property (nonatomic, assign) BOOL adaptiveBitRate;

/** The bitRate for the video stream.  bps*/
@property (nonatomic, assign) NSUInteger videoBitRate;

/** The max bitRate for adaptive biteRate. If set adaptiveBitRate true, must set videoMaxBitRate. bps*/
@property (nonatomic, assign) NSUInteger videoMaxBitRate;

/** The min bitRate for adaptive biteRate. If set adaptiveBitRate true, must set videoMinBitRate. bps*/
@property (nonatomic, assign) NSUInteger videoMinBitRate;

/** The level for audio denoise, 0~3. Default is 0.*/
@property (nonatomic, assign) int denoiseLevel;

- (nonnull instancetype)init UNAVAILABLE_ATTRIBUTE;
+ (nonnull instancetype)new UNAVAILABLE_ATTRIBUTE;

/** create live session with 720P video quality*/
- (nullable instancetype)initWithCaptureType:(NXLiveCaptureTypeMask)captureType;

/** create live with set videoQuality. Not greater than live room resolution. */
- (instancetype)initWithCaptureType:(NXLiveCaptureTypeMask)captureType
                       videoQuality:(NXLiveVideoQuality)quality;
/** start live */
- (void)startLiveWithRoomId:(NSString *)roomId;

/** stop live and could restart with origin roomId*/
- (void)suspendLive;

/** stop live，could't restart */
- (void)stopLive;

/** support outer input yuv or rgb video (set NXLiveCaptureTypeMask) */
- (void)pushVideo:(nullable CVPixelBufferRef)pixelBuffer;

/** support outer input pcm audio (set NXLiveCaptureTypeMask) */
- (void)pushAudio:(nullable NSData *)audioData;

/** The on-off of inputAudio.*/
- (void)turnOffAudio:(BOOL)isOff;

/** The on-off of inputVideo.*/
- (void)turnOffVideo:(BOOL)isOff;

@end

NS_ASSUME_NONNULL_END
