資源簡介
nginx服務器搭建,基于librtmp的rtmp推流封裝。在訪問量不是特別大的時候可以正常使用,大數據量的情況沒有進行過壓力測試不知道效果怎么樣。

代碼片段和文件信息
#include?“stdafx.h“
#include?“SGRtmpSend.h“
SGRtmpSend::SGRtmpSend()
{
m_rtmp?=?NULL;
m_nTick?=?0;
memset(&m_SpsPps?0?sizeof(m_SpsPps));
m_bSendSpsPps?=?FALSE;
}
SGRtmpSend::~SGRtmpSend()
{
if?(m_rtmp?!=?NULL)
{
m_rtmp->Close();
m_rtmp?=?NULL;
}
}
BOOL?SGRtmpSend::ConnectRtmpSrv(const?char*?szRtmpUrl)
{
if?(m_rtmp?==?NULL)
{
m_rtmp?=?LibrtmpGetInstance();
}
return?m_rtmp->Connect(szRtmpUrl);
}
int?SGRtmpSend::GetStartCodeInfoWithSpsPps(BYTE?*pBuffer?int?bufSize?std::vectorameDataInfo>?&startCodeInfo)
{
if?(pBuffer?==?NULL?||?bufSize?==?0)
{
return?0;
}
tagframeDataInfo?lframeDataInfo;
int?nCount?=?0;
for?(int?i?=?0;?i?+?3? {
if?(*(pBuffer?+?i)?==?0x00?&&?*(pBuffer?+?i?+?1)?==?0x00?&&?*(pBuffer?+?i?+?2)?==?0x01)
{
if?((i?!=?0)?&&?(*(pBuffer?+?i?-?1)?==?0x00))
{
lframeDataInfo.nStartCodeLen?=?4;
lframeDataInfo.nStartPos?=?i?-?1;
}
else
{
lframeDataInfo.nStartCodeLen?=?3;
lframeDataInfo.nStartPos?=?i;
}
startCodeInfo.push_back(lframeDataInfo);
if?((*(pBuffer?+?i?+?3)?&?0x1F)?==?NAL_IDR_SLICE?||?(*(pBuffer?+?i?+?3)?&?0x1F)?==?NAL_SLICE)
{
//++nCount;
//if?(nCount?==?0)
{
break;
}
}
i?+=?3;
}
}
if?(startCodeInfo.size()?==?0)
{
return?0;
}
return?1;
}
BOOL?SGRtmpSend::SendVideoData(BYTE*?pBuff?DWORD?dwBuffSize)
{
m_SpsPps.bHasAudio?=?false;
m_SpsPps.nframeRate?=?25;
std::vectorameDataInfo>?startCodeInfo;
if?(!GetStartCodeInfoWithSpsPps((BYTE*)pBuff?dwBuffSize?startCodeInfo))
{
return?FALSE;
}
int?nPosSize?=?startCodeInfo.size();
for?(int?i?=?0;?i?!=?nPosSize;?i++)
{
if?(i?==?nPosSize?-?1)
{
startCodeInfo[i].nframeDataLen?=?dwBuffSize?-?startCodeInfo[i].nStartPos?-?startCodeInfo[i].nStartCodeLen;
}
else
{
startCodeInfo[i].nframeDataLen?=?startCodeInfo[i?+?1].nStartPos?-?startCodeInfo[i].nStartPos?-?startCodeInfo[i].nStartCodeLen;
}
switch?(*(((BYTE*)pBuff)?+?startCodeInfo[i].nStartPos?+?startCodeInfo[i].nStartCodeLen)?&?0x1F)
{
case?NAL_SPS:
{
m_SpsPps.nSpsLen?=?startCodeInfo[i].nframeDataLen;
memcpy(m_SpsPps.Sps?((BYTE*)pBuff)?+?startCodeInfo[i].nStartPos?+?startCodeInfo[i].nStartCodeLen?m_SpsPps.nSpsLen);
if?((m_SpsPps.nSpsLen?!=?0)?&&?(m_SpsPps.nPpsLen?!=?0)?&&?!m_bSendSpsPps)
{
m_bSendSpsPps?=?TRUE;
h264_decode_sps(m_SpsPps.Sps?m_SpsPps.nSpsLen?m_SpsPps.nWidth?m_SpsPps.nHeight);
m_rtmp->Sendmetadata(&m_SpsPps);
memset(&m_SpsPps?0?sizeof(RTMPmetadata));
m_SpsPps.bHasAudio?=?false;
m_SpsPps.nframeRate?=?25;
}
break;
}
case?NAL_PPS:
{
m_SpsPps.nPpsLen?=?startCodeInfo[i].nframeDataLen;
memcpy(m_SpsPps.Pps?((BYTE*)pBuff)?+?startCodeInfo[i].nStartPos?+?startCodeInfo[i].nStartCodeLen?m_SpsPps.nPpsLen);
if?((m_SpsPps.nSpsLen?!=?0)?&&?(m_SpsPps.nPpsLen?!=?0)?&&?!m_bSendSpsPps)
{
m_bSend
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2018-08-21?10:52??nginx\
?????目錄???????????0??2018-08-21?10:52??nginx\conf\
?????文件????????3463??2013-06-12?13:12??nginx\conf\mime.types
?????文件????????3418??2017-09-27?08:46??nginx\conf\nginx.conf
?????目錄???????????0??2018-08-21?10:52??nginx\logs\
?????文件??????271416??2018-07-11?14:54??nginx\logs\access.log
?????文件?????2265463??2018-07-12?08:03??nginx\logs\error.log
?????文件???????????6??2018-07-11?13:41??nginx\logs\nginx.pid
?????文件?????2676736??2013-06-12?13:12??nginx\nginx.exe
?????目錄???????????0??2018-08-21?10:52??nginx\temp\
?????目錄???????????0??2018-08-21?11:00??nginx\temp\client_body_temp\
?????目錄???????????0??2018-08-21?11:00??nginx\temp\fastcgi_temp\
?????目錄???????????0??2018-08-21?11:00??nginx\temp\proxy_temp\
?????目錄???????????0??2018-08-21?11:00??nginx\temp\scgi_temp\
?????目錄???????????0??2018-08-21?11:00??nginx\temp\uwsgi_temp\
?????文件?????????172??2017-09-07?14:57??nginx\使用說明.txt
?????目錄???????????0??2018-08-21?10:59??rtmp\
?????文件?????2546176??2015-01-04?23:14??rtmp\LibrtmpStream.dll
?????文件????????3034??2014-09-10?16:46??rtmp\LibrtmpStream.lib
?????文件?????????726??2014-09-23?14:30??rtmp\LibrtmpStreamInterface.h
?????文件????????1947??2014-08-25?08:56??rtmp\LibtrmpData.h
?????文件????????6499??2017-09-08?14:20??rtmp\SGRtmpSend.cpp
?????文件????????2054??2017-09-08?14:19??rtmp\SGRtmpSend.h
?????文件?????????517??2018-08-21?10:59??rtmp\使用說明.txt
- 上一篇:斑馬打印機ZPL指令中文手冊
- 下一篇:樣本標注工具ob
jectmarker.exe
評論
共有 條評論