nishiwei
5 days ago 3f43e40ed1a1e9f66b3ad2862da9dbc4b710c712
ard-sample/src/main/java/com/ard/sample/component/websocket/handler/LiveStreamHandler.java
@@ -79,23 +79,21 @@
    public void StopLiveStreaming(String sn) {
        ResponseResult rlive = null;
//        String resultLive = "";
        try {
            // 获取直播参数
            LiveTypeDTO param = getLiveParam(sn);
            // 停止直播逻辑
            rlive = _liveStreamService.liveStop(param.getVideoId());
            log.info("SN: {}-停止直播!返回值:{}", sn, rlive);
//            rlive.setGateway(sn);
//            rlive.setType(MessageType.LIVESTREAM.getType());
//            resultLive = _objectMapper.writeValueAsString(rlive);
            RedisOpsUtils.del(RedisConst.WEBSOCKET_VIDEO_ADDRESS_PREFIX + sn);
            log.info("SN: {}-停止直播,并删除redis直播信息!", sn);
        } catch (Exception e) {
            log.info("SN: {}-停止直播时发生异常,原因:{}", sn,e.getMessage());
            e.printStackTrace();
            log.info("SN: {}-停止直播时发生异常,原因:{}", sn, e.getMessage(), e);
        } finally {
            // 无论停流是否成功都清理缓存地址:
            // 设备离线等原因导致停流异常时,若不清 Redis,后续订阅会直接拿到失效地址,
            // 页面持续黑屏,只有等设备离线清理缓存后才能恢复
            RedisOpsUtils.del(RedisConst.WEBSOCKET_VIDEO_ADDRESS_PREFIX + sn);
            log.info("SN: {}-已删除redis直播信息!", sn);
        }
        // 停止直播不返回数据,直接删除redis中的直播地址标记即可;并且方法在websocket连接断开后执行。
    }
    public String getResult(String sn, String msg) {
@@ -140,32 +138,43 @@
                continue;
            }
            List<CapacityCameraDTO> camerasList = device.getCamerasList();
            for (CapacityCameraDTO camera : camerasList) {
                // 机场3中飞行器,没有name,需要其他条件确定主摄像头参数
                for(CapacityVideoDTO video : camera.getVideosList())
                {
                    if(video.getSwitchVideoTypes().size() == 1 && camera.getName() == null)
                    {
            if (camerasList == null || camerasList.isEmpty()) {
                        continue;
                    }
                }
//                camera.getVideosList().get(0).getSwitchVideoTypes().add("main");
//                if(camera.getVideosList().size() == 1 && camera.getName() == null) {
//                    continue;
//                }
//                if (camera.getName() == null || camera.getName().isEmpty()) {
//                    continue;
//                }
                String videoid = device.getSn() + "/" + camera.getIndex();
            for (CapacityCameraDTO camera : camerasList) {
                List<CapacityVideoDTO> videosList = camera.getVideosList();
                if (videosList == null || videosList.isEmpty()) {
                    continue;
                }
                // 机场1:M30 / M30T 相机索引为 52-x-x / 53-x-x,live_capacity 可能同时上报
                // normal-0、zoom-0、ir-0 多条码流。默认优先选 normal 码流(可见光),
                // 避免原来“循环取最后一条”时默认落到红外。其他机型保持原行为(取最后一条)。
                boolean m30SeriesCamera = camera.getIndex() != null
                        && (camera.getIndex().startsWith("52-") || camera.getIndex().startsWith("53-"));
                CapacityVideoDTO selectedVideo = null;
                for (CapacityVideoDTO video : videosList) {
                    videoid = videoid + "/" + video.getIndex();
                    selectedVideo = video;
                    if (m30SeriesCamera && video.getIndex() != null
                            && video.getIndex().startsWith("normal")) {
                        break;
                    }
                }
                if (selectedVideo == null) {
                    continue;
                }
                List<String> switchVideoTypes = selectedVideo.getSwitchVideoTypes();
                if (switchVideoTypes == null || switchVideoTypes.isEmpty()) {
                    // 没有镜头类型信息时跳过该相机,避免 get(0) 越界
                    continue;
                }
                // 机场1:video_id 格式固定为 {sn}/{camera_index}/{video_index}。
                // 按选中的码流独立构造,单码流设备结果与原来完全一致。
                String videoid = device.getSn() + "/" + camera.getIndex() + "/" + selectedVideo.getIndex();
                    param.setUrlType(1);
                    param.setUrl("");
                    param.setVideoId(videoid);
                    param.setVideoQuality(1);
                    param.setVideoType(video.getSwitchVideoTypes().get(0));
                }
                param.setVideoType(switchVideoTypes.get(0));
            }
        }
        return param;