Skip to content

Commit

Permalink
Update VideoParser.
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverou committed Jan 17, 2019
1 parent 0b471e4 commit 4094b6e
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 129 deletions.
83 changes: 0 additions & 83 deletions Sample Code/DJIVideoParser/h264_Decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,68 +27,6 @@ static bool s_is_init_ffmpeg = false;

#define HEAD_SIZE 12

bool Pack_Compositer::CompositePack(const uint8_t *data, const uint32_t size)
{
m_packBuffer.insert(m_packBuffer.end(), data, data + size);

while (!m_hasPackHeader && m_packBuffer.size() >= HEAD_SIZE)
{
const uint8_t* pData = (const uint8_t*)m_packBuffer.data();

if (pData[0] == 0x00 && pData[1] == 0x00 && pData[2] == 0x01 && pData[3] == 0xff)
{
if (HeaderXor(pData))
{
m_hasPackHeader = true;
break;
}
}

m_packBuffer.erase(m_packBuffer.begin());

}

if (m_hasPackHeader)
{
m_pCurDataItem = (HPI_CHL_DATA*)(m_packBuffer.data());
uint32_t totalSize = m_pCurDataItem->total_size();

if (m_packBuffer.size() < totalSize) return false;

m_hasPackHeader = false;

if (m_pCurDataItem->chnl_id == m_channelId)
{

m_outBuffer.resize(m_pCurDataItem->payload_size());

std::copy(m_pCurDataItem->data_byte, m_pCurDataItem->data_byte + m_pCurDataItem->payload_size(), &m_outBuffer.front());

m_packBuffer.erase(m_packBuffer.begin(), m_packBuffer.begin() + totalSize);

return true;
}
else {

m_packBuffer.erase(m_packBuffer.begin(), m_packBuffer.begin() + totalSize);

}
}

return false;
}

bool Pack_Compositer::HeaderXor(const uint8_t* pData)
{
int result = 0;
for (int i = 0; i < HEAD_SIZE - 1; i++)
{
result ^= pData[i];
}

return (result == 0);
}

h264_Decoder::h264_Decoder()
{

Expand Down Expand Up @@ -201,7 +139,6 @@ bool h264_Decoder::InitFrameBuffer()
{
if (m_dst_frame)
{
#ifdef _PC_
m_outBuffer = new uint8_t[avpicture_get_size(PIX_FMT_FORMAT, m_codec_context->width, m_codec_context->height)];

avpicture_fill((AVPicture *)m_dst_frame, m_outBuffer, PIX_FMT_FORMAT, m_codec_context->width, m_codec_context->height);
Expand All @@ -219,26 +156,6 @@ bool h264_Decoder::InitFrameBuffer()
nullptr,
nullptr
);
#else
m_outBuffer = new uint8_t[avpicture_get_size(AV_PIX_FMT_BGR24, m_codec_context->width, m_codec_context->height)];

avpicture_fill((AVPicture *)m_dst_frame, m_outBuffer, AV_PIX_FMT_BGR24, m_codec_context->width, m_codec_context->height);

m_sws_ctx = sws_getContext
(
m_codec_context->width,
m_codec_context->height,
m_codec_context->pix_fmt,
m_codec_context->width,
m_codec_context->height,
AV_PIX_FMT_BGR24,
SWS_BILINEAR,
nullptr,
nullptr,
nullptr
);

#endif


return true;
Expand Down
45 changes: 0 additions & 45 deletions Sample Code/DJIVideoParser/h264_Decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,50 +25,6 @@ namespace dji {
}
}

#pragma pack(1)
typedef struct tagHPI_CHL_DATA
{
uint32_t magic;
uint32_t len;
uint8_t ver_hsize;
uint8_t chnl_id;
uint8_t checksum;
uint8_t padding;
uint8_t data_byte[1];

uint32_t total_size() const
{
return payload_size() + 12;
}
uint32_t payload_size() const
{
uint32_t temp = ((len & 0xFF000000) >> 8) | (len & 0x0000FFFF);
return temp;
}
}HPI_CHL_DATA;
#pragma pack()

class Pack_Compositer
{
public:
Pack_Compositer() : m_hasPackHeader(false), m_channelId(0x11) {}
~Pack_Compositer() {}

bool CompositePack(const uint8_t *data, const uint32_t size);
void SetChannelIdx(const uint8_t chID) { m_channelId = chID; }
HPI_CHL_DATA* m_pCurDataItem;

std::vector<uint8_t> m_outBuffer;
private:
bool HeaderXor(const uint8_t* pData);

private:
std::vector<uint8_t> m_packBuffer;
bool m_hasPackHeader;
uint8_t m_channelId;
int m_counter = 0;
};

class h264_Decoder {
public:
h264_Decoder();
Expand All @@ -83,7 +39,6 @@ class h264_Decoder {
AVCodecParserContext* m_codec_paser = nullptr;

SwsContext* m_sws_ctx = nullptr;
Pack_Compositer m_pack_compositer;

int videoFrameParse(const uint8_t* buff, int video_size, FrameType type, uint64_t pts);

Expand Down
4 changes: 3 additions & 1 deletion Sample Code/DJIWindowsSDKSample/FPV/FPVPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,13 @@ private void UninitializeVideoFeedModule()
}
}

//raw data
void OnVideoPush(VideoFeed sender, byte[] bytes)
{
this.videoParser.PushVideoData(0, 0, bytes, bytes.Length);
videoParser.PushVideoData(0, 0, bytes, bytes.Length);
}

//Decode data. Do nothing here. This function would return a bytes array with image data in RGBA format.
async void ReceiveDecodedData(byte[] data, int width, int height)
{
}
Expand Down

0 comments on commit 4094b6e

Please sign in to comment.