package com.sz.admin.monitor.utils;




import com.sz.admin.monitor.enums.DriverEnums;

import java.util.HashMap;
import java.util.Map;

public class RtspUtil {


    /**
     * 获取rtsp地址
     *
     * @param device        驱动类型 海康 大华
     * @param username      用户名
     * @param password      密码
     * @param ip            ip地址
     * @param channelNumber 通道号
     * @return rtsp地址
     */
    public static Map<String, String> getRtsp(Integer driver, String username, String password, String ip, int channelNumber) {
        Map<String, String> map = new HashMap<>();
        if (DriverEnums.HKSDK.ordinal() == driver) {
            String rtsp = "rtsp://#{username}:#{password}@#{ip}:554/ch#{channelNumber}/#{mode}/av_stream";
            rtsp = rtsp.replace("#{username}", username).replace("#{password}", password).replace("#{ip}", ip).replace("#{channelNumber}", String.valueOf(channelNumber));
            String mainRtsp = rtsp.replace("#{mode}", "main"); // 主码流
            String subRtsp = rtsp.replace("#{mode}", "sub");  // 子码流
            map.put("mainRtsp", mainRtsp);
            map.put("subRtsp", subRtsp);
            return map;
        }
        // 大华的rtsp流拼接
        else if (DriverEnums.DHSDK.ordinal() == driver) {
            String rtsp = "rtsp://#{username}:#{password}@#{ip}:554/cam/realmonitor?channel=#{channelNumber}&subtype" +
                    "=#{mode}";
            rtsp = rtsp.replace("#{username}", username).replace("#{password}", password).replace("#{ip}", ip).replace("#{channelNumber}", String.valueOf(channelNumber));
            String mainRtsp = rtsp.replace("#{mode}", "0"); // 主码流
            String subRtsp = rtsp.replace("#{mode}", "1"); // 子码流
            map.put("mainRtsp", mainRtsp);
            map.put("subRtsp", subRtsp);
            return map;
        }
        return null;
    }

    public static Map<String, String> getRtsp(Integer driver, String username, String password, Integer channelNumber, String ip, Integer port) {
        Map<String, String> urlMap = new HashMap<>();
        if (DriverEnums.HKSDK.ordinal() == driver) {
            String rtsp = "rtsp://#{username}:#{password}@#{ip}:#{port}/Streaming/Channels/#{videoType}#{mode}";
            rtsp = rtsp
                    .replace("#{username}", username)
                    .replace("#{password}", password)
                    .replace("#{ip}", ip)
                    .replace("#{port}",String.valueOf(port))
                    .replace("#{videoType}",String.valueOf(channelNumber));
            String mainRtsp = rtsp.replace("#{mode}", "01");
            String subRtsp = rtsp.replace("#{mode}", "02");
            urlMap.put("mainRtsp", mainRtsp);
            urlMap.put("subRtsp", subRtsp);
            return urlMap;
        } else if (DriverEnums.DHSDK.ordinal() == driver) {
            String rtsp = "rtsp://#{username}:#{password}@#{ip}:554/cam/realmonitor?channel=#{channelNumber}&subtype" +
                    "=#{mode}";
            rtsp = rtsp.replace("#{username}", username).replace("#{password}", password).replace("#{ip}", ip).replace("#{channelNumber}", String.valueOf(channelNumber));
            String mainRtsp = rtsp.replace("#{mode}", "0");
            String subRtsp = rtsp.replace("#{mode}", "1");
            urlMap.put("mainRtsp", mainRtsp);
            urlMap.put("subRtsp", subRtsp);
            return urlMap;
        }
        return null;
    }

//    public static void main(String[] args) {
//        Map<String, String> admin = getRtsp(0, "admin", "bdz13579.", 1, "192.168.1.11", 554);
//        System.out.println(admin);
//        Map<String, String> admin1 = getRtsp(0, "admin", "bdz13579.", 24, "192.168.2.221", 554);
//        System.out.println(admin1);
//    }
}
