From 2d217c614073681cf14719fd201993d5c5fb5aa7 Mon Sep 17 00:00:00 2001 From: Pu Zhibing <393733352@qq.com> Date: 星期五, 18 四月 2025 16:25:14 +0800 Subject: [PATCH] 修改测试bug --- ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/CarController.java | 135 ++++++++++++++++++++++++++------------------ 1 files changed, 79 insertions(+), 56 deletions(-) diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/CarController.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/CarController.java index f5d89b4..008df12 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/CarController.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/CarController.java @@ -52,14 +52,23 @@ @RequestMapping("/car") public class CarController { - @Value("${live.output.path}") - private String outputPath; + @Value("${live.hls.output-path}") + private String hlsOutputPath; - @Value("${live.ip}") - private String liveIp; + @Value("${live.hls.ip}") + private String hlsIp; - @Value("${live.port}") - private Integer livePort; + @Value("${live.hls.port}") + private Integer hlsPort; + + @Value("${live.flv.ip}") + private String flvIp; + + @Value("${live.flv.rtmp-port}") + private Integer flvRtmpPort; + + @Value("${live.flv.http-port}") + private Integer flvHttpPort; @Resource private ICarService carService; @Resource @@ -115,39 +124,24 @@ public R<RealVideoResp> getRealVideo(@PathVariable("id") Integer id) { Car car = carService.getById(id); if (null == car) { - return R.fail("失败"); + return R.fail("车辆信息获取失败"); } //手动加一次状态数据,避免定时任务结束任务线程 redisTemplate.opsForValue().set("live:" + id, true, 1, TimeUnit.MINUTES); Enterprise enterprise = enterpriseService.getById(car.getEnterpriseId()); R<UPRealvideoMsgStartupAckVo> msgStartupAckVoR = realVideoMsgClient.startupRealVideo(Integer.valueOf(enterprise.getCode()), car.getVehicleNumber()); if (200 == msgStartupAckVoR.getCode()) { - String path = outputPath + "hls\\" + car.getVehicleNumber() + "\\live.m3u8"; - String folderPath = outputPath + "hls\\" + car.getVehicleNumber(); - FileUtil.mkParentDirs(path); - File file = new File(path); - if (!file.exists()) { - try { - file.createNewFile(); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - UPRealvideoMsgStartupAckVo data = msgStartupAckVoR.getData(); + RealVideoResp resp = new RealVideoResp(); //执行拉流和推流 - ExecutorService executorService = new ThreadPoolExecutor(1, 1, - 0L, TimeUnit.MILLISECONDS, - new LinkedBlockingQueue<Runnable>()); - executorService.execute(new Runnable() { - @Override - public void run() { - JavaCVStreamUtil.push_hls(data.getUrl(), path, id, folderPath); - } - }); - resp.setServerIp(liveIp); - resp.setServerPort(livePort); +// live_hls(data.getUrl(), car); +// resp.setServerIp(hlsIp); +// resp.setServerPort(hlsPort); + + live_flv(data.getUrl(), car.getId()); + resp.setServerIp(flvIp); + resp.setServerPort(flvHttpPort); return R.ok(resp); } @@ -165,7 +159,7 @@ if (null == car) { return R.fail("失败"); } - String folderPath = outputPath + "hls\\" + car.getVehicleNumber(); + String folderPath = hlsOutputPath + "hls\\" + car.getVehicleNumber(); JavaCVStreamUtil.close(id, folderPath); return R.ok(); } @@ -197,30 +191,14 @@ if (200 == startupAckVoR.getCode()) { UPPlaybackMsgStartupAckVo data = startupAckVoR.getData(); RealVideoResp resp = new RealVideoResp(); - String path = outputPath + "hls\\" + car.getVehicleNumber() + "\\live.m3u8"; - String folderPath = outputPath + "hls\\" + car.getVehicleNumber(); - FileUtil.mkParentDirs(path); - File file = new File(path); - if (!file.exists()) { - try { - file.createNewFile(); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - //执行拉流和推流 - ExecutorService executorService = new ThreadPoolExecutor(1, 1, - 0L, TimeUnit.MILLISECONDS, - new LinkedBlockingQueue<Runnable>()); - executorService.execute(new Runnable() { - @Override - public void run() { - JavaCVStreamUtil.push_hls(data.getUrl(), path, req.getId(), folderPath); - } - }); - resp.setServerIp(liveIp); - resp.setServerPort(livePort); +// live_hls(data.getUrl(), car); +// resp.setServerIp(hlsIp); +// resp.setServerPort(hlsPort); + + live_flv(data.getUrl(), car.getId()); + resp.setServerIp(flvIp); + resp.setServerPort(flvHttpPort); return R.ok(resp); } return R.fail(startupAckVoR.getMsg()); @@ -302,8 +280,11 @@ public R<List<Car>> getMapCarList() { List<Car> list = carService.list(new LambdaQueryWrapper<Car>().eq(Car::getStatus, 1)); for (Car car : list) { - Long s = (null == car.getDownlineTime() ? LocalDateTime.now() : car.getDownlineTime()).toEpochSecond(ZoneOffset.ofHours(8)) - car.getOnlineTime().toEpochSecond(ZoneOffset.ofHours(8)); - car.setDrivingTime(s / 60); + car.setDrivingTime(0L); + if(null != car.getOnlineTime()){ + Long s = (null == car.getDownlineTime() ? LocalDateTime.now() : car.getDownlineTime()).toEpochSecond(ZoneOffset.ofHours(8)) - car.getOnlineTime().toEpochSecond(ZoneOffset.ofHours(8)); + car.setDrivingTime(s / 60); + } GnssDataVo gnssDataVo = (GnssDataVo) redisTemplate.opsForValue().get("location:" + car.getVehicleNumber()); if (null != gnssDataVo) { car.setLongitude(new BigDecimal(gnssDataVo.getLon()).divide(new BigDecimal(1000000)).toString()); @@ -313,4 +294,46 @@ } return R.ok(list); } + + + public void live_hls(String input, Car car){ + String path = hlsOutputPath + "hls\\" + car.getVehicleNumber() + "\\live.m3u8"; + String folderPath = hlsOutputPath + "hls\\" + car.getVehicleNumber(); + FileUtil.mkParentDirs(path); + File file = new File(path); + if (!file.exists()) { + try { + file.createNewFile(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + //执行拉流和推流 + ExecutorService executorService = new ThreadPoolExecutor(1, 1, + 0L, TimeUnit.MILLISECONDS, + new LinkedBlockingQueue<Runnable>()); + executorService.execute(new Runnable() { + @Override + public void run() { + JavaCVStreamUtil.push_hls(input, path, car.getId(), folderPath); + } + }); + carService.taskPlayDetection(car.getId()); + } + + public void live_flv(String input, Integer id){ + String url = "rtmp://" + flvIp + ":" + flvRtmpPort + "/flv/" + id; + //执行拉流和推流 + ExecutorService executorService = new ThreadPoolExecutor(1, 1, + 0L, TimeUnit.MILLISECONDS, + new LinkedBlockingQueue<Runnable>()); + executorService.execute(new Runnable() { + @Override + public void run() { + JavaCVStreamUtil.push_flv(input, url, id); + } + }); + carService.taskPlayDetection(id); + } } -- Gitblit v1.7.1