Commit 1342aad0327a800d474b42b40a8c056de8d411ce

Authored by panlinlin
1 parent 224e9043

修复检测字段是否存在带来的停止按钮无法点击

修改错别字
src/main/java/com/genersoft/iot/vmp/common/StreamInfo.java
... ... @@ -6,7 +6,7 @@ public class StreamInfo {
6 6  
7 7 private String streamId;
8 8 private String deviceID;
9   - private String cahnnelId;
  9 + private String channelId;
10 10 private String flv;
11 11 private String ws_flv;
12 12 private String fmp4;
... ... @@ -27,12 +27,12 @@ public class StreamInfo {
27 27 this.deviceID = deviceID;
28 28 }
29 29  
30   - public String getCahnnelId() {
31   - return cahnnelId;
  30 + public String getChannelId() {
  31 + return channelId;
32 32 }
33 33  
34   - public void setCahnnelId(String cahnnelId) {
35   - this.cahnnelId = cahnnelId;
  34 + public void setChannelId(String channelId) {
  35 + this.channelId = channelId;
36 36 }
37 37  
38 38 public String getFlv() {
... ...
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java
... ... @@ -323,30 +323,61 @@ public class SIPCommander implements ISIPCommander {
323 323 content.append("s=Play\r\n");
324 324 content.append("c=IN IP4 "+mediaInfo.getWanIp()+"\r\n");
325 325 content.append("t=0 0\r\n");
326   - if("TCP-PASSIVE".equals(streamMode)) {
327   - content.append("m=video "+ mediaPort +" TCP/RTP/AVP 126 125 99 34 98 97 96\r\n");
328   - }else if ("TCP-ACTIVE".equals(streamMode)) {
329   - content.append("m=video "+ mediaPort +" TCP/RTP/AVP 126 125 99 34 98 97 96\r\n");
330   - }else if("UDP".equals(streamMode)) {
331   - content.append("m=video "+ mediaPort +" RTP/AVP 126 125 99 34 98 97 96\r\n");
332   - }
333   - content.append("a=recvonly\r\n");
334   - content.append("a=fmtp:126 profile-level-id=42e01e\r\n");
335   - content.append("a=rtpmap:126 H264/90000\r\n");
336   - content.append("a=rtpmap:125 H264S/90000\r\n");
337   - content.append("a=fmtp:125 profile-level-id=42e01e\r\n");
338   - content.append("a=rtpmap:99 MP4V-ES/90000\r\n");
339   - content.append("a=fmtp:99 profile-level-id=3\r\n");
340   - content.append("a=rtpmap:98 H264/90000\r\n");
341   - content.append("a=rtpmap:97 MPEG4/90000\r\n");
342   - content.append("a=rtpmap:96 PS/90000\r\n");
343   - if("TCP-PASSIVE".equals(streamMode)){ // tcp被动模式
344   - content.append("a=setup:passive\r\n");
345   - content.append("a=connection:new\r\n");
346   - }else if ("TCP-ACTIVE".equals(streamMode)) { // tcp主动模式
347   - content.append("a=setup:active\r\n");
348   - content.append("a=connection:new\r\n");
  326 +
  327 + if (seniorSdp) {
  328 + if("TCP-PASSIVE".equals(streamMode)) {
  329 + content.append("m=video "+ mediaPort +" TCP/RTP/AVP 126 125 99 34 98 97 96\r\n");
  330 + }else if ("TCP-ACTIVE".equals(streamMode)) {
  331 + content.append("m=video "+ mediaPort +" TCP/RTP/AVP 126 125 99 34 98 97 96\r\n");
  332 + }else if("UDP".equals(streamMode)) {
  333 + content.append("m=video "+ mediaPort +" RTP/AVP 126 125 99 34 98 97 96\r\n");
  334 + }
  335 + content.append("a=recvonly\r\n");
  336 + content.append("a=fmtp:126 profile-level-id=42e01e\r\n");
  337 + content.append("a=rtpmap:126 H264/90000\r\n");
  338 + content.append("a=rtpmap:125 H264S/90000\r\n");
  339 + content.append("a=fmtp:125 profile-level-id=42e01e\r\n");
  340 + content.append("a=rtpmap:99 MP4V-ES/90000\r\n");
  341 + content.append("a=fmtp:99 profile-level-id=3\r\n");
  342 + content.append("a=rtpmap:98 H264/90000\r\n");
  343 + content.append("a=rtpmap:97 MPEG4/90000\r\n");
  344 + content.append("a=rtpmap:96 PS/90000\r\n");
  345 + if("TCP-PASSIVE".equals(streamMode)){ // tcp被动模式
  346 + content.append("a=setup:passive\r\n");
  347 + content.append("a=connection:new\r\n");
  348 + }else if ("TCP-ACTIVE".equals(streamMode)) { // tcp主动模式
  349 + content.append("a=setup:active\r\n");
  350 + content.append("a=connection:new\r\n");
  351 + }
  352 + }else {
  353 + if("TCP-PASSIVE".equals(streamMode)) {
  354 + content.append("m=video "+ mediaPort +" TCP/RTP/AVP 96 98 97\r\n");
  355 + }else if ("TCP-ACTIVE".equals(streamMode)) {
  356 + content.append("m=video "+ mediaPort +" TCP/RTP/AVP 96 98 97\r\n");
  357 + }else if("UDP".equals(streamMode)) {
  358 + content.append("m=video "+ mediaPort +" RTP/AVP 96 98 97\r\n");
  359 + }
  360 + content.append("a=recvonly\r\n");
  361 + content.append("a=rtpmap:96 PS/90000\r\n");
  362 + content.append("a=rtpmap:98 H264/90000\r\n");
  363 + content.append("a=rtpmap:97 MPEG4/90000\r\n");
  364 + if("TCP-PASSIVE".equals(streamMode)) { // tcp被动模式
  365 + content.append("a=setup:passive\r\n");
  366 + content.append("a=recvonly\r\n");
  367 + content.append("a=rtpmap:96 PS/90000\r\n");
  368 + content.append("a=rtpmap:98 H264/90000\r\n");
  369 + content.append("a=rtpmap:97 MPEG4/90000\r\n");
  370 + if ("TCP-PASSIVE".equals(streamMode)) { // tcp被动模式
  371 + content.append("a=setup:passive\r\n");
  372 + content.append("a=connection:new\r\n");
  373 + } else if ("TCP-ACTIVE".equals(streamMode)) { // tcp主动模式
  374 + } else if ("TCP-ACTIVE".equals(streamMode)) { // tcp主动模式
  375 + content.append("a=setup:active\r\n");
  376 + content.append("a=connection:new\r\n");
  377 + }
  378 + }
349 379 }
  380 +
350 381 content.append("y="+ssrc+"\r\n");//ssrc
351 382  
352 383 // String fromTag = UUID.randomUUID().toString();
... ...
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java
... ... @@ -261,6 +261,7 @@ public class ZLMHttpHookListener {
261 261 if ("rtp".equals(app) && !regist ) {
262 262 if (streamInfo!=null){
263 263 redisCatchStorage.stopPlay(streamInfo);
  264 + storager.stopPlay(streamInfo.getDeviceID(), streamInfo.getChannelId());
264 265 }else{
265 266 streamInfo = redisCatchStorage.queryPlaybackByStreamId(streamId);
266 267 redisCatchStorage.stopPlayback(streamInfo);
... ... @@ -292,6 +293,7 @@ public class ZLMHttpHookListener {
292 293 StreamInfo streamInfo = redisCatchStorage.queryPlayByStreamId(streamId);
293 294 if (streamInfo!=null){
294 295 redisCatchStorage.stopPlay(streamInfo);
  296 + storager.stopPlay(streamInfo.getDeviceID(), streamInfo.getChannelId());
295 297 }else{
296 298 streamInfo = redisCatchStorage.queryPlaybackByStreamId(streamId);
297 299 redisCatchStorage.stopPlayback(streamInfo);
... ...
src/main/java/com/genersoft/iot/vmp/storager/IVideoManagerStorager.java
... ... @@ -44,6 +44,21 @@ public interface IVideoManagerStorager {
44 44 * @param channel 通道
45 45 */
46 46 public void updateChannel(String deviceId, DeviceChannel channel);
  47 +
  48 + /**
  49 + * 开始播放
  50 + * @param deviceId 设备id
  51 + * @param channelId 通道ID
  52 + * @param streamId 流地址
  53 + */
  54 + public void startPlay(String deviceId, String channelId, String streamId);
  55 +
  56 + /**
  57 + * 停止播放
  58 + * @param deviceId 设备id
  59 + * @param channelId 通道ID
  60 + */
  61 + public void stopPlay(String deviceId, String channelId);
47 62  
48 63 /**
49 64 * 获取设备
... ...
src/main/java/com/genersoft/iot/vmp/storager/dao/DeviceChannelMapper.java
... ... @@ -77,4 +77,9 @@ public interface DeviceChannelMapper {
77 77 @Delete("DELETE FROM device_channel WHERE deviceId=#{deviceId}")
78 78 int cleanChannelsByDeviceId(String deviceId);
79 79  
  80 + @Update(value = {"UPDATE device_channel SET streamId=null WHERE deviceId=#{deviceId} AND channelId=#{channelId}"})
  81 + void stopPlay(String deviceId, String channelId);
  82 +
  83 + @Update(value = {"UPDATE device_channel SET streamId=#{streamId} WHERE deviceId=#{deviceId} AND channelId=#{channelId}"})
  84 + void startPlay(String deviceId, String channelId, String streamId);
80 85 }
... ...
src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java
... ... @@ -32,7 +32,7 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
32 32 */
33 33 @Override
34 34 public boolean startPlay(StreamInfo stream) {
35   - return redis.set(String.format("%S_%s_%s_%s", VideoManagerConstants.PLAYER_PREFIX, stream.getStreamId(),stream.getDeviceID(), stream.getCahnnelId()),
  35 + return redis.set(String.format("%S_%s_%s_%s", VideoManagerConstants.PLAYER_PREFIX, stream.getStreamId(),stream.getDeviceID(), stream.getChannelId()),
36 36 stream);
37 37 }
38 38  
... ... @@ -44,16 +44,10 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
44 44 @Override
45 45 public boolean stopPlay(StreamInfo streamInfo) {
46 46 if (streamInfo == null) return false;
47   - DeviceChannel deviceChannel = deviceChannelMapper.queryChannel(streamInfo.getDeviceID(), streamInfo.getCahnnelId());
48   - if (deviceChannel != null) {
49   - deviceChannel.setStreamId(null);
50   - deviceChannel.setDeviceId(streamInfo.getDeviceID());
51   - deviceChannelMapper.update(deviceChannel);
52   - }
53 47 return redis.del(String.format("%S_%s_%s_%s", VideoManagerConstants.PLAYER_PREFIX,
54 48 streamInfo.getStreamId(),
55 49 streamInfo.getDeviceID(),
56   - streamInfo.getCahnnelId()));
  50 + streamInfo.getChannelId()));
57 51 }
58 52  
59 53 /**
... ... @@ -66,7 +60,7 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
66 60 VideoManagerConstants.PLAYER_PREFIX,
67 61 streamInfo.getStreamId(),
68 62 streamInfo.getDeviceID(),
69   - streamInfo.getCahnnelId()));
  63 + streamInfo.getChannelId()));
70 64 }
71 65 @Override
72 66 public StreamInfo queryPlayByStreamId(String steamId) {
... ... @@ -120,7 +114,7 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
120 114 for (int i = 0; i < players.size(); i++) {
121 115 String key = (String) players.get(i);
122 116 StreamInfo streamInfo = (StreamInfo)redis.get(key);
123   - streamInfos.put(streamInfo.getDeviceID() + "_" + streamInfo.getCahnnelId(), streamInfo);
  117 + streamInfos.put(streamInfo.getDeviceID() + "_" + streamInfo.getChannelId(), streamInfo);
124 118 }
125 119 return streamInfos;
126 120 }
... ... @@ -128,7 +122,7 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
128 122  
129 123 @Override
130 124 public boolean startPlayback(StreamInfo stream) {
131   - return redis.set(String.format("%S_%s_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX, stream.getStreamId(),stream.getDeviceID(), stream.getCahnnelId()),
  125 + return redis.set(String.format("%S_%s_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX, stream.getStreamId(),stream.getDeviceID(), stream.getChannelId()),
132 126 stream);
133 127 }
134 128  
... ... @@ -136,7 +130,7 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
136 130 @Override
137 131 public boolean stopPlayback(StreamInfo streamInfo) {
138 132 if (streamInfo == null) return false;
139   - DeviceChannel deviceChannel = deviceChannelMapper.queryChannel(streamInfo.getDeviceID(), streamInfo.getCahnnelId());
  133 + DeviceChannel deviceChannel = deviceChannelMapper.queryChannel(streamInfo.getDeviceID(), streamInfo.getChannelId());
140 134 if (deviceChannel != null) {
141 135 deviceChannel.setStreamId(null);
142 136 deviceChannel.setDeviceId(streamInfo.getDeviceID());
... ... @@ -145,7 +139,7 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
145 139 return redis.del(String.format("%S_%s_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX,
146 140 streamInfo.getStreamId(),
147 141 streamInfo.getDeviceID(),
148   - streamInfo.getCahnnelId()));
  142 + streamInfo.getChannelId()));
149 143 }
150 144  
151 145 @Override
... ...
src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStoragerImpl.java
... ... @@ -83,6 +83,16 @@ public class VideoManagerStoragerImpl implements IVideoManagerStorager {
83 83 }
84 84 }
85 85  
  86 + @Override
  87 + public void startPlay(String deviceId, String channelId, String streamId) {
  88 + deviceChannelMapper.startPlay(deviceId, channelId, streamId);
  89 + }
  90 +
  91 + @Override
  92 + public void stopPlay(String deviceId, String channelId) {
  93 + deviceChannelMapper.stopPlay(deviceId, channelId);
  94 + }
  95 +
86 96 /**
87 97 * 获取设备
88 98 *
... ...
src/main/java/com/genersoft/iot/vmp/vmanager/play/PlayController.java
... ... @@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON;
4 4 import com.alibaba.fastjson.JSONArray;
5 5 import com.genersoft.iot.vmp.common.StreamInfo;
6 6 import com.genersoft.iot.vmp.conf.MediaServerConfig;
  7 +import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
7 8 import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder;
8 9 import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage;
9 10 import com.genersoft.iot.vmp.media.zlm.ZLMRESTfulUtils;
... ... @@ -94,6 +95,7 @@ public class PlayController {
94 95 resultHolder.invokeResult(msg);
95 96 } else {
96 97 redisCatchStorage.stopPlay(streamInfo);
  98 + storager.stopPlay(streamInfo.getDeviceID(), streamInfo.getChannelId());
97 99 cmder.playStreamCmd(device, channelId, (JSONObject response) -> {
98 100 logger.info("收到订阅消息: " + response.toJSONString());
99 101 playService.onPublishHandlerForPlay(response, deviceId, channelId, uuid.toString());
... ... @@ -138,18 +140,17 @@ public class PlayController {
138 140 msg.setId(DeferredResultHolder.CALLBACK_CMD_PlAY + uuid);
139 141 msg.setData("streamId not found");
140 142 resultHolder.invokeResult(msg);
  143 + }else {
141 144 redisCatchStorage.stopPlay(streamInfo);
  145 + storager.stopPlay(streamInfo.getDeviceID(), streamInfo.getChannelId());
  146 + RequestMessage msg = new RequestMessage();
  147 + msg.setId(DeferredResultHolder.CALLBACK_CMD_STOP + uuid);
  148 + Response response = event.getResponse();
  149 + msg.setData(String.format("success"));
  150 + resultHolder.invokeResult(msg);
142 151 }
143   -
144   - RequestMessage msg = new RequestMessage();
145   - msg.setId(DeferredResultHolder.CALLBACK_CMD_STOP + uuid);
146   - Response response = event.getResponse();
147   - msg.setData(String.format("success"));
148   - resultHolder.invokeResult(msg);
149 152 });
150 153  
151   -
152   -
153 154 if (streamId != null) {
154 155 JSONObject json = new JSONObject();
155 156 json.put("streamId", streamId);
... ... @@ -168,6 +169,7 @@ public class PlayController {
168 169 // 超时处理
169 170 result.onTimeout(()->{
170 171 logger.warn(String.format("设备预览/回放停止超时,streamId:%s ", streamId));
  172 +
171 173 RequestMessage msg = new RequestMessage();
172 174 msg.setId(DeferredResultHolder.CALLBACK_CMD_STOP + uuid);
173 175 msg.setData("Timeout");
... ...
src/main/java/com/genersoft/iot/vmp/vmanager/service/impl/PlayServiceImpl.java
... ... @@ -41,7 +41,7 @@ public class PlayServiceImpl implements IPlayService {
41 41 DeviceChannel deviceChannel = storager.queryChannel(deviceId, channelId);
42 42 if (deviceChannel != null) {
43 43 deviceChannel.setStreamId(streamInfo.getStreamId());
44   - storager.updateChannel(deviceId, deviceChannel);
  44 + storager.startPlay(deviceId, channelId, streamInfo.getStreamId());
45 45 }
46 46  
47 47 redisCatchStorage.startPlay(streamInfo);
... ... @@ -75,7 +75,7 @@ public class PlayServiceImpl implements IPlayService {
75 75 StreamInfo streamInfo = new StreamInfo();
76 76 streamInfo.setStreamId(streamId);
77 77 streamInfo.setDeviceID(deviceId);
78   - streamInfo.setCahnnelId(channelId);
  78 + streamInfo.setChannelId(channelId);
79 79 MediaServerConfig mediaServerConfig = redisCatchStorage.getMediaInfo();
80 80  
81 81 streamInfo.setFlv(String.format("http://%s:%s/rtp/%s.flv", mediaServerConfig.getWanIp(), mediaServerConfig.getHttpPort(), streamId));
... ...
src/main/java/com/genersoft/iot/vmp/web/ApiStreamController.java
... ... @@ -170,6 +170,7 @@ public class ApiStreamController {
170 170 }
171 171 cmder.streamByeCmd(streamInfo.getStreamId());
172 172 redisCatchStorage.stopPlay(streamInfo);
  173 + storager.stopPlay(streamInfo.getDeviceID(), streamInfo.getChannelId());
173 174 return null;
174 175 }
175 176  
... ...