临时提交

pull/1642/head
648540858 2024-08-12 18:00:06 +08:00
parent 9a4a81a90e
commit 213b218efa
4 changed files with 111 additions and 8 deletions

View File

@ -15,5 +15,7 @@ public class InviteInfo {
private Long startTime; private Long startTime;
private Long stopTime; private Long stopTime;
private String downloadSpeed; private String downloadSpeed;
private String ip;
private int port;
} }

View File

@ -0,0 +1,14 @@
package com.genersoft.iot.vmp.gb28181.bean;
import lombok.Data;
@Data
public class PlayException extends RuntimeException{
private int code;
private String msg;
public PlayException(int code, String msg) {
this.code = code;
this.msg = msg;
}
}

View File

@ -1,5 +1,6 @@
package com.genersoft.iot.vmp.gb28181.service.impl; package com.genersoft.iot.vmp.gb28181.service.impl;
import com.genersoft.iot.vmp.common.StreamInfo;
import com.genersoft.iot.vmp.conf.exception.ControllerException; import com.genersoft.iot.vmp.conf.exception.ControllerException;
import com.genersoft.iot.vmp.gb28181.bean.*; import com.genersoft.iot.vmp.gb28181.bean.*;
import com.genersoft.iot.vmp.gb28181.dao.CommonGBChannelMapper; import com.genersoft.iot.vmp.gb28181.dao.CommonGBChannelMapper;
@ -7,7 +8,9 @@ import com.genersoft.iot.vmp.gb28181.dao.GroupMapper;
import com.genersoft.iot.vmp.gb28181.dao.RegionMapper; import com.genersoft.iot.vmp.gb28181.dao.RegionMapper;
import com.genersoft.iot.vmp.gb28181.event.EventPublisher; import com.genersoft.iot.vmp.gb28181.event.EventPublisher;
import com.genersoft.iot.vmp.gb28181.event.subscribe.catalog.CatalogEvent; import com.genersoft.iot.vmp.gb28181.event.subscribe.catalog.CatalogEvent;
import com.genersoft.iot.vmp.gb28181.service.IDeviceService;
import com.genersoft.iot.vmp.gb28181.service.IGbChannelService; import com.genersoft.iot.vmp.gb28181.service.IGbChannelService;
import com.genersoft.iot.vmp.service.bean.ErrorCallback;
import com.genersoft.iot.vmp.utils.DateUtil; import com.genersoft.iot.vmp.utils.DateUtil;
import com.genersoft.iot.vmp.vmanager.bean.ErrorCode; import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
@ -19,6 +22,7 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import javax.sip.message.Response;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
@ -34,6 +38,9 @@ public class GbChannelServiceImpl implements IGbChannelService {
@Autowired @Autowired
private CommonGBChannelMapper commonGBChannelMapper; private CommonGBChannelMapper commonGBChannelMapper;
@Autowired
private IDeviceService deviceService;
@Autowired @Autowired
private RegionMapper regionMapper; private RegionMapper regionMapper;
@ -637,4 +644,18 @@ public class GbChannelServiceImpl implements IGbChannelService {
public CommonGBChannel queryOneWithPlatform(Integer platformId, String channelDeviceId) { public CommonGBChannel queryOneWithPlatform(Integer platformId, String channelDeviceId) {
return commonGBChannelMapper.queryOneWithPlatform(platformId, channelDeviceId); return commonGBChannelMapper.queryOneWithPlatform(platformId, channelDeviceId);
} }
@Override
public void start(CommonGBChannel channel, ErrorCallback<StreamInfo> callback) {
if (channel.getGbDeviceDbId() > 0) {
// 国标通道
Device device = deviceService.getDevice(channel.getGbDeviceDbId());
if (device == null) {
log.warn("[点播] 未找到通道{}的设备信息", channel);
throw new PlayException(Response.SERVER_INTERNAL_ERROR, "serverInternalError");
}
}
}
} }

View File

