• RTSP播放器高起播低延时RTSP网页无插件流媒体播放器EasyPlayerRTSP代码解析(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)

    函数说明:播放器按比例进行显示
    参数说明: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();
                    }
                }
            }
    
    

  • 相关阅读:
    mysql update与select结合修改表数据
    编译与安装 OpenSSL
    MQTT的学习之Mosquitto安装&使用(1)
    Spring Cloud构建微服务架构(三)消息总线
    Spring Cloud构建微服务架构(一)服务注册与发现
    Spring Cloud构建微服务架构(二)分布式配置中心
    【行为型模式】《大话设计模式》——读后感 (16)加薪非要老板批?——职责链模式
    【行为型模式】《大话设计模式》——读后感 (15)烤羊肉串引来的思考?——命令模式
    【结构型模式】《大话设计模式》——读后感 (14)分公司=一部门?——组合模式
    【结构型模式】《大话设计模式》——读后感 (13)手机软件何时能统一?——桥接模式
  • 原文地址:https://www.cnblogs.com/TSINGSEE/p/11970641.html
Copyright © 2020-2023  润新知