From b8a3a680f3e6720a8329bfaae571b09659aace52 Mon Sep 17 00:00:00 2001 From: Pu Zhibing <393733352@qq.com> Date: 星期三, 09 四月 2025 19:47:55 +0800 Subject: [PATCH] 开发推流拉流工具类 --- ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/CarController.java | 58 ++++++++++++++++++++++++++++++++++++++++++++++------------ 1 files changed, 46 insertions(+), 12 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 6389a8e..b0f5363 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 @@ -20,6 +20,7 @@ import com.ruoyi.system.service.ICarTypeService; import com.ruoyi.system.service.IDriverService; import com.ruoyi.system.service.IEnterpriseService; +import com.ruoyi.system.util.JavaCVStreamUtil; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; @@ -34,6 +35,10 @@ import java.time.LocalDateTime; import java.time.ZoneOffset; import java.util.List; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; /** * @author zhibing.pu @@ -43,30 +48,23 @@ @RequestMapping("/car") public class CarController { + private String outputUrl = "F:\\nginx 1.7.11.3 Gryphon\\html\\"; @Resource private ICarService carService; - @Resource private IDriverService driverService; - @Resource private IEnterpriseService enterpriseService; - @Resource private RealVideoMsgClient realVideoMsgClient; - @Resource private PlaybackMsgClient playbackMsgClient; - @Resource private UPExgMsgRealLocationClient upExgMsgRealLocationClient; - @Resource private ICarTypeService carTypeService; - @Resource private RedisTemplate redisTemplate; - @GetMapping("/getCarList") @ApiOperation(value = "获取车辆列表", tags = {"车辆管理"}) @@ -113,12 +111,37 @@ if (200 == msgStartupAckVoR.getCode()) { UPRealvideoMsgStartupAckVo data = msgStartupAckVoR.getData(); RealVideoResp resp = new RealVideoResp(); - resp.setServerIp(data.getServerIP()); - resp.setServerPort(data.getServerPort()); + String url = "rtmp://192.168.110.85:1935/flv-live/" + car.getVehicleNumber(); + //执行拉流和推流 + ExecutorService executorService = new ThreadPoolExecutor(1, 1, + 0L, TimeUnit.MILLISECONDS, + new LinkedBlockingQueue<Runnable>()); + executorService.execute(new Runnable() { + @Override + public void run() { + JavaCVStreamUtil.push_flv(data.getUrl(), url, id); + } + }); + resp.setUrl(url); return R.ok(resp); } + return R.fail(msgStartupAckVoR.getMsg()); } + + + @GetMapping("/closeRealVideo/{id}") + @ApiOperation(value = "关闭实时音视频", tags = {"车辆管理"}) + @ApiImplicitParams({ + @ApiImplicitParam(value = "车辆id", name = "id", required = true) + }) + public R closeRealVideo(@PathVariable("id") Integer id){ + JavaCVStreamUtil.close(id); + return R.ok(); + } + + + @GetMapping("/getPlaybackVideo") @@ -134,8 +157,18 @@ if (200 == startupAckVoR.getCode()) { UPPlaybackMsgStartupAckVo data = startupAckVoR.getData(); RealVideoResp resp = new RealVideoResp(); - resp.setServerIp(data.getServerIP()); - resp.setServerPort(data.getServerPort()); + String url = "rtmp://192.168.110.85:1935/flv-live/" + car.getVehicleNumber(); + //执行拉流和推流 + ExecutorService executorService = new ThreadPoolExecutor(1, 1, + 0L, TimeUnit.MILLISECONDS, + new LinkedBlockingQueue<Runnable>()); + executorService.execute(new Runnable() { + @Override + public void run() { + JavaCVStreamUtil.push_flv(data.getUrl(), url, req.getId()); + } + }); + resp.setUrl(url); return R.ok(resp); } return R.fail(startupAckVoR.getMsg()); @@ -223,6 +256,7 @@ if (null != gnssDataVo) { car.setLongitude(new BigDecimal(gnssDataVo.getLon()).divide(new BigDecimal(1000000)).toString()); car.setLatitude(new BigDecimal(gnssDataVo.getLat()).divide(new BigDecimal(1000000)).toString()); + car.setSpeed(gnssDataVo.getVec1()); } } return R.ok(list); -- Gitblit v1.7.1