Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
PHZ76 committed Oct 16, 2019
1 parent dc64974 commit 4500199
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 102 deletions.
144 changes: 72 additions & 72 deletions src/xop/H264Parser.cpp
Original file line number Diff line number Diff line change
@@ -1,72 +1,72 @@
#include "H264Parser.h"
#include <cstring>

using namespace xop;

Nal H264Parser::findNal(const uint8_t *data, uint32_t size)
{
Nal nal(nullptr, nullptr);

if(size < 5)
{
return nal;
}

nal.second = const_cast<uint8_t*>(data) + (size-1);

//uint32_t startCode = 0;
uint32_t pos = 0;
uint8_t prefix[3] = {0};
memcpy(prefix, data, 3);
size -= 3;
data += 2;

while(size--)
{
if ((prefix[pos % 3] == 0) && (prefix[(pos + 1) % 3] == 0) && (prefix[(pos + 2) % 3] == 1))
{
if(nal.first == nullptr) // 00 00 01
{
nal.first = const_cast<uint8_t*>(data) + 1;
//startCode = 3;
}
else if(data > nal.first + 3)
{
nal.second = const_cast<uint8_t*>(data) - 3;
break;
}
}
else if ((prefix[pos % 3] == 0) && (prefix[(pos + 1) % 3] == 0) && (prefix[(pos + 2) % 3] == 0))
{
if (*(data+1) == 0x01) // 00 00 00 01
{
if(nal.first == nullptr)
{
if(size >= 1)
{
nal.first = const_cast<uint8_t*>(data) + 2;
}
else
{
break;
}
//startCode = 4;
}
else //if(startCode == 4)
{
nal.second = const_cast<uint8_t*>(data) - 3;
break;
}
}
}

prefix[(pos++) % 3] = *(++data);
}

if(nal.first == nullptr)
nal.second = nullptr;

return nal;
}


#include "H264Parser.h"
#include <cstring>

using namespace xop;

Nal H264Parser::findNal(const uint8_t *data, uint32_t size)
{
Nal nal(nullptr, nullptr);

if(size < 5)
{
return nal;
}

nal.second = const_cast<uint8_t*>(data) + (size-1);

//uint32_t startCode = 0;
uint32_t pos = 0;
uint8_t prefix[3] = {0};
memcpy(prefix, data, 3);
size -= 3;
data += 2;

while(size--)
{
if ((prefix[pos % 3] == 0) && (prefix[(pos + 1) % 3] == 0) && (prefix[(pos + 2) % 3] == 1))
{
if(nal.first == nullptr) // 00 00 01
{
nal.first = const_cast<uint8_t*>(data) + 1;
//startCode = 3;
}
else if(data > nal.first + 3)
{
nal.second = const_cast<uint8_t*>(data) - 3;
break;
}
}
else if ((prefix[pos % 3] == 0) && (prefix[(pos + 1) % 3] == 0) && (prefix[(pos + 2) % 3] == 0))
{
if (*(data+1) == 0x01) // 00 00 00 01
{
if(nal.first == nullptr)
{
if(size >= 1)
{
nal.first = const_cast<uint8_t*>(data) + 2;
}
else
{
break;
}
//startCode = 4;
}
else //if(startCode == 4)
{
nal.second = const_cast<uint8_t*>(data) - 3;
break;
}
}
}

prefix[(pos++) % 3] = *(++data);
}

if(nal.first == nullptr)
nal.second = nullptr;

return nal;
}


48 changes: 24 additions & 24 deletions src/xop/H264Parser.h
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
#ifndef XOP_H264_PARSER_H
#define XOP_H264_PARSER_H

#include <cstdint>
#include <utility>

namespace xop
{

typedef std::pair<uint8_t*, uint8_t*> Nal; // <nal begin, nal end>

class H264Parser
{
public:
static Nal findNal(const uint8_t *data, uint32_t size);

private:

};

}

#endif

#ifndef XOP_H264_PARSER_H
#define XOP_H264_PARSER_H

#include <cstdint>
#include <utility>

namespace xop
{

typedef std::pair<uint8_t*, uint8_t*> Nal; // <nal begin, nal end>

class H264Parser
{
public:
static Nal findNal(const uint8_t *data, uint32_t size);

private:

};

}

#endif

8 changes: 4 additions & 4 deletions src/xop/RtmpConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ int RtmpConnection::parseChunkHeader(BufferReader& buffer)
uint8_t csid = flags & 0x3f; // chunk stream id
if (csid == 0) // csid [64, 319]
{
if ((bufSize - bytesUsed) < 2)
if (bufSize < (bytesUsed + 2))
{
return 0;
}
Expand All @@ -272,7 +272,7 @@ int RtmpConnection::parseChunkHeader(BufferReader& buffer)
}
else if (csid == 1) // csid [64, 65599]
{
if ((bufSize - bytesUsed) < 3)
if (bufSize < (3 + bytesUsed))
{
return 0;
}
Expand All @@ -287,7 +287,7 @@ int RtmpConnection::parseChunkHeader(BufferReader& buffer)
}

uint32_t headerLen = kChunkMessageLen[fmt]; // basic_header + message_header
if ((bufSize - bytesUsed) < headerLen)
if (bufSize < (headerLen + bytesUsed))
{
return 0;
}
Expand Down Expand Up @@ -324,7 +324,7 @@ int RtmpConnection::parseChunkHeader(BufferReader& buffer)
uint32_t extTimestamp = 0;
if (timestamp >= 0xffffff) // extended timestamp
{
if ((bufSize - bytesUsed) < 4)
if (bufSize < (4 + bytesUsed))
{
return 0;
}
Expand Down
4 changes: 2 additions & 2 deletions src/xop/RtmpSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,15 @@ void RtmpSession::saveGop(uint8_t type, uint64_t timestamp, std::shared_ptr<char
}
}
}
else if (codecId == RTMP_CODEC_ID_H264)
else if (codecId == RTMP_CODEC_ID_H264 && gop != nullptr)
{
if (m_maxGopCacheLen > 0 && gop->size() >= 1 && gop->size() < m_maxGopCacheLen)
{
avFrame.reset(new AVFrame);
}
}
}
else if (type == RTMP_AUDIO)
else if (type == RTMP_AUDIO && gop != nullptr)
{
uint8_t soundFormat = (payload[0] >> 4) & 0x0f;
uint8_t soundSize = (payload[0] >> 1) & 0x01;
Expand Down

0 comments on commit 4500199

Please sign in to comment.