Commit b95fe5fb79dd79622454f366ff0f63b30c36607e

Authored by liujun001
1 parent e1f3d030

添加配置 用于调度系统

src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java
... ... @@ -49,10 +49,7 @@ import javax.servlet.http.HttpServletRequest;
49 49 import javax.sip.InvalidArgumentException;
50 50 import javax.sip.SipException;
51 51 import java.text.ParseException;
52   -import java.util.HashMap;
53   -import java.util.List;
54   -import java.util.Map;
55   -import java.util.UUID;
  52 +import java.util.*;
56 53  
57 54 /**
58 55 * @description:针对 ZLMediaServer的hook事件监听
... ... @@ -567,6 +564,8 @@ public class ZLMHttpHookListener {
567 564 String stream = param.getStream();
568 565 Object port = redisTemplate.opsForValue().get("tag:history:port:" + stream);
569 566 Object httpPort = redisTemplate.opsForValue().get("tag:history:httpPort:" + stream);
  567 + Object time = redisTemplate.opsForValue().get("tag:history:httpPort:time:" + stream);
  568 +
570 569 if (ObjectUtils.isEmpty(port)) {
571 570 port = -1;
572 571 }
... ... @@ -575,11 +574,14 @@ public class ZLMHttpHookListener {
575 574 httpPort = -1;
576 575 }
577 576  
578   - Map<String, Object> resl = jt1078OfCarController.sendIORequestStop(StringUtils.substringBefore(stream, "-"), StringUtils.substringAfter(stream, "-"), stream, (Integer) port, (Integer) httpPort);
579   - if (!StringUtils.equals(String.valueOf(resl.get("code")), "1")) {
580   - logger.info("停流失败,稍后再试:{},{},{}", stream, port, httpPort);
581   - return ret;
  577 + if (Objects.isNull(time) || Objects.equals(0L, time)) {
  578 + Map<String, Object> resl = jt1078OfCarController.sendIORequestStop(StringUtils.substringBefore(stream, "-"), StringUtils.substringAfter(stream, "-"), stream, (Integer) port, (Integer) httpPort);
  579 + if (!StringUtils.equals(String.valueOf(resl.get("code")), "1")) {
  580 + logger.info("停流失败,稍后再试:{},{},{}", stream, port, httpPort);
  581 + return ret;
  582 + }
582 583 }
  584 +
583 585 // 国标流, 点播/录像回放/录像下载
584 586 InviteInfo inviteInfo = inviteStreamService.getInviteInfoByStream(null, param.getStream());
585 587 // 点播
... ...
src/main/java/com/genersoft/iot/vmp/vmanager/jt1078/platform/Jt1078OfCarController.java
... ... @@ -5,6 +5,7 @@ import com.alibaba.fastjson2.JSONException;
5 5 import com.genersoft.iot.vmp.conf.MediaConfig;
6 6 import com.genersoft.iot.vmp.conf.UserSetting;
7 7 import com.genersoft.iot.vmp.conf.security.SecurityUtils;
  8 +import com.genersoft.iot.vmp.media.zlm.dto.StreamProxyItem;
8 9 import com.genersoft.iot.vmp.media.zlm.dto.StreamPushItem;
9 10 import com.genersoft.iot.vmp.service.IStreamPushService;
10 11 import com.genersoft.iot.vmp.vmanager.bean.StreamContent;
... ... @@ -15,6 +16,7 @@ import com.genersoft.iot.vmp.vmanager.jt1078.platform.config.RtspConfigBean;
15 16 import com.genersoft.iot.vmp.vmanager.jt1078.platform.config.TuohuaConfigBean;
16 17 import com.genersoft.iot.vmp.vmanager.jt1078.platform.handler.HttpClientUtil;
17 18  
  19 +import com.genersoft.iot.vmp.vmanager.streamProxy.StreamProxyController;
18 20 import com.genersoft.iot.vmp.vmanager.streamPush.StreamPushController;
19 21 import com.sun.jna.platform.win32.Rasapi32Util;
20 22 import com.xiaoleilu.hutool.crypto.SecureUtil;
... ... @@ -71,6 +73,8 @@ public class Jt1078OfCarController {
71 73 private MediaConfig mediaConfig;
72 74 @Autowired
73 75 private StreamPushController streamPushController;
  76 + @Autowired
  77 + private StreamProxyController streamProxyController;
74 78  
75 79 @Autowired
76 80 private IStreamPushService streamPushService;
... ... @@ -189,17 +193,19 @@ public class Jt1078OfCarController {
189 193 resultMap.put("httpPort", entity.getHttpPort());
190 194 resultMap.put("stream", stream);
191 195  
192   - redisTemplate.opsForValue().set("tag:history:port:"+stream, entity.getPort(), 2, TimeUnit.DAYS);
193   - redisTemplate.opsForValue().set("tag:history:httpPort:"+stream, entity.getHttpPort(), 2, TimeUnit.DAYS);
  196 + redisTemplate.opsForValue().set("tag:history:port:" + stream, entity.getPort(), 2, TimeUnit.DAYS);
  197 + redisTemplate.opsForValue().set("tag:history:httpPort:" + stream, entity.getHttpPort(), 2, TimeUnit.DAYS);
  198 + redisTemplate.opsForValue().set("tag:history:httpPort:time:" + stream, new Date().getTime(), 1800, TimeUnit.SECONDS);
194 199  
195   - msg = jt1078ConfigBean.formatMessageId(sim, channel, rtspConfigBean, entity.getPort() + 30000);
  200 + msg = jt1078ConfigBean.formatMessageId(sim, channel, rtspConfigBean, entity.getPort());
196 201  
197 202 entity = httpClientUtil.doPost(url, msg, null);
198   - Map<String, Object> resultMap1 = chooseEntity(entity);
199   - if (Objects.nonNull(resultMap1)) {
200   - return resultMap1;
201   - }
  203 +// Map<String, Object> resultMap1 = chooseEntity(entity);
  204 +// if (Objects.nonNull(resultMap1)) {
  205 +// return resultMap1;
  206 +// }
202 207 log.info(entity.getResultStr());
  208 + createStreamProxy(sim + "-" + channel);
203 209  
204 210 streamContent = getStreamContent(stream);
205 211 }
... ... @@ -241,6 +247,8 @@ public class Jt1078OfCarController {
241 247  
242 248 String url = jt1078ConfigBean.formatStopPushURL(stream, port, httpPort);
243 249 try {
  250 + streamProxyController.del(stream,stream);
  251 +
244 252 httpClientUtil.doGet(url, null);
245 253  
246 254 url = StringUtils.replace(jt1078ConfigBean.getJt1078Url(), "{0}", jt1078ConfigBean.getStopSendPort());
... ... @@ -267,7 +275,6 @@ public class Jt1078OfCarController {
267 275 resultMap.put("code", "1");
268 276 resultMap.put("message", "OK");
269 277  
270   -
271 278 return resultMap;
272 279 } catch (URISyntaxException | IOException e) {
273 280 log.error("发送停止推流指令异常;[{}],[{}]", url, msg, e);
... ... @@ -325,7 +332,7 @@ public class Jt1078OfCarController {
325 332 return resultMap;
326 333 }
327 334  
328   - Map<String, Object> resultMap1 = chooseEntity(entity);
  335 + Map<String, Object> resultMap1 = chooseEntity(entity,url);
329 336 if (Objects.nonNull(resultMap1)) {
330 337 return resultMap1;
331 338 }
... ... @@ -402,7 +409,7 @@ public class Jt1078OfCarController {
402 409 return resultMap;
403 410 }
404 411  
405   - Map<String, Object> resultMap1 = chooseEntity(entity);
  412 + Map<String, Object> resultMap1 = chooseEntity(entity,url);
406 413 if (Objects.nonNull(resultMap1)) {
407 414 return resultMap1;
408 415 }
... ... @@ -411,10 +418,11 @@ public class Jt1078OfCarController {
411 418 resultMap.put("port", entity.getPort());
412 419 resultMap.put("httpPort", entity.getHttpPort());
413 420  
414   - redisTemplate.opsForValue().set("tag:history:port:"+channelMapping, entity.getPort(), 2, TimeUnit.DAYS);
415   - redisTemplate.opsForValue().set("tag:history:httpPort:"+channelMapping, entity.getHttpPort(), 2, TimeUnit.DAYS);
  421 + redisTemplate.opsForValue().set("tag:history:port:" + channelMapping, entity.getPort(), 2, TimeUnit.DAYS);
  422 + redisTemplate.opsForValue().set("tag:history:httpPort:" + channelMapping, entity.getHttpPort(), 2, TimeUnit.DAYS);
  423 + redisTemplate.opsForValue().set("tag:history:httpPort:time:" + channelMapping, new Date().getTime(), 1800, TimeUnit.SECONDS);
416 424  
417   - msg = jt1078ConfigBean.formatMessageHistoryPlayRTSP(sim, channel, startTime, endTime, rtspConfigBean, entity.getPort() + 30000);
  425 + msg = jt1078ConfigBean.formatMessageHistoryPlayRTSP(sim, channel, startTime, endTime, rtspConfigBean, entity.getPort());
418 426 boolean flag = false;
419 427  
420 428 key = key + "-lock";
... ... @@ -439,7 +447,7 @@ public class Jt1078OfCarController {
439 447 return resultMap;
440 448 }
441 449 log.info(entity.getResultStr());
442   -
  450 + createStreamProxy(channelMapping);
443 451  
444 452 resultMap.put("code", "1");
445 453 resultMap.put("message", "OK");
... ... @@ -635,23 +643,56 @@ public class Jt1078OfCarController {
635 643 return httpClientPostEntity;
636 644 }
637 645  
638   - private Map<String, Object> chooseEntity(HttpClientPostEntity entity) {
  646 + private Map<String, Object> chooseEntity(HttpClientPostEntity entity,String url) {
639 647 Map<String, Object> result = new HashMap<>();
640 648 if (Objects.isNull(entity)) {
641 649 result.put("code", "301");
642 650 result.put("msg", "下发指令异常");
643 651 return result;
644 652 }
645   - Map<String,String> rsultMap = JSON.parseObject(entity.getResultStr(),HashMap.class);
646   - if(Objects.equals(rsultMap.get("code"),"4000") || Objects.equals(rsultMap.get("code"),4000)){
647   - result.put("code", "304");
648   - result.put("msg", "离线的客户端(请检查设备是否注册或者鉴权");
649   - return result;
  653 + try {
  654 + Map<String, Object> rsultMap = JSON.parseObject(entity.getResultStr(), HashMap.class);
  655 + if (Objects.equals(rsultMap.get("code"), "4000") || Objects.equals(rsultMap.get("code"), 4000)) {
  656 + result.put("code", "304");
  657 + result.put("msg", "离线的客户端(请检查设备是否注册或者鉴权");
  658 + return result;
  659 + }
  660 +
  661 + if (Objects.nonNull(rsultMap.get("success")) && StringUtils.equalsAnyIgnoreCase(String.valueOf(rsultMap.get("success")), "true")) {
  662 + return null;
  663 + } else if (StringUtils.isNoneBlank(rsultMap.get("msg") + "")) {
  664 + result.put("code", "304");
  665 + result.put("msg", rsultMap.get("msg"));
  666 + return result;
  667 + }
  668 + }catch (Exception e){
  669 + log.error("entity.getResultStr():{{}}",entity.getResultStr(),e);
650 670 }
651 671  
652 672 return null;
653 673  
654 674 }
655 675  
  676 + private void createStreamProxy(String stream) {
  677 + String url = StringUtils.replace(jt1078ConfigBean.getGetURL(), "{stream}", stream);
  678 + StreamProxyItem item = new StreamProxyItem();
  679 + item.setApp("schedule");
  680 + item.setEnable(true);
  681 + item.setEnableAudio(true);
  682 + item.setRtpType("default");
  683 + item.setStream(stream);
  684 + item.setMediaServerId(mediaConfig.getId());
  685 + item.setUrl(url);
  686 + item.setFfmpegCmdKey("ffmpeg.cmd");
  687 + item.setEnable(true);
  688 + item.setEnableAudio(true);
  689 + item.setEnableMp4(false);
  690 + item.setEnableRemoveNoneReader(false);
  691 + item.setEnableDisableNoneReader(false);
  692 +
  693 + streamProxyController.save(item);
  694 +
  695 + }
  696 +
656 697  
657 698 }
... ...
src/main/java/com/genersoft/iot/vmp/vmanager/jt1078/platform/config/Jt1078ConfigBean.java
... ... @@ -33,6 +33,8 @@ public class Jt1078ConfigBean {
33 33  
34 34 private Integer start1078Port;
35 35 private Integer end1078Port;
  36 + @Value("${tuohua.bsth.jt1078.get.url}")
  37 + private String getURL;
36 38  
37 39  
38 40 private static final String SEND_IO_MESSAGE_RTSP = "{ \"messageId\": 37121, \"properties\": 0, \"clientId\": \"{clientId}\", \"serialNo\": \"1\", \"ip\": \"{ip}\", \"tcpPort\": \"{tcpPort}\", \"udpPort\": \"{udpPort}\", \"channelNo\": \"{channelNo}\", \"mediaType\": \"1\", \"streamType\": \"1\"}";
... ... @@ -124,4 +126,8 @@ public class Jt1078ConfigBean {
124 126 public String getStopPUshURL() {
125 127 return stopPUshURL;
126 128 }
  129 +
  130 + public String getGetURL() {
  131 + return getURL;
  132 + }
127 133 }
... ...
src/main/java/com/genersoft/iot/vmp/vmanager/jt1078/platform/config/TuohuaConfigBean.java
... ... @@ -84,7 +84,7 @@ public class TuohuaConfigBean {
84 84  
85 85  
86 86 private final String LINE_URL = "/line/company/{companyId}?timestamp={timestamp}&nonce={nonce}&password={password}&sign={sign}";
87   -//private final String LINE_URL = "/line/all?timestamp={timestamp}&nonce={nonce}&password={password}&sign={sign}";
  87 + //private final String LINE_URL = "/line/all?timestamp={timestamp}&nonce={nonce}&password={password}&sign={sign}";
88 88 private final String CAR_URL = "/car/company/{companyId}?timestamp={timestamp}&nonce={nonce}&password={password}&sign={sign}";
89 89  
90 90 public String requestLine(HttpClientUtil httpClientUtil, String companyId) throws Exception {
... ... @@ -142,7 +142,7 @@ public class TuohuaConfigBean {
142 142 String code = convertStr(hashMap.get("lineCode"));
143 143 HashMap<String, Object> map = combationTree(code, convertStr(hashMap.get("line")), code, false, convertStr(hashMap.get("name")), code, false,
144 144 "<span><img src='/metronic_v4.5.4/layui/icon/line.png' class ='imageIcon' /></span><span>" + convertStr(hashMap.get("name")) + "</span>",
145   - "<span><img src='/metronic_v4.5.4/layui/icon/line.png' class ='imageIcon' /></span><span>" + convertStr(hashMap.get("name")) + "</span>",201);
  145 + "<span><img src='/metronic_v4.5.4/layui/icon/line.png' class ='imageIcon' /></span><span>" + convertStr(hashMap.get("name")) + "</span>", 201);
146 146 if (carsSize > 0) {
147 147 List<HashMap> carList = carJsonListFinal.stream().filter(c -> Objects.nonNull(c.get("lineCode")) && StringUtils.equals(convertStr(c.get("lineCode")), code)).map(ch -> {
148 148 ch.put("used", "1");
... ... @@ -196,7 +196,7 @@ public class TuohuaConfigBean {
196 196 }
197 197  
198 198 public HashMap<String, Object> combationTree(String code, String icon, String id, boolean initChild, String name, String sourceId,
199   - boolean spread, String text, String title,Integer type) {
  199 + boolean spread, String text, String title, Integer type) {
200 200 HashMap<String, Object> result = new HashMap<>();
201 201 result.put("code", code);
202 202 result.put("icon", icon);
... ... @@ -207,16 +207,16 @@ public class TuohuaConfigBean {
207 207 result.put("spread", spread);
208 208 result.put("text", text);
209 209 result.put("title", title);
210   - result.put("type",type);
  210 + result.put("type", type);
211 211 return result;
212 212 }
213 213  
214 214 private HashMap<String, Object> combatioinCarTree(HashMap ch) {
215 215 String code = convertStr(ch.get("nbbm"));
216 216 HashMap<String, Object> hashMap = combationTree(code, "bus1", code, false, code, code, false, "<span><img src='/metronic_v4.5.4/layui/icon/bus1.png' class ='imageIcon' /></span><span>" + code + "</span>",
217   - "<span><img src='/metronic_v4.5.4/layui/icon/bus1.png' class ='imageIcon' /></span><span>" + code + "</span>",301);
218   - hashMap.put("sim",convertStr(ch.get("sim")));
219   -// hashMap.put("sim","122223333444");
  217 + "<span><img src='/metronic_v4.5.4/layui/icon/bus1.png' class ='imageIcon' /></span><span>" + code + "</span>", 301);
  218 + hashMap.put("sim", formatSim(convertStr(ch.get("sim"))));
  219 +// hashMap.put("sim","013800138999");
220 220 return hashMap;
221 221 }
222 222  
... ... @@ -243,5 +243,33 @@ public class TuohuaConfigBean {
243 243 return Objects.isNull(object) ? "" : object.toString();
244 244 }
245 245  
  246 + private String formatSim(String sim) {
  247 + if (StringUtils.isBlank(sim)) {
  248 + return sim;
  249 + }
  250 +
  251 + char[] chars = sim.toCharArray();
  252 + int length = chars.length;
  253 + StringBuilder builder = new StringBuilder();
  254 + boolean flag = true;
  255 + for (int i = 0; i < length; i++) {
  256 + char val = chars[i];
  257 + if (flag && val == '0') {
  258 + continue;
  259 + }
  260 + flag = false;
  261 + builder.append(chars[i]);
  262 + }
  263 + return builder.toString();
  264 + }
  265 +
  266 + public static void main(String[] args) {
  267 +
  268 + TuohuaConfigBean bean = new TuohuaConfigBean();
  269 + String str = "0000156012345000";
  270 +
  271 + System.out.println(bean.formatSim(str));
  272 + }
  273 +
246 274  
247 275 }
... ...
src/main/java/com/genersoft/iot/vmp/vmanager/jt1078/platform/handler/HttpClientUtil.java
1 1 package com.genersoft.iot.vmp.vmanager.jt1078.platform.handler;
2 2  
  3 +import com.alibaba.fastjson2.JSON;
3 4 import com.genersoft.iot.vmp.vmanager.jt1078.platform.ben.HttpClientPostEntity;
4 5 import org.apache.commons.collections4.CollectionUtils;
5 6 import org.apache.http.HttpEntity;
... ... @@ -61,7 +62,7 @@ public class HttpClientUtil {
61 62 response = httpclient.execute(httpPost);
62 63 // 判断返回状态是否为200
63 64 if (response.getStatusLine().getStatusCode() == 200) {
64   - return combationReturnObj(response, httpclient);
  65 + return combationReturnObj(response, httpclient,url, null);
65 66 }
66 67 } finally {
67 68 if (response != null) {
... ... @@ -96,7 +97,7 @@ public class HttpClientUtil {
96 97 response = httpclient.execute(httpPost);
97 98 // 判断返回状态是否为200
98 99 if (response.getStatusLine().getStatusCode() == 200) {
99   - return combationReturnObj(response, httpclient);
  100 + return combationReturnObj(response, httpclient,url,requestBody);
100 101 }
101 102 } catch (Exception e) {
102 103 log.error("请求数据异常", e);
... ... @@ -148,7 +149,7 @@ public class HttpClientUtil {
148 149 response = httpclient.execute(httpGet);
149 150 // 判断返回状态是否为200
150 151 if (response.getStatusLine().getStatusCode() == 200) {
151   - return combationReturnObj(response, httpclient);
  152 + return combationReturnObj(response, httpclient,url,null);
152 153 }
153 154 } finally {
154 155 if (response != null) {
... ... @@ -161,7 +162,7 @@ public class HttpClientUtil {
161 162  
162 163  
163 164 @NotNull
164   - private static HttpClientPostEntity combationReturnObj(CloseableHttpResponse response, DefaultHttpClient httpclient) throws IOException {
  165 + private static HttpClientPostEntity combationReturnObj(CloseableHttpResponse response, DefaultHttpClient httpclient,String url,String requestBody) throws IOException {
165 166 HttpEntity httpEntity = response.getEntity();
166 167  
167 168 CookieStore cookieStore = httpclient.getCookieStore();
... ... @@ -170,7 +171,7 @@ public class HttpClientUtil {
170 171 HttpClientPostEntity postEntity = new HttpClientPostEntity();
171 172 postEntity.setCookieStore(cookieStore);
172 173 postEntity.setResultStr(result);
173   - log.info("response data:{}",result);
  174 + log.info("url:{};requestBody:{};response data:{}",url,requestBody,result);
174 175 return postEntity;
175 176 }
176 177 }
... ...
src/main/resources/application-local.yml
... ... @@ -92,7 +92,7 @@ media:
92 92 # [可选] zlm服务器的http.sslport, 置空使用zlm配置文件配置
93 93 http-ssl-port: 443
94 94 # [可选] zlm服务器的hook.admin_params=secret
95   - secret: RPorcBlIw26uHGnEHYGesIYyFDXpgjkP
  95 + secret: RPorcBlIw26uHGnEHYGesIYyFDXpgjkP1
96 96 # 启用多端口模式, 多端口模式使用端口区分每路流,兼容性更好。 单端口使用流的ssrc区分, 点播超时建议使用多端口测试
97 97 rtp:
98 98 # [可选] 是否启用多端口模式, 开启后会在portRange范围内选择端口用于媒体流传输
... ... @@ -159,6 +159,8 @@ tuohua:
159 159 playHistoryPort: 9201
160 160 sendPort: 9101
161 161 stopSendPort: 9102
  162 + get:
  163 + url: http://192.169.1.92:3333/video/{stream}.flv
162 164 playURL: /play/wasm/ws%3A%2F%2F{ip}%3A{port}%2Fschedule%2F{sim}-{channel}.live.flv%3FcallId%{publickey}
163 165  
164 166  
... ...
src/main/resources/application-localDev.yml
... ... @@ -157,6 +157,8 @@ tuohua:
157 157 playHistoryPort: 9201
158 158 sendPort: 9101
159 159 stopSendPort: 9102
  160 + get:
  161 + url: http://192.169.1.92:3333/video/{stream}.flv
160 162 playURL: /play/wasm/ws%3A%2F%2F{ip}%3A{port}%2Fschedule%2F{sim}-{channel}.live.flv%3FcallId%{publickey}
161 163  
162 164  
... ...
src/main/resources/application.yml
... ... @@ -2,6 +2,6 @@ spring:
2 2 application:
3 3 name: wvp
4 4 profiles:
5   - active: localDev
  5 + active: local
6 6 server:
7 7 port: 18080
8 8 \ No newline at end of file
... ...