Commit d58064587d02f3bb11b2b355c41aee6fc9931a6c

Authored by 648540858
1 parent cebea64d

修复兼容接口

src/main/java/com/genersoft/iot/vmp/gb28181/transmit/response/impl/InviteResponseProcessor.java
... ... @@ -31,7 +31,7 @@ import com.genersoft.iot.vmp.gb28181.transmit.response.ISIPResponseProcessor;
31 31 @Component
32 32 public class InviteResponseProcessor implements ISIPResponseProcessor {
33 33  
34   - private final static Logger logger = LoggerFactory.getLogger(SIPProcessorFactory.class);
  34 + private final static Logger logger = LoggerFactory.getLogger(InviteResponseProcessor.class);
35 35  
36 36 /**
37 37 * 处理invite响应
... ...
src/main/java/com/genersoft/iot/vmp/storager/IVideoManagerStorager.java
... ... @@ -87,6 +87,7 @@ public interface IVideoManagerStorager {
87 87 * @return
88 88 */
89 89 public List<DeviceChannel> queryChannelsByDeviceId(String deviceId);
  90 +
90 91 /**
91 92 * 获取某个设备的通道
92 93 * @param deviceId 设备ID
... ...
src/main/java/com/genersoft/iot/vmp/web/ApiStreamController.java
... ... @@ -17,6 +17,7 @@ import org.springframework.beans.factory.annotation.Value;
17 17 import org.springframework.http.HttpStatus;
18 18 import org.springframework.http.ResponseEntity;
19 19 import org.springframework.web.bind.annotation.*;
  20 +import org.springframework.web.context.request.async.DeferredResult;
20 21  
21 22 /**
22 23 * 兼容LiveGBS的API:实时直播
... ... @@ -40,6 +41,10 @@ public class ApiStreamController {
40 41 @Autowired
41 42 private ZLMRESTfulUtils zlmresTfulUtils;
42 43  
  44 +
  45 + @Autowired
  46 + private PlayController playController;
  47 +
43 48 /**
44 49 * 实时直播 - 开始直播
45 50 * @param serial 设备编号
... ... @@ -54,124 +59,50 @@ public class ApiStreamController {
54 59 * @return
55 60 */
56 61 @RequestMapping(value = "/start")
57   - private JSONObject start(String serial ,
58   - @RequestParam(required = false)Integer channel ,
59   - @RequestParam(required = false)String code,
60   - @RequestParam(required = false)String cdn,
61   - @RequestParam(required = false)String audio,
62   - @RequestParam(required = false)String transport,
63   - @RequestParam(required = false)String checkchannelstatus ,
64   - @RequestParam(required = false)String transportmode,
65   - @RequestParam(required = false)String timeout
  62 + private DeferredResult<JSONObject> start(String serial ,
  63 + @RequestParam(required = false)Integer channel ,
  64 + @RequestParam(required = false)String code,
  65 + @RequestParam(required = false)String cdn,
  66 + @RequestParam(required = false)String audio,
  67 + @RequestParam(required = false)String transport,
  68 + @RequestParam(required = false)String checkchannelstatus ,
  69 + @RequestParam(required = false)String transportmode,
  70 + @RequestParam(required = false)String timeout
66 71  
67 72 ){
68   - int getEncoding = closeWaitRTPInfo? 1: 0;
  73 + DeferredResult<JSONObject> resultDeferredResult = new DeferredResult<JSONObject>();
69 74 Device device = storager.queryVideoDevice(serial);
70   -
71 75 if (device == null ) {
72 76 JSONObject result = new JSONObject();
73 77 result.put("error","device[ " + serial + " ]未找到");
74   - return result;
  78 + resultDeferredResult.setResult(result);
75 79 }else if (device.getOnline() == 0) {
76 80 JSONObject result = new JSONObject();
77 81 result.put("error","device[ " + code + " ]offline");
78   - return result;
  82 + resultDeferredResult.setResult(result);
79 83 }
  84 + resultDeferredResult.onTimeout(()->{
  85 + logger.info("播放等待超时");
  86 + JSONObject result = new JSONObject();
  87 + result.put("error","timeout");
  88 + resultDeferredResult.setResult(result);
  89 + });
80 90  
81 91 DeviceChannel deviceChannel = storager.queryChannel(serial, code);
82 92 if (deviceChannel == null) {
83 93 JSONObject result = new JSONObject();
84 94 result.put("error","channel[ " + code + " ]未找到");
85   - return result;
  95 + resultDeferredResult.setResult(result);
86 96 }else if (deviceChannel.getStatus() == 0) {
87 97 JSONObject result = new JSONObject();
88 98 result.put("error","channel[ " + code + " ]offline");
89   - return result;
  99 + resultDeferredResult.setResult(result);
90 100 }
  101 + DeferredResult<ResponseEntity<String>> play = playController.play(serial, code);
91 102  
92   - // 查询是否已经在播放
93   - StreamInfo streamInfo = storager.queryPlayByDevice(device.getDeviceId(), code);
94   - if (streamInfo == null) {
95   - logger.debug("streamInfo 等于null, 重新点播");
96   -// streamInfo = cmder.playStreamCmd(device, code);
97   - }else {
98   - logger.debug("streamInfo 不等于null, 向流媒体查询是否正在推流");
99   - String streamId = streamInfo.getStreamId();
100   - JSONObject rtpInfo = zlmresTfulUtils.getRtpInfo(streamId);
101   - if (rtpInfo.getBoolean("exist")) {
102   - logger.debug("向流媒体查询正在推流, 直接返回: " + streamInfo.getRtsp());
103   - JSONObject result = new JSONObject();
104   - result.put("StreamID", streamInfo.getStreamId());
105   - result.put("DeviceID", device.getDeviceId());
106   - result.put("ChannelID", code);
107   - result.put("ChannelName", deviceChannel.getName());
108   - result.put("ChannelCustomName", "");
109   - result.put("FLV", streamInfo.getFlv());
110   - result.put("WS_FLV", streamInfo.getWs_flv());
111   - result.put("RTMP", streamInfo.getRtmp());
112   - result.put("HLS", streamInfo.getHls());
113   - result.put("RTSP", streamInfo.getRtsp());
114   - result.put("CDN", "");
115   - result.put("SnapURL", "");
116   - result.put("Transport", device.getTransport());
117   - result.put("StartAt", "");
118   - result.put("Duration", "");
119   - result.put("SourceVideoCodecName", "");
120   - result.put("SourceVideoWidth", "");
121   - result.put("SourceVideoHeight", "");
122   - result.put("SourceVideoFrameRate", "");
123   - result.put("SourceAudioCodecName", "");
124   - result.put("SourceAudioSampleRate", "");
125   - result.put("AudioEnable", "");
126   - result.put("Ondemand", "");
127   - result.put("InBytes", "");
128   - result.put("InBitRate", "");
129   - result.put("OutBytes", "");
130   - result.put("NumOutputs", "");
131   - result.put("CascadeSize", "");
132   - result.put("RelaySize", "");
133   - result.put("ChannelPTZType", 0);
134   - return result;
135   - } else {
136   - logger.debug("向流媒体查询没有推流, 重新点播");
137   - storager.stopPlay(streamInfo);
138   -// streamInfo = cmder.playStreamCmd(device, code);
139   - }
140   - }
141   -
142   - if (logger.isDebugEnabled()) {
143   - logger.debug(String.format("设备预览 API调用,deviceId:%s ,channelId:%s",serial, code));
144   - logger.debug("设备预览 API调用,streamId:"+streamInfo.getStreamId());
145   - }
146   - boolean lockFlag = true;
147   - long startTime = System.currentTimeMillis();
148   - while (lockFlag) {
149   - try {
150   - if (System.currentTimeMillis() - startTime > 10 * 1000) {
151   - storager.stopPlay(streamInfo);
152   - logger.info("播放等待超时");
153   - JSONObject result = new JSONObject();
154   - result.put("error","timeout");
155   - return result;
156   - } else {
157   -
158   - StreamInfo streamInfoNow = storager.queryPlayByDevice(serial, code);
159   - logger.debug("正在向流媒体查询");
160   - if (streamInfoNow != null && streamInfoNow.getFlv() != null) {
161   - streamInfo = streamInfoNow;
162   - logger.debug("向流媒体查询到: " + streamInfoNow.getRtsp());
163   - lockFlag = false;
164   - continue;
165   - } else {
166   - Thread.sleep(2000);
167   - continue;
168   - }
169   - }
170   - } catch (InterruptedException e) {
171   - e.printStackTrace();
172   - }
173   - }
174   - if(streamInfo!=null) {
  103 + play.setResultHandler((Object o)->{
  104 + ResponseEntity<String> responseEntity = (ResponseEntity)o;
  105 + StreamInfo streamInfo = JSON.parseObject(responseEntity.getBody(), StreamInfo.class);
175 106 JSONObject result = new JSONObject();
176 107 result.put("StreamID", streamInfo.getStreamId());
177 108 result.put("DeviceID", device.getDeviceId());
... ... @@ -203,13 +134,9 @@ public class ApiStreamController {
203 134 result.put("CascadeSize", "");
204 135 result.put("RelaySize", "");
205 136 result.put("ChannelPTZType", 0);
206   - return result;
207   - } else {
208   - logger.warn("设备预览API调用失败!");
209   - JSONObject result = new JSONObject();
210   - result.put("error","调用失败");
211   - return result;
212   - }
  137 + resultDeferredResult.setResult(result);
  138 + });
  139 + return resultDeferredResult;
213 140 }
214 141  
215 142 /**
... ... @@ -228,6 +155,7 @@ public class ApiStreamController {
228 155 @RequestParam(required = false)String check_outputs
229 156  
230 157 ){
  158 +
231 159 StreamInfo streamInfo = storager.queryPlayByDevice(serial, code);
232 160 if (streamInfo == null) {
233 161 JSONObject result = new JSONObject();
... ...
src/main/resources/application-dev.yml
... ... @@ -69,11 +69,7 @@ media:
69 69 # [可选] zlm服务器的hook.admin_params=secret
70 70 secret: 035c73f7-bb6b-4889-a715-d9eb2d1925cc
71 71 # [可选] zlm服务器的general.streamNoneReaderDelayMS
72   - streamNoneReaderDelayMS: 600000 # 无人观看多久自动关闭流
73   - # [可选] 关闭等待收到流编码信息后在返回,
74   - # 设为false可以获得更好的兼容性,保证返回后流就可以播放,
75   - # 设为true可以快速打开播放窗口,可以获得更好的体验
76   - closeWaitRTPInfo: false
  72 + streamNoneReaderDelayMS: 600000 # 无人观看多久自动关闭流, -1表示永不自动关闭,即 关闭按需拉流
77 73 # [可选] 自动点播, 使用固定流地址进行播放时,如果未点播则自动进行点播
78 74 autoApplyPlay: true
79 75 # 启用udp多端口模式, 详细解释参考: https://github.com/xia-chu/ZLMediaKit/wiki/GB28181%E6%8E%A8%E6%B5%81 下的高阶使用
... ...