diff --git a/src/main/java/com/genersoft/iot/vmp/common/InviteInfo.java b/src/main/java/com/genersoft/iot/vmp/common/InviteInfo.java index adf9643f..41b363e4 100644 --- a/src/main/java/com/genersoft/iot/vmp/common/InviteInfo.java +++ b/src/main/java/com/genersoft/iot/vmp/common/InviteInfo.java @@ -35,10 +35,12 @@ public class InviteInfo { private Long createTime; + private Boolean record; + public static InviteInfo getInviteInfo(String deviceId, Integer channelId, String stream, SSRCInfo ssrcInfo, String mediaServerId, String receiveIp, Integer receivePort, String streamMode, - InviteSessionType type, InviteSessionStatus status) { + InviteSessionType type, InviteSessionStatus status, Boolean record) { InviteInfo inviteInfo = new InviteInfo(); inviteInfo.setDeviceId(deviceId); inviteInfo.setChannelId(channelId); @@ -50,6 +52,7 @@ public class InviteInfo { inviteInfo.setType(type); inviteInfo.setStatus(status); inviteInfo.setMediaServerId(mediaServerId); + inviteInfo.setRecord(record); return inviteInfo; } diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/controller/CommonChannelController.java b/src/main/java/com/genersoft/iot/vmp/gb28181/controller/CommonChannelController.java index 3db52a43..3590fc2a 100755 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/controller/CommonChannelController.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/controller/CommonChannelController.java @@ -3,7 +3,10 @@ package com.genersoft.iot.vmp.gb28181.controller; import com.genersoft.iot.vmp.common.StreamInfo; import com.genersoft.iot.vmp.conf.UserSetting; import com.genersoft.iot.vmp.conf.security.JwtUtils; -import com.genersoft.iot.vmp.gb28181.bean.*; +import com.genersoft.iot.vmp.gb28181.bean.CommonGBChannel; +import com.genersoft.iot.vmp.gb28181.bean.DeviceType; +import com.genersoft.iot.vmp.gb28181.bean.IndustryCodeType; +import com.genersoft.iot.vmp.gb28181.bean.NetworkIdentificationType; import com.genersoft.iot.vmp.gb28181.controller.bean.ChannelToGroupByGbDeviceParam; import com.genersoft.iot.vmp.gb28181.controller.bean.ChannelToGroupParam; import com.genersoft.iot.vmp.gb28181.controller.bean.ChannelToRegionByGbDeviceParam; @@ -29,7 +32,6 @@ import org.springframework.web.bind.annotation.*; import org.springframework.web.context.request.async.DeferredResult; import javax.servlet.http.HttpServletRequest; -import javax.sip.message.Response; import java.net.MalformedURLException; import java.net.URL; import java.util.List; @@ -261,7 +263,7 @@ public class CommonChannelController { result.setResult(WVPResult.fail(code, msg)); } }; - channelPlayService.play(channel, null, callback); + channelPlayService.play(channel, null, userSetting.getRecordSip(), callback); return result; } } diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/service/IGbChannelPlayService.java b/src/main/java/com/genersoft/iot/vmp/gb28181/service/IGbChannelPlayService.java index 4f577939..ac58d28b 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/service/IGbChannelPlayService.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/service/IGbChannelPlayService.java @@ -10,11 +10,11 @@ public interface IGbChannelPlayService { void start(CommonGBChannel channel, InviteInfo inviteInfo, Platform platform, ErrorCallback callback); - void play(CommonGBChannel channel, Platform platform, ErrorCallback callback); + void play(CommonGBChannel channel, Platform platform, Boolean record, ErrorCallback callback); - void playGbDeviceChannel(CommonGBChannel channel, ErrorCallback callback); + void playGbDeviceChannel(CommonGBChannel channel, Boolean record, ErrorCallback callback); - void playProxy(CommonGBChannel channel, ErrorCallback callback); + void playProxy(CommonGBChannel channel, Boolean record, ErrorCallback callback); void playPush(CommonGBChannel channel, String platformDeviceId, String platformName, ErrorCallback callback); } diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/service/IPlayService.java b/src/main/java/com/genersoft/iot/vmp/gb28181/service/IPlayService.java index aa2ca3ab..e208d315 100755 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/service/IPlayService.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/service/IPlayService.java @@ -64,7 +64,7 @@ public interface IPlayService { void stop(InviteInfo inviteInfo); - void play(CommonGBChannel channel, ErrorCallback callback); + void play(CommonGBChannel channel, Boolean record, ErrorCallback callback); void playBack(CommonGBChannel channel, Long startTime, Long stopTime, ErrorCallback callback); diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/service/impl/GbChannelPlayServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/gb28181/service/impl/GbChannelPlayServiceImpl.java index cfa63fd2..4b828a2f 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/service/impl/GbChannelPlayServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/service/impl/GbChannelPlayServiceImpl.java @@ -2,6 +2,7 @@ package com.genersoft.iot.vmp.gb28181.service.impl; import com.genersoft.iot.vmp.common.StreamInfo; import com.genersoft.iot.vmp.common.enums.ChannelDataType; +import com.genersoft.iot.vmp.conf.UserSetting; import com.genersoft.iot.vmp.gb28181.bean.CommonGBChannel; import com.genersoft.iot.vmp.gb28181.bean.InviteInfo; import com.genersoft.iot.vmp.gb28181.bean.Platform; @@ -9,7 +10,6 @@ import com.genersoft.iot.vmp.gb28181.bean.PlayException; import com.genersoft.iot.vmp.gb28181.service.IGbChannelPlayService; import com.genersoft.iot.vmp.gb28181.service.IPlayService; import com.genersoft.iot.vmp.service.bean.ErrorCallback; -import com.genersoft.iot.vmp.service.bean.InviteErrorCode; import com.genersoft.iot.vmp.streamProxy.service.IStreamProxyPlayService; import com.genersoft.iot.vmp.streamPush.service.IStreamPushPlayService; import lombok.extern.slf4j.Slf4j; @@ -31,6 +31,9 @@ public class GbChannelPlayServiceImpl implements IGbChannelPlayService { @Autowired private IStreamPushPlayService streamPushPlayService; + @Autowired + private UserSetting userSetting; + @Override public void start(CommonGBChannel channel, InviteInfo inviteInfo, Platform platform, ErrorCallback callback) { @@ -40,7 +43,7 @@ public class GbChannelPlayServiceImpl implements IGbChannelPlayService { } log.info("[点播通用通道] 类型:{}, 通道: {}({})", inviteInfo.getSessionName(), channel.getGbName(), channel.getGbDeviceId()); if ("Play".equalsIgnoreCase(inviteInfo.getSessionName())) { - play(channel, platform, callback); + play(channel, platform, userSetting.getRecordSip(), callback); }else if ("Playback".equals(inviteInfo.getSessionName())) { if (channel.getDataType() == ChannelDataType.GB28181.value) { // 国标通道 @@ -90,13 +93,13 @@ public class GbChannelPlayServiceImpl implements IGbChannelPlayService { } @Override - public void play(CommonGBChannel channel, Platform platform, ErrorCallback callback) { + public void play(CommonGBChannel channel, Platform platform, Boolean record, ErrorCallback callback) { if (channel.getDataType() == ChannelDataType.GB28181.value) { // 国标通道 - playGbDeviceChannel(channel, callback); + playGbDeviceChannel(channel, record, callback); } else if (channel.getDataType() == ChannelDataType.STREAM_PROXY.value) { // 拉流代理 - playProxy(channel, callback); + playProxy(channel, record, callback); } else if (channel.getDataType() == ChannelDataType.STREAM_PUSH.value) { if (platform != null) { // 推流 @@ -113,10 +116,10 @@ public class GbChannelPlayServiceImpl implements IGbChannelPlayService { } @Override - public void playGbDeviceChannel(CommonGBChannel channel, ErrorCallback callback){ + public void playGbDeviceChannel(CommonGBChannel channel, Boolean record, ErrorCallback callback){ // 国标通道 try { - deviceChannelPlayService.play(channel, callback); + deviceChannelPlayService.play(channel, record, callback); } catch (PlayException e) { callback.run(e.getCode(), e.getMsg(), null); } catch (Exception e) { @@ -126,10 +129,10 @@ public class GbChannelPlayServiceImpl implements IGbChannelPlayService { } @Override - public void playProxy(CommonGBChannel channel, ErrorCallback callback){ + public void playProxy(CommonGBChannel channel, Boolean record, ErrorCallback callback){ // 拉流代理通道 try { - streamProxyPlayService.start(channel.getDataDeviceId(), callback); + streamProxyPlayService.start(channel.getDataDeviceId(), record, callback); }catch (Exception e) { callback.run(Response.BUSY_HERE, "busy here", null); } diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/service/impl/PlatformServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/gb28181/service/impl/PlatformServiceImpl.java index 7d9f7e16..5a7abffa 100755 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/service/impl/PlatformServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/service/impl/PlatformServiceImpl.java @@ -543,7 +543,7 @@ public class PlatformServiceImpl implements IPlatformService { // 初始化redis中的invite消息状态 InviteInfo inviteInfo = InviteInfo.getInviteInfo(platform.getServerGBId(), channel.getGbId(), ssrcInfo.getStream(), ssrcInfo, mediaServerItem.getId(), mediaServerItem.getSdpIp(), ssrcInfo.getPort(), userSetting.getBroadcastForPlatform(), InviteSessionType.BROADCAST, - InviteSessionStatus.ready); + InviteSessionStatus.ready, userSetting.getRecordSip()); inviteStreamService.updateInviteInfo(inviteInfo); String timeOutTaskKey = UUID.randomUUID().toString(); dynamicTask.startDelay(timeOutTaskKey, () -> { diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/service/impl/PlayServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/gb28181/service/impl/PlayServiceImpl.java index d6dbb4f1..ae8a8645 100755 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/service/impl/PlayServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/service/impl/PlayServiceImpl.java @@ -305,11 +305,11 @@ public class PlayServiceImpl implements IPlayService { throw new ControllerException(ErrorCode.ERROR100.getCode(), "未找到通道"); } - return play(mediaServerItem, device, channel, ssrc, callback); + return play(mediaServerItem, device, channel, ssrc, userSetting.getRecordSip(), callback); } - private SSRCInfo play(MediaServer mediaServerItem, Device device, DeviceChannel channel, String ssrc, - ErrorCallback callback) { + private SSRCInfo play(MediaServer mediaServerItem, Device device, DeviceChannel channel, String ssrc, Boolean record, + ErrorCallback callback) { if (mediaServerItem == null ) { if (callback != null) { callback.run(InviteErrorCode.ERROR_FOR_PARAMETER_ERROR.getCode(), @@ -322,7 +322,8 @@ public class PlayServiceImpl implements IPlayService { InviteInfo inviteInfoInCatch = inviteStreamService.getInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, channel.getId()); if (inviteInfoInCatch != null ) { if (inviteInfoInCatch.getStreamInfo() == null) { - // 释放生成的ssrc,使用上一次申请的 + // 释放生成的ssrc,使用上一次申请的322 + ssrcFactory.releaseSsrc(mediaServerItem.getId(), ssrc); // 点播发起了但是尚未成功, 仅注册回调等待结果即可 inviteStreamService.once(InviteSessionType.PLAY, channel.getId(), null, callback); @@ -432,7 +433,13 @@ public class PlayServiceImpl implements IPlayService { // 初始化redis中的invite消息状态 InviteInfo inviteInfo = InviteInfo.getInviteInfo(device.getDeviceId(), channel.getId(), ssrcInfo.getStream(), ssrcInfo, mediaServerItem.getId(), mediaServerItem.getSdpIp(), ssrcInfo.getPort(), device.getStreamMode(), InviteSessionType.PLAY, - InviteSessionStatus.ready); + InviteSessionStatus.ready, userSetting.getRecordSip()); + if (record != null) { + inviteInfo.setRecord(record); + }else { + inviteInfo.setRecord(userSetting.getRecordSip()); + } + inviteStreamService.updateInviteInfo(inviteInfo); try { @@ -812,7 +819,7 @@ public class PlayServiceImpl implements IPlayService { // 初始化redis中的invite消息状态 InviteInfo inviteInfo = InviteInfo.getInviteInfo(device.getDeviceId(), channel.getId(), ssrcInfo.getStream(), ssrcInfo, mediaServerItem.getId(), mediaServerItem.getSdpIp(), ssrcInfo.getPort(), device.getStreamMode(), InviteSessionType.PLAYBACK, - InviteSessionStatus.ready); + InviteSessionStatus.ready, userSetting.getRecordSip()); inviteStreamService.updateInviteInfo(inviteInfo); try { @@ -1018,7 +1025,7 @@ public class PlayServiceImpl implements IPlayService { // 初始化redis中的invite消息状态 InviteInfo inviteInfo = InviteInfo.getInviteInfo(device.getDeviceId(), channel.getId(), ssrcInfo.getStream(), ssrcInfo, mediaServerItem.getId(), mediaServerItem.getSdpIp(), ssrcInfo.getPort(), device.getStreamMode(), InviteSessionType.DOWNLOAD, - InviteSessionStatus.ready); + InviteSessionStatus.ready, true); inviteStreamService.updateInviteInfo(inviteInfo); try { @@ -1647,7 +1654,7 @@ public class PlayServiceImpl implements IPlayService { } @Override - public void play(CommonGBChannel channel, ErrorCallback callback) { + public void play(CommonGBChannel channel, Boolean record, ErrorCallback callback) { Device device = deviceService.getDevice(channel.getDataDeviceId()); if (device == null) { log.warn("[点播] 未找到通道{}的设备信息", channel); @@ -1659,7 +1666,7 @@ public class PlayServiceImpl implements IPlayService { throw new PlayException(Response.SERVER_INTERNAL_ERROR, "server internal error"); } DeviceChannel deviceChannel = deviceChannelService.getOneForSourceById(channel.getGbId()); - play(mediaServer, device, deviceChannel, null, callback); + play(mediaServer, device, deviceChannel, null, record, callback); } @Override 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 fcb7570f..b0b70791 100755 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServiceImpl.java @@ -129,17 +129,19 @@ public class MediaServiceImpl implements IMediaService { ResultForOnPublish result = new ResultForOnPublish(); result.setEnable_audio(true); - // 是否录像 - if ("rtp".equals(app)) { - result.setEnable_mp4(userSetting.getRecordSip()); - } else { - result.setEnable_mp4(userSetting.getRecordPushLive()); - } // 国标流 if ("rtp".equals(app)) { InviteInfo inviteInfo = inviteStreamService.getInviteInfoByStream(null, stream); + if (inviteInfo != null) { + result.setEnable_mp4(inviteInfo.getRecord()); + }else { + result.setEnable_mp4(userSetting.getRecordSip()); + } + + result.setEnable_mp4(inviteInfo.getRecord()); + // 单端口模式下修改流 ID if (!mediaServer.isRtpEnable() && inviteInfo == null) { String ssrc = String.format("%010d", Long.parseLong(stream, 16)); @@ -190,8 +192,12 @@ public class MediaServiceImpl implements IMediaService { } } else if (app.equals("broadcast")) { result.setEnable_audio(true); + result.setEnable_mp4(userSetting.getRecordSip()); } else if (app.equals("talk")) { result.setEnable_audio(true); + result.setEnable_mp4(userSetting.getRecordSip()); + }else { + result.setEnable_mp4(userSetting.getRecordPushLive()); } if (app.equalsIgnoreCase("rtp")) { String receiveKey = VideoManagerConstants.WVP_OTHER_RECEIVE_RTP_INFO + userSetting.getServerId() + "_" + stream; diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/RecordPlanServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/RecordPlanServiceImpl.java index 1b5317a0..2e97d775 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/RecordPlanServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/RecordPlanServiceImpl.java @@ -66,7 +66,7 @@ public class RecordPlanServiceImpl implements IRecordPlanService { return; } // 开启点播, - channelPlayService.play(channel, null, ((code, msg, streamInfo) -> { + channelPlayService.play(channel, null, true, ((code, msg, streamInfo) -> { if (code == InviteErrorCode.SUCCESS.getCode() && streamInfo != null) { log.info("[录像] 流离开时拉起需要录像的流, 开启成功, 通道ID: {}", channel.getGbId()); recordStreamMap.put(channel.getGbId(), streamInfo); @@ -110,7 +110,7 @@ public class RecordPlanServiceImpl implements IRecordPlanService { // 查找是否已经开启录像, 如果没有则开启录像 for (CommonGBChannel channel : channelList) { // 开启点播, - channelPlayService.play(channel, null, ((code, msg, streamInfo) -> { + channelPlayService.play(channel, null, true, ((code, msg, streamInfo) -> { if (code == InviteErrorCode.SUCCESS.getCode() && streamInfo != null) { log.info("[录像] 开启成功, 通道ID: {}", channel.getGbId()); recordStreamMap.put(channel.getGbId(), streamInfo); diff --git a/src/main/java/com/genersoft/iot/vmp/streamProxy/controller/StreamProxyController.java b/src/main/java/com/genersoft/iot/vmp/streamProxy/controller/StreamProxyController.java index 4cf966a5..d7f8d62b 100755 --- a/src/main/java/com/genersoft/iot/vmp/streamProxy/controller/StreamProxyController.java +++ b/src/main/java/com/genersoft/iot/vmp/streamProxy/controller/StreamProxyController.java @@ -187,7 +187,7 @@ public class StreamProxyController { @Parameter(name = "id", description = "代理Id", required = true) public StreamContent start(int id){ log.info("播放代理: {}", id); - StreamInfo streamInfo = streamProxyPlayService.start(id); + StreamInfo streamInfo = streamProxyPlayService.start(id, null, null); if (streamInfo == null) { throw new ControllerException(ErrorCode.ERROR100.getCode(), ErrorCode.ERROR100.getMsg()); }else { diff --git a/src/main/java/com/genersoft/iot/vmp/streamProxy/service/IStreamProxyPlayService.java b/src/main/java/com/genersoft/iot/vmp/streamProxy/service/IStreamProxyPlayService.java index 18b1499a..284c90bf 100755 --- a/src/main/java/com/genersoft/iot/vmp/streamProxy/service/IStreamProxyPlayService.java +++ b/src/main/java/com/genersoft/iot/vmp/streamProxy/service/IStreamProxyPlayService.java @@ -6,7 +6,7 @@ import com.genersoft.iot.vmp.streamProxy.bean.StreamProxy; public interface IStreamProxyPlayService { - StreamInfo start(int id); + StreamInfo start(int id, Boolean record, ErrorCallback callback); void start(int id, ErrorCallback callback); diff --git a/src/main/java/com/genersoft/iot/vmp/streamProxy/service/impl/StreamProxyPlayServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/streamProxy/service/impl/StreamProxyPlayServiceImpl.java index 9e5fa140..3d4e75c6 100755 --- a/src/main/java/com/genersoft/iot/vmp/streamProxy/service/impl/StreamProxyPlayServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/streamProxy/service/impl/StreamProxyPlayServiceImpl.java @@ -14,11 +14,6 @@ import com.genersoft.iot.vmp.streamProxy.dao.StreamProxyMapper; import com.genersoft.iot.vmp.streamProxy.service.IStreamProxyPlayService; import com.genersoft.iot.vmp.vmanager.bean.ErrorCode; import lombok.extern.slf4j.Slf4j; - -import java.util.concurrent.ConcurrentHashMap; - -import javax.sip.message.Response; - import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.event.EventListener; import org.springframework.scheduling.annotation.Async; @@ -27,6 +22,9 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; +import javax.sip.message.Response; +import java.util.concurrent.ConcurrentHashMap; + /** * 视频代理业务 */ @@ -90,11 +88,14 @@ public class StreamProxyPlayServiceImpl implements IStreamProxyPlayService { } @Override - public StreamInfo start(int id) { + public StreamInfo start(int id, Boolean record, ErrorCallback callback) { StreamProxy streamProxy = streamProxyMapper.select(id); if (streamProxy == null) { throw new ControllerException(ErrorCode.ERROR404.getCode(), "代理信息未找到"); } + if (record != null) { + streamProxy.setEnableMp4(record); + } return startProxy(streamProxy); }