Commit bac9aca311dba1b8796c6166d6618462fc7aa3a5

Authored by 648540858
1 parent 13811b0c

合并分支新内容

src/main/java/com/genersoft/iot/vmp/web/gb28181/ApiStreamController.java
1 1 package com.genersoft.iot.vmp.web.gb28181;
2 2  
3 3 import com.alibaba.fastjson2.JSONObject;
4   -import com.genersoft.iot.vmp.common.StreamInfo;
  4 +import com.genersoft.iot.vmp.common.InviteInfo;
  5 +import com.genersoft.iot.vmp.common.InviteSessionType;
5 6 import com.genersoft.iot.vmp.conf.UserSetting;
6 7 import com.genersoft.iot.vmp.conf.exception.SsrcTransactionNotFoundException;
7 8 import com.genersoft.iot.vmp.gb28181.bean.Device;
... ... @@ -9,13 +10,18 @@ import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
9 10 import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander;
10 11 import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
11 12 import com.genersoft.iot.vmp.service.IDeviceService;
  13 +import com.genersoft.iot.vmp.service.IInviteStreamService;
12 14 import com.genersoft.iot.vmp.service.IPlayService;
  15 +import com.genersoft.iot.vmp.service.bean.InviteErrorCode;
13 16 import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
14 17 import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
15 18 import org.slf4j.Logger;
16 19 import org.slf4j.LoggerFactory;
17 20 import org.springframework.beans.factory.annotation.Autowired;
18   -import org.springframework.web.bind.annotation.*;
  21 +import org.springframework.web.bind.annotation.RequestMapping;
  22 +import org.springframework.web.bind.annotation.RequestParam;
  23 +import org.springframework.web.bind.annotation.ResponseBody;
  24 +import org.springframework.web.bind.annotation.RestController;
