修复网页语音对讲

pull/1669/head
648540858 2024-10-23 15:20:34 +08:00
parent cb39593a79
commit 93de123330
6 changed files with 77 additions and 24 deletions

View File

@ -211,7 +211,7 @@ public class PlayController {
if (device == null) { if (device == null) {
throw new ControllerException(ErrorCode.ERROR400.getCode(), "未找到设备: " + deviceId); throw new ControllerException(ErrorCode.ERROR400.getCode(), "未找到设备: " + deviceId);
} }
DeviceChannel channel = deviceChannelService.getOneForSource(device.getId(), channelId); DeviceChannel channel = deviceChannelService.getOne(deviceId, channelId);
if (channel == null) { if (channel == null) {
throw new ControllerException(ErrorCode.ERROR400.getCode(), "未找到通道: " + channelId); throw new ControllerException(ErrorCode.ERROR400.getCode(), "未找到通道: " + channelId);
} }

View File

@ -604,4 +604,56 @@ public interface DeviceChannelMapper {
" WHERE id = #{id}" + " WHERE id = #{id}" +
"</script>"}) "</script>"})
void updateChannelForNotify(DeviceChannel channel); void updateChannelForNotify(DeviceChannel channel);
@Select(value = {" <script>" +
" SELECT " +
" id,\n" +
" device_db_id,\n" +
" create_time,\n" +
" update_time,\n" +
" sub_count,\n" +
" stream_id,\n" +
" has_audio,\n" +
" gps_time,\n" +
" stream_identification,\n" +
" channel_type,\n" +
" device_id,\n" +
" name,\n" +
" manufacturer,\n" +
" model,\n" +
" owner,\n" +
" civil_code,\n" +
" block,\n" +
" address,\n" +
" parental,\n" +
" parent_id,\n" +
" safety_way,\n" +
" register_way,\n" +
" cert_num,\n" +
" certifiable,\n" +
" err_code,\n" +
" end_time,\n" +
" secrecy,\n" +
" ip_address,\n" +
" port,\n" +
" password,\n" +
" status,\n" +
" longitude,\n" +
" latitude,\n" +
" ptz_type,\n" +
" position_type,\n" +
" room_type,\n" +
" use_type,\n" +
" supply_light_type,\n" +
" direction_type,\n" +
" resolution,\n" +
" business_group_id,\n" +
" download_speed,\n" +
" svc_space_support_mod,\n" +
" svc_time_support_mode\n" +
" from wvp_device_channel " +
" where device_db_id=#{deviceDbId} and device_id = #{channelId}" +
" </script>"})
DeviceChannel getOneBySourceChannelId(int deviceDbId, String channelId);
} }

View File

@ -119,4 +119,7 @@ public interface IDeviceChannelService {
void updateChannelForNotify(DeviceChannel channel); void updateChannelForNotify(DeviceChannel channel);
DeviceChannel getOneForSource(int deviceDbId, String channelId); DeviceChannel getOneForSource(int deviceDbId, String channelId);
DeviceChannel getOneBySourceId(int deviceDbId, String channelId);
} }

View File

