648540858 5 роки тому
батько
коміт
fc901e8c65

+ 5 - 0
README.md

@@ -3,6 +3,8 @@ WEB VIDEO PLATFORM是一个基于GB28181-2016标准实现的网络视频平台
 流媒体服务基于ZLMediaKit-https://github.com/xiongziliang/ZLMediaKit   
 前端展示基于MediaServerUI-https://gitee.com/kkkkk5G/MediaServerUI/tree/gb28181/
 
+### fork自  [swwheihei/wvp-GB28181](https://github.com/swwheihei/wvp-GB28181)
+
 # 应用场景:
 主要应用在IPC等设备没有固定IP地址,但需要在互联网中观看的场景。  
 要求IPC设备可以访问互联网,有云服务器用于部署本服务。
@@ -36,3 +38,6 @@ WEB VIDEO PLATFORM是一个基于GB28181-2016标准实现的网络视频平台
 # 致谢
 感谢作者[夏楚](https://github.com/xiongziliang) 提供这么棒的开源流媒体服务框架  
 感谢作者[kkkkk5G](https://gitee.com/kkkkk5G) 提供这么棒的前端UI
+
+
+[]: https://github.com/swwheihei/wvp-GB28181

+ 96 - 0
src/main/java/com/genersoft/iot/vmp/web/ApiControlController.java

@@ -0,0 +1,96 @@
+package com.genersoft.iot.vmp.web;
+
+import com.alibaba.fastjson.JSONObject;
+import com.genersoft.iot.vmp.gb28181.bean.Device;
+import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander;
+import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
+import com.genersoft.iot.vmp.vmanager.ptz.PtzController;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.*;
+
+/**
+ * 兼容LiveGBS的API:设备控制
+ */
+@CrossOrigin
+@RestController
+@RequestMapping(value = "/api/v1/control")
+public class ApiControlController {
+
+    private final static Logger logger = LoggerFactory.getLogger(ApiControlController.class);
+
+    @Autowired
+    private SIPCommander cmder;
+
+    @Autowired
+    private IVideoManagerStorager storager;
+
+    /**
+     * 设备控制 - 云台控制
+     * @param serial 设备编号
+     * @param command 控制指令 允许值: left, right, up, down, upleft, upright, downleft, downright, zoomin, zoomout, stop
+     * @param channel 通道序号
+     * @param code 通道编号
+     * @param speed 速度(0~255) 默认值: 129
+     * @return
+     */
+    @RequestMapping(value = "/ptz")
+    private JSONObject list(String serial,String command,
+                            @RequestParam(required = false)Integer channel,
+                            @RequestParam(required = false)String code,
+                            @RequestParam(required = false)Integer speed){
+
+        if (logger.isDebugEnabled()) {
+            logger.debug(String.format("模拟接口> 设备云台控制 API调用,deviceId:%s ,channelId:%s ,command:%d ,speed:%d ",
+                    serial, code, command, speed));
+        }
+        Device device = storager.queryVideoDevice(serial);
+        int leftRight = 0;
+        int upDown = 0;
+        int inOut = 0;
+        switch (command) {
+            case "left":
+                leftRight = 1;
+                break;
+            case "right":
+                leftRight = 2;
+                break;
+            case "up":
+                upDown = 1;
+                break;
+            case "down":
+                upDown = 2;
+                break;
+            case "upleft":
+                upDown = 1;
+                leftRight = 1;
+            case "upright":
+                upDown = 1;
+                leftRight = 2;
+                break;
+            case "downleft":
+                upDown = 2;
+                leftRight = 1;
+                break;
+            case "downright":
+                upDown = 2;
+                leftRight = 2;
+                break;
+            case "zoomin":
+                inOut = 2;
+                break;
+            case "zoomout":
+                inOut = 1;
+                break;
+            case "stop":
+                break;
+
+        }
+        // 默认值 50
+        cmder.ptzCmd(device, code, leftRight, upDown, inOut, speed==0 ? 129 : speed, 50);
+        return null;
+    }
+}

+ 109 - 0
src/main/java/com/genersoft/iot/vmp/web/ApiController.java

@@ -0,0 +1,109 @@
+package com.genersoft.iot.vmp.web;
+
+import com.alibaba.fastjson.JSONObject;
+import com.genersoft.iot.vmp.conf.SipConfig;
+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.stereotype.Controller;
+import org.springframework.web.bind.annotation.CrossOrigin;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.ResponseBody;
+
+/**
+ * 兼容LiveGBS的API:系统接口
+ */
+@Controller
+@CrossOrigin
+@RequestMapping(value = "/api/v1")
+public class ApiController {
+
+    private final static Logger logger = LoggerFactory.getLogger(ApiController.class);
+
+    @Autowired
+    private SipConfig sipConfig;
+
+
+    @RequestMapping("/getserverinfo")
+    private JSONObject getserverinfo(){
+        JSONObject result = new JSONObject();
+        result.put("Authorization","ceshi");
+        result.put("Hardware","");
+        result.put("InterfaceVersion","2.5.5");
+        result.put("IsDemo","");
+        result.put("Hardware","false");
+        result.put("APIAuth","false");
+        result.put("RemainDays","永久");
+        result.put("RunningTime","");
+        result.put("ServerTime","2020-09-02 17:11");
+        result.put("StartUpTime","2020-09-02 17:11");
+        result.put("Server","");
+        result.put("SIPSerial", sipConfig.getSipId());
+        result.put("SIPRealm", sipConfig.getSipDomain());
+        result.put("SIPHost", sipConfig.getSipIp());
+        result.put("SIPPort", sipConfig.getSipPort());
+        result.put("ChannelCount","1000");
+        result.put("VersionType","");
+        result.put("LogoMiniText","");
+        result.put("LogoText","");
+        result.put("CopyrightText","");
+
+        return result;
+    }
+
+    @RequestMapping(value = "/userinfo")
+    private JSONObject userinfo(){
+//        JSONObject result = new JSONObject();
+//        result.put("ID","ceshi");
+//        result.put("Hardware","");
+//        result.put("InterfaceVersion","2.5.5");
+//        result.put("IsDemo","");
+//        result.put("Hardware","false");
+//        result.put("APIAuth","false");
+//        result.put("RemainDays","永久");
+//        result.put("RunningTime","");
+//        result.put("ServerTime","2020-09-02 17:11");
+//        result.put("StartUpTime","2020-09-02 17:11");
+//        result.put("Server","");
+//        result.put("SIPSerial", sipConfig.getSipId());
+//        result.put("SIPRealm", sipConfig.getSipDomain());
+//        result.put("SIPHost", sipConfig.getSipIp());
+//        result.put("SIPPort", sipConfig.getSipPort());
+//        result.put("ChannelCount","1000");
+//        result.put("VersionType","");
+//        result.put("LogoMiniText","");
+//        result.put("LogoText","");
+//        result.put("CopyrightText","");
+
+        return null;
+    }
+
+    /**
+     *  系统接口 - 登录
+     * @param username 用户名
+     * @param password 密码(经过md5加密,32位长度,不带中划线,不区分大小写)
+     * @return
+     */
+    @RequestMapping(value = "/login")
+    @ResponseBody
+    private JSONObject login(String username,String password ){
+        if (logger.isDebugEnabled()) {
+            logger.debug(String.format("模拟接口> 登录 API调用,username:%s ,password:%s ",
+                    username, password));
+        }
+
+        JSONObject result = new JSONObject();
+        result.put("CookieToken","ynBDDiKMg");
+        result.put("URLToken","MOBkORkqnrnoVGcKIAHXppgfkNWRdV7utZSkDrI448Q.oxNjAxNTM4NDk3LCJwIjoiZGJjODg5NzliNzVj" +
+                "Nzc2YmU5MzBjM2JjNjg1ZWFiNGI5ZjhhN2Y0N2RlZjg3NWUyOTJkY2VkYjkwYmEwMTA0NyIsInQiOjE2MDA5MzM2OTcsInUiOiI" +
+                "4ODlkZDYyM2ViIn0eyJlIj.GciOiJIUzI1NiIsInR5cCI6IkpXVCJ9eyJhb");
+        result.put("TokenTimeout",604800);
+        result.put("AuthToken","MOBkORkqnrnoVGcKIAHXppgfkNWRdV7utZSkDrI448Q.oxNjAxNTM4NDk3LCJwIjoiZGJjODg5NzliNzVj" +
+                "Nzc2YmU5MzBjM2JjNjg1ZWFiNGI5ZjhhN2Y0N2RlZjg3NWUyOTJkY2VkYjkwYmEwMTA0NyIsInQiOjE2MDA5MzM2OTcsInUiOiI" +
+                "4ODlkZDYyM2ViIn0eyJlIj.GciOiJIUzI1NiIsInR5cCI6IkpXVCJ9eyJhb");
+        result.put("Token","ynBDDiKMg");
+        return result;
+    }
+}

+ 169 - 0
src/main/java/com/genersoft/iot/vmp/web/ApiDeviceController.java

@@ -0,0 +1,169 @@
+package com.genersoft.iot.vmp.web;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.genersoft.iot.vmp.common.PageResult;
+import com.genersoft.iot.vmp.gb28181.bean.Device;
+import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
+import com.genersoft.iot.vmp.gb28181.event.DeviceOffLineDetector;
+import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder;
+import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander;
+import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
+import com.genersoft.iot.vmp.vmanager.device.DeviceController;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+
+/**
+ * 兼容LiveGBS的API:设备信息
+ */
+@CrossOrigin
+@RestController
+@RequestMapping(value = "/api/v1/device")
+public class ApiDeviceController {
+
+    private final static Logger logger = LoggerFactory.getLogger(ApiDeviceController.class);
+
+    @Autowired
+    private IVideoManagerStorager storager;
+
+    @Autowired
+    private SIPCommander cmder;
+
+    @Autowired
+    private DeferredResultHolder resultHolder;
+
+    @Autowired
+    private DeviceOffLineDetector offLineDetector;
+
+    /**
+     * 分页获取设备列表 TODO 现在直接返回,尚未实现分页
+     * @param start
+     * @param limit
+     * @param q
+     * @param online
+     * @return
+     */
+    @RequestMapping(value = "/list")
+    public JSONObject list( @RequestParam(required = false)Integer start,
+                            @RequestParam(required = false)Integer limit,
+                            @RequestParam(required = false)String q,
+                            @RequestParam(required = false)Boolean online ){
+
+        if (logger.isDebugEnabled()) {
+            logger.debug("查询所有视频设备API调用");
+        }
+
+        logger.debug("查询所有视频设备API调用");
+        JSONObject result = new JSONObject();
+        List<Device> devices;
+        if (start == null || limit ==null) {
+            devices = storager.queryVideoDeviceList(null);
+            result.put("DeviceCount", devices.size());
+        }else {
+            PageResult<Device> deviceList = storager.queryVideoDeviceList(null, start, limit);
+            result.put("DeviceCount", deviceList.getTotal());
+            devices = deviceList.getData();
+        }
+
+        JSONArray deviceJSONList = new JSONArray();
+        for (Device device : devices) {
+            JSONObject deviceJsonObject = new JSONObject();
+            deviceJsonObject.put("ID", device.getDeviceId());
+            deviceJsonObject.put("Name", device.getName());
+            deviceJsonObject.put("Type", "GB");
+            deviceJsonObject.put("ChannelCount", device.getChannelCount());
+            deviceJsonObject.put("RecvStreamIP", "");
+            deviceJsonObject.put("CatalogInterval", 3600); // 通道目录抓取周期
+            deviceJsonObject.put("SubscribeInterval", 0); // 订阅周期(秒), 0 表示后台不周期订阅
+            deviceJsonObject.put("Online", device.getOnline() == 1);
+            deviceJsonObject.put("Password", "");
+            deviceJsonObject.put("MediaTransport", device.getTransport());
+            deviceJsonObject.put("RemoteIP", device.getHost().getIp());
+            deviceJsonObject.put("RemotePort", device.getHost().getPort());
+            deviceJsonObject.put("LastRegisterAt", "");
+            deviceJsonObject.put("LastKeepaliveAt", "");
+            deviceJsonObject.put("UpdatedAt", "");
+            deviceJsonObject.put("CreatedAt", "");
+            deviceJSONList.add(deviceJsonObject);
+        }
+        result.put("DeviceList",deviceJSONList);
+        return result;
+    }
+
+    @RequestMapping(value = "/channellist")
+    public JSONObject channellist( String serial,
+                                   @RequestParam(required = false)String channel_type,
+                                   @RequestParam(required = false)String dir_serial ,
+                                   @RequestParam(required = false)Integer start,
+                                   @RequestParam(required = false)Integer limit,
+                                   @RequestParam(required = false)String q,
+                                   @RequestParam(required = false)Boolean online ){
+
+        if (logger.isDebugEnabled()) {
+            logger.debug("查询所有视频设备API调用");
+        }
+        JSONObject result = new JSONObject();
+        // 查询设备是否存在
+        Device device = storager.queryVideoDevice(serial);
+        if (device == null) {
+            result.put("ChannelCount", 0);
+            result.put("ChannelList", "[]");
+            return result;
+        }
+        List<DeviceChannel> deviceChannels;
+        if (start == null || limit ==null) {
+            deviceChannels = storager.queryChannelsByDeviceId(serial);
+            result.put("ChannelCount", deviceChannels.size());
+        }else {
+            PageResult<DeviceChannel> pageResult = storager.queryChannelsByDeviceId(serial, start, limit);
+            result.put("ChannelCount", pageResult.getTotal());
+            deviceChannels = pageResult.getData();
+        }
+
+        JSONArray channleJSONList = new JSONArray();
+        for (DeviceChannel deviceChannel : deviceChannels) {
+            JSONObject deviceJOSNChannel = new JSONObject();
+            deviceJOSNChannel.put("ID", deviceChannel.getChannelId());
+            deviceJOSNChannel.put("DeviceID", device.getDeviceId());
+            deviceJOSNChannel.put("DeviceName", device.getName());
+            deviceJOSNChannel.put("DeviceOnline", device.getOnline() == 1);
+            deviceJOSNChannel.put("Channel", 0); // TODO 自定义序号
+            deviceJOSNChannel.put("Name", deviceChannel.getName());
+            deviceJOSNChannel.put("Custom", false);
+            deviceJOSNChannel.put("CustomName", "");
+            deviceJOSNChannel.put("SubCount", 0); // TODO ? 子节点数, SubCount > 0 表示该通道为子目录
+            deviceJOSNChannel.put("SnapURL", "");
+            deviceJOSNChannel.put("Manufacturer ", deviceChannel.getManufacture());
+            deviceJOSNChannel.put("Model", deviceChannel.getModel());
+            deviceJOSNChannel.put("Owner", deviceChannel.getOwner());
+            deviceJOSNChannel.put("CivilCode", deviceChannel.getCivilCode());
+            deviceJOSNChannel.put("Address", deviceChannel.getAddress());
+            deviceJOSNChannel.put("Parental", deviceChannel.getParental()); // 当为通道设备时, 是否有通道子设备, 1-有,0-没有
+            deviceJOSNChannel.put("ParentID", deviceChannel.getParentId()); // 直接上级编号
+            deviceJOSNChannel.put("Secrecy", deviceChannel.getSecrecy());
+            deviceJOSNChannel.put("RegisterWay", 1); // 注册方式, 缺省为1, 允许值: 1, 2, 3
+                                                     // 1-IETF RFC3261,
+                                                     // 2-基于口令的双向认证,
+                                                     // 3-基于数字证书的双向认证
+            deviceJOSNChannel.put("Status", deviceChannel.getStatus());
+            deviceJOSNChannel.put("Longitude", deviceChannel.getLongitude());
+            deviceJOSNChannel.put("Latitude", deviceChannel.getLatitude());
+            deviceJOSNChannel.put("PTZType ", deviceChannel.getPTZType()); // 云台类型, 0 - 未知, 1 - 球机, 2 - 半球,
+                                                                            //   3 - 固定枪机, 4 - 遥控枪机
+            deviceJOSNChannel.put("CustomPTZType", "");
+            deviceJOSNChannel.put("StreamID", deviceChannel.getSsrc()); // StreamID 直播流ID, 有值表示正在直播
+            deviceJOSNChannel.put("NumOutputs ", -1); // 直播在线人数
+            channleJSONList.add(deviceJOSNChannel);
+        }
+        result.put("ChannelList", channleJSONList);
+        return result;
+    }
+}

+ 168 - 0
src/main/java/com/genersoft/iot/vmp/web/ApiStreamController.java

@@ -0,0 +1,168 @@
+package com.genersoft.iot.vmp.web;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import com.genersoft.iot.vmp.common.StreamInfo;
+import com.genersoft.iot.vmp.gb28181.bean.Device;
+import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
+import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander;
+import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
+import com.genersoft.iot.vmp.vmanager.play.PlayController;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.*;
+
+/**
+ * 兼容LiveGBS的API:实时直播
+ */
+@CrossOrigin
+@RestController
+@RequestMapping(value = "/api/v1/stream")
+public class ApiStreamController {
+
+    private final static Logger logger = LoggerFactory.getLogger(ApiStreamController.class);
+
+    @Autowired
+    private SIPCommander cmder;
+
+    @Autowired
+    private IVideoManagerStorager storager;
+
+    /**
+     * 实时直播 - 开始直播
+     * @param serial 设备编号
+     * @param channel 通道序号 默认值: 1
+     * @param code 通道编号,通过 /api/v1/device/channellist 获取的 ChannelList.ID, 该参数和 channel 二选一传递即可
+     * @param cdn TODO 转推 CDN 地址, 形如: [rtmp|rtsp]://xxx, encodeURIComponent
+     * @param audio TODO 是否开启音频, 默认 开启
+     * @param transport 流传输模式, 默认 UDP
+     * @param checkchannelstatus TODO 是否检查通道状态, 默认 false, 表示 拉流前不检查通道状态是否在线
+     * @param transportmode TODO 当 transport=TCP 时有效, 指示流传输主被动模式, 默认被动
+     * @param timeout TODO 拉流超时(秒),
+     * @return
+     */
+    @RequestMapping(value = "/start")
+    private JSONObject start(String serial ,
+                             @RequestParam(required = false)Integer channel ,
+                             @RequestParam(required = false)String code,
+                             @RequestParam(required = false)String cdn,
+                             @RequestParam(required = false)String audio,
+                             @RequestParam(required = false)String transport,
+                             @RequestParam(required = false)String checkchannelstatus ,
+                             @RequestParam(required = false)String transportmode,
+                             @RequestParam(required = false)String timeout
+
+    ){
+
+        Device device = storager.queryVideoDevice(serial);
+        if (device == null ) {
+            JSONObject result = new JSONObject();
+            result.put("error","device[ " + serial + " ]未找到");
+            return result;
+        }
+        DeviceChannel deviceChannel = storager.queryChannel(serial, code);
+        if (deviceChannel == null) {
+            JSONObject result = new JSONObject();
+            result.put("error","channel[ " + code + " ]未找到");
+            return result;
+        }
+        // 查询是否已经在播放
+        StreamInfo streamInfo = storager.queryPlay(device.getDeviceId(), code);
+        if (streamInfo == null) streamInfo = cmder.playStreamCmd(device, code);
+
+        if (logger.isDebugEnabled()) {
+            logger.debug(String.format("设备预览 API调用,deviceId:%s ,channelId:%s",serial, code));
+            logger.debug("设备预览 API调用,ssrc:"+streamInfo.getSsrc()+",ZLMedia streamId:"+Integer.toHexString(Integer.parseInt(streamInfo.getSsrc())));
+        }
+
+        if(streamInfo!=null) {
+            JSONObject result = new JSONObject();
+            result.put("StreamID", streamInfo.getSsrc());
+            result.put("DeviceID", device.getDeviceId());
+            result.put("ChannelID", code);
+            result.put("ChannelName", deviceChannel.getName());
+            result.put("ChannelCustomName ", "");
+            result.put("FLV ", streamInfo.getFlv());
+            result.put("WS_FLV ", streamInfo.getWS_FLV());
+            result.put("RTMP", streamInfo.getRTMP());
+            result.put("HLS", streamInfo.getHLS());
+            result.put("RTSP", streamInfo.getRTSP());
+            result.put("CDN", "");
+            result.put("SnapURL", "");
+            result.put("Transport", device.getTransport());
+            result.put("StartAt", "");
+            result.put("Duration", "");
+            result.put("SourceVideoCodecName", "");
+            result.put("SourceVideoWidth", "");
+            result.put("SourceVideoHeight", "");
+            result.put("SourceVideoFrameRate", "");
+            result.put("SourceAudioCodecName", "");
+            result.put("SourceAudioSampleRate", "");
+            result.put("AudioEnable", "");
+            result.put("Ondemand", "");
+            result.put("InBytes", "");
+            result.put("InBitRate", "");
+            result.put("OutBytes", "");
+            result.put("NumOutputs", "");
+            result.put("CascadeSize", "");
+            result.put("RelaySize", "");
+            result.put("ChannelPTZType", 0);
+            return result;
+        } else {
+            logger.warn("设备预览API调用失败!");
+            JSONObject result = new JSONObject();
+            result.put("error","调用失败");
+            return result;
+        }
+    }
+
+    /**
+     * 实时直播 - 直播流停止
+     * @param serial 设备编号
+     * @param channel 通道序号
+     * @param code 通道国标编号
+     * @param check_outputs
+     * @return
+     */
+    @RequestMapping(value = "/stop")
+    @ResponseBody
+    private JSONObject stop(String serial ,
+                             @RequestParam(required = false)Integer channel ,
+                             @RequestParam(required = false)String code,
+                             @RequestParam(required = false)String check_outputs
+
+    ){
+        StreamInfo streamInfo = storager.queryPlay(serial, code);
+        if (streamInfo == null) {
+            JSONObject result = new JSONObject();
+            result.put("error","未找到流信息");
+            return result;
+        }
+        cmder.streamByeCmd(streamInfo.getSsrc());
+        storager.stopPlay(serial, code);
+        return null;
+    }
+
+    /**
+     * 实时直播 - 直播流保活
+     * @param serial 设备编号
+     * @param channel 通道序号
+     * @param code 通道国标编号
+     * @param check_outputs
+     * @return
+     */
+    @RequestMapping(value = "/touch")
+    @ResponseBody
+    private JSONObject touch(String serial ,String t,
+                            @RequestParam(required = false)Integer channel ,
+                            @RequestParam(required = false)String code,
+                            @RequestParam(required = false)String autorestart,
+                            @RequestParam(required = false)String audio,
+                            @RequestParam(required = false)String cdn
+    ){
+        return null;
+    }
+}