diff --git a/Cargo.toml b/Cargo.toml index 77493ab..c86b47e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ workspace = { members = ["rszlm-sys"] } [package] name = "rszlm" -version = "0.1.4" +version = "0.1.5" edition = "2021" authors = ["shiben. "] description = "ZLMediaKit rust api" diff --git a/examples/server.rs b/examples/server.rs index 21f6eda..70bc098 100644 --- a/examples/server.rs +++ b/examples/server.rs @@ -127,6 +127,7 @@ async fn proxy_pull_worker(source: &str, app: &str, stream: &str, cancel: Cancel .vhost("__defaultVhost__") .app(app) .stream(stream) + .add_option("rtp_type", "0") .build(); let (tx, rx) = tokio::sync::oneshot::channel::(); player.on_close(move |_, _, _| { diff --git a/src/init.rs b/src/init.rs index e4f4304..4cdd360 100644 --- a/src/init.rs +++ b/src/init.rs @@ -30,12 +30,11 @@ impl EnvInitBuilder { /// 设置日志级别 /// - /// ??? - /// - 0: 不输出日志 - /// - 1: 输出错误日志 - /// - 2: 输出错误和警告日志 - /// - 3: 输出错误、警告和调试日志 - /// - 4: 输出错误、警告、调试和信息日志 + /// - 0: Trace + /// - 1: Debug + /// - 2: Info + /// - 3: Warn + /// - 4: Error /// pub fn log_level(mut self, log_level: i32) -> Self { self.0.log_level = log_level; @@ -56,11 +55,17 @@ impl EnvInitBuilder { self } + /// 文件日志保存路径,路径可以不存在(内部可以创建文件夹) + /// 默认设置为NULL关闭日志输出至文件 + /// pub fn log_file_path(mut self, log_file_path: &str) -> Self { self.0.log_file_path = const_str_to_ptr!(log_file_path); self } + /// 文件日志保存天数 + /// 默认设置为0关闭日志文件 + /// pub fn log_file_days(mut self, log_file_days: i32) -> Self { self.0.log_file_days = log_file_days; self diff --git a/src/player.rs b/src/player.rs index 84cc2f3..a67ff99 100644 --- a/src/player.rs +++ b/src/player.rs @@ -1,3 +1,5 @@ +use std::collections::HashMap; + use rszlm_sys::*; use crate::{box_to_mut_void_ptr, const_ptr_to_string, const_str_to_ptr}; @@ -55,6 +57,7 @@ pub struct ProxyPlayerBuilder { stream: String, hls_enabled: bool, mp4_enabled: bool, + options: HashMap, } impl ProxyPlayerBuilder { @@ -87,8 +90,23 @@ impl ProxyPlayerBuilder { self } + /// Add option + /// key: + /// - net_adapter + /// - rtp_type:rtsp播放方式:RTP_TCP = 0, RTP_UDP = 1, RTP_MULTICAST = 2 + /// - rtsp_user: rtsp播放用户名 + /// - rtsp_pwd: rtsp播放密码 + /// - protocol_timeout_ms + /// - media_timeout_ms + /// - beat_interval_ms + /// - rtsp_speed + pub fn add_option(mut self, key: &str, val: &str) -> Self { + self.options.insert(key.to_string(), val.to_string()); + self + } + pub fn build(self) -> ProxyPlayer { - ProxyPlayer(unsafe { + let tmp = ProxyPlayer(unsafe { mk_proxy_player_create( const_str_to_ptr!(self.vhost), const_str_to_ptr!(self.app), @@ -96,7 +114,15 @@ impl ProxyPlayerBuilder { self.hls_enabled as i32, self.mp4_enabled as i32, ) - }) + }); + + if !self.options.is_empty() { + for (key, val) in self.options { + tmp.set_options(&key, &val); + } + } + + tmp } }