修复编辑通道编号后无法点播的BUG

This commit is contained in:
648540858
2024-09-13 15:06:11 +08:00
parent fa063b3fda
commit 875285418b
13 changed files with 220 additions and 100 deletions

View File

@@ -70,6 +70,8 @@ public interface IDeviceChannelService {
*/
DeviceChannel getOne(String deviceId, String channelId);
DeviceChannel getOneForSource(String deviceId, String channelId);
/**
* 直接批量更新通道
*/
@@ -120,5 +122,7 @@ public interface IDeviceChannelService {
DeviceChannel getOneById(Integer channelId);
DeviceChannel getOneForSourceById(Integer channelId);
DeviceChannel getBroadcastChannel(int deviceDbId);
}

View File

@@ -1,14 +1,16 @@
package com.genersoft.iot.vmp.gb28181.service;
import com.genersoft.iot.vmp.common.InviteInfo;
import com.genersoft.iot.vmp.common.InviteSessionType;
import com.genersoft.iot.vmp.common.StreamInfo;
import com.genersoft.iot.vmp.conf.exception.ServiceException;
import com.genersoft.iot.vmp.gb28181.bean.*;
import com.genersoft.iot.vmp.gb28181.controller.bean.AudioBroadcastEvent;
import com.genersoft.iot.vmp.media.bean.MediaInfo;
import com.genersoft.iot.vmp.media.bean.MediaServer;
import com.genersoft.iot.vmp.service.bean.ErrorCallback;
import com.genersoft.iot.vmp.service.bean.SSRCInfo;
import com.genersoft.iot.vmp.vmanager.bean.AudioBroadcastResult;
import com.genersoft.iot.vmp.gb28181.controller.bean.AudioBroadcastEvent;
import gov.nist.javax.sip.message.SIPResponse;
import javax.sip.InvalidArgumentException;
@@ -58,11 +60,14 @@ public interface IPlayService {
void getSnap(String deviceId, String channelId, String fileName, ErrorCallback errorCallback);
void stopPlay(Device device, DeviceChannel channel);
void stop(InviteSessionType type, Device device, DeviceChannel channel, String stream);
void stop(InviteInfo inviteInfo);
void play(CommonGBChannel channel, ErrorCallback<StreamInfo> callback);
void playBack(CommonGBChannel channel, Long startTime, Long stopTime, ErrorCallback<StreamInfo> callback);
void download(CommonGBChannel channel, Long startTime, Long stopTime, Integer downloadSpeed, ErrorCallback<StreamInfo> callback);
}

View File

@@ -252,6 +252,15 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService {
return channelMapper.getOneByDeviceId(device.getId(), channelId);
}
@Override
public DeviceChannel getOneForSource(String deviceId, String channelId){
Device device = deviceMapper.getDeviceByDeviceId(deviceId);
if (device == null) {
throw new ControllerException(ErrorCode.ERROR100.getCode(), "未找到设备:" + deviceId);
}
return channelMapper.getOneByDeviceIdForSource(device.getId(), channelId);
}
@Override
public synchronized void batchUpdateChannel(List<DeviceChannel> channels) {
String now = DateUtil.getNow();
@@ -595,6 +604,11 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService {
return channelMapper.getOne(channelId);
}
@Override
public DeviceChannel getOneForSourceById(Integer channelId) {
return channelMapper.getOneForSource(channelId);
}
@Override
public DeviceChannel getBroadcastChannel(int deviceDbId) {
List<DeviceChannel> channels = channelMapper.getByDeviceId(deviceDbId);

View File

@@ -226,6 +226,15 @@ public class PlayServiceImpl implements IPlayService {
}
}
}
}else if ("rtp".equals(event.getApp())) {
// 释放ssrc
InviteInfo inviteInfo = inviteStreamService.getInviteInfoByStream(null, event.getStream());
if (inviteInfo != null && inviteInfo.getStatus() == InviteSessionStatus.ok
&& inviteInfo.getStreamInfo() != null && inviteInfo.getSsrcInfo() != null) {
// 发送bye
stop(inviteInfo);
}
}
}
@@ -286,7 +295,7 @@ public class PlayServiceImpl implements IPlayService {
log.warn("[点播] 单端口收流时不支持TCP主动方式收流 deviceId: {},channelId:{}", deviceId, channelId);
throw new ControllerException(ErrorCode.ERROR100.getCode(), "单端口收流时不支持TCP主动方式收流");
}
DeviceChannel channel = deviceChannelService.getOne(deviceId, channelId);
DeviceChannel channel = deviceChannelService.getOneForSource(deviceId, channelId);
if (channel == null) {
log.warn("[点播] 未找到通道 deviceId: {},channelId:{}", deviceId, channelId);
throw new ControllerException(ErrorCode.ERROR100.getCode(), "未找到通道");
@@ -1529,24 +1538,56 @@ public class PlayServiceImpl implements IPlayService {
}
@Override
public void stopPlay(Device device, DeviceChannel channel) {
InviteInfo inviteInfo = inviteStreamService.getInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, channel.getId());
public void stop(InviteSessionType type, Device device, DeviceChannel channel, String stream) {
InviteInfo inviteInfo = inviteStreamService.getInviteInfoByStream(type, stream);
if (inviteInfo == null) {
throw new ControllerException(ErrorCode.ERROR100.getCode(), "点播未找到");
}
if (InviteSessionStatus.ok == inviteInfo.getStatus()) {
try {
log.info("[停止点播] {}/{}", device.getDeviceId(), channel.getDeviceId());
log.info("[停止点播/回放/下载] {}/{}", device.getDeviceId(), channel.getDeviceId());
cmder.streamByeCmd(device, channel.getDeviceId(), inviteInfo.getStream(), null, null);
} catch (InvalidArgumentException | SipException | ParseException | SsrcTransactionNotFoundException e) {
log.error("[命令发送失败] 停止点播, 发送BYE: {}", e.getMessage());
log.error("[命令发送失败] 停止点播/回放/下载 发送BYE: {}", e.getMessage());
throw new ControllerException(ErrorCode.ERROR100.getCode(), "命令发送失败: " + e.getMessage());
}
}
inviteStreamService.removeInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, channel.getId());
deviceChannelService.stopPlay(channel.getId());
inviteStreamService.removeInviteInfoByDeviceAndChannel(inviteInfo.getType(), channel.getId());
if (inviteInfo.getType() == InviteSessionType.PLAY) {
deviceChannelService.stopPlay(channel.getId());
}
if (inviteInfo.getStreamInfo() != null) {
mediaServerService.closeRTPServer(inviteInfo.getStreamInfo().getMediaServer(), inviteInfo.getStream());
receiveRtpServerService.closeRTPServer(inviteInfo.getStreamInfo().getMediaServer(), inviteInfo.getSsrcInfo());
}
}
@Override
public void stop(InviteInfo inviteInfo) {
Assert.notNull(inviteInfo, "参数异常");
DeviceChannel channel = deviceChannelService.getOneForSourceById(inviteInfo.getChannelId());
if (channel == null) {
log.warn("[停止点播] 发现通道不存在");
return;
}
Device device = deviceService.getDevice(channel.getDeviceDbId());
if (device == null) {
log.warn("[停止点播] 发现设备不存在");
return;
}
if (InviteSessionStatus.ok == inviteInfo.getStatus()) {
try {
log.info("[停止点播/回放/下载] {}/{}", device.getDeviceId(), channel.getDeviceId());
cmder.streamByeCmd(device, channel.getDeviceId(), inviteInfo.getStream(), null, null);
} catch (InvalidArgumentException | SipException | ParseException | SsrcTransactionNotFoundException e) {
log.warn("[命令发送失败] 停止点播/回放/下载, 发送BYE: {}", e.getMessage());
}
}
inviteStreamService.removeInviteInfoByDeviceAndChannel(inviteInfo.getType(), channel.getId());
if (inviteInfo.getType() == InviteSessionType.PLAY) {
deviceChannelService.stopPlay(channel.getId());
}
if (inviteInfo.getStreamInfo() != null) {
receiveRtpServerService.closeRTPServer(inviteInfo.getStreamInfo().getMediaServer(), inviteInfo.getSsrcInfo());
}
}