@ -273,6 +273,11 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService {
return channelMapper.getOneByDeviceIdForSource(deviceDbId, channelId); return channelMapper.getOneByDeviceIdForSource(deviceDbId, channelId);
} }
@Override
public DeviceChannel getOneBySourceId(int deviceDbId, String channelId) {
return channelMapper.getOneBySourceChannelId(deviceDbId, channelId);
}
@Override @Override
@Transactional @Transactional
public synchronized void batchUpdateChannelForNotify(List<DeviceChannel> channels) { public synchronized void batchUpdateChannelForNotify(List<DeviceChannel> channels) {

View File

@ -138,7 +138,7 @@ public class PlayServiceImpl implements IPlayService {
String deviceId = streamArray[0]; String deviceId = streamArray[0];
String channelId = streamArray[1]; String channelId = streamArray[1];
Device device = deviceService.getDeviceByDeviceId(deviceId); Device device = deviceService.getDeviceByDeviceId(deviceId);
DeviceChannel channel = deviceChannelService.getOne(deviceId, channelId); DeviceChannel channel = deviceChannelService.getOneForSource(deviceId, channelId);
if (device == null) { if (device == null) {
log.info("[语音对讲/喊话] 未找到设备:{}", deviceId); log.info("[语音对讲/喊话] 未找到设备:{}", deviceId);
return; return;
@ -218,7 +218,7 @@ public class PlayServiceImpl implements IPlayService {
log.info("[语音对讲/喊话] 未找到设备:{}", deviceId); log.info("[语音对讲/喊话] 未找到设备:{}", deviceId);
return; return;
} }
DeviceChannel channel = deviceChannelService.getOne(deviceId, channelId); DeviceChannel channel = deviceChannelService.getOneForSource(deviceId, channelId);
if (channel == null) { if (channel == null) {
log.info("[语音对讲/喊话] 未找到通道:{}", channelId); log.info("[语音对讲/喊话] 未找到通道:{}", channelId);
return; return;
@ -1220,36 +1220,30 @@ public class PlayServiceImpl implements IPlayService {
} }
@Override @Override
public boolean audioBroadcastCmd(Device device, DeviceChannel channel, MediaServer mediaServerItem, String app, String stream, int timeout, boolean isFromPlatform, AudioBroadcastEvent event) throws InvalidArgumentException, ParseException, SipException { public boolean audioBroadcastCmd(Device device, DeviceChannel deviceChannel, MediaServer mediaServerItem, String app, String stream, int timeout, boolean isFromPlatform, AudioBroadcastEvent event) throws InvalidArgumentException, ParseException, SipException {
Assert.notNull(device, "设备不存在"); Assert.notNull(device, "设备不存在");
Assert.notNull(channel, "通道不存在"); Assert.notNull(deviceChannel, "通道不存在");
log.info("[语音喊话] device {}, channel: {}", device.getDeviceId(), channel.getDeviceId()); log.info("[语音喊话] device {}, channel: {}", device.getDeviceId(), deviceChannel.getDeviceId());
DeviceChannel deviceChannel = deviceChannelService.getOne(device.getDeviceId(), channel.getDeviceId());
if (deviceChannel == null) {
log.warn("开启语音广播的时候未找到通道: {}", channel.getDeviceId());
event.call("开启语音广播的时候未找到通道");
return false;
}
// 查询通道使用状态 // 查询通道使用状态
if (audioBroadcastManager.exit(deviceChannel.getId())) { if (audioBroadcastManager.exit(deviceChannel.getId())) {
SendRtpInfo sendRtpInfo = sendRtpServerService.queryByChannelId(channel.getId(), device.getDeviceId()); SendRtpInfo sendRtpInfo = sendRtpServerService.queryByChannelId(deviceChannel.getId(), device.getDeviceId());
if (sendRtpInfo != null && sendRtpInfo.isOnlyAudio()) { if (sendRtpInfo != null && sendRtpInfo.isOnlyAudio()) {
// 查询流是否存在,不存在则认为是异常状态 // 查询流是否存在,不存在则认为是异常状态
Boolean streamReady = mediaServerService.isStreamReady(mediaServerItem, sendRtpInfo.getApp(), sendRtpInfo.getStream()); Boolean streamReady = mediaServerService.isStreamReady(mediaServerItem, sendRtpInfo.getApp(), sendRtpInfo.getStream());
if (streamReady) { if (streamReady) {
log.warn("语音广播已经开启: {}", channel.getDeviceId()); log.warn("语音广播已经开启: {}", deviceChannel.getDeviceId());
event.call("语音广播已经开启"); event.call("语音广播已经开启");
return false; return false;
} else { } else {
stopAudioBroadcast(device, channel); stopAudioBroadcast(device, deviceChannel);
} }
} }
} }
// 发送通知 // 发送通知
cmder.audioBroadcastCmd(device, channel.getDeviceId(), eventResultForOk -> { cmder.audioBroadcastCmd(device, deviceChannel.getDeviceId(), eventResultForOk -> {
// 发送成功 // 发送成功
AudioBroadcastCatch audioBroadcastCatch = new AudioBroadcastCatch(device.getDeviceId(), channel.getId(), mediaServerItem, app, stream, event, AudioBroadcastCatchStatus.Ready, isFromPlatform); AudioBroadcastCatch audioBroadcastCatch = new AudioBroadcastCatch(device.getDeviceId(), deviceChannel.getId(), mediaServerItem, app, stream, event, AudioBroadcastCatchStatus.Ready, isFromPlatform);
audioBroadcastManager.update(audioBroadcastCatch); audioBroadcastManager.update(audioBroadcastCatch);
// 等待invite消息 超时则结束 // 等待invite消息 超时则结束
String key = VideoManagerConstants.BROADCAST_WAITE_INVITE + device.getDeviceId(); String key = VideoManagerConstants.BROADCAST_WAITE_INVITE + device.getDeviceId();
@ -1257,14 +1251,14 @@ public class PlayServiceImpl implements IPlayService {
key += audioBroadcastCatch.getChannelId(); key += audioBroadcastCatch.getChannelId();
} }
dynamicTask.startDelay(key, ()->{ dynamicTask.startDelay(key, ()->{
log.info("[语音广播]等待invite消息超时{}/{}", device.getDeviceId(), channel.getDeviceId()); log.info("[语音广播]等待invite消息超时{}/{}", device.getDeviceId(), deviceChannel.getDeviceId());
stopAudioBroadcast(device, channel); stopAudioBroadcast(device, deviceChannel);
}, 10*1000); }, 10*1000);
}, eventResultForError -> { }, eventResultForError -> {
// 发送失败 // 发送失败
log.error("语音广播发送失败: {}:{}", channel.getDeviceId(), eventResultForError.msg); log.error("语音广播发送失败: {}:{}", deviceChannel.getDeviceId(), eventResultForError.msg);
event.call("语音广播发送失败"); event.call("语音广播发送失败");
stopAudioBroadcast(device, channel); stopAudioBroadcast(device, deviceChannel);
}); });
return true; return true;
} }

View File

@ -1,13 +1,12 @@
package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.response.cmd; package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.response.cmd;
import com.genersoft.iot.vmp.conf.DynamicTask;
import com.genersoft.iot.vmp.gb28181.bean.*; import com.genersoft.iot.vmp.gb28181.bean.*;
import com.genersoft.iot.vmp.gb28181.service.IDeviceChannelService; import com.genersoft.iot.vmp.gb28181.service.IDeviceChannelService;
import com.genersoft.iot.vmp.gb28181.service.IPlayService;
import com.genersoft.iot.vmp.gb28181.session.AudioBroadcastManager; import com.genersoft.iot.vmp.gb28181.session.AudioBroadcastManager;
import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent; import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent;
import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.IMessageHandler; import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.IMessageHandler;
import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.response.ResponseMessageHandler; import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.response.ResponseMessageHandler;
import com.genersoft.iot.vmp.gb28181.service.IPlayService;
import gov.nist.javax.sip.message.SIPRequest; import gov.nist.javax.sip.message.SIPRequest;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.dom4j.Element; import org.dom4j.Element;
@ -54,7 +53,7 @@ public class BroadcastResponseMessageHandler extends SIPRequestProcessorParent i
String channelId = getText(rootElement, "DeviceID"); String channelId = getText(rootElement, "DeviceID");
DeviceChannel channel = null; DeviceChannel channel = null;
if (!channelId.equals(device.getDeviceId())) { if (!channelId.equals(device.getDeviceId())) {
channel = deviceChannelService.getOne(device.getDeviceId(), channelId); channel = deviceChannelService.getOneBySourceId(device.getId(), channelId);
}else { }else {
channel = deviceChannelService.getBroadcastChannel(device.getId()); channel = deviceChannelService.getBroadcastChannel(device.getId());
} }