diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/bean/GbStream.java b/src/main/java/com/genersoft/iot/vmp/gb28181/bean/GbStream.java index 8fb1980c..fd469474 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/bean/GbStream.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/bean/GbStream.java @@ -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; + } } diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/bean/PlatformGbStream.java b/src/main/java/com/genersoft/iot/vmp/gb28181/bean/PlatformGbStream.java index a4871aef..a4f7730d 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/bean/PlatformGbStream.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/bean/PlatformGbStream.java @@ -28,4 +28,5 @@ public class PlatformGbStream { public void setPlatformId(String platformId) { this.platformId = platformId; } + } diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/SIPProcessorFactory.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/SIPProcessorFactory.java index de9d8377..02eedc46 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/SIPProcessorFactory.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/SIPProcessorFactory.java @@ -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; diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/InviteRequestProcessor.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/InviteRequestProcessor.java index 15d06387..9db7a299 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/InviteRequestProcessor.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/InviteRequestProcessor.java @@ -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; /** diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/MessageRequestProcessor.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/MessageRequestProcessor.java index 8176f459..52774259 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/MessageRequestProcessor.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/MessageRequestProcessor.java @@ -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()); diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java index b2c15978..0065b214 100644 --- a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java +++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java @@ -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(); diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookSubscribe.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookSubscribe.java index 129f8a38..5aee00cd 100644 --- a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookSubscribe.java +++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookSubscribe.java @@ -70,6 +70,11 @@ public class ZLMHttpHookSubscribe { return event; } + /** + * 获取某个类型的所有的订阅 + * @param type + * @return + */ public List getSubscribes(HookType type) { ZLMHttpHookSubscribe.Event event= null; Map eventMap = allSubscribes.get(type); diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMMediaListManager.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMMediaListManager.java index 5ffa4670..1bf51621 100644 --- a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMMediaListManager.java +++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMMediaListManager.java @@ -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 result = new HashMap<>(); - if (code == 0 ) { - if (dataStr != null) { - List mediaItems = JSON.parseObject(dataStr, new TypeReference>() {}); - 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 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 result = new HashMap<>(); + List streamPushItems = null; + // 获取所有的国标关联 + List gbStreams = gbStreamMapper.selectAll(); + if (code == 0 ) { + if (dataStr != null) { + streamPushItems = streamPushService.handleJSON(dataStr); } - + }else { + logger.warn("更新视频流失败,错误code: " + code); } - }else { - logger.warn("更新视频流失败,错误code: " + code); - } - List 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 result = new HashMap<>(); + List 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); + } + } } diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRESTfulUtils.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRESTfulUtils.java index 21752a03..0265815d 100644 --- a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRESTfulUtils.java +++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRESTfulUtils.java @@ -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 param) { + public interface RequestCallback{ + void run(JSONObject response); + } + + public JSONObject sendPost(String api, Map 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 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 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 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 param){ - return sendPost("setServerConfig",param); + return sendPost("setServerConfig",param, null); } public JSONObject openRtpServer(Map param){ - return sendPost("openRtpServer",param); + return sendPost("openRtpServer",param, null); } public JSONObject closeRtpServer(Map param) { - return sendPost("closeRtpServer",param); + return sendPost("closeRtpServer",param, null); } public JSONObject startSendRtp(Map param) { - return sendPost("startSendRtp",param); + return sendPost("startSendRtp",param, null); } public JSONObject stopSendRtp(Map 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); } } diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRunner.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRunner.java index 1340a68f..edce4113 100644 --- a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRunner.java +++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRunner.java @@ -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; } diff --git a/src/main/java/com/genersoft/iot/vmp/common/RealVideo.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/StreamPushItem.java similarity index 91% rename from src/main/java/com/genersoft/iot/vmp/common/RealVideo.java rename to src/main/java/com/genersoft/iot/vmp/media/zlm/dto/StreamPushItem.java index b5ed8516..f745b2a9 100644 --- a/src/main/java/com/genersoft/iot/vmp/common/RealVideo.java +++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/StreamPushItem.java @@ -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{ +public class StreamPushItem extends GbStream implements Comparable{ /** * 应用名 @@ -85,9 +84,10 @@ public class RealVideo implements Comparable{ 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 { diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/service/IGbStreamService.java b/src/main/java/com/genersoft/iot/vmp/service/IGbStreamService.java similarity index 87% rename from src/main/java/com/genersoft/iot/vmp/vmanager/service/IGbStreamService.java rename to src/main/java/com/genersoft/iot/vmp/service/IGbStreamService.java index 877ec2a6..49ba7b7f 100644 --- a/src/main/java/com/genersoft/iot/vmp/vmanager/service/IGbStreamService.java +++ b/src/main/java/com/genersoft/iot/vmp/service/IGbStreamService.java @@ -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; diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/service/IMediaService.java b/src/main/java/com/genersoft/iot/vmp/service/IMediaService.java similarity index 78% rename from src/main/java/com/genersoft/iot/vmp/vmanager/service/IMediaService.java rename to src/main/java/com/genersoft/iot/vmp/service/IMediaService.java index 757a7acb..526da370 100644 --- a/src/main/java/com/genersoft/iot/vmp/vmanager/service/IMediaService.java +++ b/src/main/java/com/genersoft/iot/vmp/service/IMediaService.java @@ -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); + } diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/service/IPlayService.java b/src/main/java/com/genersoft/iot/vmp/service/IPlayService.java similarity index 92% rename from src/main/java/com/genersoft/iot/vmp/vmanager/service/IPlayService.java rename to src/main/java/com/genersoft/iot/vmp/service/IPlayService.java index 963fc8cc..7f4d9c7c 100644 --- a/src/main/java/com/genersoft/iot/vmp/vmanager/service/IPlayService.java +++ b/src/main/java/com/genersoft/iot/vmp/service/IPlayService.java @@ -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; diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/service/IStreamProxyService.java b/src/main/java/com/genersoft/iot/vmp/service/IStreamProxyService.java similarity index 95% rename from src/main/java/com/genersoft/iot/vmp/vmanager/service/IStreamProxyService.java rename to src/main/java/com/genersoft/iot/vmp/service/IStreamProxyService.java index 49d1e8aa..023c0757 100644 --- a/src/main/java/com/genersoft/iot/vmp/vmanager/service/IStreamProxyService.java +++ b/src/main/java/com/genersoft/iot/vmp/service/IStreamProxyService.java @@ -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; diff --git a/src/main/java/com/genersoft/iot/vmp/service/IStreamPushService.java b/src/main/java/com/genersoft/iot/vmp/service/IStreamPushService.java new file mode 100644 index 00000000..9724eb78 --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/service/IStreamPushService.java @@ -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 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 getPushList(Integer page, Integer count); +} diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/service/impl/GbStreamServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/GbStreamServiceImpl.java similarity index 83% rename from src/main/java/com/genersoft/iot/vmp/vmanager/service/impl/GbStreamServiceImpl.java rename to src/main/java/com/genersoft/iot/vmp/service/impl/GbStreamServiceImpl.java index b8caacd7..5002d29d 100644 --- a/src/main/java/com/genersoft/iot/vmp/vmanager/service/impl/GbStreamServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/GbStreamServiceImpl.java @@ -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 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; diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/service/impl/MediaServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServiceImpl.java similarity index 92% rename from src/main/java/com/genersoft/iot/vmp/vmanager/service/impl/MediaServiceImpl.java rename to src/main/java/com/genersoft/iot/vmp/service/impl/MediaServiceImpl.java index 68a1c440..f721b90d 100644 --- a/src/main/java/com/genersoft/iot/vmp/vmanager/service/impl/MediaServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServiceImpl.java @@ -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; } + + + } diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/service/impl/PlayServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java similarity index 96% rename from src/main/java/com/genersoft/iot/vmp/vmanager/service/impl/PlayServiceImpl.java rename to src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java index 694c74f2..e7298d20 100644 --- a/src/main/java/com/genersoft/iot/vmp/vmanager/service/impl/PlayServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java @@ -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; diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/service/impl/StreamProxyServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/StreamProxyServiceImpl.java similarity index 93% rename from src/main/java/com/genersoft/iot/vmp/vmanager/service/impl/StreamProxyServiceImpl.java rename to src/main/java/com/genersoft/iot/vmp/service/impl/StreamProxyServiceImpl.java index ec94844c..ddf81834 100644 --- a/src/main/java/com/genersoft/iot/vmp/vmanager/service/impl/StreamProxyServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/StreamProxyServiceImpl.java @@ -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 如果关联的推流, 那么状态设置为离线 } } diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/StreamPushServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/StreamPushServiceImpl.java new file mode 100644 index 00000000..ce7f02b1 --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/StreamPushServiceImpl.java @@ -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 handleJSON(String jsonData) { + if (jsonData == null) return null; + + Map result = new HashMap<>(); + + List mediaItems = JSON.parseObject(jsonData, new TypeReference>() {}); + 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 getPushList(Integer page, Integer count) { + PageHelper.startPage(page, count); + List 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; + } +} diff --git a/src/main/java/com/genersoft/iot/vmp/storager/IRedisCatchStorage.java b/src/main/java/com/genersoft/iot/vmp/storager/IRedisCatchStorage.java index ca4ebaef..1aba063f 100644 --- a/src/main/java/com/genersoft/iot/vmp/storager/IRedisCatchStorage.java +++ b/src/main/java/com/genersoft/iot/vmp/storager/IRedisCatchStorage.java @@ -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 mediaList); - - /** - * 获取当前媒体流列表 - * @return List - */ - JSONObject getMediaList(int start, int end); } diff --git a/src/main/java/com/genersoft/iot/vmp/storager/IVideoManagerStorager.java b/src/main/java/com/genersoft/iot/vmp/storager/IVideoManagerStorager.java index e8f32409..846e8c77 100644 --- a/src/main/java/com/genersoft/iot/vmp/storager/IVideoManagerStorager.java +++ b/src/main/java/com/genersoft/iot/vmp/storager/IVideoManagerStorager.java @@ -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 queryGbStreamListInPlatform(String platformId); + + /** + * 批量更新推流列表 + * @param streamPushItems + */ + void updateMediaList(List 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); } diff --git a/src/main/java/com/genersoft/iot/vmp/storager/dao/GbStreamMapper.java b/src/main/java/com/genersoft/iot/vmp/storager/dao/GbStreamMapper.java index 2b83a4a7..2ada231a 100644 --- a/src/main/java/com/genersoft/iot/vmp/storager/dao/GbStreamMapper.java +++ b/src/main/java/com/genersoft/iot/vmp/storager/dao/GbStreamMapper.java @@ -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 queryGbStreamListInPlatform(String platformId); + + @Update("UPDATE gb_stream " + + "SET status=${status} " + + "WHERE app=#{app} AND stream=#{stream}") + void setStatus(String app, String stream, boolean status); } diff --git a/src/main/java/com/genersoft/iot/vmp/storager/dao/PlarfotmGbStreamMapper.java b/src/main/java/com/genersoft/iot/vmp/storager/dao/PlatformGbStreamMapper.java similarity index 75% rename from src/main/java/com/genersoft/iot/vmp/storager/dao/PlarfotmGbStreamMapper.java rename to src/main/java/com/genersoft/iot/vmp/storager/dao/PlatformGbStreamMapper.java index 1172aebb..aad93f65 100644 --- a/src/main/java/com/genersoft/iot/vmp/storager/dao/PlarfotmGbStreamMapper.java +++ b/src/main/java/com/genersoft/iot/vmp/storager/dao/PlatformGbStreamMapper.java @@ -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 selectByAppAndStream(String app, String stream); } diff --git a/src/main/java/com/genersoft/iot/vmp/storager/dao/StreamPushMapper.java b/src/main/java/com/genersoft/iot/vmp/storager/dao/StreamPushMapper.java new file mode 100644 index 00000000..c0472a44 --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/storager/dao/StreamPushMapper.java @@ -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 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 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("") + void addAll(List streamPushItems); + + @Delete("DELETE FROM stream_push") + void clear(); + +} diff --git a/src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java b/src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java index 7b7f5993..91017fad 100644 --- a/src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java @@ -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 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 - */ - @Override - public JSONObject getMediaList(int start, int end) { - String key = VideoManagerConstants.MEDIA_STREAM_PREFIX; - Set realVideos = redis.ZRange(key, start, end); - JSONObject jsonObject = new JSONObject(); - jsonObject.put("list", new ArrayList(realVideos)); - jsonObject.put("total", redis.zSize(key)); - - return jsonObject; - } } diff --git a/src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStoragerImpl.java b/src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStoragerImpl.java index b2756e27..63fbbd11 100644 --- a/src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStoragerImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStoragerImpl.java @@ -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 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); + } } diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/gbStream/GbStreamController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/gbStream/GbStreamController.java index d6afb09e..787a094c 100644 --- a/src/main/java/com/genersoft/iot/vmp/vmanager/gbStream/GbStreamController.java +++ b/src/main/java/com/genersoft/iot/vmp/vmanager/gbStream/GbStreamController.java @@ -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") diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/media/MediaController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/media/MediaController.java index 0710f9b0..e01b06e6 100644 --- a/src/main/java/com/genersoft/iot/vmp/vmanager/media/MediaController.java +++ b/src/main/java/com/genersoft/iot/vmp/vmanager/media/MediaController.java @@ -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); } + + } diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/platformGbStream/PlatformGbStreamController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/platformGbStream/PlatformGbStreamController.java index f2db3403..f040d1a1 100644 --- a/src/main/java/com/genersoft/iot/vmp/vmanager/platformGbStream/PlatformGbStreamController.java +++ b/src/main/java/com/genersoft/iot/vmp/vmanager/platformGbStream/PlatformGbStreamController.java @@ -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; diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/play/PlayController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/play/PlayController.java index c4bee6d1..d104b85c 100644 --- a/src/main/java/com/genersoft/iot/vmp/vmanager/play/PlayController.java +++ b/src/main/java/com/genersoft/iot/vmp/vmanager/play/PlayController.java @@ -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; diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/playback/PlaybackController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/playback/PlaybackController.java index 020a26c2..9ce26728 100644 --- a/src/main/java/com/genersoft/iot/vmp/vmanager/playback/PlaybackController.java +++ b/src/main/java/com/genersoft/iot/vmp/vmanager/playback/PlaybackController.java @@ -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; diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/streamProxy/StreamProxyController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/streamProxy/StreamProxyController.java index 95b83ef1..6fc3beec 100644 --- a/src/main/java/com/genersoft/iot/vmp/vmanager/streamProxy/StreamProxyController.java +++ b/src/main/java/com/genersoft/iot/vmp/vmanager/streamProxy/StreamProxyController.java @@ -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; diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/streamPush/StreamPushController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/streamPush/StreamPushController.java new file mode 100644 index 00000000..1dd9036e --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/vmanager/streamPush/StreamPushController.java @@ -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 list(@RequestParam(required = false)Integer page, + @RequestParam(required = false)Integer count, + @RequestParam(required = false)String q, + @RequestParam(required = false)Boolean online ){ + + PageInfo 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"; + } + } +} diff --git a/src/main/resources/wvp.sqlite b/src/main/resources/wvp.sqlite index 315c6899..f6c72578 100644 Binary files a/src/main/resources/wvp.sqlite and b/src/main/resources/wvp.sqlite differ diff --git a/web_src/src/components/PLatformStreamList.vue b/web_src/src/components/PLatformStreamList.vue deleted file mode 100644 index ef5b5ec1..00000000 --- a/web_src/src/components/PLatformStreamList.vue +++ /dev/null @@ -1,283 +0,0 @@ - - - - - diff --git a/web_src/src/components/PushVideoList.vue b/web_src/src/components/PushVideoList.vue index bbfc5f8b..0955cc9f 100644 --- a/web_src/src/components/PushVideoList.vue +++ b/web_src/src/components/PushVideoList.vue @@ -8,10 +8,8 @@
推流列表
-
- 添加代理 -
+ @@ -19,6 +17,8 @@ + + + + + @@ -55,11 +62,13 @@ diff --git a/web_src/src/components/dialog/chooseChannelForStream.vue b/web_src/src/components/dialog/chooseChannelForStream.vue index 0824cbb9..ff655328 100644 --- a/web_src/src/components/dialog/chooseChannelForStream.vue +++ b/web_src/src/components/dialog/chooseChannelForStream.vue @@ -10,8 +10,6 @@ - -