diff --git a/src/main/java/com/genersoft/iot/vmp/service/IMediaServerService.java b/src/main/java/com/genersoft/iot/vmp/service/IMediaServerService.java index f42b8679..657d2808 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/IMediaServerService.java +++ b/src/main/java/com/genersoft/iot/vmp/service/IMediaServerService.java @@ -61,4 +61,6 @@ public interface IMediaServerService { boolean checkMediaRecordServer(String ip, int port); void delete(String id); + + MediaServerItem getDefaultMediaServer(); } diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java index 4ba361c0..1c2190a9 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java @@ -241,6 +241,11 @@ public class MediaServerServiceImpl implements IMediaServerService, CommandLineR return mediaServerMapper.queryOneByHostAndPort(host, port); } + @Override + public MediaServerItem getDefaultMediaServer() { + return mediaServerMapper.queryDefault(); + } + @Override public void clearMediaServerForOnline() { String key = VideoManagerConstants.MEDIA_SERVERS_ONLINE_PREFIX; diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServiceImpl.java index 51c5979e..a261d247 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServiceImpl.java @@ -38,7 +38,13 @@ public class MediaServiceImpl implements IMediaService { @Override public StreamInfo getStreamInfoByAppAndStreamWithCheck(String app, String stream, String mediaServerId, String addr) { StreamInfo streamInfo = null; - MediaServerItem mediaInfo = mediaServerService.getOne(mediaServerId); + + MediaServerItem mediaInfo; + if (mediaServerId == null) { + mediaInfo = mediaServerService.getDefaultMediaServer(); + }else { + mediaInfo = mediaServerService.getOne(mediaServerId); + } if (mediaInfo == null) { return streamInfo; } @@ -55,6 +61,8 @@ public class MediaServiceImpl implements IMediaService { return streamInfo; } + + @Override public StreamInfo getStreamInfoByAppAndStreamWithCheck(String app, String stream, String mediaServerId) { return getStreamInfoByAppAndStreamWithCheck(app, stream, mediaServerId, null); diff --git a/src/main/java/com/genersoft/iot/vmp/storager/dao/MediaServerMapper.java b/src/main/java/com/genersoft/iot/vmp/storager/dao/MediaServerMapper.java index 8d45b054..8cd5d6a9 100644 --- a/src/main/java/com/genersoft/iot/vmp/storager/dao/MediaServerMapper.java +++ b/src/main/java/com/genersoft/iot/vmp/storager/dao/MediaServerMapper.java @@ -105,4 +105,7 @@ public interface MediaServerMapper { @Select("SELECT * FROM media_server WHERE ip='${host}' and httpPort=${port}") MediaServerItem queryOneByHostAndPort(String host, int port); + + @Select("SELECT * FROM media_server WHERE defaultServer=1") + MediaServerItem queryDefault(); } diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/media/MediaController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/media/MediaController.java index b4b74690..d5caab29 100644 --- a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/media/MediaController.java +++ b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/media/MediaController.java @@ -44,11 +44,11 @@ public class MediaController { @ApiImplicitParams({ @ApiImplicitParam(name = "app", value = "应用名", dataTypeClass = String.class), @ApiImplicitParam(name = "stream", value = "流id", dataTypeClass = String.class), - @ApiImplicitParam(name = "mediaServerId", value = "媒体服务器id", dataTypeClass = String.class), + @ApiImplicitParam(name = "mediaServerId", value = "媒体服务器id", dataTypeClass = String.class, required = false), }) @GetMapping(value = "/stream_info_by_app_and_stream") @ResponseBody - public WVPResult getStreamInfoByAppAndStream(@RequestParam String app, @RequestParam String stream, @RequestParam String mediaServerId){ + public WVPResult getStreamInfoByAppAndStream(@RequestParam String app, @RequestParam String stream, @RequestParam(required = false) String mediaServerId){ StreamInfo streamInfoByAppAndStreamWithCheck = mediaService.getStreamInfoByAppAndStreamWithCheck(app, stream, mediaServerId); WVPResult result = new WVPResult<>(); if (streamInfoByAppAndStreamWithCheck != null){