Commit 3d9d432b by guoxuejian Committed by gdj

fix: handle live stream reuse when already streaming and improve error handling

parent c2c11e95
...@@ -37,6 +37,8 @@ import java.util.stream.Collectors; ...@@ -37,6 +37,8 @@ import java.util.stream.Collectors;
@Slf4j @Slf4j
public class LiveStreamServiceImpl implements ILiveStreamService { public class LiveStreamServiceImpl implements ILiveStreamService {
private static final int LIVE_ALREADY_STREAMING_CODE = 513003;
@Autowired @Autowired
private ICapacityCameraService capacityCameraService; private ICapacityCameraService capacityCameraService;
...@@ -137,8 +139,14 @@ public class LiveStreamServiceImpl implements ILiveStreamService { ...@@ -137,8 +139,14 @@ public class LiveStreamServiceImpl implements ILiveStreamService {
.setVideoId(liveParam.getVideoId()) .setVideoId(liveParam.getVideoId())
.setVideoQuality(liveParam.getVideoQuality())); .setVideoQuality(liveParam.getVideoQuality()));
if (!response.getData().getResult().isSuccess()) { boolean isStartPushSuccess = response.getData().getResult().isSuccess();
return HttpResultResponse.error(response.getData().getResult()); if (!isStartPushSuccess) {
HttpResultResponse errorResponse = HttpResultResponse.error(response.getData().getResult());
// 复用场景:设备已在直播时,不应阻断新观看者会话注册
if (errorResponse.getCode() != LIVE_ALREADY_STREAMING_CODE) {
return errorResponse;
}
log.info("Live stream already started on device, reuse existing stream. videoId={}", liveParam.getVideoId());
} }
LiveDTO live = new LiveDTO(); LiveDTO live = new LiveDTO();
...@@ -161,7 +169,15 @@ public class LiveStreamServiceImpl implements ILiveStreamService { ...@@ -161,7 +169,15 @@ public class LiveStreamServiceImpl implements ILiveStreamService {
.toString()); .toString());
break; break;
case RTSP: case RTSP:
if (StringUtils.hasText(response.getData().getOutput())) {
live.setUrl(response.getData().getOutput()); live.setUrl(response.getData().getOutput());
} else {
// RTSP 在“已在直播”且无 output 时无法构造可用地址,返回原始错误
if (!isStartPushSuccess) {
return HttpResultResponse.error(response.getData().getResult());
}
live.setUrl(url.toString());
}
break; break;
case WHIP: case WHIP:
live.setUrl(url.toString().replace("whip", "whep")); live.setUrl(url.toString().replace("whip", "whep"));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment