优化拉流代理

This commit is contained in:
648540858
2024-07-19 17:54:14 +08:00
parent 78088ba53f
commit 9f4e66a38b
23 changed files with 607 additions and 351 deletions

View File

@@ -82,7 +82,8 @@ public class CommonChannelController {
@Operation(summary = "增加通道", security = @SecurityRequirement(name = JwtUtils.HEADER))
@ResponseBody
@PostMapping("/add")
public void add(@RequestBody CommonGBChannel channel){
public CommonGBChannel add(@RequestBody CommonGBChannel channel){
channelService.add(channel);
return channel;
}
}

View File

@@ -95,8 +95,8 @@ public class MediaController {
return new StreamContent(streamInfo);
}else {
//获取流失败,重启拉流后重试一次
streamProxyService.stop(app,stream);
boolean start = streamProxyService.start(app, stream);
streamProxyService.stopByAppAndStream(app,stream);
boolean start = streamProxyService.startByAppAndStream(app, stream);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
@@ -117,4 +117,30 @@ public class MediaController {
}
}
}
/**
* 获取推流播放地址
* @param app 应用名
* @param stream 流id
* @return
*/
@GetMapping(value = "/getPlayUrl")
@ResponseBody
@Operation(summary = "获取推流播放地址", security = @SecurityRequirement(name = JwtUtils.HEADER))
@Parameter(name = "app", description = "应用名", required = true)
@Parameter(name = "stream", description = "流id", required = true)
@Parameter(name = "mediaServerId", description = "媒体服务器id")
public StreamContent getPlayUrl(@RequestParam String app, @RequestParam String stream,
@RequestParam(required = false) String mediaServerId){
boolean authority = false;
// 是否登陆用户, 登陆用户返回完整信息
LoginUser userInfo = SecurityUtils.getUserInfo();
if (userInfo!= null) {
authority = true;
}
StreamInfo streamInfo = mediaServerService.getStreamInfoByAppAndStreamWithCheck(app, stream, mediaServerId, authority);
if (streamInfo == null){
throw new ControllerException(ErrorCode.ERROR100.getCode(), "获取播放地址失败");
}
return new StreamContent(streamInfo);
}
}

View File

