Commit 3c0dde2f3c6beb441184b033f1e3c6369100c0b5

Authored by 648540858
1 parent 83bdb911

修复兼容接口

src/main/java/com/genersoft/iot/vmp/gb28181/transmit/callback/DeferredResultHolder.java
... ... @@ -108,7 +108,7 @@ public class DeferredResultHolder {
108 108 if (result == null) {
109 109 return;
110 110 }
111   - result.setResult(new ResponseEntity<>(msg.getData(),HttpStatus.OK));
  111 + result.setResult(ResponseEntity.ok().body(msg.getData()));
112 112 }
113 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 304 @Override
305 305 public void sendStreamChangeMsg(JSONObject jsonObject) {
306 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 310 @Override
... ...
src/main/java/com/genersoft/iot/vmp/web/gb28181/ApiStreamController.java
1 1 package com.genersoft.iot.vmp.web.gb28181;
2 2  
3   -import com.alibaba.fastjson.JSON;
4 3 import com.alibaba.fastjson.JSONObject;
5 4 import com.genersoft.iot.vmp.common.StreamInfo;
  5 +import com.genersoft.iot.vmp.conf.UserSetup;
6 6 import com.genersoft.iot.vmp.gb28181.bean.Device;
7 7 import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
  8 +import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder;
8 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 12 import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
10 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 15 import org.slf4j.Logger;
13 16 import org.slf4j.LoggerFactory;
14 17 import org.springframework.beans.factory.annotation.Autowired;
15   -import org.springframework.http.ResponseEntity;
16 18 import org.springframework.web.bind.annotation.*;
17 19 import org.springframework.web.context.request.async.DeferredResult;
18 20  
... ... @@ -34,15 +36,13 @@ public class ApiStreamController {
34 36 private IVideoManagerStorager storager;
35 37  
36 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 44 @Autowired
45   - private PlayController playController;
  45 + private IPlayService playService;
46 46  
47 47 /**
48 48 * 实时直播 - 开始直播
... ... @@ -69,7 +69,7 @@ public class ApiStreamController {
69 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 73 Device device = storager.queryVideoDevice(serial);
74 74 if (device == null ) {
75 75 JSONObject result = new JSONObject();
... ... @@ -99,11 +99,9 @@ public class ApiStreamController {
99 99 result.put("error","channel[ " + code + " ]offline");
100 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 105 JSONObject result = new JSONObject();
108 106 result.put("StreamID", streamInfo.getStreamId());
109 107 result.put("DeviceID", device.getDeviceId());
... ... @@ -134,7 +132,23 @@ public class ApiStreamController {
134 132 result.put("NumOutputs", "");
135 133 result.put("CascadeSize", "");
136 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 152 resultDeferredResult.setResult(result);
139 153 });
140 154 return resultDeferredResult;
... ...