Skip to content

Commit

Permalink
添加proxyplayer option
Browse files Browse the repository at this point in the history
  • Loading branch information
BenLocal committed Jul 2, 2024
1 parent 63057c4 commit 47621e7
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ workspace = { members = ["rszlm-sys"] }

[package]
name = "rszlm"
version = "0.1.4"
version = "0.1.5"
edition = "2021"
authors = ["shiben. <[email protected]>"]
description = "ZLMediaKit rust api"
Expand Down
1 change: 1 addition & 0 deletions examples/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<String>();
player.on_close(move |_, _, _| {
Expand Down
17 changes: 11 additions & 6 deletions src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
30 changes: 28 additions & 2 deletions src/player.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -55,6 +57,7 @@ pub struct ProxyPlayerBuilder {
stream: String,
hls_enabled: bool,
mp4_enabled: bool,
options: HashMap<String, String>,
}

impl ProxyPlayerBuilder {
Expand Down Expand Up @@ -87,16 +90,39 @@ 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),
const_str_to_ptr!(self.stream),
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
}
}

Expand Down

0 comments on commit 47621e7

Please sign in to comment.