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)

函數說明:播放器按比例進行顯示
參數說明: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();
                }
            }
        }


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM