Commit 8056704b by guoxuejian

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

parent 8324360f
......@@ -37,6 +37,8 @@ import java.util.stream.Collectors;
@Slf4j
public class LiveStreamServiceImpl implements ILiveStreamService {
private static final int LIVE_ALREADY_STREAMING_CODE = 513003;
@Autowired
private ICapacityCameraService capacityCameraService;
......@@ -137,8 +139,14 @@ public class LiveStreamServiceImpl implements ILiveStreamService {
.setVideoId(liveParam.getVideoId())
.setVideoQuality(liveParam.getVideoQuality()));
if (!response.getData().getResult().isSuccess()) {
return HttpResultResponse.error(response.getData().getResult());
boolean isStartPushSuccess = response.getData().getResult().isSuccess();
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();
......@@ -161,7 +169,15 @@ public class LiveStreamServiceImpl implements ILiveStreamService {
.toString());
break;
case RTSP:
if (StringUtils.hasText(response.getData().getOutput())) {
live.setUrl(response.getData().getOutput());
} else {
// RTSP 在“已在直播”且无 output 时无法构造可用地址,返回原始错误
if (!isStartPushSuccess) {
return HttpResultResponse.error(response.getData().getResult());
}
live.setUrl(url.toString());
}
break;
case WHIP:
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