Commit 483d5e04a71b6632419699df1077ac5a5457ad38

Authored by 648540858
1 parent e8411bc7

优化拉流代理

src/main/java/com/genersoft/iot/vmp/gb28181/event/subscribe/catalog/CatalogEventLister.java
@@ -93,7 +93,7 @@ public class CatalogEventLister implements ApplicationListener<CatalogEvent> { @@ -93,7 +93,7 @@ public class CatalogEventLister implements ApplicationListener<CatalogEvent> {
93 } 93 }
94 if (event.getGbStreams() != null && event.getGbStreams().size() > 0){ 94 if (event.getGbStreams() != null && event.getGbStreams().size() > 0){
95 for (GbStream gbStream : event.getGbStreams()) { 95 for (GbStream gbStream : event.getGbStreams()) {
96 - if (gbStream.getStreamType().equals("push") && !userSetting.isUsePushingAsStatus()) { 96 + if (gbStream != null && gbStream.getStreamType().equals("push") && !userSetting.isUsePushingAsStatus()) {
97 continue; 97 continue;
98 } 98 }
99 DeviceChannel deviceChannelByStream = gbStreamService.getDeviceChannelListByStream(gbStream, gbStream.getCatalogId(), parentPlatform); 99 DeviceChannel deviceChannelByStream = gbStreamService.getDeviceChannelListByStream(gbStream, gbStream.getCatalogId(), parentPlatform);
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRESTfulUtils.java
@@ -32,13 +32,20 @@ public class ZLMRESTfulUtils { @@ -32,13 +32,20 @@ public class ZLMRESTfulUtils {
32 } 32 }
33 33
34 private OkHttpClient getClient(){ 34 private OkHttpClient getClient(){
  35 + return getClient(null);
  36 + }
  37 +
  38 + private OkHttpClient getClient(Integer readTimeOut){
35 if (client == null) { 39 if (client == null) {
  40 + if (readTimeOut == null) {
  41 + readTimeOut = 10;
  42 + }
36 OkHttpClient.Builder httpClientBuilder = new OkHttpClient.Builder(); 43 OkHttpClient.Builder httpClientBuilder = new OkHttpClient.Builder();
37 //todo 暂时写死超时时间 均为5s 44 //todo 暂时写死超时时间 均为5s
38 // 设置连接超时时间 45 // 设置连接超时时间
39 - httpClientBuilder.connectTimeout(5,TimeUnit.SECONDS); 46 + httpClientBuilder.connectTimeout(8,TimeUnit.SECONDS);
40 // 设置读取超时时间 47 // 设置读取超时时间
41 - httpClientBuilder.readTimeout(10,TimeUnit.SECONDS); 48 + httpClientBuilder.readTimeout(readTimeOut,TimeUnit.SECONDS);
42 // 设置连接池 49 // 设置连接池
43 httpClientBuilder.connectionPool(new ConnectionPool(16, 5, TimeUnit.MINUTES)); 50 httpClientBuilder.connectionPool(new ConnectionPool(16, 5, TimeUnit.MINUTES));
44 if (logger.isDebugEnabled()) { 51 if (logger.isDebugEnabled()) {
@@ -55,9 +62,13 @@ public class ZLMRESTfulUtils { @@ -55,9 +62,13 @@ public class ZLMRESTfulUtils {
55 62
56 } 63 }
57 64
58 -  
59 public JSONObject sendPost(MediaServerItem mediaServerItem, String api, Map<String, Object> param, RequestCallback callback) { 65 public JSONObject sendPost(MediaServerItem mediaServerItem, String api, Map<String, Object> param, RequestCallback callback) {
60 - OkHttpClient client = getClient(); 66 + return sendPost(mediaServerItem, api, param, callback, null);
  67 + }
  68 +
  69 +
  70 + public JSONObject sendPost(MediaServerItem mediaServerItem, String api, Map<String, Object> param, RequestCallback callback, Integer readTimeOut) {
  71 + OkHttpClient client = getClient(readTimeOut);
61 72
62 if (mediaServerItem == null) { 73 if (mediaServerItem == null) {
63 return null; 74 return null;
@@ -310,7 +321,7 @@ public class ZLMRESTfulUtils { @@ -310,7 +321,7 @@ public class ZLMRESTfulUtils {
310 param.put("enable_mp4", enable_mp4?1:0); 321 param.put("enable_mp4", enable_mp4?1:0);
311 param.put("enable_audio", enable_audio?1:0); 322 param.put("enable_audio", enable_audio?1:0);
312 param.put("rtp_type", rtp_type); 323 param.put("rtp_type", rtp_type);
313 - return sendPost(mediaServerItem, "addStreamProxy",param, null); 324 + return sendPost(mediaServerItem, "addStreamProxy",param, null, 20);
314 } 325 }
315 326
316 public JSONObject closeStreams(MediaServerItem mediaServerItem, String app, String stream) { 327 public JSONObject closeStreams(MediaServerItem mediaServerItem, String app, String stream) {
src/main/java/com/genersoft/iot/vmp/service/impl/StreamProxyServiceImpl.java
@@ -11,6 +11,8 @@ import com.genersoft.iot.vmp.gb28181.event.EventPublisher; @@ -11,6 +11,8 @@ import com.genersoft.iot.vmp.gb28181.event.EventPublisher;
11 import com.genersoft.iot.vmp.gb28181.event.subscribe.catalog.CatalogEvent; 11 import com.genersoft.iot.vmp.gb28181.event.subscribe.catalog.CatalogEvent;
12 import com.genersoft.iot.vmp.media.zlm.ZLMRESTfulUtils; 12 import com.genersoft.iot.vmp.media.zlm.ZLMRESTfulUtils;
13 import com.genersoft.iot.vmp.media.zlm.ZlmHttpHookSubscribe; 13 import com.genersoft.iot.vmp.media.zlm.ZlmHttpHookSubscribe;
  14 +import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeFactory;
  15 +import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeForStreamChange;
14 import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; 16 import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
15 import com.genersoft.iot.vmp.media.zlm.dto.StreamProxyItem; 17 import com.genersoft.iot.vmp.media.zlm.dto.StreamProxyItem;
16 import com.genersoft.iot.vmp.media.zlm.dto.hook.OnStreamChangedHookParam; 18 import com.genersoft.iot.vmp.media.zlm.dto.hook.OnStreamChangedHookParam;
@@ -160,15 +162,20 @@ public class StreamProxyServiceImpl implements IStreamProxyService { @@ -160,15 +162,20 @@ public class StreamProxyServiceImpl implements IStreamProxyService {
160 callback.run(ErrorCode.ERROR100.getCode(), "保存失败", null); 162 callback.run(ErrorCode.ERROR100.getCode(), "保存失败", null);
161 return; 163 return;
162 } 164 }
163 - 165 + HookSubscribeForStreamChange hookSubscribeForStreamChange = HookSubscribeFactory.on_stream_changed(param.getApp(), param.getStream(), true, "rtsp", mediaInfo.getId());
  166 + hookSubscribe.addSubscribe(hookSubscribeForStreamChange, (mediaServerItem, response) -> {
  167 + StreamInfo streamInfo = mediaService.getStreamInfoByAppAndStream(
  168 + mediaInfo, param.getApp(), param.getStream(), null, null);
  169 + callback.run(ErrorCode.SUCCESS.getCode(), ErrorCode.SUCCESS.getMsg(), streamInfo);
  170 + });
164 if (param.isEnable()) { 171 if (param.isEnable()) {
165 String talkKey = UUID.randomUUID().toString(); 172 String talkKey = UUID.randomUUID().toString();
166 - dynamicTask.startCron(talkKey, ()->{  
167 - StreamInfo streamInfo = mediaService.getStreamInfoByAppAndStreamWithCheck(param.getApp(), param.getStream(), mediaInfo.getId(), false);  
168 - if (streamInfo != null) {  
169 - callback.run(ErrorCode.SUCCESS.getCode(), ErrorCode.SUCCESS.getMsg(), streamInfo);  
170 - }  
171 - }, 1000); 173 +// dynamicTask.startCron(talkKey, ()->{
  174 +// StreamInfo streamInfo = mediaService.getStreamInfoByAppAndStreamWithCheck(param.getApp(), param.getStream(), mediaInfo.getId(), false);
  175 +// if (streamInfo != null) {
  176 +// callback.run(ErrorCode.SUCCESS.getCode(), ErrorCode.SUCCESS.getMsg(), streamInfo);
  177 +// }
  178 +// }, 3000);
172 String delayTalkKey = UUID.randomUUID().toString(); 179 String delayTalkKey = UUID.randomUUID().toString();
173 dynamicTask.startDelay(delayTalkKey, ()->{ 180 dynamicTask.startDelay(delayTalkKey, ()->{
174 StreamInfo streamInfo = mediaService.getStreamInfoByAppAndStreamWithCheck(param.getApp(), param.getStream(), mediaInfo.getId(), false); 181 StreamInfo streamInfo = mediaService.getStreamInfoByAppAndStreamWithCheck(param.getApp(), param.getStream(), mediaInfo.getId(), false);
@@ -178,9 +185,10 @@ public class StreamProxyServiceImpl implements IStreamProxyService { @@ -178,9 +185,10 @@ public class StreamProxyServiceImpl implements IStreamProxyService {
178 dynamicTask.stop(talkKey); 185 dynamicTask.stop(talkKey);
179 callback.run(ErrorCode.ERROR100.getCode(), "超时", null); 186 callback.run(ErrorCode.ERROR100.getCode(), "超时", null);
180 } 187 }
181 - }, 5000); 188 + }, 7000);
182 JSONObject jsonObject = addStreamProxyToZlm(param); 189 JSONObject jsonObject = addStreamProxyToZlm(param);
183 if (jsonObject != null && jsonObject.getInteger("code") == 0) { 190 if (jsonObject != null && jsonObject.getInteger("code") == 0) {
  191 + hookSubscribe.removeSubscribe(hookSubscribeForStreamChange);
184 dynamicTask.stop(talkKey); 192 dynamicTask.stop(talkKey);
185 StreamInfo streamInfo = mediaService.getStreamInfoByAppAndStream( 193 StreamInfo streamInfo = mediaService.getStreamInfoByAppAndStream(
186 mediaInfo, param.getApp(), param.getStream(), null, null); 194 mediaInfo, param.getApp(), param.getStream(), null, null);
src/main/java/com/genersoft/iot/vmp/vmanager/streamProxy/StreamProxyController.java
@@ -80,6 +80,9 @@ public class StreamProxyController { @@ -80,6 +80,9 @@ public class StreamProxyController {
80 if (ObjectUtils.isEmpty(param.getType())) { 80 if (ObjectUtils.isEmpty(param.getType())) {
81 param.setType("default"); 81 param.setType("default");
82 } 82 }
  83 + if (ObjectUtils.isEmpty(param.getRtpType())) {
  84 + param.setRtpType("1");
  85 + }
83 if (ObjectUtils.isEmpty(param.getGbId())) { 86 if (ObjectUtils.isEmpty(param.getGbId())) {
84 param.setGbId(null); 87 param.setGbId(null);
85 } 88 }