PreviewController.java
2.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package com.objecteye.controller;
import com.objecteye.common.CommonResult;
import com.objecteye.entity.SyAreaEquipment;
import com.objecteye.entity.SyEquipment;
import com.objecteye.service.AreaEquipmentService;
import com.objecteye.service.EquipmentService;
import com.objecteye.utils.PreviewUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Map;
@Api(tags = "PreviewController", description = "实时预览")
@RestController
@RequestMapping(value = "/preview")
@CrossOrigin
public class PreviewController {
@Autowired
private EquipmentService equipmentService;
@Autowired
private AreaEquipmentService areaEquipmentService;
@ApiOperation("实时预览:获取rtmp流")
@RequestMapping(value = "/getRtmpStream", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
public CommonResult getRtmpStream(@RequestBody Map<String, Integer> map) {
try {
/*String token = map.get("token");
String userNameFromToken = jwtTokenUtil.getUserNameFromToken(token);
System.out.println("username:"+userNameFromToken);*/
String address = InetAddress.getLocalHost().toString().split("/")[1];
//获得区域信息
int deviceId = map.get("deviceId");
SyAreaEquipment areaEquipment = areaEquipmentService.findOne(deviceId);
if (areaEquipment != null) {
Integer isEquipment = areaEquipment.getIsEquipment();
//为设备,进行转流
if (isEquipment == 1) {
Integer typeId = areaEquipment.getTypeId();
SyEquipment equipment = equipmentService.findOne(typeId);
if (equipment == null) {
throw new RuntimeException("设备无效");
}
//进行转流
String rtmp = PreviewUtils.RtspToRtmp(address, equipment.getRtspUrl(), typeId, equipment.getUsername(), equipment.getPassword(), equipment.getEquipmentIp(), equipment.getIntentPort());
if (rtmp != null) {
return CommonResult.success(rtmp);
}
return CommonResult.failed("转流失败");
} else { //选择区域,则提示信息
return CommonResult.failed("请选择具体设备");
}
}
} catch (RuntimeException e) {
//e.printStackTrace();
return CommonResult.failed(e.getMessage());
} catch (InterruptedException e) {
e.printStackTrace();
} catch (UnknownHostException e) {
e.printStackTrace();
}
return CommonResult.failed("转流失败");
}
}