@ -10,6 +10,7 @@ import com.genersoft.iot.vmp.conf.SipConfig;
import com.genersoft.iot.vmp.conf.UserSetting; import com.genersoft.iot.vmp.conf.UserSetting;
import com.genersoft.iot.vmp.conf.exception.ControllerException; import com.genersoft.iot.vmp.conf.exception.ControllerException;
import com.genersoft.iot.vmp.gb28181.bean.*; import com.genersoft.iot.vmp.gb28181.bean.*;
import com.genersoft.iot.vmp.gb28181.service.IDeviceService;
import com.genersoft.iot.vmp.gb28181.service.IGbChannelService; import com.genersoft.iot.vmp.gb28181.service.IGbChannelService;
import com.genersoft.iot.vmp.gb28181.service.IPlayService; import com.genersoft.iot.vmp.gb28181.service.IPlayService;
import com.genersoft.iot.vmp.gb28181.session.AudioBroadcastManager; import com.genersoft.iot.vmp.gb28181.session.AudioBroadcastManager;
@ -83,6 +84,9 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
@Autowired @Autowired
private IVideoManagerStorage storager; private IVideoManagerStorage storager;
@Autowired
private IDeviceService deviceService;
@Autowired @Autowired
private IGbChannelService channelService; private IGbChannelService channelService;
@ -158,7 +162,58 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
SIPRequest request = (SIPRequest)evt.getRequest(); SIPRequest request = (SIPRequest)evt.getRequest();
try { try {
InviteInfo inviteInfo = decode(evt); InviteInfo inviteInfo = decode(evt);
} catch (SdpParseException e) {
// 查询请求是否来自上级平台\设备
Platform platform = storager.queryParentPlatByServerGBId(inviteInfo.getRequesterId());
if (platform == null) {
inviteFromDeviceHandle(request, inviteInfo.getRequesterId(), inviteInfo.getChannelId());
} else {
// 查询平台下是否有该通道
CommonGBChannel channel= channelService.queryOneWithPlatform(platform.getId(), inviteInfo.getChannelId());
if (channel == null) {
log.info("[上级INVITE] 通道不存在返回404: {}", inviteInfo.getChannelId());
try {
// 通道不存在发404资源不存在
responseAck(request, Response.NOT_FOUND);
} catch (SipException | InvalidArgumentException | ParseException e) {
log.error("[命令发送失败] invite 通道不存在: {}", e.getMessage());
}
return;
}
// 通道存在发100TRYING
try {
responseAck(request, Response.TRYING);
} catch (SipException | InvalidArgumentException | ParseException e) {
log.error("[命令发送失败] invite TRYING: {}", e.getMessage());
}
channelService.start(channel, ((code, msg, data) -> {
if (code != Response.OK) {
try {
responseAck(request, code, msg);
} catch (SipException | InvalidArgumentException | ParseException e) {
log.error("[命令发送失败] 点播失败: {}", e.getMessage());
}
}else {
}
}));
if (channel.getGbDeviceDbId() > 0) {
Device device = deviceService.getDevice(channel.getGbDeviceDbId());
if (device == null) {
log.warn("点播平台{}的通道{}时未找到设备信息", requesterId, channel);
try {
responseAck(request, Response.SERVER_INTERNAL_ERROR);
} catch (SipException | InvalidArgumentException | ParseException e) {
log.error("[命令发送失败] invite 未找到设备信息: {}", e.getMessage());
}
return;
}
}
}
} catch (SdpException e) {
// 参数不全, 发400请求错误 // 参数不全, 发400请求错误
try { try {
responseAck(request, Response.BAD_REQUEST); responseAck(request, Response.BAD_REQUEST);
@ -172,6 +227,12 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
} catch (SipException | InvalidArgumentException | ParseException e) { } catch (SipException | InvalidArgumentException | ParseException e) {
log.error("[命令发送失败] invite BAD_REQUEST: {}", e.getMessage()); log.error("[命令发送失败] invite BAD_REQUEST: {}", e.getMessage());
} }
}catch (PlayException e) {
try {
responseAck(request, e.getCode(), e.getMsg());
} catch (SipException | InvalidArgumentException | ParseException e) {
log.error("[命令发送失败] invite 点播失败: {}", e.getMessage());
}
} }
// Invite Request消息实现此消息一般为级联消息上级给下级发送请求视频指令 // Invite Request消息实现此消息一般为级联消息上级给下级发送请求视频指令
@ -546,7 +607,7 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
inviteInfo.setChannelId(channelId); inviteInfo.setChannelId(channelId);
inviteInfo.setSessionName(sessionName); inviteInfo.setSessionName(sessionName);
inviteInfo.setSsrc(gb28181Sdp.getSsrc()); inviteInfo.setSsrc(gb28181Sdp.getSsrc());
inviteInfo.setCallId(request.getCallIdHeader().getCallId()); inviteInfo.setCallId(callIdHeader.getCallId());
// 如果是录像回放,则会存在录像的开始时间与结束时间 // 如果是录像回放,则会存在录像的开始时间与结束时间
Long startTime = null; Long startTime = null;
@ -603,12 +664,12 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
inviteInfo.setStartTime(startTime); inviteInfo.setStartTime(startTime);
inviteInfo.setStopTime(stopTime); inviteInfo.setStopTime(stopTime);
String username = sdp.getOrigin().getUsername(); String username = sdp.getOrigin().getUsername();
String addressStr; // String addressStr;
if(StringUtils.isEmpty(platform.getSendStreamIp())){ // if(StringUtils.isEmpty(platform.getSendStreamIp())){
addressStr = sdp.getConnection().getAddress(); // addressStr = sdp.getConnection().getAddress();
}else { // }else {
addressStr = platform.getSendStreamIp(); // addressStr = platform.getSendStreamIp();
} // }
Vector sdpMediaDescriptions = sdp.getMediaDescriptions(true); Vector sdpMediaDescriptions = sdp.getMediaDescriptions(true);
MediaDescription mediaDescription = null; MediaDescription mediaDescription = null;
@ -619,6 +680,11 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
if (mediaDescription != null) { if (mediaDescription != null) {
downloadSpeed = mediaDescription.getAttribute("downloadspeed"); downloadSpeed = mediaDescription.getAttribute("downloadspeed");
} }
inviteInfo.setIp(sdp.getConnection().getAddress());
inviteInfo.setPort(port);
inviteInfo.setDownloadSpeed(downloadSpeed);
return inviteInfo;
} }