diff --git a/client/qt_gl_/yuvgl/mainwindow.cpp b/client/qt_gl_/yuvgl/mainwindow.cpp index 3dc31c7..d501076 100644 --- a/client/qt_gl_/yuvgl/mainwindow.cpp +++ b/client/qt_gl_/yuvgl/mainwindow.cpp @@ -96,7 +96,8 @@ void MainWindow::on_pushButton_2_clicked() qDebug()<<"连接RTMP服务器"<lineEdit->text(); if (!mPusher->IfConnect()) { const char* address = ui->lineEdit->text().toLocal8Bit().data(); - if (0 == mPusher->RTMP264_Connect("rtmp://127.0.0.1:1935/live/1")) { + qDebug()<RTMP264_Connect("rtmp://127.0.0.1:1939/live/1")) { ToastWidget::showTip("已经连接上RTMP服务器",this); mVideoCoder->SetOberver(mPusher); mPusher->StartPush(); diff --git a/client/qt_gl_/yuvgl/media/RtmpPusher.cpp b/client/qt_gl_/yuvgl/media/RtmpPusher.cpp index a5defdc..8fb71da 100644 --- a/client/qt_gl_/yuvgl/media/RtmpPusher.cpp +++ b/client/qt_gl_/yuvgl/media/RtmpPusher.cpp @@ -139,6 +139,7 @@ int RtmpPusher::SendVideoPacket(unsigned int nPacketType, packet->m_packetType = nPacketType; /*˴ΪһƵ,һƵ*/ packet->m_nInfoField2 = m_pRtmp->m_stream_id; packet->m_nChannel = 0x04; + packet->m_nTimeStamp += 33; packet->m_headerType = RTMP_PACKET_SIZE_LARGE; if (RTMP_PACKET_TYPE_AUDIO == nPacketType && size != 4) @@ -197,6 +198,7 @@ H264RtmpPuser::H264RtmpPuser() this->metaData.Sps = nullptr; this->metaData.nPpsLen = 0; this->metaData.nSpsLen = 0; + this->mStartTime = 0; mFirtACC = false; } @@ -206,9 +208,9 @@ int H264RtmpPuser::sortAndSendNal(uint8_t * data, int len) uint8_t * nalhead = nullptr; uint8_t * naltail = nullptr; uint32_t size = 0; - - static int timestamp = 0; - timestamp += 1000 / 25; + if(0 == mStartTime){ + mStartTime = RTMP_GetTime(); + } if (nullptr == data) { return -1; } @@ -219,10 +221,11 @@ int H264RtmpPuser::sortAndSendNal(uint8_t * data, int len) && ((data[i + 2] == 0x00) && (data[i + 3] == 0x01) || (data[i + 2] == 0x01))) { if ((nalhead == nullptr) && (i == 0) ) { if ((data[i + 3] == 0x01) && (data[i + 4] == 0x41)) { //p ֱ֡ӷ + nalhead = data; naltail = data + (len); size = naltail - nalhead; - this->SendH264Packet(nalhead, size, 0, timestamp); + this->SendH264Packet(nalhead, size, 0, RTMP_GetTime() - mStartTime); return 0; } //sps ֡н @@ -238,20 +241,21 @@ int H264RtmpPuser::sortAndSendNal(uint8_t * data, int len) else { // i frame if ((data[i + 2] == 0x01) && (data[i + 3] == 0x65)) { + naltail = data + i; size = naltail - nalhead; - this->SendH264Packet(nalhead, size, 0, timestamp); + this->SendH264Packet(nalhead, size, 0, RTMP_GetTime() - mStartTime); nalhead = data + i; naltail = data + (len); size = naltail - nalhead; - this->SendH264Packet(nalhead, size, 0, timestamp); + this->SendH264Packet(nalhead, size, 0, RTMP_GetTime() - mStartTime); return 0; } //pps if ((data[i + 3] == 0x01) && (data[i + 4] == 0x68)) { // sps or pps or sei naltail = data + i; size = naltail - nalhead; - this->SendH264Packet(nalhead, size, 0, timestamp); + this->SendH264Packet(nalhead, size, 0, RTMP_GetTime() - mStartTime); nalhead = data + i; i += 3; }//sps @@ -263,7 +267,7 @@ int H264RtmpPuser::sortAndSendNal(uint8_t * data, int len) if ((data[i + 3] == 0x01) && (data[i + 4] == 0x06)) { // sps or pps or sei naltail = data + i; size = naltail - nalhead; - this->SendH264Packet(nalhead, size, 0, timestamp); + this->SendH264Packet(nalhead, size, 0, RTMP_GetTime() - mStartTime); nalhead = data + i; i += 3; } @@ -419,7 +423,7 @@ int H264RtmpPuser::sendDataPackH264(unsigned char * data, memcpy(&gBody[i], data, size); if(metaData.Sps != nullptr) SendVideoSpsPps(metaData.Pps, metaData.nPpsLen, metaData.Sps, - metaData.nSpsLen, nTimeStamp); + metaData.nSpsLen, 0); } else { gBody[i++] = 0x27;// 2:Pframe 7:AVC diff --git a/client/qt_gl_/yuvgl/media/RtmpPusher.h b/client/qt_gl_/yuvgl/media/RtmpPusher.h index 74a9a1e..64010d9 100644 --- a/client/qt_gl_/yuvgl/media/RtmpPusher.h +++ b/client/qt_gl_/yuvgl/media/RtmpPusher.h @@ -96,7 +96,7 @@ private: int sendDataPackH264(unsigned char *data, unsigned int size, int bIsKeyFrame, unsigned int nTimeStamp); int sendDataPackAAC(unsigned char *data, unsigned int size, unsigned int nTimeStamp); - + uint32_t mStartTime; public: queue mPack;