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

#import <Foundation/Foundation.h>
#import <AVFoundation/AVFoundation.h>
#import <NXSdwan/NXSdwan.h>
#import "NXAudioFilter.h"
#import "NXAudioFilterRnnoise.h"
#import "NXAudioFilterSpeexNoise.h"
#import "NXAudioFilterSpeexAEC.h"
#import "NXAudioFilterAEC3.h"
#import "NXAudioFilterRecorder.h"
#import "NXAudioFilterSimpleGain.h"

NS_ASSUME_NONNULL_BEGIN

@protocol NXAudioEngineDelegate <NSObject>

- (void)onAudioVolume:(int)volume from:(int64_t)from;
- (void)onAudioVolumeOfSelf:(int)volume;
- (void)onAudioRecorderData:(NSData *)data;

@end

@interface NXAudioEngine : NSObject<NXTransportSessionAudioDelegate>

//@property (nonatomic)  int  sampleRate;
@property (nonatomic, weak) id<NXAudioEngineDelegate>     delegate;
@property (nonatomic, strong, nullable) NXTransportSession *transportSession; //后改为strong，因为会引起crash
@property (nonatomic, strong)         NSOrderedSet        *activeParticipants;
@property (nonatomic)                 NXCallMediaType     mediaType;
@property (nonatomic)                 NXCallMode          mode;
@property (nonatomic, strong, nullable) NSSet             *audioAcceptList;

@property (nonatomic, getter = isAlterAECEnabled) BOOL alterAECEnabled;

+ (instancetype)sharedInstance;
- (void)PrepareAudioSession;
- (void)Start;
- (void)Stop;
- (int16_t)getCurrentPlayingSeqidOf:(int64_t)from;
- (void)setVideoDelayExtra:(int)extra forFrom:(int64_t) from;
- (int16_t)getCurrentRecordingSeqid;

- (int) getAudioSampleRate;
- (void) setAudioSampleRate:(int)sampleRate;
- (int) getAudioQuality;
- (void) setAudioQuality:(int)quality;
- (BOOL) isSpeakerOn;
- (void) setSpeaker:(BOOL)on;
- (void) setMute:(BOOL)on;
- (BOOL) isMuted;
- (void) setMuteMixer:(BOOL)on;
- (BOOL) isMixerMuted;
- (void) setAudioPreferredMode:(NXCallAudioPreferredMode) preferredMode;
- (NXCallAudioPreferredMode) getAudioPreferredMode;
- (int) getAudioFrameMs;
- (int) getAudioFrameMsOf:(int64_t)from;
- (void) setDenoiseLevel:(int)level;
- (int) getDenoiseLevel;
//- (int) getVoiceRatio;
//- (BOOL) isMusic;
- (int) getMaxMixNum;
- (void) setMaxMixNum:(int)mixNum;
-(void)setInputGainDB:(int)gainDB;
-(int)getInputGainDB;

//- (void)mixExternalAudio:(nonnull NSData *)data;
//- (void)setExternalAudioFormat:(AudioStreamBasicDescription)audioFormat;
//- (void)setExternalAudioVolume:(float)volume;

//external audio的接口改成如下
- (int)createExternalAudioTrack:(AudioStreamBasicDescription)audioFormat;
- (int)destroyExternalAudioTrack:(int)trackId;
- (int)mixExternalAudio:(nonnull NSData *)data trackId:(int)trackId;
- (int)setExternalAudioVolume:(float)volume trackId:(int)trackId;

- (void)setAudioRecorderEnabled:(BOOL)enabled;

- (int)getJitterBuffersAverageLossRateIns; //这个给计算网络质量时做参考

@end

NS_ASSUME_NONNULL_END


/*
 AVAudioSession的使用
 https://www.jianshu.com/p/fb0e5fb71b3c
 https://www.jianshu.com/p/446792276d9d  有车载蓝牙部分
 https://blog.csdn.net/chenyong05314/article/details/81746885
 https://blog.csdn.net/u010795305/article/details/50979099   有蓝牙方面内容
 */
