• 大小: 28.46MB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-06-13
  • 语言: 其他
  • 标签: librtmp  H.264  Qt  流媒体  

资源简介

Qt基于librtmp推送H.264 详见博客:http://blog.csdn.net/caoshangpa/article/details/53125949

资源截图

代码片段和文件信息

#include “crtmpstream.h“
#include “SpsDecode.h“
#ifdef WIN32
#include 
#endif

CRTMPStream::CRTMPStream(void)
{
#ifdef WIN32
    WSADATA wsaData;
    WSAStartup(MAKEWORD(1 1) &wsaData);
#endif
    nalhead_pos=0;
    m_nFileBufSize=BUFFER_SIZE;
    m_pFileBuf=(unsigned char*)malloc(BUFFER_SIZE);
    m_pFileBuf_tmp=(unsigned char*)malloc(BUFFER_SIZE);

    m_pRtmp = RTMP_Alloc();
    RTMP_Init(m_pRtmp);
}

CRTMPStream::~CRTMPStream(void)
{
#ifdef WIN32
    WSACleanup();
#endif
}

bool CRTMPStream::Connect(const char* url)
{
    if(RTMP_SetupURL(m_pRtmp (char*)url)<0)
    {
        RTMP_Free(m_pRtmp);
        return FALSE;
    }

    RTMP_EnableWrite(m_pRtmp);

    if(RTMP_Connect(m_pRtmp NULL)<0)
    {
        RTMP_Free(m_pRtmp);
        return FALSE;
    }

    if(RTMP_ConnectStream(m_pRtmp0)<0)
    {
        RTMP_Close(m_pRtmp);
        RTMP_Free(m_pRtmp);
        return FALSE;
    }
    return TRUE;
}

void CRTMPStream::Disconnect()
{
    if(m_pRtmp)
    {
        RTMP_Close(m_pRtmp);
        RTMP_Free(m_pRtmp);
        m_pRtmp = NULL;
    }
    if (m_pFileBuf != NULL)
    {
        free(m_pFileBuf);
    }
    if (m_pFileBuf_tmp != NULL)
    {
        free(m_pFileBuf_tmp);
    }
}

int CRTMPStream::SendPacket(unsigned int nPacketTypeunsigned char *dataunsigned int sizeunsigned int nTimestamp)
{
    if(m_pRtmp == NULL)
    {
        return FALSE;
    }

    RTMPPacket* packet;

    packet = (RTMPPacket *)malloc(RTMP_HEAD_SIZE+size);
    memset(packet0RTMP_HEAD_SIZE);

    packet->m_body = (char *)packet + RTMP_HEAD_SIZE;
    packet->m_nBodySize = size;
    memcpy(packet->m_bodydatasize);
    packet->m_hasAbsTimestamp = 0;
    packet->m_packetType = nPacketType;
    packet->m_nInfoField2 = m_pRtmp->m_stream_id;
    packet->m_nChannel = 0x04;

    packet->m_headerType = RTMP_PACKET_SIZE_LARGE;
    if (RTMP_PACKET_TYPE_AUDIO ==nPacketType && size !=4)
    {
        packet->m_headerType = RTMP_PACKET_SIZE_MEDIUM;
    }
    packet->m_nTimeStamp = nTimestamp;

    int nRet =0;
    if (RTMP_IsConnected(m_pRtmp))
    {
        nRet = RTMP_SendPacket(m_pRtmppacketTRUE); /*TRUE为放进发送队列FALSE是不放进发送队列直接发送*/
    }

    free(packet);
    return nRet;
}

bool CRTMPStream::SendH264Packet(unsigned char *dataunsigned int sizebool bIsKeyframeunsigned int nTimeStamp)
{
    if(data == NULL && size<11)
    {
        return false;
    }

    unsigned char *body = (unsigned char*)malloc(size+9);
    memset(body0size+9);

    int i = 0;
    if(bIsKeyframe)
    {
        body[i++] = 0x17;// 1:iframe  7:AVC
        body[i++] = 0x01;// AVC NALU
        body[i++] = 0x00;
        body[i++] = 0x00;
        body[i++] = 0x00;


        // NALU size
        body[i++] = size>>24 &0xff;
        body[i++] = size>>16 &0xff;
        body[i++] = size>>8 &0xff;
        body[i++] = size&0xff;
        // NALU data
        memcpy(&body[i]datasize);
        SendVideoSpsPps(metaData.PpsmetaData.nPpsLenmetaData.SpsmetaData.nSpsLennTimeStamp);
    }
    else

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件   25821394  2016-11-07 12:00  TestRTMP\480320.264

     文件      26408  2016-11-08 11:51  TestRTMP\crtmpstream.cpp

     文件       4502  2016-10-31 09:53  TestRTMP\crtmpstream.h

     文件    1264640  2016-10-20 17:04  TestRTMP\debug\TestRTMP.exe

     文件    2101248  2016-10-20 17:04  TestRTMP\debug\testrtmp.pdb

     文件       5475  2010-07-01 03:58  TestRTMP\include\amf.h

     文件       2539  2010-07-01 03:58  TestRTMP\include\bytes.h

     文件       8264  2010-07-01 03:58  TestRTMP\include\dh.h

     文件       9575  2010-07-01 03:58  TestRTMP\include\dhgroups.h

     文件      31323  2010-07-01 03:58  TestRTMP\include\handshake.h

     文件       1637  2010-07-01 03:58  TestRTMP\include\http.h

     文件       1905  2010-07-01 03:58  TestRTMP\include\log.h

     文件       9537  2010-07-01 03:58  TestRTMP\include\rtmp.h

     文件       3938  2016-10-20 16:45  TestRTMP\include\rtmp_sys.h

     文件   16122906  2016-10-21 10:20  TestRTMP\lib\librtmpWindows.lib

     文件        523  2016-11-11 10:06  TestRTMP\main.cpp

     文件      25351  2016-10-21 14:25  TestRTMP\Makefile

     文件      16067  2016-10-21 14:25  TestRTMP\Makefile.Debug

     文件      15058  2016-10-21 14:25  TestRTMP\Makefile.Release

     文件      11114  2016-11-08 15:55  TestRTMP\release\crtmpstream.obj

     文件       2764  2016-11-11 10:06  TestRTMP\release\main.obj

     文件    1036800  2016-11-11 10:06  TestRTMP\release\TestRTMP.exe

     文件        638  2016-11-11 10:06  TestRTMP\release\TestRTMP.exe.embed.manifest

     文件       7992  2016-11-08 16:52  TestRTMP\spsdecode.h

     文件        331  2016-10-20 17:37  TestRTMP\TestRTMP.pro

     文件      78682  2016-11-11 10:18  TestRTMP\TestRTMP.pro.user

     文件      78682  2016-10-27 09:29  TestRTMP\TestRTMP.pro.user.93c588c

     目录          0  2016-10-20 17:04  TestRTMP\debug

     目录          0  2016-10-18 14:21  TestRTMP\include

     目录          0  2016-10-20 17:35  TestRTMP\lib

............此处省略5个文件信息

评论

共有 条评论