Monica视频监控处理程序
xc
2021-03-20 1be7edf5fbbd984f35f5c48d89686caf23b9873e
src/test/java/com/hbbh/adapter/HttpClientUtilTest.java
@@ -1,9 +1,11 @@
package com.hbbh.adapter;
import com.alibaba.fastjson.JSON;
import com.google.common.collect.Maps;
import com.hbbh.adapter.utils.HttpClientUtil;
import org.junit.jupiter.api.Test;
import java.util.List;
import java.util.Map;
public class HttpClientUtilTest {
@@ -20,7 +22,7 @@
     * Referer: http://192.168.1.109:3000/
     * Accept-Encoding: gzip, deflate
     * Accept-Language: zh-CN,zh;q=0.9
     *
     * <p>
     * path: E:\store\live
     * name: live
     * info: [Monibuca]
@@ -47,7 +49,7 @@
     * #StreamPath = "live/rtsp2"
     * clear: true
     */
    private String info="[Monibuca]\n" +
    private String info = "[Monibuca]\n" +
            "# 是否等待流,如果为true则订阅一个尚未发布的流会进入等待发布的状态,否则返回订阅失败\n" +
            "EnableWaitStream = true\n" +
            "EnableAudio = true\n" +
@@ -124,27 +126,194 @@
    @Test
    void init() {
        String result = createInstance();
        if (result.contains("success")){
        System.out.println(result);
        /*if (result.contains("success")) {
            startInstance();
        }else {
        } else {
            //创建实例失败
            System.out.println("创建实例失败");
        }
        }*/
    }
    /**
     * 创建实例
     * GET
     */
    private String  createInstance(){
        String url="http://127.0.0.1:3000/api/instance/create";
    private String createInstance() {
        String url = "http://127.0.0.1:3000/api/instance/create";
        Map<String, String> params = Maps.newLinkedHashMap();
        params.put("path","/Users/xucheng/Downloads/store/live");
        params.put("name","live");
        params.put("info",info);
        params.put("clear","true");
        params.put("path", "/Users/xucheng/Downloads/store/live");
        params.put("name", "live");
        params.put("info", info);
        params.put("clear", "true");
        String result = HttpClientUtil.doGet(url, params);
        return result;
    }
    /**
     * [{
     * "Name": "history",
     * "Path": "/Users/xucheng/Downloads/store/history",
     * "config": {
     * "Monibuca": {
     * "EnableWaitStream": true,
     * "EnableAudio": true,
     * "EnableVideo": true,
     * "RingSize": 10,
     * "PublishTimeout": 60000000000
     * },
     * "RTMP": {
     * "ListenAddr": ":1933"
     * },
     * "GateWay": {
     * "ListenAddr": ":8071"
     * },
     * "Jessica": {
     * "ListenAddr": ":8072"
     * },
     * "LogRotate": {
     * "Path": "logs",
     * "Size": 0,
     * "Days": 1
     * },
     * "Cluster": {
     * "ListenAddr": ":2011",
     * "OriginServer": "",
     * "Push": true
     * },
     * "HLS": {
     * "EnableWrite": false,
     * "EnableMemory": false,
     * "Fragment": 10,
     * "Window": 2,
     * "Path": "resource"
     * },
     * "HDL": {
     * "ListenAddr": ":2012"
     * },
     * "TS": {
     * "AutoPublish": false,
     * "Path": "resource"
     * },
     * "Record": {
     * "Path": "resource",
     * "AutoPublish": false,
     * "AutoRecord": false
     * },
     * "RTSP": {
     * "ListenAddr": ":551",
     * "AutoPull": true,
     * "Reconnect": true,
     * "RemoteAddr": "rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov",
     * "StreamPath": "live/rtsp"
     * },
     * "WebRTC": {
     * "PublicIP": ["127.0.0.1"]
     * },
     * "GB28181": {
     * "Serial": "34020000002000000001",
     * "Realm": "3402000000",
     * "Expires": 3600,
     * "AutoInvite": false,
     * "ListenAddr": "192.168.1.120:5062"
     * }*    },
     * "pid": "46533",
     * "status": "offline"
     * }, {
     * "Name": "live",
     * "Path": "/Users/xucheng/Downloads/store/live",
     * "config": {
     * "Monibuca": {
     * "EnableWaitStream": true,
     * "EnableAudio": true,
     * "EnableVideo": true,
     * "RingSize": 10,
     * "PublishTimeout": 60000000000
     * }        ,
     * "RTMP": {
     * "ListenAddr": ":1935"
     * },
     * "GateWay": {
     * "ListenAddr": ":8081"
     * },
     * "Jessica": {
     * "ListenAddr": ":8080"
     * },
     * "LogRotate": {
     * "Path": "logs",
     * "Size": 0,
     * "Days": 1
     * },
     * "Cluster": {
     * "ListenAddr": ":2019",
     * "OriginServer": "",
     * "Push": true
     * },
     * "HLS": {
     * "EnableWrite": false,
     * "EnableMemory": false,
     * "Fragment": 10,
     * "Window": 2,
     * "Path": "resource"
     * },
     * "HDL": {
     * "ListenAddr": ":2020"
     * },
     * "TS": {
     * "AutoPublish": false,
     * "Path": "resource"
     * },
     * "Record": {
     * "Path": "resource",
     * "AutoPublish": false,
     * "AutoRecord": false
     * },
     * "RTSP": {
     * "ListenAddr": ":554",
     * "AutoPull": true,
     * "Reconnect": true,
     * "RemoteAddr": "rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov",
     * "StreamPath": "live/rtsp"
     * },
     * "WebRTC": {
     * "PublicIP": ["127.0.0.1"]
     * },
     * "GB28181": {
     * "Serial": "34020000002000000001",
     * "Realm": "3402000000",
     * "Expires": 3600,
     * "AutoInvite": false,
     * "ListenAddr": "192.168.1.120:5060"
     * }
     * },
     * "pid": "17003",
     * "status": "offline"
     * }]
     *
     * @return
     */
    private String findList() {
        String url = "http://localhost:3000/api/instance/list";
        String result = HttpClientUtil.doGet(url);
        return result;
    }
    @Test
    public void findListTest() throws Exception {
        String list = findList();
        List<Map> maps = JSON.parseObject(list, List.class);
        for (Map map : maps) {
            String name = map.get("Name") + "";//实例名称
            String path = map.get("Path") + "";//实例存放路径
            String status = map.get("status") + "";// offline 不在线 online 在线
            System.out.println(status);
        }
    }
    @Test
    public void test01() throws Exception {
        startInstance();
    }
    /**
@@ -152,8 +321,8 @@
     * POST
     * http://localhost:3000/api/instance/start?name=live
     */
    private void startInstance(){
        String url="http://localhost:3000/api/instance/start?name=live";
    private void startInstance() {
        String url = "http://localhost:3000/api/instance/start?name=live";
        String result = HttpClientUtil.doPost(url);
        System.out.println(result);
    }
@@ -164,12 +333,12 @@
     * http://localhost:8081/rtsp/pull?
     * target=rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov&
     * streamPath=live/test
     *
     *
     * <p>
     * <p>
     * return :http://localhost:2020/live/test1.flv
     */
    private void pullRTSPURL(){
        String url="http://localhost:8081/rtsp/pull";
    private void pullRTSPURL() {
        String url = "http://localhost:8081/rtsp/pull";
        Map<String, String> params = Maps.newLinkedHashMap();
 /*       params.put("target","rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov");
        params.put("streamPath","live/test");
@@ -181,12 +350,12 @@
*/
        for (int i = 0; i < 10; i++) {
            params.put("target","rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov");
            params.put("streamPath","live/test"+i);
            params.put("target", "rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov");
            params.put("streamPath", "live/test" + i);
            String result = HttpClientUtil.doGet(url, params);
            if (result.contains("0")){
            }else {
                System.out.println("第"+i+"次创建失败");
            if (result.contains("0")) {
            } else {
                System.out.println("第" + i + "次创建失败");
            }
            params.clear();
@@ -195,12 +364,12 @@
    }
    @Test
    public void pullRTSP(){
        String url="http://localhost:8081/rtsp/pull";
    public void pullRTSP() {
        String url = "http://localhost:8081/rtsp/pull";
        Map<String, String> params = Maps.newLinkedHashMap();
        params.put("target","rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov");
        params.put("streamPath","live/test");
        params.put("target", "rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov");
        params.put("streamPath", "live/test");
        String result = HttpClientUtil.doGet(url, params);
        System.out.println(result);
    }