增加推流转发到国标,尚不完善
This commit is contained in:
@@ -12,6 +12,7 @@ public class GbStream extends PlatformGbStream{
|
||||
private double longitude;
|
||||
private double latitude;
|
||||
private String streamType;
|
||||
private boolean status;
|
||||
|
||||
public String getApp() {
|
||||
return app;
|
||||
@@ -68,4 +69,12 @@ public class GbStream extends PlatformGbStream{
|
||||
public void setStreamType(String streamType) {
|
||||
this.streamType = streamType;
|
||||
}
|
||||
|
||||
public boolean isStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(boolean status) {
|
||||
this.status = status;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,4 +28,5 @@ public class PlatformGbStream {
|
||||
public void setPlatformId(String platformId) {
|
||||
this.platformId = platformId;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommanderFroPlatform;
|
||||
import com.genersoft.iot.vmp.media.zlm.ZLMRTPServerFactory;
|
||||
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.response.impl.*;
|
||||
import com.genersoft.iot.vmp.vmanager.service.IPlayService;
|
||||
import com.genersoft.iot.vmp.service.IPlayService;
|
||||
// import org.slf4j.Logger;
|
||||
// import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
@@ -13,24 +13,20 @@ import javax.sip.message.Response;
|
||||
|
||||
import com.genersoft.iot.vmp.conf.MediaServerConfig;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.*;
|
||||
import com.genersoft.iot.vmp.gb28181.event.SipSubscribe;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommanderFroPlatform;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.request.SIPRequestAbstractProcessor;
|
||||
import com.genersoft.iot.vmp.media.zlm.ZLMHttpHookSubscribe;
|
||||
import com.genersoft.iot.vmp.media.zlm.ZLMRTPServerFactory;
|
||||
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
||||
import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
|
||||
import com.genersoft.iot.vmp.vmanager.play.bean.PlayResult;
|
||||
import com.genersoft.iot.vmp.vmanager.service.IPlayService;
|
||||
import com.genersoft.iot.vmp.service.IPlayService;
|
||||
import gov.nist.javax.sip.address.AddressImpl;
|
||||
import gov.nist.javax.sip.address.SipUri;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Vector;
|
||||
|
||||
/**
|
||||
|
||||
@@ -549,7 +549,7 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor {
|
||||
deviceChannel.setLatitude(gbStream.getLatitude());
|
||||
deviceChannel.setDeviceId(parentPlatform.getDeviceGBId());
|
||||
deviceChannel.setManufacture("wvp-pro");
|
||||
deviceChannel.setStatus(1);
|
||||
deviceChannel.setStatus(gbStream.isStatus()?1:0);
|
||||
// deviceChannel.setParentId(parentPlatform.getDeviceGBId());
|
||||
deviceChannel.setRegisterWay(1);
|
||||
deviceChannel.setCivilCode(cmder.getSipConfig().getSipDomain());
|
||||
|
||||
@@ -9,7 +9,7 @@ import com.genersoft.iot.vmp.conf.MediaServerConfig;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.Device;
|
||||
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
||||
import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
|
||||
import com.genersoft.iot.vmp.vmanager.service.IPlayService;
|
||||
import com.genersoft.iot.vmp.service.IPlayService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -240,8 +240,9 @@ public class ZLMHttpHookListener {
|
||||
String streamId = json.getString("stream");
|
||||
String schema = json.getString("schema");
|
||||
boolean regist = json.getBoolean("regist");
|
||||
StreamInfo streamInfo = redisCatchStorage.queryPlayByStreamId(streamId);
|
||||
|
||||
if ("rtp".equals(app) && !regist ) {
|
||||
StreamInfo streamInfo = redisCatchStorage.queryPlayByStreamId(streamId);
|
||||
if (streamInfo!=null){
|
||||
redisCatchStorage.stopPlay(streamInfo);
|
||||
storager.stopPlay(streamInfo.getDeviceID(), streamInfo.getChannelId());
|
||||
@@ -250,8 +251,12 @@ public class ZLMHttpHookListener {
|
||||
redisCatchStorage.stopPlayback(streamInfo);
|
||||
}
|
||||
}else {
|
||||
if (!"rtp".equals(app) && "rtsp".equals(schema)){
|
||||
zlmMediaListManager.updateMediaList();
|
||||
if (!"rtp".equals(app) && "rtmp".equals(schema)){
|
||||
if (regist) {
|
||||
zlmMediaListManager.addMedia(app, streamId);
|
||||
}else {
|
||||
zlmMediaListManager.removeMedia(app, streamId);
|
||||
}
|
||||
}
|
||||
}
|
||||
JSONObject ret = new JSONObject();
|
||||
|
||||
@@ -70,6 +70,11 @@ public class ZLMHttpHookSubscribe {
|
||||
return event;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取某个类型的所有的订阅
|
||||
* @param type
|
||||
* @return
|
||||
*/
|
||||
public List<ZLMHttpHookSubscribe.Event> getSubscribes(HookType type) {
|
||||
ZLMHttpHookSubscribe.Event event= null;
|
||||
Map<JSONObject, Event> eventMap = allSubscribes.get(type);
|
||||
|
||||
@@ -1,19 +1,20 @@
|
||||
package com.genersoft.iot.vmp.media.zlm;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson.TypeReference;
|
||||
import com.genersoft.iot.vmp.common.RealVideo;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.SendRtpItem;
|
||||
import com.genersoft.iot.vmp.gb28181.session.SsrcUtil;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.StreamProxyItem;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.StreamPushItem;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.GbStream;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.MediaItem;
|
||||
import com.genersoft.iot.vmp.service.IStreamPushService;
|
||||
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
||||
import com.genersoft.iot.vmp.storager.impl.RedisCatchStorageImpl;
|
||||
import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
|
||||
import com.genersoft.iot.vmp.storager.dao.GbStreamMapper;
|
||||
import com.genersoft.iot.vmp.storager.dao.PlatformGbStreamMapper;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.*;
|
||||
@@ -29,60 +30,79 @@ public class ZLMMediaListManager {
|
||||
@Autowired
|
||||
private IRedisCatchStorage redisCatchStorage;
|
||||
|
||||
@Autowired
|
||||
private IVideoManagerStorager storager;
|
||||
|
||||
@Autowired
|
||||
private GbStreamMapper gbStreamMapper;
|
||||
|
||||
@Autowired
|
||||
private PlatformGbStreamMapper platformGbStreamMapper;
|
||||
|
||||
@Autowired
|
||||
private IStreamPushService streamPushService;
|
||||
|
||||
|
||||
public void updateMediaList() {
|
||||
JSONObject mediaList = zlmresTfulUtils.getMediaList();
|
||||
if (mediaList == null) return;
|
||||
String dataStr = mediaList.getString("data");
|
||||
storager.clearMediaList();
|
||||
|
||||
Integer code = mediaList.getInteger("code");
|
||||
Map<String, RealVideo> result = new HashMap<>();
|
||||
if (code == 0 ) {
|
||||
if (dataStr != null) {
|
||||
List<MediaItem> mediaItems = JSON.parseObject(dataStr, new TypeReference<List<MediaItem>>() {});
|
||||
for (MediaItem item : mediaItems) {
|
||||
if ("rtp".equals(item.getApp())) {
|
||||
continue;
|
||||
}
|
||||
String key = item.getApp() + "_" + item.getStream();
|
||||
RealVideo realVideo = result.get(key);
|
||||
if (realVideo == null) {
|
||||
realVideo = new RealVideo();
|
||||
realVideo.setApp(item.getApp());
|
||||
realVideo.setStream(item.getStream());
|
||||
realVideo.setAliveSecond(item.getAliveSecond());
|
||||
realVideo.setCreateStamp(item.getCreateStamp());
|
||||
realVideo.setOriginSock(item.getOriginSock());
|
||||
realVideo.setTotalReaderCount(item.getTotalReaderCount());
|
||||
realVideo.setOriginType(item.getOriginType());
|
||||
realVideo.setOriginTypeStr(item.getOriginTypeStr());
|
||||
realVideo.setOriginUrl(item.getOriginUrl());
|
||||
realVideo.setCreateStamp(item.getCreateStamp());
|
||||
realVideo.setAliveSecond(item.getAliveSecond());
|
||||
// 使用异步的当时更新媒体流列表
|
||||
zlmresTfulUtils.getMediaList((mediaList ->{
|
||||
if (mediaList == null) return;
|
||||
String dataStr = mediaList.getString("data");
|
||||
|
||||
ArrayList<RealVideo.MediaSchema> mediaSchemas = new ArrayList<>();
|
||||
realVideo.setSchemas(mediaSchemas);
|
||||
realVideo.setTracks(item.getTracks());
|
||||
realVideo.setVhost(item.getVhost());
|
||||
result.put(key, realVideo);
|
||||
}
|
||||
|
||||
RealVideo.MediaSchema mediaSchema = new RealVideo.MediaSchema();
|
||||
mediaSchema.setSchema(item.getSchema());
|
||||
mediaSchema.setBytesSpeed(item.getBytesSpeed());
|
||||
realVideo.getSchemas().add(mediaSchema);
|
||||
Integer code = mediaList.getInteger("code");
|
||||
Map<String, StreamPushItem> result = new HashMap<>();
|
||||
List<StreamPushItem> streamPushItems = null;
|
||||
// 获取所有的国标关联
|
||||
List<GbStream> gbStreams = gbStreamMapper.selectAll();
|
||||
if (code == 0 ) {
|
||||
if (dataStr != null) {
|
||||
streamPushItems = streamPushService.handleJSON(dataStr);
|
||||
}
|
||||
|
||||
}else {
|
||||
logger.warn("更新视频流失败,错误code: " + code);
|
||||
}
|
||||
}else {
|
||||
logger.warn("更新视频流失败,错误code: " + code);
|
||||
}
|
||||
|
||||
List<RealVideo> realVideos = new ArrayList<>(result.values());
|
||||
Collections.sort(realVideos);
|
||||
redisCatchStorage.updateMediaList(realVideos);
|
||||
if (streamPushItems != null) {
|
||||
storager.updateMediaList(streamPushItems);
|
||||
}
|
||||
}));
|
||||
|
||||
}
|
||||
|
||||
public void addMedia(String app, String streamId) {
|
||||
//使用异步更新推流
|
||||
zlmresTfulUtils.getMediaList(app, streamId, "rtmp", json->{
|
||||
|
||||
if (json == null) return;
|
||||
String dataStr = json.getString("data");
|
||||
|
||||
Integer code = json.getInteger("code");
|
||||
Map<String, StreamPushItem> result = new HashMap<>();
|
||||
List<StreamPushItem> streamPushItems = null;
|
||||
if (code == 0 ) {
|
||||
if (dataStr != null) {
|
||||
streamPushItems = streamPushService.handleJSON(dataStr);
|
||||
}
|
||||
}else {
|
||||
logger.warn("更新视频流失败,错误code: " + code);
|
||||
}
|
||||
|
||||
if (streamPushItems != null && streamPushItems.size() == 1) {
|
||||
storager.updateMedia(streamPushItems.get(0));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void removeMedia(String app, String streamId) {
|
||||
// 查找是否关联了国标, 关联了不删除, 置为离线
|
||||
StreamProxyItem streamProxyItem = gbStreamMapper.selectOne(app, streamId);
|
||||
if (streamProxyItem == null) {
|
||||
storager.removeMedia(app, streamId);
|
||||
}else {
|
||||
storager.mediaOutline(app, streamId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.genersoft.iot.vmp.media.zlm;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import okhttp3.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
@@ -27,7 +28,11 @@ public class ZLMRESTfulUtils {
|
||||
@Value("${media.secret}")
|
||||
private String mediaSecret;
|
||||
|
||||
public JSONObject sendPost(String api, Map<String, Object> param) {
|
||||
public interface RequestCallback{
|
||||
void run(JSONObject response);
|
||||
}
|
||||
|
||||
public JSONObject sendPost(String api, Map<String, Object> param, RequestCallback callback) {
|
||||
OkHttpClient client = new OkHttpClient();
|
||||
String url = String.format("http://%s:%s/index/api/%s", mediaIp, mediaPort, api);
|
||||
JSONObject responseJSON = null;
|
||||
@@ -47,34 +52,68 @@ public class ZLMRESTfulUtils {
|
||||
.post(body)
|
||||
.url(url)
|
||||
.build();
|
||||
try {
|
||||
Response response = client.newCall(request).execute();
|
||||
if (response.isSuccessful()) {
|
||||
String responseStr = response.body().string();
|
||||
if (responseStr != null) {
|
||||
responseJSON = JSON.parseObject(responseStr);
|
||||
if (callback == null) {
|
||||
try {
|
||||
Response response = client.newCall(request).execute();
|
||||
if (response.isSuccessful()) {
|
||||
String responseStr = response.body().string();
|
||||
if (responseStr != null) {
|
||||
responseJSON = JSON.parseObject(responseStr);
|
||||
}
|
||||
}
|
||||
} catch (ConnectException e) {
|
||||
logger.error(String.format("连接ZLM失败: %s, %s", e.getCause().getMessage(), e.getMessage()));
|
||||
logger.info("请检查media配置并确认ZLM已启动...");
|
||||
}catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}else {
|
||||
client.newCall(request).enqueue(new Callback(){
|
||||
|
||||
@Override
|
||||
public void onResponse(@NotNull Call call, @NotNull Response response){
|
||||
if (response.isSuccessful()) {
|
||||
try {
|
||||
String responseStr = response.body().string();
|
||||
if (responseStr != null) {
|
||||
callback.run(JSON.parseObject(responseStr));
|
||||
}else {
|
||||
callback.run(null);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NotNull Call call, @NotNull IOException e) {
|
||||
logger.error(String.format("连接ZLM失败: %s, %s", e.getCause().getMessage(), e.getMessage()));
|
||||
logger.info("请检查media配置并确认ZLM已启动...");
|
||||
}
|
||||
});
|
||||
}
|
||||
} catch (ConnectException e) {
|
||||
logger.error(String.format("连接ZLM失败: %s, %s", e.getCause().getMessage(), e.getMessage()));
|
||||
logger.info("请检查media配置并确认ZLM已启动...");
|
||||
}catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
|
||||
return responseJSON;
|
||||
}
|
||||
|
||||
public JSONObject getMediaList(String app, String schema){
|
||||
public JSONObject getMediaList(String app, String stream, String schema, RequestCallback callback){
|
||||
Map<String, Object> param = new HashMap<>();
|
||||
param.put("app",app);
|
||||
param.put("schema",schema);
|
||||
if (app != null) param.put("app",app);
|
||||
if (stream != null) param.put("stream",stream);
|
||||
if (schema != null) param.put("schema",schema);
|
||||
param.put("vhost","__defaultVhost__");
|
||||
return sendPost("getMediaList",param);
|
||||
return sendPost("getMediaList",param, callback);
|
||||
}
|
||||
|
||||
public JSONObject getMediaList(){
|
||||
return sendPost("getMediaList",null);
|
||||
public JSONObject getMediaList(String app, String stream){
|
||||
return getMediaList(app, stream,null, null);
|
||||
}
|
||||
|
||||
public JSONObject getMediaList(RequestCallback callback){
|
||||
return sendPost("getMediaList",null, callback);
|
||||
}
|
||||
|
||||
public JSONObject getMediaInfo(String app, String schema, String stream){
|
||||
@@ -83,13 +122,13 @@ public class ZLMRESTfulUtils {
|
||||
param.put("schema",schema);
|
||||
param.put("stream",stream);
|
||||
param.put("vhost","__defaultVhost__");
|
||||
return sendPost("getMediaInfo",param);
|
||||
return sendPost("getMediaInfo",param, null);
|
||||
}
|
||||
|
||||
public JSONObject getRtpInfo(String stream_id){
|
||||
Map<String, Object> param = new HashMap<>();
|
||||
param.put("stream_id",stream_id);
|
||||
return sendPost("getRtpInfo",param);
|
||||
return sendPost("getRtpInfo",param, null);
|
||||
}
|
||||
|
||||
public JSONObject addFFmpegSource(String src_url, String dst_url, String timeout_ms){
|
||||
@@ -99,37 +138,37 @@ public class ZLMRESTfulUtils {
|
||||
param.put("src_url", src_url);
|
||||
param.put("dst_url", dst_url);
|
||||
param.put("timeout_ms", timeout_ms);
|
||||
return sendPost("addFFmpegSource",param);
|
||||
return sendPost("addFFmpegSource",param, null);
|
||||
}
|
||||
|
||||
public JSONObject delFFmpegSource(String key){
|
||||
Map<String, Object> param = new HashMap<>();
|
||||
param.put("key", key);
|
||||
return sendPost("delFFmpegSource",param);
|
||||
return sendPost("delFFmpegSource",param, null);
|
||||
}
|
||||
|
||||
public JSONObject getMediaServerConfig(){
|
||||
return sendPost("getServerConfig",null);
|
||||
return sendPost("getServerConfig",null, null);
|
||||
}
|
||||
|
||||
public JSONObject setServerConfig(Map<String, Object> param){
|
||||
return sendPost("setServerConfig",param);
|
||||
return sendPost("setServerConfig",param, null);
|
||||
}
|
||||
|
||||
public JSONObject openRtpServer(Map<String, Object> param){
|
||||
return sendPost("openRtpServer",param);
|
||||
return sendPost("openRtpServer",param, null);
|
||||
}
|
||||
|
||||
public JSONObject closeRtpServer(Map<String, Object> param) {
|
||||
return sendPost("closeRtpServer",param);
|
||||
return sendPost("closeRtpServer",param, null);
|
||||
}
|
||||
|
||||
public JSONObject startSendRtp(Map<String, Object> param) {
|
||||
return sendPost("startSendRtp",param);
|
||||
return sendPost("startSendRtp",param, null);
|
||||
}
|
||||
|
||||
public JSONObject stopSendRtp(Map<String, Object> param) {
|
||||
return sendPost("stopSendRtp",param);
|
||||
return sendPost("stopSendRtp",param, null);
|
||||
}
|
||||
|
||||
public JSONObject addStreamProxy(String app, String stream, String url, boolean enable_hls, boolean enable_mp4, String rtp_type) {
|
||||
@@ -141,7 +180,7 @@ public class ZLMRESTfulUtils {
|
||||
param.put("enable_hls", enable_hls?1:0);
|
||||
param.put("enable_mp4", enable_mp4?1:0);
|
||||
param.put("rtp_type", rtp_type);
|
||||
return sendPost("addStreamProxy",param);
|
||||
return sendPost("addStreamProxy",param, null);
|
||||
}
|
||||
|
||||
public JSONObject closeStreams(String app, String stream) {
|
||||
@@ -150,6 +189,6 @@ public class ZLMRESTfulUtils {
|
||||
param.put("app", app);
|
||||
param.put("stream", stream);
|
||||
param.put("force", 1);
|
||||
return sendPost("close_streams",param);
|
||||
return sendPost("close_streams",param, null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import com.genersoft.iot.vmp.media.zlm.dto.StreamProxyItem;
|
||||
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
||||
//import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
|
||||
import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
|
||||
import com.genersoft.iot.vmp.vmanager.service.IStreamProxyService;
|
||||
import com.genersoft.iot.vmp.service.IStreamProxyService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -75,9 +75,8 @@ public class ZLMRunner implements CommandLineRunner {
|
||||
|
||||
@Override
|
||||
public void run(String... strings) throws Exception {
|
||||
JSONObject subscribeKey = new JSONObject();
|
||||
// 订阅 zlm启动事件
|
||||
hookSubscribe.addSubscribe(ZLMHttpHookSubscribe.HookType.on_server_started,subscribeKey,(response)->{
|
||||
hookSubscribe.addSubscribe(ZLMHttpHookSubscribe.HookType.on_server_started,null,(response)->{
|
||||
MediaServerConfig mediaServerConfig = JSONObject.toJavaObject(response, MediaServerConfig.class);
|
||||
zLmRunning(mediaServerConfig);
|
||||
});
|
||||
@@ -155,7 +154,7 @@ public class ZLMRunner implements CommandLineRunner {
|
||||
logger.info("zlm接入成功...");
|
||||
if (autoConfig) saveZLMConfig();
|
||||
MediaServerConfig mediaInfo = redisCatchStorage.getMediaInfo();
|
||||
if (System.currentTimeMillis() - mediaInfo.getUpdateTime() < 50){
|
||||
if (mediaInfo != null && System.currentTimeMillis() - mediaInfo.getUpdateTime() < 50){
|
||||
logger.info("zlm刚刚更新,忽略这次更新");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
package com.genersoft.iot.vmp.common;
|
||||
package com.genersoft.iot.vmp.media.zlm.dto;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.MediaItem;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.GbStream;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class RealVideo implements Comparable<RealVideo>{
|
||||
public class StreamPushItem extends GbStream implements Comparable<StreamPushItem>{
|
||||
|
||||
/**
|
||||
* 应用名
|
||||
@@ -85,9 +84,10 @@ public class RealVideo implements Comparable<RealVideo>{
|
||||
this.vhost = vhost;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int compareTo(@NotNull RealVideo realVideo) {
|
||||
return new Long(this.createStamp - realVideo.getCreateStamp().intValue()).intValue();
|
||||
public int compareTo(@NotNull StreamPushItem streamPushItem) {
|
||||
return new Long(this.createStamp - streamPushItem.getCreateStamp().intValue()).intValue();
|
||||
}
|
||||
|
||||
public static class MediaSchema {
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.genersoft.iot.vmp.vmanager.service;
|
||||
package com.genersoft.iot.vmp.service;
|
||||
|
||||
import com.genersoft.iot.vmp.gb28181.bean.GbStream;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.PlatformGbStream;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
|
||||
import java.util.List;
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.genersoft.iot.vmp.vmanager.service;
|
||||
package com.genersoft.iot.vmp.service;
|
||||
|
||||
import com.genersoft.iot.vmp.common.StreamInfo;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.GbStream;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.PlatformGbStream;
|
||||
|
||||
/**
|
||||
* 媒体信息业务
|
||||
@@ -22,4 +24,5 @@ public interface IMediaService {
|
||||
* @return
|
||||
*/
|
||||
StreamInfo getStreamInfoByAppAndStream(String app, String stream);
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.genersoft.iot.vmp.vmanager.service;
|
||||
package com.genersoft.iot.vmp.service;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.genersoft.iot.vmp.gb28181.event.SipSubscribe;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.genersoft.iot.vmp.vmanager.service;
|
||||
package com.genersoft.iot.vmp.service;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.StreamProxyItem;
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.genersoft.iot.vmp.service;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.GbStream;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.StreamProxyItem;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.StreamPushItem;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface IStreamPushService {
|
||||
|
||||
List<StreamPushItem> handleJSON(String json);
|
||||
|
||||
/**
|
||||
* 将应用名和流ID加入国标关联
|
||||
* @param stream
|
||||
* @return
|
||||
*/
|
||||
boolean saveToGB(GbStream stream);
|
||||
|
||||
/**
|
||||
* 将应用名和流ID移出国标关联
|
||||
* @param stream
|
||||
* @return
|
||||
*/
|
||||
boolean removeFromGB(GbStream stream);
|
||||
|
||||
/**
|
||||
* 获取
|
||||
* @param page
|
||||
* @param count
|
||||
* @return
|
||||
*/
|
||||
PageInfo<StreamPushItem> getPushList(Integer page, Integer count);
|
||||
}
|
||||
@@ -1,12 +1,9 @@
|
||||
package com.genersoft.iot.vmp.vmanager.service.impl;
|
||||
package com.genersoft.iot.vmp.service.impl;
|
||||
|
||||
import com.genersoft.iot.vmp.gb28181.bean.GbStream;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.PlatformGbStream;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.StreamProxyItem;
|
||||
import com.genersoft.iot.vmp.storager.dao.GbStreamMapper;
|
||||
import com.genersoft.iot.vmp.storager.dao.PlarfotmGbStreamMapper;
|
||||
import com.genersoft.iot.vmp.vmanager.platform.PlatformController;
|
||||
import com.genersoft.iot.vmp.vmanager.service.IGbStreamService;
|
||||
import com.genersoft.iot.vmp.storager.dao.PlatformGbStreamMapper;
|
||||
import com.genersoft.iot.vmp.service.IGbStreamService;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import org.slf4j.Logger;
|
||||
@@ -34,7 +31,7 @@ public class GbStreamServiceImpl implements IGbStreamService {
|
||||
private GbStreamMapper gbStreamMapper;
|
||||
|
||||
@Autowired
|
||||
private PlarfotmGbStreamMapper plarfotmGbStreamMapper;
|
||||
private PlatformGbStreamMapper platformGbStreamMapper;
|
||||
|
||||
@Override
|
||||
public PageInfo<GbStream> getAll(Integer page, Integer count) {
|
||||
@@ -57,7 +54,7 @@ public class GbStreamServiceImpl implements IGbStreamService {
|
||||
try {
|
||||
for (GbStream gbStream : gbStreams) {
|
||||
gbStream.setPlatformId(platformId);
|
||||
plarfotmGbStreamMapper.add(gbStream);
|
||||
platformGbStreamMapper.add(gbStream);
|
||||
}
|
||||
dataSourceTransactionManager.commit(transactionStatus); //手动提交
|
||||
result = true;
|
||||
@@ -76,7 +73,7 @@ public class GbStreamServiceImpl implements IGbStreamService {
|
||||
TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition);
|
||||
try {
|
||||
for (GbStream gbStream : gbStreams) {
|
||||
plarfotmGbStreamMapper.delByAppAndStream(gbStream.getApp(), gbStream.getStream());
|
||||
platformGbStreamMapper.delByAppAndStream(gbStream.getApp(), gbStream.getStream());
|
||||
}
|
||||
dataSourceTransactionManager.commit(transactionStatus); //手动提交
|
||||
result = true;
|
||||
@@ -1,13 +1,14 @@
|
||||
package com.genersoft.iot.vmp.vmanager.service.impl;
|
||||
package com.genersoft.iot.vmp.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.genersoft.iot.vmp.common.StreamInfo;
|
||||
import com.genersoft.iot.vmp.conf.MediaServerConfig;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.GbStream;
|
||||
import com.genersoft.iot.vmp.media.zlm.ZLMRESTfulUtils;
|
||||
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
||||
import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
|
||||
import com.genersoft.iot.vmp.vmanager.service.IMediaService;
|
||||
import com.genersoft.iot.vmp.vmanager.service.IStreamProxyService;
|
||||
import com.genersoft.iot.vmp.service.IMediaService;
|
||||
import com.genersoft.iot.vmp.storager.dao.GbStreamMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -23,6 +24,8 @@ public class MediaServiceImpl implements IMediaService {
|
||||
@Autowired
|
||||
private ZLMRESTfulUtils zlmresTfulUtils;
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public StreamInfo getStreamInfoByAppAndStream(String app, String stream) {
|
||||
MediaServerConfig mediaInfo = redisCatchStorage.getMediaInfo();
|
||||
@@ -51,4 +54,7 @@ public class MediaServiceImpl implements IMediaService {
|
||||
}
|
||||
return streamInfo;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -1,9 +1,8 @@
|
||||
package com.genersoft.iot.vmp.vmanager.service.impl;
|
||||
package com.genersoft.iot.vmp.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.genersoft.iot.vmp.common.StreamInfo;
|
||||
import com.genersoft.iot.vmp.conf.MediaServerConfig;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.Device;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
|
||||
import com.genersoft.iot.vmp.gb28181.event.SipSubscribe;
|
||||
@@ -15,8 +14,8 @@ import com.genersoft.iot.vmp.media.zlm.ZLMRESTfulUtils;
|
||||
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
||||
import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
|
||||
import com.genersoft.iot.vmp.vmanager.play.bean.PlayResult;
|
||||
import com.genersoft.iot.vmp.vmanager.service.IMediaService;
|
||||
import com.genersoft.iot.vmp.vmanager.service.IPlayService;
|
||||
import com.genersoft.iot.vmp.service.IMediaService;
|
||||
import com.genersoft.iot.vmp.service.IPlayService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.genersoft.iot.vmp.vmanager.service.impl;
|
||||
package com.genersoft.iot.vmp.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.genersoft.iot.vmp.conf.MediaServerConfig;
|
||||
@@ -7,9 +7,9 @@ import com.genersoft.iot.vmp.media.zlm.dto.StreamProxyItem;
|
||||
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
||||
import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
|
||||
import com.genersoft.iot.vmp.storager.dao.GbStreamMapper;
|
||||
import com.genersoft.iot.vmp.storager.dao.PlarfotmGbStreamMapper;
|
||||
import com.genersoft.iot.vmp.storager.dao.PlatformGbStreamMapper;
|
||||
import com.genersoft.iot.vmp.storager.dao.StreamProxyMapper;
|
||||
import com.genersoft.iot.vmp.vmanager.service.IStreamProxyService;
|
||||
import com.genersoft.iot.vmp.service.IStreamProxyService;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -36,7 +36,7 @@ public class StreamProxyServiceImpl implements IStreamProxyService {
|
||||
private GbStreamMapper gbStreamMapper;
|
||||
|
||||
@Autowired
|
||||
private PlarfotmGbStreamMapper plarfotmGbStreamMapper;
|
||||
private PlatformGbStreamMapper platformGbStreamMapper;
|
||||
|
||||
|
||||
@Override
|
||||
@@ -94,7 +94,7 @@ public class StreamProxyServiceImpl implements IStreamProxyService {
|
||||
videoManagerStorager.deleteStreamProxy(app, stream);
|
||||
// 如果关联了国标那么移除关联
|
||||
gbStreamMapper.del(app, stream);
|
||||
plarfotmGbStreamMapper.delByAppAndStream(app, stream);
|
||||
platformGbStreamMapper.delByAppAndStream(app, stream);
|
||||
// TODO 如果关联的推流, 那么状态设置为离线
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
package com.genersoft.iot.vmp.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson.TypeReference;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.GbStream;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.MediaItem;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.StreamProxyItem;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.StreamPushItem;
|
||||
import com.genersoft.iot.vmp.service.IStreamPushService;
|
||||
import com.genersoft.iot.vmp.storager.dao.GbStreamMapper;
|
||||
import com.genersoft.iot.vmp.storager.dao.StreamPushMapper;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
public class StreamPushServiceImpl implements IStreamPushService {
|
||||
|
||||
@Autowired
|
||||
private GbStreamMapper gbStreamMapper;
|
||||
|
||||
@Autowired
|
||||
private StreamPushMapper streamPushMapper;
|
||||
|
||||
@Override
|
||||
public List<StreamPushItem> handleJSON(String jsonData) {
|
||||
if (jsonData == null) return null;
|
||||
|
||||
Map<String, StreamPushItem> result = new HashMap<>();
|
||||
|
||||
List<MediaItem> mediaItems = JSON.parseObject(jsonData, new TypeReference<List<MediaItem>>() {});
|
||||
for (MediaItem item : mediaItems) {
|
||||
|
||||
// 不保存国标推理以及拉流代理的流
|
||||
if (item.getOriginType() == 3 || item.getOriginType() == 4 || item.getOriginType() == 5) {
|
||||
continue;
|
||||
}
|
||||
String key = item.getApp() + "_" + item.getStream();
|
||||
StreamPushItem streamPushItem = result.get(key);
|
||||
if (streamPushItem == null) {
|
||||
streamPushItem = new StreamPushItem();
|
||||
streamPushItem.setApp(item.getApp());
|
||||
streamPushItem.setStream(item.getStream());
|
||||
streamPushItem.setAliveSecond(item.getAliveSecond());
|
||||
streamPushItem.setCreateStamp(item.getCreateStamp());
|
||||
streamPushItem.setOriginSock(item.getOriginSock());
|
||||
streamPushItem.setTotalReaderCount(item.getTotalReaderCount());
|
||||
streamPushItem.setOriginType(item.getOriginType());
|
||||
streamPushItem.setOriginTypeStr(item.getOriginTypeStr());
|
||||
streamPushItem.setOriginUrl(item.getOriginUrl());
|
||||
streamPushItem.setCreateStamp(item.getCreateStamp());
|
||||
streamPushItem.setAliveSecond(item.getAliveSecond());
|
||||
streamPushItem.setStatus(true);
|
||||
streamPushItem.setVhost(item.getVhost());
|
||||
result.put(key, streamPushItem);
|
||||
}
|
||||
}
|
||||
|
||||
return new ArrayList<>(result.values());
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageInfo<StreamPushItem> getPushList(Integer page, Integer count) {
|
||||
PageHelper.startPage(page, count);
|
||||
List<StreamPushItem> all = streamPushMapper.selectAll();
|
||||
return new PageInfo<>(all);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean saveToGB(GbStream stream) {
|
||||
stream.setStreamType("push");
|
||||
stream.setStatus(true);
|
||||
int add = gbStreamMapper.add(stream);
|
||||
return add > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeFromGB(GbStream stream) {
|
||||
int del = gbStreamMapper.del(stream.getApp(), stream.getStream());
|
||||
return del > 0;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.genersoft.iot.vmp.storager;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.genersoft.iot.vmp.common.RealVideo;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.StreamPushItem;
|
||||
import com.genersoft.iot.vmp.common.StreamInfo;
|
||||
import com.genersoft.iot.vmp.conf.MediaServerConfig;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
|
||||
@@ -107,15 +107,4 @@ public interface IRedisCatchStorage {
|
||||
*/
|
||||
boolean isChannelSendingRTP(String channelId);
|
||||
|
||||
/**
|
||||
* 更新媒体流列表
|
||||
* @param mediaList
|
||||
*/
|
||||
void updateMediaList(List<RealVideo> mediaList);
|
||||
|
||||
/**
|
||||
* 获取当前媒体流列表
|
||||
* @return List<RealVideo>
|
||||
*/
|
||||
JSONObject getMediaList(int start, int end);
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import java.util.List;
|
||||
|
||||
import com.genersoft.iot.vmp.gb28181.bean.*;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.StreamProxyItem;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.StreamPushItem;
|
||||
import com.genersoft.iot.vmp.vmanager.platform.bean.ChannelReduce;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
|
||||
@@ -319,4 +320,36 @@ public interface IVideoManagerStorager {
|
||||
* @return
|
||||
*/
|
||||
List<GbStream> queryGbStreamListInPlatform(String platformId);
|
||||
|
||||
/**
|
||||
* 批量更新推流列表
|
||||
* @param streamPushItems
|
||||
*/
|
||||
void updateMediaList(List<StreamPushItem> streamPushItems);
|
||||
|
||||
/**
|
||||
* 更新单个推流
|
||||
* @param streamPushItem
|
||||
*/
|
||||
void updateMedia(StreamPushItem streamPushItem);
|
||||
|
||||
/**
|
||||
* 移除单个推流
|
||||
* @param app
|
||||
* @param stream
|
||||
*/
|
||||
void removeMedia(String app, String stream);
|
||||
|
||||
|
||||
/**
|
||||
* 清空推流列表
|
||||
*/
|
||||
void clearMediaList();
|
||||
|
||||
/**
|
||||
* 设置流离线
|
||||
* @param app
|
||||
* @param streamId
|
||||
*/
|
||||
void mediaOutline(String app, String streamId);
|
||||
}
|
||||
|
||||
@@ -12,9 +12,9 @@ import java.util.List;
|
||||
public interface GbStreamMapper {
|
||||
|
||||
@Insert("INSERT INTO gb_stream (app, stream, gbId, name, " +
|
||||
"longitude, latitude, streamType) VALUES" +
|
||||
"longitude, latitude, streamType, status) VALUES" +
|
||||
"('${app}', '${stream}', '${gbId}', '${name}', " +
|
||||
"'${longitude}', '${latitude}', '${streamType}')")
|
||||
"'${longitude}', '${latitude}', '${streamType}', ${status})")
|
||||
int add(GbStream gbStream);
|
||||
|
||||
@Update("UPDATE gb_stream " +
|
||||
@@ -24,7 +24,8 @@ public interface GbStreamMapper {
|
||||
"name=#{name}," +
|
||||
"streamType=#{streamType}," +
|
||||
"longitude=#{longitude}, " +
|
||||
"latitude=#{latitude}, " +
|
||||
"latitude=#{latitude} " +
|
||||
"status=${status} " +
|
||||
"WHERE app=#{app} AND stream=#{stream} AND gbId=#{gbId}")
|
||||
int update(GbStream gbStream);
|
||||
|
||||
@@ -46,4 +47,9 @@ public interface GbStreamMapper {
|
||||
"LEFT JOIN platform_gb_stream pgs ON gs.app = pgs.app AND gs.stream = pgs.stream " +
|
||||
"WHERE pgs.platformId = '${platformId}'")
|
||||
List<GbStream> queryGbStreamListInPlatform(String platformId);
|
||||
|
||||
@Update("UPDATE gb_stream " +
|
||||
"SET status=${status} " +
|
||||
"WHERE app=#{app} AND stream=#{stream}")
|
||||
void setStatus(String app, String stream, boolean status);
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import java.util.List;
|
||||
|
||||
@Mapper
|
||||
@Repository
|
||||
public interface PlarfotmGbStreamMapper {
|
||||
public interface PlatformGbStreamMapper {
|
||||
|
||||
@Insert("INSERT INTO platform_gb_stream (app, stream, platformId) VALUES" +
|
||||
"('${app}', '${stream}', '${platformId}')")
|
||||
@@ -20,9 +20,9 @@ public interface PlarfotmGbStreamMapper {
|
||||
@Delete("DELETE FROM platform_gb_stream WHERE app=#{app} AND stream=#{stream}")
|
||||
int delByAppAndStream(String app, String stream);
|
||||
|
||||
@Delete("DELETE FROM platform_gb_stream WHERE app=#{app} AND stream=#{stream}")
|
||||
@Delete("DELETE FROM platform_gb_stream WHERE platformId=#{platformId}")
|
||||
int delByPlatformId(String platformId);
|
||||
|
||||
@Select("SELECT * FROM platform_gb_stream WHERE app=#{app} AND stream=#{stream} AND platformId=#{platformId}")
|
||||
StreamProxyItem selectOne(String app, String stream, String platformId);
|
||||
@Select("SELECT * FROM platform_gb_stream WHERE app=#{app} AND stream=#{stream}")
|
||||
List<StreamProxyItem> selectByAppAndStream(String app, String stream);
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package com.genersoft.iot.vmp.storager.dao;
|
||||
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.StreamProxyItem;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.StreamPushItem;
|
||||
import org.apache.ibatis.annotations.*;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
@Repository
|
||||
public interface StreamPushMapper {
|
||||
|
||||
@Insert("INSERT INTO stream_push (app, stream, totalReaderCount, originType, originTypeStr, " +
|
||||
"createStamp, aliveSecond) VALUES" +
|
||||
"('${app}', '${stream}', '${totalReaderCount}', '${originType}', '${originTypeStr}', " +
|
||||
"'${createStamp}', '${aliveSecond}' )")
|
||||
int add(StreamPushItem streamPushItem);
|
||||
|
||||
@Update("UPDATE stream_push " +
|
||||
"SET app=#{app}," +
|
||||
"stream=#{stream}," +
|
||||
"totalReaderCount=#{totalReaderCount}, " +
|
||||
"originType=#{originType}," +
|
||||
"originTypeStr=#{originTypeStr}, " +
|
||||
"createStamp=#{createStamp}, " +
|
||||
"aliveSecond=#{aliveSecond} " +
|
||||
"WHERE app=#{app} AND stream=#{stream}")
|
||||
int update(StreamPushItem streamPushItem);
|
||||
|
||||
@Delete("DELETE FROM stream_push WHERE app=#{app} AND stream=#{stream}")
|
||||
int del(String app, String stream);
|
||||
|
||||
@Select("SELECT st.*, pgs.gbId, pgs.status, pgs.name, pgs.longitude, pgs.latitude FROM stream_push st LEFT JOIN gb_stream pgs on st.app = pgs.app AND st.stream = pgs.stream")
|
||||
List<StreamPushItem> selectAll();
|
||||
|
||||
@Select("SELECT st.*, pgs.gbId, pgs.status, pgs.name, pgs.longitude, pgs.latitude FROM stream_push st LEFT JOIN gb_stream pgs on st.app = pgs.app AND st.stream = pgs.stream WHERE st.enable=${enable}")
|
||||
List<StreamPushItem> selectForEnable(boolean enable);
|
||||
|
||||
@Select("SELECT st.*, pgs.gbId, pgs.status, pgs.name, pgs.longitude, pgs.latitude FROM stream_push st LEFT JOIN gb_stream pgs on st.app = pgs.app AND st.stream = pgs.stream WHERE st.app=#{app} AND st.stream=#{stream}")
|
||||
StreamPushItem selectOne(String app, String stream);
|
||||
|
||||
@Insert("<script>" +
|
||||
"INSERT INTO stream_push (app, stream, totalReaderCount, originType, originTypeStr, " +
|
||||
"createStamp, aliveSecond) " +
|
||||
"VALUES <foreach collection='streamPushItems' item='item' index='index' >" +
|
||||
"( '${item.app}', '${item.stream}', '${item.totalReaderCount}', '${item.originType}', " +
|
||||
"'${item.originTypeStr}','${item.createStamp}', '${item.aliveSecond}' )" +
|
||||
" </foreach>" +
|
||||
"</script>")
|
||||
void addAll(List<StreamPushItem> streamPushItems);
|
||||
|
||||
@Delete("DELETE FROM stream_push")
|
||||
void clear();
|
||||
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.genersoft.iot.vmp.storager.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.genersoft.iot.vmp.common.RealVideo;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.StreamPushItem;
|
||||
import com.genersoft.iot.vmp.common.StreamInfo;
|
||||
import com.genersoft.iot.vmp.common.VideoManagerConstants;
|
||||
import com.genersoft.iot.vmp.conf.MediaServerConfig;
|
||||
@@ -261,34 +261,4 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 更新媒体流列表
|
||||
* @param mediaList
|
||||
*/
|
||||
@Override
|
||||
public void updateMediaList(List<RealVideo> mediaList) {
|
||||
String key = VideoManagerConstants.MEDIA_STREAM_PREFIX;
|
||||
redis.del(key);
|
||||
for (int i = 0; i < mediaList.size(); i++) {
|
||||
RealVideo realVideo = mediaList.get(i);
|
||||
redis.zAdd(key, realVideo, realVideo.getCreateStamp());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取当前媒体流列表
|
||||
* @return List<RealVideo>
|
||||
*/
|
||||
@Override
|
||||
public JSONObject getMediaList(int start, int end) {
|
||||
String key = VideoManagerConstants.MEDIA_STREAM_PREFIX;
|
||||
Set<Object> realVideos = redis.ZRange(key, start, end);
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("list", new ArrayList(realVideos));
|
||||
jsonObject.put("total", redis.zSize(key));
|
||||
|
||||
return jsonObject;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import java.util.*;
|
||||
|
||||
import com.genersoft.iot.vmp.gb28181.bean.*;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.StreamProxyItem;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.StreamPushItem;
|
||||
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
||||
import com.genersoft.iot.vmp.storager.dao.*;
|
||||
import com.genersoft.iot.vmp.vmanager.platform.bean.ChannelReduce;
|
||||
@@ -53,6 +54,9 @@ public class VideoManagerStoragerImpl implements IVideoManagerStorager {
|
||||
@Autowired
|
||||
private StreamProxyMapper streamProxyMapper;
|
||||
|
||||
@Autowired
|
||||
private StreamPushMapper streamPushMapper;
|
||||
|
||||
@Autowired
|
||||
private GbStreamMapper gbStreamMapper;
|
||||
|
||||
@@ -221,9 +225,10 @@ public class VideoManagerStoragerImpl implements IVideoManagerStorager {
|
||||
*/
|
||||
@Override
|
||||
public synchronized boolean outline(String deviceId) {
|
||||
System.out.println("更新设备离线: " + deviceId);
|
||||
Device device = deviceMapper.getDeviceByDeviceId(deviceId);
|
||||
if (device == null) return false;
|
||||
device.setOnline(0);
|
||||
System.out.println("更新设备离线");
|
||||
return deviceMapper.update(device) > 0;
|
||||
}
|
||||
|
||||
@@ -403,6 +408,7 @@ public class VideoManagerStoragerImpl implements IVideoManagerStorager {
|
||||
TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition);
|
||||
boolean result = false;
|
||||
streamProxyItem.setStreamType("proxy");
|
||||
streamProxyItem.setStatus(true);
|
||||
try {
|
||||
if (gbStreamMapper.add(streamProxyItem)<0 || streamProxyMapper.add(streamProxyItem) < 0) {
|
||||
//事务回滚
|
||||
@@ -504,4 +510,37 @@ public class VideoManagerStoragerImpl implements IVideoManagerStorager {
|
||||
public StreamProxyItem queryStreamProxy(String app, String stream){
|
||||
return streamProxyMapper.selectOne(app, stream);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateMediaList(List<StreamPushItem> streamPushItems) {
|
||||
if (streamPushItems == null || streamPushItems.size() == 0) return;
|
||||
System.out.printf("updateMediaList: " + streamPushItems.size());
|
||||
streamPushMapper.addAll(streamPushItems);
|
||||
// TODO 待优化
|
||||
for (int i = 0; i < streamPushItems.size(); i++) {
|
||||
gbStreamMapper.setStatus(streamPushItems.get(i).getApp(), streamPushItems.get(i).getStream(), true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateMedia(StreamPushItem streamPushItem) {
|
||||
streamPushMapper.del(streamPushItem.getApp(), streamPushItem.getStream());
|
||||
streamPushMapper.add(streamPushItem);
|
||||
gbStreamMapper.setStatus(streamPushItem.getApp(), streamPushItem.getStream(), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeMedia(String app, String stream) {
|
||||
streamPushMapper.del(app, stream);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearMediaList() {
|
||||
streamPushMapper.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mediaOutline(String app, String streamId) {
|
||||
gbStreamMapper.setStatus(app, streamId, false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +1,15 @@
|
||||
package com.genersoft.iot.vmp.vmanager.gbStream;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.GbStream;
|
||||
import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
|
||||
import com.genersoft.iot.vmp.vmanager.gbStream.bean.GbStreamParam;
|
||||
import com.genersoft.iot.vmp.vmanager.platform.bean.UpdateChannelParam;
|
||||
import com.genersoft.iot.vmp.vmanager.service.IGbStreamService;
|
||||
import com.genersoft.iot.vmp.service.IGbStreamService;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@CrossOrigin
|
||||
@RestController
|
||||
@RequestMapping("/api/gbStream")
|
||||
|
||||
@@ -2,9 +2,13 @@ package com.genersoft.iot.vmp.vmanager.media;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.genersoft.iot.vmp.common.StreamInfo;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.GbStream;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.PlatformGbStream;
|
||||
import com.genersoft.iot.vmp.service.IStreamPushService;
|
||||
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
||||
import com.genersoft.iot.vmp.vmanager.service.IMediaService;
|
||||
import com.genersoft.iot.vmp.vmanager.service.IStreamProxyService;
|
||||
import com.genersoft.iot.vmp.service.IMediaService;
|
||||
import com.genersoft.iot.vmp.service.IStreamProxyService;
|
||||
import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -20,25 +24,16 @@ public class MediaController {
|
||||
private final static Logger logger = LoggerFactory.getLogger(MediaController.class);
|
||||
|
||||
@Autowired
|
||||
private IRedisCatchStorage redisCatchStorage;
|
||||
private IVideoManagerStorager storager;
|
||||
|
||||
@Autowired
|
||||
private IStreamProxyService streamProxyService;
|
||||
private IStreamPushService streamPushService;
|
||||
|
||||
@Autowired
|
||||
private IMediaService mediaService;
|
||||
|
||||
|
||||
@RequestMapping(value = "/list")
|
||||
@ResponseBody
|
||||
public JSONObject list( @RequestParam(required = false)Integer page,
|
||||
@RequestParam(required = false)Integer count,
|
||||
@RequestParam(required = false)String q,
|
||||
@RequestParam(required = false)Boolean online ){
|
||||
|
||||
JSONObject jsonObject = redisCatchStorage.getMediaList(page - 1, page - 1 + count);
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/getStreamInfoByAppAndStream")
|
||||
@ResponseBody
|
||||
@@ -46,4 +41,6 @@ public class MediaController {
|
||||
return mediaService.getStreamInfoByAppAndStreamWithCheck(app, stream);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
package com.genersoft.iot.vmp.vmanager.platformGbStream;
|
||||
|
||||
import com.genersoft.iot.vmp.gb28181.bean.GbStream;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.PlatformGbStream;
|
||||
import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
|
||||
import com.genersoft.iot.vmp.vmanager.service.IGbStreamService;
|
||||
import com.genersoft.iot.vmp.service.IGbStreamService;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -8,8 +8,8 @@ import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage;
|
||||
import com.genersoft.iot.vmp.media.zlm.ZLMRESTfulUtils;
|
||||
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
||||
import com.genersoft.iot.vmp.vmanager.play.bean.PlayResult;
|
||||
import com.genersoft.iot.vmp.vmanager.service.IMediaService;
|
||||
import com.genersoft.iot.vmp.vmanager.service.IPlayService;
|
||||
import com.genersoft.iot.vmp.service.IMediaService;
|
||||
import com.genersoft.iot.vmp.service.IPlayService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
@@ -5,7 +5,7 @@ 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;
|
||||
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
||||
import com.genersoft.iot.vmp.vmanager.service.IPlayService;
|
||||
import com.genersoft.iot.vmp.service.IPlayService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
@@ -3,7 +3,7 @@ package com.genersoft.iot.vmp.vmanager.streamProxy;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.StreamProxyItem;
|
||||
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
||||
import com.genersoft.iot.vmp.vmanager.service.IStreamProxyService;
|
||||
import com.genersoft.iot.vmp.service.IStreamProxyService;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
package com.genersoft.iot.vmp.vmanager.streamPush;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.GbStream;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.StreamProxyItem;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.StreamPushItem;
|
||||
import com.genersoft.iot.vmp.service.IStreamPushService;
|
||||
import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
|
||||
import com.genersoft.iot.vmp.vmanager.media.MediaController;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@Controller
|
||||
@CrossOrigin
|
||||
@RequestMapping(value = "/api/push")
|
||||
public class StreamPushController {
|
||||
|
||||
private final static Logger logger = LoggerFactory.getLogger(StreamPushController.class);
|
||||
|
||||
@Autowired
|
||||
private IStreamPushService streamPushService;
|
||||
|
||||
@RequestMapping(value = "/list")
|
||||
@ResponseBody
|
||||
public PageInfo<StreamPushItem> list(@RequestParam(required = false)Integer page,
|
||||
@RequestParam(required = false)Integer count,
|
||||
@RequestParam(required = false)String q,
|
||||
@RequestParam(required = false)Boolean online ){
|
||||
|
||||
PageInfo<StreamPushItem> pushList = streamPushService.getPushList(page - 1, page - 1 + count);
|
||||
return pushList;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/saveToGB")
|
||||
@ResponseBody
|
||||
public Object saveToGB(@RequestBody GbStream stream){
|
||||
if (streamPushService.saveToGB(stream)){
|
||||
return "success";
|
||||
}else {
|
||||
return "fail";
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/removeFormGB")
|
||||
@ResponseBody
|
||||
public Object removeFormGB(@RequestBody GbStream stream){
|
||||
if (streamPushService.removeFromGB(stream)){
|
||||
return "success";
|
||||
}else {
|
||||
return "fail";
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user