From 5a04575cb99f2624391e699eb557bbdcc8dc6e10 Mon Sep 17 00:00:00 2001
From: rqb500 <32304362+rqb500@users.noreply.github.com>
Date: Mon, 25 Oct 2021 15:13:21 +0800
Subject: [PATCH] 增加实用restful接口 (#1183)

---
 postman/ZLMediaKit.postman_collection.json | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 server/WebApi.cpp                          | 41 ++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 132 insertions(+), 1 deletion(-)

diff --git a/postman/ZLMediaKit.postman_collection.json b/postman/ZLMediaKit.postman_collection.json
index 6807231..3e28644 100644
--- a/postman/ZLMediaKit.postman_collection.json
+++ b/postman/ZLMediaKit.postman_collection.json
@@ -945,6 +945,98 @@
 			"response": []
 		},
 		{
+			"name": "设置录像速度(setRecordSpeed)",
+			"request": {
+				"method": "GET",
+				"header": [],
+				"url": {
+					"raw": "{{ZLMediaKit_URL}}/index/api/setRecordSpeed?secret={{ZLMediaKit_secret}}&vhost={{defaultVhost}}&app=live&stream=obs&speed=2.0",
+					"host": [
+						"{{ZLMediaKit_URL}}"
+					],
+					"path": [
+						"index",
+						"api",
+						"setRecordSpeed"
+					],
+					"query": [
+						{
+							"key": "secret",
+							"value": "{{ZLMediaKit_secret}}",
+							"description": "api操作密钥(配置文件配置),如果操作ip是127.0.0.1,则不需要此参数"
+						},
+						{
+							"key": "vhost",
+							"value": "{{defaultVhost}}",
+							"description": "虚拟主机,例如__defaultVhost__"
+						},
+						{
+							"key": "app",
+							"value": "live",
+							"description": "应用名,例如 live"
+						},
+						{
+							"key": "stream",
+							"value": "obs",
+							"description": "流id,例如 obs"
+						},
+						{
+							"key": "speed",
+							"value": 2.0,
+							"description": "要设置的录像倍速",
+						}
+					]
+				}
+			},
+			"response": []
+		},
+		{
+			"name": "设置录像流播放位置(seekRecordStamp)",
+			"request": {
+				"method": "GET",
+				"header": [],
+				"url": {
+					"raw": "{{ZLMediaKit_URL}}/index/api/startRecord?secret={{ZLMediaKit_secret}}&vhost={{defaultVhost}}&app=live&stream=obs&stamp=1000",
+					"host": [
+						"{{ZLMediaKit_URL}}"
+					],
+					"path": [
+						"index",
+						"api",
+						"seekRecordStamp"
+					],
+					"query": [
+						{
+							"key": "secret",
+							"value": "{{ZLMediaKit_secret}}",
+							"description": "api操作密钥(配置文件配置),如果操作ip是127.0.0.1,则不需要此参数"
+						},
+						{
+							"key": "vhost",
+							"value": "{{defaultVhost}}",
+							"description": "虚拟主机,例如__defaultVhost__"
+						},
+						{
+							"key": "app",
+							"value": "live",
+							"description": "应用名,例如 live"
+						},
+						{
+							"key": "stream",
+							"value": "obs",
+							"description": "流id,例如 obs"
+						},
+						{
+							"key": "stamp",
+							"value": 1000,
+							"description": "要设置的录像播放位置",
+						}
+					]
+				}
+			},
+			"response": []
+		},
+		{
 			"name": "停止录制(stopRecord)",
 			"request": {
 				"method": "GET",
diff --git a/server/WebApi.cpp b/server/WebApi.cpp
index a6b916f..5d9d0a0 100755
--- a/server/WebApi.cpp
+++ b/server/WebApi.cpp
@@ -1037,6 +1037,45 @@ void installWebApi() {
         val["code"] = result ? API::Success : API::OtherFailed;
         val["msg"] = result ? "success" :  "start record failed";
     });
+    
+    //设置录像流播放速度
+    api_regist("/index/api/setRecordSpeed", [](API_ARGS_MAP) {
+        CHECK_SECRET();
+        CHECK_ARGS("schema", "vhost", "app", "stream", "speed");
+        auto src = MediaSource::find(allArgs["schema"],
+                                     allArgs["vhost"],
+                                     allArgs["app"],
+                                     allArgs["stream"]);
+        if (src) {
+            bool flag = src->speed(allArgs["speed"].as<float>());
+            val["result"] = flag ? 0 : -1;
+            val["msg"] = flag ? "success" : "set failed";
+            val["code"] = flag ? API::Success : API::OtherFailed;
+        } else {
+            val["result"] = -2;
+            val["msg"] = "can not find the stream";
+            val["code"] = API::OtherFailed;
+        }
+    });
+
+    api_regist("/index/api/seekRecordStamp", [](API_ARGS_MAP) {
+        CHECK_SECRET();
+        CHECK_ARGS("schema", "vhost", "app", "stream", "stamp");
+        auto src = MediaSource::find(allArgs["schema"],
+                                     allArgs["vhost"],
+                                     allArgs["app"],
+                                     allArgs["stream"]);
+        if (src) {
+            bool flag = src->seekTo(allArgs["stamp"].as<size_t>());
+            val["result"] = flag ? 0 : -1;
+            val["msg"] = flag ? "success" : "seek failed";
+            val["code"] = flag ? API::Success : API::OtherFailed;
+        } else {
+            val["result"] = -2;
+            val["msg"] = "can not find the stream";
+            val["code"] = API::OtherFailed;
+        }
+    });
 
     // 停止录制hls或MP4
     api_regist("/index/api/stopRecord",[](API_ARGS_MAP){
@@ -1399,4 +1438,4 @@ void unInstallWebApi(){
         s_rtpServerMap.clear();
 #endif
     }
-}
\ No newline at end of file
+}
--
libgit2 0.26.0