Browse Source

Merge remote-tracking branch 'origin/master' into wvp-28181-2.0

# Conflicts:
#	src/main/java/com/genersoft/iot/vmp/storager/dao/DeviceChannelMapper.java
pull/29/head
panlinlin 4 years ago
parent
commit
7e581e9d3a
  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. 6
      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 deviceID;
private String cahnnelId;
private String channelId;
private String flv;
private String ws_flv;
private String fmp4;
@ -27,12 +27,12 @@ public class StreamInfo {
this.deviceID = deviceID;
}
public String getCahnnelId() {
return cahnnelId;
public String getChannelId() {
return channelId;
}
public void setCahnnelId(String cahnnelId) {
this.cahnnelId = cahnnelId;
public void setChannelId(String channelId) {
this.channelId = channelId;
}
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("c=IN IP4 "+mediaInfo.getWanIp()+"\r\n");
content.append("t=0 0\r\n");
if (seniorSdp) {
if("TCP-PASSIVE".equals(streamMode)) {
content.append("m=video "+ mediaPort +" TCP/RTP/AVP 126 125 99 34 98 97 96\r\n");
}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=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
// 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 (streamInfo!=null){
redisCatchStorage.stopPlay(streamInfo);
storager.stopPlay(streamInfo.getDeviceID(), streamInfo.getChannelId());
}else{
streamInfo = redisCatchStorage.queryPlaybackByStreamId(streamId);
redisCatchStorage.stopPlayback(streamInfo);
@ -292,6 +293,7 @@ public class ZLMHttpHookListener {
StreamInfo streamInfo = redisCatchStorage.queryPlayByStreamId(streamId);
if (streamInfo!=null){
redisCatchStorage.stopPlay(streamInfo);
storager.stopPlay(streamInfo.getDeviceID(), streamInfo.getChannelId());
}else{
streamInfo = redisCatchStorage.queryPlaybackByStreamId(streamId);
redisCatchStorage.stopPlayback(streamInfo);

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

@ -48,6 +48,21 @@ public interface IVideoManagerStorager {
*/
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);
/**
* 获取设备
*

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

@ -1,7 +1,6 @@
package com.genersoft.iot.vmp.storager.dao;
import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
import org.apache.ibatis.annotations.*;
import java.util.List;
@ -78,6 +77,9 @@ public interface DeviceChannelMapper {
@Delete("DELETE FROM device_channel WHERE deviceId=#{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

@ -35,7 +35,7 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
*/
@Override
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);
}
@ -47,16 +47,10 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
@Override
public boolean stopPlay(StreamInfo streamInfo) {
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,
streamInfo.getStreamId(),
streamInfo.getDeviceID(),
streamInfo.getCahnnelId()));
streamInfo.getChannelId()));
}
/**
@ -69,7 +63,7 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
VideoManagerConstants.PLAYER_PREFIX,
streamInfo.getStreamId(),
streamInfo.getDeviceID(),
streamInfo.getCahnnelId()));
streamInfo.getChannelId()));
}
@Override
public StreamInfo queryPlayByStreamId(String steamId) {
@ -123,7 +117,7 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
for (int i = 0; i < players.size(); i++) {
String key = (String) players.get(i);
StreamInfo streamInfo = (StreamInfo)redis.get(key);
streamInfos.put(streamInfo.getDeviceID() + "_" + streamInfo.getCahnnelId(), streamInfo);
streamInfos.put(streamInfo.getDeviceID() + "_" + streamInfo.getChannelId(), streamInfo);
}
return streamInfos;
}
@ -131,7 +125,7 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
@Override
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);
}
@ -139,7 +133,7 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
@Override
public boolean stopPlayback(StreamInfo streamInfo) {
if (streamInfo == null) return false;
DeviceChannel deviceChannel = deviceChannelMapper.queryChannel(streamInfo.getDeviceID(), streamInfo.getCahnnelId());
DeviceChannel deviceChannel = deviceChannelMapper.queryChannel(streamInfo.getDeviceID(), streamInfo.getChannelId());
if (deviceChannel != null) {
deviceChannel.setStreamId(null);
deviceChannel.setDeviceId(streamInfo.getDeviceID());
@ -148,7 +142,7 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
return redis.del(String.format("%S_%s_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX,
streamInfo.getStreamId(),
streamInfo.getDeviceID(),
streamInfo.getCahnnelId()));
streamInfo.getChannelId()));
}
@Override

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

@ -93,6 +93,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.genersoft.iot.vmp.common.StreamInfo;
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.RequestMessage;
import com.genersoft.iot.vmp.media.zlm.ZLMRESTfulUtils;
@ -94,6 +95,7 @@ public class PlayController {
resultHolder.invokeResult(msg);
} else {
redisCatchStorage.stopPlay(streamInfo);
storager.stopPlay(streamInfo.getDeviceID(), streamInfo.getChannelId());
cmder.playStreamCmd(device, channelId, (JSONObject response) -> {
logger.info("收到订阅消息: " + response.toJSONString());
playService.onPublishHandlerForPlay(response, deviceId, channelId, uuid.toString());
@ -138,18 +140,17 @@ public class PlayController {
msg.setId(DeferredResultHolder.CALLBACK_CMD_PlAY + uuid);
msg.setData("streamId not found");
resultHolder.invokeResult(msg);
}else {
redisCatchStorage.stopPlay(streamInfo);
}
storager.stopPlay(streamInfo.getDeviceID(), streamInfo.getChannelId());
RequestMessage msg = new RequestMessage();
msg.setId(DeferredResultHolder.CALLBACK_CMD_STOP + uuid);
Response response = event.getResponse();
msg.setData(String.format("success"));
resultHolder.invokeResult(msg);
}
});
if (streamId != null) {
JSONObject json = new JSONObject();
json.put("streamId", streamId);
@ -168,6 +169,7 @@ public class PlayController {
// 超时处理
result.onTimeout(()->{
logger.warn(String.format("设备预览/回放停止超时,streamId:%s ", streamId));
RequestMessage msg = new RequestMessage();
msg.setId(DeferredResultHolder.CALLBACK_CMD_STOP + uuid);
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);
if (deviceChannel != null) {
deviceChannel.setStreamId(streamInfo.getStreamId());
storager.updateChannel(deviceId, deviceChannel);
storager.startPlay(deviceId, channelId, streamInfo.getStreamId());
}
redisCatchStorage.startPlay(streamInfo);
@ -75,7 +75,7 @@ public class PlayServiceImpl implements IPlayService {
StreamInfo streamInfo = new StreamInfo();
streamInfo.setStreamId(streamId);
streamInfo.setDeviceID(deviceId);
streamInfo.setCahnnelId(channelId);
streamInfo.setChannelId(channelId);
MediaServerConfig mediaServerConfig = redisCatchStorage.getMediaInfo();
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

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

Loading…
Cancel
Save