Commit 483d5e04a71b6632419699df1077ac5a5457ad38
1 parent
e8411bc7
优化拉流代理
Showing
4 changed files
with
36 additions
and
14 deletions
src/main/java/com/genersoft/iot/vmp/gb28181/event/subscribe/catalog/CatalogEventLister.java
| ... | ... | @@ -93,7 +93,7 @@ public class CatalogEventLister implements ApplicationListener<CatalogEvent> { |
| 93 | 93 | } |
| 94 | 94 | if (event.getGbStreams() != null && event.getGbStreams().size() > 0){ |
| 95 | 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 | 97 | continue; |
| 98 | 98 | } |
| 99 | 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 | 32 | } |
| 33 | 33 | |
| 34 | 34 | private OkHttpClient getClient(){ |
| 35 | + return getClient(null); | |
| 36 | + } | |
| 37 | + | |
| 38 | + private OkHttpClient getClient(Integer readTimeOut){ | |
| 35 | 39 | if (client == null) { |
| 40 | + if (readTimeOut == null) { | |
| 41 | + readTimeOut = 10; | |
| 42 | + } | |
| 36 | 43 | OkHttpClient.Builder httpClientBuilder = new OkHttpClient.Builder(); |
| 37 | 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 | 50 | httpClientBuilder.connectionPool(new ConnectionPool(16, 5, TimeUnit.MINUTES)); |
| 44 | 51 | if (logger.isDebugEnabled()) { |
| ... | ... | @@ -55,9 +62,13 @@ public class ZLMRESTfulUtils { |
| 55 | 62 | |
| 56 | 63 | } |
| 57 | 64 | |
| 58 | - | |
| 59 | 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 | 73 | if (mediaServerItem == null) { |
| 63 | 74 | return null; |
| ... | ... | @@ -310,7 +321,7 @@ public class ZLMRESTfulUtils { |
| 310 | 321 | param.put("enable_mp4", enable_mp4?1:0); |
| 311 | 322 | param.put("enable_audio", enable_audio?1:0); |
| 312 | 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 | 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 | 11 | import com.genersoft.iot.vmp.gb28181.event.subscribe.catalog.CatalogEvent; |
| 12 | 12 | import com.genersoft.iot.vmp.media.zlm.ZLMRESTfulUtils; |
| 13 | 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 | 16 | import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; |
| 15 | 17 | import com.genersoft.iot.vmp.media.zlm.dto.StreamProxyItem; |
| 16 | 18 | import com.genersoft.iot.vmp.media.zlm.dto.hook.OnStreamChangedHookParam; |
| ... | ... | @@ -160,15 +162,20 @@ public class StreamProxyServiceImpl implements IStreamProxyService { |
| 160 | 162 | callback.run(ErrorCode.ERROR100.getCode(), "保存失败", null); |
| 161 | 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 | 171 | if (param.isEnable()) { |
| 165 | 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 | 179 | String delayTalkKey = UUID.randomUUID().toString(); |
| 173 | 180 | dynamicTask.startDelay(delayTalkKey, ()->{ |
| 174 | 181 | StreamInfo streamInfo = mediaService.getStreamInfoByAppAndStreamWithCheck(param.getApp(), param.getStream(), mediaInfo.getId(), false); |
| ... | ... | @@ -178,9 +185,10 @@ public class StreamProxyServiceImpl implements IStreamProxyService { |
| 178 | 185 | dynamicTask.stop(talkKey); |
| 179 | 186 | callback.run(ErrorCode.ERROR100.getCode(), "超时", null); |
| 180 | 187 | } |
| 181 | - }, 5000); | |
| 188 | + }, 7000); | |
| 182 | 189 | JSONObject jsonObject = addStreamProxyToZlm(param); |
| 183 | 190 | if (jsonObject != null && jsonObject.getInteger("code") == 0) { |
| 191 | + hookSubscribe.removeSubscribe(hookSubscribeForStreamChange); | |
| 184 | 192 | dynamicTask.stop(talkKey); |
| 185 | 193 | StreamInfo streamInfo = mediaService.getStreamInfoByAppAndStream( |
| 186 | 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 | 80 | if (ObjectUtils.isEmpty(param.getType())) { |
| 81 | 81 | param.setType("default"); |
| 82 | 82 | } |
| 83 | + if (ObjectUtils.isEmpty(param.getRtpType())) { | |
| 84 | + param.setRtpType("1"); | |
| 85 | + } | |
| 83 | 86 | if (ObjectUtils.isEmpty(param.getGbId())) { |
| 84 | 87 | param.setGbId(null); |
| 85 | 88 | } | ... | ... |