支持rtsp回放控制 (#4691)

目前对接过很多第三方系统(海康ISC、大华ICC、华为IVS、中维等)都支持rtsp回放,觉得有必要支持该功能
This commit is contained in:
XiaoYan Lin
2026-04-01 20:42:32 +08:00
committed by GitHub
parent 66b94b266c
commit c3c0fb4448
6 changed files with 186 additions and 12 deletions

View File

@@ -2564,6 +2564,89 @@ void installWebApi() {
invoker(200, headerOut, val.toStyledString());
});
#endif
// 设置流播放速度
// Set stream playback speed
api_regist("/index/api/setStreamSpeed", [](API_ARGS_JSON_ASYNC) {
CHECK_SECRET();
CHECK_ARGS("vhost", "app", "stream", "speed");
std::string vhost = allArgs["vhost"];
std::string app = allArgs["app"];
std::string stream = allArgs["stream"];
float speed = allArgs["speed"].as<float>();
auto tuple = MediaTuple { vhost, app, stream, "" };
std::string key = tuple.shortUrl();
auto player_proxy = s_player_proxy.find(key);
if (!player_proxy) {
throw ApiRetException("can not find the stream proxy", API::NotFound);
}
player_proxy->getPoller()->async([=]() mutable {
player_proxy->MediaPlayer::speed(speed);
val["result"] = 0;
val["msg"] = "success";
val["code"] = API::Success;
invoker(200, headerOut, val.toStyledString());
});
});
// 暂停/恢复流播放
// Pause/Resume stream playback
api_regist("/index/api/pauseStream", [](API_ARGS_JSON_ASYNC) {
CHECK_SECRET();
CHECK_ARGS("vhost", "app", "stream");
std::string vhost = allArgs["vhost"];
std::string app = allArgs["app"];
std::string stream = allArgs["stream"];
auto tuple = MediaTuple { vhost, app, stream, "" };
std::string key = tuple.shortUrl();
auto player_proxy = s_player_proxy.find(key);
if (!player_proxy) {
throw ApiRetException("can not find the stream proxy", API::NotFound);
}
player_proxy->getPoller()->async([=]() mutable {
player_proxy->MediaPlayer::pause(true);
val["result"] = 0;
val["msg"] = "success";
val["code"] = API::Success;
invoker(200, headerOut, val.toStyledString());
});
});
// 跳转到指定位置
// Seek to specified position
api_regist("/index/api/seekStream", [](API_ARGS_JSON_ASYNC) {
CHECK_SECRET();
CHECK_ARGS("vhost", "app", "stream");
std::string vhost = allArgs["vhost"];
std::string app = allArgs["app"];
std::string stream = allArgs["stream"];
uint32_t pos = allArgs["position"].as<uint32_t>();
auto tuple = MediaTuple { vhost, app, stream, "" };
std::string key = tuple.shortUrl();
auto player_proxy = s_player_proxy.find(key);
if (!player_proxy) {
throw ApiRetException("can not find the stream proxy", API::NotFound);
}
player_proxy->getPoller()->async([=]() mutable {
player_proxy->MediaPlayer::seekTo(pos);
val["result"] = 0;
val["msg"] = "success";
val["code"] = API::Success;
invoker(200, headerOut, val.toStyledString());
});
});
}
void unInstallWebApi(){