| | |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.genersoft.iot.vmp.common.StreamInfo; |
| | | import com.genersoft.iot.vmp.conf.UserSetup; |
| | | import com.genersoft.iot.vmp.gb28181.bean.Device; |
| | | import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel; |
| | | import com.genersoft.iot.vmp.gb28181.event.SipSubscribe; |
| | |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.http.HttpStatus; |
| | | import org.springframework.http.ResponseEntity; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | import org.springframework.web.context.request.async.DeferredResult; |
| | | |
| | | import javax.sip.ClientTransaction; |
| | | import javax.sip.Dialog; |
| | | import javax.sip.header.CallIdHeader; |
| | | import javax.sip.message.Response; |
| | | import java.io.File; |
| | | import java.io.FileNotFoundException; |
| | | import java.util.UUID; |
| | | |
| | | @SuppressWarnings(value = {"rawtypes", "unchecked"}) |
| | | @Service |
| | | public class PlayServiceImpl implements IPlayService { |
| | | |
| | |
| | | @Autowired |
| | | private VideoStreamSessionManager streamSession; |
| | | |
| | | @Value("${userSettings.playTimeout}") |
| | | private long playTimeout; |
| | | @Autowired |
| | | private UserSetup userSetup; |
| | | |
| | | |
| | | @Override |
| | |
| | | playResult.setDevice(device); |
| | | UUID uuid = UUID.randomUUID(); |
| | | playResult.setUuid(uuid.toString()); |
| | | DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String>>(playTimeout); |
| | | DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String>>(userSetup.getPlayTimeout()); |
| | | playResult.setResult(result); |
| | | // 录像查询以channelId作为deviceId查询 |
| | | resultHolder.put(DeferredResultHolder.CALLBACK_CMD_PlAY + uuid, result); |
| | |
| | | result.onCompletion(()->{ |
| | | // 点播结束时调用截图接口 |
| | | try { |
| | | String path = ResourceUtils.getURL("classpath:").getPath()+"static/static/snap/"; |
| | | String classPath = ResourceUtils.getURL("classpath:").getPath(); |
| | | // System.out.println(classPath); |
| | | // 兼容打包为jar的class路径 |
| | | if(classPath.contains("jar")) { |
| | | classPath = classPath.substring(0, classPath.lastIndexOf(".")); |
| | | classPath = classPath.substring(0, classPath.lastIndexOf("/") + 1); |
| | | } |
| | | if (classPath.startsWith("file:")) { |
| | | classPath = classPath.substring(classPath.indexOf(":") + 1, classPath.length()); |
| | | } |
| | | String path = classPath + "static/static/snap/"; |
| | | // 兼容Windows系统路径(去除前面的“/”) |
| | | if(System.getProperty("os.name").contains("indows")) { |
| | | path = path.substring(1, path.length()); |
| | | } |
| | | String fileName = deviceId + "_" + channelId + ".jpg"; |
| | | ResponseEntity responseEntity = (ResponseEntity)result.getResult(); |
| | | if (responseEntity != null && responseEntity.getStatusCode() == HttpStatus.OK) { |
| | |
| | | StreamInfo streamInfoForSuccess = (StreamInfo)wvpResult.getData(); |
| | | String flvUrl = streamInfoForSuccess.getFlv(); |
| | | // 请求截图 |
| | | zlmresTfulUtils.getSnap(flvUrl, 5, 1, path, fileName); |
| | | zlmresTfulUtils.getSnap(flvUrl, 15, 1, path, fileName); |
| | | } |
| | | } |
| | | |
| | | System.out.println(path); |
| | | } catch (FileNotFoundException e) { |
| | | e.printStackTrace(); |