houxiao
2016-12-28 017b7eb736ccc53c52f81486be8196d7fafc3289
RtspFace/PL_H264Decoder.cpp
@@ -1,4 +1,5 @@
#include "PL_H264Decoder.h"
#include "MaterialBuffer.h"
#include <H264VideoRTPSource.hh> // for SPropRecord
#include <libbase64.h>
@@ -20,12 +21,14 @@
   AVCodecContext* pAVCodecContext;
   AVFrame* pAVFrame;//#todo delete
   MB_Frame lastFrame;
   
   H264Decoder_Internal() : 
      //buffSize(0), buffSizeMax(sizeof(buffer)), 
      fmtp_set_to_context(false), 
      payError(true), 
      pAVCodecContext(nullptr), pAVFrame(nullptr)
      pAVCodecContext(nullptr), pAVFrame(nullptr),
      lastFrame()
   {
   }
   
@@ -38,6 +41,9 @@
      //buffSize = 0;
      fmtp_set_to_context = false;
      payError = true;
      MB_Frame _lastFrame;
      lastFrame = _lastFrame;
   }
};
@@ -211,7 +217,27 @@
         in->fmtp_set_to_context = true;
   }
   
   bool ret = decodeH264(in, pm.buffer, pm.buffSize);
   if (pm.buffer == nullptr || pm.buffSize <= 0)
      return false;
   bool ret = false;
   if (pm.type == PipeMaterial::PMT_BYTES)
      ret = decodeH264(in, pm.buffer, pm.buffSize);
   else if (pm.type == PipeMaterial::PMT_FRAME)
   {
      MB_Frame* frame = (MB_Frame*)pm.buffer;
      ret = decodeH264(in, frame->buffer, frame->buffSize);
      if (ret)
      {
         in->lastFrame.type = MB_Frame::MBFT_PTR_AVFRAME;
         in->lastFrame.buffer = (uint8_t*)(in->pAVFrame);
         in->lastFrame.buffSize = sizeof(in->pAVFrame);
         //in->lastFrame.pts = frame->pts;//#todo
         gettimeofday(&(in->lastFrame.pts),NULL);
      }
   }
   in->payError = !ret;
   return ret;
}
@@ -222,8 +248,9 @@
   if (!in->payError)
   {
      pm.buffer = (uint8_t*)in->pAVFrame;//in->buffer;
      pm.buffSize = sizeof(uint8_t*);//in->buffSize;
      pm.type = PipeMaterial::PMT_FRAME;
      pm.buffer = (uint8_t*)(&(in->lastFrame));
      pm.buffSize = sizeof(uint8_t*);
   }
   pm.former = this;
   return !in->payError;