Commit eb177a67424c0f83ab02abe338dbc3cd0d49cd62
Committed by
GitHub
Merge pull request #570 from TristingChen/optimize--play-complete
优化--直播接口流程结束异步处理截图操作,提高接口响应速度和并发能力
Showing
1 changed file
with
22 additions
and
14 deletions
src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java
| ... | ... | @@ -11,8 +11,10 @@ import javax.sip.ResponseEvent; |
| 11 | 11 | import org.slf4j.Logger; |
| 12 | 12 | import org.slf4j.LoggerFactory; |
| 13 | 13 | import org.springframework.beans.factory.annotation.Autowired; |
| 14 | +import org.springframework.beans.factory.annotation.Qualifier; | |
| 14 | 15 | import org.springframework.http.HttpStatus; |
| 15 | 16 | import org.springframework.http.ResponseEntity; |
| 17 | +import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; | |
| 16 | 18 | import org.springframework.stereotype.Service; |
| 17 | 19 | import org.springframework.web.context.request.async.DeferredResult; |
| 18 | 20 | |
| ... | ... | @@ -104,6 +106,10 @@ public class PlayServiceImpl implements IPlayService { |
| 104 | 106 | private ZLMHttpHookSubscribe subscribe; |
| 105 | 107 | |
| 106 | 108 | |
| 109 | + @Qualifier("taskExecutor") | |
| 110 | + @Autowired | |
| 111 | + private ThreadPoolTaskExecutor taskExecutor; | |
| 112 | + | |
| 107 | 113 | |
| 108 | 114 | |
| 109 | 115 | @Override |
| ... | ... | @@ -135,21 +141,23 @@ public class PlayServiceImpl implements IPlayService { |
| 135 | 141 | |
| 136 | 142 | result.onCompletion(()->{ |
| 137 | 143 | // 点播结束时调用截图接口 |
| 138 | - // TODO 应该在上流时调用更好,结束也可能是错误结束 | |
| 139 | - String path = "snap"; | |
| 140 | - String fileName = deviceId + "_" + channelId + ".jpg"; | |
| 141 | - ResponseEntity responseEntity = (ResponseEntity)result.getResult(); | |
| 142 | - if (responseEntity != null && responseEntity.getStatusCode() == HttpStatus.OK) { | |
| 143 | - WVPResult wvpResult = (WVPResult)responseEntity.getBody(); | |
| 144 | - if (Objects.requireNonNull(wvpResult).getCode() == 0) { | |
| 145 | - StreamInfo streamInfoForSuccess = (StreamInfo)wvpResult.getData(); | |
| 146 | - MediaServerItem mediaInfo = mediaServerService.getOne(streamInfoForSuccess.getMediaServerId()); | |
| 147 | - String streamUrl = streamInfoForSuccess.getFmp4(); | |
| 148 | - // 请求截图 | |
| 149 | - logger.info("[请求截图]: " + fileName); | |
| 150 | - zlmresTfulUtils.getSnap(mediaInfo, streamUrl, 15, 1, path, fileName); | |
| 144 | + taskExecutor.execute(()->{ | |
| 145 | + // TODO 应该在上流时调用更好,结束也可能是错误结束 | |
| 146 | + String path = "snap"; | |
| 147 | + String fileName = deviceId + "_" + channelId + ".jpg"; | |
| 148 | + ResponseEntity responseEntity = (ResponseEntity)result.getResult(); | |
| 149 | + if (responseEntity != null && responseEntity.getStatusCode() == HttpStatus.OK) { | |
| 150 | + WVPResult wvpResult = (WVPResult)responseEntity.getBody(); | |
| 151 | + if (Objects.requireNonNull(wvpResult).getCode() == 0) { | |
| 152 | + StreamInfo streamInfoForSuccess = (StreamInfo)wvpResult.getData(); | |
| 153 | + MediaServerItem mediaInfo = mediaServerService.getOne(streamInfoForSuccess.getMediaServerId()); | |
| 154 | + String streamUrl = streamInfoForSuccess.getFmp4(); | |
| 155 | + // 请求截图 | |
| 156 | + logger.info("[请求截图]: " + fileName); | |
| 157 | + zlmresTfulUtils.getSnap(mediaInfo, streamUrl, 15, 1, path, fileName); | |
| 158 | + } | |
| 151 | 159 | } |
| 152 | - } | |
| 160 | + }); | |
| 153 | 161 | }); |
| 154 | 162 | if (streamInfo != null) { |
| 155 | 163 | String streamId = streamInfo.getStream(); | ... | ... |