//
//  EZConfGlobalConfig.m
//  ERTCDemo
//
//  Created by Harper Kan on 2021/11/2.
//

#import "EZConfGlobalConfig.h"


ERTCVideoEncParam *g_videoEncParam;
ERTCVideoFillMode g_fillMode;

@implementation EZConfGlobalConfig

+ (instancetype)sharedInstance {
    static EZConfGlobalConfig *_sharedInstance = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _sharedInstance = [EZConfGlobalConfig new];
        _sharedInstance.qualityInterval = 2;
        _sharedInstance.hardDecodePriority = false;
        _sharedInstance.isEZRTC = YES;
        _sharedInstance.bigVideoEncParam = [ERTCVideoEncParam new];
        _sharedInstance.smallVideoEncParam = [_sharedInstance smallParamFromBigRes:_sharedInstance.bigVideoEncParam.videoResolution];
    });
    
    return _sharedInstance;
}

+(void)load {
    g_videoEncParam = [ERTCVideoEncParam new];
    g_fillMode = ERTCVideoFillMode_AspectFill;
}



+ (NSString *)desForRes:(ERTCVideoResolution)res
{
    NSString *des = @"未知";
    switch (res) {
        case ERTCVideoResolution_120_120:
            des = @"120*120";
            break;
        case ERTCVideoResolution_160_160:
            des = @"160*160";
            break;
        case ERTCVideoResolution_270_270:
            des = @"270*270";
            break;
        case ERTCVideoResolution_480_480:
            des = @"480*480";
            break;
        case ERTCVideoResolution_160_120:
            des = @"160*120";
            break;
        case ERTCVideoResolution_240_180:
            des = @"240*180";
            break;
        case ERTCVideoResolution_280_210:
            des = @"280*210";
            break;
        case ERTCVideoResolution_320_240:
            des = @"320*240";
            break;
        case ERTCVideoResolution_400_300:
            des = @"400*300";
            break;
        case ERTCVideoResolution_480_360:
            des = @"480*360";
            break;
        case ERTCVideoResolution_640_480:
            des = @"640*480";
            break;
        case ERTCVideoResolution_960_720:
            des = @"960*720";
            break;
        case ERTCVideoResolution_160_90:
            des = @"160*90";
            break;
        case ERTCVideoResolution_256_144:
            des = @"256*144";
            break;
        case ERTCVideoResolution_320_180:
            des = @"320*180";
            break;
        case ERTCVideoResolution_480_270:
            des = @"480*270";
            break;
        case ERTCVideoResolution_640_360:
            des = @"640*360";
            break;
        case ERTCVideoResolution_960_540:
            des = @"960*540";
            break;
        case ERTCVideoResolution_1280_720:
            des = @"1280*720";
            break;
        case ERTCVideoResolution_1920_1080:
            des = @"1920*1080";
            break;
        default:
            break;
    }
    return des;
}

- (ERTCVideoEncParam *)smallParamFromBigRes:(ERTCVideoResolution)bigVideoResolution {
    ERTCVideoEncParam *smallParam = [ERTCVideoEncParam new];
    smallParam.videoFps = 10;
    switch (bigVideoResolution) {
        //宽高比 1:1
        case ERTCVideoResolution_120_120:
        case ERTCVideoResolution_160_160:
        case ERTCVideoResolution_270_270:
        case ERTCVideoResolution_480_480:
        {
            smallParam.videoResolution = ERTCVideoResolution_120_120;
            break;
        }
        //宽高比 4:3
        case ERTCVideoResolution_160_120:
        case ERTCVideoResolution_240_180:
        case ERTCVideoResolution_280_210:
        case ERTCVideoResolution_320_240:
        case ERTCVideoResolution_400_300:
        case ERTCVideoResolution_480_360:
        case ERTCVideoResolution_640_480:
        case ERTCVideoResolution_960_720:
        {
            smallParam.videoResolution = ERTCVideoResolution_160_120;
            break;
        }
        //宽高比 16:9
        case ERTCVideoResolution_160_90:
        case ERTCVideoResolution_256_144:
        case ERTCVideoResolution_320_180:
        case ERTCVideoResolution_480_270:
        case ERTCVideoResolution_640_360:
        case ERTCVideoResolution_960_540:
        case ERTCVideoResolution_1280_720:
        case ERTCVideoResolution_1920_1080:
        default:
        {
            smallParam.videoResolution = ERTCVideoResolution_160_90;
            break;
        }
    }
    smallParam.videoBitrate = [ERTCVideoEncParam recommendedBitrateForRes:smallParam.videoResolution];
    return smallParam;
}


@end
