Commit 3c0dde2f3c6beb441184b033f1e3c6369100c0b5
1 parent
83bdb911
修复兼容接口
Showing
3 changed files
with
32 additions
and
18 deletions
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/callback/DeferredResultHolder.java
| @@ -108,7 +108,7 @@ public class DeferredResultHolder { | @@ -108,7 +108,7 @@ public class DeferredResultHolder { | ||
| 108 | if (result == null) { | 108 | if (result == null) { |
| 109 | return; | 109 | return; |
| 110 | } | 110 | } |
| 111 | - result.setResult(new ResponseEntity<>(msg.getData(),HttpStatus.OK)); | 111 | + result.setResult(ResponseEntity.ok().body(msg.getData())); |
| 112 | } | 112 | } |
| 113 | map.remove(msg.getKey()); | 113 | map.remove(msg.getKey()); |
| 114 | 114 |
src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java
| @@ -304,7 +304,7 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage { | @@ -304,7 +304,7 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage { | ||
| 304 | @Override | 304 | @Override |
| 305 | public void sendStreamChangeMsg(JSONObject jsonObject) { | 305 | public void sendStreamChangeMsg(JSONObject jsonObject) { |
| 306 | String key = VideoManagerConstants.WVP_MSG_STREAM_PUSH_CHANGE_PREFIX; | 306 | String key = VideoManagerConstants.WVP_MSG_STREAM_PUSH_CHANGE_PREFIX; |
| 307 | - redis.convertAndSend(key, jsonObject.toJSONString()); | 307 | + redis.convertAndSend(key, jsonObject); |
| 308 | } | 308 | } |
| 309 | 309 | ||
| 310 | @Override | 310 | @Override |
src/main/java/com/genersoft/iot/vmp/web/gb28181/ApiStreamController.java
| 1 | package com.genersoft.iot.vmp.web.gb28181; | 1 | package com.genersoft.iot.vmp.web.gb28181; |
| 2 | 2 | ||
| 3 | -import com.alibaba.fastjson.JSON; | ||
| 4 | import com.alibaba.fastjson.JSONObject; | 3 | import com.alibaba.fastjson.JSONObject; |
| 5 | import com.genersoft.iot.vmp.common.StreamInfo; | 4 | import com.genersoft.iot.vmp.common.StreamInfo; |
| 5 | +import com.genersoft.iot.vmp.conf.UserSetup; | ||
| 6 | import com.genersoft.iot.vmp.gb28181.bean.Device; | 6 | import com.genersoft.iot.vmp.gb28181.bean.Device; |
| 7 | import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel; | 7 | import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel; |
| 8 | +import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder; | ||
| 8 | import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander; | 9 | import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander; |
| 10 | +import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; | ||
| 11 | +import com.genersoft.iot.vmp.service.IPlayService; | ||
| 9 | import com.genersoft.iot.vmp.storager.IRedisCatchStorage; | 12 | import com.genersoft.iot.vmp.storager.IRedisCatchStorage; |
| 10 | import com.genersoft.iot.vmp.storager.IVideoManagerStorager; | 13 | import com.genersoft.iot.vmp.storager.IVideoManagerStorager; |
| 11 | -import com.genersoft.iot.vmp.vmanager.gb28181.play.PlayController; | 14 | +import com.genersoft.iot.vmp.vmanager.gb28181.play.bean.PlayResult; |
| 12 | import org.slf4j.Logger; | 15 | import org.slf4j.Logger; |
| 13 | import org.slf4j.LoggerFactory; | 16 | import org.slf4j.LoggerFactory; |
| 14 | import org.springframework.beans.factory.annotation.Autowired; | 17 | import org.springframework.beans.factory.annotation.Autowired; |
| 15 | -import org.springframework.http.ResponseEntity; | ||
| 16 | import org.springframework.web.bind.annotation.*; | 18 | import org.springframework.web.bind.annotation.*; |
| 17 | import org.springframework.web.context.request.async.DeferredResult; | 19 | import org.springframework.web.context.request.async.DeferredResult; |
| 18 | 20 | ||
| @@ -34,15 +36,13 @@ public class ApiStreamController { | @@ -34,15 +36,13 @@ public class ApiStreamController { | ||
| 34 | private IVideoManagerStorager storager; | 36 | private IVideoManagerStorager storager; |
| 35 | 37 | ||
| 36 | @Autowired | 38 | @Autowired |
| 37 | - private IRedisCatchStorage redisCatchStorage; | ||
| 38 | - | ||
| 39 | - | ||
| 40 | - // @Autowired | ||
| 41 | - // private ZLMRESTfulUtils zlmresTfulUtils; | 39 | + private UserSetup userSetup; |
| 42 | 40 | ||
| 41 | + @Autowired | ||
| 42 | + private IRedisCatchStorage redisCatchStorage; | ||
| 43 | 43 | ||
| 44 | @Autowired | 44 | @Autowired |
| 45 | - private PlayController playController; | 45 | + private IPlayService playService; |
| 46 | 46 | ||
| 47 | /** | 47 | /** |
| 48 | * 实时直播 - 开始直播 | 48 | * 实时直播 - 开始直播 |
| @@ -69,7 +69,7 @@ public class ApiStreamController { | @@ -69,7 +69,7 @@ public class ApiStreamController { | ||
| 69 | @RequestParam(required = false)String timeout | 69 | @RequestParam(required = false)String timeout |
| 70 | 70 | ||
| 71 | ){ | 71 | ){ |
| 72 | - DeferredResult<JSONObject> resultDeferredResult = new DeferredResult<JSONObject>(); | 72 | + DeferredResult<JSONObject> resultDeferredResult = new DeferredResult<>(userSetup.getPlayTimeout() + 10); |
| 73 | Device device = storager.queryVideoDevice(serial); | 73 | Device device = storager.queryVideoDevice(serial); |
| 74 | if (device == null ) { | 74 | if (device == null ) { |
| 75 | JSONObject result = new JSONObject(); | 75 | JSONObject result = new JSONObject(); |
| @@ -99,11 +99,9 @@ public class ApiStreamController { | @@ -99,11 +99,9 @@ public class ApiStreamController { | ||
| 99 | result.put("error","channel[ " + code + " ]offline"); | 99 | result.put("error","channel[ " + code + " ]offline"); |
| 100 | resultDeferredResult.setResult(result); | 100 | resultDeferredResult.setResult(result); |
| 101 | } | 101 | } |
| 102 | - DeferredResult<ResponseEntity<String>> play = playController.play(serial, code); | ||
| 103 | - | ||
| 104 | - play.setResultHandler((Object o)->{ | ||
| 105 | - ResponseEntity<String> responseEntity = (ResponseEntity)o; | ||
| 106 | - StreamInfo streamInfo = JSON.parseObject(responseEntity.getBody(), StreamInfo.class); | 102 | + MediaServerItem newMediaServerItem = playService.getNewMediaServerItem(device); |
| 103 | + PlayResult play = playService.play(newMediaServerItem, serial, code, (mediaServerItem, response)->{ | ||
| 104 | + StreamInfo streamInfo = redisCatchStorage.queryPlayByDevice(serial, code); | ||
| 107 | JSONObject result = new JSONObject(); | 105 | JSONObject result = new JSONObject(); |
| 108 | result.put("StreamID", streamInfo.getStreamId()); | 106 | result.put("StreamID", streamInfo.getStreamId()); |
| 109 | result.put("DeviceID", device.getDeviceId()); | 107 | result.put("DeviceID", device.getDeviceId()); |
| @@ -134,7 +132,23 @@ public class ApiStreamController { | @@ -134,7 +132,23 @@ public class ApiStreamController { | ||
| 134 | result.put("NumOutputs", ""); | 132 | result.put("NumOutputs", ""); |
| 135 | result.put("CascadeSize", ""); | 133 | result.put("CascadeSize", ""); |
| 136 | result.put("RelaySize", ""); | 134 | result.put("RelaySize", ""); |
| 137 | - result.put("ChannelPTZType", 0); | 135 | + result.put("ChannelPTZType", "0"); |
| 136 | + resultDeferredResult.setResult(result); | ||
| 137 | +// Class<?> aClass = responseEntity.getClass().getSuperclass(); | ||
| 138 | +// Field body = null; | ||
| 139 | +// try { | ||
| 140 | +// // 使用反射动态修改返回的body | ||
| 141 | +// body = aClass.getDeclaredField("body"); | ||
| 142 | +// body.setAccessible(true); | ||
| 143 | +// body.set(responseEntity, result); | ||
| 144 | +// } catch (NoSuchFieldException e) { | ||
| 145 | +// e.printStackTrace(); | ||
| 146 | +// } catch (IllegalAccessException e) { | ||
| 147 | +// e.printStackTrace(); | ||
| 148 | +// } | ||
| 149 | + }, (eventResult) -> { | ||
| 150 | + JSONObject result = new JSONObject(); | ||
| 151 | + result.put("error", "channel[ " + code + " ] " + eventResult.msg); | ||
| 138 | resultDeferredResult.setResult(result); | 152 | resultDeferredResult.setResult(result); |
| 139 | }); | 153 | }); |
| 140 | return resultDeferredResult; | 154 | return resultDeferredResult; |