@@ -12,16 +12,12 @@ public interface CommonGBChannelMapper {
@Select("select\n" +
" id as gb_id,\n" +
" device_db_id,\n" +
" id as gb_id,\n" +
" device_db_id as gb_device_db_id,\n" +
" stream_push_id,\n" +
" stream_proxy_id,\n" +
" create_time,\n" +
" update_time,\n" +
" sub_count,\n" +
" stream_id,\n" +
" has_audio,\n" +
" gps_time,\n" +
" stream_identification,\n" +
" coalesce(gb_device_id, device_id) as gb_device_id,\n" +
" coalesce(gb_name, name) as gb_name,\n" +
" coalesce(gb_manufacturer, manufacturer) as gb_manufacturer,\n" +
@@ -141,6 +137,7 @@ public interface CommonGBChannelMapper {
"#{gbSvcTimeSupportMode}"+
")" +
" </script>")
@Options(useGeneratedKeys = true, keyProperty = "gbId", keyColumn = "id")
int insert(CommonGBChannel commonGBChannel);
@Select(" select\n" +
@@ -283,16 +280,11 @@ public interface CommonGBChannelMapper {
@Select(value = {" <script>" +
" select\n" +
" id as gb_id,\n" +
" device_db_id,\n" +
" device_db_id as gb_device_db_id,\n" +
" stream_push_id,\n" +
" stream_proxy_id,\n" +
" create_time,\n" +
" update_time,\n" +
" sub_count,\n" +
" stream_id,\n" +
" has_audio,\n" +
" gps_time,\n" +
" stream_identification,\n" +
" coalesce(gb_device_id, device_id) as gb_device_id,\n" +
" coalesce(gb_name, name) as gb_name,\n" +
" coalesce(gb_manufacturer, manufacturer) as gb_manufacturer,\n" +
@@ -462,16 +454,11 @@ public interface CommonGBChannelMapper {
@Select(value = {" <script>" +
" select\n" +
" id as gb_id,\n" +
" device_db_id,\n" +
" device_db_id as gb_device_db_id,\n" +
" stream_push_id,\n" +
" stream_proxy_id,\n" +
" create_time,\n" +
" update_time,\n" +
" sub_count,\n" +
" stream_id,\n" +
" has_audio,\n" +
" gps_time,\n" +
" stream_identification,\n" +
" coalesce(gb_device_id, device_id) as gb_device_id,\n" +
" coalesce(gb_name, name) as gb_name,\n" +
" coalesce(gb_manufacturer, manufacturer) as gb_manufacturer,\n" +
@@ -518,4 +505,94 @@ public interface CommonGBChannelMapper {
" <foreach collection='channelListInDb' item='item' open='(' separator=',' close=')' > #{item.gbId}</foreach>" +
"</script>"})
void batchDelete(List<CommonGBChannel> channelListInDb);
@Select(value = {"select\n" +
" id as gb_id,\n" +
" device_db_id as gb_device_db_id,\n" +
" stream_push_id,\n" +
" stream_proxy_id,\n" +
" create_time,\n" +
" update_time,\n" +
" coalesce(gb_device_id, device_id) as gb_device_id,\n" +
" coalesce(gb_name, name) as gb_name,\n" +
" coalesce(gb_manufacturer, manufacturer) as gb_manufacturer,\n" +
" coalesce(gb_model, model) as gb_model,\n" +
" coalesce(gb_owner, owner) as gb_owner,\n" +
" coalesce(gb_civil_code, civil_code) as gb_civil_code,\n" +
" coalesce(gb_block, block) as gb_block,\n" +
" coalesce(gb_address, address) as gb_address,\n" +
" coalesce(gb_parental, parental) as gb_parental,\n" +
" coalesce(gb_parent_id, parent_id) as gb_parent_id,\n" +
" coalesce(gb_safety_way, safety_way) as gb_safety_way,\n" +
" coalesce(gb_register_way, register_way) as gb_register_way,\n" +
" coalesce(gb_cert_num, cert_num) as gb_cert_num,\n" +
" coalesce(gb_certifiable, certifiable) as gb_certifiable,\n" +
" coalesce(gb_err_code, err_code) as gb_err_code,\n" +
" coalesce(gb_end_time, end_time) as gb_end_time,\n" +
" coalesce(gb_secrecy, secrecy) as gb_secrecy,\n" +
" coalesce(gb_ip_address, ip_address) as gb_ip_address,\n" +
" coalesce(gb_port, port) as gb_port,\n" +
" coalesce(gb_password, password) as gb_password,\n" +
" coalesce(gb_status, status) as gb_status,\n" +
" coalesce(gb_longitude, longitude) as gb_longitude,\n" +
" coalesce(gb_latitude, latitude) as gb_latitude,\n" +
" coalesce(gb_ptz_type, ptz_type) as gb_ptz_type,\n" +
" coalesce(gb_position_type, position_type) as gb_position_type,\n" +
" coalesce(gb_room_type, room_type) as gb_room_type,\n" +
" coalesce(gb_use_type, use_type) as gb_use_type,\n" +
" coalesce(gb_supply_light_type, supply_light_type) as gb_supply_light_type,\n" +
" coalesce(gb_direction_type, direction_type) as gb_direction_type,\n" +
" coalesce(gb_resolution, resolution) as gb_resolution,\n" +
" coalesce(gb_business_group_id, business_group_id) as gb_business_group_id,\n" +
" coalesce(gb_download_speed, download_speed) as gb_download_speed,\n" +
" coalesce(gb_svc_space_support_mod, svc_space_support_mod) as gb_svc_space_support_mod,\n" +
" coalesce(gb_svc_time_support_mode,svc_time_support_mode) as gb_svc_time_support_mode\n" +
"from wvp_device_channel \n" +
"where stream_push_id = #{streamPushId}"})
CommonGBChannel queryByStreamPushId(@Param("streamPushId") Integer streamPushId);
@Select(value = {"select\n" +
" id as gb_id,\n" +
" device_db_id as gb_device_db_id,\n" +
" stream_push_id,\n" +
" stream_proxy_id,\n" +
" create_time,\n" +
" update_time,\n" +
" coalesce(gb_device_id, device_id) as gb_device_id,\n" +
" coalesce(gb_name, name) as gb_name,\n" +
" coalesce(gb_manufacturer, manufacturer) as gb_manufacturer,\n" +
" coalesce(gb_model, model) as gb_model,\n" +
" coalesce(gb_owner, owner) as gb_owner,\n" +
" coalesce(gb_civil_code, civil_code) as gb_civil_code,\n" +
" coalesce(gb_block, block) as gb_block,\n" +
" coalesce(gb_address, address) as gb_address,\n" +
" coalesce(gb_parental, parental) as gb_parental,\n" +
" coalesce(gb_parent_id, parent_id) as gb_parent_id,\n" +
" coalesce(gb_safety_way, safety_way) as gb_safety_way,\n" +
" coalesce(gb_register_way, register_way) as gb_register_way,\n" +
" coalesce(gb_cert_num, cert_num) as gb_cert_num,\n" +
" coalesce(gb_certifiable, certifiable) as gb_certifiable,\n" +
" coalesce(gb_err_code, err_code) as gb_err_code,\n" +
" coalesce(gb_end_time, end_time) as gb_end_time,\n" +
" coalesce(gb_secrecy, secrecy) as gb_secrecy,\n" +
" coalesce(gb_ip_address, ip_address) as gb_ip_address,\n" +
" coalesce(gb_port, port) as gb_port,\n" +
" coalesce(gb_password, password) as gb_password,\n" +
" coalesce(gb_status, status) as gb_status,\n" +
" coalesce(gb_longitude, longitude) as gb_longitude,\n" +
" coalesce(gb_latitude, latitude) as gb_latitude,\n" +
" coalesce(gb_ptz_type, ptz_type) as gb_ptz_type,\n" +
" coalesce(gb_position_type, position_type) as gb_position_type,\n" +
" coalesce(gb_room_type, room_type) as gb_room_type,\n" +
" coalesce(gb_use_type, use_type) as gb_use_type,\n" +
" coalesce(gb_supply_light_type, supply_light_type) as gb_supply_light_type,\n" +
" coalesce(gb_direction_type, direction_type) as gb_direction_type,\n" +
" coalesce(gb_resolution, resolution) as gb_resolution,\n" +
" coalesce(gb_business_group_id, business_group_id) as gb_business_group_id,\n" +
" coalesce(gb_download_speed, download_speed) as gb_download_speed,\n" +
" coalesce(gb_svc_space_support_mod, svc_space_support_mod) as gb_svc_space_support_mod,\n" +
" coalesce(gb_svc_time_support_mode,svc_time_support_mode) as gb_svc_time_support_mode\n" +
"from wvp_device_channel \n" +
"where stream_proxy_id = #{streamProxyId}"})
CommonGBChannel queryByStreamProxyId(@Param("streamProxyId") Integer streamProxyId);
}

View File

@@ -34,6 +34,18 @@ public class GbChannelServiceImpl implements IGbChannelService {
@Override
public int add(CommonGBChannel commonGBChannel) {
if (commonGBChannel.getStreamPushId() != null && commonGBChannel.getStreamPushId() > 0) {
CommonGBChannel commonGBChannelInDb = commonGBChannelMapper.queryByStreamPushId(commonGBChannel.getStreamPushId());
if (commonGBChannelInDb != null) {
throw new ControllerException(ErrorCode.ERROR100.getCode(), "此推流已经关联通道");
}
}
if (commonGBChannel.getStreamProxyId() != null && commonGBChannel.getStreamProxyId() > 0) {
CommonGBChannel commonGBChannelInDb = commonGBChannelMapper.queryByStreamProxyId(commonGBChannel.getStreamProxyId());
if (commonGBChannelInDb != null) {
throw new ControllerException(ErrorCode.ERROR100.getCode(), "此代理已经关联通道");
}
}
return commonGBChannelMapper.insert(commonGBChannel);
}
@@ -74,6 +86,7 @@ public class GbChannelServiceImpl implements IGbChannelService {
log.warn("[更新通道] 未找到数据库ID更新失败 {}", commonGBChannel.getGbDeviceDbId());
return 0;
}
commonGBChannel.setUpdateTime(DateUtil.getNow());
int result = commonGBChannelMapper.update(commonGBChannel);
if (result > 0) {
try {

View File

@@ -743,7 +743,7 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
log.info("[ app={}, stream={} ] 等待拉流代理流超时", sendRtpItem.getApp(), sendRtpItem.getStream());
hookSubscribe.removeSubscribe(hook);
}, userSetting.getPlatformPlayTimeout());
boolean start = streamProxyService.start(sendRtpItem.getApp(), sendRtpItem.getStream());
boolean start = streamProxyService.startByAppAndStream(sendRtpItem.getApp(), sendRtpItem.getStream());
if (!start) {
try {
responseAck(request, Response.BUSY_HERE, "channel [" + sendRtpItem.getChannelId() + "] offline");