CZT
2023-09-06 71c4fa1e27f75ae4b765c95c67a3069c84dc72ba
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package com.ld.igds.camera;
 
import com.ld.igds.sec.dto.SecCameraDto;
import org.apache.commons.lang3.StringUtils;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;
 
/**
 * @author: andy.jia
 * @description:
 * @version:
 * @data:2020年6月12日
 */
public class CameraUtil {
 
 
    /**
     * 流媒体中摄像头的在线状态,key = 流媒体通道ID value= ON/OFF
     */
    public static Map<String, String> contextCameraStatus = new HashMap<>();
 
    public static Map<String, Integer> contextOrderId = new HashMap<>();
 
 
    public static final String STATUS_ON = "ON";
 
    public static final String STATUS_OFF = "OFF";
 
 
    //播放方式
    public static final String PLAY_TYPE_DEFAULT = "DEFAULT";//默认其他
    public static final String PLAY_TYPE_VLC = "VLC"; //VLC播放方式
    public static final String PLAY_TYPE_FZZY_GB = "FZZY_GB"; //FZZY-GB服务器
    public static final String PLAY_TYPE_EASY_GBS = "EASY_GBS";//EASY-GBS服务器
    public static final String PLAY_TYPE_EASY_DSS = "EASY_DSS";//EASY-DSS服务器
    public static final String PLAY_TYPE_MEDIA_HIK = "MEDIA_HIK";//海康流媒体-综合安防管理平台
    public static final String PLAY_TYPE_MEDIA_HIK_INFOVISION_IOT_161 = "MEDIA_HIK_INFOVISION_IOT_161";//海康流媒体-智能应用平台V1.6.1
    public static final String PLAY_TYPE_HIK_YS = "HIK_YS";//海康-萤石云
    public static final String PLAY_TYPE_HIK_WEB4 = "HIK_WEB4";//海康-WEB4.0插件
    public static final String PLAY_TYPE_IMOU = "IMOU";//乐橙云
 
    //抓拍方式
    public static final String SNAP_TYPE_FZZY_PLUGIN = "FZZY-PLUGIN";//风正致远插件
    public static final String SNAP_TYPE_MEDIA = "MEDIA";//流媒体
 
 
    public static final String buildOrderId() {
        Integer start = contextOrderId.get("ORDER_ID") == null ? 1000 : contextOrderId.get("ORDER_ID");
        contextOrderId.put("ORDER_ID", start + 1);
        return start + "";
    }
 
 
    /**
     * {0} = 用户名
     * {1} = 密码
     * {2} = IP
     * {3} = PORT
     * {4} = 通道号
     *
     * @param dto
     * @param isEncode
     * @return
     */
    public static String updateMediaAddr2(SecCameraDto dto, boolean isEncode) {
 
        // 替换表达式中的值
        String mediaAddr = dto.getMediaAddr();
        if (StringUtils.isEmpty(mediaAddr)) return null;
        mediaAddr = mediaAddr.replace("{0}", dto.getLoginId());
        mediaAddr = mediaAddr.replace("{1}", dto.getPwd());
        mediaAddr = mediaAddr.replace("{2}", dto.getIpIn());
        mediaAddr = mediaAddr.replace("{3}", dto.getPortInC() + "");
        mediaAddr = mediaAddr.replace("{4}", dto.getChanNum() + "");
 
        if (isEncode) {
            try {
                mediaAddr = URLEncoder.encode(mediaAddr, "UTF-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
        }
        return mediaAddr;
    }
 
 
    /**
     * {0} = 用户名
     * {1} = 密码
     * {2} = IP
     * {3} = PORT 控制端口
     * {4} = 通道号
     *
     * @return
     */
    public static String updateMediaAddr(String mediaAddr, String loginId, String pwd, String ip, int portCtr, int chanNum) {
 
        // 替换表达式中的值
        if (StringUtils.isEmpty(mediaAddr)) return null;
 
        mediaAddr = mediaAddr.replace("{0}", null == loginId ? "" : loginId);
        mediaAddr = mediaAddr.replace("{1}", null == pwd ? "" : pwd);
        mediaAddr = mediaAddr.replace("{2}", null == ip ? "" : ip);
        mediaAddr = mediaAddr.replace("{3}", portCtr == 0 ? "" : portCtr + "");
        mediaAddr = mediaAddr.replace("{4}", chanNum == 0 ? "" : chanNum + "");
 
        return mediaAddr;
    }
 
    public static void updateMediaStatus(String sn, String status) {
        contextCameraStatus.put(sn, status);
    }
 
    public static String getCameraStatus(String sn) {
        return contextCameraStatus.get(sn);
    }
}