19 25 import org.springframework.web.context.request.async.DeferredResult;
20 26  
21 27 import javax.sip.InvalidArgumentException;
... ... @@ -51,6 +57,9 @@ public class ApiStreamController {
51 57 @Autowired
52 58 private IPlayService playService;
53 59  
  60 + @Autowired
  61 + private IInviteStreamService inviteStreamService;
  62 +
54 63 /**
55 64 * 实时直播 - 开始直播
56 65 * @param serial 设备编号
... ... @@ -83,7 +92,7 @@ public class ApiStreamController {
83 92 result.put("error","device[ " + serial + " ]未找到");
84 93 resultDeferredResult.setResult(result);
85 94 return resultDeferredResult;
86   - }else if (device.getOnline() == 0) {
  95 + }else if (device.isOnLine()) {
87 96 JSONObject result = new JSONObject();
88 97 result.put("error","device[ " + code + " ]offline");
89 98 resultDeferredResult.setResult(result);
... ... @@ -104,59 +113,66 @@ public class ApiStreamController {
104 113 result.put("error","channel[ " + code + " ]未找到");
105 114 resultDeferredResult.setResult(result);
106 115 return resultDeferredResult;
107   - }else if (deviceChannel.getStatus() == 0) {
  116 + }else if (!deviceChannel.isStatus()) {
108 117 JSONObject result = new JSONObject();
109 118 result.put("error","channel[ " + code + " ]offline");
110 119 resultDeferredResult.setResult(result);
111 120 return resultDeferredResult;
112 121 }
113 122 MediaServerItem newMediaServerItem = playService.getNewMediaServerItem(device);
114   - playService.play(newMediaServerItem, serial, code, (mediaServerItem, response)->{
115   - StreamInfo streamInfo = redisCatchStorage.queryPlayByDevice(serial, code);
116   - JSONObject result = new JSONObject();
117   - result.put("StreamID", streamInfo.getStream());
118   - result.put("DeviceID", device.getDeviceId());
119   - result.put("ChannelID", code);
120   - result.put("ChannelName", deviceChannel.getName());
121   - result.put("ChannelCustomName", "");
122   - result.put("FLV", streamInfo.getFlv().getUrl());
123   - result.put("HTTPS_FLV", streamInfo.getHttps_flv().getUrl());
124   - result.put("WS_FLV", streamInfo.getWs_flv().getUrl());
125   - result.put("WSS_FLV", streamInfo.getWss_flv().getUrl());
126   - result.put("RTMP", streamInfo.getRtmp().getUrl());
127   - result.put("RTMPS", streamInfo.getRtmps().getUrl());
128   - result.put("HLS", streamInfo.getHls().getUrl());
129   - result.put("HTTPS_HLS", streamInfo.getHttps_hls().getUrl());
130   - result.put("RTSP", streamInfo.getRtsp().getUrl());
131   - result.put("RTSPS", streamInfo.getRtsps().getUrl());
132   - result.put("WEBRTC", streamInfo.getRtc().getUrl());
133   - result.put("HTTPS_WEBRTC", streamInfo.getRtcs().getUrl());
134   - result.put("CDN", "");
135   - result.put("SnapURL", "");
136   - result.put("Transport", device.getTransport());
137   - result.put("StartAt", "");
138   - result.put("Duration", "");
139   - result.put("SourceVideoCodecName", "");
140   - result.put("SourceVideoWidth", "");
141   - result.put("SourceVideoHeight", "");
142   - result.put("SourceVideoFrameRate", "");
143   - result.put("SourceAudioCodecName", "");
144   - result.put("SourceAudioSampleRate", "");
145   - result.put("AudioEnable", "");
146   - result.put("Ondemand", "");
147   - result.put("InBytes", "");
148   - result.put("InBitRate", "");
149   - result.put("OutBytes", "");
150   - result.put("NumOutputs", "");
151   - result.put("CascadeSize", "");
152   - result.put("RelaySize", "");
153   - result.put("ChannelPTZType", "0");
154   - resultDeferredResult.setResult(result);
155   - }, (eventResult) -> {
156   - JSONObject result = new JSONObject();
157   - result.put("error", "channel[ " + code + " ] " + eventResult.msg);
158   - resultDeferredResult.setResult(result);
159   - }, null);
  123 +
  124 +
  125 + playService.play(newMediaServerItem, serial, code, null, (errorCode, msg, data) -> {
  126 + if (errorCode == InviteErrorCode.SUCCESS.getCode()) {
  127 + InviteInfo inviteInfo = inviteStreamService.getInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, serial, code);
  128 + if (inviteInfo != null && inviteInfo.getStreamInfo() != null) {
  129 + JSONObject result = new JSONObject();
  130 + result.put("StreamID", inviteInfo.getStreamInfo().getStream());
  131 + result.put("DeviceID", device.getDeviceId());
  132 + result.put("ChannelID", code);
  133 + result.put("ChannelName", deviceChannel.getName());
  134 + result.put("ChannelCustomName", "");
  135 + result.put("FLV", inviteInfo.getStreamInfo().getFlv().getUrl());
  136 + result.put("HTTPS_FLV", inviteInfo.getStreamInfo().getHttps_flv().getUrl());
  137 + result.put("WS_FLV", inviteInfo.getStreamInfo().getWs_flv().getUrl());
  138 + result.put("WSS_FLV", inviteInfo.getStreamInfo().getWss_flv().getUrl());
  139 + result.put("RTMP", inviteInfo.getStreamInfo().getRtmp().getUrl());
  140 + result.put("RTMPS", inviteInfo.getStreamInfo().getRtmps().getUrl());
  141 + result.put("HLS", inviteInfo.getStreamInfo().getHls().getUrl());
  142 + result.put("HTTPS_HLS", inviteInfo.getStreamInfo().getHttps_hls().getUrl());
  143 + result.put("RTSP", inviteInfo.getStreamInfo().getRtsp().getUrl());
  144 + result.put("RTSPS", inviteInfo.getStreamInfo().getRtsps().getUrl());
  145 + result.put("WEBRTC", inviteInfo.getStreamInfo().getRtc().getUrl());
  146 + result.put("HTTPS_WEBRTC", inviteInfo.getStreamInfo().getRtcs().getUrl());
  147 + result.put("CDN", "");
  148 + result.put("SnapURL", "");
  149 + result.put("Transport", device.getTransport());
  150 + result.put("StartAt", "");
  151 + result.put("Duration", "");
  152 + result.put("SourceVideoCodecName", "");
  153 + result.put("SourceVideoWidth", "");
  154 + result.put("SourceVideoHeight", "");
  155 + result.put("SourceVideoFrameRate", "");
  156 + result.put("SourceAudioCodecName", "");
  157 + result.put("SourceAudioSampleRate", "");
  158 + result.put("AudioEnable", "");
  159 + result.put("Ondemand", "");
  160 + result.put("InBytes", "");
  161 + result.put("InBitRate", "");
  162 + result.put("OutBytes", "");
  163 + result.put("NumOutputs", "");
  164 + result.put("CascadeSize", "");
  165 + result.put("RelaySize", "");
  166 + result.put("ChannelPTZType", "0");
  167 + resultDeferredResult.setResult(result);
  168 + }
  169 + }else {
  170 + JSONObject result = new JSONObject();
  171 + result.put("error", "channel[ " + code + " ] " + msg);
  172 + resultDeferredResult.setResult(result);
  173 + }
  174 + });
  175 +
160 176 return resultDeferredResult;
161 177 }
162 178  
... ... @@ -177,8 +193,8 @@ public class ApiStreamController {
177 193  
178 194 ){
179 195  
180   - StreamInfo streamInfo = redisCatchStorage.queryPlayByDevice(serial, code);
181   - if (streamInfo == null) {
  196 + InviteInfo inviteInfo = inviteStreamService.getInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, serial, code);
  197 + if (inviteInfo == null) {
182 198 JSONObject result = new JSONObject();
183 199 result.put("error","未找到流信息");
184 200 return result;
... ... @@ -190,14 +206,14 @@ public class ApiStreamController {
190 206 return result;
191 207 }
192 208 try {
193   - cmder.streamByeCmd(device, code, streamInfo.getStream(), null);
  209 + cmder.streamByeCmd(device, code, inviteInfo.getStream(), null);
194 210 } catch (InvalidArgumentException | ParseException | SipException | SsrcTransactionNotFoundException e) {
195 211 JSONObject result = new JSONObject();
196 212 result.put("error","发送BYE失败:" + e.getMessage());
197 213 return result;
198 214 }
199   - redisCatchStorage.stopPlay(streamInfo);
200   - storager.stopPlay(streamInfo.getDeviceID(), streamInfo.getChannelId());
  215 + inviteStreamService.removeInviteInfo(inviteInfo);
  216 + storager.stopPlay(inviteInfo.getDeviceId(), inviteInfo.getChannelId());
201 217 return null;
202 218 }
203 219  
... ...