Commit fc901e8c65b6a2ec3c19e60534202114970fccbe
1 parent
da14c7f2
更新readme
Showing
5 changed files
with
547 additions
and
0 deletions
README.md
| @@ -3,6 +3,8 @@ WEB VIDEO PLATFORM譏ッ荳荳ェ蝓コ莠雑B28181-2016譬螳樒鴫逧ス醍サ懆ァ「大ケウ蜿ー | @@ -3,6 +3,8 @@ WEB VIDEO PLATFORM譏ッ荳荳ェ蝓コ莠雑B28181-2016譬螳樒鴫逧ス醍サ懆ァ「大ケウ蜿ー | ||
| 3 | 豬∝ェ剃ス捺恪蜉。蝓コ莠算LMediaKit-https://github.com/xiongziliang/ZLMediaKit | 3 | 豬∝ェ剃ス捺恪蜉。蝓コ莠算LMediaKit-https://github.com/xiongziliang/ZLMediaKit |
| 4 | 蜑咲ォッ螻慕、コ蝓コ莠皿ediaServerUI-https://gitee.com/kkkkk5G/MediaServerUI/tree/gb28181/ | 4 | 蜑咲ォッ螻慕、コ蝓コ莠皿ediaServerUI-https://gitee.com/kkkkk5G/MediaServerUI/tree/gb28181/ |
| 5 | 5 | ||
| 6 | +### fork閾ェ [swwheihei/wvp-GB28181](https://github.com/swwheihei/wvp-GB28181) | ||
| 7 | + | ||
| 6 | # 蠎皮畑蝨コ譎ッ | 8 | # 蠎皮畑蝨コ譎ッ |
| 7 | 荳サ隕∝コ皮畑蝨ィIPC遲芽ョセ螟イ。譛牙崋螳唔P蝨ー蝮御ス怙隕∝惠莠定#鄂台クュ隗ら恚逧惻譎ッ縲 | 9 | 荳サ隕∝コ皮畑蝨ィIPC遲芽ョセ螟イ。譛牙崋螳唔P蝨ー蝮御ス怙隕∝惠莠定#鄂台クュ隗ら恚逧惻譎ッ縲 |
| 8 | 隕∵アPC隶セ螟庄莉・隶ソ髣ョ莠定#鄂托シ梧怏莠第恪蜉。蝎ィ逕ィ莠朱Κ鄂イ譛ャ譛榊苅縲 | 10 | 隕∵アPC隶セ螟庄莉・隶ソ髣ョ莠定#鄂托シ梧怏莠第恪蜉。蝎ィ逕ィ莠朱Κ鄂イ譛ャ譛榊苅縲 |
| @@ -36,3 +38,6 @@ WEB VIDEO PLATFORM譏ッ荳荳ェ蝓コ莠雑B28181-2016譬螳樒鴫逧ス醍サ懆ァ「大ケウ蜿ー | @@ -36,3 +38,6 @@ WEB VIDEO PLATFORM譏ッ荳荳ェ蝓コ莠雑B28181-2016譬螳樒鴫逧ス醍サ懆ァ「大ケウ蜿ー | ||
| 36 | # 閾エ隹「 | 38 | # 閾エ隹「 |
| 37 | 諢溯ー「菴懆螟乗・咯(https://github.com/xiongziliang) 謠蝉セ幄ソ吩ケ域」堤噪蠑貅先オ∝ェ剃ス捺恪蜉。譯楔 | 39 | 諢溯ー「菴懆螟乗・咯(https://github.com/xiongziliang) 謠蝉セ幄ソ吩ケ域」堤噪蠑貅先オ∝ェ剃ス捺恪蜉。譯楔 |
| 38 | 諢溯ー「菴懆kkkkk5G](https://gitee.com/kkkkk5G) 謠蝉セ幄ソ吩ケ域」堤噪蜑咲ォッUI | 40 | 諢溯ー「菴懆kkkkk5G](https://gitee.com/kkkkk5G) 謠蝉セ幄ソ吩ケ域」堤噪蜑咲ォッUI |
| 41 | + | ||
| 42 | + | ||
| 43 | +[]: https://github.com/swwheihei/wvp-GB28181 | ||
| 39 | \ No newline at end of file | 44 | \ No newline at end of file |
src/main/java/com/genersoft/iot/vmp/web/ApiControlController.java
0 → 100644
| 1 | +package com.genersoft.iot.vmp.web; | ||
| 2 | + | ||
| 3 | +import com.alibaba.fastjson.JSONObject; | ||
| 4 | +import com.genersoft.iot.vmp.gb28181.bean.Device; | ||
| 5 | +import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander; | ||
| 6 | +import com.genersoft.iot.vmp.storager.IVideoManagerStorager; | ||
| 7 | +import com.genersoft.iot.vmp.vmanager.ptz.PtzController; | ||
| 8 | +import org.slf4j.Logger; | ||
| 9 | +import org.slf4j.LoggerFactory; | ||
| 10 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 11 | +import org.springframework.http.HttpStatus; | ||
| 12 | +import org.springframework.http.ResponseEntity; | ||
| 13 | +import org.springframework.web.bind.annotation.*; | ||
| 14 | + | ||
| 15 | +/** | ||
| 16 | + * 兼容LiveGBS的API:设备控制 | ||
| 17 | + */ | ||
| 18 | +@CrossOrigin | ||
| 19 | +@RestController | ||
| 20 | +@RequestMapping(value = "/api/v1/control") | ||
| 21 | +public class ApiControlController { | ||
| 22 | + | ||
| 23 | + private final static Logger logger = LoggerFactory.getLogger(ApiControlController.class); | ||
| 24 | + | ||
| 25 | + @Autowired | ||
| 26 | + private SIPCommander cmder; | ||
| 27 | + | ||
| 28 | + @Autowired | ||
| 29 | + private IVideoManagerStorager storager; | ||
| 30 | + | ||
| 31 | + /** | ||
| 32 | + * 设备控制 - 云台控制 | ||
| 33 | + * @param serial 设备编号 | ||
| 34 | + * @param command 控制指令 允许值: left, right, up, down, upleft, upright, downleft, downright, zoomin, zoomout, stop | ||
| 35 | + * @param channel 通道序号 | ||
| 36 | + * @param code 通道编号 | ||
| 37 | + * @param speed 速度(0~255) 默认值: 129 | ||
| 38 | + * @return | ||
| 39 | + */ | ||
| 40 | + @RequestMapping(value = "/ptz") | ||
| 41 | + private JSONObject list(String serial,String command, | ||
| 42 | + @RequestParam(required = false)Integer channel, | ||
| 43 | + @RequestParam(required = false)String code, | ||
| 44 | + @RequestParam(required = false)Integer speed){ | ||
| 45 | + | ||
| 46 | + if (logger.isDebugEnabled()) { | ||
| 47 | + logger.debug(String.format("模拟接口> 设备云台控制 API调用,deviceId:%s ,channelId:%s ,command:%d ,speed:%d ", | ||
| 48 | + serial, code, command, speed)); | ||
| 49 | + } | ||
| 50 | + Device device = storager.queryVideoDevice(serial); | ||
| 51 | + int leftRight = 0; | ||
| 52 | + int upDown = 0; | ||
| 53 | + int inOut = 0; | ||
| 54 | + switch (command) { | ||
| 55 | + case "left": | ||
| 56 | + leftRight = 1; | ||
| 57 | + break; | ||
| 58 | + case "right": | ||
| 59 | + leftRight = 2; | ||
| 60 | + break; | ||
| 61 | + case "up": | ||
| 62 | + upDown = 1; | ||
| 63 | + break; | ||
| 64 | + case "down": | ||
| 65 | + upDown = 2; | ||
| 66 | + break; | ||
| 67 | + case "upleft": | ||
| 68 | + upDown = 1; | ||
| 69 | + leftRight = 1; | ||
| 70 | + case "upright": | ||
| 71 | + upDown = 1; | ||
| 72 | + leftRight = 2; | ||
| 73 | + break; | ||
| 74 | + case "downleft": | ||
| 75 | + upDown = 2; | ||
| 76 | + leftRight = 1; | ||
| 77 | + break; | ||
| 78 | + case "downright": | ||
| 79 | + upDown = 2; | ||
| 80 | + leftRight = 2; | ||
| 81 | + break; | ||
| 82 | + case "zoomin": | ||
| 83 | + inOut = 2; | ||
| 84 | + break; | ||
| 85 | + case "zoomout": | ||
| 86 | + inOut = 1; | ||
| 87 | + break; | ||
| 88 | + case "stop": | ||
| 89 | + break; | ||
| 90 | + | ||
| 91 | + } | ||
| 92 | + // 默认值 50 | ||
| 93 | + cmder.ptzCmd(device, code, leftRight, upDown, inOut, speed==0 ? 129 : speed, 50); | ||
| 94 | + return null; | ||
| 95 | + } | ||
| 96 | +} |
src/main/java/com/genersoft/iot/vmp/web/ApiController.java
0 → 100644
| 1 | +package com.genersoft.iot.vmp.web; | ||
| 2 | + | ||
| 3 | +import com.alibaba.fastjson.JSONObject; | ||
| 4 | +import com.genersoft.iot.vmp.conf.SipConfig; | ||
| 5 | +import org.slf4j.Logger; | ||
| 6 | +import org.slf4j.LoggerFactory; | ||
| 7 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 8 | +import org.springframework.beans.factory.annotation.Value; | ||
| 9 | +import org.springframework.stereotype.Controller; | ||
| 10 | +import org.springframework.web.bind.annotation.CrossOrigin; | ||
| 11 | +import org.springframework.web.bind.annotation.RequestMapping; | ||
| 12 | +import org.springframework.web.bind.annotation.RequestParam; | ||
| 13 | +import org.springframework.web.bind.annotation.ResponseBody; | ||
| 14 | + | ||
| 15 | +/** | ||
| 16 | + * 兼容LiveGBS的API:系统接口 | ||
| 17 | + */ | ||
| 18 | +@Controller | ||
| 19 | +@CrossOrigin | ||
| 20 | +@RequestMapping(value = "/api/v1") | ||
| 21 | +public class ApiController { | ||
| 22 | + | ||
| 23 | + private final static Logger logger = LoggerFactory.getLogger(ApiController.class); | ||
| 24 | + | ||
| 25 | + @Autowired | ||
| 26 | + private SipConfig sipConfig; | ||
| 27 | + | ||
| 28 | + | ||
| 29 | + @RequestMapping("/getserverinfo") | ||
| 30 | + private JSONObject getserverinfo(){ | ||
| 31 | + JSONObject result = new JSONObject(); | ||
| 32 | + result.put("Authorization","ceshi"); | ||
| 33 | + result.put("Hardware",""); | ||
| 34 | + result.put("InterfaceVersion","2.5.5"); | ||
| 35 | + result.put("IsDemo",""); | ||
| 36 | + result.put("Hardware","false"); | ||
| 37 | + result.put("APIAuth","false"); | ||
| 38 | + result.put("RemainDays","永久"); | ||
| 39 | + result.put("RunningTime",""); | ||
| 40 | + result.put("ServerTime","2020-09-02 17:11"); | ||
| 41 | + result.put("StartUpTime","2020-09-02 17:11"); | ||
| 42 | + result.put("Server",""); | ||
| 43 | + result.put("SIPSerial", sipConfig.getSipId()); | ||
| 44 | + result.put("SIPRealm", sipConfig.getSipDomain()); | ||
| 45 | + result.put("SIPHost", sipConfig.getSipIp()); | ||
| 46 | + result.put("SIPPort", sipConfig.getSipPort()); | ||
| 47 | + result.put("ChannelCount","1000"); | ||
| 48 | + result.put("VersionType",""); | ||
| 49 | + result.put("LogoMiniText",""); | ||
| 50 | + result.put("LogoText",""); | ||
| 51 | + result.put("CopyrightText",""); | ||
| 52 | + | ||
| 53 | + return result; | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + @RequestMapping(value = "/userinfo") | ||
| 57 | + private JSONObject userinfo(){ | ||
| 58 | +// JSONObject result = new JSONObject(); | ||
| 59 | +// result.put("ID","ceshi"); | ||
| 60 | +// result.put("Hardware",""); | ||
| 61 | +// result.put("InterfaceVersion","2.5.5"); | ||
| 62 | +// result.put("IsDemo",""); | ||
| 63 | +// result.put("Hardware","false"); | ||
| 64 | +// result.put("APIAuth","false"); | ||
| 65 | +// result.put("RemainDays","永久"); | ||
| 66 | +// result.put("RunningTime",""); | ||
| 67 | +// result.put("ServerTime","2020-09-02 17:11"); | ||
| 68 | +// result.put("StartUpTime","2020-09-02 17:11"); | ||
| 69 | +// result.put("Server",""); | ||
| 70 | +// result.put("SIPSerial", sipConfig.getSipId()); | ||
| 71 | +// result.put("SIPRealm", sipConfig.getSipDomain()); | ||
| 72 | +// result.put("SIPHost", sipConfig.getSipIp()); | ||
| 73 | +// result.put("SIPPort", sipConfig.getSipPort()); | ||
| 74 | +// result.put("ChannelCount","1000"); | ||
| 75 | +// result.put("VersionType",""); | ||
| 76 | +// result.put("LogoMiniText",""); | ||
| 77 | +// result.put("LogoText",""); | ||
| 78 | +// result.put("CopyrightText",""); | ||
| 79 | + | ||
| 80 | + return null; | ||
| 81 | + } | ||
| 82 | + | ||
| 83 | + /** | ||
| 84 | + * 系统接口 - 登录 | ||
| 85 | + * @param username 用户名 | ||
| 86 | + * @param password 密码(经过md5加密,32位长度,不带中划线,不区分大小写) | ||
| 87 | + * @return | ||
| 88 | + */ | ||
| 89 | + @RequestMapping(value = "/login") | ||
| 90 | + @ResponseBody | ||
| 91 | + private JSONObject login(String username,String password ){ | ||
| 92 | + if (logger.isDebugEnabled()) { | ||
| 93 | + logger.debug(String.format("模拟接口> 登录 API调用,username:%s ,password:%s ", | ||
| 94 | + username, password)); | ||
| 95 | + } | ||
| 96 | + | ||
| 97 | + JSONObject result = new JSONObject(); | ||
| 98 | + result.put("CookieToken","ynBDDiKMg"); | ||
| 99 | + result.put("URLToken","MOBkORkqnrnoVGcKIAHXppgfkNWRdV7utZSkDrI448Q.oxNjAxNTM4NDk3LCJwIjoiZGJjODg5NzliNzVj" + | ||
| 100 | + "Nzc2YmU5MzBjM2JjNjg1ZWFiNGI5ZjhhN2Y0N2RlZjg3NWUyOTJkY2VkYjkwYmEwMTA0NyIsInQiOjE2MDA5MzM2OTcsInUiOiI" + | ||
| 101 | + "4ODlkZDYyM2ViIn0eyJlIj.GciOiJIUzI1NiIsInR5cCI6IkpXVCJ9eyJhb"); | ||
| 102 | + result.put("TokenTimeout",604800); | ||
| 103 | + result.put("AuthToken","MOBkORkqnrnoVGcKIAHXppgfkNWRdV7utZSkDrI448Q.oxNjAxNTM4NDk3LCJwIjoiZGJjODg5NzliNzVj" + | ||
| 104 | + "Nzc2YmU5MzBjM2JjNjg1ZWFiNGI5ZjhhN2Y0N2RlZjg3NWUyOTJkY2VkYjkwYmEwMTA0NyIsInQiOjE2MDA5MzM2OTcsInUiOiI" + | ||
| 105 | + "4ODlkZDYyM2ViIn0eyJlIj.GciOiJIUzI1NiIsInR5cCI6IkpXVCJ9eyJhb"); | ||
| 106 | + result.put("Token","ynBDDiKMg"); | ||
| 107 | + return result; | ||
| 108 | + } | ||
| 109 | +} |
src/main/java/com/genersoft/iot/vmp/web/ApiDeviceController.java
0 → 100644
| 1 | +package com.genersoft.iot.vmp.web; | ||
| 2 | + | ||
| 3 | +import com.alibaba.fastjson.JSON; | ||
| 4 | +import com.alibaba.fastjson.JSONArray; | ||
| 5 | +import com.alibaba.fastjson.JSONObject; | ||
| 6 | +import com.genersoft.iot.vmp.common.PageResult; | ||
| 7 | +import com.genersoft.iot.vmp.gb28181.bean.Device; | ||
| 8 | +import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel; | ||
| 9 | +import com.genersoft.iot.vmp.gb28181.event.DeviceOffLineDetector; | ||
| 10 | +import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder; | ||
| 11 | +import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander; | ||
| 12 | +import com.genersoft.iot.vmp.storager.IVideoManagerStorager; | ||
| 13 | +import com.genersoft.iot.vmp.vmanager.device.DeviceController; | ||
| 14 | +import org.slf4j.Logger; | ||
| 15 | +import org.slf4j.LoggerFactory; | ||
| 16 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 17 | +import org.springframework.http.HttpStatus; | ||
| 18 | +import org.springframework.http.ResponseEntity; | ||
| 19 | +import org.springframework.stereotype.Controller; | ||
| 20 | +import org.springframework.web.bind.annotation.*; | ||
| 21 | + | ||
| 22 | +import java.util.List; | ||
| 23 | + | ||
| 24 | +/** | ||
| 25 | + * 兼容LiveGBS的API:设备信息 | ||
| 26 | + */ | ||
| 27 | +@CrossOrigin | ||
| 28 | +@RestController | ||
| 29 | +@RequestMapping(value = "/api/v1/device") | ||
| 30 | +public class ApiDeviceController { | ||
| 31 | + | ||
| 32 | + private final static Logger logger = LoggerFactory.getLogger(ApiDeviceController.class); | ||
| 33 | + | ||
| 34 | + @Autowired | ||
| 35 | + private IVideoManagerStorager storager; | ||
| 36 | + | ||
| 37 | + @Autowired | ||
| 38 | + private SIPCommander cmder; | ||
| 39 | + | ||
| 40 | + @Autowired | ||
| 41 | + private DeferredResultHolder resultHolder; | ||
| 42 | + | ||
| 43 | + @Autowired | ||
| 44 | + private DeviceOffLineDetector offLineDetector; | ||
| 45 | + | ||
| 46 | + /** | ||
| 47 | + * 分页获取设备列表 TODO 现在直接返回,尚未实现分页 | ||
| 48 | + * @param start | ||
| 49 | + * @param limit | ||
| 50 | + * @param q | ||
| 51 | + * @param online | ||
| 52 | + * @return | ||
| 53 | + */ | ||
| 54 | + @RequestMapping(value = "/list") | ||
| 55 | + public JSONObject list( @RequestParam(required = false)Integer start, | ||
| 56 | + @RequestParam(required = false)Integer limit, | ||
| 57 | + @RequestParam(required = false)String q, | ||
| 58 | + @RequestParam(required = false)Boolean online ){ | ||
| 59 | + | ||
| 60 | + if (logger.isDebugEnabled()) { | ||
| 61 | + logger.debug("查询所有视频设备API调用"); | ||
| 62 | + } | ||
| 63 | + | ||
| 64 | + logger.debug("查询所有视频设备API调用"); | ||
| 65 | + JSONObject result = new JSONObject(); | ||
| 66 | + List<Device> devices; | ||
| 67 | + if (start == null || limit ==null) { | ||
| 68 | + devices = storager.queryVideoDeviceList(null); | ||
| 69 | + result.put("DeviceCount", devices.size()); | ||
| 70 | + }else { | ||
| 71 | + PageResult<Device> deviceList = storager.queryVideoDeviceList(null, start, limit); | ||
| 72 | + result.put("DeviceCount", deviceList.getTotal()); | ||
| 73 | + devices = deviceList.getData(); | ||
| 74 | + } | ||
| 75 | + | ||
| 76 | + JSONArray deviceJSONList = new JSONArray(); | ||
| 77 | + for (Device device : devices) { | ||
| 78 | + JSONObject deviceJsonObject = new JSONObject(); | ||
| 79 | + deviceJsonObject.put("ID", device.getDeviceId()); | ||
| 80 | + deviceJsonObject.put("Name", device.getName()); | ||
| 81 | + deviceJsonObject.put("Type", "GB"); | ||
| 82 | + deviceJsonObject.put("ChannelCount", device.getChannelCount()); | ||
| 83 | + deviceJsonObject.put("RecvStreamIP", ""); | ||
| 84 | + deviceJsonObject.put("CatalogInterval", 3600); // 通道目录抓取周期 | ||
| 85 | + deviceJsonObject.put("SubscribeInterval", 0); // 订阅周期(秒), 0 表示后台不周期订阅 | ||
| 86 | + deviceJsonObject.put("Online", device.getOnline() == 1); | ||
| 87 | + deviceJsonObject.put("Password", ""); | ||
| 88 | + deviceJsonObject.put("MediaTransport", device.getTransport()); | ||
| 89 | + deviceJsonObject.put("RemoteIP", device.getHost().getIp()); | ||
| 90 | + deviceJsonObject.put("RemotePort", device.getHost().getPort()); | ||
| 91 | + deviceJsonObject.put("LastRegisterAt", ""); | ||
| 92 | + deviceJsonObject.put("LastKeepaliveAt", ""); | ||
| 93 | + deviceJsonObject.put("UpdatedAt", ""); | ||
| 94 | + deviceJsonObject.put("CreatedAt", ""); | ||
| 95 | + deviceJSONList.add(deviceJsonObject); | ||
| 96 | + } | ||
| 97 | + result.put("DeviceList",deviceJSONList); | ||
| 98 | + return result; | ||
| 99 | + } | ||
| 100 | + | ||
| 101 | + @RequestMapping(value = "/channellist") | ||
| 102 | + public JSONObject channellist( String serial, | ||
| 103 | + @RequestParam(required = false)String channel_type, | ||
| 104 | + @RequestParam(required = false)String dir_serial , | ||
| 105 | + @RequestParam(required = false)Integer start, | ||
| 106 | + @RequestParam(required = false)Integer limit, | ||
| 107 | + @RequestParam(required = false)String q, | ||
| 108 | + @RequestParam(required = false)Boolean online ){ | ||
| 109 | + | ||
| 110 | + if (logger.isDebugEnabled()) { | ||
| 111 | + logger.debug("查询所有视频设备API调用"); | ||
| 112 | + } | ||
| 113 | + JSONObject result = new JSONObject(); | ||
| 114 | + // 查询设备是否存在 | ||
| 115 | + Device device = storager.queryVideoDevice(serial); | ||
| 116 | + if (device == null) { | ||
| 117 | + result.put("ChannelCount", 0); | ||
| 118 | + result.put("ChannelList", "[]"); | ||
| 119 | + return result; | ||
| 120 | + } | ||
| 121 | + List<DeviceChannel> deviceChannels; | ||
| 122 | + if (start == null || limit ==null) { | ||
| 123 | + deviceChannels = storager.queryChannelsByDeviceId(serial); | ||
| 124 | + result.put("ChannelCount", deviceChannels.size()); | ||
| 125 | + }else { | ||
| 126 | + PageResult<DeviceChannel> pageResult = storager.queryChannelsByDeviceId(serial, start, limit); | ||
| 127 | + result.put("ChannelCount", pageResult.getTotal()); | ||
| 128 | + deviceChannels = pageResult.getData(); | ||
| 129 | + } | ||
| 130 | + | ||
| 131 | + JSONArray channleJSONList = new JSONArray(); | ||
| 132 | + for (DeviceChannel deviceChannel : deviceChannels) { | ||
| 133 | + JSONObject deviceJOSNChannel = new JSONObject(); | ||
| 134 | + deviceJOSNChannel.put("ID", deviceChannel.getChannelId()); | ||
| 135 | + deviceJOSNChannel.put("DeviceID", device.getDeviceId()); | ||
| 136 | + deviceJOSNChannel.put("DeviceName", device.getName()); | ||
| 137 | + deviceJOSNChannel.put("DeviceOnline", device.getOnline() == 1); | ||
| 138 | + deviceJOSNChannel.put("Channel", 0); // TODO 自定义序号 | ||
| 139 | + deviceJOSNChannel.put("Name", deviceChannel.getName()); | ||
| 140 | + deviceJOSNChannel.put("Custom", false); | ||
| 141 | + deviceJOSNChannel.put("CustomName", ""); | ||
| 142 | + deviceJOSNChannel.put("SubCount", 0); // TODO ? 子节点数, SubCount > 0 表示该通道为子目录 | ||
| 143 | + deviceJOSNChannel.put("SnapURL", ""); | ||
| 144 | + deviceJOSNChannel.put("Manufacturer ", deviceChannel.getManufacture()); | ||
| 145 | + deviceJOSNChannel.put("Model", deviceChannel.getModel()); | ||
| 146 | + deviceJOSNChannel.put("Owner", deviceChannel.getOwner()); | ||
| 147 | + deviceJOSNChannel.put("CivilCode", deviceChannel.getCivilCode()); | ||
| 148 | + deviceJOSNChannel.put("Address", deviceChannel.getAddress()); | ||
| 149 | + deviceJOSNChannel.put("Parental", deviceChannel.getParental()); // 当为通道设备时, 是否有通道子设备, 1-有,0-没有 | ||
| 150 | + deviceJOSNChannel.put("ParentID", deviceChannel.getParentId()); // 直接上级编号 | ||
| 151 | + deviceJOSNChannel.put("Secrecy", deviceChannel.getSecrecy()); | ||
| 152 | + deviceJOSNChannel.put("RegisterWay", 1); // 注册方式, 缺省为1, 允许值: 1, 2, 3 | ||
| 153 | + // 1-IETF RFC3261, | ||
| 154 | + // 2-基于口令的双向认证, | ||
| 155 | + // 3-基于数字证书的双向认证 | ||
| 156 | + deviceJOSNChannel.put("Status", deviceChannel.getStatus()); | ||
| 157 | + deviceJOSNChannel.put("Longitude", deviceChannel.getLongitude()); | ||
| 158 | + deviceJOSNChannel.put("Latitude", deviceChannel.getLatitude()); | ||
| 159 | + deviceJOSNChannel.put("PTZType ", deviceChannel.getPTZType()); // 云台类型, 0 - 未知, 1 - 球机, 2 - 半球, | ||
| 160 | + // 3 - 固定枪机, 4 - 遥控枪机 | ||
| 161 | + deviceJOSNChannel.put("CustomPTZType", ""); | ||
| 162 | + deviceJOSNChannel.put("StreamID", deviceChannel.getSsrc()); // StreamID 直播流ID, 有值表示正在直播 | ||
| 163 | + deviceJOSNChannel.put("NumOutputs ", -1); // 直播在线人数 | ||
| 164 | + channleJSONList.add(deviceJOSNChannel); | ||
| 165 | + } | ||
| 166 | + result.put("ChannelList", channleJSONList); | ||
| 167 | + return result; | ||
| 168 | + } | ||
| 169 | +} |
src/main/java/com/genersoft/iot/vmp/web/ApiStreamController.java
0 → 100644
| 1 | +package com.genersoft.iot.vmp.web; | ||
| 2 | + | ||
| 3 | +import com.alibaba.fastjson.JSON; | ||
| 4 | +import com.alibaba.fastjson.JSONObject; | ||
| 5 | +import com.genersoft.iot.vmp.common.StreamInfo; | ||
| 6 | +import com.genersoft.iot.vmp.gb28181.bean.Device; | ||
| 7 | +import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel; | ||
| 8 | +import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander; | ||
| 9 | +import com.genersoft.iot.vmp.storager.IVideoManagerStorager; | ||
| 10 | +import com.genersoft.iot.vmp.vmanager.play.PlayController; | ||
| 11 | +import org.slf4j.Logger; | ||
| 12 | +import org.slf4j.LoggerFactory; | ||
| 13 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 14 | +import org.springframework.http.HttpStatus; | ||
| 15 | +import org.springframework.http.ResponseEntity; | ||
| 16 | +import org.springframework.web.bind.annotation.*; | ||
| 17 | + | ||
| 18 | +/** | ||
| 19 | + * 兼容LiveGBS的API:实时直播 | ||
| 20 | + */ | ||
| 21 | +@CrossOrigin | ||
| 22 | +@RestController | ||
| 23 | +@RequestMapping(value = "/api/v1/stream") | ||
| 24 | +public class ApiStreamController { | ||
| 25 | + | ||
| 26 | + private final static Logger logger = LoggerFactory.getLogger(ApiStreamController.class); | ||
| 27 | + | ||
| 28 | + @Autowired | ||
| 29 | + private SIPCommander cmder; | ||
| 30 | + | ||
| 31 | + @Autowired | ||
| 32 | + private IVideoManagerStorager storager; | ||
| 33 | + | ||
| 34 | + /** | ||
| 35 | + * 实时直播 - 开始直播 | ||
| 36 | + * @param serial 设备编号 | ||
| 37 | + * @param channel 通道序号 默认值: 1 | ||
| 38 | + * @param code 通道编号,通过 /api/v1/device/channellist 获取的 ChannelList.ID, 该参数和 channel 二选一传递即可 | ||
| 39 | + * @param cdn TODO 转推 CDN 地址, 形如: [rtmp|rtsp]://xxx, encodeURIComponent | ||
| 40 | + * @param audio TODO 是否开启音频, 默认 开启 | ||
| 41 | + * @param transport 流传输模式, 默认 UDP | ||
| 42 | + * @param checkchannelstatus TODO 是否检查通道状态, 默认 false, 表示 拉流前不检查通道状态是否在线 | ||
| 43 | + * @param transportmode TODO 当 transport=TCP 时有效, 指示流传输主被动模式, 默认被动 | ||
| 44 | + * @param timeout TODO 拉流超时(秒), | ||
| 45 | + * @return | ||
| 46 | + */ | ||
| 47 | + @RequestMapping(value = "/start") | ||
| 48 | + private JSONObject start(String serial , | ||
| 49 | + @RequestParam(required = false)Integer channel , | ||
| 50 | + @RequestParam(required = false)String code, | ||
| 51 | + @RequestParam(required = false)String cdn, | ||
| 52 | + @RequestParam(required = false)String audio, | ||
| 53 | + @RequestParam(required = false)String transport, | ||
| 54 | + @RequestParam(required = false)String checkchannelstatus , | ||
| 55 | + @RequestParam(required = false)String transportmode, | ||
| 56 | + @RequestParam(required = false)String timeout | ||
| 57 | + | ||
| 58 | + ){ | ||
| 59 | + | ||
| 60 | + Device device = storager.queryVideoDevice(serial); | ||
| 61 | + if (device == null ) { | ||
| 62 | + JSONObject result = new JSONObject(); | ||
| 63 | + result.put("error","device[ " + serial + " ]未找到"); | ||
| 64 | + return result; | ||
| 65 | + } | ||
| 66 | + DeviceChannel deviceChannel = storager.queryChannel(serial, code); | ||
| 67 | + if (deviceChannel == null) { | ||
| 68 | + JSONObject result = new JSONObject(); | ||
| 69 | + result.put("error","channel[ " + code + " ]未找到"); | ||
| 70 | + return result; | ||
| 71 | + } | ||
| 72 | + // 查询是否已经在播放 | ||
| 73 | + StreamInfo streamInfo = storager.queryPlay(device.getDeviceId(), code); | ||
| 74 | + if (streamInfo == null) streamInfo = cmder.playStreamCmd(device, code); | ||
| 75 | + | ||
| 76 | + if (logger.isDebugEnabled()) { | ||
| 77 | + logger.debug(String.format("设备预览 API调用,deviceId:%s ,channelId:%s",serial, code)); | ||
| 78 | + logger.debug("设备预览 API调用,ssrc:"+streamInfo.getSsrc()+",ZLMedia streamId:"+Integer.toHexString(Integer.parseInt(streamInfo.getSsrc()))); | ||
| 79 | + } | ||
| 80 | + | ||
| 81 | + if(streamInfo!=null) { | ||
| 82 | + JSONObject result = new JSONObject(); | ||
| 83 | + result.put("StreamID", streamInfo.getSsrc()); | ||
| 84 | + result.put("DeviceID", device.getDeviceId()); | ||
| 85 | + result.put("ChannelID", code); | ||
| 86 | + result.put("ChannelName", deviceChannel.getName()); | ||
| 87 | + result.put("ChannelCustomName ", ""); | ||
| 88 | + result.put("FLV ", streamInfo.getFlv()); | ||
| 89 | + result.put("WS_FLV ", streamInfo.getWS_FLV()); | ||
| 90 | + result.put("RTMP", streamInfo.getRTMP()); | ||
| 91 | + result.put("HLS", streamInfo.getHLS()); | ||
| 92 | + result.put("RTSP", streamInfo.getRTSP()); | ||
| 93 | + result.put("CDN", ""); | ||
| 94 | + result.put("SnapURL", ""); | ||
| 95 | + result.put("Transport", device.getTransport()); | ||
| 96 | + result.put("StartAt", ""); | ||
| 97 | + result.put("Duration", ""); | ||
| 98 | + result.put("SourceVideoCodecName", ""); | ||
| 99 | + result.put("SourceVideoWidth", ""); | ||
| 100 | + result.put("SourceVideoHeight", ""); | ||
| 101 | + result.put("SourceVideoFrameRate", ""); | ||
| 102 | + result.put("SourceAudioCodecName", ""); | ||
| 103 | + result.put("SourceAudioSampleRate", ""); | ||
| 104 | + result.put("AudioEnable", ""); | ||
| 105 | + result.put("Ondemand", ""); | ||
| 106 | + result.put("InBytes", ""); | ||
| 107 | + result.put("InBitRate", ""); | ||
| 108 | + result.put("OutBytes", ""); | ||
| 109 | + result.put("NumOutputs", ""); | ||
| 110 | + result.put("CascadeSize", ""); | ||
| 111 | + result.put("RelaySize", ""); | ||
| 112 | + result.put("ChannelPTZType", 0); | ||
| 113 | + return result; | ||
| 114 | + } else { | ||
| 115 | + logger.warn("设备预览API调用失败!"); | ||
| 116 | + JSONObject result = new JSONObject(); | ||
| 117 | + result.put("error","调用失败"); | ||
| 118 | + return result; | ||
| 119 | + } | ||
| 120 | + } | ||
| 121 | + | ||
| 122 | + /** | ||
| 123 | + * 实时直播 - 直播流停止 | ||
| 124 | + * @param serial 设备编号 | ||
| 125 | + * @param channel 通道序号 | ||
| 126 | + * @param code 通道国标编号 | ||
| 127 | + * @param check_outputs | ||
| 128 | + * @return | ||
| 129 | + */ | ||
| 130 | + @RequestMapping(value = "/stop") | ||
| 131 | + @ResponseBody | ||
| 132 | + private JSONObject stop(String serial , | ||
| 133 | + @RequestParam(required = false)Integer channel , | ||
| 134 | + @RequestParam(required = false)String code, | ||
| 135 | + @RequestParam(required = false)String check_outputs | ||
| 136 | + | ||
| 137 | + ){ | ||
| 138 | + StreamInfo streamInfo = storager.queryPlay(serial, code); | ||
| 139 | + if (streamInfo == null) { | ||
| 140 | + JSONObject result = new JSONObject(); | ||
| 141 | + result.put("error","未找到流信息"); | ||
| 142 | + return result; | ||
| 143 | + } | ||
| 144 | + cmder.streamByeCmd(streamInfo.getSsrc()); | ||
| 145 | + storager.stopPlay(serial, code); | ||
| 146 | + return null; | ||
| 147 | + } | ||
| 148 | + | ||
| 149 | + /** | ||
| 150 | + * 实时直播 - 直播流保活 | ||
| 151 | + * @param serial 设备编号 | ||
| 152 | + * @param channel 通道序号 | ||
| 153 | + * @param code 通道国标编号 | ||
| 154 | + * @param check_outputs | ||
| 155 | + * @return | ||
| 156 | + */ | ||
| 157 | + @RequestMapping(value = "/touch") | ||
| 158 | + @ResponseBody | ||
| 159 | + private JSONObject touch(String serial ,String t, | ||
| 160 | + @RequestParam(required = false)Integer channel , | ||
| 161 | + @RequestParam(required = false)String code, | ||
| 162 | + @RequestParam(required = false)String autorestart, | ||
| 163 | + @RequestParam(required = false)String audio, | ||
| 164 | + @RequestParam(required = false)String cdn | ||
| 165 | + ){ | ||
| 166 | + return null; | ||
| 167 | + } | ||
| 168 | +} |