Browse Source

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

修改错别字
pull/31/head
panlinlin 4 years ago
parent
commit
1342aad032
  1. 10
      src/main/java/com/genersoft/iot/vmp/common/StreamInfo.java
  2. 31
      src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java
  3. 2
      src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java
  4. 15
      src/main/java/com/genersoft/iot/vmp/storager/IVideoManagerStorager.java
  5. 5
      src/main/java/com/genersoft/iot/vmp/storager/dao/DeviceChannelMapper.java
  6. 20
      src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java
  7. 10
      src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStoragerImpl.java
  8. 10
      src/main/java/com/genersoft/iot/vmp/vmanager/play/PlayController.java
  9. 4
      src/main/java/com/genersoft/iot/vmp/vmanager/service/impl/PlayServiceImpl.java
  10. 1
      src/main/java/com/genersoft/iot/vmp/web/ApiStreamController.java

10
src/main/java/com/genersoft/iot/vmp/common/StreamInfo.java

@ -6,7 +6,7 @@ public class StreamInfo {
private String streamId; private String streamId;
private String deviceID; private String deviceID;
private String cahnnelId; private String channelId;
private String flv; private String flv;
private String ws_flv; private String ws_flv;
private String fmp4; private String fmp4;
@ -27,12 +27,12 @@ public class StreamInfo {
this.deviceID = deviceID; this.deviceID = deviceID;
} }
public String getCahnnelId() { public String getChannelId() {
return cahnnelId; return channelId;
} }
public void setCahnnelId(String cahnnelId) { public void setChannelId(String channelId) {
this.cahnnelId = cahnnelId; this.channelId = channelId;
} }
public String getFlv() { public String getFlv() {

31
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java

@ -323,6 +323,8 @@ public class SIPCommander implements ISIPCommander {
content.append("s=Play\r\n"); content.append("s=Play\r\n");
content.append("c=IN IP4 "+mediaInfo.getWanIp()+"\r\n"); content.append("c=IN IP4 "+mediaInfo.getWanIp()+"\r\n");
content.append("t=0 0\r\n"); content.append("t=0 0\r\n");
if (seniorSdp) {
if("TCP-PASSIVE".equals(streamMode)) { if("TCP-PASSIVE".equals(streamMode)) {
content.append("m=video "+ mediaPort +" TCP/RTP/AVP 126 125 99 34 98 97 96\r\n"); content.append("m=video "+ mediaPort +" TCP/RTP/AVP 126 125 99 34 98 97 96\r\n");
}else if ("TCP-ACTIVE".equals(streamMode)) { }else if ("TCP-ACTIVE".equals(streamMode)) {
@ -347,6 +349,35 @@ public class SIPCommander implements ISIPCommander {
content.append("a=setup:active\r\n"); content.append("a=setup:active\r\n");
content.append("a=connection:new\r\n"); content.append("a=connection:new\r\n");
} }
}else {
if("TCP-PASSIVE".equals(streamMode)) {
content.append("m=video "+ mediaPort +" TCP/RTP/AVP 96 98 97\r\n");
}else if ("TCP-ACTIVE".equals(streamMode)) {
content.append("m=video "+ mediaPort +" TCP/RTP/AVP 96 98 97\r\n");
}else if("UDP".equals(streamMode)) {
content.append("m=video "+ mediaPort +" RTP/AVP 96 98 97\r\n");
}
content.append("a=recvonly\r\n");
content.append("a=rtpmap:96 PS/90000\r\n");
content.append("a=rtpmap:98 H264/90000\r\n");
content.append("a=rtpmap:97 MPEG4/90000\r\n");
if("TCP-PASSIVE".equals(streamMode)) { // tcp被动模式
content.append("a=setup:passive\r\n");
content.append("a=recvonly\r\n");
content.append("a=rtpmap:96 PS/90000\r\n");
content.append("a=rtpmap:98 H264/90000\r\n");
content.append("a=rtpmap:97 MPEG4/90000\r\n");
if ("TCP-PASSIVE".equals(streamMode)) { // tcp被动模式
content.append("a=setup:passive\r\n");
content.append("a=connection:new\r\n");
} else if ("TCP-ACTIVE".equals(streamMode)) { // tcp主动模式
} else if ("TCP-ACTIVE".equals(streamMode)) { // tcp主动模式
content.append("a=setup:active\r\n");
content.append("a=connection:new\r\n");
}
}
}
content.append("y="+ssrc+"\r\n");//ssrc content.append("y="+ssrc+"\r\n");//ssrc
// String fromTag = UUID.randomUUID().toString(); // String fromTag = UUID.randomUUID().toString();

2
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java

@ -261,6 +261,7 @@ public class ZLMHttpHookListener {
if ("rtp".equals(app) && !regist ) { if ("rtp".equals(app) && !regist ) {
if (streamInfo!=null){ if (streamInfo!=null){
redisCatchStorage.stopPlay(streamInfo); redisCatchStorage.stopPlay(streamInfo);
storager.stopPlay(streamInfo.getDeviceID(), streamInfo.getChannelId());
}else{ }else{
streamInfo = redisCatchStorage.queryPlaybackByStreamId(streamId); streamInfo = redisCatchStorage.queryPlaybackByStreamId(streamId);
redisCatchStorage.stopPlayback(streamInfo); redisCatchStorage.stopPlayback(streamInfo);
@ -292,6 +293,7 @@ public class ZLMHttpHookListener {
StreamInfo streamInfo = redisCatchStorage.queryPlayByStreamId(streamId); StreamInfo streamInfo = redisCatchStorage.queryPlayByStreamId(streamId);
if (streamInfo!=null){ if (streamInfo!=null){
redisCatchStorage.stopPlay(streamInfo); redisCatchStorage.stopPlay(streamInfo);
storager.stopPlay(streamInfo.getDeviceID(), streamInfo.getChannelId());
}else{ }else{
streamInfo = redisCatchStorage.queryPlaybackByStreamId(streamId); streamInfo = redisCatchStorage.queryPlaybackByStreamId(streamId);
redisCatchStorage.stopPlayback(streamInfo); redisCatchStorage.stopPlayback(streamInfo);

15
src/main/java/com/genersoft/iot/vmp/storager/IVideoManagerStorager.java

@ -45,6 +45,21 @@ public interface IVideoManagerStorager {
*/ */
public void updateChannel(String deviceId, DeviceChannel channel); public void updateChannel(String deviceId, DeviceChannel channel);
/**
* 开始播放
* @param deviceId 设备id
* @param channelId 通道ID
* @param streamId 流地址
*/
public void startPlay(String deviceId, String channelId, String streamId);
/**
* 停止播放
* @param deviceId 设备id
* @param channelId 通道ID
*/
public void stopPlay(String deviceId, String channelId);
/** /**
* 获取设备 * 获取设备
* *

5
src/main/java/com/genersoft/iot/vmp/storager/dao/DeviceChannelMapper.java

@ -77,4 +77,9 @@ public interface DeviceChannelMapper {
@Delete("DELETE FROM device_channel WHERE deviceId=#{deviceId}") @Delete("DELETE FROM device_channel WHERE deviceId=#{deviceId}")
int cleanChannelsByDeviceId(String deviceId); int cleanChannelsByDeviceId(String deviceId);
@Update(value = {"UPDATE device_channel SET streamId=null WHERE deviceId=#{deviceId} AND channelId=#{channelId}"})
void stopPlay(String deviceId, String channelId);
@Update(value = {"UPDATE device_channel SET streamId=#{streamId} WHERE deviceId=#{deviceId} AND channelId=#{channelId}"})
void startPlay(String deviceId, String channelId, String streamId);
} }

20
src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java

@ -32,7 +32,7 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
*/ */
@Override @Override
public boolean startPlay(StreamInfo stream) { public boolean startPlay(StreamInfo stream) {
return redis.set(String.format("%S_%s_%s_%s", VideoManagerConstants.PLAYER_PREFIX, stream.getStreamId(),stream.getDeviceID(), stream.getCahnnelId()), return redis.set(String.format("%S_%s_%s_%s", VideoManagerConstants.PLAYER_PREFIX, stream.getStreamId(),stream.getDeviceID(), stream.getChannelId()),
stream); stream);
} }
@ -44,16 +44,10 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
@Override @Override
public boolean stopPlay(StreamInfo streamInfo) { public boolean stopPlay(StreamInfo streamInfo) {
if (streamInfo == null) return false; if (streamInfo == null) return false;
DeviceChannel deviceChannel = deviceChannelMapper.queryChannel(streamInfo.getDeviceID(), streamInfo.getCahnnelId());
if (deviceChannel != null) {
deviceChannel.setStreamId(null);
deviceChannel.setDeviceId(streamInfo.getDeviceID());
deviceChannelMapper.update(deviceChannel);
}
return redis.del(String.format("%S_%s_%s_%s", VideoManagerConstants.PLAYER_PREFIX, return redis.del(String.format("%S_%s_%s_%s", VideoManagerConstants.PLAYER_PREFIX,
streamInfo.getStreamId(), streamInfo.getStreamId(),
streamInfo.getDeviceID(), streamInfo.getDeviceID(),
streamInfo.getCahnnelId())); streamInfo.getChannelId()));
} }
/** /**
@ -66,7 +60,7 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
VideoManagerConstants.PLAYER_PREFIX, VideoManagerConstants.PLAYER_PREFIX,
streamInfo.getStreamId(), streamInfo.getStreamId(),
streamInfo.getDeviceID(), streamInfo.getDeviceID(),
streamInfo.getCahnnelId())); streamInfo.getChannelId()));
} }
@Override @Override
public StreamInfo queryPlayByStreamId(String steamId) { public StreamInfo queryPlayByStreamId(String steamId) {
@ -120,7 +114,7 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
for (int i = 0; i < players.size(); i++) { for (int i = 0; i < players.size(); i++) {
String key = (String) players.get(i); String key = (String) players.get(i);
StreamInfo streamInfo = (StreamInfo)redis.get(key); StreamInfo streamInfo = (StreamInfo)redis.get(key);
streamInfos.put(streamInfo.getDeviceID() + "_" + streamInfo.getCahnnelId(), streamInfo); streamInfos.put(streamInfo.getDeviceID() + "_" + streamInfo.getChannelId(), streamInfo);
} }
return streamInfos; return streamInfos;
} }
@ -128,7 +122,7 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
@Override @Override
public boolean startPlayback(StreamInfo stream) { public boolean startPlayback(StreamInfo stream) {
return redis.set(String.format("%S_%s_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX, stream.getStreamId(),stream.getDeviceID(), stream.getCahnnelId()), return redis.set(String.format("%S_%s_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX, stream.getStreamId(),stream.getDeviceID(), stream.getChannelId()),
stream); stream);
} }
@ -136,7 +130,7 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
@Override @Override
public boolean stopPlayback(StreamInfo streamInfo) { public boolean stopPlayback(StreamInfo streamInfo) {
if (streamInfo == null) return false; if (streamInfo == null) return false;
DeviceChannel deviceChannel = deviceChannelMapper.queryChannel(streamInfo.getDeviceID(), streamInfo.getCahnnelId()); DeviceChannel deviceChannel = deviceChannelMapper.queryChannel(streamInfo.getDeviceID(), streamInfo.getChannelId());
if (deviceChannel != null) { if (deviceChannel != null) {
deviceChannel.setStreamId(null); deviceChannel.setStreamId(null);
deviceChannel.setDeviceId(streamInfo.getDeviceID()); deviceChannel.setDeviceId(streamInfo.getDeviceID());
@ -145,7 +139,7 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
return redis.del(String.format("%S_%s_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX, return redis.del(String.format("%S_%s_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX,
streamInfo.getStreamId(), streamInfo.getStreamId(),
streamInfo.getDeviceID(), streamInfo.getDeviceID(),
streamInfo.getCahnnelId())); streamInfo.getChannelId()));
} }
@Override @Override

10
src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStoragerImpl.java

@ -83,6 +83,16 @@ public class VideoManagerStoragerImpl implements IVideoManagerStorager {
} }
} }
@Override
public void startPlay(String deviceId, String channelId, String streamId) {
deviceChannelMapper.startPlay(deviceId, channelId, streamId);
}
@Override
public void stopPlay(String deviceId, String channelId) {
deviceChannelMapper.stopPlay(deviceId, channelId);
}
/** /**
* 获取设备 * 获取设备
* *

10
src/main/java/com/genersoft/iot/vmp/vmanager/play/PlayController.java

@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.genersoft.iot.vmp.common.StreamInfo; import com.genersoft.iot.vmp.common.StreamInfo;
import com.genersoft.iot.vmp.conf.MediaServerConfig; import com.genersoft.iot.vmp.conf.MediaServerConfig;
import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder; import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder;
import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage; import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage;
import com.genersoft.iot.vmp.media.zlm.ZLMRESTfulUtils; import com.genersoft.iot.vmp.media.zlm.ZLMRESTfulUtils;
@ -94,6 +95,7 @@ public class PlayController {
resultHolder.invokeResult(msg); resultHolder.invokeResult(msg);
} else { } else {
redisCatchStorage.stopPlay(streamInfo); redisCatchStorage.stopPlay(streamInfo);
storager.stopPlay(streamInfo.getDeviceID(), streamInfo.getChannelId());
cmder.playStreamCmd(device, channelId, (JSONObject response) -> { cmder.playStreamCmd(device, channelId, (JSONObject response) -> {
logger.info("收到订阅消息: " + response.toJSONString()); logger.info("收到订阅消息: " + response.toJSONString());
playService.onPublishHandlerForPlay(response, deviceId, channelId, uuid.toString()); playService.onPublishHandlerForPlay(response, deviceId, channelId, uuid.toString());
@ -138,18 +140,17 @@ public class PlayController {
msg.setId(DeferredResultHolder.CALLBACK_CMD_PlAY + uuid); msg.setId(DeferredResultHolder.CALLBACK_CMD_PlAY + uuid);
msg.setData("streamId not found"); msg.setData("streamId not found");
resultHolder.invokeResult(msg); resultHolder.invokeResult(msg);
}else {
redisCatchStorage.stopPlay(streamInfo); redisCatchStorage.stopPlay(streamInfo);
} storager.stopPlay(streamInfo.getDeviceID(), streamInfo.getChannelId());
RequestMessage msg = new RequestMessage(); RequestMessage msg = new RequestMessage();
msg.setId(DeferredResultHolder.CALLBACK_CMD_STOP + uuid); msg.setId(DeferredResultHolder.CALLBACK_CMD_STOP + uuid);
Response response = event.getResponse(); Response response = event.getResponse();
msg.setData(String.format("success")); msg.setData(String.format("success"));
resultHolder.invokeResult(msg); resultHolder.invokeResult(msg);
}
}); });
if (streamId != null) { if (streamId != null) {
JSONObject json = new JSONObject(); JSONObject json = new JSONObject();
json.put("streamId", streamId); json.put("streamId", streamId);
@ -168,6 +169,7 @@ public class PlayController {
// 超时处理 // 超时处理
result.onTimeout(()->{ result.onTimeout(()->{
logger.warn(String.format("设备预览/回放停止超时,streamId:%s ", streamId)); logger.warn(String.format("设备预览/回放停止超时,streamId:%s ", streamId));
RequestMessage msg = new RequestMessage(); RequestMessage msg = new RequestMessage();
msg.setId(DeferredResultHolder.CALLBACK_CMD_STOP + uuid); msg.setId(DeferredResultHolder.CALLBACK_CMD_STOP + uuid);
msg.setData("Timeout"); msg.setData("Timeout");

4
src/main/java/com/genersoft/iot/vmp/vmanager/service/impl/PlayServiceImpl.java

@ -41,7 +41,7 @@ public class PlayServiceImpl implements IPlayService {
DeviceChannel deviceChannel = storager.queryChannel(deviceId, channelId); DeviceChannel deviceChannel = storager.queryChannel(deviceId, channelId);
if (deviceChannel != null) { if (deviceChannel != null) {
deviceChannel.setStreamId(streamInfo.getStreamId()); deviceChannel.setStreamId(streamInfo.getStreamId());
storager.updateChannel(deviceId, deviceChannel); storager.startPlay(deviceId, channelId, streamInfo.getStreamId());
} }
redisCatchStorage.startPlay(streamInfo); redisCatchStorage.startPlay(streamInfo);
@ -75,7 +75,7 @@ public class PlayServiceImpl implements IPlayService {
StreamInfo streamInfo = new StreamInfo(); StreamInfo streamInfo = new StreamInfo();
streamInfo.setStreamId(streamId); streamInfo.setStreamId(streamId);
streamInfo.setDeviceID(deviceId); streamInfo.setDeviceID(deviceId);
streamInfo.setCahnnelId(channelId); streamInfo.setChannelId(channelId);
MediaServerConfig mediaServerConfig = redisCatchStorage.getMediaInfo(); MediaServerConfig mediaServerConfig = redisCatchStorage.getMediaInfo();
streamInfo.setFlv(String.format("http://%s:%s/rtp/%s.flv", mediaServerConfig.getWanIp(), mediaServerConfig.getHttpPort(), streamId)); streamInfo.setFlv(String.format("http://%s:%s/rtp/%s.flv", mediaServerConfig.getWanIp(), mediaServerConfig.getHttpPort(), streamId));

1
src/main/java/com/genersoft/iot/vmp/web/ApiStreamController.java

@ -170,6 +170,7 @@ public class ApiStreamController {
} }
cmder.streamByeCmd(streamInfo.getStreamId()); cmder.streamByeCmd(streamInfo.getStreamId());
redisCatchStorage.stopPlay(streamInfo); redisCatchStorage.stopPlay(streamInfo);
storager.stopPlay(streamInfo.getDeviceID(), streamInfo.getChannelId());
return null; return null;
} }

Loading…
Cancel
Save