Merge branch 'master' into master
This commit is contained in:
@@ -18,6 +18,8 @@ public class VideoManagerConstants {
|
||||
|
||||
public static final String PLAYER_PREFIX = "VMP_player_";
|
||||
|
||||
public static final String PLAY_BLACK_PREFIX = "VMP_playback_";
|
||||
|
||||
public static final String EVENT_ONLINE_REGISTER = "1";
|
||||
|
||||
public static final String EVENT_ONLINE_KEEPLIVE = "2";
|
||||
|
||||
@@ -1,12 +1,18 @@
|
||||
package com.genersoft.iot.vmp.gb28181.bean;
|
||||
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @Description:设备录像bean
|
||||
* @author: swwheihei
|
||||
* @date: 2020年5月8日 下午2:06:54
|
||||
*/
|
||||
public class RecordItem {
|
||||
public class RecordItem implements Comparable<RecordItem>{
|
||||
|
||||
private String deviceId;
|
||||
|
||||
@@ -97,4 +103,21 @@ public class RecordItem {
|
||||
public void setRecorderId(String recorderId) {
|
||||
this.recorderId = recorderId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(@NotNull RecordItem recordItem) {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
try {
|
||||
Date startTime_now = sdf.parse(startTime);
|
||||
Date startTime_param = sdf.parse(recordItem.getStartTime());
|
||||
if (startTime_param.compareTo(startTime_now) > 0) {
|
||||
return -1;
|
||||
}else {
|
||||
return 1;
|
||||
}
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ public interface ISIPCommander {
|
||||
* @param startTime 开始时间,格式要求:yyyy-MM-dd HH:mm:ss
|
||||
* @param endTime 结束时间,格式要求:yyyy-MM-dd HH:mm:ss
|
||||
*/
|
||||
public String playbackStreamCmd(Device device,String channelId, String startTime, String endTime);
|
||||
public StreamInfo playbackStreamCmd(Device device,String channelId, String startTime, String endTime);
|
||||
|
||||
/**
|
||||
* 视频流停止
|
||||
|
||||
@@ -279,7 +279,7 @@ public class SIPCommander implements ISIPCommander {
|
||||
* @param endTime 结束时间,格式要求:yyyy-MM-dd HH:mm:ss
|
||||
*/
|
||||
@Override
|
||||
public String playbackStreamCmd(Device device, String channelId, String startTime, String endTime) {
|
||||
public StreamInfo playbackStreamCmd(Device device, String channelId, String startTime, String endTime) {
|
||||
try {
|
||||
MediaServerConfig mediaInfo = storager.getMediaInfo();
|
||||
String ssrc = streamSession.createPlayBackSsrc();
|
||||
@@ -324,7 +324,13 @@ public class SIPCommander implements ISIPCommander {
|
||||
|
||||
ClientTransaction transaction = transmitRequest(device, request);
|
||||
streamSession.put(ssrc, transaction);
|
||||
return ssrc;
|
||||
|
||||
StreamInfo streamInfo = new StreamInfo();
|
||||
streamInfo.setSsrc(ssrc);
|
||||
streamInfo.setCahnnelId(channelId);
|
||||
streamInfo.setDeviceID(device.getDeviceId());
|
||||
boolean b = storager.startPlayBlack(streamInfo);
|
||||
return streamInfo;
|
||||
|
||||
} catch ( SipException | ParseException | InvalidArgumentException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -2,11 +2,7 @@ package com.genersoft.iot.vmp.gb28181.transmit.request.impl;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.text.ParseException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
import javax.sip.InvalidArgumentException;
|
||||
import javax.sip.RequestEvent;
|
||||
@@ -316,6 +312,7 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor {
|
||||
record.setRecorderId(XmlUtil.getText(itemRecord,"RecorderID"));
|
||||
recordList.add(record);
|
||||
}
|
||||
// recordList.sort(Comparator.naturalOrder());
|
||||
recordInfo.setRecordList(recordList);
|
||||
}
|
||||
|
||||
@@ -349,9 +346,13 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor {
|
||||
// 走到这里,有以下可能:1、没有录像信息,第一次收到recordinfo的消息即返回响应数据,无redis操作
|
||||
// 2、有录像数据,且第一次即收到完整数据,返回响应数据,无redis操作
|
||||
// 3、有录像数据,在超时时间内收到多次包组装后数量足够,返回数据
|
||||
|
||||
// 对记录进行排序
|
||||
RequestMessage msg = new RequestMessage();
|
||||
msg.setDeviceId(deviceId);
|
||||
msg.setType(DeferredResultHolder.CALLBACK_CMD_RECORDINFO);
|
||||
// 自然顺序排序, 元素进行升序排列
|
||||
recordInfo.getRecordList().sort(Comparator.naturalOrder());
|
||||
msg.setData(recordInfo);
|
||||
deferredResultHolder.invokeResult(msg);
|
||||
} catch (DocumentException e) {
|
||||
|
||||
@@ -130,17 +130,27 @@ public class ZLMHttpHookListener {
|
||||
String streamId = json.getString("id");
|
||||
|
||||
|
||||
// String ssrc = String.format("%10d", Integer.parseInt(streamId, 16)); // ZLM 要求大写且首位补零
|
||||
String ssrc = new DecimalFormat("0000000000").format(Integer.parseInt(streamId, 16));
|
||||
StreamInfo streamInfo = storager.queryPlayBySSRC(ssrc);
|
||||
if ("rtp".equals(app) && streamInfo != null ) {
|
||||
StreamInfo streamInfoForPlay = storager.queryPlayBySSRC(ssrc);
|
||||
if ("rtp".equals(app) && streamInfoForPlay != null ) {
|
||||
MediaServerConfig mediaInfo = storager.getMediaInfo();
|
||||
streamInfo.setFlv(String.format("http://%s:%s/rtp/%s.flv", mediaInfo.getLocalIP(), mediaInfo.getHttpPort(), streamId));
|
||||
streamInfo.setWs_flv(String.format("ws://%s:%s/rtp/%s.flv", mediaInfo.getLocalIP(), mediaInfo.getHttpPort(), streamId));
|
||||
streamInfo.setRtmp(String.format("rtmp://%s:%s/rtp/%s", mediaInfo.getLocalIP(), mediaInfo.getRtmpPort(), streamId));
|
||||
streamInfo.setHls(String.format("http://%s:%s/rtp/%s/hls.m3u8", mediaInfo.getLocalIP(), mediaInfo.getHttpPort(), streamId));
|
||||
streamInfo.setRtsp(String.format("rtsp://%s:%s/rtp/%s", mediaInfo.getLocalIP(), mediaInfo.getRtspPort(), streamId));
|
||||
storager.startPlay(streamInfo);
|
||||
streamInfoForPlay.setFlv(String.format("http://%s:%s/rtp/%s.flv", mediaInfo.getLocalIP(), mediaInfo.getHttpPort(), streamId));
|
||||
streamInfoForPlay.setWs_flv(String.format("ws://%s:%s/rtp/%s.flv", mediaInfo.getLocalIP(), mediaInfo.getHttpPort(), streamId));
|
||||
streamInfoForPlay.setRtmp(String.format("rtmp://%s:%s/rtp/%s", mediaInfo.getLocalIP(), mediaInfo.getRtmpPort(), streamId));
|
||||
streamInfoForPlay.setHls(String.format("http://%s:%s/rtp/%s/hls.m3u8", mediaInfo.getLocalIP(), mediaInfo.getHttpPort(), streamId));
|
||||
streamInfoForPlay.setRtsp(String.format("rtsp://%s:%s/rtp/%s", mediaInfo.getLocalIP(), mediaInfo.getRtspPort(), streamId));
|
||||
storager.startPlay(streamInfoForPlay);
|
||||
}
|
||||
|
||||
StreamInfo streamInfoForPlayBack = storager.queryPlayBlackBySSRC(ssrc);
|
||||
if ("rtp".equals(app) && streamInfoForPlayBack != null ) {
|
||||
MediaServerConfig mediaInfo = storager.getMediaInfo();
|
||||
streamInfoForPlayBack.setFlv(String.format("http://%s:%s/rtp/%s.flv", mediaInfo.getLocalIP(), mediaInfo.getHttpPort(), streamId));
|
||||
streamInfoForPlayBack.setWs_flv(String.format("ws://%s:%s/rtp/%s.flv", mediaInfo.getLocalIP(), mediaInfo.getHttpPort(), streamId));
|
||||
streamInfoForPlayBack.setRtmp(String.format("rtmp://%s:%s/rtp/%s", mediaInfo.getLocalIP(), mediaInfo.getRtmpPort(), streamId));
|
||||
streamInfoForPlayBack.setHls(String.format("http://%s:%s/rtp/%s/hls.m3u8", mediaInfo.getLocalIP(), mediaInfo.getHttpPort(), streamId));
|
||||
streamInfoForPlayBack.setRtsp(String.format("rtsp://%s:%s/rtp/%s", mediaInfo.getLocalIP(), mediaInfo.getRtspPort(), streamId));
|
||||
storager.startPlayBlack(streamInfoForPlayBack);
|
||||
}
|
||||
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
@@ -30,11 +30,6 @@ public class ZLMUtils {
|
||||
param.put("stream_id", streamId);
|
||||
JSONObject jsonObject = zlmresTfulUtils.openRtpServer(param);
|
||||
if (jsonObject.getInteger("code") == 0) {
|
||||
System.out.println(11111111);
|
||||
System.out.println(streamId);
|
||||
System.out.println(ssrc);
|
||||
System.out.println(newPort);
|
||||
System.out.println(jsonObject.toJSONString());
|
||||
return newPort;
|
||||
} else {
|
||||
return getNewRTPPort(ssrc);
|
||||
|
||||
@@ -183,4 +183,12 @@ public interface IVideoManagerStorager {
|
||||
StreamInfo queryPlayByDevice(String deviceId, String code);
|
||||
|
||||
Map<String, StreamInfo> queryPlayByDeviceId(String deviceId);
|
||||
|
||||
boolean startPlayBlack(StreamInfo streamInfo);
|
||||
|
||||
boolean stopPlayBlack(StreamInfo streamInfo);
|
||||
|
||||
StreamInfo queryPlayBlackByDevice(String deviceId, String channelId);
|
||||
|
||||
StreamInfo queryPlayBlackBySSRC(String ssrc);
|
||||
}
|
||||
|
||||
@@ -190,6 +190,27 @@ public class VideoManagerJdbcStoragerImpl implements IVideoManagerStorager {
|
||||
|
||||
@Override
|
||||
public Map<String, StreamInfo> queryPlayByDeviceId(String deviceId) {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean startPlayBlack(StreamInfo streamInfo) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean stopPlayBlack(StreamInfo streamInfo) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StreamInfo queryPlayBlackByDevice(String deviceId, String channelId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StreamInfo queryPlayBlackBySSRC(String ssrc) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ public class VideoManagerRedisStoragerImpl implements IVideoManagerStorager {
|
||||
|
||||
// 如果有父设备,更新父设备内子节点数
|
||||
String parentId = channel.getParentId();
|
||||
if (!StringUtils.isEmpty(parentId)) {
|
||||
if (!StringUtils.isEmpty(parentId) && !parentId.equals(deviceId)) {
|
||||
|
||||
if (channelMap.get(parentId) == null) {
|
||||
channelMap.put(parentId, new HashSet<String>());
|
||||
@@ -111,8 +111,6 @@ public class VideoManagerRedisStoragerImpl implements IVideoManagerStorager {
|
||||
DeviceChannel deviceChannel = queryChannel(deviceId, parentId);
|
||||
if (deviceChannel != null) {
|
||||
deviceChannel.setSubCount(channelMap.get(parentId).size());
|
||||
// redis.set(VideoManagerConstants.CACHEKEY_PREFIX+deviceId + "_" + deviceChannel.getChannelId(),
|
||||
// deviceChannel);
|
||||
redis.set(VideoManagerConstants.CACHEKEY_PREFIX + deviceId +
|
||||
"_" + deviceChannel.getChannelId() +
|
||||
"_" + (deviceChannel.getStatus() == 1 ? "on":"off") +
|
||||
@@ -410,6 +408,14 @@ public class VideoManagerRedisStoragerImpl implements IVideoManagerStorager {
|
||||
return (StreamInfo)redis.get(playLeys.get(0).toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public StreamInfo queryPlayBlackBySSRC(String ssrc) {
|
||||
// List<Object> playLeys = redis.keys(String.format("%S_%s_*", VideoManagerConstants.PLAYER_PREFIX, ssrc));
|
||||
List<Object> playLeys = redis.scan(String.format("%S_%s_*", VideoManagerConstants.PLAY_BLACK_PREFIX, ssrc));
|
||||
if (playLeys == null || playLeys.size() == 0) return null;
|
||||
return (StreamInfo)redis.get(playLeys.get(0).toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public StreamInfo queryPlayByDevice(String deviceId, String code) {
|
||||
// List<Object> playLeys = redis.keys(String.format("%S_*_%s_%s", VideoManagerConstants.PLAYER_PREFIX,
|
||||
@@ -448,7 +454,6 @@ public class VideoManagerRedisStoragerImpl implements IVideoManagerStorager {
|
||||
for (Device device : devices) {
|
||||
// 更新设备下的通道
|
||||
HashMap<String, HashSet<String>> channelMap = new HashMap<String, HashSet<String>>();
|
||||
// List<Object> deviceChannelList = redis.keys(VideoManagerConstants.CACHEKEY_PREFIX +
|
||||
List<Object> deviceChannelList = redis.scan(VideoManagerConstants.CACHEKEY_PREFIX +
|
||||
device.getDeviceId() + "_" + "*");
|
||||
if (deviceChannelList != null && deviceChannelList.size() > 0 ) {
|
||||
@@ -469,6 +474,7 @@ public class VideoManagerRedisStoragerImpl implements IVideoManagerStorager {
|
||||
}
|
||||
deviceMap.put(device.getDeviceId(),channelMap);
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -498,5 +504,37 @@ public class VideoManagerRedisStoragerImpl implements IVideoManagerStorager {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean startPlayBlack(StreamInfo stream) {
|
||||
return redis.set(String.format("%S_%s_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX, stream.getSsrc(),stream.getDeviceID(), stream.getCahnnelId()),
|
||||
stream);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean stopPlayBlack(StreamInfo streamInfo) {
|
||||
if (streamInfo == null) return false;
|
||||
DeviceChannel deviceChannel = queryChannel(streamInfo.getDeviceID(), streamInfo.getCahnnelId());
|
||||
if (deviceChannel != null) {
|
||||
deviceChannel.setSsrc(null);
|
||||
deviceChannel.setPlay(false);
|
||||
updateChannel(streamInfo.getDeviceID(), deviceChannel);
|
||||
}
|
||||
return redis.del(String.format("%S_%s_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX,
|
||||
streamInfo.getSsrc(),
|
||||
streamInfo.getDeviceID(),
|
||||
streamInfo.getCahnnelId()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public StreamInfo queryPlayBlackByDevice(String deviceId, String code) {
|
||||
String format = String.format("%S_*_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX,
|
||||
deviceId,
|
||||
code);
|
||||
List<Object> playLeys = redis.scan(String.format("%S_*_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX,
|
||||
deviceId,
|
||||
code));
|
||||
if (playLeys == null || playLeys.size() == 0) return null;
|
||||
return (StreamInfo)redis.get(playLeys.get(0).toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ public class PlayController {
|
||||
}else {
|
||||
streamInfo = storager.queryPlayByDevice(deviceId, channelId);
|
||||
JSONObject rtpInfo = zlmresTfulUtils.getRtpInfo(streamId);
|
||||
if (rtpInfo != null && rtpInfo.getBoolean("exist") && streamInfo.getFlv() != null){
|
||||
if (rtpInfo != null && rtpInfo.getBoolean("exist") && streamInfo != null && streamInfo.getFlv() != null){
|
||||
logger.info("RTP已推流,查询编码信息:"+streamInfo.getFlv());
|
||||
Thread.sleep(2000);
|
||||
JSONObject mediaInfo = zlmresTfulUtils.getMediaInfo("rtp", "rtmp", streamId);
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
package com.genersoft.iot.vmp.vmanager.playback;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.genersoft.iot.vmp.common.StreamInfo;
|
||||
import com.genersoft.iot.vmp.media.zlm.ZLMRESTfulUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -30,7 +34,10 @@ public class PlaybackController {
|
||||
|
||||
@Autowired
|
||||
private IVideoManagerStorager storager;
|
||||
|
||||
|
||||
@Autowired
|
||||
private ZLMRESTfulUtils zlmresTfulUtils;
|
||||
|
||||
@GetMapping("/playback/{deviceId}/{channelId}")
|
||||
public ResponseEntity<String> play(@PathVariable String deviceId,@PathVariable String channelId, String startTime, String endTime){
|
||||
|
||||
@@ -43,25 +50,70 @@ public class PlaybackController {
|
||||
logger.warn(log);
|
||||
return new ResponseEntity<String>(log,HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
|
||||
Device device = storager.queryVideoDevice(deviceId);
|
||||
String ssrc = cmder.playbackStreamCmd(device, channelId, startTime, endTime);
|
||||
StreamInfo streamInfo = storager.queryPlayBlackByDevice(deviceId, channelId);
|
||||
|
||||
if (streamInfo != null) {
|
||||
cmder.streamByeCmd(streamInfo.getSsrc());
|
||||
}
|
||||
|
||||
// }else {
|
||||
// String streamId = String.format("%08x", Integer.parseInt(streamInfo.getSsrc())).toUpperCase();
|
||||
// JSONObject rtpInfo = zlmresTfulUtils.getRtpInfo(streamId);
|
||||
// if (rtpInfo.getBoolean("exist")) {
|
||||
// return new ResponseEntity<String>(JSON.toJSONString(streamInfo),HttpStatus.OK);
|
||||
// }else {
|
||||
// storager.stopPlayBlack(streamInfo);
|
||||
// streamInfo = cmder.playbackStreamCmd(device, channelId, startTime, endTime);
|
||||
// }
|
||||
// }
|
||||
streamInfo = cmder.playbackStreamCmd(device, channelId, startTime, endTime);
|
||||
|
||||
String streamId = String.format("%08x", Integer.parseInt(streamInfo.getSsrc())).toUpperCase();
|
||||
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("设备回放 API调用,ssrc:"+ssrc+",ZLMedia streamId:"+Integer.toHexString(Integer.parseInt(ssrc)));
|
||||
logger.debug("设备回放 API调用,ssrc:" + streamInfo.getSsrc() + ",ZLMedia streamId:" + streamId);
|
||||
}
|
||||
|
||||
if(ssrc!=null) {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("ssrc", ssrc);
|
||||
return new ResponseEntity<String>(json.toString(),HttpStatus.OK);
|
||||
// 等待推流, TODO 默认超时15s
|
||||
boolean lockFlag = true;
|
||||
long lockStartTime = System.currentTimeMillis();
|
||||
while (lockFlag) {
|
||||
try {
|
||||
if (System.currentTimeMillis() - lockStartTime > 75 * 1000) {
|
||||
storager.stopPlayBlack(streamInfo);
|
||||
return new ResponseEntity<String>("timeout",HttpStatus.OK);
|
||||
}else {
|
||||
streamInfo = storager.queryPlayBlackByDevice(deviceId, channelId);
|
||||
JSONObject rtpInfo = zlmresTfulUtils.getRtpInfo(streamId);
|
||||
if (rtpInfo != null && rtpInfo.getBoolean("exist") && streamInfo.getFlv() != null){
|
||||
JSONObject mediaInfo = zlmresTfulUtils.getMediaInfo("rtp", "rtmp", streamId);
|
||||
if (mediaInfo.getInteger("code") == 0 && mediaInfo.getBoolean("online")) {
|
||||
lockFlag = false;
|
||||
JSONArray tracks = mediaInfo.getJSONArray("tracks");
|
||||
streamInfo.setTracks(tracks);
|
||||
storager.startPlayBlack(streamInfo);
|
||||
}else {
|
||||
|
||||
}
|
||||
}else {
|
||||
Thread.sleep(2000);
|
||||
continue;
|
||||
};
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if(streamInfo!=null) {
|
||||
return new ResponseEntity<String>(JSON.toJSONString(streamInfo),HttpStatus.OK);
|
||||
} else {
|
||||
logger.warn("设备回放API调用失败!");
|
||||
return new ResponseEntity<String>(HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("/playback/{ssrc}/stop")
|
||||
@RequestMapping("/playback/{ssrc}/stop")
|
||||
public ResponseEntity<String> playStop(@PathVariable String ssrc){
|
||||
|
||||
cmder.streamByeCmd(ssrc);
|
||||
|
||||
Reference in New Issue
Block a user