RTSP播放器高起播低延时RTSP网页无插件流媒体播放器EasyPlayer-RTSP代码解析(C#版)

实时流协议(RTSP)是应用级协议,控制实时数据的发送。RTSP提供了一个可扩展框架,使实时数据,如音频与视频的受控点播成为可能。数据源包括现场数据与存储在剪辑中数据。该协议目的在于控制多个数据发送连接,为选择发送通道,如UDP、组播UDP与TCP,提供途径,并为选择基于RTP上发送机制提供方法。



EasyPlayer-RTSP播放器是一套RTSP专用的播放器,包括有:Windows(支持IE插件,npapi插件)、Android、iOS三个平台,EasyPlayer-RTSP系列从2014年初发展至今得到了各行各业(尤其是安防行业)的广泛应用,相较其他播放器更加精炼、更加专注,具备非常低的延时,非常高RTSP协议兼容性,编码数据解析等方面,都有很大的优势。

EasyPlayer-RTSP代码解析C#版

1、从https://github.com/tsingsee/EasyPlayer-RTSP 可以获得程序源码,下载后我们用VS2010打开工程,如下图所示;

2、其中 EasyPlayer-RTSP.NetSDK这个工程是将libEasyPlayer-RTSP.dll进行了一层包装,主要将libEasyPlayer-RTSP.dll可用函数封装到PlayerSdk类中暴露出来给.NET使用,下面简单罗列几个函数说明一下:

函数说明:开始进行流播放
参数说明:url流媒体地址、hWnd窗口句柄、renderFormat编码格式、rtpovertcp拉取流的传输模式,0=udp,1=tcp、用户名、密码、callback数据回调、bHardDecode硬件解码1=是,0=否、startTime回放开始时间,直播流填null、endTime回放结束时间,直播流填null、fScale回放倍率,直播流无效
int EasyPlayer_OpenStream(const char *url, HWND hWnd, RENDER_FORMAT renderFormat, int rtpovertcp, const char *username, const char password, MediaSourceCallBack callback=NULL, void userPtr=NULL, bool bHardDecode=true, char startTime = NULL, char endTime=NULL, float fScale = 1.0f )

函数说明: 关闭流
参数说明:channelId通道ID,EasyPlayer_OpenStream函数返回值.
int EasyPlayer_CloseStream(int channelId)

函数说明:设置当前流播放缓存帧数.
参数说明:channelId通道ID,EasyPlayer_OpenStream函数返回值,cache缓存的视频帧数
int EasyPlayer_SetFrameCache(int channelId, int cache)

扫描二维码关注公众号,回复: 8543361 查看本文章

函数说明:播放器按比例进行显示
参数说明:channelId通道ID,EasyPlayer_OpenStream函数返回值
shownToScale 0=整个窗口区域显示,1=按比例显示
int EasyPlayer_SetShownToScale(int channelId, int shownToScale)

函数说明:设置解码类型
参数说明:channelId通道ID,EasyPlayer_OpenStream函数返回值
decodeKeyframeOnly 0=所有帧解码,1=只解码关键帧
int EasyPlayer_SetDecodeType(int channelId, int decodeKeyframeOnly)
……

3、该工程生成EasyPlayer-RTSP.NetSDK.dll库文件,我们选择生成的模式为x86。

4、新建一个WINFORM工程,拖一个Panel和Button,Button按钮写点击事件

private void PlayerBtn_Click(object sender, EventArgs e)
        {
            var isPlay = (sender as Button).Text == "播放";
            if (isPlay)
            {
                string RTSPStreamURI = this.StreamURI.Text;
                channelID = PlayerSdk.EasyPlayer_OpenStream(RTSPStreamURI, this.panel1.Handle, RENDER_FORMAT, isTCP ? 1 : 0, "", "", callBack, IntPtr.Zero, isHardEncode);
                if (channelID > 0)
                {
                    PlayerSdk.EasyPlayer_SetFrameCache(channelID, 3);
                    this.PlayerBtn.Text = "停止";
                }
            }
            else
            {
                int ret = PlayerSdk.EasyPlayer_CloseStream(channelID);
                if (ret == 0)
                {
                    this.PlayerBtn.Text = "播放";
                    channelID = -1;
                    this.panel1.Refresh();
                }
            }
        }

 

发布了189 篇原创文章 · 获赞 7 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/TsingSee/article/details/103348947