修改了推流时间戳的机制,降低延时
parent
400e0453c7
commit
a115b3da8e
|
@ -96,7 +96,8 @@ void MainWindow::on_pushButton_2_clicked()
|
|||
qDebug()<<"连接RTMP服务器"<<ui->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()<<address;
|
||||
if (0 == mPusher->RTMP264_Connect("rtmp://127.0.0.1:1939/live/1")) {
|
||||
ToastWidget::showTip("已经连接上RTMP服务器",this);
|
||||
mVideoCoder->SetOberver(mPusher);
|
||||
mPusher->StartPush();
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<Buffer> mPack;
|
||||
|
|
Loading…
Reference in New Issue