RtspLiveServer项目 基于Live555 ProxyServer代理服务并用C# 封装的RTSP流媒体服务库,用于转发局域网中支持Onvif协议 的摄像机并统一提供对外服务端口。API是C++开发,上层应用软件为C#开发,非常适合.NET程序员使用,性能不差。
一、 接口列表
-
RLS_Init:初始化服务端口、缓存长度、设置访问用户及密码;
-
RLS_AddMedia:添加视频RTSP并设置通道名称;
-
RLS_RemoveMedia:删除指定通道名称的视频;
-
RLS_LookUp:查找指定通道名称的视频;
-
RLS_Listen:启动服务;
-
RLS_Stop:停止服务。
二、API定义如下
public class RtspLiveServer
{
{
/*缓存区最小长度*/
public const int OUTPACKET_MINSIZE = 102400;
/*接口返回成功*/
public const int RLS_RET_OK = 1;
/*接口返回失败*/
public const int RLS_RET_Fail = 0;
/*服务运行*/
public const int RLS_SERVER_RUN = 1;
/*服务停止*/
public const int RLS_SERVER_STOP = 0;
/// <summary>
/// 初始化RTSP服务
/// </summary>
/// <param name="port">端口</param>
/// <param name="username">访问用户</param>
/// <param name="password">访问密码</param>
/// <param name="packetSize">缓存区长度不能小于100kb</param>
/// <returns>0失败,1成功</returns>
[DllImport("RtspLiveServer.dll")]
public static extern int RLS_Init(ushort port = 554, uint packetSize=1024000,[MarshalAs(UnmanagedType.LPStr)]string username = null, [MarshalAs(UnmanagedType.LPStr)]string password = null);
public const int OUTPACKET_MINSIZE = 102400;
/*接口返回成功*/
public const int RLS_RET_OK = 1;
/*接口返回失败*/
public const int RLS_RET_Fail = 0;
/*服务运行*/
public const int RLS_SERVER_RUN = 1;
/*服务停止*/
public const int RLS_SERVER_STOP = 0;
/// <summary>
/// 初始化RTSP服务
/// </summary>
/// <param name="port">端口</param>
/// <param name="username">访问用户</param>
/// <param name="password">访问密码</param>
/// <param name="packetSize">缓存区长度不能小于100kb</param>
/// <returns>0失败,1成功</returns>
[DllImport("RtspLiveServer.dll")]
public static extern int RLS_Init(ushort port = 554, uint packetSize=1024000,[MarshalAs(UnmanagedType.LPStr)]string username = null, [MarshalAs(UnmanagedType.LPStr)]string password = null);
/// <summary>
/// 添加输入视频资源
/// </summary>
/// <param name="inputStreamURL">输入视频RTSP地址</param>
/// <param name="streamName">输出的通道名称(根据项目实际情况填写如cam1)</param>
/// <param name="autoDeleted">True时当视频资源没有客户端连接时自动释放,适合用于需要重复利用资源的场合;默认为False</param>
/// <remarks>注意事项:同一输出通道名[streamName参数]资源不要重复添加,因此添加前会删除之前名称相同的视频资源可能会造成正在播放的用户断开</remarks>
/// <returns>0失败,1成功</returns>
[DllImport("RtspLiveServer.dll")]
public static extern int RLS_AddMedia([MarshalAs(UnmanagedType.LPStr)]string inputStreamURL, [MarshalAs(UnmanagedType.LPStr)]string streamName, [MarshalAs(UnmanagedType.Bool)]bool autoDeleted=false);
/// <summary>
/// 删除视频资源
/// </summary>
/// <param name="streamName"></param>
/// <remarks>删除视频资源时,若有客户端正在直播时并不强制中断视频而且等到所有客户端退出后才停止视频流</remarks>
/// <returns></returns>
[DllImport("RtspLiveServer.dll")]
public static extern void RLS_RemoveMedia([MarshalAs(UnmanagedType.LPStr)]string streamName);
/// <summary>
/// 查找视频资源
/// </summary>
/// <param name="streamName"></param>
/// <returns>0失败,1成功</returns>
[DllImport("RtspLiveServer.dll")]
public static extern int RLS_LookUp([MarshalAs(UnmanagedType.LPStr)]string streamName);
/// 添加输入视频资源
/// </summary>
/// <param name="inputStreamURL">输入视频RTSP地址</param>
/// <param name="streamName">输出的通道名称(根据项目实际情况填写如cam1)</param>
/// <param name="autoDeleted">True时当视频资源没有客户端连接时自动释放,适合用于需要重复利用资源的场合;默认为False</param>
/// <remarks>注意事项:同一输出通道名[streamName参数]资源不要重复添加,因此添加前会删除之前名称相同的视频资源可能会造成正在播放的用户断开</remarks>
/// <returns>0失败,1成功</returns>
[DllImport("RtspLiveServer.dll")]
public static extern int RLS_AddMedia([MarshalAs(UnmanagedType.LPStr)]string inputStreamURL, [MarshalAs(UnmanagedType.LPStr)]string streamName, [MarshalAs(UnmanagedType.Bool)]bool autoDeleted=false);
/// <summary>
/// 删除视频资源
/// </summary>
/// <param name="streamName"></param>
/// <remarks>删除视频资源时,若有客户端正在直播时并不强制中断视频而且等到所有客户端退出后才停止视频流</remarks>
/// <returns></returns>
[DllImport("RtspLiveServer.dll")]
public static extern void RLS_RemoveMedia([MarshalAs(UnmanagedType.LPStr)]string streamName);
/// <summary>
/// 查找视频资源
/// </summary>
/// <param name="streamName"></param>
/// <returns>0失败,1成功</returns>
[DllImport("RtspLiveServer.dll")]
public static extern int RLS_LookUp([MarshalAs(UnmanagedType.LPStr)]string streamName);
/// <summary>
/// 启动侦听服务
/// </summary>
[DllImport("RtspLiveServer.dll")]
public static extern void RLS_Listen();
/// 启动侦听服务
/// </summary>
[DllImport("RtspLiveServer.dll")]
public static extern void RLS_Listen();
/// <summary>
/// 停止服务
/// </summary>
[DllImport("RtspLiveServer.dll")]
public static extern void RLS_Stop();
/// 停止服务
/// </summary>
[DllImport("RtspLiveServer.dll")]
public static extern void RLS_Stop();
}
三、运行效果
四、源码运行注意事项
开发工具Vs2015
.NetFramework 4.5
WPF简单界面非Winform
五、源码下载地址
2、csdn资源下载地址
有技术问题可加QQ群_341402289