From 4b83e449973eff3303ba813806c1edfafd323347 Mon Sep 17 00:00:00 2001
From: xuxiuxi <xuxiuxi@454eff88-639b-444f-9e54-f578c98de674>
Date: 星期五, 31 三月 2017 15:20:06 +0800
Subject: [PATCH]
---
RtspFace/PL_H264Decoder.cpp | 57 ++++++++++++++++++++++++++++++++++++++++-----------------
1 files changed, 40 insertions(+), 17 deletions(-)
diff --git a/RtspFace/PL_H264Decoder.cpp b/RtspFace/PL_H264Decoder.cpp
index 3f61cce..87d8735 100644
--- a/RtspFace/PL_H264Decoder.cpp
+++ b/RtspFace/PL_H264Decoder.cpp
@@ -22,14 +22,16 @@
AVCodecContext* pAVCodecContext;
AVFrame* pAVFrame;//#todo delete
+
MB_Frame lastFrame;
+ PL_H264Decoder_Config config;
H264Decoder_Internal() :
//buffSize(0), buffSizeMax(sizeof(buffer)),
fmtp_set_to_context(false),
payError(true),
pAVCodecContext(nullptr), pAVFrame(nullptr),
- lastFrame()
+ lastFrame(), config()
{
}
@@ -43,8 +45,14 @@
fmtp_set_to_context = false;
payError = true;
+ pAVCodecContext = nullptr;
+ pAVFrame = nullptr;
+
MB_Frame _lastFrame;
lastFrame = _lastFrame;
+
+ PL_H264Decoder_Config _config;
+ config = _config;
}
};
@@ -67,6 +75,12 @@
{
H264Decoder_Internal* in = (H264Decoder_Internal*)internal;
in->reset();
+
+ if (args)
+ {
+ PL_H264Decoder_Config* config = (PL_H264Decoder_Config*)args;
+ in->config = *config;
+ }
return true;
}
@@ -122,19 +136,20 @@
if (!avCodec)
{
- LOG(WARN) << "codec not found!";
+ LOG_WARN << "codec not found!" << std::endl;
return false;
}
in->pAVCodecContext = avcodec_alloc_context3(avCodec);
-
- in->pAVCodecContext->time_base.num = 1;
- in->pAVCodecContext->frame_number = 1;
+
in->pAVCodecContext->codec_type = AVMEDIA_TYPE_VIDEO;
- in->pAVCodecContext->bit_rate = 0;
- in->pAVCodecContext->time_base.den = 25;
- in->pAVCodecContext->width = 1920;//#todo get from pm
- in->pAVCodecContext->height = 1080;
+ // this is only reference for codec
+ //in->pAVCodecContext->frame_number = 1;
+ //in->pAVCodecContext->bit_rate = 0;
+ //in->pAVCodecContext->time_base.num = 1;
+ //in->pAVCodecContext->time_base.den = 25;
+ //in->pAVCodecContext->width = 1920;
+ //in->pAVCodecContext->height = 1080;
if (in->pAVCodecContext->extradata == NULL)
{
@@ -170,7 +185,7 @@
if (av_packet_from_data(&packet, buffer, buffSize) != 0)
{
- LOG(WARN) << "av_packet_from_data error";
+ LOG_WARN << "av_packet_from_data error" << std::endl;
return false;
}
@@ -185,7 +200,8 @@
}
else
{
- LOG(WARN) << "incomplete frame";
+ //#todo sps sps changing
+ LOG_WARN << "incomplete frame" << std::endl;
return false;
}
}
@@ -201,14 +217,17 @@
if (manager == NULL)
return false;
- std::string fmtp(manager->get_global_param(PLGP_RTSP_FMTP));
+ std::string fmtp(manager->get_param(PLGP_RTSP_FMTP));
if (fmtp.empty())
return false;
size_t numSPropRecords = 0;
SPropRecord *p_record = parseSPropParameterSets(fmtp.c_str(), numSPropRecords);
if (numSPropRecords < 2)
- return false;//#todo log
+ {
+ LOG_WARN << "numSPropRecords < 2" << std::endl;
+ return false;
+ }
SPropRecord &sps = p_record[0];
SPropRecord &pps = p_record[1];
@@ -216,8 +235,8 @@
bool ret = initH264DecoderEnv(in, sps.sPropBytes, sps.sPropLength, pps.sPropBytes, pps.sPropLength);
if (!ret)
{
- LOG(ERROR) << "PL_H264Decoder::pay initH264DecoderEnv error";
- return false; // #todo log
+ LOG_ERROR << "initH264DecoderEnv error" << std::endl;
+ return false;
}
else
in->fmtp_set_to_context = true;
@@ -250,8 +269,12 @@
in->lastFrame.buffSize = sizeof(in->pAVFrame);
in->lastFrame.width = in->pAVFrame->width;
in->lastFrame.height = in->pAVFrame->height;
- //in->lastFrame.pts = frame->pts;//#todo
- gettimeofday(&(in->lastFrame.pts),NULL);
+
+ if (in->config.resetPTS)
+ gettimeofday(&(in->lastFrame.pts),NULL);
+ else
+ in->lastFrame.pts = frame->pts;
+
}
}
--
Gitblit v1.8.0